Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 1x 1x 1x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 304x 1x 1x 257x 257x 239x 34x 34x 34x 34x 34x 34x 257x 257x 257x 257x 257x 257x 34x 34x 1204x 1204x 1204x 27x 27x 27x 27x 27x 27x 27x 1204x 1204x 4643x 4643x 4643x 4643x 4322x 710x 710x 591x 710x 4643x 1204x 1204x 1204x 917x 917x 287x 287x 57x 57x 57x 57x 1204x 1204x 1x | import type {IAdapterRegistry, ILog, IRegistry} from '@feasibleone/blong/types';
export interface IRealm {
addModule: (name: string, mod: IRegistry) => void;
addLayer: (name: string, layer: IRealm) => void;
}
export default class RealmImpl implements IRealm {
#registry: IRegistry;
#log: ILog;
#logger: ReturnType<ILog['logger']>;
#config: {
realm?: {logLevel?: Parameters<ILog['logger']>[0]};
name: string;
pkg: {name: string; version: string};
};
/**
* The vocabularies this realm has declared, shared by reference with every layer's result.
*
* Held on the realm rather than on a layer because a declaration names what the *realm* reports: a
* port attaches the proxy when it is created, which is after every layer has loaded, so the array
* it reads has to be the realm's own and still growing (`@@T-718`).
*/
#vocabulary: object[] = [];
public constructor(
config: {
server: {realm?: {logLevel: Parameters<ILog['logger']>[0]}};
browser: {realm?: {logLevel: Parameters<ILog['logger']>[0]}};
name: string;
pkg: {name: string; version: string};
},
{log, registry}: {log?: ILog; registry?: IRegistry},
platform: 'server' | 'browser',
) {
this.#config = config;
this.#registry = registry!;
this.#log = log!;
this.#logger = this.#log?.logger(config[platform]?.realm?.logLevel ?? 'info', {
name: config.name,
context: `${platform}`,
});
}
private _addModuleInternal(name: string | symbol, mod: IRegistry): void {
let module = this.#registry.modules.get(name);
if (!module) {
module = [];
this.#registry.modules.set(name, module);
}
module.push(mod);
}
public addModule(name: string | symbol, mod: IRegistry): void {
this.#logger?.debug?.(
{$meta: {mtid: 'event', method: 'module.add'}},
`${this.#config.name}.${String(name)}`,
);
this._addModuleInternal(name, mod);
}
public addLayer(layerName: string, layer: IRealm): void {
// this._addModuleInternal(this.#config.name, layer);
// The realm's vocabulary is one declaration for the whole realm, not one per folder: a realm
// that writes `lukaot/error.ts` beside its handlers declares names for every port it owns, and
// the port that answers them is `agent` — a different layer with a folder of its own. Each
// layer's result is pointed at this realm's *one* array, so a declaration loaded after a port
// was assembled is still in it when the port attaches, and a handler in any layer reads the
// same `signal` proxy (`@@T-718`).
const declared = (layer as {vocabulary?: object[]}).vocabulary;
if (declared?.length) this.#vocabulary.push(...declared);
(layer as {vocabulary?: object[]}).vocabulary = this.#vocabulary;
const source: string[] = [];
Object.entries(layer).forEach(([itemName, item]) => {
if (item.source) source.push(item.source);
const id = `${this.#config.name}.${itemName}`;
if (typeof item === 'object' && 'port' in item)
this.#registry.ports.set(id, item.port as unknown as IAdapterRegistry);
else if (typeof item === 'object' && 'methods' in item) {
const methods = this.#registry.methods.get(id);
if (methods) methods.push(...item.methods);
else this.#registry.methods.set(id, item.methods);
}
});
if (source.length === 1)
// this.#logger?.debug?.(`Layer ${this.#config.name}.${layerName} ${source[0]}`);
this.#logger?.debug?.(
{$meta: {mtid: 'event', method: 'layer.add'}},
`${this.#config.name}.${layerName} ${source[0]}`,
);
else if (!source.length) this.#logger?.debug?.(`Layer ${this.#config.name}.${layerName}`);
else
this.#logger?.debug?.(
{$meta: {mtid: 'event', method: 'layer.add'}},
`${this.#config.name}.${layerName} ${source}`,
);
}
}
|