@sinclair/typebox 0.26.0-dev.2 → 0.26.0-dev.4
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/compiler/compiler.d.ts +33 -33
- package/compiler/compiler.js +536 -536
- package/compiler/index.d.ts +2 -2
- package/compiler/index.js +47 -47
- package/errors/errors.d.ts +84 -84
- package/errors/errors.js +570 -570
- package/errors/index.d.ts +1 -1
- package/errors/index.js +44 -44
- package/package.json +2 -2
- package/readme.md +1 -7
- package/system/index.d.ts +1 -1
- package/system/index.js +44 -44
- package/system/system.d.ts +20 -20
- package/system/system.js +69 -69
- package/typebox.d.ts +656 -649
- package/typebox.js +1889 -1883
- package/value/cast.d.ts +26 -26
- package/value/cast.js +348 -348
- package/value/check.d.ts +8 -8
- package/value/check.js +450 -450
- package/value/clone.d.ts +3 -3
- package/value/clone.js +71 -71
- package/value/convert.d.ts +13 -13
- package/value/convert.js +345 -345
- package/value/create.d.ts +18 -18
- package/value/create.js +430 -430
- package/value/delta.d.ts +43 -43
- package/value/delta.js +204 -204
- package/value/equal.d.ts +3 -3
- package/value/equal.js +80 -80
- package/value/hash.d.ts +8 -8
- package/value/hash.js +208 -208
- package/value/index.d.ts +5 -5
- package/value/index.js +56 -56
- package/value/is.d.ts +11 -11
- package/value/is.js +53 -53
- package/value/pointer.d.ts +24 -24
- package/value/pointer.js +142 -142
- package/value/value.d.ts +26 -26
- package/value/value.js +93 -93
package/value/index.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
|
-
if (k2 === undefined) k2 = k;
|
|
31
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
32
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
33
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
|
-
}
|
|
35
|
-
Object.defineProperty(o, k2, desc);
|
|
36
|
-
}) : (function(o, m, k, k2) {
|
|
37
|
-
if (k2 === undefined) k2 = k;
|
|
38
|
-
o[k2] = m[k];
|
|
39
|
-
}));
|
|
40
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
41
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.Delete = exports.Update = exports.Insert = exports.Edit = exports.ValueHash = exports.ValueErrorType = exports.ValueErrorIterator = void 0;
|
|
45
|
-
var index_1 = require("../errors/index");
|
|
46
|
-
Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function () { return index_1.ValueErrorIterator; } });
|
|
47
|
-
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
48
|
-
var hash_1 = require("./hash");
|
|
49
|
-
Object.defineProperty(exports, "ValueHash", { enumerable: true, get: function () { return hash_1.ValueHash; } });
|
|
50
|
-
var delta_1 = require("./delta");
|
|
51
|
-
Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { return delta_1.Edit; } });
|
|
52
|
-
Object.defineProperty(exports, "Insert", { enumerable: true, get: function () { return delta_1.Insert; } });
|
|
53
|
-
Object.defineProperty(exports, "Update", { enumerable: true, get: function () { return delta_1.Update; } });
|
|
54
|
-
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return delta_1.Delete; } });
|
|
55
|
-
__exportStar(require("./pointer"), exports);
|
|
56
|
-
__exportStar(require("./value"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/value
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
32
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
33
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
|
+
}
|
|
35
|
+
Object.defineProperty(o, k2, desc);
|
|
36
|
+
}) : (function(o, m, k, k2) {
|
|
37
|
+
if (k2 === undefined) k2 = k;
|
|
38
|
+
o[k2] = m[k];
|
|
39
|
+
}));
|
|
40
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
41
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.Delete = exports.Update = exports.Insert = exports.Edit = exports.ValueHash = exports.ValueErrorType = exports.ValueErrorIterator = void 0;
|
|
45
|
+
var index_1 = require("../errors/index");
|
|
46
|
+
Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function () { return index_1.ValueErrorIterator; } });
|
|
47
|
+
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
48
|
+
var hash_1 = require("./hash");
|
|
49
|
+
Object.defineProperty(exports, "ValueHash", { enumerable: true, get: function () { return hash_1.ValueHash; } });
|
|
50
|
+
var delta_1 = require("./delta");
|
|
51
|
+
Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { return delta_1.Edit; } });
|
|
52
|
+
Object.defineProperty(exports, "Insert", { enumerable: true, get: function () { return delta_1.Insert; } });
|
|
53
|
+
Object.defineProperty(exports, "Update", { enumerable: true, get: function () { return delta_1.Update; } });
|
|
54
|
+
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return delta_1.Delete; } });
|
|
55
|
+
__exportStar(require("./pointer"), exports);
|
|
56
|
+
__exportStar(require("./value"), exports);
|
package/value/is.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export type ValueType = null | undefined | Function | symbol | bigint | number | boolean | string;
|
|
2
|
-
export type ObjectType = Record<string | number | symbol, unknown>;
|
|
3
|
-
export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
4
|
-
export type ArrayType = unknown[];
|
|
5
|
-
export declare namespace Is {
|
|
6
|
-
function Object(value: unknown): value is ObjectType;
|
|
7
|
-
function Date(value: unknown): value is Date;
|
|
8
|
-
function Array(value: unknown): value is ArrayType;
|
|
9
|
-
function Value(value: unknown): value is ValueType;
|
|
10
|
-
function TypedArray(value: unknown): value is TypedArrayType;
|
|
11
|
-
}
|
|
1
|
+
export type ValueType = null | undefined | Function | symbol | bigint | number | boolean | string;
|
|
2
|
+
export type ObjectType = Record<string | number | symbol, unknown>;
|
|
3
|
+
export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
4
|
+
export type ArrayType = unknown[];
|
|
5
|
+
export declare namespace Is {
|
|
6
|
+
function Object(value: unknown): value is ObjectType;
|
|
7
|
+
function Date(value: unknown): value is Date;
|
|
8
|
+
function Array(value: unknown): value is ArrayType;
|
|
9
|
+
function Value(value: unknown): value is ValueType;
|
|
10
|
+
function TypedArray(value: unknown): value is TypedArrayType;
|
|
11
|
+
}
|
package/value/is.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Is = void 0;
|
|
31
|
-
var Is;
|
|
32
|
-
(function (Is) {
|
|
33
|
-
function Object(value) {
|
|
34
|
-
return value !== null && typeof value === 'object' && !globalThis.Array.isArray(value) && !ArrayBuffer.isView(value) && !(value instanceof globalThis.Date);
|
|
35
|
-
}
|
|
36
|
-
Is.Object = Object;
|
|
37
|
-
function Date(value) {
|
|
38
|
-
return value instanceof globalThis.Date;
|
|
39
|
-
}
|
|
40
|
-
Is.Date = Date;
|
|
41
|
-
function Array(value) {
|
|
42
|
-
return globalThis.Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
43
|
-
}
|
|
44
|
-
Is.Array = Array;
|
|
45
|
-
function Value(value) {
|
|
46
|
-
return value === null || value === undefined || typeof value === 'function' || typeof value === 'symbol' || typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string';
|
|
47
|
-
}
|
|
48
|
-
Is.Value = Value;
|
|
49
|
-
function TypedArray(value) {
|
|
50
|
-
return ArrayBuffer.isView(value);
|
|
51
|
-
}
|
|
52
|
-
Is.TypedArray = TypedArray;
|
|
53
|
-
})(Is = exports.Is || (exports.Is = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/value
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Is = void 0;
|
|
31
|
+
var Is;
|
|
32
|
+
(function (Is) {
|
|
33
|
+
function Object(value) {
|
|
34
|
+
return value !== null && typeof value === 'object' && !globalThis.Array.isArray(value) && !ArrayBuffer.isView(value) && !(value instanceof globalThis.Date);
|
|
35
|
+
}
|
|
36
|
+
Is.Object = Object;
|
|
37
|
+
function Date(value) {
|
|
38
|
+
return value instanceof globalThis.Date;
|
|
39
|
+
}
|
|
40
|
+
Is.Date = Date;
|
|
41
|
+
function Array(value) {
|
|
42
|
+
return globalThis.Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
43
|
+
}
|
|
44
|
+
Is.Array = Array;
|
|
45
|
+
function Value(value) {
|
|
46
|
+
return value === null || value === undefined || typeof value === 'function' || typeof value === 'symbol' || typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string';
|
|
47
|
+
}
|
|
48
|
+
Is.Value = Value;
|
|
49
|
+
function TypedArray(value) {
|
|
50
|
+
return ArrayBuffer.isView(value);
|
|
51
|
+
}
|
|
52
|
+
Is.TypedArray = TypedArray;
|
|
53
|
+
})(Is = exports.Is || (exports.Is = {}));
|
package/value/pointer.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export declare class ValuePointerRootSetError extends Error {
|
|
2
|
-
readonly value: unknown;
|
|
3
|
-
readonly path: string;
|
|
4
|
-
readonly update: unknown;
|
|
5
|
-
constructor(value: unknown, path: string, update: unknown);
|
|
6
|
-
}
|
|
7
|
-
export declare class ValuePointerRootDeleteError extends Error {
|
|
8
|
-
readonly value: unknown;
|
|
9
|
-
readonly path: string;
|
|
10
|
-
constructor(value: unknown, path: string);
|
|
11
|
-
}
|
|
12
|
-
/** Provides functionality to update values through RFC6901 string pointers */
|
|
13
|
-
export declare namespace ValuePointer {
|
|
14
|
-
/** Formats the given pointer into navigable key components */
|
|
15
|
-
function Format(pointer: string): IterableIterator<string>;
|
|
16
|
-
/** Sets the value at the given pointer. If the value at the pointer does not exist it is created */
|
|
17
|
-
function Set(value: any, pointer: string, update: unknown): void;
|
|
18
|
-
/** Deletes a value at the given pointer */
|
|
19
|
-
function Delete(value: any, pointer: string): void;
|
|
20
|
-
/** Returns true if a value exists at the given pointer */
|
|
21
|
-
function Has(value: any, pointer: string): boolean;
|
|
22
|
-
/** Gets the value at the given pointer */
|
|
23
|
-
function Get(value: any, pointer: string): any;
|
|
24
|
-
}
|
|
1
|
+
export declare class ValuePointerRootSetError extends Error {
|
|
2
|
+
readonly value: unknown;
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly update: unknown;
|
|
5
|
+
constructor(value: unknown, path: string, update: unknown);
|
|
6
|
+
}
|
|
7
|
+
export declare class ValuePointerRootDeleteError extends Error {
|
|
8
|
+
readonly value: unknown;
|
|
9
|
+
readonly path: string;
|
|
10
|
+
constructor(value: unknown, path: string);
|
|
11
|
+
}
|
|
12
|
+
/** Provides functionality to update values through RFC6901 string pointers */
|
|
13
|
+
export declare namespace ValuePointer {
|
|
14
|
+
/** Formats the given pointer into navigable key components */
|
|
15
|
+
function Format(pointer: string): IterableIterator<string>;
|
|
16
|
+
/** Sets the value at the given pointer. If the value at the pointer does not exist it is created */
|
|
17
|
+
function Set(value: any, pointer: string, update: unknown): void;
|
|
18
|
+
/** Deletes a value at the given pointer */
|
|
19
|
+
function Delete(value: any, pointer: string): void;
|
|
20
|
+
/** Returns true if a value exists at the given pointer */
|
|
21
|
+
function Has(value: any, pointer: string): boolean;
|
|
22
|
+
/** Gets the value at the given pointer */
|
|
23
|
+
function Get(value: any, pointer: string): any;
|
|
24
|
+
}
|
package/value/pointer.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.ValuePointer = exports.ValuePointerRootDeleteError = exports.ValuePointerRootSetError = void 0;
|
|
31
|
-
class ValuePointerRootSetError extends Error {
|
|
32
|
-
constructor(value, path, update) {
|
|
33
|
-
super('ValuePointer: Cannot set root value');
|
|
34
|
-
this.value = value;
|
|
35
|
-
this.path = path;
|
|
36
|
-
this.update = update;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.ValuePointerRootSetError = ValuePointerRootSetError;
|
|
40
|
-
class ValuePointerRootDeleteError extends Error {
|
|
41
|
-
constructor(value, path) {
|
|
42
|
-
super('ValuePointer: Cannot delete root value');
|
|
43
|
-
this.value = value;
|
|
44
|
-
this.path = path;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.ValuePointerRootDeleteError = ValuePointerRootDeleteError;
|
|
48
|
-
/** Provides functionality to update values through RFC6901 string pointers */
|
|
49
|
-
var ValuePointer;
|
|
50
|
-
(function (ValuePointer) {
|
|
51
|
-
function Escape(component) {
|
|
52
|
-
return component.indexOf('~') === -1 ? component : component.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
53
|
-
}
|
|
54
|
-
/** Formats the given pointer into navigable key components */
|
|
55
|
-
function* Format(pointer) {
|
|
56
|
-
if (pointer === '')
|
|
57
|
-
return;
|
|
58
|
-
let [start, end] = [0, 0];
|
|
59
|
-
for (let i = 0; i < pointer.length; i++) {
|
|
60
|
-
const char = pointer.charAt(i);
|
|
61
|
-
if (char === '/') {
|
|
62
|
-
if (i === 0) {
|
|
63
|
-
start = i + 1;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
end = i;
|
|
67
|
-
yield Escape(pointer.slice(start, end));
|
|
68
|
-
start = i + 1;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
end = i;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
yield Escape(pointer.slice(start));
|
|
76
|
-
}
|
|
77
|
-
ValuePointer.Format = Format;
|
|
78
|
-
/** Sets the value at the given pointer. If the value at the pointer does not exist it is created */
|
|
79
|
-
function Set(value, pointer, update) {
|
|
80
|
-
if (pointer === '')
|
|
81
|
-
throw new ValuePointerRootSetError(value, pointer, update);
|
|
82
|
-
let [owner, next, key] = [null, value, ''];
|
|
83
|
-
for (const component of Format(pointer)) {
|
|
84
|
-
if (next[component] === undefined)
|
|
85
|
-
next[component] = {};
|
|
86
|
-
owner = next;
|
|
87
|
-
next = next[component];
|
|
88
|
-
key = component;
|
|
89
|
-
}
|
|
90
|
-
owner[key] = update;
|
|
91
|
-
}
|
|
92
|
-
ValuePointer.Set = Set;
|
|
93
|
-
/** Deletes a value at the given pointer */
|
|
94
|
-
function Delete(value, pointer) {
|
|
95
|
-
if (pointer === '')
|
|
96
|
-
throw new ValuePointerRootDeleteError(value, pointer);
|
|
97
|
-
let [owner, next, key] = [null, value, ''];
|
|
98
|
-
for (const component of Format(pointer)) {
|
|
99
|
-
if (next[component] === undefined || next[component] === null)
|
|
100
|
-
return;
|
|
101
|
-
owner = next;
|
|
102
|
-
next = next[component];
|
|
103
|
-
key = component;
|
|
104
|
-
}
|
|
105
|
-
if (globalThis.Array.isArray(owner)) {
|
|
106
|
-
const index = parseInt(key);
|
|
107
|
-
owner.splice(index, 1);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
delete owner[key];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
ValuePointer.Delete = Delete;
|
|
114
|
-
/** Returns true if a value exists at the given pointer */
|
|
115
|
-
function Has(value, pointer) {
|
|
116
|
-
if (pointer === '')
|
|
117
|
-
return true;
|
|
118
|
-
let [owner, next, key] = [null, value, ''];
|
|
119
|
-
for (const component of Format(pointer)) {
|
|
120
|
-
if (next[component] === undefined)
|
|
121
|
-
return false;
|
|
122
|
-
owner = next;
|
|
123
|
-
next = next[component];
|
|
124
|
-
key = component;
|
|
125
|
-
}
|
|
126
|
-
return globalThis.Object.getOwnPropertyNames(owner).includes(key);
|
|
127
|
-
}
|
|
128
|
-
ValuePointer.Has = Has;
|
|
129
|
-
/** Gets the value at the given pointer */
|
|
130
|
-
function Get(value, pointer) {
|
|
131
|
-
if (pointer === '')
|
|
132
|
-
return value;
|
|
133
|
-
let current = value;
|
|
134
|
-
for (const component of Format(pointer)) {
|
|
135
|
-
if (current[component] === undefined)
|
|
136
|
-
return undefined;
|
|
137
|
-
current = current[component];
|
|
138
|
-
}
|
|
139
|
-
return current;
|
|
140
|
-
}
|
|
141
|
-
ValuePointer.Get = Get;
|
|
142
|
-
})(ValuePointer = exports.ValuePointer || (exports.ValuePointer = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/value
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.ValuePointer = exports.ValuePointerRootDeleteError = exports.ValuePointerRootSetError = void 0;
|
|
31
|
+
class ValuePointerRootSetError extends Error {
|
|
32
|
+
constructor(value, path, update) {
|
|
33
|
+
super('ValuePointer: Cannot set root value');
|
|
34
|
+
this.value = value;
|
|
35
|
+
this.path = path;
|
|
36
|
+
this.update = update;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ValuePointerRootSetError = ValuePointerRootSetError;
|
|
40
|
+
class ValuePointerRootDeleteError extends Error {
|
|
41
|
+
constructor(value, path) {
|
|
42
|
+
super('ValuePointer: Cannot delete root value');
|
|
43
|
+
this.value = value;
|
|
44
|
+
this.path = path;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ValuePointerRootDeleteError = ValuePointerRootDeleteError;
|
|
48
|
+
/** Provides functionality to update values through RFC6901 string pointers */
|
|
49
|
+
var ValuePointer;
|
|
50
|
+
(function (ValuePointer) {
|
|
51
|
+
function Escape(component) {
|
|
52
|
+
return component.indexOf('~') === -1 ? component : component.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
53
|
+
}
|
|
54
|
+
/** Formats the given pointer into navigable key components */
|
|
55
|
+
function* Format(pointer) {
|
|
56
|
+
if (pointer === '')
|
|
57
|
+
return;
|
|
58
|
+
let [start, end] = [0, 0];
|
|
59
|
+
for (let i = 0; i < pointer.length; i++) {
|
|
60
|
+
const char = pointer.charAt(i);
|
|
61
|
+
if (char === '/') {
|
|
62
|
+
if (i === 0) {
|
|
63
|
+
start = i + 1;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
end = i;
|
|
67
|
+
yield Escape(pointer.slice(start, end));
|
|
68
|
+
start = i + 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
end = i;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
yield Escape(pointer.slice(start));
|
|
76
|
+
}
|
|
77
|
+
ValuePointer.Format = Format;
|
|
78
|
+
/** Sets the value at the given pointer. If the value at the pointer does not exist it is created */
|
|
79
|
+
function Set(value, pointer, update) {
|
|
80
|
+
if (pointer === '')
|
|
81
|
+
throw new ValuePointerRootSetError(value, pointer, update);
|
|
82
|
+
let [owner, next, key] = [null, value, ''];
|
|
83
|
+
for (const component of Format(pointer)) {
|
|
84
|
+
if (next[component] === undefined)
|
|
85
|
+
next[component] = {};
|
|
86
|
+
owner = next;
|
|
87
|
+
next = next[component];
|
|
88
|
+
key = component;
|
|
89
|
+
}
|
|
90
|
+
owner[key] = update;
|
|
91
|
+
}
|
|
92
|
+
ValuePointer.Set = Set;
|
|
93
|
+
/** Deletes a value at the given pointer */
|
|
94
|
+
function Delete(value, pointer) {
|
|
95
|
+
if (pointer === '')
|
|
96
|
+
throw new ValuePointerRootDeleteError(value, pointer);
|
|
97
|
+
let [owner, next, key] = [null, value, ''];
|
|
98
|
+
for (const component of Format(pointer)) {
|
|
99
|
+
if (next[component] === undefined || next[component] === null)
|
|
100
|
+
return;
|
|
101
|
+
owner = next;
|
|
102
|
+
next = next[component];
|
|
103
|
+
key = component;
|
|
104
|
+
}
|
|
105
|
+
if (globalThis.Array.isArray(owner)) {
|
|
106
|
+
const index = parseInt(key);
|
|
107
|
+
owner.splice(index, 1);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
delete owner[key];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
ValuePointer.Delete = Delete;
|
|
114
|
+
/** Returns true if a value exists at the given pointer */
|
|
115
|
+
function Has(value, pointer) {
|
|
116
|
+
if (pointer === '')
|
|
117
|
+
return true;
|
|
118
|
+
let [owner, next, key] = [null, value, ''];
|
|
119
|
+
for (const component of Format(pointer)) {
|
|
120
|
+
if (next[component] === undefined)
|
|
121
|
+
return false;
|
|
122
|
+
owner = next;
|
|
123
|
+
next = next[component];
|
|
124
|
+
key = component;
|
|
125
|
+
}
|
|
126
|
+
return globalThis.Object.getOwnPropertyNames(owner).includes(key);
|
|
127
|
+
}
|
|
128
|
+
ValuePointer.Has = Has;
|
|
129
|
+
/** Gets the value at the given pointer */
|
|
130
|
+
function Get(value, pointer) {
|
|
131
|
+
if (pointer === '')
|
|
132
|
+
return value;
|
|
133
|
+
let current = value;
|
|
134
|
+
for (const component of Format(pointer)) {
|
|
135
|
+
if (current[component] === undefined)
|
|
136
|
+
return undefined;
|
|
137
|
+
current = current[component];
|
|
138
|
+
}
|
|
139
|
+
return current;
|
|
140
|
+
}
|
|
141
|
+
ValuePointer.Get = Get;
|
|
142
|
+
})(ValuePointer = exports.ValuePointer || (exports.ValuePointer = {}));
|
package/value/value.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import * as Types from '../typebox';
|
|
2
|
-
import { ValueErrorIterator } from '../errors/index';
|
|
3
|
-
import { Edit } from './delta';
|
|
4
|
-
/** Provides functions to perform structural updates to JavaScript values */
|
|
5
|
-
export declare namespace Value {
|
|
6
|
-
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
|
|
7
|
-
function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
|
|
8
|
-
/** Creates a value from the given type */
|
|
9
|
-
function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
|
|
10
|
-
/** Returns true if the value matches the given type. */
|
|
11
|
-
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
12
|
-
/** Converts any type mismatched values to their target type if a conversion is possible. */
|
|
13
|
-
function Convert<T extends Types.TSchema>(schema: T, value: unknown): unknown;
|
|
14
|
-
/** Returns a structural clone of the given value */
|
|
15
|
-
function Clone<T>(value: T): T;
|
|
16
|
-
/** Returns an iterator for each error in this value. */
|
|
17
|
-
function Errors<T extends Types.TSchema>(schema: T, value: unknown): ValueErrorIterator;
|
|
18
|
-
/** Returns true if left and right values are structurally equal */
|
|
19
|
-
function Equal<T>(left: T, right: unknown): right is T;
|
|
20
|
-
/** Returns edits to transform the current value into the next value */
|
|
21
|
-
function Diff(current: unknown, next: unknown): Edit[];
|
|
22
|
-
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
23
|
-
function Hash(value: unknown): bigint;
|
|
24
|
-
/** Returns a new value with edits applied to the given value */
|
|
25
|
-
function Patch<T = any>(current: unknown, edits: Edit[]): T;
|
|
26
|
-
}
|
|
1
|
+
import * as Types from '../typebox';
|
|
2
|
+
import { ValueErrorIterator } from '../errors/index';
|
|
3
|
+
import { Edit } from './delta';
|
|
4
|
+
/** Provides functions to perform structural updates to JavaScript values */
|
|
5
|
+
export declare namespace Value {
|
|
6
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
|
|
7
|
+
function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
|
|
8
|
+
/** Creates a value from the given type */
|
|
9
|
+
function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
|
|
10
|
+
/** Returns true if the value matches the given type. */
|
|
11
|
+
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
12
|
+
/** Converts any type mismatched values to their target type if a conversion is possible. */
|
|
13
|
+
function Convert<T extends Types.TSchema>(schema: T, value: unknown): unknown;
|
|
14
|
+
/** Returns a structural clone of the given value */
|
|
15
|
+
function Clone<T>(value: T): T;
|
|
16
|
+
/** Returns an iterator for each error in this value. */
|
|
17
|
+
function Errors<T extends Types.TSchema>(schema: T, value: unknown): ValueErrorIterator;
|
|
18
|
+
/** Returns true if left and right values are structurally equal */
|
|
19
|
+
function Equal<T>(left: T, right: unknown): right is T;
|
|
20
|
+
/** Returns edits to transform the current value into the next value */
|
|
21
|
+
function Diff(current: unknown, next: unknown): Edit[];
|
|
22
|
+
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
23
|
+
function Hash(value: unknown): bigint;
|
|
24
|
+
/** Returns a new value with edits applied to the given value */
|
|
25
|
+
function Patch<T = any>(current: unknown, edits: Edit[]): T;
|
|
26
|
+
}
|