@entifix/transactions 0.4.1 → 0.5.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.
package/README.md CHANGED
@@ -12,9 +12,10 @@ pnpm add @entifix/transactions effect
12
12
 
13
13
  ## Entry points
14
14
 
15
- | Import | What it holds |
16
- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
- | `@entifix/transactions` | Command envelopes, transaction events, inbox / outbox / event-bus / lock / sequence ports, `defineSaga`, `runSaga`, `resumeSaga`, `resumeStaleSagas` / `startSagaResume`, `makeLocalSagaDispatcher` for a saga whose participants live in one service, the transaction stream hub |
15
+ | Import | What it holds |
16
+ | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
+ | `@entifix/transactions` | Command envelopes, transaction events, inbox / outbox / event-bus / lock / sequence / saga ports, `defineSaga`, the facade use case, `TransactionStreamHubTag` |
18
+ | `@entifix/transactions/engine` | The mechanism behind those ports: `runSaga`, `resumeSaga`, `resumeStaleSagas` / `startSagaResume`, `acceptTransaction` / `completeTransaction`, `makeLocalSagaDispatcher`, the stream hub's factories |
18
19
 
19
20
  ---
20
21
 
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The mechanism behind `@entifix/transactions`' ports: the saga runner and its
3
+ * resume sweep, the single-step transaction engine, the in-process dispatcher
4
+ * and the stream hub.
5
+ *
6
+ * A subpath rather than part of `.` although it installs nothing `.` does not,
7
+ * because a consumer that writes against the contracts — a cell, a route, a
8
+ * participant — must be able to ban the engine by name, and a ban matches a
9
+ * specifier (ADR 0006).
10
+ */
11
+ export * from '../stream/transaction-stream-hub.js';
12
+ export * from './local-saga-dispatcher.js';
13
+ export * from './resolve-template.js';
14
+ export * from './resume-sweep.js';
15
+ export * from './run-saga.js';
16
+ export * from './run-transaction.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The mechanism behind `@entifix/transactions`' ports: the saga runner and its
3
+ * resume sweep, the single-step transaction engine, the in-process dispatcher
4
+ * and the stream hub.
5
+ *
6
+ * A subpath rather than part of `.` although it installs nothing `.` does not,
7
+ * because a consumer that writes against the contracts — a cell, a route, a
8
+ * participant — must be able to ban the engine by name, and a ban matches a
9
+ * specifier (ADR 0006).
10
+ */ export * from '../stream/transaction-stream-hub.js';
11
+ export * from './local-saga-dispatcher.js';
12
+ export * from './resolve-template.js';
13
+ export * from './resume-sweep.js';
14
+ export * from './run-saga.js';
15
+ export * from './run-transaction.js';
16
+
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/engine/index.ts"],"sourcesContent":["/**\n * The mechanism behind `@entifix/transactions`' ports: the saga runner and its\n * resume sweep, the single-step transaction engine, the in-process dispatcher\n * and the stream hub.\n *\n * A subpath rather than part of `.` although it installs nothing `.` does not,\n * because a consumer that writes against the contracts — a cell, a route, a\n * participant — must be able to ban the engine by name, and a ban matches a\n * specifier (ADR 0006).\n */\nexport * from '../stream/transaction-stream-hub.js';\nexport * from './local-saga-dispatcher.js';\nexport * from './resolve-template.js';\nexport * from './resume-sweep.js';\nexport * from './run-saga.js';\nexport * from './run-transaction.js';\n"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GACD,cAAc,sCAAsC;AACpD,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,uBAAuB"}
package/dist/index.d.ts CHANGED
@@ -4,11 +4,6 @@ export * from './contracts/inbox.js';
4
4
  export * from './contracts/outbox.js';
5
5
  export * from './contracts/record.js';
6
6
  export * from './contracts/saga-definition.js';
7
- export * from './engine/local-saga-dispatcher.js';
8
- export * from './engine/resolve-template.js';
9
- export * from './engine/resume-sweep.js';
10
- export * from './engine/run-saga.js';
11
- export * from './engine/run-transaction.js';
12
7
  export * from './mixins/transaction-mixins.js';
13
8
  export * from './ports/event-bus.js';
