@emdash-cms/cloudflare 0.4.0 → 0.5.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/db/do.d.mts +1 -1
- package/dist/db/do.mjs +1 -1
- package/dist/db/playground.d.mts +1 -1
- package/dist/db/playground.mjs +1 -1
- package/dist/{do-class-x5Xh_G62.d.mts → do-class-BTfbOeYE.d.mts} +5 -0
- package/dist/{do-class-DY2Ba2RJ.mjs → do-class-DYgovHsQ.mjs} +15 -5
- package/dist/sandbox/index.mjs +4 -2
- package/package.json +2 -2
- package/src/db/do-class.ts +25 -12
- package/src/sandbox/runner.ts +4 -1
package/dist/db/do.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as PreviewDOConfig } from "../do-types-CY0G0oyh.mjs";
|
|
2
|
-
import { t as EmDashPreviewDB } from "../do-class-
|
|
2
|
+
import { t as EmDashPreviewDB } from "../do-class-BTfbOeYE.mjs";
|
|
3
3
|
import { Dialect } from "kysely";
|
|
4
4
|
import { MiddlewareHandler } from "astro";
|
|
5
5
|
|
package/dist/db/do.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../d1-introspector-bZf0_ylK.mjs";
|
|
2
2
|
import { t as PreviewDODialect } from "../do-dialect-BhFcRSFQ.mjs";
|
|
3
|
-
import { t as EmDashPreviewDB } from "../do-class-
|
|
3
|
+
import { t as EmDashPreviewDB } from "../do-class-DYgovHsQ.mjs";
|
|
4
4
|
import { env } from "cloudflare:workers";
|
|
5
5
|
import { Kysely } from "kysely";
|
|
6
6
|
import { runWithContext } from "emdash/request-context";
|
package/dist/db/playground.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as PreviewDOConfig } from "../do-types-CY0G0oyh.mjs";
|
|
2
|
-
import { t as EmDashPreviewDB } from "../do-class-
|
|
2
|
+
import { t as EmDashPreviewDB } from "../do-class-BTfbOeYE.mjs";
|
|
3
3
|
import { Dialect } from "kysely";
|
|
4
4
|
|
|
5
5
|
//#region src/db/do-playground-routes.d.ts
|
package/dist/db/playground.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../d1-introspector-bZf0_ylK.mjs";
|
|
2
2
|
import { t as PreviewDODialect } from "../do-dialect-BhFcRSFQ.mjs";
|
|
3
|
-
import { t as EmDashPreviewDB } from "../do-class-
|
|
3
|
+
import { t as EmDashPreviewDB } from "../do-class-DYgovHsQ.mjs";
|
|
4
4
|
import { t as isBlockedInPlayground } from "../do-playground-routes-CmwFeGwJ.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/db/playground.ts
|
|
@@ -65,6 +65,11 @@ declare class EmDashPreviewDB extends DurableObject {
|
|
|
65
65
|
/**
|
|
66
66
|
* Drop all user tables in the DO's SQLite database.
|
|
67
67
|
* Preserves SQLite and Cloudflare internal tables.
|
|
68
|
+
*
|
|
69
|
+
* Disables foreign key enforcement before dropping to avoid cascade
|
|
70
|
+
* errors when tables are dropped in an order that violates FK
|
|
71
|
+
* dependencies (e.g. child dropped first, then parent's implicit
|
|
72
|
+
* CASCADE delete references the already-dropped child table).
|
|
68
73
|
*/
|
|
69
74
|
private dropAllTables;
|
|
70
75
|
private applySnapshot;
|
|
@@ -125,13 +125,23 @@ var EmDashPreviewDB = class extends DurableObject {
|
|
|
125
125
|
/**
|
|
126
126
|
* Drop all user tables in the DO's SQLite database.
|
|
127
127
|
* Preserves SQLite and Cloudflare internal tables.
|
|
128
|
+
*
|
|
129
|
+
* Disables foreign key enforcement before dropping to avoid cascade
|
|
130
|
+
* errors when tables are dropped in an order that violates FK
|
|
131
|
+
* dependencies (e.g. child dropped first, then parent's implicit
|
|
132
|
+
* CASCADE delete references the already-dropped child table).
|
|
128
133
|
*/
|
|
129
134
|
dropAllTables() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
this.ctx.storage.sql.exec("PRAGMA foreign_keys = OFF");
|
|
136
|
+
try {
|
|
137
|
+
const tables = [...this.ctx.storage.sql.exec("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_cf_%'")];
|
|
138
|
+
for (const row of tables) {
|
|
139
|
+
const name = String(row.name);
|
|
140
|
+
if (!SAFE_IDENTIFIER.test(name)) continue;
|
|
141
|
+
this.ctx.storage.sql.exec(`DROP TABLE IF EXISTS "${name}"`);
|
|
142
|
+
}
|
|
143
|
+
} finally {
|
|
144
|
+
this.ctx.storage.sql.exec("PRAGMA foreign_keys = ON");
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
applySnapshot(snapshot) {
|
package/dist/sandbox/index.mjs
CHANGED
|
@@ -724,6 +724,7 @@ function sanitizeComment(s) {
|
|
|
724
724
|
* when the user configures `sandboxRunner: "@emdash-cms/cloudflare/sandbox"`.
|
|
725
725
|
*
|
|
726
726
|
*/
|
|
727
|
+
const EMDASH_SHIM = "export const definePlugin = (d) => d;\n";
|
|
727
728
|
/**
|
|
728
729
|
* Default resource limits for sandboxed plugins.
|
|
729
730
|
*
|
|
@@ -865,11 +866,12 @@ var CloudflareSandboxedPlugin = class {
|
|
|
865
866
|
subRequests: this.limits.subrequests
|
|
866
867
|
};
|
|
867
868
|
return this.loader.get(this.id, () => ({
|
|
868
|
-
compatibilityDate: "
|
|
869
|
+
compatibilityDate: "2026-04-01",
|
|
869
870
|
mainModule: "plugin.js",
|
|
870
871
|
modules: {
|
|
871
872
|
"plugin.js": { js: this.wrapperCode },
|
|
872
|
-
"sandbox-plugin.js": { js: this.code }
|
|
873
|
+
"sandbox-plugin.js": { js: this.code },
|
|
874
|
+
emdash: { js: EMDASH_SHIM }
|
|
873
875
|
},
|
|
874
876
|
globalOutbound: null,
|
|
875
877
|
limits: loaderLimits,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emdash-cms/cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Cloudflare adapters for EmDash - D1, R2, Access, and Worker Loader sandbox",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"jose": "^6.1.3",
|
|
67
67
|
"kysely-d1": "^0.4.0",
|
|
68
68
|
"ulidx": "^2.4.1",
|
|
69
|
-
"emdash": "0.
|
|
69
|
+
"emdash": "0.5.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@cloudflare/workers-types": ">=4.0.0",
|
package/src/db/do-class.ts
CHANGED
|
@@ -202,21 +202,34 @@ export class EmDashPreviewDB extends DurableObject {
|
|
|
202
202
|
/**
|
|
203
203
|
* Drop all user tables in the DO's SQLite database.
|
|
204
204
|
* Preserves SQLite and Cloudflare internal tables.
|
|
205
|
+
*
|
|
206
|
+
* Disables foreign key enforcement before dropping to avoid cascade
|
|
207
|
+
* errors when tables are dropped in an order that violates FK
|
|
208
|
+
* dependencies (e.g. child dropped first, then parent's implicit
|
|
209
|
+
* CASCADE delete references the already-dropped child table).
|
|
205
210
|
*/
|
|
206
211
|
private dropAllTables(): void {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
// Disable FK enforcement so DROP order doesn't matter.
|
|
213
|
+
// Cloudflare DO SQLite enforces foreign keys by default.
|
|
214
|
+
this.ctx.storage.sql.exec("PRAGMA foreign_keys = OFF");
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
const tables = [
|
|
218
|
+
...this.ctx.storage.sql.exec(
|
|
219
|
+
"SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_cf_%'",
|
|
220
|
+
),
|
|
221
|
+
];
|
|
222
|
+
for (const row of tables) {
|
|
223
|
+
// eslint-disable-next-line typescript-eslint(no-unsafe-type-assertion) -- SqlStorageCursor yields loosely-typed rows
|
|
224
|
+
const name = String(row.name as string);
|
|
225
|
+
if (!SAFE_IDENTIFIER.test(name)) {
|
|
226
|
+
// Skip tables with unsafe names rather than interpolating them
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
this.ctx.storage.sql.exec(`DROP TABLE IF EXISTS "${name}"`);
|
|
218
230
|
}
|
|
219
|
-
|
|
231
|
+
} finally {
|
|
232
|
+
this.ctx.storage.sql.exec("PRAGMA foreign_keys = ON");
|
|
220
233
|
}
|
|
221
234
|
}
|
|
222
235
|
|
package/src/sandbox/runner.ts
CHANGED
|
@@ -26,6 +26,8 @@ import { setEmailSendCallback } from "./bridge.js";
|
|
|
26
26
|
import type { WorkerLoader, WorkerStub, PluginBridgeBinding, WorkerLoaderLimits } from "./types.js";
|
|
27
27
|
import { generatePluginWrapper } from "./wrapper.js";
|
|
28
28
|
|
|
29
|
+
const EMDASH_SHIM = "export const definePlugin = (d) => d;\n";
|
|
30
|
+
|
|
29
31
|
/**
|
|
30
32
|
* Default resource limits for sandboxed plugins.
|
|
31
33
|
*
|
|
@@ -248,11 +250,12 @@ class CloudflareSandboxedPlugin implements SandboxedPlugin {
|
|
|
248
250
|
// Get a fresh stub with the new bridge binding.
|
|
249
251
|
// Worker Loader caches the isolate but the stub/bindings are per-call.
|
|
250
252
|
return this.loader.get(this.id, () => ({
|
|
251
|
-
compatibilityDate: "
|
|
253
|
+
compatibilityDate: "2026-04-01",
|
|
252
254
|
mainModule: "plugin.js",
|
|
253
255
|
modules: {
|
|
254
256
|
"plugin.js": { js: this.wrapperCode! },
|
|
255
257
|
"sandbox-plugin.js": { js: this.code },
|
|
258
|
+
emdash: { js: EMDASH_SHIM },
|
|
256
259
|
},
|
|
257
260
|
// Block direct network access - plugins must use ctx.http via bridge
|
|
258
261
|
globalOutbound: null,
|