@substrat-run/adapter-cloudflare 0.160.0 → 0.161.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/control-plane-do.d.ts +43 -9
- package/dist/control-plane-do.d.ts.map +1 -1
- package/dist/control-plane-do.js +156 -28
- package/dist/control-plane-do.js.map +1 -1
- package/dist/host.d.ts +76 -10
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +160 -117
- package/dist/host.js.map +1 -1
- package/dist/r2.d.ts.map +1 -1
- package/dist/r2.js +13 -10
- package/dist/r2.js.map +1 -1
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +80 -5
- package/dist/scope-do.js.map +1 -1
- package/package.json +9 -9
package/dist/r2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"r2.d.ts","sourceRoot":"","sources":["../src/r2.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"r2.d.ts","sourceRoot":"","sources":["../src/r2.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,8EAA8E;IAC9E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAaD;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,YAAY,CA2D1E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,iBAAiB,CAIjD;AAyBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,CAoClE"}
|
package/dist/r2.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { globalFetch, isSizedByteStream, knownLengthStream, } from '@substrat-run/kernel';
|
|
1
|
+
import { globalFetch, isSizedByteStream, knownLengthStream, runtimeSha256, } from '@substrat-run/kernel';
|
|
2
2
|
/** Bound an untrusted upstream body for an error message, marking the cut (#307). */
|
|
3
3
|
function bounded(body, max = 2000) {
|
|
4
4
|
return body.length <= max ? body : `${body.slice(0, max)} … [truncated, ${body.length - max} chars omitted]`;
|
|
@@ -90,15 +90,10 @@ export function createR2BlobStores(opts) {
|
|
|
90
90
|
* held. The kernel's `putAttachmentBytes` takes it.
|
|
91
91
|
*/
|
|
92
92
|
export function workerdSha256() {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
hex: async () => {
|
|
98
|
-
await writer.close();
|
|
99
|
-
return [...new Uint8Array(await digest.digest)].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
100
|
-
},
|
|
101
|
-
};
|
|
93
|
+
const make = runtimeSha256();
|
|
94
|
+
if (!make)
|
|
95
|
+
throw new Error('this runtime has no crypto.DigestStream; the Cloudflare adapter runs on workerd');
|
|
96
|
+
return make();
|
|
102
97
|
}
|
|
103
98
|
/**
|
|
104
99
|
* The WORKER-side open (#473): wrap the tenant's real `r2_bucket` binding — looked up as
|
|
@@ -122,6 +117,14 @@ export function r2TenantBlobStore(bucket) {
|
|
|
122
117
|
const contentType = obj.httpMetadata?.contentType;
|
|
123
118
|
return contentType !== undefined ? { body, contentType } : { body };
|
|
124
119
|
},
|
|
120
|
+
// #2514: the object's own body stream, with the size R2 holds for it, so an open reads it as it goes.
|
|
121
|
+
getStream: async (key) => {
|
|
122
|
+
const obj = await r2.get(key);
|
|
123
|
+
if (!obj)
|
|
124
|
+
return null;
|
|
125
|
+
const contentType = obj.httpMetadata?.contentType;
|
|
126
|
+
return { stream: obj.body, size: obj.size, ...(contentType !== undefined ? { contentType } : {}) };
|
|
127
|
+
},
|
|
125
128
|
delete: async (key) => {
|
|
126
129
|
await r2.delete(key);
|
|
127
130
|
},
|
package/dist/r2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"r2.js","sourceRoot":"","sources":["../src/r2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"r2.js","sourceRoot":"","sources":["../src/r2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GAKd,MAAM,sBAAsB,CAAC;AAoC9B,qFAAqF;AACrF,SAAS,OAAO,CAAC,IAAY,EAAE,GAAG,GAAG,IAAI;IACvC,OAAO,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,kBAAkB,IAAI,CAAC,MAAM,GAAG,GAAG,iBAAiB,CAAC;AAC/G,CAAC;AAQD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAgB,EAChB,QAAgB,EAChB,OAAe;IAEf,MAAM,GAAG,GAAG,QAAQ,QAAQ,IAAI,OAAO,IAAI,QAAQ,EAAE;SAClD,WAAW,EAAE;SACb,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;SAC5B,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,C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CAAC,CAAC;QACvB,CAAC;QACD,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,IAAI,GAAa,EAAE,CAAC;YAC1B,IAAI,MAA0B,CAAC;YAC/B,GAAG,CAAC;gBACF,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gBACtE,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC7C,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;YACpD,CAAC,QAAQ,MAAM,EAAE;YACjB,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/scope-do.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-do.d.ts","sourceRoot":"","sources":["../src/scope-do.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAgEnD,OAAO,
|
|
1
|
+
{"version":3,"file":"scope-do.d.ts","sourceRoot":"","sources":["../src/scope-do.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAgEnD,OAAO,EA2DL,KAAK,mBAAmB,EASxB,KAAK,SAAS,EAsBd,KAAK,kBAAkB,EAEvB,KAAK,gBAAgB,EAmHtB,MAAM,sBAAsB,CAAC;AAoD9B,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAwBL,kBAAkB,EAiFnB,MAAM,sBAAsB,CAAC;AA2B9B;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC;AAoFD,oFAAoF;AACpF,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AA2rB5E;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AAmBtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAOxD;AAED,gHAAgH;AAChH,OAAO,EAAE,kBAAkB,EAAE,CAAC;AA2B9B,wBAAgB,aAAa,CAC3B,OAAO,EAAE,kBAAkB,EAAE,EAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACzD;;;;GAIG;AACH,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,mBAAmB,CAAA;CAAO,GAClD,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,KAAK,aAAa,CAAC,UAAU,CAAC,CA00P7E"}
|
package/dist/scope-do.js
CHANGED
|
@@ -1384,6 +1384,65 @@ options = {}) {
|
|
|
1384
1384
|
async attachmentBytesIfHeld() {
|
|
1385
1385
|
return (await this.holdsScope()) ? this.attachmentBytes() : null;
|
|
1386
1386
|
}
|
|
1387
|
+
/**
|
|
1388
|
+
* #2544: the introspection reads that name only a scope id, each as the held check and the read
|
|
1389
|
+
* in ONE call (as the size reads above are): `null` says the deployment does not hold this scope,
|
|
1390
|
+
* never an empty answer. The read itself is the one the unguarded method makes.
|
|
1391
|
+
*/
|
|
1392
|
+
async ifHeld(read) {
|
|
1393
|
+
return (await this.holdsScope()) ? read() : null;
|
|
1394
|
+
}
|
|
1395
|
+
facetEventsIfHeld(input) {
|
|
1396
|
+
return this.ifHeld(() => this.facetEvents(input));
|
|
1397
|
+
}
|
|
1398
|
+
eventEffectsIfHeld(input) {
|
|
1399
|
+
return this.ifHeld(() => this.eventEffects(input));
|
|
1400
|
+
}
|
|
1401
|
+
invocationEventsIfHeld(input) {
|
|
1402
|
+
return this.ifHeld(() => this.invocationEvents(input));
|
|
1403
|
+
}
|
|
1404
|
+
deadLettersIfHeld(input) {
|
|
1405
|
+
return this.ifHeld(() => this.deadLetters(input));
|
|
1406
|
+
}
|
|
1407
|
+
lifecycleFlowIfHeld(input) {
|
|
1408
|
+
return this.ifHeld(() => this.lifecycleFlow(input));
|
|
1409
|
+
}
|
|
1410
|
+
operationSeriesIfHeld(input) {
|
|
1411
|
+
return this.ifHeld(() => this.operationSeries(input));
|
|
1412
|
+
}
|
|
1413
|
+
eventCauseIfHeld(input) {
|
|
1414
|
+
return this.ifHeld(() => this.eventCause(input));
|
|
1415
|
+
}
|
|
1416
|
+
entityHistoryIfHeld(input) {
|
|
1417
|
+
return this.ifHeld(() => this.entityHistory(input));
|
|
1418
|
+
}
|
|
1419
|
+
appliedMigrationsIfHeld() {
|
|
1420
|
+
return this.ifHeld(() => this.appliedMigrations());
|
|
1421
|
+
}
|
|
1422
|
+
migrationBookmarksIfHeld() {
|
|
1423
|
+
return this.ifHeld(() => this.migrationBookmarks());
|
|
1424
|
+
}
|
|
1425
|
+
introspectTablesIfHeld() {
|
|
1426
|
+
return this.ifHeld(() => this.introspectTables());
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* #2563: the table page and the SQL console, each as the held check and the read in ONE call.
|
|
1430
|
+
* They answer as a `DoReply` (a refusal keeps its code across the hop, #113), `null` outside it
|
|
1431
|
+
* for a scope the deployment does not hold. The carry's reader of a wiped copy's tombstone does
|
|
1432
|
+
* not come through here: that copy is not held, by design, and it asks `introspectTableReply`.
|
|
1433
|
+
*/
|
|
1434
|
+
introspectTableIfHeld(table, limit, offset) {
|
|
1435
|
+
return this.ifHeld(() => this.introspectTableReply(table, limit, offset));
|
|
1436
|
+
}
|
|
1437
|
+
introspectQueryIfHeld(sql) {
|
|
1438
|
+
return this.ifHeld(() => this.introspectQueryReply(sql));
|
|
1439
|
+
}
|
|
1440
|
+
undrainedEventsReadIfHeld(limit) {
|
|
1441
|
+
return this.ifHeld(() => this.undrainedEventsRead(limit));
|
|
1442
|
+
}
|
|
1443
|
+
redrainCountIfHeld(drainedBefore) {
|
|
1444
|
+
return this.ifHeld(() => this.redrainCount(drainedBefore));
|
|
1445
|
+
}
|
|
1387
1446
|
/**
|
|
1388
1447
|
* #2541: whether this object is a scope the deployment holds, asked by a read that names only a
|
|
1389
1448
|
* scope id. False for a DO nothing provisioned or loaded here (never provisioned), for a reaped
|
|
@@ -3803,14 +3862,18 @@ options = {}) {
|
|
|
3803
3862
|
async roleStateHere(tenantId) {
|
|
3804
3863
|
// Spine tables only (built in the constructor), so no module migration runs ahead of a provision's.
|
|
3805
3864
|
const now = new Date().toISOString();
|
|
3806
|
-
const
|
|
3807
|
-
? this.sql.exec('SELECT role_key, permissions, holder FROM _substrat_roles WHERE tenant_id = ?
|
|
3865
|
+
const rows = this.hasTable('_substrat_roles')
|
|
3866
|
+
? this.sql.exec('SELECT role_key, permissions, holder, revoked_at FROM _substrat_roles WHERE tenant_id = ?', tenantId).toArray()
|
|
3808
3867
|
: [];
|
|
3868
|
+
const shapeOf = (r) => ({ key: r.role_key, permissions: JSON.parse(r.permissions), ...(r.holder ? { holder: r.holder } : {}) });
|
|
3869
|
+
const roles = rows.filter((r) => r.revoked_at === null).map(shapeOf);
|
|
3870
|
+
// #2531: the tombstones `applyProjection` leaves for the roles a projection dropped.
|
|
3871
|
+
const dropped = rows.filter((r) => r.revoked_at !== null).map(shapeOf);
|
|
3809
3872
|
// Scope-level seats only. The tenant-level ones are the directory's (the ControlPlaneDO reads
|
|
3810
3873
|
// them in its own unit), and this scope's projected copy can be stale: a fan-out skips an
|
|
3811
3874
|
// archived scope, and a CP-less projection carries none.
|
|
3812
3875
|
const seated = new Set(this.sql.exec(SCOPE_SEATED_ROLES_SQL, now).toArray().map((r) => r.role_key));
|
|
3813
|
-
return { roles, seated: [...seated] };
|
|
3876
|
+
return { roles, seated: [...seated], dropped };
|
|
3814
3877
|
}
|
|
3815
3878
|
/** #2447: what this class's modules reserve and declare — a coordinator judging a role definition joins its own. */
|
|
3816
3879
|
async reservationHere() {
|
|
@@ -5092,10 +5155,16 @@ options = {}) {
|
|
|
5092
5155
|
const names = this.sql
|
|
5093
5156
|
.exec(`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT GLOB '_cf_*' ORDER BY name`)
|
|
5094
5157
|
.toArray().map((r) => r.name);
|
|
5158
|
+
const count = (sql) => Number(this.sql.exec(sql).toArray()[0].c);
|
|
5095
5159
|
return names.map((name) => ({
|
|
5096
5160
|
name,
|
|
5097
|
-
rowCount:
|
|
5161
|
+
rowCount: count(`SELECT COUNT(*) AS c FROM "${name}"`),
|
|
5098
5162
|
system: isSystemTable(name),
|
|
5163
|
+
// #2531: rows whose `revoked_at` is null, for any table with that column (`ScopeTable.liveRowCount`).
|
|
5164
|
+
// Scope health reads it for `_substrat_roles`, where a dropped role is kept revoked.
|
|
5165
|
+
...(doBuiltColumnsOf(this.sql, name)?.includes('revoked_at')
|
|
5166
|
+
? { liveRowCount: count(`SELECT COUNT(*) AS c FROM "${name}" WHERE revoked_at IS NULL`) }
|
|
5167
|
+
: {}),
|
|
5099
5168
|
}));
|
|
5100
5169
|
}
|
|
5101
5170
|
/** A bounded page of one table. Unknown table names throw — never queried blind. Kept for a
|
|
@@ -7030,7 +7099,13 @@ options = {}) {
|
|
|
7030
7099
|
}
|
|
7031
7100
|
// Written before any guard below can return early, so every projection leaves it.
|
|
7032
7101
|
this.sql.exec(`INSERT OR REPLACE INTO _substrat_meta (key, value) VALUES (?, ?)`, PROVISIONED_FOR_KEY, tenantId);
|
|
7033
|
-
|
|
7102
|
+
// #2531: a role the new set leaves out is TOMBSTONED, not deleted: it keeps the keys and the
|
|
7103
|
+
// holder it had, and grants nothing (every reader skips a revoked row). Kept for good, as
|
|
7104
|
+
// evidence (K-21): the reserved-key rule reads a system-held tombstone as the stored
|
|
7105
|
+
// definition it was, so a release that drops a role and a later one that adds it back
|
|
7106
|
+
// are judged as one that kept it. A row already tombstoned keeps its first `revoked_at`;
|
|
7107
|
+
// a role the set names is written live again below, which clears it.
|
|
7108
|
+
this.sql.exec(`UPDATE _substrat_roles SET revoked_at = ? WHERE tenant_id = ? AND revoked_at IS NULL`, new Date().toISOString(), tenantId);
|
|
7034
7109
|
for (const r of roles) {
|
|
7035
7110
|
this.sql.exec(`INSERT OR REPLACE INTO _substrat_roles (tenant_id, role_key, permissions, source, holder, revoked_at)
|
|
7036
7111
|
VALUES (?, ?, ?, ?, ?, NULL)`, tenantId, r.role_key, r.permissions, r.source, r.holder === 'system' ? 'system' : r.holder == null ? null : 'person');
|