@rocicorp/zero 0.24.2025100400 → 0.24.2025100800
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/out/{chunk-SBHBYH27.js → chunk-ASFIXQH7.js} +2 -2
- package/out/{chunk-DPY6BGZO.js → chunk-QROPZW7G.js} +2 -2
- package/out/react.js +1 -1
- package/out/solid.js +2 -2
- package/out/zero/package.json +10 -6
- package/out/zero/src/adapters/drizzle.d.ts +2 -0
- package/out/zero/src/adapters/drizzle.d.ts.map +1 -0
- package/out/zero/src/adapters/drizzle.js +2 -0
- package/out/zero/src/adapters/drizzle.js.map +1 -0
- package/out/zero/src/adapters/pg.d.ts +2 -0
- package/out/zero/src/adapters/pg.d.ts.map +1 -0
- package/out/zero/src/adapters/pg.js +2 -0
- package/out/zero/src/adapters/pg.js.map +1 -0
- package/out/zero/src/zero-cache-dev.js +10 -4
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js +1 -1
- package/out/zero-server/src/adapters/drizzle.d.ts +64 -0
- package/out/zero-server/src/adapters/drizzle.d.ts.map +1 -0
- package/out/zero-server/src/adapters/drizzle.js +109 -0
- package/out/zero-server/src/adapters/drizzle.js.map +1 -0
- package/out/zero-server/src/adapters/pg.d.ts +53 -0
- package/out/zero-server/src/adapters/pg.d.ts.map +1 -0
- package/out/zero-server/src/adapters/pg.js +79 -0
- package/out/zero-server/src/adapters/pg.js.map +1 -0
- package/out/zero-server/src/adapters/postgresjs.d.ts +41 -12
- package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
- package/out/zero-server/src/adapters/postgresjs.js +27 -10
- package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
- package/out/zero.js +2 -2
- package/package.json +10 -6
- package/out/zero/src/adapters/drizzle-pg.d.ts +0 -2
- package/out/zero/src/adapters/drizzle-pg.d.ts.map +0 -1
- package/out/zero/src/adapters/drizzle-pg.js +0 -2
- package/out/zero/src/adapters/drizzle-pg.js.map +0 -1
- package/out/zero-server/src/adapters/drizzle-pg.d.ts +0 -22
- package/out/zero-server/src/adapters/drizzle-pg.d.ts.map +0 -1
- package/out/zero-server/src/adapters/drizzle-pg.js +0 -39
- package/out/zero-server/src/adapters/drizzle-pg.js.map +0 -1
- /package/out/{chunk-SBHBYH27.js.map → chunk-ASFIXQH7.js.map} +0 -0
- /package/out/{chunk-DPY6BGZO.js.map → chunk-QROPZW7G.js.map} +0 -0
|
@@ -8692,7 +8692,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
8692
8692
|
}
|
|
8693
8693
|
|
|
8694
8694
|
// ../zero-client/src/client/version.ts
|
|
8695
|
-
var version2 = "0.24.
|
|
8695
|
+
var version2 = "0.24.2025100800";
|
|
8696
8696
|
|
|
8697
8697
|
// ../zero-client/src/client/log-options.ts
|
|
8698
8698
|
var LevelFilterLogSink = class {
|
|
@@ -11665,4 +11665,4 @@ export {
|
|
|
11665
11665
|
update_needed_reason_type_enum_exports,
|
|
11666
11666
|
Zero
|
|
11667
11667
|
};
|
|
11668
|
-
//# sourceMappingURL=chunk-
|
|
11668
|
+
//# sourceMappingURL=chunk-ASFIXQH7.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clientToServer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ASFIXQH7.js";
|
|
4
4
|
import {
|
|
5
5
|
AbstractQuery,
|
|
6
6
|
ExpressionBuilder,
|
|
@@ -346,4 +346,4 @@ export {
|
|
|
346
346
|
withValidation,
|
|
347
347
|
createBuilder
|
|
348
348
|
};
|
|
349
|
-
//# sourceMappingURL=chunk-
|
|
349
|
+
//# sourceMappingURL=chunk-QROPZW7G.js.map
|
package/out/react.js
CHANGED
package/out/solid.js
CHANGED
package/out/zero/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocicorp/zero",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.2025100800",
|
|
4
4
|
"description": "Zero is a web framework for serverless web development.",
|
|
5
5
|
"author": "Rocicorp, Inc.",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@rocicorp/lock": "^1.0.4",
|
|
48
48
|
"@rocicorp/logger": "^5.4.0",
|
|
49
49
|
"@rocicorp/resolver": "^1.0.2",
|
|
50
|
-
"@rocicorp/zero-sqlite3": "^1.0.
|
|
50
|
+
"@rocicorp/zero-sqlite3": "^1.0.9",
|
|
51
51
|
"@types/basic-auth": "^1.1.8",
|
|
52
52
|
"basic-auth": "^2.0.1",
|
|
53
53
|
"chalk": "^5.3.0",
|
|
@@ -113,12 +113,16 @@
|
|
|
113
113
|
"default": "./out/zero/src/server.js"
|
|
114
114
|
},
|
|
115
115
|
"./server/adapters/postgresjs": {
|
|
116
|
-
"types": "./out/zero-server/src/adapters/
|
|
116
|
+
"types": "./out/zero-server/src/adapters/postgresjs.d.ts",
|
|
117
117
|
"default": "./out/zero/src/adapters/postgresjs.js"
|
|
118
118
|
},
|
|
119
|
-
"./server/adapters/
|
|
120
|
-
"types": "./out/zero-server/src/adapters/
|
|
121
|
-
"default": "./out/zero/src/adapters/
|
|
119
|
+
"./server/adapters/pg": {
|
|
120
|
+
"types": "./out/zero-server/src/adapters/pg.d.ts",
|
|
121
|
+
"default": "./out/zero/src/adapters/pg.js"
|
|
122
|
+
},
|
|
123
|
+
"./server/adapters/drizzle": {
|
|
124
|
+
"types": "./out/zero-server/src/adapters/drizzle.d.ts",
|
|
125
|
+
"default": "./out/zero/src/adapters/drizzle.js"
|
|
122
126
|
},
|
|
123
127
|
"./solid": {
|
|
124
128
|
"types": "./out/zero-solid/src/mod.d.ts",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,iBAAiB,GACvB,MAAM,8CAA8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.js","sourceRoot":"","sources":["../../../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAIZ,MAAM,8CAA8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../../../src/adapters/pg.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.js","sourceRoot":"","sources":["../../../../src/adapters/pg.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC"}
|
|
@@ -36,8 +36,12 @@ async function main() {
|
|
|
36
36
|
lc.error?.('Exiting');
|
|
37
37
|
process.exit(-1);
|
|
38
38
|
});
|
|
39
|
-
|
|
40
|
-
const {
|
|
39
|
+
// Parse options for each subprocess to get environment variables
|
|
40
|
+
const { env: deployPermissionsEnv } = parseOptionsAdvanced(deployPermissionsOptions, {
|
|
41
|
+
envNamePrefix: ZERO_ENV_VAR_PREFIX,
|
|
42
|
+
allowUnknown: true,
|
|
43
|
+
});
|
|
44
|
+
const { env: zeroCacheEnv } = parseOptionsAdvanced(zeroOptions, {
|
|
41
45
|
envNamePrefix: ZERO_ENV_VAR_PREFIX,
|
|
42
46
|
allowUnknown: true,
|
|
43
47
|
});
|
|
@@ -58,7 +62,8 @@ async function main() {
|
|
|
58
62
|
await killProcess(permissionsProcess);
|
|
59
63
|
permissionsProcess = undefined;
|
|
60
64
|
lc.info?.(`Running ${deployPermissionsScript}.`);
|
|
61
|
-
permissionsProcess = spawn(deployPermissionsScript,
|
|
65
|
+
permissionsProcess = spawn(deployPermissionsScript, [], {
|
|
66
|
+
env: { ...process.env, ...deployPermissionsEnv },
|
|
62
67
|
stdio: 'inherit',
|
|
63
68
|
shell: true,
|
|
64
69
|
});
|
|
@@ -89,8 +94,9 @@ async function main() {
|
|
|
89
94
|
['NODE_ENV']: 'development',
|
|
90
95
|
// But let the developer override any of these dev defaults.
|
|
91
96
|
...process.env,
|
|
97
|
+
...zeroCacheEnv,
|
|
92
98
|
};
|
|
93
|
-
zeroCacheProcess = spawn(zeroCacheScript,
|
|
99
|
+
zeroCacheProcess = spawn(zeroCacheScript, [], {
|
|
94
100
|
env,
|
|
95
101
|
stdio: 'inherit',
|
|
96
102
|
shell: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zero-cache-dev.js","sourceRoot":"","sources":["../../../src/zero-cache-dev.ts"],"names":[],"mappings":";AACA,+BAA+B;AAE/B,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAC,KAAK,EAAoB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAC,oBAAoB,EAAC,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACL,mBAAmB,EACnB,WAAW,GACZ,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAC,wBAAwB,EAAC,MAAM,6CAA6C,CAAC;AAErF,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAC1D,MAAM,eAAe,GAAG,YAAY,CAAC;AAErC,SAAS,WAAW,CAAC,YAAsC;IACzD,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QACpD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,MAAM,EAAC,OAAO,EAAE,OAAO,EAAC,GAAG,QAAQ,EAAE,CAAC;IACtC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;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CAAC,IAAI,EAAE;QAC1B,aAAa,EAAE,IAAI;QACnB,gBAAgB,EAAE,EAAC,kBAAkB,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAC;KAC/D,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;QAC9B,EAAE,CAAC,IAAI,EAAE,CAAC,YAAY,IAAI,UAAU,CAAC,CAAC;QACtC,MAAM,iBAAiB,EAAE,CAAC;IAC5B,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACrC,CAAC;AAED,KAAK,IAAI,EAAE,CAAC"}
|
|
@@ -25,7 +25,7 @@ async function validatePermissions(db, permissions) {
|
|
|
25
25
|
const schema = upstreamSchema(shard);
|
|
26
26
|
// Check if the shardConfig table has been initialized.
|
|
27
27
|
const result = await db `
|
|
28
|
-
SELECT relname FROM pg_class
|
|
28
|
+
SELECT relname FROM pg_class
|
|
29
29
|
JOIN pg_namespace ON relnamespace = pg_namespace.oid
|
|
30
30
|
WHERE nspname = ${schema} AND relname = ${SHARD_CONFIG_TABLE}`;
|
|
31
31
|
if (result.length === 0) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type SQL } from 'drizzle-orm';
|
|
2
|
+
import type { PgDatabase, PgQueryResultHKT, PgTransaction } from 'drizzle-orm/pg-core';
|
|
3
|
+
import type { ExtractTablesWithRelations } from 'drizzle-orm/relations';
|
|
4
|
+
import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
|
|
5
|
+
import type { DBConnection, DBTransaction, Row } from '../../../zql/src/mutate/custom.ts';
|
|
6
|
+
import { ZQLDatabase } from '../zql-database.ts';
|
|
7
|
+
export type DrizzleDatabase<TQueryResult extends PgQueryResultHKT = PgQueryResultHKT, TClient = unknown> = PgDatabase<TQueryResult, Record<string, unknown>> & {
|
|
8
|
+
$client: TClient;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Helper type for the wrapped transaction used by drizzle-orm.
|
|
12
|
+
*
|
|
13
|
+
* @remarks Use with `ServerTransaction` as `ServerTransaction<Schema, DrizzleTransaction<typeof drizzleDb>>`.
|
|
14
|
+
*/
|
|
15
|
+
export type DrizzleTransaction<TDbOrSchema extends DrizzleDatabase<TQueryResult, TClient> | Record<string, unknown>, TQueryResult extends PgQueryResultHKT = PgQueryResultHKT, TClient = unknown, TSchema extends Record<string, unknown> = TDbOrSchema extends PgDatabase<TQueryResult, infer TSchema> ? TSchema : TDbOrSchema> = PgTransaction<TQueryResult, TSchema, ExtractTablesWithRelations<TSchema>>;
|
|
16
|
+
export declare class DrizzleConnection<TDrizzle extends DrizzleDatabase<TQueryResult, TClient> & {
|
|
17
|
+
$client: TClient;
|
|
18
|
+
}, TQueryResult extends PgQueryResultHKT = PgQueryResultHKT, TClient = unknown, TTransaction extends DrizzleTransaction<TDrizzle, TQueryResult, TClient> = DrizzleTransaction<TDrizzle, TQueryResult, TClient>> implements DBConnection<TTransaction> {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(drizzle: TDrizzle);
|
|
21
|
+
transaction<T>(fn: (tx: DBTransaction<TTransaction>) => Promise<T>): Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Turn `$1, $2...` placeholders into a Drizzle SQL object with bound params.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fromDollarParams(text: string, params: unknown[]): SQL;
|
|
27
|
+
export declare function toIterableRows(result: unknown): Iterable<Row>;
|
|
28
|
+
/**
|
|
29
|
+
* Wrap a `drizzle-orm` database for Zero ZQL.
|
|
30
|
+
*
|
|
31
|
+
* Provides ZQL querying plus access to the underlying drizzle transaction.
|
|
32
|
+
* Use {@link DrizzleTransaction} to type your server mutator transaction.
|
|
33
|
+
*
|
|
34
|
+
* @param schema - Zero schema.
|
|
35
|
+
* @param client - Drizzle database.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import {Pool} from 'pg';
|
|
40
|
+
* import {drizzle} from 'drizzle-orm/node-postgres';
|
|
41
|
+
* import type {ServerTransaction} from '@rocicorp/zero';
|
|
42
|
+
*
|
|
43
|
+
* const pool = new Pool({connectionString: process.env.ZERO_UPSTREAM_DB!});
|
|
44
|
+
* const drizzleDb = drizzle(pool, {schema: drizzleSchema});
|
|
45
|
+
*
|
|
46
|
+
* const zql = zeroDrizzle(schema, drizzleDb);
|
|
47
|
+
*
|
|
48
|
+
* // Define the server mutator transaction type using the helper
|
|
49
|
+
* type ServerTx = ServerTransaction<Schema, DrizzleTransaction<typeof drizzleDb>>;
|
|
50
|
+
*
|
|
51
|
+
* async function createUser(
|
|
52
|
+
* tx: ServerTx,
|
|
53
|
+
* {id, name}: {id: string; name: string},
|
|
54
|
+
* ) {
|
|
55
|
+
* await tx.dbTransaction.wrappedTransaction
|
|
56
|
+
* .insert(drizzleSchema.user)
|
|
57
|
+
* .values({id, name})
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function zeroDrizzle<S extends Schema, TDrizzle extends PgDatabase<PgQueryResultHKT, Record<string, unknown>> & {
|
|
62
|
+
$client: TClient;
|
|
63
|
+
}, TClient = unknown>(schema: S, client: TDrizzle): ZQLDatabase<S, DrizzleTransaction<TDrizzle, PgQueryResultHKT, unknown, TDrizzle extends PgDatabase<PgQueryResultHKT, infer TSchema extends Record<string, unknown>, ExtractTablesWithRelations<infer TSchema extends Record<string, unknown>>> ? TSchema : TDrizzle>>;
|
|
64
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,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,EACZ,OAAO,CACR,GAAG,kBAAkB,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CACvD,YAAW,YAAY,CAAC,YAAY,CAAC;;gBAIzB,OAAO,EAAE,QAAQ;IAI7B,WAAW,CAAC,CAAC,EACX,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,YAAY,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,CAAC,CAAC;CASd;AA4BD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAiBrE;AASD,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAuB7D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CACzB,CAAC,SAAS,MAAM,EAChB,QAAQ,SAAS,UAAU,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG;IACvE,OAAO,EAAE,OAAO,CAAC;CAClB,EACD,OAAO,GAAG,OAAO,EACjB,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,8HA7JnB,OAAO,mEAAP,OAAO,0DA+JhB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { ZQLDatabase } from "../zql-database.js";
|
|
3
|
+
export class DrizzleConnection {
|
|
4
|
+
#drizzle;
|
|
5
|
+
constructor(drizzle) {
|
|
6
|
+
this.#drizzle = drizzle;
|
|
7
|
+
}
|
|
8
|
+
transaction(fn) {
|
|
9
|
+
return this.#drizzle.transaction(drizzleTx => fn(new DrizzleInternalTransaction(drizzleTx)));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class DrizzleInternalTransaction {
|
|
13
|
+
wrappedTransaction;
|
|
14
|
+
constructor(drizzleTx) {
|
|
15
|
+
this.wrappedTransaction = drizzleTx;
|
|
16
|
+
}
|
|
17
|
+
async query(sql, params) {
|
|
18
|
+
const stmt = fromDollarParams(sql, params);
|
|
19
|
+
const result = await this.wrappedTransaction.execute(stmt);
|
|
20
|
+
return toIterableRows(result);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Turn `$1, $2...` placeholders into a Drizzle SQL object with bound params.
|
|
25
|
+
*/
|
|
26
|
+
export function fromDollarParams(text, params) {
|
|
27
|
+
const re = /\$(\d+)/g;
|
|
28
|
+
const s = sql.empty();
|
|
29
|
+
let last = 0;
|
|
30
|
+
let m;
|
|
31
|
+
while ((m = re.exec(text)) !== null) {
|
|
32
|
+
const idx = Number(m[1]) - 1;
|
|
33
|
+
if (idx < 0 || idx >= params.length) {
|
|
34
|
+
throw new Error(`Missing param for $${m[1]}`);
|
|
35
|
+
}
|
|
36
|
+
if (m.index > last)
|
|
37
|
+
s.append(sql.raw(text.slice(last, m.index)));
|
|
38
|
+
s.append(sql `${params[idx]}`); // parameterized value
|
|
39
|
+
last = m.index + m[0].length;
|
|
40
|
+
}
|
|
41
|
+
if (last < text.length)
|
|
42
|
+
s.append(sql.raw(text.slice(last)));
|
|
43
|
+
return s;
|
|
44
|
+
}
|
|
45
|
+
function isIterable(value) {
|
|
46
|
+
return (value != null &&
|
|
47
|
+
typeof value[Symbol.iterator] === 'function');
|
|
48
|
+
}
|
|
49
|
+
export function toIterableRows(result) {
|
|
50
|
+
if (result === null || result === undefined) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(result)) {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
if (isIterable(result)) {
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
if (typeof result === 'object') {
|
|
60
|
+
const rows = result.rows;
|
|
61
|
+
if (rows === null || rows === undefined) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(rows)) {
|
|
65
|
+
return rows;
|
|
66
|
+
}
|
|
67
|
+
if (isIterable(rows)) {
|
|
68
|
+
return rows;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw new TypeError('Drizzle query result is not iterable');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Wrap a `drizzle-orm` database for Zero ZQL.
|
|
75
|
+
*
|
|
76
|
+
* Provides ZQL querying plus access to the underlying drizzle transaction.
|
|
77
|
+
* Use {@link DrizzleTransaction} to type your server mutator transaction.
|
|
78
|
+
*
|
|
79
|
+
* @param schema - Zero schema.
|
|
80
|
+
* @param client - Drizzle database.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import {Pool} from 'pg';
|
|
85
|
+
* import {drizzle} from 'drizzle-orm/node-postgres';
|
|
86
|
+
* import type {ServerTransaction} from '@rocicorp/zero';
|
|
87
|
+
*
|
|
88
|
+
* const pool = new Pool({connectionString: process.env.ZERO_UPSTREAM_DB!});
|
|
89
|
+
* const drizzleDb = drizzle(pool, {schema: drizzleSchema});
|
|
90
|
+
*
|
|
91
|
+
* const zql = zeroDrizzle(schema, drizzleDb);
|
|
92
|
+
*
|
|
93
|
+
* // Define the server mutator transaction type using the helper
|
|
94
|
+
* type ServerTx = ServerTransaction<Schema, DrizzleTransaction<typeof drizzleDb>>;
|
|
95
|
+
*
|
|
96
|
+
* async function createUser(
|
|
97
|
+
* tx: ServerTx,
|
|
98
|
+
* {id, name}: {id: string; name: string},
|
|
99
|
+
* ) {
|
|
100
|
+
* await tx.dbTransaction.wrappedTransaction
|
|
101
|
+
* .insert(drizzleSchema.user)
|
|
102
|
+
* .values({id, name})
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function zeroDrizzle(schema, client) {
|
|
107
|
+
return new ZQLDatabase(new DrizzleConnection(client), schema);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=drizzle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AAC;QACvB,OAAO,MAAuB,CAAC;IACjC,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAI,MAA2B,CAAC,IAAI,CAAC;QAC/C,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxC,OAAO,EAAW,CAAC;QACrB,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,IAAa,CAAC;QACvB,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,IAAqB,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,WAAW,CAMzB,MAAS,EAAE,MAAgB;IAC3B,OAAO,IAAI,WAAW,CAAC,IAAI,iBAAiB,CAAW,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
|
|
2
|
+
import type { DBConnection, DBTransaction, Row } from '../../../zql/src/mutate/custom.ts';
|
|
3
|
+
import { Client, Pool, type PoolClient } from 'pg';
|
|
4
|
+
import { ZQLDatabase } from '../zql-database.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Helper type for the wrapped transaction used by node-postgres.
|
|
7
|
+
*
|
|
8
|
+
* @remarks Use with `ServerTransaction` as `ServerTransaction<Schema, NodePgTransaction>`.
|
|
9
|
+
*/
|
|
10
|
+
export type NodePgTransaction = Pool | PoolClient | Client;
|
|
11
|
+
export declare class NodePgConnection implements DBConnection<NodePgTransaction> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(pool: NodePgTransaction);
|
|
14
|
+
transaction<TRet>(fn: (tx: DBTransaction<NodePgTransaction>) => Promise<TRet>): Promise<TRet>;
|
|
15
|
+
}
|
|
16
|
+
export declare class NodePgTransactionInternal implements DBTransaction<NodePgTransaction> {
|
|
17
|
+
readonly wrappedTransaction: NodePgTransaction;
|
|
18
|
+
constructor(client: NodePgTransaction);
|
|
19
|
+
query(sql: string, params: unknown[]): Promise<Row[]>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Wrap a `pg` Pool for Zero ZQL.
|
|
23
|
+
*
|
|
24
|
+
* Provides ZQL querying plus access to the underlying node-postgres client.
|
|
25
|
+
* Use {@link NodePgTransaction} to type your server mutator transaction.
|
|
26
|
+
*
|
|
27
|
+
* @param schema - Zero schema.
|
|
28
|
+
* @param pg - `pg` Pool or connection string.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import {Pool} from 'pg';
|
|
33
|
+
*
|
|
34
|
+
* const pool = new Pool({connectionString: process.env.ZERO_UPSTREAM_DB!});
|
|
35
|
+
* const zql = zeroNodePg(schema, pool);
|
|
36
|
+
*
|
|
37
|
+
* // Define the server mutator transaction type using the helper
|
|
38
|
+
* type ServerTx = ServerTransaction<
|
|
39
|
+
* Schema,
|
|
40
|
+
* NodePgTransaction
|
|
41
|
+
* >;
|
|
42
|
+
*
|
|
43
|
+
* async function createUser(
|
|
44
|
+
* tx: ServerTx,
|
|
45
|
+
* {id, name}: {id: string; name: string},
|
|
46
|
+
* ) {
|
|
47
|
+
* await tx.dbTransaction.wrappedTransaction
|
|
48
|
+
* .query('SELECT * FROM "user" WHERE id = $1', [id]);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function zeroNodePg<S extends Schema>(schema: S, pg: NodePgTransaction | string): ZQLDatabase<S, NodePgTransaction>;
|
|
53
|
+
//# sourceMappingURL=pg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/pg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oDAAoD,CAAC;AAC/E,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,GAAG,EACJ,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,KAAK,UAAU,EAAC,MAAM,IAAI,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,UAAU,GAAG,MAAM,CAAC;AAE3D,qBAAa,gBAAiB,YAAW,YAAY,CAAC,iBAAiB,CAAC;;gBAE1D,IAAI,EAAE,iBAAiB;IAI7B,WAAW,CAAC,IAAI,EACpB,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAC1D,OAAO,CAAC,IAAI,CAAC;CAqBjB;AAED,qBAAa,yBACX,YAAW,aAAa,CAAC,iBAAiB,CAAC;IAE3C,QAAQ,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;gBACnC,MAAM,EAAE,iBAAiB;IAI/B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CAI5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,MAAM,EAAE,CAAC,EACT,EAAE,EAAE,iBAAiB,GAAG,MAAM,qCAM/B"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Client, Pool } from 'pg';
|
|
2
|
+
import { ZQLDatabase } from "../zql-database.js";
|
|
3
|
+
export class NodePgConnection {
|
|
4
|
+
#pool;
|
|
5
|
+
constructor(pool) {
|
|
6
|
+
this.#pool = pool;
|
|
7
|
+
}
|
|
8
|
+
async transaction(fn) {
|
|
9
|
+
const client = this.#pool instanceof Pool ? await this.#pool.connect() : this.#pool;
|
|
10
|
+
try {
|
|
11
|
+
await client.query('BEGIN');
|
|
12
|
+
const result = await fn(new NodePgTransactionInternal(client));
|
|
13
|
+
await client.query('COMMIT');
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
try {
|
|
18
|
+
await client.query('ROLLBACK');
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// ignore rollback error; original error will be thrown
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
if (this.#pool instanceof Pool && 'release' in client) {
|
|
27
|
+
client.release();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class NodePgTransactionInternal {
|
|
33
|
+
wrappedTransaction;
|
|
34
|
+
constructor(client) {
|
|
35
|
+
this.wrappedTransaction = client;
|
|
36
|
+
}
|
|
37
|
+
async query(sql, params) {
|
|
38
|
+
const res = await this.wrappedTransaction.query(sql, params);
|
|
39
|
+
return res.rows;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Wrap a `pg` Pool for Zero ZQL.
|
|
44
|
+
*
|
|
45
|
+
* Provides ZQL querying plus access to the underlying node-postgres client.
|
|
46
|
+
* Use {@link NodePgTransaction} to type your server mutator transaction.
|
|
47
|
+
*
|
|
48
|
+
* @param schema - Zero schema.
|
|
49
|
+
* @param pg - `pg` Pool or connection string.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import {Pool} from 'pg';
|
|
54
|
+
*
|
|
55
|
+
* const pool = new Pool({connectionString: process.env.ZERO_UPSTREAM_DB!});
|
|
56
|
+
* const zql = zeroNodePg(schema, pool);
|
|
57
|
+
*
|
|
58
|
+
* // Define the server mutator transaction type using the helper
|
|
59
|
+
* type ServerTx = ServerTransaction<
|
|
60
|
+
* Schema,
|
|
61
|
+
* NodePgTransaction
|
|
62
|
+
* >;
|
|
63
|
+
*
|
|
64
|
+
* async function createUser(
|
|
65
|
+
* tx: ServerTx,
|
|
66
|
+
* {id, name}: {id: string; name: string},
|
|
67
|
+
* ) {
|
|
68
|
+
* await tx.dbTransaction.wrappedTransaction
|
|
69
|
+
* .query('SELECT * FROM "user" WHERE id = $1', [id]);
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function zeroNodePg(schema, pg) {
|
|
74
|
+
if (typeof pg === 'string') {
|
|
75
|
+
pg = new Pool({ connectionString: pg });
|
|
76
|
+
}
|
|
77
|
+
return new ZQLDatabase(new NodePgConnection(pg), schema);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=pg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.js","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/pg.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,MAAM,EAAE,IAAI,EAAkB,MAAM,IAAI,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAS/C,MAAM,OAAO,gBAAgB;IAClB,KAAK,CAAoB;IAClC,YAAY,IAAuB;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,WAAW,CACf,EAA2D;QAE3D,MAAM,MAAM,GACV,IAAI,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QACvE,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC5B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,yBAAyB,CAAC,MAAM,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BConnection, DBTransaction } from '../../../zql/src/mutate/custom.ts';
|
|
2
|
+
import type { DBConnection, DBTransaction, Row } from '../../../zql/src/mutate/custom.ts';
|
|
3
3
|
import postgres from 'postgres';
|
|
4
4
|
import { ZQLDatabase } from '../zql-database.ts';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Helper type for the wrapped transaction used by postgres.js.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The row-shape context bound to the postgres.js client.
|
|
9
|
+
* @remarks Use with `ServerTransaction` as `ServerTransaction<Schema, PostgresJsTransaction>`.
|
|
10
|
+
*/
|
|
11
|
+
export type PostgresJsTransaction<T extends Record<string, unknown> = Record<string, unknown>> = postgres.TransactionSql<T>;
|
|
12
|
+
export declare class PostgresJSConnection<T extends Record<string, unknown>> implements DBConnection<PostgresJsTransaction<T>> {
|
|
6
13
|
#private;
|
|
7
14
|
constructor(pg: postgres.Sql<T>);
|
|
8
|
-
transaction<TRet>(fn: (tx: DBTransaction<
|
|
15
|
+
transaction<TRet>(fn: (tx: DBTransaction<PostgresJsTransaction<T>>) => Promise<TRet>): Promise<TRet>;
|
|
16
|
+
}
|
|
17
|
+
export declare class PostgresJsTransactionInternal<T extends Record<string, unknown>> implements DBTransaction<PostgresJsTransaction<T>> {
|
|
18
|
+
readonly wrappedTransaction: PostgresJsTransaction<T>;
|
|
19
|
+
constructor(pgTx: PostgresJsTransaction<T>);
|
|
20
|
+
query(sql: string, params: unknown[]): Promise<Row[]>;
|
|
9
21
|
}
|
|
10
22
|
/**
|
|
11
|
-
*
|
|
23
|
+
* Wrap a `postgres` client for Zero ZQL.
|
|
24
|
+
*
|
|
25
|
+
* Provides ZQL querying plus access to the underlying postgres.js transaction.
|
|
26
|
+
* Use {@link PostgresJsTransaction} to type your server mutator transaction.
|
|
27
|
+
*
|
|
28
|
+
* @param schema - Zero schema.
|
|
29
|
+
* @param pg - `postgres` client or connection string.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
12
32
|
* ```ts
|
|
13
33
|
* import postgres from 'postgres';
|
|
14
|
-
* const processor = new PushProcessor(
|
|
15
|
-
* zeroPostgresJS(schema, postgres(process.env.ZERO_UPSTREAM_DB as string)),
|
|
16
|
-
* );
|
|
17
34
|
*
|
|
18
|
-
*
|
|
19
|
-
* const
|
|
20
|
-
*
|
|
21
|
-
* //
|
|
35
|
+
* const sql = postgres(process.env.ZERO_UPSTREAM_DB!);
|
|
36
|
+
* const zql = zeroPostgresJS(schema, sql);
|
|
37
|
+
*
|
|
38
|
+
* // Define the server mutator transaction type using the helper
|
|
39
|
+
* type ServerTx = ServerTransaction<
|
|
40
|
+
* Schema,
|
|
41
|
+
* PostgresJsTransaction
|
|
42
|
+
* >;
|
|
43
|
+
*
|
|
44
|
+
* async function createUser(
|
|
45
|
+
* tx: ServerTx,
|
|
46
|
+
* {id, name}: {id: string; name: string},
|
|
47
|
+
* ) {
|
|
48
|
+
* await tx.dbTransaction.wrappedTransaction
|
|
49
|
+
* .unsafe('INSERT INTO "user" (id, name) VALUES ($1, $2)', [id, name]);
|
|
50
|
+
* }
|
|
22
51
|
* ```
|
|
23
52
|
*/
|
|
24
|
-
export declare function zeroPostgresJS<S extends Schema, T extends Record<string, unknown> = Record<string, unknown>>(schema: S, pg: postgres.Sql<T> | string): ZQLDatabase<S,
|
|
53
|
+
export declare function zeroPostgresJS<S extends Schema, T extends Record<string, unknown> = Record<string, unknown>>(schema: S, pg: postgres.Sql<T> | string): ZQLDatabase<S, PostgresJsTransaction<T>>;
|
|
25
54
|
//# sourceMappingURL=postgresjs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgresjs.d.ts","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/postgresjs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oDAAoD,CAAC;AAC/E,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,
|
|
1
|
+
{"version":3,"file":"postgresjs.d.ts","sourceR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8BG;AACH,wBAAgB,cAAc,CAC5B,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,4CAKxC"}
|
|
@@ -6,10 +6,10 @@ export class PostgresJSConnection {
|
|
|
6
6
|
this.#pg = pg;
|
|
7
7
|
}
|
|
8
8
|
transaction(fn) {
|
|
9
|
-
return this.#pg.begin(pgTx => fn(new
|
|
9
|
+
return this.#pg.begin(pgTx => fn(new PostgresJsTransactionInternal(pgTx)));
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
class
|
|
12
|
+
export class PostgresJsTransactionInternal {
|
|
13
13
|
wrappedTransaction;
|
|
14
14
|
constructor(pgTx) {
|
|
15
15
|
this.wrappedTransaction = pgTx;
|
|
@@ -19,17 +19,34 @@ class Transaction {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Wrap a `postgres` client for Zero ZQL.
|
|
23
|
+
*
|
|
24
|
+
* Provides ZQL querying plus access to the underlying postgres.js transaction.
|
|
25
|
+
* Use {@link PostgresJsTransaction} to type your server mutator transaction.
|
|
26
|
+
*
|
|
27
|
+
* @param schema - Zero schema.
|
|
28
|
+
* @param pg - `postgres` client or connection string.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
23
31
|
* ```ts
|
|
24
32
|
* import postgres from 'postgres';
|
|
25
|
-
* const processor = new PushProcessor(
|
|
26
|
-
* zeroPostgresJS(schema, postgres(process.env.ZERO_UPSTREAM_DB as string)),
|
|
27
|
-
* );
|
|
28
33
|
*
|
|
29
|
-
*
|
|
30
|
-
* const
|
|
31
|
-
*
|
|
32
|
-
* //
|
|
34
|
+
* const sql = postgres(process.env.ZERO_UPSTREAM_DB!);
|
|
35
|
+
* const zql = zeroPostgresJS(schema, sql);
|
|
36
|
+
*
|
|
37
|
+
* // Define the server mutator transaction type using the helper
|
|
38
|
+
* type ServerTx = ServerTransaction<
|
|
39
|
+
* Schema,
|
|
40
|
+
* PostgresJsTransaction
|
|
41
|
+
* >;
|
|
42
|
+
*
|
|
43
|
+
* async function createUser(
|
|
44
|
+
* tx: ServerTx,
|
|
45
|
+
* {id, name}: {id: string; name: string},
|
|
46
|
+
* ) {
|
|
47
|
+
* await tx.dbTransaction.wrappedTransaction
|
|
48
|
+
* .unsafe('INSERT INTO "user" (id, name) VALUES ($1, $2)', [id, name]);
|
|
49
|
+
* }
|
|
33
50
|
* ```
|
|
34
51
|
*/
|
|
35
52
|
export function zeroPostgresJS(schema, pg) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgresjs.js","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/postgresjs.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"postgresjs.js","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/postgresjs.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAY/C,MAAM,OAAO,oBAAoB;IAGtB,GAAG,CAAkB;IAC9B,YAAY,EAAmB;QAC7B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,WAAW,CACT,EAAkE;QAElE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAC3B,EAAE,CAAC,IAAI,6BAA6B,CAAC,IAAI,CAAC,CAAC,CAC3B,CAAC;IACrB,CAAC;CACF;AAED,MAAM,OAAO,6BAA6B;IAG/B,kBAAkB,CAA2B;IACtD,YAAY,IAA8B;QACxC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,MAAiB;QAClC,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,EAAE,MAAqB,CAAC,CAAC;IACpE,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,cAAc,CAG5B,MAAS,EAAE,EAA4B;IACvC,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC3B,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAoB,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,WAAW,CAAC,IAAI,oBAAoB,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC"}
|
package/out/zero.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
syncedQuery,
|
|
10
10
|
syncedQueryWithContext,
|
|
11
11
|
withValidation
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QROPZW7G.js";
|
|
13
13
|
import {
|
|
14
14
|
IDBNotFoundError,
|
|
15
15
|
TransactionClosedError,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
transformRequestMessageSchema,
|
|
30
30
|
transformResponseMessageSchema,
|
|
31
31
|
update_needed_reason_type_enum_exports
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-ASFIXQH7.js";
|
|
33
33
|
import "./chunk-ASRS2LFV.js";
|
|
34
34
|
import {
|
|
35
35
|
applyChange
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocicorp/zero",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.2025100800",
|
|
4
4
|
"description": "Zero is a web framework for serverless web development.",
|
|
5
5
|
"author": "Rocicorp, Inc.",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@rocicorp/lock": "^1.0.4",
|
|
48
48
|
"@rocicorp/logger": "^5.4.0",
|
|
49
49
|
"@rocicorp/resolver": "^1.0.2",
|
|
50
|
-
"@rocicorp/zero-sqlite3": "^1.0.
|
|
50
|
+
"@rocicorp/zero-sqlite3": "^1.0.9",
|
|
51
51
|
"@types/basic-auth": "^1.1.8",
|
|
52
52
|
"basic-auth": "^2.0.1",
|
|
53
53
|
"chalk": "^5.3.0",
|
|
@@ -113,12 +113,16 @@
|
|
|
113
113
|
"default": "./out/zero/src/server.js"
|
|
114
114
|
},
|
|
115
115
|
"./server/adapters/postgresjs": {
|
|
116
|
-
"types": "./out/zero-server/src/adapters/
|
|
116
|
+
"types": "./out/zero-server/src/adapters/postgresjs.d.ts",
|
|
117
117
|
"default": "./out/zero/src/adapters/postgresjs.js"
|
|
118
118
|
},
|
|
119
|
-
"./server/adapters/
|
|
120
|
-
"types": "./out/zero-server/src/adapters/
|
|
121
|
-
"default": "./out/zero/src/adapters/
|
|
119
|
+
"./server/adapters/pg": {
|
|
120
|
+
"types": "./out/zero-server/src/adapters/pg.d.ts",
|
|
121
|
+
"default": "./out/zero/src/adapters/pg.js"
|
|
122
|
+
},
|
|
123
|
+
"./server/adapters/drizzle": {
|
|
124
|
+
"types": "./out/zero-server/src/adapters/drizzle.d.ts",
|
|
125
|
+
"default": "./out/zero/src/adapters/drizzle.js"
|
|
122
126
|
},
|
|
123
127
|
"./solid": {
|
|
124
128
|
"types": "./out/zero-solid/src/mod.d.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-pg.d.ts","sourceRoot":"","sources":["../../../../src/adapters/drizzle-pg.ts"],"names":[],"mappings":"AAAA,cAAc,iDAAiD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-pg.js","sourceRoot":"","sources":["../../../../src/adapters/drizzle-pg.ts"],"names":[],"mappings":"AAAA,cAAc,iDAAiD,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { NodePgClient, NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
-
import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
|
|
3
|
-
import { ZQLDatabase } from '../zql-database.ts';
|
|
4
|
-
type DrizzleConnection<T extends Record<string, unknown>> = NodePgDatabase<T> & {
|
|
5
|
-
$client: NodePgClient;
|
|
6
|
-
};
|
|
7
|
-
export type DrizzleTransaction<T extends Record<string, unknown>> = Parameters<Parameters<DrizzleConnection<T>['transaction']>[0]>[0];
|
|
8
|
-
/**
|
|
9
|
-
* Example usage:
|
|
10
|
-
* ```ts
|
|
11
|
-
* import {drizzle} from 'drizzle-orm/node-postgres';
|
|
12
|
-
* const db = drizzle(process.env.PG_URL!);
|
|
13
|
-
* const dbProvider = zeroNodePg(db);
|
|
14
|
-
*
|
|
15
|
-
* // within your custom mutators you can do:
|
|
16
|
-
* const tx = tx.wrappedTransaction();
|
|
17
|
-
* // to get ahold of the underlying drizzle client
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function zeroNodePg<S extends Schema, TDrizzleSchema extends Record<string, unknown> = Record<string, unknown>>(schema: S, client: DrizzleConnection<TDrizzleSchema>): ZQLDatabase<S, import("drizzle-orm/pg-core").PgTransaction<import("drizzle-orm/node-postgres").NodePgQueryResultHKT, TDrizzleSchema, import("drizzle-orm").ExtractTablesWithRelations<TDrizzleSchema>>>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=drizzle-pg.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-pg.d.ts","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/drizzle-pg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAM5E,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oDAAoD,CAAC;AAC/E,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACtD,cAAc,CAAC,CAAC,CAAC,GAAG;IAClB,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAEJ,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CAC5E,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CACnD,CAAC,CAAC,CAAC,CAAC;AAwCL;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACxB,CAAC,SAAS,MAAM,EAChB,cAAc,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,iBAAiB,CAAC,cAAc,CAAC,2MAErD"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ZQLDatabase } from "../zql-database.js";
|
|
2
|
-
class ZeroDrizzleConnection {
|
|
3
|
-
#client;
|
|
4
|
-
constructor(client) {
|
|
5
|
-
this.#client = client;
|
|
6
|
-
}
|
|
7
|
-
transaction(cb) {
|
|
8
|
-
return this.#client.transaction(drizzleTx => cb(new ZeroDrizzleTransaction(drizzleTx)));
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
class ZeroDrizzleTransaction {
|
|
12
|
-
#tx;
|
|
13
|
-
constructor(tx) {
|
|
14
|
-
this.#tx = tx;
|
|
15
|
-
}
|
|
16
|
-
query(sql, params) {
|
|
17
|
-
const session = this.wrappedTransaction._.session;
|
|
18
|
-
return session.client.query(sql, params).then(({ rows }) => rows);
|
|
19
|
-
}
|
|
20
|
-
get wrappedTransaction() {
|
|
21
|
-
return this.#tx;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Example usage:
|
|
26
|
-
* ```ts
|
|
27
|
-
* import {drizzle} from 'drizzle-orm/node-postgres';
|
|
28
|
-
* const db = drizzle(process.env.PG_URL!);
|
|
29
|
-
* const dbProvider = zeroNodePg(db);
|
|
30
|
-
*
|
|
31
|
-
* // within your custom mutators you can do:
|
|
32
|
-
* const tx = tx.wrappedTransaction();
|
|
33
|
-
* // to get ahold of the underlying drizzle client
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function zeroNodePg(schema, client) {
|
|
37
|
-
return new ZQLDatabase(new ZeroDrizzleConnection(client), schema);
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=drizzle-pg.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-pg.js","sourceRoot":"","sources":["../../../../../zero-server/src/adapters/drizzle-pg.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAW/C,MAAM,qBAAqB;IAIhB,OAAO,CAAuB;IACvC,YAAY,MAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,WAAW,CACT,EAA+D;QAE/D,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAC1C,EAAE,CAAC,IAAI,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAC1C,CAAC;IACJ,CAAC;CACF;AAED,MAAM,sBAAsB;IAGjB,GAAG,CAAwB;IACpC,YAAY,EAAyB;QACnC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,MAAiB;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,OAEzC,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAM,GAAG,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAGxB,MAAS,EAAE,MAAyC;IACpD,OAAO,IAAI,WAAW,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AACpE,CAAC"}
|
|
File without changes
|
|
File without changes
|