@rotorsoft/act 1.33.6 → 1.33.7

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.
@@ -12,7 +12,7 @@
12
12
  * @internal
13
13
  */
14
14
  import { type DeferSchedule } from "../internal/defer-config.js";
15
- import type { Committed, EventRegister, LaneConfig, ReactionHandler, ReactionOptions, ReactionResolver, Schemas } from "../types/index.js";
15
+ import type { Committed, EventRegister, LaneConfig, Reaction, ReactionHandler, ReactionOptions, ReactionResolver, Schemas } from "../types/index.js";
16
16
  /**
17
17
  * Validate and register a drain lane, the one rule for `withLane` on an Act
18
18
  * or a slice and for the lanes a slice brings to `withSlice`, in any order.
@@ -24,6 +24,18 @@ import type { Committed, EventRegister, LaneConfig, ReactionHandler, ReactionOpt
24
24
  * @internal
25
25
  */
26
26
  export declare function register_lane(config: LaneConfig, lanes: LaneConfig[]): void;
27
+ /**
28
+ * Register a reaction once, keyed by its handler's name, and hand back
29
+ * `builder` patched with `.to(...)`, which reroutes the same reaction in
30
+ * place (no second `Map.set()`). The one registration step for reactions and
31
+ * projection handlers: the named-function and duplicate guards run before
32
+ * `make` builds the reaction, and `kind` picks the wording of their errors.
33
+ *
34
+ * @internal
35
+ */
36
+ export declare function add_reaction<TEvents extends Schemas, TKey extends keyof TEvents, TBuilder extends object>(events: EventRegister<TEvents>, event: TKey, name: string, kind: "Reaction" | "Projection", make: () => Reaction<TEvents, TKey>, builder: TBuilder): TBuilder & {
37
+ to(resolver: ReactionResolver<TEvents, TKey> | string): TBuilder;
38
+ };
27
39
  /**
28
40
  * Build the `.on(event)` step shared by both builders. Registers a reaction
29
41
  * (named-function + duplicate guards, fail-fast literal-schedule validation,
@@ -36,13 +48,13 @@ export declare function register_lane(config: LaneConfig, lanes: LaneConfig[]):
36
48
  *
37
49
  * @internal
38
50
  */
