@opra/common 1.0.0-alpha.1 → 1.0.0-alpha.3

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 (91) hide show
  1. package/browser.js +155 -78
  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 +1 -1
  6. package/cjs/document/data-type/complex-type.js +2 -3
  7. package/cjs/document/data-type/extended-types/base64.type.js +2 -1
  8. package/cjs/document/data-type/extended-types/date-string.type.js +6 -3
  9. package/cjs/document/data-type/extended-types/date-time-string.type.js +6 -3
  10. package/cjs/document/data-type/extended-types/date-time.type.js +6 -3
  11. package/cjs/document/data-type/extended-types/date.type.js +6 -3
  12. package/cjs/document/data-type/extended-types/email.type.js +20 -10
  13. package/cjs/document/data-type/extended-types/field-path.type.js +8 -4
  14. package/cjs/document/data-type/extended-types/filter.type.js +6 -3
  15. package/cjs/document/data-type/extended-types/object-id.type.js +2 -1
  16. package/cjs/document/data-type/extended-types/operation-result.type.js +20 -10
  17. package/cjs/document/data-type/extended-types/time.type.js +6 -3
  18. package/cjs/document/data-type/extended-types/url.type.js +2 -1
  19. package/cjs/document/data-type/extended-types/uuid.type.js +4 -2
  20. package/cjs/document/data-type/primitive-types/any.type.js +2 -1
  21. package/cjs/document/data-type/primitive-types/bigint.type.js +2 -1
  22. package/cjs/document/data-type/primitive-types/boolean.type.js +2 -1
  23. package/cjs/document/data-type/primitive-types/integer.type.js +2 -1
  24. package/cjs/document/data-type/primitive-types/null.type.js +2 -1
  25. package/cjs/document/data-type/primitive-types/number.type.js +6 -3
  26. package/cjs/document/data-type/primitive-types/object.type.js +2 -1
  27. package/cjs/document/data-type/primitive-types/string.type.js +10 -5
  28. package/cjs/document/factory/api-document.factory.js +5 -0
  29. package/cjs/document/factory/data-type.factory.js +1 -1
  30. package/cjs/document/factory/http-api.factory.js +1 -1
  31. package/esm/document/api-document.js +18 -12
  32. package/esm/document/common/data-type-map.js +1 -1
  33. package/esm/document/constants.js +1 -1
  34. package/esm/document/data-type/api-field.js +1 -1
  35. package/esm/document/data-type/complex-type.js +2 -3
  36. package/esm/document/data-type/extended-types/base64.type.js +3 -2
  37. package/esm/document/data-type/extended-types/date-string.type.js +7 -4
  38. package/esm/document/data-type/extended-types/date-time-string.type.js +7 -4
  39. package/esm/document/data-type/extended-types/date-time.type.js +7 -4
  40. package/esm/document/data-type/extended-types/date.type.js +7 -4
  41. package/esm/document/data-type/extended-types/email.type.js +21 -11
  42. package/esm/document/data-type/extended-types/field-path.type.js +9 -5
  43. package/esm/document/data-type/extended-types/filter.type.js +7 -4
  44. package/esm/document/data-type/extended-types/object-id.type.js +3 -2
  45. package/esm/document/data-type/extended-types/operation-result.type.js +21 -11
  46. package/esm/document/data-type/extended-types/time.type.js +7 -4
  47. package/esm/document/data-type/extended-types/url.type.js +3 -2
  48. package/esm/document/data-type/extended-types/uuid.type.js +5 -3
  49. package/esm/document/data-type/primitive-types/any.type.js +3 -2
  50. package/esm/document/data-type/primitive-types/bigint.type.js +3 -2
  51. package/esm/document/data-type/primitive-types/boolean.type.js +3 -2
  52. package/esm/document/data-type/primitive-types/integer.type.js +3 -2
  53. package/esm/document/data-type/primitive-types/null.type.js +3 -2
  54. package/esm/document/data-type/primitive-types/number.type.js +7 -4
  55. package/esm/document/data-type/primitive-types/object.type.js +3 -2
  56. package/esm/document/data-type/primitive-types/string.type.js +11 -6
  57. package/esm/document/factory/api-document.factory.js +4 -0
  58. package/esm/document/factory/data-type.factory.js +1 -1
  59. package/esm/document/factory/http-api.factory.js +1 -1
  60. package/package.json +2 -2
  61. package/types/document/api-document.d.ts +3 -6
  62. package/types/document/factory/api-document.factory.d.ts +1 -1
  63. package/types/schema/document.interface.d.ts +13 -1
  64. package/types/schema/index.d.ts +1 -0
  65. package/cjs/document/data-type/decorators/api-field-decorator.js +0 -26
  66. package/cjs/document/data-type/decorators/complex-type.decorator.js +0 -33
  67. package/cjs/document/data-type/decorators/simple-type.decorator.js +0 -67
  68. package/cjs/document/http/decorators/http-controller.decorator.js +0 -117
  69. package/cjs/document/http/decorators/http-operation-entity.decorator.js +0 -461
  70. package/cjs/document/http/decorators/http-operation.decorator.js +0 -183
  71. package/cjs/helpers/is-url-string.js +0 -12
  72. package/cjs/http/opra-url-path.js +0 -266
  73. package/cjs/http/opra-url.js +0 -253
  74. package/esm/document/data-type/decorators/api-field-decorator.js +0 -22
  75. package/esm/document/data-type/decorators/complex-type.decorator.js +0 -28
  76. package/esm/document/data-type/decorators/simple-type.decorator.js +0 -61
  77. package/esm/document/http/decorators/http-controller.decorator.js +0 -112
  78. package/esm/document/http/decorators/http-operation-entity.decorator.js +0 -459
  79. package/esm/document/http/decorators/http-operation.decorator.js +0 -178
  80. package/esm/helpers/is-url-string.js +0 -7
  81. package/esm/http/opra-url-path.js +0 -260
  82. package/esm/http/opra-url.js +0 -249
  83. package/types/document/data-type/decorators/api-field-decorator.d.ts +0 -5
  84. package/types/document/data-type/decorators/complex-type.decorator.d.ts +0 -2
  85. package/types/document/data-type/decorators/simple-type.decorator.d.ts +0 -20
  86. package/types/document/http/decorators/http-controller.decorator.d.ts +0 -14
  87. package/types/document/http/decorators/http-operation-entity.decorator.d.ts +0 -100
  88. package/types/document/http/decorators/http-operation.decorator.d.ts +0 -30
  89. package/types/helpers/is-url-string.d.ts +0 -2
  90. package/types/http/opra-url-path.d.ts +0 -55
  91. package/types/http/opra-url.d.ts +0 -66
