@fgv/ts-utils 4.6.0 → 5.0.0-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.json +21 -0
  2. package/CHANGELOG.md +11 -1
  3. package/dist/ts-utils.d.ts +3159 -2567
  4. package/lib/index.d.ts +2 -1
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +3 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/packlets/base/mapResults.js +1 -1
  9. package/lib/packlets/base/mapResults.js.map +1 -1
  10. package/lib/packlets/base/result.d.ts +123 -24
  11. package/lib/packlets/base/result.d.ts.map +1 -1
  12. package/lib/packlets/base/result.js +145 -30
  13. package/lib/packlets/base/result.js.map +1 -1
  14. package/lib/packlets/collections/collectible.d.ts.map +1 -1
  15. package/lib/packlets/collections/collectible.js +2 -0
  16. package/lib/packlets/collections/collectible.js.map +1 -1
  17. package/lib/packlets/conversion/converters.d.ts +2 -2
  18. package/lib/packlets/conversion/converters.d.ts.map +1 -1
  19. package/lib/packlets/conversion/converters.js.map +1 -1
  20. package/lib/packlets/conversion/objectConverter.d.ts +40 -2
  21. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
  22. package/lib/packlets/conversion/objectConverter.js +81 -45
  23. package/lib/packlets/conversion/objectConverter.js.map +1 -1
  24. package/lib/packlets/file-tree/directoryItem.d.ts +47 -0
  25. package/lib/packlets/file-tree/directoryItem.d.ts.map +1 -0
  26. package/lib/packlets/file-tree/directoryItem.js +71 -0
  27. package/lib/packlets/file-tree/directoryItem.js.map +1 -0
  28. package/lib/packlets/file-tree/fileItem.d.ts +64 -0
  29. package/lib/packlets/file-tree/fileItem.d.ts.map +1 -0
  30. package/lib/packlets/file-tree/fileItem.js +93 -0
  31. package/lib/packlets/file-tree/fileItem.js.map +1 -0
  32. package/lib/packlets/file-tree/fileTree.d.ts +84 -0
  33. package/lib/packlets/file-tree/fileTree.d.ts.map +1 -0
  34. package/lib/packlets/file-tree/fileTree.js +135 -0
  35. package/lib/packlets/file-tree/fileTree.js.map +1 -0
  36. package/lib/packlets/file-tree/fileTreeAccessors.d.ts +134 -0
  37. package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +1 -0
  38. package/lib/packlets/file-tree/fileTreeAccessors.js +24 -0
  39. package/lib/packlets/file-tree/fileTreeAccessors.js.map +1 -0
  40. package/lib/packlets/file-tree/fsTree.d.ts +45 -0
  41. package/lib/packlets/file-tree/fsTree.d.ts.map +1 -0
  42. package/lib/packlets/file-tree/fsTree.js +116 -0
  43. package/lib/packlets/file-tree/fsTree.js.map +1 -0
  44. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +67 -0
  45. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +1 -0
  46. package/lib/packlets/file-tree/in-memory/inMemoryTree.js +150 -0
  47. package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
  48. package/lib/packlets/file-tree/in-memory/index.d.ts +2 -0
  49. package/lib/packlets/file-tree/in-memory/index.d.ts.map +1 -0
  50. package/lib/packlets/file-tree/in-memory/index.js +39 -0
  51. package/lib/packlets/file-tree/in-memory/index.js.map +1 -0
  52. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +106 -0
  53. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +1 -0
  54. package/lib/packlets/file-tree/in-memory/treeBuilder.js +170 -0
  55. package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
  56. package/lib/packlets/file-tree/index.d.ts +8 -0
  57. package/lib/packlets/file-tree/index.d.ts.map +1 -0
  58. package/lib/packlets/file-tree/index.js +46 -0
  59. package/lib/packlets/file-tree/index.js.map +1 -0
  60. package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -1
  61. package/lib/packlets/hash/crcNormalizer.js +3 -1
  62. package/lib/packlets/hash/crcNormalizer.js.map +1 -1
  63. package/lib/packlets/validation/validators.d.ts +1 -1
  64. package/lib/packlets/validation/validators.d.ts.map +1 -1
  65. package/lib/packlets/validation/validators.js +1 -0
  66. package/lib/packlets/validation/validators.js.map +1 -1
  67. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/packlets/file-tree/in-memory/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,iDAA+B","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './inMemoryTree';\n"]}
