@opra/common 0.16.2 → 0.17.0

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 (148) hide show
  1. package/cjs/document/data-type/complex-type.js +69 -56
  2. package/cjs/document/data-type/simple-type.js +0 -1
  3. package/cjs/document/resource/collection.js +15 -16
  4. package/cjs/document/resource/singleton.js +2 -2
  5. package/cjs/http/http-params.js +10 -11
  6. package/esm/document/api-document.js +33 -37
  7. package/esm/document/constants.js +3 -6
  8. package/esm/document/data-type/api-field.js +12 -15
  9. package/esm/document/data-type/builtin/any.type.js +5 -8
  10. package/esm/document/data-type/builtin/base64.type.js +5 -8
  11. package/esm/document/data-type/builtin/bigint.type.js +5 -8
  12. package/esm/document/data-type/builtin/boolean.type.js +8 -11
  13. package/esm/document/data-type/builtin/date.type.js +7 -10
  14. package/esm/document/data-type/builtin/guid.type.js +9 -12
  15. package/esm/document/data-type/builtin/index.js +10 -13
  16. package/esm/document/data-type/builtin/integer.type.js +10 -13
  17. package/esm/document/data-type/builtin/number.type.js +7 -10
  18. package/esm/document/data-type/builtin/object.type.js +5 -8
  19. package/esm/document/data-type/builtin/string.type.js +8 -11
  20. package/esm/document/data-type/builtin/time.type.js +7 -10
  21. package/esm/document/data-type/builtin/timestamp.type.js +9 -12
  22. package/esm/document/data-type/complex-type.js +94 -85
  23. package/esm/document/data-type/data-type.js +9 -12
  24. package/esm/document/data-type/enum-type.js +15 -19
  25. package/esm/document/data-type/mapped-type.js +24 -29
  26. package/esm/document/data-type/simple-type.js +17 -22
  27. package/esm/document/data-type/union-type.js +26 -29
  28. package/esm/document/factory/add-references.js +3 -7
  29. package/esm/document/factory/create-document.js +10 -16
  30. package/esm/document/factory/factory.js +33 -37
  31. package/esm/document/factory/import-resource-class.js +16 -22
  32. package/esm/document/factory/import-type-class.js +24 -34
  33. package/esm/document/factory/index.js +1 -4
  34. package/esm/document/factory/process-resources.js +10 -16
  35. package/esm/document/factory/process-types.js +31 -37
  36. package/esm/document/index.js +14 -17
  37. package/esm/document/resource/collection.js +58 -63
  38. package/esm/document/resource/resource.js +9 -12
  39. package/esm/document/resource/singleton.js +27 -31
  40. package/esm/document/utils/inspect.util.js +4 -7
  41. package/esm/document/utils/string-compare.util.js +1 -5
  42. package/esm/exception/enums/issue-severity.enum.js +2 -5
  43. package/esm/exception/error-issue.js +1 -2
  44. package/esm/exception/http-errors/bad-request.error.js +4 -8
  45. package/esm/exception/http-errors/failed-dependency.error.js +4 -8
  46. package/esm/exception/http-errors/forbidden.error.js +4 -8
  47. package/esm/exception/http-errors/internal-server.error.js +4 -8
  48. package/esm/exception/http-errors/method-not-allowed.error.js +4 -8
  49. package/esm/exception/http-errors/not-acceptable.error.js +4 -8
  50. package/esm/exception/http-errors/not-found.error.js +4 -8
  51. package/esm/exception/http-errors/unauthorized.error.js +4 -8
  52. package/esm/exception/http-errors/unprocessable-entity.error.js +4 -8
  53. package/esm/exception/index.js +15 -18
  54. package/esm/exception/opra-exception.js +3 -7
  55. package/esm/exception/resource-errors/resource-conflict.error.js +4 -8
  56. package/esm/exception/resource-errors/resource-not-found.error.js +4 -8
  57. package/esm/exception/wrap-exception.js +20 -24
  58. package/esm/filter/antlr/OpraFilterLexer.js +6 -9
  59. package/esm/filter/antlr/OpraFilterListener.js +2 -5
  60. package/esm/filter/antlr/OpraFilterParser.js +79 -126
  61. package/esm/filter/antlr/OpraFilterVisitor.js +2 -5
  62. package/esm/filter/ast/abstract/ast.js +1 -5
  63. package/esm/filter/ast/abstract/expression.js +2 -6
  64. package/esm/filter/ast/abstract/literal.js +2 -6
  65. package/esm/filter/ast/abstract/term.js +2 -6
  66. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -8
  67. package/esm/filter/ast/expressions/array-expression.js +2 -6
  68. package/esm/filter/ast/expressions/comparison-expression.js +2 -6
  69. package/esm/filter/ast/expressions/logical-expression.js +2 -6
  70. package/esm/filter/ast/expressions/parentheses-expression.js +2 -6
  71. package/esm/filter/ast/index.js +16 -19
  72. package/esm/filter/ast/terms/boolean-literal.js +2 -6
  73. package/esm/filter/ast/terms/date-literal.js +8 -12
  74. package/esm/filter/ast/terms/external-constant.js +2 -6
  75. package/esm/filter/ast/terms/null-literal.js +2 -6
  76. package/esm/filter/ast/terms/number-literal.js +4 -8
  77. package/esm/filter/ast/terms/qualified-identifier.js +2 -6
  78. package/esm/filter/ast/terms/string-literal.js +4 -8
  79. package/esm/filter/ast/terms/time-literal.js +6 -10
  80. package/esm/filter/build.js +45 -69
  81. package/esm/filter/errors.js +3 -9
  82. package/esm/filter/filter-tree-visitor.js +26 -31
  83. package/esm/filter/index.js +5 -8
  84. package/esm/filter/opra-error-listener.js +4 -8
  85. package/esm/filter/parse.js +14 -19
  86. package/esm/filter/utils.js +2 -7
  87. package/esm/helpers/function-utils.js +8 -14
  88. package/esm/helpers/get-stack-filename.js +1 -5
  89. package/esm/helpers/index.js +8 -11
  90. package/esm/helpers/is-url.js +1 -5
  91. package/esm/helpers/mixin-utils.js +2 -7
  92. package/esm/helpers/object-utils.js +6 -12
  93. package/esm/helpers/path-to-object-tree.js +1 -5
  94. package/esm/helpers/responsive-map.js +1 -5
  95. package/esm/helpers/type-guards.js +7 -17
  96. package/esm/http/codecs/boolean-codec.js +1 -5
  97. package/esm/http/codecs/date-codec.js +1 -5
  98. package/esm/http/codecs/filter-codec.js +5 -9
  99. package/esm/http/codecs/integer-codec.js +2 -6
  100. package/esm/http/codecs/number-codec.js +1 -5
  101. package/esm/http/codecs/string-codec.js +1 -5
  102. package/esm/http/enums/http-headers-codes.enum.js +2 -5
  103. package/esm/http/enums/http-status-codes.enum.js +2 -5
  104. package/esm/http/enums/http-status-messages.js +1 -4
  105. package/esm/http/http-headers.js +5 -9
  106. package/esm/http/http-message.host.js +13 -18
  107. package/esm/http/http-params.js +30 -36
  108. package/esm/http/http-request-message.js +18 -22
  109. package/esm/http/http-response-message.js +23 -28
  110. package/esm/http/index.js +14 -17
  111. package/esm/http/interfaces/client-http-headers.interface.js +1 -2
  112. package/esm/http/interfaces/cookie-options.interface.js +1 -2
  113. package/esm/http/interfaces/server-http-headers.interface.js +1 -2
  114. package/esm/i18n/i18n.js +23 -28
  115. package/esm/i18n/index.js +5 -9
  116. package/esm/i18n/string-utils.js +2 -7
  117. package/esm/i18n/translate.js +3 -7
  118. package/esm/index.js +11 -16
  119. package/esm/schema/constants.js +1 -4
  120. package/esm/schema/data-type/complex-type.interface.js +2 -5
  121. package/esm/schema/data-type/data-type.interface.js +1 -2
  122. package/esm/schema/data-type/enum-type.interface.js +2 -5
  123. package/esm/schema/data-type/field.interface.js +1 -2
  124. package/esm/schema/data-type/mapped-type.interface.js +2 -5
  125. package/esm/schema/data-type/simple-type.interface.js +2 -5
  126. package/esm/schema/data-type/union-type.interface.js +2 -5
  127. package/esm/schema/document.interface.js +1 -2
  128. package/esm/schema/index.js +31 -34
  129. package/esm/schema/resource/collection.interface.js +2 -5
  130. package/esm/schema/resource/container.interface.js +2 -5
  131. package/esm/schema/resource/endpoint.interface.js +1 -2
  132. package/esm/schema/resource/resource.interface.js +1 -2
  133. package/esm/schema/resource/singleton.interface.js +2 -5
  134. package/esm/schema/type-guards.js +40 -53
  135. package/esm/types.js +1 -2
  136. package/esm/url/index.js +5 -8
  137. package/esm/url/opra-url-path-component.js +3 -7
  138. package/esm/url/opra-url-path.js +14 -18
  139. package/esm/url/opra-url.js +15 -19
  140. package/esm/url/utils/decode-path-component.js +4 -8
  141. package/esm/url/utils/encode-path-component.js +3 -8
  142. package/esm/utils/path-utils.js +2 -7
  143. package/package.json +1 -1
  144. package/types/document/data-type/complex-type.d.ts +8 -2
  145. package/types/document/resource/collection.d.ts +5 -3
  146. package/types/document/resource/singleton.d.ts +3 -1
  147. package/types/filter/ast/terms/qualified-identifier.d.ts +4 -0
  148. package/types/http/http-params.d.ts +20 -19
