swallowkit 1.0.0-beta.55 → 1.0.0-beta.57
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/dist/cli/commands/add-auth.d.ts.map +1 -1
- package/dist/cli/commands/add-auth.js +154 -157
- package/dist/cli/commands/add-auth.js.map +1 -1
- package/dist/cli/commands/init.d.ts +5 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +178 -25
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +7 -2
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +113 -123
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +127 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +8 -4
- package/dist/core/config.js.map +1 -1
- package/dist/core/operations/auth-operations.d.ts +57 -0
- package/dist/core/operations/auth-operations.d.ts.map +1 -0
- package/dist/core/operations/auth-operations.js +269 -0
- package/dist/core/operations/auth-operations.js.map +1 -0
- package/dist/core/operations/create-model.d.ts.map +1 -1
- package/dist/core/operations/create-model.js +23 -13
- package/dist/core/operations/create-model.js.map +1 -1
- package/dist/core/operations/file-session.d.ts +56 -0
- package/dist/core/operations/file-session.d.ts.map +1 -0
- package/dist/core/operations/file-session.js +203 -0
- package/dist/core/operations/file-session.js.map +1 -0
- package/dist/core/operations/provision-operations.d.ts +52 -0
- package/dist/core/operations/provision-operations.d.ts.map +1 -0
- package/dist/core/operations/provision-operations.js +211 -0
- package/dist/core/operations/provision-operations.js.map +1 -0
- package/dist/core/operations/runtime.d.ts +5 -0
- package/dist/core/operations/runtime.d.ts.map +1 -1
- package/dist/core/operations/runtime.js +23 -0
- package/dist/core/operations/runtime.js.map +1 -1
- package/dist/core/operations/scaffold-apply.d.ts +21 -0
- package/dist/core/operations/scaffold-apply.d.ts.map +1 -0
- package/dist/core/operations/scaffold-apply.js +57 -0
- package/dist/core/operations/scaffold-apply.js.map +1 -0
- package/dist/core/operations/scaffold-machine.d.ts.map +1 -1
- package/dist/core/operations/scaffold-machine.js +1 -13
- package/dist/core/operations/scaffold-machine.js.map +1 -1
- package/dist/core/operations/scaffold-plan.d.ts +43 -0
- package/dist/core/operations/scaffold-plan.d.ts.map +1 -0
- package/dist/core/operations/scaffold-plan.js +187 -0
- package/dist/core/operations/scaffold-plan.js.map +1 -0
- package/dist/core/project/artifacts.d.ts +58 -0
- package/dist/core/project/artifacts.d.ts.map +1 -0
- package/dist/core/project/artifacts.js +179 -0
- package/dist/core/project/artifacts.js.map +1 -0
- package/dist/core/project/boundaries.d.ts +50 -0
- package/dist/core/project/boundaries.d.ts.map +1 -0
- package/dist/core/project/boundaries.js +117 -0
- package/dist/core/project/boundaries.js.map +1 -0
- package/dist/core/project/drift.d.ts +29 -0
- package/dist/core/project/drift.d.ts.map +1 -0
- package/dist/core/project/drift.js +188 -0
- package/dist/core/project/drift.js.map +1 -0
- package/dist/core/project/infra.d.ts +49 -0
- package/dist/core/project/infra.d.ts.map +1 -0
- package/dist/core/project/infra.js +167 -0
- package/dist/core/project/infra.js.map +1 -0
- package/dist/core/project/state.d.ts +15 -0
- package/dist/core/project/state.d.ts.map +1 -0
- package/dist/core/project/state.js +106 -0
- package/dist/core/project/state.js.map +1 -0
- package/dist/core/project/workflows.d.ts +43 -0
- package/dist/core/project/workflows.d.ts.map +1 -0
- package/dist/core/project/workflows.js +255 -0
- package/dist/core/project/workflows.js.map +1 -0
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -1
- package/dist/core/scaffold/auth-generator.js +24 -27
- package/dist/core/scaffold/auth-generator.js.map +1 -1
- package/dist/core/scaffold/functions-generator.js +9 -9
- package/dist/core/scaffold/native-schema-generator.d.ts +7 -1
- package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -1
- package/dist/core/scaffold/native-schema-generator.js +104 -47
- package/dist/core/scaffold/native-schema-generator.js.map +1 -1
- package/dist/core/scaffold/nextjs-generator.js +6 -6
- package/dist/core/scaffold/ui-generator.js +19 -19
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- package/dist/core/verify/index.d.ts +62 -0
- package/dist/core/verify/index.d.ts.map +1 -0
- package/dist/core/verify/index.js +343 -0
- package/dist/core/verify/index.js.map +1 -0
- package/dist/machine/contracts.d.ts +8 -0
- package/dist/machine/contracts.d.ts.map +1 -1
- package/dist/machine/errors.d.ts +4 -1
- package/dist/machine/errors.d.ts.map +1 -1
- package/dist/machine/errors.js +9 -1
- package/dist/machine/errors.js.map +1 -1
- package/dist/machine/index.d.ts.map +1 -1
- package/dist/machine/index.js +350 -16
- package/dist/machine/index.js.map +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +202 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +17 -17
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +6 -6
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +11 -11
- package/src/__tests__/agent-loop-phase34.test.ts +449 -0
- package/src/__tests__/file-session.test.ts +98 -0
- package/src/__tests__/init.test.ts +50 -0
- package/src/__tests__/mcp.test.ts +113 -5
- package/src/__tests__/plan-apply.test.ts +461 -0
- package/src/__tests__/scaffold.test.ts +2 -2
- package/src/cli/commands/add-auth.ts +164 -164
- package/src/cli/commands/init.ts +186 -24
- package/src/cli/commands/scaffold.ts +136 -130
- package/src/cli/index.ts +148 -2
- package/src/core/config.ts +5 -4
- package/src/core/operations/auth-operations.ts +353 -0
- package/src/core/operations/create-model.ts +25 -13
- package/src/core/operations/file-session.ts +222 -0
- package/src/core/operations/provision-operations.ts +297 -0
- package/src/core/operations/runtime.ts +23 -0
- package/src/core/operations/scaffold-apply.ts +106 -0
- package/src/core/operations/scaffold-machine.ts +2 -16
- package/src/core/operations/scaffold-plan.ts +215 -0
- package/src/core/project/artifacts.ts +205 -0
- package/src/core/project/boundaries.ts +170 -0
- package/src/core/project/drift.ts +202 -0
- package/src/core/project/infra.ts +196 -0
- package/src/core/project/state.ts +77 -0
- package/src/core/project/workflows.ts +249 -0
- package/src/core/scaffold/auth-generator.ts +24 -27
- package/src/core/scaffold/functions-generator.ts +9 -9
- package/src/core/scaffold/native-schema-generator.ts +152 -70
- package/src/core/scaffold/nextjs-generator.ts +6 -6
- package/src/core/scaffold/ui-generator.ts +19 -19
- package/src/core/verify/index.ts +392 -0
- package/src/machine/contracts.ts +16 -0
- package/src/machine/errors.ts +12 -1
- package/src/machine/index.ts +444 -15
- package/src/mcp/index.ts +198 -2
- package/src/types/index.ts +17 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Plan / Apply Auth — add-auth を collect モードで実行して差分計画を作成し、
|
|
4
|
+
* 承認・鮮度チェックを経て実際に適用する。
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.planAuthOperation = planAuthOperation;
|
|
41
|
+
exports.verifyAuthPlanFingerprints = verifyAuthPlanFingerprints;
|
|
42
|
+
exports.applyAuthOperation = applyAuthOperation;
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const add_auth_1 = require("../../cli/commands/add-auth");
|
|
46
|
+
const errors_1 = require("../../machine/errors");
|
|
47
|
+
const version_1 = require("../../version");
|
|
48
|
+
const artifacts_1 = require("../project/artifacts");
|
|
49
|
+
const state_1 = require("../project/state");
|
|
50
|
+
const file_session_1 = require("./file-session");
|
|
51
|
+
const runtime_1 = require("./runtime");
|
|
52
|
+
function deriveAuthErrorMessage(messages) {
|
|
53
|
+
return (0, runtime_1.deriveCapturedErrorMessage)(messages, "Auth operation failed.");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* add-auth を collect セッションで実行し、記録された操作を返す。ディスクには書き込まない。
|
|
57
|
+
*/
|
|
58
|
+
async function collectAuthOperations(options) {
|
|
59
|
+
const session = new file_session_1.FileOperationSession("collect");
|
|
60
|
+
const originalMachineOutput = process.env.SWALLOWKIT_MACHINE_OUTPUT;
|
|
61
|
+
process.env.SWALLOWKIT_MACHINE_OUTPUT = "1";
|
|
62
|
+
try {
|
|
63
|
+
const captured = await (0, runtime_1.captureConsoleMessagesWithError)(async () => {
|
|
64
|
+
await (0, runtime_1.interceptProcessExit)(async () => {
|
|
65
|
+
await (0, file_session_1.runWithFileSession)(session, async () => {
|
|
66
|
+
await (0, add_auth_1.addAuthCommand)({ provider: options.provider, scheme: options.scheme });
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
if (captured.error) {
|
|
71
|
+
if (captured.error instanceof runtime_1.ProcessExitInterceptError) {
|
|
72
|
+
throw new Error(deriveAuthErrorMessage(captured.messages));
|
|
73
|
+
}
|
|
74
|
+
if (captured.error instanceof Error) {
|
|
75
|
+
throw captured.error;
|
|
76
|
+
}
|
|
77
|
+
throw new Error(deriveAuthErrorMessage(captured.messages));
|
|
78
|
+
}
|
|
79
|
+
return session;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
if (originalMachineOutput === undefined) {
|
|
83
|
+
delete process.env.SWALLOWKIT_MACHINE_OUTPUT;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
process.env.SWALLOWKIT_MACHINE_OUTPUT = originalMachineOutput;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function planAuthOperation(options) {
|
|
91
|
+
const projectRoot = process.cwd();
|
|
92
|
+
const session = await collectAuthOperations(options);
|
|
93
|
+
const ledger = (0, artifacts_1.loadArtifactLedger)(projectRoot);
|
|
94
|
+
const operations = [];
|
|
95
|
+
const fingerprints = {};
|
|
96
|
+
const warnings = [...session.warnings];
|
|
97
|
+
for (const op of session.operations) {
|
|
98
|
+
fingerprints[op.path] = op.previousHash;
|
|
99
|
+
let action;
|
|
100
|
+
let conflict = false;
|
|
101
|
+
let conflictReason;
|
|
102
|
+
switch (op.action) {
|
|
103
|
+
case "create":
|
|
104
|
+
action = "create";
|
|
105
|
+
break;
|
|
106
|
+
case "skip":
|
|
107
|
+
action = "skip";
|
|
108
|
+
break;
|
|
109
|
+
case "append":
|
|
110
|
+
action = "append";
|
|
111
|
+
break;
|
|
112
|
+
case "delete":
|
|
113
|
+
action = "delete";
|
|
114
|
+
break;
|
|
115
|
+
case "modify": {
|
|
116
|
+
if (op.ownership === "extension-point") {
|
|
117
|
+
// 設定ファイル・登録ポイントへの追記型変更は想定内の更新として扱う
|
|
118
|
+
action = "update";
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
const record = ledger ? (0, artifacts_1.findArtifactRecord)(ledger, op.path) : undefined;
|
|
122
|
+
if (record && record.contentHash === op.previousHash) {
|
|
123
|
+
action = "update";
|
|
124
|
+
}
|
|
125
|
+
else if (record) {
|
|
126
|
+
action = "overwrite";
|
|
127
|
+
conflict = true;
|
|
128
|
+
conflictReason = "modified-after-generation";
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
action = "overwrite";
|
|
132
|
+
conflict = true;
|
|
133
|
+
conflictReason = "unknown-provenance";
|
|
134
|
+
warnings.push(`unknown-provenance: ${op.path} exists but is not tracked in .swallowkit/artifacts.json; regenerating will overwrite it.`);
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
operations.push({
|
|
140
|
+
path: op.path,
|
|
141
|
+
action,
|
|
142
|
+
ownership: op.ownership,
|
|
143
|
+
conflict,
|
|
144
|
+
...(conflictReason ? { conflictReason } : {}),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const conflicts = operations.filter((op) => op.conflict);
|
|
148
|
+
const planId = crypto
|
|
149
|
+
.createHash("sha256")
|
|
150
|
+
.update(JSON.stringify({
|
|
151
|
+
provider: options.provider,
|
|
152
|
+
scheme: options.scheme,
|
|
153
|
+
operations: operations.map((op) => ({ path: op.path, action: op.action })),
|
|
154
|
+
fingerprints,
|
|
155
|
+
}))
|
|
156
|
+
.digest("hex")
|
|
157
|
+
.slice(0, 12);
|
|
158
|
+
const plan = {
|
|
159
|
+
planId,
|
|
160
|
+
planType: "auth",
|
|
161
|
+
provider: options.provider,
|
|
162
|
+
...(options.scheme ? { scheme: options.scheme } : {}),
|
|
163
|
+
createdAt: new Date().toISOString(),
|
|
164
|
+
swallowkitVersion: (0, version_1.getSwallowKitVersion)(),
|
|
165
|
+
operations,
|
|
166
|
+
warnings,
|
|
167
|
+
conflicts,
|
|
168
|
+
requiresApproval: conflicts.length > 0,
|
|
169
|
+
fingerprints,
|
|
170
|
+
};
|
|
171
|
+
(0, state_1.savePlanState)(plan, projectRoot);
|
|
172
|
+
return plan;
|
|
173
|
+
}
|
|
174
|
+
function verifyAuthPlanFingerprints(plan, projectRoot = process.cwd()) {
|
|
175
|
+
const changedFiles = [];
|
|
176
|
+
for (const [relativePath, expectedHash] of Object.entries(plan.fingerprints)) {
|
|
177
|
+
const currentHash = (0, file_session_1.hashFileIfExists)(path.join(projectRoot, relativePath));
|
|
178
|
+
if (currentHash !== expectedHash) {
|
|
179
|
+
changedFiles.push(relativePath);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { fresh: changedFiles.length === 0, changedFiles };
|
|
183
|
+
}
|
|
184
|
+
async function runCommitAuthOperation(options) {
|
|
185
|
+
const originalMachineOutput = process.env.SWALLOWKIT_MACHINE_OUTPUT;
|
|
186
|
+
process.env.SWALLOWKIT_MACHINE_OUTPUT = "1";
|
|
187
|
+
try {
|
|
188
|
+
const tracked = await (0, runtime_1.trackFileMutations)(async () => {
|
|
189
|
+
const captured = await (0, runtime_1.captureConsoleMessagesWithError)(async () => {
|
|
190
|
+
await (0, runtime_1.interceptProcessExit)(async () => {
|
|
191
|
+
await (0, add_auth_1.addAuthCommand)({ provider: options.provider, scheme: options.scheme });
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
if (captured.error) {
|
|
195
|
+
if (captured.error instanceof runtime_1.ProcessExitInterceptError) {
|
|
196
|
+
throw new Error(deriveAuthErrorMessage(captured.messages));
|
|
197
|
+
}
|
|
198
|
+
if (captured.error instanceof Error) {
|
|
199
|
+
throw captured.error;
|
|
200
|
+
}
|
|
201
|
+
throw new Error(deriveAuthErrorMessage(captured.messages));
|
|
202
|
+
}
|
|
203
|
+
return captured.messages;
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
createdFiles: tracked.mutations.createdFiles,
|
|
207
|
+
updatedFiles: tracked.mutations.updatedFiles,
|
|
208
|
+
appendedFiles: tracked.mutations.appendedFiles,
|
|
209
|
+
deletedFiles: tracked.mutations.deletedFiles,
|
|
210
|
+
createdDirectories: tracked.mutations.createdDirectories,
|
|
211
|
+
diagnostics: [
|
|
212
|
+
...tracked.result.warnings.map((warning) => `warning:${warning}`),
|
|
213
|
+
...tracked.result.errors.map((error) => `error:${error}`),
|
|
214
|
+
],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
if (originalMachineOutput === undefined) {
|
|
219
|
+
delete process.env.SWALLOWKIT_MACHINE_OUTPUT;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
process.env.SWALLOWKIT_MACHINE_OUTPUT = originalMachineOutput;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async function applyAuthOperation(options) {
|
|
227
|
+
const projectRoot = process.cwd();
|
|
228
|
+
let basePlan = null;
|
|
229
|
+
if (options.planId) {
|
|
230
|
+
basePlan = (0, state_1.loadPlanState)(options.planId, projectRoot);
|
|
231
|
+
if (!basePlan) {
|
|
232
|
+
throw new errors_1.MachineCommandError("plan-not-found", `Plan "${options.planId}" was not found. Run "plan auth" to create a new plan.`, { planId: options.planId }, "blocked");
|
|
233
|
+
}
|
|
234
|
+
const freshness = verifyAuthPlanFingerprints(basePlan, projectRoot);
|
|
235
|
+
if (!freshness.fresh) {
|
|
236
|
+
throw new errors_1.MachineCommandError("stale-plan", `Plan "${options.planId}" is stale: ${freshness.changedFiles.length} file(s) changed after the plan was created. Re-run "plan auth".`, { planId: options.planId, changedFiles: freshness.changedFiles }, "blocked");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const provider = options.provider ?? basePlan?.provider;
|
|
240
|
+
if (!provider) {
|
|
241
|
+
throw new errors_1.MachineCommandError("invalid-arguments", "Either --provider or --plan <planId> must be provided.", undefined, "failed");
|
|
242
|
+
}
|
|
243
|
+
const effectiveOptions = {
|
|
244
|
+
provider,
|
|
245
|
+
scheme: options.scheme ?? basePlan?.scheme,
|
|
246
|
+
};
|
|
247
|
+
// 常に最新状態で collect し、競合を再確認する
|
|
248
|
+
const currentPlan = await planAuthOperation(effectiveOptions);
|
|
249
|
+
if (currentPlan.requiresApproval && !options.approve) {
|
|
250
|
+
throw new errors_1.MachineCommandError("approval-required", `${currentPlan.conflicts.length} file(s) were modified after generation and would be overwritten. Review the conflicts and re-run with --approve to proceed.`, {
|
|
251
|
+
planId: currentPlan.planId,
|
|
252
|
+
conflicts: currentPlan.conflicts,
|
|
253
|
+
}, "requires-human");
|
|
254
|
+
}
|
|
255
|
+
const result = await runCommitAuthOperation(effectiveOptions);
|
|
256
|
+
(0, state_1.deletePlanState)(currentPlan.planId, projectRoot);
|
|
257
|
+
if (options.planId && options.planId !== currentPlan.planId) {
|
|
258
|
+
(0, state_1.deletePlanState)(options.planId, projectRoot);
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
...result,
|
|
262
|
+
provider,
|
|
263
|
+
...(effectiveOptions.scheme ? { scheme: effectiveOptions.scheme } : {}),
|
|
264
|
+
planId: currentPlan.planId,
|
|
265
|
+
approvedConflicts: options.approve ? currentPlan.conflicts : [],
|
|
266
|
+
warnings: currentPlan.warnings,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=auth-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC;IAE9D,IAAA,uBAAe,EAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;QAC5D,IAAA,uBAAe,EAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,QAAQ;QACR,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,iBAAiB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;QAC/D,QAAQ,EAAE,WAAW,CAAC,QAAQ;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-model.d.ts","sourceRoot":"","sources":["../../../src/core/operations/create-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-model.d.ts","sourceRoot":"","sources":["../../../src/core/operations/create-model.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC9C,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CAC/B;AA2FD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAwEpH"}
|
|
@@ -34,11 +34,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createModelOperation = createModelOperation;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
37
|
const path = __importStar(require("path"));
|
|
39
38
|
const config_1 = require("../config");
|
|
40
39
|
const model_parser_1 = require("../scaffold/model-parser");
|
|
41
40
|
const manifest_1 = require("../project/manifest");
|
|
41
|
+
const artifacts_1 = require("../project/artifacts");
|
|
42
|
+
const file_session_1 = require("./file-session");
|
|
43
|
+
const CREATE_MODEL_GENERATOR = "create-model";
|
|
42
44
|
function generateModelTemplate(modelName) {
|
|
43
45
|
const pascalName = (0, model_parser_1.toPascalCase)(modelName);
|
|
44
46
|
return `import { z } from 'zod/v4';
|
|
@@ -101,17 +103,20 @@ export const connectorConfig = {
|
|
|
101
103
|
};
|
|
102
104
|
`;
|
|
103
105
|
}
|
|
104
|
-
function updateSharedIndex(kebabName, pascalName) {
|
|
105
|
-
const indexPath = path.join("shared", "index.ts");
|
|
106
|
-
if (!
|
|
106
|
+
function updateSharedIndex(kebabName, pascalName, session) {
|
|
107
|
+
const indexPath = path.join(process.cwd(), "shared", "index.ts");
|
|
108
|
+
if (!session.fileExists(indexPath)) {
|
|
107
109
|
return false;
|
|
108
110
|
}
|
|
109
|
-
const content =
|
|
111
|
+
const content = session.readFile(indexPath);
|
|
110
112
|
const exportLine = `export { ${pascalName} } from './models/${kebabName}';`;
|
|
111
113
|
if (content.includes(exportLine)) {
|
|
112
114
|
return false;
|
|
113
115
|
}
|
|
114
|
-
|
|
116
|
+
session.writeFile(indexPath, `${content}${exportLine}\n`, {
|
|
117
|
+
ownership: "extension-point",
|
|
118
|
+
generator: CREATE_MODEL_GENERATOR,
|
|
119
|
+
});
|
|
115
120
|
return true;
|
|
116
121
|
}
|
|
117
122
|
async function createModelOperation(options) {
|
|
@@ -127,9 +132,7 @@ async function createModelOperation(options) {
|
|
|
127
132
|
connectorType = connectorDefinition.type;
|
|
128
133
|
}
|
|
129
134
|
const modelsDir = options.modelsDir || "shared/models";
|
|
130
|
-
|
|
131
|
-
fs.mkdirSync(modelsDir, { recursive: true });
|
|
132
|
-
}
|
|
135
|
+
const session = (0, file_session_1.getActiveFileSession)() ?? new file_session_1.FileOperationSession("commit");
|
|
133
136
|
const createdFiles = [];
|
|
134
137
|
const skippedFiles = [];
|
|
135
138
|
let updatedIndex = false;
|
|
@@ -137,7 +140,7 @@ async function createModelOperation(options) {
|
|
|
137
140
|
const kebabName = name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
138
141
|
const filePath = path.join(modelsDir, `${kebabName}.ts`);
|
|
139
142
|
const pascalName = (0, model_parser_1.toPascalCase)(name);
|
|
140
|
-
if (
|
|
143
|
+
if (session.fileExists(path.resolve(filePath))) {
|
|
141
144
|
const overwriteMode = options.overwriteMode || "prompt";
|
|
142
145
|
const shouldOverwrite = overwriteMode === "always"
|
|
143
146
|
? true
|
|
@@ -154,13 +157,20 @@ async function createModelOperation(options) {
|
|
|
154
157
|
const content = options.connector && connectorType
|
|
155
158
|
? generateConnectorModelTemplate(name, options.connector, connectorType)
|
|
156
159
|
: generateModelTemplate(name);
|
|
157
|
-
|
|
160
|
+
session.writeFile(path.resolve(filePath), content, {
|
|
161
|
+
ownership: "user-owned",
|
|
162
|
+
generator: CREATE_MODEL_GENERATOR,
|
|
163
|
+
sourceModel: pascalName,
|
|
164
|
+
});
|
|
158
165
|
createdFiles.push(filePath.replace(/\\/g, "/"));
|
|
159
|
-
if (updateSharedIndex(kebabName, pascalName)) {
|
|
166
|
+
if (updateSharedIndex(kebabName, pascalName, session)) {
|
|
160
167
|
updatedIndex = true;
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
|
-
|
|
170
|
+
if (session.mode === "commit") {
|
|
171
|
+
(0, artifacts_1.recordSessionOperations)(session.operations, {});
|
|
172
|
+
await (0, manifest_1.syncProjectManifest)();
|
|
173
|
+
}
|
|
164
174
|
return {
|
|
165
175
|
createdFiles,
|
|
166
176
|
skippedFiles,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-model.js","sourceRoot":"","sources":["../../../src/core/operations/create-model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-model.js","sourceRoot":"","sources":["../../../src/core/operations/create-model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,oDAwEC;AAzLD,2CAA6B;AAC7B,sCAAgE;AAChE,2DAAwD;AACxD,kDAA0D;AAC1D,oDAA+D;AAC/D,iDAA4E;AAE5E,MAAM,sBAAsB,GAAG,cAAc,CAAC;AAiB9C,SAAS,qBAAqB,CAAC,SAAiB;IAC9C,MAAM,UAAU,GAAG,IAAA,2BAAY,EAAC,SAAS,CAAC,CAAC;IAE3C,OAAO;;KAEJ,UAAU;eACA,UAAU;;;;;;;cAOX,UAAU,qBAAqB,UAAU;;;8BAGzB,UAAU;CACvC,CAAC;AACF,CAAC;AAED,SAAS,8BAA8B,CAAC,SAAiB,EAAE,aAAqB,EAAE,aAA4B;IAC5G,MAAM,UAAU,GAAG,IAAA,2BAAY,EAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC;IAEzE,MAAM,MAAM,GAAG;;KAEZ,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|
3
|
+
*
|
|
4
|
+
* - mode "commit": 従来どおりディスクへ書き込みつつ、操作を記録する。
|
|
5
|
+
* - mode "collect": ディスクへは一切書き込まず、仮想オーバーレイ上で操作を収集する(Plan / dry-run 用)。
|
|
6
|
+
*
|
|
7
|
+
* すべての生成物には Artifact Ownership を付与し、Plan/Apply/Drift 検出の基礎データとする。
|
|
8
|
+
*/
|
|
9
|
+
export type FileSessionMode = "commit" | "collect";
|
|
10
|
+
export type ArtifactOwnership = "managed" | "generated-once" | "user-owned" | "extension-point" | "metadata";
|
|
11
|
+
export type FileSessionActionKind = "create" | "modify" | "append" | "delete" | "skip";
|
|
12
|
+
export interface FileWriteMeta {
|
|
13
|
+
ownership: ArtifactOwnership;
|
|
14
|
+
generator: string;
|
|
15
|
+
sourceModel?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RecordedFileOperation {
|
|
18
|
+
/** Project-relative POSIX path */
|
|
19
|
+
path: string;
|
|
20
|
+
absolutePath: string;
|
|
21
|
+
action: FileSessionActionKind;
|
|
22
|
+
ownership: ArtifactOwnership;
|
|
23
|
+
generator: string;
|
|
24
|
+
sourceModel?: string;
|
|
25
|
+
existedBefore: boolean;
|
|
26
|
+
/** sha256 (LF normalized) of on-disk content before the session touched the file */
|
|
27
|
+
previousHash: string | null;
|
|
28
|
+
/** sha256 (LF normalized) of the new content; null for delete */
|
|
29
|
+
newHash: string | null;
|
|
30
|
+
}
|
|
31
|
+
export declare function normalizeContentForHash(content: string): string;
|
|
32
|
+
export declare function hashContent(content: string): string;
|
|
33
|
+
export declare function hashFileIfExists(absolutePath: string): string | null;
|
|
34
|
+
export declare function toProjectRelativePath(rootDirectory: string, absolutePath: string): string;
|
|
35
|
+
export declare class FileOperationSession {
|
|
36
|
+
readonly mode: FileSessionMode;
|
|
37
|
+
readonly rootDirectory: string;
|
|
38
|
+
readonly warnings: string[];
|
|
39
|
+
private readonly operationsByPath;
|
|
40
|
+
private readonly inputFingerprintsByPath;
|
|
41
|
+
/** overlay: absolute normalized path -> content (null = deleted in session) */
|
|
42
|
+
private readonly overlay;
|
|
43
|
+
constructor(mode: FileSessionMode, rootDirectory?: string);
|
|
44
|
+
get operations(): RecordedFileOperation[];
|
|
45
|
+
get inputFingerprints(): Record<string, string | null>;
|
|
46
|
+
addWarning(message: string): void;
|
|
47
|
+
registerInput(absolutePath: string): void;
|
|
48
|
+
private overlayKey;
|
|
49
|
+
fileExists(absolutePath: string): boolean;
|
|
50
|
+
readFile(absolutePath: string): string;
|
|
51
|
+
writeFile(absolutePath: string, content: string, meta: FileWriteMeta): RecordedFileOperation;
|
|
52
|
+
deleteFile(absolutePath: string, meta: FileWriteMeta): RecordedFileOperation | null;
|
|
53
|
+
}
|
|
54
|
+
export declare function getActiveFileSession(): FileOperationSession | null;
|
|
55
|
+
export declare function runWithFileSession<T>(session: FileOperationSession, action: () => Promise<T>): Promise<T>;
|
|
56
|
+
//# sourceMappingURL=file-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-session.d.ts","sourceRoot":"","sources":["../../../src/core/operations/file-session.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEnD,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,gBAAgB,GAChB,YAAY,GACZ,iBAAiB,GACjB,UAAU,CAAC;AAEf,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,qBAAqB,CAAC;IA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AY,EAAE,MAAM,GAAG,MAAM;IAYtC,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,qBAAqB;IA0C5F,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,qBAAqB,GAAG,IAAI;CA6BpF;AAID,wBAAgB,oBAAoB,IAAI,oBAAoB,GAAG,IAAI,CAElE;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAQZ"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* FileOperationSession — SwallowKit generator 由来のファイル書き込みを一元管理する抽象。
|
|
4
|
+
*
|
|
5
|
+
* - mode "commit": 従来どおりディスクへ書き込みつつ、操作を記録する。
|
|
6
|
+
* - mode "collect": ディスクへは一切書き込まず、仮想オーバーレイ上で操作を収集する(Plan / dry-run 用)。
|
|
7
|
+
*
|
|
8
|
+
* すべての生成物には Artifact Ownership を付与し、Plan/Apply/Drift 検出の基礎データとする。
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.FileOperationSession = void 0;
|
|
45
|
+
exports.normalizeContentForHash = normalizeContentForHash;
|
|
46
|
+
exports.hashContent = hashContent;
|
|
47
|
+
exports.hashFileIfExists = hashFileIfExists;
|
|
48
|
+
exports.toProjectRelativePath = toProjectRelativePath;
|
|
49
|
+
exports.getActiveFileSession = getActiveFileSession;
|
|
50
|
+
exports.runWithFileSession = runWithFileSession;
|
|
51
|
+
const crypto = __importStar(require("crypto"));
|
|
52
|
+
const fs = __importStar(require("fs"));
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
function normalizeContentForHash(content) {
|
|
55
|
+
return content.replace(/\r\n/g, "\n");
|
|
56
|
+
}
|
|
57
|
+
function hashContent(content) {
|
|
58
|
+
return crypto.createHash("sha256").update(normalizeContentForHash(content), "utf-8").digest("hex");
|
|
59
|
+
}
|
|
60
|
+
function hashFileIfExists(absolutePath) {
|
|
61
|
+
try {
|
|
62
|
+
if (!fs.existsSync(absolutePath) || !fs.statSync(absolutePath).isFile()) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return hashContent(fs.readFileSync(absolutePath, "utf-8"));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function toProjectRelativePath(rootDirectory, absolutePath) {
|
|
72
|
+
const relative = path.relative(rootDirectory, absolutePath);
|
|
73
|
+
return relative && !relative.startsWith("..")
|
|
74
|
+
? relative.replace(/\\/g, "/")
|
|
75
|
+
: absolutePath.replace(/\\/g, "/");
|
|
76
|
+
}
|
|
77
|
+
class FileOperationSession {
|
|
78
|
+
constructor(mode, rootDirectory = process.cwd()) {
|
|
79
|
+
this.warnings = [];
|
|
80
|
+
this.operationsByPath = new Map();
|
|
81
|
+
this.inputFingerprintsByPath = new Map();
|
|
82
|
+
/** overlay: absolute normalized path -> content (null = deleted in session) */
|
|
83
|
+
this.overlay = new Map();
|
|
84
|
+
this.mode = mode;
|
|
85
|
+
this.rootDirectory = rootDirectory;
|
|
86
|
+
}
|
|
87
|
+
get operations() {
|
|
88
|
+
return Array.from(this.operationsByPath.values()).sort((a, b) => a.path.localeCompare(b.path));
|
|
89
|
+
}
|
|
90
|
+
get inputFingerprints() {
|
|
91
|
+
return Object.fromEntries(Array.from(this.inputFingerprintsByPath.entries()).sort(([left], [right]) => left.localeCompare(right)));
|
|
92
|
+
}
|
|
93
|
+
addWarning(message) {
|
|
94
|
+
if (!this.warnings.includes(message)) {
|
|
95
|
+
this.warnings.push(message);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
registerInput(absolutePath) {
|
|
99
|
+
const relativePath = toProjectRelativePath(this.rootDirectory, absolutePath);
|
|
100
|
+
this.inputFingerprintsByPath.set(relativePath, hashFileIfExists(absolutePath));
|
|
101
|
+
}
|
|
102
|
+
overlayKey(absolutePath) {
|
|
103
|
+
return path.resolve(absolutePath);
|
|
104
|
+
}
|
|
105
|
+
fileExists(absolutePath) {
|
|
106
|
+
const key = this.overlayKey(absolutePath);
|
|
107
|
+
if (this.overlay.has(key)) {
|
|
108
|
+
return this.overlay.get(key) !== null;
|
|
109
|
+
}
|
|
110
|
+
return fs.existsSync(absolutePath);
|
|
111
|
+
}
|
|
112
|
+
readFile(absolutePath) {
|
|
113
|
+
const key = this.overlayKey(absolutePath);
|
|
114
|
+
if (this.overlay.has(key)) {
|
|
115
|
+
const content = this.overlay.get(key);
|
|
116
|
+
if (content === null || content === undefined) {
|
|
117
|
+
throw new Error(`File was deleted in this session: ${absolutePath}`);
|
|
118
|
+
}
|
|
119
|
+
return content;
|
|
120
|
+
}
|
|
121
|
+
return fs.readFileSync(absolutePath, "utf-8");
|
|
122
|
+
}
|
|
123
|
+
writeFile(absolutePath, content, meta) {
|
|
124
|
+
const key = this.overlayKey(absolutePath);
|
|
125
|
+
const relativePath = toProjectRelativePath(this.rootDirectory, absolutePath);
|
|
126
|
+
const existing = this.operationsByPath.get(relativePath);
|
|
127
|
+
const existedBefore = existing ? existing.existedBefore : fs.existsSync(absolutePath);
|
|
128
|
+
const previousHash = existing ? existing.previousHash : hashFileIfExists(absolutePath);
|
|
129
|
+
const newHash = hashContent(content);
|
|
130
|
+
let action;
|
|
131
|
+
if (!existedBefore) {
|
|
132
|
+
action = "create";
|
|
133
|
+
}
|
|
134
|
+
else if (newHash === previousHash) {
|
|
135
|
+
action = "skip";
|
|
136
|
+
}
|
|
137
|
+
else if (meta.ownership === "extension-point") {
|
|
138
|
+
action = "append";
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
action = "modify";
|
|
142
|
+
}
|
|
143
|
+
const operation = {
|
|
144
|
+
path: relativePath,
|
|
145
|
+
absolutePath,
|
|
146
|
+
action,
|
|
147
|
+
ownership: meta.ownership,
|
|
148
|
+
generator: meta.generator,
|
|
149
|
+
sourceModel: meta.sourceModel ?? existing?.sourceModel,
|
|
150
|
+
existedBefore,
|
|
151
|
+
previousHash,
|
|
152
|
+
newHash,
|
|
153
|
+
};
|
|
154
|
+
this.operationsByPath.set(relativePath, operation);
|
|
155
|
+
this.overlay.set(key, content);
|
|
156
|
+
if (this.mode === "commit" && action !== "skip") {
|
|
157
|
+
fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
|
|
158
|
+
fs.writeFileSync(absolutePath, content, "utf-8");
|
|
159
|
+
}
|
|
160
|
+
return operation;
|
|
161
|
+
}
|
|
162
|
+
deleteFile(absolutePath, meta) {
|
|
163
|
+
if (!this.fileExists(absolutePath)) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const key = this.overlayKey(absolutePath);
|
|
167
|
+
const relativePath = toProjectRelativePath(this.rootDirectory, absolutePath);
|
|
168
|
+
const existing = this.operationsByPath.get(relativePath);
|
|
169
|
+
const operation = {
|
|
170
|
+
path: relativePath,
|
|
171
|
+
absolutePath,
|
|
172
|
+
action: "delete",
|
|
173
|
+
ownership: meta.ownership,
|
|
174
|
+
generator: meta.generator,
|
|
175
|
+
sourceModel: meta.sourceModel ?? existing?.sourceModel,
|
|
176
|
+
existedBefore: existing ? existing.existedBefore : true,
|
|
177
|
+
previousHash: existing ? existing.previousHash : hashFileIfExists(absolutePath),
|
|
178
|
+
newHash: null,
|
|
179
|
+
};
|
|
180
|
+
this.operationsByPath.set(relativePath, operation);
|
|
181
|
+
this.overlay.set(key, null);
|
|
182
|
+
if (this.mode === "commit" && fs.existsSync(absolutePath)) {
|
|
183
|
+
fs.unlinkSync(absolutePath);
|
|
184
|
+
}
|
|
185
|
+
return operation;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.FileOperationSession = FileOperationSession;
|
|
189
|
+
let activeSession = null;
|
|
190
|
+
function getActiveFileSession() {
|
|
191
|
+
return activeSession;
|
|
192
|
+
}
|
|
193
|
+
async function runWithFileSession(session, action) {
|
|
194
|
+
const previous = activeSession;
|
|
195
|
+
activeSession = session;
|
|
196
|
+
try {
|
|
197
|
+
return await action();
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
activeSession = previous;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=file-session.js.map
|