@opra/common 0.22.0 → 0.23.1
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.
- package/browser.js +957 -1566
- package/cjs/document/api-document.js +7 -3
- package/cjs/document/data-type/api-field.js +2 -2
- package/cjs/document/data-type/complex-type.js +17 -63
- package/cjs/document/data-type/data-type.js +0 -9
- package/cjs/document/data-type/enum-type.js +2 -8
- package/cjs/document/data-type/mapped-type.js +0 -36
- package/cjs/document/data-type/simple-type.js +2 -8
- package/cjs/document/data-type/union-type.js +1 -37
- package/cjs/document/index.js +2 -0
- package/cjs/document/resource/collection.js +75 -32
- package/cjs/document/resource/singleton.js +31 -20
- package/cjs/document/resource/storage.js +6 -20
- package/cjs/document/utils/generate-codec.js +39 -0
- package/cjs/exception/http-errors/bad-request.error.js +2 -3
- package/cjs/exception/http-errors/failed-dependency.error.js +2 -3
- package/cjs/exception/http-errors/forbidden.error.js +2 -3
- package/cjs/exception/http-errors/internal-server.error.js +2 -3
- package/cjs/exception/http-errors/method-not-allowed.error.js +2 -3
- package/cjs/exception/http-errors/not-acceptable.error.js +2 -3
- package/cjs/exception/http-errors/not-found.error.js +2 -3
- package/cjs/exception/http-errors/unauthorized.error.js +2 -3
- package/cjs/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/cjs/exception/opra-exception.js +48 -33
- package/cjs/exception/resource-errors/resource-not-found.error.js +2 -3
- package/cjs/exception/wrap-exception.js +16 -16
- package/cjs/helpers/index.js +1 -1
- package/cjs/helpers/is-url-string.js +14 -0
- package/cjs/helpers/object-utils.js +2 -2
- package/cjs/helpers/responsive-map.js +4 -4
- package/cjs/helpers/type-guards.js +15 -3
- package/cjs/http/index.js +2 -9
- package/cjs/http/opra-url-path.js +251 -0
- package/cjs/{url → http}/opra-url.js +53 -109
- package/cjs/i18n/i18n.js +1 -1
- package/cjs/index.js +0 -2
- package/cjs/schema/opra-schema.ns.js +1 -1
- package/cjs/schema/resource/operation.interface.js +2 -0
- package/esm/document/api-document.js +9 -5
- package/esm/document/data-type/api-field.js +2 -2
- package/esm/document/data-type/complex-type.js +13 -59
- package/esm/document/data-type/data-type.js +0 -9
- package/esm/document/data-type/enum-type.js +2 -8
- package/esm/document/data-type/mapped-type.js +0 -36
- package/esm/document/data-type/simple-type.js +2 -8
- package/esm/document/data-type/union-type.js +1 -37
- package/esm/document/index.js +2 -0
- package/esm/document/resource/collection.js +75 -32
- package/esm/document/resource/singleton.js +31 -20
- package/esm/document/resource/storage.js +6 -20
- package/esm/document/utils/generate-codec.js +33 -0
- package/esm/exception/http-errors/bad-request.error.js +2 -3
- package/esm/exception/http-errors/failed-dependency.error.js +2 -3
- package/esm/exception/http-errors/forbidden.error.js +2 -3
- package/esm/exception/http-errors/internal-server.error.js +2 -3
- package/esm/exception/http-errors/method-not-allowed.error.js +2 -3
- package/esm/exception/http-errors/not-acceptable.error.js +2 -3
- package/esm/exception/http-errors/not-found.error.js +2 -3
- package/esm/exception/http-errors/unauthorized.error.js +2 -3
- package/esm/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/esm/exception/opra-exception.js +47 -32
- package/esm/exception/resource-errors/resource-not-found.error.js +2 -3
- package/esm/exception/wrap-exception.js +16 -16
- package/esm/helpers/index.js +1 -1
- package/esm/helpers/is-url-string.js +9 -0
- package/esm/helpers/object-utils.js +2 -2
- package/esm/helpers/responsive-map.js +4 -4
- package/esm/helpers/type-guards.js +11 -2
- package/esm/http/index.js +2 -9
- package/esm/http/opra-url-path.js +246 -0
- package/esm/{url → http}/opra-url.js +53 -109
- package/esm/i18n/i18n.js +2 -2
- package/esm/index.js +0 -2
- package/esm/schema/opra-schema.ns.js +1 -1
- package/esm/schema/resource/operation.interface.js +1 -0
- package/package.json +5 -5
- package/types/document/api-document.d.ts +4 -1
- package/types/document/data-type/complex-type.d.ts +7 -12
- package/types/document/data-type/data-type.d.ts +0 -6
- package/types/document/data-type/enum-type.d.ts +2 -4
- package/types/document/data-type/mapped-type.d.ts +1 -5
- package/types/document/data-type/simple-type.d.ts +2 -4
- package/types/document/data-type/union-type.d.ts +1 -5
- package/types/document/index.d.ts +2 -0
- package/types/document/interfaces/collection-resource.interface.d.ts +10 -0
- package/types/document/interfaces/singleton-resource.interface.d.ts +7 -0
- package/types/document/interfaces/storage-resource.interface.d.ts +8 -0
- package/types/document/resource/collection.d.ts +41 -35
- package/types/document/resource/resource.d.ts +1 -0
- package/types/document/resource/singleton.d.ts +24 -21
- package/types/document/resource/storage.d.ts +14 -17
- package/types/document/utils/generate-codec.d.ts +10 -0
- package/types/exception/error-issue.d.ts +2 -1
- package/types/exception/http-errors/bad-request.error.d.ts +2 -1
- package/types/exception/http-errors/failed-dependency.error.d.ts +2 -1
- package/types/exception/http-errors/forbidden.error.d.ts +2 -1
- package/types/exception/http-errors/internal-server.error.d.ts +2 -1
- package/types/exception/http-errors/method-not-allowed.error.d.ts +2 -1
- package/types/exception/http-errors/not-acceptable.error.d.ts +2 -1
- package/types/exception/http-errors/not-found.error.d.ts +2 -1
- package/types/exception/http-errors/unauthorized.error.d.ts +2 -1
- package/types/exception/http-errors/unprocessable-entity.error.d.ts +2 -1
- package/types/exception/opra-exception.d.ts +13 -8
- package/types/exception/wrap-exception.d.ts +1 -1
- package/types/helpers/index.d.ts +1 -1
- package/types/helpers/is-url-string.d.ts +2 -0
- package/types/helpers/object-utils.d.ts +1 -1
- package/types/helpers/type-guards.d.ts +3 -0
- package/types/http/index.d.ts +2 -9
- package/types/http/opra-url-path.d.ts +54 -0
- package/types/{url → http}/opra-url.d.ts +9 -13
- package/types/index.d.ts +0 -2
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/opra-schema.ns.d.ts +1 -1
- package/types/schema/resource/collection.interface.d.ts +29 -8
- package/types/schema/resource/operation.interface.d.ts +3 -0
- package/types/schema/resource/singleton.interface.d.ts +5 -5
- package/types/schema/resource/storage.interface.d.ts +42 -5
- package/cjs/helpers/is-url.js +0 -8
- package/cjs/http/codecs/boolean-codec.js +0 -24
- package/cjs/http/codecs/date-codec.js +0 -41
- package/cjs/http/codecs/filter-codec.js +0 -17
- package/cjs/http/codecs/integer-codec.js +0 -19
- package/cjs/http/codecs/number-codec.js +0 -24
- package/cjs/http/codecs/string-codec.js +0 -23
- package/cjs/http/http-params.js +0 -353
- package/cjs/http/multipart/batch-multipart.js +0 -170
- package/cjs/http/multipart/http-request-content.js +0 -17
- package/cjs/http/multipart/http-response-content.js +0 -14
- package/cjs/http/multipart/index.js +0 -2
- package/cjs/url/index.js +0 -8
- package/cjs/url/opra-url-path-component.js +0 -30
- package/cjs/url/opra-url-path.js +0 -155
- package/cjs/url/utils/decode-path-component.js +0 -41
- package/cjs/url/utils/encode-path-component.js +0 -27
- package/cjs/utils/path-utils.js +0 -24
- package/esm/helpers/is-url.js +0 -4
- package/esm/http/codecs/boolean-codec.js +0 -20
- package/esm/http/codecs/date-codec.js +0 -37
- package/esm/http/codecs/filter-codec.js +0 -13
- package/esm/http/codecs/integer-codec.js +0 -15
- package/esm/http/codecs/number-codec.js +0 -20
- package/esm/http/codecs/string-codec.js +0 -19
- package/esm/http/http-params.js +0 -348
- package/esm/http/multipart/batch-multipart.js +0 -170
- package/esm/http/multipart/http-request-content.js +0 -17
- package/esm/http/multipart/http-response-content.js +0 -14
- package/esm/http/multipart/index.js +0 -2
- package/esm/url/index.js +0 -5
- package/esm/url/opra-url-path-component.js +0 -26
- package/esm/url/opra-url-path.js +0 -151
- package/esm/url/utils/decode-path-component.js +0 -37
- package/esm/url/utils/encode-path-component.js +0 -22
- package/esm/utils/path-utils.js +0 -19
- package/types/helpers/is-url.d.ts +0 -1
- package/types/http/codecs/boolean-codec.d.ts +0 -5
- package/types/http/codecs/date-codec.d.ts +0 -16
- package/types/http/codecs/filter-codec.d.ts +0 -6
- package/types/http/codecs/integer-codec.d.ts +0 -11
- package/types/http/codecs/number-codec.d.ts +0 -14
- package/types/http/codecs/string-codec.d.ts +0 -16
- package/types/http/http-params.d.ts +0 -114
- package/types/http/interfaces/client-http-headers.interface.d.ts +0 -65
- package/types/http/interfaces/server-http-headers.interface.d.ts +0 -1
- package/types/http/multipart/batch-multipart.d.ts +0 -0
- package/types/http/multipart/http-request-content.d.ts +0 -0
- package/types/http/multipart/http-response-content.d.ts +0 -0
- package/types/http/multipart/index.d.ts +0 -0
- package/types/schema/resource/endpoint.interface.d.ts +0 -29
- package/types/url/index.d.ts +0 -5
- package/types/url/opra-url-path-component.d.ts +0 -15
- package/types/url/opra-url-path.d.ts +0 -36
- package/types/url/utils/decode-path-component.d.ts +0 -5
- package/types/url/utils/encode-path-component.d.ts +0 -1
- package/types/utils/path-utils.d.ts +0 -2
- /package/cjs/{http/interfaces/client-http-headers.interface.js → document/interfaces/collection-resource.interface.js} +0 -0
- /package/cjs/{http/interfaces/server-http-headers.interface.js → document/interfaces/singleton-resource.interface.js} +0 -0
- /package/cjs/{schema/resource/endpoint.interface.js → document/interfaces/storage-resource.interface.js} +0 -0
- /package/esm/{http/interfaces/client-http-headers.interface.js → document/interfaces/collection-resource.interface.js} +0 -0
- /package/esm/{http/interfaces/server-http-headers.interface.js → document/interfaces/singleton-resource.interface.js} +0 -0
- /package/esm/{schema/resource/endpoint.interface.js → document/interfaces/storage-resource.interface.js} +0 -0
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import Highland from '@browsery/highland';
|
|
3
|
-
// import { Readable } from 'stream';
|
|
4
|
-
// import { uid } from 'uid';
|
|
5
|
-
// import { isReadable } from '../../helpers/index.js';
|
|
6
|
-
// import { HttpHeaderCodes } from '../enums/http-headers-codes.enum.js';
|
|
7
|
-
// import { HttpStatusCodes } from '../enums/http-status-codes.enum.js';
|
|
8
|
-
// import { normalizeHeaders } from '../utils/normalize-headers.js';
|
|
9
|
-
// import { HttpRequestContent, IHttpRequestContent } from './http-request-content.js';
|
|
10
|
-
// import { HttpResponseContent, IHttpResponseContent } from './http-response-content.js';
|
|
11
|
-
//
|
|
12
|
-
// const CRLF = '\r\n';
|
|
13
|
-
// const CHARSET_PATTERN = / *charset=./i;
|
|
14
|
-
//
|
|
15
|
-
// type Part = {
|
|
16
|
-
// headers: Record<string, string | string[]>;
|
|
17
|
-
// contentId?: string;
|
|
18
|
-
// content: HttpRequestContent | HttpResponseContent | BatchMultipart;
|
|
19
|
-
// }
|
|
20
|
-
//
|
|
21
|
-
// export class BatchMultipart {
|
|
22
|
-
// protected _parts: Part[] = [];
|
|
23
|
-
// readonly boundary: string;
|
|
24
|
-
//
|
|
25
|
-
// constructor() {
|
|
26
|
-
// this.boundary = 'batch_' + uid(12);
|
|
27
|
-
// }
|
|
28
|
-
//
|
|
29
|
-
// addRequestPart(content: IHttpRequestContent, part?: {
|
|
30
|
-
// contentId?: string;
|
|
31
|
-
// headers?: Record<string, string | string[]>;
|
|
32
|
-
// }): this {
|
|
33
|
-
// const headers: any = {
|
|
34
|
-
// ...normalizeHeaders(part?.headers || {}, true),
|
|
35
|
-
// [HttpHeaderCodes.Content_Type]: 'application/http',
|
|
36
|
-
// [HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
37
|
-
// };
|
|
38
|
-
// if (part?.contentId)
|
|
39
|
-
// headers[HttpHeaderCodes.Content_ID] = part.contentId;
|
|
40
|
-
// this._parts.push({
|
|
41
|
-
// headers,
|
|
42
|
-
// contentId: part?.contentId,
|
|
43
|
-
// content: new HttpRequestContent(content)
|
|
44
|
-
// });
|
|
45
|
-
// return this;
|
|
46
|
-
// }
|
|
47
|
-
//
|
|
48
|
-
// addHttpResponse(content: IHttpResponseContent, part?: {
|
|
49
|
-
// contentId?: string;
|
|
50
|
-
// headers?: Record<string, string | string[]>;
|
|
51
|
-
// }): this {
|
|
52
|
-
// const headers: any = {
|
|
53
|
-
// ...normalizeHeaders(part?.headers || {}, true),
|
|
54
|
-
// [HttpHeaderCodes.Content_Type]: 'application/http',
|
|
55
|
-
// [HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
56
|
-
// };
|
|
57
|
-
// if (part?.contentId)
|
|
58
|
-
// headers[HttpHeaderCodes.Content_ID] = part.contentId;
|
|
59
|
-
// this._parts.push({
|
|
60
|
-
// headers,
|
|
61
|
-
// contentId: part?.contentId,
|
|
62
|
-
// content: new HttpResponseContent(content)
|
|
63
|
-
// });
|
|
64
|
-
// return this;
|
|
65
|
-
// }
|
|
66
|
-
//
|
|
67
|
-
// addBatch(batch: BatchMultipart, part?: {
|
|
68
|
-
// contentId?: string;
|
|
69
|
-
// headers?: Record<string, string | string[]>;
|
|
70
|
-
// }): this {
|
|
71
|
-
// const headers: any = {
|
|
72
|
-
// ...normalizeHeaders(part?.headers || {}, true),
|
|
73
|
-
// [HttpHeaderCodes.Content_Type]: 'application/http',
|
|
74
|
-
// [HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
75
|
-
// };
|
|
76
|
-
// if (part?.contentId)
|
|
77
|
-
// headers[HttpHeaderCodes.Content_ID] = part.contentId;
|
|
78
|
-
// this._parts.push({
|
|
79
|
-
// headers,
|
|
80
|
-
// contentId: part?.contentId,
|
|
81
|
-
// content: batch
|
|
82
|
-
// });
|
|
83
|
-
// return this;
|
|
84
|
-
// }
|
|
85
|
-
//
|
|
86
|
-
// stream(): NodeJS.ReadableStream {
|
|
87
|
-
// const chunks: (Buffer | Readable)[] = [];
|
|
88
|
-
// this._build(chunks);
|
|
89
|
-
// return Highland(chunks).flatten().toNodeStream();
|
|
90
|
-
// }
|
|
91
|
-
//
|
|
92
|
-
// protected _build(target: (Buffer | Readable)[]) {
|
|
93
|
-
// for (const part of this._parts) {
|
|
94
|
-
// if (part.content instanceof HttpRequestContent || part.content instanceof HttpResponseContent) {
|
|
95
|
-
// let contentBody = part.content.data;
|
|
96
|
-
// let contentLength = 0;
|
|
97
|
-
// const contentHeaders = normalizeHeaders(part.content.headers);
|
|
98
|
-
// if (contentBody) {
|
|
99
|
-
// const contentType = String(contentHeaders['content-type'] || '').split(/\s*;\s*/);
|
|
100
|
-
// let charset = '';
|
|
101
|
-
// if (isReadable(contentBody)) {
|
|
102
|
-
// contentLength = parseInt(String(contentHeaders['content-length']), 10) || 0;
|
|
103
|
-
// // const l = parseInt(String(contentHeaders['content-length']), 10);
|
|
104
|
-
// // if (isNaN(l))
|
|
105
|
-
// // throw new TypeError('"content-length" header required for streamed responses');
|
|
106
|
-
// } else if (typeof contentBody === 'object') {
|
|
107
|
-
// if (typeof contentBody.stream === 'function') { // File and Blob
|
|
108
|
-
// contentType[0] = contentBody.type || 'binary';
|
|
109
|
-
// contentLength = contentBody.size;
|
|
110
|
-
// contentBody = contentBody.stream();
|
|
111
|
-
// } else if (Buffer.isBuffer(contentBody)) {
|
|
112
|
-
// contentHeaders['content-length'] = String(contentBody.length);
|
|
113
|
-
// } else {
|
|
114
|
-
// contentType[0] = contentType[0] || 'application/json';
|
|
115
|
-
// charset = 'utf-8';
|
|
116
|
-
// contentBody = Buffer.from(JSON.stringify(contentBody), 'utf-8');
|
|
117
|
-
// contentLength = contentBody.length;
|
|
118
|
-
// }
|
|
119
|
-
// } else {
|
|
120
|
-
// contentType[0] = contentType[0] || 'text/plain';
|
|
121
|
-
// charset = 'utf-8';
|
|
122
|
-
// contentBody = Buffer.from(String(contentBody), 'utf-8');
|
|
123
|
-
// contentLength = contentBody.length;
|
|
124
|
-
// }
|
|
125
|
-
// if (contentType[0]) {
|
|
126
|
-
// if (charset) {
|
|
127
|
-
// const i = contentType.findIndex(x => CHARSET_PATTERN.test(String(x)));
|
|
128
|
-
// if (i > 0) contentType[i] = 'charset=' + charset;
|
|
129
|
-
// else contentType.join('charset=' + charset);
|
|
130
|
-
// }
|
|
131
|
-
// contentHeaders['content-type'] = contentType.join(';');
|
|
132
|
-
// }
|
|
133
|
-
// if (contentLength)
|
|
134
|
-
// contentHeaders['content-length'] = String(contentLength);
|
|
135
|
-
// }
|
|
136
|
-
//
|
|
137
|
-
// let s = '--' + this.boundary + CRLF;
|
|
138
|
-
// for (const [k, v] of Object.entries(part.headers)) {
|
|
139
|
-
// if (!(v === '' || v == null))
|
|
140
|
-
// s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
141
|
-
// }
|
|
142
|
-
// s += CRLF;
|
|
143
|
-
//
|
|
144
|
-
// if (part.content instanceof HttpRequestContent)
|
|
145
|
-
// s += (part.content.method || 'GET').toUpperCase() + ' ' + part.content.url + ' HTTP/1.1' + CRLF;
|
|
146
|
-
// else
|
|
147
|
-
// s += 'HTTP/1.1 ' + part.content.status + (HttpStatusCodes[part.content.status] || 'Unknown') + CRLF;
|
|
148
|
-
// if (part.content.headers) {
|
|
149
|
-
// for (const [k, v] of Object.entries(part.content.headers)) {
|
|
150
|
-
// if (v === '' || v == null)
|
|
151
|
-
// continue;
|
|
152
|
-
// if (k === 'set-cookie' && Array.isArray(v)) {
|
|
153
|
-
// v.forEach(x => s += k + ': ' + x);
|
|
154
|
-
// } else
|
|
155
|
-
// s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
156
|
-
// }
|
|
157
|
-
// }
|
|
158
|
-
// s += CRLF;
|
|
159
|
-
// target.push(Buffer.from(s, 'utf-8'));
|
|
160
|
-
//
|
|
161
|
-
// if (contentBody) {
|
|
162
|
-
// target.push(contentBody);
|
|
163
|
-
// target.push(Buffer.from(CRLF + CRLF));
|
|
164
|
-
// }
|
|
165
|
-
// } else throw new Error('Not implemented yet');
|
|
166
|
-
// }
|
|
167
|
-
// target.push(Buffer.from('--' + this.boundary + '--' + CRLF, 'utf-8'));
|
|
168
|
-
// }
|
|
169
|
-
//
|
|
170
|
-
// }
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// export type IHttpRequestContent = Pick<HttpRequestContent, 'method' | 'url' | 'headers' | 'data'>;
|
|
4
|
-
//
|
|
5
|
-
// export class HttpRequestContent {
|
|
6
|
-
// method: string;
|
|
7
|
-
// url: string;
|
|
8
|
-
// headers?: Record<string, string | string[]>;
|
|
9
|
-
// data?: any;
|
|
10
|
-
//
|
|
11
|
-
// constructor(init: IHttpRequestContent) {
|
|
12
|
-
// this.method = init.method;
|
|
13
|
-
// this.url = encodeURI(decodeURI(init.url));
|
|
14
|
-
// this.headers = init.headers;
|
|
15
|
-
// this.data = init.data;
|
|
16
|
-
// }
|
|
17
|
-
// }
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// export type IHttpResponseContent = Pick<HttpResponseContent, 'status' | 'headers' | 'data'>;
|
|
3
|
-
//
|
|
4
|
-
// export class HttpResponseContent {
|
|
5
|
-
// status: number;
|
|
6
|
-
// headers?: Record<string, string | string[]>;
|
|
7
|
-
// data?: any;
|
|
8
|
-
//
|
|
9
|
-
// constructor(init: IHttpResponseContent) {
|
|
10
|
-
// this.status = init.status;
|
|
11
|
-
// this.headers = init.headers;
|
|
12
|
-
// this.data = init.data;
|
|
13
|
-
// }
|
|
14
|
-
// }
|
package/cjs/url/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./opra-url.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./opra-url-path.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./opra-url-path-component.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./utils/encode-path-component.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./utils/decode-path-component.js"), exports);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraURLPathComponent = void 0;
|
|
4
|
-
const encode_path_component_js_1 = require("./utils/encode-path-component.js");
|
|
5
|
-
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
6
|
-
class OpraURLPathComponent {
|
|
7
|
-
constructor(init) {
|
|
8
|
-
this.resource = init.resource;
|
|
9
|
-
this.key = init.key;
|
|
10
|
-
this.typeCast = init.typeCast;
|
|
11
|
-
}
|
|
12
|
-
toString() {
|
|
13
|
-
const obj = (0, encode_path_component_js_1.encodePathComponent)(this.resource, this.key, this.typeCast);
|
|
14
|
-
if (obj)
|
|
15
|
-
Object.setPrototypeOf(obj, OpraURLPathComponent.prototype);
|
|
16
|
-
return obj;
|
|
17
|
-
}
|
|
18
|
-
/* istanbul ignore next */
|
|
19
|
-
[nodeInspectCustom]() {
|
|
20
|
-
const out = {
|
|
21
|
-
resource: this.resource,
|
|
22
|
-
};
|
|
23
|
-
if (this.key != null)
|
|
24
|
-
out.key = this.key;
|
|
25
|
-
if (this.typeCast != null)
|
|
26
|
-
out.typeCast = this.typeCast;
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.OpraURLPathComponent = OpraURLPathComponent;
|
package/cjs/url/opra-url-path.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraURLPath = void 0;
|
|
5
|
-
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
6
|
-
const index_js_1 = require("../helpers/index.js");
|
|
7
|
-
const path_utils_js_1 = require("../utils/path-utils.js");
|
|
8
|
-
const opra_url_path_component_js_1 = require("./opra-url-path-component.js");
|
|
9
|
-
const decode_path_component_js_1 = require("./utils/decode-path-component.js");
|
|
10
|
-
const encode_path_component_js_1 = require("./utils/encode-path-component.js");
|
|
11
|
-
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
12
|
-
const kEntries = Symbol('kEntries');
|
|
13
|
-
const kOptions = Symbol('kOptions');
|
|
14
|
-
class OpraURLPath {
|
|
15
|
-
constructor(init, options) {
|
|
16
|
-
this[_a] = [];
|
|
17
|
-
this[kOptions] = { ...options, onChange: undefined };
|
|
18
|
-
if (Array.isArray(init))
|
|
19
|
-
this.join(...init);
|
|
20
|
-
else if (init)
|
|
21
|
-
this.join(init);
|
|
22
|
-
this[kOptions].onChange = options?.onChange;
|
|
23
|
-
}
|
|
24
|
-
get size() {
|
|
25
|
-
return this[kEntries].length;
|
|
26
|
-
}
|
|
27
|
-
changed() {
|
|
28
|
-
if (this[kOptions].onChange)
|
|
29
|
-
this[kOptions].onChange();
|
|
30
|
-
}
|
|
31
|
-
clear() {
|
|
32
|
-
this[kEntries] = [];
|
|
33
|
-
this.changed();
|
|
34
|
-
}
|
|
35
|
-
get(index) {
|
|
36
|
-
return this[kEntries][index];
|
|
37
|
-
}
|
|
38
|
-
join(...source) {
|
|
39
|
-
source.forEach(x => this._join(this[kEntries], x));
|
|
40
|
-
this.changed();
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
entries() {
|
|
44
|
-
let i = -1;
|
|
45
|
-
const arr = [...this[kEntries]];
|
|
46
|
-
return {
|
|
47
|
-
[Symbol.iterator]() {
|
|
48
|
-
return this;
|
|
49
|
-
},
|
|
50
|
-
next() {
|
|
51
|
-
i++;
|
|
52
|
-
return {
|
|
53
|
-
done: i >= arr.length,
|
|
54
|
-
value: [arr[i], i]
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
forEach(callback) {
|
|
60
|
-
for (const item of this[kEntries]) {
|
|
61
|
-
callback.call(this, item, this);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
getResource(index) {
|
|
65
|
-
const v = this[kEntries][index];
|
|
66
|
-
return v == null ? undefined : v.resource;
|
|
67
|
-
}
|
|
68
|
-
getKey(index) {
|
|
69
|
-
const v = this[kEntries][index];
|
|
70
|
-
return v == null ? undefined : v.key;
|
|
71
|
-
}
|
|
72
|
-
pop() {
|
|
73
|
-
const out = this[kEntries].pop();
|
|
74
|
-
this.changed();
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
|
-
shift() {
|
|
78
|
-
const out = this[kEntries].shift();
|
|
79
|
-
this.changed();
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
slice(start, end) {
|
|
83
|
-
return new OpraURLPath(this[kEntries].slice(start, end));
|
|
84
|
-
}
|
|
85
|
-
splice(start, deleteCount, join) {
|
|
86
|
-
const items = (join ? this._join([], join) : []);
|
|
87
|
-
this[kEntries].splice(start, deleteCount, ...items);
|
|
88
|
-
this.changed();
|
|
89
|
-
}
|
|
90
|
-
unshift(join) {
|
|
91
|
-
return this.splice(0, 0, join);
|
|
92
|
-
}
|
|
93
|
-
toString() {
|
|
94
|
-
return this[kEntries]
|
|
95
|
-
.map(x => (0, encode_path_component_js_1.encodePathComponent)(x.resource, x.key, x.typeCast)).join('/');
|
|
96
|
-
}
|
|
97
|
-
values() {
|
|
98
|
-
let i = -1;
|
|
99
|
-
const arr = [...this[kEntries]];
|
|
100
|
-
return {
|
|
101
|
-
[Symbol.iterator]() {
|
|
102
|
-
return this;
|
|
103
|
-
},
|
|
104
|
-
next() {
|
|
105
|
-
i++;
|
|
106
|
-
return {
|
|
107
|
-
done: i >= arr.length,
|
|
108
|
-
value: arr[i]
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
_join(target, source) {
|
|
114
|
-
if (typeof source === 'string') {
|
|
115
|
-
const pathTokenizer = (0, fast_tokenizer_1.tokenize)((0, path_utils_js_1.normalizePath)(source, true), {
|
|
116
|
-
delimiters: '/', quotes: true, brackets: true,
|
|
117
|
-
});
|
|
118
|
-
for (const x of pathTokenizer) {
|
|
119
|
-
const p = (0, decode_path_component_js_1.decodePathComponent)(x);
|
|
120
|
-
target.push(new opra_url_path_component_js_1.OpraURLPathComponent(p));
|
|
121
|
-
}
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (source instanceof OpraURLPath) {
|
|
125
|
-
target.push(...source[kEntries].map(x => new opra_url_path_component_js_1.OpraURLPathComponent(x)));
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (typeof source === 'object' && source.path instanceof OpraURLPath) {
|
|
129
|
-
this._join(target, source.path);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if ((0, index_js_1.isURL)(source)) {
|
|
133
|
-
this._join(target, source.pathname);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(source)) {
|
|
137
|
-
source.forEach(x => this._join(target, x));
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
target.push(new opra_url_path_component_js_1.OpraURLPathComponent(source));
|
|
141
|
-
}
|
|
142
|
-
/* istanbul ignore next */
|
|
143
|
-
[(_a = kEntries, nodeInspectCustom)]() {
|
|
144
|
-
return this[kEntries];
|
|
145
|
-
}
|
|
146
|
-
[Symbol.iterator]() {
|
|
147
|
-
return this.entries();
|
|
148
|
-
}
|
|
149
|
-
get [Symbol.toStringTag]() {
|
|
150
|
-
return 'OpraURLPath';
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.OpraURLPath = OpraURLPath;
|
|
154
|
-
OpraURLPath.kEntries = kEntries;
|
|
155
|
-
OpraURLPath.kOptions = kOptions;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodePathComponent = void 0;
|
|
4
|
-
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
5
|
-
const pathComponentRegEx = /^([^/?#:@]+)(?:@([^/?#:]*))?(?:::(.*))?$/;
|
|
6
|
-
function decodePathComponent(input) {
|
|
7
|
-
const m = pathComponentRegEx.exec(input);
|
|
8
|
-
if (!m)
|
|
9
|
-
throw Object.assign(new TypeError('Invalid URL path'), {
|
|
10
|
-
code: 'ERR_INVALID_URL_PATH',
|
|
11
|
-
input,
|
|
12
|
-
});
|
|
13
|
-
const resource = decodeURIComponent(m[1]);
|
|
14
|
-
let key;
|
|
15
|
-
if (m[2]) {
|
|
16
|
-
const s = decodeURIComponent(m[2] || '');
|
|
17
|
-
const b = (0, fast_tokenizer_1.splitString)(s, { delimiters: ';', quotes: true, escape: false });
|
|
18
|
-
for (const k of b) {
|
|
19
|
-
const c = (0, fast_tokenizer_1.splitString)(k, { delimiters: '=', quotes: true, escape: false });
|
|
20
|
-
if ((b.length > 1 && c.length < 2) ||
|
|
21
|
-
(key &&
|
|
22
|
-
(c.length >= 2 && typeof key !== 'object') ||
|
|
23
|
-
(c.length < 2 && typeof key === 'object')))
|
|
24
|
-
throw Object.assign(new TypeError('Invalid URL path. name:value pair required for multiple key format'), {
|
|
25
|
-
pathComponent: input,
|
|
26
|
-
code: 'ERR_INVALID_URL_PATH'
|
|
27
|
-
});
|
|
28
|
-
if (c.length >= 2) {
|
|
29
|
-
key = key || {};
|
|
30
|
-
key[c.shift() || ''] = c.join('=');
|
|
31
|
-
}
|
|
32
|
-
else
|
|
33
|
-
key = c[0];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (m[3]) {
|
|
37
|
-
return { resource, key, typeCast: m[3] };
|
|
38
|
-
}
|
|
39
|
-
return { resource, key };
|
|
40
|
-
}
|
|
41
|
-
exports.decodePathComponent = decodePathComponent;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodePathComponent = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const putil_isplainobject_1 = tslib_1.__importDefault(require("putil-isplainobject"));
|
|
6
|
-
function encodePathComponent(resource, key, typeCast) {
|
|
7
|
-
if (resource == null)
|
|
8
|
-
return '';
|
|
9
|
-
let keyString = '';
|
|
10
|
-
if (key !== '' && key != null) {
|
|
11
|
-
if ((0, putil_isplainobject_1.default)(key)) {
|
|
12
|
-
const arr = [];
|
|
13
|
-
for (const k of Object.keys(key)) {
|
|
14
|
-
arr.push(encodeURIComponent(k) + '=' + encodeURIComponent(key[k]));
|
|
15
|
-
}
|
|
16
|
-
keyString = arr.join(';');
|
|
17
|
-
}
|
|
18
|
-
else
|
|
19
|
-
keyString = encodeURIComponent('' + key);
|
|
20
|
-
}
|
|
21
|
-
if (typeCast)
|
|
22
|
-
typeCast = encodeURIComponent(typeCast);
|
|
23
|
-
return encodeURIComponent(resource).replace(/%24/, '$') +
|
|
24
|
-
(keyString ? '@' + keyString : '') +
|
|
25
|
-
(typeCast ? '::' + typeCast : '');
|
|
26
|
-
}
|
|
27
|
-
exports.encodePathComponent = encodePathComponent;
|
package/cjs/utils/path-utils.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.joinPath = exports.normalizePath = void 0;
|
|
4
|
-
function normalizePath(p, noLeadingSlash) {
|
|
5
|
-
if (!p)
|
|
6
|
-
return '';
|
|
7
|
-
while (noLeadingSlash && p.startsWith('/'))
|
|
8
|
-
p = p.substring(1);
|
|
9
|
-
while (p.endsWith('/'))
|
|
10
|
-
p = p.substring(0, p.length - 1);
|
|
11
|
-
return p;
|
|
12
|
-
}
|
|
13
|
-
exports.normalizePath = normalizePath;
|
|
14
|
-
function joinPath(...p) {
|
|
15
|
-
const out = [];
|
|
16
|
-
let s;
|
|
17
|
-
for (let i = 0, l = p.length; i < l; i++) {
|
|
18
|
-
s = normalizePath(p[i], i > 0);
|
|
19
|
-
if (s)
|
|
20
|
-
out.push(s);
|
|
21
|
-
}
|
|
22
|
-
return out.join('/');
|
|
23
|
-
}
|
|
24
|
-
exports.joinPath = joinPath;
|
package/esm/helpers/is-url.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const trueValues = ['true', 't', 'yes', 'y', '1'];
|
|
2
|
-
const falseValues = ['false', 'f', 'no', 'n', '0'];
|
|
3
|
-
export class BooleanCodec {
|
|
4
|
-
decode(value) {
|
|
5
|
-
if (value === '')
|
|
6
|
-
return true;
|
|
7
|
-
// noinspection SuspiciousTypeOfGuard
|
|
8
|
-
if (typeof value === 'boolean')
|
|
9
|
-
return value;
|
|
10
|
-
if (trueValues.includes(value.toLowerCase()))
|
|
11
|
-
return true;
|
|
12
|
-
if (falseValues.includes(value.toLowerCase()))
|
|
13
|
-
return false;
|
|
14
|
-
throw new TypeError(`"${value}" is not a valid boolean`);
|
|
15
|
-
}
|
|
16
|
-
encode(value) {
|
|
17
|
-
return typeof value === 'boolean' ?
|
|
18
|
-
(value ? 'true' : 'false') : '';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
2
|
-
const DATE_FORMAT_PATTERN = /^(\d{4})(?:-?(0[1-9]|1[012])(?:-?([123]0|[012][1-9]|31))?)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
|
|
3
|
-
export class DateCodec {
|
|
4
|
-
constructor(options) {
|
|
5
|
-
this.max = options?.max ? coerceToDateString(options.max) : undefined;
|
|
6
|
-
this.min = options?.min ? coerceToDateString(options.min) : undefined;
|
|
7
|
-
this.time = options?.time ?? true;
|
|
8
|
-
this.timeZone = options?.timeZone ?? true;
|
|
9
|
-
}
|
|
10
|
-
decode(value) {
|
|
11
|
-
const v = coerceToDateString(value, this.time, this.timeZone);
|
|
12
|
-
if (this.min != null && v < this.min)
|
|
13
|
-
throw new TypeError(`Value must be ${this.min} or greater.`);
|
|
14
|
-
if (this.max != null && v > this.max)
|
|
15
|
-
throw new TypeError(`Value must be ${this.max} or less.`);
|
|
16
|
-
return v;
|
|
17
|
-
}
|
|
18
|
-
encode(value) {
|
|
19
|
-
return coerceToDateString(value, this.time, this.timeZone);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function coerceToDateString(value, time, timeZone) {
|
|
23
|
-
if (value === '' || value == null)
|
|
24
|
-
return '';
|
|
25
|
-
const m = value.match(DATE_FORMAT_PATTERN);
|
|
26
|
-
if (!m)
|
|
27
|
-
throw new TypeError(`"${value}" is not a valid date.`);
|
|
28
|
-
let v = m[1] + '-' + (m[2] || '01') + '-' + (m[3] || '01');
|
|
29
|
-
if (time) {
|
|
30
|
-
v += 'T' + (m[4] || '00') + ':' + (m[5] || '00') + ':' + (m[6] || '00') +
|
|
31
|
-
(m[7] ? '.' + m[7] : '');
|
|
32
|
-
if (timeZone)
|
|
33
|
-
v += m[8] ? 'Z' :
|
|
34
|
-
(m[9] ? (m[9] + (m[10] || '00') + ':' + (m[11] || '00')) : '');
|
|
35
|
-
}
|
|
36
|
-
return v;
|
|
37
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Expression } from '../../filter/ast/index.js';
|
|
2
|
-
import { OpraFilter } from '../../filter/index.js';
|
|
3
|
-
export class FilterCodec {
|
|
4
|
-
decode(value) {
|
|
5
|
-
if (value instanceof Expression)
|
|
6
|
-
return value;
|
|
7
|
-
return OpraFilter.parse(value);
|
|
8
|
-
}
|
|
9
|
-
encode(value) {
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
return value ? '' + value : '';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { NumberCodec } from './number-codec.js';
|
|
2
|
-
export class IntegerCodec extends NumberCodec {
|
|
3
|
-
constructor(options) {
|
|
4
|
-
super(options);
|
|
5
|
-
this.enum = options?.enum;
|
|
6
|
-
}
|
|
7
|
-
decode(value) {
|
|
8
|
-
const v = super.decode(value);
|
|
9
|
-
if (!Number.isInteger(v))
|
|
10
|
-
throw new TypeError(`"${value}" is not a valid integer`);
|
|
11
|
-
if (this.enum && !this.enum.includes(v))
|
|
12
|
-
throw new TypeError(`"${value}" is not one of allowed enum values (${this.enum}).`);
|
|
13
|
-
return v;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class NumberCodec {
|
|
2
|
-
constructor(options) {
|
|
3
|
-
this.max = options?.max;
|
|
4
|
-
this.min = options?.min;
|
|
5
|
-
}
|
|
6
|
-
decode(value) {
|
|
7
|
-
// noinspection SuspiciousTypeOfGuard
|
|
8
|
-
const v = typeof value === 'number' ? value : parseFloat(value);
|
|
9
|
-
if (isNaN(v))
|
|
10
|
-
throw new TypeError(`"${value}" is not a valid number`);
|
|
11
|
-
if (this.min != null && v < this.min)
|
|
12
|
-
throw new TypeError(`Value must be ${this.min} or greater.`);
|
|
13
|
-
if (this.max != null && v > this.max)
|
|
14
|
-
throw new TypeError(`Value must be ${this.max} or less.`);
|
|
15
|
-
return v;
|
|
16
|
-
}
|
|
17
|
-
encode(value) {
|
|
18
|
-
return typeof value === 'number' ? '' + value : '';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export class StringCodec {
|
|
2
|
-
constructor(options) {
|
|
3
|
-
this.maxLength = options?.maxLength;
|
|
4
|
-
this.minLength = options?.minLength;
|
|
5
|
-
this.enum = options?.enum;
|
|
6
|
-
}
|
|
7
|
-
decode(value) {
|
|
8
|
-
if (this.minLength != null && value.length < this.minLength)
|
|
9
|
-
throw new TypeError(`Value must be at least ${this.minLength} character${this.minLength > 1 ? 's' : ''} long.`);
|
|
10
|
-
if (this.maxLength != null && value.length > this.maxLength)
|
|
11
|
-
throw new TypeError(`Value can be up to ${this.maxLength} character${this.maxLength > 1 ? 's' : ''} long.`);
|
|
12
|
-
if (this.enum && !this.enum.includes(value))
|
|
13
|
-
throw new TypeError(`"${value}" is not one of allowed enum values (${this.enum}).`);
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
encode(value) {
|
|
17
|
-
return value == null ? '' : '' + value;
|
|
18
|
-
}
|
|
19
|
-
}
|