@opra/common 1.0.0-alpha.2 → 1.0.0-alpha.4

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 (85) hide show
  1. package/browser.js +336 -136
  2. package/cjs/document/api-document.js +18 -12
  3. package/cjs/document/common/data-type-map.js +1 -1
  4. package/cjs/document/constants.js +1 -1
  5. package/cjs/document/data-type/api-field.js +5 -1
  6. package/cjs/document/data-type/complex-type-base.js +4 -0
  7. package/cjs/document/data-type/complex-type.js +4 -3
  8. package/cjs/document/data-type/enum-type.js +2 -0
  9. package/cjs/document/data-type/extended-types/base64.type.js +6 -1
  10. package/cjs/document/data-type/extended-types/date-string.type.js +10 -3
  11. package/cjs/document/data-type/extended-types/date-time-string.type.js +10 -3
  12. package/cjs/document/data-type/extended-types/date-time.type.js +10 -3
  13. package/cjs/document/data-type/extended-types/date.type.js +10 -3
  14. package/cjs/document/data-type/extended-types/email.type.js +24 -10
  15. package/cjs/document/data-type/extended-types/field-path.type.js +12 -4
  16. package/cjs/document/data-type/extended-types/filter.type.js +10 -3
  17. package/cjs/document/data-type/extended-types/object-id.type.js +6 -1
  18. package/cjs/document/data-type/extended-types/operation-result.type.js +20 -10
  19. package/cjs/document/data-type/extended-types/time.type.js +10 -3
  20. package/cjs/document/data-type/extended-types/url.type.js +6 -1
  21. package/cjs/document/data-type/extended-types/uuid.type.js +8 -2
  22. package/cjs/document/data-type/mapped-type.js +3 -0
  23. package/cjs/document/data-type/mixin-type.js +3 -0
  24. package/cjs/document/data-type/primitive-types/any.type.js +2 -1
  25. package/cjs/document/data-type/primitive-types/bigint.type.js +6 -1
  26. package/cjs/document/data-type/primitive-types/boolean.type.js +6 -1
  27. package/cjs/document/data-type/primitive-types/integer.type.js +6 -1
  28. package/cjs/document/data-type/primitive-types/null.type.js +6 -1
  29. package/cjs/document/data-type/primitive-types/number.type.js +10 -3
  30. package/cjs/document/data-type/primitive-types/object.type.js +2 -1
  31. package/cjs/document/data-type/primitive-types/string.type.js +14 -5
  32. package/cjs/document/data-type/simple-type.js +8 -1
  33. package/cjs/document/decorators/http-operation-entity.decorator.js +7 -7
  34. package/cjs/document/factory/api-document.factory.js +5 -0
  35. package/cjs/document/factory/data-type.factory.js +62 -39
  36. package/cjs/document/factory/http-api.factory.js +1 -1
  37. package/esm/document/api-document.js +18 -12
  38. package/esm/document/common/data-type-map.js +1 -1
  39. package/esm/document/constants.js +1 -1
  40. package/esm/document/data-type/api-field.js +5 -1
  41. package/esm/document/data-type/complex-type-base.js +4 -0
  42. package/esm/document/data-type/complex-type.js +4 -3
  43. package/esm/document/data-type/enum-type.js +2 -0
  44. package/esm/document/data-type/extended-types/base64.type.js +7 -2
  45. package/esm/document/data-type/extended-types/date-string.type.js +11 -4
  46. package/esm/document/data-type/extended-types/date-time-string.type.js +11 -4
  47. package/esm/document/data-type/extended-types/date-time.type.js +11 -4
  48. package/esm/document/data-type/extended-types/date.type.js +11 -4
  49. package/esm/document/data-type/extended-types/email.type.js +25 -11
  50. package/esm/document/data-type/extended-types/field-path.type.js +13 -5
  51. package/esm/document/data-type/extended-types/filter.type.js +11 -4
  52. package/esm/document/data-type/extended-types/object-id.type.js +7 -2
  53. package/esm/document/data-type/extended-types/operation-result.type.js +21 -11
  54. package/esm/document/data-type/extended-types/time.type.js +11 -4
  55. package/esm/document/data-type/extended-types/url.type.js +7 -2
  56. package/esm/document/data-type/extended-types/uuid.type.js +9 -3
  57. package/esm/document/data-type/mapped-type.js +3 -0
  58. package/esm/document/data-type/mixin-type.js +3 -0
  59. package/esm/document/data-type/primitive-types/any.type.js +3 -2
  60. package/esm/document/data-type/primitive-types/bigint.type.js +7 -2
  61. package/esm/document/data-type/primitive-types/boolean.type.js +7 -2
  62. package/esm/document/data-type/primitive-types/integer.type.js +7 -2
  63. package/esm/document/data-type/primitive-types/null.type.js +7 -2
  64. package/esm/document/data-type/primitive-types/number.type.js +11 -4
  65. package/esm/document/data-type/primitive-types/object.type.js +3 -2
  66. package/esm/document/data-type/primitive-types/string.type.js +15 -6
  67. package/esm/document/data-type/simple-type.js +8 -1
  68. package/esm/document/decorators/http-operation-entity.decorator.js +7 -7
  69. package/esm/document/factory/api-document.factory.js +4 -0
  70. package/esm/document/factory/data-type.factory.js +62 -39
  71. package/esm/document/factory/http-api.factory.js +1 -1
  72. package/package.json +4 -4
  73. package/types/document/api-document.d.ts +3 -6
  74. package/types/document/data-type/api-field.d.ts +2 -0
  75. package/types/document/data-type/complex-type.d.ts +1 -1
  76. package/types/document/data-type/data-type.d.ts +4 -2
  77. package/types/document/data-type/enum-type.d.ts +2 -2
  78. package/types/document/data-type/mapped-type.d.ts +2 -2
  79. package/types/document/data-type/mixin-type.d.ts +2 -2
  80. package/types/document/data-type/simple-type.d.ts +4 -2
  81. package/types/document/factory/api-document.factory.d.ts +1 -1
  82. package/types/document/factory/data-type.factory.d.ts +5 -0
  83. package/types/schema/data-type/simple-type.interface.d.ts +4 -0
  84. package/types/schema/document.interface.d.ts +13 -1
  85. package/types/schema/index.d.ts +1 -0
