@prisma/orm-postgres 8.0.0-rc.18-dev.20 → 8.0.0-rc.18-dev.22
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/contract-from-json--c1yeq8I-CgRc9Lrx.mjs +33 -0
- package/dist/contract-from-json--c1yeq8I-CgRc9Lrx.mjs.map +1 -0
- package/dist/contract-from-json-ZRZt8Cse-BkZYEfDX.d.mts +26 -0
- package/dist/contract-from-json-ZRZt8Cse-BkZYEfDX.d.mts.map +1 -0
- package/dist/contract__validate-once.d.mts +1 -0
- package/dist/contract__validate-once.mjs +2 -0
- package/dist/internal__validate-contract.d.mts +2 -0
- package/dist/internal__validate-contract.mjs +2 -0
- package/dist/{postgres-options-snwVSiHP-wfK0Xrpa.d.mts → postgres-options-C6x1ZHJX-DxeRq4pl.d.mts} +3 -3
- package/dist/{postgres-options-snwVSiHP-wfK0Xrpa.d.mts.map → postgres-options-C6x1ZHJX-DxeRq4pl.d.mts.map} +1 -1
- package/dist/{postgres-runtime-BlCLYNDD-C3z5yOO4.mjs → postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs} +2 -2
- package/dist/{postgres-runtime-BlCLYNDD-C3z5yOO4.mjs.map → postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs.map} +1 -1
- package/dist/{postgres-static-Crd_bF1a-DLqHzv91.d.mts → postgres-static-CWKc2Lc4-vwO-rlxR.d.mts} +13 -3
- package/dist/{postgres-static-Crd_bF1a-DLqHzv91.d.mts.map → postgres-static-CWKc2Lc4-vwO-rlxR.d.mts.map} +1 -1
- package/dist/{postgres-static-DzefaBeX-Cz36Sz8Q.mjs → postgres-static-ytFKA5eZ-DBqSRBpN.mjs} +20 -11
- package/dist/postgres-static-ytFKA5eZ-DBqSRBpN.mjs.map +1 -0
- package/dist/runtime.d.mts +19 -17
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +23 -14
- package/dist/runtime.mjs.map +1 -1
- package/dist/serverless.d.mts +8 -13
- package/dist/serverless.d.mts.map +1 -1
- package/dist/serverless.mjs +32 -14
- package/dist/serverless.mjs.map +1 -1
- package/dist/static.d.mts +3 -2
- package/dist/static.mjs +3 -2
- package/package.json +10 -8
- package/skills/prisma-8/SKILL.md +2 -2
- package/skills/prisma-8/references/contract.md +1 -1
- package/skills/prisma-8/references/debug.md +2 -2
- package/skills/prisma-8/references/migrations.md +3 -2
- package/skills/prisma-8/references/queries-mongo.md +1 -1
- package/skills/prisma-8/references/queries-postgres.md +1 -1
- package/skills/prisma-8/references/quickstart.md +1 -1
- package/skills/prisma-8/references/runtime.md +39 -28
- package/skills/prisma-8/references/supabase.md +6 -3
- package/dist/postgres-static-DzefaBeX-Cz36Sz8Q.mjs.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
2
|
+
import { validateContractOnce } from "@prisma/orm-framework/contract/validate-once";
|
|
3
|
+
//#region ../../../3-extensions/postgres/dist/contract-from-json--c1yeq8I.mjs
|
|
4
|
+
var version = "8.0.0-rc.18-dev.22";
|
|
5
|
+
const serializer = new PostgresContractSerializer();
|
|
6
|
+
const validator = `${postgresTarget.targetId}@${version}`;
|
|
7
|
+
/**
|
|
8
|
+
* Validates an emitted Postgres `contract.json` and returns it as the contract type the
|
|
9
|
+
* application names, ready to pass to `postgres({ contract })` and the other Postgres clients.
|
|
10
|
+
* Clients built from the result do not validate it again.
|
|
11
|
+
*
|
|
12
|
+
* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the
|
|
13
|
+
* returned value after the call: clients built from the value later do not validate it again.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import type { Contract } from './contract.d';
|
|
18
|
+
* import contractJson from './contract.json' with { type: 'json' };
|
|
19
|
+
*
|
|
20
|
+
* export const contract = contractFromJson<Contract>(contractJson);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function contractFromJson(json) {
|
|
24
|
+
return validateContractOnce(json, validator, (input) => serializer.deserializeContract(input));
|
|
25
|
+
}
|
|
26
|
+
/** Validates a contract value for a Postgres client, once per value. */
|
|
27
|
+
function validatePostgresContract(contract) {
|
|
28
|
+
return validateContractOnce(contract, validator, () => serializer.deserializeContract(serializer.serializeContract(contract)));
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { validatePostgresContract as n, contractFromJson as t };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=contract-from-json--c1yeq8I-CgRc9Lrx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-from-json--c1yeq8I-CgRc9Lrx.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/contract-from-json--c1yeq8I.mjs"],"sourcesContent":["import postgresTarget, { PostgresContractSerializer } from \"@internal/target-postgres/runtime\";\nimport { validateContractOnce } from \"@internal/contract/validate-once\";\n//#region package.json\nvar version = \"8.0.0-rc.18-dev.22\";\n//#endregion\n//#region src/static/contract-from-json.ts\nconst serializer = new PostgresContractSerializer();\nconst validator = `${postgresTarget.targetId}@${version}`;\n/**\n* Validates an emitted Postgres `contract.json` and returns it as the contract type the\n* application names, ready to pass to `postgres({ contract })` and the other Postgres clients.\n* Clients built from the result do not validate it again.\n*\n* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the\n* returned value after the call: clients built from the value later do not validate it again.\n*\n* @example\n* ```ts\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* ```\n*/\nfunction contractFromJson(json) {\n\treturn validateContractOnce(json, validator, (input) => serializer.deserializeContract(input));\n}\n/** Validates a contract value for a Postgres client, once per value. */\nfunction validatePostgresContract(contract) {\n\treturn validateContractOnce(contract, validator, () => serializer.deserializeContract(serializer.serializeContract(contract)));\n}\n//#endregion\nexport { validatePostgresContract as n, contractFromJson as t };\n\n//# sourceMappingURL=contract-from-json--c1yeq8I.mjs.map"],"mappings":";;;AAGA,IAAI,UAAU;AAGd,MAAM,aAAa,IAAI,2BAA2B;AAClD,MAAM,YAAY,GAAG,eAAe,SAAS,GAAG;;;;;;;;;;;;;;;;;AAiBhD,SAAS,iBAAiB,MAAM;CAC/B,OAAO,qBAAqB,MAAM,YAAY,UAAU,WAAW,oBAAoB,KAAK,CAAC;AAC9F;;AAEA,SAAS,yBAAyB,UAAU;CAC3C,OAAO,qBAAqB,UAAU,iBAAiB,WAAW,oBAAoB,WAAW,kBAAkB,QAAQ,CAAC,CAAC;AAC9H"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
2
|
+
import { SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
3
|
+
//#region ../../../3-extensions/postgres/dist/contract-from-json-ZRZt8Cse.d.mts
|
|
4
|
+
//#region src/static/contract-from-json.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Validates an emitted Postgres `contract.json` and returns it as the contract type the
|
|
7
|
+
* application names, ready to pass to `postgres({ contract })` and the other Postgres clients.
|
|
8
|
+
* Clients built from the result do not validate it again.
|
|
9
|
+
*
|
|
10
|
+
* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the
|
|
11
|
+
* returned value after the call: clients built from the value later do not validate it again.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { Contract } from './contract.d';
|
|
16
|
+
* import contractJson from './contract.json' with { type: 'json' };
|
|
17
|
+
*
|
|
18
|
+
* export const contract = contractFromJson<Contract>(contractJson);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function contractFromJson<TContract extends Contract<SqlStorage>>(json: unknown): TContract;
|
|
22
|
+
/** Validates a contract value for a Postgres client, once per value. */
|
|
23
|
+
declare function validatePostgresContract<TContract extends Contract<SqlStorage>>(contract: TContract): TContract;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { validatePostgresContract as n, contractFromJson as t };
|
|
26
|
+
//# sourceMappingURL=contract-from-json-ZRZt8Cse-BkZYEfDX.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-from-json-ZRZt8Cse-BkZYEfDX.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/contract-from-json-ZRZt8Cse.d.mts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAmBiB,iBAAiB,kBAAkB,SAAS,aAAa,gBAAgB;;iBAEzE,yBAAyB,kBAAkB,SAAS,aAAa,UAAU,YAAY"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@prisma/orm-framework/contract/validate-once";
|
package/dist/{postgres-options-snwVSiHP-wfK0Xrpa.d.mts → postgres-options-C6x1ZHJX-DxeRq4pl.d.mts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PostgresStaticContext, r as PostgresTargetId, t as NamespacedNativeEnums } from "./postgres-static-
|
|
1
|
+
import { n as PostgresStaticContext, r as PostgresTargetId, t as NamespacedNativeEnums } from "./postgres-static-CWKc2Lc4-vwO-rlxR.mjs";
|
|
2
2
|
import { BindSiteParams, Declaration, Log, ParamsFromDeclaration, Runtime, SqlExecutionStackWithDriver, SqlMiddleware, SqlRuntimeExtensionDescriptor, TransactionContext, VerifyMarkerOption } from "@prisma/orm-family-sql/runtime";
|
|
3
3
|
import { PreparedFrom, orm } from "@prisma/orm-family-sql/orm-client";
|
|
4
4
|
import { NamespacedEnums } from "@prisma/orm-framework/contract/enum-accessor";
|
|
@@ -8,7 +8,7 @@ import { ExtractCodecTypes, SqlStorage } from "@prisma/orm-family-sql/contract/t
|
|
|
8
8
|
import { Db } from "@prisma/orm-family-sql/builder/types";
|
|
9
9
|
import { CodecTypesBase } from "@prisma/orm-family-sql/relational-core/expression";
|
|
10
10
|
import { Preparable, SqlQueryPlan } from "@prisma/orm-family-sql/relational-core/plan";
|
|
11
|
-
//#region ../../../3-extensions/postgres/dist/postgres-options-
|
|
11
|
+
//#region ../../../3-extensions/postgres/dist/postgres-options-C6x1ZHJX.d.mts
|
|
12
12
|
//#region src/runtime/postgres-members.d.ts
|
|
13
13
|
type OrmClient<TContract extends Contract<SqlStorage>> = ReturnType<typeof orm<TContract>>;
|
|
14
14
|
interface PostgresTransactionContext<TContract extends Contract<SqlStorage>> extends TransactionContext {
|
|
@@ -53,4 +53,4 @@ interface PostgresExecutionOptions {
|
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
55
|
export { PostgresStaticMembers as a, PostgresRuntimeBoundMembers as i, PostgresExecutionOptions as n, PostgresLifecycleMembers as r, PostgresCursorOptions as t };
|
|
56
|
-
//# sourceMappingURL=postgres-options-
|
|
56
|
+
//# sourceMappingURL=postgres-options-C6x1ZHJX-DxeRq4pl.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-options-
|
|
1
|
+
{"version":3,"file":"postgres-options-C6x1ZHJX-DxeRq4pl.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-options-C6x1ZHJX.d.mts"],"mappings":";;;;;;;;;;;;KAWK,UAAU,kBAAkB,SAAS,eAAe,kBAAkB,IAAI;UACrE,2BAA2B,kBAAkB,SAAS,qBAAqB;WAC1E,KAAK,GAAG;WACR,KAAK,UAAU;WACf,OAAO,gBAAgB;WACvB,aAAa,sBAAsB;;UAEpC,sBAAsB,kBAAkB,SAAS,qBAAqB,sBAAsB;WAC3F,OAAO,4BAA4B;;UAEpC,4BAA4B,kBAAkB,SAAS;WACtD,KAAK,UAAU;EACxB,WAAW;EACX,YAAY,GAAG,KAAK,IAAI,2BAA2B,eAAe,YAAY,KAAK,QAAQ;EAC3F,QAAQ,UAAU,YAAY,KAAK,UAAU,eAAe,8BAA8B,WAAW,iBAAiB,kBAAkB,YAAY,aAAa,GAAG,WAAW,QAAQ,eAAe,OAAO,IAAI,QAAQ,aAAa,sBAAsB,GAAG,KAAK;;UAE5P;EACR,SAAS;GACR,OAAO,iBAAiB;;;;;;;;;UASjB;WACC;;;;;;UAMD;WACC,sBAAsB,8BAA8B;WACpD,sBAAsB;WACtB,eAAe;WACf,MAAM;WACN,SAAS"}
|
package/dist/{postgres-runtime-BlCLYNDD-C3z5yOO4.mjs → postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CYOOg0sB.mjs";
|
|
2
2
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
3
3
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
4
|
+
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
4
5
|
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
5
6
|
import { SqlRuntimeBase, activitySource, delegatingActivitySource, withTransaction } from "@prisma/orm-family-sql/runtime";
|
|
6
|
-
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
7
7
|
import { sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
8
8
|
import { orm, prepareQuery } from "@prisma/orm-family-sql/orm-client";
|
|
9
9
|
import { type } from "arktype";
|
|
@@ -160,4 +160,4 @@ var PostgresRuntimeImpl = class extends SqlRuntimeBase {
|
|
|
160
160
|
//#endregion
|
|
161
161
|
export { isPgPool as a, toDriverCursorOptions as c, validatePostgresUrl as d, isPgClient as i, toRuntimeOptions as l, PostgresRuntimeImpl as n, resolveOptionalPostgresBinding as o, buildPostgresRuntimeBoundMembers as r, resolvePostgresBinding as s, DEFAULT_CONNECT_TIMEOUT_MILLIS as t, validateCursorOptions as u };
|
|
162
162
|
|
|
163
|
-
//# sourceMappingURL=postgres-runtime-BlCLYNDD-
|
|
163
|
+
//# sourceMappingURL=postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-runtime-BlCLYNDD-
|
|
1
|
+
{"version":3,"file":"postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-runtime-BlCLYNDD.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { blindCast, castAs } from \"@internal/utils/casts\";\nimport { SqlRuntimeBase, activitySource, delegatingActivitySource, withTransaction } from \"@internal/sql-runtime\";\nimport postgresTarget from \"@internal/target-postgres/runtime\";\nimport { sql } from \"@internal/sql-builder/runtime\";\nimport { orm, prepareQuery } from \"@internal/sql-orm-client\";\nimport { type } from \"arktype\";\n//#region src/runtime/binding.ts\nconst isPgPool = (pg) => \"totalCount\" in pg && \"idleCount\" in pg && \"waitingCount\" in pg;\nconst isPgClient = (pg) => \"escapeIdentifier\" in pg && \"escapeLiteral\" in pg;\nfunction validatePostgresUrl(url) {\n\tconst trimmed = url.trim();\n\tif (trimmed.length === 0) throw postgresError(\"RUNTIME.BINDING_INVALID\", \"Postgres URL must be a non-empty string\", { meta: {\n\t\textension: \"postgres\",\n\t\treason: \"empty url\"\n\t} });\n\tlet parsed;\n\ttry {\n\t\tparsed = new URL(trimmed);\n\t} catch {\n\t\tthrow postgresError(\"RUNTIME.BINDING_INVALID\", \"Postgres URL must be a valid URL\", { meta: {\n\t\t\textension: \"postgres\",\n\t\t\treason: \"unparseable url\"\n\t\t} });\n\t}\n\tif (parsed.protocol !== \"postgres:\" && parsed.protocol !== \"postgresql:\") throw postgresError(\"RUNTIME.BINDING_INVALID\", \"Postgres URL must use postgres:// or postgresql://\", { meta: {\n\t\textension: \"postgres\",\n\t\treason: \"wrong scheme\",\n\t\treceived: parsed.protocol\n\t} });\n\treturn trimmed;\n}\nfunction resolvePostgresBinding(options) {\n\tif (Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.pg !== void 0) !== 1) throw postgresError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, or pg\", {\n\t\tfix: \"Pass exactly one of `binding`, `url`, or `pg`.\",\n\t\tmeta: {\n\t\t\textension: \"postgres\",\n\t\t\treason: \"zero or multiple binding inputs\"\n\t\t}\n\t});\n\tif (options.binding !== void 0) return options.binding;\n\tif (options.url !== void 0) return {\n\t\tkind: \"url\",\n\t\turl: validatePostgresUrl(options.url)\n\t};\n\tconst pgBinding = options.pg;\n\tif (pgBinding === void 0) throw new InternalError(\"Invariant violation: expected pg binding after validation\");\n\tif (isPgPool(pgBinding)) return {\n\t\tkind: \"pgPool\",\n\t\tpool: pgBinding\n\t};\n\tif (isPgClient(pgBinding)) return {\n\t\tkind: \"pgClient\",\n\t\tclient: pgBinding\n\t};\n\tthrow postgresError(\"RUNTIME.BINDING_INVALID\", \"Unable to determine pg binding type from pg input; use binding with explicit kind\", {\n\t\tfix: \"Pass `binding: { kind: \\\"pgPool\\\", pool }` or `binding: { kind: \\\"pgClient\\\", client }` instead of `pg`.\",\n\t\tmeta: {\n\t\t\textension: \"postgres\",\n\t\t\treason: \"unrecognizable pg object\"\n\t\t}\n\t});\n}\nfunction resolveOptionalPostgresBinding(options) {\n\tif (Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.pg !== void 0) === 0) return;\n\treturn resolvePostgresBinding(blindCast(options));\n}\n//#endregion\n//#region src/runtime/postgres-members.ts\nfunction buildPostgresRuntimeBoundMembers(options) {\n\tconst { context, rawCodecInferer, enums, nativeEnums, getRuntime, getRuntimeForWork } = options;\n\tconst orm$1 = orm({\n\t\truntime: {\n\t\t\tquery(plan) {\n\t\t\t\treturn getRuntimeForWork().query(plan);\n\t\t\t},\n\t\t\texecute(plan) {\n\t\t\t\treturn getRuntimeForWork().execute(plan);\n\t\t\t},\n\t\t\tconnection() {\n\t\t\t\treturn getRuntimeForWork().connection();\n\t\t\t},\n\t\t\t[activitySource]: delegatingActivitySource(() => getRuntimeForWork())\n\t\t},\n\t\tcontext\n\t});\n\tfunction prepare(declaration, callback) {\n\t\treturn prepareQuery(getRuntimeForWork(), declaration, callback);\n\t}\n\treturn {\n\t\torm: orm$1,\n\t\truntime() {\n\t\t\treturn getRuntime();\n\t\t},\n\t\tprepare,\n\t\ttransaction(fn) {\n\t\t\treturn withTransaction(getRuntimeForWork(), (txCtx) => {\n\t\t\t\tconst txSql = sql({\n\t\t\t\t\tcontext,\n\t\t\t\t\trawCodecInferer\n\t\t\t\t});\n\t\t\t\tconst txOrm = orm({\n\t\t\t\t\truntime: {\n\t\t\t\t\t\tquery(plan) {\n\t\t\t\t\t\t\treturn txCtx.query(plan);\n\t\t\t\t\t\t},\n\t\t\t\t\t\texecute(plan) {\n\t\t\t\t\t\t\treturn txCtx.execute(plan);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[activitySource]: delegatingActivitySource(() => txCtx)\n\t\t\t\t\t},\n\t\t\t\t\tcontext\n\t\t\t\t});\n\t\t\t\treturn fn(Object.assign(castAs(Object.create(txCtx)), {\n\t\t\t\t\tsql: txSql,\n\t\t\t\t\torm: txOrm,\n\t\t\t\t\tenums,\n\t\t\t\t\tnativeEnums\n\t\t\t\t}));\n\t\t\t});\n\t\t}\n\t};\n}\n//#endregion\n//#region src/runtime/postgres-options.ts\n/**\n* Default time to wait for the database to accept a connection, for a client's pool and for a\n* connection's `pg.Client`.\n*/\nconst DEFAULT_CONNECT_TIMEOUT_MILLIS = 2e4;\nconst cursorOptionsSchema = type({ \"batchSize?\": \"number.integer > 0 | undefined\" }).onUndeclaredKey(\"reject\");\nfunction validateCursorOptions(cursor, helper) {\n\tif (cursor === void 0) return;\n\tconst result = cursorOptionsSchema(cursor);\n\tif (result instanceof type.errors) throw postgresError(\"RUNTIME.ARGUMENT_INVALID\", \"Invalid cursor option\", {\n\t\twhy: result.summary,\n\t\tfix: \"Pass cursor: {} or cursor: { batchSize: <positive integer> } to read through a server-side cursor, or leave cursor unset to read without one.\",\n\t\tmeta: {\n\t\t\textension: \"postgres\",\n\t\t\thelper,\n\t\t\targument: \"cursor\",\n\t\t\treceived: cursor\n\t\t}\n\t});\n\treturn result;\n}\nfunction toDriverCursorOptions(cursor) {\n\treturn cursor === void 0 ? { disabled: true } : ifDefined(\"batchSize\", cursor.batchSize);\n}\nfunction toRuntimeOptions(options) {\n\treturn {\n\t\t...ifDefined(\"verifyMarker\", options.verifyMarker),\n\t\t...ifDefined(\"middleware\", options.middleware),\n\t\t...ifDefined(\"log\", options.log)\n\t};\n}\n//#endregion\n//#region src/runtime/postgres-runtime.ts\nvar PostgresRuntimeImpl = class extends SqlRuntimeBase {\n\tgetListDecoder() {\n\t\treturn postgresTarget.listDecoder();\n\t}\n};\n//#endregion\nexport { validateCursorOptions as a, isPgPool as c, validatePostgresUrl as d, toRuntimeOptions as i, resolveOptionalPostgresBinding as l, DEFAULT_CONNECT_TIMEOUT_MILLIS as n, buildPostgresRuntimeBoundMembers as o, toDriverCursorOptions as r, isPgClient as s, PostgresRuntimeImpl as t, resolvePostgresBinding as u };\n\n//# sourceMappingURL=postgres-runtime-BlCLYNDD.mjs.map"],"mappings":";;;;;;;;;;AAUA,MAAM,YAAY,OAAO,gBAAgB,MAAM,eAAe,MAAM,kBAAkB;AACtF,MAAM,cAAc,OAAO,sBAAsB,MAAM,mBAAmB;AAC1E,SAAS,oBAAoB,KAAK;CACjC,MAAM,UAAU,IAAI,KAAK;CACzB,IAAI,QAAQ,WAAW,GAAG,MAAM,cAAc,2BAA2B,2CAA2C,EAAE,MAAM;EAC3H,WAAW;EACX,QAAQ;CACT,EAAE,CAAC;CACH,IAAI;CACJ,IAAI;EACH,SAAS,IAAI,IAAI,OAAO;CACzB,QAAQ;EACP,MAAM,cAAc,2BAA2B,oCAAoC,EAAE,MAAM;GAC1F,WAAW;GACX,QAAQ;EACT,EAAE,CAAC;CACJ;CACA,IAAI,OAAO,aAAa,eAAe,OAAO,aAAa,eAAe,MAAM,cAAc,2BAA2B,sDAAsD,EAAE,MAAM;EACtL,WAAW;EACX,QAAQ;EACR,UAAU,OAAO;CAClB,EAAE,CAAC;CACH,OAAO;AACR;AACA,SAAS,uBAAuB,SAAS;CACxC,IAAI,OAAO,QAAQ,YAAY,KAAK,CAAC,IAAI,OAAO,QAAQ,QAAQ,KAAK,CAAC,IAAI,OAAO,QAAQ,OAAO,KAAK,CAAC,MAAM,GAAG,MAAM,cAAc,2BAA2B,kDAAkD;EAC/M,KAAK;EACL,MAAM;GACL,WAAW;GACX,QAAQ;EACT;CACD,CAAC;CACD,IAAI,QAAQ,YAAY,KAAK,GAAG,OAAO,QAAQ;CAC/C,IAAI,QAAQ,QAAQ,KAAK,GAAG,OAAO;EAClC,MAAM;EACN,KAAK,oBAAoB,QAAQ,GAAG;CACrC;CACA,MAAM,YAAY,QAAQ;CAC1B,IAAI,cAAc,KAAK,GAAG,MAAM,IAAI,cAAc,2DAA2D;CAC7G,IAAI,SAAS,SAAS,GAAG,OAAO;EAC/B,MAAM;EACN,MAAM;CACP;CACA,IAAI,WAAW,SAAS,GAAG,OAAO;EACjC,MAAM;EACN,QAAQ;CACT;CACA,MAAM,cAAc,2BAA2B,qFAAqF;EACnI,KAAK;EACL,MAAM;GACL,WAAW;GACX,QAAQ;EACT;CACD,CAAC;AACF;AACA,SAAS,+BAA+B,SAAS;CAChD,IAAI,OAAO,QAAQ,YAAY,KAAK,CAAC,IAAI,OAAO,QAAQ,QAAQ,KAAK,CAAC,IAAI,OAAO,QAAQ,OAAO,KAAK,CAAC,MAAM,GAAG;CAC/G,OAAO,uBAAuB,UAAU,OAAO,CAAC;AACjD;AAGA,SAAS,iCAAiC,SAAS;CAClD,MAAM,EAAE,SAAS,iBAAiB,OAAO,aAAa,YAAY,sBAAsB;CACxF,MAAM,QAAQ,IAAI;EACjB,SAAS;GACR,MAAM,MAAM;IACX,OAAO,kBAAkB,CAAC,CAAC,MAAM,IAAI;GACtC;GACA,QAAQ,MAAM;IACb,OAAO,kBAAkB,CAAC,CAAC,QAAQ,IAAI;GACxC;GACA,aAAa;IACZ,OAAO,kBAAkB,CAAC,CAAC,WAAW;GACvC;IACC,iBAAiB,+BAA+B,kBAAkB,CAAC;EACrE;EACA;CACD,CAAC;CACD,SAAS,QAAQ,aAAa,UAAU;EACvC,OAAO,aAAa,kBAAkB,GAAG,aAAa,QAAQ;CAC/D;CACA,OAAO;EACN,KAAK;EACL,UAAU;GACT,OAAO,WAAW;EACnB;EACA;EACA,YAAY,IAAI;GACf,OAAO,gBAAgB,kBAAkB,IAAI,UAAU;IACtD,MAAM,QAAQ,IAAI;KACjB;KACA;IACD,CAAC;IACD,MAAM,QAAQ,IAAI;KACjB,SAAS;MACR,MAAM,MAAM;OACX,OAAO,MAAM,MAAM,IAAI;MACxB;MACA,QAAQ,MAAM;OACb,OAAO,MAAM,QAAQ,IAAI;MAC1B;OACC,iBAAiB,+BAA+B,KAAK;KACvD;KACA;IACD,CAAC;IACD,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK,CAAC,GAAG;KACrD,KAAK;KACL,KAAK;KACL;KACA;IACD,CAAC,CAAC;GACH,CAAC;EACF;CACD;AACD;;;;;AAOA,MAAM,iCAAiC;AACvC,MAAM,sBAAsB,KAAK,EAAE,cAAc,iCAAiC,CAAC,CAAC,CAAC,gBAAgB,QAAQ;AAC7G,SAAS,sBAAsB,QAAQ,QAAQ;CAC9C,IAAI,WAAW,KAAK,GAAG;CACvB,MAAM,SAAS,oBAAoB,MAAM;CACzC,IAAI,kBAAkB,KAAK,QAAQ,MAAM,cAAc,4BAA4B,yBAAyB;EAC3G,KAAK,OAAO;EACZ,KAAK;EACL,MAAM;GACL,WAAW;GACX;GACA,UAAU;GACV,UAAU;EACX;CACD,CAAC;CACD,OAAO;AACR;AACA,SAAS,sBAAsB,QAAQ;CACtC,OAAO,WAAW,KAAK,IAAI,EAAE,UAAU,KAAK,IAAI,UAAU,aAAa,OAAO,SAAS;AACxF;AACA,SAAS,iBAAiB,SAAS;CAClC,OAAO;EACN,GAAG,UAAU,gBAAgB,QAAQ,YAAY;EACjD,GAAG,UAAU,cAAc,QAAQ,UAAU;EAC7C,GAAG,UAAU,OAAO,QAAQ,GAAG;CAChC;AACD;AAGA,IAAI,sBAAsB,cAAc,eAAe;CACtD,iBAAiB;EAChB,OAAO,eAAe,YAAY;CACnC;AACD"}
|
package/dist/{postgres-static-Crd_bF1a-DLqHzv91.d.mts → postgres-static-CWKc2Lc4-vwO-rlxR.d.mts}
RENAMED
|
@@ -4,7 +4,7 @@ import { Contract } from "@prisma/orm-framework/contract/types";
|
|
|
4
4
|
import { SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
5
5
|
import { Db, RawLane } from "@prisma/orm-family-sql/builder/types";
|
|
6
6
|
import "@prisma/orm-family-sql/relational-core/expression";
|
|
7
|
-
//#region ../../../3-extensions/postgres/dist/postgres-static-
|
|
7
|
+
//#region ../../../3-extensions/postgres/dist/postgres-static-CWKc2Lc4.d.mts
|
|
8
8
|
//#region src/runtime/native-enums.d.ts
|
|
9
9
|
declare function buildNamespacedNativeEnums(storage: SqlStorage, domain: Contract['domain']): Record<string, Record<string, EnumAccessor>>;
|
|
10
10
|
type Present<T> = Exclude<T, undefined>;
|
|
@@ -50,10 +50,20 @@ interface PostgresStaticContext<TContract extends Contract<SqlStorage>> {
|
|
|
50
50
|
readonly sql: Db<TContract>;
|
|
51
51
|
readonly raw: RawLane<TContract>;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The query surfaces of a Postgres client without a driver: `sql`, `raw`, `enums` and
|
|
55
|
+
* `nativeEnums`. Use it where loading `pg` is not wanted, for example in browser code that reads
|
|
56
|
+
* enums.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { enums } = postgresStatic({ contract: contractFromJson<Contract>(contractJson) });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
53
63
|
declare function postgresStatic<TContract extends Contract<SqlStorage>>(options: {
|
|
54
|
-
readonly
|
|
64
|
+
readonly contract: TContract;
|
|
55
65
|
readonly extensions?: readonly SqlRuntimeExtensionDescriptor<PostgresTargetId>[];
|
|
56
66
|
}): PostgresStaticContext<TContract>;
|
|
57
67
|
//#endregion
|
|
58
68
|
export { postgresStatic as a, buildNamespacedNativeEnums as i, PostgresStaticContext as n, PostgresTargetId as r, NamespacedNativeEnums as t };
|
|
59
|
-
//# sourceMappingURL=postgres-static-
|
|
69
|
+
//# sourceMappingURL=postgres-static-CWKc2Lc4-vwO-rlxR.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-static-
|
|
1
|
+
{"version":3,"file":"postgres-static-CWKc2Lc4-vwO-rlxR.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-static-CWKc2Lc4.d.mts"],"mappings":";;;;;;;;iBAOiB,2BAA2B,SAAS,YAAY,QAAQ,qBAAqB,eAAe,eAAe;KACvH,QAAQ,KAAK,QAAQ;KACrB,yBAAyB,OAAO;WAC1B;aACE,iBAAiB;;oBAEV,IAAI,uBAAuB,QAAQ,KAAK;KACvD;WACM;;KAEN,gBAAgB,iDAAiD,WAAW;WACtE,MAAM,QAAQ,OAAO;WACrB,OAAO,OAAO;;;;;;;;KAQpB,oBAAoB,cAAc;WAC5B,SAAS,gBAAgB;;KAE/B,6BAA6B,SAAS,+BAA+B,WAAW,WAAW,QAAQ,GAAG,mBAAmB,QAAQ,WAAW,gBAAgB,oBAAoB,QAAQ;KACxL,gBAAgB,kBAAkB,UAAU,MAAM,iBAAiB,oCAAoC,kCAAkC;WACnI,aAAa;yBACC,QAAQ,mBAAmB,QAAQ;;;;KAIvD,sBAAsB,kBAAkB,wBAAwB,YAAY,qCAAqC,uBAAuB,6BAA6B,yBAAyB,mCAAmC,MAAM,gBAAgB,WAAW;;;KAGlQ;;;UAGK,sBAAsB,kBAAkB,SAAS;WAChD,SAAS,iBAAiB;WAC1B,UAAU;WACV,OAAO,gBAAgB;WACvB,aAAa,sBAAsB;WACnC,KAAK,GAAG;WACR,KAAK,QAAQ;;;;;;;;;;;;iBAYP,eAAe,kBAAkB,SAAS,aAAa;WAC7D,UAAU;WACV,sBAAsB,8BAA8B;IAC3D,sBAAsB"}
|
package/dist/{postgres-static-DzefaBeX-Cz36Sz8Q.mjs → postgres-static-ytFKA5eZ-DBqSRBpN.mjs}
RENAMED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { n as validatePostgresContract } from "./contract-from-json--c1yeq8I-CgRc9Lrx.mjs";
|
|
1
2
|
import { PG_ENUM_CODEC_ID } from "@prisma/orm-target-postgres/target/codec-ids";
|
|
3
|
+
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
2
4
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
5
|
import { createExecutionContext, createSqlExecutionStack } from "@prisma/orm-family-sql/runtime";
|
|
4
|
-
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
5
6
|
import { createRawLane, sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
6
7
|
import { buildNamespacedEnums, createEnumAccessor } from "@prisma/orm-framework/contract/enum-accessor";
|
|
7
8
|
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
8
|
-
//#region ../../../3-extensions/postgres/dist/postgres-static-
|
|
9
|
+
//#region ../../../3-extensions/postgres/dist/postgres-static-ytFKA5eZ.mjs
|
|
9
10
|
/**
|
|
10
11
|
* The accessors for one namespace's value sets, leaving out each value set whose name is a domain enum's in the same namespace: a domain enum's value set takes its enum's name and namespace, and `db.enums` holds that enum. The rest are native enum types, because `native_enum` is the only pack entity that derives a value set today. Reads plain contract data, so a `validateContract`'d JSON contract works as well as a hydrated one. A member is a value, as in `CREATE TYPE … AS ENUM ('a', 'b')`, so each value is also its own name.
|
|
11
12
|
*/
|
|
@@ -31,7 +32,7 @@ function buildNamespacedNativeEnums(storage, domain) {
|
|
|
31
32
|
for (const namespaceId of Object.keys(storage.namespaces)) result[namespaceId] = buildNativeEnumsMapForNamespace(storage, domain, namespaceId);
|
|
32
33
|
return result;
|
|
33
34
|
}
|
|
34
|
-
function buildPostgresStaticContext(context, rawCodecInferer) {
|
|
35
|
+
function buildPostgresStaticContext(contract, context, rawCodecInferer) {
|
|
35
36
|
const sqlDb = sql({
|
|
36
37
|
context,
|
|
37
38
|
rawCodecInferer
|
|
@@ -40,25 +41,33 @@ function buildPostgresStaticContext(context, rawCodecInferer) {
|
|
|
40
41
|
context,
|
|
41
42
|
rawCodecInferer
|
|
42
43
|
});
|
|
43
|
-
const enums = Object.freeze(buildNamespacedEnums(context.contract.domain, (codecId) => context.contractCodecs.forCodecRef({ codecId })));
|
|
44
|
-
const nativeEnums = blindCast(Object.freeze(buildNamespacedNativeEnums(context.contract.storage, context.contract.domain)));
|
|
45
44
|
return {
|
|
46
45
|
context,
|
|
47
|
-
contract
|
|
48
|
-
enums,
|
|
49
|
-
nativeEnums,
|
|
46
|
+
contract,
|
|
47
|
+
enums: Object.freeze(buildNamespacedEnums(context.contract.domain, (codecId) => context.contractCodecs.forCodecRef({ codecId }))),
|
|
48
|
+
nativeEnums: blindCast(Object.freeze(buildNamespacedNativeEnums(context.contract.storage, context.contract.domain))),
|
|
50
49
|
sql: sqlDb,
|
|
51
50
|
raw
|
|
52
51
|
};
|
|
53
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The query surfaces of a Postgres client without a driver: `sql`, `raw`, `enums` and
|
|
55
|
+
* `nativeEnums`. Use it where loading `pg` is not wanted, for example in browser code that reads
|
|
56
|
+
* enums.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { enums } = postgresStatic({ contract: contractFromJson<Contract>(contractJson) });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
54
63
|
function postgresStatic(options) {
|
|
55
|
-
const contract =
|
|
64
|
+
const contract = validatePostgresContract(options.contract);
|
|
56
65
|
const stack = createSqlExecutionStack({
|
|
57
66
|
target: postgresTarget,
|
|
58
67
|
adapter: postgresAdapter,
|
|
59
68
|
extensions: options.extensions ?? []
|
|
60
69
|
});
|
|
61
|
-
return buildPostgresStaticContext(createExecutionContext({
|
|
70
|
+
return buildPostgresStaticContext(contract, createExecutionContext({
|
|
62
71
|
contract,
|
|
63
72
|
stack
|
|
64
73
|
}), stack.adapter.rawCodecInferer);
|
|
@@ -66,4 +75,4 @@ function postgresStatic(options) {
|
|
|
66
75
|
//#endregion
|
|
67
76
|
export { buildPostgresStaticContext as n, postgresStatic as r, buildNamespacedNativeEnums as t };
|
|
68
77
|
|
|
69
|
-
//# sourceMappingURL=postgres-static-
|
|
78
|
+
//# sourceMappingURL=postgres-static-ytFKA5eZ-DBqSRBpN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-static-ytFKA5eZ-DBqSRBpN.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-static-ytFKA5eZ.mjs"],"sourcesContent":["import { n as validatePostgresContract } from \"./contract-from-json--c1yeq8I.mjs\";\nimport { PG_ENUM_CODEC_ID } from \"@internal/target-postgres/codec-ids\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { buildNamespacedEnums, createEnumAccessor } from \"@internal/contract/enum-accessor\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport { createExecutionContext, createSqlExecutionStack } from \"@internal/sql-runtime\";\nimport postgresTarget from \"@internal/target-postgres/runtime\";\nimport { createRawLane, sql } from \"@internal/sql-builder/runtime\";\n//#region src/runtime/native-enums.ts\n/**\n* The accessors for one namespace's value sets, leaving out each value set whose name is a domain enum's in the same namespace: a domain enum's value set takes its enum's name and namespace, and `db.enums` holds that enum. The rest are native enum types, because `native_enum` is the only pack entity that derives a value set today. Reads plain contract data, so a `validateContract`'d JSON contract works as well as a hydrated one. A member is a value, as in `CREATE TYPE … AS ENUM ('a', 'b')`, so each value is also its own name.\n*/\nfunction buildNativeEnumsMapForNamespace(storage, domain, namespaceId) {\n\tconst result = {};\n\tconst valueSets = storage.namespaces[namespaceId]?.entries.valueSet;\n\tif (!valueSets) return result;\n\tconst domainEnums = domain.namespaces[namespaceId]?.enum ?? {};\n\tfor (const [name, valueSet] of Object.entries(valueSets)) {\n\t\tif (Object.hasOwn(domainEnums, name)) continue;\n\t\tresult[name] = createEnumAccessor({\n\t\t\tcodecId: PG_ENUM_CODEC_ID,\n\t\t\tmembers: valueSet.values.map((value) => ({\n\t\t\t\tname: String(value),\n\t\t\t\tvalue\n\t\t\t}))\n\t\t});\n\t}\n\treturn result;\n}\nfunction buildNamespacedNativeEnums(storage, domain) {\n\tconst result = {};\n\tfor (const namespaceId of Object.keys(storage.namespaces)) result[namespaceId] = buildNativeEnumsMapForNamespace(storage, domain, namespaceId);\n\treturn result;\n}\n//#endregion\n//#region src/static/postgres-static.ts\nfunction buildPostgresStaticContext(contract, context, rawCodecInferer) {\n\tconst sqlDb = sql({\n\t\tcontext,\n\t\trawCodecInferer\n\t});\n\tconst raw = createRawLane({\n\t\tcontext,\n\t\trawCodecInferer\n\t});\n\treturn {\n\t\tcontext,\n\t\tcontract,\n\t\tenums: Object.freeze(buildNamespacedEnums(context.contract.domain, (codecId) => context.contractCodecs.forCodecRef({ codecId }))),\n\t\tnativeEnums: blindCast(Object.freeze(buildNamespacedNativeEnums(context.contract.storage, context.contract.domain))),\n\t\tsql: sqlDb,\n\t\traw\n\t};\n}\n/**\n* The query surfaces of a Postgres client without a driver: `sql`, `raw`, `enums` and\n* `nativeEnums`. Use it where loading `pg` is not wanted, for example in browser code that reads\n* enums.\n*\n* @example\n* ```ts\n* const { enums } = postgresStatic({ contract: contractFromJson<Contract>(contractJson) });\n* ```\n*/\nfunction postgresStatic(options) {\n\tconst contract = validatePostgresContract(options.contract);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\textensions: options.extensions ?? []\n\t});\n\treturn buildPostgresStaticContext(contract, createExecutionContext({\n\t\tcontract,\n\t\tstack\n\t}), stack.adapter.rawCodecInferer);\n}\n//#endregion\nexport { postgresStatic as n, buildNamespacedNativeEnums as r, buildPostgresStaticContext as t };\n\n//# sourceMappingURL=postgres-static-ytFKA5eZ.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,SAAS,gCAAgC,SAAS,QAAQ,aAAa;CACtE,MAAM,SAAS,CAAC;CAChB,MAAM,YAAY,QAAQ,WAAW,YAAY,EAAE,QAAQ;CAC3D,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,cAAc,OAAO,WAAW,YAAY,EAAE,QAAQ,CAAC;CAC7D,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,GAAG;EACzD,IAAI,OAAO,OAAO,aAAa,IAAI,GAAG;EACtC,OAAO,QAAQ,mBAAmB;GACjC,SAAS;GACT,SAAS,SAAS,OAAO,KAAK,WAAW;IACxC,MAAM,OAAO,KAAK;IAClB;GACD,EAAE;EACH,CAAC;CACF;CACA,OAAO;AACR;AACA,SAAS,2BAA2B,SAAS,QAAQ;CACpD,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,eAAe,OAAO,KAAK,QAAQ,UAAU,GAAG,OAAO,eAAe,gCAAgC,SAAS,QAAQ,WAAW;CAC7I,OAAO;AACR;AAGA,SAAS,2BAA2B,UAAU,SAAS,iBAAiB;CACvE,MAAM,QAAQ,IAAI;EACjB;EACA;CACD,CAAC;CACD,MAAM,MAAM,cAAc;EACzB;EACA;CACD,CAAC;CACD,OAAO;EACN;EACA;EACA,OAAO,OAAO,OAAO,qBAAqB,QAAQ,SAAS,SAAS,YAAY,QAAQ,eAAe,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;EAChI,aAAa,UAAU,OAAO,OAAO,2BAA2B,QAAQ,SAAS,SAAS,QAAQ,SAAS,MAAM,CAAC,CAAC;EACnH,KAAK;EACL;CACD;AACD;;;;;;;;;;;AAWA,SAAS,eAAe,SAAS;CAChC,MAAM,WAAW,yBAAyB,QAAQ,QAAQ;CAC1D,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,OAAO,2BAA2B,UAAU,uBAAuB;EAClE;EACA;CACD,CAAC,GAAG,MAAM,QAAQ,eAAe;AAClC"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as buildNamespacedNativeEnums, t as NamespacedNativeEnums } from "./postgres-static-
|
|
2
|
-
import { a as PostgresStaticMembers, i as PostgresRuntimeBoundMembers, n as PostgresExecutionOptions, r as PostgresLifecycleMembers, t as PostgresCursorOptions } from "./postgres-options-
|
|
1
|
+
import { i as buildNamespacedNativeEnums, t as NamespacedNativeEnums } from "./postgres-static-CWKc2Lc4-vwO-rlxR.mjs";
|
|
2
|
+
import { a as PostgresStaticMembers, i as PostgresRuntimeBoundMembers, n as PostgresExecutionOptions, r as PostgresLifecycleMembers, t as PostgresCursorOptions } from "./postgres-options-C6x1ZHJX-DxeRq4pl.mjs";
|
|
3
3
|
import { Runtime, SqlRuntimeBase } from "@prisma/orm-family-sql/runtime";
|
|
4
4
|
import { Client, Pool } from "pg";
|
|
5
5
|
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
@@ -48,25 +48,27 @@ interface PostgresBindingOptions {
|
|
|
48
48
|
readonly url?: string;
|
|
49
49
|
readonly pg?: Pool | Client;
|
|
50
50
|
}
|
|
51
|
-
type
|
|
51
|
+
type PostgresOptions<TContract extends Contract<SqlStorage>> = PostgresBindingOptions & PostgresOptionsBase & {
|
|
52
52
|
readonly contract: TContract;
|
|
53
|
-
readonly contractJson?: never;
|
|
54
53
|
};
|
|
55
|
-
type PostgresOptionsWithContractJson<TContract extends Contract<SqlStorage>> = PostgresBindingOptions & PostgresOptionsBase & {
|
|
56
|
-
readonly contractJson: unknown;
|
|
57
|
-
readonly contract?: never;
|
|
58
|
-
readonly _contract?: TContract;
|
|
59
|
-
};
|
|
60
|
-
type PostgresOptions<TContract extends Contract<SqlStorage>> = PostgresOptionsWithContract<TContract> | PostgresOptionsWithContractJson<TContract>;
|
|
61
54
|
/**
|
|
62
|
-
* Creates a lazy Postgres client
|
|
63
|
-
*
|
|
55
|
+
* Creates a lazy Postgres client. The client infers its contract type from `contract`: a value from
|
|
56
|
+
* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is
|
|
57
|
+
* validated once, however many clients are built from it. The static query surfaces are available
|
|
58
|
+
* at once; the pool is created on the first query or `connect()`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { contractFromJson } from '@prisma/orm-postgres/static';
|
|
63
|
+
* import postgres from '@prisma/orm-postgres/runtime';
|
|
64
|
+
* import type { Contract } from './contract.d';
|
|
65
|
+
* import contractJson from './contract.json' with { type: 'json' };
|
|
64
66
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
+
* export const contract = contractFromJson<Contract>(contractJson);
|
|
68
|
+
* export const db = postgres({ contract, url: process.env['DATABASE_URL']! });
|
|
69
|
+
* ```
|
|
67
70
|
*/
|
|
68
|
-
declare function postgres<TContract extends Contract<SqlStorage>>(options:
|
|
69
|
-
declare function postgres<TContract extends Contract<SqlStorage>>(options: PostgresOptionsWithContractJson<TContract>): PostgresClient<TContract>;
|
|
71
|
+
declare function postgres<TContract extends Contract<SqlStorage>>(options: PostgresOptions<TContract>): PostgresClient<TContract>;
|
|
70
72
|
//#endregion
|
|
71
73
|
//#region src/runtime/postgres-runtime.d.ts
|
|
72
74
|
/**
|
|
@@ -82,5 +84,5 @@ declare class PostgresRuntimeImpl<TContract extends Contract<SqlStorage> = Contr
|
|
|
82
84
|
protected getListDecoder(): PostgresListDecoder;
|
|
83
85
|
}
|
|
84
86
|
//#endregion
|
|
85
|
-
export { type NamespacedNativeEnums, type PostgresBinding, type PostgresClient, type PostgresCursorOptions, type PostgresFullTextMethods, type PostgresOptions, type PostgresOptionsBase, type
|
|
87
|
+
export { type NamespacedNativeEnums, type PostgresBinding, type PostgresClient, type PostgresCursorOptions, type PostgresFullTextMethods, type PostgresOptions, type PostgresOptionsBase, type PostgresRuntime, PostgresRuntimeImpl, buildNamespacedNativeEnums, postgres as default, isPgClient, isPgPool };
|
|
86
88
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/runtime.d.mts"],"mappings":";;;;;;;;;cAQc,WAAW,IAAI,OAAO,WAAW,MAAM;cACvC,aAAa,IAAI,OAAO,WAAW,MAAM;KAClD;WACM;WACA;;WAEA;WACA,MAAM;;WAEN;WACA,QAAQ;;KAEd;WACM,SAAS;WACT;WACA;;WAEA;WACA;WACA;;WAEA,IAAI,OAAO;WACX;WACA;;;;UAID,eAAe,kBAAkB,SAAS,qBAAqB,sBAAsB,YAAY,4BAA4B,YAAY;EACjJ,QAAQ,eAAe,uBAAuB,QAAQ;;UAE9C,4BAA4B;WAC3B;aACE;aACA;;;UAGH;WACC,UAAU;WACV;WACA,KAAK,OAAO;;KAElB,
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/runtime.d.mts"],"mappings":";;;;;;;;;cAQc,WAAW,IAAI,OAAO,WAAW,MAAM;cACvC,aAAa,IAAI,OAAO,WAAW,MAAM;KAClD;WACM;WACA;;WAEA;WACA,MAAM;;WAEN;WACA,QAAQ;;KAEd;WACM,SAAS;WACT;WACA;;WAEA;WACA;WACA;;WAEA,IAAI,OAAO;WACX;WACA;;;;UAID,eAAe,kBAAkB,SAAS,qBAAqB,sBAAsB,YAAY,4BAA4B,YAAY;EACjJ,QAAQ,eAAe,uBAAuB,QAAQ;;UAE9C,4BAA4B;WAC3B;aACE;aACA;;;UAGH;WACC,UAAU;WACV;WACA,KAAK,OAAO;;KAElB,gBAAgB,kBAAkB,SAAS,eAAe,yBAAyB;WAC7E,UAAU;;;;;;;;;;;;;;;;;;;iBAmBJ,SAAS,kBAAkB,SAAS,aAAa,SAAS,gBAAgB,aAAa,eAAe;;;;;;;;;;UAU7G,wBAAwB;KAC7B,uBAAuB,oBAAoB,gBAAgB,mBAAmB,qBAAqB;cAC1F,oBAAoB,kBAAkB,SAAS,cAAc,SAAS,qBAAqB,eAAe;YAC5G,kBAAkB"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CYOOg0sB.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
2
|
+
import { n as validatePostgresContract } from "./contract-from-json--c1yeq8I-CgRc9Lrx.mjs";
|
|
3
|
+
import { a as isPgPool, c as toDriverCursorOptions, i as isPgClient, l as toRuntimeOptions, n as PostgresRuntimeImpl, o as resolveOptionalPostgresBinding, r as buildPostgresRuntimeBoundMembers, s as resolvePostgresBinding, u as validateCursorOptions } from "./postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs";
|
|
4
|
+
import { n as buildPostgresStaticContext, t as buildNamespacedNativeEnums } from "./postgres-static-ytFKA5eZ-DBqSRBpN.mjs";
|
|
4
5
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
5
|
-
import
|
|
6
|
+
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
6
7
|
import { createExecutionContext, createSqlExecutionStack } from "@prisma/orm-family-sql/runtime";
|
|
7
|
-
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
8
8
|
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
9
9
|
import postgresDriver, { suppressIdleConnectionErrors } from "@prisma/orm-target-postgres/driver/runtime";
|
|
10
10
|
import { instantiateExecutionStack } from "@prisma/orm-framework/components/execution";
|
|
11
11
|
import { Pool } from "pg";
|
|
12
12
|
//#region ../../../3-extensions/postgres/dist/runtime.mjs
|
|
13
|
-
function hasContractJson(options) {
|
|
14
|
-
return "contractJson" in options;
|
|
15
|
-
}
|
|
16
|
-
const contractSerializer = new PostgresContractSerializer();
|
|
17
|
-
function resolveContract(options) {
|
|
18
|
-
const contractJson = hasContractJson(options) ? options.contractJson : contractSerializer.serializeContract(options.contract);
|
|
19
|
-
return blindCast(contractSerializer.deserializeContract(contractJson));
|
|
20
|
-
}
|
|
21
13
|
function toRuntimeBinding(binding, options) {
|
|
22
14
|
if (binding.kind !== "url") return binding;
|
|
23
15
|
return {
|
|
@@ -29,9 +21,26 @@ function toRuntimeBinding(binding, options) {
|
|
|
29
21
|
}))
|
|
30
22
|
};
|
|
31
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a lazy Postgres client. The client infers its contract type from `contract`: a value from
|
|
26
|
+
* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is
|
|
27
|
+
* validated once, however many clients are built from it. The static query surfaces are available
|
|
28
|
+
* at once; the pool is created on the first query or `connect()`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { contractFromJson } from '@prisma/orm-postgres/static';
|
|
33
|
+
* import postgres from '@prisma/orm-postgres/runtime';
|
|
34
|
+
* import type { Contract } from './contract.d';
|
|
35
|
+
* import contractJson from './contract.json' with { type: 'json' };
|
|
36
|
+
*
|
|
37
|
+
* export const contract = contractFromJson<Contract>(contractJson);
|
|
38
|
+
* export const db = postgres({ contract, url: process.env['DATABASE_URL']! });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
32
41
|
function postgres(options) {
|
|
33
42
|
const cursor = validateCursorOptions(options.cursor, "postgres");
|
|
34
|
-
const contract =
|
|
43
|
+
const contract = validatePostgresContract(options.contract);
|
|
35
44
|
let binding = resolveOptionalPostgresBinding(options);
|
|
36
45
|
const stack = createSqlExecutionStack({
|
|
37
46
|
target: postgresTarget,
|
|
@@ -44,7 +53,7 @@ function postgres(options) {
|
|
|
44
53
|
stack,
|
|
45
54
|
driver: postgresDriver
|
|
46
55
|
});
|
|
47
|
-
const { sql, raw: rawSqlTag, enums, nativeEnums } = buildPostgresStaticContext(context, stack.adapter.rawCodecInferer);
|
|
56
|
+
const { sql, raw: rawSqlTag, enums, nativeEnums } = buildPostgresStaticContext(contract, context, stack.adapter.rawCodecInferer);
|
|
48
57
|
let runtimeInstance;
|
|
49
58
|
let runtimeDriver;
|
|
50
59
|
let driverConnected = false;
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/runtime.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { a as validateCursorOptions, c as isPgPool, i as toRuntimeOptions, l as resolveOptionalPostgresBinding, o as buildPostgresRuntimeBoundMembers, r as toDriverCursorOptions, s as isPgClient, t as PostgresRuntimeImpl, u as resolvePostgresBinding } from \"./postgres-runtime-BlCLYNDD.mjs\";\nimport { r as buildNamespacedNativeEnums, t as buildPostgresStaticContext } from \"./postgres-static-
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/runtime.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { a as validateCursorOptions, c as isPgPool, i as toRuntimeOptions, l as resolveOptionalPostgresBinding, o as buildPostgresRuntimeBoundMembers, r as toDriverCursorOptions, s as isPgClient, t as PostgresRuntimeImpl, u as resolvePostgresBinding } from \"./postgres-runtime-BlCLYNDD.mjs\";\nimport { r as buildNamespacedNativeEnums, t as buildPostgresStaticContext } from \"./postgres-static-ytFKA5eZ.mjs\";\nimport { n as validatePostgresContract } from \"./contract-from-json--c1yeq8I.mjs\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport postgresDriver, { suppressIdleConnectionErrors } from \"@internal/driver-postgres/runtime\";\nimport { instantiateExecutionStack } from \"@internal/framework-components/execution\";\nimport { createExecutionContext, createSqlExecutionStack } from \"@internal/sql-runtime\";\nimport postgresTarget from \"@internal/target-postgres/runtime\";\nimport { Pool } from \"pg\";\n//#region src/runtime/postgres.ts\nfunction toRuntimeBinding(binding, options) {\n\tif (binding.kind !== \"url\") return binding;\n\treturn {\n\t\tkind: \"pgPool\",\n\t\tpool: suppressIdleConnectionErrors(new Pool({\n\t\t\tconnectionString: binding.url,\n\t\t\tconnectionTimeoutMillis: options.poolOptions?.connectionTimeoutMillis ?? 2e4,\n\t\t\tidleTimeoutMillis: options.poolOptions?.idleTimeoutMillis ?? 3e4\n\t\t}))\n\t};\n}\n/**\n* Creates a lazy Postgres client. The client infers its contract type from `contract`: a value from\n* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is\n* validated once, however many clients are built from it. The static query surfaces are available\n* at once; the pool is created on the first query or `connect()`.\n*\n* @example\n* ```ts\n* import { contractFromJson } from '@prisma/orm-postgres/static';\n* import postgres from '@prisma/orm-postgres/runtime';\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* export const db = postgres({ contract, url: process.env['DATABASE_URL']! });\n* ```\n*/\nfunction postgres(options) {\n\tconst cursor = validateCursorOptions(options.cursor, \"postgres\");\n\tconst contract = validatePostgresContract(options.contract);\n\tlet binding = resolveOptionalPostgresBinding(options);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\tdriver: postgresDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst context = createExecutionContext({\n\t\tcontract,\n\t\tstack,\n\t\tdriver: postgresDriver\n\t});\n\tconst { sql, raw: rawSqlTag, enums, nativeEnums } = buildPostgresStaticContext(contract, context, stack.adapter.rawCodecInferer);\n\tlet runtimeInstance;\n\tlet runtimeDriver;\n\tlet driverConnected = false;\n\tlet connectPromise;\n\tlet backgroundConnectError;\n\tlet closePromise;\n\tlet ownsPool = false;\n\tconst connectDriver = async (resolvedBinding) => {\n\t\tif (driverConnected) return;\n\t\tif (!runtimeDriver) throw new InternalError(\"Postgres runtime driver missing\");\n\t\tif (connectPromise) return connectPromise;\n\t\tconst runtimeBinding = toRuntimeBinding(resolvedBinding, options);\n\t\tconst ownedPool = resolvedBinding.kind === \"url\" && runtimeBinding.kind === \"pgPool\" ? runtimeBinding.pool : void 0;\n\t\tconnectPromise = runtimeDriver.connect(runtimeBinding).then(() => {\n\t\t\tdriverConnected = true;\n\t\t\townsPool = ownedPool !== void 0;\n\t\t}).catch(async (err) => {\n\t\t\tbackgroundConnectError = err;\n\t\t\tconnectPromise = void 0;\n\t\t\tawait ownedPool?.end().catch(() => void 0);\n\t\t\tthrow err;\n\t\t});\n\t\treturn connectPromise;\n\t};\n\tconst getRuntime = () => {\n\t\tif (closePromise !== void 0) throw postgresError(\"DRIVER.NOT_CONNECTED\", \"Postgres client is closed\", {\n\t\t\twhy: \"close() was called on this client.\",\n\t\t\tfix: \"Create a new postgres(...) client.\",\n\t\t\tmeta: { extension: \"postgres\" }\n\t\t});\n\t\tif (backgroundConnectError !== void 0) throw backgroundConnectError;\n\t\tif (runtimeInstance) return runtimeInstance;\n\t\tconst stackInstance = instantiateExecutionStack(stack);\n\t\tconst driverDescriptor = stack.driver;\n\t\tif (!driverDescriptor) throw new InternalError(\"Driver descriptor missing from execution stack\");\n\t\tconst driver = driverDescriptor.create({ cursor: toDriverCursorOptions(cursor) });\n\t\truntimeDriver = driver;\n\t\tconst runtime = new PostgresRuntimeImpl({\n\t\t\tcontext,\n\t\t\tadapter: stackInstance.adapter,\n\t\t\tdriver,\n\t\t\t...toRuntimeOptions(options),\n\t\t\tcloseRefusal: \"at-once\"\n\t\t});\n\t\truntimeInstance = runtime;\n\t\tif (binding !== void 0) connectDriver(binding).catch(() => void 0);\n\t\treturn runtime;\n\t};\n\tconst closeOwnedRuntime = async () => {\n\t\tif (!driverConnected) await connectPromise?.catch(() => void 0);\n\t\tif (ownsPool) await runtimeInstance?.close();\n\t};\n\treturn {\n\t\tsql,\n\t\t...buildPostgresRuntimeBoundMembers({\n\t\t\tcontext,\n\t\t\trawCodecInferer: stack.adapter.rawCodecInferer,\n\t\t\tenums,\n\t\t\tnativeEnums,\n\t\t\tgetRuntime,\n\t\t\tgetRuntimeForWork: getRuntime\n\t\t}),\n\t\tenums,\n\t\tnativeEnums,\n\t\traw: rawSqlTag,\n\t\tcontext,\n\t\tcontract,\n\t\tstack,\n\t\tasync connect(bindingInput) {\n\t\t\tif (closePromise !== void 0) throw postgresError(\"DRIVER.NOT_CONNECTED\", \"Postgres client is closed\", {\n\t\t\t\twhy: \"close() was called on this client.\",\n\t\t\t\tfix: \"Create a new postgres(...) client.\",\n\t\t\t\tmeta: { extension: \"postgres\" }\n\t\t\t});\n\t\t\tif (driverConnected || connectPromise) throw postgresError(\"DRIVER.ALREADY_CONNECTED\", \"Postgres client already connected\", {\n\t\t\t\tfix: \"Call connect() at most once per client.\",\n\t\t\t\tmeta: { extension: \"postgres\" }\n\t\t\t});\n\t\t\tif (bindingInput !== void 0) binding = resolvePostgresBinding(bindingInput);\n\t\t\tif (binding === void 0) throw postgresError(\"RUNTIME.BINDING_MISSING\", \"Postgres binding not configured. Pass url/pg/binding to postgres(...) or call db.connect({ ... }).\", { meta: { extension: \"postgres\" } });\n\t\t\tconst runtime = getRuntime();\n\t\t\tif (driverConnected) return runtime;\n\t\t\tawait connectDriver(binding);\n\t\t\treturn runtime;\n\t\t},\n\t\tclose() {\n\t\t\tclosePromise ??= closeOwnedRuntime();\n\t\t\treturn closePromise;\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn this.close();\n\t\t}\n\t};\n}\n//#endregion\nexport { PostgresRuntimeImpl, buildNamespacedNativeEnums, postgres as default, isPgClient, isPgPool };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":"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"}
|
package/dist/serverless.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as PostgresStaticMembers, i as PostgresRuntimeBoundMembers, n as PostgresExecutionOptions, r as PostgresLifecycleMembers, t as PostgresCursorOptions } from "./postgres-options-
|
|
1
|
+
import { a as PostgresStaticMembers, i as PostgresRuntimeBoundMembers, n as PostgresExecutionOptions, r as PostgresLifecycleMembers, t as PostgresCursorOptions } from "./postgres-options-C6x1ZHJX-DxeRq4pl.mjs";
|
|
2
2
|
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
3
3
|
import { SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
4
4
|
import { PostgresFullTextMethods } from "@prisma/orm-target-postgres/target/full-text";
|
|
@@ -11,16 +11,9 @@ interface PostgresServerlessClient<TContract extends Contract<SqlStorage>> exten
|
|
|
11
11
|
}): Promise<PostgresServerlessConnection<TContract>>;
|
|
12
12
|
}
|
|
13
13
|
interface PostgresServerlessOptionsBase extends PostgresExecutionOptions {}
|
|
14
|
-
type
|
|
14
|
+
type PostgresServerlessOptions<TContract extends Contract<SqlStorage>> = PostgresServerlessOptionsBase & {
|
|
15
15
|
readonly contract: TContract;
|
|
16
|
-
readonly contractJson?: never;
|
|
17
16
|
};
|
|
18
|
-
type PostgresServerlessOptionsWithContractJson<TContract extends Contract<SqlStorage>> = PostgresServerlessOptionsBase & {
|
|
19
|
-
readonly contractJson: unknown;
|
|
20
|
-
readonly contract?: never;
|
|
21
|
-
readonly _contract?: TContract;
|
|
22
|
-
};
|
|
23
|
-
type PostgresServerlessOptions<TContract extends Contract<SqlStorage>> = PostgresServerlessOptionsWithContract<TContract> | PostgresServerlessOptionsWithContractJson<TContract>;
|
|
24
17
|
/**
|
|
25
18
|
* Creates a serverless client for serverless and edge runtimes (Cloudflare Workers + Hyperdrive,
|
|
26
19
|
* AWS Lambda, Vercel, Deno Deploy).
|
|
@@ -31,9 +24,12 @@ type PostgresServerlessOptions<TContract extends Contract<SqlStorage>> = Postgre
|
|
|
31
24
|
* `DRIVER.CONNECTION_FAILED` when the database refuses the connection, rejects the credentials,
|
|
32
25
|
* or does not answer within 20 seconds. Close the connection with `await using` or `close()`.
|
|
33
26
|
*
|
|
27
|
+
* The client infers its contract type from `contract` and validates it once, when the client is
|
|
28
|
+
* created; connections reuse it.
|
|
29
|
+
*
|
|
34
30
|
* @example
|
|
35
31
|
* ```ts
|
|
36
|
-
* const postgres = postgresServerless<Contract>(
|
|
32
|
+
* const postgres = postgresServerless({ contract: contractFromJson<Contract>(contractJson) });
|
|
37
33
|
*
|
|
38
34
|
* export default {
|
|
39
35
|
* async fetch(_req: Request, env: Env): Promise<Response> {
|
|
@@ -44,8 +40,7 @@ type PostgresServerlessOptions<TContract extends Contract<SqlStorage>> = Postgre
|
|
|
44
40
|
* };
|
|
45
41
|
* ```
|
|
46
42
|
*/
|
|
47
|
-
declare function postgresServerless<TContract extends Contract<SqlStorage>>(options:
|
|
48
|
-
declare function postgresServerless<TContract extends Contract<SqlStorage>>(options: PostgresServerlessOptionsWithContractJson<TContract>): PostgresServerlessClient<TContract>;
|
|
43
|
+
declare function postgresServerless<TContract extends Contract<SqlStorage>>(options: PostgresServerlessOptions<TContract>): PostgresServerlessClient<TContract>;
|
|
49
44
|
//#endregion
|
|
50
|
-
export { type PostgresCursorOptions, type PostgresFullTextMethods, type PostgresServerlessClient, type PostgresServerlessConnection, type PostgresServerlessOptions, type PostgresServerlessOptionsBase,
|
|
45
|
+
export { type PostgresCursorOptions, type PostgresFullTextMethods, type PostgresServerlessClient, type PostgresServerlessConnection, type PostgresServerlessOptions, type PostgresServerlessOptionsBase, postgresServerless as default };
|
|
51
46
|
//# sourceMappingURL=serverless.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverless.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/serverless.d.mts"],"mappings":";;;;;;UAKU,6BAA6B,kBAAkB,SAAS,qBAAqB,sBAAsB,YAAY,4BAA4B,YAAY;UACvJ,yBAAyB,kBAAkB,SAAS,qBAAqB,sBAAsB;EACvG,QAAQ;aACG;MACP,QAAQ,6BAA6B;;UAEjC,sCAAsC;KAC3C,
|
|
1
|
+
{"version":3,"file":"serverless.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/serverless.d.mts"],"mappings":";;;;;;UAKU,6BAA6B,kBAAkB,SAAS,qBAAqB,sBAAsB,YAAY,4BAA4B,YAAY;UACvJ,yBAAyB,kBAAkB,SAAS,qBAAqB,sBAAsB;EACvG,QAAQ;aACG;MACP,QAAQ,6BAA6B;;UAEjC,sCAAsC;KAC3C,0BAA0B,kBAAkB,SAAS,eAAe;WAC9D,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BJ,mBAAmB,kBAAkB,SAAS,aAAa,SAAS,0BAA0B,aAAa,yBAAyB"}
|
package/dist/serverless.mjs
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CYOOg0sB.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
2
|
+
import { n as validatePostgresContract } from "./contract-from-json--c1yeq8I-CgRc9Lrx.mjs";
|
|
3
|
+
import { c as toDriverCursorOptions, d as validatePostgresUrl, l as toRuntimeOptions, n as PostgresRuntimeImpl, r as buildPostgresRuntimeBoundMembers, t as DEFAULT_CONNECT_TIMEOUT_MILLIS, u as validateCursorOptions } from "./postgres-runtime-BlCLYNDD-Tv3dpPe7.mjs";
|
|
4
|
+
import { n as buildPostgresStaticContext } from "./postgres-static-ytFKA5eZ-DBqSRBpN.mjs";
|
|
4
5
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
5
|
-
import
|
|
6
|
+
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
6
7
|
import { createExecutionContext, createSqlExecutionStack } from "@prisma/orm-family-sql/runtime";
|
|
7
|
-
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
8
8
|
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
9
9
|
import postgresDriver, { suppressIdleConnectionErrors } from "@prisma/orm-target-postgres/driver/runtime";
|
|
10
10
|
import { instantiateExecutionStack } from "@prisma/orm-framework/components/execution";
|
|
11
11
|
import { Client } from "pg";
|
|
12
12
|
import { redactDatabaseUrl } from "@prisma/orm-framework/utils/redact-db-url";
|
|
13
13
|
//#region ../../../3-extensions/postgres/dist/serverless.mjs
|
|
14
|
-
function hasContractJson(options) {
|
|
15
|
-
return "contractJson" in options;
|
|
16
|
-
}
|
|
17
|
-
const contractSerializer = new PostgresContractSerializer();
|
|
18
|
-
function resolveContract(options) {
|
|
19
|
-
const contractJson = hasContractJson(options) ? options.contractJson : contractSerializer.serializeContract(options.contract);
|
|
20
|
-
return blindCast(contractSerializer.deserializeContract(contractJson));
|
|
21
|
-
}
|
|
22
14
|
function closedConnectionError() {
|
|
23
15
|
return postgresError("DRIVER.NOT_CONNECTED", "Postgres connection is closed", {
|
|
24
16
|
why: "close() was called on this connection, or the await using scope that held it has ended.",
|
|
@@ -37,9 +29,35 @@ function connectionFailedError(url, cause) {
|
|
|
37
29
|
cause
|
|
38
30
|
});
|
|
39
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a serverless client for serverless and edge runtimes (Cloudflare Workers + Hyperdrive,
|
|
34
|
+
* AWS Lambda, Vercel, Deno Deploy).
|
|
35
|
+
*
|
|
36
|
+
* The serverless client holds no database connection and has the static members. Each
|
|
37
|
+
* `connect({ url })` opens one database connection, a fresh `pg.Client`, and returns a connection
|
|
38
|
+
* with the members of a `postgres()` client except `connect`. It rejects with
|
|
39
|
+
* `DRIVER.CONNECTION_FAILED` when the database refuses the connection, rejects the credentials,
|
|
40
|
+
* or does not answer within 20 seconds. Close the connection with `await using` or `close()`.
|
|
41
|
+
*
|
|
42
|
+
* The client infers its contract type from `contract` and validates it once, when the client is
|
|
43
|
+
* created; connections reuse it.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const postgres = postgresServerless({ contract: contractFromJson<Contract>(contractJson) });
|
|
48
|
+
*
|
|
49
|
+
* export default {
|
|
50
|
+
* async fetch(_req: Request, env: Env): Promise<Response> {
|
|
51
|
+
* await using db = await postgres.connect({ url: env.HYPERDRIVE.connectionString });
|
|
52
|
+
* const users = await db.orm.public.User.all();
|
|
53
|
+
* return Response.json(users);
|
|
54
|
+
* },
|
|
55
|
+
* };
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
40
58
|
function postgresServerless(options) {
|
|
41
59
|
const cursor = validateCursorOptions(options.cursor, "postgresServerless");
|
|
42
|
-
const contract =
|
|
60
|
+
const contract = validatePostgresContract(options.contract);
|
|
43
61
|
const stack = createSqlExecutionStack({
|
|
44
62
|
target: postgresTarget,
|
|
45
63
|
adapter: postgresAdapter,
|
|
@@ -52,7 +70,7 @@ function postgresServerless(options) {
|
|
|
52
70
|
driver: postgresDriver
|
|
53
71
|
});
|
|
54
72
|
const rawCodecInferer = stack.adapter.rawCodecInferer;
|
|
55
|
-
const { sql, raw, enums, nativeEnums } = buildPostgresStaticContext(context, rawCodecInferer);
|
|
73
|
+
const { sql, raw, enums, nativeEnums } = buildPostgresStaticContext(contract, context, rawCodecInferer);
|
|
56
74
|
const buildRuntimeBoundMembers = (getRuntime, getRuntimeForWork) => buildPostgresRuntimeBoundMembers({
|
|
57
75
|
context,
|
|
58
76
|
rawCodecInferer,
|
package/dist/serverless.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverless.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/serverless.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { a as validateCursorOptions, d as validatePostgresUrl, i as toRuntimeOptions, n as DEFAULT_CONNECT_TIMEOUT_MILLIS, o as buildPostgresRuntimeBoundMembers, r as toDriverCursorOptions, t as PostgresRuntimeImpl } from \"./postgres-runtime-BlCLYNDD.mjs\";\nimport { t as buildPostgresStaticContext } from \"./postgres-static-
|
|
1
|
+
{"version":3,"file":"serverless.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/serverless.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { a as validateCursorOptions, d as validatePostgresUrl, i as toRuntimeOptions, n as DEFAULT_CONNECT_TIMEOUT_MILLIS, o as buildPostgresRuntimeBoundMembers, r as toDriverCursorOptions, t as PostgresRuntimeImpl } from \"./postgres-runtime-BlCLYNDD.mjs\";\nimport { t as buildPostgresStaticContext } from \"./postgres-static-ytFKA5eZ.mjs\";\nimport { n as validatePostgresContract } from \"./contract-from-json--c1yeq8I.mjs\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport postgresDriver, { suppressIdleConnectionErrors } from \"@internal/driver-postgres/runtime\";\nimport { instantiateExecutionStack } from \"@internal/framework-components/execution\";\nimport { createExecutionContext, createSqlExecutionStack } from \"@internal/sql-runtime\";\nimport postgresTarget from \"@internal/target-postgres/runtime\";\nimport { Client } from \"pg\";\nimport { redactDatabaseUrl } from \"@internal/utils/redact-db-url\";\n//#region src/runtime/postgres-serverless.ts\nfunction closedConnectionError() {\n\treturn postgresError(\"DRIVER.NOT_CONNECTED\", \"Postgres connection is closed\", {\n\t\twhy: \"close() was called on this connection, or the await using scope that held it has ended.\",\n\t\tfix: \"Call connect({ url }) again to open a new connection.\",\n\t\tmeta: { extension: \"postgres\" }\n\t});\n}\nfunction connectionFailedError(url, cause) {\n\treturn postgresError(\"DRIVER.CONNECTION_FAILED\", \"Database connection failed\", {\n\t\twhy: cause instanceof Error ? cause.message : String(cause),\n\t\tfix: \"Verify the database URL, ensure the database is reachable, and confirm credentials/permissions\",\n\t\tmeta: {\n\t\t\textension: \"postgres\",\n\t\t\t...redactDatabaseUrl(url)\n\t\t},\n\t\tcause\n\t});\n}\n/**\n* Creates a serverless client for serverless and edge runtimes (Cloudflare Workers + Hyperdrive,\n* AWS Lambda, Vercel, Deno Deploy).\n*\n* The serverless client holds no database connection and has the static members. Each\n* `connect({ url })` opens one database connection, a fresh `pg.Client`, and returns a connection\n* with the members of a `postgres()` client except `connect`. It rejects with\n* `DRIVER.CONNECTION_FAILED` when the database refuses the connection, rejects the credentials,\n* or does not answer within 20 seconds. Close the connection with `await using` or `close()`.\n*\n* The client infers its contract type from `contract` and validates it once, when the client is\n* created; connections reuse it.\n*\n* @example\n* ```ts\n* const postgres = postgresServerless({ contract: contractFromJson<Contract>(contractJson) });\n*\n* export default {\n* async fetch(_req: Request, env: Env): Promise<Response> {\n* await using db = await postgres.connect({ url: env.HYPERDRIVE.connectionString });\n* const users = await db.orm.public.User.all();\n* return Response.json(users);\n* },\n* };\n* ```\n*/\nfunction postgresServerless(options) {\n\tconst cursor = validateCursorOptions(options.cursor, \"postgresServerless\");\n\tconst contract = validatePostgresContract(options.contract);\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\tdriver: postgresDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst context = createExecutionContext({\n\t\tcontract,\n\t\tstack,\n\t\tdriver: postgresDriver\n\t});\n\tconst rawCodecInferer = stack.adapter.rawCodecInferer;\n\tconst { sql, raw, enums, nativeEnums } = buildPostgresStaticContext(contract, context, rawCodecInferer);\n\tconst buildRuntimeBoundMembers = (getRuntime, getRuntimeForWork) => buildPostgresRuntimeBoundMembers({\n\t\tcontext,\n\t\trawCodecInferer,\n\t\tenums,\n\t\tnativeEnums,\n\t\tgetRuntime,\n\t\tgetRuntimeForWork\n\t});\n\tconst noRuntime = () => {\n\t\tthrow new InternalError(\"The serverless client has no runtime\");\n\t};\n\tbuildRuntimeBoundMembers(noRuntime, noRuntime);\n\tconst createConnection = (runtime) => {\n\t\tlet closing;\n\t\tconst close = () => {\n\t\t\tclosing ??= runtime.close();\n\t\t\treturn closing;\n\t\t};\n\t\tconst runtimeBoundMembers = buildRuntimeBoundMembers(() => {\n\t\t\tif (closing !== void 0) throw closedConnectionError();\n\t\t\treturn runtime;\n\t\t}, () => runtime);\n\t\treturn {\n\t\t\tsql,\n\t\t\traw,\n\t\t\tenums,\n\t\t\tnativeEnums,\n\t\t\tcontext,\n\t\t\tcontract,\n\t\t\tstack,\n\t\t\t...runtimeBoundMembers,\n\t\t\tclose,\n\t\t\t[Symbol.asyncDispose]: close\n\t\t};\n\t};\n\treturn {\n\t\tsql,\n\t\traw,\n\t\tenums,\n\t\tnativeEnums,\n\t\tcontext,\n\t\tstack,\n\t\tcontract,\n\t\tasync connect(binding) {\n\t\t\tconst url = validatePostgresUrl(binding.url);\n\t\t\tconst driverDescriptor = stack.driver;\n\t\t\tif (!driverDescriptor) throw new InternalError(\"Driver descriptor missing from execution stack\");\n\t\t\tconst stackInstance = instantiateExecutionStack(stack);\n\t\t\tconst driver = driverDescriptor.create({ cursor: toDriverCursorOptions(cursor) });\n\t\t\tconst pgClient = suppressIdleConnectionErrors(new Client({\n\t\t\t\tconnectionString: url,\n\t\t\t\tconnectionTimeoutMillis: DEFAULT_CONNECT_TIMEOUT_MILLIS\n\t\t\t}));\n\t\t\tawait driver.connect({\n\t\t\t\tkind: \"pgClient\",\n\t\t\t\tclient: pgClient\n\t\t\t});\n\t\t\tconst runtime = new PostgresRuntimeImpl({\n\t\t\t\tcontext,\n\t\t\t\tadapter: stackInstance.adapter,\n\t\t\t\tdriver,\n\t\t\t\t...toRuntimeOptions(options),\n\t\t\t\tcloseRefusal: \"when-idle\"\n\t\t\t});\n\t\t\tconst connection = createConnection(runtime);\n\t\t\ttry {\n\t\t\t\tawait (await driver.acquireConnection()).release();\n\t\t\t} catch (err) {\n\t\t\t\tpgClient.end().catch(() => void 0);\n\t\t\t\tthrow connectionFailedError(url, err);\n\t\t\t}\n\t\t\treturn connection;\n\t\t}\n\t};\n}\n//#endregion\nexport { postgresServerless as default };\n\n//# sourceMappingURL=serverless.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,wBAAwB;CAChC,OAAO,cAAc,wBAAwB,iCAAiC;EAC7E,KAAK;EACL,KAAK;EACL,MAAM,EAAE,WAAW,WAAW;CAC/B,CAAC;AACF;AACA,SAAS,sBAAsB,KAAK,OAAO;CAC1C,OAAO,cAAc,4BAA4B,8BAA8B;EAC9E,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAC1D,KAAK;EACL,MAAM;GACL,WAAW;GACX,GAAG,kBAAkB,GAAG;EACzB;EACA;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,mBAAmB,SAAS;CACpC,MAAM,SAAS,sBAAsB,QAAQ,QAAQ,oBAAoB;CACzE,MAAM,WAAW,yBAAyB,QAAQ,QAAQ;CAC1D,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,MAAM,UAAU,uBAAuB;EACtC;EACA;EACA,QAAQ;CACT,CAAC;CACD,MAAM,kBAAkB,MAAM,QAAQ;CACtC,MAAM,EAAE,KAAK,KAAK,OAAO,gBAAgB,2BAA2B,UAAU,SAAS,eAAe;CACtG,MAAM,4BAA4B,YAAY,sBAAsB,iCAAiC;EACpG;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CACD,MAAM,kBAAkB;EACvB,MAAM,IAAI,cAAc,sCAAsC;CAC/D;CACA,yBAAyB,WAAW,SAAS;CAC7C,MAAM,oBAAoB,YAAY;EACrC,IAAI;EACJ,MAAM,cAAc;GACnB,YAAY,QAAQ,MAAM;GAC1B,OAAO;EACR;EACA,MAAM,sBAAsB,+BAA+B;GAC1D,IAAI,YAAY,KAAK,GAAG,MAAM,sBAAsB;GACpD,OAAO;EACR,SAAS,OAAO;EAChB,OAAO;GACN;GACA;GACA;GACA;GACA;GACA;GACA;GACA,GAAG;GACH;IACC,OAAO,eAAe;EACxB;CACD;CACA,OAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM,QAAQ,SAAS;GACtB,MAAM,MAAM,oBAAoB,QAAQ,GAAG;GAC3C,MAAM,mBAAmB,MAAM;GAC/B,IAAI,CAAC,kBAAkB,MAAM,IAAI,cAAc,gDAAgD;GAC/F,MAAM,gBAAgB,0BAA0B,KAAK;GACrD,MAAM,SAAS,iBAAiB,OAAO,EAAE,QAAQ,sBAAsB,MAAM,EAAE,CAAC;GAChF,MAAM,WAAW,6BAA6B,IAAI,OAAO;IACxD,kBAAkB;IAClB,yBAAyB;GAC1B,CAAC,CAAC;GACF,MAAM,OAAO,QAAQ;IACpB,MAAM;IACN,QAAQ;GACT,CAAC;GACD,MAAM,UAAU,IAAI,oBAAoB;IACvC;IACA,SAAS,cAAc;IACvB;IACA,GAAG,iBAAiB,OAAO;IAC3B,cAAc;GACf,CAAC;GACD,MAAM,aAAa,iBAAiB,OAAO;GAC3C,IAAI;IACH,OAAO,MAAM,OAAO,kBAAkB,EAAA,CAAG,QAAQ;GAClD,SAAS,KAAK;IACb,SAAS,IAAI,CAAC,CAAC,YAAY,KAAK,CAAC;IACjC,MAAM,sBAAsB,KAAK,GAAG;GACrC;GACA,OAAO;EACR;CACD;AACD"}
|
package/dist/static.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { t as contractFromJson } from "./contract-from-json-ZRZt8Cse-BkZYEfDX.mjs";
|
|
2
|
+
import { a as postgresStatic, n as PostgresStaticContext } from "./postgres-static-CWKc2Lc4-vwO-rlxR.mjs";
|
|
3
|
+
export { type PostgresStaticContext, contractFromJson, postgresStatic as default };
|
package/dist/static.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { t as contractFromJson } from "./contract-from-json--c1yeq8I-CgRc9Lrx.mjs";
|
|
2
|
+
import { r as postgresStatic } from "./postgres-static-ytFKA5eZ-DBqSRBpN.mjs";
|
|
3
|
+
export { contractFromJson, postgresStatic as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-postgres",
|
|
3
|
-
"version": "8.0.0-rc.18-dev.
|
|
3
|
+
"version": "8.0.0-rc.18-dev.22",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"skills"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@prisma/orm-family-sql": "8.0.0-rc.18-dev.
|
|
14
|
-
"@prisma/orm-framework": "8.0.0-rc.18-dev.
|
|
15
|
-
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.
|
|
16
|
-
"@prisma/orm-toolchain": "8.0.0-rc.18-dev.
|
|
13
|
+
"@prisma/orm-family-sql": "8.0.0-rc.18-dev.22",
|
|
14
|
+
"@prisma/orm-framework": "8.0.0-rc.18-dev.22",
|
|
15
|
+
"@prisma/orm-target-postgres": "8.0.0-rc.18-dev.22",
|
|
16
|
+
"@prisma/orm-toolchain": "8.0.0-rc.18-dev.22",
|
|
17
17
|
"@types/node": "26.1.2",
|
|
18
18
|
"@types/pg": "8.20.4",
|
|
19
19
|
"arktype": "^2.2.2",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"tinyglobby": "^0.2.17"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@internal/postgres": "8.0.0-rc.18-dev.
|
|
26
|
-
"@repo/tsconfig": "8.0.0-rc.18-dev.
|
|
27
|
-
"@repo/tsdown": "8.0.0-rc.18-dev.
|
|
25
|
+
"@internal/postgres": "8.0.0-rc.18-dev.22",
|
|
26
|
+
"@repo/tsconfig": "8.0.0-rc.18-dev.22",
|
|
27
|
+
"@repo/tsdown": "8.0.0-rc.18-dev.22",
|
|
28
28
|
"tsdown": "0.22.14",
|
|
29
29
|
"typescript": "5.9.3"
|
|
30
30
|
},
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"./contract/resolve-domain-model": "./dist/contract__resolve-domain-model.mjs",
|
|
72
72
|
"./contract/types": "./dist/contract__types.mjs",
|
|
73
73
|
"./contract/validate-domain": "./dist/contract__validate-domain.mjs",
|
|
74
|
+
"./contract/validate-once": "./dist/contract__validate-once.mjs",
|
|
74
75
|
"./contract-builder": "./dist/contract-builder.mjs",
|
|
75
76
|
"./control": "./dist/control.mjs",
|
|
76
77
|
"./driver": "./dist/driver.mjs",
|
|
@@ -108,6 +109,7 @@
|
|
|
108
109
|
"./family-contract/value-set-derivation-hook": "./dist/family-contract__value-set-derivation-hook.mjs",
|
|
109
110
|
"./family-runtime": "./dist/family-runtime.mjs",
|
|
110
111
|
"./family-runtime/internal/prepared-query": "./dist/family-runtime__internal__prepared-query.mjs",
|
|
112
|
+
"./internal/validate-contract": "./dist/internal__validate-contract.mjs",
|
|
111
113
|
"./migration": "./dist/migration.mjs",
|
|
112
114
|
"./migration-tools/aggregate": "./dist/migration-tools__aggregate.mjs",
|
|
113
115
|
"./migration-tools/contract-snapshot-store": "./dist/migration-tools__contract-snapshot-store.mjs",
|
package/skills/prisma-8/SKILL.md
CHANGED
|
@@ -15,7 +15,7 @@ description: >-
|
|
|
15
15
|
ORM 7 or earlier (schema.prisma + @prisma/client).
|
|
16
16
|
metadata:
|
|
17
17
|
library: '@prisma/orm-postgres'
|
|
18
|
-
library_version: '8.0.0-rc.18-dev.
|
|
18
|
+
library_version: '8.0.0-rc.18-dev.22'
|
|
19
19
|
version: '2026-09-12'
|
|
20
20
|
---
|
|
21
21
|
|
|
@@ -63,7 +63,7 @@ Open the reference whose triggers match the task. If more than one matches, open
|
|
|
63
63
|
| Migration graph, refs, plan origin | [`references/migration-model.md`](references/migration-model.md) | migration graph, refs, `migration ref set` / `list` / `delete`, the `db` ref, `--advance-ref`, `--no-advance-ref`, `migration plan --from`, `from: (baseline)` in plan output, greenfield / from-scratch plan, baseline, first migration before deploy (Composer / CD-managed databases), chaining migrations, retrofitting migrations onto an existing database, `MIGRATION.HASH_NOT_IN_GRAPH`, `MIGRATION.PATH_UNREACHABLE` at plan/chain time |
|
|
64
64
|
| Review migrations on deploy | [`references/migration-review.md`](references/migration-review.md) | "what migrations are going to run", "what runs on deploy / merge", merge conflict, diamond convergence, concurrent migrations, migration status, ref management for CI, staging / production environment refs, `MIGRATION.MARKER_NOT_IN_HISTORY`, `MIGRATION.MISSING_INVARIANTS`, `db migrate --show` |
|
|
65
65
|
| Write queries | [`references/queries.md`](references/queries.md) | query, where, select, project, orderBy, limit, offset, take, skip, include, lookup, first, all, count, aggregate, groupBy, create, update, delete, upsert, returning, transaction, `db.orm`, `db.sql`, `runtime.query(plan)` vs `runtime.execute(plan)`, `db.prepare` / prepared statements, streaming / `for await`, many-to-many `include` and nested `connect`, `and` / `or` / `not` from `@prisma/orm-postgres/orm-client`, `db.query.from(...)` (Mongo pipeline), namespace-aware accessors, `.all()` Thenable, single-use iterators (`RUNTIME.ITERATOR_CONSUMED`), target-declared aggregate types (`count`, integer `sum`, and integer `avg` are `number`; `count` and integer `sum` throw outside ±(2^53 − 1) rather than round, while `avg` is a fraction already and carries no guard; `countBigInt` / `sumBigInt` / `avgDecimal` are the lossless forms, `avgDecimal` on PostgreSQL only), custom collection class (`extends Collection`), `with` and query fragments (`QueryFragment`, `Filtered`, `Ordered`), shared query fragments and scopes (`db.orm.fragment(fields, body)` for a filter on every model with given fields, `CodecField`, `db.orm.public.Post.fragment(...)` for a shared `select` / `include`, `orderByField` for an order or sort parameter from a request), drizzle-style, kysely-style. Naming types (§ *Naming model and result types*): "type of my model", "return type of a query", `ResultType`, `Scalars`, `Shape`, `models` / `Models` namespace in `contract.d.ts`, `Models.public_User`, Prisma 7 `Prisma.User` / `GetPayload` / `UserGetPayload` equivalents. Postgres/SQLite specifics: [`references/queries-postgres.md`](references/queries-postgres.md); Mongo specifics: [`references/queries-mongo.md`](references/queries-mongo.md) |
|
|
66
|
-
| Wire the runtime | [`references/runtime.md`](references/runtime.md) | `db.ts`, `
|
|
66
|
+
| Wire the runtime | [`references/runtime.md`](references/runtime.md) | `db.ts`, `contractFromJson<Contract>(...)`, `postgres({ contract })` / `sqlite({ contract })` / `mongo({ contract })` façades, middleware composition (lints, budgets, cache via `@prisma/orm-extension-middleware-cache`, custom `activityEnded` middleware, `@prisma/orm-postgres/family-runtime`), `DATABASE_URL`, `.env`, connection pool / `poolOptions`, dev vs prod config, transactions, read replicas, multi-database, script won't exit / hangs, `db.close` / `pool.end`, `await using` / `[Symbol.asyncDispose]` |
|
|
67
67
|
| Build-tool integration | [`references/build.md`](references/build.md) | Vite plugin (`@internal/vite-plugin-contract-emit`, Vite 7/8), `vite.config.ts`, contract emit on save, HMR / dev server, Next.js / Webpack / esbuild / Rollup / Turbopack (named gaps, not fabricated) |
|
|
68
68
|
| Supabase | [`references/supabase.md`](references/supabase.md) | `@internal/extension-supabase`, RLS, row level security, policies (`policy_select` / `policy_update` / `@@rls`, `auth.uid()`), role binding (`asUser(jwt)` / `asAnon()` / `asServiceRole()`), `auth.users`, cross-space FKs to `supabase:auth.AuthUser`, JWT / JWKS (`SUPABASE_JWKS_URL`, `SUPABASE_JWT_SECRET`), `SUPABASE.JWT_INVALID`, `SUPABASE.CONFIG_INVALID`, `RoleBoundDb`, session pooler |
|
|
69
69
|
| Debug an error | [`references/debug.md`](references/debug.md) | any structured error envelope (code, severity, why, fix, nextActions, meta), emit failed, query won't typecheck, query crashed, migration won't apply, `MIGRATION.HASH_MISMATCH`, `MIGRATION.RUNNER_FAILED`, `BUDGET.ROWS_EXCEEDED`, `BUDGET.TIME_EXCEEDED`, `RUNTIME.ABORTED`, `RUNTIME.TEMPORAL_UNAVAILABLE`, `PLAN.HASH_MISMATCH`, `CONTRACT.MARKER_MISSING`, `CONFIG.*` / `CLI.*` / `CONTRACT.*` / `MIGRATION.*` / `ORM.*` / `RUNTIME.*` codes, legacy `PN-*` codes, exit code 4 findings, drift, capability missing, planner conflict, EXPLAIN, query log, script won't exit / close connection |
|
|
@@ -40,7 +40,7 @@ Both files are **emitted artefacts**. Edit the source; never the JSON or `.d.ts`
|
|
|
40
40
|
|
|
41
41
|
## Key Concepts
|
|
42
42
|
|
|
43
|
-
- **The `@internal/<target>` façade is the only surface user-authored code imports from.** For a Postgres app: `@internal/postgres/config`, `@internal/postgres/contract-builder`, `@internal/postgres/control`, `@internal/postgres/runtime`. Mongo has the same layout (`@internal/mongo/config`, `@internal/mongo/contract-builder`, `@internal/mongo/runtime`). Each extension publishes its own façade — `@internal/extension-pgvector/control`, `@internal/extension-postgis/control`, `@internal/extension-paradedb/control`. **Never reach into `@internal/cli/*`, `@internal/family-*`, `@internal/target-*`, `@internal/adapter-*`, `@internal/driver-*`, or `@internal/sql-contract-*` from user code.** The façade bakes the family / target / adapter / driver wiring in. See *Common Pitfalls* #4.
|
|
43
|
+
- **The `@internal/<target>` façade is the only surface user-authored code imports from.** For a Postgres app: `@internal/postgres/config`, `@internal/postgres/contract-builder`, `@internal/postgres/control`, `@internal/postgres/runtime`, `@internal/postgres/static`. Mongo has the same layout (`@internal/mongo/config`, `@internal/mongo/contract-builder`, `@internal/mongo/runtime`, `@internal/mongo/static`). Each extension publishes its own façade — `@internal/extension-pgvector/control`, `@internal/extension-postgis/control`, `@internal/extension-paradedb/control`. **Never reach into `@internal/cli/*`, `@internal/family-*`, `@internal/target-*`, `@internal/adapter-*`, `@internal/driver-*`, or `@internal/sql-contract-*` from user code.** The façade bakes the family / target / adapter / driver wiring in. See *Common Pitfalls* #4.
|
|
44
44
|
- **Contract source.** A file the framework reads and lowers to the canonical Contract IR. Two flavours, both first-class:
|
|
45
45
|
- **`contract.prisma` (PSL)** — schema-flavoured DSL. Canonical for typical apps and brownfield Prisma users. Wired by `contract: './<path>/contract.prisma'` — the target config (`ormConfig`, below) detects the `.prisma` extension and routes through the PSL provider. The first line of every `.prisma` file is `// use prisma-8`; `orm init` and `contract infer` write it, and the language server only serves diagnostics, completion, and formatting on files that carry it (it still recognises the header earlier releases wrote and rewrites it on Format).
|
|
46
46
|
- **`contract.ts` (TypeScript builder)** — programmatic authoring with `defineContract({...}, ({ field, model, rel, type }) => ({...}))` from `@internal/postgres/contract-builder` (or `@internal/mongo/contract-builder`). Wired by `contract: './<path>/contract.ts'` — the façade detects the `.ts` extension and routes through the TS provider. Use when you need programmatic composition (per-tenant variants, generated fields) or constructs PSL doesn't yet express (e.g. registering a parameterised extension type — see pgvector's contract).
|
|
@@ -68,7 +68,7 @@ These symptoms are not structured envelopes — route on the message text and ch
|
|
|
68
68
|
| Symptom | Next move |
|
|
69
69
|
|---|---|
|
|
70
70
|
| `TypeError: db.end is not a function` | The runtime client does not expose `db.end()` — that's the `node-postgres` pool API (`pool.end()`). The right call is `await db.close()`. See `references/runtime.md` § *Running as a script (teardown)*. |
|
|
71
|
-
| Script hangs after queries print / process won't exit | On Postgres the façade-owned `pg.Pool` keeps the event loop alive. Call `await db.close()` before the script returns, or `await using db = postgres
|
|
71
|
+
| Script hangs after queries print / process won't exit | On Postgres the façade-owned `pg.Pool` keeps the event loop alive. Call `await db.close()` before the script returns, or `await using db = postgres({ contract, ... })` at the top of a script module (do NOT put `await using` inside a request handler — block-scoped, would close per-request). See `references/runtime.md` § *Running as a script (teardown)*. |
|
|
72
72
|
| `Error('Postgres client is closed')` / `Error('SQLite client is closed')` / `Error('Mongo client is closed')` | The client was closed via `db.close()` (terminal state). Remove the early `close()`, reorder so `close()` runs last after all queries, or construct a new `db` if reconnection is intended. See `references/runtime.md` § *Running as a script (teardown)*. |
|
|
73
73
|
|
|
74
74
|
## Routing — symptom and code → next move
|
|
@@ -114,7 +114,7 @@ The single source of truth: read the envelope, find the row by `code`, follow th
|
|
|
114
114
|
| `RUNTIME.ABORTED` (`details.phase` = `encode\|decode\|stream\|beforeEncode\|onRow`) | Runtime, when an `AbortSignal` fires mid-execute | Cancellation, not a bug; surface to the caller. |
|
|
115
115
|
| `SqlQueryError` (no dotted code) | Raw-SQL paths surfacing a driver error | Inspect `sqlState` + `constraint` + `table` + `column`. Postgres `23505` = unique violation, `23503` = foreign-key violation, etc. Fix the data or the schema. |
|
|
116
116
|
| TypeScript error mentioning a capability (e.g. `returning()` not on the type, `include` of a many-relation off a many-load) | Authoring-time, before any envelope fires | Capability gates are declared in the **contract** (`capabilities` block, namespaced by target/family), not in `prisma.config.ts`. Route to `references/contract.md` for capability declaration and to `references/queries.md` for which method gates on which capability. Re-emit (`pnpm prisma contract emit`) after enabling. |
|
|
117
|
-
| TypeScript error mentioning a missing field/method on `db.orm.<ns>.<Model>` or a stale `Contract` shape | Authoring-time | Re-emit (`pnpm prisma contract emit`); confirm `db.ts`
|
|
117
|
+
| TypeScript error mentioning a missing field/method on `db.orm.<ns>.<Model>` or a stale `Contract` shape | Authoring-time | Re-emit (`pnpm prisma contract emit`); confirm `db.ts` builds its contract with `contractFromJson<Contract>(contractJson)` and passes it to `postgres({ contract })` (the client infers the contract types from it). See `references/runtime.md` and `references/contract.md`. |
|
|
118
118
|
|
|
119
119
|
If the envelope's `code` is not in this table, follow the envelope's `fix` field literally — it's the framework's first-party next move. If `fix` is empty or unhelpful, escalate via `references/feedback.md`.
|
|
120
120
|
|
|
@@ -263,17 +263,18 @@ MigrationCLI.run(import.meta.url, M);
|
|
|
263
263
|
|
|
264
264
|
Replace both `placeholder(...)` calls with query-plan closures built from `endContract`. The `check` closure must return a **rowset query whose presence of any row signals "work remains"** — conventionally `<table>.select('id').where(<violation predicate>).limit(1)`. Scalar/aggregate shapes (`count(*)`, `bool_and(...)`) silently break the contract: the runner wraps `check` twice (`EXISTS(...)` for precheck, `NOT EXISTS(...)` for postcheck), and a query that always returns one row makes `EXISTS` always true and `NOT EXISTS` always false.
|
|
265
265
|
|
|
266
|
-
Build the query builder against `endContract` so the storage hashes line up — using a different contract reference raises `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH`. The cheapest way to get a typed SQL builder over the end contract is the façade itself: `postgres
|
|
266
|
+
Build the query builder against `endContract` so the storage hashes line up — using a different contract reference raises `MIGRATION.DATA_TRANSFORM_CONTRACT_MISMATCH`. The cheapest way to get a typed SQL builder over the end contract is the façade itself: `postgres({ contract: contractFromJson<End>(endContract) })` connects lazily, so constructing it inside `migration.ts` opens no connection; its `sql` is the builder and its `contract` is the validated contract to hand to `this.dataTransform`. The filled-in shape is the rendered scaffold above with only the two `placeholder(...)` arrows replaced (the operation list, including the `this.setNotNull({...})` the planner rendered after the transform, stays as rendered):
|
|
267
267
|
|
|
268
268
|
```typescript
|
|
269
269
|
import { col, Migration, MigrationCLI } from '@internal/postgres/migration';
|
|
270
270
|
import postgres from '@internal/postgres/runtime';
|
|
271
|
+
import { contractFromJson } from '@internal/postgres/static';
|
|
271
272
|
import type { Contract as End } from '../../snapshots/93f07d1b…c9e1e5a2/contract';
|
|
272
273
|
import endContract from '../../snapshots/93f07d1b…c9e1e5a2/contract.json' with { type: 'json' };
|
|
273
274
|
import type { Contract as Start } from '../../snapshots/f62a4154…d07dddc/contract';
|
|
274
275
|
import startContract from '../../snapshots/f62a4154…d07dddc/contract.json' with { type: 'json' };
|
|
275
276
|
|
|
276
|
-
const { sql: db, contract } = postgres
|
|
277
|
+
const { sql: db, contract } = postgres({ contract: contractFromJson<End>(endContract) });
|
|
277
278
|
|
|
278
279
|
export default class M extends Migration<Start, End> {
|
|
279
280
|
override readonly startContractJson = startContract;
|
|
@@ -6,7 +6,7 @@ Shared concepts (result consumption, script teardown, cross-target pitfalls, cap
|
|
|
6
6
|
|
|
7
7
|
## Key Concepts
|
|
8
8
|
|
|
9
|
-
**Mongo** (`mongo
|
|
9
|
+
**Mongo** (`mongo({ contract, ... })` from `@internal/mongo/runtime`):
|
|
10
10
|
|
|
11
11
|
- **`db.orm.<root>`** — ORM, lowercased plural contract root (`db.orm.users`, `db.orm.posts`). Same fluent chaining; `.where({ field: value })` object equality is the idiomatic filter form.
|
|
12
12
|
- **`db.query`** — typed aggregation-pipeline builder. Start with `db.query.from('<root>')`, chain `.match(...)` / `.project(...)` / `.group(...)` / `.lookup(...)`, terminal with `.build()`. Run via `(await db.runtime()).query(plan)` for anything that returns documents; `execute(plan)` is only for a write you want an affected count from, and it throws `RUNTIME.MONGO_STATISTICS_UNSUPPORTED` on a find or aggregate.
|
|
@@ -6,7 +6,7 @@ Shared concepts (result consumption, script teardown, cross-target pitfalls, cap
|
|
|
6
6
|
|
|
7
7
|
## Key Concepts
|
|
8
8
|
|
|
9
|
-
**Postgres** (`postgres
|
|
9
|
+
**Postgres** (`postgres({ contract, ... })` from `@internal/postgres/runtime`):
|
|
10
10
|
|
|
11
11
|
- **`db.orm.<ns>.<Model>`** — ORM, PascalCase model name (`db.orm.public.User`). Fluent `.where(...).select(...).orderBy(...).all()`, fully typed against `Contract`. Default lane for CRUD with relations.
|
|
12
12
|
- **`db.sql.<ns>.<table>`** — SQL builder, lowercase storage name (`db.sql.public.user`). Produces a *plan*. A plan that returns rows (`select`, or a write with `.returning(...)`) runs through `db.runtime().query(plan)`; a write with no `RETURNING` runs through `db.runtime().execute(plan)`, which resolves `{ affectedRows }`. Use when the ORM is too high-level — explicit `JOIN`, computed projections, set operations, window functions.
|
|
@@ -32,7 +32,7 @@ This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, S
|
|
|
32
32
|
- **Contract**: the data model. Authored as `contract.prisma` (PSL, the canonical surface) or `contract.ts` (TypeScript builder). The framework reads it and emits two artefacts: `contract.json` (runtime IR) and `contract.d.ts` (types).
|
|
33
33
|
- **Target**: the backing store. Today: `postgres` or `mongodb`. Picked at `init` time; baked into the `@internal/<target>` façade the scaffold imports from.
|
|
34
34
|
- **Authoring mode**: how you write the contract. `psl` (Prisma Schema Language, default) or `typescript` (programmatic builder, optionally paired with the Vite plugin for auto-emit during `vite dev` — see `references/build.md`).
|
|
35
|
-
- **Façade packages.** The scaffold installs exactly one façade per target — `@internal/postgres` (or `@internal/mongo`). User code imports from façade subpaths (`@internal/postgres/config`, `@internal/postgres/runtime`, `@internal/postgres/contract-builder`). The façade bakes in the family / target / adapter / driver wiring; never reach past it. See `references/contract.md` for the full list.
|
|
35
|
+
- **Façade packages.** The scaffold installs exactly one façade per target — `@internal/postgres` (or `@internal/mongo`). User code imports from façade subpaths (`@internal/postgres/config`, `@internal/postgres/runtime`, `@internal/postgres/static`, `@internal/postgres/contract-builder`). The façade bakes in the family / target / adapter / driver wiring; never reach past it. See `references/contract.md` for the full list.
|
|
36
36
|
- **`db.ts`**: the runtime entry point. Lives next to the contract source at `src/prisma/db.ts`. Imports the contract artefacts and exports a `db` value the rest of the app uses.
|
|
37
37
|
- **Marker**: a row in the `prisma_contract.marker` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets PN detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
|
|
38
38
|
|
|
@@ -27,8 +27,8 @@ This skill covers the **runtime entry point** — `db.ts` — and how to compose
|
|
|
27
27
|
|
|
28
28
|
## Key Concepts
|
|
29
29
|
|
|
30
|
-
- **`db.ts` is the runtime entry point.** Imports the runtime factory from the `@internal/<target>` façade (`@internal/postgres/runtime`, `@internal/sqlite/runtime`, or `@internal/mongo/runtime`), the contract artefacts (`contract.json` + the `Contract` type from `contract.d.ts`), and any middleware. Exports a `db` value the rest of your app imports. On a per-request runtime, `db.ts` imports `postgresServerless` from `@internal/postgres/serverless` instead and exports the serverless client `postgres`; see *Workflow — Serverless and per-request runtimes*.
|
|
31
|
-
-
|
|
30
|
+
- **`db.ts` is the runtime entry point.** Imports the runtime factory from the `@internal/<target>` façade (`@internal/postgres/runtime`, `@internal/sqlite/runtime`, or `@internal/mongo/runtime`), `contractFromJson` from the same façade's `/static` entry point, the contract artefacts (`contract.json` + the `Contract` type from `contract.d.ts`), and any middleware. Exports the typed `contract` and a `db` value the rest of your app imports. On a per-request runtime, `db.ts` imports `postgresServerless` from `@internal/postgres/serverless` instead and exports the serverless client `postgres`; see *Workflow — Serverless and per-request runtimes*.
|
|
31
|
+
- **`db.ts` imports only from the façade's `/runtime` and `/static` entry points.** Each factory is a *default* export. For Postgres: `import postgres from '@internal/postgres/runtime'`; SQLite: `import sqlite from '@internal/sqlite/runtime'`; Mongo: `import mongo from '@internal/mongo/runtime'`. The factory takes one options object and no type argument: it infers the contract type from `contract`. Turn the emitted JSON into a typed value once with `contractFromJson<Contract>(contractJson)` from the façade's `/static` entry point (`@internal/postgres/static`, `@internal/sqlite/static`, `@internal/mongo/static`; Supabase uses the Postgres one). That call is the only place you write the `Contract` type argument. A contract written in TypeScript with `defineContract` is already a typed value and goes to `{ contract }` directly. A contract value is validated once, however many clients use it.
|
|
32
32
|
- **Lazy connect.** The factory does not connect to the database synchronously. `db.sql` and `db.orm` are available immediately; the driver / pool is instantiated on the first call that needs a runtime (or when you explicitly call `await db.connect({ url })`, which binds the client to that URL), and the pool opens its first database connection on the first query. This is why `db.ts` can be imported in modules that load before the env is ready.
|
|
33
33
|
- **Middleware composes in order.** Every hook runs in the order of the `middleware: [...]` array — the first middleware's `beforeEncode` sees the statement first, and `intercept.onQuery` handlers are consulted in registration order with the first non-`undefined` result winning. Register a cache first so it gets first claim on a hit. Every middleware's `activityEnded` still fires on a cache hit, with `result.source: 'middleware'`.
|
|
34
34
|
- **`prisma.config.ts` vs `.env`.** The config (`definePrismaConfig({ orm: ormConfig({ contract, db, extensions, migrations }) })` — see `references/contract.md`) is for static project shape: contract path, installed extensions, migrations directory, default connection string. `.env` is for per-environment values (`DATABASE_URL`, secrets). Nothing reads `.env` on its own: the scaffolded `prisma.config.ts` starts with `import 'dotenv/config'`, and that import is what loads `.env` into `process.env` before the config (and the CLI running it) reads `process.env['DATABASE_URL']`. Keep the import; a config without it sees no `.env` values. Hardcoding `DATABASE_URL` in the config file leaks credentials and bypasses per-env overrides.
|
|
@@ -36,18 +36,21 @@ This skill covers the **runtime entry point** — `db.ts` — and how to compose
|
|
|
36
36
|
|
|
37
37
|
## Workflow — Basic `db.ts`
|
|
38
38
|
|
|
39
|
-
The concept: `db.ts` is the seam between the emitted contract artefacts (target-shaped) and the runtime that executes queries against them.
|
|
39
|
+
The concept: `db.ts` is the seam between the emitted contract artefacts (target-shaped) and the runtime that executes queries against them. Four imports are required — the runtime factory, `contractFromJson` from the façade's `/static` entry point, the `Contract` type (so the static query surfaces are typed), and the JSON artefact (which `contractFromJson` validates once).
|
|
40
40
|
|
|
41
41
|
`init` scaffolds something like this (for `--target postgres`):
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
44
|
// src/prisma/db.ts
|
|
45
45
|
import postgres from '@internal/postgres/runtime';
|
|
46
|
+
import { contractFromJson } from '@internal/postgres/static';
|
|
46
47
|
import type { Contract } from './contract.d';
|
|
47
48
|
import contractJson from './contract.json' with { type: 'json' };
|
|
48
49
|
|
|
49
|
-
export const
|
|
50
|
-
|
|
50
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
51
|
+
|
|
52
|
+
export const db = postgres({
|
|
53
|
+
contract,
|
|
51
54
|
url: process.env['DATABASE_URL']!,
|
|
52
55
|
});
|
|
53
56
|
```
|
|
@@ -56,7 +59,7 @@ export const db = postgres<Contract>({
|
|
|
56
59
|
|
|
57
60
|
Three things to know:
|
|
58
61
|
|
|
59
|
-
-
|
|
62
|
+
- **Name `Contract` on `contractFromJson`, not on the client.** `contractFromJson<Contract>(contractJson)` is where the JSON gets its type; without the type argument, the static surfaces collapse to a generic shape and you lose autocomplete on model names. Always import `Contract` from the emitted `./contract.d.ts`. The clients take no type argument and no `contractJson` option.
|
|
60
63
|
- **`with { type: 'json' }` is required.** Node's ESM JSON-import-attribute spec. Without it, the import errors.
|
|
61
64
|
- **`url` is optional at construct time.** If `DATABASE_URL` is not set when `db.ts` loads, the factory still returns a client; you can call `await db.connect({ url })` later. The factory throws lazily — only when a runtime is actually needed.
|
|
62
65
|
|
|
@@ -84,10 +87,9 @@ await db.close();
|
|
|
84
87
|
```typescript
|
|
85
88
|
// src/scripts/hello.ts — top-level await in a script module
|
|
86
89
|
import postgres from '@internal/postgres/runtime';
|
|
87
|
-
import
|
|
88
|
-
import contractJson from '../prisma/contract.json' with { type: 'json' };
|
|
90
|
+
import { contract } from '../prisma/db';
|
|
89
91
|
|
|
90
|
-
await using db = postgres
|
|
92
|
+
await using db = postgres({ contract, url: process.env.DATABASE_URL! });
|
|
91
93
|
|
|
92
94
|
const user = await db.orm.public.User.first();
|
|
93
95
|
console.log(user);
|
|
@@ -103,7 +105,7 @@ This is the most important rule in this section. `await using db = postgres(...)
|
|
|
103
105
|
```typescript
|
|
104
106
|
// DO NOT do this — closes the pool after every request.
|
|
105
107
|
app.get('/users', async (req, res) => {
|
|
106
|
-
await using db = postgres
|
|
108
|
+
await using db = postgres({ contract, url: process.env.DATABASE_URL! });
|
|
107
109
|
const users = await db.orm.public.User.all();
|
|
108
110
|
res.json(users);
|
|
109
111
|
});
|
|
@@ -113,7 +115,7 @@ The right server pattern is a **module-level singleton** in `db.ts`, imported by
|
|
|
113
115
|
|
|
114
116
|
```typescript
|
|
115
117
|
// src/prisma/db.ts — constructed once, lives for the process
|
|
116
|
-
export const db = postgres
|
|
118
|
+
export const db = postgres({ contract, url: process.env.DATABASE_URL });
|
|
117
119
|
|
|
118
120
|
// src/routes/users.ts
|
|
119
121
|
import { db } from '../prisma/db';
|
|
@@ -142,10 +144,12 @@ The concept: a per-request runtime (Cloudflare Workers + Hyperdrive, AWS Lambda,
|
|
|
142
144
|
```typescript
|
|
143
145
|
// src/prisma/db.ts — the serverless client: module scope, built once per isolate, holds no database connection
|
|
144
146
|
import postgresServerless from '@internal/postgres/serverless';
|
|
147
|
+
import { contractFromJson } from '@internal/postgres/static';
|
|
145
148
|
import type { Contract } from './contract.d';
|
|
146
149
|
import contractJson from './contract.json' with { type: 'json' };
|
|
147
150
|
|
|
148
|
-
export const
|
|
151
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
152
|
+
export const postgres = postgresServerless({ contract });
|
|
149
153
|
|
|
150
154
|
// src/worker.ts
|
|
151
155
|
import { postgres } from './prisma/db';
|
|
@@ -215,12 +219,15 @@ Both are exported from the façade's `family-runtime` subpath — `@prisma/orm-p
|
|
|
215
219
|
|
|
216
220
|
```typescript
|
|
217
221
|
import postgres from '@internal/postgres/runtime';
|
|
222
|
+
import { contractFromJson } from '@internal/postgres/static';
|
|
218
223
|
import { budgets, lints } from '@prisma/orm-postgres/family-runtime';
|
|
219
224
|
import type { Contract } from './contract.d';
|
|
220
225
|
import contractJson from './contract.json' with { type: 'json' };
|
|
221
226
|
|
|
222
|
-
export const
|
|
223
|
-
|
|
227
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
228
|
+
|
|
229
|
+
export const db = postgres({
|
|
230
|
+
contract,
|
|
224
231
|
url: process.env['DATABASE_URL'],
|
|
225
232
|
middleware: [
|
|
226
233
|
lints({
|
|
@@ -259,8 +266,8 @@ import {
|
|
|
259
266
|
export const cache = createCacheMiddleware({
|
|
260
267
|
store: createInMemoryCacheStore({ maxEntries: 1_000, ttlMs: 60_000 }),
|
|
261
268
|
});
|
|
262
|
-
export const db = postgres
|
|
263
|
-
|
|
269
|
+
export const db = postgres({
|
|
270
|
+
contract,
|
|
264
271
|
url: process.env['DATABASE_URL']!,
|
|
265
272
|
middleware: [cache, lints(), budgets({ maxRows: 10_000 })],
|
|
266
273
|
});
|
|
@@ -298,8 +305,8 @@ The concept: the runtime takes one of three binding shapes — `url`, `pg` (a pr
|
|
|
298
305
|
|
|
299
306
|
```typescript
|
|
300
307
|
// Default — URL string, factory constructs the pool.
|
|
301
|
-
postgres
|
|
302
|
-
|
|
308
|
+
postgres({
|
|
309
|
+
contract,
|
|
303
310
|
url: process.env['DATABASE_URL'],
|
|
304
311
|
poolOptions: {
|
|
305
312
|
connectionTimeoutMillis: 20_000,
|
|
@@ -312,7 +319,7 @@ postgres<Contract>({
|
|
|
312
319
|
// BYO pool — pass a pg.Pool you already created.
|
|
313
320
|
import { Pool } from 'pg';
|
|
314
321
|
const pool = new Pool({ connectionString: process.env['DATABASE_URL'] });
|
|
315
|
-
postgres
|
|
322
|
+
postgres({ contract, pg: pool });
|
|
316
323
|
```
|
|
317
324
|
|
|
318
325
|
The `url` and `pg` keys are mutually exclusive at the type level; passing both errors.
|
|
@@ -326,8 +333,8 @@ The concept: one `DATABASE_URL` per environment; the rest of the `db.ts` shape i
|
|
|
326
333
|
```typescript
|
|
327
334
|
const isProd = process.env['NODE_ENV'] === 'production';
|
|
328
335
|
|
|
329
|
-
export const db = postgres
|
|
330
|
-
|
|
336
|
+
export const db = postgres({
|
|
337
|
+
contract,
|
|
331
338
|
url: process.env['DATABASE_URL']!,
|
|
332
339
|
middleware: isProd
|
|
333
340
|
? [slowQueryWarning({ thresholdMs: 250 })]
|
|
@@ -363,10 +370,12 @@ After the switch (Mongo):
|
|
|
363
370
|
```typescript
|
|
364
371
|
// src/prisma/db.ts (Mongo)
|
|
365
372
|
import mongo from '@internal/mongo/runtime';
|
|
373
|
+
import { contractFromJson } from '@internal/mongo/static';
|
|
366
374
|
import type { Contract } from './contract.d';
|
|
367
375
|
import contractJson from './contract.json' with { type: 'json' };
|
|
368
376
|
|
|
369
|
-
export const
|
|
377
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
378
|
+
export const db = mongo({ contract, url: process.env['DATABASE_URL'] });
|
|
370
379
|
```
|
|
371
380
|
|
|
372
381
|
SQLite:
|
|
@@ -374,10 +383,12 @@ SQLite:
|
|
|
374
383
|
```typescript
|
|
375
384
|
// src/prisma/db.ts (SQLite)
|
|
376
385
|
import sqlite from '@internal/sqlite/runtime';
|
|
386
|
+
import { contractFromJson } from '@internal/sqlite/static';
|
|
377
387
|
import type { Contract } from './contract.d';
|
|
378
388
|
import contractJson from './contract.json' with { type: 'json' };
|
|
379
389
|
|
|
380
|
-
export const
|
|
390
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
391
|
+
export const db = sqlite({ contract, path: 'app.db' });
|
|
381
392
|
```
|
|
382
393
|
|
|
383
394
|
`path` is optional at construct time (you can call `db.connect({ path })` later); omit it and the façade still returns a client. The SQLite façade exposes the same `db.sql`, `db.orm`, `db.transaction(...)`, `db.close()`, and `[Symbol.asyncDispose]` surfaces as Postgres, with one addressing difference: SQLite has no schemas, so `db.sql` and `db.orm` are the unbound namespace itself (`db.orm.User`, `db.sql.user`) instead of Postgres's `db.orm.public.User` / `db.sql.public.user`. The Mongo façade shares `db.orm`, `db.close()`, and `[Symbol.asyncDispose]` but has no `db.sql` and no `db.transaction(...)`.
|
|
@@ -396,13 +407,13 @@ The runtime side (this skill) is the same regardless: `db.ts` reads `contract.js
|
|
|
396
407
|
## Common Pitfalls
|
|
397
408
|
|
|
398
409
|
1. **Hardcoding `DATABASE_URL` in `prisma.config.ts`.** Leaks credentials; bypasses per-environment overrides. Use `.env`.
|
|
399
|
-
2. **
|
|
410
|
+
2. **Writing the type argument on the client, or passing `contractJson`.** `postgres<Contract>({ contractJson })` no longer compiles: the clients take `{ contract }` and infer its type. Write `contractFromJson<Contract>(contractJson)` and pass the result. Omitting `<Contract>` there collapses the static surfaces to a generic shape and you lose autocomplete for models.
|
|
400
411
|
3. **Forgetting `with { type: 'json' }` on the contract import.** Required by Node's ESM JSON-import-attribute spec.
|
|
401
412
|
4. **Middleware order matters.** Registration order is hook order; put the cache first so its `intercept.onActivity` and `intercept.onQuery` are consulted first.
|
|
402
413
|
5. **Importing middleware from a non-existent package or subpath.** There is no `@internal/postgres/middleware` subpath and no `@internal/middleware-telemetry` package. `lints` / `budgets` / `SqlMiddleware` come from `@prisma/orm-postgres/family-runtime`; the cache comes from `@prisma/orm-extension-middleware-cache`; a query log or telemetry hook is a custom `activityEnded` middleware (above).
|
|
403
414
|
6. **Confabulating lint / budget option names.** Lints take `severities` (with the five keys above), not `requireWhere` / `maxRowsWithoutLimit`. Budgets use `maxLatencyMs` (not `maxDurationMs`) plus `maxRows` / `defaultTableRows` / `tableRows`. When in doubt, read the source.
|
|
404
415
|
7. **Switching targets without re-emitting.** The contract artefacts are target-shaped; emit after the target change.
|
|
405
|
-
8. **Script hangs after queries finish on Postgres.** The `pg.Pool` keeps Node's event loop alive. Solution: `await db.close()` before the script returns, or `await using db = postgres
|
|
416
|
+
8. **Script hangs after queries finish on Postgres.** The `pg.Pool` keeps Node's event loop alive. Solution: `await db.close()` before the script returns, or `await using db = postgres({ contract, ... })` at the top of a script module. Do not put `await using db = postgres(...)` inside a request handler — it's block-scoped and would close the pool after every request. The right server pattern is a module-level singleton in `db.ts` that lives for the process lifetime. On a per-request runtime, use `postgresServerless()` and `await using db = await postgres.connect({ url })` in the handler instead (see *Workflow — Serverless and per-request runtimes*).
|
|
406
417
|
|
|
407
418
|
## What Prisma 8 doesn't do yet
|
|
408
419
|
|
|
@@ -417,15 +428,15 @@ This skill is intentionally body-only; `prisma orm init --help`, the target `def
|
|
|
417
428
|
|
|
418
429
|
## Checklist
|
|
419
430
|
|
|
420
|
-
- [ ] `db.ts` imports the runtime factory from `@internal/<target>/runtime` (`postgres`, `sqlite`, or `mongo`) and the `Contract` type from `./contract.d`.
|
|
431
|
+
- [ ] `db.ts` imports the runtime factory from `@internal/<target>/runtime` (`postgres`, `sqlite`, or `mongo`), `contractFromJson` from `@internal/<target>/static`, and the `Contract` type from `./contract.d`.
|
|
421
432
|
- [ ] `with { type: 'json' }` on the contract JSON import.
|
|
422
|
-
- [ ]
|
|
433
|
+
- [ ] `Contract` is named once, on `contractFromJson<Contract>(contractJson)`, and the client gets `{ contract }` with no type argument.
|
|
423
434
|
- [ ] `DATABASE_URL` lives in `.env`, not in `prisma.config.ts`.
|
|
424
435
|
- [ ] Middleware ordered intentionally (cache first when used).
|
|
425
436
|
- [ ] `lints` / `budgets` imported from `@prisma/orm-postgres/family-runtime` and using the verified option keys (`severities`, `maxLatencyMs`, `maxRows`, `tableRows`).
|
|
426
437
|
- [ ] Per-env divergence (if any) gated by `NODE_ENV` or similar.
|
|
427
438
|
- [ ] Did NOT hardcode credentials in any committed file.
|
|
428
|
-
- [ ] Did NOT confabulate a `@internal/postgres/middleware` subpath, a `@internal/middleware-telemetry` package, a `@internal/postgres-extension-audit` package, or a
|
|
439
|
+
- [ ] Did NOT confabulate a `@internal/postgres/middleware` subpath, a `@internal/middleware-telemetry` package, a `@internal/postgres-extension-audit` package, or a type argument or `contractJson` option on `postgres(...)`.
|
|
429
440
|
- [ ] Did NOT claim `db.transaction(...)` exists on the Mongo façade — only Postgres and SQLite expose it.
|
|
430
441
|
- [ ] Did NOT confabulate read-replica / multi-DB / extra pool config — pointed at *What Prisma 8 doesn't do yet* and routed to `references/feedback.md`.
|
|
431
442
|
- [ ] For build-system / dev-server prompts (Vite plugin, Next.js plugin, …) routed to `references/build.md`.
|
|
@@ -108,11 +108,14 @@ The concept: instead of the stock `postgres()` factory, a Supabase app builds it
|
|
|
108
108
|
```typescript
|
|
109
109
|
// src/prisma/db.ts
|
|
110
110
|
import { supabase } from '@internal/extension-supabase/runtime';
|
|
111
|
+
import { contractFromJson } from '@internal/postgres/static';
|
|
111
112
|
import type { Contract } from './contract.d';
|
|
112
113
|
import contractJson from './contract.json' with { type: 'json' };
|
|
113
114
|
|
|
114
|
-
export const
|
|
115
|
-
|
|
115
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
116
|
+
|
|
117
|
+
export const db = await supabase({
|
|
118
|
+
contract,
|
|
116
119
|
url: process.env['DATABASE_URL'], // direct Postgres connection — see pitfalls
|
|
117
120
|
jwksUrl: process.env['SUPABASE_JWKS_URL'], // https://<project-ref>.supabase.co/auth/v1/.well-known/jwks.json
|
|
118
121
|
// Legacy HS256 projects use jwtSecret: process.env['SUPABASE_JWT_SECRET'] instead — exactly one of the two.
|
|
@@ -223,7 +226,7 @@ The concept: the runtime needs a **direct, session-capable** Postgres connection
|
|
|
223
226
|
- [ ] `extensions: [supabasePack]` (the `pack` export) in `ormConfig({...})` inside `definePrismaConfig({ orm: ... })`.
|
|
224
227
|
- [ ] Cross-space FK typed `supabase:auth.AuthUser` with explicit `fields` / `references` (+ `onDelete` if wanted).
|
|
225
228
|
- [ ] Every policy target model carries `@@rls`; predicates quote camelCase columns and cast for `auth.uid()`.
|
|
226
|
-
- [ ] `db.ts` uses `await supabase
|
|
229
|
+
- [ ] `db.ts` uses `await supabase({ contract, url, jwksUrl | jwtSecret })`, with `contract` from `contractFromJson<Contract>(contractJson)` of `@internal/postgres/static` — exactly one JWT key source; `jwksUrl` for current projects, `jwtSecret` only for legacy HS256.
|
|
227
230
|
- [ ] Queries go through a `RoleBoundDb` from `asUser` / `asAnon` / `asServiceRole`; `asUser` is awaited.
|
|
228
231
|
- [ ] `auth.*` / `storage.*` reads go through `asServiceRole().supabase` only, after the one-time narrow grant (`GRANT USAGE ON SCHEMA auth` + `GRANT SELECT` on the tables you read).
|
|
229
232
|
- [ ] No per-table grants added for your own `public` tables — Supabase default privileges cover them; RLS does the protecting.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-static-DzefaBeX-Cz36Sz8Q.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-static-DzefaBeX.mjs"],"sourcesContent":["import { PG_ENUM_CODEC_ID } from \"@internal/target-postgres/codec-ids\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { buildNamespacedEnums, createEnumAccessor } from \"@internal/contract/enum-accessor\";\nimport postgresAdapter from \"@internal/adapter-postgres/runtime\";\nimport { createExecutionContext, createSqlExecutionStack } from \"@internal/sql-runtime\";\nimport postgresTarget, { PostgresContractSerializer } from \"@internal/target-postgres/runtime\";\nimport { createRawLane, sql } from \"@internal/sql-builder/runtime\";\n//#region src/runtime/native-enums.ts\n/**\n* The accessors for one namespace's value sets, leaving out each value set whose name is a domain enum's in the same namespace: a domain enum's value set takes its enum's name and namespace, and `db.enums` holds that enum. The rest are native enum types, because `native_enum` is the only pack entity that derives a value set today. Reads plain contract data, so a `validateContract`'d JSON contract works as well as a hydrated one. A member is a value, as in `CREATE TYPE … AS ENUM ('a', 'b')`, so each value is also its own name.\n*/\nfunction buildNativeEnumsMapForNamespace(storage, domain, namespaceId) {\n\tconst result = {};\n\tconst valueSets = storage.namespaces[namespaceId]?.entries.valueSet;\n\tif (!valueSets) return result;\n\tconst domainEnums = domain.namespaces[namespaceId]?.enum ?? {};\n\tfor (const [name, valueSet] of Object.entries(valueSets)) {\n\t\tif (Object.hasOwn(domainEnums, name)) continue;\n\t\tresult[name] = createEnumAccessor({\n\t\t\tcodecId: PG_ENUM_CODEC_ID,\n\t\t\tmembers: valueSet.values.map((value) => ({\n\t\t\t\tname: String(value),\n\t\t\t\tvalue\n\t\t\t}))\n\t\t});\n\t}\n\treturn result;\n}\nfunction buildNamespacedNativeEnums(storage, domain) {\n\tconst result = {};\n\tfor (const namespaceId of Object.keys(storage.namespaces)) result[namespaceId] = buildNativeEnumsMapForNamespace(storage, domain, namespaceId);\n\treturn result;\n}\n//#endregion\n//#region src/static/postgres-static.ts\nfunction buildPostgresStaticContext(context, rawCodecInferer) {\n\tconst sqlDb = sql({\n\t\tcontext,\n\t\trawCodecInferer\n\t});\n\tconst raw = createRawLane({\n\t\tcontext,\n\t\trawCodecInferer\n\t});\n\tconst enums = Object.freeze(buildNamespacedEnums(context.contract.domain, (codecId) => context.contractCodecs.forCodecRef({ codecId })));\n\tconst nativeEnums = blindCast(Object.freeze(buildNamespacedNativeEnums(context.contract.storage, context.contract.domain)));\n\treturn {\n\t\tcontext,\n\t\tcontract: context.contract,\n\t\tenums,\n\t\tnativeEnums,\n\t\tsql: sqlDb,\n\t\traw\n\t};\n}\nfunction postgresStatic(options) {\n\tconst contract = blindCast(new PostgresContractSerializer().deserializeContract(options.contractJson));\n\tconst stack = createSqlExecutionStack({\n\t\ttarget: postgresTarget,\n\t\tadapter: postgresAdapter,\n\t\textensions: options.extensions ?? []\n\t});\n\treturn buildPostgresStaticContext(createExecutionContext({\n\t\tcontract,\n\t\tstack\n\t}), stack.adapter.rawCodecInferer);\n}\n//#endregion\nexport { postgresStatic as n, buildNamespacedNativeEnums as r, buildPostgresStaticContext as t };\n\n//# sourceMappingURL=postgres-static-DzefaBeX.mjs.map"],"mappings":";;;;;;;;;;;AAWA,SAAS,gCAAgC,SAAS,QAAQ,aAAa;CACtE,MAAM,SAAS,CAAC;CAChB,MAAM,YAAY,QAAQ,WAAW,YAAY,EAAE,QAAQ;CAC3D,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,cAAc,OAAO,WAAW,YAAY,EAAE,QAAQ,CAAC;CAC7D,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,GAAG;EACzD,IAAI,OAAO,OAAO,aAAa,IAAI,GAAG;EACtC,OAAO,QAAQ,mBAAmB;GACjC,SAAS;GACT,SAAS,SAAS,OAAO,KAAK,WAAW;IACxC,MAAM,OAAO,KAAK;IAClB;GACD,EAAE;EACH,CAAC;CACF;CACA,OAAO;AACR;AACA,SAAS,2BAA2B,SAAS,QAAQ;CACpD,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,eAAe,OAAO,KAAK,QAAQ,UAAU,GAAG,OAAO,eAAe,gCAAgC,SAAS,QAAQ,WAAW;CAC7I,OAAO;AACR;AAGA,SAAS,2BAA2B,SAAS,iBAAiB;CAC7D,MAAM,QAAQ,IAAI;EACjB;EACA;CACD,CAAC;CACD,MAAM,MAAM,cAAc;EACzB;EACA;CACD,CAAC;CACD,MAAM,QAAQ,OAAO,OAAO,qBAAqB,QAAQ,SAAS,SAAS,YAAY,QAAQ,eAAe,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;CACvI,MAAM,cAAc,UAAU,OAAO,OAAO,2BAA2B,QAAQ,SAAS,SAAS,QAAQ,SAAS,MAAM,CAAC,CAAC;CAC1H,OAAO;EACN;EACA,UAAU,QAAQ;EAClB;EACA;EACA,KAAK;EACL;CACD;AACD;AACA,SAAS,eAAe,SAAS;CAChC,MAAM,WAAW,UAAU,IAAI,2BAA2B,CAAC,CAAC,oBAAoB,QAAQ,YAAY,CAAC;CACrG,MAAM,QAAQ,wBAAwB;EACrC,QAAQ;EACR,SAAS;EACT,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,OAAO,2BAA2B,uBAAuB;EACxD;EACA;CACD,CAAC,GAAG,MAAM,QAAQ,eAAe;AAClC"}
|