@fgv/ts-json-base 5.0.1-5 → 5.0.1-7

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.
@@ -8,24 +8,35 @@ import { Validator } from '@fgv/ts-utils';
8
8
  import { Validators as Validators_3 } from '@fgv/ts-utils';
9
9
 
10
10
  /**
11
- * A helper function to create a {@link Converter | Converter} which converts a supplied `unknown` value to a valid
12
- * array of {@link JsonCompatibleType | JsonCompatibleType<T>}.
13
- * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
14
- * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source array.
11
+ * A converter which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatible} values.
12
+ * @public
13
+ */
14
+ declare type ArrayConverter<T, TC = unknown> = Converter<JsonCompatibleType<T>[], TC>;
15
+
16
+ /**
17
+ * A helper function to create a {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>}
18
+ * which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatibleType<T>}.
19
+ * @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.
15
20
  * @param onError - The error handling option to use for the conversion.
16
- * @returns A {@link Converter | Converter} which returns `JsonCompatibleType<T>[]`.
21
+ * @returns A {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>} which returns `JsonCompatibleType<T>[]`.
17
22
  * @public
18
23
  */
19
- declare function arrayOf<T, TC = unknown>(converter: JsonCompatible_2.Converter<T, TC> | JsonCompatible_2.Validator<T, TC>, onError?: Conversion.OnError): Converter<JsonCompatibleType<T>[], TC>;
24
+ declare function arrayOf<T, TC = unknown>(converter: JsonCompatible_2.Converter<T, TC> | JsonCompatible_2.Validator<T, TC>, onError?: Conversion.OnError): JsonCompatible_2.ArrayConverter<T, TC>;
20
25
 
21
26
  /**
22
27
  * 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.
23
- * @param validateElement - The element to validate.
28
+ * @param validateElement - The element validator to use.
24
29
  * @param params - The parameters to use for the validation.
25
30
  * @returns A {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
26
31
  * @public
27
32
  */
28
- declare function arrayOf_2<T, TC = unknown>(validateElement: JsonCompatible_2.Validator<T, TC>, params?: Omit<Validation.Classes.ArrayValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'validateElement'>): Validation.Classes.ArrayValidator<JsonCompatibleType<T>, TC>;
33
+ declare function arrayOf_2<T, TC = unknown>(validateElement: JsonCompatible_2.Validator<T, TC>, params?: Omit<Validation.Classes.ArrayValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'validateElement'>): JsonCompatible_2.ArrayValidator<T, TC>;
34
+
35
+ /**
36
+ * A validator which validates arrays of {@link JsonCompatibleType | JsonCompatible} values in place.
37
+ * @public
38
+ */
39
+ declare type ArrayValidator<T, TC = unknown> = Validation.Classes.ArrayValidator<JsonCompatibleType<T>, TC>;
29
40
 
30
41
  /**
31
42
  * Identifies whether some `unknown` value is a {@link JsonPrimitive | primitive},
@@ -166,10 +177,12 @@ declare class DirectoryItem<TCT extends string = string> implements IFileTreeDir
166
177
  }
167
178
 
168
179
  /**
169
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
180
+ * A helper function to create a {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which converts a
181
+ * supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
170
182
  * @param discriminatorProp - The name of the property used to discriminate types.
171
183
  * @param converters - The converters to use for the conversion.
172
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
184
+ * @returns A {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which
185
+ * converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
173
186
  * @public
174
187
  */
175
188
  declare function discriminatedObject<T, TD extends string = string, TC = unknown>(discriminatorProp: string, converters: Converters_3.DiscriminatedObjectConverters<JsonCompatibleType<T>, TD, TC>): JsonCompatible_2.Converter<T, TC>;
@@ -269,6 +282,7 @@ declare class FileItem<TCT extends string = string> implements IFileTreeFileItem
269
282
 
