@fgv/ts-utils 4.3.0 → 4.5.0-0

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 (112) hide show
  1. package/CHANGELOG.json +6 -0
  2. package/CHANGELOG.md +6 -1
  3. package/dist/ts-utils.d.ts +4248 -3531
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib/index.d.ts +3 -2
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +7 -3
  8. package/lib/index.js.map +1 -1
  9. package/lib/packlets/base/utils.d.ts.map +1 -1
  10. package/lib/packlets/base/utils.js +0 -1
  11. package/lib/packlets/base/utils.js.map +1 -1
  12. package/lib/packlets/collections/collectible.d.ts +82 -8
  13. package/lib/packlets/collections/collectible.d.ts.map +1 -1
  14. package/lib/packlets/collections/collectible.js +36 -11
  15. package/lib/packlets/collections/collectible.js.map +1 -1
  16. package/lib/packlets/collections/collector.d.ts +78 -79
  17. package/lib/packlets/collections/collector.d.ts.map +1 -1
  18. package/lib/packlets/collections/collector.js +83 -52
  19. package/lib/packlets/collections/collector.js.map +1 -1
  20. package/lib/packlets/collections/collectorValidator.d.ts +89 -0
  21. package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
  22. package/lib/packlets/collections/collectorValidator.js +98 -0
  23. package/lib/packlets/collections/collectorValidator.js.map +1 -0
  24. package/lib/packlets/collections/convertingCollector.d.ts +77 -36
  25. package/lib/packlets/collections/convertingCollector.d.ts.map +1 -1
  26. package/lib/packlets/collections/convertingCollector.js +71 -26
  27. package/lib/packlets/collections/convertingCollector.js.map +1 -1
  28. package/lib/packlets/collections/convertingCollectorValidator.d.ts +69 -0
  29. package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
  30. package/lib/packlets/collections/{collectorConverter.js → convertingCollectorValidator.js} +28 -15
  31. package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
  32. package/lib/packlets/collections/index.d.ts +7 -5
  33. package/lib/packlets/collections/index.d.ts.map +1 -1
  34. package/lib/packlets/collections/index.js +7 -5
  35. package/lib/packlets/collections/index.js.map +1 -1
  36. package/lib/packlets/collections/keyValueConverters.d.ts +1 -17
  37. package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -1
  38. package/lib/packlets/collections/keyValueConverters.js +1 -8
  39. package/lib/packlets/collections/keyValueConverters.js.map +1 -1
  40. package/lib/packlets/collections/readonlyResultMap.d.ts +0 -4
  41. package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -1
  42. package/lib/packlets/collections/readonlyResultMap.js.map +1 -1
  43. package/lib/packlets/collections/resultMap.d.ts +0 -4
  44. package/lib/packlets/collections/resultMap.d.ts.map +1 -1
  45. package/lib/packlets/collections/resultMap.js +0 -6
  46. package/lib/packlets/collections/resultMap.js.map +1 -1
  47. package/lib/packlets/collections/{resultMapConverter.d.ts → resultMapValidator.d.ts} +11 -11
  48. package/lib/packlets/collections/{resultMapConverter.d.ts.map → resultMapValidator.d.ts.map} +1 -1
  49. package/lib/packlets/collections/{resultMapConverter.js → resultMapValidator.js} +6 -6
  50. package/lib/packlets/collections/{resultMapConverter.js.map → resultMapValidator.js.map} +1 -1
  51. package/lib/packlets/collections/validatingCollector.d.ts +69 -0
  52. package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
  53. package/lib/packlets/collections/validatingCollector.js +67 -0
  54. package/lib/packlets/collections/validatingCollector.js.map +1 -0
  55. package/lib/packlets/collections/validatingConvertingCollector.d.ts +59 -0
  56. package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
  57. package/lib/packlets/collections/validatingConvertingCollector.js +68 -0
  58. package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
  59. package/lib/packlets/collections/validatingResultMap.d.ts +53 -0
  60. package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
  61. package/lib/packlets/collections/validatingResultMap.js +61 -0
  62. package/lib/packlets/collections/validatingResultMap.js.map +1 -0
  63. package/lib/packlets/file-tree/directoryItem.d.ts +47 -0
  64. package/lib/packlets/file-tree/directoryItem.d.ts.map +1 -0
  65. package/lib/packlets/file-tree/directoryItem.js +71 -0
  66. package/lib/packlets/file-tree/directoryItem.js.map +1 -0
  67. package/lib/packlets/file-tree/fileItem.d.ts +64 -0
  68. package/lib/packlets/file-tree/fileItem.d.ts.map +1 -0
  69. package/lib/packlets/file-tree/fileItem.js +93 -0
  70. package/lib/packlets/file-tree/fileItem.js.map +1 -0
  71. package/lib/packlets/file-tree/fileTree.d.ts +84 -0
  72. package/lib/packlets/file-tree/fileTree.d.ts.map +1 -0
  73. package/lib/packlets/file-tree/fileTree.js +135 -0
  74. package/lib/packlets/file-tree/fileTree.js.map +1 -0
  75. package/lib/packlets/file-tree/fileTreeAccessors.d.ts +134 -0
  76. package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +1 -0
  77. package/lib/packlets/file-tree/fileTreeAccessors.js +24 -0
  78. package/lib/packlets/file-tree/fileTreeAccessors.js.map +1 -0
  79. package/lib/packlets/file-tree/fsTree.d.ts +45 -0
  80. package/lib/packlets/file-tree/fsTree.d.ts.map +1 -0
  81. package/lib/packlets/file-tree/fsTree.js +116 -0
  82. package/lib/packlets/file-tree/fsTree.js.map +1 -0
  83. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +67 -0
  84. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +1 -0
  85. package/lib/packlets/file-tree/in-memory/inMemoryTree.js +150 -0
  86. package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
  87. package/lib/packlets/file-tree/in-memory/index.d.ts +2 -0
  88. package/lib/packlets/file-tree/in-memory/index.d.ts.map +1 -0
  89. package/lib/packlets/file-tree/in-memory/index.js +39 -0
  90. package/lib/packlets/file-tree/in-memory/index.js.map +1 -0
  91. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +106 -0
  92. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +1 -0
  93. package/lib/packlets/file-tree/in-memory/treeBuilder.js +170 -0
  94. package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
  95. package/lib/packlets/file-tree/index.d.ts +8 -0
  96. package/lib/packlets/file-tree/index.d.ts.map +1 -0
  97. package/lib/packlets/file-tree/index.js +46 -0
  98. package/lib/packlets/file-tree/index.js.map +1 -0
  99. package/lib/packlets/hash/crcNormalizer.js +1 -1
  100. package/lib/packlets/hash/crcNormalizer.js.map +1 -1
  101. package/package.json +15 -15
  102. package/lib/packlets/collections/collectorConverter.d.ts +0 -59
  103. package/lib/packlets/collections/collectorConverter.d.ts.map +0 -1
  104. package/lib/packlets/collections/collectorConverter.js.map +0 -1
  105. package/lib/packlets/collections/collectors.d.ts +0 -32
  106. package/lib/packlets/collections/collectors.d.ts.map +0 -1
  107. package/lib/packlets/collections/collectors.js +0 -57
  108. package/lib/packlets/collections/collectors.js.map +0 -1
  109. package/lib/packlets/collections/convertingResultMap.d.ts +0 -73
  110. package/lib/packlets/collections/convertingResultMap.d.ts.map +0 -1
  111. package/lib/packlets/collections/convertingResultMap.js +0 -102
  112. package/lib/packlets/collections/convertingResultMap.js.map +0 -1
