@api-client/core 0.6.13 → 0.6.16

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 (155) hide show
  1. package/build/browser.d.ts +9 -2
  2. package/build/browser.js +12 -2
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +9 -2
  5. package/build/index.js +12 -2
  6. package/build/index.js.map +1 -1
  7. package/build/src/amf/AmfMixin.d.ts +395 -0
  8. package/build/src/amf/AmfMixin.js +1146 -0
  9. package/build/src/amf/AmfMixin.js.map +1 -0
  10. package/build/src/amf/AmfSerializer.d.ts +136 -0
  11. package/build/src/amf/AmfSerializer.js +1913 -0
  12. package/build/src/amf/AmfSerializer.js.map +1 -0
  13. package/build/src/amf/AmfShapeGenerator.d.ts +85 -0
  14. package/build/src/amf/AmfShapeGenerator.js +385 -0
  15. package/build/src/amf/AmfShapeGenerator.js.map +1 -0
  16. package/build/src/amf/AmfTypes.d.ts +24 -0
  17. package/build/src/amf/AmfTypes.js +122 -0
  18. package/build/src/amf/AmfTypes.js.map +1 -0
  19. package/build/src/amf/ApiExampleGenerator.d.ts +36 -0
  20. package/build/src/amf/ApiExampleGenerator.js +109 -0
  21. package/build/src/amf/ApiExampleGenerator.js.map +1 -0
  22. package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +67 -0
  23. package/build/src/amf/ApiMonacoSchemaGenerator.js +243 -0
  24. package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -0
  25. package/build/src/amf/ApiSchemaGenerator.d.ts +55 -0
  26. package/build/src/amf/ApiSchemaGenerator.js +94 -0
  27. package/build/src/amf/ApiSchemaGenerator.js.map +1 -0
  28. package/build/src/amf/ApiSchemaValues.d.ts +98 -0
  29. package/build/src/amf/ApiSchemaValues.js +382 -0
  30. package/build/src/amf/ApiSchemaValues.js.map +1 -0
  31. package/build/src/amf/Utils.d.ts +41 -0
  32. package/build/src/amf/Utils.js +176 -0
  33. package/build/src/amf/Utils.js.map +1 -0
  34. package/build/src/amf/data-node/DataNodeBase.d.ts +31 -0
  35. package/build/src/amf/data-node/DataNodeBase.js +77 -0
  36. package/build/src/amf/data-node/DataNodeBase.js.map +1 -0
  37. package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +15 -0
  38. package/build/src/amf/data-node/JsonDataNodeGenerator.js +24 -0
  39. package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -0
  40. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +13 -0
  41. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +42 -0
  42. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -0
  43. package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +21 -0
  44. package/build/src/amf/data-node/XmlDataNodeGenerator.js +30 -0
  45. package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -0
  46. package/build/src/amf/definitions/Amf.d.ts +362 -0
  47. package/build/src/amf/definitions/Amf.js +2 -0
  48. package/build/src/amf/definitions/Amf.js.map +1 -0
  49. package/build/src/amf/definitions/Api.d.ts +381 -0
  50. package/build/src/amf/definitions/Api.js +2 -0
  51. package/build/src/amf/definitions/Api.js.map +1 -0
  52. package/build/src/amf/definitions/Base.d.ts +11 -0
  53. package/build/src/amf/definitions/Base.js +2 -0
  54. package/build/src/amf/definitions/Base.js.map +1 -0
  55. package/build/src/amf/definitions/Namespace.d.ts +311 -0
  56. package/build/src/amf/definitions/Namespace.js +330 -0
  57. package/build/src/amf/definitions/Namespace.js.map +1 -0
  58. package/build/src/amf/definitions/Shapes.d.ts +309 -0
  59. package/build/src/amf/definitions/Shapes.js +87 -0
  60. package/build/src/amf/definitions/Shapes.js.map +1 -0
  61. package/build/src/amf/models/AmfDataNode.d.ts +68 -0
  62. package/build/src/amf/models/AmfDataNode.js +188 -0
  63. package/build/src/amf/models/AmfDataNode.js.map +1 -0
  64. package/build/src/amf/shape/ShapeBase.d.ts +75 -0
  65. package/build/src/amf/shape/ShapeBase.js +90 -0
  66. package/build/src/amf/shape/ShapeBase.js.map +1 -0
  67. package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +46 -0
  68. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +406 -0
  69. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -0
  70. package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +84 -0
  71. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +820 -0
  72. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -0
  73. package/build/src/models/Thing.d.ts +17 -0
  74. package/build/src/models/Thing.js +19 -1
  75. package/build/src/models/Thing.js.map +1 -1
  76. package/build/src/models/data/Bindings.d.ts +161 -0
  77. package/build/src/models/data/Bindings.js +2 -0
  78. package/build/src/models/data/Bindings.js.map +1 -0
  79. package/build/src/models/data/DataAssociation.d.ts +135 -14
  80. package/build/src/models/data/DataAssociation.js +154 -21
  81. package/build/src/models/data/DataAssociation.js.map +1 -1
  82. package/build/src/models/data/DataAssociationSchema.d.ts +36 -0
  83. package/build/src/models/data/DataEntity.d.ts +76 -4
  84. package/build/src/models/data/DataEntity.js +136 -9
  85. package/build/src/models/data/DataEntity.js.map +1 -1
  86. package/build/src/models/data/DataFile.d.ts +3 -0
  87. package/build/src/models/data/DataFile.js +3 -0
  88. package/build/src/models/data/DataFile.js.map +1 -1
  89. package/build/src/models/data/DataModel.d.ts +1 -1
  90. package/build/src/models/data/DataModel.js.map +1 -1
  91. package/build/src/models/data/DataNamespace.d.ts +6 -0
  92. package/build/src/models/data/DataNamespace.js +11 -1
  93. package/build/src/models/data/DataNamespace.js.map +1 -1
  94. package/build/src/models/data/DataProperty.d.ts +131 -36
  95. package/build/src/models/data/DataProperty.js +200 -17
  96. package/build/src/models/data/DataProperty.js.map +1 -1
  97. package/data/apis/oas-date/oas-date.yaml +28 -0
  98. package/data/apis/oas-types/oas-types.yaml +159 -0
  99. package/data/apis/oas-unions/oas-unions.yaml +75 -0
  100. package/data/apis/raml-date/raml-date.raml +28 -0
  101. package/data/apis/recursive/recursive.raml +14 -0
  102. package/data/apis/schema-api/examples/person.json +14 -0
  103. package/data/apis/schema-api/examples/person.raml +14 -0
  104. package/data/apis/schema-api/examples/person.url.encoded +1 -0
  105. package/data/apis/schema-api/examples/person.xml +14 -0
  106. package/data/apis/schema-api/library/demo-types.raml +43 -0
  107. package/data/apis/schema-api/schema-api.raml +644 -0
  108. package/data/apis/schema-api/schemas/person.json +104 -0
  109. package/data/apis/schema-api/schemas/person.xsd +26 -0
  110. package/data/apis/schema-api/types/DemoPerson.raml +67 -0
  111. package/data/model.js +106 -0
  112. package/data/models/oas-date.json +637 -0
  113. package/data/models/oas-types.json +5352 -0
  114. package/data/models/oas-unions.json +1881 -0
  115. package/data/models/raml-date.json +1096 -0
  116. package/data/models/recursive.json +610 -0
  117. package/data/models/schema-api.json +37319 -0
  118. package/package.json +9 -6
  119. package/src/amf/AmfMixin.ts +1623 -0
  120. package/src/amf/AmfSerializer.ts +2028 -0
  121. package/src/amf/AmfShapeGenerator.ts +400 -0
  122. package/src/amf/AmfTypes.ts +126 -0
  123. package/src/amf/ApiExampleGenerator.ts +112 -0
  124. package/src/amf/ApiMonacoSchemaGenerator.ts +296 -0
  125. package/src/amf/ApiSchemaGenerator.ts +108 -0
  126. package/src/amf/ApiSchemaValues.ts +411 -0
  127. package/src/amf/Utils.ts +182 -0
  128. package/src/amf/data-node/DataNodeBase.ts +81 -0
  129. package/src/amf/data-node/JsonDataNodeGenerator.ts +26 -0
  130. package/src/amf/data-node/README.md +3 -0
  131. package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +43 -0
  132. package/src/amf/data-node/XmlDataNodeGenerator.ts +38 -0
  133. package/src/amf/definitions/Amf.ts +443 -0
  134. package/src/amf/definitions/Api.ts +427 -0
  135. package/src/amf/definitions/Base.ts +13 -0
  136. package/src/amf/definitions/Namespace.ts +341 -0
  137. package/src/amf/definitions/Shapes.ts +414 -0
  138. package/src/amf/models/AmfDataNode.ts +200 -0
  139. package/src/amf/shape/README.md +4 -0
  140. package/src/amf/shape/ShapeBase.ts +160 -0
  141. package/src/amf/shape/ShapeJsonSchemaGenerator.ts +422 -0
  142. package/src/amf/shape/ShapeXmlSchemaGenerator.ts +876 -0
  143. package/src/models/Thing.ts +25 -1
  144. package/src/models/data/Bindings.ts +186 -0
  145. package/src/models/data/DataAssociation.ts +226 -29
  146. package/src/models/data/DataAssociationSchema.ts +38 -0
  147. package/src/models/data/DataEntity.ts +170 -13
  148. package/src/models/data/DataFile.ts +3 -0
  149. package/src/models/data/DataModel.ts +1 -1
  150. package/src/models/data/DataNamespace.ts +16 -1
  151. package/src/models/data/DataProperty.ts +250 -47
  152. package/build/src/models/data/DataPropertySchema.d.ts +0 -125
  153. package/build/src/models/data/DataPropertySchema.js +0 -33
  154. package/build/src/models/data/DataPropertySchema.js.map +0 -1
  155. package/src/models/data/DataPropertySchema.ts +0 -156
