@substrat-run/adapter-cloudflare 0.229.0 → 0.231.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/broker-lake.d.ts +27 -2
- package/dist/broker-lake.d.ts.map +1 -1
- package/dist/broker-lake.js +57 -3
- package/dist/broker-lake.js.map +1 -1
- package/dist/control-plane-do.d.ts +57 -18
- package/dist/control-plane-do.d.ts.map +1 -1
- package/dist/control-plane-do.js +154 -70
- package/dist/control-plane-do.js.map +1 -1
- package/dist/delivery-broker-do.d.ts +13 -1
- package/dist/delivery-broker-do.d.ts.map +1 -1
- package/dist/delivery-broker-do.js +43 -3
- package/dist/delivery-broker-do.js.map +1 -1
- package/dist/directory-cutover.d.ts +93 -1
- package/dist/directory-cutover.d.ts.map +1 -1
- package/dist/directory-cutover.js +91 -2
- package/dist/directory-cutover.js.map +1 -1
- package/dist/directory-objects.d.ts +12 -0
- package/dist/directory-objects.d.ts.map +1 -1
- package/dist/directory-objects.js +8 -1
- package/dist/directory-objects.js.map +1 -1
- package/dist/directory-placement.d.ts.map +1 -1
- package/dist/directory-placement.js +1 -0
- package/dist/directory-placement.js.map +1 -1
- package/dist/directory-tenant-connect-links.d.ts +40 -0
- package/dist/directory-tenant-connect-links.d.ts.map +1 -0
- package/dist/directory-tenant-connect-links.js +48 -0
- package/dist/directory-tenant-connect-links.js.map +1 -0
- package/dist/directory-tenant-identities.d.ts +30 -0
- package/dist/directory-tenant-identities.d.ts.map +1 -0
- package/dist/directory-tenant-identities.js +64 -0
- package/dist/directory-tenant-identities.js.map +1 -0
- package/dist/directory-tenant-tuples.d.ts +69 -3
- package/dist/directory-tenant-tuples.d.ts.map +1 -1
- package/dist/directory-tenant-tuples.js +52 -0
- package/dist/directory-tenant-tuples.js.map +1 -1
- package/dist/host.d.ts +27 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +81 -9
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/peer-call-target.d.ts +16 -2
- package/dist/peer-call-target.d.ts.map +1 -1
- package/dist/peer-call-target.js +36 -6
- package/dist/peer-call-target.js.map +1 -1
- package/dist/route-read-model-publisher.d.ts.map +1 -1
- package/dist/route-read-model-publisher.js +4 -0
- package/dist/route-read-model-publisher.js.map +1 -1
- package/dist/route-resolver.d.ts +19 -2
- package/dist/route-resolver.d.ts.map +1 -1
- package/dist/route-resolver.js +25 -5
- package/dist/route-resolver.js.map +1 -1
- package/dist/scope-do.d.ts +19 -0
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +294 -8
- package/dist/scope-do.js.map +1 -1
- package/dist/scope-facets.d.ts +121 -0
- package/dist/scope-facets.d.ts.map +1 -0
- package/dist/scope-facets.js +98 -0
- package/dist/scope-facets.js.map +1 -0
- package/dist/scope-supervisor-do.d.ts +112 -0
- package/dist/scope-supervisor-do.d.ts.map +1 -0
- package/dist/scope-supervisor-do.js +529 -0
- package/dist/scope-supervisor-do.js.map +1 -0
- package/dist/scope-work.d.ts +1 -1
- package/dist/scope-work.js +1 -1
- package/dist/scope-work.js.map +1 -1
- package/dist/supplied-pass-box.d.ts +77 -0
- package/dist/supplied-pass-box.d.ts.map +1 -0
- package/dist/supplied-pass-box.js +265 -0
- package/dist/supplied-pass-box.js.map +1 -0
- package/dist/tenant-due-index-do.d.ts +76 -0
- package/dist/tenant-due-index-do.d.ts.map +1 -0
- package/dist/tenant-due-index-do.js +90 -0
- package/dist/tenant-due-index-do.js.map +1 -0
- package/dist/tenant-due-nudge.d.ts +67 -0
- package/dist/tenant-due-nudge.d.ts.map +1 -0
- package/dist/tenant-due-nudge.js +77 -0
- package/dist/tenant-due-nudge.js.map +1 -0
- package/dist/tenant-due-work-do.d.ts +53 -0
- package/dist/tenant-due-work-do.d.ts.map +1 -1
- package/dist/tenant-due-work-do.js +204 -5
- package/dist/tenant-due-work-do.js.map +1 -1
- package/package.json +12 -12
package/dist/control-plane-do.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tenantDueWorkName } from './tenant-due-work-do.js';
|
|
2
2
|
import { DurableObject } from 'cloudflare:workers';
|
|
3
|
-
import { membershipFencesBackfillSql, MEMBERSHIP_FENCES_DDL, MEMBERSHIP_FENCES_TABLE, membershipFencesTableExists, IMPERSONATION_COLUMNS, IMPERSONATION_DDL, impersonationByIdQuery, impersonationListQuery, impersonationRowValues, ISSUE_RETENTION_DAYS, telemetryRetentionStatements, FINDINGS_DDL, SCOPE_STORAGE_DDL, forgetScopeStorage, retireScopeStorage, listScopeStorageAttemptRows, listScopeStorageRows, listScopeAttachmentStorageRows, listScopeStoreStorageRows, pruneScopeStorageRows, recordScopeStorageRows, readBoundedTenantStorageGauge, REQUEST_ROLLUP_DDL, listRequestDayRows, listRequestRollupDayRows, pruneRequestDayRows, recordRequestDayRows, readTenantRequestMeterRows, readRequestMeterDayRows, COST_ROLLUP_DDL, listCostDayRows, listCostRollupDayRows, sumCostDayRows, pruneCostDayRows, recordCostDayRows, recordCostContainerRows, recordScopeObjectRow, scopeObjectsDueRows, METER_DAYS_DDL, STALE_SCOPES_DDL, listStaleScopeRows, listStaleScopeTakeRows, recordStaleScopeRows, VERTICAL_OWNERS_BACKFILL, VERTICAL_OWNERS_DDL, closeVerticalOwnerRow, listVerticalOwnerRows, openVerticalOwnerRow, verticalOwnerNow, listMeterDayRows, listMeterDayTakeRows, pruneMeterDayRows, recordMeterDayRows, DIRECTORY_LAKE_DDL, ackDirectoryOutbox, ensureDirectoryLakeTriggers, advanceDirectoryLakeBackfill, pruneDirectoryLakeWindow, readDirectoryLakeBackfill, readDirectoryLakeCapture, readDirectoryOutbox, setDirectoryLakeCapture, CONNECT_LINKS_DDL,
|
|
3
|
+
import { membershipFencesBackfillSql, MEMBERSHIP_FENCES_DDL, MEMBERSHIP_FENCES_TABLE, membershipFencesTableExists, IMPERSONATION_COLUMNS, IMPERSONATION_DDL, impersonationByIdQuery, impersonationListQuery, impersonationRowValues, ISSUE_RETENTION_DAYS, telemetryRetentionStatements, FINDINGS_DDL, SCOPE_STORAGE_DDL, forgetScopeStorage, retireScopeStorage, listScopeStorageAttemptRows, listScopeStorageRows, listScopeAttachmentStorageRows, listScopeStoreStorageRows, pruneScopeStorageRows, recordScopeStorageRows, readBoundedTenantStorageGauge, REQUEST_ROLLUP_DDL, listRequestDayRows, listRequestRollupDayRows, pruneRequestDayRows, recordRequestDayRows, readTenantRequestMeterRows, readRequestMeterDayRows, COST_ROLLUP_DDL, listCostDayRows, listCostRollupDayRows, sumCostDayRows, pruneCostDayRows, recordCostDayRows, recordCostContainerRows, recordScopeObjectRow, scopeObjectsDueRows, METER_DAYS_DDL, STALE_SCOPES_DDL, listStaleScopeRows, listStaleScopeTakeRows, recordStaleScopeRows, VERTICAL_OWNERS_BACKFILL, VERTICAL_OWNERS_DDL, closeVerticalOwnerRow, listVerticalOwnerRows, openVerticalOwnerRow, verticalOwnerNow, listMeterDayRows, listMeterDayTakeRows, pruneMeterDayRows, recordMeterDayRows, DIRECTORY_LAKE_DDL, ackDirectoryOutbox, ensureDirectoryLakeTriggers, advanceDirectoryLakeBackfill, pruneDirectoryLakeWindow, readDirectoryLakeBackfill, readDirectoryLakeCapture, readDirectoryOutbox, setDirectoryLakeCapture, CONNECT_LINKS_DDL, createFindingRule, findingOfOpsFailure, findingOfSweepRun, pruneFindings, listFindingRules, listFindings, observeFinding, revokeFindingRule, setFindingStatus, assertRowLimit, OPS_FAILURE_RETENTION_DAYS, SWEEP_RUN_RETENTION_DAYS, SWEEP_RUNS_INTENT_INDEX, sweepRunsIntentHasKind, CONNECTIONS_LIVE_INDEX, connectionsLiveIndexHasOwner, PEER_SWITCHES_DDL, PEER_BINDINGS_DDL, APP_ENVIRONMENTS_DDL, claimEnvironmentServeIn, defineEnvironmentIn, ENVIRONMENT_SCRIPT_JOIN_SQL, environmentPeerResolutionIn, environmentsOf, HOME_SCOPE_TYPE, homeScopeIn, secondHomeRefusal, releaseEnvironmentServeIn, removeEnvironmentIn, setEnvironmentServingIn, environmentBindRefusalIn, setEnvironmentEffectsIn, connectionReachIn, SWITCH_OWED_DDL, DEPENDENT_ERASURES_DDL, DEPENDENT_ERASURE_DUE_SQL, DEPENDENT_ERASURE_HOLD_SQL, DEPENDENT_ERASURE_OWE_SQL, DEPENDENT_ERASURE_SETTLE_SQL, nextDependentErasureAt, clearSwitchOwed, markSwitchOwed, scopeOwesSwitch, switchesOwedOf, SWITCH_KINDS, SYSTEM_SWITCHES_DDL, forgetSwitchesOf, listSystemSwitchRecords, recordSwitchedOff, recordSwitchedOn, recordWriteSuperseded, restoreSwitchRecord, scopesSwitchedOffFor, switchRecordStatesOf, switchRecordsOf, switchesBackfillSqlOf, switchesDdlOf, switchesTableExists, switchesTableOf, tenantHeldOf, VERSION_MIGRATIONS_DDL, VERTICAL_SCOPE_STORES_DDL, DEPLOYMENT_WIRE_AUTH_DDL, deploymentWireAuthOf, forgetVerticalWireAuth, writeDeploymentWireAuth, STORE_DRIVER_RELEASES_DDL, approveStoreDriverReleaseIn, legacyStoreDriverConflict, legacyStoreDriverRenames, beginStoreDriverRolloutIn, finishStoreDriverRolloutIn, holdStoreDriverIn, advanceStoreDriverRebuildIn, claimStoreDriverRebuildIn, storeDriverRebuildIn, driverDeclarationsOf, recordStoreDriverReleaseIn, recordStoreDriverRevokeWalkIn, releaseStoreDriverHoldIn, revokeStoreDriverReleaseIn, liveStoreDriverApprovalIn, storeDriverApprovalsIn, storeDriverRevokeWalkIn, storeDriverReleaseIn, storeDriverStateIn, storeDriverRolloutPendingIn, storeDriverRolloutWalkedIn, forgetVerticalScopeStores, indexVersionScopeStores, verticalScopeStoresOf, splitVersionMigrationsBatch, versionMigrationsOf, versionMigrationsExtractedOf, recordVersionMigrationsExtracted, versionsAwaitSplit, versionsAwaitDigest, deriveMigrationDigestsBatch, deriveVersionMigrationDigest, writeVersionMigrations, MODEL_USAGE_RETENTION_DAYS, BUILD_USAGE_RETENTION_DAYS, DO_SQL_LIMITS, ulid, isPrimaryScopeRow, samePeerVertical, peerVerticalSpellings, resolveVerticalInstanceFrom, resolvePeerInstanceFrom, LEGACY_SCOPE_ROWS_BACKFILL, loadDirectoryDump, storesFencedRefusal, redactSubjectDirectoryText, ISSUE_EXEMPLAR_OWNER_BACKFILL_SQL, issueExemplarOwner, SETTLE_INTENT_SQL, SETTLE_OUTCOME_SQL, settleOutcomeParamsOf, unknownOutcomeOf, ADMIN_LOG_INDEX_DDL, ADMIN_LOG_INDEXES_SQL, readAuditedOperations, } from '@substrat-run/kernel';
|
|
4
4
|
import { MARKUP_INSERT_SQL, MARKUP_SELECT_FOR_TENANT_SQL, MARKUP_SELECT_SQL, } from '@substrat-run/kernel';
|
|
5
5
|
import { replyOf } from './do-reply.js';
|
|
6
6
|
import { rowBytes, switchSqlOver } from './scope-do.js';
|
|
@@ -18,16 +18,22 @@ import { durableMirrorSender } from './directory-objects.js';
|
|
|
18
18
|
import { directoryBackfillFor } from './directory-mirror-backfill.js';
|
|
19
19
|
import { directoryVerifyFor } from './directory-mirror-verify.js';
|
|
20
20
|
// K-68 step 3e: a tenant's role definitions read from, and first written to, its own object (off by default).
|
|
21
|
-
import { cutoverLive, directoryCutoverFor } from './directory-cutover.js';
|
|
21
|
+
import { cutoverFlagsPage, cutoverLive, cutoverParityPage, directoryCutoverFor, PARITY_PAGE_MAX } from './directory-cutover.js';
|
|
22
22
|
// K-68 step 3e, the second family: a tenant's tuples and removal fences (directory-tenant-tuples.ts).
|
|
23
23
|
import { applyMembershipIn, assignTenantRoleIn, dumpTenantTupleRows, listMemberRows, revokeAndFenceIn, revokeTenantTupleIn, TENANT_TUPLES, tenantTupleRows, writeTenantTupleIn, } from './directory-tenant-tuples.js';
|
|
24
24
|
// K-68 step 3e, the third family: a tenant's organizations (directory-tenant-orgs.ts).
|
|
25
25
|
import { createOrgIn, listOrgRows, ORGS, readOrgRow } from './directory-tenant-orgs.js';
|
|
26
26
|
// K-68 step 3e, the fourth family: a tenant's entitlements (directory-tenant-entitlements.ts).
|
|
27
27
|
import { ENTITLEMENTS, entitlementAuditOf, grantEntitlementIn, holdsEntitlement, listEntitlementRows, revokeEntitlementIn, } from './directory-tenant-entitlements.js';
|
|
28
|
-
|
|
28
|
+
// K-68 step 3e, the fifth family: a tenant's identity links (directory-tenant-identities.ts).
|
|
29
|
+
import { dumpIdentityRows, IDENTITIES, linkIdentityIn, resolveIdentityIn, unlinkIdentityIn } from './directory-tenant-identities.js';
|
|
30
|
+
// K-68 step 3e, the sixth family: a tenant's connect links (directory-tenant-connect-links.ts).
|
|
31
|
+
import { CONNECT_LINKS, consumeConnectLinkIn, listConnectLinksIn, mintConnectLinkIn, readConnectLinkIn, restoreConnectLinkIn, revokeConnectLinkIn, } from './directory-tenant-connect-links.js';
|
|
32
|
+
/** A cut-over unit's result that does not carry the answer its op asks for. */
|
|
33
|
+
const NOT_ANSWERED = Symbol('not answered');
|
|
34
|
+
import { durableCutoverSender, registryStub } from './directory-objects.js';
|
|
29
35
|
import { defineRoleRow, listRoleRows, readRole } from './directory-tenant-roles.js';
|
|
30
|
-
import { assertReplayableDump, AUTO_ADMISSION_NOTE, instant, isRuntimeTable, opsFailureFingerprint, ROUTE_SCOPE_HOSTNAMES_MAX, SCOPE_DUMP_PAGE_MAX_BYTES, SCOPE_GATE_REASONS, substratError } from '@substrat-run/contracts';
|
|
36
|
+
import { admittedBundleAudit, assertReplayableDump, AUTO_ADMISSION_NOTE, instant, isRuntimeTable, opsFailureFingerprint, ROUTE_SCOPE_HOSTNAMES_MAX, SCOPE_DUMP_PAGE_MAX_BYTES, SCOPE_GATE_REASONS, substratError } from '@substrat-run/contracts';
|
|
31
37
|
/**
|
|
32
38
|
* The router's per-request directory read (`readRoute`), lifted out so its plan can be asked for
|
|
33
39
|
* (#2005): the scope's hostname set is a correlated subquery on the hot path every request takes,
|
|
@@ -363,6 +369,8 @@ const DIRECTORY_DDL = `
|
|
|
363
369
|
migration_digest_derived INTEGER,
|
|
364
370
|
-- #2351: the digest of the migrations read from the version's bundle. NULL = never read.
|
|
365
371
|
migrations_extracted TEXT,
|
|
372
|
+
-- #3612: the sha256 the control plane took of the module bytes it stored. NULL = pushed before.
|
|
373
|
+
bundle_digest TEXT,
|
|
366
374
|
created_at TEXT NOT NULL,
|
|
367
375
|
UNIQUE (vertical_slug, version)
|
|
368
376
|
);
|
|
@@ -1258,6 +1266,32 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1258
1266
|
await this.directoryCutover.retry();
|
|
1259
1267
|
return this.directoryCutover.status();
|
|
1260
1268
|
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Whether the registry's record of each tenant's flag agrees with this directory's, which is the one
|
|
1271
|
+
* acted on in 3e (`directory-cutover.ts`, `cutoverParityOf`): a page of tenants in id order after
|
|
1272
|
+
* `after`, the drift among them, and where the next page starts. Staff only, and only when asked: it
|
|
1273
|
+
* runs on no alarm, writes nothing on either side, and changes no dispatch, so a disagreement is
|
|
1274
|
+
* reported here and nowhere acted on. Works whatever `DIRECTORY_CUTOVER` says, since a flag flipped
|
|
1275
|
+
* off stays on record; refused only where the registry is not bound.
|
|
1276
|
+
*/
|
|
1277
|
+
async directoryCutoverParity(query = {}) {
|
|
1278
|
+
const registry = Reflect.get(this.env, 'DIRECTORY_REGISTRY');
|
|
1279
|
+
if (!registry || typeof Reflect.get(registry, 'idFromName') !== 'function')
|
|
1280
|
+
return { enabled: false, reason: 'DIRECTORY_REGISTRY is not bound' };
|
|
1281
|
+
const limit = Math.max(1, Math.min(Math.trunc(query.limit ?? 100) || 100, PARITY_PAGE_MAX));
|
|
1282
|
+
const after = query.after ?? '';
|
|
1283
|
+
const flags = cutoverFlagsPage(this.sql, after, limit);
|
|
1284
|
+
// The same range on both sides: up to this page's last flag, or to the end when the page is the last.
|
|
1285
|
+
const upTo = flags.length === limit ? flags.at(-1).tenantId : null;
|
|
1286
|
+
const { records, truncated } = await registryStub(registry).tenantCutoversIn({ after, upTo, limit });
|
|
1287
|
+
if (truncated) {
|
|
1288
|
+
// The registry holds more in the range than one read carries: the page ends at its last record, so
|
|
1289
|
+
// no flag past it is judged against a record not read.
|
|
1290
|
+
const boundary = records.at(-1).tenantId;
|
|
1291
|
+
return cutoverParityPage(flags.filter((f) => f.tenantId <= boundary), records, boundary, true);
|
|
1292
|
+
}
|
|
1293
|
+
return cutoverParityPage(flags, records, upTo, false);
|
|
1294
|
+
}
|
|
1261
1295
|
// -- the routing read model (#3395) -------------------------------------------
|
|
1262
1296
|
/** Set where a `ROUTES` KV namespace is bound; null otherwise, and the read model is off. */
|
|
1263
1297
|
routePublisher = null;
|
|
@@ -1863,6 +1897,8 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1863
1897
|
this.addColumn('vertical_versions', 'migration_digest_derived INTEGER');
|
|
1864
1898
|
// #2351: the digest of the migrations read from the bundle; NULL = never read.
|
|
1865
1899
|
this.addColumn('vertical_versions', 'migrations_extracted TEXT');
|
|
1900
|
+
// #3612: the sha256 the control plane took of the module bytes; NULL = pushed before.
|
|
1901
|
+
this.addColumn('vertical_versions', 'bundle_digest TEXT');
|
|
1866
1902
|
// #33: the SKU flag learns to express a plan. All nullable — a legacy row
|
|
1867
1903
|
// reads as a perpetual boolean flag, exactly its pre-widening semantics.
|
|
1868
1904
|
this.addColumn('_substrat_entitlements', 'expires_at TEXT');
|
|
@@ -3292,6 +3328,10 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
3292
3328
|
entitlementsCutOver(tenantId) {
|
|
3293
3329
|
return this.directoryCutover?.cutOverFor(tenantId, ENTITLEMENTS) ?? false;
|
|
3294
3330
|
}
|
|
3331
|
+
/** Whether the tenant's identity links are read from, and first written to, its own object (the fifth family). */
|
|
3332
|
+
identitiesCutOver(tenantId) {
|
|
3333
|
+
return this.directoryCutover?.cutOverFor(tenantId, IDENTITIES) ?? false;
|
|
3334
|
+
}
|
|
3295
3335
|
/** This directory as a `TupleStore`: its rows, its admin log, its orgs. */
|
|
3296
3336
|
tupleStore() {
|
|
3297
3337
|
return {
|
|
@@ -3462,8 +3502,12 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
3462
3502
|
}
|
|
3463
3503
|
/** Binding is read at call execution, so a queued invoke follows the current explicit choice. */
|
|
3464
3504
|
resolvePeerInstance(tenantId, callerScopeId, vertical) {
|
|
3465
|
-
const binding = this.peerBinding(tenantId, callerScopeId, vertical);
|
|
3466
3505
|
const tenant = this.peerTenant(tenantId);
|
|
3506
|
+
// D-83 (#3530 step 5): a caller that is not an install is answered per environment.
|
|
3507
|
+
const perEnvironment = environmentPeerResolutionIn(this.kernelSql, tenant, callerScopeId, vertical);
|
|
3508
|
+
if (perEnvironment)
|
|
3509
|
+
return perEnvironment;
|
|
3510
|
+
const binding = this.peerBinding(tenantId, callerScopeId, vertical);
|
|
3467
3511
|
return resolvePeerInstanceFrom(this.peerCandidates(tenant, vertical), tenant, vertical, binding?.target_scope_id ?? null, binding?.invalidated === 1);
|
|
3468
3512
|
}
|
|
3469
3513
|
peerBinding(tenantId, callerScopeId, vertical) {
|
|
@@ -3598,9 +3642,14 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
3598
3642
|
* `publish` (#3395, K-72) is the router's read-model miss: a dispatchable answer is queued for
|
|
3599
3643
|
* publishing unless it is published already. A directory that predates it ignores the argument.
|
|
3600
3644
|
* The answer is the same either way.
|
|
3645
|
+
*
|
|
3646
|
+
* `environments` (D-83, #3530 step 5) is a router that dispatches a named environment's pair as a
|
|
3647
|
+
* scope that is no install: only it is answered with the pair (`readPeerCallTarget`).
|
|
3601
3648
|
*/
|
|
3602
3649
|
peerCallTarget(tenantId, callerScopeId, callerVertical, vertical, opts) {
|
|
3603
|
-
const read = readPeerCallTarget(this.sql, tenantId, callerScopeId, callerVertical, vertical
|
|
3650
|
+
const read = readPeerCallTarget(this.sql, tenantId, callerScopeId, callerVertical, vertical, {
|
|
3651
|
+
environments: opts?.environments === true,
|
|
3652
|
+
});
|
|
3604
3653
|
if (opts?.publish === true && this.routePublisher) {
|
|
3605
3654
|
// Optional, as `readRoute`'s: a fill that cannot be queued must not fail a read that succeeded.
|
|
3606
3655
|
// This method's own return starts the flush (`kickRouteReadModelAfterEveryCall`).
|
|
@@ -3981,8 +4030,8 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
3981
4030
|
this.sql.exec(`INSERT INTO vertical_versions
|
|
3982
4031
|
(id, vertical_slug, version, manifest_digest, permission_digest,
|
|
3983
4032
|
migration_digest, deployment_ref, admission, admission_note, manifest_json,
|
|
3984
|
-
origin_json, migration_count, migrations_split, migration_digest_derived, created_at)
|
|
3985
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, 1, ?)`, v.id, v.verticalSlug, v.version, v.manifestDigest, v.permissionDigest, v.migrationDigest, v.deploymentRef, admission, selfAdmits ? AUTO_ADMISSION_NOTE : null, v.manifestJson, v.originJson, v.migrations?.length ?? null, v.createdAt);
|
|
4033
|
+
origin_json, migration_count, migrations_split, migration_digest_derived, bundle_digest, created_at)
|
|
4034
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, 1, ?, ?)`, v.id, v.verticalSlug, v.version, v.manifestDigest, v.permissionDigest, v.migrationDigest, v.deploymentRef, admission, selfAdmits ? AUTO_ADMISSION_NOTE : null, v.manifestJson, v.originJson, v.migrations?.length ?? null, v.bundleDigest ?? null, v.createdAt);
|
|
3986
4035
|
writeVersionMigrations(this.kernelSql, v.id, v.migrations);
|
|
3987
4036
|
// #2286: the version's scope-store bindings, refusing one moved to another driver, in the insert's transaction.
|
|
3988
4037
|
indexVersionScopeStores(this.kernelSql, v.verticalSlug, v.id, v.manifestJson);
|
|
@@ -4118,7 +4167,7 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
4118
4167
|
// failing the whole page on `->`.
|
|
4119
4168
|
const read = () => this.sql
|
|
4120
4169
|
.exec(`SELECT id, vertical_slug, version, manifest_digest, permission_digest, migration_digest,
|
|
4121
|
-
migration_digest_derived, deployment_ref, admission, admission_note, origin_json, created_at,
|
|
4170
|
+
migration_digest_derived, deployment_ref, admission, admission_note, origin_json, bundle_digest, created_at,
|
|
4122
4171
|
CASE WHEN json_valid(manifest_json) THEN manifest_json -> '$.outbound' END AS outbound_json,
|
|
4123
4172
|
CASE WHEN json_valid(manifest_json) THEN manifest_json -> '$.calls' END AS calls_json
|
|
4124
4173
|
FROM vertical_versions WHERE ${where.join(' AND ')}${tail}`, ...params)
|
|
@@ -4148,13 +4197,13 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
4148
4197
|
if (v.admission === 'admitted') {
|
|
4149
4198
|
if (v.admission_note !== AUTO_ADMISSION_NOTE)
|
|
4150
4199
|
return false;
|
|
4151
|
-
row = { before: { admission: v.admission, note: v.admission_note }, after: { admission: 'admitted', note: null } };
|
|
4200
|
+
row = { before: { admission: v.admission, note: v.admission_note }, after: { admission: 'admitted', note: null, ...admittedBundleAudit(id, v.bundle_digest) } };
|
|
4152
4201
|
}
|
|
4153
4202
|
else if (v.admission === 'rejected') {
|
|
4154
4203
|
throw substratError('conflict', `version ${id} was rejected — publish a new one`);
|
|
4155
4204
|
}
|
|
4156
4205
|
else {
|
|
4157
|
-
row = { before: { admission: v.admission }, after: { admission: 'admitted' } };
|
|
4206
|
+
row = { before: { admission: v.admission }, after: { admission: 'admitted', ...admittedBundleAudit(id, v.bundle_digest) } };
|
|
4158
4207
|
}
|
|
4159
4208
|
return this.sql.exec("UPDATE vertical_versions SET admission = 'admitted', admission_note = NULL WHERE id = ?", id)
|
|
4160
4209
|
.rowsWritten > 0;
|
|
@@ -4175,7 +4224,7 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
4175
4224
|
}, audit && (() => ({ ...audit, before, after: { admission: 'rejected', note } })));
|
|
4176
4225
|
}
|
|
4177
4226
|
versionAdmission(id) {
|
|
4178
|
-
const v = this.sql.exec('SELECT admission, admission_note FROM vertical_versions WHERE id = ?', id)
|
|
4227
|
+
const v = this.sql.exec('SELECT admission, admission_note, bundle_digest FROM vertical_versions WHERE id = ?', id)
|
|
4179
4228
|
.toArray()[0];
|
|
4180
4229
|
if (!v)
|
|
4181
4230
|
throw substratError('not_found', `unknown version ${id}`);
|
|
@@ -5221,40 +5270,68 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
5221
5270
|
}, audit);
|
|
5222
5271
|
}
|
|
5223
5272
|
// -- a vertical's mailed connect links (connections.md §3.5.4) ------------------
|
|
5224
|
-
// The kernel's statements (`connect-links.ts`), shared with the pure adapter
|
|
5225
|
-
// runs inside this single-threaded object with no await
|
|
5226
|
-
// write, which is what makes consume's single-use hold across racing
|
|
5227
|
-
// the UPDATE's own WHERE holds it again regardless. `now` is the coordinator's. A
|
|
5228
|
-
// and the audit row it hands back commit in one unit: `audit` is the row the host
|
|
5229
|
-
//
|
|
5273
|
+
// The kernel's statements (`connect-links.ts`), shared with the pure adapter, run through the units
|
|
5274
|
+
// in `directory-tenant-connect-links.ts`. Each runs inside this single-threaded object with no await
|
|
5275
|
+
// between its read and its write, which is what makes consume's single-use hold across racing
|
|
5276
|
+
// callbacks here; the UPDATE's own WHERE holds it again regardless. `now` is the coordinator's. A
|
|
5277
|
+
// move and the audit row it hands back commit in one unit: `audit` is the row the host minted
|
|
5278
|
+
// (actor, attribution), completed from what the move changed.
|
|
5279
|
+
//
|
|
5280
|
+
// K-68 step 3e (the sixth family): a tenant whose flip froze its connect links in reads them from,
|
|
5281
|
+
// and mints, revokes, spends and restores them first in, its own object, with the same units. Each
|
|
5282
|
+
// unit is one synchronous transaction there too, so single-use holds in the object as it does here.
|
|
5283
|
+
/** Whether the tenant's connect links are read from, and first written to, its own object (the sixth family). */
|
|
5284
|
+
connectLinksCutOver(tenantId) {
|
|
5285
|
+
return this.directoryCutover?.cutOverFor(tenantId, CONNECT_LINKS) ?? false;
|
|
5286
|
+
}
|
|
5287
|
+
/** A cut-over unit's answer, or a throw when the object predates this family (it wrote nothing). */
|
|
5288
|
+
connectLinkFirst(tenantId, op, pick) {
|
|
5289
|
+
return this.directoryCutover.tupleWrite(tenantId, op).then((r) => {
|
|
5290
|
+
const answer = r ? pick(r) : NOT_ANSWERED;
|
|
5291
|
+
if (answer === NOT_ANSWERED)
|
|
5292
|
+
throw new Error(`tenant object did not run ${op.kind} for ${tenantId}: it predates the connect-link cut-over`);
|
|
5293
|
+
return answer;
|
|
5294
|
+
});
|
|
5295
|
+
}
|
|
5230
5296
|
insertConnectLink(row, audit) {
|
|
5231
|
-
|
|
5297
|
+
if (this.connectLinksCutOver(row.tenantId)) {
|
|
5298
|
+
return this.connectLinkFirst(row.tenantId, { kind: 'mintConnectLink', row, audit: audit }, (r) => 'connectLink' in r && r.connectLink ? r.connectLink : NOT_ANSWERED);
|
|
5299
|
+
}
|
|
5300
|
+
return this.auditedConnectLink((store) => mintConnectLinkIn(store, row, audit));
|
|
5232
5301
|
}
|
|
5233
5302
|
readConnectLink(key) {
|
|
5234
|
-
|
|
5303
|
+
if (this.connectLinksCutOver(key.tenantId)) {
|
|
5304
|
+
return this.directoryCutover.tupleRead(key.tenantId, { kind: 'connectLink', key }).then((r) => r ?? undefined);
|
|
5305
|
+
}
|
|
5306
|
+
return readConnectLinkIn(this.sql, key);
|
|
5235
5307
|
}
|
|
5236
5308
|
listConnectLinks(filter, now) {
|
|
5237
|
-
|
|
5309
|
+
if (this.connectLinksCutOver(filter.tenantId)) {
|
|
5310
|
+
return this.directoryCutover.tupleRead(filter.tenantId, { kind: 'connectLinks', filter, now });
|
|
5311
|
+
}
|
|
5312
|
+
return listConnectLinksIn(this.sql, filter, now);
|
|
5238
5313
|
}
|
|
5239
5314
|
revokeConnectLink(key, audit) {
|
|
5240
|
-
|
|
5315
|
+
if (this.connectLinksCutOver(key.tenantId)) {
|
|
5316
|
+
return this.connectLinkFirst(key.tenantId, { kind: 'revokeConnectLink', key, audit: audit }, (r) => 'connectLinkMove' in r ? (r.connectLinkMove ?? undefined) : NOT_ANSWERED);
|
|
5317
|
+
}
|
|
5318
|
+
return this.auditedConnectLink((store) => revokeConnectLinkIn(store, key, audit));
|
|
5241
5319
|
}
|
|
5242
5320
|
consumeConnectLink(input, now, audit) {
|
|
5243
|
-
|
|
5321
|
+
if (this.connectLinksCutOver(input.tenantId)) {
|
|
5322
|
+
return this.connectLinkFirst(input.tenantId, { kind: 'consumeConnectLink', input, now, audit: audit }, (r) => 'consumed' in r ? r.consumed : NOT_ANSWERED);
|
|
5323
|
+
}
|
|
5324
|
+
return this.auditedConnectLink((store) => consumeConnectLinkIn(store, input, now, audit));
|
|
5244
5325
|
}
|
|
5245
5326
|
restoreConnectLink(key, now, audit) {
|
|
5246
|
-
|
|
5327
|
+
if (this.connectLinksCutOver(key.tenantId)) {
|
|
5328
|
+
return this.connectLinkFirst(key.tenantId, { kind: 'restoreConnectLink', key, now, audit: audit }, (r) => 'connectLink' in r ? (r.connectLink ?? undefined) : NOT_ANSWERED);
|
|
5329
|
+
}
|
|
5330
|
+
return this.auditedConnectLink((store) => restoreConnectLinkIn(store, key, now, audit));
|
|
5247
5331
|
}
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
action: a.action,
|
|
5252
|
-
tenantId: a.target.tenantId,
|
|
5253
|
-
scopeId: a.target.scopeId,
|
|
5254
|
-
vertical: a.target.vertical,
|
|
5255
|
-
before: a.before,
|
|
5256
|
-
after: a.after,
|
|
5257
|
-
})));
|
|
5332
|
+
/** This directory as a connect-link store, in one transaction with the move's admin row. */
|
|
5333
|
+
auditedConnectLink(run) {
|
|
5334
|
+
return this.ctx.storage.transactionSync(() => run({ sql: this.sql, admin: (entry) => this.recordAdmin(entry) }));
|
|
5258
5335
|
}
|
|
5259
5336
|
/**
|
|
5260
5337
|
* Record a connection grant directory-side (#592) — written by `grantToConnection`
|
|
@@ -5518,44 +5595,51 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
5518
5595
|
.filter((r) => !prefix || r.state_key.startsWith(prefix))
|
|
5519
5596
|
.map((r) => ({ key: r.state_key, value: r.value }));
|
|
5520
5597
|
}
|
|
5598
|
+
// -- identity links (K-22/K-23) ----------------------------------------------
|
|
5599
|
+
// K-68 step 3e (the fifth family): a tenant whose flip froze its identity links in reads them from,
|
|
5600
|
+
// and links and unlinks them first in, its own object (`directory-tenant-identities.ts`, the same
|
|
5601
|
+
// code in either store). The cross-tenant login reads above stay here: no tenant's object holds them.
|
|
5602
|
+
/**
|
|
5603
|
+
* Bind `provider:externalId` to `principal` in the tenant. False when the same binding is already
|
|
5604
|
+
* held (no admin row); a conflict when another principal holds it. With `audit`, a new link commits
|
|
5605
|
+
* with its admin row.
|
|
5606
|
+
*/
|
|
5521
5607
|
linkIdentity(provider, externalId, principal, tenantId, scopeId, createdAt, audit) {
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
return true;
|
|
5536
|
-
}, audit);
|
|
5608
|
+
if (this.identitiesCutOver(tenantId)) {
|
|
5609
|
+
return this.directoryCutover.tupleWrite(tenantId, {
|
|
5610
|
+
kind: 'linkIdentity', provider, externalId, principal, scopeId, createdAt, audit: (audit ?? null),
|
|
5611
|
+
}).then((r) => {
|
|
5612
|
+
if (r && 'conflict' in r)
|
|
5613
|
+
throw substratError('conflict', r.conflict);
|
|
5614
|
+
// An object from before this family answers nothing, having written nothing.
|
|
5615
|
+
if (!r || !('linked' in r))
|
|
5616
|
+
throw new Error(`tenant object did not link ${provider}:${externalId}: it predates the identity cut-over`);
|
|
5617
|
+
return r.linked;
|
|
5618
|
+
});
|
|
5619
|
+
}
|
|
5620
|
+
return this.writeAndAudit(() => linkIdentityIn({ sql: this.sql }, provider, externalId, principal, tenantId, scopeId, createdAt), audit);
|
|
5537
5621
|
}
|
|
5538
5622
|
/** Remove a principal's identity link(s) in a tenant. Returns whether a row was
|
|
5539
5623
|
* deleted so a no-op stays silent (idempotent). */
|
|
5540
5624
|
unlinkIdentity(tenantId, principal, audit) {
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
}
|
|
5625
|
+
if (this.identitiesCutOver(tenantId)) {
|
|
5626
|
+
return this.directoryCutover.tupleWrite(tenantId, {
|
|
5627
|
+
kind: 'unlinkIdentity', principal, audit: (audit ?? null),
|
|
5628
|
+
}).then((r) => {
|
|
5629
|
+
if (!r || !('unlinked' in r))
|
|
5630
|
+
throw new Error(`tenant object did not unlink ${principal}: it predates the identity cut-over`);
|
|
5631
|
+
return r.unlinked;
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
return this.writeAndAudit(() => unlinkIdentityIn({ sql: this.sql }, tenantId, principal), audit);
|
|
5550
5635
|
}
|
|
5551
5636
|
resolveIdentity(tenantId, provider, externalId) {
|
|
5552
|
-
|
|
5553
|
-
.
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
return { principal: row.principal_id, scopeId: row.scope_id };
|
|
5637
|
+
if (this.identitiesCutOver(tenantId)) {
|
|
5638
|
+
return this.directoryCutover
|
|
5639
|
+
.tupleRead(tenantId, { kind: 'identity', provider, externalId })
|
|
5640
|
+
.then((r) => r ?? undefined);
|
|
5641
|
+
}
|
|
5642
|
+
return resolveIdentityIn(this.sql, tenantId, provider, externalId);
|
|
5559
5643
|
}
|
|
5560
5644
|
/**
|
|
5561
5645
|
* ALL of a tenant's identity links — the read behind identity-link projection
|
|
@@ -5563,13 +5647,13 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
5563
5647
|
* `unlinkIdentity` hard-deletes (the admin log is the audit), so the projection
|
|
5564
5648
|
* is a full replace and a removed link is simply absent from the next snapshot.
|
|
5565
5649
|
* Not on the request hot path — this runs on the admin write path, projecting
|
|
5566
|
-
* into a tenant's scopes, and at provision/reconcile gathering.
|
|
5650
|
+
* into a tenant's scopes, and at provision/reconcile gathering. A cut-over
|
|
5651
|
+
* tenant's are its object's (3e).
|
|
5567
5652
|
*/
|
|
5568
5653
|
dumpTenantIdentities(tenantId) {
|
|
5569
|
-
|
|
5570
|
-
.
|
|
5571
|
-
|
|
5572
|
-
.toArray();
|
|
5654
|
+
if (this.identitiesCutOver(tenantId))
|
|
5655
|
+
return this.directoryCutover.tupleRead(tenantId, { kind: 'identities' });
|
|
5656
|
+
return dumpIdentityRows(this.sql, tenantId);
|
|
5573
5657
|
}
|
|
5574
5658
|
// -- admin audit log (control-plane.md §4.4) --------------------------------
|
|
5575
5659
|
/** Append one audit row. before/after are arbitrary JSON, stringified here. */
|