@substrat-run/adapter-cloudflare 0.212.0 → 0.214.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.
Files changed (44) hide show
  1. package/dist/control-plane-do.d.ts +95 -8
  2. package/dist/control-plane-do.d.ts.map +1 -1
  3. package/dist/control-plane-do.js +307 -10
  4. package/dist/control-plane-do.js.map +1 -1
  5. package/dist/directory-objects.d.ts +74 -0
  6. package/dist/directory-objects.d.ts.map +1 -0
  7. package/dist/directory-objects.js +179 -0
  8. package/dist/directory-objects.js.map +1 -0
  9. package/dist/directory-placement.d.ts +27 -0
  10. package/dist/directory-placement.d.ts.map +1 -0
  11. package/dist/directory-placement.js +287 -0
  12. package/dist/directory-placement.js.map +1 -0
  13. package/dist/directory-split-inventory.d.ts +52 -0
  14. package/dist/directory-split-inventory.d.ts.map +1 -0
  15. package/dist/directory-split-inventory.js +109 -0
  16. package/dist/directory-split-inventory.js.map +1 -0
  17. package/dist/host.d.ts +3 -2
  18. package/dist/host.d.ts.map +1 -1
  19. package/dist/host.js +4 -2
  20. package/dist/host.js.map +1 -1
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +6 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/reconcile-on-wake.d.ts +35 -0
  26. package/dist/reconcile-on-wake.d.ts.map +1 -0
  27. package/dist/reconcile-on-wake.js +75 -0
  28. package/dist/reconcile-on-wake.js.map +1 -0
  29. package/dist/route-read-model-publisher.d.ts +171 -0
  30. package/dist/route-read-model-publisher.d.ts.map +1 -0
  31. package/dist/route-read-model-publisher.js +524 -0
  32. package/dist/route-read-model-publisher.js.map +1 -0
  33. package/dist/route-read-model.d.ts +166 -0
  34. package/dist/route-read-model.d.ts.map +1 -0
  35. package/dist/route-read-model.js +195 -0
  36. package/dist/route-read-model.js.map +1 -0
  37. package/dist/route-resolver.d.ts +41 -3
  38. package/dist/route-resolver.d.ts.map +1 -1
  39. package/dist/route-resolver.js +58 -3
  40. package/dist/route-resolver.js.map +1 -1
  41. package/dist/scope-do.d.ts.map +1 -1
  42. package/dist/scope-do.js +38 -2
  43. package/dist/scope-do.js.map +1 -1
  44. package/package.json +9 -9