@@ -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;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAmB,YAAoB;QACrC,IA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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"]}
@@ -69,7 +69,7 @@ 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('|'))).toString(16);
73
73
  }
74
74
  }
75
75
  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;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,GAAG,KAAK,CAAC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAU,EAAE;IACrC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,UAAU,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,SAAS,eAAe;IACtB,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,CAAC;YACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3B,sCAAsC;gBACtC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBACV,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;gBAC7B,CAAC;qBAAM,CAAC;oBACN,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACd,CAAC;YACH,CAAC;YACD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;IACH,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":["../../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AAC,GAAG,CAAC,EAAE,CAAC;oBACV,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;gBAC7B,CAAC;qBAAM,CAAC;oBACN,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACd,CAAC;YACH,CAAC;YACD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;IACH,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,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjE,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 crc32(textEncoder.encode(parts.join('|'))).toString(16);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "4.3.0",
3
+ "version": "4.5.0-0",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-utils.d.ts",
@@ -29,32 +29,32 @@
29
29
  "homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#readme",
30
30
  "devDependencies": {
31
31
  "@jest/expect-utils": "^29.7.0",
32
- "@microsoft/api-documenter": "^7.26.5",
33
- "@microsoft/api-extractor": "^7.49.1",
32
+ "@microsoft/api-documenter": "^7.26.17",
33
+ "@microsoft/api-extractor": "^7.52.1",
34
34
  "@types/jest": "^29.5.14",
35
35
  "@types/luxon": "^3.4.2",
36
36
  "@types/mustache": "^4.2.5",
37
- "@types/node": "^20.14.9",
38
- "@typescript-eslint/eslint-plugin": "^7.14.1",
39
- "@typescript-eslint/parser": "^7.14.1",
37
+ "@types/node": "^22.13.11",
38
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
39
+ "@typescript-eslint/parser": "^8.27.0",
40
40
  "eslint": "^8.57.0",
41
41
  "eslint-plugin-import": "^2.31.0",
42
42
  "eslint-plugin-node": "^11.1.0",
43
- "eslint-plugin-promise": "^6.2.0",
43
+ "eslint-plugin-promise": "^7.2.1",
44
44
  "jest": "^29.7.0",
45
45
  "jest-extended": "^4.0.2",
46
46
  "jest-matcher-utils": "^29.7.0",
47
- "rimraf": "^5.0.7",
48
- "ts-jest": "^29.2.5",
47
+ "rimraf": "^6.0.1",
48
+ "ts-jest": "^29.2.6",
49
49
  "ts-node": "^10.9.2",
50
- "typescript": "^5.7.3",
51
- "eslint-plugin-n": "^16.6.2",
50
+ "typescript": "^5.8.2",
51
+ "eslint-plugin-n": "^17.16.2",
52
52
  "jest-snapshot": "~29.7.0",
53
- "@rushstack/heft": "~0.68.13",
54
- "@rushstack/heft-node-rig": "~2.6.49",
55
- "@rushstack/eslint-config": "~3.7.0",
53
+ "@rushstack/heft": "~0.71.0",
54
+ "@rushstack/heft-node-rig": "~2.8.2",
55
+ "@rushstack/eslint-config": "~4.3.0",
56
56
  "@types/heft-jest": "1.0.6",
57
- "@rushstack/heft-jest-plugin": "~0.14.3",
57
+ "@rushstack/heft-jest-plugin": "~0.15.2",
58
58
  "eslint-plugin-tsdoc": "~0.4.0"
59
59
  }
