zodvex 0.7.7 → 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/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/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/server/index.ts +4 -1
|
@@ -13,7 +13,7 @@ export { customCtx } from 'convex-helpers/server/customFunctions';
|
|
|
13
13
|
export { createZodvexActionCtx } from '../../internal/actionCtx';
|
|
14
14
|
export { zActionBuilder, zCustomActionBuilder, zCustomMutationBuilder, zCustomQueryBuilder, zMutationBuilder, zQueryBuilder } from '../../internal/builders';
|
|
15
15
|
export { type CustomBuilder, zCustomAction, zCustomMutation, zCustomQuery } from '../../internal/custom';
|
|
16
|
-
export { createZodvexCustomization } from '../../internal/customization';
|
|
16
|
+
export { createZodvexCustomization, type ZodvexUnderlyingDb } from '../../internal/customization';
|
|
17
17
|
export { createZodDbReader, createZodDbWriter, ZodvexDatabaseReader, ZodvexDatabaseWriter, type ZodvexExpression, type ZodvexExpressionOrValue, type ZodvexFilterBuilder, type ZodvexIndexFieldValue, type ZodvexIndexRangeBuilder, type ZodvexLowerBoundBuilder, ZodvexQueryChain, type ZodvexUpperBoundBuilder } from '../../internal/db';
|
|
18
18
|
export { defineContext, initZodvex, type ZodvexActionCtx, type ZodvexBuilder, type ZodvexCustomization, type ZodvexMutationCtx, type ZodvexQueryCtx } from '../../internal/init';
|
|
19
19
|
export type { DeleteRule, InsertRule, PatchRule, ReaderAuditConfig, ReadRule, ReplaceRule, TableRules, WriteEvent, WriterAuditConfig, ZodvexRules, ZodvexRulesConfig } from '../../internal/rules';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAA;AAEjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACd,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EACL,KAAK,aAAa,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAA;AAEjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACd,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EACL,KAAK,aAAa,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,yBAAyB,EACzB,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAA;AAErC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,gBAAgB,EAChB,KAAK,uBAAuB,EAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAA;AAI5B,YAAY,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EAClB,MAAM,sBAAsB,CAAA;AAE7B,cAAc,uBAAuB,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAE9D,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,4BAA4B,EACjC,kBAAkB,EAClB,YAAY,EACb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/server/index.js
CHANGED
|
@@ -1674,6 +1674,17 @@ var ZodvexDatabaseReader = class {
|
|
|
1674
1674
|
get _internals() {
|
|
1675
1675
|
return { db: this.db, tableMap: this.tableMap };
|
|
1676
1676
|
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Escape hatch (#85/#92): returns the database this codec wrapper delegates
|
|
1679
|
+
* to — the composed underlying stack when `underlyingDb` is configured (e.g.
|
|
1680
|
+
* a trigger-wrapped writer), the bare Convex db otherwise.
|
|
1681
|
+
*
|
|
1682
|
+
* The returned db is native-shape: reads are undecoded wire documents and it
|
|
1683
|
+
* bypasses codec, `.withRules()`, and `.audit()` layers entirely.
|
|
1684
|
+
*/
|
|
1685
|
+
unwrap() {
|
|
1686
|
+
return this.db;
|
|
1687
|
+
}
|
|
1677
1688
|
normalizeId(tableName, id2) {
|
|
1678
1689
|
return this.db.normalizeId(tableName, id2);
|
|
1679
1690
|
}
|
|
@@ -1733,6 +1744,17 @@ var ZodvexDatabaseWriter = class extends ZodvexDatabaseReader {
|
|
|
1733
1744
|
get _internals() {
|
|
1734
1745
|
return { db: this.writerDb, tableMap: this.tableMap, reader: this };
|
|
1735
1746
|
}
|
|
1747
|
+
/**
|
|
1748
|
+
* Escape hatch (#85/#92): returns the writer this codec wrapper delegates
|
|
1749
|
+
* to — the composed underlying stack when `underlyingDb` is configured (e.g.
|
|
1750
|
+
* a trigger-wrapped writer), the bare Convex db otherwise.
|
|
1751
|
+
*
|
|
1752
|
+
* The returned db is native-shape: writes must be wire-format and it
|
|
1753
|
+
* bypasses codec, `.withRules()`, and `.audit()` layers entirely.
|
|
1754
|
+
*/
|
|
1755
|
+
unwrap() {
|
|
1756
|
+
return this.writerDb;
|
|
1757
|
+
}
|
|
1736
1758
|
async insert(table, value) {
|
|
1737
1759
|
const schemas = this.tableMap[table];
|
|
1738
1760
|
const wireValue = schemas ? encodeDoc(schemas.insert, value) : value;
|
|
@@ -1817,19 +1839,25 @@ installRulesSubclasses({
|
|
|
1817
1839
|
});
|
|
1818
1840
|
|
|
1819
1841
|
// src/internal/customization.ts
|
|
1820
|
-
function createZodvexCustomization(tableMap) {
|
|
1842
|
+
function createZodvexCustomization(tableMap, options) {
|
|
1843
|
+
const resolveReaderDb = options?.underlyingDb?.query;
|
|
1844
|
+
const resolveWriterDb = options?.underlyingDb?.mutation;
|
|
1821
1845
|
return {
|
|
1822
1846
|
query: {
|
|
1823
1847
|
args: {},
|
|
1824
1848
|
input: async (ctx, _args, _extra) => ({
|
|
1825
|
-
ctx: {
|
|
1849
|
+
ctx: {
|
|
1850
|
+
db: new ZodvexDatabaseReader(resolveReaderDb ? resolveReaderDb(ctx) : ctx.db, tableMap)
|
|
1851
|
+
},
|
|
1826
1852
|
args: {}
|
|
1827
1853
|
})
|
|
1828
1854
|
},
|
|
1829
1855
|
mutation: {
|
|
1830
1856
|
args: {},
|
|
1831
1857
|
input: async (ctx, _args, _extra) => ({
|
|
1832
|
-
ctx: {
|
|
1858
|
+
ctx: {
|
|
1859
|
+
db: new ZodvexDatabaseWriter(resolveWriterDb ? resolveWriterDb(ctx) : ctx.db, tableMap)
|
|
1860
|
+
},
|
|
1833
1861
|
args: {}
|
|
1834
1862
|
})
|
|
1835
1863
|
}
|
|
@@ -1839,9 +1867,16 @@ function defineContext(_builder, customization) {
|
|
|
1839
1867
|
return customization;
|
|
1840
1868
|
}
|
|
1841
1869
|
function initZodvex(schema, server, options) {
|
|
1842
|
-
const codec2 = createZodvexCustomization(schema.__zodTableMap);
|
|
1843
|
-
const noOp = createNoOpCustomization();
|
|
1844
1870
|
const wrap = options?.wrapDb !== false;
|
|
1871
|
+
if (!wrap && options?.underlyingDb) {
|
|
1872
|
+
throw new Error(
|
|
1873
|
+
"[zodvex] initZodvex: `underlyingDb` requires the codec db wrapper \u2014 remove `wrapDb: false` or drop `underlyingDb`."
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
const codec2 = createZodvexCustomization(schema.__zodTableMap, {
|
|
1877
|
+
underlyingDb: options?.underlyingDb
|
|
1878
|
+
});
|
|
1879
|
+
const noOp = createNoOpCustomization();
|
|
1845
1880
|
const registryThunk = options?.registry;
|
|
1846
1881
|
const actionCust = createActionCustomization(registryThunk, noOp);
|
|
1847
1882
|
const customizations = {
|