39
- export declare function reaction_on<TEvents extends Schemas, TKey extends keyof TEvents, TBuilder>(event: TKey, events: EventRegister<TEvents>, builder: TBuilder): {
40
- do: (handler: ReactionHandler<TEvents, TKey>, options?: Partial<ReactionOptions>) => object & {
41
- to(resolver: ReactionResolver<TEvents, TKey> | string): TBuilder;
51
+ export declare function reaction_on<TEvents extends Schemas, TKey extends keyof TEvents, TBuilder extends object>(event: TKey, events: EventRegister<TEvents>, builder: TBuilder): {
52
+ do: (handler: ReactionHandler<TEvents, TKey>, options?: Partial<ReactionOptions>) => TBuilder & {
53
+ to(resolver: string | ReactionResolver<TEvents, TKey>): TBuilder;
42
54
  };
43
55
  defer: (schedule: DeferSchedule<Committed<TEvents, TKey>>) => {
44
- do: (handler: ReactionHandler<TEvents, TKey>, options?: Partial<ReactionOptions>) => object & {
45
- to(resolver: ReactionResolver<TEvents, TKey> | string): TBuilder;
56
+ do: (handler: ReactionHandler<TEvents, TKey>, options?: Partial<ReactionOptions>) => TBuilder & {
57
+ to(resolver: string | ReactionResolver<TEvents, TKey>): TBuilder;
46
58
  };
47
59
  };
48
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"builder-utils.d.ts","sourceRoot":"","sources":["../../../src/builders/builder-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,UAAU,EAEV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,OAAO,EACR,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAc3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,OAAO,SAAS,OAAO,EACvB,IAAI,SAAS,MAAM,OAAO,EAC1B,QAAQ,EACR,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ;IA2C5D,EAAE,YACS,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M,EACvB,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ;IAgC5D,EAAE,YACS,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,YAC7B,OAAO,CAAC,eAAe,CAAC;;;IAEpC,KAAK,aAAa,aAAa,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACvD,EAAE,YACS,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,YAC7B,OAAO,CAAC,eAAe,CAAC;;;;EAIzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"projection-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/projection-builder.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EASV,OAAO,EAER,MAAM,mBAAmB,CAAC;AA8M3B;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,OAAO,GAAG,EAAE,EACrD,MAAM,EAAE,MAAM,GACb,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACtC;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,OAAO,GAAG,EAAE,EACrD,MAAM,CAAC,EAAE,SAAS,GACjB,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"projection-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/projection-builder.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAOV,OAAO,EAER,MAAM,mBAAmB,CAAC;AAgM3B;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,OAAO,GAAG,EAAE,EACrD,MAAM,EAAE,MAAM,GACb,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACtC;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,OAAO,GAAG,EAAE,EACrD,MAAM,CAAC,EAAE,SAAS,GACjB,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC"}
package/dist/index.cjs CHANGED
@@ -4308,37 +4308,49 @@ function register_lane(config2, lanes) {
4308
4308
  `Lane "${config2.name}" was already declared with a different config`
4309
4309
  );
4310
4310
  }
4311
+ function add_reaction(events, event, name, kind, make, builder) {
4312
+ if (!name)
4313
+ throw new Error(
4314
+ `${kind} handler for "${String(event)}" must be a named function`
4315
+ );
4316
+ const label = kind === "Reaction" ? "reaction" : "projection handler";
4317
+ if (events[event].reactions.has(name))
4318
+ throw new Error(
4319
+ `Duplicate ${label} "${name}" for event "${String(event)}". ${kind} handlers are keyed by function name; rename one of them.`
4320
+ );
4321
+ const reaction = make();
4322
+ events[event].reactions.set(name, reaction);
4323
+ return Object.assign(builder, {
4324
+ to(resolver) {
4325
+ reaction.resolver = typeof resolver === "string" ? { target: resolver } : resolver;
4326
+ return builder;
4327
+ }
4328
+ });
4329
+ }
4311
4330
  function reaction_on(event, events, builder) {
4312
- const register = (handler, options, schedule) => {
4313
- if (!handler.name)
4314
- throw new Error(
4315
- `Reaction handler for "${String(event)}" must be a named function`
4316
- );
4317
- if (events[event].reactions.has(handler.name))
4318
- throw new Error(
4319
- `Duplicate reaction "${handler.name}" for event "${String(event)}". Reaction handlers are keyed by function name; rename one of them.`
4320
- );
4321
- if (schedule && typeof schedule !== "function") assert_defer_when(schedule);
4322
- const reaction = {
4323
- handler: schedule ? make_deferred(handler, schedule) : handler,
4324
- resolver: _this_,
4325
- // Validate the whole bag at the declaration site so a bad
4326
- // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
4327
- // not a NaN gate on the first retry.
4328
- options: _chunkO6QIJQRNcjs.resolveReactionConfig.call(void 0, {
4329
- blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _155 => _155.blockOnError]), () => ( _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR)),
4330
- maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _156 => _156.maxRetries]), () => ( _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES)),
4331
- backoff: _optionalChain([options, 'optionalAccess', _157 => _157.backoff])
4332
- })
4333
- };
4334
- events[event].reactions.set(handler.name, reaction);
4335
- return Object.assign(builder, {
4336
- to(resolver) {
4337
- reaction.resolver = typeof resolver === "string" ? { target: resolver } : resolver;
4338
- return builder;
4339
- }
4340
- });
4341
- };
4331
+ const register = (handler, options, schedule) => add_reaction(
4332
+ events,
4333
+ event,
4334
+ handler.name,
4335
+ "Reaction",
4336
+ () => {
4337
+ if (schedule && typeof schedule !== "function")
4338
+ assert_defer_when(schedule);
4339
+ return {
4340
+ handler: schedule ? make_deferred(handler, schedule) : handler,
4341
+ resolver: _this_,
4342
+ // Validate the whole bag at the declaration site so a bad
4343
+ // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
4344
+ // not a NaN gate on the first retry.
4345
+ options: _chunkO6QIJQRNcjs.resolveReactionConfig.call(void 0, {
4346
+ blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _155 => _155.blockOnError]), () => ( _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR)),
4347
+ maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _156 => _156.maxRetries]), () => ( _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES)),
4348
+ backoff: _optionalChain([options, 'optionalAccess', _157 => _157.backoff])
4349
+ })
4350
+ };
4351
+ },
4352
+ builder
4353
+ );
4342
4354
  return {
4343
4355
  do: (handler, options) => register(handler, options),
4344
4356
  defer: (schedule) => ({
@@ -4767,31 +4779,22 @@ function _projection(target) {
4767
4779
  }
4768
4780
  return {
4769
4781
  do: (handler) => {
4770
- const reaction = {
4771
- handler,
4772
- resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
4773
- options: {
4774
- blockOnError: _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR,
4775
- maxRetries: _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES
4776
- }
4777
- };
4778
- const register = events[event];
4779
- if (!handler.name)
4780
- throw new Error(
4781
- `Projection handler for "${event}" must be a named function`
4782
- );
4783
- if (register.reactions.has(handler.name))
4784
- throw new Error(
4785
- `Duplicate projection handler "${handler.name}" for event "${event}". Projection handlers are keyed by function name; rename one of them.`
4786
- );
4787
- register.reactions.set(handler.name, reaction);
4788
4782
  const widened = base;
4789
- return Object.assign(widened, {
4790
- to(resolver) {
4791
- reaction.resolver = typeof resolver === "string" ? { target: resolver } : resolver;
4792
- return widened;
4793
- }
4794
- });
4783
+ return add_reaction(
4784
+ events,
4785
+ event,
4786
+ handler.name,
4787
+ "Projection",
4788
+ () => ({
4789
+ handler,
4790
+ resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
4791
+ options: {
4792
+ blockOnError: _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR,
4793
+ maxRetries: _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES
4794
+ }
4795
+ }),
4796
+ widened
4797
+ );
4795
4798
  }
4796
4799
  };
4797
4800
  },