@api-client/core 0.11.4 → 0.11.7
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/oauth-popup.html +33 -0
- package/build/src/amf/definitions/Shapes.d.ts +1 -1
- package/build/src/amf/definitions/Shapes.js.map +1 -1
- package/build/src/modeling/DataAssociation.d.ts +7 -3
- package/build/src/modeling/DataAssociation.d.ts.map +1 -1
- package/build/src/modeling/DataAssociation.js +22 -6
- package/build/src/modeling/DataAssociation.js.map +1 -1
- package/build/src/modeling/DataEntity.d.ts +14 -1
- package/build/src/modeling/DataEntity.d.ts.map +1 -1
- package/build/src/modeling/DataEntity.js +39 -9
- package/build/src/modeling/DataEntity.js.map +1 -1
- package/build/src/modeling/DataModel.d.ts +5 -1
- package/build/src/modeling/DataModel.d.ts.map +1 -1
- package/build/src/modeling/DataModel.js +15 -11
- package/build/src/modeling/DataModel.js.map +1 -1
- package/build/src/modeling/DataNamespace.d.ts +12 -1
- package/build/src/modeling/DataNamespace.d.ts.map +1 -1
- package/build/src/modeling/DataNamespace.js +45 -6
- package/build/src/modeling/DataNamespace.js.map +1 -1
- package/build/src/modeling/DataProperty.js +2 -2
- package/build/src/modeling/DataProperty.js.map +1 -1
- package/data/models/example-generator-api.json +27 -27
- package/package.json +6 -16
- package/src/amf/definitions/Shapes.ts +1 -1
- package/src/modeling/DataAssociation.ts +26 -6
- package/src/modeling/DataEntity.ts +44 -9
- package/src/modeling/DataModel.ts +16 -11
- package/src/modeling/DataNamespace.ts +46 -6
- package/src/modeling/DataProperty.ts +2 -2
- package/tests/unit/modeling/data_association.spec.ts +2 -2
- package/tests/unit/modeling/data_entity.spec.ts +3 -3
- package/tests/unit/modeling/data_model.spec.ts +3 -3
- package/tests/unit/modeling/data_namespace.spec.ts +72 -3
- package/tsconfig.browser.json +2 -1
- package/Local.session.sql +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>Oauth2 callback window</title>
|
|
6
|
+
<style>
|
|
7
|
+
*[hidden] {
|
|
8
|
+
display: none;
|
|
9
|
+
}
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<h1>Sending the authorization data to the application</h1>
|
|
14
|
+
<p id="general-error" hidden>
|
|
15
|
+
The window wasn't opened as a popup and therefore it can't pass the authorization information.<br />
|
|
16
|
+
This is an error.
|
|
17
|
+
</p>
|
|
18
|
+
<script>
|
|
19
|
+
const messageTarget = window.opener || window.parent || window.top
|
|
20
|
+
if (!messageTarget || messageTarget === window || !messageTarget.postMessage) {
|
|
21
|
+
const elm = document.getElementById('general-error')
|
|
22
|
+
elm.removeAttribute('hidden')
|
|
23
|
+
} else {
|
|
24
|
+
const search = window.location.search.substr(1)
|
|
25
|
+
if (search) {
|
|
26
|
+
messageTarget.postMessage(search, '*')
|
|
27
|
+
} else {
|
|
28
|
+
messageTarget.postMessage(window.location.hash.substr(1), '*')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
@@ -45,7 +45,7 @@ export interface IApiAssociationShape {
|
|
|
45
45
|
* - anyOf - To validate against `anyOf`, the given data must be valid against
|
|
46
46
|
* any (one or more) of the given sub-schemas. When generation a schema, it takes first union schema.
|
|
47
47
|
* - oneOf - To validate against `oneOf`, the given data must be valid against
|
|
48
|
-
* exactly one of the given sub-schemas. It behaves the same as `
|
|
48
|
+
* exactly one of the given sub-schemas. It behaves the same as `anyOf` when generating a schema
|
|
49
49
|
* - not - The `not` keyword declares that an instance validates if it doesn’t
|
|
50
50
|
* validate against the given sub-schema. It has no use when generating a schema.
|
|
51
51
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shapes.js","sourceRoot":"","sources":["../../../../src/amf/definitions/Shapes.ts"],"names":[],"mappings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AQ,CAAC,EAAE,CAAC,CAAA;IAC3B,MAAM,CAAC,KAAK,GAAG,iBAAiB,CAAA;IAChC,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU,EAAE,OAAgB;IACzD,MAAM,MAAM,GAAuB;QACjC,GAAG,KAAK,CAAC,EAAE,CAAC;QACZ,EAAE,EAAE,aAAa,EAAE,EAAE;QACrB,KAAK,EAAE,kBAAkB;QACzB,QAAQ,EAAE,OAAO,IAAI,EAAE;KACxB,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {\n IAmfAnyTypes,\n IAmfArrayTypes,\n IAmfFileTypes,\n IAmfNodeTypes,\n IAmfPropertyTypes,\n IAmfRecursiveTypes,\n IAmfScalarTypes,\n IAmfTupleTypes,\n IAmfUnionTypes,\n IAmfXmlSerializationTypes,\n} from '../AmfTypes.js'\nimport { IApiDocumentation, IApiDocumentSourceMaps } from './Api.js'\nimport { IApiDomainProperty } from './Base.js'\n\nexport type IShapeUnion =\n | IApiScalarShape\n | IApiNodeShape\n | IApiUnionShape\n | IApiFileShape\n | IApiSchemaShape\n | IApiAnyShape\n | IApiArrayShape\n | IApiTupleShape\n | IApiRecursiveShape\n\nexport interface IApiAssociationShape {\n /**\n * This is custom property not available in AMF and used with data associations.\n *\n * Whether the target entity should be embedded under the property name.\n * When false, this association is just an information that one entity depend on another.\n * When true, it changes the definition of the schema having this association to\n * add the target schema properties inline with this property.\n *\n * **When true**\n *\n * ```javascript\n * // generated schema for `address` association\n * {\n * \"name\": \"example value\",\n * \"address\": {\n * \"city\": \"example value\",\n * ...\n * }\n * }\n * ```\n *\n * **When false**\n *\n * ```javascript\n * // generated schema for `address` association\n * {\n * \"name\": \"example value\",\n * \"address\": \"the key of the referenced schema\"\n * }\n * ```\n */\n linked?: boolean\n /**\n * When the association has multiple targets the union type should be\n * set to describe which union this is.\n *\n * Possible values are:\n *\n * - allOf - To validate against `allOf`, the given data must be valid against\n * all of the given sub-schemas. When generating, it's a sum of all properties.\n * - anyOf - To validate against `anyOf`, the given data must be valid against\n * any (one or more) of the given sub-schemas. When generation a schema, it takes first union schema.\n * - oneOf - To validate against `oneOf`, the given data must be valid against\n * exactly one of the given sub-schemas. It behaves the same as `oneOf` when generating a schema\n * - not - The `not` keyword declares that an instance validates if it doesn’t\n * validate against the given sub-schema. It has no use when generating a schema.\n *\n * @default anyOf\n */\n unionType?: 'allOf' | 'anyOf' | 'oneOf' | 'not'\n}\n\nexport interface IApiDataExample extends IApiDomainProperty {\n name?: string\n displayName?: string\n description?: string\n /**\n * This is the \"raw\" property of AMF\n */\n value?: string\n structuredValue?: IApiDataNodeUnion\n strict: boolean\n mediaType?: string\n location?: string\n sourceMaps?: IApiDocumentSourceMaps\n}\n\nexport function xmlSerializer(id: string): IApiXmlSerializer {\n return {\n id: `xml-serializer-${id}`,\n types: IAmfXmlSerializationTypes,\n customDomainProperties: [],\n }\n}\n\nexport function shape(id: string): IApiShape {\n const result: IApiShape = {\n id,\n types: [],\n values: [],\n inherits: [],\n or: [],\n and: [],\n xone: [],\n customDomainProperties: [],\n }\n return result\n}\n\nexport function anyShape(id: string): IApiAnyShape {\n const result: IApiAnyShape = {\n ...shape(id),\n types: IAmfAnyTypes,\n examples: [],\n xmlSerialization: xmlSerializer(id),\n }\n return result\n}\n\nexport function nodeShape(id: string): IApiNodeShape {\n const result = anyShape(id)\n result.types = IAmfNodeTypes\n result.id = `node-shape-${id}`\n return {\n ...result,\n properties: [],\n dependencies: [],\n customShapeProperties: [],\n customShapePropertyDefinitions: [],\n }\n}\n\nexport function scalarShape(id: string): IApiScalarShape {\n const result = anyShape(id)\n result.id = `scalar-shape-${id}`\n result.types = IAmfScalarTypes\n return result\n}\n\nexport function unionShape(id: string): IApiUnionShape {\n const result = anyShape(id)\n result.id = `union-shape-${id}`\n result.types = IAmfUnionTypes\n return { ...result, anyOf: [] }\n}\n\nexport function fileShape(id: string): IApiFileShape {\n const result = anyShape(id)\n result.id = `file-shape-${id}`\n result.types = IAmfFileTypes\n return result\n}\n\nexport function arrayShape(id: string): IApiArrayShape {\n const result = anyShape(id)\n result.id = `array-shape-${id}`\n result.types = IAmfArrayTypes\n return result\n}\n\nexport function tupleShape(id: string): IApiTupleShape {\n const result = anyShape(id)\n result.id = `tuple-shape-${id}`\n result.types = IAmfTupleTypes\n return { ...result, items: [] }\n}\n\nexport function propertyShape(id: string): IApiPropertyShape {\n const result = anyShape(id)\n result.types = IAmfPropertyTypes\n return result\n}\n\nexport function recursiveShape(id: string, fixedId?: string): IApiRecursiveShape {\n const result: IApiRecursiveShape = {\n ...shape(id),\n id: `recursive-${id}`,\n types: IAmfRecursiveTypes,\n fixPoint: fixedId || '',\n }\n return result\n}\n\nexport interface IApiShape extends IApiDomainProperty {\n /**\n * Enum values for this shape.\n */\n values: IApiDataNodeUnion[]\n /**\n * The list of shapes that this shape inherits from\n */\n inherits: IShapeUnion[]\n /**\n * The `anyOf` union type.\n */\n or: IShapeUnion[]\n /**\n * The `allOf` union type.\n */\n and: IShapeUnion[]\n /**\n * The `oneOf` union type.\n */\n xone: IShapeUnion[]\n /**\n * The name of the shape in the system.\n */\n name?: string\n /**\n * The display name for the shape in the UI.\n */\n displayName?: string\n /**\n * The description of the shape.\n */\n description?: string\n /**\n * The default value encoded as a string\n */\n defaultValueStr?: string\n /**\n * The description of the default value of the shape.\n */\n defaultValue?: IApiDataNodeUnion\n /**\n * Whether the shape is deprecated.\n */\n deprecated?: boolean\n /**\n * Whether the shape is a read only shape (disallow writes to the value)\n */\n readOnly?: boolean\n /**\n * Whether the shape can only be written to (disallow reading the value)\n */\n writeOnly?: boolean\n not?: IShapeUnion\n /**\n * A label that appeared on a link.\n */\n linkLabel?: string\n sourceMaps?: IApiDocumentSourceMaps\n}\n\n/**\n * A property of an API operation.\n */\nexport interface IApiPropertyShape<T = IShapeUnion> extends IApiShape {\n /**\n * The path of the property. Essentially, it is link generated by the AMF library\n * where the fragment part is the name of the property.\n */\n path?: string\n /**\n * The parameter shape definition\n */\n range?: T\n /**\n * When > 0 then the parameter is required.\n */\n minCount?: number\n maxCount?: number\n}\n\nexport interface IApiAnyShape extends IApiShape {\n documentation?: IApiDocumentation\n /**\n * Description of how the shape should be serialized as XML.\n */\n xmlSerialization: IApiXmlSerializer\n /**\n * Examples defined for the shape.\n */\n examples: IApiDataExample[]\n}\n\n/**\n * Describes an object shape.\n */\nexport interface IApiNodeShape extends IApiAnyShape {\n minProperties?: number\n maxProperties?: number\n closed?: boolean\n customShapeProperties: string[]\n customShapePropertyDefinitions: string[]\n discriminator?: string\n discriminatorValue?: string\n properties: IApiPropertyShape[]\n dependencies: string[]\n}\n\nexport interface IApiXmlSerializer extends IApiDomainProperty {\n /**\n * Whether this property should be represented as an attribute of the parent shape.\n *\n * ```\n * <Person name=\"John Doe\"></Person>\n * ```\n */\n attribute?: boolean\n /**\n * When the property is an array (has the `multiple` set to true in the data model)\n * then it tells that the list of values should be wrapped with a parent\n * element:\n *\n * ```\n * <Person>\n * <Person fullName=\"John Doe\"></Person>\n * <Person fullName=\"Other Doe\"></Person>\n * </Person>\n * ```\n *\n * Use this with the combination with `name` to describe the name of the wrapped\n * element\n *\n * ```\n * <people>\n * <Person fullName=\"John Doe\"></Person>\n * </people>\n * ```\n *\n * Note, this is mutually exclusive with `attribute`.\n */\n wrapped?: boolean\n /**\n * The name of the attribute or a wrapped property to use when serializing the property.\n *\n * Attribute name\n * ```xml\n * <Person fullName=\"John Doe\"></Person>\n * ```\n *\n * Wrapped name\n * ```xml\n * <people>\n * <Person name=\"John Doe\"></Person>\n * </people>\n * ```\n */\n name?: string\n /**\n * The XML namespace to use.\n *\n * ```xml\n * <Person ns:name=\"John Doe\"></Person>\n * ```\n */\n namespace?: string\n /**\n * Name prefix\n *\n * ```xml\n * <ns:Person name=\"John Doe\"></ns:Person>\n * ```\n */\n prefix?: string\n sourceMaps?: IApiDocumentSourceMaps\n}\n\nexport interface IApiScalarShape extends IApiAnyShape {\n dataType?: string\n pattern?: string\n minLength?: number\n maxLength?: number\n minimum?: number\n maximum?: number\n exclusiveMinimum?: boolean\n exclusiveMaximum?: boolean\n format?: string\n multipleOf?: number\n}\n\nexport interface IApiFileShape extends IApiAnyShape {\n fileTypes?: string[]\n pattern?: string\n minLength?: number\n maxLength?: number\n minimum?: number\n maximum?: number\n exclusiveMinimum?: boolean\n exclusiveMaximum?: boolean\n format?: string\n multipleOf?: number\n}\n\nexport interface IApiSchemaShape extends IApiAnyShape {\n mediaType?: string\n raw?: string\n}\n\nexport interface IApiUnionShape extends IApiAnyShape {\n anyOf: IShapeUnion[]\n}\n\nexport interface IApiDataArrangeShape extends IApiAnyShape {\n minItems?: number\n maxItems?: number\n uniqueItems?: boolean\n}\n\nexport interface IApiArrayShape<T = IShapeUnion> extends IApiDataArrangeShape {\n items?: T\n}\n\nexport interface IApiTupleShape<T = IShapeUnion> extends IApiDataArrangeShape {\n items: T[]\n additionalItems?: boolean\n}\n\nexport interface IApiRecursiveShape extends IApiShape {\n fixPoint: string\n}\n\nexport interface IApiDataNode extends IApiDomainProperty {\n name?: string\n}\n\nexport interface IApiObjectNode extends IApiDataNode {\n properties: Record<string, IApiDataNodeUnion>\n}\n\nexport interface IApiScalarNode extends IApiDataNode {\n value?: string\n dataType?: string\n}\n\nexport interface IApiArrayNode extends IApiDataNode {\n members: IApiDataNodeUnion[]\n}\n\nexport type IApiDataNodeUnion = IApiDataNode | IApiObjectNode | IApiScalarNode | IApiArrayNode\n"]}
|
|
1
|
+
{"version":3,"file":"Shapes.js","sourceRoot":"","sources":["../../../../src/amf/definitions/Shapes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,cAAc,EACd,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AAmFvB,MAAM,UAAU,aAAa,CAAC,EAAU;IACtC,OAAO;QACL,EAAE,EA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EAAE,EAAE,aAAa,EAAE,EAAE;QACrB,KAAK,EAAE,kBAAkB;QACzB,QAAQ,EAAE,OAAO,IAAI,EAAE;KACxB,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {\n IAmfAnyTypes,\n IAmfArrayTypes,\n IAmfFileTypes,\n IAmfNodeTypes,\n IAmfPropertyTypes,\n IAmfRecursiveTypes,\n IAmfScalarTypes,\n IAmfTupleTypes,\n IAmfUnionTypes,\n IAmfXmlSerializationTypes,\n} from '../AmfTypes.js'\nimport { IApiDocumentation, IApiDocumentSourceMaps } from './Api.js'\nimport { IApiDomainProperty } from './Base.js'\n\nexport type IShapeUnion =\n | IApiScalarShape\n | IApiNodeShape\n | IApiUnionShape\n | IApiFileShape\n | IApiSchemaShape\n | IApiAnyShape\n | IApiArrayShape\n | IApiTupleShape\n | IApiRecursiveShape\n\nexport interface IApiAssociationShape {\n /**\n * This is custom property not available in AMF and used with data associations.\n *\n * Whether the target entity should be embedded under the property name.\n * When false, this association is just an information that one entity depend on another.\n * When true, it changes the definition of the schema having this association to\n * add the target schema properties inline with this property.\n *\n * **When true**\n *\n * ```javascript\n * // generated schema for `address` association\n * {\n * \"name\": \"example value\",\n * \"address\": {\n * \"city\": \"example value\",\n * ...\n * }\n * }\n * ```\n *\n * **When false**\n *\n * ```javascript\n * // generated schema for `address` association\n * {\n * \"name\": \"example value\",\n * \"address\": \"the key of the referenced schema\"\n * }\n * ```\n */\n linked?: boolean\n /**\n * When the association has multiple targets the union type should be\n * set to describe which union this is.\n *\n * Possible values are:\n *\n * - allOf - To validate against `allOf`, the given data must be valid against\n * all of the given sub-schemas. When generating, it's a sum of all properties.\n * - anyOf - To validate against `anyOf`, the given data must be valid against\n * any (one or more) of the given sub-schemas. When generation a schema, it takes first union schema.\n * - oneOf - To validate against `oneOf`, the given data must be valid against\n * exactly one of the given sub-schemas. It behaves the same as `anyOf` when generating a schema\n * - not - The `not` keyword declares that an instance validates if it doesn’t\n * validate against the given sub-schema. It has no use when generating a schema.\n *\n * @default anyOf\n */\n unionType?: 'allOf' | 'anyOf' | 'oneOf' | 'not'\n}\n\nexport interface IApiDataExample extends IApiDomainProperty {\n name?: string\n displayName?: string\n description?: string\n /**\n * This is the \"raw\" property of AMF\n */\n value?: string\n structuredValue?: IApiDataNodeUnion\n strict: boolean\n mediaType?: string\n location?: string\n sourceMaps?: IApiDocumentSourceMaps\n}\n\nexport function xmlSerializer(id: string): IApiXmlSerializer {\n return {\n id: `xml-serializer-${id}`,\n types: IAmfXmlSerializationTypes,\n customDomainProperties: [],\n }\n}\n\nexport function shape(id: string): IApiShape {\n const result: IApiShape = {\n id,\n types: [],\n values: [],\n inherits: [],\n or: [],\n and: [],\n xone: [],\n customDomainProperties: [],\n }\n return result\n}\n\nexport function anyShape(id: string): IApiAnyShape {\n const result: IApiAnyShape = {\n ...shape(id),\n types: IAmfAnyTypes,\n examples: [],\n xmlSerialization: xmlSerializer(id),\n }\n return result\n}\n\nexport function nodeShape(id: string): IApiNodeShape {\n const result = anyShape(id)\n result.types = IAmfNodeTypes\n result.id = `node-shape-${id}`\n return {\n ...result,\n properties: [],\n dependencies: [],\n customShapeProperties: [],\n customShapePropertyDefinitions: [],\n }\n}\n\nexport function scalarShape(id: string): IApiScalarShape {\n const result = anyShape(id)\n result.id = `scalar-shape-${id}`\n result.types = IAmfScalarTypes\n return result\n}\n\nexport function unionShape(id: string): IApiUnionShape {\n const result = anyShape(id)\n result.id = `union-shape-${id}`\n result.types = IAmfUnionTypes\n return { ...result, anyOf: [] }\n}\n\nexport function fileShape(id: string): IApiFileShape {\n const result = anyShape(id)\n result.id = `file-shape-${id}`\n result.types = IAmfFileTypes\n return result\n}\n\nexport function arrayShape(id: string): IApiArrayShape {\n const result = anyShape(id)\n result.id = `array-shape-${id}`\n result.types = IAmfArrayTypes\n return result\n}\n\nexport function tupleShape(id: string): IApiTupleShape {\n const result = anyShape(id)\n result.id = `tuple-shape-${id}`\n result.types = IAmfTupleTypes\n return { ...result, items: [] }\n}\n\nexport function propertyShape(id: string): IApiPropertyShape {\n const result = anyShape(id)\n result.types = IAmfPropertyTypes\n return result\n}\n\nexport function recursiveShape(id: string, fixedId?: string): IApiRecursiveShape {\n const result: IApiRecursiveShape = {\n ...shape(id),\n id: `recursive-${id}`,\n types: IAmfRecursiveTypes,\n fixPoint: fixedId || '',\n }\n return result\n}\n\nexport interface IApiShape extends IApiDomainProperty {\n /**\n * Enum values for this shape.\n */\n values: IApiDataNodeUnion[]\n /**\n * The list of shapes that this shape inherits from\n */\n inherits: IShapeUnion[]\n /**\n * The `anyOf` union type.\n */\n or: IShapeUnion[]\n /**\n * The `allOf` union type.\n */\n and: IShapeUnion[]\n /**\n * The `oneOf` union type.\n */\n xone: IShapeUnion[]\n /**\n * The name of the shape in the system.\n */\n name?: string\n /**\n * The display name for the shape in the UI.\n */\n displayName?: string\n /**\n * The description of the shape.\n */\n description?: string\n /**\n * The default value encoded as a string\n */\n defaultValueStr?: string\n /**\n * The description of the default value of the shape.\n */\n defaultValue?: IApiDataNodeUnion\n /**\n * Whether the shape is deprecated.\n */\n deprecated?: boolean\n /**\n * Whether the shape is a read only shape (disallow writes to the value)\n */\n readOnly?: boolean\n /**\n * Whether the shape can only be written to (disallow reading the value)\n */\n writeOnly?: boolean\n not?: IShapeUnion\n /**\n * A label that appeared on a link.\n */\n linkLabel?: string\n sourceMaps?: IApiDocumentSourceMaps\n}\n\n/**\n * A property of an API operation.\n */\nexport interface IApiPropertyShape<T = IShapeUnion> extends IApiShape {\n /**\n * The path of the property. Essentially, it is link generated by the AMF library\n * where the fragment part is the name of the property.\n */\n path?: string\n /**\n * The parameter shape definition\n */\n range?: T\n /**\n * When > 0 then the parameter is required.\n */\n minCount?: number\n maxCount?: number\n}\n\nexport interface IApiAnyShape extends IApiShape {\n documentation?: IApiDocumentation\n /**\n * Description of how the shape should be serialized as XML.\n */\n xmlSerialization: IApiXmlSerializer\n /**\n * Examples defined for the shape.\n */\n examples: IApiDataExample[]\n}\n\n/**\n * Describes an object shape.\n */\nexport interface IApiNodeShape extends IApiAnyShape {\n minProperties?: number\n maxProperties?: number\n closed?: boolean\n customShapeProperties: string[]\n customShapePropertyDefinitions: string[]\n discriminator?: string\n discriminatorValue?: string\n properties: IApiPropertyShape[]\n dependencies: string[]\n}\n\nexport interface IApiXmlSerializer extends IApiDomainProperty {\n /**\n * Whether this property should be represented as an attribute of the parent shape.\n *\n * ```\n * <Person name=\"John Doe\"></Person>\n * ```\n */\n attribute?: boolean\n /**\n * When the property is an array (has the `multiple` set to true in the data model)\n * then it tells that the list of values should be wrapped with a parent\n * element:\n *\n * ```\n * <Person>\n * <Person fullName=\"John Doe\"></Person>\n * <Person fullName=\"Other Doe\"></Person>\n * </Person>\n * ```\n *\n * Use this with the combination with `name` to describe the name of the wrapped\n * element\n *\n * ```\n * <people>\n * <Person fullName=\"John Doe\"></Person>\n * </people>\n * ```\n *\n * Note, this is mutually exclusive with `attribute`.\n */\n wrapped?: boolean\n /**\n * The name of the attribute or a wrapped property to use when serializing the property.\n *\n * Attribute name\n * ```xml\n * <Person fullName=\"John Doe\"></Person>\n * ```\n *\n * Wrapped name\n * ```xml\n * <people>\n * <Person name=\"John Doe\"></Person>\n * </people>\n * ```\n */\n name?: string\n /**\n * The XML namespace to use.\n *\n * ```xml\n * <Person ns:name=\"John Doe\"></Person>\n * ```\n */\n namespace?: string\n /**\n * Name prefix\n *\n * ```xml\n * <ns:Person name=\"John Doe\"></ns:Person>\n * ```\n */\n prefix?: string\n sourceMaps?: IApiDocumentSourceMaps\n}\n\nexport interface IApiScalarShape extends IApiAnyShape {\n dataType?: string\n pattern?: string\n minLength?: number\n maxLength?: number\n minimum?: number\n maximum?: number\n exclusiveMinimum?: boolean\n exclusiveMaximum?: boolean\n format?: string\n multipleOf?: number\n}\n\nexport interface IApiFileShape extends IApiAnyShape {\n fileTypes?: string[]\n pattern?: string\n minLength?: number\n maxLength?: number\n minimum?: number\n maximum?: number\n exclusiveMinimum?: boolean\n exclusiveMaximum?: boolean\n format?: string\n multipleOf?: number\n}\n\nexport interface IApiSchemaShape extends IApiAnyShape {\n mediaType?: string\n raw?: string\n}\n\nexport interface IApiUnionShape extends IApiAnyShape {\n anyOf: IShapeUnion[]\n}\n\nexport interface IApiDataArrangeShape extends IApiAnyShape {\n minItems?: number\n maxItems?: number\n uniqueItems?: boolean\n}\n\nexport interface IApiArrayShape<T = IShapeUnion> extends IApiDataArrangeShape {\n items?: T\n}\n\nexport interface IApiTupleShape<T = IShapeUnion> extends IApiDataArrangeShape {\n items: T[]\n additionalItems?: boolean\n}\n\nexport interface IApiRecursiveShape extends IApiShape {\n fixPoint: string\n}\n\nexport interface IApiDataNode extends IApiDomainProperty {\n name?: string\n}\n\nexport interface IApiObjectNode extends IApiDataNode {\n properties: Record<string, IApiDataNodeUnion>\n}\n\nexport interface IApiScalarNode extends IApiDataNode {\n value?: string\n dataType?: string\n}\n\nexport interface IApiArrayNode extends IApiDataNode {\n members: IApiDataNodeUnion[]\n}\n\nexport type IApiDataNodeUnion = IApiDataNode | IApiObjectNode | IApiScalarNode | IApiArrayNode\n"]}
|
|
@@ -235,21 +235,25 @@ export declare class DataAssociation {
|
|
|
235
235
|
* @returns AMF property shape definition.
|
|
236
236
|
*/
|
|
237
237
|
toApiShape(): IApiPropertyShape;
|
|
238
|
+
/**
|
|
239
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
240
|
+
*/
|
|
241
|
+
getParent(): DataEntity;
|
|
238
242
|
/**
|
|
239
243
|
* Retrieves the parent entity of this association.
|
|
240
244
|
*
|
|
241
245
|
* @returns The `DataEntity` instance that contains this association.
|
|
242
246
|
*/
|
|
243
|
-
|
|
247
|
+
getParentInstance(): DataEntity;
|
|
244
248
|
/**
|
|
245
249
|
* Creates the `schema` object if missing and returns it.
|
|
246
250
|
* @returns The schema object.
|
|
247
251
|
*/
|
|
248
252
|
ensureSchema(): IApiAssociationShape;
|
|
249
253
|
/**
|
|
250
|
-
* Checks whether the passed value is one of the supported data
|
|
254
|
+
* Checks whether the passed value is one of the supported data property attributes.
|
|
251
255
|
* @param value The value to test
|
|
252
|
-
* @returns True when the passed value is one of the supported data
|
|
256
|
+
* @returns True when the passed value is one of the supported data property attributes.
|
|
253
257
|
*/
|
|
254
258
|
static isValidAttribute(value: unknown): value is DataAttributeAttribute;
|
|
255
259
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataAssociation.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataAssociation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAEtF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACpG,OAAO,EAA2B,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAEtF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,mBAAmB,CAAA;IAChC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,iBAAiB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nC;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IA8CjE;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI;IAa3D;;;;;;;;;OASG;IACH,UAAU,IAAI,iBAAiB;IAK/B;;OAEG;IACH,SAAS,IAAI,UAAU;IAIvB;;;;OAIG;IACH,iBAAiB,IAAI,UAAU;IAM/B;;;OAGG;IACH,YAAY,IAAI,oBAAoB;IAOpC;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB;IAOxE;;;OAGG;IACH,aAAa,IAAI,sBAAsB;IASvC;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,UAAU,GAAG,mBAAmB,GAAG,SAAS;CAIvE"}
|
|
@@ -276,9 +276,9 @@ export class DataAssociation {
|
|
|
276
276
|
*/
|
|
277
277
|
remove() {
|
|
278
278
|
const { root } = this;
|
|
279
|
-
const entity = root.definitions.entities.find((i) => i.associations.some((j) => j === this));
|
|
279
|
+
const entity = root.definitions.entities.find((i) => i.associations.some((j) => j.key === this.key));
|
|
280
280
|
if (entity) {
|
|
281
|
-
const assocIndex = entity.associations.findIndex((i) => i === this);
|
|
281
|
+
const assocIndex = entity.associations.findIndex((i) => i.key === this.key);
|
|
282
282
|
entity.associations.splice(assocIndex, 1);
|
|
283
283
|
}
|
|
284
284
|
const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key);
|
|
@@ -303,6 +303,16 @@ export class DataAssociation {
|
|
|
303
303
|
namespace = typed.root.key;
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
|
+
if (this.targets.some((i) => i.key === key)) {
|
|
307
|
+
const message = `Target ${key} already exists.`;
|
|
308
|
+
throw new ValidationError([
|
|
309
|
+
{
|
|
310
|
+
field: 'targets',
|
|
311
|
+
message,
|
|
312
|
+
rule: 'unique',
|
|
313
|
+
},
|
|
314
|
+
], { message });
|
|
315
|
+
}
|
|
306
316
|
if (namespace && namespace !== this.root.key) {
|
|
307
317
|
const foreignNamespace = this.root.foreign.find((ns) => ns.key === namespace);
|
|
308
318
|
if (!foreignNamespace) {
|
|
@@ -349,15 +359,21 @@ export class DataAssociation {
|
|
|
349
359
|
const serializer = new AmfShapeGenerator();
|
|
350
360
|
return serializer.associationProperty(this);
|
|
351
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
364
|
+
*/
|
|
365
|
+
getParent() {
|
|
366
|
+
return this.getParentInstance();
|
|
367
|
+
}
|
|
352
368
|
/**
|
|
353
369
|
* Retrieves the parent entity of this association.
|
|
354
370
|
*
|
|
355
371
|
* @returns The `DataEntity` instance that contains this association.
|
|
356
372
|
*/
|
|
357
|
-
|
|
373
|
+
getParentInstance() {
|
|
358
374
|
// this is forced as an association is only created when an entity is created
|
|
359
375
|
// so it has to be defined.
|
|
360
|
-
return this.root.definitions.entities.find((i) => i.associations.
|
|
376
|
+
return this.root.definitions.entities.find((i) => i.associations.some((a) => a.key === this.key));
|
|
361
377
|
}
|
|
362
378
|
/**
|
|
363
379
|
* Creates the `schema` object if missing and returns it.
|
|
@@ -370,9 +386,9 @@ export class DataAssociation {
|
|
|
370
386
|
return this.schema;
|
|
371
387
|
}
|
|
372
388
|
/**
|
|
373
|
-
* Checks whether the passed value is one of the supported data
|
|
389
|
+
* Checks whether the passed value is one of the supported data property attributes.
|
|
374
390
|
* @param value The value to test
|
|
375
|
-
* @returns True when the passed value is one of the supported data
|
|
391
|
+
* @returns True when the passed value is one of the supported data property attributes.
|
|
376
392
|
*/
|
|
377
393
|
static isValidAttribute(value) {
|
|
378
394
|
if (typeof value !== 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataAssociation.js","sourceRoot":"","sources":["../../../src/modeling/DataAss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B,CAAA;QAC7E,OAAO,IAAI,EAAE,MAAM,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { Json } from '@api-client/json'\nimport { AmfShapeGenerator } from '../amf/AmfShapeGenerator.js'\nimport { IApiAssociationShape, IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport v4 from '../lib/uuid.js'\nimport { IThing, Thing } from '../models/Thing.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { type FieldValidationMessage, ValidationError } from '../exceptions/validation_error.js'\nimport { DataAssociationKind } from '../models/kinds.js'\nimport type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'\nimport { DataAttributeAttributes, type DataAttributeAttribute } from './DataFormat.js'\n\n/**\n * Describes association target of an entity\n */\nexport interface AssociationTarget {\n /**\n * The key of the associated entity.\n */\n key: string\n /**\n * The key of the namespace to look for entities.\n * By default it is the current (root) namespace. When this is set the program\n * will look into `foreign` of the root namespace for the definition\n * of the entity.\n */\n namespace?: string\n}\n\n/**\n * Describes an association between entities. An association is another property of an entity.\n * The `name` is the name of the property and the value is the associated target or targets.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf` and `oneOf` schemas.\n * When the association has only one target, then generated schema cannot have union types.\n *\n * Depending on the schema translation an association can be embedded as a sub-object in the generated schema\n * or can be references via a primary key.\n */\nexport interface IDataAssociation {\n kind: typeof DataAssociationKind\n /**\n * The key of the association.\n */\n key: string\n /**\n * The data association description.\n */\n info: IThing\n /**\n * Wether the data association is required.\n */\n required?: boolean\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets?: AssociationTarget[]\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\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?: AssociationBinding[]\n}\n\n/**\n * Describes an association between entities. An association is a relationship defined on an entity\n * that links it to one or more other entities. The association has a `name` which is used as the\n * property name in the context of the parent entity, and it connects to a set of `targets`\n * representing the associated entities.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf`, or `oneOf`\n * schemas. When the association has only one target, then the generated schema cannot have union types.\n *\n * Depending on the schema translation, an association can be embedded as a sub-object in the generated\n * schema, or it can be referenced via a primary key.\n *\n * ## Key Concepts\n *\n * - **Targets**: An association's `targets` specify the entities that this association points to.\n * Each target is defined by:\n * - `key`: The key of the target entity.\n * - `namespace` (optional): The key of the namespace where the target entity is defined.\n * If not specified, it defaults to the current namespace.\n *\n * - **Cardinality**:\n * - `multiple` (boolean): Indicates whether the association allows multiple target entities.\n * If `true`, it's a to-many relationship; otherwise, it's a to-one relationship.\n *\n * - **Schema**:\n * - `schema` (optional): A custom schema for the association, allowing manual definition of the\n * association's structure in specific formats (e.g., JSON, RAML, XML).\n * When provided, this schema overrides the automatically generated schema based on the\n * target entities.\n * - **Important**: If a custom schema is defined and changes are made to the referenced\n * entities, those changes **will not** be automatically propagated to the custom schema.\n * This means the custom schema may become outdated and no longer accurately reflect the\n * structure of the target entities.\n *\n * - **Hidden**:\n * - `hidden`: (boolean) Defines if this association is a part of the schema or not.\n */\nexport class DataAssociation {\n kind = DataAssociationKind\n\n key = ''\n\n /**\n * The description of the data association.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * Wether the data association is required.\n */\n required?: boolean\n\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets: AssociationTarget[] = []\n\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\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 bindings: AssociationBinding[] = []\n\n /**\n * Returns true when the association has 0 or 1 targets.\n */\n get isSingle(): boolean {\n return this.targets.length < 2\n }\n\n /**\n * Creates an instance of DataAssociation from a target entity key.\n * Note, this entity will have no name. The default name is used instead.\n *\n * @param root The namespace root.\n * @param target The target entity key.\n * @param namespace The optional key of the target association when different to the current one.\n * @returns A new `DataAssociation` instance.\n */\n static fromTarget(root: DataNamespace, target: string, namespace?: string): DataAssociation {\n const assoc = new DataAssociation(root)\n const info: AssociationTarget = {\n key: target,\n }\n if (namespace) {\n info.namespace = namespace\n }\n assoc.targets = [info]\n return assoc\n }\n\n /**\n * Creates an instance of DataAssociation from a name, without defining a target.\n *\n * @param root The namespace root.\n * @param name The name of the association.\n * @returns A new `DataAssociation` instance.\n */\n static fromName(root: DataNamespace, name: string): DataAssociation {\n const assoc = new DataAssociation(root)\n assoc.info = Thing.fromName(name)\n return assoc\n }\n\n /**\n * @param input The data association definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataAssociation\n ) {\n let init: IDataAssociation\n if (typeof input === 'string') {\n try {\n init = JSON.parse(input)\n } catch {\n throw new ValidationError([\n {\n field: '',\n message: 'Unable to parse the data association input as JSON.',\n rule: 'object_required',\n },\n ])\n }\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataAssociationKind,\n key: v4(),\n info: Thing.fromName('Unnamed association').toJSON(),\n }\n }\n this.new(init)\n }\n\n /**\n * Initializes the association using provided data.\n *\n * @param init - The data association definition to restore.\n */\n new(init: IDataAssociation): this {\n DataAssociation.validate(init)\n const { info, key = v4(), kind = DataAssociationKind, schema, multiple, required, targets, bindings } = 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 if (schema) {\n this.schema = Json.clone(schema)\n } else {\n this.schema = undefined\n }\n if (typeof multiple === 'boolean') {\n this.multiple = multiple\n } else {\n this.multiple = undefined\n }\n if (typeof required === 'boolean') {\n this.required = required\n } else {\n this.required = undefined\n }\n if (Array.isArray(targets)) {\n this.targets = targets.map((i) => ({ ...i }))\n } else {\n this.targets = []\n }\n if (Array.isArray(bindings)) {\n this.bindings = bindings.map((i) => Json.clone(i))\n } else {\n this.bindings = []\n }\n return this\n }\n\n /**\n * Validates if the input object is a valid `DataAssociation` definition.\n * Throws a `ValidationError` if the input is invalid.\n *\n * @param input The object to validate.\n * @throws {ValidationError} When the validation fails.\n */\n static validate(input: unknown): void {\n const typed = input as IDataAssociation\n const messages: FieldValidationMessage[] = []\n if (!typed) {\n messages.push({\n field: '',\n message: 'The input is required. None given',\n rule: 'required',\n })\n throw new ValidationError(messages)\n }\n if (typed.kind !== DataAssociationKind) {\n messages.push({\n field: 'kind',\n message: `The kind property must be ${DataAssociationKind}`,\n rule: 'invalid',\n })\n }\n if (typed.info && typeof typed.info !== 'object') {\n messages.push({\n field: 'info',\n message: 'The info property must be an object',\n rule: 'invalid',\n })\n }\n if (messages.length) {\n throw new ValidationError(messages)\n }\n }\n\n /**\n * Generates an object representing the association, suitable for serialization.\n *\n * @returns A plain object representation of the `DataAssociation`.\n */\n toJSON(): IDataAssociation {\n const result: IDataAssociation = {\n kind: DataAssociationKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (this.schema) {\n result.schema = Json.clone(this.schema)\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 (Array.isArray(this.targets) && this.targets.length) {\n result.targets = this.targets.map((i) => ({ ...i }))\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = this.bindings.map((i) => Json.clone(i))\n }\n return result\n }\n\n /**\n * Retrieves the list of target entities.\n *\n * @returns An array of `DataEntity` instances representing the targets of this association.\n */\n getTargets(): DataEntity[] {\n const { targets } = this\n return this.root.findAssociatedEntities(targets).filter((i) => !!i) as DataEntity[]\n }\n\n /**\n * Removes self from the parent entity and the namespace definition.\n */\n remove(): void {\n const { root } = this\n const entity = root.definitions.entities.find((i) => i.associations.some((j) => j === this))\n if (entity) {\n const assocIndex = entity.associations.findIndex((i) => i === this)\n entity.associations.splice(assocIndex, 1)\n }\n const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key)\n if (defIndex >= 0) {\n this.root.definitions.associations.splice(defIndex, 1)\n }\n }\n\n /**\n * Adds a target entity to the association.\n * If the entity comes from another namespace then it is set as a foreign entity.\n *\n * @param entity - The `DataEntity` instance to add.\n */\n addTarget(entity: DataEntity): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param entity - The `IDataEntity` definition or just its key.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(entity: IDataEntity | string, namespace?: string): void\n\n /**\n * @param init The key of an entity, its instance, or schema.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(init: string | DataEntity | IDataEntity, namespace?: string): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n const typed = init as IDataEntity & { root?: DataNamespace }\n if (!namespace && typed.root && typed.root !== this.root) {\n namespace = typed.root.key\n }\n }\n if (namespace && namespace !== this.root.key) {\n const foreignNamespace = this.root.foreign.find((ns) => ns.key === namespace)\n if (!foreignNamespace) {\n throw new Error(`Foreign namespace \"${namespace}\" does not exist.`)\n }\n }\n const info: AssociationTarget = {\n key,\n }\n if (namespace) {\n info.namespace = namespace\n }\n this.targets.push(info)\n }\n\n /**\n * Removes a target entity from the targets list.\n *\n * @param init The key of an entity, its instance, or schema.\n */\n removeTarget(init: string | DataEntity | IDataEntity): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n }\n const index = this.targets.findIndex((i) => i.key === key)\n if (index >= 0) {\n this.targets.splice(index, 1)\n }\n }\n\n /**\n * Creates a Property Shape of AMF.\n * The property itself is auto-generated. If the `schema` is defined then it is used\n * as the `range` of the property. Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this synchronizes changed\n * data properties with the shape definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new AmfShapeGenerator()\n return serializer.associationProperty(this)\n }\n\n /**\n * Retrieves the parent entity of this association.\n *\n * @returns The `DataEntity` instance that contains this association.\n */\n getParent(): DataEntity {\n // this is forced as an association is only created when an entity is created\n // so it has to be defined.\n return this.root.definitions.entities.find((i) => i.associations.includes(this)) as DataEntity\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): IApiAssociationShape {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Checks whether the passed value is one of the supported data proprty attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data proprty attributes.\n */\n static isValidAttribute(value: unknown): value is DataAttributeAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DataAttributeAttributes.includes(value as DataAttributeAttribute)\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): AssociationWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as AssociationBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as AssociationBinding\n this.bindings.push(object)\n }\n return object.schema as AssociationWebBindings\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'): AssociationBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as AssociationBinding\n return item?.schema\n }\n}\n"]}
|
|
1
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AC,CAAA;IAC1E,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAmC,CAAA;QAC1F,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAwB,CAAA;YAC1D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,MAAgC,CAAA;IAChD,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAwB;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAuB,CAAA;QAC7E,OAAO,IAAI,EAAE,MAAM,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { Json } from '@api-client/json'\nimport { AmfShapeGenerator } from '../amf/AmfShapeGenerator.js'\nimport { IApiAssociationShape, IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport v4 from '../lib/uuid.js'\nimport { IThing, Thing } from '../models/Thing.js'\nimport { DataEntity, IDataEntity } from './DataEntity.js'\nimport { DataNamespace } from './DataNamespace.js'\nimport { type FieldValidationMessage, ValidationError } from '../exceptions/validation_error.js'\nimport { DataAssociationKind } from '../models/kinds.js'\nimport type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'\nimport { DataAttributeAttributes, type DataAttributeAttribute } from './DataFormat.js'\n\n/**\n * Describes association target of an entity\n */\nexport interface AssociationTarget {\n /**\n * The key of the associated entity.\n */\n key: string\n /**\n * The key of the namespace to look for entities.\n * By default it is the current (root) namespace. When this is set the program\n * will look into `foreign` of the root namespace for the definition\n * of the entity.\n */\n namespace?: string\n}\n\n/**\n * Describes an association between entities. An association is another property of an entity.\n * The `name` is the name of the property and the value is the associated target or targets.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf` and `oneOf` schemas.\n * When the association has only one target, then generated schema cannot have union types.\n *\n * Depending on the schema translation an association can be embedded as a sub-object in the generated schema\n * or can be references via a primary key.\n */\nexport interface IDataAssociation {\n kind: typeof DataAssociationKind\n /**\n * The key of the association.\n */\n key: string\n /**\n * The data association description.\n */\n info: IThing\n /**\n * Wether the data association is required.\n */\n required?: boolean\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets?: AssociationTarget[]\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\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?: AssociationBinding[]\n}\n\n/**\n * Describes an association between entities. An association is a relationship defined on an entity\n * that links it to one or more other entities. The association has a `name` which is used as the\n * property name in the context of the parent entity, and it connects to a set of `targets`\n * representing the associated entities.\n *\n * An association can have multiple targets to allow describing the model as `allOf`, `anyOf`, or `oneOf`\n * schemas. When the association has only one target, then the generated schema cannot have union types.\n *\n * Depending on the schema translation, an association can be embedded as a sub-object in the generated\n * schema, or it can be referenced via a primary key.\n *\n * ## Key Concepts\n *\n * - **Targets**: An association's `targets` specify the entities that this association points to.\n * Each target is defined by:\n * - `key`: The key of the target entity.\n * - `namespace` (optional): The key of the namespace where the target entity is defined.\n * If not specified, it defaults to the current namespace.\n *\n * - **Cardinality**:\n * - `multiple` (boolean): Indicates whether the association allows multiple target entities.\n * If `true`, it's a to-many relationship; otherwise, it's a to-one relationship.\n *\n * - **Schema**:\n * - `schema` (optional): A custom schema for the association, allowing manual definition of the\n * association's structure in specific formats (e.g., JSON, RAML, XML).\n * When provided, this schema overrides the automatically generated schema based on the\n * target entities.\n * - **Important**: If a custom schema is defined and changes are made to the referenced\n * entities, those changes **will not** be automatically propagated to the custom schema.\n * This means the custom schema may become outdated and no longer accurately reflect the\n * structure of the target entities.\n *\n * - **Hidden**:\n * - `hidden`: (boolean) Defines if this association is a part of the schema or not.\n */\nexport class DataAssociation {\n kind = DataAssociationKind\n\n key = ''\n\n /**\n * The description of the data association.\n */\n info: Thing = Thing.fromName('')\n\n /**\n * Wether the data association is required.\n */\n required?: boolean\n\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets: AssociationTarget[] = []\n\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\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 bindings: AssociationBinding[] = []\n\n /**\n * Returns true when the association has 0 or 1 targets.\n */\n get isSingle(): boolean {\n return this.targets.length < 2\n }\n\n /**\n * Creates an instance of DataAssociation from a target entity key.\n * Note, this entity will have no name. The default name is used instead.\n *\n * @param root The namespace root.\n * @param target The target entity key.\n * @param namespace The optional key of the target association when different to the current one.\n * @returns A new `DataAssociation` instance.\n */\n static fromTarget(root: DataNamespace, target: string, namespace?: string): DataAssociation {\n const assoc = new DataAssociation(root)\n const info: AssociationTarget = {\n key: target,\n }\n if (namespace) {\n info.namespace = namespace\n }\n assoc.targets = [info]\n return assoc\n }\n\n /**\n * Creates an instance of DataAssociation from a name, without defining a target.\n *\n * @param root The namespace root.\n * @param name The name of the association.\n * @returns A new `DataAssociation` instance.\n */\n static fromName(root: DataNamespace, name: string): DataAssociation {\n const assoc = new DataAssociation(root)\n assoc.info = Thing.fromName(name)\n return assoc\n }\n\n /**\n * @param input The data association definition to restore.\n */\n constructor(\n public root: DataNamespace,\n input?: string | IDataAssociation\n ) {\n let init: IDataAssociation\n if (typeof input === 'string') {\n try {\n init = JSON.parse(input)\n } catch {\n throw new ValidationError([\n {\n field: '',\n message: 'Unable to parse the data association input as JSON.',\n rule: 'object_required',\n },\n ])\n }\n } else if (typeof input === 'object') {\n init = input\n } else {\n init = {\n kind: DataAssociationKind,\n key: v4(),\n info: Thing.fromName('Unnamed association').toJSON(),\n }\n }\n this.new(init)\n }\n\n /**\n * Initializes the association using provided data.\n *\n * @param init - The data association definition to restore.\n */\n new(init: IDataAssociation): this {\n DataAssociation.validate(init)\n const { info, key = v4(), kind = DataAssociationKind, schema, multiple, required, targets, bindings } = 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 if (schema) {\n this.schema = Json.clone(schema)\n } else {\n this.schema = undefined\n }\n if (typeof multiple === 'boolean') {\n this.multiple = multiple\n } else {\n this.multiple = undefined\n }\n if (typeof required === 'boolean') {\n this.required = required\n } else {\n this.required = undefined\n }\n if (Array.isArray(targets)) {\n this.targets = targets.map((i) => ({ ...i }))\n } else {\n this.targets = []\n }\n if (Array.isArray(bindings)) {\n this.bindings = bindings.map((i) => Json.clone(i))\n } else {\n this.bindings = []\n }\n return this\n }\n\n /**\n * Validates if the input object is a valid `DataAssociation` definition.\n * Throws a `ValidationError` if the input is invalid.\n *\n * @param input The object to validate.\n * @throws {ValidationError} When the validation fails.\n */\n static validate(input: unknown): void {\n const typed = input as IDataAssociation\n const messages: FieldValidationMessage[] = []\n if (!typed) {\n messages.push({\n field: '',\n message: 'The input is required. None given',\n rule: 'required',\n })\n throw new ValidationError(messages)\n }\n if (typed.kind !== DataAssociationKind) {\n messages.push({\n field: 'kind',\n message: `The kind property must be ${DataAssociationKind}`,\n rule: 'invalid',\n })\n }\n if (typed.info && typeof typed.info !== 'object') {\n messages.push({\n field: 'info',\n message: 'The info property must be an object',\n rule: 'invalid',\n })\n }\n if (messages.length) {\n throw new ValidationError(messages)\n }\n }\n\n /**\n * Generates an object representing the association, suitable for serialization.\n *\n * @returns A plain object representation of the `DataAssociation`.\n */\n toJSON(): IDataAssociation {\n const result: IDataAssociation = {\n kind: DataAssociationKind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (this.schema) {\n result.schema = Json.clone(this.schema)\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 (Array.isArray(this.targets) && this.targets.length) {\n result.targets = this.targets.map((i) => ({ ...i }))\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = this.bindings.map((i) => Json.clone(i))\n }\n return result\n }\n\n /**\n * Retrieves the list of target entities.\n *\n * @returns An array of `DataEntity` instances representing the targets of this association.\n */\n getTargets(): DataEntity[] {\n const { targets } = this\n return this.root.findAssociatedEntities(targets).filter((i) => !!i) as DataEntity[]\n }\n\n /**\n * Removes self from the parent entity and the namespace definition.\n */\n remove(): void {\n const { root } = this\n const entity = root.definitions.entities.find((i) => i.associations.some((j) => j.key === this.key))\n if (entity) {\n const assocIndex = entity.associations.findIndex((i) => i.key === this.key)\n entity.associations.splice(assocIndex, 1)\n }\n const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key)\n if (defIndex >= 0) {\n this.root.definitions.associations.splice(defIndex, 1)\n }\n }\n\n /**\n * Adds a target entity to the association.\n * If the entity comes from another namespace then it is set as a foreign entity.\n *\n * @param entity - The `DataEntity` instance to add.\n */\n addTarget(entity: DataEntity): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param entity - The `IDataEntity` definition or just its key.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(entity: IDataEntity | string, namespace?: string): void\n\n /**\n * @param init The key of an entity, its instance, or schema.\n * @param namespace - The key of the foreign namespace this entity belongs to.\n * Do not set this value for local entities.\n */\n addTarget(init: string | DataEntity | IDataEntity, namespace?: string): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n const typed = init as IDataEntity & { root?: DataNamespace }\n if (!namespace && typed.root && typed.root !== this.root) {\n namespace = typed.root.key\n }\n }\n if (this.targets.some((i) => i.key === key)) {\n const message = `Target ${key} already exists.`\n throw new ValidationError(\n [\n {\n field: 'targets',\n message,\n rule: 'unique',\n },\n ],\n { message }\n )\n }\n if (namespace && namespace !== this.root.key) {\n const foreignNamespace = this.root.foreign.find((ns) => ns.key === namespace)\n if (!foreignNamespace) {\n throw new Error(`Foreign namespace \"${namespace}\" does not exist.`)\n }\n }\n const info: AssociationTarget = {\n key,\n }\n if (namespace) {\n info.namespace = namespace\n }\n this.targets.push(info)\n }\n\n /**\n * Removes a target entity from the targets list.\n *\n * @param init The key of an entity, its instance, or schema.\n */\n removeTarget(init: string | DataEntity | IDataEntity): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n }\n const index = this.targets.findIndex((i) => i.key === key)\n if (index >= 0) {\n this.targets.splice(index, 1)\n }\n }\n\n /**\n * Creates a Property Shape of AMF.\n * The property itself is auto-generated. If the `schema` is defined then it is used\n * as the `range` of the property. Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this synchronizes changed\n * data properties with the shape definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new AmfShapeGenerator()\n return serializer.associationProperty(this)\n }\n\n /**\n * @deprecated Use the `getParentInstance()` method instead.\n */\n getParent(): DataEntity {\n return this.getParentInstance()\n }\n\n /**\n * Retrieves the parent entity of this association.\n *\n * @returns The `DataEntity` instance that contains this association.\n */\n getParentInstance(): DataEntity {\n // this is forced as an association is only created when an entity is created\n // so it has to be defined.\n return this.root.definitions.entities.find((i) => i.associations.some((a) => a.key === this.key)) as DataEntity\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): IApiAssociationShape {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\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 DataAttributeAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DataAttributeAttributes.includes(value as DataAttributeAttribute)\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): AssociationWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as AssociationBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as AssociationBinding\n this.bindings.push(object)\n }\n return object.schema as AssociationWebBindings\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'): AssociationBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as AssociationBinding\n return item?.schema\n }\n}\n"]}
|
|
@@ -223,9 +223,13 @@ export declare class DataEntity {
|
|
|
223
223
|
*/
|
|
224
224
|
remove(): void;
|
|
225
225
|
/**
|
|
226
|
-
*
|
|
226
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
227
227
|
*/
|
|
228
228
|
getParent(): DataModel | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Returns a parent data model where this entity exist.
|
|
231
|
+
*/
|
|
232
|
+
getParentInstance(): DataModel | undefined;
|
|
229
233
|
/**
|
|
230
234
|
* Adds a parent reference to this entity.
|
|
231
235
|
* This will not add the parent to the namespace. It only adds a reference to the parent.
|
|
@@ -233,6 +237,15 @@ export declare class DataEntity {
|
|
|
233
237
|
* @returns `this` for chaining.
|
|
234
238
|
*/
|
|
235
239
|
addParent(key: string): this;
|
|
240
|
+
/**
|
|
241
|
+
* Removes a parent reference from this entity.
|
|
242
|
+
* It keeps the parent as is.
|
|
243
|
+
*
|
|
244
|
+
* @param key The key of the parent entity to remove.
|
|
245
|
+
* @throws ValidationError when the parent is not found.
|
|
246
|
+
* @returns Self for chaining.
|
|
247
|
+
*/
|
|
248
|
+
removeParent(key: string): this;
|
|
236
249
|
/**
|
|
237
250
|
* Checks if the entity has a circular parent relationship when attempting to add a new parent.
|
|
238
251
|
* @param key The key of the parent being added.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataEntity.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAO/D,UAAU,WAAW;IACnB,IAAI,EAAE,UAAU,GAAG,aAAa,CAAA;IAChC,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,cAAc,CAAA;IAC3B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAE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AI;IA8D5B;;;;;;;OAOG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAmB/B;;;;OAIG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAsBvC;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO;IAItE;;;;OAIG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAMrC;;;;;OAKG;IACF,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;IAOvD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,kBAAkB,IAAI,UAAU,EAAE;IAclC,MAAM,CAAC,kBAAkB,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,EAAE;IAYpF;;OAEG;IACH,WAAW,IAAI,cAAc,EAAE;IAgC/B;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAgBzB;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAY5B;;;;;;;;;OASG;IACH,UAAU,IAAI,WAAW;IAKzB;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,mBAAwB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS;IAWrG,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;CAyBlE"}
|
|
@@ -465,7 +465,7 @@ export class DataEntity {
|
|
|
465
465
|
const associationsToEntity = this.root.definitions.associations.filter((a) => a.targets.some((t) => t.key === this.key));
|
|
466
466
|
if (associationsToEntity.length > 0) {
|
|
467
467
|
const entitiesNames = associationsToEntity.reduce((acc, association) => {
|
|
468
|
-
const entity = root.definitions.entities.find((e) => e.associations.
|
|
468
|
+
const entity = root.definitions.entities.find((e) => e.associations.some((a) => a.key === association.key));
|
|
469
469
|
if (entity) {
|
|
470
470
|
acc.push(entity.info.name);
|
|
471
471
|
}
|
|
@@ -482,17 +482,24 @@ export class DataEntity {
|
|
|
482
482
|
root.definitions.entities.splice(index, 1);
|
|
483
483
|
}
|
|
484
484
|
// remove from the parent
|
|
485
|
-
const model = this.
|
|
485
|
+
const model = this.getParentInstance();
|
|
486
486
|
if (model) {
|
|
487
|
-
const entityIndex = model.entities.findIndex((e) => e === this);
|
|
487
|
+
const entityIndex = model.entities.findIndex((e) => e.key === this.key);
|
|
488
488
|
model.entities.splice(entityIndex, 1);
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
/**
|
|
492
|
-
*
|
|
492
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
493
493
|
*/
|
|
494
|
+
// This method name collides with the `getParents()` method.
|
|
494
495
|
getParent() {
|
|
495
|
-
return this.
|
|
496
|
+
return this.getParentInstance();
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Returns a parent data model where this entity exist.
|
|
500
|
+
*/
|
|
501
|
+
getParentInstance() {
|
|
502
|
+
return this.root.definitions.models.find((m) => m.entities.some((e) => e.key === this.key));
|
|
496
503
|
}
|
|
497
504
|
/**
|
|
498
505
|
* Adds a parent reference to this entity.
|
|
@@ -542,13 +549,36 @@ export class DataEntity {
|
|
|
542
549
|
{
|
|
543
550
|
field: 'parents',
|
|
544
551
|
message,
|
|
545
|
-
rule: '
|
|
552
|
+
rule: 'unique',
|
|
546
553
|
},
|
|
547
554
|
], { message });
|
|
548
555
|
}
|
|
549
556
|
this.parents.push(key);
|
|
550
557
|
return this;
|
|
551
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Removes a parent reference from this entity.
|
|
561
|
+
* It keeps the parent as is.
|
|
562
|
+
*
|
|
563
|
+
* @param key The key of the parent entity to remove.
|
|
564
|
+
* @throws ValidationError when the parent is not found.
|
|
565
|
+
* @returns Self for chaining.
|
|
566
|
+
*/
|
|
567
|
+
removeParent(key) {
|
|
568
|
+
const index = this.parents.findIndex((i) => i === key);
|
|
569
|
+
if (index < 0) {
|
|
570
|
+
const message = `Parent ${key} not found.`;
|
|
571
|
+
throw new ValidationError([
|
|
572
|
+
{
|
|
573
|
+
field: 'parents',
|
|
574
|
+
message,
|
|
575
|
+
rule: 'not-found',
|
|
576
|
+
},
|
|
577
|
+
], { message });
|
|
578
|
+
}
|
|
579
|
+
this.parents.splice(index, 1);
|
|
580
|
+
return this;
|
|
581
|
+
}
|
|
552
582
|
/**
|
|
553
583
|
* Checks if the entity has a circular parent relationship when attempting to add a new parent.
|
|
554
584
|
* @param key The key of the parent being added.
|
|
@@ -664,21 +694,21 @@ export class DataEntity {
|
|
|
664
694
|
name: this.info.name || 'Unnamed entity',
|
|
665
695
|
kind: DataEntityKind,
|
|
666
696
|
});
|
|
667
|
-
const model = this.
|
|
697
|
+
const model = this.getParentInstance();
|
|
668
698
|
if (model) {
|
|
669
699
|
result.push({
|
|
670
700
|
key: model.key,
|
|
671
701
|
kind: model.kind,
|
|
672
702
|
name: model.info.name || 'Unnamed data model',
|
|
673
703
|
});
|
|
674
|
-
let parent = model.
|
|
704
|
+
let parent = model.getParentInstance();
|
|
675
705
|
while (parent && parent !== this.root) {
|
|
676
706
|
result.push({
|
|
677
707
|
key: parent.key,
|
|
678
708
|
kind: parent.kind,
|
|
679
709
|
name: parent.info.name || 'Unnamed namespace',
|
|
680
710
|
});
|
|
681
|
-
parent = parent.
|
|
711
|
+
parent = parent.getParentInstance();
|
|
682
712
|
}
|
|
683
713
|
}
|
|
684
714
|
result.push({
|