@fgv/ts-json-base 5.0.0-3 → 5.0.0-30

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 (32) hide show
  1. package/CHANGELOG.json +0 -18
  2. package/README.md +150 -0
  3. package/dist/ts-json-base.d.ts +58 -2
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/eslint.config.js +16 -0
  6. package/lib/packlets/json/common.d.ts +56 -2
  7. package/lib/packlets/json/common.js +7 -3
  8. package/lib/packlets/validators/validators.js +4 -4
  9. package/package.json +18 -18
  10. package/CHANGELOG.md +0 -100
  11. package/lib/index.d.ts.map +0 -1
  12. package/lib/index.js.map +0 -1
  13. package/lib/packlets/converters/converters.d.ts.map +0 -1
  14. package/lib/packlets/converters/converters.js.map +0 -1
  15. package/lib/packlets/converters/index.d.ts.map +0 -1
  16. package/lib/packlets/converters/index.js.map +0 -1
  17. package/lib/packlets/json/common.d.ts.map +0 -1
  18. package/lib/packlets/json/common.js.map +0 -1
  19. package/lib/packlets/json/index.d.ts.map +0 -1
  20. package/lib/packlets/json/index.js.map +0 -1
  21. package/lib/packlets/json-file/file.d.ts.map +0 -1
  22. package/lib/packlets/json-file/file.js.map +0 -1
  23. package/lib/packlets/json-file/index.d.ts.map +0 -1
  24. package/lib/packlets/json-file/index.js.map +0 -1
  25. package/lib/packlets/json-file/jsonFsHelper.d.ts.map +0 -1
  26. package/lib/packlets/json-file/jsonFsHelper.js.map +0 -1
  27. package/lib/packlets/json-file/jsonLike.d.ts.map +0 -1
  28. package/lib/packlets/json-file/jsonLike.js.map +0 -1
  29. package/lib/packlets/validators/index.d.ts.map +0 -1
  30. package/lib/packlets/validators/index.js.map +0 -1
  31. package/lib/packlets/validators/validators.d.ts.map +0 -1
  32. package/lib/packlets/validators/validators.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -1,24 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-json-base",
