@fuzdev/fuz_util 0.55.0 → 0.56.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.
- package/dist/args.d.ts +12 -12
- package/dist/args.js +11 -11
- package/dist/async.d.ts +12 -12
- package/dist/async.js +12 -12
- package/dist/benchmark.d.ts +24 -24
- package/dist/benchmark.js +26 -26
- package/dist/benchmark_baseline.d.ts +11 -11
- package/dist/benchmark_baseline.js +11 -11
- package/dist/benchmark_format.d.ts +15 -15
- package/dist/benchmark_format.js +15 -15
- package/dist/benchmark_stats.d.ts +5 -5
- package/dist/benchmark_stats.js +5 -5
- package/dist/benchmark_types.d.ts +7 -7
- package/dist/bytes.d.ts +4 -4
- package/dist/bytes.js +4 -4
- package/dist/dag.d.ts +2 -2
- package/dist/dag.js +2 -2
- package/dist/deep_equal.d.ts +2 -2
- package/dist/deep_equal.js +2 -2
- package/dist/diff.d.ts +17 -17
- package/dist/diff.js +17 -17
- package/dist/dom.d.ts +4 -4
- package/dist/dom.js +4 -4
- package/dist/fetch.d.ts +1 -1
- package/dist/fetch.js +1 -1
- package/dist/git.d.ts +1 -1
- package/dist/git.js +1 -1
- package/dist/hash.d.ts +6 -6
- package/dist/hash.js +8 -8
- package/dist/hash_blake3.d.ts +1 -1
- package/dist/hash_blake3.js +1 -1
- package/dist/hex.d.ts +4 -4
- package/dist/hex.js +4 -4
- package/dist/json.d.ts +2 -2
- package/dist/json.js +2 -2
- package/dist/log.d.ts +12 -12
- package/dist/log.js +11 -11
- package/dist/map.d.ts +1 -1
- package/dist/map.js +1 -1
- package/dist/object.d.ts +1 -1
- package/dist/object.js +1 -1
- package/dist/package_json.d.ts +1 -1
- package/dist/package_json.js +1 -1
- package/dist/path.d.ts +5 -5
- package/dist/path.js +5 -5
- package/dist/process.d.ts +22 -22
- package/dist/process.js +22 -22
- package/dist/random.d.ts +2 -2
- package/dist/random.js +2 -2
- package/dist/result.d.ts +6 -6
- package/dist/result.js +6 -6
- package/dist/sort.d.ts +3 -3
- package/dist/sort.js +3 -3
- package/dist/source_json.d.ts +3 -3
- package/dist/source_json.js +3 -3
- package/dist/stats.d.ts +17 -17
- package/dist/stats.js +17 -17
- package/dist/string.d.ts +6 -6
- package/dist/string.js +6 -6
- package/dist/svelte_preprocess_helpers.d.ts +42 -42
- package/dist/svelte_preprocess_helpers.js +42 -42
- package/dist/testing.d.ts +44 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +59 -0
- package/dist/time.d.ts +19 -19
- package/dist/time.js +19 -19
- package/dist/zod.d.ts +16 -16
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +24 -24
- package/package.json +6 -6
- package/src/lib/args.ts +12 -12
- package/src/lib/async.ts +12 -12
- package/src/lib/benchmark.ts +28 -28
- package/src/lib/benchmark_baseline.ts +11 -11
- package/src/lib/benchmark_format.ts +15 -15
- package/src/lib/benchmark_stats.ts +5 -5
- package/src/lib/benchmark_types.ts +7 -7
- package/src/lib/bytes.ts +4 -4
- package/src/lib/dag.ts +2 -2
- package/src/lib/deep_equal.ts +2 -2
- package/src/lib/diff.ts +17 -17
- package/src/lib/dom.ts +4 -4
- package/src/lib/fetch.ts +1 -1
- package/src/lib/git.ts +1 -1
- package/src/lib/hash.ts +8 -8
- package/src/lib/hash_blake3.ts +1 -1
- package/src/lib/hex.ts +4 -4
- package/src/lib/json.ts +2 -2
- package/src/lib/log.ts +12 -12
- package/src/lib/map.ts +1 -1
- package/src/lib/object.ts +1 -1
- package/src/lib/package_json.ts +1 -1
- package/src/lib/path.ts +5 -5
- package/src/lib/process.ts +22 -22
- package/src/lib/random.ts +2 -2
- package/src/lib/result.ts +6 -6
- package/src/lib/sort.ts +3 -3
- package/src/lib/source_json.ts +3 -3
- package/src/lib/stats.ts +17 -17
- package/src/lib/string.ts +6 -6
- package/src/lib/svelte_preprocess_helpers.ts +42 -42
- package/src/lib/testing.ts +80 -0
- package/src/lib/time.ts +19 -19
- package/src/lib/zod.ts +24 -24
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAC1B,IAAI,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,UAAU,MAAM,KACd,OAAO,CAAC,KAAK,CAWf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IACjC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,QAAO,UAiBrC,CAAC"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test assertions for the `@fuzdev` ecosystem.
|
|
3
|
+
*
|
|
4
|
+
* Extends the fuz-stack testing conventions (`assert` from vitest, tests in `src/test/`,
|
|
5
|
+
* plain object mocks) with reusable helpers for patterns that appear across multiple repos.
|
|
6
|
+
* Only depends on vitest — safe for fuz_util's zero-runtime-deps constraint.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { assert, vi } from 'vitest';
|
|
11
|
+
/**
|
|
12
|
+
* Asserts that `fn` rejects with an `Error`.
|
|
13
|
+
* Optionally matches the error message against `pattern`.
|
|
14
|
+
* Returns the caught `Error` for further assertions by the caller.
|
|
15
|
+
*
|
|
16
|
+
* `assert.fail` is placed after the catch block so that assertion failures
|
|
17
|
+
* from the test itself are not swallowed by the catch.
|
|
18
|
+
*
|
|
19
|
+
* @param fn - async function expected to reject
|
|
20
|
+
* @param pattern - optional regex to match against the error message
|
|
21
|
+
* @returns the caught `Error`
|
|
22
|
+
*/
|
|
23
|
+
export const assert_rejects = async (fn, pattern) => {
|
|
24
|
+
try {
|
|
25
|
+
await fn();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
assert(err instanceof Error, 'Expected rejection to be an Error');
|
|
29
|
+
if (pattern) {
|
|
30
|
+
assert.match(err.message, pattern);
|
|
31
|
+
}
|
|
32
|
+
return err;
|
|
33
|
+
}
|
|
34
|
+
assert.fail('Expected to throw');
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a mock `Logger` with `vi.fn()` on each logging method
|
|
38
|
+
* and tracking arrays for inspecting logged messages.
|
|
39
|
+
* Follows the fuz-stack convention of plain object mocks over mocking libraries.
|
|
40
|
+
*
|
|
41
|
+
* @returns a `MockLogger` assignable to `Logger`
|
|
42
|
+
*/
|
|
43
|
+
export const create_mock_logger = () => {
|
|
44
|
+
const error_calls = [];
|
|
45
|
+
const warn_calls = [];
|
|
46
|
+
const info_calls = [];
|
|
47
|
+
const debug_calls = [];
|
|
48
|
+
return {
|
|
49
|
+
error: vi.fn((msg) => error_calls.push(msg)),
|
|
50
|
+
warn: vi.fn((msg) => warn_calls.push(msg)),
|
|
51
|
+
info: vi.fn((msg) => info_calls.push(msg)),
|
|
52
|
+
debug: vi.fn((msg) => debug_calls.push(msg)),
|
|
53
|
+
raw: vi.fn(),
|
|
54
|
+
error_calls,
|
|
55
|
+
warn_calls,
|
|
56
|
+
info_calls,
|
|
57
|
+
debug_calls,
|
|
58
|
+
};
|
|
59
|
+
};
|
package/dist/time.d.ts
CHANGED
|
@@ -65,23 +65,23 @@ export declare const TIME_UNIT_DISPLAY: Record<TimeUnit, string>;
|
|
|
65
65
|
/**
|
|
66
66
|
* Detect the best time unit for a set of nanosecond values.
|
|
67
67
|
* Chooses the unit where most values fall in the range 1-9999.
|
|
68
|
-
* @param values_ns -
|
|
69
|
-
* @returns
|
|
68
|
+
* @param values_ns - array of times in nanoseconds
|
|
69
|
+
* @returns best unit to use for all values
|
|
70
70
|
*/
|
|
71
71
|
export declare const time_unit_detect_best: (values_ns: Array<number>) => TimeUnit;
|
|
72
72
|
/**
|
|
73
73
|
* Format time with a specific unit.
|
|
74
|
-
* @param ns -
|
|
75
|
-
* @param unit -
|
|
76
|
-
* @param decimals -
|
|
77
|
-
* @returns
|
|
74
|
+
* @param ns - time in nanoseconds
|
|
75
|
+
* @param unit - unit to use ('ns', 'us', 'ms', 's')
|
|
76
|
+
* @param decimals - number of decimal places (default: 2)
|
|
77
|
+
* @returns formatted string like "3.87μs"
|
|
78
78
|
*/
|
|
79
79
|
export declare const time_format: (ns: number, unit: TimeUnit, decimals?: number) => string;
|
|
80
80
|
/**
|
|
81
81
|
* Format time with adaptive units (ns/μs/ms/s) based on magnitude.
|
|
82
|
-
* @param ns -
|
|
83
|
-
* @param decimals -
|
|
84
|
-
* @returns
|
|
82
|
+
* @param ns - time in nanoseconds
|
|
83
|
+
* @param decimals - number of decimal places (default: 2)
|
|
84
|
+
* @returns formatted string like "3.87μs" or "1.23ms"
|
|
85
85
|
*
|
|
86
86
|
* @example
|
|
87
87
|
* ```ts
|
|
@@ -110,9 +110,9 @@ export interface TimeResult {
|
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Time an asynchronous function execution.
|
|
113
|
-
* @param fn -
|
|
114
|
-
* @param timer -
|
|
115
|
-
* @returns
|
|
113
|
+
* @param fn - async function to time
|
|
114
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
115
|
+
* @returns object containing the function result and timing information
|
|
116
116
|
*
|
|
117
117
|
* @example
|
|
118
118
|
* ```ts
|
|
@@ -129,9 +129,9 @@ export declare const time_async: <T>(fn: () => Promise<T>, timer?: Timer) => Pro
|
|
|
129
129
|
}>;
|
|
130
130
|
/**
|
|
131
131
|
* Time a synchronous function execution.
|
|
132
|
-
* @param fn -
|
|
133
|
-
* @param timer -
|
|
134
|
-
* @returns
|
|
132
|
+
* @param fn - sync function to time
|
|
133
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
134
|
+
* @returns object containing the function result and timing information
|
|
135
135
|
*
|
|
136
136
|
* @example
|
|
137
137
|
* ```ts
|
|
@@ -147,10 +147,10 @@ export declare const time_sync: <T>(fn: () => T, timer?: Timer) => {
|
|
|
147
147
|
};
|
|
148
148
|
/**
|
|
149
149
|
* Measure multiple executions of a function and return all timings.
|
|
150
|
-
* @param fn -
|
|
151
|
-
* @param iterations -
|
|
152
|
-
* @param timer -
|
|
153
|
-
* @returns
|
|
150
|
+
* @param fn - function to measure (sync or async)
|
|
151
|
+
* @param iterations - number of times to execute
|
|
152
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
153
|
+
* @returns array of elapsed times in nanoseconds
|
|
154
154
|
*
|
|
155
155
|
* @example
|
|
156
156
|
* ```ts
|
package/dist/time.js
CHANGED
|
@@ -96,8 +96,8 @@ export const TIME_UNIT_DISPLAY = { ns: 'ns', us: 'μs', ms: 'ms', s: 's' };
|
|
|
96
96
|
/**
|
|
97
97
|
* Detect the best time unit for a set of nanosecond values.
|
|
98
98
|
* Chooses the unit where most values fall in the range 1-9999.
|
|
99
|
-
* @param values_ns -
|
|
100
|
-
* @returns
|
|
99
|
+
* @param values_ns - array of times in nanoseconds
|
|
100
|
+
* @returns best unit to use for all values
|
|
101
101
|
*/
|
|
102
102
|
export const time_unit_detect_best = (values_ns) => {
|
|
103
103
|
if (values_ns.length === 0)
|
|
@@ -125,10 +125,10 @@ export const time_unit_detect_best = (values_ns) => {
|
|
|
125
125
|
};
|
|
126
126
|
/**
|
|
127
127
|
* Format time with a specific unit.
|
|
128
|
-
* @param ns -
|
|
129
|
-
* @param unit -
|
|
130
|
-
* @param decimals -
|
|
131
|
-
* @returns
|
|
128
|
+
* @param ns - time in nanoseconds
|
|
129
|
+
* @param unit - unit to use ('ns', 'us', 'ms', 's')
|
|
130
|
+
* @param decimals - number of decimal places (default: 2)
|
|
131
|
+
* @returns formatted string like "3.87μs"
|
|
132
132
|
*/
|
|
133
133
|
export const time_format = (ns, unit, decimals = 2) => {
|
|
134
134
|
if (!isFinite(ns))
|
|
@@ -146,9 +146,9 @@ export const time_format = (ns, unit, decimals = 2) => {
|
|
|
146
146
|
};
|
|
147
147
|
/**
|
|
148
148
|
* Format time with adaptive units (ns/μs/ms/s) based on magnitude.
|
|
149
|
-
* @param ns -
|
|
150
|
-
* @param decimals -
|
|
151
|
-
* @returns
|
|
149
|
+
* @param ns - time in nanoseconds
|
|
150
|
+
* @param decimals - number of decimal places (default: 2)
|
|
151
|
+
* @returns formatted string like "3.87μs" or "1.23ms"
|
|
152
152
|
*
|
|
153
153
|
* @example
|
|
154
154
|
* ```ts
|
|
@@ -177,9 +177,9 @@ export const time_format_adaptive = (ns, decimals = 2) => {
|
|
|
177
177
|
};
|
|
178
178
|
/**
|
|
179
179
|
* Time an asynchronous function execution.
|
|
180
|
-
* @param fn -
|
|
181
|
-
* @param timer -
|
|
182
|
-
* @returns
|
|
180
|
+
* @param fn - async function to time
|
|
181
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
182
|
+
* @returns object containing the function result and timing information
|
|
183
183
|
*
|
|
184
184
|
* @example
|
|
185
185
|
* ```ts
|
|
@@ -208,9 +208,9 @@ export const time_async = async (fn, timer = timer_default) => {
|
|
|
208
208
|
};
|
|
209
209
|
/**
|
|
210
210
|
* Time a synchronous function execution.
|
|
211
|
-
* @param fn -
|
|
212
|
-
* @param timer -
|
|
213
|
-
* @returns
|
|
211
|
+
* @param fn - sync function to time
|
|
212
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
213
|
+
* @returns object containing the function result and timing information
|
|
214
214
|
*
|
|
215
215
|
* @example
|
|
216
216
|
* ```ts
|
|
@@ -238,10 +238,10 @@ export const time_sync = (fn, timer = timer_default) => {
|
|
|
238
238
|
};
|
|
239
239
|
/**
|
|
240
240
|
* Measure multiple executions of a function and return all timings.
|
|
241
|
-
* @param fn -
|
|
242
|
-
* @param iterations -
|
|
243
|
-
* @param timer -
|
|
244
|
-
* @returns
|
|
241
|
+
* @param fn - function to measure (sync or async)
|
|
242
|
+
* @param iterations - number of times to execute
|
|
243
|
+
* @param timer - timer to use (defaults to `timer_default`)
|
|
244
|
+
* @returns array of elapsed times in nanoseconds
|
|
245
245
|
*
|
|
246
246
|
* @example
|
|
247
247
|
* ```ts
|
package/dist/zod.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ import type { z } from 'zod';
|
|
|
10
10
|
/**
|
|
11
11
|
* Unwrap nested schema types (optional, default, nullable, etc).
|
|
12
12
|
*
|
|
13
|
-
* @param def - Zod type definition to unwrap
|
|
14
|
-
* @returns
|
|
13
|
+
* @param def - Zod type definition to unwrap
|
|
14
|
+
* @returns inner schema if wrapped, undefined otherwise
|
|
15
15
|
*/
|
|
16
16
|
export declare const zod_to_subschema: (def: z.core.$ZodTypeDef) => z.ZodType | undefined;
|
|
17
17
|
/** Zod wrapper type names that `zod_unwrap_def` traverses through. */
|
|
@@ -78,36 +78,36 @@ export declare const zod_extract_fields: (schema: z.ZodObject) => Array<ZodField
|
|
|
78
78
|
/**
|
|
79
79
|
* Get the description from a schema's metadata, unwrapping if needed.
|
|
80
80
|
*
|
|
81
|
-
* @param schema - Zod schema to extract description from
|
|
82
|
-
* @returns
|
|
81
|
+
* @param schema - Zod schema to extract description from
|
|
82
|
+
* @returns description string or null if not found
|
|
83
83
|
*/
|
|
84
84
|
export declare const zod_to_schema_description: (schema: z.ZodType) => string | null;
|
|
85
85
|
/**
|
|
86
86
|
* Get the default value from a schema, unwrapping if needed.
|
|
87
87
|
*
|
|
88
|
-
* @param schema - Zod schema to extract default from
|
|
89
|
-
* @returns
|
|
88
|
+
* @param schema - Zod schema to extract default from
|
|
89
|
+
* @returns default value or undefined
|
|
90
90
|
*/
|
|
91
91
|
export declare const zod_to_schema_default: (schema: z.ZodType) => unknown;
|
|
92
92
|
/**
|
|
93
93
|
* Get aliases from a schema's metadata, unwrapping if needed.
|
|
94
94
|
*
|
|
95
|
-
* @param schema - Zod schema to extract aliases from
|
|
96
|
-
* @returns
|
|
95
|
+
* @param schema - Zod schema to extract aliases from
|
|
96
|
+
* @returns array of alias strings
|
|
97
97
|
*/
|
|
98
98
|
export declare const zod_to_schema_aliases: (schema: z.ZodType) => Array<string>;
|
|
99
99
|
/**
|
|
100
100
|
* Get the type string for a schema, suitable for display.
|
|
101
101
|
*
|
|
102
|
-
* @param schema - Zod schema to get type string for
|
|
103
|
-
* @returns
|
|
102
|
+
* @param schema - Zod schema to get type string for
|
|
103
|
+
* @returns human-readable type string
|
|
104
104
|
*/
|
|
105
105
|
export declare const zod_to_schema_type_string: (schema: z.ZodType) => string;
|
|
106
106
|
/**
|
|
107
107
|
* Format a value for display in help text.
|
|
108
108
|
*
|
|
109
|
-
* @param value -
|
|
110
|
-
* @returns
|
|
109
|
+
* @param value - value to format
|
|
110
|
+
* @returns formatted string representation
|
|
111
111
|
*/
|
|
112
112
|
export declare const zod_format_value: (value: unknown) => string;
|
|
113
113
|
/**
|
|
@@ -123,15 +123,15 @@ export interface ZodSchemaProperty {
|
|
|
123
123
|
/**
|
|
124
124
|
* Extract properties from a Zod object schema.
|
|
125
125
|
*
|
|
126
|
-
* @param schema - Zod object schema to extract from
|
|
127
|
-
* @returns
|
|
126
|
+
* @param schema - Zod object schema to extract from
|
|
127
|
+
* @returns array of property definitions
|
|
128
128
|
*/
|
|
129
129
|
export declare const zod_to_schema_properties: (schema: z.ZodType) => Array<ZodSchemaProperty>;
|
|
130
130
|
/**
|
|
131
131
|
* Get all property names and their aliases from an object schema.
|
|
132
132
|
*
|
|
133
|
-
* @param schema - Zod object schema
|
|
134
|
-
* @returns
|
|
133
|
+
* @param schema - Zod object schema
|
|
134
|
+
* @returns set of all names and aliases
|
|
135
135
|
*/
|
|
136
136
|
export declare const zod_to_schema_names_with_aliases: (schema: z.ZodType) => Set<string>;
|
|
137
137
|
//# sourceMappingURL=zod.d.ts.map
|
package/dist/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/zod.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAM3B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,CAAC,CAAC,IAAI,CAAC,WAAW,KAAG,CAAC,CAAC,OAAO,GAAG,SAStE,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,aAO5B,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,IAAI,CAAC,WAOzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MAAqC,CAAC;AAE5F;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/zod.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAM3B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,CAAC,CAAC,IAAI,CAAC,WAAW,KAAG,CAAC,CAAC,OAAO,GAAG,SAStE,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,aAO5B,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,IAAI,CAAC,WAOzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MAAqC,CAAC;AAE5F;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAAyC,CAAC;AAE9F;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAQnD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAMnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,SAAS,GAAG,IAUtE,CAAC;AAIF,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,CAAC,CAAC,SAAS,KAAG,KAAK,CAAC,YAAY,CAa1E,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MAAM,GAAG,IAUtE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAUzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,KAAK,CAAC,MAAM,CAUrE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MA4C7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,MAQjD,CAAC;AAMF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,KAAK,CAAC,iBAAiB,CAuBnF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,GAAG,CAAC,MAAM,CAW9E,CAAC"}
|
package/dist/zod.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
/**
|
|
13
13
|
* Unwrap nested schema types (optional, default, nullable, etc).
|
|
14
14
|
*
|
|
15
|
-
* @param def - Zod type definition to unwrap
|
|
16
|
-
* @returns
|
|
15
|
+
* @param def - Zod type definition to unwrap
|
|
16
|
+
* @returns inner schema if wrapped, undefined otherwise
|
|
17
17
|
*/
|
|
18
18
|
export const zod_to_subschema = (def) => {
|
|
19
19
|
if ('innerType' in def) {
|
|
@@ -44,7 +44,7 @@ export const ZOD_WRAPPER_TYPES = new Set([
|
|
|
44
44
|
* @returns the innermost non-wrapper type definition
|
|
45
45
|
*/
|
|
46
46
|
export const zod_unwrap_def = (schema) => {
|
|
47
|
-
const def = schema
|
|
47
|
+
const { def } = schema;
|
|
48
48
|
if (ZOD_WRAPPER_TYPES.has(def.type)) {
|
|
49
49
|
const sub = zod_to_subschema(def);
|
|
50
50
|
if (sub)
|
|
@@ -64,14 +64,14 @@ export const zod_get_base_type = (schema) => zod_unwrap_def(schema).type;
|
|
|
64
64
|
*
|
|
65
65
|
* @param schema - Zod schema to check
|
|
66
66
|
*/
|
|
67
|
-
export const zod_is_optional = (schema) => schema.
|
|
67
|
+
export const zod_is_optional = (schema) => schema.def.type === 'optional';
|
|
68
68
|
/**
|
|
69
69
|
* Check if a schema accepts null at any wrapping level.
|
|
70
70
|
*
|
|
71
71
|
* @param schema - Zod schema to check
|
|
72
72
|
*/
|
|
73
73
|
export const zod_is_nullable = (schema) => {
|
|
74
|
-
const def = schema
|
|
74
|
+
const { def } = schema;
|
|
75
75
|
if (def.type === 'nullable')
|
|
76
76
|
return true;
|
|
77
77
|
if (ZOD_WRAPPER_TYPES.has(def.type)) {
|
|
@@ -90,7 +90,7 @@ export const zod_is_nullable = (schema) => {
|
|
|
90
90
|
* @param schema - Zod schema to check
|
|
91
91
|
*/
|
|
92
92
|
export const zod_has_default = (schema) => {
|
|
93
|
-
const def = schema
|
|
93
|
+
const { def } = schema;
|
|
94
94
|
if ('defaultValue' in def)
|
|
95
95
|
return true;
|
|
96
96
|
const sub = zod_to_subschema(def);
|
|
@@ -110,8 +110,8 @@ export const zod_unwrap_to_object = (schema) => {
|
|
|
110
110
|
if (def.type !== 'object')
|
|
111
111
|
return null;
|
|
112
112
|
let s = schema;
|
|
113
|
-
while (s.
|
|
114
|
-
const sub = zod_to_subschema(s.
|
|
113
|
+
while (s.def.type !== 'object') {
|
|
114
|
+
const sub = zod_to_subschema(s.def);
|
|
115
115
|
if (!sub)
|
|
116
116
|
return null;
|
|
117
117
|
s = sub;
|
|
@@ -142,8 +142,8 @@ export const zod_extract_fields = (schema) => {
|
|
|
142
142
|
/**
|
|
143
143
|
* Get the description from a schema's metadata, unwrapping if needed.
|
|
144
144
|
*
|
|
145
|
-
* @param schema - Zod schema to extract description from
|
|
146
|
-
* @returns
|
|
145
|
+
* @param schema - Zod schema to extract description from
|
|
146
|
+
* @returns description string or null if not found
|
|
147
147
|
*/
|
|
148
148
|
export const zod_to_schema_description = (schema) => {
|
|
149
149
|
const meta = schema.meta();
|
|
@@ -159,11 +159,11 @@ export const zod_to_schema_description = (schema) => {
|
|
|
159
159
|
/**
|
|
160
160
|
* Get the default value from a schema, unwrapping if needed.
|
|
161
161
|
*
|
|
162
|
-
* @param schema - Zod schema to extract default from
|
|
163
|
-
* @returns
|
|
162
|
+
* @param schema - Zod schema to extract default from
|
|
163
|
+
* @returns default value or undefined
|
|
164
164
|
*/
|
|
165
165
|
export const zod_to_schema_default = (schema) => {
|
|
166
|
-
const { def } = schema
|
|
166
|
+
const { def } = schema;
|
|
167
167
|
if ('defaultValue' in def) {
|
|
168
168
|
return def.defaultValue;
|
|
169
169
|
}
|
|
@@ -176,8 +176,8 @@ export const zod_to_schema_default = (schema) => {
|
|
|
176
176
|
/**
|
|
177
177
|
* Get aliases from a schema's metadata, unwrapping if needed.
|
|
178
178
|
*
|
|
179
|
-
* @param schema - Zod schema to extract aliases from
|
|
180
|
-
* @returns
|
|
179
|
+
* @param schema - Zod schema to extract aliases from
|
|
180
|
+
* @returns array of alias strings
|
|
181
181
|
*/
|
|
182
182
|
export const zod_to_schema_aliases = (schema) => {
|
|
183
183
|
const meta = schema.meta();
|
|
@@ -193,11 +193,11 @@ export const zod_to_schema_aliases = (schema) => {
|
|
|
193
193
|
/**
|
|
194
194
|
* Get the type string for a schema, suitable for display.
|
|
195
195
|
*
|
|
196
|
-
* @param schema - Zod schema to get type string for
|
|
197
|
-
* @returns
|
|
196
|
+
* @param schema - Zod schema to get type string for
|
|
197
|
+
* @returns human-readable type string
|
|
198
198
|
*/
|
|
199
199
|
export const zod_to_schema_type_string = (schema) => {
|
|
200
|
-
const { def } = schema
|
|
200
|
+
const { def } = schema;
|
|
201
201
|
switch (def.type) {
|
|
202
202
|
case 'string':
|
|
203
203
|
return 'string';
|
|
@@ -244,8 +244,8 @@ export const zod_to_schema_type_string = (schema) => {
|
|
|
244
244
|
/**
|
|
245
245
|
* Format a value for display in help text.
|
|
246
246
|
*
|
|
247
|
-
* @param value -
|
|
248
|
-
* @returns
|
|
247
|
+
* @param value - value to format
|
|
248
|
+
* @returns formatted string representation
|
|
249
249
|
*/
|
|
250
250
|
export const zod_format_value = (value) => {
|
|
251
251
|
if (value === undefined)
|
|
@@ -265,8 +265,8 @@ export const zod_format_value = (value) => {
|
|
|
265
265
|
/**
|
|
266
266
|
* Extract properties from a Zod object schema.
|
|
267
267
|
*
|
|
268
|
-
* @param schema - Zod object schema to extract from
|
|
269
|
-
* @returns
|
|
268
|
+
* @param schema - Zod object schema to extract from
|
|
269
|
+
* @returns array of property definitions
|
|
270
270
|
*/
|
|
271
271
|
export const zod_to_schema_properties = (schema) => {
|
|
272
272
|
const { def } = schema;
|
|
@@ -293,8 +293,8 @@ export const zod_to_schema_properties = (schema) => {
|
|
|
293
293
|
/**
|
|
294
294
|
* Get all property names and their aliases from an object schema.
|
|
295
295
|
*
|
|
296
|
-
* @param schema - Zod object schema
|
|
297
|
-
* @returns
|
|
296
|
+
* @param schema - Zod object schema
|
|
297
|
+
* @returns set of all names and aliases
|
|
298
298
|
*/
|
|
299
299
|
export const zod_to_schema_names_with_aliases = (schema) => {
|
|
300
300
|
const names = new Set();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuzdev/fuz_util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "utility belt for JS",
|
|
5
5
|
"glyph": "🦕",
|
|
6
6
|
"logo": "logo.svg",
|
|
@@ -75,11 +75,11 @@
|
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@changesets/changelog-git": "^0.2.1",
|
|
78
|
-
"@fuzdev/blake3_wasm": "^0.1.
|
|
78
|
+
"@fuzdev/blake3_wasm": "^0.1.1",
|
|
79
79
|
"@fuzdev/fuz_code": "^0.45.1",
|
|
80
|
-
"@fuzdev/fuz_css": "^0.
|
|
81
|
-
"@fuzdev/fuz_ui": "^0.
|
|
82
|
-
"@fuzdev/gro": "^0.197.
|
|
80
|
+
"@fuzdev/fuz_css": "^0.58.0",
|
|
81
|
+
"@fuzdev/fuz_ui": "^0.191.3",
|
|
82
|
+
"@fuzdev/gro": "^0.197.3",
|
|
83
83
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
84
84
|
"@ryanatkn/eslint-config": "^0.10.1",
|
|
85
85
|
"@sveltejs/acorn-typescript": "^1.0.9",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"magic-string": "^0.30.21",
|
|
99
99
|
"prettier": "^3.7.4",
|
|
100
100
|
"prettier-plugin-svelte": "^3.4.1",
|
|
101
|
-
"svelte": "^5.
|
|
101
|
+
"svelte": "^5.55.0",
|
|
102
102
|
"svelte-check": "^4.3.6",
|
|
103
103
|
"svelte2tsx": "^0.7.47",
|
|
104
104
|
"tslib": "^2.8.1",
|
package/src/lib/args.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type ArgValue = string | number | boolean | undefined | Array<string | nu
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Schema description for help text generation.
|
|
28
|
-
* Not used by args_parse
|
|
28
|
+
* Not used by `args_parse`/`args_serialize` directly - provided for consumers
|
|
29
29
|
* building CLI help output.
|
|
30
30
|
*/
|
|
31
31
|
export interface ArgSchema {
|
|
@@ -184,8 +184,8 @@ const get_schema_cache = (schema: z.ZodType): SchemaCacheEntry => {
|
|
|
184
184
|
*
|
|
185
185
|
* Results are cached per schema (WeakMap). Safe to call multiple times.
|
|
186
186
|
*
|
|
187
|
-
* @param schema
|
|
188
|
-
* @returns
|
|
187
|
+
* @param schema - zod object schema with optional alias metadata
|
|
188
|
+
* @returns validation result with success flag and optional error
|
|
189
189
|
*/
|
|
190
190
|
export const args_validate_schema = (
|
|
191
191
|
schema: z.ZodType,
|
|
@@ -209,8 +209,8 @@ export const args_validate_schema = (
|
|
|
209
209
|
*
|
|
210
210
|
* Schema analysis is cached per schema (WeakMap) for performance.
|
|
211
211
|
*
|
|
212
|
-
* @param unparsed_args
|
|
213
|
-
* @param schema
|
|
212
|
+
* @param unparsed_args - args object from CLI parser (mri, minimist, etc.)
|
|
213
|
+
* @param schema - zod object schema with optional alias metadata
|
|
214
214
|
* @returns Zod SafeParseResult with expanded/synced data on success
|
|
215
215
|
*/
|
|
216
216
|
export const args_parse = <TOutput extends Record<string, ArgValue> = Args>(
|
|
@@ -276,9 +276,9 @@ export const args_parse = <TOutput extends Record<string, ArgValue> = Args>(
|
|
|
276
276
|
*
|
|
277
277
|
* Schema analysis is cached per schema (WeakMap) for performance.
|
|
278
278
|
*
|
|
279
|
-
* @param args
|
|
280
|
-
* @param schema
|
|
281
|
-
* @returns
|
|
279
|
+
* @param args - args object to serialize
|
|
280
|
+
* @param schema - optional zod schema to extract aliases for short form preference
|
|
281
|
+
* @returns array of CLI argument strings
|
|
282
282
|
*/
|
|
283
283
|
export const args_serialize = (args: Args, schema?: z.ZodType): Array<string> => {
|
|
284
284
|
const result: Array<string> = [];
|
|
@@ -349,8 +349,8 @@ export const args_serialize = (args: Args, schema?: z.ZodType): Array<string> =>
|
|
|
349
349
|
*
|
|
350
350
|
* Note: Returns copies of the cached data to prevent mutation of internal cache.
|
|
351
351
|
*
|
|
352
|
-
* @param schema
|
|
353
|
-
* @returns
|
|
352
|
+
* @param schema - zod object schema with optional `.meta({aliases})` on fields
|
|
353
|
+
* @returns object with aliases map and canonical_keys set
|
|
354
354
|
*/
|
|
355
355
|
export const args_extract_aliases = (schema: z.ZodType): ArgsAliasesResult => {
|
|
356
356
|
const cache = get_schema_cache(schema);
|
|
@@ -419,8 +419,8 @@ const set_arg = (args: Args, key: string, value: string | number | boolean): voi
|
|
|
419
419
|
* The returned object uses `Object.create(null)` to prevent prototype pollution
|
|
420
420
|
* and allow any key name including `__proto__` and `constructor`.
|
|
421
421
|
*
|
|
422
|
-
* @param argv
|
|
423
|
-
* @returns
|
|
422
|
+
* @param argv - raw argument array (typically process.argv.slice(2))
|
|
423
|
+
* @returns parsed `Args` object with guaranteed `_` array (null prototype)
|
|
424
424
|
*/
|
|
425
425
|
export const argv_parse = (argv: Array<string>): ParsedArgs => {
|
|
426
426
|
// Use Object.create(null) to allow __proto__ as a normal key
|
package/src/lib/async.ts
CHANGED
|
@@ -38,10 +38,10 @@ export const create_deferred = <T>(): Deferred<T> => {
|
|
|
38
38
|
* Runs a function on each item with controlled concurrency.
|
|
39
39
|
* Like `map_concurrent` but doesn't collect results (more efficient for side effects).
|
|
40
40
|
*
|
|
41
|
-
* @param items items to process
|
|
42
|
-
* @param concurrency maximum number of concurrent operations
|
|
43
|
-
* @param fn function to apply to each item
|
|
44
|
-
* @param signal optional `AbortSignal` to cancel processing
|
|
41
|
+
* @param items - items to process
|
|
42
|
+
* @param concurrency - maximum number of concurrent operations
|
|
43
|
+
* @param fn - function to apply to each item
|
|
44
|
+
* @param signal - optional `AbortSignal` to cancel processing
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
47
|
* ```ts
|
|
@@ -123,10 +123,10 @@ export const each_concurrent = async <T>(
|
|
|
123
123
|
/**
|
|
124
124
|
* Maps over items with controlled concurrency, preserving input order.
|
|
125
125
|
*
|
|
126
|
-
* @param items items to process
|
|
127
|
-
* @param concurrency maximum number of concurrent operations
|
|
128
|
-
* @param fn function to apply to each item
|
|
129
|
-
* @param signal optional `AbortSignal` to cancel processing
|
|
126
|
+
* @param items - items to process
|
|
127
|
+
* @param concurrency - maximum number of concurrent operations
|
|
128
|
+
* @param fn - function to apply to each item
|
|
129
|
+
* @param signal - optional `AbortSignal` to cancel processing
|
|
130
130
|
* @returns promise resolving to array of results in same order as input
|
|
131
131
|
*
|
|
132
132
|
* @example
|
|
@@ -215,10 +215,10 @@ export const map_concurrent = async <T, R>(
|
|
|
215
215
|
* On abort, resolves with partial results: completed items keep their real settlements,
|
|
216
216
|
* in-flight and un-started items are settled as rejected with the abort reason.
|
|
217
217
|
*
|
|
218
|
-
* @param items items to process
|
|
219
|
-
* @param concurrency maximum number of concurrent operations
|
|
220
|
-
* @param fn function to apply to each item
|
|
221
|
-
* @param signal optional `AbortSignal` to cancel processing
|
|
218
|
+
* @param items - items to process
|
|
219
|
+
* @param concurrency - maximum number of concurrent operations
|
|
220
|
+
* @param fn - function to apply to each item
|
|
221
|
+
* @param signal - optional `AbortSignal` to cancel processing
|
|
222
222
|
* @returns promise resolving to array of `PromiseSettledResult` objects in input order
|
|
223
223
|
*
|
|
224
224
|
* @example
|