@fgv/ts-json-base 5.1.0-4 → 5.1.0-40
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 +2 -1
- package/dist/index.browser.js.map +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/packlets/converters/converters.js +11 -0
- package/dist/packlets/converters/converters.js.map +1 -0
- package/dist/packlets/converters/index.js.map +1 -0
- package/dist/packlets/file-tree/directoryItem.js.map +1 -0
- package/dist/packlets/file-tree/fileItem.js +11 -4
- package/dist/packlets/file-tree/fileItem.js.map +1 -0
- package/dist/packlets/file-tree/fileTree.js.map +1 -0
- package/dist/packlets/file-tree/fileTreeAccessors.js.map +1 -0
- package/dist/packlets/file-tree/fileTreeHelpers.inMemory.js.map +1 -0
- package/dist/packlets/file-tree/fileTreeHelpers.js.map +1 -0
- package/dist/packlets/file-tree/filterSpec.js.map +1 -0
- package/dist/packlets/file-tree/fsTree.js +44 -13
- package/dist/packlets/file-tree/fsTree.js.map +1 -0
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js +44 -13
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
- package/dist/packlets/file-tree/in-memory/index.js.map +1 -0
- package/dist/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
- package/dist/packlets/file-tree/index.browser.js.map +1 -0
- package/dist/packlets/file-tree/index.js.map +1 -0
- package/dist/packlets/json/common.js.map +1 -0
- package/dist/packlets/json/index.js.map +1 -0
- package/dist/packlets/json-compatible/common.js.map +1 -0
- package/dist/packlets/json-compatible/converters.js.map +1 -0
- package/dist/packlets/json-compatible/index.js.map +1 -0
- package/dist/packlets/json-compatible/validators.js.map +1 -0
- package/dist/packlets/json-file/file.js.map +1 -0
- package/dist/packlets/json-file/index.browser.js.map +1 -0
- package/dist/packlets/json-file/index.js.map +1 -0
- package/dist/packlets/json-file/jsonFsHelper.js.map +1 -0
- package/dist/packlets/json-file/jsonLike.js.map +1 -0
- package/dist/packlets/json-file/jsonTreeHelper.js.map +1 -0
- package/dist/packlets/json-schema-builder/factories.js +342 -0
- package/dist/packlets/json-schema-builder/factories.js.map +1 -0
- package/dist/packlets/json-schema-builder/fromJson.js +371 -0
- package/dist/packlets/json-schema-builder/fromJson.js.map +1 -0
- package/dist/packlets/json-schema-builder/index.js +36 -0
- package/dist/packlets/json-schema-builder/index.js.map +1 -0
- package/dist/{test/unit/json-compatible/helpers.js → packlets/json-schema-builder/types.js} +3 -12
- package/dist/packlets/json-schema-builder/types.js.map +1 -0
- package/dist/packlets/validators/index.js.map +1 -0
- package/dist/packlets/validators/validators.js.map +1 -0
- package/dist/ts-json-base.d.ts +473 -36
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +2 -1
- package/lib/index.browser.d.ts.map +1 -0
- package/lib/index.browser.js +3 -1
- package/lib/index.browser.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -0
- package/lib/packlets/converters/converters.d.ts +27 -1
- package/lib/packlets/converters/converters.d.ts.map +1 -0
- package/lib/packlets/converters/converters.js +12 -0
- package/lib/packlets/converters/converters.js.map +1 -0
- package/lib/packlets/converters/index.d.ts.map +1 -0
- package/lib/packlets/converters/index.js.map +1 -0
- package/lib/packlets/file-tree/directoryItem.d.ts.map +1 -0
- package/lib/packlets/file-tree/directoryItem.js.map +1 -0
- package/lib/packlets/file-tree/fileItem.d.ts +11 -4
- package/lib/packlets/file-tree/fileItem.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileItem.js +11 -4
- package/lib/packlets/file-tree/fileItem.js.map +1 -0
- package/lib/packlets/file-tree/fileTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTree.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.inMemory.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.inMemory.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.js.map +1 -0
- package/lib/packlets/file-tree/filterSpec.d.ts.map +1 -0
- package/lib/packlets/file-tree/filterSpec.js.map +1 -0
- package/lib/packlets/file-tree/fsTree.d.ts +44 -13
- package/lib/packlets/file-tree/fsTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/fsTree.js +44 -13
- package/lib/packlets/file-tree/fsTree.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +44 -13
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +44 -13
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/index.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
- package/lib/packlets/file-tree/index.browser.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.browser.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.js.map +1 -0
- package/lib/packlets/json/common.d.ts.map +1 -0
- package/lib/packlets/json/common.js.map +1 -0
- package/lib/packlets/json/index.d.ts.map +1 -0
- package/lib/packlets/json/index.js.map +1 -0
- package/lib/packlets/json-compatible/common.d.ts.map +1 -0
- package/lib/packlets/json-compatible/common.js.map +1 -0
- package/lib/packlets/json-compatible/converters.d.ts.map +1 -0
- package/lib/packlets/json-compatible/converters.js.map +1 -0
- package/lib/packlets/json-compatible/index.d.ts.map +1 -0
- package/lib/packlets/json-compatible/index.js.map +1 -0
- package/lib/packlets/json-compatible/validators.d.ts.map +1 -0
- package/lib/packlets/json-compatible/validators.js.map +1 -0
- package/lib/packlets/json-file/file.d.ts.map +1 -0
- package/lib/packlets/json-file/file.js.map +1 -0
- package/lib/packlets/json-file/index.browser.d.ts.map +1 -0
- package/lib/packlets/json-file/index.browser.js.map +1 -0
- package/lib/packlets/json-file/index.d.ts.map +1 -0
- package/lib/packlets/json-file/index.js.map +1 -0
- package/lib/packlets/json-file/jsonFsHelper.d.ts.map +1 -0
- package/lib/packlets/json-file/jsonFsHelper.js.map +1 -0
- package/lib/packlets/json-file/jsonLike.d.ts.map +1 -0
- package/lib/packlets/json-file/jsonLike.js.map +1 -0
- package/lib/packlets/json-file/jsonTreeHelper.d.ts.map +1 -0
- package/lib/packlets/json-file/jsonTreeHelper.js.map +1 -0
- package/lib/packlets/json-schema-builder/factories.d.ts +95 -0
- package/lib/packlets/json-schema-builder/factories.d.ts.map +1 -0
- package/lib/packlets/json-schema-builder/factories.js +352 -0
- package/lib/packlets/json-schema-builder/factories.js.map +1 -0
- package/lib/packlets/json-schema-builder/fromJson.d.ts +45 -0
- package/lib/packlets/json-schema-builder/fromJson.d.ts.map +1 -0
- package/lib/packlets/json-schema-builder/fromJson.js +375 -0
- package/lib/packlets/json-schema-builder/fromJson.js.map +1 -0
- package/lib/packlets/json-schema-builder/index.d.ts +15 -0
- package/lib/packlets/json-schema-builder/index.d.ts.map +1 -0
- package/lib/packlets/json-schema-builder/index.js +52 -0
- package/lib/packlets/json-schema-builder/index.js.map +1 -0
- package/lib/packlets/json-schema-builder/types.d.ts +142 -0
- package/lib/packlets/json-schema-builder/types.d.ts.map +1 -0
- package/lib/packlets/json-schema-builder/types.js +24 -0
- package/lib/packlets/json-schema-builder/types.js.map +1 -0
- package/lib/packlets/validators/index.d.ts.map +1 -0
- package/lib/packlets/validators/index.js.map +1 -0
- package/lib/packlets/validators/validators.d.ts.map +1 -0
- package/lib/packlets/validators/validators.js.map +1 -0
- package/package.json +6 -6
- package/dist/test/fixtures/file-tree/config.json +0 -1
- package/dist/test/fixtures/file-tree/data/items.json +0 -1
- package/dist/test/fixtures/file-tree/docs/api/reference.json +0 -1
- package/dist/test/unit/data/file/bad/bad3.json +0 -3
- package/dist/test/unit/data/file/bad/thing1.json +0 -4
- package/dist/test/unit/data/file/bad/thing2.json +0 -3
- package/dist/test/unit/data/file/good/thing1.json +0 -4
- package/dist/test/unit/data/file/good/thing2.json +0 -3
package/dist/ts-json-base.d.ts
CHANGED
|
@@ -33,6 +33,15 @@ declare type AnyFileTreeDirectoryItem<TCT extends string = string> = IFileTreeDi
|
|
|
33
33
|
*/
|
|
34
34
|
declare type AnyFileTreeFileItem<TCT extends string = string> = IFileTreeFileItem<TCT> | IMutableFileTreeFileItem<TCT>;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Creates a schema node for a JSON `array` whose elements all match `items`.
|
|
38
|
+
* @param items - The schema applied to every element.
|
|
39
|
+
* @param opts - Optional description.
|
|
40
|
+
* @returns An `ISchemaValidator` whose `Static` type is `Array<Static<S>>`.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
declare function array<S extends ISchemaValidator<unknown>>(items: S, opts?: ISchemaOptions): ISchemaValidator<Static<S>[]>;
|
|
44
|
+
|
|
36
45
|
/**
|
|
37
46
|
* A converter which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatible} values.
|
|
38
47
|
* @public
|
|
@@ -72,12 +81,20 @@ declare type ArrayValidator<T, TC = unknown> = Validation.Classes.ArrayValidator
|
|
|
72
81
|
*/
|
|
73
82
|
declare const boolean: Converter<boolean, IJsonConverterContext>;
|
|
74
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Creates a schema node for a JSON `boolean`.
|
|
86
|
+
* @param opts - Optional description.
|
|
87
|
+
* @returns An `ISchemaValidator` whose `Static` type is `boolean`.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
declare function boolean_2(opts?: ISchemaOptions): ISchemaValidator<boolean>;
|
|
91
|
+
|
|
75
92
|
/**
|
|
76
93
|
* A `BooleanValidator` which validates a boolean in place.
|
|
77
94
|
* Accepts `IJsonValidatorContext` but ignores it.
|
|
78
95
|
* @public
|
|
79
96
|
*/
|
|
80
|
-
declare const
|
|
97
|
+
declare const boolean_3: Validator<boolean, IJsonValidatorContext>;
|
|
81
98
|
|
|
82
99
|
/**
|
|
83
100
|
* Identifies whether some `unknown` value is a {@link JsonPrimitive | primitive},
|
|
@@ -105,6 +122,7 @@ declare namespace Converters {
|
|
|
105
122
|
export {
|
|
106
123
|
literal,
|
|
107
124
|
enumeratedValue,
|
|
125
|
+
stringifiedJson,
|
|
108
126
|
jsonConverter,
|
|
109
127
|
IJsonConverterContext,
|
|
110
128
|
jsonPrimitive,
|
|
@@ -289,6 +307,15 @@ declare function enumeratedValue<T>(values: ReadonlyArray<T>, message?: string):
|
|
|
289
307
|
*/
|
|
290
308
|
declare function enumeratedValue_2<T>(values: ReadonlyArray<T>, message?: string): Validator<T, IJsonValidatorContext | ReadonlyArray<T>>;
|
|
291
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Creates a schema node for a closed set of string literals.
|
|
312
|
+
* @param values - The allowed string values.
|
|
313
|
+
* @param opts - Optional description.
|
|
314
|
+
* @returns An `ISchemaValidator` whose `Static` type is the union of `values`.
|
|
315
|
+
* @public
|
|
316
|
+
*/
|
|
317
|
+
declare function enumOf<T extends string>(values: readonly T[], opts?: ISchemaOptions): ISchemaValidator<T>;
|
|
318
|
+
|
|
292
319
|
/**
|
|
293
320
|
* Class representing a file in a file tree.
|
|
294
321
|
* @public
|
|
@@ -345,7 +372,9 @@ declare class FileItem<TCT extends string = string> implements IMutableFileTreeF
|
|
|
345
372
|
*/
|
|
346
373
|
static create<TCT extends string = string>(path: string, hal: IFileTreeAccessors<TCT>): Result<FileItem<TCT>>;
|
|
347
374
|
/**
|
|
348
|
-
*
|
|
375
|
+
* Indicates whether this file can be saved.
|
|
376
|
+
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
377
|
+
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
349
378
|
*/
|
|
350
379
|
getIsMutable(): DetailedResult<boolean, SaveDetail>;
|
|
351
380
|
/**
|
|
@@ -366,15 +395,20 @@ declare class FileItem<TCT extends string = string> implements IMutableFileTreeF
|
|
|
366
395
|
*/
|
|
367
396
|
setContentType(contentType: TCT | undefined): void;
|
|
368
397
|
/**
|
|
369
|
-
*
|
|
398
|
+
* Sets the contents of the file from a JSON value.
|
|
399
|
+
* @param json - The JSON value to serialize and save.
|
|
400
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
370
401
|
*/
|
|
371
402
|
setContents(json: JsonValue): Result<JsonValue>;
|
|
372
403
|
/**
|
|
373
|
-
*
|
|
404
|
+
* Sets the raw contents of the file.
|
|
405
|
+
* @param contents - The string contents to save.
|
|
406
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
374
407
|
*/
|
|
375
408
|
setRawContents(contents: string): Result<string>;
|
|
376
409
|
/**
|
|
377
|
-
*
|
|
410
|
+
* Deletes this file from its backing store.
|
|
411
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
378
412
|
*/
|
|
379
413
|
delete(): Result<boolean>;
|
|
380
414
|
/**
|
|
@@ -516,6 +550,27 @@ declare function forFilesystem<TCT extends string = string>(prefix?: string): Re
|
|
|
516
550
|
*/
|
|
517
551
|
declare function forFilesystem<TCT extends string = string>(params?: IFileTreeInitParams<TCT>): Result<FileTree_2<TCT>>;
|
|
518
552
|
|
|
553
|
+
/**
|
|
554
|
+
* Parses a raw JSON Schema object (e.g. one discovered at an MCP tool boundary) into a typed schema
|
|
555
|
+
* value within the LLM-tool subset.
|
|
556
|
+
*
|
|
557
|
+
* @remarks
|
|
558
|
+
* Because the static type cannot be recovered from a runtime value, the result is typed as the
|
|
559
|
+
* opaque supertype `ISchemaValidator<JsonValue>` — the honest type when a schema arrives at runtime,
|
|
560
|
+
* since schemas may validate strings, numbers, booleans, arrays, or objects. The `validate()` method
|
|
561
|
+
* performs real runtime validation; the derived static type is the opaque `JsonValue`.
|
|
562
|
+
*
|
|
563
|
+
* Consumers who need a narrower derived type must author the schema via the factories.
|
|
564
|
+
*
|
|
565
|
+
* Out-of-subset features fail loudly (see `FORBIDDEN_KEYWORDS`); `description` is preserved on every
|
|
566
|
+
* node; other annotations (`title`, `default`, `format`, `examples`) are silently ignored.
|
|
567
|
+
*
|
|
568
|
+
* @param json - The raw JSON Schema object to parse.
|
|
569
|
+
* @returns `Success` with the parsed schema, or `Failure` describing the first out-of-subset feature.
|
|
570
|
+
* @public
|
|
571
|
+
*/
|
|
572
|
+
declare function fromJson(json: JsonObject): Result<ISchemaValidator<JsonValue>>;
|
|
573
|
+
|
|
519
574
|
/**
|
|
520
575
|
* Implementation of {@link FileTree.IMutableFileTreeAccessors} that uses the
|
|
521
576
|
* file system to access and modify files and directories.
|
|
@@ -542,55 +597,86 @@ declare class FsFileTreeAccessors<TCT extends string = string> implements IMutab
|
|
|
542
597
|
*/
|
|
543
598
|
constructor(params?: IFileTreeInitParams<TCT>);
|
|
544
599
|
/**
|
|
545
|
-
*
|
|
600
|
+
* Resolves paths to an absolute path.
|
|
601
|
+
* @param paths - Paths to resolve.
|
|
602
|
+
* @returns The resolved absolute path.
|
|
546
603
|
*/
|
|
547
604
|
resolveAbsolutePath(...paths: string[]): string;
|
|
548
605
|
/**
|
|
549
|
-
*
|
|
606
|
+
* Gets the extension of a path.
|
|
607
|
+
* @param itemPath - Path to get the extension of.
|
|
608
|
+
* @returns The extension of the path.
|
|
550
609
|
*/
|
|
551
610
|
getExtension(itemPath: string): string;
|
|
552
611
|
/**
|
|
553
|
-
*
|
|
612
|
+
* Gets the base name of a path.
|
|
613
|
+
* @param itemPath - Path to get the base name of.
|
|
614
|
+
* @param suffix - Optional suffix to remove from the base name.
|
|
615
|
+
* @returns The base name of the path.
|
|
554
616
|
*/
|
|
555
617
|
getBaseName(itemPath: string, suffix?: string): string;
|
|
556
618
|
/**
|
|
557
|
-
*
|
|
619
|
+
* Joins paths together.
|
|
620
|
+
* @param paths - Paths to join.
|
|
621
|
+
* @returns The joined paths.
|
|
558
622
|
*/
|
|
559
623
|
joinPaths(...paths: string[]): string;
|
|
560
624
|
/**
|
|
561
|
-
*
|
|
625
|
+
* Gets an item from the file tree.
|
|
626
|
+
* @param itemPath - Path of the item to get.
|
|
627
|
+
* @returns The item if it exists.
|
|
562
628
|
*/
|
|
563
629
|
getItem(itemPath: string): Result<FileTreeItem<TCT>>;
|
|
564
630
|
/**
|
|
565
|
-
*
|
|
631
|
+
* Gets the contents of a file in the file tree.
|
|
632
|
+
* @param filePath - Absolute path of the file.
|
|
633
|
+
* @returns The contents of the file.
|
|
566
634
|
*/
|
|
567
635
|
getFileContents(filePath: string): Result<string>;
|
|
568
636
|
/**
|
|
569
|
-
*
|
|
637
|
+
* Gets the content type of a file in the file tree.
|
|
638
|
+
* @param filePath - Absolute path of the file.
|
|
639
|
+
* @param provided - Optional supplied content type.
|
|
640
|
+
* @returns The content type of the file.
|
|
570
641
|
*/
|
|
571
642
|
getFileContentType(filePath: string, provided?: string): Result<TCT | undefined>;
|
|
572
643
|
/**
|
|
573
|
-
*
|
|
644
|
+
* Gets the children of a directory in the file tree.
|
|
645
|
+
* @param dirPath - Path of the directory.
|
|
646
|
+
* @returns The children of the directory.
|
|
574
647
|
*/
|
|
575
648
|
getChildren(dirPath: string): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
576
649
|
/**
|
|
577
|
-
*
|
|
650
|
+
* Checks if a file at the given path can be saved.
|
|
651
|
+
* @param path - The path to check.
|
|
652
|
+
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
653
|
+
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
578
654
|
*/
|
|
579
655
|
fileIsMutable(path: string): DetailedResult<boolean, SaveDetail>;
|
|
580
656
|
/**
|
|
581
|
-
*
|
|
657
|
+
* Saves the contents to a file at the given path.
|
|
658
|
+
* @param path - The path of the file to save.
|
|
659
|
+
* @param contents - The string contents to save.
|
|
660
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
582
661
|
*/
|
|
583
662
|
saveFileContents(path: string, contents: string): Result<string>;
|
|
584
663
|
/**
|
|
585
|
-
*
|
|
664
|
+
* Deletes a file at the given path.
|
|
665
|
+
* @param path - The path of the file to delete.
|
|
666
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
586
667
|
*/
|
|
587
668
|
deleteFile(path: string): Result<boolean>;
|
|
588
669
|
/**
|
|
589
|
-
*
|
|
670
|
+
* Creates a directory at the given path, including any missing parent directories.
|
|
671
|
+
* @param dirPath - The path of the directory to create.
|
|
672
|
+
* @returns `Success` with the absolute path if created, or `Failure` with an error message.
|
|
590
673
|
*/
|
|
591
674
|
createDirectory(dirPath: string): Result<string>;
|
|
592
675
|
/**
|
|
593
|
-
*
|
|
676
|
+
* Deletes a directory at the given path.
|
|
677
|
+
* The directory must be empty or the operation will fail.
|
|
678
|
+
* @param dirPath - The path of the directory to delete.
|
|
679
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
594
680
|
*/
|
|
595
681
|
deleteDirectory(dirPath: string): Result<boolean>;
|
|
596
682
|
}
|
|
@@ -849,6 +935,67 @@ declare interface IJsonValidatorContext {
|
|
|
849
935
|
ignoreUndefinedProperties?: boolean;
|
|
850
936
|
}
|
|
851
937
|
|
|
938
|
+
/**
|
|
939
|
+
* Schema node for a JSON `array`.
|
|
940
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
941
|
+
* @public
|
|
942
|
+
*/
|
|
943
|
+
declare type ILlmArraySchema<S extends ISchemaValidator<unknown>> = ISchemaValidator<Static<S>[]>;
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Schema node for a JSON `boolean`.
|
|
947
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
948
|
+
* @public
|
|
949
|
+
*/
|
|
950
|
+
declare type ILlmBooleanSchema = ISchemaValidator<boolean>;
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Schema node for a closed set of string literals (`enum`).
|
|
954
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
955
|
+
* @public
|
|
956
|
+
*/
|
|
957
|
+
declare type ILlmEnumSchema<T extends string> = ISchemaValidator<T>;
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Schema node for a JSON `number` or `integer`.
|
|
961
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
962
|
+
* @public
|
|
963
|
+
*/
|
|
964
|
+
declare type ILlmNumberSchema = ISchemaValidator<number>;
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* Schema node for a JSON `object`.
|
|
968
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
969
|
+
* @public
|
|
970
|
+
*/
|
|
971
|
+
declare type ILlmObjectSchema<P extends ILlmProperties> = ISchemaValidator<ObjectStatic<P>>;
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Wrapper marking a property as optional within an object schema.
|
|
975
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
976
|
+
* @public
|
|
977
|
+
*/
|
|
978
|
+
declare type ILlmOptional<S extends ISchemaValidator<unknown>> = ISchemaValidator<Static<S> | undefined>;
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* A record of property schemas, as accepted by the `object` factory.
|
|
982
|
+
* @public
|
|
983
|
+
*/
|
|
984
|
+
declare type ILlmProperties = Record<string, ISchemaValidator<unknown>>;
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
988
|
+
* @public
|
|
989
|
+
*/
|
|
990
|
+
declare type ILlmSchema<T> = ISchemaValidator<T>;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Schema node for a JSON `string`.
|
|
994
|
+
* @deprecated Use `ISchemaValidator` instead.
|
|
995
|
+
* @public
|
|
996
|
+
*/
|
|
997
|
+
declare type ILlmStringSchema = ISchemaValidator<string>;
|
|
998
|
+
|
|
852
999
|
/**
|
|
853
1000
|
* Extended accessors interface that supports mutation operations.
|
|
854
1001
|
* All mutation methods are required — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
@@ -1011,60 +1158,124 @@ declare class InMemoryTreeAccessors<TCT extends string = string> implements IMut
|
|
|
1011
1158
|
*/
|
|
1012
1159
|
static create<TCT extends string = string>(files: IInMemoryFile<TCT>[], params?: IFileTreeInitParams<TCT>): Result<InMemoryTreeAccessors<TCT>>;
|
|
1013
1160
|
/**
|
|
1014
|
-
*
|
|
1161
|
+
* Resolves paths to an absolute path.
|
|
1162
|
+
* @param paths - Paths to resolve.
|
|
1163
|
+
* @returns The resolved absolute path.
|
|
1015
1164
|
*/
|
|
1016
1165
|
resolveAbsolutePath(...paths: string[]): string;
|
|
1017
1166
|
/**
|
|
1018
|
-
*
|
|
1167
|
+
* Gets the extension of a path.
|
|
1168
|
+
* @param path - Path to get the extension of.
|
|
1169
|
+
* @returns The extension of the path.
|
|
1019
1170
|
*/
|
|
1020
1171
|
getExtension(path: string): string;
|
|
1021
1172
|
/**
|
|
1022
|
-
*
|
|
1173
|
+
* Gets the base name of a path.
|
|
1174
|
+
* @param path - Path to get the base name of.
|
|
1175
|
+
* @param suffix - Optional suffix to remove from the base name.
|
|
1176
|
+
* @returns The base name of the path.
|
|
1023
1177
|
*/
|
|
1024
1178
|
getBaseName(path: string, suffix?: string): string;
|
|
1025
1179
|
/**
|
|
1026
|
-
*
|
|
1180
|
+
* Joins paths together.
|
|
1181
|
+
* @param paths - Paths to join.
|
|
1182
|
+
* @returns The joined paths.
|
|
1027
1183
|
*/
|
|
1028
1184
|
joinPaths(...paths: string[]): string;
|
|
1029
1185
|
/**
|
|
1030
|
-
*
|
|
1186
|
+
* Gets an item from the file tree.
|
|
1187
|
+
* @param itemPath - Path of the item to get.
|
|
1188
|
+
* @returns The item if it exists.
|
|
1031
1189
|
*/
|
|
1032
1190
|
getItem(itemPath: string): Result<FileTreeItem<TCT>>;
|
|
1033
1191
|
/**
|
|
1034
|
-
*
|
|
1192
|
+
* Gets the contents of a file in the file tree.
|
|
1193
|
+
* @param path - Absolute path of the file.
|
|
1194
|
+
* @returns The contents of the file.
|
|
1035
1195
|
*/
|
|
1036
1196
|
getFileContents(path: string): Result<string>;
|
|
1037
1197
|
/**
|
|
1038
|
-
*
|
|
1198
|
+
* Gets the content type of a file in the file tree.
|
|
1199
|
+
* @param path - Absolute path of the file.
|
|
1200
|
+
* @param provided - Optional supplied content type.
|
|
1201
|
+
* @returns The content type of the file.
|
|
1039
1202
|
*/
|
|
1040
1203
|
getFileContentType(path: string, provided?: string): Result<TCT | undefined>;
|
|
1041
1204
|
/**
|
|
1042
|
-
*
|
|
1205
|
+
* Gets the children of a directory in the file tree.
|
|
1206
|
+
* @param path - Path of the directory.
|
|
1207
|
+
* @returns The children of the directory.
|
|
1043
1208
|
*/
|
|
1044
1209
|
getChildren(path: string): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
1045
1210
|
private _addMutableFile;
|
|
1046
1211
|
/**
|
|
1047
|
-
*
|
|
1212
|
+
* Creates a directory at the given path, including any missing parent directories.
|
|
1213
|
+
* @param dirPath - The path of the directory to create.
|
|
1214
|
+
* @returns `Success` with the absolute path if created, or `Failure` with an error message.
|
|
1048
1215
|
*/
|
|
1049
1216
|
createDirectory(dirPath: string): Result<string>;
|
|
1050
1217
|
/**
|
|
1051
|
-
*
|
|
1218
|
+
* Checks if a file at the given path can be saved.
|
|
1219
|
+
* @param path - The path to check.
|
|
1220
|
+
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
1221
|
+
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
1052
1222
|
*/
|
|
1053
1223
|
fileIsMutable(path: string): DetailedResult<boolean, SaveDetail>;
|
|
1054
1224
|
/**
|
|
1055
|
-
*
|
|
1225
|
+
* Deletes a file at the given path.
|
|
1226
|
+
* @param path - The path of the file to delete.
|
|
1227
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
1056
1228
|
*/
|
|
1057
1229
|
deleteFile(path: string): Result<boolean>;
|
|
1058
1230
|
/**
|
|
1059
|
-
*
|
|
1231
|
+
* Deletes a directory at the given path.
|
|
1232
|
+
* The directory must be empty or the operation will fail.
|
|
1233
|
+
* @param path - The path of the directory to delete.
|
|
1234
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
1060
1235
|
*/
|
|
1061
1236
|
deleteDirectory(path: string): Result<boolean>;
|
|
1062
1237
|
/**
|
|
1063
|
-
*
|
|
1238
|
+
* Saves the contents to a file at the given path.
|
|
1239
|
+
* @param path - The path of the file to save.
|
|
1240
|
+
* @param contents - The string contents to save.
|
|
1241
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
1064
1242
|
*/
|
|
1065
1243
|
saveFileContents(path: string, contents: string): Result<string>;
|
|
1066
1244
|
}
|
|
1067
1245
|
|
|
1246
|
+
/**
|
|
1247
|
+
* Creates a schema node for a JSON `integer`.
|
|
1248
|
+
* @param opts - Optional description and strict mode (see `INumberSchemaOptions`).
|
|
1249
|
+
* @returns An `ISchemaValidator` (tagged `integer`) whose `Static` type is `number`.
|
|
1250
|
+
* @public
|
|
1251
|
+
*/
|
|
1252
|
+
declare function integer(opts?: INumberSchemaOptions): ISchemaValidator<number>;
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Options for the `number` and `integer` factories.
|
|
1256
|
+
* @public
|
|
1257
|
+
*/
|
|
1258
|
+
declare interface INumberSchemaOptions extends ISchemaOptions {
|
|
1259
|
+
/**
|
|
1260
|
+
* When `true` (default), the derived validator rejects numeric strings such as `'42'` and
|
|
1261
|
+
* accepts only genuine JSON numbers. Set `false` to opt into permissive coercion (numeric
|
|
1262
|
+
* strings are accepted and converted to their numeric value).
|
|
1263
|
+
*/
|
|
1264
|
+
strict?: boolean;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* Options for the `object` factory.
|
|
1269
|
+
* @public
|
|
1270
|
+
*/
|
|
1271
|
+
declare interface IObjectSchemaOptions extends ISchemaOptions {
|
|
1272
|
+
/**
|
|
1273
|
+
* When `false` (default), the validator rejects unrecognized properties and the emitted schema
|
|
1274
|
+
* sets `additionalProperties: false`. Set `true` to allow extra fields.
|
|
1275
|
+
*/
|
|
1276
|
+
additionalProperties?: boolean;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1068
1279
|
/**
|
|
1069
1280
|
* Extended accessors interface that supports persistence operations.
|
|
1070
1281
|
* @public
|
|
@@ -1102,6 +1313,55 @@ declare interface IReadDirectoryItem<T> {
|
|
|
1102
1313
|
item: T;
|
|
1103
1314
|
}
|
|
1104
1315
|
|
|
1316
|
+
/**
|
|
1317
|
+
* Common options accepted by every schema factory.
|
|
1318
|
+
* @public
|
|
1319
|
+
*/
|
|
1320
|
+
declare interface ISchemaOptions {
|
|
1321
|
+
/**
|
|
1322
|
+
* Optional human-readable description emitted into the wire JSON Schema.
|
|
1323
|
+
*/
|
|
1324
|
+
description?: string;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* A typed JSON Schema node for the LLM-tool subset. Every value returned by the
|
|
1329
|
+
* schema factories implements this interface — it IS a `Validator<T>` and also
|
|
1330
|
+
* carries a `toJson()` method for wire-format emission.
|
|
1331
|
+
*
|
|
1332
|
+
* @remarks
|
|
1333
|
+
* The `__staticType` property is a phantom: it exists only in the type system to carry
|
|
1334
|
+
* the derived static type `T` and is never assigned at runtime (declared optional so
|
|
1335
|
+
* factory return values need not populate it). `Static<S>` reads this slot to recover
|
|
1336
|
+
* `T` from a schema value without requiring a user-supplied type assertion. A plain
|
|
1337
|
+
* optional property is used rather than a module-private `unique symbol` because this is
|
|
1338
|
+
* a published package surface — a private-symbol-keyed property cannot be named in the
|
|
1339
|
+
* emitted `.d.ts` (TypeBox issue #679), which would break declaration emission and API
|
|
1340
|
+
* Extractor for downstream consumers.
|
|
1341
|
+
*
|
|
1342
|
+
* Consumers call `schema.validate(input)` directly; no separate adapter step is required.
|
|
1343
|
+
* @public
|
|
1344
|
+
*/
|
|
1345
|
+
declare interface ISchemaValidator<T> extends Validator<T> {
|
|
1346
|
+
/**
|
|
1347
|
+
* Phantom type carrier — type-level only, never present at runtime.
|
|
1348
|
+
*/
|
|
1349
|
+
readonly __staticType?: T;
|
|
1350
|
+
/**
|
|
1351
|
+
* Runtime discriminant. Identifies the schema node kind.
|
|
1352
|
+
*/
|
|
1353
|
+
readonly _type: SchemaNodeType;
|
|
1354
|
+
/**
|
|
1355
|
+
* Optional human-readable description emitted into the wire JSON Schema.
|
|
1356
|
+
*/
|
|
1357
|
+
readonly description?: string;
|
|
1358
|
+
/**
|
|
1359
|
+
* Emits the standard JSON Schema (draft-07 LLM-tool subset) wire form for this schema.
|
|
1360
|
+
* @returns The JSON Schema object describing this schema node.
|
|
1361
|
+
*/
|
|
1362
|
+
toJson(): JsonObject;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1105
1365
|
/**
|
|
1106
1366
|
* Test if an `unknown` is potentially a {@link JsonArray | JsonArray}.
|
|
1107
1367
|
* @param from - The `unknown` to be tested.
|
|
@@ -1455,6 +1715,64 @@ declare type JsonReplacerFunction = (key: string, value: JsonValue) => JsonValue
|
|
|
1455
1715
|
*/
|
|
1456
1716
|
declare type JsonReviver = (key: string, value: JsonValue) => JsonValue;
|
|
1457
1717
|
|
|
1718
|
+
declare namespace JsonSchema {
|
|
1719
|
+
export {
|
|
1720
|
+
SchemaNodeType,
|
|
1721
|
+
ISchemaValidator,
|
|
1722
|
+
Static,
|
|
1723
|
+
ILlmProperties,
|
|
1724
|
+
OptionalKeys,
|
|
1725
|
+
RequiredKeys,
|
|
1726
|
+
OptionalPropertyStatic,
|
|
1727
|
+
Simplify,
|
|
1728
|
+
ObjectStatic,
|
|
1729
|
+
ILlmSchema,
|
|
1730
|
+
ILlmStringSchema,
|
|
1731
|
+
ILlmNumberSchema,
|
|
1732
|
+
ILlmBooleanSchema,
|
|
1733
|
+
ILlmEnumSchema,
|
|
1734
|
+
ILlmOptional,
|
|
1735
|
+
ILlmArraySchema,
|
|
1736
|
+
ILlmObjectSchema,
|
|
1737
|
+
string_2 as string,
|
|
1738
|
+
number_2 as number,
|
|
1739
|
+
integer,
|
|
1740
|
+
boolean_2 as boolean,
|
|
1741
|
+
enumOf,
|
|
1742
|
+
optional,
|
|
1743
|
+
array,
|
|
1744
|
+
object_3 as object,
|
|
1745
|
+
ISchemaOptions,
|
|
1746
|
+
INumberSchemaOptions,
|
|
1747
|
+
IObjectSchemaOptions,
|
|
1748
|
+
fromJson,
|
|
1749
|
+
jsonSchemaConverter
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
export { JsonSchema }
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* The main converter. Parses a raw JSON Schema object into a typed schema validator
|
|
1756
|
+
* for the LLM-tool subset.
|
|
1757
|
+
*
|
|
1758
|
+
* @remarks
|
|
1759
|
+
* Performs pre-flight checks (non-object root, union type arrays, forbidden keywords,
|
|
1760
|
+
* unknown types) before dispatching to the per-type arm converters.
|
|
1761
|
+
*
|
|
1762
|
+
* The conversion context (`TC = string`) carries the current JSON Pointer path so that
|
|
1763
|
+
* error messages from nested nodes name the actual failing node (e.g.
|
|
1764
|
+
* `#/properties/config/properties/inner: 'required' key '...'`) rather than always
|
|
1765
|
+
* reporting `#:`. The context defaults to `'#'` when absent (top-level call).
|
|
1766
|
+
*
|
|
1767
|
+
* Array and object arms reference `jsonSchemaConverter` by name from inside function
|
|
1768
|
+
* declarations (hoisted). By the time any arm is called at runtime, `jsonSchemaConverter`
|
|
1769
|
+
* is fully initialized, so recursive sub-schema calls also go through the pre-flight checks
|
|
1770
|
+
* and produce meaningful error messages.
|
|
1771
|
+
*
|
|
1772
|
+
* @public
|
|
1773
|
+
*/
|
|
1774
|
+
declare const jsonSchemaConverter: Converter<ISchemaValidator<JsonValue>, string>;
|
|
1775
|
+
|
|
1458
1776
|
/**
|
|
1459
1777
|
* Helper class to work with JSON files using FileTree API (web-compatible).
|
|
1460
1778
|
* @public
|
|
@@ -1572,12 +1890,20 @@ declare type MutableFileTreeItem<TCT extends string = string> = IMutableFileTree
|
|
|
1572
1890
|
*/
|
|
1573
1891
|
declare const number: Converter<number, IJsonConverterContext>;
|
|
1574
1892
|
|
|
1893
|
+
/**
|
|
1894
|
+
* Creates a schema node for a JSON `number`.
|
|
1895
|
+
* @param opts - Optional description and strict mode (see `INumberSchemaOptions`).
|
|
1896
|
+
* @returns An `ISchemaValidator` whose `Static` type is `number`.
|
|
1897
|
+
* @public
|
|
1898
|
+
*/
|
|
1899
|
+
declare function number_2(opts?: INumberSchemaOptions): ISchemaValidator<number>;
|
|
1900
|
+
|
|
1575
1901
|
/**
|
|
1576
1902
|
* A `NumberValidator` which validates a number in place.
|
|
1577
1903
|
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
1578
1904
|
* @public
|
|
1579
1905
|
*/
|
|
1580
|
-
declare const
|
|
1906
|
+
declare const number_3: Validation.Classes.NumberValidator<number, IJsonValidatorContext>;
|
|
1581
1907
|
|
|
1582
1908
|
/**
|
|
1583
1909
|
* A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
|
|
@@ -1599,18 +1925,62 @@ declare function object<T, TC = unknown>(properties: Conversion.FieldConverters<
|
|
|
1599
1925
|
*/
|
|
1600
1926
|
declare function object_2<T, TC = unknown>(properties: Validation.Classes.FieldValidators<JsonCompatibleType<T>, TC>, params?: Omit<Validation.Classes.ObjectValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'fields'>): JsonCompatible_2.ObjectValidator<T, TC>;
|
|
1601
1927
|
|
|
1928
|
+
/**
|
|
1929
|
+
* Creates a schema node for a JSON `object` with a fixed set of typed properties.
|
|
1930
|
+
* @param properties - A record mapping property names to their schemas. Wrap a property with
|
|
1931
|
+
* `optional` to make it optional.
|
|
1932
|
+
* @param opts - Optional description and `additionalProperties` flag.
|
|
1933
|
+
* @returns An `ISchemaValidator` whose `Static` type derives the required/optional split.
|
|
1934
|
+
* @public
|
|
1935
|
+
*/
|
|
1936
|
+
declare function object_3<P extends ILlmProperties>(properties: P, opts?: IObjectSchemaOptions): ISchemaValidator<ObjectStatic<P>>;
|
|
1937
|
+
|
|
1602
1938
|
/**
|
|
1603
1939
|
* A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
1604
1940
|
* @public
|
|
1605
1941
|
*/
|
|
1606
1942
|
declare type ObjectConverter<T, TC = unknown> = ObjectConverter_2<JsonCompatibleType<T>, TC>;
|
|
1607
1943
|
|
|
1944
|
+
/**
|
|
1945
|
+
* The derived static type for an object built from properties `P`: required keys carry their
|
|
1946
|
+
* static type directly, optional keys carry theirs under a `?` modifier.
|
|
1947
|
+
* @public
|
|
1948
|
+
*/
|
|
1949
|
+
declare type ObjectStatic<P extends ILlmProperties> = Simplify<{
|
|
1950
|
+
[K in RequiredKeys<P>]: Static<P[K]>;
|
|
1951
|
+
} & {
|
|
1952
|
+
[K in OptionalKeys<P>]?: OptionalPropertyStatic<P[K]>;
|
|
1953
|
+
}>;
|
|
1954
|
+
|
|
1608
1955
|
/**
|
|
1609
1956
|
* A validator which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
1610
1957
|
* @public
|
|
1611
1958
|
*/
|
|
1612
1959
|
declare type ObjectValidator<T, TC = unknown> = Validation.Classes.ObjectValidator<JsonCompatibleType<T>, TC>;
|
|
1613
1960
|
|
|
1961
|
+
/**
|
|
1962
|
+
* Marks a property schema as optional within an `object` schema.
|
|
1963
|
+
* @param schema - The inner schema to make optional.
|
|
1964
|
+
* @returns An `ISchemaValidator` whose `Static` type is `Static<S> | undefined`.
|
|
1965
|
+
* @public
|
|
1966
|
+
*/
|
|
1967
|
+
declare function optional<S extends ISchemaValidator<unknown>>(schema: S): ISchemaValidator<Static<S> | undefined>;
|
|
1968
|
+
|
|
1969
|
+
/**
|
|
1970
|
+
* The keys of `P` whose schemas are optional (wrapped with the `optional` modifier).
|
|
1971
|
+
* @public
|
|
1972
|
+
*/
|
|
1973
|
+
declare type OptionalKeys<P extends ILlmProperties> = {
|
|
1974
|
+
[K in keyof P]: P[K] extends ISchemaValidator<infer U> ? (undefined extends U ? K : never) : never;
|
|
1975
|
+
}[keyof P];
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* The static value type carried by an optional property (the inner schema's static type,
|
|
1979
|
+
* without the `| undefined` that optionality adds — the `?` modifier conveys that separately).
|
|
1980
|
+
* @public
|
|
1981
|
+
*/
|
|
1982
|
+
declare type OptionalPropertyStatic<V> = V extends ISchemaValidator<infer U> ? Exclude<U, undefined> : never;
|
|
1983
|
+
|
|
1614
1984
|
/**
|
|
1615
1985
|
* Picks a nested {@link JsonObject | JsonObject} from a supplied
|
|
1616
1986
|
* {@link JsonObject | JsonObject}.
|
|
@@ -1679,6 +2049,12 @@ declare function recordOf_2<T, TC = unknown, TK extends string = string>(validat
|
|
|
1679
2049
|
*/
|
|
1680
2050
|
declare type RecordValidator<T, TC = unknown, TK extends string = string> = Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>;
|
|
1681
2051
|
|
|
2052
|
+
/**
|
|
2053
|
+
* The keys of `P` whose schemas are required (i.e. not optional).
|
|
2054
|
+
* @public
|
|
2055
|
+
*/
|
|
2056
|
+
declare type RequiredKeys<P extends ILlmProperties> = Exclude<keyof P, OptionalKeys<P>>;
|
|
2057
|
+
|
|
1682
2058
|
/**
|
|
1683
2059
|
* "Sanitizes" an `unknown` by stringifying and then parsing it. Guarantees a
|
|
1684
2060
|
* valid {@link JsonValue | JsonValue} but is not idempotent and gives no guarantees
|
|
@@ -1725,6 +2101,31 @@ declare type SaveDetail = SaveCapability | SaveFailureReason;
|
|
|
1725
2101
|
*/
|
|
1726
2102
|
declare type SaveFailureReason = 'not-supported' | 'read-only' | 'not-mutable' | 'path-excluded' | 'permission-denied';
|
|
1727
2103
|
|
|
2104
|
+
/**
|
|
2105
|
+
* Discriminant tag carried by every schema node.
|
|
2106
|
+
* @public
|
|
2107
|
+
*/
|
|
2108
|
+
declare type SchemaNodeType = 'string' | 'number' | 'integer' | 'boolean' | 'enum' | 'optional' | 'array' | 'object';
|
|
2109
|
+
|
|
2110
|
+
/**
|
|
2111
|
+
* Flattens an intersection of object types into a single object type for readable derived types.
|
|
2112
|
+
* @public
|
|
2113
|
+
*/
|
|
2114
|
+
declare type Simplify<T> = {
|
|
2115
|
+
[K in keyof T]: T[K];
|
|
2116
|
+
} & {};
|
|
2117
|
+
|
|
2118
|
+
/**
|
|
2119
|
+
* Recover the derived static type `T` from a schema value.
|
|
2120
|
+
*
|
|
2121
|
+
* @remarks
|
|
2122
|
+
* `Static<typeof MySchema>` resolves to the TypeScript type that `schema.validate()` produces
|
|
2123
|
+
* and that `schema.toJson()` describes — derived, never asserted. No user-supplied `T` is ever
|
|
2124
|
+
* required.
|
|
2125
|
+
* @public
|
|
2126
|
+
*/
|
|
2127
|
+
declare type Static<S extends ISchemaValidator<unknown>> = S extends ISchemaValidator<infer T> ? T : never;
|
|
2128
|
+
|
|
1728
2129
|
/**
|
|
1729
2130
|
* A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a
|
|
1730
2131
|
* supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.
|
|
@@ -1743,12 +2144,48 @@ declare function strictObject<T, TC = unknown>(properties: Conversion.FieldConve
|
|
|
1743
2144
|
*/
|
|
1744
2145
|
declare const string: StringConverter<string, IJsonConverterContext>;
|
|
1745
2146
|
|
|
2147
|
+
/**
|
|
2148
|
+
* Creates a schema node for a JSON `string`.
|
|
2149
|
+
* @param opts - Optional description.
|
|
2150
|
+
* @returns An `ISchemaValidator` whose `Static` type is `string`.
|
|
2151
|
+
* @public
|
|
2152
|
+
*/
|
|
2153
|
+
declare function string_2(opts?: ISchemaOptions): ISchemaValidator<string>;
|
|
2154
|
+
|
|
1746
2155
|
/**
|
|
1747
2156
|
* A `StringValidator` which validates a string in place.
|
|
1748
2157
|
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
1749
2158
|
* @public
|
|
1750
2159
|
*/
|
|
1751
|
-
declare const
|
|
2160
|
+
declare const string_3: Validation.Classes.StringValidator<string, IJsonValidatorContext>;
|
|
2161
|
+
|
|
2162
|
+
/**
|
|
2163
|
+
* Creates a converter that accepts a string, parses it as JSON, and optionally
|
|
2164
|
+
* applies the supplied inner converter or validator to the parsed value.
|
|
2165
|
+
*
|
|
2166
|
+
* @remarks
|
|
2167
|
+
* Unlike {@link Converters.jsonConverter}, the inner step is optional. When omitted, the
|
|
2168
|
+
* converter resolves to the parsed `JsonValue` (object, array, or primitive).
|
|
2169
|
+
* Both `Converter<T>` and `Validator<T>` are accepted because both expose
|
|
2170
|
+
* `convert(unknown): Result<T>`.
|
|
2171
|
+
*
|
|
2172
|
+
* @param inner - Optional `Converter<T>` or `Validator<T>` applied to the
|
|
2173
|
+
* parsed JSON value.
|
|
2174
|
+
* @returns Converter that parses a JSON string into `T` (or `JsonValue` when
|
|
2175
|
+
* no inner step is supplied).
|
|
2176
|
+
* @public
|
|
2177
|
+
*/
|
|
2178
|
+
declare function stringifiedJson(): Converter<JsonValue>;
|
|
2179
|
+
|
|
2180
|
+
/**
|
|
2181
|
+
* Creates a converter that accepts a string, parses it as JSON, and applies
|
|
2182
|
+
* the supplied inner converter or validator to the parsed value.
|
|
2183
|
+
*
|
|
2184
|
+
* @param inner - `Converter<T>` or `Validator<T>` applied to the parsed JSON.
|
|
2185
|
+
* @returns Converter that parses a JSON string into `T`.
|
|
2186
|
+
* @public
|
|
2187
|
+
*/
|
|
2188
|
+
declare function stringifiedJson<T>(inner: Converter<T> | Validator<T>): Converter<T>;
|
|
1752
2189
|
|
|
1753
2190
|
/**
|
|
1754
2191
|
* A validator which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.
|
|
@@ -1765,9 +2202,9 @@ declare namespace Validators {
|
|
|
1765
2202
|
jsonObject_2 as jsonObject,
|
|
1766
2203
|
jsonArray_2 as jsonArray,
|
|
1767
2204
|
jsonValue_2 as jsonValue,
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2205
|
+
string_3 as string,
|
|
2206
|
+
number_3 as number,
|
|
2207
|
+
boolean_3 as boolean
|
|
1771
2208
|
}
|
|
1772
2209
|
}
|
|
1773
2210
|
export { Validators }
|