@@ -90,65 +90,78 @@ const proto = {
90
90
  this.fields.set(field.name, field);
91
91
  return field;
92
92
  },
93
- getField(name) {
94
- if (name.includes('.')) {
95
- let dt = this;
96
- const arr = name.split('.');
97
- const l = arr.length;
98
- let field;
99
- for (let i = 0; i < l; i++) {
100
- if (!(dt instanceof exports.ComplexType))
101
- throw new TypeError(`"${arr.slice(0, i - 1)}" field is not a ${index_js_2.OpraSchema.ComplexType.Kind} and has no child fields`);
102
- field = dt.getField(arr[i]);
103
- dt = field.type;
104
- }
105
- // @ts-ignore
106
- return field;
93
+ findField(nameOrPath) {
94
+ let field;
95
+ for (const [, f] of this.iteratePath(nameOrPath, true)) {
96
+ if (!f)
97
+ return;
98
+ field = f;
99
+ }
100
+ return field;
101
+ },
102
+ getField(nameOrPath) {
103
+ let field;
104
+ for (const [, f, path] of this.iteratePath(nameOrPath)) {
105
+ if (!f)
106
+ throw new Error(`Invalid field definition "${path}"`);
107
+ field = f;
107
108
  }
108
- const t = this.fields.get(name);
109
- if (!t)
110
- throw new Error(`"${this.name}" type doesn't have an field named "${name}"`);
111
- return t;
109
+ /* istanbul ignore next */
110
+ if (!field)
111
+ throw new Error(`Invalid field definition "${nameOrPath}"`);
112
+ return field;
113
+ },
114
+ iteratePath(path, silent) {
115
+ const arr = path.split('.');
116
+ const len = arr.length;
117
+ let dataType = this;
118
+ let field;
119
+ let curPath = '';
120
+ let s;
121
+ let i = -1;
122
+ return {
123
+ [Symbol.iterator]() {
124
+ return this;
125
+ },
126
+ next() {
127
+ i++;
128
+ if (i < len) {
129
+ s = arr[i];
130
+ if (dataType && !(dataType instanceof exports.ComplexType)) {
131
+ if (silent)
132
+ return { done: true, value: [] };
133
+ throw new TypeError(`"${curPath}" field is not a complex type and has no child fields`);
134
+ }
135
+ field = dataType?.fields.get(s);
136
+ if (field) {
137
+ curPath += (curPath ? '.' : '') + field.name;
138
+ dataType = field.type;
139
+ }
140
+ else {
141
+ curPath += (curPath ? '.' : '') + s;
142
+ if (dataType && !dataType.additionalFields) {
143
+ if (silent)
144
+ return { done: true, value: [] };
145
+ throw new Error(`Invalid field definition "${curPath}"`);
146
+ }
147
+ }
148
+ }
149
+ return {
150
+ done: i >= len,
151
+ value: [field?.name || s, field, curPath]
152
+ };
153
+ }
154
+ };
112
155
  },
113
- normalizeFieldNames(fields) {
114
- const fieldsTree = (fields && (0, index_js_1.pathToObjectTree)(Array.isArray(fields) ? fields : [fields])) || {};
115
- const out = _normalizeFieldsNames([], this.document, this, fieldsTree, '', '');
116
- return out.length ? out : undefined;
156
+ normalizeFieldPath(path) {
157
+ if (Array.isArray(path))
158
+ return path.map((s) => this.normalizeFieldPath(s));
159
+ let curPath = '';
160
+ for (const [, , p] of this.iteratePath(path)) {
161
+ curPath = p;
162
+ }
163
+ return curPath;
117
164
  }
118
165
  };
119
166
  Object.assign(exports.ComplexType.prototype, proto);
120
167
  Object.setPrototypeOf(exports.ComplexType.prototype, data_type_js_1.DataType.prototype);
121
- /**
122
- * Normalizes field names
123
- */
124
- function _normalizeFieldsNames(target, document, dataType, node, parentPath = '', actualPath = '') {
125
- let curPath = '';
126
- for (const k of Object.keys(node)) {
127
- const nodeVal = node[k];
128
- const field = dataType?.fields.get(k);
129
- if (!field) {
130
- curPath = parentPath ? parentPath + '.' + k : k;
131
- if ((dataType && !dataType.additionalFields))
132
- throw new TypeError(`Unknown field "${curPath}"`);
133
- if (typeof nodeVal === 'object')
134
- _normalizeFieldsNames(target, document, undefined, nodeVal, curPath, actualPath);
135
- else
136
- target.push(curPath);
137
- continue;
138
- }
139
- curPath = parentPath ? parentPath + '.' + field.name : field.name;
140
- if (typeof nodeVal === 'object') {
141
- if (!(field.type instanceof exports.ComplexType))
142
- throw new TypeError(`"${(actualPath ? actualPath + '.' + curPath : curPath)}" is not a complex type and has no sub fields`);
143
- if (target.findIndex(x => x === parentPath) >= 0)
144
- continue;
145
- target = _normalizeFieldsNames(target, document, field.type, nodeVal, curPath, actualPath);
146
- continue;
147
- }
148
- if (target.findIndex(x => x.startsWith(curPath + '.')) >= 0) {
149
- target = target.filter(x => !x.startsWith(curPath + '.'));
150
- }
151
- target.push(curPath);
152
- }
153
- return target;
154
- }
@@ -51,7 +51,6 @@ const proto = {
51
51
  Object.assign(out, (0, index_js_1.omitUndefined)({
52
52
  base: this.base ?
53
53
  (this.base.name ? this.base.name : this.base.exportSchema()) : undefined,
54
- codec: this.own.codec,
55
54
  pattern: this.own.pattern
56
55
  }));
57
56
  return out;
@@ -64,9 +64,9 @@ const proto = {
64
64
  if (!_this.primaryKey.length)
65
65
  throw new TypeError(`You must provide primaryKey for Collection resource ("${_this.name}")`);
66
66
  _this.primaryKey.forEach(f => {
67
- const el = dataType.getField(f);
68
- if (!(el.type instanceof simple_type_js_1.SimpleType))
69
- throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${el.type.kind}`);
67
+ const field = dataType.getField(f);
68
+ if (!(field?.type instanceof simple_type_js_1.SimpleType))
69
+ throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${field.type.kind}`);
70
70
  });
71
71
  if (_this.controller) {
72
72
  const instance = typeof _this.controller == 'function'
@@ -122,13 +122,11 @@ const proto = {
122
122
  return result;
123
123
  }
124
124
  },
125
- normalizeFieldNames(fields) {
126
- return this.type.normalizeFieldNames(fields);
125
+ normalizeFieldPath(path) {
126
+ return this.type.normalizeFieldPath(path);
127
127
  },
128
128
  normalizeSortFields(fields) {
129
- const normalized = this.normalizeFieldNames(fields);
130
- if (!normalized)
131
- return;
129
+ const normalized = this.type.normalizeFieldPath(fields);
132
130
  const findManyEndpoint = this.operations.findMany;
133
131
  const sortFields = findManyEndpoint && findManyEndpoint.sortFields;
134
132
  normalized.forEach(field => {
@@ -139,25 +137,26 @@ const proto = {
139
137
  });
140
138
  return normalized;
141
139
  },
142
- normalizeFilterFields(ast) {
140
+ normalizeFilter(ast) {
143
141
  if (ast instanceof index_js_2.ComparisonExpression) {
144
- this.normalizeFilterFields(ast.left);
142
+ this.normalizeFilter(ast.left);
145
143
  }
146
144
  else if (ast instanceof index_js_2.LogicalExpression) {
147
- ast.items.forEach(item => this.normalizeFilterFields(item));
145
+ ast.items.forEach(item => this.normalizeFilter(item));
148
146
  }
149
147
  else if (ast instanceof index_js_2.ArithmeticExpression) {
150
- ast.items.forEach(item => this.normalizeFilterFields(item.expression));
148
+ ast.items.forEach(item => this.normalizeFilter(item.expression));
151
149
  }
152
150
  else if (ast instanceof index_js_2.ArrayExpression) {
153
- ast.items.forEach(item => this.normalizeFilterFields(item));
151
+ ast.items.forEach(item => this.normalizeFilter(item));
154
152
  }
155
153
  else if (ast instanceof index_js_2.ParenthesesExpression) {
156
- this.normalizeFilterFields(ast.expression);
154
+ this.normalizeFilter(ast.expression);
157
155
  }
158
156
  else if (ast instanceof index_js_2.QualifiedIdentifier) {
159
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
160
- ast.value = this.normalizeFieldNames([ast.value])[0];
157
+ ast.field = this.type.findField(ast.value);
158
+ ast.dataType = ast.field?.type || this.document.getDataType('any');
159
+ ast.value = this.type.normalizeFieldPath(ast.value);
161
160
  }
162
161
  return ast;
163
162
  }
@@ -67,8 +67,8 @@ const proto = {
67
67
  }));
68
68
  return out;
69
69
  },
70
- normalizeFieldNames(fields) {
71
- return this.type.normalizeFieldNames(fields);
70
+ normalizeFieldPath(path) {
71
+ return this.type.normalizeFieldPath(path);
72
72
  },
73
73
  };
74
74
  Object.assign(exports.Singleton.prototype, proto);
@@ -191,7 +191,7 @@ class HttpParams {
191
191
  get(target, p, receiver) {
192
192
  if (typeof p === 'string') {
193
193
  const v = _this[kEntries].get(p);
194
- return v ? (v.length > 1 ? v : v[0]) : undefined;
194
+ return v ? (v.length > 1 ? v : v[0]) : null;
195
195
  }
196
196
  return Reflect.get(target, p, receiver);
197
197
  },
@@ -236,7 +236,7 @@ class HttpParams {
236
236
  ? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
237
237
  : fn(value);
238
238
  }
239
- return encodeURIParam(value);
239
+ return encodeURIParam(String(value));
240
240
  }
241
241
  decodeValue(value, key) {
242
242
  const prmDef = this[kParamDefs].get(key);
@@ -268,6 +268,12 @@ class HttpParams {
268
268
  }
269
269
  return decodeURIComponent(value);
270
270
  }
271
+ [(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
272
+ return this.entries();
273
+ }
274
+ get [Symbol.toStringTag]() {
275
+ return 'HttpParams';
276
+ }
271
277
  _append(name, value) {
272
278
  let values = this[kEntries].get(name);
273
279
  if (!values) {
@@ -283,8 +289,7 @@ class HttpParams {
283
289
  return false;
284
290
  const oldSize = this[kSize];
285
291
  if (value) {
286
- const valueToDelete = Array.isArray(value) ? value : [value];
287
- const newValues = oldValues.filter(x => !valueToDelete.includes(x));
292
+ const newValues = oldValues.filter(x => x === value);
288
293
  this[kEntries].set(name, newValues);
289
294
  this[kSize] += -oldValues.length + newValues.length;
290
295
  }
@@ -295,7 +300,7 @@ class HttpParams {
295
300
  return oldSize !== this[kSize];
296
301
  }
297
302
  _set(name, value, index) {
298
- if (value == null) {
303
+ if (value === undefined) {
299
304
  this._delete(name);
300
305
  return;
301
306
  }
@@ -314,12 +319,6 @@ class HttpParams {
314
319
  values[Math.min(index, values.length)] = value;
315
320
  this[kSize] += -oldLen + values.length;
316
321
  }
317
- [(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
318
- return this.entries();
319
- }
320
- get [Symbol.toStringTag]() {
321
- return 'HttpParams';
322
- }
323
322
  }
324
323
  exports.HttpParams = HttpParams;
325
324
  HttpParams.kEntries = kEntries;
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiDocument = void 0;
4
- const index_js_1 = require("../exception/index.js");
5
- const index_js_2 = require("../helpers/index.js");
6
- const index_js_3 = require("../schema/index.js");
7
- const constants_js_1 = require("./constants.js");
8
- const complex_type_js_1 = require("./data-type/complex-type.js");
9
- const simple_type_js_1 = require("./data-type/simple-type.js");
10
- class ApiDocument {
1
+ import { NotAcceptableError, NotFoundError } from '../exception/index.js';
2
+ import { cloneObject, omitUndefined, ResponsiveMap } from '../helpers/index.js';
3
+ import { OpraSchema } from '../schema/index.js';
4
+ import { NAMESPACE_PATTERN } from './constants.js';
5
+ import { ComplexType } from './data-type/complex-type.js';
6
+ import { SimpleType } from './data-type/simple-type.js';
7
+ export class ApiDocument {
11
8
  constructor() {
12
- this._typeCache = new index_js_2.ResponsiveMap();
9
+ this._typeCache = new ResponsiveMap();
13
10
  this._typesCacheByCtor = new Map();
14
- this.references = new index_js_2.ResponsiveMap();
15
- this.types = new index_js_2.ResponsiveMap();
16
- this.resources = new index_js_2.ResponsiveMap();
11
+ this.references = new ResponsiveMap();
12
+ this.types = new ResponsiveMap();
13
+ this.resources = new ResponsiveMap();
17
14
  this.info = {
18
15
  version: '',
19
16
  title: ''
@@ -33,19 +30,19 @@ class ApiDocument {
33
30
  if (t === null) {
34
31
  if (silent)
35
32
  return;
36
- throw new index_js_1.NotFoundError(`Data type "${nameOrCtorName}" does not exists`);
33
+ throw new NotFoundError(`Data type "${nameOrCtorName}" does not exists`);
37
34
  }
38
35
  if (typeof nameOrCtor === 'string') {
39
- const m = constants_js_1.NAMESPACE_PATTERN.exec(nameOrCtor);
36
+ const m = NAMESPACE_PATTERN.exec(nameOrCtor);
40
37
  if (!m)
41
- throw new index_js_1.NotFoundError(`Invalid data type name "${nameOrCtorName}"`);
38
+ throw new NotFoundError(`Invalid data type name "${nameOrCtorName}"`);
42
39
  // If given string has namespace pattern (ns:type_name)
43
40
  if (m[2]) {
44
41
  const ref = this.references.get(m[1]);
45
42
  if (!ref) {
46
43
  if (silent)
47
44
  return;
48
- throw new index_js_1.NotFoundError(`Reference "${m[1]}" not found`);
45
+ throw new NotFoundError(`Reference "${m[1]}" not found`);
49
46
  }
50
47
  dataType = ref.getDataType(m[2]);
51
48
  this._typeCache.set(nameOrCtor, dataType);
@@ -70,7 +67,7 @@ class ApiDocument {
70
67
  else if (typeof nameOrCtor === 'function') {
71
68
  const types = Array.from(this.types.values()).reverse();
72
69
  for (const dt of types) {
73
- if ((dt instanceof complex_type_js_1.ComplexType || dt instanceof simple_type_js_1.SimpleType) && dt.own.ctor === nameOrCtor) {
70
+ if ((dt instanceof ComplexType || dt instanceof SimpleType) && dt.own.ctor === nameOrCtor) {
74
71
  dataType = dt;
75
72
  break;
76
73
  }
@@ -86,7 +83,7 @@ class ApiDocument {
86
83
  }
87
84
  }
88
85
  if (dataType) {
89
- if ((dataType instanceof complex_type_js_1.ComplexType || dataType instanceof simple_type_js_1.SimpleType) &&
86
+ if ((dataType instanceof ComplexType || dataType instanceof SimpleType) &&
90
87
  dataType.own?.ctor && dataType.own.ctor !== Object)
91
88
  this._typesCacheByCtor.set(dataType.own.ctor, dataType);
92
89
  return dataType;
@@ -99,7 +96,7 @@ class ApiDocument {
99
96
  }
100
97
  if (silent)
101
98
  return;
102
- throw new index_js_1.NotFoundError(`Data type "${nameOrCtorName}" does not exists`);
99
+ throw new NotFoundError(`Data type "${nameOrCtorName}" does not exists`);
103
100
  }
104
101
  getComplexType(nameOrCtor, silent) {
105
102
  if (nameOrCtor === Object)
@@ -107,30 +104,30 @@ class ApiDocument {
107
104
  const t = this.getDataType(nameOrCtor);
108
105
  if (!t && silent)
109
106
  return;
110
- if (t && t.kind === index_js_3.OpraSchema.ComplexType.Kind)
107
+ if (t && t.kind === OpraSchema.ComplexType.Kind)
111
108
  return t;
112
- throw new index_js_1.NotAcceptableError(`Data type "${t.name}" is not a ComplexType`);
109
+ throw new NotAcceptableError(`Data type "${t.name}" is not a ComplexType`);
113
110
  }
114
111
  getSimpleType(nameOrCtor, silent) {
115
112
  const t = this.getDataType(nameOrCtor);
116
113
  if (!t && silent)
117
114
  return;
118
- if (t && t.kind === index_js_3.OpraSchema.SimpleType.Kind)
115
+ if (t && t.kind === OpraSchema.SimpleType.Kind)
119
116
  return t;
120
- throw new index_js_1.NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
117
+ throw new NotAcceptableError(`Data type "${t.name || t}" is not a SimpleType`);
121
118
  }
122
119
  getResource(path, silent) {
123
120
  let resource;
124
- const m = constants_js_1.NAMESPACE_PATTERN.exec(path);
121
+ const m = NAMESPACE_PATTERN.exec(path);
125
122
  if (!m)
126
- throw new index_js_1.NotFoundError(`Invalid resource path "${path}"`);
123
+ throw new NotFoundError(`Invalid resource path "${path}"`);
127
124
  // If given string has namespace pattern (ns:type_name)
128
125
  if (m[2]) {
129
126
  const ref = this.references.get(m[1]);
130
127
  if (!ref) {
131
128
  if (silent)
132
129
  return;
133
- throw new index_js_1.NotFoundError(`Reference "${m[1]}" not found`);
130
+ throw new NotFoundError(`Reference "${m[1]}" not found`);
134
131
  }
135
132
  return ref.getResource(m[2]);
136
133
  }
@@ -150,32 +147,32 @@ class ApiDocument {
150
147
  }
151
148
  if (silent)
152
149
  return;
153
- throw new index_js_1.NotFoundError(`Resource not found (${path})`);
150
+ throw new NotFoundError(`Resource not found (${path})`);
154
151
  }
155
152
  getCollection(path, silent) {
156
153
  const t = this.getResource(path);
157
154
  if (!t && silent)
158
155
  return;
159
- if (t && t.kind === index_js_3.OpraSchema.Collection.Kind)
156
+ if (t && t.kind === OpraSchema.Collection.Kind)
160
157
  return t;
161
- throw new index_js_1.NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
158
+ throw new NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
162
159
  }
163
160
  getSingleton(path, silent) {
164
161
  const t = this.getResource(path);
165
162
  if (!t && silent)
166
163
  return;
167
- if (t && t.kind === index_js_3.OpraSchema.Singleton.Kind)
164
+ if (t && t.kind === OpraSchema.Singleton.Kind)
168
165
  return t;
169
- throw new index_js_1.NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
166
+ throw new NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
170
167
  }
171
168
  /**
172
169
  * Export as Opra schema definition object
173
170
  */
174
171
  exportSchema() {
175
172
  const schema = {
176
- version: index_js_3.OpraSchema.SpecVersion,
173
+ version: OpraSchema.SpecVersion,
177
174
  url: this.url,
178
- info: (0, index_js_2.cloneObject)(this.info)
175
+ info: cloneObject(this.info)
179
176
  };
180
177
  if (this.references.size) {
181
178
  const references = {};
@@ -201,11 +198,10 @@ class ApiDocument {
201
198
  types[name] = r.exportSchema();
202
199
  }
203
200
  }
204
- return (0, index_js_2.omitUndefined)(schema);
201
+ return omitUndefined(schema);
205
202
  }
206
203
  invalidate() {
207
204
  this._typeCache.clear();
208
205
  this._typesCacheByCtor.clear();
209
206
  }
210
207
  }
211
- exports.ApiDocument = ApiDocument;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TYPENAME_PATTERN = exports.NAMESPACE_PATTERN = exports.METADATA_KEY = void 0;
4
- exports.METADATA_KEY = Symbol.for('opra.metadata');
5
- exports.NAMESPACE_PATTERN = /([A-Z$_]\w+)(?::.+)?/i;
6
- exports.TYPENAME_PATTERN = /^(.*)Type$/;
1
+ export const METADATA_KEY = Symbol.for('opra.metadata');
2
+ export const NAMESPACE_PATTERN = /([A-Z$_]\w+)(?::.+)?/i;
3
+ export const TYPENAME_PATTERN = /^(.*)Type$/;
@@ -1,22 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiField = void 0;
4
- const index_js_1 = require("../../helpers/index.js");
5
- const index_js_2 = require("../../schema/index.js");
6
- const constants_js_1 = require("../constants.js");
7
- const enum_type_js_1 = require("./enum-type.js");
1
+ import { omitUndefined } from '../../helpers/index.js';
2
+ import { OpraSchema } from '../../schema/index.js';
3
+ import { METADATA_KEY } from '../constants.js';
4
+ import { EnumType } from './enum-type.js';
8
5
  /**
9
6
  * @class ComplexType
10
7
  */
11
- exports.ApiField = function (...args) {
8
+ export const ApiField = function (...args) {
12
9
  // ClassDecorator
13
10
  if (!this) {
14
11
  const [options] = args;
15
12
  return function (target, propertyKey) {
16
13
  if (typeof propertyKey !== 'string')
17
14
  throw new TypeError(`Symbol properties can't be used as a field`);
18
- const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target.constructor) || {};
19
- metadata.kind = index_js_2.OpraSchema.ComplexType.Kind;
15
+ const metadata = Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {};
16
+ metadata.kind = OpraSchema.ComplexType.Kind;
20
17
  metadata.fields = metadata.fields || {};
21
18
  const designType = Reflect.getMetadata('design:type', target, propertyKey);
22
19
  const isArray = designType === Array;
@@ -34,17 +31,17 @@ exports.ApiField = function (...args) {
34
31
  o[v] = v;
35
32
  return o;
36
33
  }, {});
37
- (0, enum_type_js_1.EnumType)(enumObj);
34
+ EnumType(enumObj);
38
35
  elemMeta.enum = enumObj;
39
36
  }
40
37
  else {
41
- const m = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, options?.enum);
42
- if (!index_js_2.OpraSchema.isEnumType(m))
38
+ const m = Reflect.getOwnMetadata(METADATA_KEY, options?.enum);
39
+ if (!OpraSchema.isEnumType(m))
43
40
  throw new TypeError(`Invalid "enum" value. Did you forget to set metadata using EnumType() method?`);
44
41
  elemMeta.enum = options.enum;
45
42
  }
46
43
  }
47
- Reflect.defineMetadata(constants_js_1.METADATA_KEY, (0, index_js_1.omitUndefined)(metadata), target.constructor);
44
+ Reflect.defineMetadata(METADATA_KEY, omitUndefined(metadata), target.constructor);
48
45
  };
49
46
  }
50
47
  // Constructor
@@ -79,4 +76,4 @@ const proto = {
79
76
  return out;
80
77
  }
81
78
  };
82
- Object.assign(exports.ApiField.prototype, proto);
79
+ Object.assign(ApiField.prototype, proto);
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnyType = void 0;
4
- const tslib_1 = require("tslib");
5
- const simple_type_js_1 = require("../simple-type.js");
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
6
3
  let AnyType = class AnyType {
7
4
  };
8
- AnyType = tslib_1.__decorate([
9
- (0, simple_type_js_1.SimpleType)({
5
+ AnyType = __decorate([
6
+ SimpleType({
10
7
  description: 'Any value',
11
8
  ctor: Object
12
9
  })
13
10
  ], AnyType);
14
- exports.AnyType = AnyType;
11
+ export { AnyType };
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Base64Type = void 0;
4
- const tslib_1 = require("tslib");
5
- const simple_type_js_1 = require("../simple-type.js");
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
6
3
  const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:(?:[A-Za-z0-9+/][AQgw](:?==)?)|(?:[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=?))?$/;
7
4
  let Base64Type = class Base64Type {
8
5
  decode(v) {
@@ -29,10 +26,10 @@ let Base64Type = class Base64Type {
29
26
  throw new TypeError(`Invalid base64 value "${String(v).substring(0, 10)}..."`);
30
27
  }
31
28
  };
32
- Base64Type = tslib_1.__decorate([
33
- (0, simple_type_js_1.SimpleType)({
29
+ Base64Type = __decorate([
30
+ SimpleType({
34
31
  description: 'A stream of bytes, base64 encoded',
35
32
  ctor: ArrayBuffer
36
33
  })
37
34
  ], Base64Type);
38
- exports.Base64Type = Base64Type;
35
+ export { Base64Type };
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BigIntType = void 0;
4
- const tslib_1 = require("tslib");
5
- const simple_type_js_1 = require("../simple-type.js");
1
+ import { __decorate } from "tslib";
2
+ import { SimpleType } from '../simple-type.js';
6
3
  const BigIntConstructor = Object.getPrototypeOf(BigInt(0)).constructor;
7
4
  let BigIntType = class BigIntType {
8
5
  decode(v) {
@@ -23,11 +20,11 @@ let BigIntType = class BigIntType {
23
20
  throw new TypeError(`Invalid number value "${v}"`);
24
21
  }
25
22
  };
26
- BigIntType = tslib_1.__decorate([
27
- (0, simple_type_js_1.SimpleType)({
23
+ BigIntType = __decorate([
24
+ SimpleType({
28
25
  name: 'bigint',
29
26
  description: 'BigInt number',
30
27
  ctor: BigIntConstructor
31
28
  })
32
29
  ], BigIntType);
33
- exports.BigIntType = BigIntType;
30
+ export { BigIntType };
@@ -1,28 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BooleanType = void 0;
4
- const tslib_1 = require("tslib");
5
- const putil_varhelpers_1 = require("putil-varhelpers");
6
- const simple_type_js_1 = require("../simple-type.js");
1
+ import { __decorate } from "tslib";
2
+ import { toBoolean } from 'putil-varhelpers';
3
+ import { SimpleType } from '../simple-type.js';
7
4
  let BooleanType = class BooleanType {
8
5
  decode(v) {
9
6
  if (v == null)
10
7
  return v;
11
- return (0, putil_varhelpers_1.toBoolean)(v);
8
+ return toBoolean(v);
12
9
  }
13
10
  encode(v) {
14
11
  if (v == null)
15
12
  return v;
16
- return (0, putil_varhelpers_1.toBoolean)(v);
13
+ return toBoolean(v);
17
14
  }
18
15
  coerce(v) {
19
16
  return this.decode(v);
20
17
  }
21
18
  };
22
- BooleanType = tslib_1.__decorate([
23
- (0, simple_type_js_1.SimpleType)({
19
+ BooleanType = __decorate([
20
+ SimpleType({
24
21
  description: 'Simple true/false value',
25
22
  ctor: Boolean
26
23
  })
27
24
  ], BooleanType);
28
- exports.BooleanType = BooleanType;
25
+ export { BooleanType };