@prisma-next/cli 0.3.0-dev.16 → 0.3.0-dev.163
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 +201 -0
- package/README.md +381 -128
- package/dist/cli-errors-BDCYR5ap.mjs +4 -0
- package/dist/cli-errors-Dzs7Oxz7.d.mts +3 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2671
- package/dist/cli.mjs +238 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-yYtotiSX.mjs +1063 -0
- package/dist/client-yYtotiSX.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +4 -0
- package/dist/commands/contract-infer.d.mts +7 -0
- package/dist/commands/contract-infer.d.mts.map +1 -0
- package/dist/commands/contract-infer.mjs +4 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +124 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-schema.d.mts +7 -0
- package/dist/commands/db-schema.d.mts.map +1 -0
- package/dist/commands/db-schema.mjs +52 -0
- package/dist/commands/db-schema.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +135 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-update.d.mts +7 -0
- package/dist/commands/db-update.d.mts.map +1 -0
- package/dist/commands/db-update.mjs +121 -0
- package/dist/commands/db-update.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +321 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/commands/migration-apply.d.mts +36 -0
- package/dist/commands/migration-apply.d.mts.map +1 -0
- package/dist/commands/migration-apply.mjs +243 -0
- package/dist/commands/migration-apply.mjs.map +1 -0
- package/dist/commands/migration-new.d.mts +8 -0
- package/dist/commands/migration-new.d.mts.map +1 -0
- package/dist/commands/migration-new.mjs +151 -0
- package/dist/commands/migration-new.mjs.map +1 -0
- package/dist/commands/migration-plan.d.mts +47 -0
- package/dist/commands/migration-plan.d.mts.map +1 -0
- package/dist/commands/migration-plan.mjs +312 -0
- package/dist/commands/migration-plan.mjs.map +1 -0
- package/dist/commands/migration-ref.d.mts +43 -0
- package/dist/commands/migration-ref.d.mts.map +1 -0
- package/dist/commands/migration-ref.mjs +194 -0
- package/dist/commands/migration-ref.mjs.map +1 -0
- package/dist/commands/migration-show.d.mts +28 -0
- package/dist/commands/migration-show.d.mts.map +1 -0
- package/dist/commands/migration-show.mjs +139 -0
- package/dist/commands/migration-show.mjs.map +1 -0
- package/dist/commands/migration-status.d.mts +86 -0
- package/dist/commands/migration-status.d.mts.map +1 -0
- package/dist/commands/migration-status.mjs +4 -0
- package/dist/commands/migration-verify.d.mts +16 -0
- package/dist/commands/migration-verify.d.mts.map +1 -0
- package/dist/commands/migration-verify.mjs +109 -0
- package/dist/commands/migration-verify.mjs.map +1 -0
- package/dist/config-loader-C4VXKl8f.mjs +43 -0
- package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/contract-emit-Bk_eEDKu.mjs +187 -0
- package/dist/contract-emit-Bk_eEDKu.mjs.map +1 -0
- package/dist/contract-infer-suMDmFSG.mjs +89 -0
- package/dist/contract-infer-suMDmFSG.mjs.map +1 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +624 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +109 -0
- package/dist/exports/control-api.mjs.map +1 -0
- package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +137 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/extract-operation-statements-BVlb3jxp.mjs +13 -0
- package/dist/extract-operation-statements-BVlb3jxp.mjs.map +1 -0
- package/dist/extract-sql-ddl-6EVSOThm.mjs +26 -0
- package/dist/extract-sql-ddl-6EVSOThm.mjs.map +1 -0
- package/dist/framework-components-BAsliT4V.mjs +59 -0
- package/dist/framework-components-BAsliT4V.mjs.map +1 -0
- package/dist/inspect-live-schema-HMutsJYh.mjs +91 -0
- package/dist/inspect-live-schema-HMutsJYh.mjs.map +1 -0
- package/dist/migration-command-scaffold-Dg7CKKCg.mjs +105 -0
- package/dist/migration-command-scaffold-Dg7CKKCg.mjs.map +1 -0
- package/dist/migration-status-BqfVmC0w.mjs +1582 -0
- package/dist/migration-status-BqfVmC0w.mjs.map +1 -0
- package/dist/migrations-Bv8oeiY_.mjs +173 -0
- package/dist/migrations-Bv8oeiY_.mjs.map +1 -0
- package/dist/progress-adapter-D4x8SbJa.mjs +43 -0
- package/dist/progress-adapter-D4x8SbJa.mjs.map +1 -0
- package/dist/terminal-ui-N5tR-ob5.mjs +967 -0
- package/dist/terminal-ui-N5tR-ob5.mjs.map +1 -0
- package/dist/verify-WARh5TjK.mjs +385 -0
- package/dist/verify-WARh5TjK.mjs.map +1 -0
- package/package.json +88 -42
- package/src/cli.ts +113 -58
- package/src/commands/contract-emit.ts +237 -144
- package/src/commands/contract-infer-paths.ts +32 -0
- package/src/commands/contract-infer.ts +143 -0
- package/src/commands/db-init.ts +97 -219
- package/src/commands/db-schema.ts +77 -0
- package/src/commands/db-sign.ts +208 -229
- package/src/commands/db-update.ts +236 -0
- package/src/commands/db-verify.ts +504 -184
- package/src/commands/inspect-live-schema.ts +170 -0
- package/src/commands/migration-apply.ts +427 -0
- package/src/commands/migration-new.ts +260 -0
- package/src/commands/migration-plan.ts +519 -0
- package/src/commands/migration-ref.ts +305 -0
- package/src/commands/migration-show.ts +246 -0
- package/src/commands/migration-status.ts +864 -0
- package/src/commands/migration-verify.ts +180 -0
- package/src/config-loader.ts +13 -3
- package/src/control-api/client.ts +424 -72
- package/src/control-api/contract-enrichment.ts +119 -0
- package/src/control-api/errors.ts +9 -0
- package/src/control-api/operations/contract-emit.ts +174 -0
- package/src/control-api/operations/db-init.ts +53 -49
- package/src/control-api/operations/db-update.ts +220 -0
- package/src/control-api/operations/extract-operation-statements.ts +14 -0
- package/src/control-api/operations/extract-sql-ddl.ts +47 -0
- package/src/control-api/operations/migration-apply.ts +191 -0
- package/src/control-api/operations/migration-helpers.ts +49 -0
- package/src/control-api/types.ts +388 -18
- package/src/exports/config-types.ts +4 -3
- package/src/exports/control-api.ts +21 -2
- package/src/load-ts-contract.ts +30 -19
- package/src/utils/cli-errors.ts +14 -8
- package/src/utils/command-helpers.ts +302 -3
- package/src/utils/formatters/emit.ts +67 -0
- package/src/utils/formatters/errors.ts +82 -0
- package/src/utils/formatters/graph-migration-mapper.ts +240 -0
- package/src/utils/formatters/graph-render.ts +1323 -0
- package/src/utils/formatters/graph-types.ts +120 -0
- package/src/utils/formatters/help.ts +380 -0
- package/src/utils/formatters/helpers.ts +28 -0
- package/src/utils/formatters/migrations.ts +346 -0
- package/src/utils/formatters/styled.ts +212 -0
- package/src/utils/formatters/verify.ts +621 -0
- package/src/utils/framework-components.ts +13 -10
- package/src/utils/global-flags.ts +41 -23
- package/src/utils/migration-command-scaffold.ts +184 -0
- package/src/utils/migration-types.ts +12 -0
- package/src/utils/progress-adapter.ts +18 -29
- package/src/utils/result-handler.ts +12 -13
- package/src/utils/shutdown.ts +92 -0
- package/src/utils/suggest-command.ts +31 -0
- package/src/utils/terminal-ui.ts +276 -0
- package/dist/chunk-5MPKZYVI.js +0 -47
- package/dist/chunk-5MPKZYVI.js.map +0 -1
- package/dist/chunk-6EPKRATC.js +0 -91
- package/dist/chunk-6EPKRATC.js.map +0 -1
- package/dist/chunk-74IELXRA.js +0 -371
- package/dist/chunk-74IELXRA.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-U6QI3AZ3.js +0 -133
- package/dist/chunk-U6QI3AZ3.js.map +0 -1
- package/dist/chunk-VI2YETW7.js +0 -38
- package/dist/chunk-VI2YETW7.js.map +0 -1
- package/dist/chunk-ZG5T6OB5.js +0 -923
- package/dist/chunk-ZG5T6OB5.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -3
- package/dist/commands/contract-emit.d.ts.map +0 -1
- package/dist/commands/contract-emit.js +0 -11
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -3
- package/dist/commands/db-init.d.ts.map +0 -1
- package/dist/commands/db-init.js +0 -302
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -3
- package/dist/commands/db-introspect.d.ts.map +0 -1
- package/dist/commands/db-introspect.js +0 -185
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -3
- package/dist/commands/db-schema-verify.d.ts.map +0 -1
- package/dist/commands/db-schema-verify.js +0 -163
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -3
- package/dist/commands/db-sign.d.ts.map +0 -1
- package/dist/commands/db-sign.js +0 -198
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -3
- package/dist/commands/db-verify.d.ts.map +0 -1
- package/dist/commands/db-verify.js +0 -172
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/control-api/client.d.ts +0 -13
- package/dist/control-api/client.d.ts.map +0 -1
- package/dist/control-api/operations/db-init.d.ts +0 -29
- package/dist/control-api/operations/db-init.d.ts.map +0 -1
- package/dist/control-api/types.d.ts +0 -256
- package/dist/control-api/types.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -6
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/control-api.d.ts +0 -13
- package/dist/exports/control-api.d.ts.map +0 -1
- package/dist/exports/control-api.js +0 -9
- package/dist/exports/control-api.js.map +0 -1
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -177
- package/dist/exports/index.js.map +0 -1
- package/dist/load-ts-contract.d.ts.map +0 -1
- package/dist/utils/action.d.ts +0 -16
- package/dist/utils/action.d.ts.map +0 -1
- package/dist/utils/cli-errors.d.ts +0 -7
- package/dist/utils/cli-errors.d.ts.map +0 -1
- package/dist/utils/command-helpers.d.ts +0 -12
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/framework-components.d.ts +0 -70
- package/dist/utils/framework-components.d.ts.map +0 -1
- package/dist/utils/global-flags.d.ts +0 -25
- package/dist/utils/global-flags.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -142
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/progress-adapter.d.ts +0 -26
- package/dist/utils/progress-adapter.d.ts.map +0 -1
- package/dist/utils/result-handler.d.ts +0 -15
- package/dist/utils/result-handler.d.ts.map +0 -1
- package/dist/utils/spinner.d.ts +0 -29
- package/dist/utils/spinner.d.ts.map +0 -1
- package/src/commands/db-introspect.ts +0 -254
- package/src/commands/db-schema-verify.ts +0 -231
- package/src/utils/action.ts +0 -43
- package/src/utils/output.ts +0 -1471
- package/src/utils/spinner.ts +0 -67
package/dist/chunk-74IELXRA.js
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertFrameworkComponentsCompatible
|
|
3
|
-
} from "./chunk-6EPKRATC.js";
|
|
4
|
-
|
|
5
|
-
// src/control-api/client.ts
|
|
6
|
-
import { createControlPlaneStack } from "@prisma-next/core-control-plane/stack";
|
|
7
|
-
|
|
8
|
-
// src/control-api/operations/db-init.ts
|
|
9
|
-
import { notOk, ok } from "@prisma-next/utils/result";
|
|
10
|
-
async function executeDbInit(options) {
|
|
11
|
-
const { driver, familyInstance, contractIR, mode, migrations, frameworkComponents, onProgress } = options;
|
|
12
|
-
const planner = migrations.createPlanner(familyInstance);
|
|
13
|
-
const runner = migrations.createRunner(familyInstance);
|
|
14
|
-
const introspectSpanId = "introspect";
|
|
15
|
-
onProgress?.({
|
|
16
|
-
action: "dbInit",
|
|
17
|
-
kind: "spanStart",
|
|
18
|
-
spanId: introspectSpanId,
|
|
19
|
-
label: "Introspecting database schema"
|
|
20
|
-
});
|
|
21
|
-
const schemaIR = await familyInstance.introspect({ driver });
|
|
22
|
-
onProgress?.({
|
|
23
|
-
action: "dbInit",
|
|
24
|
-
kind: "spanEnd",
|
|
25
|
-
spanId: introspectSpanId,
|
|
26
|
-
outcome: "ok"
|
|
27
|
-
});
|
|
28
|
-
const policy = { allowedOperationClasses: ["additive"] };
|
|
29
|
-
const planSpanId = "plan";
|
|
30
|
-
onProgress?.({
|
|
31
|
-
action: "dbInit",
|
|
32
|
-
kind: "spanStart",
|
|
33
|
-
spanId: planSpanId,
|
|
34
|
-
label: "Planning migration"
|
|
35
|
-
});
|
|
36
|
-
const plannerResult = await planner.plan({
|
|
37
|
-
contract: contractIR,
|
|
38
|
-
schema: schemaIR,
|
|
39
|
-
policy,
|
|
40
|
-
frameworkComponents
|
|
41
|
-
});
|
|
42
|
-
if (plannerResult.kind === "failure") {
|
|
43
|
-
onProgress?.({
|
|
44
|
-
action: "dbInit",
|
|
45
|
-
kind: "spanEnd",
|
|
46
|
-
spanId: planSpanId,
|
|
47
|
-
outcome: "error"
|
|
48
|
-
});
|
|
49
|
-
return notOk({
|
|
50
|
-
code: "PLANNING_FAILED",
|
|
51
|
-
summary: "Migration planning failed due to conflicts",
|
|
52
|
-
conflicts: plannerResult.conflicts,
|
|
53
|
-
why: void 0,
|
|
54
|
-
meta: void 0
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const migrationPlan = plannerResult.plan;
|
|
58
|
-
onProgress?.({
|
|
59
|
-
action: "dbInit",
|
|
60
|
-
kind: "spanEnd",
|
|
61
|
-
spanId: planSpanId,
|
|
62
|
-
outcome: "ok"
|
|
63
|
-
});
|
|
64
|
-
const checkMarkerSpanId = "checkMarker";
|
|
65
|
-
onProgress?.({
|
|
66
|
-
action: "dbInit",
|
|
67
|
-
kind: "spanStart",
|
|
68
|
-
spanId: checkMarkerSpanId,
|
|
69
|
-
label: "Checking contract marker"
|
|
70
|
-
});
|
|
71
|
-
const existingMarker = await familyInstance.readMarker({ driver });
|
|
72
|
-
if (existingMarker) {
|
|
73
|
-
const markerMatchesDestination = existingMarker.coreHash === migrationPlan.destination.coreHash && (!migrationPlan.destination.profileHash || existingMarker.profileHash === migrationPlan.destination.profileHash);
|
|
74
|
-
if (markerMatchesDestination) {
|
|
75
|
-
onProgress?.({
|
|
76
|
-
action: "dbInit",
|
|
77
|
-
kind: "spanEnd",
|
|
78
|
-
spanId: checkMarkerSpanId,
|
|
79
|
-
outcome: "skipped"
|
|
80
|
-
});
|
|
81
|
-
const result2 = {
|
|
82
|
-
mode,
|
|
83
|
-
plan: { operations: [] },
|
|
84
|
-
...mode === "apply" ? {
|
|
85
|
-
execution: { operationsPlanned: 0, operationsExecuted: 0 },
|
|
86
|
-
marker: {
|
|
87
|
-
coreHash: existingMarker.coreHash,
|
|
88
|
-
profileHash: existingMarker.profileHash
|
|
89
|
-
}
|
|
90
|
-
} : {},
|
|
91
|
-
summary: "Database already at target contract state"
|
|
92
|
-
};
|
|
93
|
-
return ok(result2);
|
|
94
|
-
}
|
|
95
|
-
onProgress?.({
|
|
96
|
-
action: "dbInit",
|
|
97
|
-
kind: "spanEnd",
|
|
98
|
-
spanId: checkMarkerSpanId,
|
|
99
|
-
outcome: "error"
|
|
100
|
-
});
|
|
101
|
-
return notOk({
|
|
102
|
-
code: "MARKER_ORIGIN_MISMATCH",
|
|
103
|
-
summary: "Existing contract marker does not match plan destination",
|
|
104
|
-
marker: {
|
|
105
|
-
coreHash: existingMarker.coreHash,
|
|
106
|
-
profileHash: existingMarker.profileHash
|
|
107
|
-
},
|
|
108
|
-
destination: {
|
|
109
|
-
coreHash: migrationPlan.destination.coreHash,
|
|
110
|
-
profileHash: migrationPlan.destination.profileHash
|
|
111
|
-
},
|
|
112
|
-
why: void 0,
|
|
113
|
-
conflicts: void 0,
|
|
114
|
-
meta: void 0
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
onProgress?.({
|
|
118
|
-
action: "dbInit",
|
|
119
|
-
kind: "spanEnd",
|
|
120
|
-
spanId: checkMarkerSpanId,
|
|
121
|
-
outcome: "ok"
|
|
122
|
-
});
|
|
123
|
-
if (mode === "plan") {
|
|
124
|
-
const result2 = {
|
|
125
|
-
mode: "plan",
|
|
126
|
-
plan: { operations: migrationPlan.operations },
|
|
127
|
-
summary: `Planned ${migrationPlan.operations.length} operation(s)`
|
|
128
|
-
};
|
|
129
|
-
return ok(result2);
|
|
130
|
-
}
|
|
131
|
-
const applySpanId = "apply";
|
|
132
|
-
onProgress?.({
|
|
133
|
-
action: "dbInit",
|
|
134
|
-
kind: "spanStart",
|
|
135
|
-
spanId: applySpanId,
|
|
136
|
-
label: "Applying migration plan"
|
|
137
|
-
});
|
|
138
|
-
const callbacks = onProgress ? {
|
|
139
|
-
onOperationStart: (op) => {
|
|
140
|
-
onProgress({
|
|
141
|
-
action: "dbInit",
|
|
142
|
-
kind: "spanStart",
|
|
143
|
-
spanId: `operation:${op.id}`,
|
|
144
|
-
parentSpanId: applySpanId,
|
|
145
|
-
label: op.label
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
onOperationComplete: (op) => {
|
|
149
|
-
onProgress({
|
|
150
|
-
action: "dbInit",
|
|
151
|
-
kind: "spanEnd",
|
|
152
|
-
spanId: `operation:${op.id}`,
|
|
153
|
-
outcome: "ok"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
} : void 0;
|
|
157
|
-
const runnerResult = await runner.execute({
|
|
158
|
-
plan: migrationPlan,
|
|
159
|
-
driver,
|
|
160
|
-
destinationContract: contractIR,
|
|
161
|
-
policy,
|
|
162
|
-
...callbacks ? { callbacks } : {},
|
|
163
|
-
// db init plans and applies back-to-back from a fresh introspection, so per-operation
|
|
164
|
-
// pre/postchecks and the idempotency probe are usually redundant overhead. We still
|
|
165
|
-
// enforce marker/origin compatibility and a full schema verification after apply.
|
|
166
|
-
executionChecks: {
|
|
167
|
-
prechecks: false,
|
|
168
|
-
postchecks: false,
|
|
169
|
-
idempotencyChecks: false
|
|
170
|
-
},
|
|
171
|
-
frameworkComponents
|
|
172
|
-
});
|
|
173
|
-
if (!runnerResult.ok) {
|
|
174
|
-
onProgress?.({
|
|
175
|
-
action: "dbInit",
|
|
176
|
-
kind: "spanEnd",
|
|
177
|
-
spanId: applySpanId,
|
|
178
|
-
outcome: "error"
|
|
179
|
-
});
|
|
180
|
-
return notOk({
|
|
181
|
-
code: "RUNNER_FAILED",
|
|
182
|
-
summary: runnerResult.failure.summary,
|
|
183
|
-
why: runnerResult.failure.why,
|
|
184
|
-
meta: runnerResult.failure.meta,
|
|
185
|
-
conflicts: void 0
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const execution = runnerResult.value;
|
|
189
|
-
onProgress?.({
|
|
190
|
-
action: "dbInit",
|
|
191
|
-
kind: "spanEnd",
|
|
192
|
-
spanId: applySpanId,
|
|
193
|
-
outcome: "ok"
|
|
194
|
-
});
|
|
195
|
-
const result = {
|
|
196
|
-
mode: "apply",
|
|
197
|
-
plan: { operations: migrationPlan.operations },
|
|
198
|
-
execution: {
|
|
199
|
-
operationsPlanned: execution.operationsPlanned,
|
|
200
|
-
operationsExecuted: execution.operationsExecuted
|
|
201
|
-
},
|
|
202
|
-
marker: migrationPlan.destination.profileHash ? {
|
|
203
|
-
coreHash: migrationPlan.destination.coreHash,
|
|
204
|
-
profileHash: migrationPlan.destination.profileHash
|
|
205
|
-
} : { coreHash: migrationPlan.destination.coreHash },
|
|
206
|
-
summary: `Applied ${execution.operationsExecuted} operation(s), marker written`
|
|
207
|
-
};
|
|
208
|
-
return ok(result);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/control-api/client.ts
|
|
212
|
-
function createControlClient(options) {
|
|
213
|
-
return new ControlClientImpl(options);
|
|
214
|
-
}
|
|
215
|
-
var ControlClientImpl = class {
|
|
216
|
-
options;
|
|
217
|
-
stack = null;
|
|
218
|
-
driver = null;
|
|
219
|
-
familyInstance = null;
|
|
220
|
-
frameworkComponents = null;
|
|
221
|
-
initialized = false;
|
|
222
|
-
defaultConnection;
|
|
223
|
-
constructor(options) {
|
|
224
|
-
this.options = options;
|
|
225
|
-
this.defaultConnection = options.connection;
|
|
226
|
-
}
|
|
227
|
-
init() {
|
|
228
|
-
if (this.initialized) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
this.stack = createControlPlaneStack({
|
|
232
|
-
target: this.options.target,
|
|
233
|
-
adapter: this.options.adapter,
|
|
234
|
-
driver: this.options.driver,
|
|
235
|
-
extensionPacks: this.options.extensionPacks
|
|
236
|
-
});
|
|
237
|
-
this.familyInstance = this.options.family.create(this.stack);
|
|
238
|
-
const rawComponents = [
|
|
239
|
-
this.options.target,
|
|
240
|
-
this.options.adapter,
|
|
241
|
-
...this.options.extensionPacks ?? []
|
|
242
|
-
];
|
|
243
|
-
this.frameworkComponents = assertFrameworkComponentsCompatible(
|
|
244
|
-
this.options.family.familyId,
|
|
245
|
-
this.options.target.targetId,
|
|
246
|
-
rawComponents
|
|
247
|
-
);
|
|
248
|
-
this.initialized = true;
|
|
249
|
-
}
|
|
250
|
-
async connect(connection) {
|
|
251
|
-
this.init();
|
|
252
|
-
if (this.driver) {
|
|
253
|
-
throw new Error("Already connected. Call close() before reconnecting.");
|
|
254
|
-
}
|
|
255
|
-
const resolvedConnection = connection ?? this.defaultConnection;
|
|
256
|
-
if (resolvedConnection === void 0) {
|
|
257
|
-
throw new Error(
|
|
258
|
-
"No connection provided. Pass a connection to connect() or provide a default connection when creating the client."
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
if (!this.stack?.driver) {
|
|
262
|
-
throw new Error(
|
|
263
|
-
"Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations."
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
this.driver = await this.stack?.driver.create(resolvedConnection);
|
|
267
|
-
}
|
|
268
|
-
async close() {
|
|
269
|
-
if (this.driver) {
|
|
270
|
-
await this.driver.close();
|
|
271
|
-
this.driver = null;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
async ensureConnected() {
|
|
275
|
-
this.init();
|
|
276
|
-
if (!this.driver && this.defaultConnection !== void 0) {
|
|
277
|
-
await this.connect(this.defaultConnection);
|
|
278
|
-
}
|
|
279
|
-
if (!this.driver || !this.familyInstance || !this.frameworkComponents) {
|
|
280
|
-
throw new Error("Not connected. Call connect(connection) first.");
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
driver: this.driver,
|
|
284
|
-
familyInstance: this.familyInstance,
|
|
285
|
-
frameworkComponents: this.frameworkComponents
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
async verify(options) {
|
|
289
|
-
const { driver, familyInstance } = await this.ensureConnected();
|
|
290
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
291
|
-
return familyInstance.verify({
|
|
292
|
-
driver,
|
|
293
|
-
contractIR,
|
|
294
|
-
expectedTargetId: this.options.target.targetId,
|
|
295
|
-
contractPath: ""
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
async schemaVerify(options) {
|
|
299
|
-
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
300
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
301
|
-
return familyInstance.schemaVerify({
|
|
302
|
-
driver,
|
|
303
|
-
contractIR,
|
|
304
|
-
strict: options.strict ?? false,
|
|
305
|
-
contractPath: "",
|
|
306
|
-
frameworkComponents
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
async sign(options) {
|
|
310
|
-
const { driver, familyInstance } = await this.ensureConnected();
|
|
311
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
312
|
-
return familyInstance.sign({
|
|
313
|
-
driver,
|
|
314
|
-
contractIR,
|
|
315
|
-
contractPath: ""
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
async dbInit(options) {
|
|
319
|
-
const { onProgress } = options;
|
|
320
|
-
if (options.connection !== void 0) {
|
|
321
|
-
onProgress?.({
|
|
322
|
-
action: "dbInit",
|
|
323
|
-
kind: "spanStart",
|
|
324
|
-
spanId: "connect",
|
|
325
|
-
label: "Connecting to database..."
|
|
326
|
-
});
|
|
327
|
-
try {
|
|
328
|
-
await this.connect(options.connection);
|
|
329
|
-
onProgress?.({
|
|
330
|
-
action: "dbInit",
|
|
331
|
-
kind: "spanEnd",
|
|
332
|
-
spanId: "connect",
|
|
333
|
-
outcome: "ok"
|
|
334
|
-
});
|
|
335
|
-
} catch (error) {
|
|
336
|
-
onProgress?.({
|
|
337
|
-
action: "dbInit",
|
|
338
|
-
kind: "spanEnd",
|
|
339
|
-
spanId: "connect",
|
|
340
|
-
outcome: "error"
|
|
341
|
-
});
|
|
342
|
-
throw error;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
346
|
-
if (!this.options.target.migrations) {
|
|
347
|
-
throw new Error(`Target "${this.options.target.targetId}" does not support migrations`);
|
|
348
|
-
}
|
|
349
|
-
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
350
|
-
return executeDbInit({
|
|
351
|
-
driver,
|
|
352
|
-
familyInstance,
|
|
353
|
-
contractIR,
|
|
354
|
-
mode: options.mode,
|
|
355
|
-
migrations: this.options.target.migrations,
|
|
356
|
-
frameworkComponents,
|
|
357
|
-
...onProgress ? { onProgress } : {}
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
async introspect(options) {
|
|
361
|
-
const { driver, familyInstance } = await this.ensureConnected();
|
|
362
|
-
const _schema = options?.schema;
|
|
363
|
-
void _schema;
|
|
364
|
-
return familyInstance.introspect({ driver });
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
export {
|
|
369
|
-
createControlClient
|
|
370
|
-
};
|
|
371
|
-
//# sourceMappingURL=chunk-74IELXRA.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/control-api/client.ts","../src/control-api/operations/db-init.ts"],"sourcesContent":["import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';\nimport { createControlPlaneStack } from '@prisma-next/core-control-plane/stack';\nimport type {\n ControlDriverInstance,\n ControlFamilyInstance,\n ControlPlaneStack,\n SignDatabaseResult,\n VerifyDatabaseResult,\n VerifyDatabaseSchemaResult,\n} from '@prisma-next/core-control-plane/types';\nimport { assertFrameworkComponentsCompatible } from '../utils/framework-components';\nimport { executeDbInit } from './operations/db-init';\nimport type {\n ControlClient,\n ControlClientOptions,\n DbInitOptions,\n DbInitResult,\n IntrospectOptions,\n SchemaVerifyOptions,\n SignOptions,\n VerifyOptions,\n} from './types';\n\n/**\n * Creates a programmatic control client for Prisma Next operations.\n *\n * The client accepts framework component descriptors at creation time,\n * manages driver lifecycle via connect()/close(), and exposes domain\n * operations that delegate to the existing family instance methods.\n *\n * @see {@link ControlClient} for the client interface\n * @see README.md \"Programmatic Control API\" section for usage examples\n */\nexport function createControlClient(options: ControlClientOptions): ControlClient {\n return new ControlClientImpl(options);\n}\n\n/**\n * Implementation of ControlClient.\n * Manages initialization and connection state, delegates operations to family instance.\n */\nclass ControlClientImpl implements ControlClient {\n private readonly options: ControlClientOptions;\n private stack: ControlPlaneStack<string, string> | null = null;\n private driver: ControlDriverInstance<string, string> | null = null;\n private familyInstance: ControlFamilyInstance<string> | null = null;\n private frameworkComponents: ReadonlyArray<\n TargetBoundComponentDescriptor<string, string>\n > | null = null;\n private initialized = false;\n private readonly defaultConnection: unknown;\n\n constructor(options: ControlClientOptions) {\n this.options = options;\n this.defaultConnection = options.connection;\n }\n\n init(): void {\n if (this.initialized) {\n return; // Idempotent\n }\n\n // Create the control plane stack\n this.stack = createControlPlaneStack({\n target: this.options.target,\n adapter: this.options.adapter,\n driver: this.options.driver,\n extensionPacks: this.options.extensionPacks,\n });\n\n // Create family instance using the stack\n this.familyInstance = this.options.family.create(this.stack);\n\n // Validate and type-narrow framework components\n const rawComponents = [\n this.options.target,\n this.options.adapter,\n ...(this.options.extensionPacks ?? []),\n ];\n this.frameworkComponents = assertFrameworkComponentsCompatible(\n this.options.family.familyId,\n this.options.target.targetId,\n rawComponents,\n );\n\n this.initialized = true;\n }\n\n async connect(connection?: unknown): Promise<void> {\n // Auto-init if needed\n this.init();\n\n if (this.driver) {\n throw new Error('Already connected. Call close() before reconnecting.');\n }\n\n // Resolve connection: argument > default from options\n const resolvedConnection = connection ?? this.defaultConnection;\n if (resolvedConnection === undefined) {\n throw new Error(\n 'No connection provided. Pass a connection to connect() or provide a default connection when creating the client.',\n );\n }\n\n // Check for driver descriptor\n if (!this.stack?.driver) {\n throw new Error(\n 'Driver is not configured. Pass a driver descriptor when creating the control client to enable database operations.',\n );\n }\n\n // Create driver instance\n // Cast through any since connection type is driver-specific at runtime.\n // The driver descriptor is typed with any for TConnection in ControlClientOptions,\n // but createControlPlaneStack defaults it to string. We bridge this at runtime.\n // biome-ignore lint/suspicious/noExplicitAny: required for runtime connection type flexibility\n this.driver = await this.stack?.driver.create(resolvedConnection as any);\n }\n\n async close(): Promise<void> {\n if (this.driver) {\n await this.driver.close();\n this.driver = null;\n }\n }\n\n private async ensureConnected(): Promise<{\n driver: ControlDriverInstance<string, string>;\n familyInstance: ControlFamilyInstance<string>;\n frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<string, string>>;\n }> {\n // Auto-init if needed\n this.init();\n\n // Auto-connect if not connected and default connection is available\n if (!this.driver && this.defaultConnection !== undefined) {\n await this.connect(this.defaultConnection);\n }\n\n if (!this.driver || !this.familyInstance || !this.frameworkComponents) {\n throw new Error('Not connected. Call connect(connection) first.');\n }\n return {\n driver: this.driver,\n familyInstance: this.familyInstance,\n frameworkComponents: this.frameworkComponents,\n };\n }\n\n async verify(options: VerifyOptions): Promise<VerifyDatabaseResult> {\n const { driver, familyInstance } = await this.ensureConnected();\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to family instance verify method\n // Note: We pass empty strings for contractPath/configPath since the programmatic\n // API doesn't deal with file paths. The family instance accepts these as optional\n // metadata for error reporting.\n return familyInstance.verify({\n driver,\n contractIR,\n expectedTargetId: this.options.target.targetId,\n contractPath: '',\n });\n }\n\n async schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult> {\n const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to family instance schemaVerify method\n return familyInstance.schemaVerify({\n driver,\n contractIR,\n strict: options.strict ?? false,\n contractPath: '',\n frameworkComponents,\n });\n }\n\n async sign(options: SignOptions): Promise<SignDatabaseResult> {\n const { driver, familyInstance } = await this.ensureConnected();\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to family instance sign method\n return familyInstance.sign({\n driver,\n contractIR,\n contractPath: '',\n });\n }\n\n async dbInit(options: DbInitOptions): Promise<DbInitResult> {\n const { onProgress } = options;\n\n // Connect with progress span if connection provided\n if (options.connection !== undefined) {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: 'connect',\n label: 'Connecting to database...',\n });\n try {\n await this.connect(options.connection);\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: 'connect',\n outcome: 'ok',\n });\n } catch (error) {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: 'connect',\n outcome: 'error',\n });\n throw error;\n }\n }\n\n const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();\n\n // Check target supports migrations\n if (!this.options.target.migrations) {\n throw new Error(`Target \"${this.options.target.targetId}\" does not support migrations`);\n }\n\n // Validate contract using family instance\n const contractIR = familyInstance.validateContractIR(options.contractIR);\n\n // Delegate to extracted dbInit operation\n return executeDbInit({\n driver,\n familyInstance,\n contractIR,\n mode: options.mode,\n migrations: this.options.target.migrations,\n frameworkComponents,\n ...(onProgress ? { onProgress } : {}),\n });\n }\n\n async introspect(options?: IntrospectOptions): Promise<unknown> {\n const { driver, familyInstance } = await this.ensureConnected();\n\n // TODO: Pass schema option to familyInstance.introspect when schema filtering is implemented\n const _schema = options?.schema;\n void _schema;\n\n return familyInstance.introspect({ driver });\n }\n}\n","import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport type {\n ControlDriverInstance,\n ControlFamilyInstance,\n MigrationPlan,\n MigrationPlannerResult,\n MigrationPlanOperation,\n MigrationRunnerResult,\n TargetMigrationsCapability,\n} from '@prisma-next/core-control-plane/types';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport type { DbInitResult, DbInitSuccess, OnControlProgress } from '../types';\n\n/**\n * Options for executing dbInit operation.\n */\nexport interface ExecuteDbInitOptions<TFamilyId extends string, TTargetId extends string> {\n readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;\n readonly familyInstance: ControlFamilyInstance<TFamilyId>;\n readonly contractIR: ContractIR;\n readonly mode: 'plan' | 'apply';\n readonly migrations: TargetMigrationsCapability<\n TFamilyId,\n TTargetId,\n ControlFamilyInstance<TFamilyId>\n >;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;\n /** Optional progress callback for observing operation progress */\n readonly onProgress?: OnControlProgress;\n}\n\n/**\n * Executes the dbInit operation.\n *\n * This is the core logic extracted from the CLI command, without any file I/O,\n * process.exit(), or console output. It uses the Result pattern to return\n * success or failure details.\n *\n * @param options - The options for executing dbInit\n * @returns Result with DbInitSuccess on success, DbInitFailure on failure\n */\nexport async function executeDbInit<TFamilyId extends string, TTargetId extends string>(\n options: ExecuteDbInitOptions<TFamilyId, TTargetId>,\n): Promise<DbInitResult> {\n const { driver, familyInstance, contractIR, mode, migrations, frameworkComponents, onProgress } =\n options;\n\n // Create planner and runner from target migrations capability\n const planner = migrations.createPlanner(familyInstance);\n const runner = migrations.createRunner(familyInstance);\n\n // Introspect live schema\n const introspectSpanId = 'introspect';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: introspectSpanId,\n label: 'Introspecting database schema',\n });\n const schemaIR = await familyInstance.introspect({ driver });\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: introspectSpanId,\n outcome: 'ok',\n });\n\n // Policy for init mode (additive only)\n const policy = { allowedOperationClasses: ['additive'] as const };\n\n // Plan migration\n const planSpanId = 'plan';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: planSpanId,\n label: 'Planning migration',\n });\n const plannerResult: MigrationPlannerResult = await planner.plan({\n contract: contractIR,\n schema: schemaIR,\n policy,\n frameworkComponents,\n });\n\n if (plannerResult.kind === 'failure') {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: planSpanId,\n outcome: 'error',\n });\n return notOk({\n code: 'PLANNING_FAILED' as const,\n summary: 'Migration planning failed due to conflicts',\n conflicts: plannerResult.conflicts,\n why: undefined,\n meta: undefined,\n });\n }\n\n const migrationPlan: MigrationPlan = plannerResult.plan;\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: planSpanId,\n outcome: 'ok',\n });\n\n // Check for existing marker - handle idempotency and mismatch errors\n const checkMarkerSpanId = 'checkMarker';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: checkMarkerSpanId,\n label: 'Checking contract marker',\n });\n const existingMarker = await familyInstance.readMarker({ driver });\n if (existingMarker) {\n const markerMatchesDestination =\n existingMarker.coreHash === migrationPlan.destination.coreHash &&\n (!migrationPlan.destination.profileHash ||\n existingMarker.profileHash === migrationPlan.destination.profileHash);\n\n if (markerMatchesDestination) {\n // Already at destination - return success with no operations\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: checkMarkerSpanId,\n outcome: 'skipped',\n });\n const result: DbInitSuccess = {\n mode,\n plan: { operations: [] },\n ...(mode === 'apply'\n ? {\n execution: { operationsPlanned: 0, operationsExecuted: 0 },\n marker: {\n coreHash: existingMarker.coreHash,\n profileHash: existingMarker.profileHash,\n },\n }\n : {}),\n summary: 'Database already at target contract state',\n };\n return ok(result);\n }\n\n // Marker exists but doesn't match destination - fail\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: checkMarkerSpanId,\n outcome: 'error',\n });\n return notOk({\n code: 'MARKER_ORIGIN_MISMATCH' as const,\n summary: 'Existing contract marker does not match plan destination',\n marker: {\n coreHash: existingMarker.coreHash,\n profileHash: existingMarker.profileHash,\n },\n destination: {\n coreHash: migrationPlan.destination.coreHash,\n profileHash: migrationPlan.destination.profileHash,\n },\n why: undefined,\n conflicts: undefined,\n meta: undefined,\n });\n }\n\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: checkMarkerSpanId,\n outcome: 'ok',\n });\n\n // Plan mode - don't execute\n if (mode === 'plan') {\n const result: DbInitSuccess = {\n mode: 'plan',\n plan: { operations: migrationPlan.operations },\n summary: `Planned ${migrationPlan.operations.length} operation(s)`,\n };\n return ok(result);\n }\n\n // Apply mode - execute runner\n const applySpanId = 'apply';\n onProgress?.({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: applySpanId,\n label: 'Applying migration plan',\n });\n\n const callbacks = onProgress\n ? {\n onOperationStart: (op: MigrationPlanOperation) => {\n onProgress({\n action: 'dbInit',\n kind: 'spanStart',\n spanId: `operation:${op.id}`,\n parentSpanId: applySpanId,\n label: op.label,\n });\n },\n onOperationComplete: (op: MigrationPlanOperation) => {\n onProgress({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: `operation:${op.id}`,\n outcome: 'ok',\n });\n },\n }\n : undefined;\n\n const runnerResult: MigrationRunnerResult = await runner.execute({\n plan: migrationPlan,\n driver,\n destinationContract: contractIR,\n policy,\n ...(callbacks ? { callbacks } : {}),\n // db init plans and applies back-to-back from a fresh introspection, so per-operation\n // pre/postchecks and the idempotency probe are usually redundant overhead. We still\n // enforce marker/origin compatibility and a full schema verification after apply.\n executionChecks: {\n prechecks: false,\n postchecks: false,\n idempotencyChecks: false,\n },\n frameworkComponents,\n });\n\n if (!runnerResult.ok) {\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: applySpanId,\n outcome: 'error',\n });\n return notOk({\n code: 'RUNNER_FAILED' as const,\n summary: runnerResult.failure.summary,\n why: runnerResult.failure.why,\n meta: runnerResult.failure.meta,\n conflicts: undefined,\n });\n }\n\n const execution = runnerResult.value;\n\n onProgress?.({\n action: 'dbInit',\n kind: 'spanEnd',\n spanId: applySpanId,\n outcome: 'ok',\n });\n\n const result: DbInitSuccess = {\n mode: 'apply',\n plan: { operations: migrationPlan.operations },\n execution: {\n operationsPlanned: execution.operationsPlanned,\n operationsExecuted: execution.operationsExecuted,\n },\n marker: migrationPlan.destination.profileHash\n ? {\n coreHash: migrationPlan.destination.coreHash,\n profileHash: migrationPlan.destination.profileHash,\n }\n : { coreHash: migrationPlan.destination.coreHash },\n summary: `Applied ${execution.operationsExecuted} operation(s), marker written`,\n };\n return ok(result);\n}\n"],"mappings":";;;;;AACA,SAAS,+BAA+B;;;ACUxC,SAAS,OAAO,UAAU;AA+B1B,eAAsB,cACpB,SACuB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AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,YAAY,KAAK,QAAQ,OAAO;AAAA,MAChC;AAAA,MACA,GAAI,aAAa,EAAE,WAAW,IAAI,CAAC;AAAA,IACrC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,WAAW,SAA+C;AAC9D,UAAM,EAAE,QAAQ,eAAe,IAAI,MAAM,KAAK,gBAAgB;AAG9D,UAAM,UAAU,SAAS;AACzB,SAAK;AAEL,WAAO,eAAe,WAAW,EAAE,OAAO,CAAC;AAAA,EAC7C;AACF;","names":["result"]}
|
package/dist/chunk-HWYQOCAJ.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// src/config-loader.ts
|
|
2
|
-
import { dirname, resolve } from "path";
|
|
3
|
-
import { validateConfig } from "@prisma-next/core-control-plane/config-validation";
|
|
4
|
-
import { errorConfigFileNotFound, errorUnexpected } from "@prisma-next/core-control-plane/errors";
|
|
5
|
-
import { loadConfig as loadConfigC12 } from "c12";
|
|
6
|
-
async function loadConfig(configPath) {
|
|
7
|
-
try {
|
|
8
|
-
const cwd = process.cwd();
|
|
9
|
-
const resolvedConfigPath = configPath ? resolve(cwd, configPath) : void 0;
|
|
10
|
-
const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;
|
|
11
|
-
const result = await loadConfigC12({
|
|
12
|
-
name: "prisma-next",
|
|
13
|
-
...resolvedConfigPath ? { configFile: resolvedConfigPath } : {},
|
|
14
|
-
cwd: configCwd
|
|
15
|
-
});
|
|
16
|
-
if (resolvedConfigPath && result.configFile !== resolvedConfigPath) {
|
|
17
|
-
throw errorConfigFileNotFound(resolvedConfigPath);
|
|
18
|
-
}
|
|
19
|
-
if (!result.config || Object.keys(result.config).length === 0) {
|
|
20
|
-
const displayPath = result.configFile || resolvedConfigPath || configPath;
|
|
21
|
-
throw errorConfigFileNotFound(displayPath);
|
|
22
|
-
}
|
|
23
|
-
validateConfig(result.config);
|
|
24
|
-
return result.config;
|
|
25
|
-
} catch (error) {
|
|
26
|
-
if (error instanceof Error && "code" in error && typeof error.code === "string") {
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
if (error instanceof Error) {
|
|
30
|
-
if (error.message.includes("not found") || error.message.includes("Cannot find") || error.message.includes("ENOENT")) {
|
|
31
|
-
const displayPath = configPath ? resolve(process.cwd(), configPath) : void 0;
|
|
32
|
-
throw errorConfigFileNotFound(displayPath, {
|
|
33
|
-
why: error.message
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
throw errorUnexpected(error.message, {
|
|
37
|
-
why: `Failed to load config: ${error.message}`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
throw errorUnexpected(String(error));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
loadConfig
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=chunk-HWYQOCAJ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config-loader.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path';\nimport type { PrismaNextConfig } from '@prisma-next/core-control-plane/config-types';\nimport { validateConfig } from '@prisma-next/core-control-plane/config-validation';\nimport { errorConfigFileNotFound, errorUnexpected } from '@prisma-next/core-control-plane/errors';\nimport { loadConfig as loadConfigC12 } from 'c12';\n\n/**\n * Loads the Prisma Next config from a TypeScript file.\n * Supports both default export and named export.\n * Uses c12 to automatically handle TypeScript compilation and config file discovery.\n *\n * @param configPath - Optional path to config file. Defaults to `./prisma-next.config.ts` in current directory.\n * @returns The loaded config object.\n * @throws Error if config file doesn't exist or is invalid.\n */\nexport async function loadConfig(configPath?: string): Promise<PrismaNextConfig> {\n try {\n const cwd = process.cwd();\n // Resolve config path to absolute path and set cwd to config directory when path is provided\n const resolvedConfigPath = configPath ? resolve(cwd, configPath) : undefined;\n const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;\n\n const result = await loadConfigC12<PrismaNextConfig>({\n name: 'prisma-next',\n ...(resolvedConfigPath ? { configFile: resolvedConfigPath } : {}),\n cwd: configCwd,\n });\n\n // When a specific config file was requested, verify it was actually loaded\n // (c12 falls back to searching by name if the specified file doesn't exist)\n if (resolvedConfigPath && result.configFile !== resolvedConfigPath) {\n throw errorConfigFileNotFound(resolvedConfigPath);\n }\n\n // Check if config is missing or empty (c12 may return empty object when file doesn't exist)\n if (!result.config || Object.keys(result.config).length === 0) {\n // Use c12's configFile if available, otherwise use explicit configPath, otherwise omit path\n const displayPath = result.configFile || resolvedConfigPath || configPath;\n throw errorConfigFileNotFound(displayPath);\n }\n\n // Validate config structure\n validateConfig(result.config);\n\n return result.config;\n } catch (error) {\n // Re-throw structured errors as-is\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as { code: string }).code === 'string'\n ) {\n throw error;\n }\n\n if (error instanceof Error) {\n // Check for file not found errors\n if (\n error.message.includes('not found') ||\n error.message.includes('Cannot find') ||\n error.message.includes('ENOENT')\n ) {\n // Use resolved path if available, otherwise use original configPath\n const displayPath = configPath ? resolve(process.cwd(), configPath) : undefined;\n throw errorConfigFileNotFound(displayPath, {\n why: error.message,\n });\n }\n // For other errors, wrap in unexpected error\n throw errorUnexpected(error.message, {\n why: `Failed to load config: ${error.message}`,\n });\n }\n throw errorUnexpected(String(error));\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,eAAe;AAEjC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB,uBAAuB;AACzD,SAAS,cAAc,qBAAqB;AAW5C,eAAsB,WAAW,YAAgD;AAC/E,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AAExB,UAAM,qBAAqB,aAAa,QAAQ,KAAK,UAAU,IAAI;AACnE,UAAM,YAAY,qBAAqB,QAAQ,kBAAkB,IAAI;AAErE,UAAM,SAAS,MAAM,cAAgC;AAAA,MACnD,MAAM;AAAA,MACN,GAAI,qBAAqB,EAAE,YAAY,mBAAmB,IAAI,CAAC;AAAA,MAC/D,KAAK;AAAA,IACP,CAAC;AAID,QAAI,sBAAsB,OAAO,eAAe,oBAAoB;AAClE,YAAM,wBAAwB,kBAAkB;AAAA,IAClD;AAGA,QAAI,CAAC,OAAO,UAAU,OAAO,KAAK,OAAO,MAAM,EAAE,WAAW,GAAG;AAE7D,YAAM,cAAc,OAAO,cAAc,sBAAsB;AAC/D,YAAM,wBAAwB,WAAW;AAAA,IAC3C;AAGA,mBAAe,OAAO,MAAM;AAE5B,WAAO,OAAO;AAAA,EAChB,SAAS,OAAO;AAEd,QACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAA2B,SAAS,UAC5C;AACA,YAAM;AAAA,IACR;AAEA,QAAI,iBAAiB,OAAO;AAE1B,UACE,MAAM,QAAQ,SAAS,WAAW,KAClC,MAAM,QAAQ,SAAS,aAAa,KACpC,MAAM,QAAQ,SAAS,QAAQ,GAC/B;AAEA,cAAM,cAAc,aAAa,QAAQ,QAAQ,IAAI,GAAG,UAAU,IAAI;AACtE,cAAM,wBAAwB,aAAa;AAAA,UACzC,KAAK,MAAM;AAAA,QACb,CAAC;AAAA,MACH;AAEA,YAAM,gBAAgB,MAAM,SAAS;AAAA,QACnC,KAAK,0BAA0B,MAAM,OAAO;AAAA,MAC9C,CAAC;AAAA,IACH;AACA,UAAM,gBAAgB,OAAO,KAAK,CAAC;AAAA,EACrC;AACF;","names":[]}
|
package/dist/chunk-U6QI3AZ3.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
performAction,
|
|
3
|
-
withSpinner
|
|
4
|
-
} from "./chunk-5MPKZYVI.js";
|
|
5
|
-
import {
|
|
6
|
-
formatCommandHelp,
|
|
7
|
-
formatEmitJson,
|
|
8
|
-
formatEmitOutput,
|
|
9
|
-
formatStyledHeader,
|
|
10
|
-
formatSuccessMessage,
|
|
11
|
-
handleResult,
|
|
12
|
-
parseGlobalFlags,
|
|
13
|
-
setCommandDescriptions
|
|
14
|
-
} from "./chunk-ZG5T6OB5.js";
|
|
15
|
-
import {
|
|
16
|
-
loadConfig
|
|
17
|
-
} from "./chunk-HWYQOCAJ.js";
|
|
18
|
-
|
|
19
|
-
// src/commands/contract-emit.ts
|
|
20
|
-
import { mkdirSync, writeFileSync } from "fs";
|
|
21
|
-
import { dirname, relative, resolve } from "path";
|
|
22
|
-
import { errorContractConfigMissing } from "@prisma-next/core-control-plane/errors";
|
|
23
|
-
import { createControlPlaneStack } from "@prisma-next/core-control-plane/types";
|
|
24
|
-
import { Command } from "commander";
|
|
25
|
-
function createContractEmitCommand() {
|
|
26
|
-
const command = new Command("emit");
|
|
27
|
-
setCommandDescriptions(
|
|
28
|
-
command,
|
|
29
|
-
"Write your contract to JSON and sign it",
|
|
30
|
-
"Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\ncontract.d.ts. The contract.json contains the canonical contract structure, and\ncontract.d.ts provides TypeScript types for type-safe query building."
|
|
31
|
-
);
|
|
32
|
-
command.configureHelp({
|
|
33
|
-
formatHelp: (cmd) => {
|
|
34
|
-
const flags = parseGlobalFlags({});
|
|
35
|
-
return formatCommandHelp({ command: cmd, flags });
|
|
36
|
-
}
|
|
37
|
-
}).option("--config <path>", "Path to prisma-next.config.ts").option("--json [format]", "Output as JSON (object or ndjson)", false).option("-q, --quiet", "Quiet mode: errors only").option("-v, --verbose", "Verbose output: debug info, timings").option("-vv, --trace", "Trace output: deep internals, stack traces").option("--timestamps", "Add timestamps to output").option("--color", "Force color output").option("--no-color", "Disable color output").action(async (options) => {
|
|
38
|
-
const flags = parseGlobalFlags(options);
|
|
39
|
-
const result = await performAction(async () => {
|
|
40
|
-
const config = await loadConfig(options.config);
|
|
41
|
-
if (!config.contract) {
|
|
42
|
-
throw errorContractConfigMissing({
|
|
43
|
-
why: "Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }"
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const contractConfig = config.contract;
|
|
47
|
-
if (!contractConfig.output || !contractConfig.types) {
|
|
48
|
-
throw errorContractConfigMissing({
|
|
49
|
-
why: "Contract config must have output and types paths. This should not happen if defineConfig() was used."
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const outputJsonPath = resolve(contractConfig.output);
|
|
53
|
-
const outputDtsPath = resolve(contractConfig.types);
|
|
54
|
-
if (flags.json !== "object" && !flags.quiet) {
|
|
55
|
-
const configPath = options.config ? relative(process.cwd(), resolve(options.config)) : "prisma-next.config.ts";
|
|
56
|
-
const contractPath = relative(process.cwd(), outputJsonPath);
|
|
57
|
-
const typesPath = relative(process.cwd(), outputDtsPath);
|
|
58
|
-
const header = formatStyledHeader({
|
|
59
|
-
command: "contract emit",
|
|
60
|
-
description: "Write your contract to JSON and sign it",
|
|
61
|
-
url: "https://pris.ly/contract-emit",
|
|
62
|
-
details: [
|
|
63
|
-
{ label: "config", value: configPath },
|
|
64
|
-
{ label: "contract", value: contractPath },
|
|
65
|
-
{ label: "types", value: typesPath }
|
|
66
|
-
],
|
|
67
|
-
flags
|
|
68
|
-
});
|
|
69
|
-
console.log(header);
|
|
70
|
-
}
|
|
71
|
-
const stack = createControlPlaneStack({
|
|
72
|
-
target: config.target,
|
|
73
|
-
adapter: config.adapter,
|
|
74
|
-
driver: config.driver,
|
|
75
|
-
extensionPacks: config.extensionPacks
|
|
76
|
-
});
|
|
77
|
-
const familyInstance = config.family.create(stack);
|
|
78
|
-
let contractRaw;
|
|
79
|
-
if (typeof contractConfig.source === "function") {
|
|
80
|
-
contractRaw = await contractConfig.source();
|
|
81
|
-
} else {
|
|
82
|
-
contractRaw = contractConfig.source;
|
|
83
|
-
}
|
|
84
|
-
const emitResult = await withSpinner(
|
|
85
|
-
() => familyInstance.emitContract({ contractIR: contractRaw }),
|
|
86
|
-
{
|
|
87
|
-
message: "Emitting contract...",
|
|
88
|
-
flags
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
mkdirSync(dirname(outputJsonPath), { recursive: true });
|
|
92
|
-
mkdirSync(dirname(outputDtsPath), { recursive: true });
|
|
93
|
-
writeFileSync(outputJsonPath, emitResult.contractJson, "utf-8");
|
|
94
|
-
writeFileSync(outputDtsPath, emitResult.contractDts, "utf-8");
|
|
95
|
-
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
96
|
-
console.log("");
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
coreHash: emitResult.coreHash,
|
|
100
|
-
profileHash: emitResult.profileHash,
|
|
101
|
-
outDir: dirname(outputJsonPath),
|
|
102
|
-
files: {
|
|
103
|
-
json: outputJsonPath,
|
|
104
|
-
dts: outputDtsPath
|
|
105
|
-
},
|
|
106
|
-
timings: {
|
|
107
|
-
total: 0
|
|
108
|
-
// Timing is handled by emitContract internally if needed
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
});
|
|
112
|
-
const exitCode = handleResult(result, flags, (emitResult) => {
|
|
113
|
-
if (flags.json === "object") {
|
|
114
|
-
console.log(formatEmitJson(emitResult));
|
|
115
|
-
} else {
|
|
116
|
-
const output = formatEmitOutput(emitResult, flags);
|
|
117
|
-
if (output) {
|
|
118
|
-
console.log(output);
|
|
119
|
-
}
|
|
120
|
-
if (!flags.quiet) {
|
|
121
|
-
console.log(formatSuccessMessage(flags));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
process.exit(exitCode);
|
|
126
|
-
});
|
|
127
|
-
return command;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export {
|
|
131
|
-
createContractEmitCommand
|
|
132
|
-
};
|
|
133
|
-
//# sourceMappingURL=chunk-U6QI3AZ3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/commands/contract-emit.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, relative, resolve } from 'node:path';\nimport { errorContractConfigMissing } from '@prisma-next/core-control-plane/errors';\nimport { createControlPlaneStack } from '@prisma-next/core-control-plane/types';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { performAction } from '../utils/action';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatEmitJson,\n formatEmitOutput,\n formatStyledHeader,\n formatSuccessMessage,\n} from '../utils/output';\nimport { handleResult } from '../utils/result-handler';\nimport { withSpinner } from '../utils/spinner';\n\ninterface ContractEmitOptions {\n readonly config?: string;\n readonly json?: string | boolean;\n readonly quiet?: boolean;\n readonly q?: boolean;\n readonly verbose?: boolean;\n readonly v?: boolean;\n readonly vv?: boolean;\n readonly trace?: boolean;\n readonly timestamps?: boolean;\n readonly color?: boolean;\n readonly 'no-color'?: boolean;\n}\n\nexport function createContractEmitCommand(): Command {\n const command = new Command('emit');\n setCommandDescriptions(\n command,\n 'Write your contract to JSON and sign it',\n 'Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\\n' +\n 'contract.d.ts. The contract.json contains the canonical contract structure, and\\n' +\n 'contract.d.ts provides TypeScript types for type-safe query building.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object or ndjson)', false)\n .option('-q, --quiet', 'Quiet mode: errors only')\n .option('-v, --verbose', 'Verbose output: debug info, timings')\n .option('-vv, --trace', 'Trace output: deep internals, stack traces')\n .option('--timestamps', 'Add timestamps to output')\n .option('--color', 'Force color output')\n .option('--no-color', 'Disable color output')\n .action(async (options: ContractEmitOptions) => {\n const flags = parseGlobalFlags(options);\n\n const result = await performAction(async () => {\n // Load config\n const config = await loadConfig(options.config);\n\n // Resolve contract from config\n if (!config.contract) {\n throw errorContractConfigMissing({\n why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }',\n });\n }\n\n // Contract config is already normalized by defineConfig() with defaults applied\n const contractConfig = config.contract;\n\n // Resolve artifact paths from config (already normalized by defineConfig() with defaults)\n if (!contractConfig.output || !contractConfig.types) {\n throw errorContractConfigMissing({\n why: 'Contract config must have output and types paths. This should not happen if defineConfig() was used.',\n });\n }\n const outputJsonPath = resolve(contractConfig.output);\n const outputDtsPath = resolve(contractConfig.types);\n\n // Output header (only for human-readable output)\n if (flags.json !== 'object' && !flags.quiet) {\n // Normalize config path for display (match contract path format - no ./ prefix)\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n // Convert absolute paths to relative paths for display\n const contractPath = relative(process.cwd(), outputJsonPath);\n const typesPath = relative(process.cwd(), outputDtsPath);\n const header = formatStyledHeader({\n command: 'contract emit',\n description: 'Write your contract to JSON and sign it',\n url: 'https://pris.ly/contract-emit',\n details: [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n { label: 'types', value: typesPath },\n ],\n flags,\n });\n console.log(header);\n }\n\n const stack = createControlPlaneStack({\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks,\n });\n const familyInstance = config.family.create(stack);\n\n // Resolve contract source from config (user's config handles loading)\n let contractRaw: unknown;\n if (typeof contractConfig.source === 'function') {\n contractRaw = await contractConfig.source();\n } else {\n contractRaw = contractConfig.source;\n }\n\n // Call emitContract on family instance (handles stripping mappings and validation internally)\n const emitResult = await withSpinner(\n () => familyInstance.emitContract({ contractIR: contractRaw }),\n {\n message: 'Emitting contract...',\n flags,\n },\n );\n\n // Create directories if needed\n mkdirSync(dirname(outputJsonPath), { recursive: true });\n mkdirSync(dirname(outputDtsPath), { recursive: true });\n\n // Write the results to files\n writeFileSync(outputJsonPath, emitResult.contractJson, 'utf-8');\n writeFileSync(outputDtsPath, emitResult.contractDts, 'utf-8');\n\n // Add blank line after all async operations if spinners were shown\n if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {\n console.log('');\n }\n\n // Return result with file paths for output formatting\n return {\n coreHash: emitResult.coreHash,\n profileHash: emitResult.profileHash,\n outDir: dirname(outputJsonPath),\n files: {\n json: outputJsonPath,\n dts: outputDtsPath,\n },\n timings: {\n total: 0, // Timing is handled by emitContract internally if needed\n },\n };\n });\n\n // Handle result - formats output and returns exit code\n const exitCode = handleResult(result, flags, (emitResult) => {\n // Output based on flags\n if (flags.json === 'object') {\n // JSON output to stdout\n console.log(formatEmitJson(emitResult));\n } else {\n // Human-readable output to stdout\n const output = formatEmitOutput(emitResult, flags);\n if (output) {\n console.log(output);\n }\n // Output success message\n if (!flags.quiet) {\n console.log(formatSuccessMessage(flags));\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,qBAAqB;AACzC,SAAS,SAAS,UAAU,eAAe;AAC3C,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,eAAe;AA6BjB,SAAS,4BAAqC;AACnD,QAAM,UAAU,IAAI,QAAQ,MAAM;AAClC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EAGF;AACA,UACG,cAAc;AAAA,IACb,YAAY,CAAC,QAAQ;AACnB,YAAM,QAAQ,iBAAiB,CAAC,CAAC;AACjC,aAAO,kBAAkB,EAAE,SAAS,KAAK,MAAM,CAAC;AAAA,IAClD;AAAA,EACF,CAAC,EACA,OAAO,mBAAmB,+BAA+B,EACzD,OAAO,mBAAmB,qCAAqC,KAAK,EACpE,OAAO,eAAe,yBAAyB,EAC/C,OAAO,iBAAiB,qCAAqC,EAC7D,OAAO,gBAAgB,4CAA4C,EACnE,OAAO,gBAAgB,0BAA0B,EACjD,OAAO,WAAW,oBAAoB,EACtC,OAAO,cAAc,sBAAsB,EAC3C,OAAO,OAAO,YAAiC;AAC9C,UAAM,QAAQ,iBAAiB,OAAO;AAEtC,UAAM,SAAS,MAAM,cAAc,YAAY;AAE7C,YAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;AAG9C,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