@api-client/core 0.18.16 → 0.18.18
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/{modeling → decorators}/observed.d.ts +3 -3
- package/build/src/decorators/observed.d.ts.map +1 -0
- package/build/src/{modeling → decorators}/observed.js +4 -4
- package/build/src/decorators/observed.js.map +1 -0
- package/build/src/modeling/ApiModel.js +1 -1
- package/build/src/modeling/ApiModel.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +7 -2
- package/build/src/modeling/DataDomain.d.ts.map +1 -1
- package/build/src/modeling/DataDomain.js +15 -2
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +7 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +44 -1
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +6 -0
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +21 -1
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainModel.js +1 -1
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainNamespace.js +1 -1
- package/build/src/modeling/DomainNamespace.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +5 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +38 -1
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/DomainSerialization.d.ts +6 -3
- package/build/src/modeling/DomainSerialization.d.ts.map +1 -1
- package/build/src/modeling/DomainSerialization.js +374 -52
- package/build/src/modeling/DomainSerialization.js.map +1 -1
- package/build/src/modeling/types.d.ts +69 -2
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/Thing.js +1 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +10 -10
- package/package.json +2 -1
- package/src/{modeling → decorators}/observed.ts +5 -5
- package/src/modeling/ApiModel.ts +1 -1
- package/src/modeling/DataDomain.ts +24 -3
- package/src/modeling/DomainAssociation.ts +51 -1
- package/src/modeling/DomainEntity.ts +24 -1
- package/src/modeling/DomainModel.ts +1 -1
- package/src/modeling/DomainNamespace.ts +1 -1
- package/src/modeling/DomainProperty.ts +43 -1
- package/src/modeling/DomainSerialization.ts +440 -56
- package/src/modeling/types.ts +73 -2
- package/src/models/Thing.ts +1 -1
- package/tests/unit/decorators/observed.spec.ts +527 -0
- package/tests/unit/modeling/data_domain_serialization.spec.ts +508 -0
- package/tests/unit/modeling/domain_asociation.spec.ts +376 -0
- package/tests/unit/modeling/domain_entity.spec.ts +147 -0
- package/tests/unit/modeling/domain_property.spec.ts +273 -0
- package/build/src/modeling/observed.d.ts.map +0 -1
- package/build/src/modeling/observed.js.map +0 -1
|
@@ -3,7 +3,7 @@ import { DomainPropertyKind } from '../models/kinds.js';
|
|
|
3
3
|
import { DomainElement } from './DomainElement.js';
|
|
4
4
|
import { nanoid } from '../nanoid.js';
|
|
5
5
|
import { Thing } from '../models/Thing.js';
|
|
6
|
-
import { observed, retargetChange, toRaw } from '
|
|
6
|
+
import { observed, retargetChange, toRaw } from '../decorators/observed.js';
|
|
7
7
|
import { BinaryFormats, DomainPropertyAttributes, DomainPropertyList, DomainPropertyTypes, NumberFormats, } from './DataFormat.js';
|
|
8
8
|
import { ShapeGenerator } from './amf/ShapeGenerator.js';
|
|
9
9
|
import { DataSemantics, isPropertySemantic } from './Semantics.js';
|
|
@@ -620,6 +620,43 @@ let DomainProperty = (() => {
|
|
|
620
620
|
hasSemantic(semanticId) {
|
|
621
621
|
return this.semantics.some((s) => s.id === semanticId);
|
|
622
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Creates a duplicate of this domain property on the parent entity.
|
|
625
|
+
* It places the duplicate on the parent entity right after the original property.
|
|
626
|
+
*/
|
|
627
|
+
duplicate() {
|
|
628
|
+
const parent = this.getParentInstance();
|
|
629
|
+
if (!parent) {
|
|
630
|
+
throw new Error(`Cannot duplicate property ${this.key} as it has no parent entity.`);
|
|
631
|
+
}
|
|
632
|
+
const originalIndex = parent.fields.findIndex((f) => f.key === this.key);
|
|
633
|
+
if (originalIndex === -1) {
|
|
634
|
+
throw new Error(`Cannot duplicate property ${this.key} as it does not exist on the parent entity fields list.`);
|
|
635
|
+
}
|
|
636
|
+
const baseName = this.info.name || 'field';
|
|
637
|
+
const newName = parent.generateUniqueName(baseName);
|
|
638
|
+
// Making a copy and restoring it through the `addProperty()` method
|
|
639
|
+
// scales better than copying it manually.
|
|
640
|
+
const copy = this.toJSON();
|
|
641
|
+
// Delete properties that should not be copied
|
|
642
|
+
delete copy.key;
|
|
643
|
+
delete copy.primary; // Don't duplicate the primary key
|
|
644
|
+
// Set the new name for the duplicated property
|
|
645
|
+
if (copy.info) {
|
|
646
|
+
copy.info.name = newName;
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
copy.info = { name: newName };
|
|
650
|
+
}
|
|
651
|
+
const result = parent.addProperty(copy);
|
|
652
|
+
// Move the duplicate to be right after the original
|
|
653
|
+
const fromIndex = parent.fields.length - 1;
|
|
654
|
+
const duplicateField = parent.fields[fromIndex];
|
|
655
|
+
parent.fields.splice(fromIndex, 1);
|
|
656
|
+
parent.fields.splice(originalIndex + 1, 0, duplicateField);
|
|
657
|
+
this.domain.notifyChange();
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
623
660
|
};
|
|
624
661
|
})();
|
|
625
662
|
export { DomainProperty };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainProperty.js","sourceRoot":"","sources":["../../../src/modeling/DomainProperty.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAo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AAY,EAAE,CAAA;QAC5B,CAAC;QAED;;;WAGG;QACH,cAAc,CAAC,UAAwB;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;YAClE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBAC/B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;QAED;;;;WAIG;QACH,WAAW,CAAC,UAAwB;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;QACxD,CAAC;;;SAjeU,cAAc","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from './observed.js'\nimport {\n type BinaryFormat,\n BinaryFormats,\n type DomainPropertyAttribute,\n DomainPropertyAttributes,\n type DomainPropertyFormat,\n DomainPropertyList,\n type DomainPropertyType,\n DomainPropertyTypes,\n type NumberFormat,\n NumberFormats,\n} from './DataFormat.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport type { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'\nimport type { ModelValidationOptions } from '../models/types.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport type { PropertySchema } from './types.js'\nimport { DataSemantics, isPropertySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\nimport { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js'\nimport type { IShapeRenderOptions } from '../amf/shape/ShapeBase.js'\n\nexport interface DomainPropertySchema extends DomainElementSchema {\n kind: typeof DomainPropertyKind\n /**\n * The domain property description.\n */\n info: IThing\n /**\n * Wether the data property is required.\n */\n required?: boolean\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n /**\n * The semantics applied to this property.\n * This is a list of applied semantics that can be used to\n * describe the property in more detail.\n */\n semantics?: AppliedDataSemantic[]\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers, but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DomainPropertyType\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: PropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: PropertyBinding[]\n}\n\n/**\n * Represents a property within a data domain entity.\n *\n * A `DomainProperty` defines a single data element within a\n * `DomainEntity`. It specifies the data type, constraints,\n * and other metadata for a specific piece of information.\n *\n * **Key Features:**\n *\n * - **Data Type:** Defines the type of data the property\n * holds (e.g., string, number, boolean, date).\n * - **Constraints:** Supports defining constraints such as\n * minimum/maximum values, enum values, and default values.\n * - **Bindings:** Allows defining how the property is\n * represented in different formats (e.g., web APIs,\n * protocol buffers).\n * - **Metadata:** Supports metadata such as tags, semantics,\n * read-only/write-only status, and deprecation.\n * - **Schema:** Allows defining a general schema for the\n * property, which is propagated to all bindings.\n *\n * **Usage:**\n *\n * Use the `DomainEntity.addProperty` method to add a new property to an\n * entity. The property can be created using the constructor, but it\n * won't be added to the graph until you call the `addProperty` method.\n *\n * **Example:**\n *\n * ```typescript\n * const entity = domainModel.addEntity({ key: 'user' });\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * schema: {\n * minimum: 3,\n * maximum: 50,\n * },\n * });\n * ```\n */\nexport class DomainProperty extends DomainElement {\n override kind: typeof DomainPropertyKind\n\n /**\n * The description of the domain property.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Wether the data property is required.\n */\n @observed() accessor required: boolean | undefined\n\n /**\n * Whether the data property allows multiple items.\n */\n @observed() accessor multiple: boolean | undefined\n\n /**\n * Whether this property describes a primary key of the entity.\n */\n @observed() accessor primary: boolean | undefined\n\n /**\n * Whether this property describes an indexed property of the entity.\n */\n @observed() accessor index: boolean | undefined\n\n /**\n * Whether the property is read only in the schema.\n */\n @observed() accessor readOnly: boolean | undefined\n\n /**\n * Whether the property is write only in the schema.\n */\n @observed() accessor writeOnly: boolean | undefined\n\n /**\n * Whether this property is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Optional general purpose tags for the UI.\n *\n * Note to implementations, use the `addTag()` method as it propagates the \"tag\" value in the namespace.\n * Also, the tags property is excluded from the observer properties.\n * Changes to this property will not notify the observers.\n */\n @observed({ deep: true }) accessor tags: string[] = []\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n @observed() accessor type: DomainPropertyType = 'string'\n\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n @observed({ deep: true }) accessor schema: PropertySchema | undefined\n\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n @observed({ deep: true }) accessor bindings: PropertyBinding[] = []\n\n /**\n * Creates a full data model schema with defaults.\n *\n * @param input The partial data model schema.\n * @returns The data model schema.\n */\n static createSchema(input: Partial<DomainPropertySchema> = {}): DomainPropertySchema {\n const {\n key = nanoid(),\n multiple,\n required,\n type = DomainPropertyList.string,\n index,\n primary,\n readOnly,\n writeOnly,\n tags,\n semantics,\n deprecated,\n schema,\n bindings,\n } = input\n if (typeof type === 'string') {\n if (!DomainPropertyTypes.includes(type as DomainPropertyType)) {\n throw new Error(`Invalid data property type ${type}`)\n }\n }\n const info = Thing.fromJSON(input.info, { name: 'new_property' }).toJSON()\n const result: DomainPropertySchema = {\n kind: DomainPropertyKind,\n key,\n info,\n type,\n }\n if (typeof multiple === 'boolean') {\n result.multiple = multiple\n }\n if (typeof required === 'boolean') {\n result.required = required\n }\n if (typeof index === 'boolean') {\n result.index = index\n }\n if (typeof primary === 'boolean') {\n result.primary = primary\n }\n if (typeof readOnly === 'boolean') {\n result.readOnly = readOnly\n }\n if (typeof writeOnly === 'boolean') {\n result.writeOnly = writeOnly\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (schema) {\n result.schema = structuredClone(schema)\n }\n if (Array.isArray(bindings)) {\n result.bindings = bindings.map((i) => structuredClone(i))\n } else {\n result.bindings = []\n }\n return result\n }\n\n /**\n * The key of the parent entity.\n */\n protected parent: string\n\n /**\n * Creates a new domain property instance.\n * It does not add it to the graph.\n * You need to call the `addProperty` method of the graph or a data model to add it.\n *\n * Domain objects constructors shouldn't be used directly. Use methods\n * provided on the DataDomain class to create new objects.\n *\n * @param root A reference to the root DataDomain instance.\n * @param parent The key of the parent entity.\n * @param input The partial domain property schema.\n * @returns Created domain property instance.\n */\n constructor(root: DataDomain, parent: string, input: Partial<DomainPropertySchema> = {}) {\n const init = DomainProperty.createSchema(input)\n super(root, init.key)\n this.parent = parent\n this.kind = DomainPropertyKind\n this.info = new Thing(init.info)\n this.type = init.type\n\n if (typeof init.multiple === 'boolean') {\n this.multiple = init.multiple\n } else {\n this.multiple = undefined\n }\n if (typeof init.required === 'boolean') {\n this.required = init.required\n } else {\n this.required = undefined\n }\n if (typeof init.index === 'boolean') {\n this.index = init.index\n } else {\n this.index = undefined\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n } else {\n this.deprecated = undefined\n }\n if (typeof init.primary === 'boolean') {\n this.primary = init.primary\n } else {\n this.primary = undefined\n }\n if (typeof init.readOnly === 'boolean') {\n this.readOnly = init.readOnly\n } else {\n this.readOnly = undefined\n }\n if (typeof init.writeOnly === 'boolean') {\n this.writeOnly = init.writeOnly\n } else {\n this.writeOnly = undefined\n }\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = [...init.semantics]\n } else {\n this.semantics = []\n }\n if (init.schema) {\n this.schema = structuredClone(init.schema)\n } else {\n this.schema = undefined\n }\n if (Array.isArray(init.bindings)) {\n this.bindings = init.bindings.map((i) => structuredClone(i))\n } else {\n this.bindings = []\n }\n }\n\n /**\n * Checks whether the input is a valid definition of a domain property.\n *\n * @param input The input to validate.\n * @param options Validation options.\n * @returns true when the passed input is a valid definition of a domain property.\n */\n static validate(input: unknown, options: ModelValidationOptions = {}): boolean {\n if (!input || (typeof input !== 'object' && input !== null)) {\n return false\n }\n const typed = input as DomainPropertySchema\n if (options.strict && typed.kind !== DomainPropertyKind) {\n return false\n }\n return true\n }\n\n toJSON(): DomainPropertySchema {\n const result: DomainPropertySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n type: this.type || DomainPropertyList.string,\n }\n if (typeof this.index === 'boolean') {\n result.index = this.index\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n if (typeof this.primary === 'boolean') {\n result.primary = this.primary\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (typeof this.readOnly === 'boolean') {\n result.readOnly = this.readOnly\n }\n if (typeof this.writeOnly === 'boolean') {\n result.writeOnly = this.writeOnly\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...this.tags]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (this.schema) {\n result.schema = structuredClone(toRaw(this, this.schema))\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))\n }\n return result\n }\n\n /**\n * Removes this property from the parent entity.\n * It calls the `removeProperty()` method of the parent entity.\n */\n remove(): void {\n const parent = this.getParentInstance()\n parent?.removeProperty(this.key)\n }\n\n /**\n * Returns a parent data entity where this data property exist.\n */\n getParentInstance(): DomainEntity | undefined {\n return this.root.graph.node(this.parent) as DomainEntity | undefined\n }\n\n /**\n * Checks whether the passed value is one of the supported data types.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data types.\n */\n static isValidType(value: unknown): value is DomainPropertyType {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyTypes.includes(value as DomainPropertyType)\n }\n\n /**\n * Checks whether the passed value is one of the supported data property attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data property attributes.\n */\n static isValidAttribute(value: unknown): value is DomainPropertyAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyAttributes.includes(value as DomainPropertyAttribute)\n }\n\n /**\n * Checks whether the passed value of one of the supported `format` values.\n *\n * @param value The value to test\n * @returns `true` when the value is one of the supported `format` values.\n */\n static isValidFormat(value: unknown): value is DomainPropertyFormat {\n if (value === undefined) {\n // It is the valid value.\n return true\n }\n if (typeof value !== 'string') {\n return false\n }\n if (NumberFormats.includes(value as NumberFormat)) {\n return true\n }\n if (BinaryFormats.includes(value as BinaryFormat)) {\n return true\n }\n return false\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): PropertySchema {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): PropertyWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as PropertyBinding\n this.bindings.push(object)\n }\n return object.schema as PropertyWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was created.\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n */\n readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as PropertyBinding\n return item?.schema || undefined\n }\n\n /**\n * Creates a Property Shape of AMF.\n *\n * The property itself is auto-generated. If the `schema` is\n * defined then it is used as the `range` of the property.\n * Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this\n * synchronizes changed data properties with the shape\n * definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new ShapeGenerator()\n return serializer.property(this)\n }\n\n /**\n * Generates an example value for this property based on its schema and type.\n *\n * This method converts the property to an AMF shape and then generates\n * an example value using the ApiSchemaGenerator. The generated example\n * respects the property's type, constraints, and any defined schema.\n *\n * @param mime The mime type of the example (e.g., 'application/json', 'application/xml').\n * @param opts Optional configuration for example generation.\n * @returns The generated example value.\n * @example\n * ```typescript\n * const example = property.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n // TODO: add support for semantic extensions and generate example values based on them.\n const shape = this.toApiShape()\n if (!shape.range) {\n return undefined\n }\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: opts.renderExamples ?? true,\n renderMocked: opts.renderMocked ?? true,\n renderOptional: opts.renderOptional ?? true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Adds or updates a semantic to the property.\n * @param semantic The semantic to add to the property.\n * @throws Error if the semantic is not an property semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isPropertySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected a property semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the property.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the property has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DomainProperty.js","sourceRoot":"","sources":["../../../src/modeling/DomainProperty.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EAEL,aAAa,EAEb,wBAAwB,EAExB,kBAAkB,EAElB,mBAAmB,EAEnB,aAAa,GAC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,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;YAC/B,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YAEvC,oDAAoD;YACpD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;YAC1C,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAC/C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;YAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAA;YAE1D,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC1B,OAAO,MAAM,CAAA;QACf,CAAC;;;SA3gBU,cAAc","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from '../decorators/observed.js'\nimport {\n type BinaryFormat,\n BinaryFormats,\n type DomainPropertyAttribute,\n DomainPropertyAttributes,\n type DomainPropertyFormat,\n DomainPropertyList,\n type DomainPropertyType,\n DomainPropertyTypes,\n type NumberFormat,\n NumberFormats,\n} from './DataFormat.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport type { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'\nimport type { ModelValidationOptions } from '../models/types.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport type { PropertySchema } from './types.js'\nimport { DataSemantics, isPropertySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\nimport { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js'\nimport type { IShapeRenderOptions } from '../amf/shape/ShapeBase.js'\n\nexport interface DomainPropertySchema extends DomainElementSchema {\n kind: typeof DomainPropertyKind\n /**\n * The domain property description.\n */\n info: IThing\n /**\n * Wether the data property is required.\n */\n required?: boolean\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n /**\n * The semantics applied to this property.\n * This is a list of applied semantics that can be used to\n * describe the property in more detail.\n */\n semantics?: AppliedDataSemantic[]\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers, but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DomainPropertyType\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: PropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: PropertyBinding[]\n}\n\n/**\n * Represents a property within a data domain entity.\n *\n * A `DomainProperty` defines a single data element within a\n * `DomainEntity`. It specifies the data type, constraints,\n * and other metadata for a specific piece of information.\n *\n * **Key Features:**\n *\n * - **Data Type:** Defines the type of data the property\n * holds (e.g., string, number, boolean, date).\n * - **Constraints:** Supports defining constraints such as\n * minimum/maximum values, enum values, and default values.\n * - **Bindings:** Allows defining how the property is\n * represented in different formats (e.g., web APIs,\n * protocol buffers).\n * - **Metadata:** Supports metadata such as tags, semantics,\n * read-only/write-only status, and deprecation.\n * - **Schema:** Allows defining a general schema for the\n * property, which is propagated to all bindings.\n *\n * **Usage:**\n *\n * Use the `DomainEntity.addProperty` method to add a new property to an\n * entity. The property can be created using the constructor, but it\n * won't be added to the graph until you call the `addProperty` method.\n *\n * **Example:**\n *\n * ```typescript\n * const entity = domainModel.addEntity({ key: 'user' });\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * schema: {\n * minimum: 3,\n * maximum: 50,\n * },\n * });\n * ```\n */\nexport class DomainProperty extends DomainElement {\n override kind: typeof DomainPropertyKind\n\n /**\n * The description of the domain property.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Wether the data property is required.\n */\n @observed() accessor required: boolean | undefined\n\n /**\n * Whether the data property allows multiple items.\n */\n @observed() accessor multiple: boolean | undefined\n\n /**\n * Whether this property describes a primary key of the entity.\n */\n @observed() accessor primary: boolean | undefined\n\n /**\n * Whether this property describes an indexed property of the entity.\n */\n @observed() accessor index: boolean | undefined\n\n /**\n * Whether the property is read only in the schema.\n */\n @observed() accessor readOnly: boolean | undefined\n\n /**\n * Whether the property is write only in the schema.\n */\n @observed() accessor writeOnly: boolean | undefined\n\n /**\n * Whether this property is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Optional general purpose tags for the UI.\n *\n * Note to implementations, use the `addTag()` method as it propagates the \"tag\" value in the namespace.\n * Also, the tags property is excluded from the observer properties.\n * Changes to this property will not notify the observers.\n */\n @observed({ deep: true }) accessor tags: string[] = []\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n @observed() accessor type: DomainPropertyType = 'string'\n\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n @observed({ deep: true }) accessor schema: PropertySchema | undefined\n\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n @observed({ deep: true }) accessor bindings: PropertyBinding[] = []\n\n /**\n * Creates a full data model schema with defaults.\n *\n * @param input The partial data model schema.\n * @returns The data model schema.\n */\n static createSchema(input: Partial<DomainPropertySchema> = {}): DomainPropertySchema {\n const {\n key = nanoid(),\n multiple,\n required,\n type = DomainPropertyList.string,\n index,\n primary,\n readOnly,\n writeOnly,\n tags,\n semantics,\n deprecated,\n schema,\n bindings,\n } = input\n if (typeof type === 'string') {\n if (!DomainPropertyTypes.includes(type as DomainPropertyType)) {\n throw new Error(`Invalid data property type ${type}`)\n }\n }\n const info = Thing.fromJSON(input.info, { name: 'new_property' }).toJSON()\n const result: DomainPropertySchema = {\n kind: DomainPropertyKind,\n key,\n info,\n type,\n }\n if (typeof multiple === 'boolean') {\n result.multiple = multiple\n }\n if (typeof required === 'boolean') {\n result.required = required\n }\n if (typeof index === 'boolean') {\n result.index = index\n }\n if (typeof primary === 'boolean') {\n result.primary = primary\n }\n if (typeof readOnly === 'boolean') {\n result.readOnly = readOnly\n }\n if (typeof writeOnly === 'boolean') {\n result.writeOnly = writeOnly\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (schema) {\n result.schema = structuredClone(schema)\n }\n if (Array.isArray(bindings)) {\n result.bindings = bindings.map((i) => structuredClone(i))\n } else {\n result.bindings = []\n }\n return result\n }\n\n /**\n * The key of the parent entity.\n */\n protected parent: string\n\n /**\n * Creates a new domain property instance.\n * It does not add it to the graph.\n * You need to call the `addProperty` method of the graph or a data model to add it.\n *\n * Domain objects constructors shouldn't be used directly. Use methods\n * provided on the DataDomain class to create new objects.\n *\n * @param root A reference to the root DataDomain instance.\n * @param parent The key of the parent entity.\n * @param input The partial domain property schema.\n * @returns Created domain property instance.\n */\n constructor(root: DataDomain, parent: string, input: Partial<DomainPropertySchema> = {}) {\n const init = DomainProperty.createSchema(input)\n super(root, init.key)\n this.parent = parent\n this.kind = DomainPropertyKind\n this.info = new Thing(init.info)\n this.type = init.type\n\n if (typeof init.multiple === 'boolean') {\n this.multiple = init.multiple\n } else {\n this.multiple = undefined\n }\n if (typeof init.required === 'boolean') {\n this.required = init.required\n } else {\n this.required = undefined\n }\n if (typeof init.index === 'boolean') {\n this.index = init.index\n } else {\n this.index = undefined\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n } else {\n this.deprecated = undefined\n }\n if (typeof init.primary === 'boolean') {\n this.primary = init.primary\n } else {\n this.primary = undefined\n }\n if (typeof init.readOnly === 'boolean') {\n this.readOnly = init.readOnly\n } else {\n this.readOnly = undefined\n }\n if (typeof init.writeOnly === 'boolean') {\n this.writeOnly = init.writeOnly\n } else {\n this.writeOnly = undefined\n }\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = [...init.semantics]\n } else {\n this.semantics = []\n }\n if (init.schema) {\n this.schema = structuredClone(init.schema)\n } else {\n this.schema = undefined\n }\n if (Array.isArray(init.bindings)) {\n this.bindings = init.bindings.map((i) => structuredClone(i))\n } else {\n this.bindings = []\n }\n }\n\n /**\n * Checks whether the input is a valid definition of a domain property.\n *\n * @param input The input to validate.\n * @param options Validation options.\n * @returns true when the passed input is a valid definition of a domain property.\n */\n static validate(input: unknown, options: ModelValidationOptions = {}): boolean {\n if (!input || (typeof input !== 'object' && input !== null)) {\n return false\n }\n const typed = input as DomainPropertySchema\n if (options.strict && typed.kind !== DomainPropertyKind) {\n return false\n }\n return true\n }\n\n toJSON(): DomainPropertySchema {\n const result: DomainPropertySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n type: this.type || DomainPropertyList.string,\n }\n if (typeof this.index === 'boolean') {\n result.index = this.index\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n if (typeof this.primary === 'boolean') {\n result.primary = this.primary\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (typeof this.readOnly === 'boolean') {\n result.readOnly = this.readOnly\n }\n if (typeof this.writeOnly === 'boolean') {\n result.writeOnly = this.writeOnly\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...this.tags]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (this.schema) {\n result.schema = structuredClone(toRaw(this, this.schema))\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))\n }\n return result\n }\n\n /**\n * Removes this property from the parent entity.\n * It calls the `removeProperty()` method of the parent entity.\n */\n remove(): void {\n const parent = this.getParentInstance()\n parent?.removeProperty(this.key)\n }\n\n /**\n * Returns a parent data entity where this data property exist.\n */\n getParentInstance(): DomainEntity | undefined {\n return this.root.graph.node(this.parent) as DomainEntity | undefined\n }\n\n /**\n * Checks whether the passed value is one of the supported data types.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data types.\n */\n static isValidType(value: unknown): value is DomainPropertyType {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyTypes.includes(value as DomainPropertyType)\n }\n\n /**\n * Checks whether the passed value is one of the supported data property attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data property attributes.\n */\n static isValidAttribute(value: unknown): value is DomainPropertyAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyAttributes.includes(value as DomainPropertyAttribute)\n }\n\n /**\n * Checks whether the passed value of one of the supported `format` values.\n *\n * @param value The value to test\n * @returns `true` when the value is one of the supported `format` values.\n */\n static isValidFormat(value: unknown): value is DomainPropertyFormat {\n if (value === undefined) {\n // It is the valid value.\n return true\n }\n if (typeof value !== 'string') {\n return false\n }\n if (NumberFormats.includes(value as NumberFormat)) {\n return true\n }\n if (BinaryFormats.includes(value as BinaryFormat)) {\n return true\n }\n return false\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): PropertySchema {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): PropertyWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as PropertyBinding\n this.bindings.push(object)\n }\n return object.schema as PropertyWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was created.\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n */\n readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as PropertyBinding\n return item?.schema || undefined\n }\n\n /**\n * Creates a Property Shape of AMF.\n *\n * The property itself is auto-generated. If the `schema` is\n * defined then it is used as the `range` of the property.\n * Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this\n * synchronizes changed data properties with the shape\n * definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new ShapeGenerator()\n return serializer.property(this)\n }\n\n /**\n * Generates an example value for this property based on its schema and type.\n *\n * This method converts the property to an AMF shape and then generates\n * an example value using the ApiSchemaGenerator. The generated example\n * respects the property's type, constraints, and any defined schema.\n *\n * @param mime The mime type of the example (e.g., 'application/json', 'application/xml').\n * @param opts Optional configuration for example generation.\n * @returns The generated example value.\n * @example\n * ```typescript\n * const example = property.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n // TODO: add support for semantic extensions and generate example values based on them.\n const shape = this.toApiShape()\n if (!shape.range) {\n return undefined\n }\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: opts.renderExamples ?? true,\n renderMocked: opts.renderMocked ?? true,\n renderOptional: opts.renderOptional ?? true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Adds or updates a semantic to the property.\n * @param semantic The semantic to add to the property.\n * @throws Error if the semantic is not an property semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isPropertySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected a property semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the property.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the property has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n\n /**\n * Creates a duplicate of this domain property on the parent entity.\n * It places the duplicate on the parent entity right after the original property.\n */\n duplicate(): DomainProperty {\n const parent = this.getParentInstance()\n if (!parent) {\n throw new Error(`Cannot duplicate property ${this.key} as it has no parent entity.`)\n }\n const originalIndex = parent.fields.findIndex((f) => f.key === this.key)\n if (originalIndex === -1) {\n throw new Error(`Cannot duplicate property ${this.key} as it does not exist on the parent entity fields list.`)\n }\n const baseName = this.info.name || 'field'\n const newName = parent.generateUniqueName(baseName)\n\n // Making a copy and restoring it through the `addProperty()` method\n // scales better than copying it manually.\n const copy = this.toJSON() as Partial<DomainPropertySchema>\n\n // Delete properties that should not be copied\n delete copy.key\n delete copy.primary // Don't duplicate the primary key\n\n // Set the new name for the duplicated property\n if (copy.info) {\n copy.info.name = newName\n } else {\n copy.info = { name: newName }\n }\n const result = parent.addProperty(copy)\n\n // Move the duplicate to be right after the original\n const fromIndex = parent.fields.length - 1\n const duplicateField = parent.fields[fromIndex]\n parent.fields.splice(fromIndex, 1)\n parent.fields.splice(originalIndex + 1, 0, duplicateField)\n\n this.domain.notifyChange()\n return result\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataDomainGraph, SerializedGraph } from './types.js';
|
|
1
|
+
import type { DataDomainGraph, SerializedGraph, DeserializationResult, DeserializeOptions } from './types.js';
|
|
2
2
|
import type { DataDomain } from './DataDomain.js';
|
|
3
3
|
interface GraphMergeResult {
|
|
4
4
|
/**
|
|
@@ -33,8 +33,11 @@ export declare function mergeGraph(own: DataDomainGraph, foreign: DataDomainGrap
|
|
|
33
33
|
*
|
|
34
34
|
* @param root The DataDomain instance to use as the root for the graph
|
|
35
35
|
* @param json The previously serialized graph
|
|
36
|
-
* @
|
|
36
|
+
* @param dependencies An array of foreign data domains to register with this domain
|
|
37
|
+
* @param mode The deserialization mode - 'strict' throws errors, 'lenient' collects issues
|
|
38
|
+
* @returns DeserializationResult with graph, issues, and success status
|
|
39
|
+
* @throws Error in strict mode when any issue is encountered
|
|
37
40
|
*/
|
|
38
|
-
export declare function deserialize(root: DataDomain,
|
|
41
|
+
export declare function deserialize(root: DataDomain, options?: DeserializeOptions): DeserializationResult;
|
|
39
42
|
export {};
|
|
40
43
|
//# sourceMappingURL=DomainSerialization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainSerialization.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"DomainSerialization.d.ts","sourceRoot":"","sources":["../../../src/modeling/DomainSerialization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EAGf,eAAe,EAEf,qBAAqB,EAErB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AASnB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAMjD,UAAU,gBAAgB;IACxB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACnB;AAoMD,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe,CAchF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAa9E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAyD3G;AAgJD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,kBAAuB,GAAG,qBAAqB,CAsNrG"}
|