@opra/common 0.10.2 → 0.12.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 (126) hide show
  1. package/cjs/filter/antlr/OpraFilterLexer.js +1 -1
  2. package/cjs/filter/antlr/OpraFilterListener.js +1 -1
  3. package/cjs/filter/antlr/OpraFilterParser.js +5 -5
  4. package/cjs/filter/antlr/OpraFilterVisitor.js +1 -1
  5. package/cjs/filter/filter-tree-visitor.js +8 -2
  6. package/cjs/filter/opra-error-listener.js +2 -2
  7. package/cjs/filter/parse.js +1 -1
  8. package/cjs/helpers/responsive-map.js +45 -28
  9. package/{esm/http/enums/http-headers.enum.js → cjs/http/enums/http-headers-codes.enum.js} +95 -92
  10. package/{esm/http/enums/http-status.enum.js → cjs/http/enums/http-status-codes.enum.js} +62 -59
  11. package/cjs/http/http-headers.js +213 -0
  12. package/cjs/http/http-param-codec.js +6 -0
  13. package/cjs/http/http-params.js +321 -0
  14. package/cjs/http/http-request-node.js +105 -0
  15. package/cjs/http/http-request.js +73 -88
  16. package/cjs/http/http-response.js +23 -0
  17. package/cjs/http/index.js +13 -2
  18. package/cjs/http/multipart/batch-multipart.js +12 -12
  19. package/cjs/http/param-codec/boolean-codec.js +25 -0
  20. package/cjs/http/param-codec/date-codec.js +44 -0
  21. package/cjs/http/param-codec/filter-codec.js +18 -0
  22. package/cjs/http/param-codec/integer-codec.js +19 -0
  23. package/cjs/http/param-codec/number-codec.js +26 -0
  24. package/cjs/http/param-codec/string-codec.js +25 -0
  25. package/cjs/http/utils/encodeURIParam.js +21 -0
  26. package/cjs/http/utils/normalize-headers.js +2 -2
  27. package/cjs/i18n/i18n.js +1 -4
  28. package/cjs/schema/implementation/opra-document.js +12 -11
  29. package/cjs/schema/implementation/resource/collection-resource-info.js +7 -0
  30. package/cjs/url/opra-url-path.js +96 -72
  31. package/cjs/url/opra-url-search-params.js +16 -234
  32. package/cjs/url/opra-url.js +201 -160
  33. package/esm/filter/antlr/OpraFilterLexer.d.ts +1 -1
  34. package/esm/filter/antlr/OpraFilterLexer.js +1 -1
  35. package/esm/filter/antlr/OpraFilterListener.d.ts +1 -1
  36. package/esm/filter/antlr/OpraFilterListener.js +1 -1
  37. package/esm/filter/antlr/OpraFilterParser.d.ts +1 -1
  38. package/esm/filter/antlr/OpraFilterParser.js +5 -5
  39. package/esm/filter/antlr/OpraFilterVisitor.d.ts +1 -1
  40. package/esm/filter/antlr/OpraFilterVisitor.js +1 -1
  41. package/esm/filter/ast/expressions/arithmetic-expression.d.ts +1 -1
  42. package/esm/filter/ast/expressions/comparison-expression.d.ts +1 -1
  43. package/esm/filter/ast/expressions/logical-expression.d.ts +1 -1
  44. package/esm/filter/build.d.ts +3 -3
  45. package/esm/filter/errors.d.ts +4 -2
  46. package/esm/filter/filter-tree-visitor.d.ts +2 -1
  47. package/esm/filter/filter-tree-visitor.js +8 -2
  48. package/esm/filter/opra-error-listener.d.ts +2 -2
  49. package/esm/filter/opra-error-listener.js +2 -2
  50. package/esm/filter/parse.d.ts +1 -1
  51. package/esm/filter/parse.js +1 -1
  52. package/esm/helpers/responsive-map.d.ts +19 -5
  53. package/esm/helpers/responsive-map.js +45 -28
  54. package/esm/http/enums/{http-headers.enum.d.ts → http-headers-codes.enum.d.ts} +1 -1
  55. package/{cjs/http/enums/http-headers.enum.js → esm/http/enums/http-headers-codes.enum.js} +92 -95
  56. package/esm/http/enums/{http-status.enum.d.ts → http-status-codes.enum.d.ts} +1 -1
  57. package/{cjs/http/enums/http-status.enum.js → esm/http/enums/http-status-codes.enum.js} +59 -62
  58. package/esm/http/http-headers.d.ts +70 -0
  59. package/esm/http/http-headers.js +209 -0
  60. package/esm/http/http-param-codec.d.ts +4 -0
  61. package/esm/http/http-param-codec.js +2 -0
  62. package/esm/http/http-params.d.ts +99 -0
  63. package/esm/http/http-params.js +317 -0
  64. package/esm/http/http-request-node.d.ts +34 -0
  65. package/esm/http/http-request-node.js +101 -0
  66. package/esm/http/http-request.d.ts +73 -31
  67. package/esm/http/http-request.js +72 -87
  68. package/esm/http/http-response.d.ts +41 -0
  69. package/esm/http/http-response.js +19 -0
  70. package/esm/http/index.d.ts +13 -2
  71. package/esm/http/index.js +13 -2
  72. package/esm/http/interfaces/client-http-headers.interface.d.ts +1 -1
  73. package/esm/http/interfaces/server-http-headers.interface.d.ts +1 -1
  74. package/esm/http/multipart/batch-multipart.d.ts +1 -1
  75. package/esm/http/multipart/batch-multipart.js +12 -12
  76. package/esm/http/multipart/http-request-content.d.ts +1 -1
  77. package/esm/http/multipart/http-response-content.d.ts +1 -1
  78. package/esm/http/param-codec/boolean-codec.d.ts +5 -0
  79. package/esm/http/param-codec/boolean-codec.js +21 -0
  80. package/esm/http/param-codec/date-codec.d.ts +16 -0
  81. package/esm/http/param-codec/date-codec.js +40 -0
  82. package/esm/http/param-codec/filter-codec.d.ts +6 -0
  83. package/esm/http/param-codec/filter-codec.js +14 -0
  84. package/esm/http/param-codec/integer-codec.d.ts +9 -0
  85. package/esm/http/param-codec/integer-codec.js +15 -0
  86. package/esm/http/param-codec/number-codec.d.ts +12 -0
  87. package/esm/http/param-codec/number-codec.js +22 -0
  88. package/esm/http/param-codec/string-codec.d.ts +14 -0
  89. package/esm/http/param-codec/string-codec.js +21 -0
  90. package/esm/http/utils/encodeURIParam.d.ts +1 -0
  91. package/esm/http/utils/encodeURIParam.js +17 -0
  92. package/esm/http/utils/normalize-headers.js +2 -2
  93. package/esm/i18n/i18n.d.ts +6 -6
  94. package/esm/i18n/i18n.js +1 -4
  95. package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +1 -1
  96. package/esm/schema/decorators/opr-complex-type.decorator.d.ts +1 -1
  97. package/esm/schema/decorators/opr-simple-type.decorator.d.ts +1 -1
  98. package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +1 -1
  99. package/esm/schema/implementation/data-type/complex-type.d.ts +1 -1
  100. package/esm/schema/implementation/data-type/union-type.d.ts +1 -1
  101. package/esm/schema/implementation/document-builder.d.ts +1 -1
  102. package/esm/schema/implementation/opra-document.d.ts +2 -2
  103. package/esm/schema/implementation/opra-document.js +12 -11
  104. package/esm/schema/implementation/query/collection-count-query.d.ts +1 -1
  105. package/esm/schema/implementation/query/collection-create-query.d.ts +1 -1
  106. package/esm/schema/implementation/query/collection-delete-many-query.d.ts +1 -1
  107. package/esm/schema/implementation/query/collection-get-query.d.ts +1 -1
  108. package/esm/schema/implementation/query/collection-search-query.d.ts +1 -1
  109. package/esm/schema/implementation/query/collection-update-many-query.d.ts +1 -1
  110. package/esm/schema/implementation/query/collection-update-query.d.ts +1 -1
  111. package/esm/schema/implementation/query/field-get-query.d.ts +1 -1
  112. package/esm/schema/implementation/query/index.d.ts +4 -4
  113. package/esm/schema/implementation/query/singleton-get-query.d.ts +1 -1
  114. package/esm/schema/implementation/resource/collection-resource-info.d.ts +2 -0
  115. package/esm/schema/implementation/resource/collection-resource-info.js +7 -0
  116. package/esm/schema/interfaces/data-type.metadata.d.ts +4 -4
  117. package/esm/schema/interfaces/resource.metadata.d.ts +9 -9
  118. package/esm/schema/types.d.ts +8 -8
  119. package/esm/url/opra-url-path-component.d.ts +1 -1
  120. package/esm/url/opra-url-path.d.ts +24 -18
  121. package/esm/url/opra-url-path.js +96 -72
  122. package/esm/url/opra-url-search-params.d.ts +3 -42
  123. package/esm/url/opra-url-search-params.js +16 -234
  124. package/esm/url/opra-url.d.ts +38 -28
  125. package/esm/url/opra-url.js +201 -160
  126. package/package.json +12 -12
