swarm-deploy 0.3.1 → 0.4.2

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/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;;;;AAAA,yCAA0D;AAC1D,2CAAsD;AAqDtD,MAAM,uBAAuB,GAAG,IAAI,OAAO,EAA6B,CAAA;AACxE,MAAM,UAAU,GAAG,CAAC,cAAc,EAAE,aAAa,EAAE,WAAW,CAAU,CAAA;AAExE;;;;GAIG;AACH,uBAA8B,KAAqC;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACnE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,4BAAgB,CAAC,kBAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAA;IACtE,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAE,UAA2C,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACjE,MAAM,IAAI,4BAAgB,CAAC,kBAAM,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAgB,EAAE,CAAA;IAChC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAY,KAAK,CAAC,IAAI,CAAC,CAAA;QACrC,IAAI,QAAQ,KAAK,SAAS;YAAE,SAAQ;QACpC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,MAAM,IAAI,4BAAgB,CAAC,kBAAM,CAAC,gBAAgB,EAAE,WAAW,IAAI,OAAO,CAAC,CAAA;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CAAA;QAChB,OAAO;YACL,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;gBACtB,IAAI,MAAM,GAAG,GAAS,EAAE,GAAE,CAAC,CAAA;gBAC3B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAY,CAAC,OAAO,EAAE,EAAE;oBACjD,MAAM,GAAG,IAAA,kBAAO,EAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;gBACpD,CAAC,CAAC,CAAA;gBACF,IAAI,CAAC;oBACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;gBAC7E,CAAC;wBAAS,CAAC;oBACT,MAAM,EAAE,CAAA;gBACV,CAAC;YACH,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACZ,IAAI,IAAI;oBAAE,OAAM;gBAChB,IAAI,GAAG,IAAI,CAAA;gBACX,IAAI,EAAE,CAAA;gBACN,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;oBAClB,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI;wBAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBAC1D,CAAC,CAAC,CAAA;YACJ,CAAC;SACF,CAAA;IACH,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { ERRORS, SwarmDeployError, type ErrorCode } from './errors.js';
2
2
  export type { Binary, BinaryInput, Digest, FingerprintEvent, KeyPair, Logger, PublicKey, PublicKeyInput, Seed, SeedInput, ServerScheduler } from './types.js';
3
3
  export { parseSeed, parsePublicKey, generateSeed, keyPairFromSeed, publicKeyFromSeed } from './identity.js';
4
- export type { AfterCommitContext, BeforeCommitContext, HookArtifact, HookFailureContext, HookFailurePhase, ServerHooks } from './hooks.js';
4
+ export type { AfterCommitContext, AfterLinkContext, BeforeCommitContext, HookArtifact, HookFailureContext, HookFailurePhase, HookLink, HookLinkMode, HookLinkStatus, HookLinkTrigger, ServerHooks } from './hooks.js';
5
5
  export { fixedSeriesKey, type ReleaseCoordinates, type VersionGranularity } from './release.js';
6
6
  export { parseAllowlist } from './allowlist.js';
7
7
  export type { ArtifactKind } from './types.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAsE;AAA7D,mGAAA,MAAM,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAcjC,6CAMsB;AALpB,wGAAA,SAAS,OAAA;AACT,6GAAA,cAAc,OAAA;AACd,2GAAA,YAAY,OAAA;AACZ,8GAAA,eAAe,OAAA;AACf,gHAAA,iBAAiB,OAAA;AAUnB,2CAA+F;AAAtF,4GAAA,cAAc,OAAA;AACvB,+CAA+C;AAAtC,8GAAA,cAAc,OAAA;AAIvB,yCAgBoB;AAflB,mGAAA,MAAM,OAAA;AAgBR,yCAeoB;AAdlB,mGAAA,MAAM,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAsE;AAA7D,mGAAA,MAAM,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAcjC,6CAMsB;AALpB,wGAAA,SAAS,OAAA;AACT,6GAAA,cAAc,OAAA;AACd,2GAAA,YAAY,OAAA;AACZ,8GAAA,eAAe,OAAA;AACf,gHAAA,iBAAiB,OAAA;AAenB,2CAA+F;AAAtF,4GAAA,cAAc,OAAA;AACvB,+CAA+C;AAAtC,8GAAA,cAAc,OAAA;AAIvB,yCAgBoB;AAflB,mGAAA,MAAM,OAAA;AAgBR,yCAeoB;AAdlB,mGAAA,MAAM,OAAA"}
package/dist/server.d.ts CHANGED
@@ -16,7 +16,7 @@ declare const FINGERPRINT_LENGTH = 12;
16
16
  /**
17
17
  * How many transfers may owe a deferred post-commit retention pass at once.
18
18
  *
19
- * The set grows only when an `afterCommit` hook fails after a durable commit,
19
+ * The set grows only when an `afterCommit` or `afterLink` hook fails after a durable commit,
20
20
  * and entries are removed as soon as a retry succeeds, so reaching the bound
21
21
  * means a persistently failing hook. Capping it at the connection ceiling
22
22
  * keeps a broken deployment step from growing server memory without limit.
@@ -97,6 +97,12 @@ export interface ServerLinkEvent extends FingerprintEvent {
97
97
  name: string;
98
98
  status: 'linked' | 'unchanged' | 'rejected' | 'failed';
99
99
  reason?: ErrorCode;
100
+ /**
101
+ * The durable link outcome when it already applied before the request
102
+ * failed: `failed` with reason `HOOK_FAILED` means the link did change (or
103
+ * already matched) and only its `afterLink` hook failed.
104
+ */
105
+ result?: 'LINKED' | 'UNCHANGED';
100
106
  }
