@prisma/orm-postgres 8.0.0-rc.23-dev.13 → 8.0.0-rc.24-dev.1

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.
Files changed (48) hide show
  1. package/dist/{binding-BilWdtbO-DQOnbc6i.d.mts → binding-BN5X69gf-CIDnIWcw.d.mts} +3 -3
  2. package/dist/{binding-BilWdtbO-DQOnbc6i.d.mts.map → binding-BN5X69gf-CIDnIWcw.d.mts.map} +1 -1
  3. package/dist/{binding-DgumIe5f-BPV5_73g.mjs → binding-DkfRsUZE-Co5ssUZw.mjs} +4 -29
  4. package/dist/binding-DkfRsUZE-Co5ssUZw.mjs.map +1 -0
  5. package/dist/contract-builder.d.mts +2 -2
  6. package/dist/contract-builder.d.mts.map +1 -1
  7. package/dist/{contract-from-json-ClLoxky7-BbmbxtVO.mjs → contract-from-json-D1F9kILp-DTraX6wO.mjs} +3 -3
  8. package/dist/contract-from-json-D1F9kILp-DTraX6wO.mjs.map +1 -0
  9. package/dist/internal__options.d.mts +3 -3
  10. package/dist/internal__options.mjs +3 -2
  11. package/dist/internal__static-context.mjs +1 -1
  12. package/dist/internal__transaction-members.d.mts +1 -1
  13. package/dist/internal__transaction-members.mjs +1 -1
  14. package/dist/internal__validate-contract.mjs +1 -1
  15. package/dist/{postgres-members-Bwcngc1q-HwIhD-Fq.mjs → postgres-members-B7ZvxGYc-D_L3NVGm.mjs} +11 -4
  16. package/dist/postgres-members-B7ZvxGYc-D_L3NVGm.mjs.map +1 -0
  17. package/dist/{postgres-members-C-tRvikK-CCXnwtJ2.d.mts → postgres-members-F9CVSrrN-BFAuNPbW.d.mts} +4 -3
  18. package/dist/postgres-members-F9CVSrrN-BFAuNPbW.d.mts.map +1 -0
  19. package/dist/{postgres-options-BmYdDr4L-Dir2eRdu.d.mts → postgres-options-B0YrJID9-YkuL0Mao.d.mts} +10 -3
  20. package/dist/postgres-options-B0YrJID9-YkuL0Mao.d.mts.map +1 -0
  21. package/dist/postgres-options-CZyV9Him-2OSYJKqo.mjs +51 -0
  22. package/dist/postgres-options-CZyV9Him-2OSYJKqo.mjs.map +1 -0
  23. package/dist/{postgres-static-D8VZSxOQ-CGls_F3g.mjs → postgres-static-DEqSWtE1-DAPwV7Ep.mjs} +3 -3
  24. package/dist/{postgres-static-D8VZSxOQ-CGls_F3g.mjs.map → postgres-static-DEqSWtE1-DAPwV7Ep.mjs.map} +1 -1
  25. package/dist/runtime.d.mts +5 -4
  26. package/dist/runtime.d.mts.map +1 -1
  27. package/dist/runtime.mjs +10 -7
  28. package/dist/runtime.mjs.map +1 -1
  29. package/dist/serverless.d.mts +4 -3
  30. package/dist/serverless.d.mts.map +1 -1
  31. package/dist/serverless.mjs +10 -7
  32. package/dist/serverless.mjs.map +1 -1
  33. package/dist/static.mjs +2 -2
  34. package/package.json +8 -8
  35. package/skills/prisma-8/SKILL.md +1 -1
  36. package/skills/prisma-8/references/contract.md +3 -1
  37. package/skills/prisma-8/references/migrations.md +5 -3
  38. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +319 -0
  39. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
  40. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
  41. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +304 -0
  42. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
  43. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
  44. package/dist/binding-DgumIe5f-BPV5_73g.mjs.map +0 -1
  45. package/dist/contract-from-json-ClLoxky7-BbmbxtVO.mjs.map +0 -1
  46. package/dist/postgres-members-Bwcngc1q-HwIhD-Fq.mjs.map +0 -1
  47. package/dist/postgres-members-C-tRvikK-CCXnwtJ2.d.mts.map +0 -1
  48. package/dist/postgres-options-BmYdDr4L-Dir2eRdu.d.mts.map +0 -1