@@ -1,51 +1,44 @@
1
+ import { Core as JsonCore } from '@api-client/json';
1
2
  import { IThing, Thing } from "../Thing.js";
2
3
  import v4 from '../../lib/uuid.js';
3
4
  import { DataNamespace } from "./DataNamespace.js";
4
- import { IDataPropertySchema } from "./DataPropertySchema.js";
5
+ import { IPropertyShape } from "../../amf/definitions/Shapes.js";
6
+ import { AmfShapeGenerator } from '../../amf/AmfShapeGenerator.js';
7
+ import { IPropertyBindings, IPropertySchema } from './Bindings.js';
5
8
 
6
- export type DataPropertyType = 'string' | 'number' | 'nil' | 'boolean' | 'date' | 'datetime' |
7
- 'time' | 'bytes' | 'any' | 'file';
9
+ export type DataPropertyType = 'string' | 'number' | 'integer' | 'nil' | 'boolean' | 'date' | 'datetime' | 'time' | 'any' | 'binary';
8
10
  export const DataPropertyTypes: DataPropertyType[] = [
9
- 'string', 'number', 'nil', 'boolean', 'date', 'datetime', 'time', 'bytes', 'any', 'file'
11
+ 'string', 'number', 'integer', 'nil', 'boolean', 'date', 'datetime', 'time' , 'any', 'binary'
10
12
  ];