@@ -0,0 +1,106 @@
1
+ import { Result } from '../../base';
2
+ /**
3
+ * Represents a file in an in-memory file tree.
4
+ * @public
5
+ */
6
+ export declare class InMemoryFile {
7
+ /**
8
+ * The absolute path of the file.
9
+ */
10
+ readonly absolutePath: string;
11
+ /**
12
+ * The contents of the file.
13
+ */
14
+ readonly contents: unknown;
15
+ /**
16
+ * Creates a new {@link InMemoryFile | InMemoryFile} instance.
17
+ * @param absolutePath - The absolute path of the file.
18
+ * @param contents - The contents of the file.
19
+ */
20
+ constructor(absolutePath: string, contents: unknown);
21
+ }
22
+ /**
23
+ * Represents a directory in an in-memory file tree.
24
+ * @public
25
+ */
26
+ export declare class InMemoryDirectory {
27
+ /**
28
+ * The absolute path of the directory.
29
+ */
30
+ readonly absolutePath: string;
31
+ protected _children: Map<string, InMemoryDirectory | InMemoryFile>;
32
+ /**
33
+ * The children of the directory.
34
+ */
35
+ get children(): ReadonlyMap<string, InMemoryDirectory | InMemoryFile>;
36
+ /**
37
+ * Creates an empty new {@link InMemoryDirectory | InMemoryDirectory} instance.
38
+ * @param absolutePath - The absolute path of the directory.
39
+ */
40
+ constructor(absolutePath: string);
41
+ /**
42
+ * Gets or adds a child directory with the specified name.
43
+ * @param name - The name of the child directory.
44
+ * @returns {@link Success | Success} with the child directory if successful, or
45
+ * {@link Failure | Failure} with an error message otherwise.
46
+ */
47
+ getOrAddDirectory(name: string): Result<InMemoryDirectory>;
48
+ /**
49
+ * Adds a file to the directory.
50
+ * @param name - The name of the file.
51
+ * @param contents - The contents of the file.
52
+ * @returns {@link Success | Success} with the new file if successful, or
53
+ * {@link Failure | Failure} with an error message otherwise.
54
+ */
55
+ addFile(name: string, contents: unknown): Result<InMemoryFile>;
56
+ /**
57
+ * Gets the absolute path for a child of this directory with the supplied
58
+ * name.
59
+ * @param name - The name of the child.
60
+ * @returns {@link Success | Success} with the absolute path if successful, or
61
+ * {@link Failure | Failure} with an error message otherwise.
62
+ */
63
+ getChildPath(name: string): string;
64
+ }
65
+ /**
66
+ * Helper class to build an in-memory file tree.
67
+ * @public
68
+ */
69
+ export declare class TreeBuilder {
70
+ /**
71
+ * The prefix for all paths in the tree.
72
+ */
73
+ readonly prefix: string;
74
+ /**
75
+ * The root directory of the tree.
76
+ */
77
+ readonly root: InMemoryDirectory;
78
+ /**
79
+ * A map of all directories and files in the tree by absolute path.
80
+ */
81
+ readonly byAbsolutePath: Map<string, InMemoryDirectory | InMemoryFile>;
82
+ /**
83
+ * Protected constructor for derived classes.
84
+ * @param prefix - The prefix for all paths in the tree.
85
+ * @public
86
+ */
87
+ protected constructor(prefix?: string);
88
+ /**
89
+ * Creates a new {@link TreeBuilder | TreeBuilder} instance.
90
+ * @param prefix - The prefix for all paths in the tree.
91
+ * @returns {@link Success | Success} with the new {@link TreeBuilder | TreeBuilder} instance if successful,
92
+ * or {@link Failure | Failure} with an error message otherwise.
93
+ * @public
94
+ */
95
+ static create(prefix?: string): Result<TreeBuilder>;
96
+ /**
97
+ * Adds a file to the tree.
98
+ * @param absolutePath - The absolute path of the file.
99
+ * @param contents - The contents of the file.
100
+ * @returns {@link Success | Success} with the new file if successful, or
101
+ * {@link Failure | Failure} with an error message otherwise.
102
+ * @public
103
+ */
104
+ addFile(absolutePath: string, contents: unknown): Result<InMemoryFile>;
105
+ }
106
+ //# sourceMappingURL=treeBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeBuilder.d.ts","sourceRoot":"","sources":["../../../../src/packlets/file-tree/in-memory/treeBuilder.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAgC,MAAM,YAAY,CAAC;AAElE;;;GAGG;AACH,qBAAa,YAAY;IACvB;;OAEG;IACH,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC;;OAEG;IACH,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAElC;;;;OAIG;gBACgB,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO;CAI3D;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B;;OAEG;IACH,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,YAAY,CAAC,CAAC;IAEnE;;OAEG;IACH,IAAW,QAAQ,IAAI,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,YAAY,CAAC,CAE3E;IAED;;;OAGG;gBACgB,YAAY,EAAE,MAAM;IAKvC;;;;;OAKG;IACI,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAajE;;;;;;OAMG;IACI,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC;IASrE;;;;;;OAMG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAM1C;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,SAAgB,IAAI,EAAE,iBAAiB,CAAC;IAExC;;OAEG;IACH,SAAgB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,YAAY,CAAC,CAAC;IAE9E;;;;OAIG;IACH,SAAS,aAAa,MAAM,CAAC,EAAE,MAAM;IAUrC;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC;IAI1D;;;;;;;OAOG;IACI,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC;CAsB9E"}
@@ -0,0 +1,170 @@
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.TreeBuilder = exports.InMemoryDirectory = exports.InMemoryFile = void 0;
25
+ const base_1 = require("../../base");
26
+ /**
27
+ * Represents a file in an in-memory file tree.
28
+ * @public
29
+ */
30
+ class InMemoryFile {
31
+ /**
32
+ * Creates a new {@link InMemoryFile | InMemoryFile} instance.
33
+ * @param absolutePath - The absolute path of the file.
34
+ * @param contents - The contents of the file.
35
+ */
36
+ constructor(absolutePath, contents) {
37
+ this.absolutePath = absolutePath;
38
+ this.contents = contents;
39
+ }
40
+ }
41
+ exports.InMemoryFile = InMemoryFile;
42
+ /**
43
+ * Represents a directory in an in-memory file tree.
44
+ * @public
45
+ */
46
+ class InMemoryDirectory {
47
+ /**
48
+ * The children of the directory.
49
+ */
50
+ get children() {
51
+ return this._children;
52
+ }
53
+ /**
54
+ * Creates an empty new {@link InMemoryDirectory | InMemoryDirectory} instance.
55
+ * @param absolutePath - The absolute path of the directory.
56
+ */
57
+ constructor(absolutePath) {
58
+ this.absolutePath = absolutePath;
59
+ this._children = new Map();
60
+ }
61
+ /**
62
+ * Gets or adds a child directory with the specified name.
63
+ * @param name - The name of the child directory.
64
+ * @returns {@link Success | Success} with the child directory if successful, or
65
+ * {@link Failure | Failure} with an error message otherwise.
66
+ */
67
+ getOrAddDirectory(name) {
68
+ const existing = this._children.get(name);
69
+ if (existing) {
70
+ if (existing instanceof InMemoryDirectory) {
71
+ return (0, base_1.succeed)(existing);
72
+ }
73
+ return (0, base_1.fail)(`${name}: not a directory`);
74
+ }
75
+ const child = new InMemoryDirectory(this.getChildPath(name));
76
+ this._children.set(name, child);
77
+ return (0, base_1.succeed)(child);
78
+ }
79
+ /**
80
+ * Adds a file to the directory.
81
+ * @param name - The name of the file.
82
+ * @param contents - The contents of the file.
83
+ * @returns {@link Success | Success} with the new file if successful, or
84
+ * {@link Failure | Failure} with an error message otherwise.
85
+ */
86
+ addFile(name, contents) {
87
+ if (this._children.has(name)) {
88
+ return (0, base_1.fail)(`${name}: already exists`);
89
+ }
90
+ const child = new InMemoryFile(this.getChildPath(name), contents);
91
+ this._children.set(name, child);
92
+ return (0, base_1.succeed)(child);
93
+ }
94
+ /**
95
+ * Gets the absolute path for a child of this directory with the supplied
96
+ * name.
97
+ * @param name - The name of the child.
98
+ * @returns {@link Success | Success} with the absolute path if successful, or
99
+ * {@link Failure | Failure} with an error message otherwise.
100
+ */
101
+ getChildPath(name) {
102
+ if (this.absolutePath === '/') {
103
+ return `/${name}`;
104
+ }
105
+ return [this.absolutePath, name].join('/');
106
+ }
107
+ }
108
+ exports.InMemoryDirectory = InMemoryDirectory;
109
+ /**
110
+ * Helper class to build an in-memory file tree.
111
+ * @public
112
+ */
113
+ class TreeBuilder {
114
+ /**
115
+ * Protected constructor for derived classes.
116
+ * @param prefix - The prefix for all paths in the tree.
117
+ * @public
118
+ */
119
+ constructor(prefix) {
120
+ this.prefix = prefix !== null && prefix !== void 0 ? prefix : '/';
121
+ if (!this.prefix.startsWith('/')) {
122
+ throw new Error(`${prefix}: not an absolute path`);
123
+ }
124
+ this.root = new InMemoryDirectory(this.prefix);
125
+ this.byAbsolutePath = new Map();
126
+ this.byAbsolutePath.set(this.prefix, this.root);
127
+ }
128
+ /**
129
+ * Creates a new {@link TreeBuilder | TreeBuilder} instance.
130
+ * @param prefix - The prefix for all paths in the tree.
131
+ * @returns {@link Success | Success} with the new {@link TreeBuilder | TreeBuilder} instance if successful,
132
+ * or {@link Failure | Failure} with an error message otherwise.
133
+ * @public
134
+ */
135
+ static create(prefix) {
136
+ return (0, base_1.captureResult)(() => new TreeBuilder(prefix));
137
+ }
138
+ /**
139
+ * Adds a file to the tree.
140
+ * @param absolutePath - The absolute path of the file.
141
+ * @param contents - The contents of the file.
142
+ * @returns {@link Success | Success} with the new file if successful, or
143
+ * {@link Failure | Failure} with an error message otherwise.
144
+ * @public
145
+ */
146
+ addFile(absolutePath, contents) {
147
+ const parts = absolutePath.split('/').filter((p) => p.length > 0);
148
+ if (parts.length === 0) {
149
+ return (0, base_1.fail)(`${absolutePath}: invalid file path`);
150
+ }
151
+ let dir = this.root;
152
+ while (parts.length > 1) {
153
+ const part = parts.shift();
154
+ const result = dir.getOrAddDirectory(part);
155
+ if (result.isFailure()) {
156
+ return (0, base_1.fail)(result.message);
157
+ }
158
+ dir = result.value;
159
+ if (!this.byAbsolutePath.has(dir.absolutePath)) {
160
+ this.byAbsolutePath.set(dir.absolutePath, dir);
161
+ }
162
+ }
163
+ return dir.addFile(parts[0], contents).onSuccess((file) => {
164
+ this.byAbsolutePath.set(file.absolutePath, file);
165
+ return (0, base_1.succeed)(file);
166
+ });
167
+ }
168
+ }
169
+ exports.TreeBuilder = TreeBuilder;
170
+ //# sourceMappingURL=treeBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeBuilder.js","sourceRoot":"","sources":["../../../../src/packlets/file-tree/in-memory/treeBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAAkE;AAElE;;;GAGG;AACH,MAAa,YAAY;IAUvB;;;;OAIG;IACH,YAAmB,YAAoB,EAAE,QAAiB;QACxD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAnBD,oCAmBC;AAED;;;GAGG;AACH,MAAa,iBAAiB;IAO5B;;OAEG;IACH,IAAW,QAAQ;QACj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C,CAAC;QACpD,CAAC;QACD,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;QACpB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAG,CAAC;YAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,OAAO,IAAA,WAAI,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;YACD,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC/C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YACxD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YACjD,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAxED,kCAwEC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '../../base';\n\n/**\n * Represents a file in an in-memory file tree.\n * @public\n */\nexport class InMemoryFile {\n /**\n * The absolute path of the file.\n */\n public readonly absolutePath: string;\n /**\n * The contents of the file.\n */\n public readonly contents: unknown;\n\n /**\n * Creates a new {@link InMemoryFile | InMemoryFile} instance.\n * @param absolutePath - The absolute path of the file.\n * @param contents - The contents of the file.\n */\n public constructor(absolutePath: string, contents: unknown) {\n this.absolutePath = absolutePath;\n this.contents = contents;\n }\n}\n\n/**\n * Represents a directory in an in-memory file tree.\n * @public\n */\nexport class InMemoryDirectory {\n /**\n * The absolute path of the directory.\n */\n public readonly absolutePath: string;\n protected _children: Map<string, InMemoryDirectory | InMemoryFile>;\n\n /**\n * The children of the directory.\n */\n public get children(): ReadonlyMap<string, InMemoryDirectory | InMemoryFile> {\n return this._children;\n }\n\n /**\n * Creates an empty new {@link InMemoryDirectory | InMemoryDirectory} instance.\n * @param absolutePath - The absolute path of the directory.\n */\n public constructor(absolutePath: string) {\n this.absolutePath = absolutePath;\n this._children = new Map<string, InMemoryDirectory | InMemoryFile>();\n }\n\n /**\n * Gets or adds a child directory with the specified name.\n * @param name - The name of the child directory.\n * @returns {@link Success | Success} with the child directory if successful, or\n * {@link Failure | Failure} with an error message otherwise.\n */\n public getOrAddDirectory(name: string): Result<InMemoryDirectory> {\n const existing = this._children.get(name);\n if (existing) {\n if (existing instanceof InMemoryDirectory) {\n return succeed(existing);\n }\n return fail(`${name}: not a directory`);\n }\n const child = new InMemoryDirectory(this.getChildPath(name));\n this._children.set(name, child);\n return succeed(child);\n }\n\n /**\n * Adds a file to the directory.\n * @param name - The name of the file.\n * @param contents - The contents of the file.\n * @returns {@link Success | Success} with the new file if successful, or\n * {@link Failure | Failure} with an error message otherwise.\n */\n public addFile(name: string, contents: unknown): Result<InMemoryFile> {\n if (this._children.has(name)) {\n return fail(`${name}: already exists`);\n }\n const child = new InMemoryFile(this.getChildPath(name), contents);\n this._children.set(name, child);\n return succeed(child);\n }\n\n /**\n * Gets the absolute path for a child of this directory with the supplied\n * name.\n * @param name - The name of the child.\n * @returns {@link Success | Success} with the absolute path if successful, or\n * {@link Failure | Failure} with an error message otherwise.\n */\n public getChildPath(name: string): string {\n if (this.absolutePath === '/') {\n return `/${name}`;\n }\n return [this.absolutePath, name].join('/');\n }\n}\n\n/**\n * Helper class to build an in-memory file tree.\n * @public\n */\nexport class TreeBuilder {\n /**\n * The prefix for all paths in the tree.\n */\n public readonly prefix: string;\n\n /**\n * The root directory of the tree.\n */\n public readonly root: InMemoryDirectory;\n\n /**\n * A map of all directories and files in the tree by absolute path.\n */\n public readonly byAbsolutePath: Map<string, InMemoryDirectory | InMemoryFile>;\n\n /**\n * Protected constructor for derived classes.\n * @param prefix - The prefix for all paths in the tree.\n * @public\n */\n protected constructor(prefix?: string) {\n this.prefix = prefix ?? '/';\n if (!this.prefix.startsWith('/')) {\n throw new Error(`${prefix}: not an absolute path`);\n }\n this.root = new InMemoryDirectory(this.prefix);\n this.byAbsolutePath = new Map<string, InMemoryDirectory | InMemoryFile>();\n this.byAbsolutePath.set(this.prefix, this.root);\n }\n\n /**\n * Creates a new {@link TreeBuilder | TreeBuilder} instance.\n * @param prefix - The prefix for all paths in the tree.\n * @returns {@link Success | Success} with the new {@link TreeBuilder | TreeBuilder} instance if successful,\n * or {@link Failure | Failure} with an error message otherwise.\n * @public\n */\n public static create(prefix?: string): Result<TreeBuilder> {\n return captureResult(() => new TreeBuilder(prefix));\n }\n\n /**\n * Adds a file to the tree.\n * @param absolutePath - The absolute path of the file.\n * @param contents - The contents of the file.\n * @returns {@link Success | Success} with the new file if successful, or\n * {@link Failure | Failure} with an error message otherwise.\n * @public\n */\n public addFile(absolutePath: string, contents: unknown): Result<InMemoryFile> {\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n if (parts.length === 0) {\n return fail(`${absolutePath}: invalid file path`);\n }\n let dir = this.root;\n while (parts.length > 1) {\n const part = parts.shift()!;\n const result = dir.getOrAddDirectory(part);\n if (result.isFailure()) {\n return fail(result.message);\n }\n dir = result.value;\n if (!this.byAbsolutePath.has(dir.absolutePath)) {\n this.byAbsolutePath.set(dir.absolutePath, dir);\n }\n }\n return dir.addFile(parts[0], contents).onSuccess((file) => {\n this.byAbsolutePath.set(file.absolutePath, file);\n return succeed(file);\n });\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { IInMemoryFile, InMemoryTreeAccessors } from './in-memory';
2
+ export * from './directoryItem';
3
+ export * from './fileItem';
4
+ export * from './fileTreeAccessors';
5
+ export * from './fsTree';
6
+ export * from './fileTree';
7
+ export { IInMemoryFile, InMemoryTreeAccessors };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEnE,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.InMemoryTreeAccessors = void 0;
39
+ const in_memory_1 = require("./in-memory");
40
+ Object.defineProperty(exports, "InMemoryTreeAccessors", { enumerable: true, get: function () { return in_memory_1.InMemoryTreeAccessors; } });
41
+ __exportStar(require("./directoryItem"), exports);
42
+ __exportStar(require("./fileItem"), exports);
43
+ __exportStar(require("./fileTreeAccessors"), exports);
44
+ __exportStar(require("./fsTree"), exports);
45
+ __exportStar(require("./fileTree"), exports);
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,2CAAmE;AAQ3C,sGARA,iCAAqB,OAQA;AAN7C,kDAAgC;AAChC,6CAA2B;AAC3B,sDAAoC;AACpC,2CAAyB;AACzB,6CAA2B","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { IInMemoryFile, InMemoryTreeAccessors } from './in-memory';\n\nexport * from './directoryItem';\nexport * from './fileItem';\nexport * from './fileTreeAccessors';\nexport * from './fsTree';\nexport * from './fileTree';\n\nexport { IInMemoryFile, InMemoryTreeAccessors };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"crcNormalizer.d.ts","sourceRoot":"","sources":["../../../src/packlets/hash/crcNormalizer.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA2CxD;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,iBAAiB;;WAKtC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;CAGjD"}
1
+ {"version":3,"file":"crcNormalizer.d.ts","sourceRoot":"","sources":["../../../src/packlets/hash/crcNormalizer.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA2CxD;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,iBAAiB;;WAKtC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;CAKjD"}
@@ -69,7 +69,9 @@ class Crc32Normalizer extends hashingNormalizer_1.HashingNormalizer {
69
69
  super(Crc32Normalizer.crc32Hash);
70
70
  }
71
71
  static crc32Hash(parts) {
72
- return String(crc32(textEncoder.encode(parts.join('|'))));
72
+ return crc32(textEncoder.encode(parts.join('|')))
73
+ .toString(16)
74
+ .padStart(8, '0');
73
75
  }
74
76
  }
