@prisma-next/core-control-plane 0.0.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.
- package/README.md +118 -0
- package/dist/chunk-DZPZSLCM.js +178 -0
- package/dist/chunk-DZPZSLCM.js.map +1 -0
- package/dist/exports/config-types.d.ts +69 -0
- package/dist/exports/config-types.js +53 -0
- package/dist/exports/config-types.js.map +1 -0
- package/dist/exports/config-validation.d.ts +17 -0
- package/dist/exports/config-validation.js +252 -0
- package/dist/exports/config-validation.js.map +1 -0
- package/dist/exports/emission.d.ts +42 -0
- package/dist/exports/emission.js +313 -0
- package/dist/exports/emission.js.map +1 -0
- package/dist/exports/errors.d.ts +146 -0
- package/dist/exports/errors.js +35 -0
- package/dist/exports/errors.js.map +1 -0
- package/dist/exports/schema-view.d.ts +87 -0
- package/dist/exports/schema-view.js +1 -0
- package/dist/exports/schema-view.js.map +1 -0
- package/dist/exports/types.d.ts +371 -0
- package/dist/exports/types.js +1 -0
- package/dist/exports/types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import {
|
|
2
|
+
errorConfigValidation
|
|
3
|
+
} from "../chunk-DZPZSLCM.js";
|
|
4
|
+
|
|
5
|
+
// src/config-validation.ts
|
|
6
|
+
function validateConfig(config) {
|
|
7
|
+
if (!config || typeof config !== "object") {
|
|
8
|
+
throw errorConfigValidation("object", {
|
|
9
|
+
why: "Config must be an object"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const configObj = config;
|
|
13
|
+
if (!configObj["family"]) {
|
|
14
|
+
throw errorConfigValidation("family");
|
|
15
|
+
}
|
|
16
|
+
if (!configObj["target"]) {
|
|
17
|
+
throw errorConfigValidation("target");
|
|
18
|
+
}
|
|
19
|
+
if (!configObj["adapter"]) {
|
|
20
|
+
throw errorConfigValidation("adapter");
|
|
21
|
+
}
|
|
22
|
+
const family = configObj["family"];
|
|
23
|
+
if (family["kind"] !== "family") {
|
|
24
|
+
throw errorConfigValidation("family.kind", {
|
|
25
|
+
why: 'Config.family must have kind: "family"'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (typeof family["familyId"] !== "string") {
|
|
29
|
+
throw errorConfigValidation("family.familyId", {
|
|
30
|
+
why: "Config.family must have familyId: string"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (!family["manifest"] || typeof family["manifest"] !== "object") {
|
|
34
|
+
throw errorConfigValidation("family.manifest", {
|
|
35
|
+
why: "Config.family must have manifest: ExtensionPackManifest"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!family["hook"] || typeof family["hook"] !== "object") {
|
|
39
|
+
throw errorConfigValidation("family.hook", {
|
|
40
|
+
why: "Config.family must have hook: TargetFamilyHook"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (typeof family["create"] !== "function") {
|
|
44
|
+
throw errorConfigValidation("family.create", {
|
|
45
|
+
why: "Config.family must have create: function"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const familyId = family["familyId"];
|
|
49
|
+
const target = configObj["target"];
|
|
50
|
+
if (target["kind"] !== "target") {
|
|
51
|
+
throw errorConfigValidation("target.kind", {
|
|
52
|
+
why: 'Config.target must have kind: "target"'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (typeof target["id"] !== "string") {
|
|
56
|
+
throw errorConfigValidation("target.id", {
|
|
57
|
+
why: "Config.target must have id: string"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (typeof target["familyId"] !== "string") {
|
|
61
|
+
throw errorConfigValidation("target.familyId", {
|
|
62
|
+
why: "Config.target must have familyId: string"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (!target["manifest"] || typeof target["manifest"] !== "object") {
|
|
66
|
+
throw errorConfigValidation("target.manifest", {
|
|
67
|
+
why: "Config.target must have manifest: ExtensionPackManifest"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (target["familyId"] !== familyId) {
|
|
71
|
+
throw errorConfigValidation("target.familyId", {
|
|
72
|
+
why: `Config.target.familyId must match Config.family.familyId (expected: ${familyId}, got: ${target["familyId"]})`
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (typeof target["targetId"] !== "string") {
|
|
76
|
+
throw errorConfigValidation("target.targetId", {
|
|
77
|
+
why: "Config.target must have targetId: string"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (typeof target["create"] !== "function") {
|
|
81
|
+
throw errorConfigValidation("target.create", {
|
|
82
|
+
why: "Config.target must have create: function"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const expectedTargetId = target["targetId"];
|
|
86
|
+
const adapter = configObj["adapter"];
|
|
87
|
+
if (adapter["kind"] !== "adapter") {
|
|
88
|
+
throw errorConfigValidation("adapter.kind", {
|
|
89
|
+
why: 'Config.adapter must have kind: "adapter"'
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (typeof adapter["id"] !== "string") {
|
|
93
|
+
throw errorConfigValidation("adapter.id", {
|
|
94
|
+
why: "Config.adapter must have id: string"
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (typeof adapter["familyId"] !== "string") {
|
|
98
|
+
throw errorConfigValidation("adapter.familyId", {
|
|
99
|
+
why: "Config.adapter must have familyId: string"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (!adapter["manifest"] || typeof adapter["manifest"] !== "object") {
|
|
103
|
+
throw errorConfigValidation("adapter.manifest", {
|
|
104
|
+
why: "Config.adapter must have manifest: ExtensionPackManifest"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (adapter["familyId"] !== familyId) {
|
|
108
|
+
throw errorConfigValidation("adapter.familyId", {
|
|
109
|
+
why: `Config.adapter.familyId must match Config.family.familyId (expected: ${familyId}, got: ${adapter["familyId"]})`
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (typeof adapter["targetId"] !== "string") {
|
|
113
|
+
throw errorConfigValidation("adapter.targetId", {
|
|
114
|
+
why: "Config.adapter must have targetId: string"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (adapter["targetId"] !== expectedTargetId) {
|
|
118
|
+
throw errorConfigValidation("adapter.targetId", {
|
|
119
|
+
why: `Config.adapter.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${adapter["targetId"]})`
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (typeof adapter["create"] !== "function") {
|
|
123
|
+
throw errorConfigValidation("adapter.create", {
|
|
124
|
+
why: "Config.adapter must have create: function"
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (configObj["extensions"] !== void 0) {
|
|
128
|
+
if (!Array.isArray(configObj["extensions"])) {
|
|
129
|
+
throw errorConfigValidation("extensions", {
|
|
130
|
+
why: "Config.extensions must be an array"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
for (const ext of configObj["extensions"]) {
|
|
134
|
+
if (!ext || typeof ext !== "object") {
|
|
135
|
+
throw errorConfigValidation("extensions[]", {
|
|
136
|
+
why: "Config.extensions must contain ExtensionDescriptor objects"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const extObj = ext;
|
|
140
|
+
if (extObj["kind"] !== "extension") {
|
|
141
|
+
throw errorConfigValidation("extensions[].kind", {
|
|
142
|
+
why: 'Config.extensions items must have kind: "extension"'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (typeof extObj["id"] !== "string") {
|
|
146
|
+
throw errorConfigValidation("extensions[].id", {
|
|
147
|
+
why: "Config.extensions items must have id: string"
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (typeof extObj["familyId"] !== "string") {
|
|
151
|
+
throw errorConfigValidation("extensions[].familyId", {
|
|
152
|
+
why: "Config.extensions items must have familyId: string"
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!extObj["manifest"] || typeof extObj["manifest"] !== "object") {
|
|
156
|
+
throw errorConfigValidation("extensions[].manifest", {
|
|
157
|
+
why: "Config.extensions items must have manifest: ExtensionPackManifest"
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (extObj["familyId"] !== familyId) {
|
|
161
|
+
throw errorConfigValidation("extensions[].familyId", {
|
|
162
|
+
why: `Config.extensions[].familyId must match Config.family.familyId (expected: ${familyId}, got: ${extObj["familyId"]})`
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (typeof extObj["targetId"] !== "string") {
|
|
166
|
+
throw errorConfigValidation("extensions[].targetId", {
|
|
167
|
+
why: "Config.extensions items must have targetId: string"
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (extObj["targetId"] !== expectedTargetId) {
|
|
171
|
+
throw errorConfigValidation("extensions[].targetId", {
|
|
172
|
+
why: `Config.extensions[].targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${extObj["targetId"]})`
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (typeof extObj["create"] !== "function") {
|
|
176
|
+
throw errorConfigValidation("extensions[].create", {
|
|
177
|
+
why: "Config.extensions items must have create: function"
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (configObj["driver"] !== void 0) {
|
|
183
|
+
const driver = configObj["driver"];
|
|
184
|
+
if (driver["kind"] !== "driver") {
|
|
185
|
+
throw errorConfigValidation("driver.kind", {
|
|
186
|
+
why: 'Config.driver must have kind: "driver"'
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (typeof driver["id"] !== "string") {
|
|
190
|
+
throw errorConfigValidation("driver.id", {
|
|
191
|
+
why: "Config.driver must have id: string"
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (!driver["manifest"] || typeof driver["manifest"] !== "object") {
|
|
195
|
+
throw errorConfigValidation("driver.manifest", {
|
|
196
|
+
why: "Config.driver must have manifest: ExtensionPackManifest"
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (typeof driver["familyId"] !== "string") {
|
|
200
|
+
throw errorConfigValidation("driver.familyId", {
|
|
201
|
+
why: "Config.driver must have familyId: string"
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (driver["familyId"] !== familyId) {
|
|
205
|
+
throw errorConfigValidation("driver.familyId", {
|
|
206
|
+
why: `Config.driver.familyId must match Config.family.familyId (expected: ${familyId}, got: ${driver["familyId"]})`
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (typeof driver["targetId"] !== "string") {
|
|
210
|
+
throw errorConfigValidation("driver.targetId", {
|
|
211
|
+
why: "Config.driver must have targetId: string"
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (driver["targetId"] !== expectedTargetId) {
|
|
215
|
+
throw errorConfigValidation("driver.targetId", {
|
|
216
|
+
why: `Config.driver.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${driver["targetId"]})`
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
if (typeof driver["create"] !== "function") {
|
|
220
|
+
throw errorConfigValidation("driver.create", {
|
|
221
|
+
why: "Config.driver must have create: function"
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (configObj["contract"] !== void 0) {
|
|
226
|
+
const contract = configObj["contract"];
|
|
227
|
+
if (!contract || typeof contract !== "object") {
|
|
228
|
+
throw errorConfigValidation("contract", {
|
|
229
|
+
why: "Config.contract must be an object"
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (!("source" in contract)) {
|
|
233
|
+
throw errorConfigValidation("contract.source", {
|
|
234
|
+
why: "Config.contract.source is required when contract is provided"
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
if (contract["output"] !== void 0 && typeof contract["output"] !== "string") {
|
|
238
|
+
throw errorConfigValidation("contract.output", {
|
|
239
|
+
why: "Config.contract.output must be a string when provided"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (contract["types"] !== void 0 && typeof contract["types"] !== "string") {
|
|
243
|
+
throw errorConfigValidation("contract.types", {
|
|
244
|
+
why: "Config.contract.types must be a string when provided"
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export {
|
|
250
|
+
validateConfig
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=config-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config-validation.ts"],"sourcesContent":["import type { PrismaNextConfig } from './config-types';\nimport { errorConfigValidation } from './errors';\n\n/**\n * Validates that the config has the required structure.\n * This is pure validation logic with no file I/O or CLI awareness.\n *\n * @param config - Config object to validate\n * @throws CliStructuredError if config structure is invalid\n */\nexport function validateConfig(config: unknown): asserts config is PrismaNextConfig {\n if (!config || typeof config !== 'object') {\n throw errorConfigValidation('object', {\n why: 'Config must be an object',\n });\n }\n\n const configObj = config as Record<string, unknown>;\n\n if (!configObj['family']) {\n throw errorConfigValidation('family');\n }\n\n if (!configObj['target']) {\n throw errorConfigValidation('target');\n }\n\n if (!configObj['adapter']) {\n throw errorConfigValidation('adapter');\n }\n\n // Validate family descriptor\n const family = configObj['family'] as Record<string, unknown>;\n if (family['kind'] !== 'family') {\n throw errorConfigValidation('family.kind', {\n why: 'Config.family must have kind: \"family\"',\n });\n }\n if (typeof family['familyId'] !== 'string') {\n throw errorConfigValidation('family.familyId', {\n why: 'Config.family must have familyId: string',\n });\n }\n if (!family['manifest'] || typeof family['manifest'] !== 'object') {\n throw errorConfigValidation('family.manifest', {\n why: 'Config.family must have manifest: ExtensionPackManifest',\n });\n }\n if (!family['hook'] || typeof family['hook'] !== 'object') {\n throw errorConfigValidation('family.hook', {\n why: 'Config.family must have hook: TargetFamilyHook',\n });\n }\n if (typeof family['create'] !== 'function') {\n throw errorConfigValidation('family.create', {\n why: 'Config.family must have create: function',\n });\n }\n\n const familyId = family['familyId'] as string;\n\n // Validate target descriptor\n const target = configObj['target'] as Record<string, unknown>;\n if (target['kind'] !== 'target') {\n throw errorConfigValidation('target.kind', {\n why: 'Config.target must have kind: \"target\"',\n });\n }\n if (typeof target['id'] !== 'string') {\n throw errorConfigValidation('target.id', {\n why: 'Config.target must have id: string',\n });\n }\n if (typeof target['familyId'] !== 'string') {\n throw errorConfigValidation('target.familyId', {\n why: 'Config.target must have familyId: string',\n });\n }\n if (!target['manifest'] || typeof target['manifest'] !== 'object') {\n throw errorConfigValidation('target.manifest', {\n why: 'Config.target must have manifest: ExtensionPackManifest',\n });\n }\n if (target['familyId'] !== familyId) {\n throw errorConfigValidation('target.familyId', {\n why: `Config.target.familyId must match Config.family.familyId (expected: ${familyId}, got: ${target['familyId']})`,\n });\n }\n if (typeof target['targetId'] !== 'string') {\n throw errorConfigValidation('target.targetId', {\n why: 'Config.target must have targetId: string',\n });\n }\n if (typeof target['create'] !== 'function') {\n throw errorConfigValidation('target.create', {\n why: 'Config.target must have create: function',\n });\n }\n const expectedTargetId = target['targetId'] as string;\n\n // Validate adapter descriptor\n const adapter = configObj['adapter'] as Record<string, unknown>;\n if (adapter['kind'] !== 'adapter') {\n throw errorConfigValidation('adapter.kind', {\n why: 'Config.adapter must have kind: \"adapter\"',\n });\n }\n if (typeof adapter['id'] !== 'string') {\n throw errorConfigValidation('adapter.id', {\n why: 'Config.adapter must have id: string',\n });\n }\n if (typeof adapter['familyId'] !== 'string') {\n throw errorConfigValidation('adapter.familyId', {\n why: 'Config.adapter must have familyId: string',\n });\n }\n if (!adapter['manifest'] || typeof adapter['manifest'] !== 'object') {\n throw errorConfigValidation('adapter.manifest', {\n why: 'Config.adapter must have manifest: ExtensionPackManifest',\n });\n }\n if (adapter['familyId'] !== familyId) {\n throw errorConfigValidation('adapter.familyId', {\n why: `Config.adapter.familyId must match Config.family.familyId (expected: ${familyId}, got: ${adapter['familyId']})`,\n });\n }\n if (typeof adapter['targetId'] !== 'string') {\n throw errorConfigValidation('adapter.targetId', {\n why: 'Config.adapter must have targetId: string',\n });\n }\n if (adapter['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('adapter.targetId', {\n why: `Config.adapter.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${adapter['targetId']})`,\n });\n }\n if (typeof adapter['create'] !== 'function') {\n throw errorConfigValidation('adapter.create', {\n why: 'Config.adapter must have create: function',\n });\n }\n\n // Validate extensions array if present\n if (configObj['extensions'] !== undefined) {\n if (!Array.isArray(configObj['extensions'])) {\n throw errorConfigValidation('extensions', {\n why: 'Config.extensions must be an array',\n });\n }\n for (const ext of configObj['extensions']) {\n if (!ext || typeof ext !== 'object') {\n throw errorConfigValidation('extensions[]', {\n why: 'Config.extensions must contain ExtensionDescriptor objects',\n });\n }\n const extObj = ext as Record<string, unknown>;\n if (extObj['kind'] !== 'extension') {\n throw errorConfigValidation('extensions[].kind', {\n why: 'Config.extensions items must have kind: \"extension\"',\n });\n }\n if (typeof extObj['id'] !== 'string') {\n throw errorConfigValidation('extensions[].id', {\n why: 'Config.extensions items must have id: string',\n });\n }\n if (typeof extObj['familyId'] !== 'string') {\n throw errorConfigValidation('extensions[].familyId', {\n why: 'Config.extensions items must have familyId: string',\n });\n }\n if (!extObj['manifest'] || typeof extObj['manifest'] !== 'object') {\n throw errorConfigValidation('extensions[].manifest', {\n why: 'Config.extensions items must have manifest: ExtensionPackManifest',\n });\n }\n if (extObj['familyId'] !== familyId) {\n throw errorConfigValidation('extensions[].familyId', {\n why: `Config.extensions[].familyId must match Config.family.familyId (expected: ${familyId}, got: ${extObj['familyId']})`,\n });\n }\n if (typeof extObj['targetId'] !== 'string') {\n throw errorConfigValidation('extensions[].targetId', {\n why: 'Config.extensions items must have targetId: string',\n });\n }\n if (extObj['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('extensions[].targetId', {\n why: `Config.extensions[].targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${extObj['targetId']})`,\n });\n }\n if (typeof extObj['create'] !== 'function') {\n throw errorConfigValidation('extensions[].create', {\n why: 'Config.extensions items must have create: function',\n });\n }\n }\n }\n\n // Validate driver descriptor if present\n if (configObj['driver'] !== undefined) {\n const driver = configObj['driver'] as Record<string, unknown>;\n if (driver['kind'] !== 'driver') {\n throw errorConfigValidation('driver.kind', {\n why: 'Config.driver must have kind: \"driver\"',\n });\n }\n if (typeof driver['id'] !== 'string') {\n throw errorConfigValidation('driver.id', {\n why: 'Config.driver must have id: string',\n });\n }\n if (!driver['manifest'] || typeof driver['manifest'] !== 'object') {\n throw errorConfigValidation('driver.manifest', {\n why: 'Config.driver must have manifest: ExtensionPackManifest',\n });\n }\n if (typeof driver['familyId'] !== 'string') {\n throw errorConfigValidation('driver.familyId', {\n why: 'Config.driver must have familyId: string',\n });\n }\n if (driver['familyId'] !== familyId) {\n throw errorConfigValidation('driver.familyId', {\n why: `Config.driver.familyId must match Config.family.familyId (expected: ${familyId}, got: ${driver['familyId']})`,\n });\n }\n if (typeof driver['targetId'] !== 'string') {\n throw errorConfigValidation('driver.targetId', {\n why: 'Config.driver must have targetId: string',\n });\n }\n if (driver['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('driver.targetId', {\n why: `Config.driver.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${driver['targetId']})`,\n });\n }\n if (typeof driver['create'] !== 'function') {\n throw errorConfigValidation('driver.create', {\n why: 'Config.driver must have create: function',\n });\n }\n }\n\n // Validate contract config if present (structure validation - defineConfig() handles normalization)\n if (configObj['contract'] !== undefined) {\n const contract = configObj['contract'] as Record<string, unknown>;\n if (!contract || typeof contract !== 'object') {\n throw errorConfigValidation('contract', {\n why: 'Config.contract must be an object',\n });\n }\n if (!('source' in contract)) {\n throw errorConfigValidation('contract.source', {\n why: 'Config.contract.source is required when contract is provided',\n });\n }\n if (contract['output'] !== undefined && typeof contract['output'] !== 'string') {\n throw errorConfigValidation('contract.output', {\n why: 'Config.contract.output must be a string when provided',\n });\n }\n if (contract['types'] !== undefined && typeof contract['types'] !== 'string') {\n throw errorConfigValidation('contract.types', {\n why: 'Config.contract.types must be a string when provided',\n });\n }\n }\n}\n"],"mappings":";;;;;AAUO,SAAS,eAAe,QAAqD;AAClF,MAAI,CAAC,UAAU,OAAO,WAAW,UAAU;AACzC,UAAM,sBAAsB,UAAU;AAAA,MACpC,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AAEA,QAAM,YAAY;AAElB,MAAI,CAAC,UAAU,QAAQ,GAAG;AACxB,UAAM,sBAAsB,QAAQ;AAAA,EACtC;AAEA,MAAI,CAAC,UAAU,QAAQ,GAAG;AACxB,UAAM,sBAAsB,QAAQ;AAAA,EACtC;AAEA,MAAI,CAAC,UAAU,SAAS,GAAG;AACzB,UAAM,sBAAsB,SAAS;AAAA,EACvC;AAGA,QAAM,SAAS,UAAU,QAAQ;AACjC,MAAI,OAAO,MAAM,MAAM,UAAU;AAC/B,UAAM,sBAAsB,eAAe;AAAA,MACzC,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,MAAI,OAAO,OAAO,UAAU,MAAM,UAAU;AAC1C,UAAM,sBAAsB,mBAAmB;AAAA,MAC7C,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,MAAI,CAAC,OAAO,UAAU,KAAK,OAAO,OAAO,UAAU,MAAM,UAAU;AACjE,UAAM,sBAAsB,mBAAmB;AAAA,MAC7C,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,MAAI,CAAC,OAAO,MAAM,KAAK,OAAO,OAAO,MAAM,MAAM,UAAU;AACzD,UAAM,sBAAsB,eAAe;AAAA,MACzC,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,MAAI,OAAO,OAAO,QAAQ,MAAM,YAAY;AAC1C,UAAM,sBAAsB,iBAAiB;AAAA,MAC3C,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,OAAO,UAAU;AAGlC,QAAM,SAAS,UAAU,QAAQ;AACjC,MAAI,OAAO,MAAM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AM,UAAU;AAC5E,YAAM,sBAAsB,kBAAkB;AAAA,QAC5C,KAAK;AAAA,MACP,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ContractIR } from '@prisma-next/contract/ir';
|
|
2
|
+
import { TypesImportSpec, TargetFamilyHook } from '@prisma-next/contract/types';
|
|
3
|
+
import { OperationRegistry } from '@prisma-next/operations';
|
|
4
|
+
|
|
5
|
+
declare function canonicalizeContract(ir: ContractIR & {
|
|
6
|
+
coreHash?: string;
|
|
7
|
+
profileHash?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
|
|
10
|
+
interface EmitOptions {
|
|
11
|
+
readonly outputDir: string;
|
|
12
|
+
readonly operationRegistry?: OperationRegistry;
|
|
13
|
+
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
14
|
+
readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
15
|
+
readonly extensionIds?: ReadonlyArray<string>;
|
|
16
|
+
}
|
|
17
|
+
interface EmitResult {
|
|
18
|
+
readonly contractJson: string;
|
|
19
|
+
readonly contractDts: string;
|
|
20
|
+
readonly coreHash: string;
|
|
21
|
+
readonly profileHash: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare function emit(ir: ContractIR, options: EmitOptions, targetFamily: TargetFamilyHook): Promise<EmitResult>;
|
|
25
|
+
|
|
26
|
+
type ContractInput = {
|
|
27
|
+
schemaVersion: string;
|
|
28
|
+
targetFamily: string;
|
|
29
|
+
target: string;
|
|
30
|
+
models: Record<string, unknown>;
|
|
31
|
+
relations: Record<string, unknown>;
|
|
32
|
+
storage: Record<string, unknown>;
|
|
33
|
+
extensions: Record<string, unknown>;
|
|
34
|
+
sources: Record<string, unknown>;
|
|
35
|
+
capabilities: Record<string, Record<string, boolean>>;
|
|
36
|
+
meta: Record<string, unknown>;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
declare function computeCoreHash(contract: ContractInput): string;
|
|
40
|
+
declare function computeProfileHash(contract: ContractInput): string;
|
|
41
|
+
|
|
42
|
+
export { type EmitOptions, type EmitResult, canonicalizeContract, computeCoreHash, computeProfileHash, emit };
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// src/emission/canonicalization.ts
|
|
2
|
+
var TOP_LEVEL_ORDER = [
|
|
3
|
+
"schemaVersion",
|
|
4
|
+
"canonicalVersion",
|
|
5
|
+
"targetFamily",
|
|
6
|
+
"target",
|
|
7
|
+
"coreHash",
|
|
8
|
+
"profileHash",
|
|
9
|
+
"models",
|
|
10
|
+
"storage",
|
|
11
|
+
"capabilities",
|
|
12
|
+
"extensions",
|
|
13
|
+
"meta",
|
|
14
|
+
"sources"
|
|
15
|
+
];
|
|
16
|
+
function isDefaultValue(value) {
|
|
17
|
+
if (value === false) return true;
|
|
18
|
+
if (value === null) return false;
|
|
19
|
+
if (Array.isArray(value) && value.length === 0) return true;
|
|
20
|
+
if (typeof value === "object" && value !== null) {
|
|
21
|
+
const keys = Object.keys(value);
|
|
22
|
+
return keys.length === 0;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function omitDefaults(obj, path) {
|
|
27
|
+
if (obj === null || typeof obj !== "object") {
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(obj)) {
|
|
31
|
+
return obj.map((item) => omitDefaults(item, path));
|
|
32
|
+
}
|
|
33
|
+
const result = {};
|
|
34
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
35
|
+
const currentPath = [...path, key];
|
|
36
|
+
if (key === "_generated") {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (key === "nullable" && value === false) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (key === "generated" && value === false) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (isDefaultValue(value)) {
|
|
46
|
+
const isRequiredModels = currentPath.length === 1 && currentPath[0] === "models";
|
|
47
|
+
const isRequiredTables = currentPath.length === 2 && currentPath[0] === "storage" && currentPath[1] === "tables";
|
|
48
|
+
const isRequiredRelations = currentPath.length === 1 && currentPath[0] === "relations";
|
|
49
|
+
const isRequiredExtensions = currentPath.length === 1 && currentPath[0] === "extensions";
|
|
50
|
+
const isRequiredCapabilities = currentPath.length === 1 && currentPath[0] === "capabilities";
|
|
51
|
+
const isRequiredMeta = currentPath.length === 1 && currentPath[0] === "meta";
|
|
52
|
+
const isRequiredSources = currentPath.length === 1 && currentPath[0] === "sources";
|
|
53
|
+
const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === "extensions";
|
|
54
|
+
const isModelRelations = currentPath.length === 3 && currentPath[0] === "models" && currentPath[2] === "relations";
|
|
55
|
+
const isTableUniques = currentPath.length === 4 && currentPath[0] === "storage" && currentPath[1] === "tables" && currentPath[3] === "uniques";
|
|
56
|
+
const isTableIndexes = currentPath.length === 4 && currentPath[0] === "storage" && currentPath[1] === "tables" && currentPath[3] === "indexes";
|
|
57
|
+
const isTableForeignKeys = currentPath.length === 4 && currentPath[0] === "storage" && currentPath[1] === "tables" && currentPath[3] === "foreignKeys";
|
|
58
|
+
if (!isRequiredModels && !isRequiredTables && !isRequiredRelations && !isRequiredExtensions && !isRequiredCapabilities && !isRequiredMeta && !isRequiredSources && !isExtensionNamespace && !isModelRelations && !isTableUniques && !isTableIndexes && !isTableForeignKeys) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
result[key] = omitDefaults(value, currentPath);
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function sortObjectKeys(obj) {
|
|
67
|
+
if (obj === null || typeof obj !== "object") {
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(obj)) {
|
|
71
|
+
return obj.map((item) => sortObjectKeys(item));
|
|
72
|
+
}
|
|
73
|
+
const sorted = {};
|
|
74
|
+
const keys = Object.keys(obj).sort();
|
|
75
|
+
for (const key of keys) {
|
|
76
|
+
sorted[key] = sortObjectKeys(obj[key]);
|
|
77
|
+
}
|
|
78
|
+
return sorted;
|
|
79
|
+
}
|
|
80
|
+
function sortIndexesAndUniques(storage) {
|
|
81
|
+
if (!storage || typeof storage !== "object") {
|
|
82
|
+
return storage;
|
|
83
|
+
}
|
|
84
|
+
const storageObj = storage;
|
|
85
|
+
if (!storageObj.tables || typeof storageObj.tables !== "object") {
|
|
86
|
+
return storage;
|
|
87
|
+
}
|
|
88
|
+
const tables = storageObj.tables;
|
|
89
|
+
const result = { ...storageObj };
|
|
90
|
+
result.tables = {};
|
|
91
|
+
const sortedTableNames = Object.keys(tables).sort();
|
|
92
|
+
for (const tableName of sortedTableNames) {
|
|
93
|
+
const table = tables[tableName];
|
|
94
|
+
if (!table || typeof table !== "object") {
|
|
95
|
+
result.tables[tableName] = table;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const tableObj = table;
|
|
99
|
+
const sortedTable = { ...tableObj };
|
|
100
|
+
if (Array.isArray(tableObj.indexes)) {
|
|
101
|
+
sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {
|
|
102
|
+
const nameA = a?.name || "";
|
|
103
|
+
const nameB = b?.name || "";
|
|
104
|
+
return nameA.localeCompare(nameB);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(tableObj.uniques)) {
|
|
108
|
+
sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {
|
|
109
|
+
const nameA = a?.name || "";
|
|
110
|
+
const nameB = b?.name || "";
|
|
111
|
+
return nameA.localeCompare(nameB);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
result.tables[tableName] = sortedTable;
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
function orderTopLevel(obj) {
|
|
119
|
+
const ordered = {};
|
|
120
|
+
const remaining = new Set(Object.keys(obj));
|
|
121
|
+
for (const key of TOP_LEVEL_ORDER) {
|
|
122
|
+
if (remaining.has(key)) {
|
|
123
|
+
ordered[key] = obj[key];
|
|
124
|
+
remaining.delete(key);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const key of Array.from(remaining).sort()) {
|
|
128
|
+
ordered[key] = obj[key];
|
|
129
|
+
}
|
|
130
|
+
return ordered;
|
|
131
|
+
}
|
|
132
|
+
function canonicalizeContract(ir) {
|
|
133
|
+
const normalized = {
|
|
134
|
+
schemaVersion: ir.schemaVersion,
|
|
135
|
+
targetFamily: ir.targetFamily,
|
|
136
|
+
target: ir.target,
|
|
137
|
+
models: ir.models,
|
|
138
|
+
relations: ir.relations,
|
|
139
|
+
storage: ir.storage,
|
|
140
|
+
extensions: ir.extensions,
|
|
141
|
+
capabilities: ir.capabilities,
|
|
142
|
+
meta: ir.meta,
|
|
143
|
+
sources: ir.sources
|
|
144
|
+
};
|
|
145
|
+
if (ir.coreHash !== void 0) {
|
|
146
|
+
normalized.coreHash = ir.coreHash;
|
|
147
|
+
}
|
|
148
|
+
if (ir.profileHash !== void 0) {
|
|
149
|
+
normalized.profileHash = ir.profileHash;
|
|
150
|
+
}
|
|
151
|
+
const withDefaultsOmitted = omitDefaults(normalized, []);
|
|
152
|
+
const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);
|
|
153
|
+
const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };
|
|
154
|
+
const withSortedKeys = sortObjectKeys(withSortedStorage);
|
|
155
|
+
const withOrderedTopLevel = orderTopLevel(withSortedKeys);
|
|
156
|
+
return JSON.stringify(withOrderedTopLevel, null, 2);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/emission/emit.ts
|
|
160
|
+
import { format } from "prettier";
|
|
161
|
+
|
|
162
|
+
// src/emission/hashing.ts
|
|
163
|
+
import { createHash } from "crypto";
|
|
164
|
+
function computeHash(content) {
|
|
165
|
+
const hash = createHash("sha256");
|
|
166
|
+
hash.update(content);
|
|
167
|
+
return `sha256:${hash.digest("hex")}`;
|
|
168
|
+
}
|
|
169
|
+
function computeCoreHash(contract) {
|
|
170
|
+
const coreContract = {
|
|
171
|
+
schemaVersion: contract.schemaVersion,
|
|
172
|
+
targetFamily: contract.targetFamily,
|
|
173
|
+
target: contract.target,
|
|
174
|
+
models: contract.models,
|
|
175
|
+
relations: contract.relations,
|
|
176
|
+
storage: contract.storage,
|
|
177
|
+
extensions: contract.extensions,
|
|
178
|
+
sources: contract.sources,
|
|
179
|
+
capabilities: contract.capabilities,
|
|
180
|
+
meta: contract.meta
|
|
181
|
+
};
|
|
182
|
+
const canonical = canonicalizeContract(coreContract);
|
|
183
|
+
return computeHash(canonical);
|
|
184
|
+
}
|
|
185
|
+
function computeProfileHash(contract) {
|
|
186
|
+
const profileContract = {
|
|
187
|
+
schemaVersion: contract.schemaVersion,
|
|
188
|
+
targetFamily: contract.targetFamily,
|
|
189
|
+
target: contract.target,
|
|
190
|
+
models: {},
|
|
191
|
+
relations: {},
|
|
192
|
+
storage: {},
|
|
193
|
+
extensions: {},
|
|
194
|
+
capabilities: contract.capabilities,
|
|
195
|
+
meta: {},
|
|
196
|
+
sources: {}
|
|
197
|
+
};
|
|
198
|
+
const canonical = canonicalizeContract(profileContract);
|
|
199
|
+
return computeHash(canonical);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/emission/emit.ts
|
|
203
|
+
function validateCoreStructure(ir) {
|
|
204
|
+
if (!ir.targetFamily) {
|
|
205
|
+
throw new Error("ContractIR must have targetFamily");
|
|
206
|
+
}
|
|
207
|
+
if (!ir.target) {
|
|
208
|
+
throw new Error("ContractIR must have target");
|
|
209
|
+
}
|
|
210
|
+
if (!ir.schemaVersion) {
|
|
211
|
+
throw new Error("ContractIR must have schemaVersion");
|
|
212
|
+
}
|
|
213
|
+
if (!ir.models || typeof ir.models !== "object") {
|
|
214
|
+
throw new Error("ContractIR must have models");
|
|
215
|
+
}
|
|
216
|
+
if (!ir.storage || typeof ir.storage !== "object") {
|
|
217
|
+
throw new Error("ContractIR must have storage");
|
|
218
|
+
}
|
|
219
|
+
if (!ir.relations || typeof ir.relations !== "object") {
|
|
220
|
+
throw new Error("ContractIR must have relations");
|
|
221
|
+
}
|
|
222
|
+
if (!ir.extensions || typeof ir.extensions !== "object") {
|
|
223
|
+
throw new Error("ContractIR must have extensions");
|
|
224
|
+
}
|
|
225
|
+
if (!ir.capabilities || typeof ir.capabilities !== "object") {
|
|
226
|
+
throw new Error("ContractIR must have capabilities");
|
|
227
|
+
}
|
|
228
|
+
if (!ir.meta || typeof ir.meta !== "object") {
|
|
229
|
+
throw new Error("ContractIR must have meta");
|
|
230
|
+
}
|
|
231
|
+
if (!ir.sources || typeof ir.sources !== "object") {
|
|
232
|
+
throw new Error("ContractIR must have sources");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function validateExtensions(ir, extensionIds) {
|
|
236
|
+
const extensions = ir.extensions;
|
|
237
|
+
for (const extensionId of extensionIds) {
|
|
238
|
+
if (!extensions[extensionId]) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Extension "${extensionId}" must appear in contract.extensions.${extensionId}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function emit(ir, options, targetFamily) {
|
|
246
|
+
const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds } = options;
|
|
247
|
+
validateCoreStructure(ir);
|
|
248
|
+
const ctx = {
|
|
249
|
+
...operationRegistry ? { operationRegistry } : {},
|
|
250
|
+
...codecTypeImports ? { codecTypeImports } : {},
|
|
251
|
+
...operationTypeImports ? { operationTypeImports } : {},
|
|
252
|
+
...extensionIds ? { extensionIds } : {}
|
|
253
|
+
};
|
|
254
|
+
targetFamily.validateTypes(ir, ctx);
|
|
255
|
+
targetFamily.validateStructure(ir);
|
|
256
|
+
if (extensionIds) {
|
|
257
|
+
validateExtensions(ir, extensionIds);
|
|
258
|
+
}
|
|
259
|
+
const contractJson = {
|
|
260
|
+
schemaVersion: ir.schemaVersion,
|
|
261
|
+
targetFamily: ir.targetFamily,
|
|
262
|
+
target: ir.target,
|
|
263
|
+
models: ir.models,
|
|
264
|
+
relations: ir.relations,
|
|
265
|
+
storage: ir.storage,
|
|
266
|
+
extensions: ir.extensions,
|
|
267
|
+
capabilities: ir.capabilities,
|
|
268
|
+
meta: ir.meta,
|
|
269
|
+
sources: ir.sources
|
|
270
|
+
};
|
|
271
|
+
const coreHash = computeCoreHash(contractJson);
|
|
272
|
+
const profileHash = computeProfileHash(contractJson);
|
|
273
|
+
const contractWithHashes = {
|
|
274
|
+
...ir,
|
|
275
|
+
schemaVersion: contractJson.schemaVersion,
|
|
276
|
+
coreHash,
|
|
277
|
+
profileHash
|
|
278
|
+
};
|
|
279
|
+
const contractJsonObj = JSON.parse(canonicalizeContract(contractWithHashes));
|
|
280
|
+
const contractJsonWithMeta = {
|
|
281
|
+
...contractJsonObj,
|
|
282
|
+
_generated: {
|
|
283
|
+
warning: "\u26A0\uFE0F GENERATED FILE - DO NOT EDIT",
|
|
284
|
+
message: 'This file is automatically generated by "prisma-next emit".',
|
|
285
|
+
regenerate: "To regenerate, run: prisma-next emit"
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);
|
|
289
|
+
const contractDtsRaw = targetFamily.generateContractTypes(
|
|
290
|
+
ir,
|
|
291
|
+
codecTypeImports ?? [],
|
|
292
|
+
operationTypeImports ?? []
|
|
293
|
+
);
|
|
294
|
+
const contractDts = await format(contractDtsRaw, {
|
|
295
|
+
parser: "typescript",
|
|
296
|
+
singleQuote: true,
|
|
297
|
+
semi: true,
|
|
298
|
+
printWidth: 100
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
contractJson: contractJsonString,
|
|
302
|
+
contractDts,
|
|
303
|
+
coreHash,
|
|
304
|
+
profileHash
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
export {
|
|
308
|
+
canonicalizeContract,
|
|
309
|
+
computeCoreHash,
|
|
310
|
+
computeProfileHash,
|
|
311
|
+
emit
|
|
312
|
+
};
|
|
313
|
+
//# sourceMappingURL=emission.js.map
|