14
9
  export * from './ports/event-source.js';
@@ -18,6 +13,6 @@ export * from './ports/saga-store.js';
18
13
  export * from './ports/sequence-service.js';
19
14
  export * from './ports/transaction-handler.js';
20
15
  export * from './ports/transaction-sink.js';
21
- export * from './stream/transaction-stream-hub.js';
16
+ export * from './ports/transaction-stream-hub.js';
22
17
  export * from './use-case/facade.uc.js';
23
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -4,11 +4,6 @@ export * from './contracts/inbox.js';
4
4
  export * from './contracts/outbox.js';
5
5
  export * from './contracts/record.js';
6
6
  export * from './contracts/saga-definition.js';
7
- export * from './engine/local-saga-dispatcher.js';
8
- export * from './engine/resolve-template.js';
9
- export * from './engine/resume-sweep.js';
10
- export * from './engine/run-saga.js';
11
- export * from './engine/run-transaction.js';
12
7
  export * from './mixins/transaction-mixins.js';
13
8
  export * from './ports/event-bus.js';
14
9
  export * from './ports/event-source.js';
@@ -18,7 +13,7 @@ export * from './ports/saga-store.js';
18
13
  export * from './ports/sequence-service.js';
19
14
  export * from './ports/transaction-handler.js';
20
15
  export * from './ports/transaction-sink.js';
21
- export * from './stream/transaction-stream-hub.js';
16
+ export * from './ports/transaction-stream-hub.js';
22
17
  export * from './use-case/facade.uc.js';
23
18
 