package/dist/scope-do.js CHANGED
@@ -6,6 +6,7 @@ import { ulid, DO_SQL_LIMITS, unknownRoleError, createUlid, assertAllowed, Conne
6
6
  import { isUpgradeRequest, readSubscription, LIVE_DECIDE_ATTEMPTS, LIVE_FANOUT_LIMIT, LIVE_PRINCIPAL_HEADER, LIVE_SCOPE_HEADER, LIVE_SUBSCRIBE_PATH, LIVE_TENANT_HEADER, LIVE_WITHIN_HEADER, LIVE_EXPIRES_HEADER, LIVE_CLOSE, LIVE_SOCKETS_PER_PRINCIPAL, decodeLiveWithin, liveInstant, liveRefusal, liveRefusalStatus, } from './live-reads.js';
7
7
  import { replyOf } from './do-reply.js';
8
8
  import { OperationQueue } from './serialization.js';
9
+ import { reconcileOnWake } from './reconcile-on-wake.js';
9
10
  import { meterScopeWorkEntries, ScopeWorkMeter } from './scope-work.js';
10
11
  import { assertNoWorkerdStorage, doScopedSql, doBuiltColumnsOf, doRedactionSql, doSpineSql } from './sql.js';
11
12
  import { actorOf, admitPeer, boundToPeerDeclarations, collectPeers, switchPeer, peerSubjectRef, subjectGrantState, assertNoSecret, CAPABILITY_DDL, UPLOAD_LINK_DDL, DOWNLOAD_LINK_DDL, createAttachmentVerbs, inspectUploadLink, resolveDownloadLink, redeemUploadLinkInTransaction, COPY_ORIGIN_DDL, ENTITY_STATE_MOVES_DDL, SWITCH_FENCES_DDL, TABLE_OWNERS_DDL, assertMigrationLeavesLedgerAlone, recordOwnershipSteps, runMigrationStatements, splitSqlStatements, executableSqlStatements, blankSqlComments, CAPABILITY_EXCHANGE_OPERATION, CAPABILITY_BECOME_MINT_OPERATION, becomeMintCheck, mintBecomeCapabilityAsPrincipal, CAPABILITY_BIND_MINT_OPERATION, bindLinkMintCheck, mintBindLinkAsPrincipal, revokeBecomeCapabilityAsPrincipal, readBecomeLinkStates, ENTITY_UNBIND_OPERATION, allowedFor, unbindEntityHolderBounded, capabilityAttachmentWriteRefused, createCapabilityVerbs, createEntityEdgeVerbs, createEntityStateVerbs, createTrashedReads, CONTINUATION_POSITION_CAP, visibleContinuation, searchStateWhere, uncheckedView, addStatePlans, addUpdatedStampPlans, watchUpdatedStamps, assertNoCallerPurge, isUnreachableParent, PURGE_BATCH, heldPurgePass, lifecycleRefusal, purgeHeldBy, assertPlatformRequestRoom, CONNECTOR_DISPATCH_REQUESTED_BY, MAX_PENDING_CONNECTOR_DISPATCHES, purgeDueOf, purgeOnlyKeysOf, runPurgePass, refuseTrashedTarget, assertBoundOperations, checkHeldOperationsOf, countChecks, noteUncheckedCompletion, registerTrashTargets, withheldKeysFor, capCoverage, delegationCeilingOf, delegationStampOf, outsideCeiling, parseScopeDelegation, statefulTablesOf, afterMigration, afterRuntimeDdl, derivesAnything, repairDerivedObjects, StateColumnLost, exchangeCapability, exchangeBecomeLinkById, guardSecrets, mintBecomeCapability, redactSecrets, redactSecretText, moduleLog, asyncInvocationId, asyncLinePass, resolveCapabilitySession, revokeCapabilityAsPlatform, readCapabilityPage, domainEventOf, facetEvents, readDeadLetters, readLifecycleFlow, readOperationSeries, readHistory, readInvocation, readUndrainedOutbox, walkEventCause, walkEventEffects, } from '@substrat-run/kernel';
@@ -1058,6 +1059,8 @@ options = {}) {
1058
1059
  lastFailure = null;
1059
1060
  /** Passes of `applyPendingMigrations` that had work to do — see `migrationAttemptsOnInstance`. */
1060
1061
  migrationRuns = 0;
1062
+ /** K-69: this instance's wake wrote a `provision-reconcile` intent no invoke has reported yet. */
1063
+ reconcileAskUnsignalled = false;
1061
1064
  /**
1062
1065
  * TEST-ONLY (#1860): no production code reads this. An exact `'ping'` is answered
1063
1066
  * by `setWebSocketAutoResponse` without reaching `webSocketMessage` at all, and
@@ -2748,7 +2751,8 @@ options = {}) {
2748
2751
  const exported = exportMark !== null && !replayed ? this.exportedSince(exportTypes, exportMark) : 0;
2749
2752
  return {
2750
2753
  result,
2751
- platformRequests: signals.platformRequests,
2754
+ // K-69: plus the intent this instance's wake wrote, once, so the router kicks its drain.
2755
+ platformRequests: signals.platformRequests + this.takeReconcileAsk(),
2752
2756
  // #1705 PR 2: the coordinator fires `onExportedEvents` from this. Omitted at 0, so
2753
2757
  // the envelope of a deployment that exports nothing is byte-for-byte what it was.
2754
2758
  ...(exported > 0 ? { exported } : {}),
@@ -5082,14 +5086,46 @@ options = {}) {
5082
5086
  // -- migrations (port of applyPendingMigrations) --------------------------
5083
5087
  ensureMigrations() {
5084
5088
  if (!this.migrationPromise) {
5089
+ // K-69: read before the pass, so a scope with nothing applied yet reads as a provision.
5090
+ const upgrade = this.applied.size > 0;
5085
5091
  // #3316: counted as the migration it is, not as whichever entry woke it — the first
5086
5092
  // operation after a promote runs the whole pass.
5087
- this.migrationPromise = this.scopeWork
5093
+ const pass = this.scopeWork
5088
5094
  ? this.scopeWork.apart('migration-pass', 'migration', () => this.applyPendingMigrations())
5089
5095
  : this.applyPendingMigrations();
5096
+ // K-69: only after the pass SUCCEEDED — a scope failing closed asks for nothing, and the
5097
+ // rejection passes through untouched.
5098
+ this.migrationPromise = pass.then((applied) => {
5099
+ this.askReconcileOnWake(upgrade);
5100
+ return applied;
5101
+ });
5090
5102
  }
5091
5103
  return this.migrationPromise;
5092
5104
  }
5105
+ /**
5106
+ * K-69 (rfc/tenant-scale.md §7.5): the first wake on a version this scope has not asked about
5107
+ * writes one `provision-reconcile` intent (`reconcileOnWake`). Never throws: a scope that cannot
5108
+ * ask is still reached by the batched pass, and failing the request over it protects nothing.
5109
+ */
5110
+ askReconcileOnWake(upgrade) {
5111
+ try {
5112
+ const asked = reconcileOnWake(this.sql, this.env.SUBSTRAT_VERSION_ID, upgrade, new Date().toISOString());
5113
+ if (asked === 'requested')
5114
+ this.reconcileAskUnsignalled = true;
5115
+ }
5116
+ catch (err) {
5117
+ console.warn('reconcile-on-wake: could not ask; the batched pass is the backstop', {
5118
+ error: err instanceof Error ? err.message : String(err),
5119
+ });
5120
+ }
5121
+ }
5122
+ /** K-69: 1 once, on the first committed invoke after the wake asked, so its response flags a drain. */
5123
+ takeReconcileAsk() {
5124
+ if (!this.reconcileAskUnsignalled)
5125
+ return 0;
5126
+ this.reconcileAskUnsignalled = false;
5127
+ return 1;
5128
+ }
5093
5129
  /** Every registered module's derivation plans — what `repairDerivedObjects` and its checks read. */
5094
5130
  derivedPlans() {
5095
5131
  return { state: this.statePlans, lists: this.listPlans, search: this.searchPlans };