75
77
  exports.Crc32Normalizer = Crc32Normalizer;
@@ -1 +1 @@
1
- {"version":3,"file":"crcNormalizer.js","sourceRoot":"","sources":["../../../src/packlets/hash/crcNormalizer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,2DAAwD;AAExD,MAAM,WAAW,GAAgB,IAAI,WAAW,EAAE,CAAC;AAEnD,MAAM,UAAU,GAAW,UAAU,CAAC;AAEtC,MAAM,UAAU,GAAa,EAAE,CAAC;AAEhC,SAAS,KAAK,CAAC,KAAiB,EAAE,MAAc,UAAU;IACx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,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAa,eAAgB,SAAQ,qCAAiB;IACpD;QACE,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,KAAe;QACrC,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF;AARD,0CAQC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { HashingNormalizer } from './hashingNormalizer';\n\nconst textEncoder: TextEncoder = new TextEncoder();\n\nconst POLYNOMIAL: number = 0xedb88320;\n\nconst crc32Table: number[] = [];\n\nfunction crc32(bytes: Uint8Array, crc: number = 0xffffffff): number {\n if (crc32Table.length === 0) {\n buildCrc32Table();\n }\n for (let i = 0; i < bytes.length; ++i) {\n // eslint-disable-next-line no-bitwise\n crc = crc32Table[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);\n }\n return (crc ^ -1) >>> 0;\n}\n\nconst toUInt32 = (n: number): number => {\n if (n >= 0) {\n return n;\n }\n return 0xffffffff - n * -1 + 1;\n};\n\nfunction buildCrc32Table(): void {\n if (crc32Table.length === 0) {\n for (let n = 0; n < 256; n++) {\n let r = n;\n for (let i = 0; i < 8; i++) {\n // eslint-disable-next-line no-bitwise\n if (r & 1) {\n r = (r >>> 1) ^ POLYNOMIAL;\n } else {\n r = r >>> 1;\n }\n }\n crc32Table.push(toUInt32(r));\n }\n }\n}\n\n/**\n * A {@link Hash.HashingNormalizer | hashing normalizer} which computes object\n * hash using the CRC32 algorithm.\n * @public\n */\nexport class Crc32Normalizer extends HashingNormalizer {\n public constructor() {\n super(Crc32Normalizer.crc32Hash);\n }\n\n public static crc32Hash(parts: string[]): string {\n return String(crc32(textEncoder.encode(parts.join('|'))));\n }\n}\n"]}
1
+ {"version":3,"file":"crcNormalizer.js","sourceRoot":"","sources":["../../../src/packlets/hash/crcNormalizer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,2DAAwD;AAExD,MAAM,WAAW,GAAgB,IAAI,WAAW,EAAE,CAAC;AAEnD,MAAM,UAAU,GAAW,UAAU,CAAC;AAEtC,MAAM,UAAU,GAAa,EAAE,CAAC;AAEhC,SAAS,KAAK,CAAC,KAAiB,EAAE,MAAc,UAAU;IACxD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,eAAe,EAAE,CAAC;IACpB,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACtC,sCAAsC;QACtC,GAAG,GAAG,UAAU,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,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AC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAVD,0CAUC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { HashingNormalizer } from './hashingNormalizer';\n\nconst textEncoder: TextEncoder = new TextEncoder();\n\nconst POLYNOMIAL: number = 0xedb88320;\n\nconst crc32Table: number[] = [];\n\nfunction crc32(bytes: Uint8Array, crc: number = 0xffffffff): number {\n if (crc32Table.length === 0) {\n buildCrc32Table();\n }\n for (let i = 0; i < bytes.length; ++i) {\n // eslint-disable-next-line no-bitwise\n crc = crc32Table[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);\n }\n return (crc ^ -1) >>> 0;\n}\n\nconst toUInt32 = (n: number): number => {\n if (n >= 0) {\n return n;\n }\n return 0xffffffff - n * -1 + 1;\n};\n\nfunction buildCrc32Table(): void {\n if (crc32Table.length === 0) {\n for (let n = 0; n < 256; n++) {\n let r = n;\n for (let i = 0; i < 8; i++) {\n // eslint-disable-next-line no-bitwise\n if (r & 1) {\n r = (r >>> 1) ^ POLYNOMIAL;\n } else {\n r = r >>> 1;\n }\n }\n crc32Table.push(toUInt32(r));\n }\n }\n}\n\n/**\n * A {@link Hash.HashingNormalizer | hashing normalizer} which computes object\n * hash using the CRC32 algorithm.\n * @public\n */\nexport class Crc32Normalizer extends HashingNormalizer {\n public constructor() {\n super(Crc32Normalizer.crc32Hash);\n }\n\n public static crc32Hash(parts: string[]): string {\n return crc32(textEncoder.encode(parts.join('|')))\n .toString(16)\n .padStart(8, '0');\n }\n}\n"]}
@@ -75,7 +75,7 @@ export declare function recordOf<T, TC = unknown, TK extends string = string>(va
75
75
  * value in place.
76
76
  * @public
77
77
  */
78
- export declare function enumeratedValue<T extends string>(values: T[]): Validator<T, T[]>;
78
+ export declare function enumeratedValue<T extends string>(values: ReadonlyArray<T>): Validator<T, ReadonlyArray<T>>;
79
79
  /**
80
80
  * Helper function to create a {@link Validation.Validator} which validates a literal value.
81
81
  * @param value - the literal value to be validated
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAGtF,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG/D,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAAyB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,MAAM,EA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CAAmC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GACjF,kBAAkB,CAAC,CAAC,EAAE,EAAE,CAAC,CAE3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAE1F"}
@@ -127,6 +127,7 @@ function recordOf(validator, options) {
127
127
  }
128
128
  }
129
129
  }
130
+ /* c8 ignore next 1 - defense in depth */
130
131
  return errors.hasMessages ? (0, base_1.fail)(errors.toString()) : true;
131
132
  }
