@fgv/ts-json-base 5.0.1-9 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/tsdoc-metadata.json +1 -1
- package/lib/packlets/json-file/index.browser.d.ts +1 -1
- package/lib/packlets/json-file/index.browser.js +2 -2
- package/package.json +7 -5
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export const DefaultJsonLike = JSON;
|
|
26
|
+
//# sourceMappingURL=jsonLike.js.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { mapResults, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { DefaultJsonLike } from './jsonLike';
|
|
24
|
+
/**
|
|
25
|
+
* Helper class to work with JSON files using FileTree API (web-compatible).
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class JsonTreeHelper {
|
|
29
|
+
/**
|
|
30
|
+
* Construct a new JsonTreeHelper.
|
|
31
|
+
* @param json - Optional {@link JsonFile.IJsonLike | IJsonLike} used to process strings
|
|
32
|
+
* and JSON values.
|
|
33
|
+
*/
|
|
34
|
+
constructor(json) {
|
|
35
|
+
this.json = json !== null && json !== void 0 ? json : DefaultJsonLike;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Read type-safe JSON from a file in a FileTree.
|
|
39
|
+
* @param fileTree - The FileTree to read from
|
|
40
|
+
* @param filePath - Path of the file to read within the tree
|
|
41
|
+
* @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`
|
|
42
|
+
* with a message if an error occurs.
|
|
43
|
+
*/
|
|
44
|
+
readJsonFromTree(fileTree, filePath) {
|
|
45
|
+
return fileTree.getFile(filePath).onSuccess((file) => {
|
|
46
|
+
// Now getContents() returns JsonCompatibleType<unknown> which is assignable to JsonValue!
|
|
47
|
+
return file.getContents();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read a JSON file from a FileTree and apply a supplied converter or validator.
|
|
52
|
+
* @param fileTree - The FileTree to read from
|
|
53
|
+
* @param filePath - Path of the file to read within the tree
|
|
54
|
+
* @param cv - Converter or validator used to process the file.
|
|
55
|
+
* @param context - Optional context for the converter/validator
|
|
56
|
+
* @returns `Success` with a result of type `<T>`, or `Failure`
|
|
57
|
+
* with a message if an error occurs.
|
|
58
|
+
*/
|
|
59
|
+
convertJsonFromTree(fileTree, filePath, cv, context) {
|
|
60
|
+
return this.readJsonFromTree(fileTree, filePath).onSuccess((json) => {
|
|
61
|
+
return cv.convert(json, context);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reads all JSON files from a directory in a FileTree and applies a converter or validator.
|
|
66
|
+
* @param fileTree - The FileTree to read from
|
|
67
|
+
* @param dirPath - The path of the directory within the tree
|
|
68
|
+
* @param cv - Converter or validator to apply to each JSON file
|
|
69
|
+
* @param filePattern - Optional regex pattern to filter files (defaults to .json files)
|
|
70
|
+
* @param context - Optional context for the converter/validator
|
|
71
|
+
* @returns Array of items with filename and converted content
|
|
72
|
+
*/
|
|
73
|
+
convertJsonDirectoryFromTree(fileTree, dirPath, cv, filePattern, context) {
|
|
74
|
+
const pattern = filePattern !== null && filePattern !== void 0 ? filePattern : /\.json$/;
|
|
75
|
+
return fileTree.getDirectory(dirPath).onSuccess((dir) => {
|
|
76
|
+
return dir.getChildren().onSuccess((children) => {
|
|
77
|
+
const results = children
|
|
78
|
+
.filter((child) => child.type === 'file' && pattern.test(child.name))
|
|
79
|
+
.map((file) => {
|
|
80
|
+
return this.convertJsonFromTree(fileTree, file.absolutePath, cv, context).onSuccess((item) => {
|
|
81
|
+
return succeed({
|
|
82
|
+
filename: file.name,
|
|
83
|
+
item
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
return mapResults(results);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads and converts all JSON files from a directory in a FileTree,
|
|
93
|
+
* returning a Map indexed by file base name.
|
|
94
|
+
* @param fileTree - The FileTree to read from
|
|
95
|
+
* @param dirPath - The path of the directory within the tree
|
|
96
|
+
* @param cv - Converter or validator to apply to each JSON file
|
|
97
|
+
* @param filePattern - Optional regex pattern to filter files
|
|
98
|
+
* @param context - Optional context for the converter/validator
|
|
99
|
+
* @returns Map of basename to converted content
|
|
100
|
+
*/
|
|
101
|
+
convertJsonDirectoryToMapFromTree(fileTree, dirPath, cv, filePattern, context) {
|
|
102
|
+
return this.convertJsonDirectoryFromTree(fileTree, dirPath, cv, filePattern, context).onSuccess((items) => {
|
|
103
|
+
const map = new Map();
|
|
104
|
+
for (const item of items) {
|
|
105
|
+
const basename = item.filename.replace(/\.json$/, '');
|
|
106
|
+
map.set(basename, item.item);
|
|
107
|
+
}
|
|
108
|
+
return succeed(map);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
export const DefaultJsonTreeHelper = new JsonTreeHelper();
|
|
116
|
+
//# sourceMappingURL=jsonTreeHelper.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export * from './validators';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { Validation, fail } from '@fgv/ts-utils';
|
|
23
|
+
import { isJsonArray, isJsonObject } from '../json';
|
|
24
|
+
/**
|
|
25
|
+
* An in-place validator which validates that a supplied `unknown` value is
|
|
26
|
+
* a valid {@link JsonPrimitive | JsonPrimitive}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const jsonPrimitive = new Validation.Base.GenericValidator({
|
|
30
|
+
validator: (from, ctx, self) => {
|
|
31
|
+
if (from === null) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
switch (typeof from) {
|
|
35
|
+
case 'boolean':
|
|
36
|
+
case 'string':
|
|
37
|
+
return true;
|
|
38
|
+
case 'number':
|
|
39
|
+
if (!Number.isNaN(from)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (from === undefined && (ctx === null || ctx === void 0 ? void 0 : ctx.ignoreUndefinedProperties) === true) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return fail(`"${String(from)}": invalid JSON primitive.`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* An in-place validator which validates that a supplied `unknown` value is
|
|
52
|
+
* a valid {@link JsonObject | JsonObject}. Fails by default if any properties or array elements
|
|
53
|
+
* are `undefined` - this default behavior can be overridden by supplying an appropriate
|
|
54
|
+
* {@link Validators.IJsonValidatorContext | context} at runtime.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export const jsonObject = new Validation.Base.GenericValidator({
|
|
58
|
+
validator: (from, ctx, self) => {
|
|
59
|
+
if (!isJsonObject(from)) {
|
|
60
|
+
return fail('invalid JSON object.');
|
|
61
|
+
}
|
|
62
|
+
const errors = [];
|
|
63
|
+
for (const [name, value] of Object.entries(from)) {
|
|
64
|
+
jsonValue.validate(value, ctx).onFailure((m) => {
|
|
65
|
+
errors.push(`${name}: ${m}`);
|
|
66
|
+
return fail(m);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (errors.length > 0) {
|
|
70
|
+
return fail(`invalid JSON object:\n${errors.join('\n')}`);
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* An in-place validator which validates that a supplied `unknown` value is
|
|
77
|
+
* a valid {@link JsonArray | JsonArray}. Fails by default if any properties or array elements
|
|
78
|
+
* are `undefined` - this default behavior can be overridden by supplying an appropriate
|
|
79
|
+
* {@link Validators.IJsonValidatorContext | context} at runtime.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export const jsonArray = new Validation.Base.GenericValidator({
|
|
83
|
+
validator: (from, ctx, self) => {
|
|
84
|
+
if (!isJsonArray(from)) {
|
|
85
|
+
return fail('not an array');
|
|
86
|
+
}
|
|
87
|
+
const errors = [];
|
|
88
|
+
for (let i = 0; i < from.length; i++) {
|
|
89
|
+
const value = from[i];
|
|
90
|
+
jsonValue.validate(value, ctx).onFailure((m) => {
|
|
91
|
+
errors.push(`${i}: ${m}`);
|
|
92
|
+
return fail(m);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (errors.length > 0) {
|
|
96
|
+
return fail(`array contains non-json elements:\n${errors.join('\n')}`);
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* An in-place validator which validates that a supplied `unknown` value is
|
|
103
|
+
* a valid {@link JsonValue | JsonValue}. Fails by default if any properties or array elements
|
|
104
|
+
* are `undefined` - this default behavior can be overridden by supplying an appropriate
|
|
105
|
+
* {@link Validators.IJsonValidatorContext | context} at runtime.
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export const jsonValue = new Validation.Base.GenericValidator({
|
|
109
|
+
validator: (from, ctx, self) => {
|
|
110
|
+
if (isJsonArray(from)) {
|
|
111
|
+
const result = jsonArray.validate(from, ctx);
|
|
112
|
+
return result.success === true ? true : result;
|
|
113
|
+
}
|
|
114
|
+
else if (isJsonObject(from)) {
|
|
115
|
+
const result = jsonObject.validate(from, ctx);
|
|
116
|
+
return result.success === true ? true : result;
|
|
117
|
+
}
|
|
118
|
+
const result = jsonPrimitive.validate(from, ctx);
|
|
119
|
+
return result.success === true ? true : result;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
/**
|
|
123
|
+
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
124
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export const string = new Validation.Classes.StringValidator();
|
|
128
|
+
/**
|
|
129
|
+
* A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
|
|
130
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export const number = new Validation.Classes.NumberValidator();
|
|
134
|
+
/**
|
|
135
|
+
* A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.
|
|
136
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
137
|
+
* @public
|
|
138
|
+
*/
|
|
139
|
+
export const boolean = new Validation.Classes.BooleanValidator();
|
|
140
|
+
/**
|
|
141
|
+
* Helper to create a validator for a literal value.
|
|
142
|
+
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
143
|
+
* Mirrors the behavior of `@fgv/ts-utils`.
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
export function literal(value) {
|
|
147
|
+
return new Validation.Base.GenericValidator({
|
|
148
|
+
validator: (from) => {
|
|
149
|
+
return from === value ? true : fail(`Expected literal ${String(value)}, found ${JSON.stringify(from)}`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Helper function to create a {@link Validator | Validator} which validates `unknown` to one of a set of
|
|
155
|
+
* supplied enumerated values. Anything else fails.
|
|
156
|
+
*
|
|
157
|
+
* @remarks
|
|
158
|
+
* This JSON variant accepts an {@link Validators.IJsonValidatorContext | IJsonValidatorContext} OR
|
|
159
|
+
* a `ReadonlyArray<T>` as its validation context. If the context is an array, it is used to override the
|
|
160
|
+
* allowed values for that validation; otherwise, the original `values` supplied at creation time are used.
|
|
161
|
+
*
|
|
162
|
+
* @param values - Array of allowed values.
|
|
163
|
+
* @param message - Optional custom failure message.
|
|
164
|
+
* @returns A new {@link Validator | Validator} returning `<T>`.
|
|
165
|
+
* @public
|
|
166
|
+
*/
|
|
167
|
+
export function enumeratedValue(values, message) {
|
|
168
|
+
return new Validation.Base.GenericValidator({
|
|
169
|
+
validator: (from, context) => {
|
|
170
|
+
const effectiveValues = Array.isArray(context) ? context : values;
|
|
171
|
+
const index = effectiveValues.indexOf(from);
|
|
172
|
+
if (index >= 0) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
return fail(message !== null && message !== void 0 ? message : `Invalid enumerated value ${JSON.stringify(from)}`);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "name": "test", "enabled": true }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[1, 2, 3]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "endpoints": [] }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
// Factory helpers for runtime sections
|
|
23
|
+
export function makeUser(overrides = {}) {
|
|
24
|
+
return Object.assign({ id: 'u1', name: 'Test User', tags: ['a', 'b'], meta: { active: true, score: 10 } }, overrides);
|
|
25
|
+
}
|
|
26
|
+
export function makeAlpha() {
|
|
27
|
+
return { kind: 'alpha', value: 'ok' };
|
|
28
|
+
}
|
|
29
|
+
export function makeBeta() {
|
|
30
|
+
return { kind: 'beta', count: 3 };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=helpers.js.map
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-json-base",
|
|
3
|
-
"version": "5.0.1
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Typescript types and basic functions for working with json",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-json-base.d.ts",
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"ts-node": "^10.9.2",
|
|
45
45
|
"typescript": "5.9.3",
|
|
46
46
|
"eslint-plugin-n": "^17.23.1",
|
|
47
|
-
"@rushstack/heft-node-rig": "2.11.4",
|
|
48
47
|
"@rushstack/heft": "1.1.3",
|
|
49
48
|
"@rushstack/heft-jest-plugin": "1.1.3",
|
|
50
49
|
"@types/heft-jest": "1.0.6",
|
|
@@ -53,11 +52,14 @@
|
|
|
53
52
|
"@rushstack/eslint-config": "4.5.3",
|
|
54
53
|
"eslint-plugin-tsdoc": "~0.4.0",
|
|
55
54
|
"@types/luxon": "^3.7.1",
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
55
|
+
"@rushstack/heft-node-rig": "2.11.4",
|
|
56
|
+
"@microsoft/api-extractor": "^7.53.3",
|
|
57
|
+
"@fgv/ts-utils": "5.0.1",
|
|
58
|
+
"@fgv/heft-dual-rig": "0.1.0",
|
|
59
|
+
"@fgv/ts-utils-jest": "5.0.1"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
60
|
-
"@fgv/ts-utils": "5.0.1
|
|
62
|
+
"@fgv/ts-utils": "5.0.1"
|
|
61
63
|
},
|
|
62
64
|
"dependencies": {
|
|
63
65
|
"luxon": "^3.7.2"
|