@api-client/core 0.11.6 → 0.11.8
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/build/src/amf/definitions/Shapes.d.ts +1 -1
- package/build/src/amf/definitions/Shapes.js.map +1 -1
- package/build/src/browser.d.ts +2 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +2 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +2 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -0
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/DataAssociation.d.ts +10 -2
- package/build/src/modeling/DataAssociation.d.ts.map +1 -1
- package/build/src/modeling/DataAssociation.js +32 -2
- package/build/src/modeling/DataAssociation.js.map +1 -1
- package/build/src/modeling/DataEntity.d.ts +26 -1
- package/build/src/modeling/DataEntity.d.ts.map +1 -1
- package/build/src/modeling/DataEntity.js +73 -8
- package/build/src/modeling/DataEntity.js.map +1 -1
- package/build/src/modeling/DataModel.d.ts +10 -1
- package/build/src/modeling/DataModel.d.ts.map +1 -1
- package/build/src/modeling/DataModel.js +22 -2
- package/build/src/modeling/DataModel.js.map +1 -1
- package/build/src/modeling/DataNamespace.d.ts +60 -55
- package/build/src/modeling/DataNamespace.d.ts.map +1 -1
- package/build/src/modeling/DataNamespace.js +133 -116
- package/build/src/modeling/DataNamespace.js.map +1 -1
- package/build/src/modeling/DataProperty.d.ts +16 -3
- package/build/src/modeling/DataProperty.d.ts.map +1 -1
- package/build/src/modeling/DataProperty.js +28 -2
- package/build/src/modeling/DataProperty.js.map +1 -1
- package/build/src/modeling/ImpactAnalysis.d.ts +290 -0
- package/build/src/modeling/ImpactAnalysis.d.ts.map +1 -0
- package/build/src/modeling/ImpactAnalysis.js +437 -0
- package/build/src/modeling/ImpactAnalysis.js.map +1 -0
- package/build/src/modeling/types.d.ts +14 -0
- package/build/src/modeling/types.d.ts.map +1 -0
- package/build/src/modeling/types.js +2 -0
- package/build/src/modeling/types.js.map +1 -0
- package/data/models/example-generator-api.json +9 -9
- package/package.json +9 -19
- package/src/amf/definitions/Shapes.ts +1 -1
- package/src/modeling/DataAssociation.ts +36 -2
- package/src/modeling/DataEntity.ts +88 -12
- package/src/modeling/DataModel.ts +24 -2
- package/src/modeling/DataNamespace.ts +150 -137
- package/src/modeling/DataProperty.ts +32 -3
- package/src/modeling/ImpactAnalysis.ts +519 -0
- package/src/modeling/types.ts +13 -0
- package/tests/servers/ExpressServer.ts +1 -0
- package/tests/servers/express-routes/BaseApi.ts +1 -1
- package/tests/servers/express-routes/TestsApi.ts +1 -1
- package/tests/unit/modeling/data_association.spec.ts +73 -0
- package/tests/unit/modeling/data_entity.spec.ts +111 -1
- package/tests/unit/modeling/data_model.spec.ts +54 -0
- package/tests/unit/modeling/data_namespace.spec.ts +46 -1
- package/tests/unit/modeling/data_property.spec.ts +73 -0
- package/tests/unit/modeling/impact_analysis.spec.ts +373 -0
- package/tsconfig.browser.json +2 -1
|
@@ -3,6 +3,7 @@ import { DataEntity, IDataEntity } from './DataEntity.js';
|
|
|
3
3
|
import type { DataItemAdaptingOptions, DataNamespace } from './DataNamespace.js';
|
|
4
4
|
import { FileBreadcrumb } from '../models/store/File.js';
|
|
5
5
|
import { DataModelKind } from '../models/kinds.js';
|
|
6
|
+
import type { DataDomainRemoveOptions } from './types.js';
|
|
6
7
|
/**
|
|
7
8
|
* Data model creates a logical structure around data entities.
|
|
8
9
|
* It groups entities that represents a whole schema, like a Product data model
|
|
@@ -55,7 +56,7 @@ export declare class DataModel {
|
|
|
55
56
|
/**
|
|
56
57
|
* Removes self from the namespace with all entities.
|
|
57
58
|
*/
|
|
58
|
-
remove(): void;
|
|
59
|
+
remove(opts?: DataDomainRemoveOptions): void;
|
|
59
60
|
/**
|
|
60
61
|
* Adapts an entity to this data model.
|
|
61
62
|
* The entity must already be added to another data model within this namespace for it to be
|
|
@@ -84,5 +85,13 @@ export declare class DataModel {
|
|
|
84
85
|
* Creates breadcrumbs from this data model to the root namespace.
|
|
85
86
|
*/
|
|
86
87
|
breadcrumbs(): FileBreadcrumb[];
|
|
88
|
+
/**
|
|
89
|
+
* Checks whether the data model is a child of the given namespace.
|
|
90
|
+
* The relationship doesn't have to be direct, as long as the data model is in the hierarchy it will return true.
|
|
91
|
+
*
|
|
92
|
+
* @param key The key of the parent namespace to check.
|
|
93
|
+
* @returns True if this data model is a child of the given namespace.
|
|
94
|
+
*/
|
|
95
|
+
isChildOf(key: string): boolean;
|
|
87
96
|
}
|
|
88
97
|
//# sourceMappingURL=DataModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModel.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"DataModel.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAEzD;;;;;GAKG;AAC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GAAG,OAAO;CAahC"}
|
|
@@ -95,10 +95,10 @@ export class DataModel {
|
|
|
95
95
|
/**
|
|
96
96
|
* Removes self from the namespace with all entities.
|
|
97
97
|
*/
|
|
98
|
-
remove() {
|
|
98
|
+
remove(opts) {
|
|
99
99
|
const { key, entities, root } = this;
|
|
100
100
|
// remove children
|
|
101
|
-
entities.forEach((e) => e.remove());
|
|
101
|
+
entities.forEach((e) => e.remove(opts));
|
|
102
102
|
// remove self from the parent
|
|
103
103
|
const parent = this.getParentInstance();
|
|
104
104
|
if (parent) {
|
|
@@ -212,5 +212,25 @@ export class DataModel {
|
|
|
212
212
|
});
|
|
213
213
|
return result.reverse();
|
|
214
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Checks whether the data model is a child of the given namespace.
|
|
217
|
+
* The relationship doesn't have to be direct, as long as the data model is in the hierarchy it will return true.
|
|
218
|
+
*
|
|
219
|
+
* @param key The key of the parent namespace to check.
|
|
220
|
+
* @returns True if this data model is a child of the given namespace.
|
|
221
|
+
*/
|
|
222
|
+
isChildOf(key) {
|
|
223
|
+
if (this.key === key) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
const parent = this.getParentInstance();
|
|
227
|
+
if (!parent) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
if (parent.key === key) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return parent.isChildOf(key);
|
|
234
|
+
}
|
|
215
235
|
}
|
|
216
236
|
//# sourceMappingURL=DataModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAA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C,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IAC9F,CAAC;IAED;;OAEG;IACH,WAAW;QACT,MAAM,MAAM,GAAqB,EAAE,CAAA;QACnC,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,oBAAoB;YAC5C,IAAI,EAAE,aAAa;SACpB,CAAC,CAAA;QACF,IAAI,MAAM,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACrC,OAAO,MAAM,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC;gBACV,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;aAC9C,CAAC,CAAA;YACF,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,CAAA;QACrC,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;YAChD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;SACrB,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;CACF","sourcesContent":["import { IThing, Thing } from '../models/Thing.js'\nimport v4 from '../lib/uuid.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport type { DataItemAdaptingOptions, DataNamespace } from './DataNamespace.js'\nimport { FileBreadcrumb } from '../models/store/File.js'\nimport { DataModelKind } from '../models/kinds.js'\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport interface IDataModel {\n kind: typeof DataModelKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The data model description.\n */\n info: IThing\n /**\n * The list of keys of entities that this data model contain.\n */\n entities?: string[]\n}\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport class DataModel {\n kind = DataModelKind\n\n key = ''\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * The list of entities that this data model has.\n */\n entities: DataEntity[] = []\n\n static fromName(root: DataNamespace, name: string): DataModel {\n const entity = new DataModel(root)\n entity.info = Thing.fromName(name)\n return entity\n }\n\n /**\n * @param root the root namespace.\n * @param input The data model definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataModel\n ) {\n let init: IDataModel\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataModelKind,\n key: v4(),\n info: Thing.fromName('').toJSON(),\n entities: [],\n }\n }\n this.new(init)\n }\n\n new(init: IDataModel): void {\n if (!DataModel.isDataModel(init)) {\n throw new Error(`Not a data model.`)\n }\n const { info, key = v4(), kind = DataModelKind, entities } = init\n this.kind = kind\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n\n this.entities = []\n if (Array.isArray(entities)) {\n entities.forEach((key) => {\n const value = this._readEntity(key)\n if (value) {\n this.entities.push(value)\n }\n })\n }\n }\n\n static isDataModel(input: unknown): boolean {\n const typed = input as IDataModel\n if (!input || typed.kind !== DataModelKind) {\n return false\n }\n return true\n }\n\n toJSON(): IDataModel {\n const result: IDataModel = {\n kind: DataModelKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.entities) && this.entities.length) {\n result.entities = this.entities.map((i) => i.key)\n }\n return result\n }\n\n protected _readEntity(key: string): DataEntity | undefined {\n return this.root.definitions.entities.find((i) => i.key === key)\n }\n\n /**\n * Removes self from the namespace with all entities.\n */\n remove(): void {\n const { key, entities, root } = this\n // remove children\n entities.forEach((e) => e.remove())\n\n // remove self from the parent\n const parent = this.getParentInstance()\n if (parent) {\n const itemIndex = parent.items.findIndex((i) => i.key === key)\n if (itemIndex >= 0) {\n parent.items.splice(itemIndex, 1)\n }\n }\n // remove self from definitions\n const index = root.definitions.models.findIndex((i) => i.key === key)\n if (index >= 0) {\n root.definitions.models.splice(index, 1)\n }\n }\n\n /**\n * Adapts an entity to this data model.\n * The entity must already be added to another data model within this namespace for it to be\n * adapted to this data model.\n * This method is used to change the data model of an entity.\n * It will remove the entity from the previous data model and add it to this one.\n * @param entity The entity to adapt.\n */\n adaptEntity(entity: DataEntity, opts: DataItemAdaptingOptions = {}): void {\n if (opts.index !== undefined) {\n if (opts.index < 0) {\n throw new Error(`The index ${opts.index} cannot be below 0.`)\n }\n if (opts.index >= this.entities.length) {\n throw new Error(`The index ${opts.index} is not valid.`)\n }\n }\n if (entity.root !== this.root) {\n throw new Error(`The entity ${entity.key} is not in the same namespace as this data model.`)\n }\n const parent = entity.getParentInstance()\n if (!parent) {\n throw new Error(`The entity ${entity.key} has no parent.`)\n }\n if (parent.key === this.key) {\n throw new Error(`The entity ${entity.key} is already adapted by this data model.`)\n }\n // it has a parent (above check) so it has the index.\n const index = parent.entities.findIndex((i) => i.key === entity.key)\n parent.entities.splice(index, 1)\n if (opts.index !== undefined) {\n this.entities.splice(opts.index, 0, entity)\n } else {\n this.entities.push(entity)\n }\n }\n\n /**\n * Adds an entity to this data model.\n *\n * @param init The name of the entity to create, the instance of the entity or its schema\n * @returns A reference to the created entity.\n */\n addEntity(init: string | DataEntity | IDataEntity): DataEntity {\n let definition: DataEntity\n if (typeof init === 'string') {\n definition = DataEntity.fromName(this.root, init)\n } else if (init instanceof DataEntity) {\n definition = init\n } else {\n definition = new DataEntity(this.root, init)\n }\n this.root.definitions.entities.push(definition)\n this.entities.push(definition)\n return definition\n }\n\n /**\n * @deprecated Use the `getParentInstance()` method instead.\n */\n getParent(): DataNamespace | undefined {\n return this.getParentInstance()\n }\n\n /**\n * Returns the parent namespace where this data model exist.\n */\n getParentInstance(): DataNamespace | undefined {\n if (this.root.items.some((e) => e.key === this.key)) {\n return this.root\n }\n return this.root.definitions.namespaces.find((n) => n.items.some((e) => e.key === this.key))\n }\n\n /**\n * Creates breadcrumbs from this data model to the root namespace.\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.name || 'Unnamed data model',\n kind: DataModelKind,\n })\n let parent = this.getParentInstance()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.name || 'Unnamed namespace',\n })\n parent = parent.getParentInstance()\n }\n result.push({\n key: this.root.key,\n name: this.root.info.name || 'Unnamed namespace',\n kind: this.root.kind,\n })\n return result.reverse()\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../../src/modeling/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAyBlD;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IA0BX;IAzBT,IAAI,GAAG,aAAa,CAAA;IAEpB,GAAG,GAAG,EAAE,CAAA;IAER;;OAEG;IACH,IAAI,GAAU,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAEhC;;OAEG;IACH,QAAQ,GAAiB,EAAE,CAAA;IAE3B,MAAM,CAAC,QAAQ,CAAC,IAAmB,EAAE,IAAY;QAC/C,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAA;QAClC,MAAM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,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACrC,OAAO,MAAM,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC;gBACV,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;aAC9C,CAAC,CAAA;YACF,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,CAAA;QACrC,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;YAChD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;SACrB,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAW;QACnB,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACrB,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACvC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACvB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC;CACF","sourcesContent":["import { IThing, Thing } from '../models/Thing.js'\nimport v4 from '../lib/uuid.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport type { DataItemAdaptingOptions, DataNamespace } from './DataNamespace.js'\nimport { FileBreadcrumb } from '../models/store/File.js'\nimport { DataModelKind } from '../models/kinds.js'\nimport type { DataDomainRemoveOptions } from './types.js'\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport interface IDataModel {\n kind: typeof DataModelKind\n /**\n * The key of the namespace.\n */\n key: string\n /**\n * The data model description.\n */\n info: IThing\n /**\n * The list of keys of entities that this data model contain.\n */\n entities?: string[]\n}\n\n/**\n * Data model creates a logical structure around data entities.\n * It groups entities that represents a whole schema, like a Product data model\n * can have entities that describe: the product entity, price history entity,\n * product location, etc.\n */\nexport class DataModel {\n kind = DataModelKind\n\n key = ''\n\n /**\n * The description of the data namespace.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * The list of entities that this data model has.\n */\n entities: DataEntity[] = []\n\n static fromName(root: DataNamespace, name: string): DataModel {\n const entity = new DataModel(root)\n entity.info = Thing.fromName(name)\n return entity\n }\n\n /**\n * @param root the root namespace.\n * @param input The data model definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataModel\n ) {\n let init: IDataModel\n if (typeof input === 'string') {\n init = JSON.parse(input)\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataModelKind,\n key: v4(),\n info: Thing.fromName('').toJSON(),\n entities: [],\n }\n }\n this.new(init)\n }\n\n new(init: IDataModel): void {\n if (!DataModel.isDataModel(init)) {\n throw new Error(`Not a data model.`)\n }\n const { info, key = v4(), kind = DataModelKind, entities } = init\n this.kind = kind\n this.key = key\n if (info) {\n this.info = new Thing(info)\n } else {\n this.info = Thing.fromName('')\n }\n\n this.entities = []\n if (Array.isArray(entities)) {\n entities.forEach((key) => {\n const value = this._readEntity(key)\n if (value) {\n this.entities.push(value)\n }\n })\n }\n }\n\n static isDataModel(input: unknown): boolean {\n const typed = input as IDataModel\n if (!input || typed.kind !== DataModelKind) {\n return false\n }\n return true\n }\n\n toJSON(): IDataModel {\n const result: IDataModel = {\n kind: DataModelKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.entities) && this.entities.length) {\n result.entities = this.entities.map((i) => i.key)\n }\n return result\n }\n\n protected _readEntity(key: string): DataEntity | undefined {\n return this.root.definitions.entities.find((i) => i.key === key)\n }\n\n /**\n * Removes self from the namespace with all entities.\n */\n remove(opts?: DataDomainRemoveOptions): void {\n const { key, entities, root } = this\n // remove children\n entities.forEach((e) => e.remove(opts))\n\n // remove self from the parent\n const parent = this.getParentInstance()\n if (parent) {\n const itemIndex = parent.items.findIndex((i) => i.key === key)\n if (itemIndex >= 0) {\n parent.items.splice(itemIndex, 1)\n }\n }\n // remove self from definitions\n const index = root.definitions.models.findIndex((i) => i.key === key)\n if (index >= 0) {\n root.definitions.models.splice(index, 1)\n }\n }\n\n /**\n * Adapts an entity to this data model.\n * The entity must already be added to another data model within this namespace for it to be\n * adapted to this data model.\n * This method is used to change the data model of an entity.\n * It will remove the entity from the previous data model and add it to this one.\n * @param entity The entity to adapt.\n */\n adaptEntity(entity: DataEntity, opts: DataItemAdaptingOptions = {}): void {\n if (opts.index !== undefined) {\n if (opts.index < 0) {\n throw new Error(`The index ${opts.index} cannot be below 0.`)\n }\n if (opts.index >= this.entities.length) {\n throw new Error(`The index ${opts.index} is not valid.`)\n }\n }\n if (entity.root !== this.root) {\n throw new Error(`The entity ${entity.key} is not in the same namespace as this data model.`)\n }\n const parent = entity.getParentInstance()\n if (!parent) {\n throw new Error(`The entity ${entity.key} has no parent.`)\n }\n if (parent.key === this.key) {\n throw new Error(`The entity ${entity.key} is already adapted by this data model.`)\n }\n // it has a parent (above check) so it has the index.\n const index = parent.entities.findIndex((i) => i.key === entity.key)\n parent.entities.splice(index, 1)\n if (opts.index !== undefined) {\n this.entities.splice(opts.index, 0, entity)\n } else {\n this.entities.push(entity)\n }\n }\n\n /**\n * Adds an entity to this data model.\n *\n * @param init The name of the entity to create, the instance of the entity or its schema\n * @returns A reference to the created entity.\n */\n addEntity(init: string | DataEntity | IDataEntity): DataEntity {\n let definition: DataEntity\n if (typeof init === 'string') {\n definition = DataEntity.fromName(this.root, init)\n } else if (init instanceof DataEntity) {\n definition = init\n } else {\n definition = new DataEntity(this.root, init)\n }\n this.root.definitions.entities.push(definition)\n this.entities.push(definition)\n return definition\n }\n\n /**\n * @deprecated Use the `getParentInstance()` method instead.\n */\n getParent(): DataNamespace | undefined {\n return this.getParentInstance()\n }\n\n /**\n * Returns the parent namespace where this data model exist.\n */\n getParentInstance(): DataNamespace | undefined {\n if (this.root.items.some((e) => e.key === this.key)) {\n return this.root\n }\n return this.root.definitions.namespaces.find((n) => n.items.some((e) => e.key === this.key))\n }\n\n /**\n * Creates breadcrumbs from this data model to the root namespace.\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.name || 'Unnamed data model',\n kind: DataModelKind,\n })\n let parent = this.getParentInstance()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.name || 'Unnamed namespace',\n })\n parent = parent.getParentInstance()\n }\n result.push({\n key: this.root.key,\n name: this.root.info.name || 'Unnamed namespace',\n kind: this.root.kind,\n })\n return result.reverse()\n }\n\n /**\n * Checks whether the data model is a child of the given namespace.\n * The relationship doesn't have to be direct, as long as the data model is in the hierarchy it will return true.\n *\n * @param key The key of the parent namespace to check.\n * @returns True if this data model is a child of the given namespace.\n */\n isChildOf(key: string): boolean {\n if (this.key === key) {\n return false\n }\n const parent = this.getParentInstance()\n if (!parent) {\n return false\n }\n if (parent.key === key) {\n return true\n }\n return parent.isChildOf(key)\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { IDataEntity, DataEntity } from './DataEntity.js';
|
|
|
4
4
|
import { IDataModel, DataModel } from './DataModel.js';
|
|
5
5
|
import { IDataProperty, DataProperty } from './DataProperty.js';
|
|
6
6
|
import { DataNamespaceKind, DataModelKind } from '../models/kinds.js';
|
|
7
|
+
import type { DataDomainRemoveOptions } from './types.js';
|
|
7
8
|
type ItemKind = typeof DataNamespaceKind | typeof DataModelKind;
|
|
8
9
|
export interface DataItemAdaptingOptions {
|
|
9
10
|
/**
|
|
@@ -49,7 +50,10 @@ interface ForeignNamespace {
|
|
|
49
50
|
key: string;
|
|
50
51
|
version: string;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Data namespace is a logical description of the hierarchy in the data.
|
|
55
|
+
*/
|
|
56
|
+
export interface IDataNamespace {
|
|
53
57
|
kind: typeof DataNamespaceKind;
|
|
54
58
|
/**
|
|
55
59
|
* The key of the namespace.
|
|
@@ -63,11 +67,6 @@ interface IDataNamespaceParent {
|
|
|
63
67
|
* The data namespace description.
|
|
64
68
|
*/
|
|
65
69
|
info: IThing;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Data namespace is a logical description of the hierarchy in the data.
|
|
69
|
-
*/
|
|
70
|
-
export interface IDataNamespace extends IDataNamespaceParent {
|
|
71
70
|
/**
|
|
72
71
|
* The list of definitions used in the namespace.
|
|
73
72
|
*/
|
|
@@ -87,54 +86,6 @@ export interface IDataItem {
|
|
|
87
86
|
*/
|
|
88
87
|
key: string;
|
|
89
88
|
}
|
|
90
|
-
declare class DataNamespaceParent {
|
|
91
|
-
kind: string;
|
|
92
|
-
key: string;
|
|
93
|
-
/**
|
|
94
|
-
* The ordered list of items in this namespace.
|
|
95
|
-
*/
|
|
96
|
-
items: DataItem[];
|
|
97
|
-
/**
|
|
98
|
-
* The description of the data namespace.
|
|
99
|
-
*/
|
|
100
|
-
info: Thing;
|
|
101
|
-
/**
|
|
102
|
-
* When a namespace is a sub-namespace this is the reference to the
|
|
103
|
-
* root namespace with all definitions.
|
|
104
|
-
*/
|
|
105
|
-
root?: DataNamespace;
|
|
106
|
-
constructor(root?: DataNamespace);
|
|
107
|
-
/**
|
|
108
|
-
* @deprecated Use the `getParentInstance()` method instead.
|
|
109
|
-
*/
|
|
110
|
-
getParent(): DataNamespace | undefined;
|
|
111
|
-
/**
|
|
112
|
-
* @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
|
|
113
|
-
*/
|
|
114
|
-
getParentInstance(): DataNamespace | undefined;
|
|
115
|
-
/**
|
|
116
|
-
* Adds a data namespace to the structure.
|
|
117
|
-
* @param init The name of the namespace to add, namespace's schema, or instance.
|
|
118
|
-
*/
|
|
119
|
-
addNamespace(init: string | IDataNamespace | DataNamespace): DataNamespace;
|
|
120
|
-
/**
|
|
121
|
-
* Lists namespaces that are in this namespace items.
|
|
122
|
-
*/
|
|
123
|
-
listNamespaces(): DataNamespace[];
|
|
124
|
-
/**
|
|
125
|
-
* Lists namespaces that are in this namespace items.
|
|
126
|
-
*/
|
|
127
|
-
listDataModels(): DataModel[];
|
|
128
|
-
/**
|
|
129
|
-
* @returns The root of the namespaces tree. It might be the same object.
|
|
130
|
-
*/
|
|
131
|
-
getRoot(): DataNamespace;
|
|
132
|
-
/**
|
|
133
|
-
* Removes self from the parent namespace with all data models.
|
|
134
|
-
* This does noting for the root namespace.
|
|
135
|
-
*/
|
|
136
|
-
remove(): void;
|
|
137
|
-
}
|
|
138
89
|
export declare class DataItem implements IDataItem {
|
|
139
90
|
kind: ItemKind;
|
|
140
91
|
key: string;
|
|
@@ -157,7 +108,25 @@ export declare class DataItem implements IDataItem {
|
|
|
157
108
|
/**
|
|
158
109
|
* Data namespace is a logical description of the hierarchy in the data.
|
|
159
110
|
*/
|
|
160
|
-
export declare class DataNamespace
|
|
111
|
+
export declare class DataNamespace {
|
|
112
|
+
kind: string;
|
|
113
|
+
key: string;
|
|
114
|
+
/**
|
|
115
|
+
* The ordered list of items in this namespace.
|
|
116
|
+
*/
|
|
117
|
+
items: DataItem[];
|
|
118
|
+
/**
|
|
119
|
+
* The description of the data namespace.
|
|
120
|
+
*/
|
|
121
|
+
info: Thing;
|
|
122
|
+
/**
|
|
123
|
+
* When a namespace is a sub-namespace this is the reference to the
|
|
124
|
+
* root namespace with all definitions.
|
|
125
|
+
*/
|
|
126
|
+
root?: DataNamespace;
|
|
127
|
+
/**
|
|
128
|
+
* The list of definitions used in the namespace.
|
|
129
|
+
*/
|
|
161
130
|
definitions: DataDefinitions;
|
|
162
131
|
/**
|
|
163
132
|
* The list of foreign namespaces.
|
|
@@ -173,10 +142,38 @@ export declare class DataNamespace extends DataNamespaceParent {
|
|
|
173
142
|
* @param name The name to set.
|
|
174
143
|
*/
|
|
175
144
|
static fromName(name: string, root?: DataNamespace): DataNamespace;
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated
|
|
147
|
+
*/
|
|
176
148
|
static definitions(): DataDefinitions;
|
|
177
149
|
constructor(input?: string | IDataNamespace, root?: DataNamespace);
|
|
178
150
|
new(init: IDataNamespace): void;
|
|
179
151
|
toJSON(): IDataNamespace;
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
154
|
+
*/
|
|
155
|
+
getParent(): DataNamespace | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
|
|
158
|
+
*/
|
|
159
|
+
getParentInstance(): DataNamespace | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Lists namespaces that are in this namespace items.
|
|
162
|
+
*/
|
|
163
|
+
listNamespaces(): DataNamespace[];
|
|
164
|
+
/**
|
|
165
|
+
* Lists namespaces that are in this namespace items.
|
|
166
|
+
*/
|
|
167
|
+
listDataModels(): DataModel[];
|
|
168
|
+
/**
|
|
169
|
+
* @returns The root of the namespaces tree. It might be the same object.
|
|
170
|
+
*/
|
|
171
|
+
getRoot(): DataNamespace;
|
|
172
|
+
/**
|
|
173
|
+
* Removes self from the parent namespace with all data models.
|
|
174
|
+
* This does noting for the root namespace.
|
|
175
|
+
*/
|
|
176
|
+
remove(opts?: DataDomainRemoveOptions): void;
|
|
180
177
|
/**
|
|
181
178
|
* Checks if this is the root namespace.
|
|
182
179
|
* @returns True if this is the root namespace.
|
|
@@ -303,6 +300,14 @@ export declare class DataNamespace extends DataNamespaceParent {
|
|
|
303
300
|
addForeign(ns: DataNamespace): void;
|
|
304
301
|
removeForeign(ns: DataNamespace): void;
|
|
305
302
|
hasForeignNamespace(key: string): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Checks whether the namespace is a child of the given namespace.
|
|
305
|
+
* The relationship doesn't have to be direct, as long as the namespace is in the hierarchy it will return true.
|
|
306
|
+
*
|
|
307
|
+
* @param key The key of the parent namespace to check.
|
|
308
|
+
* @returns True if this namespace is a child of the given namespace.
|
|
309
|
+
*/
|
|
310
|
+
isChildOf(key: string): boolean;
|
|
306
311
|
}
|
|
307
312
|
export {};
|
|
308
313
|
//# sourceMappingURL=DataNamespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataNamespace.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataNamespace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"DataNamespace.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataNamespace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACzD,O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Property.js';
|
|
7
7
|
import { DataNamespaceKind, DataModelKind } from '../models/kinds.js';
|
|
8
8
|
import v4 from '../lib/uuid.js';
|
|
9
|
-
class DataNamespaceParent {
|
|
10
|
-
kind = DataNamespaceKind;
|
|
11
|
-
key = '';
|
|
12
|
-
/**
|
|
13
|
-
* The ordered list of items in this namespace.
|
|
14
|
-
*/
|
|
15
|
-
items = [];
|
|
16
|
-
/**
|
|
17
|
-
* The description of the data namespace.
|
|
18
|
-
*/
|
|
19
|
-
info = Thing.fromName('');
|
|
20
|
-
/**
|
|
21
|
-
* When a namespace is a sub-namespace this is the reference to the
|
|
22
|
-
* root namespace with all definitions.
|
|
23
|
-
*/
|
|
24
|
-
root;
|
|
25
|
-
constructor(root) {
|
|
26
|
-
this.root = root;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated Use the `getParentInstance()` method instead.
|
|
30
|
-
*/
|
|
31
|
-
getParent() {
|
|
32
|
-
return this.getParentInstance();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
|
|
36
|
-
*/
|
|
37
|
-
getParentInstance() {
|
|
38
|
-
const { root, key } = this;
|
|
39
|
-
if (root) {
|
|
40
|
-
const result = root.findParent(key);
|
|
41
|
-
if (result === this.root) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
// we are the root namespace.
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Adds a data namespace to the structure.
|
|
51
|
-
* @param init The name of the namespace to add, namespace's schema, or instance.
|
|
52
|
-
*/
|
|
53
|
-
addNamespace(init) {
|
|
54
|
-
return this.root.addNamespace(init, this.key);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Lists namespaces that are in this namespace items.
|
|
58
|
-
*/
|
|
59
|
-
listNamespaces() {
|
|
60
|
-
const result = [];
|
|
61
|
-
const { items } = this;
|
|
62
|
-
const root = this.getRoot();
|
|
63
|
-
const { namespaces } = root.definitions;
|
|
64
|
-
items.forEach((i) => {
|
|
65
|
-
if (i.kind !== DataNamespaceKind) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const def = namespaces.find((j) => j.key === i.key);
|
|
69
|
-
if (def) {
|
|
70
|
-
result.push(def);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Lists namespaces that are in this namespace items.
|
|
77
|
-
*/
|
|
78
|
-
listDataModels() {
|
|
79
|
-
const result = [];
|
|
80
|
-
const { items } = this;
|
|
81
|
-
const root = this.getRoot();
|
|
82
|
-
const { models } = root.definitions;
|
|
83
|
-
items.forEach((i) => {
|
|
84
|
-
if (i.kind !== DataModelKind) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const def = models.find((j) => j.key === i.key);
|
|
88
|
-
if (def) {
|
|
89
|
-
result.push(def);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @returns The root of the namespaces tree. It might be the same object.
|
|
96
|
-
*/
|
|
97
|
-
getRoot() {
|
|
98
|
-
if (this.root) {
|
|
99
|
-
return this.root;
|
|
100
|
-
}
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Removes self from the parent namespace with all data models.
|
|
105
|
-
* This does noting for the root namespace.
|
|
106
|
-
*/
|
|
107
|
-
remove() {
|
|
108
|
-
const { root } = this;
|
|
109
|
-
if (!root) {
|
|
110
|
-
throw new Error(`Unable to remove the root namespace this way.`);
|
|
111
|
-
}
|
|
112
|
-
const models = this.listDataModels();
|
|
113
|
-
const children = this.listNamespaces();
|
|
114
|
-
models.forEach((m) => m.remove());
|
|
115
|
-
children.forEach((c) => c.remove());
|
|
116
|
-
const index = root.definitions.namespaces.findIndex((i) => i.key === this.key);
|
|
117
|
-
if (index >= 0) {
|
|
118
|
-
root.definitions.namespaces.splice(index, 1);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
9
|
export class DataItem {
|
|
123
10
|
kind = DataModelKind;
|
|
124
11
|
key = '';
|
|
@@ -194,7 +81,25 @@ export class DataItem {
|
|
|
194
81
|
/**
|
|
195
82
|
* Data namespace is a logical description of the hierarchy in the data.
|
|
196
83
|
*/
|
|
197
|
-
export class DataNamespace
|
|
84
|
+
export class DataNamespace {
|
|
85
|
+
kind = DataNamespaceKind;
|
|
86
|
+
key = '';
|
|
87
|
+
/**
|
|
88
|
+
* The ordered list of items in this namespace.
|
|
89
|
+
*/
|
|
90
|
+
items = [];
|
|
91
|
+
/**
|
|
92
|
+
* The description of the data namespace.
|
|
93
|
+
*/
|
|
94
|
+
info = Thing.fromName('');
|
|
95
|
+
/**
|
|
96
|
+
* When a namespace is a sub-namespace this is the reference to the
|
|
97
|
+
* root namespace with all definitions.
|
|
98
|
+
*/
|
|
99
|
+
root;
|
|
100
|
+
/**
|
|
101
|
+
* The list of definitions used in the namespace.
|
|
102
|
+
*/
|
|
198
103
|
definitions;
|
|
199
104
|
/**
|
|
200
105
|
* The list of foreign namespaces.
|
|
@@ -215,6 +120,9 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
215
120
|
ns.info = info;
|
|
216
121
|
return ns;
|
|
217
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated
|
|
125
|
+
*/
|
|
218
126
|
static definitions() {
|
|
219
127
|
return {
|
|
220
128
|
models: [],
|
|
@@ -226,8 +134,15 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
226
134
|
};
|
|
227
135
|
}
|
|
228
136
|
constructor(input, root) {
|
|
229
|
-
|
|
230
|
-
this.definitions =
|
|
137
|
+
this.root = root;
|
|
138
|
+
this.definitions = {
|
|
139
|
+
models: [],
|
|
140
|
+
associations: [],
|
|
141
|
+
entities: [],
|
|
142
|
+
properties: [],
|
|
143
|
+
namespaces: [],
|
|
144
|
+
tags: [],
|
|
145
|
+
};
|
|
231
146
|
let init;
|
|
232
147
|
if (typeof input === 'string') {
|
|
233
148
|
init = JSON.parse(input);
|
|
@@ -335,6 +250,88 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
335
250
|
}
|
|
336
251
|
return result;
|
|
337
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
255
|
+
*/
|
|
256
|
+
getParent() {
|
|
257
|
+
return this.getParentInstance();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
|
|
261
|
+
*/
|
|
262
|
+
getParentInstance() {
|
|
263
|
+
const { root, key } = this;
|
|
264
|
+
if (root) {
|
|
265
|
+
return root.findParent(key);
|
|
266
|
+
}
|
|
267
|
+
// we are the root namespace.
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Lists namespaces that are in this namespace items.
|
|
272
|
+
*/
|
|
273
|
+
listNamespaces() {
|
|
274
|
+
const result = [];
|
|
275
|
+
const { items } = this;
|
|
276
|
+
const root = this.getRoot();
|
|
277
|
+
const { namespaces } = root.definitions;
|
|
278
|
+
items.forEach((i) => {
|
|
279
|
+
if (i.kind !== DataNamespaceKind) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const def = namespaces.find((j) => j.key === i.key);
|
|
283
|
+
if (def) {
|
|
284
|
+
result.push(def);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Lists namespaces that are in this namespace items.
|
|
291
|
+
*/
|
|
292
|
+
listDataModels() {
|
|
293
|
+
const result = [];
|
|
294
|
+
const { items } = this;
|
|
295
|
+
const root = this.getRoot();
|
|
296
|
+
const { models } = root.definitions;
|
|
297
|
+
items.forEach((i) => {
|
|
298
|
+
if (i.kind !== DataModelKind) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const def = models.find((j) => j.key === i.key);
|
|
302
|
+
if (def) {
|
|
303
|
+
result.push(def);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @returns The root of the namespaces tree. It might be the same object.
|
|
310
|
+
*/
|
|
311
|
+
getRoot() {
|
|
312
|
+
if (this.root) {
|
|
313
|
+
return this.root;
|
|
314
|
+
}
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Removes self from the parent namespace with all data models.
|
|
319
|
+
* This does noting for the root namespace.
|
|
320
|
+
*/
|
|
321
|
+
remove(opts) {
|
|
322
|
+
const { root } = this;
|
|
323
|
+
if (!root) {
|
|
324
|
+
throw new Error(`Unable to remove the root namespace this way.`);
|
|
325
|
+
}
|
|
326
|
+
const models = this.listDataModels();
|
|
327
|
+
const children = this.listNamespaces();
|
|
328
|
+
models.forEach((m) => m.remove(opts));
|
|
329
|
+
children.forEach((c) => c.remove(opts));
|
|
330
|
+
const index = root.definitions.namespaces.findIndex((i) => i.key === this.key);
|
|
331
|
+
if (index >= 0) {
|
|
332
|
+
root.definitions.namespaces.splice(index, 1);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
338
335
|
/**
|
|
339
336
|
* Checks if this is the root namespace.
|
|
340
337
|
* @returns True if this is the root namespace.
|
|
@@ -731,5 +728,25 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
731
728
|
hasForeignNamespace(key) {
|
|
732
729
|
return this.foreign.some((i) => i.key === key);
|
|
733
730
|
}
|
|
731
|
+
/**
|
|
732
|
+
* Checks whether the namespace is a child of the given namespace.
|
|
733
|
+
* The relationship doesn't have to be direct, as long as the namespace is in the hierarchy it will return true.
|
|
734
|
+
*
|
|
735
|
+
* @param key The key of the parent namespace to check.
|
|
736
|
+
* @returns True if this namespace is a child of the given namespace.
|
|
737
|
+
*/
|
|
738
|
+
isChildOf(key) {
|
|
739
|
+
if (this.key === key) {
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
const parent = this.getParentInstance();
|
|
743
|
+
if (!parent) {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
if (parent.key === key) {
|
|
747
|
+
return true;
|
|
748
|
+
}
|
|
749
|
+
return parent.isChildOf(key);
|
|
750
|
+
}
|
|
734
751
|
}
|
|
735
752
|
//# sourceMappingURL=DataNamespace.js.map
|