132
133
  });
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA4CH,wBAKC;AAUD,0BAKC;AAgCD,4BA+CC;AAOD,0CAWC;AAOD,0BAUC;AAWD,sBAKC;AAWD,kBAMC;AAWD,0BAEC;AA9ND,kCAAoE;AACpE,mCAA0E;AAC1E,qCAA8F;AAC9F,2CAAsF;AAEtF,uCAA6C;AAE7C,yDAAsD;AACtD,qCAA2C;AAC3C,mCAA0E;AAC1E,qCAA2C;AAG3C;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,OAAO,GAAuB,IAAI,0BAAgB,EAAE,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CACpB,MAA8B,EAC9B,MAAgE;IAEhE,OAAO,IAAI,wBAAe,iBAAG,MAAM,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC5D,CAAC;AAED;;;;;;;GAOG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AI,CAAC,GAAG,CAAC,CAAC;YACvG,CAAC;YACD,OAAO,IAAA,WAAI,EAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACtE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CACrB,KAAQ;IAER,OAAO,IAAI,mCAAgB,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAa,EAAwB,EAAE;YACjD,OAAO,IAAI,KAAK,KAAK;gBACnB,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,IAAA,WAAI,EAAC,oBAAoB,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,KAAK,CACnB,UAAmC,EACnC,MAAmE;IAEnE,OAAO,IAAI,sBAAc,iCAAa,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,KAAE,UAAU,IAAG,CAAC;AACtE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CACjB,WAAmB,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAkB,SAA+B;IACtE,OAAO,IAAI,mCAAgB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail, isKeyOf, MessageAggregator } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext, ValidatorFunc } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';\nimport { StringValidator } from './string';\nimport { Validator } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Options for {@link Validators.recordOf} helper function.\n * @public\n */\nexport interface IRecordOfValidatorOptions<TK extends string = string, TC = unknown> {\n /**\n * If `onError` is `'fail'` (default), then the entire validation fails if any key or element\n * cannot be validated. If `onError` is `'ignore'`, failing elements are silently ignored.\n */\n onError?: 'fail' | 'ignore';\n /**\n * If present, `keyValidator` is used to validate the source object property names.\n * @remarks\n * Can be used to validate key names to supported values and/or strong types.\n */\n keyValidator?: Validator<TK, TC>;\n}\n\n/**\n * A helper function to create a {@link Validation.Validator | Validator} which validates the `string`-keyed properties\n * using a supplied {@link Validation.Validator | Validator<T, TC>} to produce a `Record<TK, T>`.\n * @remarks\n * If present, the supplied {@link Validators.IRecordOfValidatorOptions | options} can provide a strongly-typed\n * validator for keys and/or control the handling of elements that fail validation.\n * @param validator - {@link Validation.Validator | Validator} used for each item in the source object.\n * @param options - Optional {@link Validators.IRecordOfValidatorOptions | IRecordOfValidatorOptions<TK, TC>} which\n * supplies a key validator and/or error-handling options.\n * @returns A {@link Validation.Validator | Validator} which validates `Record<TK, T>`.\n * @public\n */\nexport function recordOf<T, TC = unknown, TK extends string = string>(\n validator: Validator<T, TC>,\n options?: IRecordOfValidatorOptions<TK, TC>\n): Validator<Record<TK, T>, TC> {\n const opts: IRecordOfValidatorOptions<TK, TC> = { onError: 'fail', ...options };\n\n return new GenericValidator({\n validator: (from: unknown, context?: TC): boolean | Failure<Record<TK, T>> => {\n if (typeof from !== 'object' || from === null || Array.isArray(from)) {\n return fail(`Not a string-keyed object: ${JSON.stringify(from)}`);\n }\n\n const errors = new MessageAggregator();\n\n for (const key in from) {\n if (isKeyOf(key, from)) {\n // Validate key if keyValidator is provided\n if (opts.keyValidator) {\n const keyResult = opts.keyValidator.validate(key, context);\n if (!keyResult.isSuccess()) {\n if (opts.onError === 'ignore') {\n continue;\n }\n errors.addMessage(`Key \"${key}\": ${keyResult.message}`);\n if (opts.onError === 'fail') {\n return fail(keyResult.message);\n }\n }\n }\n\n // Validate value\n const valueResult = validator.validate(from[key] as unknown, context);\n if (!valueResult.isSuccess()) {\n if (opts.onError === 'ignore') {\n continue;\n }\n errors.addMessage(`Property \"${key}\": ${valueResult.message}`);\n if (opts.onError === 'fail') {\n return fail(valueResult.message);\n }\n }\n }\n }\n\n return errors.hasMessages ? fail(errors.toString()) : true;\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: T[]): Validator<T, T[]> {\n return new GenericValidator({\n validator: (from: unknown, context?: T[]): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} which validates one\n * of several possible validated values.\n * @param validators - the {@link Validation.Validator | validators} to be considered.\n * @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.\n * @returns A new {@link Validator | Validator} which validates values that match any of\n * the supplied validators.\n * @public\n */\nexport function oneOf<T, TC = unknown>(\n validators: Array<Validator<T, TC>>,\n params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>\n): OneOfValidator<T, TC> {\n return new OneOfValidator<T, TC>({ ...(params ?? {}), validators });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC = unknown>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} using a\n * supplied {@link Validation.ValidatorFunc | validator function}.\n * @param validator - A {@link Validation.ValidatorFunc | validator function} that a\n * supplied unknown value matches some condition.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * value using the supplied function.\n * @public\n */\nexport function generic<T, TC = unknown>(validator: ValidatorFunc<T, TC>): Validator<T, TC> {\n return new GenericValidator({ validator });\n}\n"]}
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources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AAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,KAAK,CACnB,UAAmC,EACnC,MAAmE;IAEnE,OAAO,IAAI,sBAAc,iCAAa,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,KAAE,UAAU,IAAG,CAAC;AACtE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CACjB,WAAmB,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAkB,SAA+B;IACtE,OAAO,IAAI,mCAAgB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail, isKeyOf, MessageAggregator } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext, ValidatorFunc } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';\nimport { StringValidator } from './string';\nimport { Validator } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Options for {@link Validators.recordOf} helper function.\n * @public\n */\nexport interface IRecordOfValidatorOptions<TK extends string = string, TC = unknown> {\n /**\n * If `onError` is `'fail'` (default), then the entire validation fails if any key or element\n * cannot be validated. If `onError` is `'ignore'`, failing elements are silently ignored.\n */\n onError?: 'fail' | 'ignore';\n /**\n * If present, `keyValidator` is used to validate the source object property names.\n * @remarks\n * Can be used to validate key names to supported values and/or strong types.\n */\n keyValidator?: Validator<TK, TC>;\n}\n\n/**\n * A helper function to create a {@link Validation.Validator | Validator} which validates the `string`-keyed properties\n * using a supplied {@link Validation.Validator | Validator<T, TC>} to produce a `Record<TK, T>`.\n * @remarks\n * If present, the supplied {@link Validators.IRecordOfValidatorOptions | options} can provide a strongly-typed\n * validator for keys and/or control the handling of elements that fail validation.\n * @param validator - {@link Validation.Validator | Validator} used for each item in the source object.\n * @param options - Optional {@link Validators.IRecordOfValidatorOptions | IRecordOfValidatorOptions<TK, TC>} which\n * supplies a key validator and/or error-handling options.\n * @returns A {@link Validation.Validator | Validator} which validates `Record<TK, T>`.\n * @public\n */\nexport function recordOf<T, TC = unknown, TK extends string = string>(\n validator: Validator<T, TC>,\n options?: IRecordOfValidatorOptions<TK, TC>\n): Validator<Record<TK, T>, TC> {\n const opts: IRecordOfValidatorOptions<TK, TC> = { onError: 'fail', ...options };\n\n return new GenericValidator({\n validator: (from: unknown, context?: TC): boolean | Failure<Record<TK, T>> => {\n if (typeof from !== 'object' || from === null || Array.isArray(from)) {\n return fail(`Not a string-keyed object: ${JSON.stringify(from)}`);\n }\n\n const errors = new MessageAggregator();\n\n for (const key in from) {\n if (isKeyOf(key, from)) {\n // Validate key if keyValidator is provided\n if (opts.keyValidator) {\n const keyResult = opts.keyValidator.validate(key, context);\n if (!keyResult.isSuccess()) {\n if (opts.onError === 'ignore') {\n continue;\n }\n errors.addMessage(`Key \"${key}\": ${keyResult.message}`);\n if (opts.onError === 'fail') {\n return fail(keyResult.message);\n }\n }\n }\n\n // Validate value\n const valueResult = validator.validate(from[key] as unknown, context);\n if (!valueResult.isSuccess()) {\n if (opts.onError === 'ignore') {\n continue;\n }\n errors.addMessage(`Property \"${key}\": ${valueResult.message}`);\n if (opts.onError === 'fail') {\n return fail(valueResult.message);\n }\n }\n }\n }\n\n /* c8 ignore next 1 - defense in depth */\n return errors.hasMessages ? fail(errors.toString()) : true;\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: ReadonlyArray<T>): Validator<T, ReadonlyArray<T>> {\n return new GenericValidator({\n validator: (from: unknown, context?: ReadonlyArray<T>): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} which validates one\n * of several possible validated values.\n * @param validators - the {@link Validation.Validator | validators} to be considered.\n * @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.\n * @returns A new {@link Validator | Validator} which validates values that match any of\n * the supplied validators.\n * @public\n */\nexport function oneOf<T, TC = unknown>(\n validators: Array<Validator<T, TC>>,\n params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>\n): OneOfValidator<T, TC> {\n return new OneOfValidator<T, TC>({ ...(params ?? {}), validators });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC = unknown>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} using a\n * supplied {@link Validation.ValidatorFunc | validator function}.\n * @param validator - A {@link Validation.ValidatorFunc | validator function} that a\n * supplied unknown value matches some condition.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * value using the supplied function.\n * @public\n */\nexport function generic<T, TC = unknown>(validator: ValidatorFunc<T, TC>): Validator<T, TC> {\n return new GenericValidator({ validator });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "4.6.0",
3
+ "version": "5.0.0-10",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-utils.d.ts",
@@ -20,7 +20,7 @@
20
20
  "@microsoft/api-documenter": "^7.26.29",
21
21
  "@microsoft/api-extractor": "^7.49.1",
22
22
  "@types/jest": "^29.5.14",
23
- "@types/luxon": "^3.4.2",
23
+ "@types/luxon": "^3.6.2",
24
24
  "@types/mustache": "^4.2.5",
25
25
  "@types/node": "^20.14.9",
26
26
  "@typescript-eslint/eslint-plugin": "^7.14.1",