24
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './engine/local-saga-dispatcher.js';\nexport * from './engine/resolve-template.js';\nexport * from './engine/resume-sweep.js';\nexport * from './engine/run-saga.js';\nexport * from './engine/run-transaction.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './stream/transaction-stream-hub.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,oCAAoC;AAClD,cAAc,+BAA+B;AAC7C,cAAc,2BAA2B;AACzC,cAAc,uBAAuB;AACrC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,qCAAqC;AACnD,cAAc,0BAA0B"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './contracts/command.js';\nexport * from './contracts/event.js';\nexport * from './contracts/inbox.js';\nexport * from './contracts/outbox.js';\nexport * from './contracts/record.js';\nexport * from './contracts/saga-definition.js';\nexport * from './mixins/transaction-mixins.js';\nexport * from './ports/event-bus.js';\nexport * from './ports/event-source.js';\nexport * from './ports/lock-service.js';\nexport * from './ports/saga-dispatcher.js';\nexport * from './ports/saga-store.js';\nexport * from './ports/sequence-service.js';\nexport * from './ports/transaction-handler.js';\nexport * from './ports/transaction-sink.js';\nexport * from './ports/transaction-stream-hub.js';\nexport * from './use-case/facade.uc.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,iCAAiC;AAC/C,cAAc,iCAAiC;AAC/C,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,wBAAwB;AACtC,cAAc,8BAA8B;AAC5C,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,0BAA0B"}
@@ -0,0 +1,28 @@
1
+ import type { DomainEvent, EntityChangeEvent } from '@entifix/core';
2
+ import { Context, type Effect, type Stream } from 'effect';
3
+ import type { TransactionEvent } from '../contracts/event.js';
4
+ /**
5
+ * The in-process fan-out behind `GET /api/transaction/events`.
6
+ *
7
+ * One subscription to the bus feeds it; each connected browser takes its own
8
+ * filtered view. It is a hub rather than a bus subscription per connection
9
+ * because a queue per open tab is a broker resource a client controls.
10
+ */
11
+ export interface TransactionStreamHub {
12
+ /** Offer one bus event to every connection scoped to its organization. */
13
+ publish(event: DomainEvent<TransactionEvent>): Effect.Effect<void>;
14
+ /**
15
+ * One connection's view, already scoped and already mapped.
16
+ *
17
+ * ⚠️ **Fails closed.** An event whose `organizationId` does not match is
18
+ * dropped, and so is one carrying none at all — including every event emitted
19
+ * before that member existed. Defaulting an absent organization to "everyone"
20
+ * is a cross-tenant delivery that raises nothing.
21
+ */
22
+ subscribe(organizationId: string): Stream.Stream<DomainEvent<EntityChangeEvent>>;
23
+ }
24
+ declare const TransactionStreamHubTag_base: Context.ServiceClass<TransactionStreamHubTag, "TransactionStreamHubTag", TransactionStreamHub>;
25
+ export declare class TransactionStreamHubTag extends TransactionStreamHubTag_base {
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=transaction-stream-hub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-stream-hub.d.ts","sourceRoot":"","sources":["../../src/ports/transaction-stream-hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnE;;;;;;;OAOG;IACH,SAAS,CACP,cAAc,EAAE,MAAM,GACrB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC;CAClD;;AAED,qBAAa,uBAAwB,SAAQ,4BAGf;CAAG"}
@@ -0,0 +1,5 @@
1
+ import { Context } from 'effect';
2
+ export class TransactionStreamHubTag extends Context.Service()('TransactionStreamHubTag') {
3
+ }
4
+
5
+ //# sourceMappingURL=transaction-stream-hub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ports/transaction-stream-hub.ts"],"sourcesContent":["import type { DomainEvent, EntityChangeEvent } from '@entifix/core';\nimport { Context, type Effect, type Stream } from 'effect';\n\nimport type { TransactionEvent } from '../contracts/event.js';\n\n/**\n * The in-process fan-out behind `GET /api/transaction/events`.\n *\n * One subscription to the bus feeds it; each connected browser takes its own\n * filtered view. It is a hub rather than a bus subscription per connection\n * because a queue per open tab is a broker resource a client controls.\n */\nexport interface TransactionStreamHub {\n /** Offer one bus event to every connection scoped to its organization. */\n publish(event: DomainEvent<TransactionEvent>): Effect.Effect<void>;\n /**\n * One connection's view, already scoped and already mapped.\n *\n * ⚠️ **Fails closed.** An event whose `organizationId` does not match is\n * dropped, and so is one carrying none at all — including every event emitted\n * before that member existed. Defaulting an absent organization to \"everyone\"\n * is a cross-tenant delivery that raises nothing.\n */\n subscribe(\n organizationId: string,\n ): Stream.Stream<DomainEvent<EntityChangeEvent>>;\n}\n\nexport class TransactionStreamHubTag extends Context.Service<\n TransactionStreamHubTag,\n TransactionStreamHub\n>()('TransactionStreamHubTag') {}\n"],"names":["Context","TransactionStreamHubTag","Service"],"mappings":"AACA,SAASA,OAAO,QAAkC,SAAS;AA2B3D,OAAO,MAAMC,gCAAgCD,QAAQE,OAAO,GAGxD;AAA4B"}
@@ -1,6 +1,7 @@
1
1
  import type { DomainEvent, EntityChangeEvent } from '@entifix/core';
2
- import { Context, Effect, PubSub, Stream } from 'effect';
2
+ import { Effect, PubSub } from 'effect';
3
3
  import type { TransactionEvent } from '../contracts/event.js';
4
+ import type { TransactionStreamHub } from '../ports/transaction-stream-hub.js';
4
5
  /**
5
6
  * Rewrites a transaction event as the entity change it announces, keeping the
6
7
  * message's own metadata untouched.
@@ -10,32 +11,8 @@ import type { TransactionEvent } from '../contracts/event.js';
10
11
  * `.at` and `.id` on the message this returns (ADR 0036).
11
12
  */
12
13
  export declare const entityChangeFor: (event: DomainEvent<TransactionEvent>) => DomainEvent<EntityChangeEvent>;
13
- /**
14
- * The in-process fan-out behind `GET /api/transaction/events`.
15
- *
16
- * One subscription to the bus feeds it; each connected browser takes its own
17
- * filtered view. It is a hub rather than a bus subscription per connection
18
- * because a queue per open tab is a broker resource a client controls.
19
- */
20
- export interface TransactionStreamHub {
21
- /** Offer one bus event to every connection scoped to its organization. */
22
- publish(event: DomainEvent<TransactionEvent>): Effect.Effect<void>;
23
- /**
24
- * One connection's view, already scoped and already mapped.
25
- *
26
- * ⚠️ **Fails closed.** An event whose `organizationId` does not match is
27
- * dropped, and so is one carrying none at all — including every event emitted
28
- * before that member existed. Defaulting an absent organization to "everyone"
29
- * is a cross-tenant delivery that raises nothing.
30
- */
31
- subscribe(organizationId: string): Stream.Stream<DomainEvent<EntityChangeEvent>>;
32
- }
33
- declare const TransactionStreamHubTag_base: Context.ServiceClass<TransactionStreamHubTag, "TransactionStreamHubTag", TransactionStreamHub>;
34
- export declare class TransactionStreamHubTag extends TransactionStreamHubTag_base {
35
- }
36
14
  /** Builds a hub over a sliding {@link PubSub}. */
37
15
  export declare const makeTransactionStreamHub: (pubsub: PubSub.PubSub<DomainEvent<TransactionEvent>>) => TransactionStreamHub;
38
16
  /** Opens a hub. Scoped, so its subscribers are released with the scope. */
39
17
  export declare const makeTransactionStreamHubEffect: Effect.Effect<TransactionStreamHub, never, never>;
40
- export {};
41
18
  //# sourceMappingURL=transaction-stream-hub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-stream-hub.d.ts","sourceRoot":"","sources":["../../src/stream/transaction-stream-hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,uBAAuB,CAAC;AA4BhF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,WAAW,CAAC,gBAAgB,CAAC,KACnC,WAAW,CAAC,iBAAiB,CAW9B,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnE;;;;;;;OAOG;IACH,SAAS,CACP,cAAc,EAAE,MAAM,GACrB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC;CAClD;;AAED,qBAAa,uBAAwB,SAAQ,4BAGf;CAAG;AAEjC,kDAAkD;AAClD,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,KACnD,oBAOD,CAAC;AAEH,2EAA2E;AAC3E,eAAO,MAAM,8BAA8B,mDAG1C,CAAC"}
1
+ {"version":3,"file":"transaction-stream-hub.d.ts","sourceRoot":"","sources":["../../src/stream/transaction-stream-hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AA4B/E;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,WAAW,CAAC,gBAAgB,CAAC,KACnC,WAAW,CAAC,iBAAiB,CAW9B,CAAC;AAEH,kDAAkD;AAClD,eAAO,MAAM,wBAAwB,GACnC,QAAQ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,KACnD,oBAOD,CAAC;AAEH,2EAA2E;AAC3E,eAAO,MAAM,8BAA8B,mDAG1C,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Context, Effect, PubSub, Stream } from 'effect';
1
+ import { Effect, PubSub, Stream } from 'effect';
2
2
  /**
3
3
  * How many undelivered events one hub holds before the oldest are dropped.
4
4
  *
@@ -42,8 +42,6 @@ import { Context, Effect, PubSub, Stream } from 'effect';
42
42
  }
43
43
  };
44
44
  };
45
- export class TransactionStreamHubTag extends Context.Service()('TransactionStreamHubTag') {
46
- }
47
45
  /** Builds a hub over a sliding {@link PubSub}. */ export const makeTransactionStreamHub = (pubsub)=>({
48
46
  publish: (event)=>Effect.asVoid(PubSub.publish(pubsub, event)),
49
47
  subscribe: (organizationId)=>Stream.fromPubSub(pubsub).pipe(Stream.filter((event)=>event.data.organizationId === organizationId), Stream.map(entityChangeFor))
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stream/transaction-stream-hub.ts"],"sourcesContent":["import type { DomainEvent, EntityChangeEvent } from '@entifix/core';\nimport { Context, Effect, PubSub, Stream } from 'effect';\n\nimport type { TransactionEvent, TransactionState } from '../contracts/event.js';\n\n/**\n * How many undelivered events one hub holds before the oldest are dropped.\n *\n * Bounded with a **sliding** strategy rather than unbounded: a browser that\n * stops reading its connection must not be able to grow the service's heap, and\n * a reactive hint is worth less the older it is — the record behind it is the\n * truth, and re-reading it is cheap (ADR 0036 declines replay for the same\n * reason).\n */\nconst CAPACITY = 256;\n\n/**\n * What a transaction's state means for the entity it is about.\n *\n * `type: 'create'` is the only command that exists, so `PENDING` and\n * `COMPLETED` both announce an entity coming into existence — the id is already\n * known at `accepted`, because ADR 0028 makes the client-minted transaction id\n * the stored entity's id. A terminal failure announces the opposite: nothing was\n * written, so a consumer holding an optimistic row must drop it.\n *\n * When `update`/`delete` commands land this keys off `command.type` instead;\n * the state alone cannot distinguish them.\n */\nconst changeFor = (state: TransactionState): EntityChangeEvent['change'] =>\n state === 'PENDING' || state === 'COMPLETED' ? 'created' : 'deleted';\n\n/**\n * Rewrites a transaction event as the entity change it announces, keeping the\n * message's own metadata untouched.\n *\n * No fourth framing and no duplicated fields: the transaction id, the timestamp\n * and the sequence a consumer needs are already `meta.event.correlationId`,\n * `.at` and `.id` on the message this returns (ADR 0036).\n */\nexport const entityChangeFor = (\n event: DomainEvent<TransactionEvent>,\n): DomainEvent<EntityChangeEvent> => ({\n name: event.name,\n id: event.id,\n source: event.source,\n at: event.at,\n correlationId: event.correlationId,\n data: {\n entity: event.data.entity,\n change: changeFor(event.data.state),\n id: event.data.entityId ?? event.data.transactionId,\n },\n});\n\n/**\n * The in-process fan-out behind `GET /api/transaction/events`.\n *\n * One subscription to the bus feeds it; each connected browser takes its own\n * filtered view. It is a hub rather than a bus subscription per connection\n * because a queue per open tab is a broker resource a client controls.\n */\nexport interface TransactionStreamHub {\n /** Offer one bus event to every connection scoped to its organization. */\n publish(event: DomainEvent<TransactionEvent>): Effect.Effect<void>;\n /**\n * One connection's view, already scoped and already mapped.\n *\n * ⚠️ **Fails closed.** An event whose `organizationId` does not match is\n * dropped, and so is one carrying none at all — including every event emitted\n * before that member existed. Defaulting an absent organization to \"everyone\"\n * is a cross-tenant delivery that raises nothing.\n */\n subscribe(\n organizationId: string,\n ): Stream.Stream<DomainEvent<EntityChangeEvent>>;\n}\n\nexport class TransactionStreamHubTag extends Context.Service<\n TransactionStreamHubTag,\n TransactionStreamHub\n>()('TransactionStreamHubTag') {}\n\n/** Builds a hub over a sliding {@link PubSub}. */\nexport const makeTransactionStreamHub = (\n pubsub: PubSub.PubSub<DomainEvent<TransactionEvent>>,\n): TransactionStreamHub => ({\n publish: event => Effect.asVoid(PubSub.publish(pubsub, event)),\n subscribe: organizationId =>\n Stream.fromPubSub(pubsub).pipe(\n Stream.filter(event => event.data.organizationId === organizationId),\n Stream.map(entityChangeFor),\n ),\n});\n\n/** Opens a hub. Scoped, so its subscribers are released with the scope. */\nexport const makeTransactionStreamHubEffect = Effect.map(\n PubSub.sliding<DomainEvent<TransactionEvent>>(CAPACITY),\n makeTransactionStreamHub,\n);\n"],"names":["Context","Effect","PubSub","Stream","CAPACITY","changeFor","state","entityChangeFor","event","name","id","source","at","correlationId","data","entity","change","entityId","transactionId","TransactionStreamHubTag","Service","makeTransactionStreamHub","pubsub","publish","asVoid","subscribe","organizationId","fromPubSub","pipe","filter","map","makeTransactionStreamHubEffect","sliding"],"mappings":"AACA,SAASA,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAIzD;;;;;;;;CAQC,GACD,MAAMC,WAAW;AAEjB;;;;;;;;;;;CAWC,GACD,MAAMC,YAAY,CAACC,QACjBA,UAAU,aAAaA,UAAU,cAAc,YAAY;AAE7D;;;;;;;CAOC,GACD,OAAO,MAAMC,kBAAkB,CAC7BC;QAUMA;WAT8B;QACpCC,MAAMD,MAAMC,IAAI;QAChBC,IAAIF,MAAME,EAAE;QACZC,QAAQH,MAAMG,MAAM;QACpBC,IAAIJ,MAAMI,EAAE;QACZC,eAAeL,MAAMK,aAAa;QAClCC,MAAM;YACJC,QAAQP,MAAMM,IAAI,CAACC,MAAM;YACzBC,QAAQX,UAAUG,MAAMM,IAAI,CAACR,KAAK;YAClCI,EAAE,GAAEF,uBAAAA,MAAMM,IAAI,CAACG,QAAQ,YAAnBT,uBAAuBA,MAAMM,IAAI,CAACI,aAAa;QACrD;IACF;EAAG;AAyBH,OAAO,MAAMC,gCAAgCnB,QAAQoB,OAAO,GAGxD;AAA4B;AAEhC,gDAAgD,GAChD,OAAO,MAAMC,2BAA2B,CACtCC,SAC0B,CAAA;QAC1BC,SAASf,CAAAA,QAASP,OAAOuB,MAAM,CAACtB,OAAOqB,OAAO,CAACD,QAAQd;QACvDiB,WAAWC,CAAAA,iBACTvB,OAAOwB,UAAU,CAACL,QAAQM,IAAI,CAC5BzB,OAAO0B,MAAM,CAACrB,CAAAA,QAASA,MAAMM,IAAI,CAACY,cAAc,KAAKA,iBACrDvB,OAAO2B,GAAG,CAACvB;IAEjB,CAAA,EAAG;AAEH,yEAAyE,GACzE,OAAO,MAAMwB,iCAAiC9B,OAAO6B,GAAG,CACtD5B,OAAO8B,OAAO,CAAgC5B,WAC9CiB,0BACA"}
1
+ {"version":3,"sources":["../../src/stream/transaction-stream-hub.ts"],"sourcesContent":["import type { DomainEvent, EntityChangeEvent } from '@entifix/core';\nimport { Effect, PubSub, Stream } from 'effect';\n\nimport type { TransactionEvent, TransactionState } from '../contracts/event.js';\nimport type { TransactionStreamHub } from '../ports/transaction-stream-hub.js';\n\n/**\n * How many undelivered events one hub holds before the oldest are dropped.\n *\n * Bounded with a **sliding** strategy rather than unbounded: a browser that\n * stops reading its connection must not be able to grow the service's heap, and\n * a reactive hint is worth less the older it is — the record behind it is the\n * truth, and re-reading it is cheap (ADR 0036 declines replay for the same\n * reason).\n */\nconst CAPACITY = 256;\n\n/**\n * What a transaction's state means for the entity it is about.\n *\n * `type: 'create'` is the only command that exists, so `PENDING` and\n * `COMPLETED` both announce an entity coming into existence — the id is already\n * known at `accepted`, because ADR 0028 makes the client-minted transaction id\n * the stored entity's id. A terminal failure announces the opposite: nothing was\n * written, so a consumer holding an optimistic row must drop it.\n *\n * When `update`/`delete` commands land this keys off `command.type` instead;\n * the state alone cannot distinguish them.\n */\nconst changeFor = (state: TransactionState): EntityChangeEvent['change'] =>\n state === 'PENDING' || state === 'COMPLETED' ? 'created' : 'deleted';\n\n/**\n * Rewrites a transaction event as the entity change it announces, keeping the\n * message's own metadata untouched.\n *\n * No fourth framing and no duplicated fields: the transaction id, the timestamp\n * and the sequence a consumer needs are already `meta.event.correlationId`,\n * `.at` and `.id` on the message this returns (ADR 0036).\n */\nexport const entityChangeFor = (\n event: DomainEvent<TransactionEvent>,\n): DomainEvent<EntityChangeEvent> => ({\n name: event.name,\n id: event.id,\n source: event.source,\n at: event.at,\n correlationId: event.correlationId,\n data: {\n entity: event.data.entity,\n change: changeFor(event.data.state),\n id: event.data.entityId ?? event.data.transactionId,\n },\n});\n\n/** Builds a hub over a sliding {@link PubSub}. */\nexport const makeTransactionStreamHub = (\n pubsub: PubSub.PubSub<DomainEvent<TransactionEvent>>,\n): TransactionStreamHub => ({\n publish: event => Effect.asVoid(PubSub.publish(pubsub, event)),\n subscribe: organizationId =>\n Stream.fromPubSub(pubsub).pipe(\n Stream.filter(event => event.data.organizationId === organizationId),\n Stream.map(entityChangeFor),\n ),\n});\n\n/** Opens a hub. Scoped, so its subscribers are released with the scope. */\nexport const makeTransactionStreamHubEffect = Effect.map(\n PubSub.sliding<DomainEvent<TransactionEvent>>(CAPACITY),\n makeTransactionStreamHub,\n);\n"],"names":["Effect","PubSub","Stream","CAPACITY","changeFor","state","entityChangeFor","event","name","id","source","at","correlationId","data","entity","change","entityId","transactionId","makeTransactionStreamHub","pubsub","publish","asVoid","subscribe","organizationId","fromPubSub","pipe","filter","map","makeTransactionStreamHubEffect","sliding"],"mappings":"AACA,SAASA,MAAM,EAAEC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAKhD;;;;;;;;CAQC,GACD,MAAMC,WAAW;AAEjB;;;;;;;;;;;CAWC,GACD,MAAMC,YAAY,CAACC,QACjBA,UAAU,aAAaA,UAAU,cAAc,YAAY;AAE7D;;;;;;;CAOC,GACD,OAAO,MAAMC,kBAAkB,CAC7BC;QAUMA;WAT8B;QACpCC,MAAMD,MAAMC,IAAI;QAChBC,IAAIF,MAAME,EAAE;QACZC,QAAQH,MAAMG,MAAM;QACpBC,IAAIJ,MAAMI,EAAE;QACZC,eAAeL,MAAMK,aAAa;QAClCC,MAAM;YACJC,QAAQP,MAAMM,IAAI,CAACC,MAAM;YACzBC,QAAQX,UAAUG,MAAMM,IAAI,CAACR,KAAK;YAClCI,EAAE,GAAEF,uBAAAA,MAAMM,IAAI,CAACG,QAAQ,YAAnBT,uBAAuBA,MAAMM,IAAI,CAACI,aAAa;QACrD;IACF;EAAG;AAEH,gDAAgD,GAChD,OAAO,MAAMC,2BAA2B,CACtCC,SAC0B,CAAA;QAC1BC,SAASb,CAAAA,QAASP,OAAOqB,MAAM,CAACpB,OAAOmB,OAAO,CAACD,QAAQZ;QACvDe,WAAWC,CAAAA,iBACTrB,OAAOsB,UAAU,CAACL,QAAQM,IAAI,CAC5BvB,OAAOwB,MAAM,CAACnB,CAAAA,QAASA,MAAMM,IAAI,CAACU,cAAc,KAAKA,iBACrDrB,OAAOyB,GAAG,CAACrB;IAEjB,CAAA,EAAG;AAEH,yEAAyE,GACzE,OAAO,MAAMsB,iCAAiC5B,OAAO2B,GAAG,CACtD1B,OAAO4B,OAAO,CAAgC1B,WAC9Ce,0BACA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/transactions",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Commands, transactions and sagas: inbox and outbox ports, an event bus, locks, and a declarative saga runner.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,6 +21,11 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "import": "./dist/index.js",
23
23
  "default": "./dist/index.js"
24
+ },
25
+ "./engine": {
26
+ "types": "./dist/engine/index.d.ts",
27
+ "import": "./dist/engine/index.js",
28
+ "default": "./dist/engine/index.js"
24
29
  }
25
30
  },
26
31
  "files": [
@@ -51,8 +56,8 @@
51
56
  },
52
57
  "dependencies": {
53
58
  "@swc/helpers": "0.5.23",
54
- "@entifix/business": "0.4.1",
55
- "@entifix/core": "0.4.1"
59
+ "@entifix/business": "0.5.0",
60
+ "@entifix/core": "0.5.0"
56
61
  },
57
62
  "peerDependencies": {
58
63
  "effect": "^4.0.5"