@opra/common 0.22.0 → 0.23.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.
- package/browser.js +806 -1421
- 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 +0 -36
- 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/resource-errors/resource-not-found.error.js +1 -1
- 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 +0 -36
- 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/resource-errors/resource-not-found.error.js +1 -1
- 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 +1 -1
- package/types/document/api-document.d.ts +4 -1
- package/types/document/data-type/complex-type.d.ts +6 -11
- 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 +0 -4
- package/types/document/data-type/simple-type.d.ts +2 -4
- package/types/document/data-type/union-type.d.ts +0 -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 +2 -1
- 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/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/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/resource.interface.d.ts +1 -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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._generateDecoder = exports.generateCodec = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const vg = tslib_1.__importStar(require("valgen"));
|
|
6
|
+
const complex_type_js_1 = require("../data-type/complex-type.js");
|
|
7
|
+
const enum_type_js_1 = require("../data-type/enum-type.js");
|
|
8
|
+
const mapped_type_js_1 = require("../data-type/mapped-type.js");
|
|
9
|
+
const simple_type_js_1 = require("../data-type/simple-type.js");
|
|
10
|
+
const union_type_js_1 = require("../data-type/union-type.js");
|
|
11
|
+
function generateCodec(type, codec, options) {
|
|
12
|
+
return _generateDecoder(type, codec, options);
|
|
13
|
+
}
|
|
14
|
+
exports.generateCodec = generateCodec;
|
|
15
|
+
function _generateDecoder(type, codec, options) {
|
|
16
|
+
const schema = {};
|
|
17
|
+
for (const f of type.fields.values()) {
|
|
18
|
+
let fn;
|
|
19
|
+
if (f.type instanceof simple_type_js_1.SimpleType || f.type instanceof enum_type_js_1.EnumType) {
|
|
20
|
+
fn = f.type[codec];
|
|
21
|
+
}
|
|
22
|
+
else if (f.type instanceof complex_type_js_1.ComplexType || f.type instanceof mapped_type_js_1.MappedType || f.type instanceof union_type_js_1.UnionType) {
|
|
23
|
+
fn = _generateDecoder(f.type, codec, options);
|
|
24
|
+
}
|
|
25
|
+
/* istanbul ignore next */
|
|
26
|
+
if (!fn)
|
|
27
|
+
throw new TypeError(`Can't generate codec for (${f.type})`);
|
|
28
|
+
if (f.isArray)
|
|
29
|
+
fn = vg.isArray(fn);
|
|
30
|
+
schema[f.name] = !options.partial && f.required ? vg.required(fn) : vg.optional(fn);
|
|
31
|
+
}
|
|
32
|
+
return vg.isObject(schema, {
|
|
33
|
+
ctor: type.ctor,
|
|
34
|
+
additionalFields: type.additionalFields ?? 'ignore',
|
|
35
|
+
name: type.name,
|
|
36
|
+
caseInSensitive: true,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports._generateDecoder = _generateDecoder;
|
|
@@ -10,7 +10,7 @@ const opra_exception_js_1 = require("../opra-exception.js");
|
|
|
10
10
|
class ResourceNotFoundError extends opra_exception_js_1.OpraException {
|
|
11
11
|
constructor(resource, keyValue, cause) {
|
|
12
12
|
super({
|
|
13
|
-
message: (0, index_js_1.translate)(`error:RESOURCE_NOT_FOUND`, { resource: resource + (keyValue ? '@' + keyValue : '') }, `The resource '{{resource}}'
|
|
13
|
+
message: (0, index_js_1.translate)(`error:RESOURCE_NOT_FOUND`, { resource: resource + (keyValue ? '@' + keyValue : '') }, `The resource '{{resource}}' not found`),
|
|
14
14
|
severity: 'error',
|
|
15
15
|
code: 'RESOURCE_NOT_FOUND',
|
|
16
16
|
details: {
|
package/cjs/helpers/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./function-utils.js"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./get-stack-filename.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./is-url.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./is-url-string.js"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./mixin-utils.js"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./object-utils.js"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./path-to-object-tree.js"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAbsoluteUrl = exports.isUrlString = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const URL_PATTERN = /^(https?:\/\/.)[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/i;
|
|
6
|
+
function isUrlString(url) {
|
|
7
|
+
return URL_PATTERN.test(url);
|
|
8
|
+
}
|
|
9
|
+
exports.isUrlString = isUrlString;
|
|
10
|
+
const isAbsoluteUrl = (urlString) => {
|
|
11
|
+
return !urlString.includes('://') &&
|
|
12
|
+
(new url_1.URL(urlString, 'http://tempuri.org/')).host !== 'tempuri.org';
|
|
13
|
+
};
|
|
14
|
+
exports.isAbsoluteUrl = isAbsoluteUrl;
|
|
@@ -17,13 +17,13 @@ function cloneObject(obj, jsonOnly) {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
exports.cloneObject = cloneObject;
|
|
20
|
-
function omitUndefined(obj) {
|
|
20
|
+
function omitUndefined(obj, recursive) {
|
|
21
21
|
if (!(obj && typeof obj === 'object'))
|
|
22
22
|
return obj;
|
|
23
23
|
for (const k of Object.keys(obj)) {
|
|
24
24
|
if (obj[k] === undefined)
|
|
25
25
|
delete obj[k];
|
|
26
|
-
else if (typeof obj[k] === 'object')
|
|
26
|
+
else if (recursive && typeof obj[k] === 'object')
|
|
27
27
|
omitUndefined(obj[k]);
|
|
28
28
|
}
|
|
29
29
|
return obj;
|
|
@@ -5,10 +5,10 @@ exports.ResponsiveMap = void 0;
|
|
|
5
5
|
function isMap(v) {
|
|
6
6
|
return v && typeof v.forEach === 'function';
|
|
7
7
|
}
|
|
8
|
-
const kKeyMap = Symbol('kKeyMap');
|
|
9
|
-
const kKeyOrder = Symbol('kKeyOrder');
|
|
10
|
-
const kWellKnownKeys = Symbol('kWellKnownKeys');
|
|
11
|
-
const kOptions = Symbol('kOptions');
|
|
8
|
+
const kKeyMap = Symbol.for('kKeyMap');
|
|
9
|
+
const kKeyOrder = Symbol.for('kKeyOrder');
|
|
10
|
+
const kWellKnownKeys = Symbol.for('kWellKnownKeys');
|
|
11
|
+
const kOptions = Symbol.for('kOptions');
|
|
12
12
|
/**
|
|
13
13
|
* A Map implementation that supports case-insensitivity and ordered keys
|
|
14
14
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isURL = exports.isFormData = exports.isBlob = exports.isReadableStream = exports.isReadable = exports.isStream = exports.isConstructor = void 0;
|
|
3
|
+
exports.isAsyncIterable = exports.isIterable = exports.isURL = exports.isFormData = exports.isBlob = exports.isReadableStream = exports.isWritable = exports.isReadable = exports.isStream = exports.isConstructor = void 0;
|
|
4
4
|
function isConstructor(fn) {
|
|
5
5
|
return typeof fn === 'function' && fn.prototype &&
|
|
6
6
|
fn.prototype.constructor === fn &&
|
|
@@ -16,14 +16,17 @@ function isStream(stream) {
|
|
|
16
16
|
exports.isStream = isStream;
|
|
17
17
|
function isReadable(x) {
|
|
18
18
|
return isStream(x)
|
|
19
|
-
&& x.readable !== false
|
|
20
19
|
&& typeof x._read === 'function'
|
|
21
20
|
&& typeof x._readableState === 'object';
|
|
22
21
|
}
|
|
23
22
|
exports.isReadable = isReadable;
|
|
23
|
+
function isWritable(x) {
|
|
24
|
+
return isStream(x)
|
|
25
|
+
&& typeof x._write === 'function';
|
|
26
|
+
}
|
|
27
|
+
exports.isWritable = isWritable;
|
|
24
28
|
function isReadableStream(x) {
|
|
25
29
|
return isStream(x)
|
|
26
|
-
&& x.readable !== false
|
|
27
30
|
&& typeof x.getReader === 'function'
|
|
28
31
|
&& typeof x.pipeThrough === 'function'
|
|
29
32
|
&& typeof x.pipeTo === 'function';
|
|
@@ -47,7 +50,16 @@ function isFormData(x) {
|
|
|
47
50
|
exports.isFormData = isFormData;
|
|
48
51
|
function isURL(x) {
|
|
49
52
|
return x !== null
|
|
53
|
+
&& typeof x == 'object'
|
|
50
54
|
&& typeof x.host === 'string'
|
|
51
55
|
&& typeof x.href === 'string';
|
|
52
56
|
}
|
|
53
57
|
exports.isURL = isURL;
|
|
58
|
+
function isIterable(x) {
|
|
59
|
+
return Symbol.iterator in x;
|
|
60
|
+
}
|
|
61
|
+
exports.isIterable = isIterable;
|
|
62
|
+
function isAsyncIterable(x) {
|
|
63
|
+
return Symbol.asyncIterator in x;
|
|
64
|
+
}
|
|
65
|
+
exports.isAsyncIterable = isAsyncIterable;
|
package/cjs/http/index.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
4
|
+
tslib_1.__exportStar(require("./opra-url.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./opra-url-path.js"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./enums/http-headers-codes.enum.js"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./enums/http-status-codes.enum.js"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./enums/http-status-messages.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./interfaces/client-http-headers.interface.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./interfaces/server-http-headers.interface.js"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./codecs/date-codec.js"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./codecs/boolean-codec.js"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./codecs/filter-codec.js"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./codecs/integer-codec.js"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./codecs/number-codec.js"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./codecs/string-codec.js"), exports);
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
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
|
+
resolve(...items) {
|
|
25
|
+
this._resolve(items);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
join(...items) {
|
|
29
|
+
this._resolve(items, true);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
isRelativeTo(basePath) {
|
|
33
|
+
basePath = basePath instanceof OpraURLPath ? basePath : new OpraURLPath(basePath);
|
|
34
|
+
let i;
|
|
35
|
+
for (i = 0; i < basePath.length; i++) {
|
|
36
|
+
if (String(this[i]) !== String(basePath[i]))
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
forEach(callback) {
|
|
42
|
+
let i = 0;
|
|
43
|
+
for (const item of this.values()) {
|
|
44
|
+
callback.call(this, item, i++, this);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
values() {
|
|
48
|
+
const arr = new Array(this.length);
|
|
49
|
+
for (let i = 0; i < this.length; i++)
|
|
50
|
+
arr[i] = this[i];
|
|
51
|
+
return arr.values();
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
const v = Array.from(this).join('/');
|
|
55
|
+
return v ? '/' + v : '';
|
|
56
|
+
}
|
|
57
|
+
/* istanbul ignore next */
|
|
58
|
+
[(_a = kLength, nodeInspectCustom)]() {
|
|
59
|
+
return `(UrlPath [${this.toString()}])`;
|
|
60
|
+
}
|
|
61
|
+
[Symbol.iterator]() {
|
|
62
|
+
return this.values();
|
|
63
|
+
}
|
|
64
|
+
_resolve(items, join) {
|
|
65
|
+
let paths = (Array.isArray(items) ? items : [items]).map(item => {
|
|
66
|
+
if (typeof item === 'object' && !(item instanceof OpraURLPath || item instanceof OpraURLPathComponent))
|
|
67
|
+
item = new OpraURLPathComponent(item);
|
|
68
|
+
item = String(item);
|
|
69
|
+
// Remove url parts coming after path (query, hash parts)
|
|
70
|
+
if (item.includes('?'))
|
|
71
|
+
item = (0, fast_tokenizer_1.splitString)(item, {
|
|
72
|
+
delimiters: '?',
|
|
73
|
+
quotes: true,
|
|
74
|
+
brackets: true,
|
|
75
|
+
keepBrackets: true,
|
|
76
|
+
keepQuotes: true
|
|
77
|
+
})[0];
|
|
78
|
+
if (item.includes('#'))
|
|
79
|
+
item = (0, fast_tokenizer_1.splitString)(item, {
|
|
80
|
+
delimiters: '#',
|
|
81
|
+
quotes: true,
|
|
82
|
+
brackets: true,
|
|
83
|
+
keepBrackets: true,
|
|
84
|
+
keepQuotes: true
|
|
85
|
+
})[0];
|
|
86
|
+
return join ? removeLeadingSeparator(item) : item;
|
|
87
|
+
});
|
|
88
|
+
const oldLength = this.length;
|
|
89
|
+
let n = 0;
|
|
90
|
+
if (!join) {
|
|
91
|
+
for (n = paths.length - 1; n >= 0; n--) {
|
|
92
|
+
if (String(items[n]).startsWith('/'))
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (n > 0)
|
|
96
|
+
paths = paths.slice(n);
|
|
97
|
+
}
|
|
98
|
+
const newPath = paths[0]?.startsWith('/') ? [] : Array.from(this).map(String);
|
|
99
|
+
for (let i = 0; i < paths.length; i++) {
|
|
100
|
+
const pathTokenizer = (0, fast_tokenizer_1.tokenize)(paths[i], { delimiters: '/', quotes: true, brackets: true });
|
|
101
|
+
for (const x of pathTokenizer) {
|
|
102
|
+
if (!x)
|
|
103
|
+
continue;
|
|
104
|
+
if (x.startsWith('.')) {
|
|
105
|
+
if (x === '.')
|
|
106
|
+
continue;
|
|
107
|
+
if (x === '..') {
|
|
108
|
+
newPath.pop();
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
throw new TypeError('Invalid path string');
|
|
112
|
+
}
|
|
113
|
+
newPath.push(x);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (let i = 0; i < newPath.length; i++) {
|
|
117
|
+
this[i] = OpraURLPathComponent.parse(newPath[i]);
|
|
118
|
+
}
|
|
119
|
+
for (let i = newPath.length; i < oldLength; i++) {
|
|
120
|
+
delete this[i];
|
|
121
|
+
}
|
|
122
|
+
this[kLength] = newPath.length;
|
|
123
|
+
}
|
|
124
|
+
static join(...items) {
|
|
125
|
+
const instance = new OpraURLPath();
|
|
126
|
+
instance.join(...items);
|
|
127
|
+
return instance;
|
|
128
|
+
}
|
|
129
|
+
static resolve(...items) {
|
|
130
|
+
return new OpraURLPath(...items);
|
|
131
|
+
}
|
|
132
|
+
static relative(source, basePath) {
|
|
133
|
+
source = source instanceof OpraURLPath ? source : new OpraURLPath(source);
|
|
134
|
+
basePath = basePath instanceof OpraURLPath ? basePath : new OpraURLPath(basePath);
|
|
135
|
+
let i;
|
|
136
|
+
for (i = 0; i < basePath.length; i++) {
|
|
137
|
+
if (String(source[i]) !== String(basePath[i]))
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return new OpraURLPath(Array.from(source).slice(i).join('/'));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.OpraURLPath = OpraURLPath;
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @class OpraURLPathComponent
|
|
147
|
+
*/
|
|
148
|
+
class OpraURLPathComponent {
|
|
149
|
+
constructor(init) {
|
|
150
|
+
this.resource = init.resource;
|
|
151
|
+
this.key = init.key;
|
|
152
|
+
this.args = init.args;
|
|
153
|
+
this.typeCast = init.typeCast;
|
|
154
|
+
}
|
|
155
|
+
toString() {
|
|
156
|
+
let out = encodeURIComponent(this.resource).replace(/%24/, '$');
|
|
157
|
+
if (this.key) {
|
|
158
|
+
if (typeof this.key === 'object' && (0, putil_isplainobject_1.default)(this.key)) {
|
|
159
|
+
const arr = [];
|
|
160
|
+
for (const k of Object.keys(this.key)) {
|
|
161
|
+
let v = this.key[k];
|
|
162
|
+
if (typeof v === 'number' || typeof v === 'boolean')
|
|
163
|
+
v = String(v);
|
|
164
|
+
else
|
|
165
|
+
v = '"' + encodeURIComponent(String(v)) + '"';
|
|
166
|
+
arr.push(encodeURIComponent(k) + '=' + v);
|
|
167
|
+
}
|
|
168
|
+
out += '@' + arr.join(';');
|
|
169
|
+
}
|
|
170
|
+
else
|
|
171
|
+
out += '@' + encodeURIComponent(String(this.key));
|
|
172
|
+
}
|
|
173
|
+
if (this.args) {
|
|
174
|
+
const arr = [];
|
|
175
|
+
for (const k of Object.keys(this.args)) {
|
|
176
|
+
arr.push(encodeURIComponent(k) + '=' + encodeURIComponent(String(this.args[k])));
|
|
177
|
+
}
|
|
178
|
+
out += '(' + arr.join(';') + ')';
|
|
179
|
+
}
|
|
180
|
+
if (this.typeCast)
|
|
181
|
+
out += '::' + encodeURIComponent(this.typeCast);
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
/* istanbul ignore next */
|
|
185
|
+
[nodeInspectCustom]() {
|
|
186
|
+
return this.toString();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Factory method.
|
|
190
|
+
* @param input
|
|
191
|
+
*/
|
|
192
|
+
static parse(input) {
|
|
193
|
+
const m = pathComponentRegEx.exec(input);
|
|
194
|
+
if (!m)
|
|
195
|
+
throw Object.assign(new TypeError('Invalid Opra URL'), {
|
|
196
|
+
code: 'ERR_INVALID_OPRA_URL',
|
|
197
|
+
input,
|
|
198
|
+
});
|
|
199
|
+
let key;
|
|
200
|
+
if (m[2]) {
|
|
201
|
+
const s = decodeURIComponent(m[2]);
|
|
202
|
+
const b = (0, fast_tokenizer_1.splitString)(s, { delimiters: ';', quotes: true, escape: false, keepQuotes: true, keepBrackets: true });
|
|
203
|
+
for (const n of b) {
|
|
204
|
+
const c = (0, fast_tokenizer_1.splitString)(n, { delimiters: '=', quotes: true, escape: false, keepQuotes: true, keepBrackets: true });
|
|
205
|
+
if ((b.length > 1 && c.length < 2) ||
|
|
206
|
+
(key &&
|
|
207
|
+
(c.length >= 2 && typeof key !== 'object') ||
|
|
208
|
+
(c.length < 2 && typeof key === 'object')))
|
|
209
|
+
throw Object.assign(new TypeError('Invalid Opra URL. name:value pair required for multiple key format'), {
|
|
210
|
+
pathComponent: input,
|
|
211
|
+
code: 'ERR_INVALID_OPRA_URL'
|
|
212
|
+
});
|
|
213
|
+
if (c.length >= 2) {
|
|
214
|
+
key = key || {};
|
|
215
|
+
const k = c.shift() || '';
|
|
216
|
+
let v = c.join('=');
|
|
217
|
+
if (decimalPattern.test(v))
|
|
218
|
+
v = Number(v);
|
|
219
|
+
else if (booleanPattern.test(v))
|
|
220
|
+
v = Boolean(v);
|
|
221
|
+
else if (v.startsWith('"') && v.endsWith('"'))
|
|
222
|
+
v = v.substring(1, v.length - 1);
|
|
223
|
+
else if (v.startsWith("'") && v.endsWith("'"))
|
|
224
|
+
v = v.substring(1, v.length - 1);
|
|
225
|
+
key[k] = v;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
if (decimalPattern.test(c[0]))
|
|
229
|
+
key = Number(c[0]);
|
|
230
|
+
else if (booleanPattern.test(c[0]))
|
|
231
|
+
key = Boolean(c[0]);
|
|
232
|
+
else
|
|
233
|
+
key = c[0];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return new OpraURLPathComponent({
|
|
237
|
+
resource: decodeURIComponent(m[1]),
|
|
238
|
+
key,
|
|
239
|
+
typeCast: m[3] ? decodeURIComponent(m[3]) : undefined
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return new OpraURLPathComponent({
|
|
243
|
+
resource: decodeURIComponent(m[1]),
|
|
244
|
+
typeCast: m[3] ? decodeURIComponent(m[3]) : undefined
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function removeLeadingSeparator(s) {
|
|
249
|
+
const m = /^\/*(.*)/.exec(s);
|
|
250
|
+
return m?.[1] || s;
|
|
251
|
+
}
|