@fantastic.dev/better-stripe 0.97.1 → 0.98.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 (68) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +5 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +38 -0
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +54 -0
  8. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +44 -37
  10. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
  14. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +3 -0
  16. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +71 -46
  18. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
  20. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
  22. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
  26. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +6 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  29. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +19 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  31. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
  33. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
  35. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +161 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
  39. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
  41. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
  42. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
  43. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  44. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  45. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  46. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  47. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  48. package/dist/component/earnings/triggers.d.ts +16 -16
  49. package/dist/component/payoutRelease/queries.d.ts +2 -2
  50. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  51. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  52. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  53. package/docs/renewal-context-reads.md +26 -6
  54. package/package.json +1 -1
  55. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +42 -0
  56. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +55 -48
  57. package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
  58. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +91 -55
  59. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
  60. package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
  61. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +22 -0
  62. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
  63. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +175 -0
  64. package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
  65. package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
  66. package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
  67. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
  68. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +69 -11
@@ -163,10 +163,10 @@ export declare const snapshot: import("convex/server").RegisteredQuery<"public",
163
163
  accountId: string;
164
164
  ownerKey: string;
165
165
  }, Promise<{
166
- status: "held";
167
- reason: "snapshot_limit";
168
166
  transfers?: undefined;
169
167
  claims?: undefined;
168
+ status: "held";
169
+ reason: "snapshot_limit";
170
170
  } | {
171
171
  reason?: undefined;
172
172
  status: "ready";
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/payoutRelease/queries.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIlB,CAAC;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiBd,CAAC;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;GAQf,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;YAsBE,MAAM;YAAmB,gBAAgB;;;;;YAS3C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE1B,CAAC"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/payoutRelease/queries.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIlB,CAAC;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiBd,CAAC;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;GAQf,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;;;YAsBE,MAAM;YAAmB,gBAAgB;;;YAS3C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE1B,CAAC"}
@@ -14,7 +14,7 @@ export declare function checkRollback(ctx: MutationCtx, op: Doc<"processingCostR
14
14
  readonly bindFunding?: undefined;
15
15
  } | {
16
16
  reason?: undefined;
17
- readonly retryable?: undefined;
17
+ retryable?: undefined;
18
18
  readonly status: "ready";
19
19
  readonly bindFunding: boolean;
20
20
  }>;