@@ -0,0 +1,621 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Rewrites the removed MongoDB field helpers of TypeScript contracts to `field.scalar(type.X())`: `field.objectId()` becomes `field.scalar(type.ObjectId())`, `field.scalar('mongo/string@1')` becomes `field.scalar(type.String())`, and `field.vector({ typeParams: { length: 3 } })` becomes `field.scalar(type.Vector(3))`.
4
+ *
5
+ * It rewrites a call only where its `field` is the MongoDB builder's: imported or required from a MongoDB contract builder entry under any name, destructured from the helpers of a `defineContract` imported from one, or read as `helpers.field` from them, which becomes `helpers.field.scalar(helpers.type.Int32())`. Where a rewritten call reads `type` by itself, the script adds `type` to the import or destructuring that gives the call its `field`. A `field` of another builder, such as a SQL `defineContract`'s, is left alone.
6
+ *
7
+ * Usage: node rewrite-mongo-field-types.ts [file or directory ...]
8
+ *
9
+ * The paths default to the working directory. In a directory the script reads every TypeScript and JavaScript file outside `node_modules`, `.git`, `dist` and `build`. It rewrites only code: comments and strings stay as they are, and the contract each file builds does not change. It reads the files with the `typescript` package of the project, or of the folder the script is in. It prints one line per file it changes, and one line per call it leaves for a person: a call it cannot carry over, such as a codec id with no type constructor; a call where `type` already names another value; and a removed helper called on a `field` it cannot tell is the MongoDB builder's, such as one imported from a module of the project.
10
+ */
11
+ import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
12
+ import { createRequire } from 'node:module';
13
+ import { join, relative } from 'node:path';
14
+ import type * as TypeScript from 'typescript';
15
+
16
+ const SKIPPED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', 'build']);
17
+ const SOURCE_FILE = /\.(?:[cm]?ts|tsx|[cm]?js|jsx)$/;
18
+ const BUILDER_MODULE =
19
+ /^(?:@prisma\/orm-mongo|@prisma\/orm-family-mongo\/contract-ts|@internal\/mongo|@internal\/mongo-contract-ts)\/contract-builder$/;
20
+ const TYPE_EXPORTING_MODULE = /^(?:@prisma\/orm-mongo|@internal\/mongo)\/contract-builder$/;
21
+ const WRITE_BY_HAND = 'write it as field.scalar(type.X(...))';
22
+ const WRITE_BY_HAND_IF_MONGO =
23
+ 'if it is, write it as field.scalar(type.X(...)), and if not, leave it';
24
+ const UNKNOWN: Origin = {
25
+ kind: 'unknown',
26
+ reason: "the script cannot tell this field is the MongoDB builder's",
27
+ };
28
+
29
+ const TYPE_OF_HELPER: Readonly<Record<string, string>> = {
30
+ objectId: 'ObjectId',
31
+ string: 'String',
32
+ double: 'Double',
33
+ int32: 'Int32',
34
+ bool: 'Bool',
35
+ date: 'DateTime',
36
+ int64: 'Int64',
37
+ int64Number: 'Int64Number',
38
+ decimal128: 'Decimal128',
39
+ binary: 'Binary',
40
+ json: 'Json',
41
+ bson: 'Bson',
42
+ vector: 'Vector',
43
+ };
44
+
45
+ const TYPE_OF_CODEC: Readonly<Record<string, string>> = Object.fromEntries(
46
+ Object.entries(TYPE_OF_HELPER).map(([helper, typeName]) => [`mongo/${helper}@1`, typeName]),
47
+ );
48
+
49
+ function loadTypeScript(): typeof TypeScript {
50
+ for (const from of [join(process.cwd(), 'package.json'), import.meta.url]) {
51
+ try {
52
+ return createRequire(from)('typescript');
53
+ } catch {}
54
+ }
55
+ console.error(
56
+ 'The script reads files with the "typescript" package, which this project does not have. Install it, for example with "pnpm add -D typescript", and run the script again.',
57
+ );
58
+ process.exit(1);
59
+ }
60
+
61
+ const ts = loadTypeScript();
62
+
63
+ interface Edit {
64
+ readonly start: number;
65
+ readonly end: number;
66
+ readonly text: string;
67
+ }
68
+
69
+ /** What a name binds `field` to: the MongoDB builder's, another builder's, or something the script cannot tell. */
70
+ type Origin =
71
+ | {
72
+ readonly kind: 'mongo';
73
+ /** The `type` the rewritten call reads, such as `type` or `helpers.type`. */
74
+ readonly typeText: string;
75
+ /** Adds `type` beside the `field` binding, once; undefined when the rewrite reads a `type` already there. */
76
+ readonly bind: (() => void) | undefined;
77
+ /** The declaration of the `type` this origin reads or adds, which is not a conflict. */
78
+ readonly ownType: TypeScript.Node | undefined;
79
+ }
80
+ | { readonly kind: 'other' }
81
+ | { readonly kind: 'unknown'; readonly reason: string };
82
+
83
+ /** A binding of a name and the code it reaches. */
84
+ interface Scoped<Value> {
85
+ readonly value: Value;
86
+ readonly scope: TypeScript.Node;
87
+ }
88
+
89
+ interface FileResult {
90
+ readonly text: string;
91
+ readonly rewritten: number;
92
+ readonly reports: readonly string[];
93
+ }
94
+
95
+ function moduleOf(node: TypeScript.Node): string | undefined {
96
+ if (ts.isImportDeclaration(node)) {
97
+ return ts.isStringLiteral(node.moduleSpecifier) ? node.moduleSpecifier.text : undefined;
98
+ }
99
+ if (
100
+ ts.isCallExpression(node) &&
101
+ ts.isIdentifier(node.expression) &&
102
+ node.expression.text === 'require' &&
103
+ node.arguments.length === 1
104
+ ) {
105
+ const [specifier] = node.arguments;
106
+ return specifier !== undefined && ts.isStringLiteralLike(specifier)
107
+ ? specifier.text
108
+ : undefined;
109
+ }
110
+ return undefined;
111
+ }
112
+
113
+ function propertyNameOf(element: TypeScript.BindingElement | TypeScript.ImportSpecifier) {
114
+ const name = element.propertyName ?? element.name;
115
+ return ts.isIdentifier(name) || ts.isStringLiteral(name) ? name.text : undefined;
116
+ }
117
+
118
+ /** The code a declaration reaches: a parameter's function, an import's file, and otherwise the nearest block. */
119
+ function scopeOf(declaration: TypeScript.Node): TypeScript.Node {
120
+ let node: TypeScript.Node = declaration;
121
+ while (
122
+ ts.isBindingElement(node) ||
123
+ ts.isObjectBindingPattern(node) ||
124
+ ts.isArrayBindingPattern(node)
125
+ ) {
126
+ node = node.parent;
127
+ }
128
+ if (ts.isParameter(node)) return node.parent;
129
+ if (
130
+ (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) &&
131
+ node.parent !== undefined
132
+ ) {
133
+ node = node.parent;
134
+ }
135
+ while (
136
+ !ts.isBlock(node) &&
137
+ !ts.isSourceFile(node) &&
138
+ !ts.isCaseClause(node) &&
139
+ !ts.isFunctionLike(node) &&
140
+ node.parent !== undefined
141
+ ) {
142
+ node = node.parent;
143
+ }
144
+ return node;
145
+ }
146
+
147
+ function rewrite(file: TypeScript.SourceFile): FileResult {
148
+ const edits: Edit[] = [];
149
+ const reports: string[] = [];
150
+ const fields = new Map<string, Scoped<Origin>[]>();
151
+ const helpersObjects = new Map<string, Scoped<'mongo' | 'other'>[]>();
152
+ const typeDeclarations: Scoped<TypeScript.Node>[] = [];
153
+ const mongoDefines = new Set<string>();
154
+ const otherDefines = new Set<string>();
155
+ const mongoNamespaces = new Map<string, string>();
156
+ const knownPatterns = new Set<TypeScript.Node>();
157
+ const constantStrings = new Map<string, Scoped<string>[]>();
158
+ const namesBuilder =
159
+ file.statements.some((statement) => {
160
+ const module = ts.isImportDeclaration(statement) ? moduleOf(statement) : undefined;
161
+ return module !== undefined && BUILDER_MODULE.test(module);
162
+ }) ||
163
+ /require\(\s*['"](?:@prisma\/orm-mongo|@prisma\/orm-family-mongo\/contract-ts|@internal\/mongo|@internal\/mongo-contract-ts)\/contract-builder['"]\s*\)/.test(
164
+ file.text,
165
+ );
166
+ let rewritten = 0;
167
+
168
+ const report = (node: TypeScript.Node, why: string, advice = WRITE_BY_HAND) => {
169
+ const line = file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1;
170
+ const call = node.getText(file).replace(/\s+/g, ' ');
171
+ reports.push(
172
+ `line ${line}: ${call.length > 100 ? `${call.slice(0, 97)}...` : call}: not rewritten, as ${why}; ${advice}.`,
173
+ );
174
+ };
175
+ const contains = (scope: TypeScript.Node, node: TypeScript.Node) =>
176
+ scope.getStart(file) <= node.getStart(file) && node.end <= scope.end;
177
+ function innermost<Value>(
178
+ bindings: readonly Scoped<Value>[] | undefined,
179
+ node: TypeScript.Node,
180
+ ): Value | undefined {
181
+ const reaching = (bindings ?? []).filter(({ scope }) => contains(scope, node));
182
+ reaching.sort(
183
+ (a, b) => a.scope.end - a.scope.getStart(file) - (b.scope.end - b.scope.getStart(file)),
184
+ );
185
+ return reaching[0]?.value;
186
+ }
187
+ const add = <Value>(map: Map<string, Scoped<Value>[]>, name: string, binding: Scoped<Value>) => {
188
+ map.set(name, [...(map.get(name) ?? []), binding]);
189
+ };
190
+
191
+ /** The origin of `field` bound in `elements`, beside which `type` is added when needed. */
192
+ function mongoOrigin(
193
+ elements: TypeScript.NodeArray<TypeScript.BindingElement | TypeScript.ImportSpecifier>,
194
+ exportsType: boolean,
195
+ ): Origin {
196
+ const existing = elements.find((element) => propertyNameOf(element) === 'type');
197
+ if (existing !== undefined && ts.isIdentifier(existing.name)) {
198
+ return { kind: 'mongo', typeText: existing.name.text, bind: undefined, ownType: existing };
199
+ }
200
+ const last = elements[elements.length - 1];
201
+ if (!exportsType || last === undefined) {
202
+ return {
203
+ kind: 'unknown',
204
+ reason:
205
+ 'this module exports no type, so import type from @prisma/orm-mongo/contract-builder',
206
+ };
207
+ }
208
+ let bound = false;
209
+ return {
210
+ kind: 'mongo',
211
+ typeText: 'type',
212
+ ownType: undefined,
213
+ bind: () => {
214
+ if (bound) return;
215
+ bound = true;
216
+ if (ts.isBindingElement(last) && last.dotDotDotToken !== undefined) {
217
+ edits.push({ start: last.getStart(file), end: last.getStart(file), text: 'type, ' });
218
+ } else {
219
+ edits.push({ start: last.end, end: last.end, text: ', type' });
220
+ }
221
+ },
222
+ };
223
+ }
224
+
225
+ /** Records what an import or `require` of a builder entry binds. */
226
+ function bindModule(
227
+ module: string,
228
+ names:
229
+ | TypeScript.NamedImports
230
+ | TypeScript.ObjectBindingPattern
231
+ | TypeScript.Identifier
232
+ | undefined,
233
+ ): void {
234
+ if (names === undefined) return;
235
+ const isMongo = BUILDER_MODULE.test(module);
236
+ const isOtherBuilder = !isMongo && /\/contract-builder$/.test(module);
237
+ if (ts.isObjectBindingPattern(names)) knownPatterns.add(names);
238
+ if (ts.isIdentifier(names)) {
239
+ if (isMongo) mongoNamespaces.set(names.text, module);
240
+ return;
241
+ }
242
+ for (const element of names.elements) {
243
+ if (!ts.isIdentifier(element.name)) continue;
244
+ const imported = propertyNameOf(element);
245
+ if (imported === 'defineContract') {
246
+ (isMongo ? mongoDefines : otherDefines).add(element.name.text);
247
+ }
248
+ if (imported === 'field') {
249
+ add(fields, element.name.text, {
250
+ value: isMongo
251
+ ? mongoOrigin(names.elements, TYPE_EXPORTING_MODULE.test(module))
252
+ : isOtherBuilder
253
+ ? { kind: 'other' }
254
+ : UNKNOWN,
255
+ scope: file,
256
+ });
257
+ }
258
+ }
259
+ }
260
+
261
+ function collectModules(node: TypeScript.Node): void {
262
+ if (ts.isImportDeclaration(node)) {
263
+ const module = moduleOf(node);
264
+ const bindings = node.importClause?.namedBindings;
265
+ if (module !== undefined && node.importClause?.isTypeOnly !== true) {
266
+ if (bindings !== undefined && ts.isNamedImports(bindings)) bindModule(module, bindings);
267
+ if (bindings !== undefined && ts.isNamespaceImport(bindings)) {
268
+ bindModule(module, bindings.name);
269
+ }
270
+ }
271
+ }
272
+ if (ts.isVariableDeclaration(node) && node.initializer !== undefined) {
273
+ const module = moduleOf(node.initializer);
274
+ if (
275
+ module !== undefined &&
276
+ (ts.isObjectBindingPattern(node.name) || ts.isIdentifier(node.name))
277
+ ) {
278
+ bindModule(module, node.name);
279
+ }
280
+ }
281
+ ts.forEachChild(node, collectModules);
282
+ }
283
+
284
+ /** Whether `callee` is a `defineContract` of the MongoDB builder, of another builder, or neither. */
285
+ function defineOf(callee: TypeScript.Expression): 'mongo' | 'other' | undefined {
286
+ if (ts.isIdentifier(callee)) {
287
+ if (mongoDefines.has(callee.text)) return 'mongo';
288
+ return otherDefines.has(callee.text) ? 'other' : undefined;
289
+ }
290
+ if (
291
+ ts.isPropertyAccessExpression(callee) &&
292
+ callee.name.text === 'defineContract' &&
293
+ ts.isIdentifier(callee.expression)
294
+ ) {
295
+ return mongoNamespaces.has(callee.expression.text) ? 'mongo' : undefined;
296
+ }
297
+ return undefined;
298
+ }
299
+
300
+ /** Records the bindings of `field`, of a helpers object, and of other values named `type`. */
301
+ function collectBindings(node: TypeScript.Node): void {
302
+ if (ts.isCallExpression(node)) {
303
+ const define = defineOf(node.expression);
304
+ if (define !== undefined) {
305
+ for (const argument of node.arguments) {
306
+ if (!ts.isArrowFunction(argument) && !ts.isFunctionExpression(argument)) continue;
307
+ const [helpers] = argument.parameters;
308
+ if (helpers === undefined) continue;
309
+ if (ts.isIdentifier(helpers.name)) {
310
+ add(helpersObjects, helpers.name.text, { value: define, scope: argument });
311
+ }
312
+ if (ts.isObjectBindingPattern(helpers.name)) bindHelpers(helpers.name, define, argument);
313
+ }
314
+ }
315
+ }
316
+ if (
317
+ ts.isVariableDeclaration(node) &&
318
+ ts.isObjectBindingPattern(node.name) &&
319
+ node.initializer !== undefined &&
320
+ ts.isIdentifier(node.initializer)
321
+ ) {
322
+ const origin = innermost(helpersObjects.get(node.initializer.text), node);
323
+ if (origin !== undefined) bindHelpers(node.name, origin, scopeOf(node));
324
+ }
325
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
326
+ const origin = node.initializer === undefined ? undefined : propertyOrigin(node.initializer);
327
+ if (origin !== undefined) {
328
+ add(fields, node.name.text, { value: origin, scope: scopeOf(node) });
329
+ } else if (node.name.text === 'field' && namesBuilder) {
330
+ add(fields, 'field', { value: UNKNOWN, scope: scopeOf(node) });
331
+ }
332
+ if (
333
+ node.initializer !== undefined &&
334
+ ts.isStringLiteralLike(node.initializer) &&
335
+ ts.isVariableDeclarationList(node.parent) &&
336
+ (node.parent.flags & ts.NodeFlags.Const) !== 0
337
+ ) {
338
+ add(constantStrings, node.name.text, {
339
+ value: node.initializer.text,
340
+ scope: scopeOf(node),
341
+ });
342
+ }
343
+ }
344
+ if (
345
+ (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) &&
346
+ node.name?.text === 'field' &&
347
+ namesBuilder
348
+ ) {
349
+ add(fields, 'field', { value: UNKNOWN, scope: scopeOf(node) });
350
+ }
351
+ if (ts.isParameter(node) && ts.isIdentifier(node.name) && node.name.text === 'field') {
352
+ if (!isHelpersParameter(node)) add(fields, 'field', { value: UNKNOWN, scope: node.parent });
353
+ }
354
+ if (
355
+ ts.isBindingElement(node) &&
356
+ ts.isIdentifier(node.name) &&
357
+ propertyNameOf(node) === 'field' &&
358
+ !isKnownPattern(node.parent)
359
+ ) {
360
+ add(fields, node.name.text, { value: UNKNOWN, scope: scopeOf(node) });
361
+ }
362
+ const declared = declaredName(node);
363
+ if (declared === 'type') typeDeclarations.push({ value: node, scope: scopeOf(node) });
364
+ ts.forEachChild(node, collectBindings);
365
+ }
366
+
367
+ function isKnownPattern(pattern: TypeScript.Node): boolean {
368
+ return knownPatterns.has(pattern);
369
+ }
370
+ function isHelpersParameter(parameter: TypeScript.ParameterDeclaration): boolean {
371
+ const owner = parameter.parent;
372
+ return ts.isCallExpression(owner.parent) && defineOf(owner.parent.expression) !== undefined;
373
+ }
374
+
375
+ function bindHelpers(
376
+ pattern: TypeScript.ObjectBindingPattern,
377
+ define: 'mongo' | 'other',
378
+ scope: TypeScript.Node,
379
+ ): void {
380
+ knownPatterns.add(pattern);
381
+ for (const element of pattern.elements) {
382
+ if (propertyNameOf(element) !== 'field' || !ts.isIdentifier(element.name)) continue;
383
+ add(fields, element.name.text, {
384
+ value: define === 'mongo' ? mongoOrigin(pattern.elements, true) : { kind: 'other' },
385
+ scope,
386
+ });
387
+ }
388
+ }
389
+
390
+ /** The name a declaration binds, when it is one. */
391
+ function declaredName(node: TypeScript.Node): string | undefined {
392
+ if (
393
+ ts.isVariableDeclaration(node) ||
394
+ ts.isParameter(node) ||
395
+ ts.isBindingElement(node) ||
396
+ ts.isFunctionDeclaration(node) ||
397
+ ts.isClassDeclaration(node) ||
398
+ ts.isImportSpecifier(node) ||
399
+ ts.isNamespaceImport(node) ||
400
+ ts.isImportClause(node)
401
+ ) {
402
+ return node.name !== undefined && ts.isIdentifier(node.name) ? node.name.text : undefined;
403
+ }
404
+ return undefined;
405
+ }
406
+
407
+ /** The origin of `<object>.field`: a helpers object's, a namespace import's, or `require(<builder>).field`; undefined for any other expression. */
408
+ function propertyOrigin(expression: TypeScript.Expression): Origin | undefined {
409
+ if (!ts.isPropertyAccessExpression(expression) || expression.name.text !== 'field') {
410
+ return undefined;
411
+ }
412
+ const module = moduleOf(expression.expression);
413
+ if (module !== undefined) {
414
+ return BUILDER_MODULE.test(module)
415
+ ? {
416
+ kind: 'unknown',
417
+ reason:
418
+ 'no type is bound beside this field, so import type from @prisma/orm-mongo/contract-builder',
419
+ }
420
+ : UNKNOWN;
421
+ }
422
+ if (!ts.isIdentifier(expression.expression)) return UNKNOWN;
423
+ const object = expression.expression.text;
424
+ const helpers = innermost(helpersObjects.get(object), expression);
425
+ const namespace = mongoNamespaces.get(object);
426
+ if (helpers === 'other') return { kind: 'other' };
427
+ if (helpers === 'mongo' || (namespace !== undefined && TYPE_EXPORTING_MODULE.test(namespace))) {
428
+ return { kind: 'mongo', typeText: `${object}.type`, bind: undefined, ownType: undefined };
429
+ }
430
+ return UNKNOWN;
431
+ }
432
+
433
+ /** The origin of the `field` a call reads through `receiver`. */
434
+ function originOf(receiver: TypeScript.Expression): Origin | undefined {
435
+ if (ts.isIdentifier(receiver)) return innermost(fields.get(receiver.text), receiver);
436
+ return propertyOrigin(receiver);
437
+ }
438
+
439
+ /** The length a `{ typeParams: { length } }` object gives, as written, or undefined when it holds anything else. */
440
+ function lengthOf(argument: TypeScript.Expression): string | undefined {
441
+ if (!ts.isObjectLiteralExpression(argument) || argument.properties.length !== 1)
442
+ return undefined;
443
+ const [typeParams] = argument.properties;
444
+ if (
445
+ typeParams === undefined ||
446
+ !ts.isPropertyAssignment(typeParams) ||
447
+ typeParams.name.getText(file) !== 'typeParams' ||
448
+ !ts.isObjectLiteralExpression(typeParams.initializer) ||
449
+ typeParams.initializer.properties.length !== 1
450
+ ) {
451
+ return undefined;
452
+ }
453
+ const [length] = typeParams.initializer.properties;
454
+ if (length === undefined || length.name?.getText(file) !== 'length') return undefined;
455
+ if (ts.isShorthandPropertyAssignment(length)) return 'length';
456
+ return ts.isPropertyAssignment(length) ? length.initializer.getText(file) : undefined;
457
+ }
458
+
459
+ /** The type call a removed-helper call becomes, the reason it cannot be rewritten, or `keep` for a call that is not a removed helper. */
460
+ function typeCallOf(
461
+ helper: string,
462
+ args: readonly TypeScript.Expression[],
463
+ ): { readonly typeName: string; readonly argument: string } | string {
464
+ if (helper === 'scalar') {
465
+ const [codec, options] = args;
466
+ if (
467
+ codec === undefined ||
468
+ ts.isCallExpression(codec) ||
469
+ ts.isObjectLiteralExpression(codec)
470
+ ) {
471
+ return 'keep';
472
+ }
473
+ if (!ts.isStringLiteralLike(codec)) {
474
+ const codecId = ts.isIdentifier(codec) ? constantStringOf(codec) : undefined;
475
+ return codecId === undefined ? 'keep' : `its argument is the codec id "${codecId}"`;
476
+ }
477
+ const typeName = TYPE_OF_CODEC[codec.text];
478
+ if (typeName === undefined) return `codec "${codec.text}" has no type constructor here`;
479
+ if (args.length === 1) return { typeName, argument: '' };
480
+ const length = typeName === 'Vector' && options !== undefined ? lengthOf(options) : undefined;
481
+ if (args.length === 2 && length !== undefined) return { typeName, argument: length };
482
+ return 'its options are not { typeParams: { length } }';
483
+ }
484
+ const typeName = TYPE_OF_HELPER[helper];
485
+ if (typeName === undefined) return 'keep';
486
+ if (args.length === 0) return { typeName, argument: '' };
487
+ const [options] = args;
488
+ const length = helper === 'vector' && options !== undefined ? lengthOf(options) : undefined;
489
+ if (args.length === 1 && length !== undefined) return { typeName, argument: length };
490
+ return 'its arguments are not { typeParams: { length } }';
491
+ }
492
+
493
+ /** Whether a `type` other than the builder's reaches `node`. */
494
+ function typeIsTaken(
495
+ node: TypeScript.Node,
496
+ origin: Origin & { readonly kind: 'mongo' },
497
+ ): boolean {
498
+ return typeDeclarations.some(
499
+ ({ value, scope }) => value !== origin.ownType && contains(scope, node),
500
+ );
501
+ }
502
+
503
+ function visit(node: TypeScript.Node): void {
504
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
505
+ const callee = node.expression;
506
+ const origin = originOf(callee.expression);
507
+ const typeCall = origin === undefined ? 'keep' : typeCallOf(callee.name.text, node.arguments);
508
+ if (origin !== undefined && typeCall !== 'keep' && origin.kind !== 'other') {
509
+ if (origin.kind === 'unknown') {
510
+ report(node, origin.reason, origin === UNKNOWN ? WRITE_BY_HAND_IF_MONGO : WRITE_BY_HAND);
511
+ } else if (typeof typeCall === 'string') {
512
+ report(node, typeCall);
513
+ } else if (holdsComment(callee.expression.end, node.end)) {
514
+ report(node, 'a comment inside it would be lost');
515
+ } else if (origin.typeText === 'type' && typeIsTaken(node, origin)) {
516
+ report(node, 'type names another value here');
517
+ } else {
518
+ origin.bind?.();
519
+ rewritten += 1;
520
+ edits.push({
521
+ start: node.getStart(file),
522
+ end: node.end,
523
+ text: `${callee.expression.getText(file)}.scalar(${origin.typeText}.${typeCall.typeName}(${typeCall.argument}))`,
524
+ });
525
+ for (const argument of node.arguments) ts.forEachChild(argument, visit);
526
+ return;
527
+ }
528
+ }
529
+ }
530
+ ts.forEachChild(node, visit);
531
+ }
532
+
533
+ /** Whether the text from `start` to `end` holds a comment. */
534
+ function holdsComment(start: number, end: number): boolean {
535
+ const scanner = ts.createScanner(
536
+ ts.ScriptTarget.Latest,
537
+ false,
538
+ file.languageVariant,
539
+ file.text,
540
+ undefined,
541
+ start,
542
+ end - start,
543
+ );
544
+ for (
545
+ let token = scanner.scan();
546
+ token !== ts.SyntaxKind.EndOfFileToken;
547
+ token = scanner.scan()
548
+ ) {
549
+ if (
550
+ token === ts.SyntaxKind.SingleLineCommentTrivia ||
551
+ token === ts.SyntaxKind.MultiLineCommentTrivia
552
+ ) {
553
+ return true;
554
+ }
555
+ }
556
+ return false;
557
+ }
558
+
559
+ /** The string a `const` that reaches `name` holds, when it is a string literal. */
560
+ function constantStringOf(name: TypeScript.Identifier): string | undefined {
561
+ return innermost(constantStrings.get(name.text), name);
562
+ }
563
+
564
+ collectModules(file);
565
+ collectBindings(file);
566
+ visit(file);
567
+ const text = edits
568
+ .sort((a, b) => b.start - a.start)
569
+ .reduce(
570
+ (result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end),
571
+ file.text,
572
+ );
573
+ return { text, rewritten, reports };
574
+ }
575
+
576
+ function sourceFilesIn(directory: string): readonly string[] {
577
+ return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
578
+ if (entry.isDirectory()) {
579
+ return SKIPPED_DIRECTORIES.has(entry.name) ? [] : sourceFilesIn(join(directory, entry.name));
580
+ }
581
+ return entry.isFile() && SOURCE_FILE.test(entry.name) ? [join(directory, entry.name)] : [];
582
+ });
583
+ }
584
+
585
+ function scriptKindOf(file: string): TypeScript.ScriptKind {
586
+ if (file.endsWith('.tsx')) return ts.ScriptKind.TSX;
587
+ if (file.endsWith('.jsx')) return ts.ScriptKind.JSX;
588
+ return /\.[cm]?js$/.test(file) ? ts.ScriptKind.JS : ts.ScriptKind.TS;
589
+ }
590
+
591
+ function main(args: readonly string[]): void {
592
+ const root = process.cwd();
593
+ let changed = 0;
594
+ const paths = args.length === 0 ? ['.'] : args;
595
+ const files = paths.flatMap((path) =>
596
+ statSync(path).isDirectory() ? sourceFilesIn(path) : [path],
597
+ );
598
+ for (const file of files) {
599
+ const name = relative(root, file) || file;
600
+ const text = readFileSync(file, 'utf8');
601
+ const source = ts.createSourceFile(
602
+ file,
603
+ text,
604
+ ts.ScriptTarget.Latest,
605
+ true,
606
+ scriptKindOf(file),
607
+ );
608
+ const result = rewrite(source);
609
+ if (result.text !== text) {
610
+ writeFileSync(file, result.text);
611
+ changed += 1;
612
+ console.log(
613
+ `${name}: rewrote ${result.rewritten} field helper call${result.rewritten === 1 ? '' : 's'}.`,
614
+ );
615
+ }
616
+ for (const line of result.reports) console.log(`${name}: ${line}`);
617
+ }
618
+ console.log(`Changed ${changed} file${changed === 1 ? '' : 's'}.`);
619
+ }
620
+
621
+ main(process.argv.slice(2));
@@ -1 +0,0 @@
1
- {"version":3,"file":"binding-DgumIe5f-BPV5_73g.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/binding-DgumIe5f.mjs"],"sourcesContent":["import { t as postgresError } from \"./errors-DfWK9xep.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { createPgPool, suppressIdleConnectionErrors } from \"@internal/driver-postgres/runtime\";\nimport postgresTarget from \"@internal/target-postgres/runtime\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { type } from \"arktype\";\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}\n//#endregion\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, extension = \"postgres\") {\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,\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,\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,\n\t\treason: \"wrong scheme\",\n\t\t...ifDefined(\"received\", trimmed.toLowerCase().startsWith(`${parsed.protocol}//`) ? parsed.protocol : void 0)\n\t} });\n\treturn trimmed;\n}\nfunction typeOfInput(value) {\n\treturn value === null ? \"null\" : typeof value;\n}\nfunction isObject(value) {\n\treturn typeof value === \"object\" && value !== null;\n}\nconst postgresBindingRules = {\n\textension: \"postgres\",\n\tkinds: {\n\t\turl: true,\n\t\tpgPool: true,\n\t\tpgClient: true\n\t}\n};\nconst bindingForms = {\n\turl: \"{ kind: 'url', url }\",\n\tpgPool: \"{ kind: 'pgPool', pool }\",\n\tpgClient: \"{ kind: 'pgClient', client }\"\n};\nfunction isBindingKind(kind) {\n\treturn typeof kind === \"string\" && Object.hasOwn(bindingForms, kind);\n}\nconst pgObjectNames = {\n\tpgPool: \"pg.Pool\",\n\tpgClient: \"pg.Client\"\n};\nfunction orList(items) {\n\treturn items.length < 2 ? items.join(\"\") : `${items.slice(0, -1).join(\", \")} or ${items[items.length - 1]}`;\n}\nfunction wordingOf(rules) {\n\tconst kinds = Object.keys(bindingForms).filter(isBindingKind).filter((kind) => rules.kinds[kind] === true);\n\tconst pgKinds = kinds.filter((kind) => pgObjectNames[kind] !== void 0);\n\tconst pgNames = pgKinds.flatMap((kind) => pgObjectNames[kind] ?? []);\n\treturn {\n\t\textension: rules.extension,\n\t\tkinds: orList(kinds.map((kind) => `'${kind}'`)),\n\t\tforms: orList(kinds.map((kind) => bindingForms[kind])),\n\t\tpgForms: orList(pgKinds.map((kind) => `binding: ${bindingForms[kind]}`)),\n\t\tpgObjects: orList(pgNames),\n\t\tpgObjectsEach: orList(pgNames.map((name) => `a ${name}`))\n\t};\n}\nfunction invalidInput(wording, input, message, fix) {\n\tconst receivedType = typeOfInput(input.value);\n\treturn postgresError(\"RUNTIME.BINDING_INVALID\", message, {\n\t\twhy: `The ${input.name} is ${receivedType === \"null\" ? \"null\" : `a ${receivedType}`}, and it must be ${input.expected}.`,\n\t\tfix,\n\t\tmeta: {\n\t\t\textension: wording.extension,\n\t\t\treason: input.reason,\n\t\t\treceivedType\n\t\t}\n\t});\n}\nconst echoableKind = /^[A-Za-z_][A-Za-z0-9_]{0,31}$/;\nfunction describeUnknownKind(kind) {\n\tif (kind === void 0) return {\n\t\twhy: \"The binding option has no kind, so it names no database.\",\n\t\treceived: { receivedKind: \"undefined\" }\n\t};\n\tif (typeof kind === \"string\" && echoableKind.test(kind)) return {\n\t\twhy: `The binding option has kind '${kind}', which is not a binding kind this client takes.`,\n\t\treceived: { receivedKind: kind }\n\t};\n\tconst receivedType = typeOfInput(kind);\n\treturn {\n\t\twhy: typeof kind === \"string\" ? \"The binding option has a kind that is a string not in the list of binding kinds.\" : `The binding option has kind of type ${receivedType}, which is not a binding kind.`,\n\t\treceived: typeof kind === \"string\" ? { receivedType } : { receivedKind: receivedType }\n\t};\n}\nfunction unknownKindError(wording, kind) {\n\tconst { why, received } = describeUnknownKind(kind);\n\treturn postgresError(\"RUNTIME.BINDING_INVALID\", `The binding option must have kind ${wording.kinds}`, {\n\t\twhy,\n\t\tfix: `Pass binding: ${wording.forms}.`,\n\t\tmeta: {\n\t\t\textension: wording.extension,\n\t\t\treason: \"unknown binding kind\",\n\t\t\t...received\n\t\t}\n\t});\n}\nfunction checkInputTypes(options, rules, wording) {\n\tconst binding = options.binding;\n\tconst url = options.url;\n\tconst pg = options.pg;\n\tif (binding !== void 0 && !isObject(binding)) throw invalidInput(wording, {\n\t\tname: \"binding option\",\n\t\tvalue: binding,\n\t\texpected: \"an object with a kind\",\n\t\treason: \"invalid binding input\"\n\t}, \"The binding option must be an object with a kind\", `Pass binding: ${wording.forms}.`);\n\tif (url !== void 0 && typeof url !== \"string\") throw invalidInput(wording, {\n\t\tname: \"url option\",\n\t\tvalue: url,\n\t\texpected: \"a connection string\",\n\t\treason: \"invalid url input\"\n\t}, \"The url option must be a string\", \"Pass a postgres:// or postgresql:// connection string as url, and check that the variable it comes from is set.\");\n\tif (pg !== void 0 && !isObject(pg)) throw invalidInput(wording, {\n\t\tname: \"pg option\",\n\t\tvalue: pg,\n\t\texpected: `a ${wording.pgObjects} object`,\n\t\treason: \"invalid pg input\"\n\t}, `The pg option must be ${wording.pgObjectsEach}`, `Pass a ${wording.pgObjects} as pg, or pass a connection string as url.`);\n\tif (binding !== void 0) {\n\t\tconst kind = \"kind\" in binding ? binding.kind : void 0;\n\t\tif (!isBindingKind(kind) || rules.kinds[kind] !== true) throw unknownKindError(wording, kind);\n\t}\n}\nfunction checkBindingContents(binding, wording) {\n\tif (binding.kind === \"url\") {\n\t\tconst url = binding.url;\n\t\tif (typeof url !== \"string\") throw invalidInput(wording, {\n\t\t\tname: \"url in the binding option\",\n\t\t\tvalue: url,\n\t\t\texpected: \"a connection string\",\n\t\t\treason: \"invalid binding url\"\n\t\t}, \"The url in the binding option must be a string\", \"Pass binding: { kind: 'url', url } with a postgres:// or postgresql:// connection string, and check that the variable it comes from is set.\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: validatePostgresUrl(url, wording.extension)\n\t\t};\n\t}\n\tconst [name, value] = binding.kind === \"pgPool\" ? [\"pool\", binding.pool] : [\"client\", binding.client];\n\tif (!isObject(value)) {\n\t\tconst objectName = binding.kind === \"pgPool\" ? \"pg.Pool\" : \"pg.Client\";\n\t\tthrow invalidInput(wording, {\n\t\t\tname: `${name} in the binding option`,\n\t\t\tvalue,\n\t\t\texpected: `a ${objectName}`,\n\t\t\treason: `invalid binding ${name}`\n\t\t}, `The ${name} in the binding option must be a ${objectName}`, `Pass binding: ${bindingForms[binding.kind]} with a ${objectName}.`);\n\t}\n\treturn binding;\n}\nfunction resolveBinding(options, rules) {\n\tconst wording = wordingOf(rules);\n\tcheckInputTypes(options, rules, wording);\n\tconst binding = resolveInput(options, rules, wording);\n\tif (rules.kinds[binding.kind] !== true) throw refusedInputError(wording, options.url !== void 0 ? \"url\" : \"pg\", binding.kind);\n\treturn binding;\n}\nconst inputDescriptions = {\n\turl: \"a connection string\",\n\tpgPool: \"a pg.Pool\",\n\tpgClient: \"a pg.Client\"\n};\nfunction refusedInputError(wording, option, kind) {\n\tconst pgFix = wording.pgObjectsEach === \"\" ? \"\" : `${wording.pgObjectsEach} as pg, or `;\n\treturn postgresError(\"RUNTIME.BINDING_INVALID\", `The ${option} option is ${inputDescriptions[kind]}, which this client does not take`, {\n\t\tfix: `Pass ${pgFix}binding: ${wording.forms}.`,\n\t\tmeta: {\n\t\t\textension: wording.extension,\n\t\t\treason: `refused ${option} input`,\n\t\t\treceivedKind: kind\n\t\t}\n\t});\n}\nfunction resolveInput(options, rules, wording) {\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: rules.extension,\n\t\t\treason: \"zero or multiple binding inputs\"\n\t\t}\n\t});\n\tif (options.binding !== void 0) return checkBindingContents(options.binding, wording);\n\tif (options.url !== void 0) return {\n\t\tkind: \"url\",\n\t\turl: validatePostgresUrl(options.url, rules.extension)\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 ${wording.pgForms} instead of pg.`,\n\t\tmeta: {\n\t\t\textension: rules.extension,\n\t\t\treason: \"unrecognizable pg object\"\n\t\t}\n\t});\n}\nfunction resolvePostgresBinding(options) {\n\treturn resolveBinding(options, postgresBindingRules);\n}\nfunction resolveOptionalPostgresBinding(options, rules) {\n\tif (Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.pg !== void 0) === 0) return;\n\treturn resolveBinding(blindCast(options), rules);\n}\nfunction toRuntimeBinding(binding, options) {\n\tif (binding.kind !== \"url\") return {\n\t\t...binding,\n\t\townedByDriver: false\n\t};\n\treturn {\n\t\tkind: \"pgPool\",\n\t\townedByDriver: true,\n\t\tpool: suppressIdleConnectionErrors(createPgPool({\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}, postgresTarget.sessionSettings ?? {}))\n\t};\n}\n/** Connects `driver` to `binding`, and ends the pool created for a url binding when the connection fails. */\nasync function connectWithBinding(driver, binding, options) {\n\tconst runtimeBinding = toRuntimeBinding(binding, options);\n\ttry {\n\t\tawait driver.connect(runtimeBinding);\n\t} catch (error) {\n\t\tif (runtimeBinding.kind === \"pgPool\" && runtimeBinding.ownedByDriver) await runtimeBinding.pool.end().catch(() => void 0);\n\t\tthrow error;\n\t}\n}\n//#endregion\nexport { resolveOptionalPostgresBinding as a, DEFAULT_CONNECT_TIMEOUT_MILLIS as c, postgresBindingRules as i, toDriverCursorOptions as l, isPgClient as n, resolvePostgresBinding as o, isPgPool as r, validatePostgresUrl as s, connectWithBinding as t, validateCursorOptions as u };\n\n//# sourceMappingURL=binding-DgumIe5f.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,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;AAGA,MAAM,YAAY,OAAO,gBAAgB,MAAM,eAAe,MAAM,kBAAkB;AACtF,MAAM,cAAc,OAAO,sBAAsB,MAAM,mBAAmB;AAC1E,SAAS,oBAAoB,KAAK,YAAY,YAAY;CACzD,MAAM,UAAU,IAAI,KAAK;CACzB,IAAI,QAAQ,WAAW,GAAG,MAAM,cAAc,2BAA2B,2CAA2C,EAAE,MAAM;EAC3H;EACA,QAAQ;CACT,EAAE,CAAC;CACH,IAAI;CACJ,IAAI;EACH,SAAS,IAAI,IAAI,OAAO;CACzB,QAAQ;EACP,MAAM,cAAc,2BAA2B,oCAAoC,EAAE,MAAM;GAC1F;GACA,QAAQ;EACT,EAAE,CAAC;CACJ;CACA,IAAI,OAAO,aAAa,eAAe,OAAO,aAAa,eAAe,MAAM,cAAc,2BAA2B,sDAAsD,EAAE,MAAM;EACtL;EACA,QAAQ;EACR,GAAG,UAAU,YAAY,QAAQ,YAAY,CAAC,CAAC,WAAW,GAAG,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c,2BAA2B,qFAAqF;EACnI,KAAK,QAAQ,QAAQ,QAAQ;EAC7B,MAAM;GACL,WAAW,MAAM;GACjB,QAAQ;EACT;CACD,CAAC;AACF;AACA,SAAS,uBAAuB,SAAS;CACxC,OAAO,eAAe,SAAS,oBAAoB;AACpD;AACA,SAAS,+BAA+B,SAAS,OAAO;CACvD,IAAI,OAAO,QAAQ,YAAY,KAAK,CAAC,IAAI,OAAO,QAAQ,QAAQ,KAAK,CAAC,IAAI,OAAO,QAAQ,OAAO,KAAK,CAAC,MAAM,GAAG;CAC/G,OAAO,eAAe,UAAU,OAAO,GAAG,KAAK;AAChD;AACA,SAAS,iBAAiB,SAAS,SAAS;CAC3C,IAAI,QAAQ,SAAS,OAAO,OAAO;EAClC,GAAG;EACH,eAAe;CAChB;CACA,OAAO;EACN,MAAM;EACN,eAAe;EACf,MAAM,6BAA6B,aAAa;GAC/C,kBAAkB,QAAQ;GAC1B,yBAAyB,QAAQ,aAAa,2BAA2B;GACzE,mBAAmB,QAAQ,aAAa,qBAAqB;EAC9D,GAAG,eAAe,mBAAmB,CAAC,CAAC,CAAC;CACzC;AACD;;AAEA,eAAe,mBAAmB,QAAQ,SAAS,SAAS;CAC3D,MAAM,iBAAiB,iBAAiB,SAAS,OAAO;CACxD,IAAI;EACH,MAAM,OAAO,QAAQ,cAAc;CACpC,SAAS,OAAO;EACf,IAAI,eAAe,SAAS,YAAY,eAAe,eAAe,MAAM,eAAe,KAAK,IAAI,CAAC,CAAC,YAAY,KAAK,CAAC;EACxH,MAAM;CACP;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-from-json-ClLoxky7-BbmbxtVO.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/contract-from-json-ClLoxky7.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.23-dev.13\";\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-ClLoxky7.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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"postgres-members-Bwcngc1q-HwIhD-Fq.mjs","names":[],"sources":["../../../../3-targets/postgres/9-facade/dist/postgres-members-Bwcngc1q.mjs"],"sourcesContent":["import { ifDefined } from \"@internal/utils/defined\";\nimport { activitySource, delegatingActivitySource, delegatingRuntime, withTransaction, withTransactionMembers } from \"@internal/sql-runtime\";\nimport { orm, prepareQuery } from \"@internal/sql-orm-client\";\n//#region src/runtime/postgres-members.ts\n/**\n* Builds the query members of a Postgres transaction over `txCtx`, so every statement they run goes through the transaction. `query` and `execute` are the transaction's own; `sql`, `raw` and `toSql` are the client's. Preparing sends nothing to the database, so `prepare` uses `prepareRuntime`; the prepared statement runs on the queryable it is given.\n*/\nfunction buildPostgresQueryMembers(options, txCtx) {\n\tconst { context, collections, sql, raw, toSql, prepareRuntime } = options;\n\treturn {\n\t\ttoSql,\n\t\tsql,\n\t\traw,\n\t\torm: orm({\n\t\t\truntime: {\n\t\t\t\tquery(plan) {\n\t\t\t\t\treturn txCtx.query(plan);\n\t\t\t\t},\n\t\t\t\texecute(plan) {\n\t\t\t\t\treturn txCtx.execute(plan);\n\t\t\t\t},\n\t\t\t\t[activitySource]: delegatingActivitySource(() => txCtx)\n\t\t\t},\n\t\t\tcontext,\n\t\t\t...ifDefined(\"collections\", collections)\n\t\t}),\n\t\tprepare(declaration, callback) {\n\t\t\treturn prepareQuery(prepareRuntime, declaration, callback);\n\t\t}\n\t};\n}\nfunction buildPostgresRuntimeBoundMembers(options) {\n\tconst { context, collections, sql, raw, enums, nativeEnums, toSql, getRuntime, getRuntimeForWork } = options;\n\tconst workRuntime = delegatingRuntime(getRuntimeForWork);\n\tconst orm$1 = orm({\n\t\truntime: workRuntime,\n\t\tcontext,\n\t\t...ifDefined(\"collections\", collections)\n\t});\n\tfunction prepare(declaration, callback) {\n\t\treturn prepareQuery(workRuntime, declaration, callback);\n\t}\n\treturn {\n\t\torm: orm$1,\n\t\tquery: workRuntime.query,\n\t\texecute: workRuntime.execute,\n\t\truntime() {\n\t\t\treturn getRuntime();\n\t\t},\n\t\tprepare,\n\t\ttransaction(fn) {\n\t\t\treturn withTransaction(workRuntime, (txCtx) => {\n\t\t\t\treturn fn(withTransactionMembers(txCtx, {\n\t\t\t\t\t...buildPostgresQueryMembers({\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tcollections,\n\t\t\t\t\t\tsql,\n\t\t\t\t\t\traw,\n\t\t\t\t\t\ttoSql,\n\t\t\t\t\t\tprepareRuntime: workRuntime\n\t\t\t\t\t}, txCtx),\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\nexport { buildPostgresRuntimeBoundMembers as n, buildPostgresQueryMembers as t };\n\n//# sourceMappingURL=postgres-members-Bwcngc1q.mjs.map"],"mappings":";;;;;;;AAOA,SAAS,0BAA0B,SAAS,OAAO;CAClD,MAAM,EAAE,SAAS,aAAa,KAAK,KAAK,OAAO,mBAAmB;CAClE,OAAO;EACN;EACA;EACA;EACA,KAAK,IAAI;GACR,SAAS;IACR,MAAM,MAAM;KACX,OAAO,MAAM,MAAM,IAAI;IACxB;IACA,QAAQ,MAAM;KACb,OAAO,MAAM,QAAQ,IAAI;IAC1B;KACC,iBAAiB,+BAA+B,KAAK;GACvD;GACA;GACA,GAAG,UAAU,eAAe,WAAW;EACxC,CAAC;EACD,QAAQ,aAAa,UAAU;GAC9B,OAAO,aAAa,gBAAgB,aAAa,QAAQ;EAC1D;CACD;AACD;AACA,SAAS,iCAAiC,SAAS;CAClD,MAAM,EAAE,SAAS,aAAa,KAAK,KAAK,OAAO,aAAa,OAAO,YAAY,sBAAsB;CACrG,MAAM,cAAc,kBAAkB,iBAAiB;CACvD,MAAM,QAAQ,IAAI;EACjB,SAAS;EACT;EACA,GAAG,UAAU,eAAe,WAAW;CACxC,CAAC;CACD,SAAS,QAAQ,aAAa,UAAU;EACvC,OAAO,aAAa,aAAa,aAAa,QAAQ;CACvD;CACA,OAAO;EACN,KAAK;EACL,OAAO,YAAY;EACnB,SAAS,YAAY;EACrB,UAAU;GACT,OAAO,WAAW;EACnB;EACA;EACA,YAAY,IAAI;GACf,OAAO,gBAAgB,cAAc,UAAU;IAC9C,OAAO,GAAG,uBAAuB,OAAO;KACvC,GAAG,0BAA0B;MAC5B;MACA;MACA;MACA;MACA;MACA,gBAAgB;KACjB,GAAG,KAAK;KACR;KACA;IACD,CAAC,CAAC;GACH,CAAC;EACF;CACD;AACD"}