@@ -1,53 +1,43 @@
1
- import { EventEmitter } from 'events';
1
+ var _a;
2
2
  import { tokenize } from 'fast-tokenizer';
3
3
  import { isURL } from '../utils/index.js';
4
4
  import { OpraURLPathComponent } from './opra-url-path-component.js';
5
5
  import { decodePathComponent, encodePathComponent, normalizePath } from './utils/path-utils.js';
6
6
  const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
7
- export class OpraURLPath extends EventEmitter {
8
- constructor(...args) {
9
- super();
10
- this._entries = [];
11
- for (const x of args) {
12
- if (isURL(x)) {
13
- this._parse(x.pathname);
14
- continue;
15
- }
16
- // noinspection SuspiciousTypeOfGuard
17
- if (x instanceof OpraURLPath)
18
- this._entries.push(...x._entries);
19
- else
20
- this.add(x);
21
- }
7
+ const kEntries = Symbol('kEntries');
8
+ const kOptions = Symbol('kOptions');
9
+ export class OpraURLPath {
10
+ constructor(init, options) {
11
+ this[_a] = [];
12
+ this[kOptions] = { ...options, onChange: undefined };
13
+ if (Array.isArray(init))
14
+ this.join(...init);
15
+ else if (init)
16
+ this.join(init);
17
+ this[kOptions].onChange = options?.onChange;
22
18
  }
23
19
  get size() {
24
- return this._entries.length;
20
+ return this[kEntries].length;
25
21
  }
26
- add(component, key, typeCast) {
27
- this._add(component, key, typeCast);
28
- this.emit('change');
22
+ changed() {
23
+ if (this[kOptions].onChange)
24
+ this[kOptions].onChange();
29
25
  }
30
26
  clear() {
31
- this._entries = [];
32
- this.emit('change');
27
+ this[kEntries] = [];
28
+ this.changed();
33
29
  }
34
30
  get(index) {
35
- return this._entries[index];
36
- }
37
- join(pathString) {
38
- const pathTokenizer = tokenize(normalizePath(pathString, true), {
39
- delimiters: '/', quotes: true, brackets: true,
40
- });
41
- for (const x of pathTokenizer) {
42
- const p = decodePathComponent(x);
43
- this._add(p);
44
- }
45
- this.emit('change');
31
+ return this[kEntries][index];
32
+ }
33
+ join(...source) {
34
+ source.forEach(x => this._join(this[kEntries], x));
35
+ this.changed();
46
36
  return this;
47
37
  }
48
38
  entries() {
49
39
  let i = -1;
50
- const arr = [...this._entries];
40
+ const arr = [...this[kEntries]];
51
41
  return {
52
42
  [Symbol.iterator]() {
53
43
  return this;
@@ -61,9 +51,46 @@ export class OpraURLPath extends EventEmitter {
61
51
  }
62
52
  };
63
53
  }
54
+ forEach(callback) {
55
+ for (const item of this[kEntries]) {
56
+ callback.call(this, item, this);
57
+ }
58
+ }
59
+ getResource(index) {
60
+ const v = this[kEntries][index];
61
+ return v == null ? undefined : v.resource;
62
+ }
63
+ getKey(index) {
64
+ const v = this[kEntries][index];
65
+ return v == null ? undefined : v.key;
66
+ }
67
+ pop() {
68
+ const out = this[kEntries].pop();
69
+ this.changed();
70
+ return out;
71
+ }
72
+ shift() {
73
+ const out = this[kEntries].shift();
74
+ this.changed();
75
+ return out;
76
+ }
77
+ slice(start, end) {
78
+ return new OpraURLPath(this[kEntries].slice(start, end));
79
+ }
80
+ splice(start, deleteCount, join) {
81
+ const items = (join ? this._join([], join) : []);
82
+ this[kEntries].splice(start, deleteCount, ...items);
83
+ this.changed();
84
+ }
85
+ unshift(join) {
86
+ return this.splice(0, 0, join);
87
+ }
88
+ toString() {
89
+ return this[kEntries].map(x => encodePathComponent(x.resource, x.key, x.typeCast)).join('/');
90
+ }
64
91
  values() {
65
92
  let i = -1;
66
- const arr = [...this._entries];
93
+ const arr = [...this[kEntries]];
67
94
  return {
68
95
  [Symbol.iterator]() {
69
96
  return this;
@@ -77,48 +104,45 @@ export class OpraURLPath extends EventEmitter {
77
104
  }
78
105
  };
79
106
  }
80
- forEach(callback) {
81
- for (const item of this._entries) {
82
- callback.call(this, item.resource, item.key, this);
107
+ _join(target, source) {
108
+ if (typeof source === 'string') {
109
+ const pathTokenizer = tokenize(normalizePath(source, true), {
110
+ delimiters: '/', quotes: true, brackets: true,
111
+ });
112
+ for (const x of pathTokenizer) {
113
+ const p = decodePathComponent(x);
114
+ target.push(new OpraURLPathComponent(p));
115
+ }
116
+ return;
83
117
  }
118
+ if (source instanceof OpraURLPath) {
119
+ target.push(...source[kEntries].map(x => new OpraURLPathComponent(x)));
120
+ return;
121
+ }
122
+ if (typeof source === 'object' && source.path instanceof OpraURLPath) {
123
+ this._join(target, source.path);
124
+ return;
125
+ }
126
+ if (isURL(source)) {
127
+ this._join(target, source.pathname);
128
+ return;
129
+ }
130
+ if (Array.isArray(source)) {
131
+ source.forEach(x => this._join(target, x));
132
+ return;
133
+ }
134
+ target.push(new OpraURLPathComponent(source));
84
135
  }
85
- getResource(index) {
86
- const v = this._entries[index];
87
- return v == null ? undefined : v.resource;
88
- }
89
- getKey(index) {
90
- const v = this._entries[index];
91
- return v == null ? undefined : v.key;
92
- }
93
- toString() {
94
- return this._entries.map(x => encodePathComponent(x.resource, x.key, x.typeCast)).join('/');
136
+ /* istanbul ignore next */
137
+ [(_a = kEntries, nodeInspectCustom)]() {
138
+ return this[kEntries];
95
139
  }
96
140
  [Symbol.iterator]() {
97
141
  return this.entries();
98
142
  }
99
- /* istanbul ignore next */
100
- [nodeInspectCustom]() {
101
- return this._entries;
102
- }
103
- _add(component, key, typeCast) {
104
- if (component instanceof OpraURLPathComponent) {
105
- this._entries.push(component);
106
- }
107
- else if (typeof component === 'object')
108
- this._entries.push(new OpraURLPathComponent(component));
109
- else
110
- this._entries.push(new OpraURLPathComponent({ resource: component, key, typeCast }));
111
- }
112
- _parse(v) {
113
- if (!v)
114
- return;
115
- const pathTokenizer = tokenize(v, { delimiters: '/', quotes: true, brackets: true });
116
- for (const x of pathTokenizer) {
117
- if (!x)
118
- continue;
119
- const p = decodePathComponent(x);
120
- this._add(p);
121
- }
122
- this.emit('change');
143
+ get [Symbol.toStringTag]() {
144
+ return 'OpraURLPath';
123
145
  }
124
146
  }
147
+ OpraURLPath.kEntries = kEntries;
148
+ OpraURLPath.kOptions = kOptions;
@@ -1,44 +1,5 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { StrictOmit } from 'ts-gems';
4
- import { ResponsiveMap } from '../helpers/index.js';
5
- import { Format } from './formats/format.js';
6
- declare const nodeInspectCustom: unique symbol;
7
- interface OpraURLSearchParamItem {
8
- name: string;
9
- format?: Format | string;
10
- array?: boolean | 'strict';
11
- arrayDelimiter?: string;
12
- minArrayItems?: number;
13
- maxArrayItems?: number;
14
- }
15
- export declare class OpraURLSearchParams extends EventEmitter {
16
- protected _params: ResponsiveMap<string, OpraURLSearchParamItem>;
17
- private _entries;
18
- private _size;
19
- constructor(init?: (string | URLSearchParams | OpraURLSearchParams));
20
- get size(): number;
21
- addAll(values: URLSearchParams | OpraURLSearchParams | Map<string, any> | Record<string, any>): void;
22
- append(name: string, value?: any): void;
23
- clear(): void;
24
- defineParam(name: string, options?: StrictOmit<OpraURLSearchParamItem, 'name'>): this;
25
- delete(name: string): void;
26
- entries(): IterableIterator<[string, any]>;
27
- forEach(callback: (value: any, name: string, _this: this) => void): void;
28
- get(name: string, index?: number): any | null;
29
- getAll(name: string): any[];
30
- has(name: string): boolean;
31
- keys(): IterableIterator<string>;
32
- set(name: string, value?: any): void;
33
- sort(compareFn?: (a: string, b: string) => number): void;
34
- values(): IterableIterator<any>;
35
- toString(): string;
36
- parse(input: string): void;
37
- toURLSearchParams(): URLSearchParams;
38
- [Symbol.iterator](): IterableIterator<[string, any]>;
1
+ import { HttpParams, HttpParamsInit, HttpParamsOptions } from '../http/http-params.js';
2
+ export declare class OpraURLSearchParams extends HttpParams {
3
+ constructor(init?: HttpParamsInit, options?: HttpParamsOptions);
39
4
  get [Symbol.toStringTag](): string;
40
- [nodeInspectCustom](): ResponsiveMap<string, any[]>;
41
- protected _delete(name: string): boolean;
42
- protected _add(name: string, value: any): boolean;
43
5
  }
44
- export {};
@@ -1,242 +1,24 @@
1
- import { EventEmitter } from 'events';
2
- import { splitString, tokenize } from 'fast-tokenizer';
3
- import { ResponsiveMap } from '../helpers/index.js';
4
- import { BooleanFormat } from './formats/boolean-format.js';
5
- import { DateFormat } from './formats/date-format.js';
6
- import { FilterFormat } from './formats/filter-format.js';
7
- import { IntegerFormat } from './formats/integer-format.js';
8
- import { NumberFormat } from './formats/number-format.js';
9
- import { StringFormat } from './formats/string-format.js';
10
- const internalFormats = {
11
- 'integer': new IntegerFormat(),
12
- 'number': new NumberFormat(),
13
- 'string': new StringFormat(),
14
- 'boolean': new BooleanFormat(),
15
- 'date': new DateFormat(),
16
- 'filter': new FilterFormat()
17
- };
18
- const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
19
- export class OpraURLSearchParams extends EventEmitter {
20
- constructor(init) {
21
- super();
22
- this._params = new ResponsiveMap();
23
- this._entries = new ResponsiveMap();
24
- this._size = 0;
25
- this.defineParam('$filter', { format: 'filter' });
26
- this.defineParam('$limit', { format: new IntegerFormat({ min: 0 }) });
27
- this.defineParam('$skip', { format: new IntegerFormat({ min: 0 }) });
28
- this.defineParam('$pick', { format: 'string', array: 'strict' });
29
- this.defineParam('$omit', { format: 'string', array: 'strict' });
30
- this.defineParam('$include', { format: 'string', array: 'strict' });
31
- this.defineParam('$sort', { format: 'string', array: 'strict' });
32
- this.defineParam('$distinct', { format: 'boolean' });
33
- this.defineParam('$count', { format: 'boolean' });
34
- if (init) {
35
- if (typeof init === 'string')
36
- this.parse(init);
37
- else
38
- this.addAll(init);
39
- }
40
- }
41
- get size() {
42
- return this._size;
43
- }
44
- addAll(values) {
45
- let changed = false;
46
- if (typeof values.forEach === 'function') {
47
- values.forEach((value, name) => {
48
- changed = this._add(name, value) || changed;
49
- });
50
- }
51
- else if (typeof values === 'object') {
52
- Object.entries((name, value) => {
53
- changed = this._add(name, value) || changed;
54
- });
55
- }
56
- else
57
- throw new TypeError(`Invalid argument`);
58
- if (changed)
59
- this.emit('change');
60
- }
61
- append(name, value) {
62
- if (this._add(name, value))
63
- this.emit('change');
64
- }
65
- clear() {
66
- this._entries.clear();
67
- this._size = 0;
68
- this.emit('change');
69
- }
70
- defineParam(name, options) {
71
- if (!name)
72
- throw new Error('Parameter name required');
73
- const meta = {
1
+ import { HttpParams } from '../http/http-params.js';
2
+ import { IntegerCodec } from '../http/param-codec/integer-codec.js';
3
+ export class OpraURLSearchParams extends HttpParams {
4
+ constructor(init, options) {
5
+ super(init, {
74
6
  ...options,
75
- name,
76
- format: options?.format || 'string'
77
- };
78
- if (typeof meta.format === 'string' && !internalFormats[meta.format])
79
- throw new Error(`Unknown data format "${meta.format}"`);
80
- meta.format = meta.format || 'string';
81
- this._params.set(name, meta);
82
- return this;
83
- }
84
- delete(name) {
85
- if (this._delete(name))
86
- this.emit('change');
87
- }
88
- entries() {
89
- const items = [];
90
- this.forEach((value, name) => {
91
- items.push([name, value]);
92
- });
93
- return items.values();
94
- }
95
- forEach(callback) {
96
- for (const [name, entry] of this._entries.entries()) {
97
- for (let i = 0; i < entry.length; i++) {
98
- callback(entry[i], name, this);
99
- }
100
- }
101
- }
102
- get(name, index) {
103
- const entry = this._entries.get(name);
104
- const v = entry && entry[index || 0];
105
- return v == null ? null : v;
106
- }
107
- getAll(name) {
108
- const entry = this._entries.get(name);
109
- return entry ? entry.slice(0) : [];
110
- }
111
- has(name) {
112
- return this._entries.has(name);
113
- }
114
- keys() {
115
- return this._entries.keys();
116
- }
117
- set(name, value) {
118
- this._delete(name);
119
- this._add(name, value);
120
- this.emit('change');
121
- }
122
- sort(compareFn) {
123
- this._entries.sort(compareFn);
124
- this.emit('change');
125
- }
126
- values() {
127
- const items = [];
128
- this.forEach((value) => items.push(value));
129
- return items.values();
130
- }
131
- toString() {
132
- let out = '';
133
- this.forEach((v, k) => {
134
- const qi = this._params.get(k);
135
- const format = qi
136
- ? (typeof qi.format === 'string' ? internalFormats[qi.format] : qi.format)
137
- : undefined;
138
- const stringify = (x) => encodeURIComponent(format ? format.stringify(x, k) : (x == null ? '' : '' + x));
139
- const val = Array.isArray(v)
140
- ? v.map(stringify).join(qi?.arrayDelimiter || ',')
141
- : stringify(v);
142
- if (val) {
143
- if (out.length > 0)
144
- out += '&';
145
- out += k + '=' + val;
146
- }
147
- });
148
- return out;
149
- }
150
- parse(input) {
151
- this._entries.clear();
152
- this._size = 0;
153
- if (input && input.startsWith('?'))
154
- input = input.substring(1);
155
- if (!input)
156
- return;
157
- const tokenizer = tokenize(input, { delimiters: '&', quotes: true, brackets: true });
158
- for (const token of tokenizer) {
159
- if (!token)
160
- continue;
161
- const itemTokenizer = tokenize(token, {
162
- delimiters: '=',
163
- quotes: true,
164
- brackets: true,
165
- });
166
- const k = decodeURIComponent(itemTokenizer.next() || '');
167
- const v = itemTokenizer.join('=');
168
- const qi = this._params.get(k);
169
- if (qi?.array) {
170
- const values = splitString(v, {
171
- delimiters: qi?.arrayDelimiter || ',',
172
- brackets: true,
173
- quotes: true
174
- }).map((x) => decodeURIComponent(x));
175
- this._add(k, values);
7
+ params: {
8
+ '$filter': { codec: 'filter' },
9
+ '$limit': { codec: new IntegerCodec({ min: 0 }) },
10
+ '$skip': { codec: new IntegerCodec({ min: 0 }) },
11
+ '$pick': { codec: 'string', array: 'strict' },
12
+ '$omit': { codec: 'string', array: 'strict' },
13
+ '$include': { codec: 'string', array: 'strict' },
14
+ '$sort': { codec: 'string', array: 'strict' },
15
+ '$distinct': { codec: 'boolean' },
16
+ '$count': { codec: 'boolean' },
17
+ ...options?.params
176
18
  }
177
- else {
178
- this._add(k, decodeURIComponent(v));
179
- }
180
- }
181
- this.emit('change');
182
- }
183
- toURLSearchParams() {
184
- const out = new URLSearchParams();
185
- this.forEach((v, k) => {
186
- const qi = this._params.get(k);
187
- const format = qi
188
- ? (typeof qi.format === 'string' ? internalFormats[qi.format] : qi.format)
189
- : undefined;
190
- const stringify = (x) => format ? format.stringify(x, k) : (x == null ? '' : '' + x);
191
- const val = Array.isArray(v)
192
- ? v.map(stringify).join(qi?.arrayDelimiter || ',')
193
- : stringify(v);
194
- out.append(k, val);
195
19
  });
196
- return out;
197
- }
198
- [Symbol.iterator]() {
199
- return this.entries();
200
20
  }
201
21
  get [Symbol.toStringTag]() {
202
22
  return 'URLSearchParams';
203
23
  }
204
- [nodeInspectCustom]() {
205
- return this._entries;
206
- }
207
- _delete(name) {
208
- const a = this._entries.get(name);
209
- if (!a)
210
- return false;
211
- this._size -= a.length;
212
- this._entries.delete(name);
213
- return true;
214
- }
215
- _add(name, value) {
216
- const qi = this._params.get(name);
217
- const format = qi ?
218
- (typeof qi.format === 'string' ? internalFormats[qi.format] : qi.format) : undefined;
219
- const fn = (x) => format ? format.parse(x, name) : x;
220
- let v = Array.isArray(value) ? value.map(fn) : fn(value);
221
- if (qi) {
222
- if (qi.array === 'strict')
223
- v = Array.isArray(v) ? v : [v];
224
- else if (qi.array)
225
- v = Array.isArray(v) && v.length === 1 ? v[0] : v;
226
- if (Array.isArray(v)) {
227
- if (qi.minArrayItems && v.length < qi.minArrayItems)
228
- throw new Error(`"${name}" parameter requires at least ${qi.minArrayItems} values`);
229
- if (qi.maxArrayItems && v.length > qi.maxArrayItems)
230
- throw new Error(`"${name}" parameter accepts up to ${qi.maxArrayItems} values`);
231
- }
232
- }
233
- let entry = this._entries.get(name);
234
- if (!entry) {
235
- entry = [];
236
- this._entries.set(name, entry);
237
- }
238
- entry.push(v);
239
- this._size++;
240
- return true;
241
- }
242
24
  }
@@ -1,42 +1,52 @@
1
+ import type { HttpParamDefinition } from '../http/http-params.js';
1
2
  import { OpraURLPath } from './opra-url-path.js';
3
+ import { OpraURLPathComponentInit } from './opra-url-path-component.js';
2
4
  import { OpraURLSearchParams } from './opra-url-search-params.js';
3
5
  declare const nodeInspectCustom: unique symbol;
4
- declare const CONTEXT_KEY: unique symbol;
5
- declare const PATH_KEY: unique symbol;
6
- declare const SEARCHPARAMS_KEY: unique symbol;
6
+ declare const kContext: unique symbol;
7
+ declare const kPath: unique symbol;
8
+ declare const kSearchParams: unique symbol;
7
9
  export declare class OpraURL {
8
- protected [CONTEXT_KEY]: {
10
+ protected static kContext: symbol;
11
+ protected static kPath: symbol;
12
+ protected static kSearchParams: symbol;
13
+ protected [kContext]: {
9
14
  protocol: string;
10
15
  username: string;
11
- password: string;
16
+ pathname: string;
17
+ prefix: string;
12
18
  hostname: string;
13
- pathPrefix: string;
14
- port: number | null;
19
+ port: string;
15
20
  hash: string;
16
- pathname: string;
21
+ password: string;
17
22
  search: string;
23
+ address: string;
18
24
  needUpdate: boolean;
19
25
  };
20
- protected [PATH_KEY]: OpraURLPath;
21
- protected [SEARCHPARAMS_KEY]: OpraURLSearchParams;
22
- constructor(input?: string, pathPrefix?: string);
26
+ protected [kPath]: OpraURLPath;
27
+ protected [kSearchParams]: OpraURLSearchParams;
28
+ constructor(input?: string | URL | OpraURL, base?: string | URL | OpraURL);
29
+ constructor(input?: string | URL | OpraURL, options?: {
30
+ base?: string | URL | OpraURL;
31
+ params?: Record<string, HttpParamDefinition>;
32
+ });
23
33
  get address(): string;
34
+ get host(): string;
35
+ set host(v: string);
36
+ get hostname(): string;
37
+ set hostname(v: string);
24
38
  get href(): string;
39
+ get password(): string;
40
+ set password(v: string);
41
+ get port(): string;
42
+ set port(value: string);
43
+ get prefix(): string;
44
+ set prefix(value: string);
25
45
  get protocol(): string;
26
46
  set protocol(v: string);
27
47
  get username(): string;
28
48
  set username(v: string);
29
- get password(): string;
30
- set password(v: string);
31
- get host(): string;
32
- set host(v: string);
33
- get hostname(): string;
34
- set hostname(v: string);
35
- get port(): number | null;
36
- set port(v: number | null);
37
49
  get origin(): string;
38
- get pathPrefix(): string;
39
- set pathPrefix(v: string);
40
50
  get path(): OpraURLPath;
41
51
  get pathname(): string;
42
52
  set pathname(v: string);
@@ -45,18 +55,18 @@ export declare class OpraURL {
45
55
  set hash(v: string);
46
56
  get search(): string;
47
57
  set search(v: string);
48
- addPath(name: string, key?: any): this;
49
- addSearchParam(name: string, value?: any): this;
58
+ parse(input: string): void;
59
+ join(...source: (string | OpraURLPath | URL | OpraURL | OpraURLPathComponentInit)[]): this;
60
+ addParam(name: string, value?: any): this;
61
+ setParam(name: string, value?: any): this;
50
62
  setHost(v: string): this;
51
63
  setHostname(v: string): this;
52
64
  setProtocol(v: string): this;
53
- setPort(v: number | null): this;
65
+ setPort(v: string | number | null): this;
54
66
  setPrefix(v: string): this;
55
67
  setPathname(v: string): this;
56
68
  setHash(v: string): this;
57
69
  setSearch(v: string): this;
58
- setSearchParam(name: string, value?: any): this;
59
- parse(input: string): this;
60
70
  toString(): string;
61
71
  [nodeInspectCustom](): {
62
72
  protocol: string;
@@ -72,8 +82,8 @@ export declare class OpraURL {
72
82
  searchParams: OpraURLSearchParams;
73
83
  hash: string;
74
84
  };
75
- protected _invalidate(): void;
76
85
  protected _update(): void;
77
- protected _setPathname(v: string, inclSvcRoot?: boolean): void;
86
+ protected _setPathname(v: string, trimPrefix?: boolean): void;
87
+ protected _changed(): void;
78
88
  }
79
89
  export {};