60
60
  }
@@ -1,59 +0,0 @@
1
- import { DetailedResult } from '../base';
2
- import { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';
3
- import { ResultMapValueFactory } from './resultMap';
4
- import { KeyValueConverters } from './keyValueConverters';
5
- import { CollectibleFactoryCallback, ICollectible } from './collectible';
6
- import { ICollector } from './collector';
7
- import { IReadOnlyResultMapConverter } from './resultMapConverter';
8
- /**
9
- * Parameters for constructing a {@link Collections.CollectorConverter | CollectorConverter}.
10
- * @public
11
- */
12
- export interface ICollectorConverterCreateParams<TKEY extends string = string, TINDEX extends number = number, TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>, TSRC = TITEM> {
13
- collector: ICollector<TKEY, TINDEX, TITEM, TSRC>;
14
- converters: KeyValueConverters<TKEY, TSRC>;
15
- }
16
- /**
17
- * A {@link Collections.Collector | Collector} wrapper which validates weakly-typed keys
18
- * and values before calling the wrapped collector.
19
- * @public
20
- */
21
- export declare class CollectorConverter<TKEY extends string = string, TINDEX extends number = number, TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>, TSRC = TITEM> implements IReadOnlyResultMapConverter<TKEY, TITEM> {
22
- readonly converters: KeyValueConverters<TKEY, TSRC>;
23
- get map(): IReadOnlyResultMap<TKEY, TITEM>;
24
- protected _collector: ICollector<TKEY, TINDEX, TITEM, TSRC>;
25
- /**
26
- * Constructs a new {@link Collections.CollectorConverter | CollectorConverter}.
27
- * @param params - Required parameters for constructing the collector converter.
28
- */
29
- constructor(params: ICollectorConverterCreateParams<TKEY, TINDEX, TITEM, TSRC>);
30
- /**
31
- * {@inheritdoc Collections.Collector.get}
32
- */
33
- get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
34
- /**
35
- * {@inheritdoc Collections.Collector.(getOrAdd:1)}
36
- */
37
- getOrAdd(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
38
- /**
39
- * {@inheritdoc Collections.Collector.(getOrAdd:2)}
40
- */
41
- getOrAdd(key: string, factory: ResultMapValueFactory<TKEY, TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
42
- /**
43
- * {@inheritdoc Collections.Collector.has}
44
- */
45
- has(key: string): boolean;
46
- /**
47
- * {@inheritdoc Collections.Collector.toReadOnly}
48
- */
49
- toReadOnly(): IReadOnlyResultMapConverter<TKEY, TITEM>;
50
- /**
51
- * Determines if a value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback}.
52
- * @param value - The value to check.
53
- * @returns `true` if the value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback},
54
- * `false` otherwise.
55
- * @public
56
- */
57
- protected _isCollectibleFactoryCallback(value: unknown | CollectibleFactoryCallback<TKEY, TINDEX, TITEM>): value is CollectibleFactoryCallback<TKEY, TINDEX, TITEM>;
58
- }
59
- //# sourceMappingURL=collectorConverter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collectorConverter.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/collectorConverter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,+BAA+B,CAC9C,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,KAAK,SAAS,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EACrE,IAAI,GAAG,KAAK;IAEZ,SAAS,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE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AAC,6BAA6B,CACrC,KAAK,EAAE,OAAO,GAAG,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,GAC/D,KAAK,IAAI,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC;CAG5D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"collectorConverter.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectorConverter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAwBH;;;;GAIG;AACH,MAAa,kBAAkB;IAS7B,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAID;;;OAGG;IACH,YAAmB,MAAkE;QACnF,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YACrD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAcM,QAAQ,CACb,GAAW,EACX,cAAyE;QAEzE,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,cAAc,CAAC,EAAE,CAAC;YACxD,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;gBAChF,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;gBACrD,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAW,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,6BAA6B,CACrC,KAAgE;QAEhE,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF;AAtFD,gDAsFC","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 { DetailedResult } from '../base';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMapValueFactory } from './resultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { CollectibleFactoryCallback, ICollectible } from './collectible';\nimport { ICollector } from './collector';\nimport { IReadOnlyResultMapConverter } from './resultMapConverter';\n\n/**\n * Parameters for constructing a {@link Collections.CollectorConverter | CollectorConverter}.\n * @public\n */\nexport interface ICollectorConverterCreateParams<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> {\n collector: ICollector<TKEY, TINDEX, TITEM, TSRC>;\n converters: KeyValueConverters<TKEY, TSRC>;\n}\n\n/**\n * A {@link Collections.Collector | Collector} wrapper which validates weakly-typed keys\n * and values before calling the wrapped collector.\n * @public\n */\nexport class CollectorConverter<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> implements IReadOnlyResultMapConverter<TKEY, TITEM>\n{\n public readonly converters: KeyValueConverters<TKEY, TSRC>;\n\n public get map(): IReadOnlyResultMap<TKEY, TITEM> {\n return this._collector.toReadOnly();\n }\n\n protected _collector: ICollector<TKEY, TINDEX, TITEM, TSRC>;\n\n /**\n * Constructs a new {@link Collections.CollectorConverter | CollectorConverter}.\n * @param params - Required parameters for constructing the collector converter.\n */\n public constructor(params: ICollectorConverterCreateParams<TKEY, TINDEX, TITEM, TSRC>) {\n this._collector = params.collector;\n this.converters = params.converters;\n }\n\n /**\n * {@inheritdoc Collections.Collector.get}\n */\n public get(key: string): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._collector.get(k);\n });\n }\n\n /**\n * {@inheritdoc Collections.Collector.(getOrAdd:1)}\n */\n public getOrAdd(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;\n\n /**\n * {@inheritdoc Collections.Collector.(getOrAdd:2)}\n */\n public getOrAdd(\n key: string,\n factory: ResultMapValueFactory<TKEY, TITEM>\n ): DetailedResult<TITEM, ResultMapResultDetail>;\n public getOrAdd(\n key: string,\n valueOrFactory: unknown | CollectibleFactoryCallback<TKEY, TINDEX, TITEM>\n ): DetailedResult<TITEM, ResultMapResultDetail> {\n if (!this._isCollectibleFactoryCallback(valueOrFactory)) {\n return this.converters.convertEntry([key, valueOrFactory]).onSuccess(([vk, vs]) => {\n return this._collector.getOrAdd(vk, vs);\n });\n } else {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._collector.getOrAdd(k, valueOrFactory);\n });\n }\n }\n\n /**\n * {@inheritdoc Collections.Collector.has}\n */\n public has(key: string): boolean {\n return this._collector.has(key as TKEY);\n }\n\n /**\n * {@inheritdoc Collections.Collector.toReadOnly}\n */\n public toReadOnly(): IReadOnlyResultMapConverter<TKEY, TITEM> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback},\n * `false` otherwise.\n * @public\n */\n protected _isCollectibleFactoryCallback(\n value: unknown | CollectibleFactoryCallback<TKEY, TINDEX, TITEM>\n ): value is CollectibleFactoryCallback<TKEY, TINDEX, TITEM> {\n return typeof value === 'function';\n }\n}\n"]}
@@ -1,32 +0,0 @@
1
- import { Result } from '../base';
2
- import { ICollectible } from './collectible';
3
- import { Collector } from './collector';
4
- /**
5
- * Parameters for creating a {@link SimpleCollector | simple collector}.
6
- * @public
7
- */
8
- export interface ISimpleCollectorCreateParams<TITEM extends ICollectible<string, number>> {
9
- items?: TITEM[];
10
- }
11
- /**
12
- * A simple {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible items}
13
- * with non-branded `string` key and `number` index, and with no transformation other than index assignment
14
- * on addition.
15
- * @public
16
- */
17
- export declare class SimpleCollector<TITEM extends ICollectible<string, number>> extends Collector<string, number, TITEM, TITEM> {
18
- /**
19
- * Constructs a new {@link SimpleCollector | simple collector}.
20
- * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.
21
- */
22
- constructor(params?: ISimpleCollectorCreateParams<TITEM>);
23
- /**
24
- * Creates a new {@link SimpleCollector | simple collector}.
25
- * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.
26
- * @returns {@link Success | Success} if the collector is created successfully, or {@link Failure | Failure} if not.
27
- * @public
28
- */
29
- static createSimpleCollector<TITEM extends ICollectible<string, number>>(params?: ISimpleCollectorCreateParams<TITEM>): Result<SimpleCollector<TITEM>>;
30
- private static _factory;
31
- }
32
- //# sourceMappingURL=collectors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collectors.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/collectors.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAA0B,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,4BAA4B,CAAC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;IACtF,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED;;;;;GAKG;AACH,qBAAa,eAAe,CAAC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAE,SAAQ,SAAS,CACxF,MAAM,EACN,MAAM,EACN,KAAK,EACL,KAAK,CACN;IACC;;;OAGG;gBACgB,MAAM,CAAC,EAAE,4BAA4B,CAAC,KAAK,CAAC;IAK/D;;;;;OAKG;WACW,qBAAqB,CAAC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5E,MAAM,CAAC,EAAE,4BAA4B,CAAC,KAAK,CAAC,GAC3C,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAIjC,OAAO,CAAC,MAAM,CAAC,QAAQ;CAOxB"}
@@ -1,57 +0,0 @@
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.SimpleCollector = void 0;
25
- const base_1 = require("../base");
26
- const collector_1 = require("./collector");
27
- /**
28
- * A simple {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible items}
29
- * with non-branded `string` key and `number` index, and with no transformation other than index assignment
30
- * on addition.
31
- * @public
32
- */
33
- class SimpleCollector extends collector_1.Collector {
34
- /**
35
- * Constructs a new {@link SimpleCollector | simple collector}.
36
- * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.
37
- */
38
- constructor(params) {
39
- var _a;
40
- const entries = (_a = params === null || params === void 0 ? void 0 : params.items) === null || _a === void 0 ? void 0 : _a.map((item) => [item.key, item]);
41
- super({ factory: SimpleCollector._factory, entries });
42
- }
43
- /**
44
- * Creates a new {@link SimpleCollector | simple collector}.
45
- * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.
46
- * @returns {@link Success | Success} if the collector is created successfully, or {@link Failure | Failure} if not.
47
- * @public
48
- */
49
- static createSimpleCollector(params) {
50
- return (0, base_1.captureResult)(() => new SimpleCollector(params));
51
- }
52
- static _factory(key, index, item) {
53
- return item.setIndex(index).onSuccess(() => (0, base_1.succeed)(item));
54
- }
55
- }
56
- exports.SimpleCollector = SimpleCollector;
57
- //# sourceMappingURL=collectors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collectors.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAyD;AAEzD,2CAAwC;AAUxC;;;;;GAKG;AACH,MAAa,eAA4D,SAAQ,qBAKhF;IACC;;;OAGG;IACH,YAAmB,MAA4C;;QAC7D,MAAM,OAAO,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,0CAAE,GAAG,CAAC,CAAC,IAAI,EAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QAChF,KAAK,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CACjC,MAA4C;QAE5C,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,CAAC;IAEO,MAAM,CAAC,QAAQ,CACrB,GAAW,EACX,KAAa,EACb,IAAW;QAEX,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF;AAlCD,0CAkCC","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, succeed } from '../base';\nimport { ICollectible } from './collectible';\nimport { Collector } from './collector';\n\n/**\n * Parameters for creating a {@link SimpleCollector | simple collector}.\n * @public\n */\nexport interface ISimpleCollectorCreateParams<TITEM extends ICollectible<string, number>> {\n items?: TITEM[];\n}\n\n/**\n * A simple {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible items}\n * with non-branded `string` key and `number` index, and with no transformation other than index assignment\n * on addition.\n * @public\n */\nexport class SimpleCollector<TITEM extends ICollectible<string, number>> extends Collector<\n string,\n number,\n TITEM,\n TITEM\n> {\n /**\n * Constructs a new {@link SimpleCollector | simple collector}.\n * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.\n */\n public constructor(params?: ISimpleCollectorCreateParams<TITEM>) {\n const entries = params?.items?.map((item): [string, TITEM] => [item.key, item]);\n super({ factory: SimpleCollector._factory, entries });\n }\n\n /**\n * Creates a new {@link SimpleCollector | simple collector}.\n * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.\n * @returns {@link Success | Success} if the collector is created successfully, or {@link Failure | Failure} if not.\n * @public\n */\n public static createSimpleCollector<TITEM extends ICollectible<string, number>>(\n params?: ISimpleCollectorCreateParams<TITEM>\n ): Result<SimpleCollector<TITEM>> {\n return captureResult(() => new SimpleCollector(params));\n }\n\n private static _factory<TITEM extends ICollectible<string, number>>(\n key: string,\n index: number,\n item: TITEM\n ): Result<TITEM> {\n return item.setIndex(index).onSuccess(() => succeed(item));\n }\n}\n"]}
@@ -1,73 +0,0 @@
1
- import { DetailedResult, Result } from '../base';
2
- import { KeyValueEntry } from './common';
3
- import { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';
4
- import { ResultMap, ResultMapValueFactory } from './resultMap';
5
- import { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';
6
- import { KeyValueConverters } from './keyValueConverters';
7
- /**
8
- * A read-only interface exposing non-mutating methods of a {@link Collections.ConvertingResultMap | ConvertingResultMap}.
9
- * @public
10
- */
11
- export interface IReadOnlyConvertingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
12
- /**
13
- * {@inheritdoc Collections.ConvertingResultMap.converting}
14
- */
15
- readonly converting: IReadOnlyResultMapConverter<TK, TV>;
16
- }
17
- /**
18
- * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.
19
- * @public
20
- */
21
- export interface IConvertingResultMapConstructorParams<TK extends string = string, TV = unknown> {
22
- entries?: Iterable<KeyValueEntry<string, unknown>>;
23
- converters: KeyValueConverters<TK, TV>;
24
- }
25
- /**
26
- * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapConverter | validator}
27
- * property that enables validated use of the underlying map with weakly-typed keys and values.
28
- * @public
29
- */
30
- export declare class ConvertingResultMap<TK extends string = string, TV = unknown> extends ResultMap<TK, TV> implements IReadOnlyConvertingResultMap<TK, TV> {
31
- /**
32
- * A {@link Collections.ResultMapConverter | ResultMapConverter} which validates keys and values
33
- * before inserting them into this collection.
34
- */
35
- readonly converting: ResultMapConverter<TK, TV>;
36
- /**
37
- * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
38
- * @param params - Required parameters for constructing the map.
39
- */
40
- constructor(params: IConvertingResultMapConstructorParams<TK, TV>);
41
- /**
42
- * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap} instance.
43
- * @param params - Required parameters for constructing the map.
44
- * @returns `Success` with the new map if successful, `Failure` otherwise.
45
- * @public
46
- */
47
- static createConvertingResultMap<TK extends string = string, TV = unknown>(params: IConvertingResultMapConstructorParams<TK, TV>): Result<ConvertingResultMap<TK, TV>>;
48
- /**
49
- * {@inheritdoc Collections.ResultMap.add}
50
- */
51
- add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
52
- /**
53
- * {@inheritdoc Collections.ResultMap.(getOrAdd:1)}
54
- */
55
- getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
56
- /**
57
- * {@inheritdoc Collections.ResultMap.(getOrAdd:2)}
58
- */
59
- getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;
60
- /**
61
- * {@inheritdoc Collections.ResultMap.set}
62
- */
63
- set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
64
- /**
65
- * {@inheritdoc Collections.ResultMap.update}
66
- */
67
- update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
68
- /**
69
- * Gets a read-only version of this map.
70
- */
71
- toReadOnly(): IReadOnlyConvertingResultMap<TK, TV>;
72
- }
73
- //# sourceMappingURL=convertingResultMap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convertingResultMap.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":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