@prisma-next/sql-runtime 0.5.0-dev.6 → 0.5.0-dev.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -22
- package/dist/exports-BcX9wp4z.mjs +1640 -0
- package/dist/exports-BcX9wp4z.mjs.map +1 -0
- package/dist/{index-yb51L_1h.d.mts → index-DkthtnOX.d.mts} +100 -25
- package/dist/index-DkthtnOX.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/test/utils.d.mts +6 -5
- package/dist/test/utils.d.mts.map +1 -1
- package/dist/test/utils.mjs +13 -6
- package/dist/test/utils.mjs.map +1 -1
- package/package.json +13 -14
- package/src/codecs/decoding.ts +294 -173
- package/src/codecs/encoding.ts +162 -37
- package/src/codecs/validation.ts +22 -3
- package/src/content-hash.ts +44 -0
- package/src/exports/index.ts +12 -7
- package/src/fingerprint.ts +22 -0
- package/src/guardrails/raw.ts +165 -0
- package/src/lower-sql-plan.ts +3 -3
- package/src/marker.ts +75 -0
- package/src/middleware/before-compile-chain.ts +1 -0
- package/src/middleware/budgets.ts +26 -96
- package/src/middleware/lints.ts +3 -3
- package/src/middleware/sql-middleware.ts +6 -5
- package/src/runtime-spi.ts +44 -0
- package/src/sql-context.ts +438 -79
- package/src/sql-family-adapter.ts +3 -2
- package/src/sql-marker.ts +62 -47
- package/src/sql-runtime.ts +336 -113
- package/dist/exports-BQZSVXXt.mjs +0 -981
- package/dist/exports-BQZSVXXt.mjs.map +0 -1
- package/dist/index-yb51L_1h.d.mts.map +0 -1
- package/test/async-iterable-result.test.ts +0 -141
- package/test/before-compile-chain.test.ts +0 -223
- package/test/budgets.test.ts +0 -431
- package/test/context.types.test-d.ts +0 -68
- package/test/execution-stack.test.ts +0 -161
- package/test/json-schema-validation.test.ts +0 -571
- package/test/lints.test.ts +0 -160
- package/test/mutation-default-generators.test.ts +0 -254
- package/test/parameterized-types.test.ts +0 -529
- package/test/sql-context.test.ts +0 -384
- package/test/sql-family-adapter.test.ts +0 -103
- package/test/sql-runtime.test.ts +0 -792
- package/test/utils.ts +0 -297
package/src/sql-marker.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MarkerStatement } from '@prisma-next/
|
|
1
|
+
import type { MarkerStatement } from '@prisma-next/sql-relational-core/ast';
|
|
2
2
|
|
|
3
3
|
export interface SqlStatement {
|
|
4
4
|
readonly sql: string;
|
|
@@ -12,6 +12,15 @@ export interface WriteMarkerInput {
|
|
|
12
12
|
readonly canonicalVersion?: number;
|
|
13
13
|
readonly appTag?: string;
|
|
14
14
|
readonly meta?: Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Applied-invariants set on the marker.
|
|
17
|
+
*
|
|
18
|
+
* - `undefined` → existing column left untouched. Sign and
|
|
19
|
+
* verify-database paths use this; they don't accumulate invariants.
|
|
20
|
+
* - explicit value (including `[]`) → column overwritten with
|
|
21
|
+
* exactly that value.
|
|
22
|
+
*/
|
|
23
|
+
readonly invariants?: readonly string[];
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
export const ensureSchemaStatement: SqlStatement = {
|
|
@@ -28,7 +37,8 @@ export const ensureTableStatement: SqlStatement = {
|
|
|
28
37
|
canonical_version int,
|
|
29
38
|
updated_at timestamptz not null default now(),
|
|
30
39
|
app_tag text,
|
|
31
|
-
meta jsonb not null default '{}'
|
|
40
|
+
meta jsonb not null default '{}',
|
|
41
|
+
invariants text[] not null default '{}'
|
|
32
42
|
)`,
|
|
33
43
|
params: [],
|
|
34
44
|
};
|
|
@@ -42,7 +52,8 @@ export function readContractMarker(): MarkerStatement {
|
|
|
42
52
|
canonical_version,
|
|
43
53
|
updated_at,
|
|
44
54
|
app_tag,
|
|
45
|
-
meta
|
|
55
|
+
meta,
|
|
56
|
+
invariants
|
|
46
57
|
from prisma_contract.marker
|
|
47
58
|
where id = $1`,
|
|
48
59
|
params: [1],
|
|
@@ -54,52 +65,56 @@ export interface WriteContractMarkerStatements {
|
|
|
54
65
|
readonly update: SqlStatement;
|
|
55
66
|
}
|
|
56
67
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Variable columns that participate in INSERT/UPDATE alongside the
|
|
70
|
+
* always-on `id = $1` and `updated_at = now()`. Each column declares
|
|
71
|
+
* its name, optional cast type, and parameter value; the placeholder
|
|
72
|
+
* (`$N`) is computed positionally below — adding or reordering a
|
|
73
|
+
* column doesn't desync indices. `invariants` only appears when the
|
|
74
|
+
* caller supplies it — see `WriteMarkerInput.invariants`.
|
|
75
|
+
*/
|
|
76
|
+
function markerColumns(
|
|
77
|
+
input: WriteMarkerInput,
|
|
78
|
+
): ReadonlyArray<{ readonly name: string; readonly type?: string; readonly param: unknown }> {
|
|
79
|
+
return [
|
|
80
|
+
{ name: 'core_hash', param: input.storageHash },
|
|
81
|
+
{ name: 'profile_hash', param: input.profileHash },
|
|
82
|
+
{ name: 'contract_json', type: 'jsonb', param: input.contractJson ?? null },
|
|
83
|
+
{ name: 'canonical_version', param: input.canonicalVersion ?? null },
|
|
84
|
+
{ name: 'app_tag', param: input.appTag ?? null },
|
|
85
|
+
{ name: 'meta', type: 'jsonb', param: JSON.stringify(input.meta ?? {}) },
|
|
86
|
+
...(input.invariants !== undefined
|
|
87
|
+
? [{ name: 'invariants' as const, type: 'text[]' as const, param: input.invariants }]
|
|
88
|
+
: []),
|
|
66
89
|
];
|
|
90
|
+
}
|
|
67
91
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
meta
|
|
78
|
-
) values (
|
|
79
|
-
$1,
|
|
80
|
-
$2,
|
|
81
|
-
$3,
|
|
82
|
-
$4::jsonb,
|
|
83
|
-
$5,
|
|
84
|
-
now(),
|
|
85
|
-
$6,
|
|
86
|
-
$7::jsonb
|
|
87
|
-
)`,
|
|
88
|
-
params: baseParams,
|
|
89
|
-
};
|
|
92
|
+
export function writeContractMarker(input: WriteMarkerInput): WriteContractMarkerStatements {
|
|
93
|
+
const cols = markerColumns(input);
|
|
94
|
+
// $1 is reserved for `id`; subsequent positions follow the order of cols.
|
|
95
|
+
const placed = cols.map((c, i) => ({
|
|
96
|
+
name: c.name,
|
|
97
|
+
expr: c.type ? `$${i + 2}::${c.type}` : `$${i + 2}`,
|
|
98
|
+
param: c.param,
|
|
99
|
+
}));
|
|
100
|
+
const params: readonly unknown[] = [1, ...placed.map((c) => c.param)];
|
|
90
101
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
app_tag = $6,
|
|
99
|
-
meta = $7::jsonb
|
|
100
|
-
where id = $1`,
|
|
101
|
-
params: baseParams,
|
|
102
|
-
};
|
|
102
|
+
// `updated_at = now()` is a SQL literal with no parameter slot, so it
|
|
103
|
+
// sits outside `placed` and is appended directly to each statement.
|
|
104
|
+
const insertColumns = ['id', ...placed.map((c) => c.name), 'updated_at'].join(', ');
|
|
105
|
+
const insertValues = ['$1', ...placed.map((c) => c.expr), 'now()'].join(', ');
|
|
106
|
+
const setClauses = [...placed.map((c) => `${c.name} = ${c.expr}`), 'updated_at = now()'].join(
|
|
107
|
+
', ',
|
|
108
|
+
);
|
|
103
109
|
|
|
104
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
insert: {
|
|
112
|
+
sql: `insert into prisma_contract.marker (${insertColumns}) values (${insertValues})`,
|
|
113
|
+
params,
|
|
114
|
+
},
|
|
115
|
+
update: {
|
|
116
|
+
sql: `update prisma_contract.marker set ${setClauses} where id = $1`,
|
|
117
|
+
params,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
105
120
|
}
|