3
3
  "entries": [
4
- {
5
- "version": "5.0.0",
6
- "tag": "@fgv/ts-json-base_v5.0.0",
7
- "date": "Thu, 17 Jul 2025 00:13:24 GMT",
8
- "comments": {
9
- "none": [
10
- {
11
- "comment": "add sanitizeJsonObject"
12
- },
13
- {
14
- "comment": "upgrade dependencies"
15
- },
16
- {
17
- "comment": "bump version"
18
- }
19
- ]
20
- }
21
- },
22
4
  {
23
5
  "version": "4.6.0",
24
6
  "tag": "@fgv/ts-json-base_v4.6.0",
package/README.md CHANGED
@@ -32,3 +32,153 @@ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
32
32
  interface JsonArray extends Array<JsonValue> { }
33
33
  ```
34
34
 
35
+ ### JsonCompatible Type
36
+
37
+ The `JsonCompatible<T>` type provides compile-time validation that a type is JSON-serializable, unlike `JsonValue` which requires an index signature. This is particularly useful for strongly-typed interfaces.
38
+
39
+ #### Basic Usage
40
+
41
+ ```typescript
42
+ import { JsonCompatible } from '@fgv/ts-json-base';
43
+
44
+ // ✅ JSON-compatible interface
45
+ interface UserData {
46
+ id: string;
47
+ name: string;
48
+ preferences: {
49
+ theme: 'light' | 'dark';
50
+ notifications: boolean;
51
+ };
52
+ }
53
+
54
+ // ✅ This type remains unchanged because it's fully JSON-compatible
55
+ type ValidatedUserData = JsonCompatible<UserData>;
56
+
57
+ // ❌ Interface with non-JSON properties
58
+ interface UserWithMethods {
59
+ id: string;
60
+ name: string;
61
+ save(): Promise<void>; // Functions are not JSON-serializable
62
+ }
63
+
64
+ // ❌ This type transforms 'save' to an error type
65
+ type InvalidUserData = JsonCompatible<UserWithMethods>;
66
+ // Result: { id: string; name: string; save: ['Error: Function is not JSON-compatible'] }
67
+ ```
68
+
69
+ #### The MapOf Pattern
70
+
71
+ The most powerful application is using `JsonCompatible<T>` as a constraint with default type parameters:
72
+
73
+ ```typescript
74
+ class MapOf<T, TV extends JsonCompatible<T> = JsonCompatible<T>> extends Map<string, TV> {
75
+ public override set(key: string, value: TV): this {
76
+ return super.set(key, value);
77
+ }
78
+ }
79
+
80
+ // ✅ Works perfectly with JSON-compatible types
81
+ const userMap = new MapOf<UserData>();
82
+ userMap.set('user1', {
83
+ id: 'user1',
84
+ name: 'Alice',
85
+ preferences: { theme: 'dark', notifications: true }
86
+ });
87
+
88
+ // ❌ Prevents usage with non-JSON-compatible types
89
+ const badMap = new MapOf<UserWithMethods>();
90
+ // The 'save' method becomes type 'never', making the interface unusable
91
+ ```
92
+
93
+ #### Real-World Examples
94
+
95
+ **API Response Caching:**
96
+ ```typescript
97
+ interface ApiResponse {
98
+ id: string;
99
+ data: unknown;
100
+ timestamp: number;
101
+ metadata: Record<string, string | number>;
102
+ }
103
+
104
+ class ApiCache extends MapOf<ApiResponse> {
105
+ setWithTTL(key: string, response: ApiResponse, ttlMs: number) {
106
+ this.set(key, response);
107
+ setTimeout(() => this.delete(key), ttlMs);
108
+ }
109
+ }
110
+ ```
111
+
112
+ **Configuration Management:**
113
+ ```typescript
114
+ interface AppConfig {
115
+ features: Record<string, boolean>;
116
+ limits: {
117
+ maxUsers: number;
118
+ maxStorage: number;
119
+ };
120
+ ui: {
121
+ theme: 'light' | 'dark';
122
+ language: string;
123
+ };
124
+ }
125
+
126
+ // Ensures config is always serializable for storage/transmission
127
+ const configStore = new MapOf<AppConfig>();
128
+ ```
129
+
130
+ **Data Transfer Objects:**
131
+ ```typescript
132
+ // ✅ Perfect for DTOs - no methods, just data
133
+ interface CreateUserRequest {
134
+ name: string;
135
+ email: string;
136
+ preferences?: {
137
+ newsletter: boolean;
138
+ theme: string;
139
+ };
140
+ }
141
+
142
+ const requestCache = new MapOf<CreateUserRequest>();
143
+
144
+ // ❌ Domain objects with behavior are rejected
145
+ interface User extends CreateUserRequest {
146
+ id: string;
147
+ save(): Promise<void>;
148
+ validate(): boolean;
149
+ }
150
+
151
+ // This won't work - methods become 'never'
152
+ // const userStore = new MapOf<User>();
153
+ ```
154
+
155
+ #### Array and Nested Validation
156
+
157
+ ```typescript
158
+ // ✅ Arrays of JSON-compatible types work fine
159
+ interface DataStructure {
160
+ numbers: number[];
161
+ objects: Array<{ id: number; name: string }>;
162
+ matrix: number[][];
163
+ }
164
+
165
+ const dataMap = new MapOf<DataStructure>();
166
+
167
+ // ❌ Arrays with functions are detected
168
+ interface WithHandlers {
169
+ callbacks: Array<() => void>; // Functions in arrays also become 'never'
170
+ data: string[];
171
+ }
172
+
173
+ // The 'callbacks' property becomes Array<['Error: Function is not JSON-compatible']>
174
+ const handlersMap = new MapOf<WithHandlers>();
175
+ ```
176
+
177
+ #### Benefits
178
+
179
+ 1. **Compile-time safety**: Non-serializable types are caught during development
180
+ 2. **Clear interfaces**: Makes it obvious which types are meant for serialization
181
+ 3. **Architecture enforcement**: Separates data objects from behavior objects
182
+ 4. **Runtime protection**: Prevents serialization errors in production
183
+ 5. **IDE support**: Full autocomplete and error highlighting
184
+
@@ -153,8 +153,8 @@ export declare function isJsonArray(from: unknown): from is JsonArray;
153
153
  /**
154
154
  * Test if an `unknown` is potentially a {@link JsonObject | JsonObject}.
155
155
  * @param from - The `unknown` to be tested.
156
- * @returns `true` if the supplied parameter is a non-array, non-special object,
157
- * `false` otherwise.
156
+ * @returns `true` if the supplied parameter is a non-array, non-special object
157
+ * with no symbol keys, `false` otherwise.
158
158
  * @public
159
159
  */
160
160
  export declare function isJsonObject(from: unknown): from is JsonObject;
@@ -168,6 +168,11 @@ export declare function isJsonObject(from: unknown): from is JsonObject;
168
168
  */
169
169
  export declare function isJsonPrimitive(from: unknown): from is JsonPrimitive;
170
170
 
171
+ /**
172
+ * Helper type to detect if T is exactly unknown.
173
+ */
174
+ declare type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false;
175
+
171
176
  /**
172
177
  * Function to transform the name of a some entity, given an original name
173
178
  * and the contents of the entity.
@@ -202,6 +207,57 @@ declare const jsonArray: Converter<JsonArray, IJsonConverterContext>;
202
207
  */
203
208
  declare const jsonArray_2: Validator<JsonArray, IJsonValidatorContext>;
204
209
 
210
+ /**
211
+ * A constrained type that is compatible with JSON serialization.
212
+ *
213
+ * This type transforms input types to ensure they can be safely serialized to JSON:
214
+ * - JSON primitives (string, number, boolean, null) are preserved as-is
215
+ * - `undefined` is allowed for TypeScript compatibility with optional properties
216
+ * - Objects are recursively transformed with all properties made JSON-compatible
217
+ * - Arrays are transformed to contain only JSON-compatible elements
218
+ * - Functions are transformed to error types
219
+ * - Other non-JSON types are transformed to error types
220
+ *
221
+ * Note: While `undefined` is technically not JSON-serializable, it's allowed here
222
+ * to support TypeScript's optional property patterns. Use `sanitizeJsonObject`
223
+ * to remove undefined properties before actual JSON serialization.
224
+ *
225
+ * @param T - The type to be constrained
226
+ * @returns A constrained type that is compatible with JSON serialization.
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * interface IUser {
231
+ * name: string;
232
+ * email?: string; // Optional property can be undefined
233
+ * }
234
+ *
235
+ * type UserCompatible = JsonCompatible<IUser>; // Allows undefined for email
236
+ *
237
+ * const user: UserCompatible = {
238
+ * name: "John",
239
+ * email: undefined // This works
240
+ * };
241
+ *
242
+ * // Before JSON serialization, sanitize to remove undefined:
243
+ * const sanitized = sanitizeJsonObject(user); // Removes undefined properties
244
+ * JSON.stringify(sanitized.value); // Safe to serialize
245
+ * ```
246
+ *
247
+ * @public
248
+ */
249
+ export declare type JsonCompatible<T> = IsUnknown<T> extends true ? JsonValue : T extends JsonPrimitive | undefined ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
250
+ [K in keyof T]: JsonCompatible<T[K]>;
251
+ } : ['Error: Non-JSON type'];
252
+
253
+ /**
254
+ * A type that represents an array of JSON-compatible values.
255
+ * @param T - The type to be constrained
256
+ * @returns A constrained type that is compatible with JSON serialization.
257
+ * @public
258
+ */
259
+ export declare type JsonCompatibleArray<T> = Array<JsonCompatible<T>>;
260
+
205
261
  declare namespace JsonFile {
206
262
  export {
207
263
  readJsonFileSync,
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.8"
8
+ "packageVersion": "7.52.12"
9
9
  }
10
10
  ]
11
11
  }
