@api-client/core 0.13.6 → 0.14.1

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.
Files changed (174) hide show
  1. package/build/src/amf/AmfTypes.d.ts +1 -1
  2. package/build/src/amf/AmfTypes.js +1 -1
  3. package/build/src/amf/AmfTypes.js.map +1 -1
  4. package/build/src/amf/Utils.d.ts +0 -6
  5. package/build/src/amf/Utils.d.ts.map +1 -1
  6. package/build/src/amf/Utils.js +0 -14
  7. package/build/src/amf/Utils.js.map +1 -1
  8. package/build/src/browser.d.ts +1 -0
  9. package/build/src/browser.d.ts.map +1 -1
  10. package/build/src/browser.js +1 -0
  11. package/build/src/browser.js.map +1 -1
  12. package/build/src/index.d.ts +1 -0
  13. package/build/src/index.d.ts.map +1 -1
  14. package/build/src/index.js +1 -0
  15. package/build/src/index.js.map +1 -1
  16. package/build/src/legacy.d.ts +0 -8
  17. package/build/src/legacy.d.ts.map +1 -1
  18. package/build/src/legacy.js +0 -9
  19. package/build/src/legacy.js.map +1 -1
  20. package/build/src/modeling/Bindings.d.ts +1 -1
  21. package/build/src/modeling/Bindings.js.map +1 -1
  22. package/build/src/modeling/DataDomain.js +2 -2
  23. package/build/src/modeling/DataDomain.js.map +1 -1
  24. package/build/src/modeling/DataFormat.d.ts +0 -40
  25. package/build/src/modeling/DataFormat.d.ts.map +1 -1
  26. package/build/src/modeling/DataFormat.js +0 -27
  27. package/build/src/modeling/DataFormat.js.map +1 -1
  28. package/build/src/modeling/DomainAssociation.d.ts +28 -0
  29. package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
  30. package/build/src/modeling/DomainAssociation.js +73 -4
  31. package/build/src/modeling/DomainAssociation.js.map +1 -1
  32. package/build/src/modeling/DomainEntity.d.ts +25 -9
  33. package/build/src/modeling/DomainEntity.d.ts.map +1 -1
  34. package/build/src/modeling/DomainEntity.js +65 -21
  35. package/build/src/modeling/DomainEntity.js.map +1 -1
  36. package/build/src/modeling/DomainFile.d.ts +3 -4
  37. package/build/src/modeling/DomainFile.d.ts.map +1 -1
  38. package/build/src/modeling/DomainFile.js +5 -9
  39. package/build/src/modeling/DomainFile.js.map +1 -1
  40. package/build/src/modeling/DomainImpactAnalysis.d.ts +1 -1
  41. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  42. package/build/src/modeling/DomainImpactAnalysis.js +3 -3
  43. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  44. package/build/src/modeling/DomainModel.d.ts +2 -2
  45. package/build/src/modeling/DomainModel.js +2 -2
  46. package/build/src/modeling/DomainModel.js.map +1 -1
  47. package/build/src/modeling/DomainProperty.d.ts +28 -12
  48. package/build/src/modeling/DomainProperty.d.ts.map +1 -1
  49. package/build/src/modeling/DomainProperty.js +61 -26
  50. package/build/src/modeling/DomainProperty.js.map +1 -1
  51. package/build/src/modeling/Semantics.d.ts +109 -0
  52. package/build/src/modeling/Semantics.d.ts.map +1 -0
  53. package/build/src/modeling/Semantics.js +97 -0
  54. package/build/src/modeling/Semantics.js.map +1 -0
  55. package/build/src/models/CertificateFile.d.ts +2 -3
  56. package/build/src/models/CertificateFile.d.ts.map +1 -1
  57. package/build/src/models/CertificateFile.js +4 -8
  58. package/build/src/models/CertificateFile.js.map +1 -1
  59. package/build/src/models/Folder.d.ts +1 -2
  60. package/build/src/models/Folder.d.ts.map +1 -1
  61. package/build/src/models/Folder.js +2 -4
  62. package/build/src/models/Folder.js.map +1 -1
  63. package/build/src/models/Project.d.ts +2 -3
  64. package/build/src/models/Project.d.ts.map +1 -1
  65. package/build/src/models/Project.js +4 -8
  66. package/build/src/models/Project.js.map +1 -1
  67. package/build/src/models/kinds.d.ts +0 -24
  68. package/build/src/models/kinds.d.ts.map +1 -1
  69. package/build/src/models/kinds.js +0 -24
  70. package/build/src/models/kinds.js.map +1 -1
  71. package/build/src/models/store/File.d.ts +1 -21
  72. package/build/src/models/store/File.d.ts.map +1 -1
  73. package/build/src/models/store/File.js +3 -23
  74. package/build/src/models/store/File.js.map +1 -1
  75. package/build/src/models/store/data_catalog.d.ts +1 -1
  76. package/build/src/models/store/data_catalog.js.map +1 -1
  77. package/build/src/sdk/FilesSdk.js +1 -1
  78. package/build/src/sdk/FilesSdk.js.map +1 -1
  79. package/build/tsconfig.tsbuildinfo +1 -1
  80. package/data/models/example-generator-api.json +22 -22
  81. package/eslint.config.js +1 -0
  82. package/package.json +5 -5
  83. package/src/amf/AmfTypes.ts +1 -1
  84. package/src/amf/Utils.ts +0 -15
  85. package/src/modeling/Bindings.ts +1 -1
  86. package/src/modeling/DataDomain.ts +2 -2
  87. package/src/modeling/DataFormat.ts +0 -48
  88. package/src/modeling/DomainAssociation.ts +66 -3
  89. package/src/modeling/DomainEntity.ts +56 -17
  90. package/src/modeling/DomainFile.ts +5 -9
  91. package/src/modeling/DomainImpactAnalysis.ts +3 -3
  92. package/src/modeling/DomainModel.ts +2 -2
  93. package/src/modeling/DomainProperty.ts +60 -21
  94. package/src/modeling/Semantics.ts +178 -0
  95. package/src/modeling/graph.md +14 -14
  96. package/src/modeling/readme.md +29 -29
  97. package/src/models/CertificateFile.ts +4 -12
  98. package/src/models/Folder.ts +2 -4
  99. package/src/models/Project.ts +4 -8
  100. package/src/models/kinds.ts +0 -25
  101. package/src/models/store/File.ts +4 -35
  102. package/src/models/store/data_catalog.ts +1 -1
  103. package/src/sdk/FilesSdk.ts +1 -1
  104. package/tests/unit/modeling/data_domain_change_observers.spec.ts +11 -10
  105. package/tests/unit/modeling/data_domain_entities.spec.ts +129 -1
  106. package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
  107. package/tests/unit/modeling/domain_asociation.spec.ts +177 -0
  108. package/tests/unit/modeling/domain_entity.spec.ts +27 -26
  109. package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +11 -11
  110. package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +10 -10
  111. package/tests/unit/modeling/domain_file.spec.ts +4 -27
  112. package/tests/unit/modeling/{domain.property.spec.ts → domain_property.spec.ts} +139 -23
  113. package/tests/unit/models/Certificate/from_name.spec.ts +3 -15
  114. package/tests/unit/models/File/constructor.spec.ts +0 -1
  115. package/tests/unit/models/File/new.spec.ts +0 -13
  116. package/tests/unit/models/File/shortcutTo.spec.ts +1 -2
  117. package/tests/unit/models/File/toJSON.spec.ts +0 -13
  118. package/tests/unit/models/File/updateByMeMeta.spec.ts +4 -6
  119. package/tests/unit/models/Folder/create.spec.ts +2 -23
  120. package/tests/unit/models/Project/create.spec.ts +6 -32
  121. package/build/src/amf/AmfShapeGenerator.d.ts +0 -103
  122. package/build/src/amf/AmfShapeGenerator.d.ts.map +0 -1
  123. package/build/src/amf/AmfShapeGenerator.js +0 -416
  124. package/build/src/amf/AmfShapeGenerator.js.map +0 -1
  125. package/build/src/modeling/legacy/DataAssociation.d.ts +0 -284
  126. package/build/src/modeling/legacy/DataAssociation.d.ts.map +0 -1
  127. package/build/src/modeling/legacy/DataAssociation.js +0 -443
  128. package/build/src/modeling/legacy/DataAssociation.js.map +0 -1
  129. package/build/src/modeling/legacy/DataEntity.d.ts +0 -358
  130. package/build/src/modeling/legacy/DataEntity.d.ts.map +0 -1
  131. package/build/src/modeling/legacy/DataEntity.js +0 -855
  132. package/build/src/modeling/legacy/DataEntity.js.map +0 -1
  133. package/build/src/modeling/legacy/DataEntityBuilder.d.ts +0 -162
  134. package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +0 -1
  135. package/build/src/modeling/legacy/DataEntityBuilder.js +0 -221
  136. package/build/src/modeling/legacy/DataEntityBuilder.js.map +0 -1
  137. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +0 -298
  138. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +0 -1
  139. package/build/src/modeling/legacy/DataImpactAnalysis.js +0 -441
  140. package/build/src/modeling/legacy/DataImpactAnalysis.js.map +0 -1
  141. package/build/src/modeling/legacy/DataModel.d.ts +0 -99
  142. package/build/src/modeling/legacy/DataModel.d.ts.map +0 -1
  143. package/build/src/modeling/legacy/DataModel.js +0 -237
  144. package/build/src/modeling/legacy/DataModel.js.map +0 -1
  145. package/build/src/modeling/legacy/DataNamespace.d.ts +0 -340
  146. package/build/src/modeling/legacy/DataNamespace.d.ts.map +0 -1
  147. package/build/src/modeling/legacy/DataNamespace.js +0 -784
  148. package/build/src/modeling/legacy/DataNamespace.js.map +0 -1
  149. package/build/src/modeling/legacy/DataProperty.d.ts +0 -332
  150. package/build/src/modeling/legacy/DataProperty.d.ts.map +0 -1
  151. package/build/src/modeling/legacy/DataProperty.js +0 -415
  152. package/build/src/modeling/legacy/DataProperty.js.map +0 -1
  153. package/build/src/models/store/DataFile.d.ts +0 -31
  154. package/build/src/models/store/DataFile.d.ts.map +0 -1
  155. package/build/src/models/store/DataFile.js +0 -92
  156. package/build/src/models/store/DataFile.js.map +0 -1
  157. package/src/amf/AmfShapeGenerator.ts +0 -477
  158. package/src/modeling/legacy/DataAssociation.ts +0 -554
  159. package/src/modeling/legacy/DataEntity.ts +0 -1019
  160. package/src/modeling/legacy/DataEntityBuilder.ts +0 -236
  161. package/src/modeling/legacy/DataImpactAnalysis.ts +0 -530
  162. package/src/modeling/legacy/DataModel.ts +0 -276
  163. package/src/modeling/legacy/DataNamespace.ts +0 -929
  164. package/src/modeling/legacy/DataProperty.ts +0 -630
  165. package/src/models/store/DataFile.ts +0 -100
  166. package/tests/unit/modeling/legacy/amf_shape_generator.spec.ts +0 -1041
  167. package/tests/unit/modeling/legacy/data_association.spec.ts +0 -710
  168. package/tests/unit/modeling/legacy/data_entity.spec.ts +0 -2061
  169. package/tests/unit/modeling/legacy/data_entity_generator_json.spec.ts +0 -987
  170. package/tests/unit/modeling/legacy/data_entity_generator_xml.spec.ts +0 -1451
  171. package/tests/unit/modeling/legacy/data_model.spec.ts +0 -395
  172. package/tests/unit/modeling/legacy/data_namespace.spec.ts +0 -1312
  173. package/tests/unit/modeling/legacy/data_property.spec.ts +0 -887
  174. package/tests/unit/modeling/legacy/impact_analysis.spec.ts +0 -373