@@ -1,266 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.OpraURLPathComponent = exports.OpraURLPath = void 0;
5
- const tslib_1 = require("tslib");
6
- const fast_tokenizer_1 = require("fast-tokenizer");
7
- const putil_isplainobject_1 = tslib_1.__importDefault(require("putil-isplainobject"));
8
- const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
9
- const kLength = Symbol.for('kLength');
10
- const pathComponentRegEx = /^([^/?#:@]+)(?:@([^/?#:]*))?(?:::(.*))?$/;
11
- const decimalPattern = /^[+-]?\d+(\.\d+)?$/;
12
- const booleanPattern = /^true|false$/;
13
- /**
14
- * @class OpraURLPath
15
- */
16
- class OpraURLPath {
17
- constructor(...init) {
18
- this[_a] = 0;
19
- this._resolve(init.filter(x => x));
20
- }
21
- get length() {
22
- return this[kLength];
23
- }
24
- slice(start, end) {
25
- return new OpraURLPath(...[...this].slice(start, end));
26
- }
27
- resolve(...items) {
28
- this._resolve(items);
29
- return this;
30
- }
31
- join(...items) {
32
- this._resolve(items, true);
33
- return this;
34
- }
35
- isRelativeTo(basePath) {
36
- basePath = basePath instanceof OpraURLPath ? basePath : new OpraURLPath(basePath);
37
- let i;
38
- for (i = 0; i < basePath.length; i++) {
39
- if (String(this[i]) !== String(basePath[i]))
40
- return false;
41
- }
42
- return true;
43
- }
44
- forEach(callback) {
45
- let i = 0;
46
- for (const item of this.values()) {
47
- callback.call(this, item, i++, this);
48
- }
49
- }
50
- values() {
51
- const arr = new Array(this.length);
52
- for (let i = 0; i < this.length; i++)
53
- arr[i] = this[i];
54
- return arr.values();
55
- }
56
- toString() {
57
- const v = Array.from(this).join('/');
58
- return v ? '/' + v : '';
59
- }
60
- /* istanbul ignore next */
61
- [(_a = kLength, nodeInspectCustom)]() {
62
- return `(UrlPath [${this.toString()}])`;
63
- }
64
- [Symbol.iterator]() {
65
- return this.values();
66
- }
67
- _resolve(items, join) {
68
- let paths = (Array.isArray(items) ? items : [items]).map(item => {
69
- if (typeof item === 'object' && !(item instanceof OpraURLPath || item instanceof OpraURLPathComponent)) {
70
- item = new OpraURLPathComponent(item);
71
- if (item.resource.includes('/')) {
72
- const subPath = new OpraURLPath(item.resource);
73
- subPath[subPath.length - 1].key = item.key;
74
- return String(subPath);
75
- }
76
- }
77
- item = String(item);
78
- // Remove url parts coming after path (query, hash parts)
79
- if (item.includes('?'))
80
- item = (0, fast_tokenizer_1.splitString)(item, {
81
- delimiters: '?',
82
- quotes: true,
83
- brackets: true,
84
- keepBrackets: true,
85
- keepQuotes: true,
86
- })[0];
87
- if (item.includes('#'))
88
- item = (0, fast_tokenizer_1.splitString)(item, {
89
- delimiters: '#',
90
- quotes: true,
91
- brackets: true,
92
- keepBrackets: true,
93
- keepQuotes: true,
94
- })[0];
95
- return join ? removeLeadingSeparator(item) : item;
96
- });
97
- const oldLength = this.length;
98
- let n = 0;
99
- if (!join) {
100
- for (n = paths.length - 1; n >= 0; n--) {
101
- if (String(items[n]).startsWith('/'))
102
- break;
103
- }
104
- if (n > 0)
105
- paths = paths.slice(n);
106
- }
107
- const newPath = paths[0]?.startsWith('/') ? [] : Array.from(this).map(String);
108
- for (let i = 0; i < paths.length; i++) {
109
- const pathTokenizer = (0, fast_tokenizer_1.tokenize)(paths[i], { delimiters: '/', quotes: true, brackets: true });
110
- for (const x of pathTokenizer) {
111
- if (!x)
112
- continue;
113
- if (x.startsWith('.')) {
114
- if (x === '.')
115
- continue;
116
- if (x === '..') {
117
- newPath.pop();
118
- continue;
119
- }
120
- throw new TypeError('Invalid path string');
121
- }
122
- newPath.push(x);
123
- }
124
- }
125
- for (let i = 0; i < newPath.length; i++) {
126
- this[i] = OpraURLPathComponent.parse(newPath[i]);
127
- }
128
- for (let i = newPath.length; i < oldLength; i++) {
129
- delete this[i];
130
- }
131
- this[kLength] = newPath.length;
132
- }
133
- static join(...items) {
134
- const instance = new OpraURLPath();
135
- instance.join(...items);
136
- return instance;
137
- }
138
- static resolve(...items) {
139
- return new OpraURLPath(...items);
140
- }
141
- static relative(source, basePath) {
142
- source = source instanceof OpraURLPath ? source : new OpraURLPath(source);
143
- basePath = basePath instanceof OpraURLPath ? basePath : new OpraURLPath(basePath);
144
- let i;
145
- for (i = 0; i < basePath.length; i++) {
146
- if (String(source[i]) !== String(basePath[i]))
147
- return;
148
- }
149
- return new OpraURLPath(Array.from(source).slice(i).join('/'));
150
- }
151
- }
152
- exports.OpraURLPath = OpraURLPath;
153
- /**
154
- *
155
- * @class OpraURLPathComponent
156
- */
157
- class OpraURLPathComponent {
158
- constructor(init) {
159
- this.resource = init.resource;
160
- this.key = init.key;
161
- this.args = init.args;
162
- this.typeCast = init.typeCast;
163
- }
164
- toString() {
165
- let out = encodeURIComponent(this.resource).replace(/%24/, '$');
166
- if (this.key) {
167
- if (typeof this.key === 'object' && (0, putil_isplainobject_1.default)(this.key)) {
168
- const arr = [];
169
- for (const k of Object.keys(this.key)) {
170
- let v = this.key[k];
171
- if (typeof v === 'number' || typeof v === 'boolean')
172
- v = String(v);
173
- else
174
- v = '"' + encodeURIComponent(String(v)) + '"';
175
- arr.push(encodeURIComponent(k) + '=' + v);
176
- }
177
- out += '@' + arr.join(';');
178
- }
179
- else
180
- out += '@' + encodeURIComponent(String(this.key));
181
- }
182
- if (this.args) {
183
- const arr = [];
184
- for (const k of Object.keys(this.args)) {
185
- arr.push(encodeURIComponent(k) + '=' + encodeURIComponent(String(this.args[k])));
186
- }
187
- out += '(' + arr.join(';') + ')';
188
- }
189
- if (this.typeCast)
190
- out += '::' + encodeURIComponent(this.typeCast);
191
- return out;
192
- }
193
- /* istanbul ignore next */
194
- [nodeInspectCustom]() {
195
- return this.toString();
196
- }
197
- /**
198
- * Factory method.
199
- * @param input
200
- */
201
- static parse(input) {
202
- const m = pathComponentRegEx.exec(input);
203
- if (!m)
204
- throw Object.assign(new TypeError('Invalid Opra URL'), {
205
- code: 'ERR_INVALID_OPRA_URL',
206
- input,
207
- });
208
- let key;
209
- if (m[2]) {
210
- const s = decodeURIComponent(m[2]);
211
- const b = (0, fast_tokenizer_1.splitString)(s, { delimiters: ';', quotes: true, escape: false, keepQuotes: true, keepBrackets: true });
212
- for (const n of b) {
213
- const c = (0, fast_tokenizer_1.splitString)(n, {
214
- delimiters: '=',
215
- quotes: true,
216
- escape: false,
217
- keepQuotes: true,
218
- keepBrackets: true,
219
- });
220
- if ((b.length > 1 && c.length < 2) ||
221
- (key && c.length >= 2 && typeof key !== 'object') ||
222
- (c.length < 2 && typeof key === 'object'))
223
- throw Object.assign(new TypeError('Invalid Opra URL. name:value pair required for multiple key format'), {
224
- pathComponent: input,
225
- code: 'ERR_INVALID_OPRA_URL',
226
- });
227
- if (c.length >= 2) {
228
- key = key || {};
229
- const k = c.shift() || '';
230
- let v = c.join('=');
231
- if (decimalPattern.test(v))
232
- v = Number(v);
233
- else if (booleanPattern.test(v))
234
- v = Boolean(v);
235
- else if (v.startsWith('"') && v.endsWith('"'))
236
- v = v.substring(1, v.length - 1);
237
- else if (v.startsWith("'") && v.endsWith("'"))
238
- v = v.substring(1, v.length - 1);
239
- key[k] = v;
240
- }
241
- else {
242
- if (decimalPattern.test(c[0]))
243
- key = Number(c[0]);
244
- else if (booleanPattern.test(c[0]))
245
- key = Boolean(c[0]);
246
- else
247
- key = c[0];
248
- }
249
- }
250
- return new OpraURLPathComponent({
251
- resource: decodeURIComponent(m[1]),
252
- key,
253
- typeCast: m[3] ? decodeURIComponent(m[3]) : undefined,
254
- });
255
- }
256
- return new OpraURLPathComponent({
257
- resource: decodeURIComponent(m[1]),
258
- typeCast: m[3] ? decodeURIComponent(m[3]) : undefined,
259
- });
260
- }
261
- }
262
- exports.OpraURLPathComponent = OpraURLPathComponent;
263
- function removeLeadingSeparator(s) {
264
- const m = /^\/*(.*)/.exec(s);
265
- return m?.[1] || s;
266
- }
@@ -1,253 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.OpraURL = void 0;
5
- const fast_tokenizer_1 = require("fast-tokenizer");
6
- const opra_url_path_js_1 = require("./opra-url-path.js");
7
- const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
8
- const urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
9
- const schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
10
- const hostRegEx = /^([^/:]+)(?::(\d+))?$/;
11
- const hostnameRegEx = /^([^/:]+)$/;
12
- const kContext = Symbol.for('kContext');
13
- const kPath = Symbol.for('kPath');
14
- const kSearchParams = Symbol.for('kSearchParams');
15
- class OpraURL {
16
- constructor(input, base) {
17
- this[_a] = {
18
- protocol: '',
19
- username: '',
20
- hostname: '',
21
- port: '',
22
- hash: '',
23
- password: '',
24
- };
25
- this[kSearchParams] = new URLSearchParams();
26
- this[kPath] = new opra_url_path_js_1.OpraURLPath();
27
- if (input)
28
- this._parse(String(input));
29
- if (base && !this.host) {
30
- const baseUrl = base instanceof OpraURL ? base : new OpraURL(base);
31
- this[kContext].protocol = baseUrl.protocol;
32
- this[kContext].hostname = baseUrl.hostname;
33
- this[kContext].username = baseUrl.username;
34
- this[kContext].password = baseUrl.password;
35
- this[kContext].port = baseUrl.port;
36
- this.path = opra_url_path_js_1.OpraURLPath.join(baseUrl.path, this.path);
37
- }
38
- }
39
- get address() {
40
- if (this[kContext].address == null) {
41
- let address = '';
42
- if (this[kContext].hostname) {
43
- address +=
44
- (this[kContext].protocol || 'http:') +
45
- '//' +
46
- (this[kContext].username || this[kContext].password
47
- ? (this[kContext].username ? encodeURIComponent(this[kContext].username) : '') +
48
- (this[kContext].password ? ':' + encodeURIComponent(this[kContext].password) : '') +
49
- '@'
50
- : '') +
51
- this.host;
52
- }
53
- this[kContext].address = address + (this.pathname !== '/' ? this.pathname : '');
54
- }
55
- return this[kContext].address;
56
- }
57
- get host() {
58
- return this.hostname ? this.hostname + (this.port ? ':' + this.port : '') : '';
59
- }
60
- set host(v) {
61
- if (v) {
62
- const m = hostRegEx.exec(v);
63
- if (!m)
64
- throw Object.assign(new TypeError('Invalid host'), {
65
- host: v,
66
- code: 'ERR_INVALID_URL',
67
- });
68
- this.hostname = m[1];
69
- this.port = m[2] || '';
70
- }
71
- else {
72
- this.hostname = '';
73
- this.port = '';
74
- }
75
- }
76
- get hostname() {
77
- return this[kContext].hostname;
78
- }
79
- set hostname(v) {
80
- if (v) {
81
- if (!hostnameRegEx.test(v))
82
- throw Object.assign(new TypeError('Invalid hostname'), {
83
- hostname: v,
84
- code: 'ERR_INVALID_URL',
85
- });
86
- this[kContext].hostname = v;
87
- }
88
- else
89
- this[kContext].hostname = '';
90
- this.invalidate();
91
- }
92
- get href() {
93
- return this.address + this.search + this.hash;
94
- }
95
- get password() {
96
- return this[kContext].password;
97
- }
98
- set password(v) {
99
- this[kContext].password = v ?? '';
100
- this.invalidate();
101
- }
102
- get port() {
103
- return this[kContext].port;
104
- }
105
- set port(value) {
106
- if (value) {
107
- // noinspection SuspiciousTypeOfGuard
108
- const v = typeof value === 'number' ? value : parseInt(value, 10);
109
- if (isNaN(v) || v < 1 || v > 65535 || v % 1 > 0)
110
- throw Object.assign(new TypeError(`Invalid port number (${value})`), {
111
- hostname: v,
112
- code: 'ERR_INVALID_URL',
113
- });
114
- this[kContext].port = String(v);
115
- }
116
- else
117
- this[kContext].port = '';
118
- this.invalidate();
119
- }
120
- get protocol() {
121
- return this[kContext].protocol;
122
- }
123
- set protocol(v) {
124
- if (v) {
125
- if (!schemeRegEx.test(v))
126
- throw Object.assign(new TypeError('Invalid protocol'), {
127
- protocol: v,
128
- code: 'ERR_INVALID_URL',
129
- });
130
- this[kContext].protocol = v + (v.endsWith(':') ? '' : ':');
131
- }
132
- else
133
- this[kContext].protocol = '';
134
- this.invalidate();
135
- }
136
- get username() {
137
- return this[kContext].username;
138
- }
139
- set username(v) {
140
- this[kContext].username = v ?? '';
141
- this.invalidate();
142
- }
143
- get origin() {
144
- return this.hostname ? this.protocol + '//' + this.hostname : '';
145
- }
146
- get path() {
147
- return this[kPath];
148
- }
149
- set path(path) {
150
- // noinspection SuspiciousTypeOfGuard
151
- this[kPath] = path instanceof opra_url_path_js_1.OpraURLPath ? path : new opra_url_path_js_1.OpraURLPath(path);
152
- this[kContext].pathname = String(this[kPath]);
153
- this.invalidate();
154
- }
155
- get pathname() {
156
- if (this[kContext].pathname == null)
157
- this[kContext].pathname = this.path.toString() || '/';
158
- return this[kContext].pathname;
159
- }
160
- set pathname(v) {
161
- this[kPath] = new opra_url_path_js_1.OpraURLPath(v);
162
- this.invalidate();
163
- }
164
- get hash() {
165
- return this[kContext].hash;
166
- }
167
- set hash(v) {
168
- this[kContext].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
169
- }
170
- get search() {
171
- const s = this[kSearchParams].toString();
172
- return s ? '?' + s : '';
173
- }
174
- set search(v) {
175
- this[kSearchParams] = new URLSearchParams(v);
176
- }
177
- get searchParams() {
178
- return this[kSearchParams];
179
- }
180
- set setSearchParams(v) {
181
- this[kSearchParams] = v;
182
- }
183
- invalidate() {
184
- this[kContext].address = undefined;
185
- this[kContext].pathname = undefined;
186
- }
187
- join(...items) {
188
- this.path = this.path.join(...items);
189
- this.invalidate();
190
- return this;
191
- }
192
- resolve(...items) {
193
- this.path = this.path.resolve(...items);
194
- this.invalidate();
195
- return this;
196
- }
197
- toString() {
198
- return this.href;
199
- }
200
- _parse(input) {
201
- const m = urlRegEx.exec(input);
202
- if (!m)
203
- throw Object.assign(new TypeError('Invalid URL'), {
204
- input,
205
- code: 'ERR_INVALID_URL',
206
- });
207
- this.protocol = m[1];
208
- const isAbsolute = !!m[2];
209
- if (isAbsolute) {
210
- let tokens = (0, fast_tokenizer_1.splitString)(m[2], { delimiters: '@' });
211
- if (tokens.length > 1) {
212
- this.host = tokens[1];
213
- tokens = (0, fast_tokenizer_1.splitString)(tokens[0], { delimiters: ':' });
214
- this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
215
- this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
216
- }
217
- else
218
- this.host = tokens[0];
219
- }
220
- else {
221
- this.host = '';
222
- this.username = '';
223
- this.password = '';
224
- }
225
- input = m[3] || '';
226
- let tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '#', quotes: true, brackets: true });
227
- input = tokenizer.next() || '';
228
- this.hash = tokenizer.join('#');
229
- tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '?', quotes: true, brackets: true });
230
- this.path = new opra_url_path_js_1.OpraURLPath(tokenizer.next());
231
- this.search = tokenizer.join('&');
232
- }
233
- /* istanbul ignore next */
234
- [(_a = kContext, nodeInspectCustom)]() {
235
- // this._update();
236
- return {
237
- protocol: this.protocol,
238
- username: this.username,
239
- password: this.password,
240
- host: this.host,
241
- hostname: this.hostname,
242
- origin: this.origin,
243
- path: this.path,
244
- pathname: this.pathname,
245
- search: this.search,
246
- hash: this.hash,
247
- };
248
- }
249
- }
250
- exports.OpraURL = OpraURL;
251
- OpraURL.kContext = kContext;
252
- OpraURL.kPath = kPath;
253
- OpraURL.kParams = kSearchParams;
@@ -1,22 +0,0 @@
1
- import { omitUndefined } from '../../../helpers/index.js';
2
- import { OpraSchema } from '../../../schema/index.js';
3
- import { DATATYPE_METADATA } from '../../constants.js';
4
- export function ApiFieldDecorator(options) {
5
- return function (target, propertyKey) {
6
- if (typeof propertyKey !== 'string')
7
- throw new TypeError(`Symbol properties can't be used as a field`);
8
- const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) || {};
9
- metadata.kind = OpraSchema.ComplexType.Kind;
10
- metadata.fields = metadata.fields || {};
11
- const designType = Reflect.getMetadata('design:type', target, propertyKey);
12
- const elemMeta = (metadata.fields[propertyKey] = {
13
- ...options,
14
- });
15
- if (designType === Array) {
16
- elemMeta.isArray = true;
17
- }
18
- else
19
- elemMeta.type = elemMeta.type || designType;
20
- Reflect.defineMetadata(DATATYPE_METADATA, omitUndefined(metadata), target.constructor);
21
- };
22
- }
@@ -1,28 +0,0 @@
1
- import omit from 'lodash.omit';
2
- import { OpraSchema } from '../../../schema/index.js';
3
- import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN } from '../../constants.js';
4
- export function ComplexTypeDecorator(options) {
5
- return function (target) {
6
- let name;
7
- if (!options?.embedded) {
8
- if (options?.name) {
9
- if (!CLASS_NAME_PATTERN.test(options.name))
10
- throw new TypeError(`"${options.name}" is not a valid type name`);
11
- name = options.name;
12
- }
13
- else {
14
- name = target.name.match(EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
15
- }
16
- }
17
- let metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target);
18
- if (!metadata) {
19
- metadata = {};
20
- Reflect.defineMetadata(DATATYPE_METADATA, metadata, target);
21
- }
22
- metadata.kind = OpraSchema.ComplexType.Kind;
23
- metadata.name = name;
24
- // Merge options
25
- if (options)
26
- Object.assign(metadata, omit(options, ['kind', 'name', 'base', 'fields']));
27
- };
28
- }
@@ -1,61 +0,0 @@
1
- import omit from 'lodash.omit';
2
- import { OpraSchema } from '../../../schema/index.js';
3
- import { CLASS_NAME_PATTERN, DATATYPE_METADATA, EXTRACT_TYPENAME_PATTERN } from '../../constants.js';
4
- export function SimpleTypeDecoratorFactory(options) {
5
- const decoratorChain = [];
6
- /**
7
- *
8
- */
9
- const decorator = function (target) {
10
- let name;
11
- if (!options?.embedded) {
12
- if (options?.name) {
13
- if (!CLASS_NAME_PATTERN.test(options.name))
14
- throw new TypeError(`"${options.name}" is not a valid type name`);
15
- name = options.name;
16
- }
17
- else {
18
- name = target.name.match(EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
19
- name = name.toLowerCase();
20
- }
21
- }
22
- const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target) || {};
23
- metadata.kind = OpraSchema.SimpleType.Kind;
24
- metadata.name = name;
25
- if (options)
26
- Object.assign(metadata, omit(options, ['kind', 'name']));
27
- Reflect.defineMetadata(DATATYPE_METADATA, metadata, target);
28
- };
29
- decorator.Example = (value, description) => {
30
- decoratorChain.push((meta) => {
31
- meta.examples = meta.examples || [];
32
- meta.examples.push({
33
- description,
34
- value,
35
- });
36
- });
37
- return decorator;
38
- };
39
- return decorator;
40
- }
41
- export function AttributeDecoratorFactory(options) {
42
- return (target, propertyKey) => {
43
- if (typeof propertyKey !== 'string')
44
- throw new TypeError(`Symbol properties can't be decorated with Attribute`);
45
- const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target.constructor) || {};
46
- const designType = Reflect.getMetadata('design:type', target, propertyKey);
47
- let format = 'string';
48
- if (designType === Boolean)
49
- format = 'boolean';
50
- else if (designType === Number)
51
- format = 'number';
52
- metadata.kind = OpraSchema.SimpleType.Kind;
53
- metadata.attributes = metadata.attributes || {};
54
- metadata.attributes[propertyKey] = {
55
- format: options?.format || format,
56
- description: options?.description,
57
- deprecated: options?.deprecated,
58
- };
59
- Reflect.defineMetadata(DATATYPE_METADATA, metadata, target.constructor);
60
- };
61
- }