@@ -0,0 +1,16 @@
1
+ // ESLint 9 flat config
2
+ const nodeProfile = require('@rushstack/eslint-config/flat/profile/node');
3
+ const packletsPlugin = require('@rushstack/eslint-config/flat/mixins/packlets');
4
+ const tsdocPlugin = require('@rushstack/eslint-config/flat/mixins/tsdoc');
5
+
6
+ module.exports = [
7
+ ...nodeProfile,
8
+ packletsPlugin,
9
+ ...tsdocPlugin,
10
+ {
11
+ // Override specific rules if needed
12
+ rules: {
13
+ '@rushstack/packlets/mechanics': 'warn'
14
+ }
15
+ }
16
+ ];
@@ -29,6 +29,59 @@ export interface JsonArray extends Array<JsonValue> {
29
29
  * @public
30
30
  */
31
31
  export type JsonValueType = 'primitive' | 'object' | 'array';
32
+ /**
33
+ * Helper type to detect if T is exactly unknown.
34
+ */
35
+ type IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false;
36
+ /**
37
+ * A constrained type that is compatible with JSON serialization.
38
+ *
39
+ * This type transforms input types to ensure they can be safely serialized to JSON:
40
+ * - JSON primitives (string, number, boolean, null) are preserved as-is
41
+ * - `undefined` is allowed for TypeScript compatibility with optional properties
42
+ * - Objects are recursively transformed with all properties made JSON-compatible
43
+ * - Arrays are transformed to contain only JSON-compatible elements
44
+ * - Functions are transformed to error types
45
+ * - Other non-JSON types are transformed to error types
46
+ *
47
+ * Note: While `undefined` is technically not JSON-serializable, it's allowed here
48
+ * to support TypeScript's optional property patterns. Use `sanitizeJsonObject`
49
+ * to remove undefined properties before actual JSON serialization.
50
+ *
51
+ * @param T - The type to be constrained
52
+ * @returns A constrained type that is compatible with JSON serialization.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * interface IUser {
57
+ * name: string;
58
+ * email?: string; // Optional property can be undefined
59
+ * }
60
+ *
61
+ * type UserCompatible = JsonCompatible<IUser>; // Allows undefined for email
62
+ *
63
+ * const user: UserCompatible = {
64
+ * name: "John",
65
+ * email: undefined // This works
66
+ * };
67
+ *
68
+ * // Before JSON serialization, sanitize to remove undefined:
69
+ * const sanitized = sanitizeJsonObject(user); // Removes undefined properties
70
+ * JSON.stringify(sanitized.value); // Safe to serialize
71
+ * ```
72
+ *
73
+ * @public
74
+ */
75
+ export type JsonCompatible<T> = IsUnknown<T> extends true ? JsonValue : T extends JsonPrimitive | undefined ? T : T extends Array<unknown> ? JsonCompatibleArray<T[number]> : T extends Function ? ['Error: Function is not JSON-compatible'] : T extends object ? {
76
+ [K in keyof T]: JsonCompatible<T[K]>;
77
+ } : ['Error: Non-JSON type'];
78
+ /**
79
+ * A type that represents an array of JSON-compatible values.
80
+ * @param T - The type to be constrained
81
+ * @returns A constrained type that is compatible with JSON serialization.
82
+ * @public
83
+ */
84
+ export type JsonCompatibleArray<T> = Array<JsonCompatible<T>>;
32
85
  /**
33
86
  * Test if an `unknown` is a {@link JsonValue | JsonValue}.
34
87
  * @param from - The `unknown` to be tested
@@ -40,8 +93,8 @@ export declare function isJsonPrimitive(from: unknown): from is JsonPrimitive;
40
93
  /**
41
94
  * Test if an `unknown` is potentially a {@link JsonObject | JsonObject}.
42
95
  * @param from - The `unknown` to be tested.
43
- * @returns `true` if the supplied parameter is a non-array, non-special object,
44
- * `false` otherwise.
96
+ * @returns `true` if the supplied parameter is a non-array, non-special object
97
+ * with no symbol keys, `false` otherwise.
45
98
  * @public
46
99
  */
47
100
  export declare function isJsonObject(from: unknown): from is JsonObject;
@@ -101,4 +154,5 @@ export declare function sanitizeJson(from: unknown): Result<JsonValue>;
101
154
  * @public
102
155
  */
103
156
  export declare function sanitizeJsonObject<T>(from: T): Result<T>;
157
+ export {};
104
158
  //# sourceMappingURL=common.d.ts.map
@@ -43,8 +43,8 @@ function isJsonPrimitive(from) {
43
43
  /**
44
44
  * Test if an `unknown` is potentially a {@link JsonObject | JsonObject}.
45
45
  * @param from - The `unknown` to be tested.
46
- * @returns `true` if the supplied parameter is a non-array, non-special object,
47
- * `false` otherwise.
46
+ * @returns `true` if the supplied parameter is a non-array, non-special object
47
+ * with no symbol keys, `false` otherwise.
48
48
  * @public
49
49
  */
50
50
  function isJsonObject(from) {
@@ -52,7 +52,11 @@ function isJsonObject(from) {
52
52
  from !== null &&
53
53
  !Array.isArray(from) &&
54
54
  !(from instanceof RegExp) &&
55
- !(from instanceof Date));
55
+ !(from instanceof Date) &&
56
+ !(from instanceof Map) &&
57
+ !(from instanceof Set) &&
58
+ !(from instanceof Error) &&
59
+ Object.getOwnPropertySymbols(from).length === 0);
56
60
  }
57
61
  /**
58
62
  * Test if an `unknown` is potentially a {@link JsonArray | JsonArray}.
@@ -30,7 +30,7 @@ const json_1 = require("../json");
30
30
  * @public
31
31
  */
32
32
  exports.jsonPrimitive = new ts_utils_1.Validation.Base.GenericValidator({
33
- validator: (from, ctx) => {
33
+ validator: (from, ctx, self) => {
34
34
  if (from === null) {
35
35
  return true;
36
36
  }
@@ -58,7 +58,7 @@ exports.jsonPrimitive = new ts_utils_1.Validation.Base.GenericValidator({
58
58
  * @public
59
59
  */
60
60
  exports.jsonObject = new ts_utils_1.Validation.Base.GenericValidator({
61
- validator: (from, ctx) => {
61
+ validator: (from, ctx, self) => {
62
62
  if (!(0, json_1.isJsonObject)(from)) {
63
63
  return (0, ts_utils_1.fail)('not a valid JSON object.');
64
64
  }
@@ -83,7 +83,7 @@ exports.jsonObject = new ts_utils_1.Validation.Base.GenericValidator({
83
83
  * @public
84
84
  */
85
85
  exports.jsonArray = new ts_utils_1.Validation.Base.GenericValidator({
86
- validator: (from, ctx) => {
86
+ validator: (from, ctx, self) => {
87
87
  if (!(0, json_1.isJsonArray)(from)) {
88
88
  return (0, ts_utils_1.fail)('not an array');
89
89
  }
@@ -109,7 +109,7 @@ exports.jsonArray = new ts_utils_1.Validation.Base.GenericValidator({
109
109
  * @public
110
110
  */
111
111
  exports.jsonValue = new ts_utils_1.Validation.Base.GenericValidator({
112
- validator: (from, ctx) => {
112
+ validator: (from, ctx, self) => {
113
113
  if ((0, json_1.isJsonArray)(from)) {
114
114
  const result = exports.jsonArray.validate(from, ctx);
115
115
  return result.success === true ? true : result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-json-base",
3
- "version": "5.0.0-3",
3
+ "version": "5.0.0-30",
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",
@@ -18,33 +18,33 @@
18
18
  "devDependencies": {
19
19
  "@types/jest": "^29.5.14",
20
20
  "@types/node": "^20.14.9",
21
- "@typescript-eslint/eslint-plugin": "^7.14.1",
22
- "@typescript-eslint/parser": "^7.14.1",
23
- "eslint": "^8.57.0",
21
+ "@typescript-eslint/eslint-plugin": "^8.42.0",
22
+ "@typescript-eslint/parser": "^8.42.0",
23
+ "eslint": "^9.35.0",
24
24
  "eslint-plugin-import": "^2.32.0",
25
25
  "eslint-plugin-node": "^11.1.0",
26
- "eslint-plugin-promise": "^6.2.0",
26
+ "eslint-plugin-promise": "^7.2.1",
27
27
  "jest": "^29.7.0",
28
28
  "jest-extended": "^4.0.2",
29
- "rimraf": "^5.0.7",
30
- "ts-jest": "^29.4.0",
29
+ "rimraf": "^6.0.1",
30
+ "ts-jest": "^29.4.1",
31
31
  "ts-node": "^10.9.2",
32
- "typescript": "^5.7.3",
33
- "eslint-plugin-n": "^16.6.2",
34
- "@rushstack/heft-node-rig": "~2.9.0",
35
- "@rushstack/heft": "~0.74.0",
36
- "heft-jest": "~1.0.2",
32
+ "typescript": "5.8.3",
33
+ "eslint-plugin-n": "^17.21.3",
34
+ "@rushstack/heft-node-rig": "2.9.5",
35
+ "@rushstack/heft": "0.74.4",
36
+ "@rushstack/heft-jest-plugin": "0.16.13",
37
37
  "@types/heft-jest": "1.0.6",
38
- "@microsoft/api-documenter": "^7.26.29",
38
+ "@microsoft/api-documenter": "^7.26.31",
39
39
  "@rushstack/eslint-patch": "~1.12.0",
40
- "@rushstack/eslint-config": "~4.4.0",
40
+ "@rushstack/eslint-config": "4.4.0",
41
41
  "eslint-plugin-tsdoc": "~0.4.0",
42
- "@fgv/ts-utils": "5.0.0-3",
43
- "@fgv/ts-utils-jest": "5.0.0-3",
44
- "@fgv/ts-extras": "5.0.0-3"
42
+ "@fgv/ts-utils": "5.0.0-30",
43
+ "@fgv/ts-utils-jest": "5.0.0-30",
44
+ "@fgv/ts-extras": "5.0.0-30"
45
45
  },
46
46
  "peerDependencies": {
47
- "@fgv/ts-utils": "5.0.0-3"
47
+ "@fgv/ts-utils": "5.0.0-30"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "heft test --clean",
package/CHANGELOG.md DELETED
@@ -1,100 +0,0 @@
1
- # Change Log - @fgv/ts-json-base
2
-
3
- This log was last generated on Thu, 17 Jul 2025 00:13:24 GMT and should not be manually modified.
4
-
5
- ## 5.0.0
6
- Thu, 17 Jul 2025 00:13:24 GMT
7
-
8
- ### Updates
9
-
10
- - add sanitizeJsonObject
11
- - upgrade dependencies
12
- - bump version
13
-
14
- ## 4.6.0
15
- Wed, 02 Jul 2025 05:48:16 GMT
16
-
17
- _Version update only_
18
-
19
- ## 4.5.1
20
- Wed, 02 Jul 2025 05:47:11 GMT
21
-
22
- ### Updates
23
-
24
- - update rushstack
25
-
26
- ## 4.5.0
27
- Tue, 01 Jul 2025 03:26:11 GMT
28
-
29
- _Version update only_
30
-
31
- ## 4.4.0
32
- Sat, 01 Feb 2025 17:13:10 GMT
33
-
34
- _Version update only_
35
-
36
- ## 4.3.0
37
- Thu, 30 Jan 2025 00:35:17 GMT
38
-
39
- _Version update only_
40
-
41
- ## 4.2.2
42
- Thu, 23 Jan 2025 06:19:32 GMT
43
-
44
- _Version update only_
45
-
46
- ## 4.2.1
47
- Tue, 21 Jan 2025 04:19:21 GMT
48
-
49
- _Version update only_
50
-
51
- ## 4.2.0
52
- Mon, 20 Jan 2025 09:46:53 GMT
53
-
54
- ### Updates
55
-
56
- - plumb conversion context through
57
-
58
- ## 4.1.0
59
- Thu, 09 Jan 2025 05:33:39 GMT
60
-
61
- ### Updates
62
-
63
- - update dependencies
64
-
65
- ## 4.0.2
66
- Tue, 14 May 2024 14:45:53 GMT
67
-
68
- _Version update only_
69
-
70
- ## 4.0.1
71
- Tue, 14 May 2024 05:02:20 GMT
72
-
73
- ### Updates
74
-
75
- - publish
76
-
77
- ## 4.0.0
78
- Tue, 14 May 2024 03:09:27 GMT
79
-
80
- ### Updates
81
-
82
- - clean up and renaming in JSON file helpers
83
- - update generated api docs
84
- - generalize fs helper to enable yaml
85
-
86
- ## 3.0.0
87
- Mon, 22 Jan 2024 07:00:18 GMT
88
-
89
- ### Updates
90
-
91
- - add validators
92
- - initial refactor
93
-
94
- ## 2.2.0
95
- Thu, 18 Jan 2024 05:45:04 GMT
96
-
97
- ### Updates
98
-
99
- - initial refactor
100
-
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAoD;AAK3C,gCAAU;AAJnB,+DAAiD;AAI5B,4BAAQ;AAH7B,kEAAoD;AAGrB,gCAAU;AADzC,kDAAgC","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 * as Converters from './packlets/converters';\nimport * as JsonFile from './packlets/json-file';\nimport * as Validators from './packlets/validators';\n\nexport * from './packlets/json';\nexport { Converters, JsonFile, Validators };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/converters.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAc,SAAS,EAAyB,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAA6B,MAAM,SAAS,CAAC;AAIrG;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,aAAa,EAAE,qBAAqB,CAqBzE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,qBAAqB,CAgCnE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,qBAAqB,CAkCjE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,qBAAqB,CAgBjE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/converters/converters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAA6E;AAC7E,kCAAqG;AAYrG;;;GAGG;AACU,QAAA,aAAa,GAAoD,IAAI,qBAAU,CAAC,aAAa,CACxG,CACE,IAAa,EACb,MAAuD,EACvD,GAA2B,EACJ,EAAE;IACzB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,QAAQ,OAAO,IAAI,EAAE,CAAC;QACpB,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,KAAK,QAAQ;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;YACvB,CAAC;YACD,MAAM;IACV,CAAC;IACD,OAAO,IAAA,eAAI,EAAC,IAAI,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AAChE,CAAC,CACF,CAAC;AAEF;;;;;;;;GAQG;AACU,QAAA,UAAU,GAAiD,IAAI,qBAAU,CAAC,aAAa,CAClG,CACE,IAAa,EACb,MAAoD,EACpD,GAA2B,EACP,EAAE;IACtB,IAAI,CAAC,IAAA,mBAAY,EAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAA,eAAI,EAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,GAAG,GAAe,EAAE,CA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AAG,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,IAAA,mBAAY,EAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,OAAO,kBAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,qBAAa,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC1C,CAAC,CACF,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 { Conversion, Converter, Result, fail, succeed } from '@fgv/ts-utils';\nimport { JsonArray, JsonObject, JsonPrimitive, JsonValue, isJsonArray, isJsonObject } from '../json';\n\n/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\n\n/**\n * Conversion context for JSON converters.\n * @public\n */\nexport interface IJsonConverterContext {\n ignoreUndefinedProperties?: boolean;\n}\n\n/**\n * An converter which converts a supplied `unknown` value to a valid {@link JsonPrimitive | JsonPrimitive}.\n * @public\n */\nexport const jsonPrimitive: Converter<JsonPrimitive, IJsonConverterContext> = new Conversion.BaseConverter(\n (\n from: unknown,\n __self: Converter<JsonPrimitive, IJsonConverterContext>,\n ctx?: IJsonConverterContext\n ): Result<JsonPrimitive> => {\n if (from === null) {\n return succeed(null);\n }\n switch (typeof from) {\n case 'boolean':\n case 'string':\n return succeed(from);\n case 'number':\n if (!Number.isNaN(from)) {\n return succeed(from);\n }\n break;\n }\n return fail(`\"${String(from)}\": not a valid JSON primitive.`);\n }\n);\n\n/**\n * An copying converter which converts a supplied `unknown` value into\n * a valid {@link JsonObject | JsonObject}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Converters.IJsonConverterContext | context} at runtime.\n *\n * Guaranteed to return a new object.\n * @public\n */\nexport const jsonObject: Converter<JsonObject, IJsonConverterContext> = new Conversion.BaseConverter(\n (\n from: unknown,\n __self: Converter<JsonObject, IJsonConverterContext>,\n ctx?: IJsonConverterContext\n ): Result<JsonObject> => {\n if (!isJsonObject(from)) {\n return fail('not a valid JSON object.');\n }\n const obj: JsonObject = {};\n const errors: string[] = [];\n for (const [name, value] of Object.entries(from)) {\n if (value === undefined && ctx?.ignoreUndefinedProperties === true) {\n // optionally ignore undefined values\n continue;\n }\n jsonValue\n .convert(value, ctx)\n .onSuccess((v: JsonValue) => {\n obj[name] = v;\n return succeed(v);\n })\n .onFailure((m) => {\n errors.push(`${name}: ${m}`);\n return fail(m);\n });\n }\n if (errors.length > 0) {\n return fail(`not a valid JSON object:\\n${errors.join('\\n')}`);\n }\n return succeed(obj);\n }\n);\n\n/**\n * An copying converter which converts a supplied `unknown` value to\n * a valid {@link JsonArray | JsonArray}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Converters.IJsonConverterContext | context} at runtime.\n *\n * Guaranteed to return a new array.\n * @public\n */\nexport const jsonArray: Converter<JsonArray, IJsonConverterContext> = new Conversion.BaseConverter(\n (\n from: unknown,\n __self: Converter<JsonArray, IJsonConverterContext>,\n ctx?: IJsonConverterContext\n ): Result<JsonArray> => {\n if (!isJsonArray(from)) {\n return fail('not an array');\n }\n const arr: JsonValue[] = [];\n const errors: string[] = [];\n for (let i = 0; i < from.length; i++) {\n const value = from[i];\n if (value === undefined && ctx?.ignoreUndefinedProperties === true) {\n // convert undefined to 'null' for parity with JSON.stringify\n arr.push(null);\n continue;\n }\n jsonValue\n .convert(value, ctx)\n .onSuccess((v) => {\n arr.push(v);\n return succeed(v);\n })\n .onFailure((m) => {\n errors.push(`${i}: ${m}`);\n return fail(m);\n });\n }\n if (errors.length > 0) {\n return fail(`array contains non-json elements:\\n${errors.join('\\n')}`);\n }\n return succeed(arr);\n }\n);\n\n/**\n * An copying converter which converts a supplied `unknown` value to a\n * valid {@link JsonValue | JsonValue}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Converters.IJsonConverterContext | context} at runtime.\n * @public\n */\nexport const jsonValue: Converter<JsonValue, IJsonConverterContext> = new Conversion.BaseConverter<\n JsonValue,\n IJsonConverterContext\n>(\n (\n from: unknown,\n __self: Converter<JsonValue, IJsonConverterContext>,\n ctx?: IJsonConverterContext\n ): Result<JsonValue> => {\n if (isJsonArray(from)) {\n return jsonArray.convert(from, ctx);\n } else if (isJsonObject(from)) {\n return jsonObject.convert(from, ctx);\n }\n return jsonPrimitive.convert(from, ctx);\n }\n);\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":"AAsBA,cAAc,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,+CAA6B","sourcesContent":["/*\n * Copyright (c) 2020 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 './converters';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/json/common.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AAIrE;;;GAGG;AAEH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE7D;;;;GAIG;AAEH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/D;;;GAGG;AAEH,MAAM,WAAW,SAAU,SAAQ,KAAK,CAAC,SAAS,CAAC;CAAG;AAEtD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE7D;;;;;;GAMG;AACH,wBA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A,eAAI,EAAC,GAAG,IAAI,YAAY,IAAI,kBAAkB,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAA,eAAI,EAAC,GAAG,IAAI,YAAY,IAAI,kBAAkB,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAAC,GAAe,EAAE,IAAY;IAC1D,OAAO,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;QAC9C,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,OAAO,IAAA,eAAI,EAAC,GAAG,IAAI,iBAAiB,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,IAAa;IACxC,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAI,IAAO;IAC3C,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 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 '@fgv/ts-utils';\n\n/* eslint-disable no-use-before-define */\n\n/**\n * Primitive (terminal) values allowed in by JSON.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type JsonPrimitive = boolean | number | string | null;\n\n/**\n * A {@link JsonObject | JsonObject} is a string-keyed object\n * containing only valid {@link JsonValue | JSON values}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface JsonObject {\n [key: string]: JsonValue;\n}\n\n/**\n * A {@link JsonValue | JsonValue} is one of: a {@link JsonPrimitive | JsonPrimitive},\n * a {@link JsonObject | JsonObject} or an {@link JsonArray | JsonArray}.\n * @public\n */\nexport type JsonValue = JsonPrimitive | JsonObject | JsonArray;\n\n/**\n * A {@link JsonArray | JsonArray} is an array containing only valid {@link JsonValue | JsonValues}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/naming-convention\nexport interface JsonArray extends Array<JsonValue> {}\n\n/**\n * Classes of {@link JsonValue | JsonValue}.\n * @public\n */\nexport type JsonValueType = 'primitive' | 'object' | 'array';\n\n/**\n * Test if an `unknown` is a {@link JsonValue | JsonValue}.\n * @param from - The `unknown` to be tested\n * @returns `true` if the supplied parameter is a valid {@link JsonPrimitive | JsonPrimitive},\n * `false` otherwise.\n * @public\n */\nexport function isJsonPrimitive(from: unknown): from is JsonPrimitive {\n return typeof from === 'boolean' || typeof from === 'number' || typeof from === 'string' || from === null;\n}\n\n/**\n * Test if an `unknown` is potentially a {@link JsonObject | JsonObject}.\n * @param from - The `unknown` to be tested.\n * @returns `true` if the supplied parameter is a non-array, non-special object,\n * `false` otherwise.\n * @public\n */\nexport function isJsonObject(from: unknown): from is JsonObject {\n return (\n typeof from === 'object' &&\n from !== null &&\n !Array.isArray(from) &&\n !(from instanceof RegExp) &&\n !(from instanceof Date)\n );\n}\n\n/**\n * Test if an `unknown` is potentially a {@link JsonArray | JsonArray}.\n * @param from - The `unknown` to be tested.\n * @returns `true` if the supplied parameter is an array object,\n * `false` otherwise.\n * @public\n */\nexport function isJsonArray(from: unknown): from is JsonArray {\n return typeof from === 'object' && Array.isArray(from);\n}\n\n/**\n * Identifies whether some `unknown` value is a {@link JsonPrimitive | primitive},\n * {@link JsonObject | object} or {@link JsonArray | array}. Fails for any value\n * that cannot be converted to JSON (e.g. a function) _but_ this is a shallow test -\n * it does not test the properties of an object or elements in an array.\n * @param from - The `unknown` value to be tested\n * @public\n */\nexport function classifyJsonValue(from: unknown): Result<JsonValueType> {\n if (isJsonPrimitive(from)) {\n return succeed('primitive');\n } else if (isJsonObject(from)) {\n return succeed('object');\n } else if (isJsonArray(from)) {\n return succeed('array');\n }\n return fail(`Invalid JSON: ${from}`);\n}\n\n/**\n * Picks a nested field from a supplied {@link JsonObject | JsonObject}.\n * @param src - The {@link JsonObject | object} from which the field is to be picked.\n * @param path - Dot-separated path of the member to be picked.\n * @returns `Success` with the property if the path is valid, `Failure`\n * with an error message otherwise.\n * @public\n */\nexport function pickJsonValue(src: JsonObject, path: string): Result<JsonValue> {\n let result: JsonValue = src;\n for (const part of path.split('.')) {\n if (result && isJsonObject(result)) {\n result = result[part];\n if (result === undefined) {\n return fail(`${path}: child '${part}' does not exist`);\n }\n } else {\n return fail(`${path}: child '${part}' does not exist`);\n }\n }\n return succeed(result);\n}\n\n/**\n * Picks a nested {@link JsonObject | JsonObject} from a supplied\n * {@link JsonObject | JsonObject}.\n * @param src - The {@link JsonObject | object} from which the field is\n * to be picked.\n * @param path - Dot-separated path of the member to be picked.\n * @returns `Success` with the property if the path is valid and the value\n * is an object. Returns `Failure` with details if an error occurs.\n * @public\n */\nexport function pickJsonObject(src: JsonObject, path: string): Result<JsonObject> {\n return pickJsonValue(src, path).onSuccess((v) => {\n if (!isJsonObject(v)) {\n return fail(`${path}: not an object`);\n }\n return succeed(v);\n });\n}\n\n/**\n * \"Sanitizes\" an `unknown` by stringifying and then parsing it. Guarantees a\n * valid {@link JsonValue | JsonValue} but is not idempotent and gives no guarantees\n * about fidelity. Fails if the supplied value cannot be stringified as Json.\n * @param from - The `unknown` to be sanitized.\n * @returns `Success` with a {@link JsonValue | JsonValue} if conversion succeeds,\n * `Failure` with details if an error occurs.\n * @public\n */\nexport function sanitizeJson(from: unknown): Result<JsonValue> {\n return captureResult(() => JSON.parse(JSON.stringify(from)));\n}\n\n/**\n * Sanitizes some value using JSON stringification and parsing, returning an\n * returning a matching strongly-typed value.\n * @param from - The value to be sanitized.\n * @returns `Success` with a {@link JsonObject | JsonObject} if conversion succeeds,\n * `Failure` with details if an error occurs.\n * @public\n */\nexport function sanitizeJsonObject<T>(from: T): Result<T> {\n return captureResult(() => JSON.parse(JSON.stringify(from)));\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/json/index.ts"],"names":[],"mappings":"AAsBA,cAAc,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/json/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,2CAAyB","sourcesContent":["/*\n * Copyright (c) 2020 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 './common';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/file.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAEL,uBAAuB,EACvB,4BAA4B,EAC5B,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AAGxB;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACjD,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAC1B,MAAM,CAAC,CAAC,CAAC,CAEX;AAED;;;;;;GAMG;AACH,wBAAg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4C;IAE5C,OAAO,kCAAmB,CAAC,6BAA6B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,kBAAkB,GAAiB,IAAI,2BAAY,CAAC;IACxD,IAAI,EAAE,0BAAe;IACrB,mBAAmB,EAAE,IAAI,CAAC,oBAAoB;CAC/C,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAAe,EAAE,KAAgB;IACjE,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 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 { Converter, Result } from '@fgv/ts-utils';\nimport { JsonValue } from '../json';\nimport {\n DefaultJsonFsHelper,\n IJsonFsDirectoryOptions,\n IJsonFsDirectoryToMapOptions,\n IReadDirectoryItem,\n JsonFsHelper\n} from './jsonFsHelper';\nimport { DefaultJsonLike } from './jsonLike';\n\n/**\n * {@inheritdoc JsonFile.JsonFsHelper.readJsonFileSync}\n * @public\n */\nexport function readJsonFileSync(srcPath: string): Result<JsonValue> {\n return DefaultJsonFsHelper.readJsonFileSync(srcPath);\n}\n\n/**\n * Read a JSON file and apply a supplied converter.\n * @param srcPath - Path of the file to read.\n * @param converter - `Converter` used to convert the file contents\n * @returns `Success` with a result of type `<T>`, or `Failure`* with a message if an error occurs.\n * @public\n */\nexport function convertJsonFileSync<T, TC = unknown>(\n srcPath: string,\n converter: Converter<T, TC>\n): Result<T> {\n return DefaultJsonFsHelper.convertJsonFileSync(srcPath, converter);\n}\n\n/**\n * Reads all JSON files from a directory and apply a supplied converter.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryOptions | Options} to control\n * conversion and filtering\n * @public\n */\nexport function convertJsonDirectorySync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryOptions<T, TC>\n): Result<IReadDirectoryItem<T>[]> {\n return DefaultJsonFsHelper.convertJsonDirectorySync(srcPath, options);\n}\n\n/**\n * Reads and converts all JSON files from a directory, returning a\n * `Map<string, T>` indexed by file base name (i.e. minus the extension)\n * with an optional name transformation applied if present.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryToMapOptions | Options} to control conversion,\n * filtering and naming.\n * @public\n */\nexport function convertJsonDirectoryToMapSync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryToMapOptions<T, TC>\n): Result<Map<string, T>> {\n return DefaultJsonFsHelper.convertJsonDirectoryToMapSync(srcPath, options);\n}\n\nconst CompatJsonFsHelper: JsonFsHelper = new JsonFsHelper({\n json: DefaultJsonLike,\n allowUndefinedWrite: true // for compatibility\n});\n\n/**\n * {@inheritDoc JsonFile.JsonFsHelper.writeJsonFileSync}\n * @public\n */\nexport function writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean> {\n return CompatJsonFsHelper.writeJsonFileSync(srcPath, value);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/index.ts"],"names":[],"mappings":"AAsBA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/json-file/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,yCAAuB;AACvB,iDAA+B;AAC/B,6CAA2B","sourcesContent":["/*\n * Copyright (c) 2020 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 './file';\nexport * from './jsonFsHelper';\nexport * from './jsonLike';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonFsHelper.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/jsonFsHelper.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAA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C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;YACpE,sBAAsB;YACtB,IAAI,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;gBAC1E,MAAM,IAAI,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAY,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAES,mBAAmB,CAAQ,OAAuC,EAAE,IAAY;;QACxF,sBAAsB;QACtB,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,KAAK,mCAAI,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QACxD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AA3ID,oCA2IC;AAED;;GAEG;AACU,QAAA,mBAAmB,GAAiB,IAAI,YAAY,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 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 { Converter, Result, Validator, captureResult, fail, mapResults, succeed } from '@fgv/ts-utils';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport { JsonValue } from '../json';\nimport { DefaultJsonLike, IJsonLike } from './jsonLike';\n\n/**\n * Options for directory conversion.\n * TODO: add filtering, allowed and excluded.\n * @public\n */\nexport interface IJsonFsDirectoryOptions<T, TC = unknown> {\n /**\n * The converter used to convert incoming JSON objects.\n */\n converter: Converter<T, TC> | Validator<T, TC>;\n\n /**\n * Filter applied to items in the directory\n */\n files?: RegExp[];\n}\n\n/**\n * Return value for one item in a directory conversion.\n * @public\n */\nexport interface IReadDirectoryItem<T> {\n /**\n * Relative name of the file that was processed\n */\n filename: string;\n\n /**\n * The payload of the file.\n */\n item: T;\n}\n\n/**\n * Function to transform the name of a some entity, given an original name\n * and the contents of the entity.\n * @public\n */\nexport type ItemNameTransformFunction<T> = (name: string, item: T) => Result<string>;\n\n/**\n * Options controlling conversion of a directory to a `Map`.\n * @public\n */\nexport interface IJsonFsDirectoryToMapOptions<T, TC = unknown> extends IJsonFsDirectoryOptions<T, TC> {\n transformName?: ItemNameTransformFunction<T>;\n}\n\n/**\n * Function to transform the name of some entity, given only a previous name. This\n * default implementation always returns `Success` with the value that was passed in.\n * @param n - The name to be transformed.\n * @returns - `Success` with the string that was passed in.\n * @public\n */\nconst defaultNameTransformer = (n: string): Result<string> => succeed(n);\n\n/**\n * Configuration for {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @public\n */\nexport interface IJsonFsHelperConfig {\n json: IJsonLike;\n allowUndefinedWrite: boolean;\n defaultFiles: RegExp[];\n}\n\n/**\n * Initialization options for {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @public\n */\nexport type JsonFsHelperInitOptions = Partial<IJsonFsHelperConfig>;\n\n/**\n * Default configuration for {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @public\n */\nexport const DefaultJsonFsHelperConfig: IJsonFsHelperConfig = {\n json: DefaultJsonLike,\n allowUndefinedWrite: false,\n defaultFiles: [/.*.json/]\n};\n\n/**\n * Helper class to simplify common filesystem operations involving JSON (or JSON-like)\n * files.\n * @public\n */\nexport class JsonFsHelper {\n /**\n * Configuration for this {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n */\n public readonly config: IJsonFsHelperConfig;\n\n /**\n * Construct a new {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @param json - Optional {@link JsonFile.IJsonLike | IJsonLike} used to process strings\n * and JSON values.\n */\n public constructor(init?: JsonFsHelperInitOptions) {\n this.config = {\n ...DefaultJsonFsHelperConfig,\n ...(init ?? {})\n };\n }\n\n /**\n * Read type-safe JSON from a file.\n * @param srcPath - Path of the file to read\n * @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`\n * with a message if an error occurs.\n */\n public readJsonFileSync(srcPath: string): Result<JsonValue> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const body = fs.readFileSync(fullPath, 'utf8').toString();\n return this.config.json.parse(body) as JsonValue;\n });\n }\n\n /**\n * Read a JSON file and apply a supplied converter or validator.\n * @param srcPath - Path of the file to read.\n * @param cv - Converter or validator used to process the file.\n * @returns `Success` with a result of type `<T>`, or `Failure`\n * with a message if an error occurs.\n */\n public convertJsonFileSync<T, TC = unknown>(\n srcPath: string,\n cv: Converter<T, TC> | Validator<T, TC>,\n context?: TC\n ): Result<T> {\n return this.readJsonFileSync(srcPath).onSuccess((json) => {\n return cv.convert(json, context);\n });\n }\n\n /**\n * Reads all JSON files from a directory and apply a supplied converter or validator.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryOptions | Options} to control\n * conversion and filtering\n */\n public convertJsonDirectorySync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryOptions<T>,\n context?: TC\n ): Result<IReadDirectoryItem<T>[]> {\n return captureResult<IReadDirectoryItem<T>[]>(() => {\n const fullPath = path.resolve(srcPath);\n if (!fs.statSync(fullPath).isDirectory()) {\n throw new Error(`${fullPath}: Not a directory`);\n }\n const files = fs.readdirSync(fullPath, { withFileTypes: true });\n const results = files\n .map((fi) => {\n if (fi.isFile() && this._pathMatchesOptions(options, fi.name)) {\n const filePath = path.resolve(fullPath, fi.name);\n return this.convertJsonFileSync(filePath, options.converter, context)\n .onSuccess((payload) => {\n return succeed({\n filename: fi.name,\n item: payload\n });\n })\n .onFailure((message) => {\n return fail(`${fi.name}: ${message}`);\n });\n }\n return undefined;\n })\n .filter((r): r is Result<IReadDirectoryItem<T>> => r !== undefined);\n return mapResults(results).orThrow();\n });\n }\n\n /**\n * Reads and converts or validates all JSON files from a directory, returning a\n * `Map<string, T>` indexed by file base name (i.e. minus the extension)\n * with an optional name transformation applied if present.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryToMapOptions | Options} to control conversion,\n * filtering and naming.\n */\n public convertJsonDirectoryToMapSync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryToMapOptions<T, TC>,\n context?: unknown\n ): Result<Map<string, T>> {\n return this.convertJsonDirectorySync(srcPath, options, context).onSuccess((items) => {\n const transformName = options.transformName ?? defaultNameTransformer;\n return mapResults(\n items.map((item) => {\n const basename = path.basename(item.filename, '.json');\n return transformName(basename, item.item).onSuccess((name) => {\n return succeed<[string, T]>([name, item.item]);\n });\n })\n ).onSuccess((items) => {\n return succeed(new Map<string, T>(items));\n });\n });\n }\n\n /**\n * Write type-safe JSON to a file.\n * @param srcPath - Path of the file to write.\n * @param value - The {@link JsonValue | JsonValue} to be written.\n */\n public writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const stringified = this.config.json.stringify(value, undefined, 2);\n /* c8 ignore next 3 */\n if (stringified === undefined && this.config.allowUndefinedWrite !== true) {\n throw new Error(`Could not stringify ${value}`);\n }\n fs.writeFileSync(fullPath, stringified!);\n return true;\n });\n }\n\n protected _pathMatchesOptions<T, TC>(options: IJsonFsDirectoryOptions<T, TC>, path: string): boolean {\n /* c8 ignore next 1 */\n const match = options.files ?? this.config.defaultFiles;\n return match.some((m) => m.exec(path));\n }\n}\n\n/**\n * @public\n */\nexport const DefaultJsonFsHelper: JsonFsHelper = new JsonFsHelper();\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonLike.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/jsonLike.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;IACrF,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnG;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,SAAgB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonLike.js","sourceRoot":"","sources":["../../../src/packlets/json-file/jsonLike.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAgCH;;GAEG;AACU,QAAA,eAAe,GAAc,IAAI,CAAC","sourcesContent":["/*\n * Copyright (c) 2024 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 { JsonValue } from '../json';\n\n/**\n * @public\n */\nexport type JsonReviver = (key: string, value: JsonValue) => JsonValue;\n\n/**\n * @public\n */\nexport type JsonReplacerFunction = (key: string, value: JsonValue) => JsonValue;\n\n/**\n * @public\n */\nexport type JsonReplacerArray = (string | number)[];\n\n/**\n * @public\n */\nexport type JsonReplacer = JsonReplacerFunction | JsonReplacerArray;\n\n/**\n * @public\n */\nexport interface IJsonLike {\n parse(text: string, reviver?: JsonReviver, options?: unknown): JsonValue | undefined;\n stringify(value: JsonValue, replacer?: JsonReplacer, space?: string | number): string | undefined;\n}\n\n/**\n * @public\n */\nexport const DefaultJsonLike: IJsonLike = JSON;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/validators/index.ts"],"names":[],"mappings":"AAsBA,cAAc,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/validators/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,+CAA6B","sourcesContent":["/*\n * Copyright (c) 2020 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 './validators';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validators/validators.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAuB,SAAS,EAAQ,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAA6B,MAAM,SAAS,CAAC;AAIrG;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,aAAa,EAAE,qBAAqB,CAqBtE,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,qBAAqB,CAiBlE,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,qBAAqB,CAkBhE,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,qBAAqB,CAehE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/packlets/validators/validators.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAqE;AACrE,kCAAqG;AAYrG;;;;GAIG;AACU,QAAA,aAAa,GACxB,IAAI,qBAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC;IACnC,SAAS,EAAE,CAAC,IAAa,EAAE,GAA2B,EAAoC,EAAE;QAC1F,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC;YACd,KAAK,QAAQ;gBACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM;QACV,CAAC;QACD,IAAI,IAAI,KAAK,SAAS,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,yBAAyB,MAAK,IAAI,EAAE,CAA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,CAAC;YAC9C,OAAO,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;QACjD,CAAC;QACD,MAAM,MAAM,GAAG,qBAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,CAAC;CACF,CAAC,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, Validation, Validator, fail } from '@fgv/ts-utils';\nimport { JsonArray, JsonObject, JsonPrimitive, JsonValue, isJsonArray, isJsonObject } from '../json';\n\n/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */\n\n/**\n * Validation context for in-place JSON validators.\n * @public\n */\nexport interface IJsonValidatorContext {\n ignoreUndefinedProperties?: boolean;\n}\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonPrimitive | JsonPrimitive}.\n * @public\n */\nexport const jsonPrimitive: Validator<JsonPrimitive, IJsonValidatorContext> =\n new Validation.Base.GenericValidator({\n validator: (from: unknown, ctx?: IJsonValidatorContext): boolean | Failure<JsonPrimitive> => {\n if (from === null) {\n return true;\n }\n switch (typeof from) {\n case 'boolean':\n case 'string':\n return true;\n case 'number':\n if (!Number.isNaN(from)) {\n return true;\n }\n break;\n }\n if (from === undefined && ctx?.ignoreUndefinedProperties === true) {\n return true;\n }\n return fail(`\"${String(from)}\": not a valid JSON primitive.`);\n }\n });\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonObject | JsonObject}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Validators.IJsonValidatorContext | context} at runtime.\n * @public\n */\nexport const jsonObject: Validator<JsonObject, IJsonValidatorContext> = new Validation.Base.GenericValidator({\n validator: (from: unknown, ctx?: IJsonValidatorContext) => {\n if (!isJsonObject(from)) {\n return fail('not a valid JSON object.');\n }\n const errors: string[] = [];\n for (const [name, value] of Object.entries(from)) {\n jsonValue.validate(value, ctx).onFailure((m) => {\n errors.push(`${name}: ${m}`);\n return fail(m);\n });\n }\n if (errors.length > 0) {\n return fail(`not a valid JSON object:\\n${errors.join('\\n')}`);\n }\n return true;\n }\n});\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonArray | JsonArray}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Validators.IJsonValidatorContext | context} at runtime.\n * @public\n */\nexport const jsonArray: Validator<JsonArray, IJsonValidatorContext> = new Validation.Base.GenericValidator({\n validator: (from: unknown, ctx?: IJsonValidatorContext) => {\n if (!isJsonArray(from)) {\n return fail('not an array');\n }\n const errors: string[] = [];\n for (let i = 0; i < from.length; i++) {\n const value = from[i];\n jsonValue.validate(value, ctx).onFailure((m) => {\n errors.push(`${i}: ${m}`);\n return fail(m);\n });\n }\n if (errors.length > 0) {\n return fail(`array contains non-json elements:\\n${errors.join('\\n')}`);\n }\n return true;\n }\n});\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonValue | JsonValue}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Validators.IJsonValidatorContext | context} at runtime.\n * @public\n */\nexport const jsonValue: Validator<JsonValue, IJsonValidatorContext> = new Validation.Base.GenericValidator<\n JsonValue,\n IJsonValidatorContext\n>({\n validator: (from: unknown, ctx?: IJsonValidatorContext) => {\n if (isJsonArray(from)) {\n const result = jsonArray.validate(from, ctx);\n return result.success === true ? true : result;\n } else if (isJsonObject(from)) {\n const result = jsonObject.validate(from, ctx);\n return result.success === true ? true : result;\n }\n const result = jsonPrimitive.validate(from, ctx);\n return result.success === true ? true : result;\n }\n});\n"]}