@fgv/ts-json-base 5.0.1-1 → 5.0.1-10
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/README.md +5 -5
- package/dist/index.browser.js +31 -0
- package/dist/index.js +29 -0
- package/dist/packlets/converters/converters.js +187 -0
- package/dist/packlets/converters/index.js +23 -0
- package/dist/packlets/file-tree/directoryItem.js +67 -0
- package/dist/packlets/file-tree/fileItem.js +126 -0
- package/dist/packlets/file-tree/fileTree.js +85 -0
- package/dist/packlets/file-tree/fileTreeAccessors.js +23 -0
- package/dist/packlets/file-tree/fileTreeHelpers.inMemory.js +28 -0
- package/dist/packlets/file-tree/fileTreeHelpers.js +29 -0
- package/dist/packlets/file-tree/fsTree.js +122 -0
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js +177 -0
- package/dist/packlets/file-tree/in-memory/index.js +23 -0
- package/dist/packlets/file-tree/in-memory/treeBuilder.js +173 -0
- package/dist/packlets/file-tree/index.browser.js +34 -0
- package/dist/packlets/file-tree/index.js +35 -0
- package/dist/packlets/json/common.js +145 -0
- package/dist/packlets/json/index.js +23 -0
- package/dist/packlets/json-compatible/common.js +23 -0
- package/dist/packlets/json-compatible/converters.js +90 -0
- package/dist/packlets/json-compatible/index.js +26 -0
- package/dist/packlets/json-compatible/validators.js +54 -0
- package/dist/packlets/json-file/file.js +74 -0
- package/dist/packlets/json-file/index.browser.js +30 -0
- package/dist/packlets/json-file/index.js +30 -0
- package/dist/packlets/json-file/jsonFsHelper.js +166 -0
- package/dist/packlets/json-file/jsonLike.js +26 -0
- package/dist/packlets/json-file/jsonTreeHelper.js +116 -0
- package/dist/packlets/validators/index.js +23 -0
- package/dist/packlets/validators/validators.js +179 -0
- package/dist/test/fixtures/file-tree/config.json +1 -0
- package/dist/test/fixtures/file-tree/data/items.json +1 -0
- package/dist/test/fixtures/file-tree/docs/api/reference.json +1 -0
- package/dist/test/unit/data/file/bad/bad3.json +3 -0
- package/dist/test/unit/data/file/bad/thing1.json +4 -0
- package/dist/test/unit/data/file/bad/thing2.json +3 -0
- package/dist/test/unit/data/file/good/thing1.json +4 -0
- package/dist/test/unit/data/file/good/thing2.json +3 -0
- package/dist/test/unit/json-compatible/helpers.js +32 -0
- package/dist/ts-json-base.d.ts +306 -14
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +2 -1
- package/lib/index.browser.js +3 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/packlets/converters/converters.d.ts +43 -1
- package/lib/packlets/converters/converters.js +59 -4
- package/lib/packlets/file-tree/fileTreeHelpers.d.ts +0 -21
- package/lib/packlets/file-tree/fileTreeHelpers.inMemory.d.ts +25 -0
- package/lib/packlets/file-tree/fileTreeHelpers.inMemory.js +31 -0
- package/lib/packlets/file-tree/fileTreeHelpers.js +0 -6
- package/lib/packlets/file-tree/index.browser.d.ts +1 -0
- package/lib/packlets/file-tree/index.browser.js +3 -0
- package/lib/packlets/file-tree/index.d.ts +1 -0
- package/lib/packlets/file-tree/index.js +3 -0
- package/lib/packlets/json/common.d.ts +4 -4
- package/lib/packlets/json-compatible/common.d.ts +43 -0
- package/lib/packlets/json-compatible/common.js +24 -0
- package/lib/packlets/json-compatible/converters.d.ts +60 -0
- package/lib/packlets/json-compatible/converters.js +97 -0
- package/lib/packlets/json-compatible/index.d.ts +5 -0
- package/lib/packlets/json-compatible/index.js +66 -0
- package/lib/packlets/json-compatible/validators.d.ts +29 -0
- package/lib/packlets/json-compatible/validators.js +59 -0
- package/lib/packlets/json-file/index.browser.d.ts +1 -1
- package/lib/packlets/json-file/index.browser.js +2 -2
- package/lib/packlets/json-file/jsonTreeHelper.js +1 -1
- package/lib/packlets/validators/validators.d.ts +41 -1
- package/lib/packlets/validators/validators.js +63 -4
- package/package.json +19 -17
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { FileTree } from './fileTree';
|
|
3
|
+
import { IInMemoryFile } from './in-memory';
|
|
4
|
+
import { IFileTreeInitParams } from './fileTreeAccessors';
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to create a new {@link FileTree.FileTree | FileTree} instance
|
|
7
|
+
* with accessors for an in-memory file tree.
|
|
8
|
+
* @param files - An array of File |{@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
|
|
9
|
+
* @param prefix - An optional prefix to add to the paths of all files in the tree.
|
|
10
|
+
* @returns `Success` with the new {@link FileTree.FileTree | FileTree} instance
|
|
11
|
+
* if successful, or `Failure` with an error message otherwise.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare function inMemory<TCT extends string = string>(files: IInMemoryFile<TCT>[], prefix?: string): Result<FileTree<TCT>>;
|
|
15
|
+
/**
|
|
16
|
+
* Helper function to create a new {@link FileTree.FileTree | FileTree} instance
|
|
17
|
+
* with accessors for an in-memory file tree.
|
|
18
|
+
* @param files - An array of File |{@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
|
|
19
|
+
* @param params - Optional {@link FileTree.IFileTreeInitParams | initialization parameters} for the file tree.
|
|
20
|
+
* @returns `Success` with the new {@link FileTree.FileTree | FileTree} instance
|
|
21
|
+
* if successful, or `Failure` with an error message otherwise.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare function inMemory<TCT extends string = string>(files: IInMemoryFile<TCT>[], params?: IFileTreeInitParams<TCT>): Result<FileTree<TCT>>;
|
|
25
|
+
//# sourceMappingURL=fileTreeHelpers.inMemory.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.inMemory = inMemory;
|
|
25
|
+
const fileTree_1 = require("./fileTree");
|
|
26
|
+
const in_memory_1 = require("./in-memory");
|
|
27
|
+
function inMemory(files, params) {
|
|
28
|
+
params = typeof params === 'string' ? { prefix: params } : params;
|
|
29
|
+
return in_memory_1.InMemoryTreeAccessors.create(files, params).onSuccess((hal) => fileTree_1.FileTree.create(hal));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=fileTreeHelpers.inMemory.js.map
|
|
@@ -22,17 +22,11 @@
|
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.forFilesystem = forFilesystem;
|
|
25
|
-
exports.inMemory = inMemory;
|
|
26
25
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
26
|
const fileTree_1 = require("./fileTree");
|
|
28
27
|
const fsTree_1 = require("./fsTree");
|
|
29
|
-
const in_memory_1 = require("./in-memory");
|
|
30
28
|
function forFilesystem(params) {
|
|
31
29
|
params = typeof params === 'string' ? { prefix: params } : params;
|
|
32
30
|
return (0, ts_utils_1.captureResult)(() => new fsTree_1.FsFileTreeAccessors(params)).onSuccess((hal) => fileTree_1.FileTree.create(hal));
|
|
33
31
|
}
|
|
34
|
-
function inMemory(files, params) {
|
|
35
|
-
params = typeof params === 'string' ? { prefix: params } : params;
|
|
36
|
-
return in_memory_1.InMemoryTreeAccessors.create(files, params).onSuccess((hal) => fileTree_1.FileTree.create(hal));
|
|
37
|
-
}
|
|
38
32
|
//# sourceMappingURL=fileTreeHelpers.js.map
|
|
@@ -35,6 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.inMemory = void 0;
|
|
38
39
|
// Browser-safe FileTree exports - excludes Node.js filesystem dependencies
|
|
39
40
|
// Export core interfaces and classes
|
|
40
41
|
__exportStar(require("./fileTreeAccessors"), exports);
|
|
@@ -43,6 +44,8 @@ __exportStar(require("./directoryItem"), exports);
|
|
|
43
44
|
__exportStar(require("./fileItem"), exports);
|
|
44
45
|
// Export in-memory implementations for web compatibility
|
|
45
46
|
__exportStar(require("./in-memory"), exports);
|
|
47
|
+
var fileTreeHelpers_inMemory_1 = require("./fileTreeHelpers.inMemory");
|
|
48
|
+
Object.defineProperty(exports, "inMemory", { enumerable: true, get: function () { return fileTreeHelpers_inMemory_1.inMemory; } });
|
|
46
49
|
// Exclude:
|
|
47
50
|
// - fsTree (requires Node.js fs/path)
|
|
48
51
|
// - fileTreeHelpers (imports fsTree)
|
|
@@ -3,6 +3,7 @@ export * from './fileTree';
|
|
|
3
3
|
export * from './directoryItem';
|
|
4
4
|
export * from './fileItem';
|
|
5
5
|
export * from './fileTreeHelpers';
|
|
6
|
+
export { inMemory } from './fileTreeHelpers.inMemory';
|
|
6
7
|
export * from './in-memory';
|
|
7
8
|
export * from './fsTree';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -35,6 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.inMemory = void 0;
|
|
38
39
|
// Export core interfaces and classes
|
|
39
40
|
__exportStar(require("./fileTreeAccessors"), exports);
|
|
40
41
|
__exportStar(require("./fileTree"), exports);
|
|
@@ -42,6 +43,8 @@ __exportStar(require("./directoryItem"), exports);
|
|
|
42
43
|
__exportStar(require("./fileItem"), exports);
|
|
43
44
|
// Export tree-shakeable helpers (filesystem ones will be shaken out if not used)
|
|
44
45
|
__exportStar(require("./fileTreeHelpers"), exports);
|
|
46
|
+
var fileTreeHelpers_inMemory_1 = require("./fileTreeHelpers.inMemory");
|
|
47
|
+
Object.defineProperty(exports, "inMemory", { enumerable: true, get: function () { return fileTreeHelpers_inMemory_1.inMemory; } });
|
|
45
48
|
// Export in-memory implementations for web compatibility
|
|
46
49
|
__exportStar(require("./in-memory"), exports);
|
|
47
50
|
// Note: FsFileTreeAccessors is now only imported by fileTreeHelpers.ts
|
|
@@ -58,7 +58,7 @@ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) :
|
|
|
58
58
|
* email?: string; // Optional property can be undefined
|
|
59
59
|
* }
|
|
60
60
|
*
|
|
61
|
-
* type UserCompatible =
|
|
61
|
+
* type UserCompatible = JsonCompatibleType<IUser>; // Allows undefined for email
|
|
62
62
|
*
|
|
63
63
|
* const user: UserCompatible = {
|
|
64
64
|
* name: "John",
|
|
@@ -72,8 +72,8 @@ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) :
|
|
|
72
72
|
*
|
|
73
73
|
* @public
|
|
74
74
|
*/
|
|
75
|
-
export type
|
|
76
|
-
[K in keyof T]:
|
|
75
|
+
export type JsonCompatibleType<T> = IsUnknown<T> extends true ? JsonValue : T extends JsonPrimitive | undefined ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
|
|
76
|
+
[K in keyof T]: JsonCompatibleType<T[K]>;
|
|
77
77
|
} : ['Error: Non-JSON type'];
|
|
78
78
|
/**
|
|
79
79
|
* A type that represents an array of JSON-compatible values.
|
|
@@ -81,7 +81,7 @@ export type JsonCompatible<T> = IsUnknown<T> extends true ? JsonValue : T extend
|
|
|
81
81
|
* @returns A constrained type that is compatible with JSON serialization.
|
|
82
82
|
* @public
|
|
83
83
|
*/
|
|
84
|
-
export type JsonCompatibleArray<T> = Array<
|
|
84
|
+
export type JsonCompatibleArray<T> = Array<JsonCompatibleType<T>>;
|
|
85
85
|
/**
|
|
86
86
|
* Test if an `unknown` is a {@link JsonValue | JsonValue}.
|
|
87
87
|
* @param from - The `unknown` to be tested
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Converter as BaseConverter, ObjectConverter as BaseObjectConverter, Validation, Validator as BaseValidator } from '@fgv/ts-utils';
|
|
2
|
+
import { JsonCompatibleType } from '../json';
|
|
3
|
+
/**
|
|
4
|
+
* A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type Converter<T, TC = unknown> = BaseConverter<JsonCompatibleType<T>, TC>;
|
|
8
|
+
/**
|
|
9
|
+
* A validator which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type Validator<T, TC = unknown> = BaseValidator<JsonCompatibleType<T>, TC>;
|
|
13
|
+
/**
|
|
14
|
+
* A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export type ObjectConverter<T, TC = unknown> = BaseObjectConverter<JsonCompatibleType<T>, TC>;
|
|
18
|
+
/**
|
|
19
|
+
* A validator which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export type ObjectValidator<T, TC = unknown> = Validation.Classes.ObjectValidator<JsonCompatibleType<T>, TC>;
|
|
23
|
+
/**
|
|
24
|
+
* A converter which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatible} values.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export type ArrayConverter<T, TC = unknown> = BaseConverter<JsonCompatibleType<T>[], TC>;
|
|
28
|
+
/**
|
|
29
|
+
* A validator which validates arrays of {@link JsonCompatibleType | JsonCompatible} values in place.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export type ArrayValidator<T, TC = unknown> = Validation.Classes.ArrayValidator<JsonCompatibleType<T>, TC>;
|
|
33
|
+
/**
|
|
34
|
+
* A converter which converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export type RecordConverter<T, TC = unknown, TK extends string = string> = BaseConverter<Record<TK, JsonCompatibleType<T>>, TC>;
|
|
38
|
+
/**
|
|
39
|
+
* A validator which validates a record of {@link JsonCompatibleType | JsonCompatible} values.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export type RecordValidator<T, TC = unknown, TK extends string = string> = Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>;
|
|
43
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Conversion, Converters } from '@fgv/ts-utils';
|
|
2
|
+
import * as JsonCompatible from './common';
|
|
3
|
+
import { JsonCompatibleType } from '../json';
|
|
4
|
+
/**
|
|
5
|
+
* A helper function to create a {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>}
|
|
6
|
+
* which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatibleType<T>}.
|
|
7
|
+
* @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source array.
|
|
8
|
+
* @param onError - The error handling option to use for the conversion.
|
|
9
|
+
* @returns A {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>} which returns `JsonCompatibleType<T>[]`.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare function arrayOf<T, TC = unknown>(converter: JsonCompatible.Converter<T, TC> | JsonCompatible.Validator<T, TC>, onError?: Conversion.OnError): JsonCompatible.ArrayConverter<T, TC>;
|
|
13
|
+
/**
|
|
14
|
+
* A helper function to create a {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>}
|
|
15
|
+
* which converts the `string`-keyed properties using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or
|
|
16
|
+
* {@link JsonCompatible.Validator | JSON-compatible Validator<T>} to produce a
|
|
17
|
+
* `Record<TK, JsonCompatibleType<T>>`.
|
|
18
|
+
* @remarks
|
|
19
|
+
* If present, the supplied `Converters.KeyedConverterOptions` can provide a strongly-typed
|
|
20
|
+
* converter for keys and/or control the handling of elements that fail conversion.
|
|
21
|
+
* @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
|
|
22
|
+
* or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source object.
|
|
23
|
+
* @param options - Optional `Converters.KeyedConverterOptions<TK, TC>` which
|
|
24
|
+
* supplies a key converter and/or error-handling options.
|
|
25
|
+
* @returns A {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>} which
|
|
26
|
+
* converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare function recordOf<T, TC = unknown, TK extends string = string>(converter: JsonCompatible.Converter<T, TC> | JsonCompatible.Validator<T, TC>, options?: Converters.KeyedConverterOptions<TK, TC>): JsonCompatible.RecordConverter<T, TC, TK>;
|
|
30
|
+
/**
|
|
31
|
+
* A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
|
|
32
|
+
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
33
|
+
* @param properties - The properties to convert.
|
|
34
|
+
* @param options - The options to use for the conversion.
|
|
35
|
+
* @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which
|
|
36
|
+
* converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare function object<T, TC = unknown>(properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>, options?: Conversion.ObjectConverterOptions<JsonCompatibleType<T>>): JsonCompatible.ObjectConverter<T, TC>;
|
|
40
|
+
/**
|
|
41
|
+
* A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
|
|
42
|
+
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
43
|
+
* @param properties - The properties to convert.
|
|
44
|
+
* @param options - The options to use for the conversion.
|
|
45
|
+
* @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which
|
|
46
|
+
* converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare function strictObject<T, TC = unknown>(properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>, options?: Converters.StrictObjectConverterOptions<JsonCompatibleType<T>>): JsonCompatible.ObjectConverter<T, TC>;
|
|
50
|
+
/**
|
|
51
|
+
* A helper function to create a {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which converts a
|
|
52
|
+
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
53
|
+
* @param discriminatorProp - The name of the property used to discriminate types.
|
|
54
|
+
* @param converters - The converters to use for the conversion.
|
|
55
|
+
* @returns A {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which
|
|
56
|
+
* converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export declare function discriminatedObject<T, TD extends string = string, TC = unknown>(discriminatorProp: string, converters: Converters.DiscriminatedObjectConverters<JsonCompatibleType<T>, TD, TC>): JsonCompatible.Converter<T, TC>;
|
|
60
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.arrayOf = arrayOf;
|
|
25
|
+
exports.recordOf = recordOf;
|
|
26
|
+
exports.object = object;
|
|
27
|
+
exports.strictObject = strictObject;
|
|
28
|
+
exports.discriminatedObject = discriminatedObject;
|
|
29
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
30
|
+
/**
|
|
31
|
+
* A helper function to create a {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>}
|
|
32
|
+
* which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatibleType<T>}.
|
|
33
|
+
* @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source array.
|
|
34
|
+
* @param onError - The error handling option to use for the conversion.
|
|
35
|
+
* @returns A {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>} which returns `JsonCompatibleType<T>[]`.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
function arrayOf(converter, onError = 'failOnError') {
|
|
39
|
+
return ts_utils_1.Converters.arrayOf(converter, onError);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A helper function to create a {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>}
|
|
43
|
+
* which converts the `string`-keyed properties using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or
|
|
44
|
+
* {@link JsonCompatible.Validator | JSON-compatible Validator<T>} to produce a
|
|
45
|
+
* `Record<TK, JsonCompatibleType<T>>`.
|
|
46
|
+
* @remarks
|
|
47
|
+
* If present, the supplied `Converters.KeyedConverterOptions` can provide a strongly-typed
|
|
48
|
+
* converter for keys and/or control the handling of elements that fail conversion.
|
|
49
|
+
* @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
|
|
50
|
+
* or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source object.
|
|
51
|
+
* @param options - Optional `Converters.KeyedConverterOptions<TK, TC>` which
|
|
52
|
+
* supplies a key converter and/or error-handling options.
|
|
53
|
+
* @returns A {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>} which
|
|
54
|
+
* converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
function recordOf(converter, options) {
|
|
58
|
+
return ts_utils_1.Converters.recordOf(converter, options !== null && options !== void 0 ? options : { onError: 'fail' });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
|
|
62
|
+
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
63
|
+
* @param properties - The properties to convert.
|
|
64
|
+
* @param options - The options to use for the conversion.
|
|
65
|
+
* @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which
|
|
66
|
+
* converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
function object(properties, options) {
|
|
70
|
+
return new ts_utils_1.Conversion.ObjectConverter(properties, options);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
|
|
74
|
+
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
75
|
+
* @param properties - The properties to convert.
|
|
76
|
+
* @param options - The options to use for the conversion.
|
|
77
|
+
* @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which
|
|
78
|
+
* converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
function strictObject(properties, options) {
|
|
82
|
+
const objectOptions = Object.assign(Object.assign({}, options), { strict: true });
|
|
83
|
+
return new ts_utils_1.Conversion.ObjectConverter(properties, objectOptions);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A helper function to create a {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which converts a
|
|
87
|
+
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
88
|
+
* @param discriminatorProp - The name of the property used to discriminate types.
|
|
89
|
+
* @param converters - The converters to use for the conversion.
|
|
90
|
+
* @returns A {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which
|
|
91
|
+
* converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
function discriminatedObject(discriminatorProp, converters) {
|
|
95
|
+
return ts_utils_1.Converters.discriminatedObject(discriminatorProp, converters);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
40
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
41
|
+
};
|
|
42
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
43
|
+
var ownKeys = function(o) {
|
|
44
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
45
|
+
var ar = [];
|
|
46
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
47
|
+
return ar;
|
|
48
|
+
};
|
|
49
|
+
return ownKeys(o);
|
|
50
|
+
};
|
|
51
|
+
return function (mod) {
|
|
52
|
+
if (mod && mod.__esModule) return mod;
|
|
53
|
+
var result = {};
|
|
54
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
55
|
+
__setModuleDefault(result, mod);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.Validators = exports.Converters = void 0;
|
|
61
|
+
__exportStar(require("./common"), exports);
|
|
62
|
+
const Converters = __importStar(require("./converters"));
|
|
63
|
+
exports.Converters = Converters;
|
|
64
|
+
const Validators = __importStar(require("./validators"));
|
|
65
|
+
exports.Validators = Validators;
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { JsonCompatibleType } from '../json';
|
|
2
|
+
import * as JsonCompatible from './common';
|
|
3
|
+
import { Validation, Validators } from '@fgv/ts-utils';
|
|
4
|
+
/**
|
|
5
|
+
* A helper function to create a {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
6
|
+
* @param validateElement - The element validator to use.
|
|
7
|
+
* @param params - The parameters to use for the validation.
|
|
8
|
+
* @returns A {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare function arrayOf<T, TC = unknown>(validateElement: JsonCompatible.Validator<T, TC>, params?: Omit<Validation.Classes.ArrayValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'validateElement'>): JsonCompatible.ArrayValidator<T, TC>;
|
|
12
|
+
/**
|
|
13
|
+
* A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC, TK>} which validates a supplied `unknown` value
|
|
14
|
+
* to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
15
|
+
* @param validateElement - The element validator to use.
|
|
16
|
+
* @param options - The options to use for the validation.
|
|
17
|
+
* @returns A `Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>` which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function recordOf<T, TC = unknown, TK extends string = string>(validateElement: JsonCompatible.Validator<T, TC>, options?: Validators.IRecordOfValidatorOptions<TK, TC>): JsonCompatible.RecordValidator<T, TC, TK>;
|
|
21
|
+
/**
|
|
22
|
+
* A helper function to create a {@link JsonCompatible.ObjectValidator | JSON-compatible ObjectValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
23
|
+
* @param properties - The properties to validate.
|
|
24
|
+
* @param params - The parameters to use for the validation.
|
|
25
|
+
* @returns A {@link JsonCompatible.ObjectValidator | JSON-compatible ObjectValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function object<T, TC = unknown>(properties: Validation.Classes.FieldValidators<JsonCompatibleType<T>, TC>, params?: Omit<Validation.Classes.ObjectValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'fields'>): JsonCompatible.ObjectValidator<T, TC>;
|
|
29
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.arrayOf = arrayOf;
|
|
25
|
+
exports.recordOf = recordOf;
|
|
26
|
+
exports.object = object;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
/**
|
|
29
|
+
* A helper function to create a {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
30
|
+
* @param validateElement - The element validator to use.
|
|
31
|
+
* @param params - The parameters to use for the validation.
|
|
32
|
+
* @returns A {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
function arrayOf(validateElement, params) {
|
|
36
|
+
return ts_utils_1.Validators.arrayOf(validateElement, params !== null && params !== void 0 ? params : {});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC, TK>} which validates a supplied `unknown` value
|
|
40
|
+
* to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
41
|
+
* @param validateElement - The element validator to use.
|
|
42
|
+
* @param options - The options to use for the validation.
|
|
43
|
+
* @returns A `Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>` which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
function recordOf(validateElement, options) {
|
|
47
|
+
return ts_utils_1.Validators.recordOf(validateElement, options !== null && options !== void 0 ? options : {});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A helper function to create a {@link JsonCompatible.ObjectValidator | JSON-compatible ObjectValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
51
|
+
* @param properties - The properties to validate.
|
|
52
|
+
* @param params - The parameters to use for the validation.
|
|
53
|
+
* @returns A {@link JsonCompatible.ObjectValidator | JSON-compatible ObjectValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
function object(properties, params) {
|
|
57
|
+
return ts_utils_1.Validators.object(properties, params !== null && params !== void 0 ? params : {});
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './file';
|
|
2
1
|
export * from './jsonLike';
|
|
3
2
|
export * from './jsonTreeHelper';
|
|
3
|
+
export type { IJsonFsDirectoryOptions, IReadDirectoryItem, ItemNameTransformFunction, IJsonFsDirectoryToMapOptions, IJsonFsHelperConfig, JsonFsHelperInitOptions } from './jsonFsHelper';
|
|
4
4
|
//# sourceMappingURL=index.browser.d.ts.map
|
|
@@ -36,11 +36,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
// Browser-safe JSON file exports - excludes Node.js filesystem dependencies
|
|
39
|
-
// Export core
|
|
40
|
-
__exportStar(require("./file"), exports);
|
|
39
|
+
// Export browser-safe core functionality
|
|
41
40
|
__exportStar(require("./jsonLike"), exports);
|
|
42
41
|
// Export FileTree-based helper (web-compatible)
|
|
43
42
|
__exportStar(require("./jsonTreeHelper"), exports);
|
|
44
43
|
// Exclude:
|
|
44
|
+
// - file.ts (wraps jsonFsHelper - requires Node.js fs/path)
|
|
45
45
|
// - jsonFsHelper (requires Node.js fs/path)
|
|
46
46
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -46,7 +46,7 @@ class JsonTreeHelper {
|
|
|
46
46
|
*/
|
|
47
47
|
readJsonFromTree(fileTree, filePath) {
|
|
48
48
|
return fileTree.getFile(filePath).onSuccess((file) => {
|
|
49
|
-
// Now getContents() returns
|
|
49
|
+
// Now getContents() returns JsonCompatibleType<unknown> which is assignable to JsonValue!
|
|
50
50
|
return file.getContents();
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Validator } from '@fgv/ts-utils';
|
|
1
|
+
import { Validation, Validator } from '@fgv/ts-utils';
|
|
2
2
|
import { JsonArray, JsonObject, JsonPrimitive, JsonValue } from '../json';
|
|
3
3
|
/**
|
|
4
4
|
* Validation context for in-place JSON validators.
|
|
@@ -37,4 +37,44 @@ export declare const jsonArray: Validator<JsonArray, IJsonValidatorContext>;
|
|
|
37
37
|
* @public
|
|
38
38
|
*/
|
|
39
39
|
export declare const jsonValue: Validator<JsonValue, IJsonValidatorContext>;
|
|
40
|
+
/**
|
|
41
|
+
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
42
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare const string: Validation.Classes.StringValidator<string, IJsonValidatorContext>;
|
|
46
|
+
/**
|
|
47
|
+
* A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
|
|
48
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare const number: Validator<number, IJsonValidatorContext>;
|
|
52
|
+
/**
|
|
53
|
+
* A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.
|
|
54
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export declare const boolean: Validator<boolean, IJsonValidatorContext>;
|
|
58
|
+
/**
|
|
59
|
+
* Helper to create a validator for a literal value.
|
|
60
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
61
|
+
* Mirrors the behavior of `@fgv/ts-utils`.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export declare function literal<T>(value: T): Validator<T, IJsonValidatorContext>;
|
|
65
|
+
/**
|
|
66
|
+
* Helper function to create a {@link Validator | Validator} which validates `unknown` to one of a set of
|
|
67
|
+
* supplied enumerated values. Anything else fails.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* This JSON variant accepts an {@link Validators.IJsonValidatorContext | IJsonValidatorContext} OR
|
|
71
|
+
* a `ReadonlyArray<T>` as its validation context. If the context is an array, it is used to override the
|
|
72
|
+
* allowed values for that validation; otherwise, the original `values` supplied at creation time are used.
|
|
73
|
+
*
|
|
74
|
+
* @param values - Array of allowed values.
|
|
75
|
+
* @param message - Optional custom failure message.
|
|
76
|
+
* @returns A new {@link Validator | Validator} returning `<T>`.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare function enumeratedValue<T>(values: ReadonlyArray<T>, message?: string): Validator<T, IJsonValidatorContext | ReadonlyArray<T>>;
|
|
40
80
|
//# sourceMappingURL=validators.d.ts.map
|