@@ -1,4 +1,4 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import { toString, vg } from 'valgen';
3
3
  import { DATATYPE_METADATA, DECODER, ENCODER } from '../../constants.js';
4
4
  import { SimpleType } from '../simple-type.js';
@@ -30,26 +30,35 @@ let StringType = class StringType {
30
30
  __decorate([
31
31
  SimpleType.Attribute({
32
32
  description: 'Regex pattern to be used for validation',
33
- })
33
+ }),
34
+ __metadata("design:type", Object)
34
35
  ], StringType.prototype, "pattern", void 0);
35
36
  __decorate([
36
37
  SimpleType.Attribute({
37
38
  description: 'Name of the pattern',
38
- })
39
+ }),
40
+ __metadata("design:type", String)
39
41
  ], StringType.prototype, "patternName", void 0);
40
42
  __decorate([
41
43
  SimpleType.Attribute({
42
44
  description: 'Minimum number of characters',
43
- })
45
+ }),
46
+ __metadata("design:type", Number)
44
47
  ], StringType.prototype, "minLength", void 0);
45
48
  __decorate([
46
49
  SimpleType.Attribute({
47
50
  description: 'Minimum number of characters',
48
- })
51
+ }),
52
+ __metadata("design:type", Number)
49
53
  ], StringType.prototype, "maxLength", void 0);
50
54
  StringType = __decorate([
51
55
  SimpleType({
52
56
  description: 'A sequence of characters',
53
- })
57
+ nameMappings: {
58
+ js: 'string',
59
+ json: 'string',
60
+ },
61
+ }),
62
+ __metadata("design:paramtypes", [Object])
54
63
  ], StringType);
55
64
  export { StringType };
@@ -25,6 +25,8 @@ export const SimpleType = function (...args) {
25
25
  _this.base = initArgs.base;
26
26
  }
27
27
  _this.properties = initArgs.properties;
28
+ _this.ownNameMappings = { ...initArgs.nameMappings };
29
+ _this.nameMappings = { ..._this.base?.nameMappings, ...initArgs.nameMappings };
28
30
  _this.ownAttributes = cloneObject(initArgs.attributes || {});
29
31
  _this.attributes = _this.base ? cloneObject(_this.base.attributes) : {};
