@fgv/ts-json-base 5.0.2 → 5.1.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/packlets/converters/converters.js +36 -14
- package/dist/packlets/file-tree/directoryItem.js +99 -4
- package/dist/packlets/file-tree/fileItem.js +47 -9
- package/dist/packlets/file-tree/fileTreeAccessors.js +59 -1
- package/dist/packlets/file-tree/filterSpec.js +74 -0
- package/dist/packlets/file-tree/fsTree.js +107 -12
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js +279 -21
- package/dist/packlets/file-tree/in-memory/treeBuilder.js +31 -0
- package/dist/packlets/file-tree/index.browser.js +1 -0
- package/dist/packlets/file-tree/index.js +1 -0
- package/dist/packlets/json-file/file.js +1 -1
- package/dist/packlets/json-file/jsonFsHelper.js +1 -1
- package/dist/packlets/validators/validators.js +8 -8
- package/dist/ts-json-base.d.ts +439 -65
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/converters/converters.d.ts +20 -13
- package/lib/packlets/converters/converters.js +36 -13
- package/lib/packlets/file-tree/directoryItem.d.ts +29 -6
- package/lib/packlets/file-tree/directoryItem.js +98 -3
- package/lib/packlets/file-tree/fileItem.d.ts +31 -14
- package/lib/packlets/file-tree/fileItem.js +46 -8
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts +237 -3
- package/lib/packlets/file-tree/fileTreeAccessors.js +63 -0
- package/lib/packlets/file-tree/filterSpec.d.ts +10 -0
- package/lib/packlets/file-tree/filterSpec.js +77 -0
- package/lib/packlets/file-tree/fsTree.d.ts +37 -13
- package/lib/packlets/file-tree/fsTree.js +106 -11
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +37 -13
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +278 -20
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +15 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js +31 -0
- package/lib/packlets/file-tree/index.browser.d.ts +1 -0
- package/lib/packlets/file-tree/index.browser.js +1 -0
- package/lib/packlets/file-tree/index.d.ts +1 -0
- package/lib/packlets/file-tree/index.js +1 -0
- package/lib/packlets/json-file/file.d.ts +1 -1
- package/lib/packlets/json-file/file.js +1 -1
- package/lib/packlets/json-file/jsonFsHelper.d.ts +1 -1
- package/lib/packlets/json-file/jsonFsHelper.js +1 -1
- package/lib/packlets/validators/validators.d.ts +9 -9
- package/lib/packlets/validators/validators.js +8 -8
- package/package.json +29 -30
- package/dist/test/fixtures/file-tree/docs/api/reference.json +0 -1
|
@@ -94,6 +94,14 @@ class InMemoryDirectory {
|
|
|
94
94
|
this._children.set(name, child);
|
|
95
95
|
return (0, ts_utils_1.succeed)(child);
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Removes a child from the directory.
|
|
99
|
+
* @param name - The name of the child to remove.
|
|
100
|
+
* @returns `true` if the child was found and removed, `false` otherwise.
|
|
101
|
+
*/
|
|
102
|
+
removeChild(name) {
|
|
103
|
+
return this._children.delete(name);
|
|
104
|
+
}
|
|
97
105
|
/**
|
|
98
106
|
* Gets the absolute path for a child of this directory with the supplied
|
|
99
107
|
* name.
|
|
@@ -174,6 +182,29 @@ class TreeBuilder {
|
|
|
174
182
|
return (0, ts_utils_1.succeed)(file);
|
|
175
183
|
});
|
|
176
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Ensures a directory exists at the given absolute path, creating
|
|
187
|
+
* intermediate directories as needed.
|
|
188
|
+
* @param absolutePath - The absolute path of the directory.
|
|
189
|
+
* @returns `Success` with the directory if successful, or
|
|
190
|
+
* `Failure` with an error message otherwise.
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
addDirectory(absolutePath) {
|
|
194
|
+
const parts = absolutePath.split('/').filter((p) => p.length > 0);
|
|
195
|
+
let dir = this.root;
|
|
196
|
+
for (const part of parts) {
|
|
197
|
+
const result = dir.getOrAddDirectory(part);
|
|
198
|
+
if (result.isFailure()) {
|
|
199
|
+
return (0, ts_utils_1.fail)(result.message);
|
|
200
|
+
}
|
|
201
|
+
dir = result.value;
|
|
202
|
+
if (!this.byAbsolutePath.has(dir.absolutePath)) {
|
|
203
|
+
this.byAbsolutePath.set(dir.absolutePath, dir);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return (0, ts_utils_1.succeed)(dir);
|
|
207
|
+
}
|
|
177
208
|
}
|
|
178
209
|
exports.TreeBuilder = TreeBuilder;
|
|
179
210
|
//# sourceMappingURL=treeBuilder.js.map
|
|
@@ -2,6 +2,7 @@ export * from './fileTreeAccessors';
|
|
|
2
2
|
export * from './fileTree';
|
|
3
3
|
export * from './directoryItem';
|
|
4
4
|
export * from './fileItem';
|
|
5
|
+
export * from './filterSpec';
|
|
5
6
|
export * from './in-memory';
|
|
6
7
|
export { inMemory } from './fileTreeHelpers.inMemory';
|
|
7
8
|
//# sourceMappingURL=index.browser.d.ts.map
|
|
@@ -42,6 +42,7 @@ __exportStar(require("./fileTreeAccessors"), exports);
|
|
|
42
42
|
__exportStar(require("./fileTree"), exports);
|
|
43
43
|
__exportStar(require("./directoryItem"), exports);
|
|
44
44
|
__exportStar(require("./fileItem"), exports);
|
|
45
|
+
__exportStar(require("./filterSpec"), exports);
|
|
45
46
|
// Export in-memory implementations for web compatibility
|
|
46
47
|
__exportStar(require("./in-memory"), exports);
|
|
47
48
|
var fileTreeHelpers_inMemory_1 = require("./fileTreeHelpers.inMemory");
|
|
@@ -2,6 +2,7 @@ export * from './fileTreeAccessors';
|
|
|
2
2
|
export * from './fileTree';
|
|
3
3
|
export * from './directoryItem';
|
|
4
4
|
export * from './fileItem';
|
|
5
|
+
export * from './filterSpec';
|
|
5
6
|
export * from './fileTreeHelpers';
|
|
6
7
|
export { inMemory } from './fileTreeHelpers.inMemory';
|
|
7
8
|
export * from './in-memory';
|
|
@@ -41,6 +41,7 @@ __exportStar(require("./fileTreeAccessors"), exports);
|
|
|
41
41
|
__exportStar(require("./fileTree"), exports);
|
|
42
42
|
__exportStar(require("./directoryItem"), exports);
|
|
43
43
|
__exportStar(require("./fileItem"), exports);
|
|
44
|
+
__exportStar(require("./filterSpec"), exports);
|
|
44
45
|
// Export tree-shakeable helpers (filesystem ones will be shaken out if not used)
|
|
45
46
|
__exportStar(require("./fileTreeHelpers"), exports);
|
|
46
47
|
var fileTreeHelpers_inMemory_1 = require("./fileTreeHelpers.inMemory");
|
|
@@ -2,7 +2,7 @@ import { Converter, Result } from '@fgv/ts-utils';
|
|
|
2
2
|
import { JsonValue } from '../json';
|
|
3
3
|
import { IJsonFsDirectoryOptions, IJsonFsDirectoryToMapOptions, IReadDirectoryItem } from './jsonFsHelper';
|
|
4
4
|
/**
|
|
5
|
-
* {@
|
|
5
|
+
* {@inheritDoc JsonFile.JsonFsHelper.readJsonFileSync}
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
8
|
export declare function readJsonFileSync(srcPath: string): Result<JsonValue>;
|
|
@@ -29,7 +29,7 @@ exports.writeJsonFileSync = writeJsonFileSync;
|
|
|
29
29
|
const jsonFsHelper_1 = require("./jsonFsHelper");
|
|
30
30
|
const jsonLike_1 = require("./jsonLike");
|
|
31
31
|
/**
|
|
32
|
-
* {@
|
|
32
|
+
* {@inheritDoc JsonFile.JsonFsHelper.readJsonFileSync}
|
|
33
33
|
* @public
|
|
34
34
|
*/
|
|
35
35
|
function readJsonFileSync(srcPath) {
|
|
@@ -74,7 +74,7 @@ export declare class JsonFsHelper {
|
|
|
74
74
|
readonly config: IJsonFsHelperConfig;
|
|
75
75
|
/**
|
|
76
76
|
* Construct a new {@link JsonFile.JsonFsHelper | JsonFsHelper}.
|
|
77
|
-
* @param
|
|
77
|
+
* @param init - Optional {@link JsonFile.JsonFsHelperInitOptions | init options} to construct
|
|
78
78
|
* and JSON values.
|
|
79
79
|
*/
|
|
80
80
|
constructor(init?: JsonFsHelperInitOptions);
|
|
@@ -54,7 +54,7 @@ exports.DefaultJsonFsHelperConfig = {
|
|
|
54
54
|
class JsonFsHelper {
|
|
55
55
|
/**
|
|
56
56
|
* Construct a new {@link JsonFile.JsonFsHelper | JsonFsHelper}.
|
|
57
|
-
* @param
|
|
57
|
+
* @param init - Optional {@link JsonFile.JsonFsHelperInitOptions | init options} to construct
|
|
58
58
|
* and JSON values.
|
|
59
59
|
*/
|
|
60
60
|
constructor(init) {
|
|
@@ -38,42 +38,42 @@ export declare const jsonArray: Validator<JsonArray, IJsonValidatorContext>;
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const jsonValue: Validator<JsonValue, IJsonValidatorContext>;
|
|
40
40
|
/**
|
|
41
|
-
* A
|
|
41
|
+
* A `StringValidator` which validates a string in place.
|
|
42
42
|
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
45
|
export declare const string: Validation.Classes.StringValidator<string, IJsonValidatorContext>;
|
|
46
46
|
/**
|
|
47
|
-
* A
|
|
47
|
+
* A `NumberValidator` which validates a number in place.
|
|
48
48
|
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
49
49
|
* @public
|
|
50
50
|
*/
|
|
51
|
-
export declare const number:
|
|
51
|
+
export declare const number: Validation.Classes.NumberValidator<number, IJsonValidatorContext>;
|
|
52
52
|
/**
|
|
53
|
-
* A
|
|
54
|
-
* Accepts
|
|
53
|
+
* A `BooleanValidator` which validates a boolean in place.
|
|
54
|
+
* Accepts `IJsonValidatorContext` but ignores it.
|
|
55
55
|
* @public
|
|
56
56
|
*/
|
|
57
57
|
export declare const boolean: Validator<boolean, IJsonValidatorContext>;
|
|
58
58
|
/**
|
|
59
59
|
* Helper to create a validator for a literal value.
|
|
60
|
-
* Accepts
|
|
60
|
+
* Accepts `IJsonValidatorContext` but ignores it.
|
|
61
61
|
* Mirrors the behavior of `@fgv/ts-utils`.
|
|
62
62
|
* @public
|
|
63
63
|
*/
|
|
64
64
|
export declare function literal<T>(value: T): Validator<T, IJsonValidatorContext>;
|
|
65
65
|
/**
|
|
66
|
-
* Helper function to create a
|
|
66
|
+
* Helper function to create a `Validator` which validates `unknown` to one of a set of
|
|
67
67
|
* supplied enumerated values. Anything else fails.
|
|
68
68
|
*
|
|
69
69
|
* @remarks
|
|
70
|
-
* This JSON variant accepts an
|
|
70
|
+
* This JSON variant accepts an `IJsonValidatorContext` OR
|
|
71
71
|
* a `ReadonlyArray<T>` as its validation context. If the context is an array, it is used to override the
|
|
72
72
|
* allowed values for that validation; otherwise, the original `values` supplied at creation time are used.
|
|
73
73
|
*
|
|
74
74
|
* @param values - Array of allowed values.
|
|
75
75
|
* @param message - Optional custom failure message.
|
|
76
|
-
* @returns A new
|
|
76
|
+
* @returns A new `Validator` returning `<T>`.
|
|
77
77
|
* @public
|
|
78
78
|
*/
|
|
79
79
|
export declare function enumeratedValue<T>(values: ReadonlyArray<T>, message?: string): Validator<T, IJsonValidatorContext | ReadonlyArray<T>>;
|
|
@@ -125,26 +125,26 @@ exports.jsonValue = new ts_utils_1.Validation.Base.GenericValidator({
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
/**
|
|
128
|
-
* A
|
|
128
|
+
* A `StringValidator` which validates a string in place.
|
|
129
129
|
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
130
130
|
* @public
|
|
131
131
|
*/
|
|
132
132
|
exports.string = new ts_utils_1.Validation.Classes.StringValidator();
|
|
133
133
|
/**
|
|
134
|
-
* A
|
|
134
|
+
* A `NumberValidator` which validates a number in place.
|
|
135
135
|
* Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.
|
|
136
136
|
* @public
|
|
137
137
|
*/
|
|
138
138
|
exports.number = new ts_utils_1.Validation.Classes.NumberValidator();
|
|
139
139
|
/**
|
|
140
|
-
* A
|
|
141
|
-
* Accepts
|
|
140
|
+
* A `BooleanValidator` which validates a boolean in place.
|
|
141
|
+
* Accepts `IJsonValidatorContext` but ignores it.
|
|
142
142
|
* @public
|
|
143
143
|
*/
|
|
144
144
|
exports.boolean = new ts_utils_1.Validation.Classes.BooleanValidator();
|
|
145
145
|
/**
|
|
146
146
|
* Helper to create a validator for a literal value.
|
|
147
|
-
* Accepts
|
|
147
|
+
* Accepts `IJsonValidatorContext` but ignores it.
|
|
148
148
|
* Mirrors the behavior of `@fgv/ts-utils`.
|
|
149
149
|
* @public
|
|
150
150
|
*/
|
|
@@ -156,17 +156,17 @@ function literal(value) {
|
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
|
-
* Helper function to create a
|
|
159
|
+
* Helper function to create a `Validator` which validates `unknown` to one of a set of
|
|
160
160
|
* supplied enumerated values. Anything else fails.
|
|
161
161
|
*
|
|
162
162
|
* @remarks
|
|
163
|
-
* This JSON variant accepts an
|
|
163
|
+
* This JSON variant accepts an `IJsonValidatorContext` OR
|
|
164
164
|
* a `ReadonlyArray<T>` as its validation context. If the context is an array, it is used to override the
|
|
165
165
|
* allowed values for that validation; otherwise, the original `values` supplied at creation time are used.
|
|
166
166
|
*
|
|
167
167
|
* @param values - Array of allowed values.
|
|
168
168
|
* @param message - Optional custom failure message.
|
|
169
|
-
* @returns A new
|
|
169
|
+
* @returns A new `Validator` returning `<T>`.
|
|
170
170
|
* @public
|
|
171
171
|
*/
|
|
172
172
|
function enumeratedValue(values, message) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-json-base",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0-1",
|
|
4
4
|
"description": "Typescript types and basic functions for working with json",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-json-base.d.ts",
|
|
@@ -17,6 +17,17 @@
|
|
|
17
17
|
"types": "./dist/ts-json-base.d.ts"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "heft build --clean",
|
|
22
|
+
"clean": "heft clean",
|
|
23
|
+
"test": "heft test --clean",
|
|
24
|
+
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
25
|
+
"build-all": "rushx build; rushx build-docs",
|
|
26
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
27
|
+
"clean-jest": "jest --clear-cache",
|
|
28
|
+
"lint": "eslint src --ext .ts",
|
|
29
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
30
|
+
},
|
|
20
31
|
"keywords": [
|
|
21
32
|
"typescript",
|
|
22
33
|
"json"
|
|
@@ -29,37 +40,37 @@
|
|
|
29
40
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-json-base#readme",
|
|
30
41
|
"sideEffects": false,
|
|
31
42
|
"devDependencies": {
|
|
43
|
+
"@fgv/ts-utils": "workspace:*",
|
|
44
|
+
"@fgv/ts-utils-jest": "workspace:*",
|
|
32
45
|
"@types/jest": "^29.5.14",
|
|
33
46
|
"@types/node": "^20.14.9",
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
35
|
-
"@typescript-eslint/parser": "^8.
|
|
36
|
-
"eslint": "^9.39.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
48
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
49
|
+
"eslint": "^9.39.2",
|
|
37
50
|
"eslint-plugin-import": "^2.32.0",
|
|
38
51
|
"eslint-plugin-node": "^11.1.0",
|
|
39
52
|
"eslint-plugin-promise": "^7.2.1",
|
|
40
53
|
"jest": "^29.7.0",
|
|
41
54
|
"jest-extended": "^4.0.2",
|
|
42
|
-
"rimraf": "^6.1.
|
|
43
|
-
"ts-jest": "^29.4.
|
|
55
|
+
"rimraf": "^6.1.2",
|
|
56
|
+
"ts-jest": "^29.4.6",
|
|
44
57
|
"ts-node": "^10.9.2",
|
|
45
58
|
"typescript": "5.9.3",
|
|
46
59
|
"eslint-plugin-n": "^17.23.1",
|
|
47
|
-
"@rushstack/heft": "1.
|
|
48
|
-
"@rushstack/heft-jest-plugin": "1.
|
|
60
|
+
"@rushstack/heft": "1.2.6",
|
|
61
|
+
"@rushstack/heft-jest-plugin": "1.2.6",
|
|
49
62
|
"@types/heft-jest": "1.0.6",
|
|
50
|
-
"@microsoft/api-documenter": "^7.
|
|
63
|
+
"@microsoft/api-documenter": "^7.28.2",
|
|
51
64
|
"@rushstack/eslint-patch": "1.14.1",
|
|
52
|
-
"@rushstack/eslint-config": "4.
|
|
53
|
-
"eslint-plugin-tsdoc": "~0.
|
|
65
|
+
"@rushstack/eslint-config": "4.6.4",
|
|
66
|
+
"eslint-plugin-tsdoc": "~0.5.2",
|
|
54
67
|
"@types/luxon": "^3.7.1",
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@fgv/heft-dual-rig": "0.1.0",
|
|
59
|
-
"@fgv/ts-utils-jest": "5.0.2"
|
|
68
|
+
"@fgv/heft-dual-rig": "workspace:*",
|
|
69
|
+
"@rushstack/heft-node-rig": "2.11.26",
|
|
70
|
+
"@microsoft/api-extractor": "^7.55.2"
|
|
60
71
|
},
|
|
61
72
|
"peerDependencies": {
|
|
62
|
-
"@fgv/ts-utils": "
|
|
73
|
+
"@fgv/ts-utils": "workspace:*"
|
|
63
74
|
},
|
|
64
75
|
"dependencies": {
|
|
65
76
|
"luxon": "^3.7.2"
|
|
@@ -67,17 +78,5 @@
|
|
|
67
78
|
"repository": {
|
|
68
79
|
"type": "git",
|
|
69
80
|
"url": "https://github.com/ErikFortune/fgv.git"
|
|
70
|
-
},
|
|
71
|
-
"scripts": {
|
|
72
|
-
"build": "heft build --clean",
|
|
73
|
-
"clean": "heft clean",
|
|
74
|
-
"test": "heft test --clean",
|
|
75
|
-
"build-docs": "api-documenter markdown --input-folder ./temp --output-folder docs",
|
|
76
|
-
"build-all": "rushx build; rushx build-docs",
|
|
77
|
-
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
78
|
-
"clean-jest": "jest --clear-cache",
|
|
79
|
-
"coverage": "jest --coverage --no-cache",
|
|
80
|
-
"lint": "eslint src --ext .ts",
|
|
81
|
-
"fixlint": "eslint src --ext .ts --fix"
|
|
82
81
|
}
|
|
83
|
-
}
|
|
82
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "endpoints": [] }
|