101
107
  export interface ServerEventMap {
102
108
  authentication: AuthenticationEvent;
@@ -164,7 +170,7 @@ export declare class Server extends EventEmitter {
164
170
  private readonly activeUploads;
165
171
  /**
166
172
  * Transfer IDs this process committed but whose deferred post-commit
167
- * retention is still owed because `afterCommit` has not yet succeeded. Only
173
+ * retention is still owed because `afterCommit` or `afterLink` has not yet succeeded. Only
168
174
  * these may start a retention pass from an already-committed retry, so an
169
175
  * ordinary duplicate offer cannot be used to force repeated full passes.
170
176
  * The set is in-memory only and bounded by `MAX_OWED_POST_COMMIT_RETENTION`;
@@ -180,6 +186,13 @@ export declare class Server extends EventEmitter {
180
186
  * and its hooks concurrently against one staging and commit identity.
181
187
  */
182
188
  private readonly activeTransfers;
189
+ /**
190
+ * One first-in, first-out line of `afterLink` calls per link name. A place is
191
+ * reserved while the root lease orders the link decision, and the hook runs
192
+ * after the lease is released, so a link's hooks start in decision order
193
+ * and never overlap, while hook code never runs under the lease.
194
+ */
195
+ private readonly linkHookTurns;
183
196
  private readonly receives;
184
197
  private layout;
185
198
  private sessions;
@@ -198,18 +211,45 @@ export declare class Server extends EventEmitter {
198
211
  private transfer;
199
212
  private rejectOffer;
200
213
  private hookArtifact;
214
+ /** Describes a durably committed artifact from its commit record, as a link hook sees it. */
215
+ private recordArtifact;
216
+ private hookLink;
201
217
  /**
202
218
  * Computes and converges the desired links from durable commit records.
203
219
  * Called with the root lease already held.
204
220
  */
221
+ private convergeLinksUnlocked;
205
222
  private reconcileLinksUnlocked;
206
223
  /** Pins link targets when reconciliation fails but retention must continue. */
207
224
  private linkPinsFallbackUnlocked;
208
- /** Reconciles after a durable commit; this is the only caller that leases the root. */
225
+ /**
226
+ * Reconciles after a durable commit; this is the only caller that leases the
227
+ * root for it. When an `afterLink` hook is configured it also returns one
228
+ * pending call for every automatic link that now designates `artifact`,
229
+ * whether this reconcile changed it or an earlier attempt already had, so a
230
+ * retry re-runs a hook that failed. The caller owns the returned places in
231
+ * the hook lines and must release them.
232
+ */
209
233
  private reconcileAfterCommit;
234
+ /**
235
+ * Runs pending `afterLink` calls one after another, each once every earlier
236
+ * hook for its link has finished. No storage lease is held while hook code
237
+ * runs. `begin` is told which call is starting so a caller can attribute a
238
+ * failure. The first failure stops the rest; the caller releases the places.
239
+ */
240
+ private runLinkHooks;
210
241
  private setManagedLinkNames;
211
242
  private refreshManagedLinkNames;
212
243
  private receiveLink;
244
+ /**
245
+ * Closes a connection after its `HOOK_FAILED` answer was written. Destroying
246
+ * the stream right behind the write can reset it before the peer has read the
247
+ * record, so the caller would see a reset instead of the stable code. The
248
+ * write side is ended first and the connection is destroyed once the peer
249
+ * closes it, or after a grace period if it never does. The work that failed
250
+ * is already durable, so lingering costs only the connection.
251
+ */
252
+ private closeAfterAnswer;
213
253
  /** Runs a gating callback; only callback exceptions become HOOK_FAILED. */
214
254
  private runHook;
215
255
  /** Runs onFailure once; its own failure is logged and never replaces the original. */
@@ -226,11 +266,21 @@ export declare class Server extends EventEmitter {
226
266
  */
227
267
  private owePostCommitRetention;
228
268
  /**
229
- * Runs the post-commit retention pass that a configured `afterCommit` hook
230
- * deferred, only after that hook succeeded, and then stops owing it. The
231
- * retention manager already reports its own failures as non-fatal, so
232
- * nothing here can fail the upload; the pass is attempted exactly once per
233
- * successful hook, which is why the transfer is cleared either way.
269
+ * Whether the post-commit retention pass waits for the hooks that follow a
270
+ * commit. Either one defers it: `afterCommit` so its callback still finds
271
+ * the artifact, and `afterLink` so this commit's own link reconciliation runs
272
+ * before this commit's retention pass does. That narrows, but does not remove,
273
+ * the chance that the link already moved: another commit's retention or
274
+ * reconciliation can do it first, and the hook then sees `UNCHANGED`.
275
+ */
276
+ private defersPostCommitRetention;
277
+ /**
278
+ * Runs the post-commit retention pass that configured `afterCommit` or
279
+ * `afterLink` hooks deferred, only after they succeeded, and then stops
280
+ * owing it. The retention manager already reports its own failures as
281
+ * non-fatal, so nothing here can fail the upload; the pass is attempted
282
+ * exactly once per successful hook run, which is why the transfer is cleared
283
+ * either way.
234
284
  */
235
285
  private settleDeferredRetention;
236
286
  /**