30
32
  if (_this.ownAttributes) {
@@ -43,6 +45,8 @@ export const SimpleType = function (...args) {
43
45
  */
44
46
  class SimpleTypeClass extends DataType {
45
47
  extendsFrom(baseType) {
48
+ if (!(baseType instanceof DataType))
49
+ baseType = this.node.getDataType(baseType);
46
50
  if (!(baseType instanceof SimpleType))
47
51
  return false;
48
52
  if (baseType === this)
@@ -87,12 +91,15 @@ class SimpleTypeClass extends DataType {
87
91
  return o;
88
92
  }, {});
89
93
  const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
90
- return omitUndefined({
94
+ const out = omitUndefined({
91
95
  ...DataType.prototype.toJSON.apply(this),
92
96
  base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
93
97
  attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
94
98
  properties: Object.keys(properties).length ? properties : undefined,
95
99
  });
100
+ if (Object.keys(this.ownNameMappings).length)
101
+ out.nameMappings = { ...this.ownNameMappings };
102
+ return out;
96
103
  }
97
104
  }
98
105
  SimpleType.prototype = SimpleTypeClass.prototype;
@@ -21,8 +21,8 @@ HttpOperation.Entity.Create = function (arg0, arg1) {
21
21
  /** Initialize the decorator and the chain */
22
22
  const decoratorChain = [];
23
23
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
24
- description: args.description,
25
24
  method: 'POST',
25
+ ...args,
26
26
  composition: 'Entity.Create',
27
27
  requestBody: {
28
28
  immediateFetch: true,
@@ -72,8 +72,8 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
72
72
  /** Initialize the decorator and the chain */
73
73
  const decoratorChain = [];
74
74
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
75
- description: args.description,
76
75
  method: 'DELETE',
76
+ ...args,
77
77
  composition: 'Entity.Delete',
78
78
  }));
79
79
  decorator
@@ -121,8 +121,8 @@ HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
121
121
  const filterType = new FilterType({ dataType: args.type });
122
122
  filterType.rules = {};
123
123
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
124
- description: args.description,
125
124
  method: 'DELETE',
125
+ ...args,
126
126
  composition: 'Entity.DeleteMany',
127
127
  }));
128
128
  decorator
@@ -169,8 +169,8 @@ HttpOperation.Entity.FindMany = function (arg0, arg1) {
169
169
  const filterType = new FilterType({ dataType: args.type });
170
170
  filterType.rules = {};
171
171
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
172
- description: args.description,
173
172
  method: 'GET',
173
+ ...args,
174
174
  composition: 'Entity.FindMany',
175
175
  }));
176
176
  decorator
@@ -261,8 +261,8 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
261
261
  /** Initialize the decorator and the chain */
262
262
  const decoratorChain = [];
263
263
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
264
- description: args.description,
265
264
  method: 'GET',
265
+ ...args,
266
266
  composition: 'Entity.Get',
267
267
  }));
268
268
  decorator
@@ -324,8 +324,8 @@ HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
324
324
  filterType.rules = {};
325
325
  const filterRules = new FilterRules();
326
326
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
327
- description: args.description,
328
327
  method: 'PATCH',
328
+ ...args,
329
329
  composition: 'Entity.UpdateMany',
330
330
  requestBody: {
331
331
  immediateFetch: true,
@@ -379,8 +379,8 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
379
379
  const filterType = new FilterType({ dataType: args.type });
380
380
  filterType.rules = {};
381
381
  const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
382
- description: args.description,
383
382
  method: 'PATCH',
383
+ ...args,
384
384
  composition: 'Entity.Update',
385
385
  requestBody: {
386
386
  partial: 'deep',
@@ -1,3 +1,5 @@
1
+ import crypto from 'node:crypto';
2
+ import { asMutable } from 'ts-gems';
1
3
  import { resolveThunk } from '../../helpers/index.js';
2
4
  import { OpraSchema } from '../../schema/index.js';
3
5
  import { ApiDocument } from '../api-document.js';
@@ -109,6 +111,8 @@ export class ApiDocumentFactory {
109
111
  context.addError(`Unknown service protocol (${init.api.protocol})`);
110
112
  });
111
113
  }
114
+ const x = document.export();
115
+ asMutable(document).id = crypto.createHash('md5').update(JSON.stringify(x)).digest('base64url');
112
116
  }
113
117
  /**
114
118
  *
@@ -4,6 +4,7 @@ import { DocumentInitContext } from '../common/document-init-context.js';
4
4
  import { DATATYPE_METADATA, DECODER, ENCODER, kCtorMap, kDataTypeMap } from '../constants.js';
5
5
  import { ComplexType } from '../data-type/complex-type.js';
6
6
  import { ComplexTypeBase } from '../data-type/complex-type-base.js';
7
+ import { DataType } from '../data-type/data-type.js';
7
8
  import { EnumType } from '../data-type/enum-type.js';
8
9
  import { MappedType } from '../data-type/mapped-type.js';
9
10
  import { MixinType } from '../data-type/mixin-type.js';
@@ -130,7 +131,7 @@ export class DataTypeFactory {
130
131
  const { importQueue, initArgsMap } = context;
131
132
  // Check if data type already exist (maybe a builtin type or already imported)
132
133
  const dataType = owner.node.findDataType(thunk);
133
- if (dataType)
134
+ if (dataType instanceof DataType)
134
135
  return dataType.name;
135
136
  let metadata;
136
137
  let ctor;
@@ -209,11 +210,15 @@ export class DataTypeFactory {
209
210
  /** Mark "out" object as initializing. This will help us to detect circular dependencies */