@@ -2632,6 +2632,14 @@ export declare function setupAllowance(): Promise<{
2632
2632
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
2633
2633
  requestKey: string;
2634
2634
  result?: {
2635
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2636
+ retryable: false;
2637
+ status: "conflict";
2638
+ } | {
2639
+ reason: "policy_invalid";
2640
+ retryable: false;
2641
+ status: "rejected";
2642
+ } | {
2635
2643
  operation: {
2636
2644
  accountId: string;
2637
2645
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2642,14 +2650,6 @@ export declare function setupAllowance(): Promise<{
2642
2650
  } | {
2643
2651
  enabled: boolean;
2644
2652
  status: "unchanged";
2645
- } | {
2646
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2647
- retryable: false;
2648
- status: "conflict";
2649
- } | {
2650
- reason: "policy_invalid";
2651
- retryable: false;
2652
- status: "rejected";
2653
2653
  } | {
2654
2654
  reason: "provider_pending";
2655
2655
  retryable: true;
@@ -2660,6 +2660,14 @@ export declare function setupAllowance(): Promise<{
2660
2660
  payload: import("convex/values").VString<string, "required">;
2661
2661
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
2662
2662
  result: import("convex/values").VUnion<{
2663
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2664
+ retryable: false;
2665
+ status: "conflict";
2666
+ } | {
2667
+ reason: "policy_invalid";
2668
+ retryable: false;
2669
+ status: "rejected";
2670
+ } | {
2663
2671
  operation: {
2664
2672
  accountId: string;
2665
2673
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2670,14 +2678,6 @@ export declare function setupAllowance(): Promise<{
2670
2678
  } | {
2671
2679
  enabled: boolean;
2672
2680
  status: "unchanged";
2673
- } | {
2674
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2675
- retryable: false;
2676
- status: "conflict";
2677
- } | {
2678
- reason: "policy_invalid";
2679
- retryable: false;
2680
- status: "rejected";
2681
2681
  } | {
2682
2682
  reason: "provider_pending";
2683
2683
  retryable: true;
@@ -113,8 +113,7 @@ Each callback rechecks both clocks and the original policy before rearming. The
113
113
  later final deadline is not a timer span limit. Event-loop suspension can delay
114
114
  callbacks. Every continuation therefore checks both clocks before
115
115
  returning a value. Retirement is irreversible and never extends either original
116
- cutoff. Legacy actors still use their separate dormant identity; extracting and
117
- wiring their per-invocation kernels remains required before runtime activation.
116
+ cutoff. Legacy actors retain their separate dormant identity and behavior.
118
117
 
119
118
  The private initial core can capture one attach-stage C10 compiler for its own
120
119
  lineage. This compiler takes the original raw source and actual acquired
@@ -127,8 +126,7 @@ Retiring one invocation rejects its pending channel without retiring another
127
126
  invocation's channel or removing already committed DATA. Stored events and C10
128
127
  append acknowledgements do not establish provider custody or a returned public
129
128
  operation acknowledgement. Legacy stage-channel facades retain their existing
130
- lazy Owner and behavior. Initial actor, acquisition and transport factory wiring
131
- remains required.
129
+ lazy Owner and behavior.
132
130
 
133
131
  The core's private material classifiers also retain the original journal source
134
132
  and canonical Owner. Retained classification accepts no replacement source.
@@ -138,8 +136,30 @@ original source. Both paths keep the existing DATA-consistency-only result and
138
136
  bounded snapshots. They do not qualify acquisition or provider custody. Pending
139
137
  reconstruction is owned by that invocation; retirement rejects its continuation
140
138
  without closing another invocation's classifier. Legacy classifier exports keep
141
- their lazy Owner and existing refusal behavior. The initial actor still needs
142
- to wire these classifiers to its per-invocation acquisition and transport.
139
+ their lazy Owner and existing refusal behavior.
140
+
141
+ The private initial actor now uses those classifiers, the canonical transport and
142
+ one acquisition reader for its lineage. Its operation retains one private origin
143
+ association and a single-use source slot. The transport captures the selected
144
+ SDK's original raw-request method and receiver, and receives the actual SDK
145
+ promise. Its fixed read plan permits the original subscription, target price,
146
+ billing customer and at most 40 original Coupon reads. It permits one attachment
147
+ POST. Callers cannot supply a replacement client, source, plan, Owner or journal
148
+ sink through the invocation core.
149
+
150
+ The actor retains the complete captured C3 receipt in the component journal at
151
+ sequence 2 before appending receipt event 3 or returning an acknowledgement.
152
+ Receipt retention alone is DATA. If the Owner retires while a committed retention
153
+ reply is pending, that DATA remains, but the actor refuses its acknowledgement.
154
+ Another invocation keeps its own client, Owner, journal and continuation.
155
+
156
+ Production Source class arrays remain empty. Empty admission returns before
157
+ constructing an Owner, loading Source data, invoking a client method or sampling
158
+ a clock, including when the
159
+ private actor is captured from a lineage that has no Owner yet. Tests admit
160
+ synthetic profiles in ordinary Node and Convex-test with controlled HTTP. They
161
+ do not qualify native execution or provider custody. Public scheduling, native
162
+ profile qualification, recovery and later operation stages remain separate work.
143
163
 
144
164
  ## Component operation journal
145
165
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantastic.dev/better-stripe",
3
- "version": "0.97.1",
3
+ "version": "0.98.0",
4
4
  "description": "Convex component for Stripe Accounts v2, subscriptions, metered billing and Connect marketplaces, with React workflows.",
5
5
  "keywords": [
6
6
  "stripe",
@@ -22,6 +22,10 @@ import {
22
22
  type RawReadTransport,
23
23
  } from "./rawWireSource.js";
24
24
  import { acquireCouponJoins } from "./rawCouponJoins.js";
25
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
26
+ import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
27
+ import { operationForInitialLineage } from "../producer/operationFactory.js";
28
+ import { createInitialTransportForLineage } from "../operations/fixedTransport.js";
25
29
  const need: (x: unknown) => asserts x = (x) => {
26
30
  if (!x) throw Error("RAW_ACQUISITION_STOP");
27
31
  };
@@ -47,6 +51,44 @@ type RawSuccess = Readonly<{
47
51
  export type RawAcquisitionResult = typeof STOP | RawSuccess;
48
52
  export type RawConfigureAcquisitionResult =
49
53
  typeof STOP | (RawSuccess & Readonly<{ schedule: Record<string, unknown> }>);
54
+ type InitialReader = Readonly<{ acquire(): Promise<RawAcquisitionResult> }>;
55
+ const initialReaders = new WeakMap<object, Promise<InitialReader>>();
56
+
57
+ /** Fixed source, transport and expected material; no replacement inputs. */
58
+ export function acquisitionForInitialLineage(
59
+ token: object,
60
+ ): Promise<InitialReader> {
61
+ if (arguments.length !== 1) throw Error("RAW_ACQUISITION_STOP");
62
+ const owner = ownerForInitialLineage(token);
63
+ owner.check();
64
+ const owned = ownedAwaitForInitialLineage(token);
65
+ let pending = initialReaders.get(token);
66
+ if (!pending) {
67
+ pending = owned(async () => {
68
+ try {
69
+ const frame = await operationForInitialLineage(token);
70
+ const pair = await createInitialTransportForLineage(token);
71
+ owner.check();
72
+ const reader = createSelectedRawAcquisition(
73
+ owner,
74
+ captureTransport(pair.transport.readTransport),
75
+ );
76
+ return Object.freeze({
77
+ acquire() {
78
+ if (arguments.length !== 0) throw Error("RAW_ACQUISITION_STOP");
79
+ return owned(() => reader.acquire(frame.expected));
80
+ },
81
+ });
82
+ } catch (error) {
83
+ owner.retire();
84
+ throw error;
85
+ }
86
+ });
87
+ initialReaders.set(token, pending);
88
+ }
89
+ const captured = pending;
90
+ return owned(() => captured);
91
+ }
50
92
  const observed = z.union([
51
93
  z.null(),
52
94
  resourceId("sub_sched"),
@@ -9,7 +9,6 @@ import {
9
9
  freezeJSON,
10
10
  type AttachRequest,
11
11
  type ReadRow,
12
- type SourceMethod,
13
12
  } from "./types.js";
14
13
  import {
15
14
  safeDiagnostics,
@@ -23,34 +22,14 @@ import {
23
22
  loadOwnedTransportSource,
24
23
  } from "./sourceOperations.js";
25
24
  import { OWNER } from "../originalOwner.js";
26
-
27
- function sourceFunction(
28
- service: unknown,
29
- name: string,
30
- ): { receiver: object; method: SourceMethod } {
31
- need(service && typeof service === "object" && !types.isProxy(service));
32
- const d = Object.getOwnPropertyDescriptor(service, name);
33
- need(d && "value" in d && typeof d.value === "function");
34
- // The function is selected once from validated own data, preserving its receiver.
35
- return { receiver: service, method: d.value as SourceMethod };
36
- }
37
-
38
- /** Internal fixed attach profile: 43 reads and one POST, never a 44-GET profile. */
39
- function captureSource(raw: unknown) {
40
- const b = closed(raw, ["owner", "request", "readPlan", "delegate"]);
41
- need(b.owner === OWNER);
42
- const owner = sourceFunction(b.owner, "check"),
43
- delegate = sourceFunction(b.delegate, "rawRequest");
44
- const { request, plan } = captureRequestAndReads(b.request, b.readPlan);
45
- return Object.freeze({
46
- owner: owner.receiver,
47
- check: owner.method,
48
- delegate: delegate.receiver,
49
- send: delegate.method,
50
- request,
51
- plan: Object.freeze(plan),
52
- });
53
- }
25
+ import {
26
+ captureLegacyTransportSource,
27
+ captureInitialTransportSource,
28
+ checkTransportOwnerResult as checkOwnerResult,
29
+ } from "./transportCapture.js";
30
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
31
+ import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
32
+ import { operationForInitialLineage } from "../producer/operationFactory.js";
54
33
 
55
34
  function validRead(
56
35
  row: ReadRow,
@@ -67,22 +46,6 @@ function validRead(
67
46
  );
68
47
  }
69
48
 
70
- function checkOwnerResult(value: unknown) {
71
- const x = closed(value, ["wallMs", "ns", "nowSeconds", "retired"]);
72
- need(
73
- typeof x.wallMs === "number" &&
74
- Number.isSafeInteger(x.wallMs) &&
75
- x.wallMs >= 0 &&
76
- typeof x.ns === "bigint" &&
77
- x.ns >= 0n &&
78
- x.ns <= 18446744073709551615n &&
79
- typeof x.nowSeconds === "number" &&
80
- Number.isSafeInteger(x.nowSeconds) &&
81
- x.nowSeconds === Math.floor(x.wallMs / 1000) &&
82
- x.retired === false,
83
- );
84
- }
85
-
86
49
  export type PostDisposition =
87
50
  | "NOT_STARTED"
88
51
  | "PENDING"
@@ -169,9 +132,12 @@ type Association = Readonly<{
169
132
  readPlan: unknown;
170
133
  delegate: unknown;
171
134
  }>;
172
- function build(source: unknown, association?: Association) {
173
- const b = captureSource(source),
174
- generation = Object.freeze({});
135
+ function build(source: unknown, association?: Association, token?: object) {
136
+ const b =
137
+ token === undefined
138
+ ? captureLegacyTransportSource(source)
139
+ : captureInitialTransportSource(token, source);
140
+ const generation = Object.freeze({});
175
141
  let ordinal = 0,
176
142
  index = 0,
177
143
  pending: Attempt | null = null,
@@ -572,3 +538,44 @@ export function createRecoveryOwnedTransportWithAttemptCapability() {
572
538
  need(arguments.length === 0);
573
539
  return createAssociatedPair(loadRecoveryOwnedTransportSource);
574
540
  }
541
+
542
+ const initialTransports = new WeakMap<
543
+ object,
544
+ Promise<ReturnType<typeof build>>
545
+ >();
546
+ /** Canonical private transport, constructed only from the original lineage. */
547
+ export function createInitialTransportForLineage(token: object) {
548
+ if (arguments.length !== 1) throw Error("INITIAL_OPERATION_UNBOUND");
549
+ const owner = ownerForInitialLineage(token);
550
+ owner.check();
551
+ const owned = ownedAwaitForInitialLineage(token);
552
+ let pending = initialTransports.get(token);
553
+ if (!pending) {
554
+ pending = owned(async () => {
555
+ try {
556
+ const frame = await operationForInitialLineage(token);
557
+ owner.check();
558
+ return build(
559
+ {
560
+ owner,
561
+ request: frame.request,
562
+ readPlan: frame.operation.readPlan,
563
+ delegate: frame.operation.delegate,
564
+ },
565
+ {
566
+ operation: frame.operation,
567
+ readPlan: frame.operation.readPlan,
568
+ delegate: frame.operation.delegate,
569
+ },
570
+ token,
571
+ );
572
+ } catch (error) {
573
+ owner.retire();
574
+ throw error;
575
+ }
576
+ });
577
+ initialTransports.set(token, pending);
578
+ }
579
+ const captured = pending;
580
+ return owned(() => captured);
581
+ }
@@ -0,0 +1,41 @@
1
+ import { types } from "node:util";
2
+ import type { AttachRequest, SourceMethod } from "./types.js";
3
+
4
+ export function sourceMethod(object: unknown, name: string): SourceMethod {
5
+ need(object !== null && typeof object === "object" && !types.isProxy(object));
6
+ const d = Object.getOwnPropertyDescriptor(object, name);
7
+ need(
8
+ d &&
9
+ d.enumerable &&
10
+ "value" in d &&
11
+ typeof d.value === "function" &&
12
+ !types.isProxy(d.value),
13
+ );
14
+ return d.value as SourceMethod;
15
+ }
16
+ export const stop = (): never => {
17
+ throw Error("INITIAL_ACTOR_STOP");
18
+ };
19
+ export function need(value: unknown): asserts value {
20
+ if (!value) stop();
21
+ }
22
+ export function seven(request: AttachRequest) {
23
+ const { scope, apiVersion, method, path, payload, key, firstDispatchedAt } =
24
+ request;
25
+ return Object.freeze({
26
+ scope,
27
+ apiVersion,
28
+ method,
29
+ path,
30
+ payload,
31
+ key,
32
+ firstDispatchedAt,
33
+ });
34
+ }
35
+
36
+ export const refuse = (reason: string) =>
37
+ Object.freeze({
38
+ status: "not_dispatched",
39
+ reason,
40
+ operationalAuthority: false,
41
+ });
@@ -1,6 +1,6 @@
1
1
  import { admitInitialOutput } from "../recovery/material.js";
2
2
  import { types } from "node:util";
3
- import { OWNER } from "../originalOwner.js";
3
+ import { OWNER as LEGACY_OWNER } from "../originalOwner.js";
4
4
  import {
5
5
  prepareRenewalPriceReplacementV2 as c1,
6
6
  prepareRenewalScheduleAttachmentV2 as c2,
@@ -18,7 +18,7 @@ import {
18
18
  type FailureControl,
19
19
  } from "./types.js";
20
20
  import { equal } from "../../../renewalAggregate/shared.js";
21
- import { owned } from "./ownedAwait.js";
21
+ import { owned as legacyOwned, ownedForInitialLineage } from "./ownedAwait.js";
22
22
  import type { Diagnostics } from "./providerFailure.js";
23
23
  import { bindRawAcquisitionFromSource } from "../acquisition/ownedAcquisition.js";
24
24
  import { createAttachEventCompiler } from "../c10/attachEvents.js";
@@ -29,46 +29,19 @@ import {
29
29
  } from "./sourceOperations.js";
30
30
  import { createInitialOwnedTransportWithAttemptCapability as createPair } from "./fixedTransport.js";
31
31
 
32
+ import { sourceMethod, stop, need, seven, refuse } from "./initialActorData.js";
33
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
34
+ import { readInitialLineage } from "../producer/lineageAuthority.js";
35
+ import {
36
+ operationForInitialLineage,
37
+ retainInitialReceiptForLineage,
38
+ } from "../producer/operationFactory.js";
39
+ import { createInitialTransportForLineage } from "./fixedTransport.js";
40
+ import { createInitialMaterialClassifiers } from "../material/classifiers.js";
41
+ import { acquisitionForInitialLineage } from "../acquisition/ownedAcquisition.js";
42
+ import { createInitialAttachEventCompiler } from "../c10/attachEvents.js";
32
43
  type Pair = ReturnType<typeof createPair>;
33
44
 
34
- function sourceMethod(object: unknown, name: string): SourceMethod {
35
- need(object !== null && typeof object === "object" && !types.isProxy(object));
36
- const d = Object.getOwnPropertyDescriptor(object, name);
37
- need(
38
- d &&
39
- d.enumerable &&
40
- "value" in d &&
41
- typeof d.value === "function" &&
42
- !types.isProxy(d.value),
43
- );
44
- return d.value as SourceMethod;
45
- }
46
- const stop = (): never => {
47
- throw Error("INITIAL_ACTOR_STOP");
48
- };
49
- function need(value: unknown): asserts value {
50
- if (!value) stop();
51
- }
52
- function seven(request: AttachRequest) {
53
- const { scope, apiVersion, method, path, payload, key, firstDispatchedAt } =
54
- request;
55
- return Object.freeze({
56
- scope,
57
- apiVersion,
58
- method,
59
- path,
60
- payload,
61
- key,
62
- firstDispatchedAt,
63
- });
64
- }
65
-
66
- const refuse = (reason: string) =>
67
- Object.freeze({
68
- status: "not_dispatched",
69
- reason,
70
- operationalAuthority: false,
71
- });
72
45
  /** Internal single-use actor. Empty class registry precedes every Source side effect. */
73
46
  export function captureInitialAttach() {
74
47
  need(arguments.length === 0);
@@ -76,6 +49,20 @@ export function captureInitialAttach() {
76
49
  }
77
50
  export function captureOwnedInitialAttachV2() {
78
51
  need(arguments.length === 0);
52
+ return initialKernel(null);
53
+ }
54
+ const actors = new WeakMap<object, ReturnType<typeof initialKernel>>();
55
+ export function captureInitialAttachForLineage(token: object) {
56
+ need(arguments.length === 1);
57
+ readInitialLineage(token);
58
+ let actor = actors.get(token);
59
+ if (!actor) {
60
+ actor = initialKernel(token);
61
+ actors.set(token, actor);
62
+ }
63
+ return actor;
64
+ }
65
+ function initialKernel(token: object | null) {
79
66
  let consumed = false;
80
67
  return Object.freeze({
81
68
  async invoke() {
@@ -84,6 +71,31 @@ export function captureOwnedInitialAttachV2() {
84
71
  consumed = true;
85
72
  need(!types.isProxy(ENTRIES) && Array.isArray(ENTRIES));
86
73
  if (ENTRIES.length === 0) return refuse("no_qualified_native_class");
74
+
75
+ const OWNER =
76
+ token === null ? LEGACY_OWNER : ownerForInitialLineage(token);
77
+ const owned =
78
+ token === null ? legacyOwned : ownedForInitialLineage(token);
79
+ const classifyRetained =
80
+ token === null
81
+ ? classifyOwnedRetainedInitialAttachment
82
+ : (_raw: unknown) =>
83
+ createInitialMaterialClassifiers(token).retained();
84
+ const classifyFresh =
85
+ token === null
86
+ ? classifyOwnedInitialAttachment
87
+ : (raw: unknown) => {
88
+ const input = closed(raw, [
89
+ "attachRequest",
90
+ "originalBundle",
91
+ "currentBundle",
92
+ "observedAt",
93
+ ]);
94
+ return createInitialMaterialClassifiers(token).fresh(
95
+ input.currentBundle,
96
+ input.observedAt,
97
+ );
98
+ };
87
99
  let pair: Pair | null = null,
88
100
  failureControl: FailureControl | null = null,
89
101
  postEligible = false;
@@ -105,7 +117,10 @@ export function captureOwnedInitialAttachV2() {
105
117
  };
106
118
  try {
107
119
  OWNER.check();
108
- const live = loadFixedInitialOperation();
120
+ const live =
121
+ token === null
122
+ ? loadFixedInitialOperation()
123
+ : (await owned(() => operationForInitialLineage(token))).operation;
109
124
  OWNER.check();
110
125
  if (live === null) return refuse("original_slot_unbound");
111
126
  const op = closed(live, [
@@ -121,7 +136,10 @@ export function captureOwnedInitialAttachV2() {
121
136
  op.originAssociation !== null &&
122
137
  typeof op.originAssociation === "object" &&
123
138
  !types.isProxy(op.originAssociation) &&
124
- op.originAssociation === ORIGINAL_ORIGIN_ASSOCIATION,
139
+ op.originAssociation ===
140
+ (token === null
141
+ ? ORIGINAL_ORIGIN_ASSOCIATION
142
+ : readInitialLineage(token).originAssociation),
125
143
  );
126
144
  const takeOnce = sourceMethod(op.slot, "takeOnce");
127
145
  OWNER.check();
@@ -146,9 +164,7 @@ export function captureOwnedInitialAttachV2() {
146
164
  }),
147
165
  );
148
166
  OWNER.check();
149
- const retained = await owned(() =>
150
- classifyOwnedRetainedInitialAttachment(original),
151
- );
167
+ const retained = await owned(() => classifyRetained(original));
152
168
  OWNER.check();
153
169
  if (retained.status !== "classified")
154
170
  return refuse("retained_material_unsupported");
@@ -169,7 +185,10 @@ export function captureOwnedInitialAttachV2() {
169
185
  if (matches.length !== 1) return refuse("retained_class_not_unique");
170
186
  const entry = matches[0];
171
187
  OWNER.check();
172
- pair = createPair();
188
+ pair =
189
+ token === null
190
+ ? createPair()
191
+ : await owned(() => createInitialTransportForLineage(token));
173
192
  OWNER.check();
174
193
  need(
175
194
  pair.capability.assertSourceOperationBinding(
@@ -342,10 +361,20 @@ export function captureOwnedInitialAttachV2() {
342
361
  })();
343
362
  OWNER.check();
344
363
  failureControl = control;
345
- const reader = bindRawAcquisitionFromSource(
346
- OWNER,
347
- activePair.transport.readTransport,
348
- );
364
+ const reader =
365
+ token === null
366
+ ? bindRawAcquisitionFromSource(
367
+ OWNER,
368
+ activePair.transport.readTransport,
369
+ )
370
+ : {
371
+ async acquire(_expected: unknown) {
372
+ const reader = await owned(() =>
373
+ acquisitionForInitialLineage(token),
374
+ );
375
+ return reader.acquire();
376
+ },
377
+ };
349
378
  OWNER.check();
350
379
  let acquiredOnce = false;
351
380
  const acquire = async () => {
@@ -370,7 +399,7 @@ export function captureOwnedInitialAttachV2() {
370
399
  if (!acquired.ok) return refuse("current_read_unsupported");
371
400
 
372
401
  const fresh = await owned(() =>
373
- classifyOwnedInitialAttachment({
402
+ classifyFresh({
374
403
  attachRequest: raw,
375
404
  originalBundle: original.originalBundle,
376
405
  currentBundle: acquired.bundle,
@@ -441,10 +470,13 @@ export function captureOwnedInitialAttachV2() {
441
470
  OWNER.check();
442
471
  return Reflect.apply(send, op.sink, [record, ack]);
443
472
  };
444
- const compiler = createAttachEventCompiler(raw, {
445
- send: sourceSend,
446
- timeoutMs: 5000,
447
- });
473
+ const compiler =
474
+ token === null
475
+ ? createAttachEventCompiler(raw, {
476
+ send: sourceSend,
477
+ timeoutMs: 5000,
478
+ })
479
+ : createInitialAttachEventCompiler(token);
448
480
  OWNER.check();
449
481
  await owned(() =>
450
482
  compiler.dispatch({ event: "dispatch", stage: "attach", request }),
@@ -489,6 +521,10 @@ export function captureOwnedInitialAttachV2() {
489
521
  }),
490
522
  );
491
523
  OWNER.check();
524
+ if (token !== null) {
525
+ await owned(() => retainInitialReceiptForLineage(token, receipt));
526
+ OWNER.check();
527
+ }
492
528
  await owned(() =>
493
529
  compiler.receipt({
494
530
  event: "receipt",
@@ -1,4 +1,5 @@
1
1
  import { OWNER } from "../originalOwner.js";
2
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
2
3
 
3
4
  export interface FailureForwarder {
4
5
  forward(error: unknown): object | null;
@@ -8,7 +9,24 @@ export function owned<T>(
8
9
  work: () => T | PromiseLike<T>,
9
10
  failureControl: FailureForwarder | null = null,
10
11
  ): Promise<T> {
11
- OWNER.check();
12
+ return runOwned(OWNER, work, failureControl);
13
+ }
14
+ export function ownedForInitialLineage(token: object) {
15
+ if (arguments.length !== 1) throw Error("INITIAL_ACTOR_STOP");
16
+ const owner = ownerForInitialLineage(token);
17
+ return function owned<T>(
18
+ work: () => T | PromiseLike<T>,
19
+ control: FailureForwarder | null = null,
20
+ ): Promise<T> {
21
+ return runOwned(owner, work, control);
22
+ };
23
+ }
24
+ function runOwned<T>(
25
+ owner: Pick<typeof OWNER, "check" | "subscribe">,
26
+ work: () => T | PromiseLike<T>,
27
+ failureControl: FailureForwarder | null,
28
+ ): Promise<T> {
29
+ owner.check();
12
30
  return new Promise((resolve, reject) => {
13
31
  let done = false,
14
32
  remove: (() => void) | null = null;
@@ -20,14 +38,14 @@ export function owned<T>(
20
38
  else reject(value);
21
39
  };
22
40
  const retire = () => finish(false, Error("INITIAL_ACTOR_STOP"));
23
- remove = OWNER.subscribe(retire);
41
+ remove = owner.subscribe(retire);
24
42
  if (done) {
25
43
  remove();
26
44
  return;
27
45
  }
28
46
  let pending: T | PromiseLike<T>;
29
47
  try {
30
- OWNER.check();
48
+ owner.check();
31
49
  pending = work();
32
50
  } catch {
33
51
  finish(false, Error("INITIAL_ACTOR_STOP"));
@@ -37,7 +55,7 @@ export function owned<T>(
37
55
  (value) => {
38
56
  if (done) return;
39
57
  try {
40
- OWNER.check();
58
+ owner.check();
41
59
  finish(true, value);
42
60
  } catch {
43
61
  retire();
@@ -46,7 +64,7 @@ export function owned<T>(
46
64
  (error: unknown) => {
47
65
  if (done) return;
48
66
  try {
49
- OWNER.check();
67
+ owner.check();
50
68
  const forwarded = failureControl
51
69
  ? failureControl.forward(error)
52
70
  : null;