@oatscenter/trellis 0.100.0-rc.48 → 0.100.0-rc.49

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.
@@ -77,16 +77,34 @@ export async function connectProvisioned(options, kind, hooks = {}, transport) {
77
77
  *
78
78
  * nats.js fails a pending flush only when it redials in place. A generation
79
79
  * never does, so without this a flush awaiting a lost connection's `PONG`
80
- * would wait forever instead of failing with the loss.
80
+ * would wait forever instead of failing with the loss. One close watcher
81
+ * serves every flush, and each flush leaves the pending set when it settles,
82
+ * so a long-lived connection retains nothing per completed flush.
81
83
  */
82
84
  function settleFlushOnClose(nc) {
83
85
  const flush = nc.flush.bind(nc);
84
- nc.flush = () => Promise.race([
85
- flush(),
86
- nc.closed().then((error) => {
87
- throw error ?? new ClosedConnectionError();
88
- }),
89
- ]);
86
+ const pending = new Set();
87
+ let closedWith;
88
+ void nc.closed().then((error) => {
89
+ closedWith = error ?? new ClosedConnectionError();
90
+ for (const reject of pending)
91
+ reject(closedWith);
92
+ pending.clear();
93
+ });
94
+ nc.flush = () => {
95
+ if (closedWith)
96
+ return Promise.reject(closedWith);
97
+ return new Promise((resolve, reject) => {
98
+ pending.add(reject);
99
+ flush().then(() => {
100
+ pending.delete(reject);
101
+ resolve();
102
+ }, (error) => {
103
+ pending.delete(reject);
104
+ reject(error);
105
+ });
106
+ });
107
+ };
90
108
  return nc;
91
109
  }
92
110
  /** One signed-admission connection path for OAuth and provisioned runtimes. */
@@ -64,7 +64,17 @@ export async function authenticateIssuerChain(issuer, anchor, target, signal, ex
64
64
  /^[0-9]{1,20}$/.test(sequence) &&
65
65
  BigInt(sequence) <= BigInt(owner.trustSnapshot.rotationSequence))
66
66
  continue;
67
- await owner.acceptIssuerRotation(signedBytes(rotation));
67
+ try {
68
+ await owner.acceptIssuerRotation(signedBytes(rotation));
69
+ }
70
+ catch (cause) {
71
+ // The connected session may install the same link while this one
72
+ // waits its turn; the final trust check below still decides.
73
+ if (typeof sequence !== "string" ||
74
+ !/^[0-9]{1,20}$/.test(sequence) ||
75
+ BigInt(sequence) > BigInt(owner.trustSnapshot.rotationSequence))
76
+ throw cause;
77
+ }
68
78
  }
69
79
  }
70
80
  const verified = owner.trustForCredential(anchor);
package/caller.d.ts CHANGED
@@ -124,10 +124,24 @@ type StoreFacadeFor<TContract extends GeneratedCaller> = {
124
124
  export type CallerParticipant = GeneratedCaller;
125
125
  /** One selected caller action with its generated surface name resolved. */
126
126
  export type CallerSelectedAction<TContract extends GeneratedCaller> = SelectedAction<TContract>;
127
+ type MethodDocs<TContract> = TContract extends {
128
+ readonly __runtimeTypes?: {
129
+ readonly methods: infer TDocs;
130
+ };
131
+ } ? TDocs : Record<never, never>;
132
+ /**
133
+ * `TSurface` with the generated documentation of each of its methods.
134
+ *
135
+ * Facade method names come from key remapping, which drops JSDoc. Generated
136
+ * descriptors carry the docs under the final names with `unknown` members, so
137
+ * intersecting them leaves every signature as it is and gives editor hover the
138
+ * authored text.
139
+ */
140
+ export type DocumentedMethods<TSurface, TContract> = TSurface & Pick<MethodDocs<TContract>, Extract<keyof TSurface, keyof MethodDocs<TContract>>>;
127
141
  /**
128
142
  * Selected caller action methods, including selected event subscriptions.
129
143
  */
130
- export type CallerSelectedActionSurface<TContract extends GeneratedCaller> = UnionToIntersection<ActionRecord<CallerSelectedAction<TContract>>>;
144
+ export type CallerSelectedActionSurface<TContract extends GeneratedCaller> = DocumentedMethods<UnionToIntersection<ActionRecord<CallerSelectedAction<TContract>>>, TContract>;
131
145
  /**
132
146
  * Selected caller invocation and publish methods, excluding event
133
147
  * subscriptions.