210
211
  out[initializingSymbol] = true;
211
212
  try {
212
- if (out.name && importQueue?.has(out.name)) {
213
- initArgsMap?.set(metadata.name, out);
213
+ if (out.name) {
214
+ if (importQueue?.has(out.name)) {
215
+ initArgsMap?.set(metadata.name, out);
216
+ out._instance = { name: metadata.name };
217
+ out[kDataTypeMap] = owner.node[kDataTypeMap];
218
+ }
219
+ else
220
+ return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
214
221
  }
215
- else if (out.name)
216
- return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
217
222
  switch (out.kind) {
218
223
  case OpraSchema.ComplexType.Kind:
219
224
  out.ctor = ctor;
@@ -287,7 +292,7 @@ export class DataTypeFactory {
287
292
  const fieldMeta = typeof v === 'string' ? { type: v } : v;
288
293
  if (fieldMeta.isArray && !fieldMeta.type)
289
294
  return context.addError(`"type" must be defined explicitly for array fields`);
290
- const t = await this._importDataTypeArgs(context, owner, fieldMeta.type);
295
+ const t = await this._importDataTypeArgs(context, owner, fieldMeta.type || 'any');
291
296
  if (!t)
292
297
  return;
293
298
  initArgs.fields[k] = {
@@ -329,6 +334,7 @@ export class DataTypeFactory {
329
334
  initArgs.ctor = initArgs.ctor || baseArgs.ctor;
330
335
  });
331
336
  initArgs.properties = metadata.properties;
337
+ initArgs.nameMappings = metadata.nameMappings;
332
338
  if (!initArgs.properties && initArgs.ctor)
333
339
  initArgs.properties = new initArgs.ctor();
334
340
  if (metadata.attributes)
@@ -381,27 +387,40 @@ export class DataTypeFactory {
381
387
  });
382
388
  }
383
389
  static _createDataType(context, owner, args) {
390
+ let dataType = owner.node.findDataType(typeof args === 'string' ? args : args.name || '');
391
+ if (dataType instanceof DataType)
392
+ return dataType;
384
393
  const initArgs = typeof args === 'string' ? context.initArgsMap?.get(args) : args;
385
- switch (initArgs?.kind) {
386
- case OpraSchema.ComplexType.Kind:
387
- return this._createComplexType(context, owner, initArgs);
388
- case OpraSchema.EnumType.Kind:
389
- return this._createEnumType(context, owner, initArgs);
390
- case OpraSchema.MappedType.Kind:
391
- return this._createMappedType(context, owner, initArgs);
392
- case OpraSchema.MixinType.Kind:
393
- return this._createMixinType(context, owner, initArgs);
394
- case OpraSchema.SimpleType.Kind:
395
- return this._createSimpleType(context, owner, initArgs);
394
+ if (initArgs) {
395
+ const dataTypeMap = initArgs[kDataTypeMap];
396
+ if (!dataTypeMap)
397
+ delete initArgs._instance;
398
+ dataType = initArgs._instance;
399
+ if (dataType?.name && dataTypeMap) {
400
+ dataTypeMap.set(dataType.name, dataType);
401
+ }
402
+ switch (initArgs?.kind) {
403
+ case OpraSchema.ComplexType.Kind:
404
+ return this._createComplexType(context, owner, initArgs);
405
+ case OpraSchema.EnumType.Kind:
406
+ return this._createEnumType(context, owner, initArgs);
407
+ case OpraSchema.MappedType.Kind:
408
+ return this._createMappedType(context, owner, initArgs);
409
+ case OpraSchema.MixinType.Kind:
410
+ return this._createMixinType(context, owner, initArgs);
411
+ case OpraSchema.SimpleType.Kind:
412
+ return this._createSimpleType(context, owner, initArgs);
413
+ }
396
414
  }
397
415
  context.addError(`Unknown data type (${String(args)})`);
398
416
  }
399
417
  static _createComplexType(context, owner, args) {
418
+ const dataType = args._instance || {};
419
+ Object.setPrototypeOf(dataType, ComplexType.prototype);
400
420
  const initArgs = cloneObject(args);
401
421
  if (args.base) {
402
422
  context.enter('.base', () => {
403
- initArgs.base = (owner.node.findDataType(args.base) ||
404
- this._createDataType(context, owner, args.base));
423
+ initArgs.base = this._createDataType(context, owner, args.base);
405
424
  });
406
425
  }
407
426
  /** Set additionalFields */
@@ -410,14 +429,7 @@ export class DataTypeFactory {
410
429
  if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
411
430
  initArgs.additionalFields = args.additionalFields;
412
431
  else {
413
- if (typeof args.additionalFields === 'string') {
414
- initArgs.additionalFields =
415
- owner.node.findDataType(args.additionalFields) ||
416
- this._createDataType(context, owner, args.additionalFields);
417
- }
418
- else {
419
- initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
420
- }
432
+ initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
421
433
  }
422
434
  });
423
435
  }
@@ -427,7 +439,7 @@ export class DataTypeFactory {
427
439
  context.enter('.fields', () => {
428
440
  for (const [k, v] of Object.entries(args.fields)) {
429
441
  context.enter(`[${k}]`, () => {
430
- const type = owner.node.findDataType(v.type) || this._createDataType(context, owner, v.type);
442
+ const type = this._createDataType(context, owner, v.type);
431
443
  if (type)
432
444
  initArgs.fields[k] = {
433
445
  ...v,
@@ -438,29 +450,37 @@ export class DataTypeFactory {
438
450
  }
439
451
  });
440
452
  }
441
- return new ComplexType(owner, initArgs);
453
+ ComplexType.apply(dataType, [owner, initArgs]);
454
+ return dataType;
442
455
  }
443
456
  static _createEnumType(context, owner, args) {
457
+ const dataType = args._instance || {};
458
+ Object.setPrototypeOf(dataType, EnumType.prototype);
444
459
  const initArgs = cloneObject(args);
445
460
  if (args.base) {
446
461
  context.enter('.base', () => {
447
- initArgs.base = (owner.node.findDataType(args.base) ||
448
- this._createDataType(context, owner, args.base));
462
+ initArgs.base = this._createDataType(context, owner, args.base);
449
463
  });
450
464
  }
451
465
  initArgs.attributes = args.attributes;
452
- return new EnumType(owner, initArgs);
466
+ EnumType.apply(dataType, [owner, initArgs]);
467
+ return dataType;
453
468
  }
454
469
  static _createMappedType(context, owner, args) {
470
+ const dataType = args._instance || {};
471
+ Object.setPrototypeOf(dataType, MappedType.prototype);
455
472
  const initArgs = cloneObject(args);
456
473
  if (args.base) {
457
474
  context.enter('.base', () => {
458
- initArgs.base = (owner.node.findDataType(args.base) || this._createDataType(context, owner, args.base));
475
+ initArgs.base = this._createDataType(context, owner, args.base);
459
476
  });
460
477
  }
461
- return new MappedType(owner, initArgs);
478
+ MappedType.apply(dataType, [owner, initArgs]);
479
+ return dataType;
462
480
  }
463
481
  static _createMixinType(context, owner, args) {
482
+ const dataType = args._instance || {};
483
+ Object.setPrototypeOf(dataType, MixinType.prototype);
464
484
  const initArgs = cloneObject(args);
465
485
  if (args.types) {
466
486
  context.enter('.types', () => {
@@ -468,7 +488,7 @@ export class DataTypeFactory {
468
488
  let i = 0;
469
489
  for (const t of args.types) {
470
490
  context.enter(`[${i++}]`, () => {
471
- const base = owner.node.findDataType(t) || this._createDataType(context, owner, t);
491
+ const base = this._createDataType(context, owner, t);
472
492
  if (!(base instanceof ComplexTypeBase))
473
493
  throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
474
494
  initArgs.types.push(base);
@@ -476,17 +496,20 @@ export class DataTypeFactory {
476
496
  }
477
497
  });
478
498
  }
479
- return new MixinType(owner, initArgs);
499
+ MixinType.apply(dataType, [owner, initArgs]);
500
+ return dataType;
480
501
  }
481
502
  static _createSimpleType(context, owner, args) {
503
+ const dataType = args._instance || {};
504
+ Object.setPrototypeOf(dataType, SimpleType.prototype);
482
505
  const initArgs = cloneObject(args);
483
506
  if (args.base) {
484
507
  context.enter('.base', () => {
485
- initArgs.base = (owner.node.findDataType(args.base) ||
486
- this._createDataType(context, owner, args.base));
508
+ initArgs.base = this._createDataType(context, owner, args.base);
487
509
  });
488
510
  }
489
- return new SimpleType(owner, initArgs);
511
+ SimpleType.apply(dataType, [owner, initArgs]);
512
+ return dataType;
490
513
  }
491
514
  }
492
515
  function preferName(initArgs) {
@@ -205,7 +205,7 @@ export class HttpApiFactory {
205
205
  });
206
206
  }
207
207
  if (metadata.requestBody) {
208
- await context.enter('.requestBody', async () => {
208
+ await context.enterAsync('.requestBody', async () => {
209
209
  const requestBody = new HttpRequestBody(operation);
210
210
  await this._initHttpRequestBody(context, requestBody, metadata.requestBody);
211
211
  operation.requestBody = requestBody;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,8 +25,8 @@
25
25
  "lint": "eslint . --max-warnings=0",
26
26
  "check": "madge --circular src/**",
27
27
  "format": "prettier . --write --log-level=warn",
28
- "test": "jest",
29
- "cover": "jest --collect-coverage",
28
+ "test": "jest --passWithNoTests",
29
+ "cover": "jest --passWithNoTests --collect-coverage",
30
30
  "clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
31
31
  "clean:src": "ts-cleanup -s src --all",
32
32
  "clean:test": "ts-cleanup -s test --all",
@@ -55,7 +55,7 @@
55
55
  "@browsery/util": "^0.12.5",
56
56
  "@types/encodeurl": "^1.0.2",
57
57
  "@types/lodash.omit": "^4.5.9",
58
- "@types/validator": "^13.11.10",
58
+ "@types/validator": "^13.12.0",
59
59
  "path-browserify": "^1.0.1",
60
60
  "ts-gems": "^3.4.0"
61
61
  },
@@ -7,17 +7,13 @@ import { kTypeNSMap } from './constants.js';
7
7
  import { DataType } from './data-type/data-type.js';
8
8
  import type { EnumType } from './data-type/enum-type.js';
9
9
  import type { HttpApi } from './http/http-api.js';
10
- export declare namespace ApiDocument {
11
- interface ExportOptions {
12
- references?: 'inline' | 'relative-url' | 'external-url';
13
- }
14
- }
15
10
  /**
16
11
  *
17
12
  * @class ApiDocument
18
13
  */
19
14
  export declare class ApiDocument extends DocumentElement {
20
15
  protected [kTypeNSMap]: WeakMap<DataType, string>;
16
+ readonly id: string;
21
17
  url?: string;
22
18
  info: OpraSchema.DocumentInfo;
23
19
  references: ResponsiveMap<ApiDocument>;
@@ -29,10 +25,11 @@ export declare class ApiDocument extends DocumentElement {
29
25
  * @param nameOrCtor
30
26
  */
31
27
  getDataTypeNs(nameOrCtor: string | Type | Function | EnumType.EnumArray | EnumType.EnumObject | DataType): string | undefined;
28
+ findDocument(id: string): ApiDocument | undefined;
32
29
  toJSON(): OpraSchema.ApiDocument;
33
30
  /**
34
31
  * Export as Opra schema definition object
35
32
  */
36
- export(options?: ApiDocument.ExportOptions): OpraSchema.ApiDocument;
33
+ export(): OpraSchema.ApiDocument;
37
34
  protected _findDataType(nameOrCtor: string | Type | Function | EnumType.EnumArray | EnumType.EnumObject, visitedRefs?: WeakMap<ApiDocument, boolean>): DataType | undefined;
38
35
  }
@@ -59,6 +59,8 @@ declare class ApiFieldClass extends DocumentElement {
59
59
  readonly exclusive?: boolean;
60
60
  readonly translatable?: boolean;
61
61
  readonly deprecated?: boolean | string;
62
+ readonly readonly?: boolean;
63
+ readonly writeonly?: boolean;
62
64
  readonly examples?: any[] | Record<string, any>;
63
65
  toJSON(): OpraSchema.Field;
64
66
  }
@@ -71,7 +71,7 @@ declare abstract class ComplexTypeClass extends ComplexTypeBase {
71
71
  readonly kind: OpraSchema.ComplexType.Kind;
72
72
  readonly base?: ComplexType | MappedType | MixinType;
73
73
  readonly ctor?: Type;
74
- extendsFrom(baseType: DataType): boolean;
74
+ extendsFrom(baseType: DataType | string | Type | object): boolean;
75
75
  toJSON(): OpraSchema.ComplexType;
76
76
  }
77
77
  export {};
@@ -1,4 +1,4 @@
1
- import { StrictOmit } from 'ts-gems';
1
+ import { StrictOmit, Type } from 'ts-gems';
2
2
  import { ValidationOptions, Validator } from 'valgen';
3
3
  import { FieldsProjection } from '../../helpers/index.js';
4
4
  import type { DataTypeBase } from '../../schema/data-type/data-type.interface.js';
@@ -23,6 +23,8 @@ export declare namespace DataType {
23
23
  caseInSensitive?: boolean;
24
24
  partial?: boolean | 'deep';
25
25
  projection?: string[] | FieldsProjection | '*';
26
+ ignoreReadonlyFields?: boolean;
27
+ ignoreWriteonlyFields?: boolean;
26
28
  }
27
29
  }
28
30
  interface DataTypeStatic {
@@ -52,7 +54,7 @@ declare abstract class DataTypeClass extends DocumentElement {
52
54
  readonly examples?: OpraSchema.DataTypeExample[];
53
55
  abstract generateCodec(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions): Validator;
54
56
  get embedded(): any;
55
- abstract extendsFrom(baseType: DataType): boolean;
57
+ abstract extendsFrom(baseType: DataType | string | Type | object): boolean;
56
58
  toJSON(): OpraSchema.DataType;
57
59
  toString(): string;
58
60
  [nodeInspectCustom](): string;
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Combine } from 'ts-gems';
2
+ import { Combine, Type } from 'ts-gems';
3
3
  import { Validator } from 'valgen';
4
4
  import { OpraSchema } from '../../schema/index.js';
5
5
  import type { DocumentElement } from '../common/document-element.js';
@@ -63,7 +63,7 @@ declare class EnumTypeClass extends DataType {
63
63
  readonly instance?: object;
64
64
  readonly attributes: Record<string | number, OpraSchema.EnumType.ValueInfo>;
65
65
  readonly ownAttributes: Record<string | number, OpraSchema.EnumType.ValueInfo>;
66
- extendsFrom(baseType: DataType): boolean;
66
+ extendsFrom(baseType: DataType | string | Type | object): boolean;
67
67
  generateCodec(): Validator;
68
68
  toJSON(): OpraSchema.EnumType;
69
69
  }
@@ -5,7 +5,7 @@ import { OpraSchema } from '../../schema/index.js';
5
5
  import { DocumentElement } from '../common/document-element.js';
6
6
  import type { ComplexType } from './complex-type.js';
7
7
  import { ComplexTypeBase } from './complex-type-base.js';
8
- import type { DataType } from './data-type.js';
8
+ import { DataType } from './data-type.js';
9
9
  import type { MixinType } from './mixin-type';
10
10
  /**
11
11
  * @namespace MappedType
@@ -67,7 +67,7 @@ declare class MappedTypeClass extends ComplexTypeBase {
67
67
  readonly pick?: Field.Name[];
68
68
  readonly partial?: Field.Name[] | boolean;
69
69
  readonly required?: Field.Name[] | boolean;
70
- extendsFrom(baseType: DataType): boolean;
70
+ extendsFrom(baseType: DataType | string | Type | object): boolean;
71
71
  toJSON(): OpraSchema.MappedType;
72
72
  }
73
73
  export {};
@@ -4,7 +4,7 @@ import { OpraSchema } from '../../schema/index.js';
4
4
  import type { DocumentElement } from '../common/document-element.js';
5
5
  import type { ComplexType } from './complex-type.js';
6
6
  import { ComplexTypeBase } from './complex-type-base.js';
7
- import type { DataType } from './data-type.js';
7
+ import { DataType } from './data-type.js';
8
8
  import type { MappedType } from './mapped-type.js';
9
9
  /**
10
10
  * @namespace MixinType
@@ -76,7 +76,7 @@ export declare const MixinType: MixinTypeStatic;
76
76
  declare class MixinTypeClass extends ComplexTypeBase {
77
77
  readonly kind: OpraSchema.MixinType.Kind;
78
78
  readonly types: (ComplexType | MixinType | MappedType)[];
79
- extendsFrom(baseType: DataType): boolean;
79
+ extendsFrom(baseType: DataType | string | Type | object): boolean;
80
80
  toJSON(): OpraSchema.MixinType;
81
81
  }
82
82
  export {};
@@ -14,7 +14,7 @@ export declare namespace SimpleType {
14
14
  kind: OpraSchema.SimpleType.Kind;
15
15
  }, DataType.Metadata, OpraSchema.SimpleType> {
16
16
  }
17
- interface Options extends DataType.Options {
17
+ interface Options extends Combine<Pick<OpraSchema.SimpleType, 'nameMappings'>, DataType.Options> {
18
18
  }
19
19
  interface InitArguments extends Combine<{
20
20
  kind: OpraSchema.SimpleType.Kind;
@@ -64,11 +64,13 @@ declare abstract class SimpleTypeClass extends DataType {
64
64
  readonly kind: OpraSchema.SimpleType.Kind;
65
65
  readonly base?: SimpleType;
66
66
  readonly attributes: Record<string, SimpleType.Attribute>;
67
+ readonly nameMappings: Record<string, string>;
67
68
  readonly ownAttributes: Record<string, SimpleType.Attribute>;
69
+ readonly ownNameMappings: Record<string, string>;
68
70
  protected _generateDecoder?: SimpleType.ValidatorGenerator;
69
71
  protected _generateEncoder?: SimpleType.ValidatorGenerator;
70
72
  properties?: any;
71
- extendsFrom(baseType: DataType): boolean;
73
+ extendsFrom(baseType: DataType | string | Type | object): boolean;
72
74
  generateCodec<T extends Record<string, any> | object = object>(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions | null, properties?: Partial<T>): Validator;
73
75
  toJSON(): OpraSchema.SimpleType;
74
76
  }
@@ -5,7 +5,7 @@ import { DocumentInitContext } from '../common/document-init-context.js';
5
5
  import { DataTypeFactory } from './data-type.factory.js';
6
6
  import { HttpApiFactory } from './http-api.factory.js';
7
7
  export declare namespace ApiDocumentFactory {
8
- interface InitArguments extends PartialSome<StrictOmit<OpraSchema.ApiDocument, 'references' | 'types' | 'api'>, 'spec'> {
8
+ interface InitArguments extends PartialSome<StrictOmit<OpraSchema.ApiDocument, 'id' | 'references' | 'types' | 'api'>, 'spec'> {
9
9
  references?: Record<string, ReferenceThunk>;
10
10
  types?: DataTypeInitSources;
11
11
  api?: HttpApiFactory.InitArguments;
@@ -18,24 +18,29 @@ export declare namespace DataTypeFactory {
18
18
  type DataTypeSources = ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray | object>[] | Record<string, OpraSchema.DataType>;
19
19
  type DataTypeThunk = Type | EnumType.EnumObject | EnumType.EnumArray | object;
20
20
  interface ComplexTypeInit extends Combine<{
21
+ _instance?: ComplexType;
21
22
  base?: string | ComplexTypeInit | MappedTypeInit | MixinTypeInit;
22
23
  fields?: Record<string, ApiFieldInit>;
23
24
  additionalFields?: boolean | string | DataTypeFactory.DataTypeInitArguments | ['error'] | ['error', string];
24
25
  }, ComplexType.InitArguments> {
25
26
  }
26
27
  interface EnumTypeInit extends Combine<{
28
+ _instance?: MappedType;
27
29
  base?: string | EnumTypeInit;
28
30
  }, EnumType.InitArguments> {
29
31
  }
30
32
  interface MappedTypeInit extends Combine<{
33
+ _instance?: MappedType;
31
34
  base: string | ComplexTypeInit | MappedTypeInit | MixinTypeInit;
32
35
  }, MappedType.InitArguments> {
33
36
  }
34
37
  interface MixinTypeInit extends Combine<{
38
+ _instance?: MixinType;
35
39
  types: (string | ComplexTypeInit | MappedTypeInit | MixinTypeInit)[];
36
40
  }, MixinType.InitArguments> {
37
41
  }
38
42
  interface SimpleTypeInit extends Combine<{
43
+ _instance?: SimpleType;
39
44
  base?: string | SimpleTypeInit;
40
45
  }, SimpleType.InitArguments> {
41
46
  }
@@ -9,6 +9,10 @@ export interface SimpleType extends StrictOmit<DataTypeBase, 'kind'> {
9
9
  base?: DataType.Name;
10
10
  attributes?: Record<string, Attribute>;
11
11
  properties?: Record<string, any>;
12
+ /**
13
+ * Naming alternatives across software languages
14
+ */
15
+ nameMappings?: Record<string, string>;
12
16
  }
13
17
  export declare namespace SimpleType {
14
18
  const Kind = "SimpleType";
@@ -7,9 +7,10 @@ export type Protocol = 'http' | 'ws' | 'rpc';
7
7
  */
8
8
  export interface Document extends DataTypeContainer {
9
9
  spec: SpecVersion;
10
+ id: string;
10
11
  url?: string;
11
12
  info?: DocumentInfo;
12
- references?: Record<string, string | Document>;
13
+ references?: Record<string, DocumentReference>;
13
14
  api?: HttpApi;
14
15
  }
15
16
  /**
@@ -39,6 +40,14 @@ export interface LicenseInfo {
39
40
  url?: string;
40
41
  content?: string;
41
42
  }
43
+ /**
44
+ * @interface DocumentReference
45
+ */
46
+ export interface DocumentReference extends Pick<Document, 'id' | 'url' | 'info'> {
47
+ }
48
+ /**
49
+ * @interface Api
50
+ */
42
51
  export interface Api extends DataTypeContainer {
43
52
  protocol: Protocol;
44
53
  /**
@@ -47,6 +56,9 @@ export interface Api extends DataTypeContainer {
47
56
  name: string;
48
57
  description?: string;
49
58
  }
59
+ /**
60
+ * @interface HttpApi
61
+ */
50
62
  export interface HttpApi extends Api {
51
63
  protocol: 'http';
52
64
  description?: string;