11
13
 
12
14
  export enum DataPropertyList {
13
15
  string = 'string',
14
16
  number = 'number',
17
+ integer = 'integer', // RAML, OAS and JSON schema define numbers and integers separately
15
18
  nil = 'nil',
16
19
  boolean = 'boolean',
17
20
  date = 'date',
18
21
  datetime = 'datetime',
19
22
  time = 'time',
20
- bytes = 'bytes',
21
23
  any = 'any',
22
- file = 'file',
24
+ file = 'binary',
23
25
  }
24
26
 
25
- export const Kind = 'Core#DataProperty';
26
-
27
- export interface IPropertySchema<T> {
27
+ export type DateFormat = 'rfc3339' | 'rfc2616';
28
+ export const DateFormats: DateFormat[] = ['rfc3339', 'rfc2616'];
29
+ export enum DateFormatList {
28
30
  /**
29
- * Whether it is a general schema for the property.
30
- * All other schemas inherit from this one. This allows creating global schema description
31
- * like examples, default values, minimum value, etc and then use it as a base to generate specific formats.
32
- *
33
- * A property may not have a global schema.
31
+ * The "date-time" notation of RFC3339
34
32
  */
35
- global?: boolean;
33
+ rfc3339 = 'rfc3339',
36
34
  /**
37
- * The mime type this schema describes.
38
- * For JSON it is `application/json`, for XML it is `application/xml` (or `text/xml`) adn so on.
39
- *
40
- * Note, when this value is missing then it is assumed that the schema is `global`.
35
+ * The format defined in RFC2616.
41
36
  */
42
- format?: string;
43
- /**
44
- * The schema definition.
45
- */
46
- value: IDataPropertySchema<T>;
37
+ rfc2616 = 'rfc2616',
47
38
  }
48
39
 
40
+ export const Kind = 'Core#DataProperty';
41
+
49
42
  export interface IDataProperty {
50
43
  kind: typeof Kind;
51
44
  /**
@@ -72,6 +65,25 @@ export interface IDataProperty {
72
65
  * Whether this property describes an indexed property of the entity.
73
66
  */
74
67
  index?: boolean;
68
+ /**
69
+ * Whether the property is read only in the schema.
70
+ */
71
+ readOnly?: boolean;
72
+ /**
73
+ * Whether the property is write only in the schema.
74
+ */
75
+ writeOnly?: boolean;
76
+ /**
77
+ * Whether the attribute is hidden in the schema (not a part of it).
78
+ *
79
+ * The hidden attribute should only appear in the adapted attribute.
80
+ * Has no effect when added to the "main" attribute.
81
+ */
82
+ hidden?: boolean;
83
+ /**
84
+ * Whether this property is deprecated.
85
+ */
86
+ deprecated?: boolean;
75
87
  /**
76
88
  * Optional general purpose tags for the UI.
77
89
  */
@@ -90,16 +102,30 @@ export interface IDataProperty {
90
102
  * a derivative entity for specific schema to describe specific schema case.
91
103
  */
92
104
  type: DataPropertyType;
93
-
94
105
  /**
95
- * While the `DataProperty` describes the general shape of the data and can be used to
96
- * model the structure of the data in the system, a schema describes hwo the data
97
- * should be serialized into a specific format. This allows adding example values,
98
- * default values, specifying data format, etc. The assumption here is
99
- * that with enough specifics provided by the user (a domain specialist)
100
- * we can automatically generate a schema for the given format.
106
+ * The general schema definition of this property.
107
+ * This is propagated to all bindings (when they support these properties).
108
+ *
109
+ * Note, schema can only occur on an adapted property. Has no effect on the "main"
110
+ * property.
111
+ */
112
+ schema?: IPropertySchema;
113
+ /**
114
+ * The list of bindings for this property.
115
+ *
116
+ * A binding defines a translation from a data model to a specific format.
117
+ * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs
118
+ * or a protocol buffer schema.
119
+ */
120
+ bindings?: IPropertyBindings[];
121
+ /**
122
+ * The key of the property that is adapted by this property.
123
+ * Adapted properties can manipulate the shape of the schema for the property.
124
+ *
125
+ * Each value defined on the adapted property changes the original value defined on
126
+ * the property.
101
127
  */
102
- schemas?: IPropertySchema<unknown>[];
128
+ adapts?: string;
103
129
  }
104
130
 
105
131
  export class DataProperty {
@@ -132,8 +158,32 @@ export class DataProperty {
132
158
  */
133
159
  index?: boolean;
134
160
 
161
+ /**
162
+ * Whether the property is read only in the schema.
163
+ */
164
+ readOnly?: boolean;
165
+
166
+ /**
167
+ * Whether the property is write only in the schema.
168
+ */
169
+ writeOnly?: boolean;
170
+
171
+ /**
172
+ * Whether the attribute is hidden in the schema (not a part of it).
173
+ * The hidden attribute should only appear in the adapted attribute.
174
+ * Has no effect when added to the "main" attribute.
175
+ */
176
+ hidden?: boolean;
177
+
178
+ /**
179
+ * Whether this property is deprecated.
180
+ */
181
+ deprecated?: boolean;
182
+
135
183
  /**
136
184
  * Optional general purpose tags for the UI.
185
+ *
186
+ * Note to implementations, use the `addTag()` method as it propagates the "tag" value in the namespace.
137
187
  */
138
188
  tags: string[] = [];
139
189
 
@@ -154,14 +204,30 @@ export class DataProperty {
154
204
  type: DataPropertyType = 'string';
155
205
 
156
206
  /**
157
- * While the `DataProperty` describes the general shape of the data and can be used to
158
- * model the structure of the data in the system, a schema describes hwo the data
159
- * should be serialized into a specific format. This allows adding example values,
160
- * default values, specifying data format, etc. The assumption here is
161
- * that with enough specifics provided by the user (a domain specialist)
162
- * we can automatically generate a schema for the given format.
207
+ * The general schema definition of this property.
208
+ * This is propagated to all bindings (when they support these properties).
209
+ *
210
+ * Note, schema can only occur on an adapted property. Has no effect on the "main"
211
+ * property.
212
+ */
213
+ schema?: IPropertySchema;
214
+ /**
215
+ * The list of bindings for this property.
216
+ *
217
+ * A binding defines a translation from a data model to a specific format.
218
+ * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs
219
+ * or a protocol buffer schema.
220
+ */
221
+ bindings: IPropertyBindings[] = [];
222
+
223
+ /**
224
+ * The key of the property that is adapted by this property.
225
+ * Adapted properties can manipulate the shape of the schema for the property.
226
+ *
227
+ * Each value defined on the adapted property changes the original value defined on
228
+ * the property.
163
229
  */
164
- schemas: IPropertySchema<unknown>[] = [];
230
+ adapts?: string;
165
231
 
166
232
  static get supportedTypes(): DataPropertyType[] {
167
233
  return [...DataPropertyTypes];
@@ -182,7 +248,7 @@ export class DataProperty {
182
248
  /**
183
249
  * @param input The data property definition to restore.
184
250
  */
185
- constructor(protected root: DataNamespace, input?: string | IDataProperty) {
251
+ constructor(public root: DataNamespace, input?: string | IDataProperty) {
186
252
  let init: IDataProperty;
187
253
  if (typeof input === 'string') {
188
254
  init = JSON.parse(input);
@@ -203,7 +269,11 @@ export class DataProperty {
203
269
  if (!DataProperty.isDataProperty(init)) {
204
270
  throw new Error(`Not a data property.`);
205
271
  }
206
- const { info, key = v4(), kind = Kind, multiple, required, type = DataPropertyList.string, index, primary, tags, taxonomy, schemas } = init;
272
+ const {
273
+ info, key = v4(), kind = Kind, multiple, required, type = DataPropertyList.string,
274
+ index, primary, readOnly, writeOnly, adapts, hidden, tags, taxonomy, deprecated,
275
+ schema, bindings,
276
+ } = init;
207
277
  this.kind = kind;
208
278
  this.key = key;
209
279
  this.type = type;
@@ -227,11 +297,36 @@ export class DataProperty {
227
297
  } else {
228
298
  this.index = undefined;
229
299
  }
300
+ if (typeof deprecated === 'boolean') {
301
+ this.deprecated = deprecated;
302
+ } else {
303
+ this.deprecated = undefined;
304
+ }
230
305
  if (typeof primary === 'boolean') {
231
306
  this.primary = primary;
232
307
  } else {
233
308
  this.primary = undefined;
234
309
  }
310
+ if (typeof readOnly === 'boolean') {
311
+ this.readOnly = readOnly;
312
+ } else {
313
+ this.readOnly = undefined;
314
+ }
315
+ if (typeof writeOnly === 'boolean') {
316
+ this.writeOnly = writeOnly;
317
+ } else {
318
+ this.writeOnly = undefined;
319
+ }
320
+ if (typeof hidden === 'boolean') {
321
+ this.hidden = hidden;
322
+ } else {
323
+ this.hidden = undefined;
324
+ }
325
+ if (typeof adapts === 'string') {
326
+ this.adapts = adapts;
327
+ } else {
328
+ this.adapts = undefined;
329
+ }
235
330
  if (Array.isArray(tags)) {
236
331
  this.tags = [...tags];
237
332
  } else {
@@ -242,10 +337,15 @@ export class DataProperty {
242
337
  } else {
243
338
  this.taxonomy = [];
244
339
  }
245
- if (Array.isArray(schemas)) {
246
- this.schemas = schemas.map(i => ({ ...i }));
340
+ if (schema) {
341
+ this.schema = JsonCore.clone(schema);
342
+ } else {
343
+ this.schema = undefined;
344
+ }
345
+ if (Array.isArray(bindings)) {
346
+ this.bindings = bindings.map(i => JsonCore.clone(i));
247
347
  } else {
248
- this.schemas = [];
348
+ this.bindings = [];
249
349
  }
250
350
  }
251
351
 
@@ -267,6 +367,9 @@ export class DataProperty {
267
367
  if (typeof this.index === 'boolean') {
268
368
  result.index = this.index;
269
369
  }
370
+ if (typeof this.deprecated === 'boolean') {
371
+ result.deprecated = this.deprecated;
372
+ }
270
373
  if (typeof this.primary === 'boolean') {
271
374
  result.primary = this.primary;
272
375
  }
@@ -276,14 +379,29 @@ export class DataProperty {
276
379
  if (typeof this.required === 'boolean') {
277
380
  result.required = this.required;
278
381
  }
382
+ if (typeof this.readOnly === 'boolean') {
383
+ result.readOnly = this.readOnly;
384
+ }
385
+ if (typeof this.writeOnly === 'boolean') {
386
+ result.writeOnly = this.writeOnly;
387
+ }
388
+ if (typeof this.hidden === 'boolean') {
389
+ result.hidden = this.hidden;
390
+ }
391
+ if (this.adapts) {
392
+ result.adapts = this.adapts;
393
+ }
279
394
  if (Array.isArray(this.tags) && this.tags.length) {
280
395
  result.tags = [...this.tags];
281
396
  }
282
397
  if (Array.isArray(this.taxonomy) && this.taxonomy.length) {
283
398
  result.taxonomy = [...this.taxonomy];
284
399
  }
285
- if (Array.isArray(this.schemas) && this.schemas.length) {
286
- result.schemas = this.schemas.map(i => ({ ...i }));
400
+ if (this.schema) {
401
+ result.schema = JsonCore.clone(this.schema);
402
+ }
403
+ if (Array.isArray(this.bindings) && this.bindings.length) {
404
+ result.taxonomy = this.taxonomy.map(i => JsonCore.clone(i));
287
405
  }
288
406
  return result;
289
407
  }
@@ -292,7 +410,7 @@ export class DataProperty {
292
410
  * Removes self from the parent entity and the namespace definition.
293
411
  */
294
412
  remove(): void {
295
- const { root } = this;
413
+ const { root, adapts } = this;
296
414
  const entity = root.definitions.entities.find(i => i.properties.some(j => j === this));
297
415
  if (entity) {
298
416
  const assocIndex = entity.properties.findIndex(i => i === this);
@@ -302,5 +420,90 @@ export class DataProperty {
302
420
  if (defIndex >= 0) {
303
421
  this.root.definitions.properties.splice(defIndex, 1);
304
422
  }
423
+ if (adapts) {
424
+ const adaptsIndex = this.root.definitions.properties.findIndex(i => i.key === adapts);
425
+ if (adaptsIndex >= 0) {
426
+ this.root.definitions.properties.splice(adaptsIndex, 1);
427
+ }
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Adds a new tag to the property. It also populates the root namespace's tags when tag is new.
433
+ *
434
+ * Note, it does nothing when the tag is already defined.
435
+ *
436
+ * @param tag The tag to add.
437
+ */
438
+ addTag(tag: string): void {
439
+ if (!tag) {
440
+ return;
441
+ }
442
+ const lower = tag.toLowerCase();
443
+ const { tags } = this;
444
+ if (tags.some(t => t.toLowerCase() === lower)) {
445
+ return;
446
+ }
447
+ tags.push(tag);
448
+ const { definitions } = this.root;
449
+ if (!definitions.tags.some(t => t.toLowerCase() === lower)) {
450
+ definitions.tags.push(tag);
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Removes a tag from the property. Unlike the `addTag()` this won't remove a `tag` from the root namespace.
456
+ *
457
+ * @param tag The tag to remove.
458
+ */
459
+ removeTag(tag: string): void {
460
+ if (!tag) {
461
+ return;
462
+ }
463
+ const lower = tag.toLowerCase();
464
+ const { tags } = this;
465
+ const index = tags.findIndex(t => t.toLowerCase() === lower);
466
+ if (index >= 0) {
467
+ tags.splice(index, 1);
468
+ }
469
+ }
470
+
471
+ /**
472
+ * Creates a Property Shape of AMF.
473
+ * The property itself is auto-generated. If the `schema` is defined then it is used
474
+ * as the `range` of the property. Otherwise basic shape is generated for the range.
475
+ *
476
+ * This is a preferred way of reading the AMF shape as this synchronizes changed
477
+ * data properties with the shape definition.
478
+ *
479
+ * @returns AMF property shape definition.
480
+ */
481
+ toApiShape(): IPropertyShape {
482
+ const serializer = new AmfShapeGenerator();
483
+ return serializer.property(this);
484
+ }
485
+
486
+ /**
487
+ * @returns The adapted property, if any
488
+ */
489
+ readAdapted(): DataProperty | undefined {
490
+ const { adapts } = this;
491
+ if (!adapts) {
492
+ return undefined;
493
+ }
494
+ return this.root.definitions.properties.find(i => i.key === adapts);
495
+ }
496
+
497
+ /**
498
+ * Creates new adapted property and associates it with this property.
499
+ * @returns The instance of the created property.
500
+ */
501
+ createAdapted(): DataProperty {
502
+ const property = new DataProperty(this.root);
503
+ // disallow defaults as this would influence the schema generation
504
+ property.info.name = undefined;
505
+ this.root.definitions.properties.push(property);
506
+ this.adapts = property.key;
507
+ return property;
305
508
  }
306
509
  }
@@ -1,125 +0,0 @@
1
- export declare type NumberFormat = 'integer' | 'float' | 'long' | 'double' | 'int32' | 'int64' | 'uint32' | 'uint64' | 'sint32' | 'sint64' | 'fixed32' | 'fixed64' | 'sfixed32' | 'sfixed64';
2
- export declare const NumberFormats: NumberFormat[];
3
- export declare enum NumberFormatList {
4
- integer = "integer",
5
- float = "float",
6
- int32 = "int32",
7
- int64 = "int64",
8
- uint32 = "uint32",
9
- uint64 = "uint64",
10
- sint32 = "sint32",
11
- sint64 = "sint64",
12
- fixed32 = "fixed32",
13
- fixed64 = "fixed64",
14
- sfixed32 = "sfixed32",
15
- sfixed64 = "sfixed64",
16
- double = "double"
17
- }
18
- export declare type DateFormat = 'rfc3339' | 'rfc2616';
19
- export declare const DateFormats: DateFormat[];
20
- export declare enum DateFormatList {
21
- /**
22
- * The "date-time" notation of RFC3339
23
- */
24
- rfc3339 = "rfc3339",
25
- /**
26
- * The format defined in RFC2616.
27
- */
28
- rfc2616 = "rfc2616"
29
- }
30
- /**
31
- * The difference between the DataProperty and this is that the `DataProperty` describes the general shape of
32
- * the data and `IDataPropertySchema` describes how this property is translated into a specific format
33
- * (like JSON, Protocol Buffer, XML, etc)
34
- */
35
- export interface IDataPropertySchema<T> {
36
- /**
37
- * The default value for the property.
38
- */
39
- default?: T;
40
- /**
41
- * Enum values for the property.
42
- */
43
- enum?: T[];
44
- /**
45
- * The example value for the property.
46
- */
47
- examples?: T[];
48
- /**
49
- * The format of a `number` or `datetime` type.
50
- */
51
- format?: NumberFormat | DateFormat;
52
- /**
53
- * Minimum length of the string or a file. Value MUST be equal to or greater than 0.
54
- */
55
- minLength?: number;
56
- /**
57
- * The minimum length of the string or a file. Value MUST be equal to or greater than 0.
58
- */
59
- maxLength?: number;
60
- /**
61
- * Regular expression that this string MUST match.
62
- */
63
- pattern?: string;
64
- /**
65
- * The minimum value.
66
- */
67
- minimum?: number;
68
- /**
69
- * The maximum value.
70
- */
71
- maximum?: number;
72
- /**
73
- * A numeric instance is valid against "multipleOf" if the result of dividing the instance by this
74
- * value is an integer.
75
- */
76
- multipleOf?: number;
77
- /**
78
- * A list of valid content-type strings for the file. The file type `*\/*` is a valid value.
79
- */
80
- fileTypes?: string[];
81
- /**
82
- * Describes XML specific serialization.
83
- */
84
- xml?: {
85
- /**
86
- * Whether is property should be represented as an attribute of the parent entity.
87
- *
88
- * ```
89
- * <Person name="John Doe"></Person>
90
- * ```
91
- */
92
- attribute?: boolean;
93
- /**
94
- * The name of the attribute or a wrapped property to use when serializing the property.
95
- *
96
- * ```
97
- * <Person fullName="John Doe"></Person>
98
- * ```
99
- */
100
- name?: string;
101
- /**
102
- * When the property is an array (has the `multiple` set to true)
103
- * then it tells that the list of values should be wrapped with a parent
104
- * element:
105
- *
106
- * ```
107
- * <Person>
108
- * <Person fullName="John Doe"></Person>
109
- * </Person>
110
- * ```
111
- *
112
- * Use this with the combination with `name` to describe the name of the wrapped
113
- * element
114
- *
115
- * ```
116
- * <people>
117
- * <Person fullName="John Doe"></Person>
118
- * </people>
119
- * ```
120
- *
121
- * Note, this is mutually exclusive with `attribute`.
122
- */
123
- wrapped?: boolean;
124
- };
125
- }
@@ -1,33 +0,0 @@
1
- export const NumberFormats = [
2
- 'integer', 'float', 'long', 'double', 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'fixed32', 'fixed64',
3
- 'sfixed32', 'sfixed64'
4
- ];
5
- export var NumberFormatList;
6
- (function (NumberFormatList) {
7
- NumberFormatList["integer"] = "integer";
8
- NumberFormatList["float"] = "float";
9
- NumberFormatList["int32"] = "int32";
10
- NumberFormatList["int64"] = "int64";
11
- NumberFormatList["uint32"] = "uint32";
12
- NumberFormatList["uint64"] = "uint64";
13
- NumberFormatList["sint32"] = "sint32";
14
- NumberFormatList["sint64"] = "sint64";
15
- NumberFormatList["fixed32"] = "fixed32";
16
- NumberFormatList["fixed64"] = "fixed64";
17
- NumberFormatList["sfixed32"] = "sfixed32";
18
- NumberFormatList["sfixed64"] = "sfixed64";
19
- NumberFormatList["double"] = "double";
20
- })(NumberFormatList || (NumberFormatList = {}));
21
- export const DateFormats = ['rfc3339', 'rfc2616'];
22
- export var DateFormatList;
23
- (function (DateFormatList) {
24
- /**
25
- * The "date-time" notation of RFC3339
26
- */
27
- DateFormatList["rfc3339"] = "rfc3339";
28
- /**
29
- * The format defined in RFC2616.
30
- */
31
- DateFormatList["rfc2616"] = "rfc2616";
32
- })(DateFormatList || (DateFormatList = {}));
33
- //# sourceMappingURL=DataPropertySchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DataPropertySchema.js","sourceRoot":"","sources":["../../../../src/models/data/DataPropertySchema.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC3C,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS;IACpH,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,CAAN,IAAY,gBAcX;AAdD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,mCAAe,CAAA;IACf,mCAAe,CAAA;IACf,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;IACnB,uCAAmB,CAAA;IACnB,yCAAqB,CAAA;IACrB,yCAAqB,CAAA;IACrB,qCAAiB,CAAA;AACnB,CAAC,EAdW,gBAAgB,KAAhB,gBAAgB,QAc3B;AAGD,MAAM,CAAC,MAAM,WAAW,GAAiB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAChE,MAAM,CAAN,IAAY,cASX;AATD,WAAY,cAAc;IACxB;;OAEG;IACH,qCAAmB,CAAA;IACnB;;OAEG;IACH,qCAAmB,CAAA;AACrB,CAAC,EATW,cAAc,KAAd,cAAc,QASzB"}