@prisma-next-idb/target-idb 0.1.0
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/LICENSE +21 -0
- package/dist/apply-ddl-op-DZAoihY0.d.mts +129 -0
- package/dist/apply-ddl-op-DZAoihY0.d.mts.map +1 -0
- package/dist/apply-ddl-op-LP-l0o4O.mjs +232 -0
- package/dist/apply-ddl-op-LP-l0o4O.mjs.map +1 -0
- package/dist/control.d.mts +33 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +44 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-CKLekROR.mjs +237 -0
- package/dist/descriptor-meta-CKLekROR.mjs.map +1 -0
- package/dist/idb-contract-types-DndrdtW0.d.mts +111 -0
- package/dist/idb-contract-types-DndrdtW0.d.mts.map +1 -0
- package/dist/migration-B43yOFXO.d.mts +227 -0
- package/dist/migration-B43yOFXO.d.mts.map +1 -0
- package/dist/migration-driver-4T8Hk1vu.mjs +334 -0
- package/dist/migration-driver-4T8Hk1vu.mjs.map +1 -0
- package/dist/migration.d.mts +3 -0
- package/dist/migration.mjs +89 -0
- package/dist/migration.mjs.map +1 -0
- package/dist/pack.d.mts +104 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +7 -0
- package/dist/pack.mjs.map +1 -0
- package/dist/runtime.d.mts +20 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +16 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
//#region src/core/codecs.ts
|
|
2
|
+
/**
|
|
3
|
+
* IDB codec descriptors — the registry of type→IDB mapping metadata.
|
|
4
|
+
*
|
|
5
|
+
* Each descriptor declares its `codecId`, `traits`, `targetTypes`, and a
|
|
6
|
+
* `factory` that returns a `Codec` instance. This is consumed by the
|
|
7
|
+
* emitter to generate `contract.d.ts` type maps, and by the adapter at
|
|
8
|
+
* runtime to resolve encode/decode per field.
|
|
9
|
+
*/
|
|
10
|
+
const codecDescriptors = [
|
|
11
|
+
{
|
|
12
|
+
codecId: "idb/string@1",
|
|
13
|
+
traits: ["equality", "textual"],
|
|
14
|
+
targetTypes: ["string"],
|
|
15
|
+
paramsSchema: void 0,
|
|
16
|
+
isParameterized: false,
|
|
17
|
+
factory: () => () => ({
|
|
18
|
+
id: "idb/string@1",
|
|
19
|
+
encode: async (value) => value,
|
|
20
|
+
decode: async (value) => value,
|
|
21
|
+
encodeJson: (value) => value,
|
|
22
|
+
decodeJson: (value) => value
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
codecId: "idb/double@1",
|
|
27
|
+
traits: [
|
|
28
|
+
"equality",
|
|
29
|
+
"numeric",
|
|
30
|
+
"order"
|
|
31
|
+
],
|
|
32
|
+
targetTypes: ["number"],
|
|
33
|
+
paramsSchema: void 0,
|
|
34
|
+
isParameterized: false,
|
|
35
|
+
factory: () => () => ({
|
|
36
|
+
id: "idb/double@1",
|
|
37
|
+
encode: async (value) => value,
|
|
38
|
+
decode: async (value) => value,
|
|
39
|
+
encodeJson: (value) => value,
|
|
40
|
+
decodeJson: (value) => value
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
codecId: "idb/int32@1",
|
|
45
|
+
traits: [
|
|
46
|
+
"equality",
|
|
47
|
+
"numeric",
|
|
48
|
+
"order"
|
|
49
|
+
],
|
|
50
|
+
targetTypes: ["number"],
|
|
51
|
+
paramsSchema: void 0,
|
|
52
|
+
isParameterized: false,
|
|
53
|
+
factory: () => () => ({
|
|
54
|
+
id: "idb/int32@1",
|
|
55
|
+
encode: async (value) => {
|
|
56
|
+
if (!Number.isInteger(value)) throw new Error(`Value ${value} is not an integer and cannot be encoded as int32.`);
|
|
57
|
+
if (value < -Math.pow(2, 31) || value > Math.pow(2, 31) - 1) throw new Error(`Value ${value} is out of range for int32 and cannot be encoded.`);
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
decode: async (value) => value,
|
|
61
|
+
encodeJson: (value) => value,
|
|
62
|
+
decodeJson: (value) => value
|
|
63
|
+
})
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
codecId: "idb/bool@1",
|
|
67
|
+
traits: ["equality", "boolean"],
|
|
68
|
+
targetTypes: ["boolean"],
|
|
69
|
+
paramsSchema: void 0,
|
|
70
|
+
isParameterized: false,
|
|
71
|
+
factory: () => () => ({
|
|
72
|
+
id: "idb/bool@1",
|
|
73
|
+
encode: async (value) => value,
|
|
74
|
+
decode: async (value) => value,
|
|
75
|
+
encodeJson: (value) => value,
|
|
76
|
+
decodeJson: (value) => value
|
|
77
|
+
})
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
codecId: "idb/date@1",
|
|
81
|
+
traits: ["equality", "order"],
|
|
82
|
+
targetTypes: ["Date"],
|
|
83
|
+
paramsSchema: void 0,
|
|
84
|
+
isParameterized: false,
|
|
85
|
+
factory: () => () => ({
|
|
86
|
+
id: "idb/date@1",
|
|
87
|
+
encode: async (value) => value,
|
|
88
|
+
decode: async (value) => value,
|
|
89
|
+
encodeJson: (value) => value.toISOString(),
|
|
90
|
+
decodeJson: (value) => new Date(value)
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
codecId: "idb/bigint@1",
|
|
95
|
+
traits: [
|
|
96
|
+
"equality",
|
|
97
|
+
"numeric",
|
|
98
|
+
"order"
|
|
99
|
+
],
|
|
100
|
+
targetTypes: ["bigint"],
|
|
101
|
+
paramsSchema: void 0,
|
|
102
|
+
isParameterized: false,
|
|
103
|
+
factory: () => () => ({
|
|
104
|
+
id: "idb/bigint@1",
|
|
105
|
+
encode: async (value) => value,
|
|
106
|
+
decode: async (value) => value,
|
|
107
|
+
encodeJson: (value) => value.toString(),
|
|
108
|
+
decodeJson: (value) => BigInt(value)
|
|
109
|
+
})
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
codecId: "idb/decimal@1",
|
|
113
|
+
traits: ["equality", "numeric"],
|
|
114
|
+
targetTypes: ["string"],
|
|
115
|
+
paramsSchema: void 0,
|
|
116
|
+
isParameterized: false,
|
|
117
|
+
factory: () => () => ({
|
|
118
|
+
id: "idb/decimal@1",
|
|
119
|
+
encode: async (value) => value,
|
|
120
|
+
decode: async (value) => value,
|
|
121
|
+
encodeJson: (value) => value,
|
|
122
|
+
decodeJson: (value) => value
|
|
123
|
+
})
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
codecId: "idb/json@1",
|
|
127
|
+
traits: ["equality"],
|
|
128
|
+
targetTypes: ["unknown"],
|
|
129
|
+
paramsSchema: void 0,
|
|
130
|
+
isParameterized: false,
|
|
131
|
+
factory: () => () => ({
|
|
132
|
+
id: "idb/json@1",
|
|
133
|
+
encode: async (value) => value,
|
|
134
|
+
decode: async (value) => value,
|
|
135
|
+
encodeJson: (value) => value,
|
|
136
|
+
decodeJson: (value) => value
|
|
137
|
+
})
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
codecId: "idb/bytes@1",
|
|
141
|
+
traits: ["equality"],
|
|
142
|
+
targetTypes: ["Uint8Array"],
|
|
143
|
+
paramsSchema: void 0,
|
|
144
|
+
isParameterized: false,
|
|
145
|
+
factory: () => () => ({
|
|
146
|
+
id: "idb/bytes@1",
|
|
147
|
+
encode: async (value) => value,
|
|
148
|
+
decode: async (value) => value,
|
|
149
|
+
encodeJson: (value) => {
|
|
150
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
151
|
+
let result = "", i = 0;
|
|
152
|
+
while (i < value.length) {
|
|
153
|
+
const a = value[i++] ?? 0, b = value[i++] ?? 0, c = value[i++] ?? 0;
|
|
154
|
+
result += chars[a >> 2] + chars[(a & 3) << 4 | b >> 4] + (i - 1 < value.length || i - 2 < value.length ? chars[(b & 15) << 2 | c >> 6] : "=") + (i - 1 < value.length ? chars[c & 63] : "=");
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
},
|
|
158
|
+
decodeJson: (value) => {
|
|
159
|
+
const b64 = value;
|
|
160
|
+
const lookup = /* @__PURE__ */ new Uint8Array(128);
|
|
161
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("").forEach((c, i) => {
|
|
162
|
+
lookup[c.charCodeAt(0)] = i;
|
|
163
|
+
});
|
|
164
|
+
const stripped = b64.replace(/=+$/, "");
|
|
165
|
+
const out = new Uint8Array(Math.floor(stripped.length * 3 / 4));
|
|
166
|
+
let o = 0;
|
|
167
|
+
for (let i = 0; i < stripped.length; i += 4) {
|
|
168
|
+
const a = lookup[stripped.charCodeAt(i)] ?? 0;
|
|
169
|
+
const b = lookup[stripped.charCodeAt(i + 1)] ?? 0;
|
|
170
|
+
const c = lookup[stripped.charCodeAt(i + 2)] ?? 0;
|
|
171
|
+
const d = lookup[stripped.charCodeAt(i + 3)] ?? 0;
|
|
172
|
+
out[o++] = a << 2 | b >> 4;
|
|
173
|
+
if (i + 2 < stripped.length) out[o++] = (b & 15) << 4 | c >> 2;
|
|
174
|
+
if (i + 3 < stripped.length) out[o++] = (c & 3) << 6 | d;
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
];
|
|
181
|
+
/**
|
|
182
|
+
* Pre-built CodecLookup for all IDB codecs.
|
|
183
|
+
*
|
|
184
|
+
* All IDB codecs are currently identity transforms, but using the real lookup
|
|
185
|
+
* ensures per-field encoding works automatically when non-identity codecs are
|
|
186
|
+
* added (e.g. idb/date@1 already encodes/decodes Date objects).
|
|
187
|
+
*/
|
|
188
|
+
const idbCodecLookup = (() => {
|
|
189
|
+
const codecMap = new Map(codecDescriptors.map((desc) => {
|
|
190
|
+
const ctx = { name: `<codec:${desc.codecId}>` };
|
|
191
|
+
const codec = desc.factory(void 0)(ctx);
|
|
192
|
+
return [desc.codecId, codec];
|
|
193
|
+
}));
|
|
194
|
+
const targetTypesMap = new Map(codecDescriptors.map((desc) => [desc.codecId, desc.targetTypes]));
|
|
195
|
+
return {
|
|
196
|
+
get: (id) => codecMap.get(id),
|
|
197
|
+
targetTypesFor: (id) => targetTypesMap.get(id),
|
|
198
|
+
metaFor: () => void 0,
|
|
199
|
+
renderOutputTypeFor: () => void 0
|
|
200
|
+
};
|
|
201
|
+
})();
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/core/descriptor-meta.ts
|
|
204
|
+
/**
|
|
205
|
+
* Descriptor metadata for the IndexedDB target.
|
|
206
|
+
*
|
|
207
|
+
* This is the identity record for the `idb` target within the `idb` family.
|
|
208
|
+
* It is consumed by:
|
|
209
|
+
* - The family descriptor (`family-idb`) to register this target in the control stack.
|
|
210
|
+
* - The emitter during contract generation to stamp `contract.target = 'idb'`.
|
|
211
|
+
*
|
|
212
|
+
* `types.codecTypes.import` tells the emitter where to import `CodecTypes`
|
|
213
|
+
* when generating `contract.d.ts`. The named export `CodecTypes` must be
|
|
214
|
+
* re-exported from the `pack` entrypoint of this package.
|
|
215
|
+
*
|
|
216
|
+
* Targets are identifiers/descriptors — they do NOT declare capabilities.
|
|
217
|
+
* Capabilities belong on the adapter descriptor.
|
|
218
|
+
*/
|
|
219
|
+
const idbTargetDescriptorMeta = {
|
|
220
|
+
kind: "target",
|
|
221
|
+
familyId: "idb",
|
|
222
|
+
targetId: "idb",
|
|
223
|
+
id: "idb",
|
|
224
|
+
version: "0.0.1",
|
|
225
|
+
types: { codecTypes: {
|
|
226
|
+
import: {
|
|
227
|
+
package: "@prisma-next-idb/target-idb/pack",
|
|
228
|
+
named: "CodecTypes",
|
|
229
|
+
alias: "IdbCodecTypes"
|
|
230
|
+
},
|
|
231
|
+
codecDescriptors
|
|
232
|
+
} }
|
|
233
|
+
};
|
|
234
|
+
//#endregion
|
|
235
|
+
export { idbCodecLookup as n, idbTargetDescriptorMeta as t };
|
|
236
|
+
|
|
237
|
+
//# sourceMappingURL=descriptor-meta-CKLekROR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-CKLekROR.mjs","names":[],"sources":["../src/core/codecs.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { JsonValue } from \"@prisma-next/contract/types\";\nimport type { AnyCodecDescriptor, CodecInstanceContext, CodecLookup } from \"@prisma-next/framework-components/codec\";\n\n/**\n * IDB codec descriptors — the registry of type→IDB mapping metadata.\n *\n * Each descriptor declares its `codecId`, `traits`, `targetTypes`, and a\n * `factory` that returns a `Codec` instance. This is consumed by the\n * emitter to generate `contract.d.ts` type maps, and by the adapter at\n * runtime to resolve encode/decode per field.\n */\nexport const codecDescriptors: readonly AnyCodecDescriptor[] = [\n {\n codecId: \"idb/string@1\",\n traits: [\"equality\", \"textual\"],\n targetTypes: [\"string\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/string@1\",\n encode: async (value: string) => value,\n decode: async (value: string) => value,\n encodeJson: (value: string) => value,\n decodeJson: (value: string) => value,\n }),\n },\n {\n codecId: \"idb/double@1\",\n traits: [\"equality\", \"numeric\", \"order\"],\n targetTypes: [\"number\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/double@1\",\n encode: async (value: number) => value,\n decode: async (value: number) => value,\n encodeJson: (value: number) => value,\n decodeJson: (value: number) => value,\n }),\n },\n {\n codecId: \"idb/int32@1\",\n traits: [\"equality\", \"numeric\", \"order\"],\n targetTypes: [\"number\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/int32@1\",\n encode: async (value: number) => {\n if (!Number.isInteger(value)) {\n throw new Error(`Value ${value} is not an integer and cannot be encoded as int32.`);\n }\n if (value < -Math.pow(2, 31) || value > Math.pow(2, 31) - 1) {\n throw new Error(`Value ${value} is out of range for int32 and cannot be encoded.`);\n }\n return value;\n },\n decode: async (value: number) => value,\n encodeJson: (value: number) => value,\n decodeJson: (value: number) => value,\n }),\n },\n {\n codecId: \"idb/bool@1\",\n traits: [\"equality\", \"boolean\"],\n targetTypes: [\"boolean\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/bool@1\",\n encode: async (value: boolean) => value,\n decode: async (value: boolean) => value,\n encodeJson: (value: boolean) => value,\n decodeJson: (value: boolean) => value,\n }),\n },\n {\n codecId: \"idb/date@1\",\n traits: [\"equality\", \"order\"],\n targetTypes: [\"Date\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/date@1\",\n encode: async (value: Date) => value,\n decode: async (value: Date) => value,\n encodeJson: (value: Date) => value.toISOString(),\n decodeJson: (value: string) => new Date(value),\n }),\n },\n {\n codecId: \"idb/bigint@1\",\n traits: [\"equality\", \"numeric\", \"order\"],\n targetTypes: [\"bigint\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/bigint@1\",\n encode: async (value: bigint) => value,\n decode: async (value: bigint) => value,\n encodeJson: (value: bigint) => value.toString(),\n decodeJson: (value: string) => BigInt(value),\n }),\n },\n {\n codecId: \"idb/decimal@1\",\n traits: [\"equality\", \"numeric\"],\n targetTypes: [\"string\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/decimal@1\",\n encode: async (value: string) => value,\n decode: async (value: string) => value,\n encodeJson: (value: string) => value,\n decodeJson: (value: string) => value,\n }),\n },\n {\n codecId: \"idb/json@1\",\n traits: [\"equality\"],\n targetTypes: [\"unknown\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/json@1\",\n encode: async (value: unknown) => value,\n decode: async (value: unknown) => value,\n encodeJson: (value: JsonValue) => value as JsonValue,\n decodeJson: (value: JsonValue) => value,\n }),\n },\n {\n codecId: \"idb/bytes@1\",\n traits: [\"equality\"],\n targetTypes: [\"Uint8Array\"],\n paramsSchema: undefined as never,\n isParameterized: false,\n factory: () => () => ({\n id: \"idb/bytes@1\",\n encode: async (value: Uint8Array) => value,\n decode: async (value: Uint8Array) => value,\n encodeJson: (value: Uint8Array) => {\n const chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\",\n i = 0;\n while (i < value.length) {\n const a = value[i++] ?? 0,\n b = value[i++] ?? 0,\n c = value[i++] ?? 0;\n result +=\n chars[a >> 2]! +\n chars[((a & 3) << 4) | (b >> 4)]! +\n (i - 1 < value.length || i - 2 < value.length ? chars[((b & 15) << 2) | (c >> 6)]! : \"=\") +\n (i - 1 < value.length ? chars[c & 63]! : \"=\");\n }\n return result;\n },\n decodeJson: (value: string) => {\n const b64 = value as string;\n const lookup = new Uint8Array(128);\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\".split(\"\").forEach((c, i) => {\n lookup[c.charCodeAt(0)!] = i;\n });\n const stripped = b64.replace(/=+$/, \"\");\n const out = new Uint8Array(Math.floor((stripped.length * 3) / 4));\n let o = 0;\n for (let i = 0; i < stripped.length; i += 4) {\n const a = lookup[stripped.charCodeAt(i)!]! ?? 0;\n const b = lookup[stripped.charCodeAt(i + 1)!]! ?? 0;\n const c = lookup[stripped.charCodeAt(i + 2)!]! ?? 0;\n const d = lookup[stripped.charCodeAt(i + 3)!]! ?? 0;\n out[o++] = (a << 2) | (b >> 4);\n if (i + 2 < stripped.length) out[o++] = ((b & 15) << 4) | (c >> 2);\n if (i + 3 < stripped.length) out[o++] = ((c & 3) << 6) | d;\n }\n return out;\n },\n }),\n },\n] as const;\n\n// ── Codec lookup ──────────────────────────────────────────────────────────────\n\n/**\n * Pre-built CodecLookup for all IDB codecs.\n *\n * All IDB codecs are currently identity transforms, but using the real lookup\n * ensures per-field encoding works automatically when non-identity codecs are\n * added (e.g. idb/date@1 already encodes/decodes Date objects).\n */\nexport const idbCodecLookup: CodecLookup = (() => {\n const codecMap = new Map(\n codecDescriptors.map((desc) => {\n const ctx: CodecInstanceContext = { name: `<codec:${desc.codecId}>` };\n const codec = (desc as AnyCodecDescriptor).factory(undefined)(ctx);\n return [desc.codecId, codec] as const;\n })\n );\n const targetTypesMap = new Map(codecDescriptors.map((desc) => [desc.codecId, desc.targetTypes]));\n return {\n get: (id) => codecMap.get(id),\n targetTypesFor: (id) => targetTypesMap.get(id),\n metaFor: () => undefined,\n renderOutputTypeFor: () => undefined,\n };\n})();\n","import type { TargetDescriptor } from \"@prisma-next/framework-components/components\";\nimport { codecDescriptors } from \"./codecs\";\n\n/**\n * Descriptor metadata for the IndexedDB target.\n *\n * This is the identity record for the `idb` target within the `idb` family.\n * It is consumed by:\n * - The family descriptor (`family-idb`) to register this target in the control stack.\n * - The emitter during contract generation to stamp `contract.target = 'idb'`.\n *\n * `types.codecTypes.import` tells the emitter where to import `CodecTypes`\n * when generating `contract.d.ts`. The named export `CodecTypes` must be\n * re-exported from the `pack` entrypoint of this package.\n *\n * Targets are identifiers/descriptors — they do NOT declare capabilities.\n * Capabilities belong on the adapter descriptor.\n */\nexport const idbTargetDescriptorMeta = {\n kind: \"target\",\n familyId: \"idb\",\n targetId: \"idb\",\n id: \"idb\",\n version: \"0.0.1\",\n types: {\n codecTypes: {\n import: {\n package: \"@prisma-next-idb/target-idb/pack\",\n named: \"CodecTypes\",\n alias: \"IdbCodecTypes\",\n },\n codecDescriptors,\n },\n },\n} as const satisfies TargetDescriptor<\"idb\", \"idb\">;\n"],"mappings":";;;;;;;;;AAWA,MAAa,mBAAkD;CAC7D;EACE,SAAS;EACT,QAAQ,CAAC,YAAY,SAAS;EAC9B,aAAa,CAAC,QAAQ;EACtB,cAAc,KAAA;EACd,iBAAiB;EACjB,sBAAsB;GACpB,IAAI;GACJ,QAAQ,OAAO,UAAkB;GACjC,QAAQ,OAAO,UAAkB;GACjC,aAAa,UAAkB;GAC/B,aAAa,UAAkB;EACjC;CACF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AAS,IAAI,EAAE;EAC5B,iBAAiB,OAAO,eAAe,IAAI,EAAE;EAC7C,eAAe,KAAA;EACf,2BAA2B,KAAA;CAC7B;AACF,EAAA,CAAG;;;;;;;;;;;;;;;;;;AC5LH,MAAa,0BAA0B;CACrC,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,OAAO,EACL,YAAY;EACV,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;EACT;EACA;CACF,EACF;AACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { StorageBase } from "@prisma-next/contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/core/idb-contract-types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Full storage shape for an IDB contract.
|
|
6
|
+
*
|
|
7
|
+
* Extends the framework {@link StorageBase} to carry the `storageHash` alongside
|
|
8
|
+
* IDB-specific data: a map of object store names to their {@link IdbStoreDefinition}s.
|
|
9
|
+
*
|
|
10
|
+
* @template THash - Literal hash string embedded in the `storageHash` branded type.
|
|
11
|
+
*/
|
|
12
|
+
type IdbStorage<THash extends string = string> = StorageBase<THash> & {
|
|
13
|
+
readonly stores: Record<string, IdbStoreDefinition>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for a single IndexedDB object store.
|
|
17
|
+
*
|
|
18
|
+
* Mirrors the options accepted by `IDBDatabase.createObjectStore()`:
|
|
19
|
+
* - `keyPath` — the property path used as the primary key (e.g. `"id"`).
|
|
20
|
+
* - `autoIncrement` — when `true` IDB auto-generates integer keys. Omit (or `false`)
|
|
21
|
+
* for client-generated keys (UUID / CUID), which is the common case for syncable models.
|
|
22
|
+
* - `indexes` — named secondary indexes on this store.
|
|
23
|
+
*/
|
|
24
|
+
type IdbStoreDefinition = {
|
|
25
|
+
readonly keyPath: string;
|
|
26
|
+
readonly autoIncrement?: boolean;
|
|
27
|
+
readonly indexes?: Record<string, IdbIndexDefinition>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for a single secondary index on an object store.
|
|
31
|
+
*
|
|
32
|
+
* Mirrors the options accepted by `IDBObjectStore.createIndex()`.
|
|
33
|
+
*/
|
|
34
|
+
type IdbIndexDefinition = {
|
|
35
|
+
readonly keyPath: string;
|
|
36
|
+
readonly unique: boolean;
|
|
37
|
+
readonly multiEntry?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** Referential action executed on child rows when a parent row is deleted. */
|
|
40
|
+
type IdbReferentialAction = "cascade" | "setNull" | "setDefault" | "restrict" | "noAction";
|
|
41
|
+
/** Per-relation storage metadata attached to {@link IdbModelStorage}. */
|
|
42
|
+
type IdbRelationStorage = {
|
|
43
|
+
readonly onDelete?: IdbReferentialAction;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Per-model storage metadata stored in `contract.models[ModelName].storage`.
|
|
47
|
+
*
|
|
48
|
+
* Tells the runtime (and the generated client) which object store owns this model
|
|
49
|
+
* and which field is its primary key. `relations` carries per-relation enforcement
|
|
50
|
+
* metadata (e.g. `onDelete`) mirroring the SQL target's FK constraint metadata.
|
|
51
|
+
*/
|
|
52
|
+
type IdbModelStorage = {
|
|
53
|
+
readonly storeName: string;
|
|
54
|
+
readonly keyPath: string;
|
|
55
|
+
readonly relations?: Record<string, IdbRelationStorage>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Type-maps structure for IDB contracts.
|
|
59
|
+
*
|
|
60
|
+
* IDB has no SQL-style operation types or query-operation types — those slots are
|
|
61
|
+
* fixed to `Record<string, never>`. Only codec types and field I/O types vary.
|
|
62
|
+
*
|
|
63
|
+
* @template TCodecTypes - Codec input/output pairs keyed by codec ID.
|
|
64
|
+
* @template TFieldOutputTypes - Per-model, per-field TypeScript output types.
|
|
65
|
+
* @template TFieldInputTypes - Per-model, per-field TypeScript input types.
|
|
66
|
+
*/
|
|
67
|
+
type IdbTypeMaps<TCodecTypes extends Record<string, {
|
|
68
|
+
output: unknown;
|
|
69
|
+
}> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
|
|
70
|
+
readonly codecTypes: TCodecTypes;
|
|
71
|
+
readonly operationTypes: Record<string, never>;
|
|
72
|
+
readonly queryOperationTypes: Record<string, never>;
|
|
73
|
+
readonly fieldOutputTypes: TFieldOutputTypes;
|
|
74
|
+
readonly fieldInputTypes: TFieldInputTypes;
|
|
75
|
+
};
|
|
76
|
+
/** @internal Phantom key used to attach {@link IdbTypeMaps} to a contract without widening the contract shape. */
|
|
77
|
+
type IdbTypeMapsPhantomKey = "__@prisma-next-idb/family-idb/typeMaps@__";
|
|
78
|
+
/**
|
|
79
|
+
* Intersects a contract type with its type-maps via a phantom property.
|
|
80
|
+
*
|
|
81
|
+
* Mirrors `ContractWithTypeMaps` from `@prisma-next/sql-contract/types`. The phantom
|
|
82
|
+
* property is optional and carries no runtime value — it exists solely so that
|
|
83
|
+
* TypeScript-level utilities can extract `TTypeMaps` from a `Contract` type parameter.
|
|
84
|
+
*
|
|
85
|
+
* @template TContract - The base contract type.
|
|
86
|
+
* @template TTypeMaps - The {@link IdbTypeMaps} instantiation to attach.
|
|
87
|
+
*/
|
|
88
|
+
type IdbContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in IdbTypeMapsPhantomKey]?: TTypeMaps };
|
|
89
|
+
/**
|
|
90
|
+
* Extract the full {@link IdbTypeMaps} from a contract wrapped with
|
|
91
|
+
* {@link IdbContractWithTypeMaps}. Returns `never` if the contract does not
|
|
92
|
+
* carry type maps (e.g. a plain `Contract<IdbStorage>` without the phantom key).
|
|
93
|
+
*/
|
|
94
|
+
type ExtractIdbTypeMaps<TContract> = TContract extends { readonly [K in IdbTypeMapsPhantomKey]?: infer TM } ? TM : never;
|
|
95
|
+
/**
|
|
96
|
+
* Extract the `fieldOutputTypes` slot from a contract's type maps.
|
|
97
|
+
*
|
|
98
|
+
* Used by the IDB ORM client to resolve per-model, per-field TypeScript output
|
|
99
|
+
* types from the emitted `IdbTypeMaps<CodecTypes, FieldOutputTypes, FieldInputTypes>`.
|
|
100
|
+
*/
|
|
101
|
+
type ExtractIdbFieldOutputTypes<TContract> = ExtractIdbTypeMaps<TContract> extends IdbTypeMaps<any, infer FO, any> ? FO : never;
|
|
102
|
+
/**
|
|
103
|
+
* Extract the `fieldInputTypes` slot from a contract's type maps.
|
|
104
|
+
*
|
|
105
|
+
* Used by the IDB ORM client to resolve per-model, per-field TypeScript input
|
|
106
|
+
* types (for `create()`, `where()`, etc.).
|
|
107
|
+
*/
|
|
108
|
+
type ExtractIdbFieldInputTypes<TContract> = ExtractIdbTypeMaps<TContract> extends IdbTypeMaps<any, any, infer FI> ? FI : never;
|
|
109
|
+
//#endregion
|
|
110
|
+
export { IdbIndexDefinition as a, IdbRelationStorage as c, IdbTypeMaps as d, IdbContractWithTypeMaps as i, IdbStorage as l, ExtractIdbFieldOutputTypes as n, IdbModelStorage as o, ExtractIdbTypeMaps as r, IdbReferentialAction as s, ExtractIdbFieldInputTypes as t, IdbStoreDefinition as u };
|
|
111
|
+
//# sourceMappingURL=idb-contract-types-DndrdtW0.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idb-contract-types-DndrdtW0.d.mts","names":[],"sources":["../src/core/idb-contract-types.ts"],"mappings":";;;;;AAUA;;;;;;KAAY,UAAA,kCAA4C,WAAA,CAAY,KAAA;EAAA,SACzD,MAAA,EAAQ,MAAA,SAAe,kBAAA;AAAA;;;;;;;;AAAkB;AAYpD;KAAY,kBAAA;EAAA,SACD,OAAA;EAAA,SACA,aAAA;EAAA,SACA,OAAA,GAAU,MAAM,SAAS,kBAAA;AAAA;;;;;AAAkB;KAQ1C,kBAAA;EAAA,SACD,OAAA;EAAA,SACA,MAAA;EAAA,SACA,UAAA;AAAA;;KAIC,oBAAA;;KAGA,kBAAA;EAAA,SACD,QAAA,GAAW,oBAAoB;AAAA;;;AAJV;AAGhC;;;;KAWY,eAAA;EAAA,SACD,SAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA,GAAY,MAAM,SAAS,kBAAA;AAAA;;;;;;;AAAkB;AAaxD;;;KAAY,WAAA,qBACU,MAAA;EAAiB,MAAA;AAAA,KAAqB,MAAA,2CAChC,MAAA,SAAe,MAAA,qBAA2B,MAAA,0CAC3C,MAAA,SAAe,MAAA,qBAA2B,MAAA;EAAA,SAE1D,UAAA,EAAY,WAAA;EAAA,SACZ,cAAA,EAAgB,MAAA;EAAA,SAChB,mBAAA,EAAqB,MAAA;EAAA,SACrB,gBAAA,EAAkB,iBAAA;EAAA,SAClB,eAAA,EAAiB,gBAAA;AAAA;;KAIvB,qBAAA;;;;;;;;;;;KAYO,uBAAA,yBAAgD,SAAA,oBAC3C,qBAAA,IAAyB,SAAA;;;;;;KAU9B,kBAAA,cAAgC,SAAA,0BAC3B,qBAAqB,iBAElC,EAAA;;;;;;;KASQ,0BAAA,cAEV,kBAAA,CAAmB,SAAA,UAAmB,WAAA,uBAAkC,EAAA;AAxCxE;;;;AAGwB;AAY1B;AAfE,KAgDU,yBAAA,cAEV,kBAAA,CAAmB,SAAA,UAAmB,WAAA,uBAAkC,EAAA"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { u as IdbStoreDefinition } from "./idb-contract-types-DndrdtW0.mjs";
|
|
2
|
+
import { d as IdbDdlOp } from "./apply-ddl-op-DZAoihY0.mjs";
|
|
3
|
+
import { ControlDriverInstance, MigrationOperationPolicy, MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationPlannerResult, MigrationRunner, MigrationRunnerPerSpaceOptions, MigrationRunnerResult, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
|
|
4
|
+
import { Migration } from "@prisma-next/migration-tools/migration";
|
|
5
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
6
|
+
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
7
|
+
|
|
8
|
+
//#region src/core/schema-diff.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Minimal schema shape used for diffing.
|
|
11
|
+
*
|
|
12
|
+
* Structurally identical to `IdbSchemaIR` in `family-idb` — compatible by
|
|
13
|
+
* TypeScript's structural typing. The contract's `storage.stores` map
|
|
14
|
+
* (which uses `IdbStoreDefinition`) has the same shape as `IdbStoreIR`, so
|
|
15
|
+
* both can be passed here without conversion.
|
|
16
|
+
*/
|
|
17
|
+
type IdbSchemaDiffInput = {
|
|
18
|
+
readonly stores: Record<string, IdbStoreDefinition>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Compute an ordered set of DDL operations to migrate from `from` to `to`.
|
|
22
|
+
*
|
|
23
|
+
* Safe execution order (important for a single `upgradeneeded` transaction):
|
|
24
|
+
* 1. Create new stores — additive
|
|
25
|
+
* 2. Create indexes on those new stores — additive
|
|
26
|
+
* 3. Create new indexes on existing stores — additive
|
|
27
|
+
* 4. Replace mutated indexes on surviving stores — destructive + additive
|
|
28
|
+
* (IDB cannot alter an existing index in place, so this is drop+create)
|
|
29
|
+
* 5. Drop removed indexes from surviving stores — destructive
|
|
30
|
+
* 6. Drop removed stores — destructive
|
|
31
|
+
*
|
|
32
|
+
* @param from - Current schema, or `null` for a fresh (empty) database.
|
|
33
|
+
* @param to - Desired target schema.
|
|
34
|
+
*
|
|
35
|
+
* **Note on store-level mutations.** IDB cannot alter an object store's
|
|
36
|
+
* `keyPath` or `autoIncrement` after creation. When those change between
|
|
37
|
+
* `from` and `to` for the same store name, this function throws — silent
|
|
38
|
+
* no-op is worse than an explicit error. The recovery path is a manual
|
|
39
|
+
* migration that drops the store and re-creates it (with whatever data
|
|
40
|
+
* preservation strategy the caller wants).
|
|
41
|
+
*/
|
|
42
|
+
declare function diffIdbSchema(from: IdbSchemaDiffInput | null, to: IdbSchemaDiffInput): IdbDdlOp[];
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/core/migration-driver.d.ts
|
|
45
|
+
/**
|
|
46
|
+
* Extended IDB control driver for migrations.
|
|
47
|
+
*
|
|
48
|
+
* Carries the `IDBFactory`, database name, and target version number so
|
|
49
|
+
* the migration runner can open the database and perform DDL inside the
|
|
50
|
+
* `upgradeneeded` callback.
|
|
51
|
+
*
|
|
52
|
+
* The `targetVersion` is the IDB database version to upgrade **to**. The
|
|
53
|
+
* caller is responsible for computing this value — typically by reading
|
|
54
|
+
* `manifest.idbVersion ?? 0` and adding 1.
|
|
55
|
+
*
|
|
56
|
+
* After a successful `IdbMigrationRunner.execute()` call, the caller must
|
|
57
|
+
* write the new `idbVersion` (= `targetVersion`) back to the manifest.
|
|
58
|
+
* The runner itself does not touch the manifest.
|
|
59
|
+
*/
|
|
60
|
+
type IdbMigrationControlDriver = ControlDriverInstance<"idb", "idb"> & {
|
|
61
|
+
readonly dbName: string;
|
|
62
|
+
readonly factory: IDBFactory;
|
|
63
|
+
readonly targetVersion: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Factory descriptor for `IdbMigrationControlDriver`.
|
|
67
|
+
*
|
|
68
|
+
* Usage:
|
|
69
|
+
* ```ts
|
|
70
|
+
* const driver = IdbMigrationControlDriverDescriptor.create({
|
|
71
|
+
* dbName: "my-app",
|
|
72
|
+
* factory: window.indexedDB, // or new IDBFactory() from fake-indexeddb
|
|
73
|
+
* targetVersion: (manifest.idbVersion ?? 0) + 1,
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare const IdbMigrationControlDriverDescriptor: {
|
|
78
|
+
readonly version: "1.0.0";
|
|
79
|
+
readonly create: ({
|
|
80
|
+
dbName,
|
|
81
|
+
factory,
|
|
82
|
+
targetVersion
|
|
83
|
+
}: {
|
|
84
|
+
readonly dbName: string;
|
|
85
|
+
readonly factory: IDBFactory;
|
|
86
|
+
readonly targetVersion: number;
|
|
87
|
+
}) => IdbMigrationControlDriver;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Narrows a `ControlDriverInstance<"idb","idb">` to `IdbMigrationControlDriver`.
|
|
91
|
+
*
|
|
92
|
+
* Throws a descriptive error if the driver was not created by
|
|
93
|
+
* {@link IdbMigrationControlDriverDescriptor}.
|
|
94
|
+
*/
|
|
95
|
+
declare function extractMigrationDriver(driver: ControlDriverInstance<"idb", "idb">): IdbMigrationControlDriver;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/core/migration-runner.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* IDB migration runner.
|
|
100
|
+
*
|
|
101
|
+
* `execute()` returns a structured refusal — IndexedDB only exists in the
|
|
102
|
+
* browser, so the framework's CLI control plane (`db init`, `db update`,
|
|
103
|
+
* `migration apply`) has no live database to talk to. The refusal points users
|
|
104
|
+
* at `prisma-next-idb preflight` for chain validation. The browser apply path
|
|
105
|
+
* goes through `openAndUpgrade()` directly via `auto-migrate.ts` in client-idb.
|
|
106
|
+
*
|
|
107
|
+
* v0.12.0 merged the former single-space `execute({plan, …})` and
|
|
108
|
+
* `executeAcrossSpaces({perSpaceOptions})` into one multi-space
|
|
109
|
+
* `execute({driver, perSpaceOptions})`; the `MultiSpaceCapableRunner` interface
|
|
110
|
+
* and `MultiSpace*` types were removed.
|
|
111
|
+
*/
|
|
112
|
+
declare class IdbMigrationRunner implements MigrationRunner<"idb", "idb"> {
|
|
113
|
+
/**
|
|
114
|
+
* Apply one or more per-space migration plans. IDB cannot be applied from
|
|
115
|
+
* the CLI — `IndexedDB` is a browser API — so this always returns a
|
|
116
|
+
* structured refusal. Authoring stays in `prisma-next migration new` /
|
|
117
|
+
* `prisma-next migration plan`; validation lives in `prisma-next-idb
|
|
118
|
+
* preflight`; apply happens in the browser the next time the user opens the
|
|
119
|
+
* app via `createAutoMigratingIdbClient`.
|
|
120
|
+
*/
|
|
121
|
+
execute(options: {
|
|
122
|
+
readonly driver: ControlDriverInstance<"idb", "idb">;
|
|
123
|
+
readonly perSpaceOptions: ReadonlyArray<MigrationRunnerPerSpaceOptions<"idb", "idb">>;
|
|
124
|
+
}): Promise<MigrationRunnerResult>;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/core/migration-planner.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* IDB-specific migration plan.
|
|
130
|
+
*
|
|
131
|
+
* Extends `MigrationPlanWithAuthoringSurface` by narrowing `operations` to
|
|
132
|
+
* `readonly IdbDdlOp[]`. This is a valid covariant narrowing because
|
|
133
|
+
* `IdbDdlOp extends MigrationPlanOperation`.
|
|
134
|
+
*
|
|
135
|
+
* The runner re-casts `plan.operations` back to `readonly IdbDdlOp[]` via
|
|
136
|
+
* `isIdbDdlOp` validation.
|
|
137
|
+
*/
|
|
138
|
+
interface IdbMigrationPlanWithAuthoring extends MigrationPlanWithAuthoringSurface {
|
|
139
|
+
readonly operations: readonly IdbDdlOp[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Extract an `IdbSchemaDiffInput` from a raw contract object.
|
|
143
|
+
*
|
|
144
|
+
* Returns `null` for a null contract (fresh database — no prior schema).
|
|
145
|
+
* The extraction is dynamic because contracts arrive as `unknown` / `Contract`
|
|
146
|
+
* at planner call sites.
|
|
147
|
+
*/
|
|
148
|
+
declare function contractToIdbSchema(contract: Contract | null | unknown): IdbSchemaDiffInput | null;
|
|
149
|
+
/**
|
|
150
|
+
* IDB migration planner.
|
|
151
|
+
*
|
|
152
|
+
* `plan()` converts `fromContract` and `contract` into `IdbSchemaDiffInput`s,
|
|
153
|
+
* diffs them using {@link diffIdbSchema}, and returns an
|
|
154
|
+
* {@link IdbMigrationPlanWithAuthoring} that can be executed by
|
|
155
|
+
* {@link IdbMigrationRunner} or rendered to a TypeScript migration file via
|
|
156
|
+
* the class-based scaffold matching vendor's Postgres/Mongo authoring surface.
|
|
157
|
+
*
|
|
158
|
+
* The planner does NOT apply the policy — it always returns the full op set.
|
|
159
|
+
* Policy enforcement happens in the runner and in the browser-side
|
|
160
|
+
* auto-migrate path.
|
|
161
|
+
*/
|
|
162
|
+
declare class IdbMigrationPlanner implements MigrationPlanner<"idb", "idb"> {
|
|
163
|
+
plan(options: {
|
|
164
|
+
readonly contract: unknown;
|
|
165
|
+
readonly schema: unknown;
|
|
166
|
+
readonly policy: MigrationOperationPolicy;
|
|
167
|
+
readonly fromContract: Contract | null;
|
|
168
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<"idb", "idb">>;
|
|
169
|
+
/**
|
|
170
|
+
* Contract space this plan applies to.
|
|
171
|
+
*
|
|
172
|
+
* Stamped onto the produced plan so the runner keys the marker row
|
|
173
|
+
* by the right space. IDB only has a single space (`"app"`), but
|
|
174
|
+
* the parameter is required by the framework's
|
|
175
|
+
* {@link MigrationPlanner} interface (added for multi-space support
|
|
176
|
+
* in contract-spaces ADR 212). Ignored by the IDB planner — all
|
|
177
|
+
* IDB schemas are single-space.
|
|
178
|
+
*/
|
|
179
|
+
readonly spaceId: string;
|
|
180
|
+
}): MigrationPlannerResult;
|
|
181
|
+
emptyMigration(context: MigrationScaffoldContext, _spaceId: string): MigrationPlanWithAuthoringSurface;
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/core/idb-migration.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Target-owned base class for IDB migrations.
|
|
187
|
+
*
|
|
188
|
+
* Fixes the framework's `Migration` generic to IDB target identity (operations
|
|
189
|
+
* narrowed to `IdbDdlOp`, family/target ids both `'idb'`) so user-authored
|
|
190
|
+
* migrations and renderer-generated scaffolds can `extends Migration` against
|
|
191
|
+
* the facade re-export from `@prisma-next-idb/target-idb/migration` without
|
|
192
|
+
* redeclaring target-local identity.
|
|
193
|
+
*
|
|
194
|
+
* Unlike SQL/Mongo, IDB has no per-instance control adapter to materialize —
|
|
195
|
+
* IDB DDL ops are pure data. The base constructor signature still accepts the
|
|
196
|
+
* `ControlStack` so the framework's `MigrationCLI` orchestration can pass one
|
|
197
|
+
* uniformly, but it is unused inside an IDB migration.
|
|
198
|
+
*/
|
|
199
|
+
declare abstract class IdbMigration extends Migration<IdbDdlOp, "idb", "idb"> {
|
|
200
|
+
readonly targetId: "idb";
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/core/migration-cli.d.ts
|
|
204
|
+
type IdbMigrationConstructor = new () => IdbMigration;
|
|
205
|
+
/**
|
|
206
|
+
* Self-emit CLI invoked by an authored `migration.ts` file:
|
|
207
|
+
*
|
|
208
|
+
* `MigrationCLI.run(import.meta.url, M);`
|
|
209
|
+
*
|
|
210
|
+
* When the file is run as a node entrypoint (`node migration.ts`), regenerates
|
|
211
|
+
* `ops.json` and `migration.json` next to the file from the migration class's
|
|
212
|
+
* current `operations` getter and `describe()` output. When the file is merely
|
|
213
|
+
* imported (e.g. by `contract-space.generated.ts`), returns 0 without side
|
|
214
|
+
* effects.
|
|
215
|
+
*
|
|
216
|
+
* IDB migrations are pure data — no SQL string compilation, no adapter-driven
|
|
217
|
+
* materialization — so this shim deliberately skips config loading and
|
|
218
|
+
* `ControlStack` assembly. That keeps the shim free of the workspace-internal
|
|
219
|
+
* `@prisma-next/cli` package (which is what vendor's `MigrationCLI.run`
|
|
220
|
+
* depends on).
|
|
221
|
+
*/
|
|
222
|
+
declare class MigrationCLI {
|
|
223
|
+
static run(importMetaUrl: string, MigrationClass: IdbMigrationConstructor): Promise<number>;
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
export { contractToIdbSchema as a, IdbMigrationControlDriverDescriptor as c, diffIdbSchema as d, IdbMigrationPlanner as i, extractMigrationDriver as l, IdbMigration as n, IdbMigrationRunner as o, IdbMigrationPlanWithAuthoring as r, IdbMigrationControlDriver as s, MigrationCLI as t, IdbSchemaDiffInput as u };
|
|
227
|
+
//# sourceMappingURL=migration-B43yOFXO.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-B43yOFXO.d.mts","names":[],"sources":["../src/core/schema-diff.ts","../src/core/mig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