@meetploy/emulator 1.26.0 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler/bundler.d.ts +1 -1
- package/dist/bundler/bundler.js +15 -317
- package/dist/bundler/bundler.js.map +1 -1
- package/dist/dashboard-dist/assets/{main-DZM02c9l.js → main-B2W_MQ7P.js} +57 -57
- package/dist/dashboard-dist/assets/main-oM9iTzuI.css +1 -0
- package/dist/dashboard-dist/index.html +2 -2
- package/dist/dev-dashboard.js +9 -1
- package/dist/dev-dashboard.js.map +1 -1
- package/dist/runtime/ai-runtime.d.ts +1 -1
- package/dist/runtime/ai-runtime.js +1 -157
- package/dist/runtime/ai-runtime.js.map +1 -1
- package/dist/runtime/fs-runtime.d.ts +1 -1
- package/dist/runtime/fs-runtime.js +1 -111
- package/dist/runtime/fs-runtime.js.map +1 -1
- package/dist/runtime/queue-runtime.d.ts +1 -1
- package/dist/runtime/queue-runtime.js +1 -59
- package/dist/runtime/queue-runtime.js.map +1 -1
- package/dist/runtime/state-runtime.d.ts +1 -1
- package/dist/runtime/state-runtime.js +1 -283
- package/dist/runtime/state-runtime.js.map +1 -1
- package/dist/runtime/timer-runtime.d.ts +1 -1
- package/dist/runtime/timer-runtime.js +1 -59
- package/dist/runtime/timer-runtime.js.map +1 -1
- package/dist/runtime/workflow-runtime.d.ts +1 -1
- package/dist/runtime/workflow-runtime.js +1 -266
- package/dist/runtime/workflow-runtime.js.map +1 -1
- package/dist/services/db-service.js +19 -12
- package/dist/services/db-service.js.map +1 -1
- package/dist/services/db-service.spec.js +45 -0
- package/dist/services/db-service.spec.js.map +1 -1
- package/dist/utils/sqlite.js +2 -86
- package/dist/utils/sqlite.js.map +1 -1
- package/package.json +1 -1
- package/dist/dashboard-dist/assets/main-C8ubpaTn.css +0 -1
|
@@ -1,267 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
interface WorkflowExecution {
|
|
3
|
-
id: string;
|
|
4
|
-
status: "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
5
|
-
result?: unknown;
|
|
6
|
-
error?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface Workflow<TInput = unknown> {
|
|
10
|
-
trigger: (input: TInput) => Promise<{ executionId: string }>;
|
|
11
|
-
getExecution: (executionId: string) => Promise<WorkflowExecution>;
|
|
12
|
-
cancel: (executionId: string) => Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function initializeWorkflow<TInput = unknown>(
|
|
16
|
-
workflowName: string,
|
|
17
|
-
serviceUrl: string
|
|
18
|
-
): Workflow<TInput> {
|
|
19
|
-
return {
|
|
20
|
-
async trigger(input: TInput): Promise<{ executionId: string }> {
|
|
21
|
-
const response = await fetch(serviceUrl + "/workflow/trigger", {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: { "Content-Type": "application/json" },
|
|
24
|
-
body: JSON.stringify({ workflowName, input }),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (!response.ok) {
|
|
28
|
-
const errorText = await response.text();
|
|
29
|
-
throw new Error("Workflow trigger failed: " + errorText);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const result = await response.json();
|
|
33
|
-
if (!result.success) {
|
|
34
|
-
throw new Error(result.error || "Workflow trigger failed");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return { executionId: result.executionId };
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
async getExecution(executionId: string): Promise<WorkflowExecution> {
|
|
41
|
-
const response = await fetch(serviceUrl + "/workflow/status", {
|
|
42
|
-
method: "POST",
|
|
43
|
-
headers: { "Content-Type": "application/json" },
|
|
44
|
-
body: JSON.stringify({ executionId }),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (!response.ok) {
|
|
48
|
-
const errorText = await response.text();
|
|
49
|
-
throw new Error("Workflow status failed: " + errorText);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const result = await response.json();
|
|
53
|
-
if (!result.success) {
|
|
54
|
-
throw new Error(result.error || "Workflow status failed");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const exec = result.execution;
|
|
58
|
-
return {
|
|
59
|
-
id: exec.id,
|
|
60
|
-
status: exec.status,
|
|
61
|
-
result: exec.output,
|
|
62
|
-
error: exec.error,
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
async cancel(executionId: string): Promise<void> {
|
|
67
|
-
const response = await fetch(serviceUrl + "/workflow/cancel", {
|
|
68
|
-
method: "POST",
|
|
69
|
-
headers: { "Content-Type": "application/json" },
|
|
70
|
-
body: JSON.stringify({ executionId }),
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (!response.ok) {
|
|
74
|
-
const errorText = await response.text();
|
|
75
|
-
throw new Error("Workflow cancel failed: " + errorText);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const result = await response.json();
|
|
79
|
-
if (!result.success) {
|
|
80
|
-
throw new Error(result.error || "Workflow cancel failed");
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface WorkflowStepContext {
|
|
87
|
-
run: <T>(stepName: string, fn: () => T | Promise<T>, options?: { retries?: number; input?: unknown }) => Promise<T>;
|
|
88
|
-
sleep: (durationMs: number) => Promise<void>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface WorkflowContext<TInput = unknown, TEnv = unknown> {
|
|
92
|
-
input: TInput;
|
|
93
|
-
env: TEnv;
|
|
94
|
-
step: WorkflowStepContext;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const MAX_ERROR_CAUSE_DEPTH = 5;
|
|
98
|
-
|
|
99
|
-
function formatErrorForStorage(error: unknown): string {
|
|
100
|
-
if (!(error instanceof Error)) {
|
|
101
|
-
return String(error);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let result = error.stack || error.name + ": " + error.message;
|
|
105
|
-
const seen = new Set<unknown>();
|
|
106
|
-
let cause: unknown = error.cause;
|
|
107
|
-
let depth = 0;
|
|
108
|
-
|
|
109
|
-
while (cause !== null && cause !== undefined && depth < MAX_ERROR_CAUSE_DEPTH) {
|
|
110
|
-
if (seen.has(cause)) {
|
|
111
|
-
result += "\\n\\nCaused by: [cycle detected in error causes]";
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
seen.add(cause);
|
|
116
|
-
|
|
117
|
-
if (cause instanceof Error) {
|
|
118
|
-
result += "\\n\\nCaused by: " + (cause.stack || cause.name + ": " + cause.message);
|
|
119
|
-
cause = cause.cause;
|
|
120
|
-
} else {
|
|
121
|
-
result += "\\n\\nCaused by: " + (typeof cause === "string" ? cause : JSON.stringify(cause));
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
depth++;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (cause !== null && cause !== undefined && depth >= MAX_ERROR_CAUSE_DEPTH) {
|
|
129
|
-
result += "\\n\\nCaused by: [additional error causes truncated]";
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function createStepContext(executionId: string, serviceUrl: string, defaultRetries: number = 3): WorkflowStepContext {
|
|
136
|
-
let stepIndex = 0;
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
async run<T>(stepName: string, fn: () => T | Promise<T>, options?: { retries?: number; input?: unknown }): Promise<T> {
|
|
140
|
-
const currentStepIndex = stepIndex++;
|
|
141
|
-
const maxRetries = options?.retries ?? defaultRetries;
|
|
142
|
-
|
|
143
|
-
const startResponse = await fetch(serviceUrl + "/workflow/step/start", {
|
|
144
|
-
method: "POST",
|
|
145
|
-
headers: { "Content-Type": "application/json" },
|
|
146
|
-
body: JSON.stringify({ executionId, stepName, stepIndex: currentStepIndex, input: options?.input }),
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
if (!startResponse.ok) {
|
|
150
|
-
const errorText = await startResponse.text();
|
|
151
|
-
throw new Error("Failed to start step: " + errorText);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const startResult = await startResponse.json();
|
|
155
|
-
|
|
156
|
-
if (startResult.alreadyCompleted) {
|
|
157
|
-
return startResult.output as T;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const startTime = Date.now();
|
|
161
|
-
let lastError: Error | null = null;
|
|
162
|
-
|
|
163
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
164
|
-
try {
|
|
165
|
-
const result = await fn();
|
|
166
|
-
const durationMs = Date.now() - startTime;
|
|
167
|
-
|
|
168
|
-
await fetch(serviceUrl + "/workflow/step/complete", {
|
|
169
|
-
method: "POST",
|
|
170
|
-
headers: { "Content-Type": "application/json" },
|
|
171
|
-
body: JSON.stringify({ executionId, stepName, input: options?.input, output: result, durationMs, attempt: attempt + 1, maxRetries }),
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return result;
|
|
175
|
-
} catch (error) {
|
|
176
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
177
|
-
if (attempt < maxRetries) {
|
|
178
|
-
const durationMs = Date.now() - startTime;
|
|
179
|
-
const retryResponse = await fetch(serviceUrl + "/workflow/step/retry", {
|
|
180
|
-
method: "POST",
|
|
181
|
-
headers: { "Content-Type": "application/json" },
|
|
182
|
-
body: JSON.stringify({ executionId, stepName, input: options?.input, error: formatErrorForStorage(lastError), durationMs, attempt: attempt + 1, maxRetries }),
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
if (!retryResponse.ok) {
|
|
186
|
-
const errorText = await retryResponse.text();
|
|
187
|
-
throw new Error("Failed to record step retry: " + errorText);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(1000 * Math.pow(2, attempt), 30000)));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const durationMs = Date.now() - startTime;
|
|
196
|
-
await fetch(serviceUrl + "/workflow/step/fail", {
|
|
197
|
-
method: "POST",
|
|
198
|
-
headers: { "Content-Type": "application/json" },
|
|
199
|
-
body: JSON.stringify({ executionId, stepName, input: options?.input, error: formatErrorForStorage(lastError || new Error("Step execution failed")), durationMs, attempt: maxRetries + 1, maxRetries }),
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
throw lastError;
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
async sleep(durationMs: number): Promise<void> {
|
|
206
|
-
const stepName = "__sleep_" + stepIndex++;
|
|
207
|
-
|
|
208
|
-
await fetch(serviceUrl + "/workflow/step/start", {
|
|
209
|
-
method: "POST",
|
|
210
|
-
headers: { "Content-Type": "application/json" },
|
|
211
|
-
body: JSON.stringify({ executionId, stepName, stepIndex: stepIndex - 1, input: { sleptMs: durationMs } }),
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
await new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
215
|
-
|
|
216
|
-
await fetch(serviceUrl + "/workflow/step/complete", {
|
|
217
|
-
method: "POST",
|
|
218
|
-
headers: { "Content-Type": "application/json" },
|
|
219
|
-
body: JSON.stringify({ executionId, stepName, input: { sleptMs: durationMs }, output: { sleptMs: durationMs }, durationMs, attempt: 1, maxRetries: 0 }),
|
|
220
|
-
});
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export async function executeWorkflow<TInput, TOutput, TEnv>(
|
|
226
|
-
executionId: string,
|
|
227
|
-
workflowFn: (context: WorkflowContext<TInput, TEnv>) => Promise<TOutput>,
|
|
228
|
-
input: TInput,
|
|
229
|
-
env: TEnv,
|
|
230
|
-
serviceUrl: string,
|
|
231
|
-
defaultRetries: number = 3,
|
|
232
|
-
onError?: (error: Error, context: WorkflowContext<TInput, TEnv>) => Promise<void>
|
|
233
|
-
): Promise<TOutput> {
|
|
234
|
-
const step = createStepContext(executionId, serviceUrl, defaultRetries);
|
|
235
|
-
const context: WorkflowContext<TInput, TEnv> = { input, env, step };
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
const output = await workflowFn(context);
|
|
239
|
-
|
|
240
|
-
await fetch(serviceUrl + "/workflow/complete", {
|
|
241
|
-
method: "POST",
|
|
242
|
-
headers: { "Content-Type": "application/json" },
|
|
243
|
-
body: JSON.stringify({ executionId, output }),
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
return output;
|
|
247
|
-
} catch (error) {
|
|
248
|
-
if (onError) {
|
|
249
|
-
try {
|
|
250
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
251
|
-
await onError(err, context);
|
|
252
|
-
} catch (onErrorError) {
|
|
253
|
-
console.error("Workflow onError handler threw:", onErrorError);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
await fetch(serviceUrl + "/workflow/fail", {
|
|
258
|
-
method: "POST",
|
|
259
|
-
headers: { "Content-Type": "application/json" },
|
|
260
|
-
body: JSON.stringify({ executionId, error: error instanceof Error ? error.message : String(error) }),
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
throw error;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
`;
|
|
1
|
+
export { WORKFLOW_RUNTIME_CODE } from "@meetploy/shared";
|
|
267
2
|
//# sourceMappingURL=workflow-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-runtime.js","sourceRoot":"","sources":["../../src/runtime/workflow-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-runtime.js","sourceRoot":"","sources":["../../src/runtime/workflow-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -11,12 +11,18 @@ export function createDbHandler(getDatabase) {
|
|
|
11
11
|
const db = getDatabase(dbName);
|
|
12
12
|
if (method === "prepare" && query) {
|
|
13
13
|
const stmt = db.prepare(query);
|
|
14
|
-
const
|
|
14
|
+
const upper = query.trim().toUpperCase();
|
|
15
|
+
const isSelect = upper.startsWith("SELECT");
|
|
16
|
+
const hasReturning = /\bRETURNING\b/.test(upper);
|
|
17
|
+
const isReader = isSelect || hasReturning;
|
|
15
18
|
let results;
|
|
16
19
|
let changes = 0;
|
|
17
20
|
let lastInsertRowid = 0;
|
|
18
|
-
if (
|
|
21
|
+
if (isReader) {
|
|
19
22
|
results = params?.length ? stmt.all(...params) : stmt.all();
|
|
23
|
+
if (hasReturning) {
|
|
24
|
+
changes = results.length;
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
27
|
else {
|
|
22
28
|
const info = params?.length ? stmt.run(...params) : stmt.run();
|
|
@@ -30,7 +36,7 @@ export function createDbHandler(getDatabase) {
|
|
|
30
36
|
success: true,
|
|
31
37
|
meta: {
|
|
32
38
|
duration,
|
|
33
|
-
rows_read: results.length,
|
|
39
|
+
rows_read: isSelect ? results.length : 0,
|
|
34
40
|
rows_written: changes,
|
|
35
41
|
changes,
|
|
36
42
|
last_row_id: lastInsertRowid,
|
|
@@ -57,24 +63,25 @@ export function createDbHandler(getDatabase) {
|
|
|
57
63
|
const transaction = db.transaction(() => {
|
|
58
64
|
for (const stmt of statements) {
|
|
59
65
|
const prepared = db.prepare(stmt.query);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (
|
|
66
|
+
const upper = stmt.query.trim().toUpperCase();
|
|
67
|
+
const isSelect = upper.startsWith("SELECT");
|
|
68
|
+
const hasReturning = /\bRETURNING\b/.test(upper);
|
|
69
|
+
const isReader = isSelect || hasReturning;
|
|
70
|
+
if (isReader) {
|
|
65
71
|
const rows = stmt.params?.length
|
|
66
72
|
? prepared.all(...stmt.params)
|
|
67
73
|
: prepared.all();
|
|
74
|
+
const changes = hasReturning ? rows.length : 0;
|
|
68
75
|
results.push({
|
|
69
76
|
results: rows,
|
|
70
77
|
success: true,
|
|
71
78
|
meta: {
|
|
72
79
|
duration: 0,
|
|
73
|
-
rows_read: rows.length,
|
|
74
|
-
rows_written:
|
|
75
|
-
changes
|
|
80
|
+
rows_read: isSelect ? rows.length : 0,
|
|
81
|
+
rows_written: changes,
|
|
82
|
+
changes,
|
|
76
83
|
last_row_id: 0,
|
|
77
|
-
changed_db:
|
|
84
|
+
changed_db: !isSelect && changes > 0,
|
|
78
85
|
size_after: 0,
|
|
79
86
|
served_by: "ploy-emulator",
|
|
80
87
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-service.js","sourceRoot":"","sources":["../../src/services/db-service.ts"],"names":[],"mappings":"AAgCA,MAAM,UAAU,eAAe,CAC9B,WAAoD;IAEpD,OAAO,KAAK,EAAE,CAAU,EAAE,EAAE;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YACJ,MAAM,IAAI,GAAc,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YAC3C,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,GACnE,IAAI,CAAC;YAGN,MAAM,MAAM,GAAG,WAAW,IAAI,UAAU,CAAC;YACzC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,mCAAmC,EAAE,EAAE,GAAG,CAAC,CAAC;YACpE,CAAC;YAED,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;YAE/B,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC;gBACnC,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC/B,MAAM,
|
|
1
|
+
{"version":3,"file":"db-service.js","sourceRoot":"","sources":["../../src/services/db-service.ts"],"names":[],"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AAE,gBAAgB,EAAE,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QACxC,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -55,6 +55,51 @@ describe("db service D1 compatibility", () => {
|
|
|
55
55
|
expect(body[0]?.meta.changes).toBe(1);
|
|
56
56
|
expect(body[1]?.results).toEqual([{ name: "Ada" }]);
|
|
57
57
|
});
|
|
58
|
+
test("returns inserted rows for INSERT ... RETURNING", async () => {
|
|
59
|
+
const response = await post(app, {
|
|
60
|
+
bindingName: "DB",
|
|
61
|
+
method: "prepare",
|
|
62
|
+
query: "INSERT INTO users (name) VALUES (?) RETURNING id, name",
|
|
63
|
+
params: ["Ada"],
|
|
64
|
+
});
|
|
65
|
+
const body = (await response.json());
|
|
66
|
+
expect(body.results).toEqual([{ id: 1, name: "Ada" }]);
|
|
67
|
+
expect(body.meta.changes).toBe(1);
|
|
68
|
+
expect(body.meta.changed_db).toBe(true);
|
|
69
|
+
expect(body.meta.rows_read).toBe(0);
|
|
70
|
+
});
|
|
71
|
+
test("returns rows for UPDATE ... RETURNING", async () => {
|
|
72
|
+
db.prepare("INSERT INTO users (name) VALUES (?)").run("Ada");
|
|
73
|
+
db.prepare("INSERT INTO users (name) VALUES (?)").run("Grace");
|
|
74
|
+
const response = await post(app, {
|
|
75
|
+
bindingName: "DB",
|
|
76
|
+
method: "prepare",
|
|
77
|
+
query: "UPDATE users SET name = ? WHERE name = ? RETURNING id, name",
|
|
78
|
+
params: ["Ada Lovelace", "Ada"],
|
|
79
|
+
});
|
|
80
|
+
const body = (await response.json());
|
|
81
|
+
expect(body.results).toEqual([{ id: 1, name: "Ada Lovelace" }]);
|
|
82
|
+
expect(body.meta.changes).toBe(1);
|
|
83
|
+
});
|
|
84
|
+
test("returns deleted rows for DELETE ... RETURNING in batch", async () => {
|
|
85
|
+
db.prepare("INSERT INTO users (name) VALUES (?)").run("Ada");
|
|
86
|
+
const response = await post(app, {
|
|
87
|
+
bindingName: "DB",
|
|
88
|
+
method: "batch",
|
|
89
|
+
statements: [
|
|
90
|
+
{
|
|
91
|
+
query: "DELETE FROM users WHERE name = ? RETURNING id",
|
|
92
|
+
params: ["Ada"],
|
|
93
|
+
},
|
|
94
|
+
{ query: "SELECT COUNT(*) AS n FROM users" },
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
const body = (await response.json());
|
|
98
|
+
expect(body[0]?.results).toEqual([{ id: 1 }]);
|
|
99
|
+
expect(body[0]?.meta.changes).toBe(1);
|
|
100
|
+
expect(body[0]?.meta.changed_db).toBe(true);
|
|
101
|
+
expect(body[1]?.results).toEqual([{ n: 0 }]);
|
|
102
|
+
});
|
|
58
103
|
test("returns Cloudflare-style exec metadata", async () => {
|
|
59
104
|
const response = await post(app, {
|
|
60
105
|
bindingName: "DB",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-service.spec.js","sourceRoot":"","sources":["../../src/services/db-service.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AAEzE,SAAS,aAAa,CAAC,EAAkB;IACxC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,GAAG,CAAC,IAAI,CACP,KAAK,EACL,eAAe,CAAC,GAAG,EAA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AC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE;YAChC,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,MAAM;YACd,KAAK,EACJ,gFAAgF;SACjF,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGlC,CAAC;QAEF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/utils/sqlite.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { escapeSqlString, PLOY_DB_MIGRATIONS_TABLE, resolveMigrationTargets, } from "@meetploy/tools/cli";
|
|
3
4
|
import { ensureDataDir } from "./paths.js";
|
|
4
5
|
import { openDatabase } from "./sqlite-db.js";
|
|
5
|
-
const PLOY_DB_MIGRATIONS_TABLE = "ploy_internal_db_migrations";
|
|
6
6
|
const EMULATOR_SCHEMA = `
|
|
7
7
|
-- Queue messages table
|
|
8
8
|
CREATE TABLE IF NOT EXISTS queue_messages (
|
|
@@ -280,88 +280,4 @@ function ensureStateTableCompatibility(db) {
|
|
|
280
280
|
db.exec(`ALTER TABLE state_entries ADD COLUMN encoding TEXT NOT NULL DEFAULT 'text'`);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
function resolveMigrationTargets(projectDir, config) {
|
|
284
|
-
const migrationsDir = join(projectDir, "migrations");
|
|
285
|
-
if (!directoryExists(migrationsDir)) {
|
|
286
|
-
return [];
|
|
287
|
-
}
|
|
288
|
-
const authBindingName = config.auth?.binding;
|
|
289
|
-
const databaseBindings = Object.entries(config.db ?? {}).filter(([bindingName]) => bindingName !== authBindingName);
|
|
290
|
-
const reservedBindingDirectoryNames = new Set(databaseBindings.map(([bindingName]) => bindingName));
|
|
291
|
-
const rootSqlFiles = getOrderedMigrationFiles(migrationsDir, reservedBindingDirectoryNames);
|
|
292
|
-
const bindingTargets = [];
|
|
293
|
-
for (const [bindingName, databaseName] of databaseBindings) {
|
|
294
|
-
const bindingMigrationsDir = join(migrationsDir, bindingName);
|
|
295
|
-
if (!directoryExists(bindingMigrationsDir)) {
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
const files = getOrderedMigrationFiles(bindingMigrationsDir);
|
|
299
|
-
if (files.length === 0) {
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
bindingTargets.push({
|
|
303
|
-
bindingName,
|
|
304
|
-
databaseName,
|
|
305
|
-
migrationsDir: bindingMigrationsDir,
|
|
306
|
-
files,
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
if (rootSqlFiles.length > 0 && bindingTargets.length > 0) {
|
|
310
|
-
throw new Error("Found both root migrations entries and binding-specific migrations directories. Use only one layout.");
|
|
311
|
-
}
|
|
312
|
-
if (rootSqlFiles.length === 0) {
|
|
313
|
-
return bindingTargets;
|
|
314
|
-
}
|
|
315
|
-
if (databaseBindings.length === 0) {
|
|
316
|
-
throw new Error("Found migrations entries but no non-auth database bindings are configured for this project.");
|
|
317
|
-
}
|
|
318
|
-
if (databaseBindings.length > 1) {
|
|
319
|
-
throw new Error(`Found root migrations entries but ${String(databaseBindings.length)} database bindings are configured. Move migrations into binding-specific directories under migrations/<bindingName>/.`);
|
|
320
|
-
}
|
|
321
|
-
const [bindingName, databaseName] = databaseBindings[0];
|
|
322
|
-
return [
|
|
323
|
-
{
|
|
324
|
-
bindingName,
|
|
325
|
-
databaseName,
|
|
326
|
-
migrationsDir,
|
|
327
|
-
files: rootSqlFiles,
|
|
328
|
-
},
|
|
329
|
-
];
|
|
330
|
-
}
|
|
331
|
-
function getOrderedMigrationFiles(path, reservedDirectoryNames = new Set()) {
|
|
332
|
-
const entries = readdirSync(path, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
333
|
-
const files = [];
|
|
334
|
-
for (const entry of entries) {
|
|
335
|
-
if (entry.isFile() && entry.name.endsWith(".sql")) {
|
|
336
|
-
files.push(entry.name);
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
if (!entry.isDirectory() || reservedDirectoryNames.has(entry.name)) {
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
const nestedPath = join(path, entry.name);
|
|
343
|
-
const nestedSqlFiles = readdirSync(nestedPath, {
|
|
344
|
-
withFileTypes: true,
|
|
345
|
-
})
|
|
346
|
-
.filter((nestedEntry) => nestedEntry.isFile() && nestedEntry.name.endsWith(".sql"))
|
|
347
|
-
.map((nestedEntry) => `${entry.name}/${nestedEntry.name}`)
|
|
348
|
-
.sort((a, b) => a.localeCompare(b));
|
|
349
|
-
files.push(...nestedSqlFiles);
|
|
350
|
-
}
|
|
351
|
-
return files;
|
|
352
|
-
}
|
|
353
|
-
function directoryExists(path) {
|
|
354
|
-
if (!existsSync(path)) {
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
try {
|
|
358
|
-
return statSync(path).isDirectory();
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function escapeSqlString(value) {
|
|
365
|
-
return value.replaceAll("'", "''");
|
|
366
|
-
}
|
|
367
283
|
//# sourceMappingURL=sqlite.js.map
|
package/dist/utils/sqlite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/utils/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/utils/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACN,eAAe,EACf,wBAAwB,EACxB,uBAAuB,GAEvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAuB,MAAM,gBAAgB,CAAC;AAUnE,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0KvB,CAAC;AAQF,MAAM,UAAU,mBAAmB,CAClC,UAAkB,EAClB,aAAsB;IAEtB,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEpD,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;IAC9D,UAAU,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACxC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACjC,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAE1C,SAAS,WAAW,CAAC,WAAmB;QACvC,IAAI,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC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