@@ -1,630 +0,0 @@
1
- import { IThing, Thing } from '../../models/Thing.js'
2
- import { nanoid } from '../../nanoid.js'
3
- import { DataNamespace } from './DataNamespace.js'
4
- import { IApiPropertyShape } from '../../amf/definitions/Shapes.js'
5
- import { AmfShapeGenerator } from '../../amf/AmfShapeGenerator.js'
6
- import { PropertyBinding, PropertyBindings, PropertyWebBindings } from '../Bindings.js'
7
- import { DataPropertyKind } from '../../models/kinds.js'
8
- import {
9
- type BinaryFormat,
10
- BinaryFormats,
11
- type DataPropertyAttribute,
12
- DataPropertyAttributes,
13
- type DataPropertyFormat,
14
- DataPropertyList,
15
- type DataPropertyType,
16
- DataPropertyTypes,
17
- type NumberFormat,
18
- NumberFormats,
19
- } from '../DataFormat.js'
20
- import type { DataEntity } from './DataEntity.js'
21
-
22
- /**
23
- * Describes the default value set on a property schema.
24
- * @deprecated
25
- */
26
- export interface SchemaDefaultValue {
27
- /**
28
- * The type of the default value.
29
- *
30
- * - `literal` The `value` should be used as-is.
31
- * - `function` The value represents the name of the function to be used.
32
- */
33
- type: 'literal' | 'function'
34
- /**
35
- * The actual value type depends on the `type`.
36
- * It is always a string and it has to be casted to the property's data type.
37
- */
38
- value: string
39
- }
40
-
41
- /**
42
- * A general schema definition for a property.
43
- * This is propagated to all bindings (when they support these properties).
44
- * @deprecated
45
- */
46
- export interface DataPropertySchema {
47
- /**
48
- * The minimum value of the property.
49
- *
50
- * By default it is inclusive value. Use the `exclusiveMinimum` property to make it exclusive.
51
- *
52
- * Used with:
53
- * - string
54
- * - number
55
- * - date
56
- * - time
57
- * - datetime
58
- */
59
- minimum?: number
60
- /**
61
- * The maximum value of the property.
62
- *
63
- * By default it is inclusive value. Use the `exclusiveMaximum` property to make it exclusive.
64
- *
65
- * Used with:
66
- * - string
67
- * - number
68
- * - date
69
- * - time
70
- * - datetime
71
- */
72
- maximum?: number
73
- /**
74
- * When set, the minimum value is exclusive.
75
- *
76
- * - When `false`: value ≥ minimum.
77
- * - When `true`: value > minimum.
78
- */
79
- exclusiveMinimum?: boolean
80
- /**
81
- * When set, the exclusiveMaximum value is exclusive.
82
- *
83
- * - When `false`: value ≤ maximum.
84
- * - When `true`: value < minimum.
85
- */
86
- exclusiveMaximum?: boolean
87
- /**
88
- * The multiplier value for a number scalar.
89
- *
90
- * Examples:
91
- * - if `1` then every integer is allowed
92
- * - if `2` than every even number is allowed
93
- * - if `0.5` than every number dividable by `0.5` is allowed
94
- */
95
- multipleOf?: number
96
- /**
97
- * The enum values for the property.
98
- * They are always encoded as strings. The actual type is defined in the `dataType` property.
99
- */
100
- enum?: string[]
101
- /**
102
- * The default value for the property.
103
- * This is always encoded as a string. The actual type is defined in the `dataType` property.
104
- */
105
- defaultValue?: SchemaDefaultValue
106
- /**
107
- * The example values for the property.
108
- * They are always encoded as strings. The actual type is defined in the `dataType` property.
109
- */
110
- examples?: string[]
111
- }
112
-
113
- /**
114
- * @deprecated
115
- */
116
- export interface IDataProperty {
117
- kind: typeof DataPropertyKind
118
- /**
119
- * The key of the namespace.
120
- */
121
- key: string
122
- /**
123
- * The data property description.
124
- */
125
- info: IThing
126
- /**
127
- * Wether the data property is required.
128
- */
129
- required?: boolean
130
- /**
131
- * Whether the data property allows multiple items.
132
- */
133
- multiple?: boolean
134
- /**
135
- * Whether this property describes a primary key of the entity.
136
- */
137
- primary?: boolean
138
- /**
139
- * Whether this property describes an indexed property of the entity.
140
- */
141
- index?: boolean
142
- /**
143
- * Whether the property is read only in the schema.
144
- */
145
- readOnly?: boolean
146
- /**
147
- * Whether the property is write only in the schema.
148
- */
149
- writeOnly?: boolean
150
- /**
151
- * Whether this property is deprecated.
152
- */
153
- deprecated?: boolean
154
- /**
155
- * Optional general purpose tags for the UI.
156
- */
157
- tags?: string[]
158
- /**
159
- * For future use.
160
- *
161
- * The keys of the taxonomy items associated with the property.
162
- */
163
- taxonomy?: string[]
164
- /**
165
- * The data type for this property.
166
- * Note, not all schemas support the same type. For example, defining `sint32`
167
- * works for protocol buffers, but does not for JSON. In such case we use default
168
- * translation `sint32` -> `number`. Another way it to create
169
- * a derivative entity for specific schema to describe specific schema case.
170
- */
171
- type: DataPropertyType
172
- /**
173
- * The general schema definition of this property.
174
- * This is propagated to all bindings (when they support these properties).
175
- */
176
- schema?: DataPropertySchema
177
- /**
178
- * The list of bindings for this property.
179
- *
180
- * A binding defines a translation from a data model to a specific format.
181
- * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs
182
- * or a protocol buffer schema.
183
- */
184
- bindings?: PropertyBinding[]
185
- }
186
-
187
- /**
188
- * @deprecated
189
- */
190
- export class DataProperty {
191
- kind = DataPropertyKind
192
-
193
- key = ''
194
-
195
- /**
196
- * The description of the data namespace.
197
- */
198
- info: Thing = Thing.fromName('')
199
-
200
- /**
201
- * Wether the data property is required.
202
- */
203
- required?: boolean
204
-
205
- /**
206
- * Whether the data property allows multiple items.
207
- */
208
- multiple?: boolean
209
-
210
- /**
211
- * Whether this property describes a primary key of the entity.
212
- */
213
- primary?: boolean
214
-
215
- /**
216
- * Whether this property describes an indexed property of the entity.
217
- */
218
- index?: boolean
219
-
220
- /**
221
- * Whether the property is read only in the schema.
222
- */
223
- readOnly?: boolean
224
-
225
- /**
226
- * Whether the property is write only in the schema.
227
- */
228
- writeOnly?: boolean
229
-
230
- /**
231
- * Whether this property is deprecated.
232
- */
233
- deprecated?: boolean
234
-
235
- /**
236
- * Optional general purpose tags for the UI.
237
- *
238
- * Note to implementations, use the `addTag()` method as it propagates the "tag" value in the namespace.
239
- */
240
- tags: string[] = []
241
-
242
- /**
243
- * Reserved for future use.
244
- *
245
- * The keys of the taxonomy items associated with the property.
246
- */
247
- taxonomy: string[] = []
248
-
249
- /**
250
- * The data type for this property.
251
- * Note, not all schemas support the same type. For example, defining `sint32`
252
- * works for protocol buffers but does not for JSON. In such case we use default
253
- * translation `sint32` -> `number`. Another way it to create
254
- * a derivative entity for specific schema to describe specific schema case.
255
- */
256
- type: DataPropertyType = 'string'
257
-
258
- /**
259
- * The general schema definition of this property.
260
- * This is propagated to all bindings (when they support these properties).
261
- */
262
- schema?: DataPropertySchema
263
- /**
264
- * The list of bindings for this property.
265
- *
266
- * A binding defines a translation from a data model to a specific format.
267
- * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs
268
- * or a protocol buffer schema.
269
- */
270
- bindings: PropertyBinding[] = []
271
-
272
- /**
273
- * @deprecated Use the direct import of types.
274
- */
275
- static get supportedTypes(): DataPropertyType[] {
276
- return [...DataPropertyTypes]
277
- }
278
-
279
- static fromName(root: DataNamespace, name: string): DataProperty {
280
- const property = new DataProperty(root)
281
- property.info = Thing.fromName(name)
282
- return property
283
- }
284
-
285
- static fromType(root: DataNamespace, type: DataPropertyType): DataProperty {
286
- const result = new DataProperty(root)
287
- result.type = type
288
- return result
289
- }
290
-
291
- /**
292
- * @param input The data property definition to restore.
293
- */
294
- constructor(
295
- public root: DataNamespace,
296
- input?: string | IDataProperty
297
- ) {
298
- let init: IDataProperty
299
- if (typeof input === 'string') {
300
- init = JSON.parse(input)
301
- } else if (typeof input === 'object') {
302
- init = input
303
- } else {
304
- init = {
305
- kind: DataPropertyKind,
306
- key: nanoid(),
307
- info: Thing.fromName('').toJSON(),
308
- type: 'string',
309
- }
310
- }
311
- this.new(init)
312
- }
313
-
314
- new(init: IDataProperty): void {
315
- if (!DataProperty.isDataProperty(init)) {
316
- throw new Error(`Not a data property.`)
317
- }
318
- const {
319
- info,
320
- key = nanoid(),
321
- kind = DataPropertyKind,
322
- multiple,
323
- required,
324
- type = DataPropertyList.string,
325
- index,
326
- primary,
327
- readOnly,
328
- writeOnly,
329
- tags,
330
- taxonomy,
331
- deprecated,
332
- schema,
333
- bindings,
334
- } = init
335
- this.kind = kind
336
- this.key = key
337
- this.type = type
338
- if (info) {
339
- this.info = new Thing(info)
340
- } else {
341
- this.info = Thing.fromName('')
342
- }
343
- if (typeof multiple === 'boolean') {
344
- this.multiple = multiple
345
- } else {
346
- this.multiple = undefined
347
- }
348
- if (typeof required === 'boolean') {
349
- this.required = required
350
- } else {
351
- this.required = undefined
352
- }
353
- if (typeof index === 'boolean') {
354
- this.index = index
355
- } else {
356
- this.index = undefined
357
- }
358
- if (typeof deprecated === 'boolean') {
359
- this.deprecated = deprecated
360
- } else {
361
- this.deprecated = undefined
362
- }
363
- if (typeof primary === 'boolean') {
364
- this.primary = primary
365
- } else {
366
- this.primary = undefined
367
- }
368
- if (typeof readOnly === 'boolean') {
369
- this.readOnly = readOnly
370
- } else {
371
- this.readOnly = undefined
372
- }
373
- if (typeof writeOnly === 'boolean') {
374
- this.writeOnly = writeOnly
375
- } else {
376
- this.writeOnly = undefined
377
- }
378
- if (Array.isArray(tags)) {
379
- this.tags = [...tags]
380
- } else {
381
- this.tags = []
382
- }
383
- if (Array.isArray(taxonomy)) {
384
- this.taxonomy = [...taxonomy]
385
- } else {
386
- this.taxonomy = []
387
- }
388
- if (schema) {
389
- this.schema = structuredClone(schema)
390
- } else {
391
- this.schema = undefined
392
- }
393
- if (Array.isArray(bindings)) {
394
- this.bindings = bindings.map((i) => structuredClone(i))
395
- } else {
396
- this.bindings = []
397
- }
398
- }
399
-
400
- static isDataProperty(input: unknown): boolean {
401
- const typed = input as IDataProperty
402
- if (!input || typed.kind !== DataPropertyKind) {
403
- return false
404
- }
405
- return true
406
- }
407
-
408
- toJSON(): IDataProperty {
409
- const result: IDataProperty = {
410
- kind: DataPropertyKind,
411
- info: this.info.toJSON(),
412
- key: this.key,
413
- type: this.type || DataPropertyList.string,
414
- }
415
- if (typeof this.index === 'boolean') {
416
- result.index = this.index
417
- }
418
- if (typeof this.deprecated === 'boolean') {
419
- result.deprecated = this.deprecated
420
- }
421
- if (typeof this.primary === 'boolean') {
422
- result.primary = this.primary
423
- }
424
- if (typeof this.multiple === 'boolean') {
425
- result.multiple = this.multiple
426
- }
427
- if (typeof this.required === 'boolean') {
428
- result.required = this.required
429
- }
430
- if (typeof this.readOnly === 'boolean') {
431
- result.readOnly = this.readOnly
432
- }
433
- if (typeof this.writeOnly === 'boolean') {
434
- result.writeOnly = this.writeOnly
435
- }
436
- if (Array.isArray(this.tags) && this.tags.length) {
437
- result.tags = [...this.tags]
438
- }
439
- if (Array.isArray(this.taxonomy) && this.taxonomy.length) {
440
- result.taxonomy = [...this.taxonomy]
441
- }
442
- if (this.schema) {
443
- result.schema = structuredClone(this.schema)
444
- }
445
- if (Array.isArray(this.bindings) && this.bindings.length) {
446
- result.bindings = this.bindings.map((i) => structuredClone(i))
447
- }
448
- return result
449
- }
450
-
451
- /**
452
- * Removes self from the parent entity and the namespace definition.
453
- */
454
- remove(): void {
455
- const { root } = this
456
- const entity = root.definitions.entities.find((i) => i.properties.some((j) => j.key === this.key))
457
- if (entity) {
458
- const assocIndex = entity.properties.findIndex((i) => i.key === this.key)
459
- entity.properties.splice(assocIndex, 1)
460
- }
461
- const defIndex = this.root.definitions.properties.findIndex((i) => i.key === this.key)
462
- if (defIndex >= 0) {
463
- this.root.definitions.properties.splice(defIndex, 1)
464
- }
465
- }
466
-
467
- /**
468
- * Adds a new tag to the property. It also populates the root namespace's tags when tag is new.
469
- *
470
- * Note, it does nothing when the tag is already defined.
471
- *
472
- * @param tag The tag to add.
473
- */
474
- addTag(tag: string): void {
475
- if (!tag) {
476
- return
477
- }
478
- const lower = tag.toLowerCase()
479
- const { tags } = this
480
- if (tags.some((t) => t.toLowerCase() === lower)) {
481
- return
482
- }
483
- tags.push(tag)
484
- const { definitions } = this.root
485
- if (!definitions.tags.some((t) => t.toLowerCase() === lower)) {
486
- definitions.tags.push(tag)
487
- }
488
- }
489
-
490
- /**
491
- * Removes a tag from the property. Unlike the `addTag()` this won't remove a `tag` from the root namespace.
492
- *
493
- * @param tag The tag to remove.
494
- */
495
- removeTag(tag: string): void {
496
- if (!tag) {
497
- return
498
- }
499
- const lower = tag.toLowerCase()
500
- const { tags } = this
501
- const index = tags.findIndex((t) => t.toLowerCase() === lower)
502
- if (index >= 0) {
503
- tags.splice(index, 1)
504
- }
505
- }
506
-
507
- /**
508
- * Creates a Property Shape of AMF.
509
- * The property itself is auto-generated. If the `schema` is defined then it is used
510
- * as the `range` of the property. Otherwise basic shape is generated for the range.
511
- *
512
- * This is a preferred way of reading the AMF shape as this synchronizes changed
513
- * data properties with the shape definition.
514
- *
515
- * @returns AMF property shape definition.
516
- */
517
- toApiShape(): IApiPropertyShape {
518
- const serializer = new AmfShapeGenerator()
519
- return serializer.property(this)
520
- }
521
-
522
- /**
523
- * Checks whether the passed value is one of the supported data types.
524
- * @param value The value to test
525
- * @returns True when the passed value is one of the supported data types.
526
- */
527
- static isValidType(value: unknown): value is DataPropertyType {
528
- if (typeof value !== 'string') {
529
- return false
530
- }
531
- return DataPropertyTypes.includes(value as DataPropertyType)
532
- }
533
-
534
- /**
535
- * Checks whether the passed value is one of the supported data property attributes.
536
- * @param value The value to test
537
- * @returns True when the passed value is one of the supported data property attributes.
538
- */
539
- static isValidAttribute(value: unknown): value is DataPropertyAttribute {
540
- if (typeof value !== 'string') {
541
- return false
542
- }
543
- return DataPropertyAttributes.includes(value as DataPropertyAttribute)
544
- }
545
-
546
- /**
547
- * Checks whether the passed value of one of the supported `format` values.
548
- *
549
- * @param value The value to test
550
- * @returns `true` when the value is one of the supported `format` values.
551
- */
552
- static isValidFormat(value: unknown): value is DataPropertyFormat {
553
- if (value === undefined) {
554
- // It is the valid value.
555
- return true
556
- }
557
- if (typeof value !== 'string') {
558
- return false
559
- }
560
- if (NumberFormats.includes(value as NumberFormat)) {
561
- return true
562
- }
563
- if (BinaryFormats.includes(value as BinaryFormat)) {
564
- return true
565
- }
566
- return false
567
- }
568
-
569
- /**
570
- * Creates the `schema` object if missing and returns it.
571
- * @returns The schema object.
572
- */
573
- ensureSchema(): DataPropertySchema {
574
- if (!this.schema) {
575
- this.schema = {}
576
- }
577
- return this.schema
578
- }
579
-
580
- /**
581
- * Creates if not existing and returns web bindings definition.
582
- * @returns The web binding definition
583
- */
584
- getWebBinding(): PropertyWebBindings {
585
- let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined
586
- if (!object) {
587
- object = { type: 'web', schema: {} } as PropertyBinding
588
- this.bindings.push(object)
589
- }
590
- return object.schema as PropertyWebBindings
591
- }
592
-
593
- /**
594
- * Returns the schema value of the binding, if any was created.
595
- * @param type The type of the binding to read.
596
- * @returns The binding schema, if any
597
- */
598
- readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {
599
- const item = this.bindings.find((i) => i.type === type) as PropertyBinding
600
- return item?.schema
601
- }
602
-
603
- /**
604
- * Returns a parent data entity where this data property exist.
605
- */
606
- getParentInstance(): DataEntity | undefined {
607
- return this.root.definitions.entities.find((e) => e.properties.some((e) => e.key === this.key))
608
- }
609
-
610
- /**
611
- * Checks whether the property is a child of the given namespace, data model, or an entity.
612
- * The relationship doesn't have to be direct, as long as the property is in the hierarchy it will return true.
613
- *
614
- * @param key The key of the parent to check.
615
- * @returns True if this data property is a child of the given namespace, data model, or an entity
616
- */
617
- isChildOf(key: string): boolean {
618
- if (this.key === key) {
619
- return false
620
- }
621
- const parent = this.getParentInstance()
622
- if (!parent) {
623
- return false
624
- }
625
- if (parent.key === key) {
626
- return true
627
- }
628
- return parent.isChildOf(key)
629
- }
630
- }
@@ -1,100 +0,0 @@
1
- import { nanoid } from '../../nanoid.js'
2
- import { File, IFile } from './File.js'
3
- import { Thing } from '../Thing.js'
4
- import { DataNamespace, IDataNamespace } from '../../modeling/legacy/DataNamespace.js'
5
- import { DataFileKind as Kind } from '../kinds.js'
6
-
7
- export interface IDataFile extends IFile {
8
- kind: typeof Kind
9
- }
10
-
11
- /**
12
- * Used by the store. A file definition for the DataNamespace
13
- * @deprecated Use DomainFile instead.
14
- */
15
- export class DataFile extends File {
16
- override kind = Kind
17
-
18
- /**
19
- * Creates the file definition for a DataNamespace contents.
20
- *
21
- * @param input The data namespace instance or schema.
22
- * @param owner Optional owner to set.
23
- * @deprecated Use DomainFile instead.
24
- */
25
- static fromDataNamespace(input: DataNamespace | IDataNamespace, organization: string, owner?: string): DataFile {
26
- let final: IDataNamespace
27
- if (typeof (input as DataNamespace).toJSON === 'function') {
28
- final = (input as DataNamespace).toJSON()
29
- } else {
30
- final = input as IDataNamespace
31
- }
32
- const init: IDataFile = {
33
- kind: Kind,
34
- key: final.key,
35
- organization,
36
- info: { ...final.info },
37
- lastModified: { user: owner || '', time: 0, byMe: false },
38
- owner,
39
- parents: [],
40
- permissionIds: [],
41
- permissions: [],
42
- }
43
- return new DataFile(init)
44
- }
45
-
46
- /**
47
- * @param name The name to set.
48
- * @param owner The user id that is the owner of the file.
49
- */
50
- static override fromName(name: string, organization: string, owner?: string): DataFile {
51
- return super.fromName(name, organization, owner, Kind) as DataFile
52
- }
53
-
54
- constructor(input?: string | IDataFile) {
55
- super()
56
- let init: IDataFile
57
- if (typeof input === 'string') {
58
- init = JSON.parse(input)
59
- } else if (typeof input === 'object') {
60
- init = input
61
- } else {
62
- init = {
63
- kind: Kind,
64
- key: nanoid(),
65
- organization: '',
66
- info: Thing.fromName('').toJSON(),
67
- parents: [],
68
- permissionIds: [],
69
- permissions: [],
70
- lastModified: { user: '', time: 0, byMe: false },
71
- }
72
- }
73
- this.new(init)
74
- }
75
-
76
- override new(init: IDataFile): this {
77
- if (!DataFile.isDataFile(init)) {
78
- throw new Error(`Not a data file.`)
79
- }
80
- super.new(init)
81
- this.kind = Kind
82
- return this
83
- }
84
-
85
- static isDataFile(input: unknown): boolean {
86
- const typed = input as IDataFile
87
- if (!input || typed.kind !== Kind) {
88
- return false
89
- }
90
- return true
91
- }
92
-
93
- override toJSON(): IDataFile {
94
- const result: IDataFile = {
95
- ...super.toJSON(),
96
- kind: Kind,
97
- }
98
- return result
99
- }
100
- }