@kubun/protocol 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/models/graph.d.ts +1 -0
- package/lib/models/graph.d.ts.map +1 -1
- package/lib/models/graph.js +17 -1
- package/package.json +2 -2
package/lib/models/graph.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class GraphModel {
|
|
|
18
18
|
constructor(params: GraphModelParams);
|
|
19
19
|
get aliases(): Record<string, string>;
|
|
20
20
|
get record(): DocumentModelsRecord;
|
|
21
|
+
getAlias(modelID: string): string | null;
|
|
21
22
|
getModel(aliasOrID: string): DocumentModel | null;
|
|
22
23
|
toJSON(): GraphModelJSON;
|
|
23
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/models/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,qBAAa,UAAU;;IACrB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,UAAU;gBAY/C,MAAM,EAAE,gBAAgB;
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/models/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,qBAAa,UAAU;;IACrB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,UAAU;gBAY/C,MAAM,EAAE,gBAAgB;IAoBpC,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEpC;IAED,IAAI,MAAM,IAAI,oBAAoB,CAEjC;IAED,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IASxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAKjD,MAAM,IAAI,cAAc;CAGzB"}
|
package/lib/models/graph.js
CHANGED
|
@@ -14,7 +14,15 @@ export class GraphModel {
|
|
|
14
14
|
#aliases;
|
|
15
15
|
#record;
|
|
16
16
|
constructor(params){
|
|
17
|
-
|
|
17
|
+
// If no aliases are provided, fallback to using the model names
|
|
18
|
+
this.#aliases = params.aliases ?? Object.entries(params.record).reduce((acc, [id, model])=>{
|
|
19
|
+
if (acc[model.name] == null) {
|
|
20
|
+
acc[model.name] = id;
|
|
21
|
+
} else {
|
|
22
|
+
console.warn(`Duplicate model name ${model.name} in GraphModel record, ignoring model ID ${id} in aliases`);
|
|
23
|
+
}
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
18
26
|
this.#record = params.record;
|
|
19
27
|
}
|
|
20
28
|
get aliases() {
|
|
@@ -23,6 +31,14 @@ export class GraphModel {
|
|
|
23
31
|
get record() {
|
|
24
32
|
return this.#record;
|
|
25
33
|
}
|
|
34
|
+
getAlias(modelID) {
|
|
35
|
+
for (const [alias, id] of Object.entries(this.#aliases)){
|
|
36
|
+
if (id === modelID) {
|
|
37
|
+
return alias;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
26
42
|
getModel(aliasOrID) {
|
|
27
43
|
const id = this.#aliases[aliasOrID] ?? aliasOrID;
|
|
28
44
|
return this.#record[id] ?? null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/protocol",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
32
32
|
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
33
33
|
"test:types": "tsc --noEmit",
|
|
34
|
-
"test:unit": "
|
|
34
|
+
"test:unit": "vitest run",
|
|
35
35
|
"test": "pnpm run test:types && pnpm run test:unit"
|
|
36
36
|
}
|
|
37
37
|
}
|