zodvex 0.7.7-beta.2 → 0.7.8-beta.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/README.md +15 -0
- package/dist/cli/index.js +45 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/internal/customization.d.ts +27 -1
- package/dist/internal/customization.d.ts.map +1 -1
- package/dist/internal/db.d.ts +18 -0
- package/dist/internal/db.d.ts.map +1 -1
- package/dist/internal/init.d.ts +15 -1
- package/dist/internal/init.d.ts.map +1 -1
- package/dist/mini/server/index.js +40 -5
- package/dist/mini/server/index.js.map +1 -1
- package/dist/public/cli/commands.d.ts.map +1 -1
- package/dist/public/server/index.d.ts +1 -1
- package/dist/public/server/index.d.ts.map +1 -1
- package/dist/server/index.js +40 -5
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/customization.ts +42 -3
- package/src/internal/db.ts +24 -0
- package/src/internal/init.ts +40 -5
- package/src/public/cli/commands.ts +59 -17
- package/src/public/server/index.ts +4 -1
package/README.md
CHANGED
|
@@ -167,6 +167,21 @@ The same wrapped `ctx.db` carries per-row security and observability — both op
|
|
|
167
167
|
|
|
168
168
|
Guide: [Rules & Audit](./docs/guide/rules-and-audit.md)
|
|
169
169
|
|
|
170
|
+
### Composable with Triggers
|
|
171
|
+
|
|
172
|
+
The codec wrapper can delegate to an underlying db you supply, so `ctx.db`-wrapping libraries like `convex-helpers/server/triggers` compose instead of colliding — codec on top, triggers underneath, real db at the bottom:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const triggers = new Triggers<DataModel>()
|
|
176
|
+
export const { zq, zm, zim /* ... */ } = initZodvex(schema, server, {
|
|
177
|
+
underlyingDb: { mutation: (ctx) => triggers.wrapDB(ctx).db },
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Triggers fire inside zodvex mutations and observe native wire-format writes — which unlocks the aggregate component's table-trigger mode, model-bound cascades, and similar reactive patterns. `ctx.db.unwrap()` is the matching escape hatch for direct access to the underlying db.
|
|
182
|
+
|
|
183
|
+
Guide: [Builders — Composing with triggers](./docs/guide/builders.md#composing-with-convex-helpers-triggers-underlyingdb)
|
|
184
|
+
|
|
170
185
|
### Codegen & Client-Side Schema Sharing
|
|
171
186
|
|
|
172
187
|
zodvex includes an optional CLI that generates typed client code:
|
package/dist/cli/index.js
CHANGED
|
@@ -2405,19 +2405,29 @@ ${dtsDeclarations.join("\n")}
|
|
|
2405
2405
|
async function generate(convexDir2, options) {
|
|
2406
2406
|
const resolved = resolveConvexDir(convexDir2);
|
|
2407
2407
|
const zodvexDir = path4.join(resolved, "_zodvex");
|
|
2408
|
-
writeStubApi(zodvexDir);
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
result
|
|
2416
|
-
result.
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2408
|
+
const restoreStubbedApi = writeStubApi(zodvexDir);
|
|
2409
|
+
let result;
|
|
2410
|
+
let schemaContent;
|
|
2411
|
+
let apiContent;
|
|
2412
|
+
let clientContent;
|
|
2413
|
+
let serverContent;
|
|
2414
|
+
try {
|
|
2415
|
+
result = await discoverModules(resolved);
|
|
2416
|
+
schemaContent = generateSchemaFile(result.models);
|
|
2417
|
+
apiContent = generateApiFile(
|
|
2418
|
+
result.functions,
|
|
2419
|
+
result.models,
|
|
2420
|
+
result.codecs,
|
|
2421
|
+
result.modelCodecs,
|
|
2422
|
+
result.functionCodecs,
|
|
2423
|
+
{ mini: options?.mini }
|
|
2424
|
+
);
|
|
2425
|
+
clientContent = generateClientFile({ mini: options?.mini });
|
|
2426
|
+
serverContent = generateServerFile();
|
|
2427
|
+
} catch (err) {
|
|
2428
|
+
restoreStubbedApi();
|
|
2429
|
+
throw err;
|
|
2430
|
+
}
|
|
2421
2431
|
fs3.mkdirSync(zodvexDir, { recursive: true });
|
|
2422
2432
|
writeIfChanged(path4.join(zodvexDir, "schema.js"), schemaContent.js);
|
|
2423
2433
|
writeIfChanged(path4.join(zodvexDir, "schema.d.ts"), schemaContent.dts);
|
|
@@ -2471,6 +2481,16 @@ function regenerate(resolved, options) {
|
|
|
2471
2481
|
});
|
|
2472
2482
|
}
|
|
2473
2483
|
function writeStubApi(zodvexDir) {
|
|
2484
|
+
const stubTargets = ["api.js", "api.d.ts"].map((name) => {
|
|
2485
|
+
const filePath = path4.join(zodvexDir, name);
|
|
2486
|
+
let original;
|
|
2487
|
+
try {
|
|
2488
|
+
original = fs3.readFileSync(filePath, "utf-8");
|
|
2489
|
+
} catch {
|
|
2490
|
+
original = null;
|
|
2491
|
+
}
|
|
2492
|
+
return { filePath, original };
|
|
2493
|
+
});
|
|
2474
2494
|
fs3.mkdirSync(zodvexDir, { recursive: true });
|
|
2475
2495
|
fs3.writeFileSync(
|
|
2476
2496
|
path4.join(zodvexDir, "api.js"),
|
|
@@ -2480,6 +2500,18 @@ function writeStubApi(zodvexDir) {
|
|
|
2480
2500
|
path4.join(zodvexDir, "api.d.ts"),
|
|
2481
2501
|
"// AUTO-GENERATED by zodvex \u2014 do not edit\n// Stub created for codegen bootstrap\n\nexport declare const zodvexRegistry: Record<string, any>\n"
|
|
2482
2502
|
);
|
|
2503
|
+
return () => {
|
|
2504
|
+
for (const { filePath, original } of stubTargets) {
|
|
2505
|
+
try {
|
|
2506
|
+
if (original !== null) {
|
|
2507
|
+
fs3.writeFileSync(filePath, original);
|
|
2508
|
+
} else {
|
|
2509
|
+
fs3.unlinkSync(filePath);
|
|
2510
|
+
}
|
|
2511
|
+
} catch {
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2483
2515
|
}
|
|
2484
2516
|
function writeIfChanged(filePath, content) {
|
|
2485
2517
|
try {
|