zodvex 0.7.7-beta.2 → 0.7.7
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/cli/index.js +45 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/public/cli/commands.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/public/cli/commands.ts +59 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/public/cli/commands.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAsB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/public/cli/commands.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAsB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAmD9F;AAED;;GAEG;AACH,wBAAsB,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAexF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zodvex",
|
|
3
|
-
"version": "0.7.7
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Codec-first Zod v4 integration for Convex -- type-safe validation, encoding, DB wrapping, and codegen.",
|
|
5
5
|
"keywords": ["zod", "convex", "validators", "codec", "mapping", "schema", "validation"],
|
|
6
6
|
"homepage": "https://github.com/panzacoder/zodvex#readme",
|
|
@@ -20,21 +20,34 @@ export async function generate(convexDir?: string, options?: { mini?: boolean })
|
|
|
20
20
|
// Ensure _zodvex/api.js exists before discovery. User modules (e.g., functions.ts)
|
|
21
21
|
// may import zodvexRegistry from it. Without a stub, dynamic import() fails and
|
|
22
22
|
// codegen can't discover those modules — a chicken-and-egg problem.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
// Stubbing overwrites the previous generation, so if anything below throws
|
|
24
|
+
// (e.g. the strict import-failure error), restore the originals: a failed
|
|
25
|
+
// run must not clobber a good checked-in registry (#104).
|
|
26
|
+
const restoreStubbedApi = writeStubApi(zodvexDir)
|
|
27
|
+
|
|
28
|
+
let result: Awaited<ReturnType<typeof discoverModules>>
|
|
29
|
+
let schemaContent: ReturnType<typeof generateSchemaFile>
|
|
30
|
+
let apiContent: ReturnType<typeof generateApiFile>
|
|
31
|
+
let clientContent: ReturnType<typeof generateClientFile>
|
|
32
|
+
let serverContent: ReturnType<typeof generateServerFile>
|
|
33
|
+
try {
|
|
34
|
+
result = await discoverModules(resolved)
|
|
35
|
+
|
|
36
|
+
schemaContent = generateSchemaFile(result.models)
|
|
37
|
+
apiContent = generateApiFile(
|
|
38
|
+
result.functions,
|
|
39
|
+
result.models,
|
|
40
|
+
result.codecs,
|
|
41
|
+
result.modelCodecs,
|
|
42
|
+
result.functionCodecs,
|
|
43
|
+
{ mini: options?.mini }
|
|
44
|
+
)
|
|
45
|
+
clientContent = generateClientFile({ mini: options?.mini })
|
|
46
|
+
serverContent = generateServerFile()
|
|
47
|
+
} catch (err) {
|
|
48
|
+
restoreStubbedApi()
|
|
49
|
+
throw err
|
|
50
|
+
}
|
|
38
51
|
|
|
39
52
|
fs.mkdirSync(zodvexDir, { recursive: true })
|
|
40
53
|
writeIfChanged(path.join(zodvexDir, 'schema.js'), schemaContent.js)
|
|
@@ -122,8 +135,23 @@ export function regenerate(resolved: string, options?: { mini?: boolean }): Prom
|
|
|
122
135
|
}
|
|
123
136
|
|
|
124
137
|
/** Writes minimal stub _zodvex/api.js + api.d.ts before discovery to break circular imports.
|
|
125
|
-
* Previous generations may contain stale imports that cause cycles during re-discovery.
|
|
126
|
-
|
|
138
|
+
* Previous generations may contain stale imports that cause cycles during re-discovery.
|
|
139
|
+
*
|
|
140
|
+
* Returns a restore closure that puts the pre-existing files back (or removes
|
|
141
|
+
* the stubs if there were none) — called when generation fails so a failed
|
|
142
|
+
* run doesn't leave the gutted stub in place of a good registry (#104). */
|
|
143
|
+
function writeStubApi(zodvexDir: string): () => void {
|
|
144
|
+
const stubTargets = ['api.js', 'api.d.ts'].map(name => {
|
|
145
|
+
const filePath = path.join(zodvexDir, name)
|
|
146
|
+
let original: string | null
|
|
147
|
+
try {
|
|
148
|
+
original = fs.readFileSync(filePath, 'utf-8')
|
|
149
|
+
} catch {
|
|
150
|
+
original = null
|
|
151
|
+
}
|
|
152
|
+
return { filePath, original }
|
|
153
|
+
})
|
|
154
|
+
|
|
127
155
|
fs.mkdirSync(zodvexDir, { recursive: true })
|
|
128
156
|
|
|
129
157
|
fs.writeFileSync(
|
|
@@ -135,6 +163,20 @@ function writeStubApi(zodvexDir: string): void {
|
|
|
135
163
|
path.join(zodvexDir, 'api.d.ts'),
|
|
136
164
|
'// AUTO-GENERATED by zodvex — do not edit\n// Stub created for codegen bootstrap\n\nexport declare const zodvexRegistry: Record<string, any>\n'
|
|
137
165
|
)
|
|
166
|
+
|
|
167
|
+
return () => {
|
|
168
|
+
for (const { filePath, original } of stubTargets) {
|
|
169
|
+
try {
|
|
170
|
+
if (original !== null) {
|
|
171
|
+
fs.writeFileSync(filePath, original)
|
|
172
|
+
} else {
|
|
173
|
+
fs.unlinkSync(filePath)
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
// Best-effort restore — the thrown generation error is the headline.
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
138
180
|
}
|
|
139
181
|
|
|
140
182
|
/** Only write if content differs from what's on disk — prevents file watcher loops. */
|