270
283
  declare namespace FileTree {
271
284
  export {
285
+ inMemory,
272
286
  FileTreeItemType,
273
287
  ContentTypeFactory,
274
288
  IFileTreeInitParams,
@@ -280,7 +294,6 @@ declare namespace FileTree {
280
294
  DirectoryItem,
281
295
  FileItem,
282
296
  forFilesystem,
283
- inMemory,
284
297
  IInMemoryFile,
285
298
  InMemoryTreeAccessors,
286
299
  FsFileTreeAccessors
@@ -815,7 +828,11 @@ declare namespace JsonCompatible {
815
828
  Converter_2 as Converter,
816
829
  Validator_2 as Validator,
817
830
  ObjectConverter,
818
- ObjectValidator
831
+ ObjectValidator,
832
+ ArrayConverter,
833
+ ArrayValidator,
834
+ RecordConverter,
835
+ RecordValidator
819
836
  }
820
837
  }
821
838
  export { JsonCompatible }
@@ -825,7 +842,11 @@ declare namespace JsonCompatible_2 {
825
842
  Converter_2 as Converter,
826
843
  Validator_2 as Validator,
827
844
  ObjectConverter,
828
- ObjectValidator
845
+ ObjectValidator,
846
+ ArrayConverter,
847
+ ArrayValidator,
848
+ RecordConverter,
849
+ RecordValidator
829
850
  }
830
851
  }
831
852
 
@@ -1126,10 +1147,12 @@ declare const jsonValue_2: Validator<JsonValue, IJsonValidatorContext>;
1126
1147
  export declare type JsonValueType = 'primitive' | 'object' | 'array';
1127
1148
 
1128
1149
  /**
1129
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1150
+ * A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
1151
+ * supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1130
1152
  * @param properties - The properties to convert.
1131
1153
  * @param options - The options to use for the conversion.
1132
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1154
+ * @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which
1155
+ * converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1133
1156
  * @public
1134
1157
  */
1135
1158
  declare function object<T, TC = unknown>(properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>, options?: Conversion.ObjectConverterOptions<JsonCompatibleType<T>>): JsonCompatible_2.ObjectConverter<T, TC>;
@@ -1184,30 +1207,44 @@ export declare function pickJsonValue(src: JsonObject, path: string): Result<Jso
1184
1207
  declare function readJsonFileSync(srcPath: string): Result<JsonValue>;
1185
1208
 
1186
1209
  /**
1187
- * A helper function to create a {@link Converter | Converter} or which converts the `string`-keyed properties
1188
- * using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or
1210
+ * A converter which converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.
1211
+ * @public
1212
+ */
1213
+ declare type RecordConverter<T, TC = unknown, TK extends string = string> = Converter<Record<TK, JsonCompatibleType<T>>, TC>;
1214
+
1215
+ /**
1216
+ * A helper function to create a {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>}
1217
+ * which converts the `string`-keyed properties using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or
1189
1218
  * {@link JsonCompatible.Validator | JSON-compatible Validator<T>} to produce a
1190
1219
  * `Record<TK, JsonCompatibleType<T>>`.
1191
1220
  * @remarks
1192
- * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
1221
+ * If present, the supplied `Converters.KeyedConverterOptions` can provide a strongly-typed
1193
1222
  * converter for keys and/or control the handling of elements that fail conversion.
1194
1223
  * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
1195
1224
  * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source object.
1196
- * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
1225
+ * @param options - Optional `Converters.KeyedConverterOptions<TK, TC>` which
1197
1226
  * supplies a key converter and/or error-handling options.
1198
- * @returns A {@link Converter | Converter} which returns `Record<TK, JsonCompatibleType<T>>`.
1227
+ * @returns A {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>} which
1228
+ * converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.
1199
1229
  * @public
1200
1230
  */
1201
- declare function recordOf<T, TC = unknown, TK extends string = string>(converter: JsonCompatible_2.Converter<T, TC> | JsonCompatible_2.Validator<T, TC>, options?: Converters_3.KeyedConverterOptions<TK, TC>): Converter<Record<TK, JsonCompatibleType<T>>, TC>;
1231
+ declare function recordOf<T, TC = unknown, TK extends string = string>(converter: JsonCompatible_2.Converter<T, TC> | JsonCompatible_2.Validator<T, TC>, options?: Converters_3.KeyedConverterOptions<TK, TC>): JsonCompatible_2.RecordConverter<T, TC, TK>;
1202
1232
 
1203
1233
  /**
1204
- * A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
1205
- * @param validateElement - The element to validate.
1234
+ * A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC, TK>} which validates a supplied `unknown` value
1235
+ * to a valid {@link JsonCompatibleType | JsonCompatible} value.
1236
+ * @param validateElement - The element validator to use.
1206
1237
  * @param options - The options to use for the validation.
1207
- * @returns A {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
1238
+ * @returns A `Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>` which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
1239
+ * @public
1240
+ */
1241
+ declare function recordOf_2<T, TC = unknown, TK extends string = string>(validateElement: JsonCompatible_2.Validator<T, TC>, options?: Validators_3.IRecordOfValidatorOptions<TK, TC>): JsonCompatible_2.RecordValidator<T, TC, TK>;
1242
+
1243
+ /**
1244
+ * A validator which validates a record of {@link JsonCompatibleType | JsonCompatible} values.
1208
1245
  * @public
1209
1246
  */
1210
- declare function recordOf_2<T, TC = unknown, TK extends string = string>(validateElement: JsonCompatible_2.Validator<T, TC>, options?: Validators_3.IRecordOfValidatorOptions<TK, TC>): Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>;
1247
+ declare type RecordValidator<T, TC = unknown, TK extends string = string> = Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>;
1211
1248
 
1212
1249
  /**
1213
1250
  * "Sanitizes" an `unknown` by stringifying and then parsing it. Guarantees a
@@ -1231,10 +1268,12 @@ export declare function sanitizeJson(from: unknown): Result<JsonValue>;
1231
1268
  export declare function sanitizeJsonObject<T>(from: T): Result<T>;
1232
1269
 
1233
1270
  /**
1234
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1271
+ * A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
1272
+ * supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1235
1273
  * @param properties - The properties to convert.
1236
1274
  * @param options - The options to use for the conversion.
1237
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1275
+ * @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which
1276
+ * converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
1238
1277
  * @public
1239
1278
  */
1240
1279
  declare function strictObject<T, TC = unknown>(properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>, options?: Converters_3.StrictObjectConverterOptions<JsonCompatibleType<T>>): JsonCompatible_2.ObjectConverter<T, TC>;
@@ -1,6 +1,5 @@
1
1
  import { Result } from '@fgv/ts-utils';
2
2
  import { FileTree } from './fileTree';
3
- import { IInMemoryFile } from './in-memory';
4
3
  import { IFileTreeInitParams } from './fileTreeAccessors';
5
4
  /**
6
5
  * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
@@ -20,24 +19,4 @@ export declare function forFilesystem<TCT extends string = string>(prefix?: stri
20
19
  * @public
21
20
  */
22
21
  export declare function forFilesystem<TCT extends string = string>(params?: IFileTreeInitParams<TCT>): Result<FileTree<TCT>>;
23
- /**
24
- * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
25
- * with accessors for an in-memory file tree.
26
- * @param files - An array of File |{@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
27
- * @param prefix - An optional prefix to add to the paths of all files in the tree.
28
- * @returns `Success` with the new {@link FileTree.FileTree | FileTree} instance
29
- * if successful, or `Failure` with an error message otherwise.
30
- * @public
31
- */
32
- export declare function inMemory<TCT extends string = string>(files: IInMemoryFile<TCT>[], prefix?: string): Result<FileTree<TCT>>;
33
- /**
34
- * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
35
- * with accessors for an in-memory file tree.
36
- * @param files - An array of File |{@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
37
- * @param params - Optional {@link FileTree.IFileTreeInitParams | initialization parameters} for the file tree.
38
- * @returns `Success` with the new {@link FileTree.FileTree | FileTree} instance
39
- * if successful, or `Failure` with an error message otherwise.
40
- * @public
41
- */
42
- export declare function inMemory<TCT extends string = string>(files: IInMemoryFile<TCT>[], params?: IFileTreeInitParams<TCT>): Result<FileTree<TCT>>;
43
22
  //# sourceMappingURL=fileTreeHelpers.d.ts.map
@@ -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
@@ -3,4 +3,5 @@ export * from './fileTree';
3
3
  export * from './directoryItem';
4
4
  export * from './fileItem';
5
5
  export * from './in-memory';
6
+ export { inMemory } from './fileTreeHelpers.inMemory';
6
7
  //# sourceMappingURL=index.browser.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
  // 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
@@ -20,4 +20,24 @@ export type ObjectConverter<T, TC = unknown> = BaseObjectConverter<JsonCompatibl
20
20
  * @public
21
21
  */
22
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>;
23
43
  //# sourceMappingURL=common.d.ts.map
@@ -1,53 +1,59 @@
1
- import { Conversion, Converter, Converters } from '@fgv/ts-utils';
1
+ import { Conversion, Converters } from '@fgv/ts-utils';
2
2
  import * as JsonCompatible from './common';
3
3
  import { JsonCompatibleType } from '../json';
4
4
  /**
5
- * A helper function to create a {@link Converter | Converter} which converts a supplied `unknown` value to a valid
6
- * array of {@link JsonCompatibleType | JsonCompatibleType<T>}.
7
- * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
8
- * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source array.
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.
9
8
  * @param onError - The error handling option to use for the conversion.
10
- * @returns A {@link Converter | Converter} which returns `JsonCompatibleType<T>[]`.
9
+ * @returns A {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>} which returns `JsonCompatibleType<T>[]`.
11
10
  * @public
12
11
  */
13
- export declare function arrayOf<T, TC = unknown>(converter: JsonCompatible.Converter<T, TC> | JsonCompatible.Validator<T, TC>, onError?: Conversion.OnError): Converter<JsonCompatibleType<T>[], TC>;
12
+ export declare function arrayOf<T, TC = unknown>(converter: JsonCompatible.Converter<T, TC> | JsonCompatible.Validator<T, TC>, onError?: Conversion.OnError): JsonCompatible.ArrayConverter<T, TC>;
14
13
  /**
15
- * A helper function to create a {@link Converter | Converter} or which converts the `string`-keyed properties
16
- * using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or
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
17
16
  * {@link JsonCompatible.Validator | JSON-compatible Validator<T>} to produce a
18
17
  * `Record<TK, JsonCompatibleType<T>>`.
19
18
  * @remarks
20
- * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
19
+ * If present, the supplied `Converters.KeyedConverterOptions` can provide a strongly-typed
21
20
  * converter for keys and/or control the handling of elements that fail conversion.
22
21
  * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
23
22
  * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source object.
24
- * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
23
+ * @param options - Optional `Converters.KeyedConverterOptions<TK, TC>` which
25
24
  * supplies a key converter and/or error-handling options.
26
- * @returns A {@link Converter | Converter} which returns `Record<TK, JsonCompatibleType<T>>`.
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
27
  * @public
28
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>): Converter<Record<TK, JsonCompatibleType<T>>, TC>;
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
30
  /**
31
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
32
33
  * @param properties - The properties to convert.
33
34
  * @param options - The options to use for the conversion.
34
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
35
37
  * @public
36
38
  */
37
39
  export declare function object<T, TC = unknown>(properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>, options?: Conversion.ObjectConverterOptions<JsonCompatibleType<T>>): JsonCompatible.ObjectConverter<T, TC>;
38
40
  /**
39
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
40
43
  * @param properties - The properties to convert.
41
44
  * @param options - The options to use for the conversion.
42
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
43
47
  * @public
44
48
  */
45
49
  export declare function strictObject<T, TC = unknown>(properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>, options?: Converters.StrictObjectConverterOptions<JsonCompatibleType<T>>): JsonCompatible.ObjectConverter<T, TC>;
46
50
  /**
47
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
48
53
  * @param discriminatorProp - The name of the property used to discriminate types.
49
54
  * @param converters - The converters to use for the conversion.
50
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
51
57
  * @public
52
58
  */
53
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>;
@@ -28,50 +28,54 @@ exports.strictObject = strictObject;
28
28
  exports.discriminatedObject = discriminatedObject;
29
29
  const ts_utils_1 = require("@fgv/ts-utils");
30
30
  /**
31
- * A helper function to create a {@link Converter | Converter} which converts a supplied `unknown` value to a valid
32
- * array of {@link JsonCompatibleType | JsonCompatibleType<T>}.
33
- * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
34
- * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source array.
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.
35
34
  * @param onError - The error handling option to use for the conversion.
36
- * @returns A {@link Converter | Converter} which returns `JsonCompatibleType<T>[]`.
35
+ * @returns A {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>} which returns `JsonCompatibleType<T>[]`.
37
36
  * @public
38
37
  */
39
38
  function arrayOf(converter, onError = 'failOnError') {
40
39
  return ts_utils_1.Converters.arrayOf(converter, onError);
41
40
  }
42
41
  /**
43
- * A helper function to create a {@link Converter | Converter} or which converts the `string`-keyed properties
44
- * using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or
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
45
44
  * {@link JsonCompatible.Validator | JSON-compatible Validator<T>} to produce a
46
45
  * `Record<TK, JsonCompatibleType<T>>`.
47
46
  * @remarks
48
- * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
47
+ * If present, the supplied `Converters.KeyedConverterOptions` can provide a strongly-typed
49
48
  * converter for keys and/or control the handling of elements that fail conversion.
50
49
  * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}
51
50
  * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source object.
52
- * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
51
+ * @param options - Optional `Converters.KeyedConverterOptions<TK, TC>` which
53
52
  * supplies a key converter and/or error-handling options.
54
- * @returns A {@link Converter | Converter} which returns `Record<TK, JsonCompatibleType<T>>`.
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
55
  * @public
56
56
  */
57
57
  function recordOf(converter, options) {
58
58
  return ts_utils_1.Converters.recordOf(converter, options !== null && options !== void 0 ? options : { onError: 'fail' });
59
59
  }
60
60
  /**
61
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
62
63
  * @param properties - The properties to convert.
63
64
  * @param options - The options to use for the conversion.
64
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
65
67
  * @public
66
68
  */
67
69
  function object(properties, options) {
68
70
  return new ts_utils_1.Conversion.ObjectConverter(properties, options);
69
71
  }
70
72
  /**
71
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
72
75
  * @param properties - The properties to convert.
73
76
  * @param options - The options to use for the conversion.
74
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
75
79
  * @public
76
80
  */
77
81
  function strictObject(properties, options) {
@@ -79,10 +83,12 @@ function strictObject(properties, options) {
79
83
  return new ts_utils_1.Conversion.ObjectConverter(properties, objectOptions);
80
84
  }
81
85
  /**
82
- * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
83
88
  * @param discriminatorProp - The name of the property used to discriminate types.
84
89
  * @param converters - The converters to use for the conversion.
85
- * @returns A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
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.
86
92
  * @public
87
93
  */
88
94
  function discriminatedObject(discriminatorProp, converters) {
@@ -3,20 +3,21 @@ import * as JsonCompatible from './common';
3
3
  import { Validation, Validators } from '@fgv/ts-utils';
4
4
  /**
5
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 to validate.
6
+ * @param validateElement - The element validator to use.
7
7
  * @param params - The parameters to use for the validation.
8
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
9
  * @public
10
10
  */
11
- export declare function arrayOf<T, TC = unknown>(validateElement: JsonCompatible.Validator<T, TC>, params?: Omit<Validation.Classes.ArrayValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'validateElement'>): Validation.Classes.ArrayValidator<JsonCompatibleType<T>, TC>;
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
12
  /**
13
- * A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
14
- * @param validateElement - The element to validate.
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.
15
16
  * @param options - The options to use for the validation.
16
- * @returns A {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
17
+ * @returns A `Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>` which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
17
18
  * @public
18
19
  */
19
- export declare function recordOf<T, TC = unknown, TK extends string = string>(validateElement: JsonCompatible.Validator<T, TC>, options?: Validators.IRecordOfValidatorOptions<TK, TC>): Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>;
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>;
20
21
  /**
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.
22
23
  * @param properties - The properties to validate.
@@ -27,7 +27,7 @@ exports.object = object;
27
27
  const ts_utils_1 = require("@fgv/ts-utils");
28
28
  /**
29
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 to validate.
30
+ * @param validateElement - The element validator to use.
31
31
  * @param params - The parameters to use for the validation.
32
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
33
  * @public
@@ -36,10 +36,11 @@ function arrayOf(validateElement, params) {
36
36
  return ts_utils_1.Validators.arrayOf(validateElement, params !== null && params !== void 0 ? params : {});
37
37
  }
38
38
  /**
39
- * A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
40
- * @param validateElement - The element to validate.
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.
41
42
  * @param options - The options to use for the validation.
42
- * @returns A {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
43
+ * @returns A `Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>` which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
43
44
  * @public
44
45
  */
45
46
  function recordOf(validateElement, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-json-base",
3
- "version": "5.0.1-5",
3
+ "version": "5.0.1-7",
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",
@@ -53,11 +53,11 @@
53
53
  "@rushstack/eslint-config": "4.5.3",
54
54
  "eslint-plugin-tsdoc": "~0.4.0",
55
55
  "@types/luxon": "^3.7.1",
56
- "@fgv/ts-utils": "5.0.1-5",
57
- "@fgv/ts-utils-jest": "5.0.1-5"
56
+ "@fgv/ts-utils": "5.0.1-7",
57
+ "@fgv/ts-utils-jest": "5.0.1-7"
58
58
  },
59
59
  "peerDependencies": {
60
- "@fgv/ts-utils": "5.0.1-5"
60
+ "@fgv/ts-utils": "5.0.1-7"
61
61
  },
62
62
  "dependencies": {
63
63
  "luxon": "^3.7.2"