@vibe-agent-toolkit/utils 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,6 +29,50 @@ import {
29
29
 
30
30
  ## Available Utilities
31
31
 
32
+ ### Zod Type Introspection (Version-Agnostic)
33
+
34
+ **Purpose**: Runtime Zod type detection that works across Zod v3 and v4.
35
+
36
+ Uses duck typing via `_def.typeName` instead of `instanceof` checks, which fail when library and user Zod versions differ. Essential for libraries that accept user-provided Zod schemas.
37
+
38
+ **Quick Example**:
39
+ ```typescript
40
+ import { getZodTypeName, isZodType, ZodTypeNames } from '@vibe-agent-toolkit/utils';
41
+ import { z } from 'zod';
42
+
43
+ const schema = z.string().optional();
44
+
45
+ // Get type name (works with Zod v3 or v4)
46
+ const typeName = getZodTypeName(schema);
47
+ console.log(typeName); // 'ZodOptional'
48
+
49
+ // Check if matches expected type
50
+ if (isZodType(schema, ZodTypeNames.STRING)) {
51
+ console.log('String type!');
52
+ }
53
+ ```
54
+
55
+ **Available Functions**:
56
+ - `getZodTypeName(zodType)` - Extract `_def.typeName` safely
57
+ - `isZodType(zodType, typeName)` - Check if type matches expected name
58
+ - `unwrapZodType(zodType)` - Unwrap optional/nullable to get inner type
59
+ - `isZodOptional(zodType)` - Check if type is optional
60
+ - `isZodNullable(zodType)` - Check if type is nullable
61
+
62
+ **Available Constants** (`ZodTypeNames`):
63
+ ```typescript
64
+ STRING, NUMBER, BOOLEAN, ARRAY, OBJECT, ENUM,
65
+ OPTIONAL, NULLABLE, DATE, BIGINT, NATIVENUM,
66
+ UNION, INTERSECTION, TUPLE, RECORD, MAP, SET,
67
+ FUNCTION, LAZY, PROMISE, and more...
68
+ ```
69
+
70
+ **See**: [docs/zod-compatibility.md](../../docs/zod-compatibility.md) for complete guide
71
+
72
+ **Peer Dependency**: Requires `zod ^3.25.0 || ^4.0.0`
73
+
74
+ ---
75
+
32
76
  ### Process Spawning
33
77
  - `safeExecSync()` - Cross-platform secure command execution without shell
34
78
 
@@ -37,9 +37,32 @@ export declare function gitLsFiles(options: {
37
37
  *
38
38
  * Uses git check-ignore which respects .gitignore, .git/info/exclude, and global gitignore
39
39
  *
40
+ * **Performance warning**: This spawns a git subprocess for each file.
41
+ * For checking multiple files, use `gitCheckIgnoredBatch()` instead.
42
+ *
40
43
  * @param filePath - Absolute or relative path to check
41
44
  * @param cwd - Working directory (defaults to process.cwd())
42
45
  * @returns true if file is gitignored, false otherwise
43
46
  */
44
47
  export declare function isGitIgnored(filePath: string, cwd?: string): boolean;
48
+ /**
49
+ * Batch check if multiple file paths are ignored by git
50
+ *
51
+ * Much more efficient than calling `isGitIgnored()` in a loop - uses a single
52
+ * git subprocess with stdin instead of N subprocesses.
53
+ *
54
+ * @param filePaths - Array of absolute or relative paths to check
55
+ * @param cwd - Working directory (defaults to process.cwd())
56
+ * @returns Map of filePath -> isIgnored (true if gitignored, false otherwise)
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const files = ['src/foo.ts', 'dist/bar.js', 'node_modules/baz.js'];
61
+ * const ignoreMap = gitCheckIgnoredBatch(files, '/project');
62
+ * // ignoreMap.get('src/foo.ts') === false
63
+ * // ignoreMap.get('dist/bar.js') === true
64
+ * // ignoreMap.get('node_modules/baz.js') === true
65
+ * ```
66
+ */
67
+ export declare function gitCheckIgnoredBatch(filePaths: string[], cwd?: string): Map<string, boolean>;
45
68
  //# sourceMappingURL=git-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"git-utils.d.ts","sourceRoot":"","sources":["../src/git-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc3D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,GAAG,MAAM,EAAE,GAAG,IAAI,CA0ClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAkBnF"}
1
+ {"version":3,"file":"git-utils.d.ts","sourceRoot":"","sources":["../src/git-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc3D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,GAAG,MAAM,EAAE,GAAG,IAAI,CA0ClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAkBnF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,MAAsB,GAC1B,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CA8DtB"}
package/dist/git-utils.js CHANGED
@@ -6,6 +6,7 @@ import { spawnSync } from 'node:child_process';
6
6
  import { existsSync } from 'node:fs';
7
7
  import { dirname, join, parse, resolve } from 'node:path';
8
8
  import which from 'which';
9
+ import { toForwardSlash } from './path-utils.js';
9
10
  /**
10
11
  * Find the git repository root by walking up from the given directory.
11
12
  *
@@ -85,6 +86,9 @@ export function gitLsFiles(options) {
85
86
  *
86
87
  * Uses git check-ignore which respects .gitignore, .git/info/exclude, and global gitignore
87
88
  *
89
+ * **Performance warning**: This spawns a git subprocess for each file.
90
+ * For checking multiple files, use `gitCheckIgnoredBatch()` instead.
91
+ *
88
92
  * @param filePath - Absolute or relative path to check
89
93
  * @param cwd - Working directory (defaults to process.cwd())
90
94
  * @returns true if file is gitignored, false otherwise
@@ -107,4 +111,78 @@ export function isGitIgnored(filePath, cwd = process.cwd()) {
107
111
  return false;
108
112
  }
109
113
  }
114
+ /**
115
+ * Batch check if multiple file paths are ignored by git
116
+ *
117
+ * Much more efficient than calling `isGitIgnored()` in a loop - uses a single
118
+ * git subprocess with stdin instead of N subprocesses.
119
+ *
120
+ * @param filePaths - Array of absolute or relative paths to check
121
+ * @param cwd - Working directory (defaults to process.cwd())
122
+ * @returns Map of filePath -> isIgnored (true if gitignored, false otherwise)
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const files = ['src/foo.ts', 'dist/bar.js', 'node_modules/baz.js'];
127
+ * const ignoreMap = gitCheckIgnoredBatch(files, '/project');
128
+ * // ignoreMap.get('src/foo.ts') === false
129
+ * // ignoreMap.get('dist/bar.js') === true
130
+ * // ignoreMap.get('node_modules/baz.js') === true
131
+ * ```
132
+ */
133
+ export function gitCheckIgnoredBatch(filePaths, cwd = process.cwd()) {
134
+ const result = new Map();
135
+ // No files to check
136
+ if (filePaths.length === 0) {
137
+ return result;
138
+ }
139
+ // Normalize paths to forward slashes for cross-platform consistency
140
+ // Git on Windows returns forward slashes, so we normalize input paths to match
141
+ const normalizedPaths = filePaths.map(p => toForwardSlash(p));
142
+ // Create map with normalized paths as keys
143
+ const pathMap = new Map(); // normalized -> original
144
+ for (const [index, normalizedPath] of normalizedPaths.entries()) {
145
+ const originalPath = filePaths[index];
146
+ if (originalPath !== undefined) {
147
+ pathMap.set(normalizedPath, originalPath);
148
+ }
149
+ }
150
+ // Initialize all as not ignored (using original paths as keys)
151
+ for (const filePath of filePaths) {
152
+ result.set(filePath, false);
153
+ }
154
+ try {
155
+ // Resolve git path using which for security (avoids PATH manipulation)
156
+ const gitPath = which.sync('git');
157
+ // git check-ignore --stdin reads paths from stdin and outputs ignored ones
158
+ // Send normalized paths to git
159
+ const gitResult = spawnSync(gitPath, ['check-ignore', '--stdin'], {
160
+ cwd,
161
+ encoding: 'utf-8',
162
+ input: normalizedPaths.join('\n'),
163
+ stdio: 'pipe',
164
+ shell: false, // No shell interpreter for security
165
+ });
166
+ // Exit code 0 = at least one file ignored, 1 = none ignored
167
+ // Parse stdout to get which files are ignored
168
+ if (gitResult.status === 0 && gitResult.stdout) {
169
+ const ignoredPaths = gitResult.stdout
170
+ .split('\n')
171
+ .map((line) => line.trim())
172
+ .filter((line) => line.length > 0);
173
+ // Mark ignored files (convert back to original paths)
174
+ for (const ignoredPath of ignoredPaths) {
175
+ const originalPath = pathMap.get(ignoredPath);
176
+ if (originalPath !== undefined) {
177
+ result.set(originalPath, true);
178
+ }
179
+ }
180
+ }
181
+ return result;
182
+ }
183
+ catch {
184
+ // If git is not available or other error, return all as not ignored
185
+ return result;
186
+ }
187
+ }
110
188
  //# sourceMappingURL=git-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"git-utils.js","sourceRoot":"","sources":["../src/git-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,IAAI,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;IAEpC,OAAO,UAAU,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,MAA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C,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM;iBAClC,KAAK,CAAC,IAAI,CAAC;iBACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;iBAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAErC,sDAAsD;YACtD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;gBACvC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAC9C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;oBAC/B,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;QACpE,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -12,4 +12,5 @@ export * from './gitignore-checker.js';
12
12
  export * from './git-utils.js';
13
13
  export * from './git-tracker.js';
14
14
  export * from './test-helpers.js';
15
+ export * from './zod-introspection.js';
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,eAAe,CAAC;AAG9B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,eAAe,CAAC;AAG9B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -20,4 +20,6 @@ export * from './git-utils.js';
20
20
  export * from './git-tracker.js';
21
21
  // Test helpers for isolated test output directories
22
22
  export * from './test-helpers.js';
23
+ // Zod type introspection (version-agnostic)
24
+ export * from './zod-introspection.js';
23
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8DAA8D;AAC9D,cAAc,gBAAgB,CAAC;AAE/B,gCAAgC;AAChC,cAAc,iBAAiB,CAAC;AAEhC,uBAAuB;AACvB,cAAc,eAAe,CAAC;AAE9B,wCAAwC;AACxC,cAAc,mBAAmB,CAAC;AAElC,sBAAsB;AACtB,cAAc,wBAAwB,CAAC;AAEvC,8CAA8C;AAC9C,cAAc,gBAAgB,CAAC;AAE/B,yDAAyD;AACzD,cAAc,kBAAkB,CAAC;AAEjC,oDAAoD;AACpD,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8DAA8D;AAC9D,cAAc,gBAAgB,CAAC;AAE/B,gCAAgC;AAChC,cAAc,iBAAiB,CAAC;AAEhC,uBAAuB;AACvB,cAAc,eAAe,CAAC;AAE9B,wCAAwC;AACxC,cAAc,mBAAmB,CAAC;AAElC,sBAAsB;AACtB,cAAc,wBAAwB,CAAC;AAEvC,8CAA8C;AAC9C,cAAc,gBAAgB,CAAC;AAE/B,yDAAyD;AACzD,cAAc,kBAAkB,CAAC;AAEjC,oDAAoD;AACpD,cAAc,mBAAmB,CAAC;AAElC,4CAA4C;AAC5C,cAAc,wBAAwB,CAAC"}
@@ -35,4 +35,68 @@ export declare function getTestOutputDir(packageName: string, testType: 'unit' |
35
35
  * ```
36
36
  */
37
37
  export declare function getTestOutputBase(packageName: string): string;
38
+ /**
39
+ * Per-suite temp directory pattern (async version)
40
+ * Creates a single temp directory for the entire test suite,
41
+ * with subdirectories for each test. This is 3-5x faster on Windows
42
+ * than creating a new mkdtemp for each test.
43
+ *
44
+ * @param prefix - Prefix for the suite temp directory name
45
+ * @returns Suite helper with beforeAll, afterAll, beforeEach, afterEach, and getTempDir
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const suite = setupAsyncTempDirSuite('my-test');
50
+ *
51
+ * describe('my tests', () => {
52
+ * beforeAll(suite.beforeAll);
53
+ * afterAll(suite.afterAll);
54
+ * beforeEach(suite.beforeEach);
55
+ *
56
+ * it('test 1', async () => {
57
+ * const tempDir = suite.getTempDir();
58
+ * // Use tempDir...
59
+ * });
60
+ * });
61
+ * ```
62
+ */
63
+ export declare function setupAsyncTempDirSuite(prefix: string): {
64
+ beforeAll: () => Promise<void>;
65
+ afterAll: () => Promise<void>;
66
+ beforeEach: () => Promise<void>;
67
+ afterEach: () => Promise<void>;
68
+ getTempDir: () => string;
69
+ };
70
+ /**
71
+ * Per-suite temp directory pattern (sync version)
72
+ * Creates a single temp directory for the entire test suite,
73
+ * with subdirectories for each test. This is 3-5x faster on Windows
74
+ * than creating a new mkdtemp for each test.
75
+ *
76
+ * @param prefix - Prefix for the suite temp directory name
77
+ * @returns Suite helper with beforeAll, afterAll, beforeEach, afterEach, and getTempDir
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const suite = setupSyncTempDirSuite('my-test');
82
+ *
83
+ * describe('my tests', () => {
84
+ * beforeAll(suite.beforeAll);
85
+ * afterAll(suite.afterAll);
86
+ * beforeEach(suite.beforeEach);
87
+ *
88
+ * it('test 1', () => {
89
+ * const tempDir = suite.getTempDir();
90
+ * // Use tempDir...
91
+ * });
92
+ * });
93
+ * ```
94
+ */
95
+ export declare function setupSyncTempDirSuite(prefix: string): {
96
+ beforeAll: () => void;
97
+ afterAll: () => void;
98
+ beforeEach: () => void;
99
+ afterEach: () => void;
100
+ getTempDir: () => string;
101
+ };
38
102
  //# sourceMappingURL=test-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../src/test-helpers.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,QAAQ,EAC3C,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,MAAM,CAuBR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG7D"}
1
+ {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["../src/test-helpers.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,QAAQ,EAC3C,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,MAAM,CAuBR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG;IACtD,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,UAAU,EAAE,MAAM,MAAM,CAAC;CAC1B,CAyBA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG;IACrD,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,MAAM,CAAC;CAC1B,CAwBA"}
@@ -1,6 +1,8 @@
1
1
  import { randomBytes } from 'node:crypto';
2
+ import { mkdtempSync, rmSync } from 'node:fs';
3
+ import fs from 'node:fs/promises';
2
4
  import { join, resolve } from 'node:path';
3
- import { mkdirSyncReal } from './path-utils.js';
5
+ import { mkdirSyncReal, normalizedTmpdir } from './path-utils.js';
4
6
  /**
5
7
  * Get isolated test output directory for current test run
6
8
  *
@@ -52,4 +54,103 @@ export function getTestOutputBase(packageName) {
52
54
  const projectRoot = resolve(process.cwd());
53
55
  return join(projectRoot, 'packages', packageName, '.test-output');
54
56
  }
57
+ /**
58
+ * Per-suite temp directory pattern (async version)
59
+ * Creates a single temp directory for the entire test suite,
60
+ * with subdirectories for each test. This is 3-5x faster on Windows
61
+ * than creating a new mkdtemp for each test.
62
+ *
63
+ * @param prefix - Prefix for the suite temp directory name
64
+ * @returns Suite helper with beforeAll, afterAll, beforeEach, afterEach, and getTempDir
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const suite = setupAsyncTempDirSuite('my-test');
69
+ *
70
+ * describe('my tests', () => {
71
+ * beforeAll(suite.beforeAll);
72
+ * afterAll(suite.afterAll);
73
+ * beforeEach(suite.beforeEach);
74
+ *
75
+ * it('test 1', async () => {
76
+ * const tempDir = suite.getTempDir();
77
+ * // Use tempDir...
78
+ * });
79
+ * });
80
+ * ```
81
+ */
82
+ export function setupAsyncTempDirSuite(prefix) {
83
+ let suiteDir = '';
84
+ let tempDir = '';
85
+ let testCounter = 0;
86
+ return {
87
+ beforeAll: async () => {
88
+ suiteDir = await fs.mkdtemp(join(normalizedTmpdir(), `${prefix}-suite-`));
89
+ },
90
+ afterAll: async () => {
91
+ if (suiteDir) {
92
+ await fs.rm(suiteDir, { recursive: true, force: true });
93
+ }
94
+ },
95
+ beforeEach: async () => {
96
+ testCounter++;
97
+ tempDir = join(suiteDir, `test-${testCounter}`);
98
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- tempDir is from mkdtemp
99
+ await fs.mkdir(tempDir, { recursive: true });
100
+ },
101
+ afterEach: async () => {
102
+ // Per-test cleanup handled by suite cleanup
103
+ },
104
+ getTempDir: () => tempDir,
105
+ };
106
+ }
107
+ /**
108
+ * Per-suite temp directory pattern (sync version)
109
+ * Creates a single temp directory for the entire test suite,
110
+ * with subdirectories for each test. This is 3-5x faster on Windows
111
+ * than creating a new mkdtemp for each test.
112
+ *
113
+ * @param prefix - Prefix for the suite temp directory name
114
+ * @returns Suite helper with beforeAll, afterAll, beforeEach, afterEach, and getTempDir
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const suite = setupSyncTempDirSuite('my-test');
119
+ *
120
+ * describe('my tests', () => {
121
+ * beforeAll(suite.beforeAll);
122
+ * afterAll(suite.afterAll);
123
+ * beforeEach(suite.beforeEach);
124
+ *
125
+ * it('test 1', () => {
126
+ * const tempDir = suite.getTempDir();
127
+ * // Use tempDir...
128
+ * });
129
+ * });
130
+ * ```
131
+ */
132
+ export function setupSyncTempDirSuite(prefix) {
133
+ let suiteDir = '';
134
+ let tempDir = '';
135
+ let testCounter = 0;
136
+ return {
137
+ beforeAll: () => {
138
+ suiteDir = mkdtempSync(join(normalizedTmpdir(), `${prefix}-suite-`));
139
+ },
140
+ afterAll: () => {
141
+ if (suiteDir) {
142
+ rmSync(suiteDir, { recursive: true, force: true });
143
+ }
144
+ },
145
+ beforeEach: () => {
146
+ testCounter++;
147
+ tempDir = join(suiteDir, `test-${testCounter}`);
148
+ mkdirSyncReal(tempDir);
149
+ },
150
+ afterEach: () => {
151
+ // Per-test cleanup handled by suite cleanup
152
+ },
153
+ getTempDir: () => tempDir,
154
+ };
155
+ }
55
156
  //# sourceMappingURL=test-helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../src/test-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,WAAmB,EACnB,QAA2C,EAC3C,GAAG,OAAiB;IAEpB,iDAAiD;IACjD,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjF,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,GAAG,SAAS,IAAI,QAAQ,EAAE,CAAC;IAEzC,iEAAiE;IACjE,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE3C,kFAAkF;IAClF,MAAM,aAAa,GAAG,IAAI,CACxB,WAAW,EACX,UAAU,EACV,WAAW,EACX,cAAc,EACd,QAAQ,EACR,KAAK,EACL,GAAG,OAAO,CACX,CAAC;IAEF,wDAAwD;IAExD,OAAO,aAAa,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB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C;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAOlD,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,OAAO;QACL,SAAS,EAAE,GAAG,EAAE;YACd,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,GAAG,MAAM,SAAS,CAAC,CAAC,CAAC;QACvE,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACb,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QACD,UAAU,EAAE,GAAG,EAAE;YACf,WAAW,EAAE,CAAC;YACd,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,QAAQ,WAAW,EAAE,CAAC,CAAC;YAChD,aAAa,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,4CAA4C;QAC9C,CAAC;QACD,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO;KAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Zod type introspection utilities
3
+ *
4
+ * Provides version-agnostic type detection using duck typing instead of
5
+ * instanceof checks, which fail across Zod v3/v4 boundaries.
6
+ *
7
+ * @module zod-introspection
8
+ */
9
+ /**
10
+ * Zod type names from _def.typeName
11
+ *
12
+ * These internal type names are stable across Zod v3 and v4.
13
+ * Using these constants instead of instanceof checks ensures
14
+ * compatibility when user's Zod version differs from library's.
15
+ *
16
+ * @see https://github.com/colinhacks/zod/issues/2543
17
+ */
18
+ export declare const ZodTypeNames: {
19
+ readonly STRING: "ZodString";
20
+ readonly NUMBER: "ZodNumber";
21
+ readonly BOOLEAN: "ZodBoolean";
22
+ readonly ARRAY: "ZodArray";
23
+ readonly OBJECT: "ZodObject";
24
+ readonly ENUM: "ZodEnum";
25
+ readonly OPTIONAL: "ZodOptional";
26
+ readonly NULLABLE: "ZodNullable";
27
+ readonly DATE: "ZodDate";
28
+ readonly LITERAL: "ZodLiteral";
29
+ readonly UNION: "ZodUnion";
30
+ readonly INTERSECTION: "ZodIntersection";
31
+ readonly TUPLE: "ZodTuple";
32
+ readonly RECORD: "ZodRecord";
33
+ readonly MAP: "ZodMap";
34
+ readonly SET: "ZodSet";
35
+ readonly FUNCTION: "ZodFunction";
36
+ readonly LAZY: "ZodLazy";
37
+ readonly PROMISE: "ZodPromise";
38
+ readonly BRANDED: "ZodBranded";
39
+ readonly PIPELINE: "ZodPipeline";
40
+ readonly READONLY: "ZodReadonly";
41
+ readonly SYMBOL: "ZodSymbol";
42
+ readonly UNDEFINED: "ZodUndefined";
43
+ readonly NULL: "ZodNull";
44
+ readonly ANY: "ZodAny";
45
+ readonly UNKNOWN: "ZodUnknown";
46
+ readonly NEVER: "ZodNever";
47
+ readonly VOID: "ZodVoid";
48
+ readonly BIGINT: "ZodBigInt";
49
+ readonly EFFECTS: "ZodEffects";
50
+ readonly NATIVENUM: "ZodNativeEnum";
51
+ readonly DISCRIMINATED_UNION: "ZodDiscriminatedUnion";
52
+ readonly DEFAULT: "ZodDefault";
53
+ readonly CATCH: "ZodCatch";
54
+ readonly NAN: "ZodNaN";
55
+ };
56
+ /**
57
+ * Type representing valid Zod type names
58
+ */
59
+ export type ZodTypeName = (typeof ZodTypeNames)[keyof typeof ZodTypeNames];
60
+ /**
61
+ * Get Zod type name in version-agnostic way
62
+ *
63
+ * Supports both Zod v3 and v4:
64
+ * - Zod v3: Uses _def.typeName (e.g., 'ZodString')
65
+ * - Zod v4: Uses _def.type (e.g., 'string'), converts to v3 format
66
+ *
67
+ * Uses duck typing instead of instanceof checks, which fail when
68
+ * user's Zod version differs from library's Zod version.
69
+ *
70
+ * @param zodType - Zod type to introspect
71
+ * @returns Type name string (e.g., 'ZodString') or undefined if not a Zod type
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { z } from 'zod';
76
+ * import { getZodTypeName, ZodTypeNames } from '@vibe-agent-toolkit/utils';
77
+ *
78
+ * const schema = z.string();
79
+ * const typeName = getZodTypeName(schema);
80
+ * console.log(typeName); // 'ZodString' (both v3 and v4)
81
+ *
82
+ * if (typeName === ZodTypeNames.STRING) {
83
+ * console.log('It\'s a string schema!');
84
+ * }
85
+ * ```
86
+ */
87
+ export declare function getZodTypeName(zodType: unknown): string | undefined;
88
+ /**
89
+ * Check if Zod type matches expected type name
90
+ *
91
+ * Version-agnostic type checking using duck typing.
92
+ * Safer than instanceof when Zod versions may differ.
93
+ *
94
+ * @param zodType - Zod type to check
95
+ * @param typeName - Expected type name constant from ZodTypeNames
96
+ * @returns True if type matches, false otherwise
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * import { z } from 'zod';
101
+ * import { isZodType, ZodTypeNames } from '@vibe-agent-toolkit/utils';
102
+ *
103
+ * const schema = z.array(z.string());
104
+ *
105
+ * if (isZodType(schema, ZodTypeNames.ARRAY)) {
106
+ * console.log('It\'s an array schema!');
107
+ * }
108
+ * ```
109
+ */
110
+ export declare function isZodType(zodType: unknown, typeName: ZodTypeName): boolean;
111
+ /**
112
+ * Unwrap optional/nullable Zod types to get inner type
113
+ *
114
+ * Recursively unwraps ZodOptional and ZodNullable to reach
115
+ * the underlying type. Returns original type if not wrapped.
116
+ *
117
+ * @param zodType - Zod type to unwrap
118
+ * @returns Unwrapped Zod type
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * import { z } from 'zod';
123
+ * import { unwrapZodType, getZodTypeName, ZodTypeNames } from '@vibe-agent-toolkit/utils';
124
+ *
125
+ * const schema = z.string().optional();
126
+ * const unwrapped = unwrapZodType(schema);
127
+ *
128
+ * console.log(getZodTypeName(unwrapped)); // 'ZodString'
129
+ * ```
130
+ */
131
+ export declare function unwrapZodType(zodType: unknown): unknown;
132
+ /**
133
+ * Check if Zod type is optional (ZodOptional)
134
+ *
135
+ * @param zodType - Zod type to check
136
+ * @returns True if type is optional
137
+ */
138
+ export declare function isZodOptional(zodType: unknown): boolean;
139
+ /**
140
+ * Check if Zod type is nullable (ZodNullable)
141
+ *
142
+ * @param zodType - Zod type to check
143
+ * @returns True if type is nullable
144
+ */
145
+ export declare function isZodNullable(zodType: unknown): boolean;
146
+ //# sourceMappingURL=zod-introspection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-introspection.d.ts","sourceRoot":"","sources":["../src/zod-introspection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCf,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAkC3E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAiBnE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAE1E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAUvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEvD"}
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Zod type introspection utilities
3
+ *
4
+ * Provides version-agnostic type detection using duck typing instead of
5
+ * instanceof checks, which fail across Zod v3/v4 boundaries.
6
+ *
7
+ * @module zod-introspection
8
+ */
9
+ /**
10
+ * Zod type names from _def.typeName
11
+ *
12
+ * These internal type names are stable across Zod v3 and v4.
13
+ * Using these constants instead of instanceof checks ensures
14
+ * compatibility when user's Zod version differs from library's.
15
+ *
16
+ * @see https://github.com/colinhacks/zod/issues/2543
17
+ */
18
+ export const ZodTypeNames = {
19
+ STRING: 'ZodString',
20
+ NUMBER: 'ZodNumber',
21
+ BOOLEAN: 'ZodBoolean',
22
+ ARRAY: 'ZodArray',
23
+ OBJECT: 'ZodObject',
24
+ ENUM: 'ZodEnum',
25
+ OPTIONAL: 'ZodOptional',
26
+ NULLABLE: 'ZodNullable',
27
+ DATE: 'ZodDate',
28
+ LITERAL: 'ZodLiteral',
29
+ UNION: 'ZodUnion',
30
+ INTERSECTION: 'ZodIntersection',
31
+ TUPLE: 'ZodTuple',
32
+ RECORD: 'ZodRecord',
33
+ MAP: 'ZodMap',
34
+ SET: 'ZodSet',
35
+ FUNCTION: 'ZodFunction',
36
+ LAZY: 'ZodLazy',
37
+ PROMISE: 'ZodPromise',
38
+ BRANDED: 'ZodBranded',
39
+ PIPELINE: 'ZodPipeline',
40
+ READONLY: 'ZodReadonly',
41
+ SYMBOL: 'ZodSymbol',
42
+ UNDEFINED: 'ZodUndefined',
43
+ NULL: 'ZodNull',
44
+ ANY: 'ZodAny',
45
+ UNKNOWN: 'ZodUnknown',
46
+ NEVER: 'ZodNever',
47
+ VOID: 'ZodVoid',
48
+ BIGINT: 'ZodBigInt',
49
+ EFFECTS: 'ZodEffects',
50
+ NATIVENUM: 'ZodNativeEnum',
51
+ DISCRIMINATED_UNION: 'ZodDiscriminatedUnion',
52
+ DEFAULT: 'ZodDefault',
53
+ CATCH: 'ZodCatch',
54
+ NAN: 'ZodNaN',
55
+ };
56
+ /**
57
+ * Convert Zod v4 lowercase type to v3 PascalCase format
58
+ *
59
+ * Zod v4 changed from _def.typeName ('ZodString') to _def.type ('string').
60
+ * This function normalizes v4 types to match v3 format for consistency.
61
+ *
62
+ * @param v4Type - Lowercase type from Zod v4 _def.type
63
+ * @returns PascalCase type name with 'Zod' prefix
64
+ * @internal
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * zodV4TypeToV3Name('string') // 'ZodString'
69
+ * zodV4TypeToV3Name('array') // 'ZodArray'
70
+ * zodV4TypeToV3Name('optional') // 'ZodOptional'
71
+ * ```
72
+ */
73
+ function zodV4TypeToV3Name(v4Type) {
74
+ // Handle special cases with different naming
75
+ const specialCases = {
76
+ nativeenum: 'ZodNativeEnum',
77
+ bigint: 'ZodBigInt',
78
+ };
79
+ if (specialCases[v4Type]) {
80
+ return specialCases[v4Type];
81
+ }
82
+ // Convert: 'string' → 'ZodString', 'array' → 'ZodArray'
83
+ return 'Zod' + v4Type.charAt(0).toUpperCase() + v4Type.slice(1);
84
+ }
85
+ /**
86
+ * Get Zod type name in version-agnostic way
87
+ *
88
+ * Supports both Zod v3 and v4:
89
+ * - Zod v3: Uses _def.typeName (e.g., 'ZodString')
90
+ * - Zod v4: Uses _def.type (e.g., 'string'), converts to v3 format
91
+ *
92
+ * Uses duck typing instead of instanceof checks, which fail when
93
+ * user's Zod version differs from library's Zod version.
94
+ *
95
+ * @param zodType - Zod type to introspect
96
+ * @returns Type name string (e.g., 'ZodString') or undefined if not a Zod type
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * import { z } from 'zod';
101
+ * import { getZodTypeName, ZodTypeNames } from '@vibe-agent-toolkit/utils';
102
+ *
103
+ * const schema = z.string();
104
+ * const typeName = getZodTypeName(schema);
105
+ * console.log(typeName); // 'ZodString' (both v3 and v4)
106
+ *
107
+ * if (typeName === ZodTypeNames.STRING) {
108
+ * console.log('It\'s a string schema!');
109
+ * }
110
+ * ```
111
+ */
112
+ export function getZodTypeName(zodType) {
113
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
+ const def = zodType?._def;
115
+ if (!def)
116
+ return undefined;
117
+ // Zod v3: uses _def.typeName (e.g., 'ZodString')
118
+ if (def.typeName) {
119
+ return def.typeName;
120
+ }
121
+ // Zod v4: uses _def.type (e.g., 'string')
122
+ // Convert to Zod v3 format for consistency
123
+ if (def.type) {
124
+ return zodV4TypeToV3Name(def.type);
125
+ }
126
+ return undefined;
127
+ }
128
+ /**
129
+ * Check if Zod type matches expected type name
130
+ *
131
+ * Version-agnostic type checking using duck typing.
132
+ * Safer than instanceof when Zod versions may differ.
133
+ *
134
+ * @param zodType - Zod type to check
135
+ * @param typeName - Expected type name constant from ZodTypeNames
136
+ * @returns True if type matches, false otherwise
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * import { z } from 'zod';
141
+ * import { isZodType, ZodTypeNames } from '@vibe-agent-toolkit/utils';
142
+ *
143
+ * const schema = z.array(z.string());
144
+ *
145
+ * if (isZodType(schema, ZodTypeNames.ARRAY)) {
146
+ * console.log('It\'s an array schema!');
147
+ * }
148
+ * ```
149
+ */
150
+ export function isZodType(zodType, typeName) {
151
+ return getZodTypeName(zodType) === typeName;
152
+ }
153
+ /**
154
+ * Unwrap optional/nullable Zod types to get inner type
155
+ *
156
+ * Recursively unwraps ZodOptional and ZodNullable to reach
157
+ * the underlying type. Returns original type if not wrapped.
158
+ *
159
+ * @param zodType - Zod type to unwrap
160
+ * @returns Unwrapped Zod type
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * import { z } from 'zod';
165
+ * import { unwrapZodType, getZodTypeName, ZodTypeNames } from '@vibe-agent-toolkit/utils';
166
+ *
167
+ * const schema = z.string().optional();
168
+ * const unwrapped = unwrapZodType(schema);
169
+ *
170
+ * console.log(getZodTypeName(unwrapped)); // 'ZodString'
171
+ * ```
172
+ */
173
+ export function unwrapZodType(zodType) {
174
+ const typeName = getZodTypeName(zodType);
175
+ if (typeName === ZodTypeNames.OPTIONAL || typeName === ZodTypeNames.NULLABLE) {
176
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
177
+ const inner = zodType.unwrap?.() ?? zodType._def?.innerType;
178
+ return inner ? unwrapZodType(inner) : zodType;
179
+ }
180
+ return zodType;
181
+ }
182
+ /**
183
+ * Check if Zod type is optional (ZodOptional)
184
+ *
185
+ * @param zodType - Zod type to check
186
+ * @returns True if type is optional
187
+ */
188
+ export function isZodOptional(zodType) {
189
+ return isZodType(zodType, ZodTypeNames.OPTIONAL);
190
+ }
191
+ /**
192
+ * Check if Zod type is nullable (ZodNullable)
193
+ *
194
+ * @param zodType - Zod type to check
195
+ * @returns True if type is nullable
196
+ */
197
+ export function isZodNullable(zodType) {
198
+ return isZodType(zodType, ZodTypeNames.NULLABLE);
199
+ }
200
+ //# sourceMappingURL=zod-introspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-introspection.js","sourceRoot":"","sources":["../src/zod-introspection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,WAAW;IACnB,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,aAAa;IACvB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,UAAU;IACjB,YAAY,EAAE,iBAAiB;IAC/B,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,WAAW;IACnB,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,QAAQ,EAAE,aAAa;IACvB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,WAAW;IACnB,SAAS,EAAE,cAAc;IACzB,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,QAAQ;IACb,OAAO,EAAE,YAAY;IACrB,K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,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAEzC,IAAI,QAAQ,KAAK,YAAY,CAAC,QAAQ,IAAI,QAAQ,KAAK,YAAY,CAAC,QAAQ,EAAE,CAAC;QAC7E,8DAA8D;QAC9D,MAAM,KAAK,GAAI,OAAe,CAAC,MAAM,EAAE,EAAE,IAAK,OAAe,CAAC,IAAI,EAAE,SAAS,CAAC;QAC9E,OAAO,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-agent-toolkit/utils",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "Core utility functions with no external dependencies",
6
6
  "keywords": [
@@ -34,12 +34,16 @@
34
34
  "picomatch": "^4.0.3",
35
35
  "which": "^5.0.0"
36
36
  },
37
+ "peerDependencies": {
38
+ "zod": "^3.25.0 || ^4.0.0"
39
+ },
37
40
  "devDependencies": {
38
41
  "@types/picomatch": "^4.0.2",
39
42
  "@types/which": "^3.0.4",
40
43
  "rimraf": "^6.0.1",
41
44
  "typescript": "^5.9.3",
42
- "vitest": "^3.2.4"
45
+ "vitest": "^3.2.4",
46
+ "zod": "^3.25.0"
43
47
  },
44
48
  "publishConfig": {
45
49
  "access": "public"