@prisma/orm-postgres 8.0.0-rc.13-dev.5 → 8.0.0-rc.13-dev.6
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/postgres-options-2XQhW8Fe-C3jEHTDJ.d.mts +55 -0
- package/dist/postgres-options-2XQhW8Fe-C3jEHTDJ.d.mts.map +1 -0
- package/dist/postgres-runtime-CYEen60e-CEkW4u-S.mjs +160 -0
- package/dist/postgres-runtime-CYEen60e-CEkW4u-S.mjs.map +1 -0
- package/dist/postgres-static-Q_C_AoOf-DNC79LUR.d.mts +61 -0
- package/dist/postgres-static-Q_C_AoOf-DNC79LUR.d.mts.map +1 -0
- package/dist/{postgres-static-KmLmp8vV-qgkhJAEz.mjs → postgres-static-zqQ1nDxl-CTre64NI.mjs} +5 -5
- package/dist/{postgres-static-KmLmp8vV-qgkhJAEz.mjs.map → postgres-static-zqQ1nDxl-CTre64NI.mjs.map} +1 -1
- package/dist/runtime.d.mts +66 -2
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +17 -120
- package/dist/runtime.mjs.map +1 -1
- package/dist/serverless.d.mts +17 -29
- package/dist/serverless.d.mts.map +1 -1
- package/dist/serverless.mjs +81 -37
- package/dist/serverless.mjs.map +1 -1
- package/dist/static.d.mts +2 -24
- package/dist/static.mjs +1 -1
- package/package.json +9 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/queries.md +6 -7
- package/skills/prisma-8/references/runtime.md +47 -8
- package/dist/postgres-B-ZPMR9y-gRfTiPA0.d.mts +0 -133
- package/dist/postgres-B-ZPMR9y-gRfTiPA0.d.mts.map +0 -1
- package/dist/postgres-runtime-oM2EIAjm-CZIDUstk.mjs +0 -12
- package/dist/postgres-runtime-oM2EIAjm-CZIDUstk.mjs.map +0 -1
- package/dist/static.d.mts.map +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { n as PostgresStaticContext, r as PostgresTargetId, t as NamespacedNativeEnums } from "./postgres-static-Q_C_AoOf-DNC79LUR.mjs";
|
|
2
|
+
import { BindSiteParams, Declaration, ParamsFromDeclaration, Runtime, SqlExecutionStackWithDriver, SqlMiddleware, SqlRuntimeExtensionDescriptor, TransactionContext, VerifyMarkerOption } from "@prisma/orm-family-sql/runtime";
|
|
3
|
+
import { PreparedFrom, orm } from "@prisma/orm-family-sql/orm-client";
|
|
4
|
+
import { NamespacedEnums } from "@prisma/orm-framework/contract/enum-accessor";
|
|
5
|
+
import "@prisma/orm-target-postgres/driver/runtime";
|
|
6
|
+
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
7
|
+
import { ExtractCodecTypes, SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
8
|
+
import { Db } from "@prisma/orm-family-sql/builder/types";
|
|
9
|
+
import { CodecTypesBase } from "@prisma/orm-family-sql/relational-core/expression";
|
|
10
|
+
import { Preparable, SqlQueryPlan } from "@prisma/orm-family-sql/relational-core/plan";
|
|
11
|
+
//#region ../../../3-extensions/postgres/dist/postgres-options-2XQhW8Fe.d.mts
|
|
12
|
+
//#region src/runtime/postgres-members.d.ts
|
|
13
|
+
type OrmClient<TContract extends Contract<SqlStorage>> = ReturnType<typeof orm<TContract>>;
|
|
14
|
+
interface PostgresTransactionContext<TContract extends Contract<SqlStorage>> extends TransactionContext {
|
|
15
|
+
readonly sql: Db<TContract>;
|
|
16
|
+
readonly orm: OrmClient<TContract>;
|
|
17
|
+
readonly enums: NamespacedEnums<TContract>;
|
|
18
|
+
readonly nativeEnums: NamespacedNativeEnums<TContract>;
|
|
19
|
+
}
|
|
20
|
+
interface PostgresStaticMembers<TContract extends Contract<SqlStorage>> extends PostgresStaticContext<TContract> {
|
|
21
|
+
readonly stack: SqlExecutionStackWithDriver<PostgresTargetId>;
|
|
22
|
+
}
|
|
23
|
+
interface PostgresRuntimeBoundMembers<TContract extends Contract<SqlStorage>> {
|
|
24
|
+
readonly orm: OrmClient<TContract>;
|
|
25
|
+
runtime(): Runtime;
|
|
26
|
+
transaction<R>(fn: (tx: PostgresTransactionContext<TContract>) => PromiseLike<R>): Promise<R>;
|
|
27
|
+
prepare<D extends Declaration<CT>, Q extends SqlQueryPlan | Preparable<unknown, unknown>, CT extends CodecTypesBase = ExtractCodecTypes<TContract>>(declaration: D, callback: (params: BindSiteParams<D>) => Q): Promise<PreparedFrom<ParamsFromDeclaration<D, CT>, Q>>;
|
|
28
|
+
}
|
|
29
|
+
interface PostgresLifecycleMembers {
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/runtime/postgres-options.d.ts
|
|
35
|
+
/**
|
|
36
|
+
* Server-side cursor for reads. Unset reads the whole result before the first row; set streams
|
|
37
|
+
* rows in batches of `batchSize`, 100 when omitted or `undefined`. A `batchSize` that is not a
|
|
38
|
+
* positive integer fails the factory call.
|
|
39
|
+
*/
|
|
40
|
+
interface PostgresCursorOptions {
|
|
41
|
+
readonly batchSize?: number | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The options `postgres()` and `postgresServerless()` share: how queries run, not where the
|
|
45
|
+
* database is.
|
|
46
|
+
*/
|
|
47
|
+
interface PostgresExecutionOptions {
|
|
48
|
+
readonly extensions?: readonly SqlRuntimeExtensionDescriptor<PostgresTargetId>[];
|
|
49
|
+
readonly middleware?: readonly SqlMiddleware[];
|
|
50
|
+
readonly verifyMarker?: VerifyMarkerOption;
|
|
51
|
+
readonly cursor?: PostgresCursorOptions;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { PostgresStaticMembers as a, PostgresRuntimeBoundMembers as i, PostgresExecutionOptions as n, PostgresLifecycleMembers as r, PostgresCursorOptions as t };
|
|
55
|
+
//# sourceMappingURL=postgres-options-2XQhW8Fe-C3jEHTDJ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-options-2XQhW8Fe-C3jEHTDJ.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-options-2XQhW8Fe.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,SAAS"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { t as postgresError } from "./errors-DfWK9xep-CYOOg0sB.mjs";
|
|
2
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
3
|
+
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
4
|
+
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
5
|
+
import { SqlRuntimeBase, withTransaction } from "@prisma/orm-family-sql/runtime";
|
|
6
|
+
import postgresTarget from "@prisma/orm-target-postgres/target/runtime";
|
|
7
|
+
import { sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
8
|
+
import { orm, prepareQuery } from "@prisma/orm-family-sql/orm-client";
|
|
9
|
+
import { type } from "arktype";
|
|
10
|
+
//#region ../../../3-extensions/postgres/dist/postgres-runtime-CYEen60e.mjs
|
|
11
|
+
const isPgPool = (pg) => "totalCount" in pg && "idleCount" in pg && "waitingCount" in pg;
|
|
12
|
+
const isPgClient = (pg) => "escapeIdentifier" in pg && "escapeLiteral" in pg;
|
|
13
|
+
function validatePostgresUrl(url) {
|
|
14
|
+
const trimmed = url.trim();
|
|
15
|
+
if (trimmed.length === 0) throw postgresError("RUNTIME.BINDING_INVALID", "Postgres URL must be a non-empty string", { meta: {
|
|
16
|
+
extension: "postgres",
|
|
17
|
+
reason: "empty url"
|
|
18
|
+
} });
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = new URL(trimmed);
|
|
22
|
+
} catch {
|
|
23
|
+
throw postgresError("RUNTIME.BINDING_INVALID", "Postgres URL must be a valid URL", { meta: {
|
|
24
|
+
extension: "postgres",
|
|
25
|
+
reason: "unparseable url"
|
|
26
|
+
} });
|
|
27
|
+
}
|
|
28
|
+
if (parsed.protocol !== "postgres:" && parsed.protocol !== "postgresql:") throw postgresError("RUNTIME.BINDING_INVALID", "Postgres URL must use postgres:// or postgresql://", { meta: {
|
|
29
|
+
extension: "postgres",
|
|
30
|
+
reason: "wrong scheme",
|
|
31
|
+
received: parsed.protocol
|
|
32
|
+
} });
|
|
33
|
+
return trimmed;
|
|
34
|
+
}
|
|
35
|
+
function resolvePostgresBinding(options) {
|
|
36
|
+
if (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", {
|
|
37
|
+
fix: "Pass exactly one of `binding`, `url`, or `pg`.",
|
|
38
|
+
meta: {
|
|
39
|
+
extension: "postgres",
|
|
40
|
+
reason: "zero or multiple binding inputs"
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
if (options.binding !== void 0) return options.binding;
|
|
44
|
+
if (options.url !== void 0) return {
|
|
45
|
+
kind: "url",
|
|
46
|
+
url: validatePostgresUrl(options.url)
|
|
47
|
+
};
|
|
48
|
+
const pgBinding = options.pg;
|
|
49
|
+
if (pgBinding === void 0) throw new InternalError("Invariant violation: expected pg binding after validation");
|
|
50
|
+
if (isPgPool(pgBinding)) return {
|
|
51
|
+
kind: "pgPool",
|
|
52
|
+
pool: pgBinding
|
|
53
|
+
};
|
|
54
|
+
if (isPgClient(pgBinding)) return {
|
|
55
|
+
kind: "pgClient",
|
|
56
|
+
client: pgBinding
|
|
57
|
+
};
|
|
58
|
+
throw postgresError("RUNTIME.BINDING_INVALID", "Unable to determine pg binding type from pg input; use binding with explicit kind", {
|
|
59
|
+
fix: "Pass `binding: { kind: \"pgPool\", pool }` or `binding: { kind: \"pgClient\", client }` instead of `pg`.",
|
|
60
|
+
meta: {
|
|
61
|
+
extension: "postgres",
|
|
62
|
+
reason: "unrecognizable pg object"
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function resolveOptionalPostgresBinding(options) {
|
|
67
|
+
if (Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.pg !== void 0) === 0) return;
|
|
68
|
+
return resolvePostgresBinding(blindCast(options));
|
|
69
|
+
}
|
|
70
|
+
function buildPostgresRuntimeBoundMembers(options) {
|
|
71
|
+
const { context, rawCodecInferer, enums, nativeEnums, getRuntime } = options;
|
|
72
|
+
const orm$1 = orm({
|
|
73
|
+
runtime: {
|
|
74
|
+
query(plan) {
|
|
75
|
+
return getRuntime().query(plan);
|
|
76
|
+
},
|
|
77
|
+
execute(plan) {
|
|
78
|
+
return getRuntime().execute(plan);
|
|
79
|
+
},
|
|
80
|
+
connection() {
|
|
81
|
+
return getRuntime().connection();
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
context
|
|
85
|
+
});
|
|
86
|
+
function prepare(declaration, callback) {
|
|
87
|
+
return prepareQuery(getRuntime(), declaration, callback);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
orm: orm$1,
|
|
91
|
+
runtime() {
|
|
92
|
+
return getRuntime();
|
|
93
|
+
},
|
|
94
|
+
prepare,
|
|
95
|
+
transaction(fn) {
|
|
96
|
+
return withTransaction(getRuntime(), (txCtx) => {
|
|
97
|
+
const txSql = sql({
|
|
98
|
+
context,
|
|
99
|
+
rawCodecInferer
|
|
100
|
+
});
|
|
101
|
+
const txOrm = orm({
|
|
102
|
+
runtime: {
|
|
103
|
+
query(plan) {
|
|
104
|
+
return txCtx.query(plan);
|
|
105
|
+
},
|
|
106
|
+
execute(plan) {
|
|
107
|
+
return txCtx.execute(plan);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
context
|
|
111
|
+
});
|
|
112
|
+
return fn(Object.assign(castAs(Object.create(txCtx)), {
|
|
113
|
+
sql: txSql,
|
|
114
|
+
orm: txOrm,
|
|
115
|
+
enums,
|
|
116
|
+
nativeEnums
|
|
117
|
+
}));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Default time to wait for the database to accept a connection, for a client's pool and for a
|
|
124
|
+
* connection's `pg.Client`.
|
|
125
|
+
*/
|
|
126
|
+
const DEFAULT_CONNECT_TIMEOUT_MILLIS = 2e4;
|
|
127
|
+
const cursorOptionsSchema = type({ "batchSize?": "number.integer > 0 | undefined" }).onUndeclaredKey("reject");
|
|
128
|
+
function validateCursorOptions(cursor, helper) {
|
|
129
|
+
if (cursor === void 0) return;
|
|
130
|
+
const result = cursorOptionsSchema(cursor);
|
|
131
|
+
if (result instanceof type.errors) throw postgresError("RUNTIME.ARGUMENT_INVALID", "Invalid cursor option", {
|
|
132
|
+
why: result.summary,
|
|
133
|
+
fix: "Pass cursor: {} or cursor: { batchSize: <positive integer> } to read through a server-side cursor, or leave cursor unset to read without one.",
|
|
134
|
+
meta: {
|
|
135
|
+
extension: "postgres",
|
|
136
|
+
helper,
|
|
137
|
+
argument: "cursor",
|
|
138
|
+
received: cursor
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
function toDriverCursorOptions(cursor) {
|
|
144
|
+
return cursor === void 0 ? { disabled: true } : ifDefined("batchSize", cursor.batchSize);
|
|
145
|
+
}
|
|
146
|
+
function toRuntimeOptions(options) {
|
|
147
|
+
return {
|
|
148
|
+
...ifDefined("verifyMarker", options.verifyMarker),
|
|
149
|
+
...ifDefined("middleware", options.middleware)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
var PostgresRuntimeImpl = class extends SqlRuntimeBase {
|
|
153
|
+
getListDecoder() {
|
|
154
|
+
return postgresTarget.listDecoder();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
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 };
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=postgres-runtime-CYEen60e-CEkW4u-S.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-runtime-CYEen60e-CEkW4u-S.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-runtime-CYEen60e.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, 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 } = options;\n\tconst orm$1 = orm({\n\t\truntime: {\n\t\t\tquery(plan) {\n\t\t\t\treturn getRuntime().query(plan);\n\t\t\t},\n\t\t\texecute(plan) {\n\t\t\t\treturn getRuntime().execute(plan);\n\t\t\t},\n\t\t\tconnection() {\n\t\t\t\treturn getRuntime().connection();\n\t\t\t}\n\t\t},\n\t\tcontext\n\t});\n\tfunction prepare(declaration, callback) {\n\t\treturn prepareQuery(getRuntime(), 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(getRuntime(), (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},\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};\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-CYEen60e.mjs.map"],"mappings":"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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ExecutionContext, SqlRuntimeExtensionDescriptor } from "@prisma/orm-family-sql/runtime";
|
|
2
|
+
import { EnumAccessor, EnumEntriesToAccessors, NamespacedEnums } from "@prisma/orm-framework/contract/enum-accessor";
|
|
3
|
+
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
4
|
+
import { SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
5
|
+
import { Db, RawLane } from "@prisma/orm-family-sql/builder/types";
|
|
6
|
+
import "@prisma/orm-family-sql/relational-core/expression";
|
|
7
|
+
//#region ../../../3-extensions/postgres/dist/postgres-static-Q_C_AoOf.d.mts
|
|
8
|
+
//#region src/runtime/native-enums.d.ts
|
|
9
|
+
declare function buildNamespacedNativeEnums(storage: SqlStorage): Record<string, Record<string, EnumAccessor>>;
|
|
10
|
+
type Present<T> = Exclude<T, undefined>;
|
|
11
|
+
type NamespaceValueSetEntries<TNs> = TNs extends {
|
|
12
|
+
readonly entries: {
|
|
13
|
+
readonly valueSet?: infer E;
|
|
14
|
+
};
|
|
15
|
+
} ? unknown extends E ? Record<never, never> : Present<E> : Record<never, never>;
|
|
16
|
+
type ValueSetEntry = {
|
|
17
|
+
readonly values: readonly unknown[];
|
|
18
|
+
};
|
|
19
|
+
type ValueSetMembers<Values extends readonly unknown[]> = { readonly [I in keyof Values]: {
|
|
20
|
+
readonly name: Extract<Values[I], string>;
|
|
21
|
+
readonly value: Values[I];
|
|
22
|
+
}; };
|
|
23
|
+
/**
|
|
24
|
+
* Projects a value-only `StorageValueSet`-shaped literal type onto the
|
|
25
|
+
* `{name, value}[]`-member shape `ContractEnumAccessor` expects, treating
|
|
26
|
+
* each value as its own name (Option B: a native-enum member is a value, not
|
|
27
|
+
* a name→value pair).
|
|
28
|
+
*/
|
|
29
|
+
type ValueSetToEnumEntry<Entry extends ValueSetEntry> = {
|
|
30
|
+
readonly members: ValueSetMembers<Entry['values']>;
|
|
31
|
+
};
|
|
32
|
+
type ValueSetEntriesToEnumEntries<Entries> = { readonly [K in keyof Entries]: Entries[K] extends ValueSetEntry ? ValueSetToEnumEntry<Entries[K]> : never; };
|
|
33
|
+
/**
|
|
34
|
+
* Accessor type for `db.nativeEnums`. Types off the namespace's `valueSet`
|
|
35
|
+
* entries — the same generic surface that types `db.enums` and column value
|
|
36
|
+
* unions — not a raw `native_enum` entity slot; `contract.d.ts` no longer
|
|
37
|
+
* emits one. For a no-emit (`typeof contract`) contract the storage type is
|
|
38
|
+
* non-literal and this degrades to the structural shape — the same
|
|
39
|
+
* emit/no-emit boundary column typing has (TML-2960).
|
|
40
|
+
*/
|
|
41
|
+
type NamespacedNativeEnums<TContract extends Contract> = { readonly [Ns in keyof TContract['storage']['namespaces']]: EnumEntriesToAccessors<ValueSetEntriesToEnumEntries<NamespaceValueSetEntries<TContract['storage']['namespaces'][Ns]>>>; };
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/runtime/postgres-target-id.d.ts
|
|
44
|
+
type PostgresTargetId = 'postgres';
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/static/postgres-static.d.ts
|
|
47
|
+
interface PostgresStaticContext<TContract extends Contract<SqlStorage>> {
|
|
48
|
+
readonly context: ExecutionContext<TContract>;
|
|
49
|
+
readonly contract: TContract;
|
|
50
|
+
readonly enums: NamespacedEnums<TContract>;
|
|
51
|
+
readonly nativeEnums: NamespacedNativeEnums<TContract>;
|
|
52
|
+
readonly sql: Db<TContract>;
|
|
53
|
+
readonly raw: RawLane<TContract>;
|
|
54
|
+
}
|
|
55
|
+
declare function postgresStatic<TContract extends Contract<SqlStorage>>(options: {
|
|
56
|
+
readonly contractJson: unknown;
|
|
57
|
+
readonly extensions?: readonly SqlRuntimeExtensionDescriptor<PostgresTargetId>[];
|
|
58
|
+
}): PostgresStaticContext<TContract>;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { postgresStatic as a, buildNamespacedNativeEnums as i, PostgresStaticContext as n, PostgresTargetId as r, NamespacedNativeEnums as t };
|
|
61
|
+
//# sourceMappingURL=postgres-static-Q_C_AoOf-DNC79LUR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-static-Q_C_AoOf-DNC79LUR.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-static-Q_C_AoOf.d.mts"],"mappings":";;;;;;;;iBAOiB,2BAA2B,SAAS,aAAa,eAAe,eAAe;KAC3F,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,uBAAuB,WAAW,UAAU,QAAQ,WAAW,gBAAgB,oBAAoB,QAAQ;;;;;;;;;KASxI,sBAAsB,kBAAkB,wBAAwB,YAAY,qCAAqC,uBAAuB,6BAA6B,yBAAyB,mCAAmC;;;KAGjO;;;UAGK,sBAAsB,kBAAkB,SAAS;WAChD,SAAS,iBAAiB;WAC1B,UAAU;WACV,OAAO,gBAAgB;WACvB,aAAa,sBAAsB;WACnC,KAAK,GAAG;WACR,KAAK,QAAQ;;iBAEP,eAAe,kBAAkB,SAAS,aAAa;WAC7D;WACA,sBAAsB,8BAA8B;IAC3D,sBAAsB"}
|
package/dist/{postgres-static-KmLmp8vV-qgkhJAEz.mjs → postgres-static-zqQ1nDxl-CTre64NI.mjs}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PG_ENUM_CODEC_ID } from "@prisma/orm-target-postgres/target/codec-ids";
|
|
2
2
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
|
-
import { buildNamespacedEnums, createEnumAccessor } from "@prisma/orm-framework/contract/enum-accessor";
|
|
4
|
-
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
5
|
-
import { createRawLane, sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
6
3
|
import { createExecutionContext, createSqlExecutionStack } from "@prisma/orm-family-sql/runtime";
|
|
7
4
|
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
8
|
-
|
|
5
|
+
import { createRawLane, sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
6
|
+
import { buildNamespacedEnums, createEnumAccessor } from "@prisma/orm-framework/contract/enum-accessor";
|
|
7
|
+
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
8
|
+
//#region ../../../3-extensions/postgres/dist/postgres-static-zqQ1nDxl.mjs
|
|
9
9
|
/**
|
|
10
10
|
* Reads the namespace's `valueSet` entries directly off the plain contract
|
|
11
11
|
* shape (`storage.namespaces[id].entries.valueSet`), not through a hydrated
|
|
@@ -73,4 +73,4 @@ function postgresStatic(options) {
|
|
|
73
73
|
//#endregion
|
|
74
74
|
export { buildPostgresStaticContext as n, postgresStatic as r, buildNamespacedNativeEnums as t };
|
|
75
75
|
|
|
76
|
-
//# sourceMappingURL=postgres-static-
|
|
76
|
+
//# sourceMappingURL=postgres-static-zqQ1nDxl-CTre64NI.mjs.map
|
package/dist/{postgres-static-KmLmp8vV-qgkhJAEz.mjs.map → postgres-static-zqQ1nDxl-CTre64NI.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-static-
|
|
1
|
+
{"version":3,"file":"postgres-static-zqQ1nDxl-CTre64NI.mjs","names":[],"sources":["../../../../3-extensions/postgres/dist/postgres-static-zqQ1nDxl.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* Reads the namespace's `valueSet` entries directly off the plain contract\n* shape (`storage.namespaces[id].entries.valueSet`), not through a hydrated\n* `PostgresSchema` class instance — the same plain-data path `db.enums`\n* reads `domain.namespaces[id].enum` through. Works on a `validateContract`'d\n* JSON contract as well as one produced by `PostgresContractSerializer`.\n*\n* A native enum is never re-emitted as its own entity: once `native_enum` is\n* lowered, its member values live on in the `valueSet` entry it derives (the\n* SQL family's generic `deriveValueSet` mechanism) — the same slot\n* `column.valueSet`-typed columns read. A member is a value, not a\n* name→value pair (matching `CREATE TYPE … AS ENUM ('a', 'b')`), so each\n* value doubles as its own accessor name.\n*/\nfunction buildNativeEnumsMapForNamespace(storage, namespaceId) {\n\tconst result = {};\n\tconst valueSets = storage.namespaces[namespaceId]?.entries.valueSet;\n\tif (!valueSets) return result;\n\tfor (const [name, valueSet] of Object.entries(valueSets)) result[name] = createEnumAccessor({\n\t\tcodecId: PG_ENUM_CODEC_ID,\n\t\tmembers: valueSet.values.map((value) => ({\n\t\t\tname: String(value),\n\t\t\tvalue\n\t\t}))\n\t});\n\treturn result;\n}\nfunction buildNamespacedNativeEnums(storage) {\n\tconst result = {};\n\tfor (const namespaceId of Object.keys(storage.namespaces)) result[namespaceId] = buildNativeEnumsMapForNamespace(storage, 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));\n\tconst nativeEnums = blindCast(Object.freeze(buildNamespacedNativeEnums(context.contract.storage)));\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-zqQ1nDxl.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gCAAgC,SAAS,aAAa;CAC9D,MAAM,SAAS,CAAC;CAChB,MAAM,YAAY,QAAQ,WAAW,YAAY,EAAE,QAAQ;CAC3D,IAAI,CAAC,WAAW,OAAO;CACvB,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,GAAG,OAAO,QAAQ,mBAAmB;EAC3F,SAAS;EACT,SAAS,SAAS,OAAO,KAAK,WAAW;GACxC,MAAM,OAAO,KAAK;GAClB;EACD,EAAE;CACH,CAAC;CACD,OAAO;AACR;AACA,SAAS,2BAA2B,SAAS;CAC5C,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,eAAe,OAAO,KAAK,QAAQ,UAAU,GAAG,OAAO,eAAe,gCAAgC,SAAS,WAAW;CACrI,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,MAAM,CAAC;CACzE,MAAM,cAAc,UAAU,OAAO,OAAO,2BAA2B,QAAQ,SAAS,OAAO,CAAC,CAAC;CACjG,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"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,8 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as buildNamespacedNativeEnums, t as NamespacedNativeEnums } from "./postgres-static-Q_C_AoOf-DNC79LUR.mjs";
|
|
2
|
+
import { a as PostgresStaticMembers, i as PostgresRuntimeBoundMembers, n as PostgresExecutionOptions, r as PostgresLifecycleMembers, t as PostgresCursorOptions } from "./postgres-options-2XQhW8Fe-C3jEHTDJ.mjs";
|
|
2
3
|
import { Runtime, SqlRuntimeBase } from "@prisma/orm-family-sql/runtime";
|
|
4
|
+
import { Client, Pool } from "pg";
|
|
3
5
|
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
4
6
|
import { SqlStorage } from "@prisma/orm-family-sql/contract/types";
|
|
5
7
|
//#region ../../../3-extensions/postgres/dist/runtime.d.mts
|
|
8
|
+
//#region src/runtime/binding.d.ts
|
|
9
|
+
declare const isPgPool: (pg: Pool | Client) => pg is Pool;
|
|
10
|
+
declare const isPgClient: (pg: Pool | Client) => pg is Client;
|
|
11
|
+
type PostgresBinding = {
|
|
12
|
+
readonly kind: 'url';
|
|
13
|
+
readonly url: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'pgPool';
|
|
16
|
+
readonly pool: Pool;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'pgClient';
|
|
19
|
+
readonly client: Client;
|
|
20
|
+
};
|
|
21
|
+
type PostgresBindingInput = {
|
|
22
|
+
readonly binding: PostgresBinding;
|
|
23
|
+
readonly url?: never;
|
|
24
|
+
readonly pg?: never;
|
|
25
|
+
} | {
|
|
26
|
+
readonly url: string;
|
|
27
|
+
readonly binding?: never;
|
|
28
|
+
readonly pg?: never;
|
|
29
|
+
} | {
|
|
30
|
+
readonly pg: Pool | Client;
|
|
31
|
+
readonly binding?: never;
|
|
32
|
+
readonly url?: never;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/runtime/postgres.d.ts
|
|
36
|
+
interface PostgresClient<TContract extends Contract<SqlStorage>> extends PostgresStaticMembers<TContract>, PostgresRuntimeBoundMembers<TContract>, PostgresLifecycleMembers {
|
|
37
|
+
connect(bindingInput?: PostgresBindingInput): Promise<Runtime>;
|
|
38
|
+
}
|
|
39
|
+
interface PostgresOptionsBase extends PostgresExecutionOptions {
|
|
40
|
+
readonly poolOptions?: {
|
|
41
|
+
readonly connectionTimeoutMillis?: number;
|
|
42
|
+
readonly idleTimeoutMillis?: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface PostgresBindingOptions {
|
|
46
|
+
readonly binding?: PostgresBinding;
|
|
47
|
+
readonly url?: string;
|
|
48
|
+
readonly pg?: Pool | Client;
|
|
49
|
+
}
|
|
50
|
+
type PostgresOptionsWithContract<TContract extends Contract<SqlStorage>> = PostgresBindingOptions & PostgresOptionsBase & {
|
|
51
|
+
readonly contract: TContract;
|
|
52
|
+
readonly contractJson?: never;
|
|
53
|
+
};
|
|
54
|
+
type PostgresOptionsWithContractJson<TContract extends Contract<SqlStorage>> = PostgresBindingOptions & PostgresOptionsBase & {
|
|
55
|
+
readonly contractJson: unknown;
|
|
56
|
+
readonly contract?: never;
|
|
57
|
+
readonly _contract?: TContract;
|
|
58
|
+
};
|
|
59
|
+
type PostgresOptions<TContract extends Contract<SqlStorage>> = PostgresOptionsWithContract<TContract> | PostgresOptionsWithContractJson<TContract>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a lazy Postgres client from either `contractJson` or a TypeScript-authored `contract`.
|
|
62
|
+
* Static query surfaces are available immediately, while `runtime()` instantiates the driver/pool on first call.
|
|
63
|
+
*
|
|
64
|
+
* - No-emit: pass a TypeScript-authored contract. Example: postgres({ contract })
|
|
65
|
+
* - Emitted: pass Contract type explicitly. Example: postgres<Contract>({ contractJson, url })
|
|
66
|
+
*/
|
|
67
|
+
declare function postgres<TContract extends Contract<SqlStorage>>(options: PostgresOptionsWithContract<TContract>): PostgresClient<TContract>;
|
|
68
|
+
declare function postgres<TContract extends Contract<SqlStorage>>(options: PostgresOptionsWithContractJson<TContract>): PostgresClient<TContract>;
|
|
69
|
+
//#endregion
|
|
6
70
|
//#region src/runtime/postgres-runtime.d.ts
|
|
7
71
|
/**
|
|
8
72
|
* The Postgres runtime interface. App code depends on this — `postgres()` returns it
|
|
@@ -17,5 +81,5 @@ declare class PostgresRuntimeImpl<TContract extends Contract<SqlStorage> = Contr
|
|
|
17
81
|
protected getListDecoder(): PostgresListDecoder;
|
|
18
82
|
}
|
|
19
83
|
//#endregion
|
|
20
|
-
export { type NamespacedNativeEnums, type PostgresBinding, type PostgresClient, type PostgresOptions, type PostgresOptionsBase, type PostgresOptionsWithContract, type PostgresOptionsWithContractJson, type PostgresRuntime, PostgresRuntimeImpl, buildNamespacedNativeEnums, postgres as default, isPgClient, isPgPool };
|
|
84
|
+
export { type NamespacedNativeEnums, type PostgresBinding, type PostgresClient, type PostgresCursorOptions, type PostgresOptions, type PostgresOptionsBase, type PostgresOptionsWithContract, type PostgresOptionsWithContractJson, type PostgresRuntime, PostgresRuntimeImpl, buildNamespacedNativeEnums, postgres as default, isPgClient, isPgPool };
|
|
21
85
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-extensions/postgres/dist/runtime.d.mts"],"mappings":";;;;;;;;cAOc,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,4BAA4B,kBAAkB,SAAS,eAAe,yBAAyB;WACzF,UAAU;WACV;;KAEN,gCAAgC,kBAAkB,SAAS,eAAe,yBAAyB;WAC7F;WACA;WACA,YAAY;;KAElB,gBAAgB,kBAAkB,SAAS,eAAe,4BAA4B,aAAa,gCAAgC;;;;;;;;iBAQvH,SAAS,kBAAkB,SAAS,aAAa,SAAS,4BAA4B,aAAa,eAAe;iBAClH,SAAS,kBAAkB,SAAS,aAAa,SAAS,gCAAgC,aAAa,eAAe;;;;;;;;;;UAU7H,wBAAwB;KAC7B,uBAAuB,oBAAoB,gBAAgB,mBAAmB,qBAAqB;cAC1F,oBAAoB,kBAAkB,SAAS,cAAc,SAAS,qBAAqB,eAAe;YAC5G,kBAAkB"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,77 +1,15 @@
|
|
|
1
1
|
import { t as postgresError } from "./errors-DfWK9xep-CYOOg0sB.mjs";
|
|
2
|
-
import { n as
|
|
3
|
-
import { t as
|
|
4
|
-
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
2
|
+
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-CYEen60e-CEkW4u-S.mjs";
|
|
3
|
+
import { n as buildPostgresStaticContext, t as buildNamespacedNativeEnums } from "./postgres-static-zqQ1nDxl-CTre64NI.mjs";
|
|
5
4
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
6
|
-
import { blindCast
|
|
7
|
-
import
|
|
8
|
-
import { sql } from "@prisma/orm-family-sql/builder/runtime";
|
|
9
|
-
import { createExecutionContext, createSqlExecutionStack, withTransaction } from "@prisma/orm-family-sql/runtime";
|
|
5
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
6
|
+
import { createExecutionContext, createSqlExecutionStack } from "@prisma/orm-family-sql/runtime";
|
|
10
7
|
import postgresTarget, { PostgresContractSerializer } from "@prisma/orm-target-postgres/target/runtime";
|
|
8
|
+
import postgresAdapter from "@prisma/orm-target-postgres/adapter/runtime";
|
|
11
9
|
import postgresDriver, { suppressIdleConnectionErrors } from "@prisma/orm-target-postgres/driver/runtime";
|
|
12
10
|
import { instantiateExecutionStack } from "@prisma/orm-framework/components/execution";
|
|
13
|
-
import { orm, prepareQuery } from "@prisma/orm-family-sql/orm-client";
|
|
14
11
|
import { Pool } from "pg";
|
|
15
12
|
//#region ../../../3-extensions/postgres/dist/runtime.mjs
|
|
16
|
-
const isPgPool = (pg) => "totalCount" in pg && "idleCount" in pg && "waitingCount" in pg;
|
|
17
|
-
const isPgClient = (pg) => "escapeIdentifier" in pg && "escapeLiteral" in pg;
|
|
18
|
-
function validatePostgresUrl(url) {
|
|
19
|
-
const trimmed = url.trim();
|
|
20
|
-
if (trimmed.length === 0) throw postgresError("RUNTIME.BINDING_INVALID", "Postgres URL must be a non-empty string", { meta: {
|
|
21
|
-
extension: "postgres",
|
|
22
|
-
reason: "empty url"
|
|
23
|
-
} });
|
|
24
|
-
let parsed;
|
|
25
|
-
try {
|
|
26
|
-
parsed = new URL(trimmed);
|
|
27
|
-
} catch {
|
|
28
|
-
throw postgresError("RUNTIME.BINDING_INVALID", "Postgres URL must be a valid URL", { meta: {
|
|
29
|
-
extension: "postgres",
|
|
30
|
-
reason: "unparseable url"
|
|
31
|
-
} });
|
|
32
|
-
}
|
|
33
|
-
if (parsed.protocol !== "postgres:" && parsed.protocol !== "postgresql:") throw postgresError("RUNTIME.BINDING_INVALID", "Postgres URL must use postgres:// or postgresql://", { meta: {
|
|
34
|
-
extension: "postgres",
|
|
35
|
-
reason: "wrong scheme",
|
|
36
|
-
received: parsed.protocol
|
|
37
|
-
} });
|
|
38
|
-
return trimmed;
|
|
39
|
-
}
|
|
40
|
-
function resolvePostgresBinding(options) {
|
|
41
|
-
if (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", {
|
|
42
|
-
fix: "Pass exactly one of `binding`, `url`, or `pg`.",
|
|
43
|
-
meta: {
|
|
44
|
-
extension: "postgres",
|
|
45
|
-
reason: "zero or multiple binding inputs"
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
if (options.binding !== void 0) return options.binding;
|
|
49
|
-
if (options.url !== void 0) return {
|
|
50
|
-
kind: "url",
|
|
51
|
-
url: validatePostgresUrl(options.url)
|
|
52
|
-
};
|
|
53
|
-
const pgBinding = options.pg;
|
|
54
|
-
if (pgBinding === void 0) throw new InternalError("Invariant violation: expected pg binding after validation");
|
|
55
|
-
if (isPgPool(pgBinding)) return {
|
|
56
|
-
kind: "pgPool",
|
|
57
|
-
pool: pgBinding
|
|
58
|
-
};
|
|
59
|
-
if (isPgClient(pgBinding)) return {
|
|
60
|
-
kind: "pgClient",
|
|
61
|
-
client: pgBinding
|
|
62
|
-
};
|
|
63
|
-
throw postgresError("RUNTIME.BINDING_INVALID", "Unable to determine pg binding type from pg input; use binding with explicit kind", {
|
|
64
|
-
fix: "Pass `binding: { kind: \"pgPool\", pool }` or `binding: { kind: \"pgClient\", client }` instead of `pg`.",
|
|
65
|
-
meta: {
|
|
66
|
-
extension: "postgres",
|
|
67
|
-
reason: "unrecognizable pg object"
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function resolveOptionalPostgresBinding(options) {
|
|
72
|
-
if (Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.pg !== void 0) === 0) return;
|
|
73
|
-
return resolvePostgresBinding(blindCast(options));
|
|
74
|
-
}
|
|
75
13
|
function hasContractJson(options) {
|
|
76
14
|
return "contractJson" in options;
|
|
77
15
|
}
|
|
@@ -92,6 +30,7 @@ function toRuntimeBinding(binding, options) {
|
|
|
92
30
|
};
|
|
93
31
|
}
|
|
94
32
|
function postgres(options) {
|
|
33
|
+
const cursor = validateCursorOptions(options.cursor, "postgres");
|
|
95
34
|
const contract = resolveContract(options);
|
|
96
35
|
let binding = resolveOptionalPostgresBinding(options);
|
|
97
36
|
const stack = createSqlExecutionStack({
|
|
@@ -105,7 +44,7 @@ function postgres(options) {
|
|
|
105
44
|
stack,
|
|
106
45
|
driver: postgresDriver
|
|
107
46
|
});
|
|
108
|
-
const { sql
|
|
47
|
+
const { sql, raw: rawSqlTag, enums, nativeEnums } = buildPostgresStaticContext(context, stack.adapter.rawCodecInferer);
|
|
109
48
|
let runtimeInstance;
|
|
110
49
|
let runtimeDriver;
|
|
111
50
|
let driverConnected = false;
|
|
@@ -148,38 +87,26 @@ function postgres(options) {
|
|
|
148
87
|
const stackInstance = instantiateExecutionStack(stack);
|
|
149
88
|
const driverDescriptor = stack.driver;
|
|
150
89
|
if (!driverDescriptor) throw new InternalError("Driver descriptor missing from execution stack");
|
|
151
|
-
const driver = driverDescriptor.create({ cursor:
|
|
90
|
+
const driver = driverDescriptor.create({ cursor: toDriverCursorOptions(cursor) });
|
|
152
91
|
runtimeDriver = driver;
|
|
153
92
|
if (binding !== void 0) connectDriver(binding).catch(() => void 0);
|
|
154
93
|
runtimeInstance = new PostgresRuntimeImpl({
|
|
155
94
|
context,
|
|
156
95
|
adapter: stackInstance.adapter,
|
|
157
96
|
driver,
|
|
158
|
-
...
|
|
159
|
-
...ifDefined("middleware", options.middleware)
|
|
97
|
+
...toRuntimeOptions(options)
|
|
160
98
|
});
|
|
161
99
|
return runtimeInstance;
|
|
162
100
|
};
|
|
163
|
-
const orm$1 = orm({
|
|
164
|
-
runtime: {
|
|
165
|
-
query(plan) {
|
|
166
|
-
return getRuntime().query(plan);
|
|
167
|
-
},
|
|
168
|
-
execute(plan) {
|
|
169
|
-
return getRuntime().execute(plan);
|
|
170
|
-
},
|
|
171
|
-
connection() {
|
|
172
|
-
return getRuntime().connection();
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
context
|
|
176
|
-
});
|
|
177
|
-
function prepare(declaration, callback) {
|
|
178
|
-
return prepareQuery(getRuntime(), declaration, callback);
|
|
179
|
-
}
|
|
180
101
|
return {
|
|
181
|
-
sql
|
|
182
|
-
|
|
102
|
+
sql,
|
|
103
|
+
...buildPostgresRuntimeBoundMembers({
|
|
104
|
+
context,
|
|
105
|
+
rawCodecInferer: stack.adapter.rawCodecInferer,
|
|
106
|
+
enums,
|
|
107
|
+
nativeEnums,
|
|
108
|
+
getRuntime
|
|
109
|
+
}),
|
|
183
110
|
enums,
|
|
184
111
|
nativeEnums,
|
|
185
112
|
raw: rawSqlTag,
|
|
@@ -203,36 +130,6 @@ function postgres(options) {
|
|
|
203
130
|
await connectDriver(binding);
|
|
204
131
|
return runtime;
|
|
205
132
|
},
|
|
206
|
-
runtime() {
|
|
207
|
-
return getRuntime();
|
|
208
|
-
},
|
|
209
|
-
prepare,
|
|
210
|
-
transaction(fn) {
|
|
211
|
-
return withTransaction(getRuntime(), (txCtx) => {
|
|
212
|
-
const rawCodecInferer = stack.adapter.rawCodecInferer;
|
|
213
|
-
const txSql = sql({
|
|
214
|
-
context,
|
|
215
|
-
rawCodecInferer
|
|
216
|
-
});
|
|
217
|
-
const txOrm = orm({
|
|
218
|
-
runtime: {
|
|
219
|
-
query(plan) {
|
|
220
|
-
return txCtx.query(plan);
|
|
221
|
-
},
|
|
222
|
-
execute(plan) {
|
|
223
|
-
return txCtx.execute(plan);
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
context
|
|
227
|
-
});
|
|
228
|
-
return fn(Object.assign(castAs(Object.create(txCtx)), {
|
|
229
|
-
sql: txSql,
|
|
230
|
-
orm: txOrm,
|
|
231
|
-
enums,
|
|
232
|
-
nativeEnums
|
|
233
|
-
}));
|
|
234
|
-
});
|
|
235
|
-
},
|
|
236
133
|
async close() {
|
|
237
134
|
if (closed) return;
|
|
238
135
|
closed = true;
|