@geekmidas/constructs 10.0.0-alpha.122 → 10.0.0-alpha.124

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 (55) hide show
  1. package/dist/ObjectSubscriberBuilder-B4j3zgCZ.d.cts +129 -0
  2. package/dist/ObjectSubscriberBuilder-B4j3zgCZ.d.cts.map +1 -0
  3. package/dist/ObjectSubscriberBuilder-C0WUU-ov.d.mts +129 -0
  4. package/dist/ObjectSubscriberBuilder-C0WUU-ov.d.mts.map +1 -0
  5. package/dist/{Subscriber-CEt7kHkc.d.cts → Subscriber-Bfw5cqzz.d.cts} +13 -1
  6. package/dist/{Subscriber-CEt7kHkc.d.cts.map → Subscriber-Bfw5cqzz.d.cts.map} +1 -1
  7. package/dist/{Subscriber-dsxc5LKa.d.mts → Subscriber-Czs77h-H.d.mts} +13 -1
  8. package/dist/{Subscriber-dsxc5LKa.d.mts.map → Subscriber-Czs77h-H.d.mts.map} +1 -1
  9. package/dist/{SubscriberBuilder-M2EAgQhC.cjs → SubscriberBuilder-CYluzubx.cjs} +109 -1
  10. package/dist/SubscriberBuilder-CYluzubx.cjs.map +1 -0
  11. package/dist/{SubscriberBuilder-DRXfxWn_.mjs → SubscriberBuilder-DUMXzjbR.mjs} +98 -2
  12. package/dist/SubscriberBuilder-DUMXzjbR.mjs.map +1 -0
  13. package/dist/adaptors/aws.cjs +2 -2
  14. package/dist/adaptors/aws.cjs.map +1 -1
  15. package/dist/adaptors/aws.d.cts +1 -1
  16. package/dist/adaptors/aws.d.mts +1 -1
  17. package/dist/adaptors/aws.mjs +2 -2
  18. package/dist/adaptors/aws.mjs.map +1 -1
  19. package/dist/adaptors/testing.cjs +109 -2
  20. package/dist/adaptors/testing.cjs.map +1 -1
  21. package/dist/adaptors/testing.d.cts +22 -1
  22. package/dist/adaptors/testing.d.cts.map +1 -1
  23. package/dist/adaptors/testing.d.mts +22 -1
  24. package/dist/adaptors/testing.d.mts.map +1 -1
  25. package/dist/adaptors/testing.mjs +109 -2
  26. package/dist/adaptors/testing.mjs.map +1 -1
  27. package/dist/{runSubscriber-D8nLXIv1.cjs → runSubscriber-B1Yg4dID.cjs} +5 -3
  28. package/dist/runSubscriber-B1Yg4dID.cjs.map +1 -0
  29. package/dist/{runSubscriber-BHvJ8POr.mjs → runSubscriber-JCgkeYbE.mjs} +5 -3
  30. package/dist/runSubscriber-JCgkeYbE.mjs.map +1 -0
  31. package/dist/subscribers/index.cjs +31 -13
  32. package/dist/subscribers/index.cjs.map +1 -1
  33. package/dist/subscribers/index.d.cts +27 -4
  34. package/dist/subscribers/index.d.cts.map +1 -1
  35. package/dist/subscribers/index.d.mts +27 -4
  36. package/dist/subscribers/index.d.mts.map +1 -1
  37. package/dist/subscribers/index.mjs +30 -14
  38. package/dist/subscribers/index.mjs.map +1 -1
  39. package/dist/worker.cjs +22 -1
  40. package/dist/worker.cjs.map +1 -1
  41. package/dist/worker.d.cts +20 -1
  42. package/dist/worker.d.cts.map +1 -1
  43. package/dist/worker.d.mts +20 -1
  44. package/dist/worker.d.mts.map +1 -1
  45. package/dist/worker.mjs +22 -1
  46. package/dist/worker.mjs.map +1 -1
  47. package/package.json +31 -31
  48. package/dist/SubscriberBuilder-BRa_nrmH.d.cts +0 -67
  49. package/dist/SubscriberBuilder-BRa_nrmH.d.cts.map +0 -1
  50. package/dist/SubscriberBuilder-D9bkrYzH.d.mts +0 -67
  51. package/dist/SubscriberBuilder-D9bkrYzH.d.mts.map +0 -1
  52. package/dist/SubscriberBuilder-DRXfxWn_.mjs.map +0 -1
  53. package/dist/SubscriberBuilder-M2EAgQhC.cjs.map +0 -1
  54. package/dist/runSubscriber-BHvJ8POr.mjs.map +0 -1
  55. package/dist/runSubscriber-D8nLXIv1.cjs.map +0 -1
@@ -0,0 +1,129 @@
1
+ import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.cjs";
2
+ import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-CFW0zjdD.cjs";
3
+ import { t as DatabaseContext } from "./Function-B0uZhZnU.cjs";
4
+ import { c as ServicesOf, r as Consumable } from "./construct-interface-B1AfqRl4.cjs";
5
+ import { n as SubscriberHandler, t as Subscriber } from "./Subscriber-Bfw5cqzz.cjs";
6
+ import { Logger } from "@geekmidas/logger";
7
+ import { InferStandardSchema } from "@geekmidas/schema";
8
+ import { Service, ServiceRecord } from "@geekmidas/services";
9
+ import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
10
+ import { ObjectEvent, ObjectEventType, ObjectFilter, ObjectMessage } from "@geekmidas/storage/events";
11
+ //#region src/subscribers/SubscriberBuilder.d.ts
12
+ declare class SubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TEventPublisher extends EventPublisher<any> | undefined = undefined, TSubscribedEvents extends any[] = [], TDatabase = undefined, TDatabaseServiceName extends string = string> {
13
+ private _subscribedEvents;
14
+ private _timeout?;
15
+ private outputSchema?;
16
+ private _services;
17
+ /** The construct ids `.dependsOn()` named — what the manifest records. */
18
+ _constructs: string[];
19
+ private _logger;
20
+ /**
21
+ * The deploy unit that runs this, by construct id. Seeded by the factory a
22
+ * `Worker` hands out, so a subscriber is not owned by its directory.
23
+ */
24
+ _owner?: string;
25
+ private _topicName?;
26
+ /** What the handler's `db` comes from — the worker's, unless overridden. */
27
+ private _databaseService?;
28
+ /** The edge `.database()` added, so the next one can replace it. */
29
+ private _databaseEdge?;
30
+ constructor();
31
+ /**
32
+ * Bind this subscriber to a {@link Topic}: the subscribable event types (and
33
+ * their payloads) come from the topic's contract, and the binding is recorded
34
+ * for the manifest, so infra wires the SNS subscription.
35
+ *
36
+ * A consumer does not publish, so binding a topic does *not* hand it the
37
+ * topic's publisher connection string (least privilege). One that publishes
38
+ * follow-up events depends on the topic it publishes to: `.dependsOn([orders])`.
39
+ */
40
+ topic<TName extends string, TEvents extends TopicEvents>(topic: Topic<TName, TEvents>): SubscriberBuilder<TServices, TLogger, OutSchema, EventPublisher<TopicMessage<TEvents>>, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
41
+ timeout(timeout: number): this;
42
+ output<T extends StandardSchemaV1>(schema: T): SubscriberBuilder<TServices, TLogger, T, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
43
+ /**
44
+ * Depend on constructs — a database, a bucket, a mail sender, a queue, a
45
+ * topic.
46
+ *
47
+ * It records the edge and dissolves each construct's client into the
48
+ * handler's service record under the construct's own id, so
49
+ * `.dependsOn([uploads])` is what makes `services.uploads` exist and type.
50
+ *
51
+ * Constructs only. A `Service` does not match the shape, which is what keeps
52
+ * env sniffing confined to `.services()` and the explicit lift.
53
+ */
54
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): SubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
55
+ services<T extends Service[]>(services: T): SubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
56
+ logger<T extends Logger>(logger: T): SubscriberBuilder<TServices, T, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
57
+ /**
58
+ * The database the handler receives as `db`.
59
+ *
60
+ * A subscriber built from a worker already has the worker's, when the
61
+ * worker named one with `.database(db)`; this replaces it — the edge as well
62
+ * as the client — for a consumer that works against a different database.
63
+ */
64
+ database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): SubscriberBuilder<TServices, TLogger, OutSchema, TEventPublisher, TSubscribedEvents, T, TDbName>;
65
+ subscribe<TEvent extends TEventPublisher extends EventPublisher<any> ? ExtractPublisherMessage<TEventPublisher>['type'] | ExtractPublisherMessage<TEventPublisher>['type'][] : never>(event: TEvent): SubscriberBuilder<TServices, TLogger, OutSchema, TEventPublisher, TEvent extends any[] ? [...TSubscribedEvents, ...TEvent] : [...TSubscribedEvents, TEvent], TDatabase, TDatabaseServiceName>;
66
+ handle(fn: SubscriberHandler<TEventPublisher, TSubscribedEvents, TServices, TLogger, OutSchema, TDatabase>): Subscriber<TServices, TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
67
+ }
68
+ //#endregion
69
+ //#region src/subscribers/ObjectSubscriberBuilder.d.ts
70
+ /**
71
+ * A subscriber bound to a bucket: a topic subscriber whose topic is the
72
+ * storage itself, so it runs through the same adaptors — Lambda, SNS push,
73
+ * a polled broker, a feature test.
74
+ */
75
+ type ObjectSubscriber<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TEvents extends ObjectEventType[] = ObjectEventType[], TDatabase = undefined, TDatabaseServiceName extends string = string> = Subscriber<TServices, TLogger, OutSchema, EventPublisher<ObjectMessage>, TEvents, TDatabase, TDatabaseServiceName>;
76
+ /** What a bucket's subscriber is handed: the objects, and how each changed. */
77
+ type ObjectSubscriberContext<TEvents extends ObjectEventType[], TServices extends Service[] = [], TLogger extends Logger = Logger, TDatabase = undefined> = {
78
+ /** Each object that changed, in the order the storage reported them. */
79
+ objects: ObjectEvent[];
80
+ /** The same objects with what happened to each — for a handler of both. */
81
+ events: ObjectMessage<TEvents[number]>[];
82
+ services: ServiceRecord<TServices>;
83
+ logger: TLogger;
84
+ } & DatabaseContext<TDatabase>;
85
+ type ObjectSubscriberHandler<TEvents extends ObjectEventType[], TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined> = (ctx: ObjectSubscriberContext<TEvents, TServices, TLogger, TDatabase>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
86
+ /** `.on()` was given no event to react to. */
87
+ declare class ObjectSubscriberHasNoEvents extends Error {
88
+ readonly bucket: string;
89
+ constructor(bucket: string);
90
+ }
91
+ /**
92
+ * A subscriber to a bucket's objects, from `worker.objects(bucket)`.
93
+ *
94
+ * Built on the topic subscriber's builder, which it wraps rather than
95
+ * extends: the services, database, owner and edges are configured exactly as
96
+ * a topic subscriber's, and only the trigger differs — the storage, filtered
97
+ * by event and key.
98
+ */
99
+ declare class ObjectSubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TEvents extends ObjectEventType[] = [], TDatabase = undefined, TDatabaseServiceName extends string = string> {
100
+ /** The topic subscriber's builder, already owned by its worker. */
101
+ private readonly inner;
102
+ /** The bucket's id — what the build binds the subscriber to. */
103
+ private readonly bucket;
104
+ private readonly events;
105
+ private readonly filter;
106
+ constructor(
107
+ /** The topic subscriber's builder, already owned by its worker. */
108
+ inner: SubscriberBuilder<any, any, any, any, any, any, any>,
109
+ /** The bucket's id — what the build binds the subscriber to. */
110
+ bucket: string, events?: readonly ObjectEventType[], filter?: ObjectFilter);
111
+ /**
112
+ * What it reacts to: the events, and — optionally — only keys under a
113
+ * prefix and ending in a suffix. Repeatable; the last filter wins.
114
+ */
115
+ on<const T extends ObjectEventType[]>(events: T, filter?: ObjectFilter): ObjectSubscriberBuilder<TServices, TLogger, OutSchema, [...TEvents, ...T], TDatabase, TDatabaseServiceName>;
116
+ /** See {@link SubscriberBuilder.dependsOn}. */
117
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): ObjectSubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
118
+ services<T extends Service[]>(services: T): ObjectSubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
119
+ /** See {@link SubscriberBuilder.database}. */
120
+ database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): ObjectSubscriberBuilder<TServices, TLogger, OutSchema, TEvents, T, TDbName>;
121
+ timeout(timeout: number): this;
122
+ output<T extends StandardSchemaV1>(schema: T): ObjectSubscriberBuilder<TServices, TLogger, T, TEvents, TDatabase, TDatabaseServiceName>;
123
+ logger<T extends Logger>(logger: T): ObjectSubscriberBuilder<TServices, T, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
124
+ handle(fn: ObjectSubscriberHandler<TEvents, TServices, TLogger, OutSchema, TDatabase>): ObjectSubscriber<TServices, TLogger, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
125
+ private with;
126
+ }
127
+ //#endregion
128
+ export { ObjectSubscriberHasNoEvents as a, ObjectSubscriberHandler as i, ObjectSubscriberBuilder as n, SubscriberBuilder as o, ObjectSubscriberContext as r, ObjectSubscriber as t };
129
+ //# sourceMappingURL=ObjectSubscriberBuilder-B4j3zgCZ.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectSubscriberBuilder-B4j3zgCZ.d.cts","names":[],"sources":["../src/subscribers/SubscriberBuilder.ts","../src/subscribers/ObjectSubscriberBuilder.ts"],"mappings":";;;;;;;;;;;cAoBa,kBACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,wBAAwB,6CACxB,sCACA,uBACA;UAEQ;UACA;UACA;UACA;;EAED;UACC;;;;;EAKD;UACC;;UAEA;;UAEA;EAER;;;;;;;;;;EAaA,MAAM,sBAAsB,gBAAgB,aAC3C,OAAO,MAAM,OAAO,WAClB,kBACF,WACA,SACA,WACA,eAAe,aAAa,WAC5B,mBACA,WACA;EAeD,QAAQ;EAIR,OAAO,UAAU,kBAChB,QAAQ,IACN,kBACF,WACA,SACA,GACA,iBACA,mBACA,WACA;;;;;;;;;;;;EAkBD,gBAAgB,mBAAmB,cAClC,YAAY,IACV,sBACE,cAAc,WAAW,KAC7B,SACA,WACA,iBACA,mBACA,WACA;EAyBD,SAAS,UAAU,WAClB,UAAU,IACR,sBACE,cAAc,IAClB,SACA,WACA,iBACA,mBACA,WACA;EAOD,OAAO,UAAU,QAChB,QAAQ,IACN,kBACF,WACA,GACA,WACA,iBACA,mBACA,WACA;;;;;;;;EAYD,SA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AU,WAClB,UAAU,IACR,4BACE,cAAc,IAClB,SACA,WACA,SACA,WACA;;EAMD,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAAK,QAAQ,SAAS,KAChD,wBACF,WACA,SACA,WACA,SACA,GACA;EAKD,QAAQ;EAIR,OAAO,UAAU,kBAChB,QAAQ,IACN,wBACF,WACA,SACA,GACA,SACA,WACA;EAKD,OAAO,UAAU,QAChB,QAAQ,IACN,wBACF,WACA,GACA,WACA,SACA,WACA;EAKD,OACC,IAAI,wBACH,SACA,WACA,SACA,WACA,aAEC,iBACF,WACA,SACA,WACA,SACA,WACA;UAgDO"}
@@ -0,0 +1,129 @@
1
+ import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.mjs";
2
+ import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-B7AXn0xH.mjs";
3
+ import { t as DatabaseContext } from "./Function-B_9R7Zy1.mjs";
4
+ import { c as ServicesOf, r as Consumable } from "./construct-interface-ZvYQbivO.mjs";
5
+ import { n as SubscriberHandler, t as Subscriber } from "./Subscriber-Czs77h-H.mjs";
6
+ import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
7
+ import { Service, ServiceRecord } from "@geekmidas/services";
8
+ import { Logger } from "@geekmidas/logger";
9
+ import { InferStandardSchema } from "@geekmidas/schema";
10
+ import { ObjectEvent, ObjectEventType, ObjectFilter, ObjectMessage } from "@geekmidas/storage/events";
11
+ //#region src/subscribers/SubscriberBuilder.d.ts
12
+ declare class SubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TEventPublisher extends EventPublisher<any> | undefined = undefined, TSubscribedEvents extends any[] = [], TDatabase = undefined, TDatabaseServiceName extends string = string> {
13
+ private _subscribedEvents;
14
+ private _timeout?;
15
+ private outputSchema?;
16
+ private _services;
17
+ /** The construct ids `.dependsOn()` named — what the manifest records. */
18
+ _constructs: string[];
19
+ private _logger;
20
+ /**
21
+ * The deploy unit that runs this, by construct id. Seeded by the factory a
22
+ * `Worker` hands out, so a subscriber is not owned by its directory.
23
+ */
24
+ _owner?: string;
25
+ private _topicName?;
26
+ /** What the handler's `db` comes from — the worker's, unless overridden. */
27
+ private _databaseService?;
28
+ /** The edge `.database()` added, so the next one can replace it. */
29
+ private _databaseEdge?;
30
+ constructor();
31
+ /**
32
+ * Bind this subscriber to a {@link Topic}: the subscribable event types (and
33
+ * their payloads) come from the topic's contract, and the binding is recorded
34
+ * for the manifest, so infra wires the SNS subscription.
35
+ *
36
+ * A consumer does not publish, so binding a topic does *not* hand it the
37
+ * topic's publisher connection string (least privilege). One that publishes
38
+ * follow-up events depends on the topic it publishes to: `.dependsOn([orders])`.
39
+ */
40
+ topic<TName extends string, TEvents extends TopicEvents>(topic: Topic<TName, TEvents>): SubscriberBuilder<TServices, TLogger, OutSchema, EventPublisher<TopicMessage<TEvents>>, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
41
+ timeout(timeout: number): this;
42
+ output<T extends StandardSchemaV1>(schema: T): SubscriberBuilder<TServices, TLogger, T, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
43
+ /**
44
+ * Depend on constructs — a database, a bucket, a mail sender, a queue, a
45
+ * topic.
46
+ *
47
+ * It records the edge and dissolves each construct's client into the
48
+ * handler's service record under the construct's own id, so
49
+ * `.dependsOn([uploads])` is what makes `services.uploads` exist and type.
50
+ *
51
+ * Constructs only. A `Service` does not match the shape, which is what keeps
52
+ * env sniffing confined to `.services()` and the explicit lift.
53
+ */
54
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): SubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
55
+ services<T extends Service[]>(services: T): SubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
56
+ logger<T extends Logger>(logger: T): SubscriberBuilder<TServices, T, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
57
+ /**
58
+ * The database the handler receives as `db`.
59
+ *
60
+ * A subscriber built from a worker already has the worker's, when the
61
+ * worker named one with `.database(db)`; this replaces it — the edge as well
62
+ * as the client — for a consumer that works against a different database.
63
+ */
64
+ database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): SubscriberBuilder<TServices, TLogger, OutSchema, TEventPublisher, TSubscribedEvents, T, TDbName>;
65
+ subscribe<TEvent extends TEventPublisher extends EventPublisher<any> ? ExtractPublisherMessage<TEventPublisher>['type'] | ExtractPublisherMessage<TEventPublisher>['type'][] : never>(event: TEvent): SubscriberBuilder<TServices, TLogger, OutSchema, TEventPublisher, TEvent extends any[] ? [...TSubscribedEvents, ...TEvent] : [...TSubscribedEvents, TEvent], TDatabase, TDatabaseServiceName>;
66
+ handle(fn: SubscriberHandler<TEventPublisher, TSubscribedEvents, TServices, TLogger, OutSchema, TDatabase>): Subscriber<TServices, TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName>;
67
+ }
68
+ //#endregion
69
+ //#region src/subscribers/ObjectSubscriberBuilder.d.ts
70
+ /**
71
+ * A subscriber bound to a bucket: a topic subscriber whose topic is the
72
+ * storage itself, so it runs through the same adaptors — Lambda, SNS push,
73
+ * a polled broker, a feature test.
74
+ */
75
+ type ObjectSubscriber<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TEvents extends ObjectEventType[] = ObjectEventType[], TDatabase = undefined, TDatabaseServiceName extends string = string> = Subscriber<TServices, TLogger, OutSchema, EventPublisher<ObjectMessage>, TEvents, TDatabase, TDatabaseServiceName>;
76
+ /** What a bucket's subscriber is handed: the objects, and how each changed. */
77
+ type ObjectSubscriberContext<TEvents extends ObjectEventType[], TServices extends Service[] = [], TLogger extends Logger = Logger, TDatabase = undefined> = {
78
+ /** Each object that changed, in the order the storage reported them. */
79
+ objects: ObjectEvent[];
80
+ /** The same objects with what happened to each — for a handler of both. */
81
+ events: ObjectMessage<TEvents[number]>[];
82
+ services: ServiceRecord<TServices>;
83
+ logger: TLogger;
84
+ } & DatabaseContext<TDatabase>;
85
+ type ObjectSubscriberHandler<TEvents extends ObjectEventType[], TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined> = (ctx: ObjectSubscriberContext<TEvents, TServices, TLogger, TDatabase>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
86
+ /** `.on()` was given no event to react to. */
87
+ declare class ObjectSubscriberHasNoEvents extends Error {
88
+ readonly bucket: string;
89
+ constructor(bucket: string);
90
+ }
91
+ /**
92
+ * A subscriber to a bucket's objects, from `worker.objects(bucket)`.
93
+ *
94
+ * Built on the topic subscriber's builder, which it wraps rather than
95
+ * extends: the services, database, owner and edges are configured exactly as
96
+ * a topic subscriber's, and only the trigger differs — the storage, filtered
97
+ * by event and key.
98
+ */
99
+ declare class ObjectSubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TEvents extends ObjectEventType[] = [], TDatabase = undefined, TDatabaseServiceName extends string = string> {
100
+ /** The topic subscriber's builder, already owned by its worker. */
101
+ private readonly inner;
102
+ /** The bucket's id — what the build binds the subscriber to. */
103
+ private readonly bucket;
104
+ private readonly events;
105
+ private readonly filter;
106
+ constructor(
107
+ /** The topic subscriber's builder, already owned by its worker. */
108
+ inner: SubscriberBuilder<any, any, any, any, any, any, any>,
109
+ /** The bucket's id — what the build binds the subscriber to. */
110
+ bucket: string, events?: readonly ObjectEventType[], filter?: ObjectFilter);
111
+ /**
112
+ * What it reacts to: the events, and — optionally — only keys under a
113
+ * prefix and ending in a suffix. Repeatable; the last filter wins.
114
+ */
115
+ on<const T extends ObjectEventType[]>(events: T, filter?: ObjectFilter): ObjectSubscriberBuilder<TServices, TLogger, OutSchema, [...TEvents, ...T], TDatabase, TDatabaseServiceName>;
116
+ /** See {@link SubscriberBuilder.dependsOn}. */
117
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): ObjectSubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
118
+ services<T extends Service[]>(services: T): ObjectSubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
119
+ /** See {@link SubscriberBuilder.database}. */
120
+ database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): ObjectSubscriberBuilder<TServices, TLogger, OutSchema, TEvents, T, TDbName>;
121
+ timeout(timeout: number): this;
122
+ output<T extends StandardSchemaV1>(schema: T): ObjectSubscriberBuilder<TServices, TLogger, T, TEvents, TDatabase, TDatabaseServiceName>;
123
+ logger<T extends Logger>(logger: T): ObjectSubscriberBuilder<TServices, T, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
124
+ handle(fn: ObjectSubscriberHandler<TEvents, TServices, TLogger, OutSchema, TDatabase>): ObjectSubscriber<TServices, TLogger, OutSchema, TEvents, TDatabase, TDatabaseServiceName>;
125
+ private with;
126
+ }
127
+ //#endregion
128
+ export { ObjectSubscriberHasNoEvents as a, ObjectSubscriberHandler as i, ObjectSubscriberBuilder as n, SubscriberBuilder as o, ObjectSubscriberContext as r, ObjectSubscriber as t };
129
+ //# sourceMappingURL=ObjectSubscriberBuilder-C0WUU-ov.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectSubscriberBuilder-C0WUU-ov.d.mts","names":[],"sources":["../src/subscribers/SubscriberBuilder.ts","../src/subscribers/ObjectSubscriberBuilder.ts"],"mappings":";;;;;;;;;;;cAoBa,kBACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,wBAAwB,6CACxB,sCACA,uBACA;UAEQ;UACA;UACA;UACA;;EAED;UACC;;;;;EAK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BAAwB,SAAS,WAAW,SAAS,eACtD,kBAAkB,mBACpB,oBAAoB,aAAa,QAAQ,oBAAoB,oBACvD;;cAGI,oCAAoC;WAC3B;EAArB,YAAqB;;;;;;;;;;cAiBT,wBACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,gBAAgB,wBAChB,uBACA;;mBAIkB;;mBAUA;mBACA;mBACA;EAdlB,YAEkB;;EAAA,OAAO,sDAUP;;EAAA,gBACA,kBAAiB,mBACjB,SAAQ;;;;;EAO1B,SAAS,UAAU,mBAClB,QAAQ,GACR,SAAQ,eACN,wBACF,WACA,SACA,eACI,YAAY,IAChB,WACA;;EAcD,gBAAgB,mBAAmB,cAClC,YAAY,IACV,4BACE,cAAc,WAAW,KAC7B,SACA,WACA,SACA,WACA;EAKD,SAAS,UAAU,WAClB,UAAU,IACR,4BACE,cAAc,IAClB,SACA,WACA,SACA,WACA;;EAMD,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAAK,QAAQ,SAAS,KAChD,wBACF,WACA,SACA,WACA,SACA,GACA;EAKD,QAAQ;EAIR,OAAO,UAAU,kBAChB,QAAQ,IACN,wBACF,WACA,SACA,GACA,SACA,WACA;EAKD,OAAO,UAAU,QAChB,QAAQ,IACN,wBACF,WACA,GACA,WACA,SACA,WACA;EAKD,OACC,IAAI,wBACH,SACA,WACA,SACA,WACA,aAEC,iBACF,WACA,SACA,WACA,SACA,WACA;UAgDO"}
@@ -48,6 +48,18 @@ TEventPublisher extends EventPublisher<any> | undefined = undefined, TSubscribed
48
48
  * the same reason.
49
49
  */
50
50
  databaseService?: Service<TDatabaseServiceName, TDatabase>);
51
+ /**
52
+ * The id of the bucket this subscriber is bound to (via
53
+ * `worker.objects(bucket)`), when its topic is the storage itself — read
54
+ * by the build to bind it, and by the adaptors to read what the storage
55
+ * sends as object events.
56
+ */
57
+ bucketName?: string;
58
+ /** Which of the bucket's keys it watches — see `worker.objects()`. */
59
+ objectFilter?: {
60
+ prefix?: string;
61
+ suffix?: string;
62
+ };
51
63
  get subscribedEvents(): TSubscribedEvents | undefined;
52
64
  }
53
65
  type SubscriberHandler<TEventPublisher extends EventPublisher<any> | undefined, TSubscribedEvents extends ExtractPublisherMessage<TEventPublisher>['type'][], TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined> = (ctx: SubscriberContext<TEventPublisher, TSubscribedEvents, TServices, TLogger, TDatabase>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
@@ -58,4 +70,4 @@ type SubscriberContext<TEventPublisher extends EventPublisher<any> | undefined,
58
70
  } & DatabaseContext<TDatabase>;
59
71
  //#endregion
60
72
  export { SubscriberHandler as n, Subscriber as t };
61
- //# sourceMappingURL=Subscriber-CEt7kHkc.d.cts.map
73
+ //# sourceMappingURL=Subscriber-Bfw5cqzz.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Subscriber-CEt7kHkc.d.cts","names":[],"sources":["../src/subscribers/Subscriber.ts"],"mappings":";;;;;;;;KAaK,qBACJ,mBAAmB,iCACnB,6BACG,mBAAmB,sBACpB,QAAQ,wBAAwB;EAAe,MAAM;;;;;;;cAQ3C,WACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB;;AAElB,wBAAwB,6CACxB,0BACC,wBAAwB,6BAA6B,wBAAwB,4BAC9E,uBACA,sDACS,UACT,SACA,WACA,8BAGA,sBACA;WAeiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA;WAEwB;YACf,oBAAoB;WACL,eAAe;WACf,UAAU;WACV,QAAQ;;;;;;WAMjB;EA/BjB;SAEO,aACN,WACE,OAAO;EAQV,YACiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA,YAEwB,kBACf,oBAAoB,+BACL,eAAe,uBACf,WAAU,WACV,SAAQ,SAMjB;;;;;;EAAA,gCAKhB;;;;;EAAA,uBAKA;;;;;EAAA,kBAAkB,QAAQ,sBAAsB;MAiB7C,oBAAoB;;KAMb,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,0BAEA,KAAK,kBACJ,iBACA,mBACA,WACA,SACA,eAEG,kBAAkB,mBACpB,oBAAoB,aAAa,QAAQ,oBAAoB,oBACvD;KAGG,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB;EAEA,QAAQ,qBAAqB,iBAAiB;EAC9C,UAAU,cAAc;EACxB,QAAQ;IACL,gBAAgB"}
1
+ {"version":3,"file":"Subscriber-Bfw5cqzz.d.cts","names":[],"sources":["../src/subscribers/Subscriber.ts"],"mappings":";;;;;;;;KAaK,qBACJ,mBAAmB,iCACnB,6BACG,mBAAmB,sBACpB,QAAQ,wBAAwB;EAAe,MAAM;;;;;;;cAQ3C,WACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB;;AAElB,wBAAwB,6CACxB,0BACC,wBAAwB,6BAA6B,wBAAwB,4BAC9E,uBACA,sDACS,UACT,SACA,WACA,8BAGA,sBACA;WAeiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA;WAEwB;YACf,oBAAoB;WACL,eAAe;WACf,UAAU;WACV,QAAQ;;;;;;WAMjB;EA/BjB;SAEO,aACN,WACE,OAAO;EAQV,YACiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA,YAEwB,kBACf,oBAAoB,+BACL,eAAe,uBACf,WAAU,WACV,SAAQ,SAMjB;;;;;;EAAA,gCAKhB;;;;;EAAA,uBAKA;;;;;EAAA,kBAAkB,QAAQ,sBAAsB;;;;;;;EAuBjD;;EAGA;IAAiB;IAAiB;;MAE9B,oBAAoB;;KAMb,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,0BAEA,KAAK,kBACJ,iBACA,mBACA,WACA,SACA,eAEG,kBAAkB,mBACpB,oBAAoB,aAAa,QAAQ,oBAAoB,oBACvD;KAGG,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB;EAEA,QAAQ,qBAAqB,iBAAiB;EAC9C,UAAU,cAAc;EACxB,QAAQ;IACL,gBAAgB"}
@@ -48,6 +48,18 @@ TEventPublisher extends EventPublisher<any> | undefined = undefined, TSubscribed
48
48
  * the same reason.
49
49
  */
50
50
  databaseService?: Service<TDatabaseServiceName, TDatabase>);
51
+ /**
52
+ * The id of the bucket this subscriber is bound to (via
53
+ * `worker.objects(bucket)`), when its topic is the storage itself — read
54
+ * by the build to bind it, and by the adaptors to read what the storage
55
+ * sends as object events.
56
+ */
57
+ bucketName?: string;
58
+ /** Which of the bucket's keys it watches — see `worker.objects()`. */
59
+ objectFilter?: {
60
+ prefix?: string;
61
+ suffix?: string;
62
+ };
51
63
  get subscribedEvents(): TSubscribedEvents | undefined;
52
64
  }
53
65
  type SubscriberHandler<TEventPublisher extends EventPublisher<any> | undefined, TSubscribedEvents extends ExtractPublisherMessage<TEventPublisher>['type'][], TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined> = (ctx: SubscriberContext<TEventPublisher, TSubscribedEvents, TServices, TLogger, TDatabase>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
@@ -58,4 +70,4 @@ type SubscriberContext<TEventPublisher extends EventPublisher<any> | undefined,
58
70
  } & DatabaseContext<TDatabase>;
59
71
  //#endregion
60
72
  export { SubscriberHandler as n, Subscriber as t };
61
- //# sourceMappingURL=Subscriber-dsxc5LKa.d.mts.map
73
+ //# sourceMappingURL=Subscriber-Czs77h-H.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Subscriber-dsxc5LKa.d.mts","names":[],"sources":["../src/subscribers/Subscriber.ts"],"mappings":";;;;;;;;KAaK,qBACJ,mBAAmB,iCACnB,6BACG,mBAAmB,sBACpB,QAAQ,wBAAwB;EAAe,MAAM;;;;;;;cAQ3C,WACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB;;AAElB,wBAAwB,6CACxB,0BACC,wBAAwB,6BAA6B,wBAAwB,4BAC9E,uBACA,sDACS,UACT,SACA,WACA,8BAGA,sBACA;WAeiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA;WAEwB;YACf,oBAAoB;WACL,eAAe;WACf,UAAU;WACV,QAAQ;;;;;;WAMjB;EA/BjB;SAEO,aACN,WACE,OAAO;EAQV,YACiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA,YAEwB,kBACf,oBAAoB,+BACL,eAAe,uBACf,WAAU,WACV,SAAQ,SAMjB;;;;;;EAAA,gCAKhB;;;;;EAAA,uBAKA;;;;;EAAA,kBAAkB,QAAQ,sBAAsB;MAiB7C,oBAAoB;;KAMb,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,0BAEA,KAAK,kBACJ,iBACA,mBACA,WACA,SACA,eAEG,kBAAkB,mBACpB,oBAAoB,aAAa,QAAQ,oBAAoB,oBACvD;KAGG,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB;EAEA,QAAQ,qBAAqB,iBAAiB;EAC9C,UAAU,cAAc;EACxB,QAAQ;IACL,gBAAgB"}
1
+ {"version":3,"file":"Subscriber-Czs77h-H.d.mts","names":[],"sources":["../src/subscribers/Subscriber.ts"],"mappings":";;;;;;;;KAaK,qBACJ,mBAAmB,iCACnB,6BACG,mBAAmB,sBACpB,QAAQ,wBAAwB;EAAe,MAAM;;;;;;;cAQ3C,WACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB;;AAElB,wBAAwB,6CACxB,0BACC,wBAAwB,6BAA6B,wBAAwB,4BAC9E,uBACA,sDACS,UACT,SACA,WACA,8BAGA,sBACA;WAeiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA;WAEwB;YACf,oBAAoB;WACL,eAAe;WACf,UAAU;WACV,QAAQ;;;;;;WAMjB;EA/BjB;SAEO,aACN,WACE,OAAO;EAQV,YACiB,SAAS,kBACxB,iBACA,mBACA,WACA,SACA,WACA,YAEwB,kBACf,oBAAoB,+BACL,eAAe,uBACf,WAAU,WACV,SAAQ,SAMjB;;;;;;EAAA,gCAKhB;;;;;EAAA,uBAKA;;;;;EAAA,kBAAkB,QAAQ,sBAAsB;;;;;;;EAuBjD;;EAGA;IAAiB;IAAiB;;MAE9B,oBAAoB;;KAMb,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,0BAEA,KAAK,kBACJ,iBACA,mBACA,WACA,SACA,eAEG,kBAAkB,mBACpB,oBAAoB,aAAa,QAAQ,oBAAoB,oBACvD;KAGG,kBACX,wBAAwB,iCACxB,0BAA0B,wBAAwB,4BAClD,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB;EAEA,QAAQ,qBAAqB,iBAAiB;EAC9C,UAAU,cAAc;EACxB,QAAQ;IACL,gBAAgB"}
@@ -2,6 +2,93 @@ const require_Construct = require("./Construct-DEOVauyA.cjs");
2
2
  const require_construct_interface = require("./construct-interface.cjs");
3
3
  const require_clone = require("./clone-UGJpvQnL.cjs");
4
4
  let _geekmidas_logger_console = require("@geekmidas/logger/console");
5
+ //#region src/subscribers/ObjectSubscriberBuilder.ts
6
+ /** `.on()` was given no event to react to. */
7
+ var ObjectSubscriberHasNoEvents = class extends Error {
8
+ bucket;
9
+ constructor(bucket) {
10
+ super(`A subscriber bound to '${bucket}' names no event. Name what it reacts to: .on(['object.created']), .on(['object.deleted']), or both.`);
11
+ this.bucket = bucket;
12
+ this.name = "ObjectSubscriberHasNoEvents";
13
+ }
14
+ };
15
+ /**
16
+ * A subscriber to a bucket's objects, from `worker.objects(bucket)`.
17
+ *
18
+ * Built on the topic subscriber's builder, which it wraps rather than
19
+ * extends: the services, database, owner and edges are configured exactly as
20
+ * a topic subscriber's, and only the trigger differs — the storage, filtered
21
+ * by event and key.
22
+ */
23
+ var ObjectSubscriberBuilder = class ObjectSubscriberBuilder {
24
+ inner;
25
+ bucket;
26
+ events;
27
+ filter;
28
+ constructor(inner, bucket, events = [], filter = {}) {
29
+ this.inner = inner;
30
+ this.bucket = bucket;
31
+ this.events = events;
32
+ this.filter = filter;
33
+ }
34
+ /**
35
+ * What it reacts to: the events, and — optionally — only keys under a
36
+ * prefix and ending in a suffix. Repeatable; the last filter wins.
37
+ */
38
+ on(events, filter = {}) {
39
+ return new ObjectSubscriberBuilder(this.inner, this.bucket, [.../* @__PURE__ */ new Set([...this.events, ...events])], {
40
+ ...filter.prefix ? { prefix: filter.prefix } : {},
41
+ ...filter.suffix ? { suffix: filter.suffix } : {}
42
+ });
43
+ }
44
+ /** See {@link SubscriberBuilder.dependsOn}. */
45
+ dependsOn(constructs) {
46
+ return this.with(this.inner.dependsOn(constructs));
47
+ }
48
+ services(services) {
49
+ return this.with(this.inner.services(services));
50
+ }
51
+ /** See {@link SubscriberBuilder.database}. */
52
+ database(source) {
53
+ return this.with(this.inner.database(source));
54
+ }
55
+ timeout(timeout) {
56
+ return this.with(this.inner.timeout(timeout));
57
+ }
58
+ output(schema) {
59
+ return this.with(this.inner.output(schema));
60
+ }
61
+ logger(logger) {
62
+ return this.with(this.inner.logger(logger));
63
+ }
64
+ handle(fn) {
65
+ if (this.events.length === 0) throw new ObjectSubscriberHasNoEvents(this.bucket);
66
+ const events = [...this.events];
67
+ const filter = this.filter;
68
+ const handler = async (ctx) => {
69
+ const { matchesObjectFilter } = await import("@geekmidas/storage/events");
70
+ const wanted = ctx.events.filter((event) => isObjectMessage(event) && events.includes(event.type) && matchesObjectFilter(event.payload, filter));
71
+ if (wanted.length === 0) return void 0;
72
+ return fn({
73
+ ...ctx,
74
+ events: wanted,
75
+ objects: wanted.map((event) => event.payload)
76
+ });
77
+ };
78
+ const subscriber = this.inner.subscribe(events).handle(handler);
79
+ subscriber.bucketName = this.bucket;
80
+ subscriber.objectFilter = filter;
81
+ return subscriber;
82
+ }
83
+ with(inner) {
84
+ return new ObjectSubscriberBuilder(inner, this.bucket, this.events, this.filter);
85
+ }
86
+ };
87
+ function isObjectMessage(value) {
88
+ const message = value;
89
+ return typeof message === "object" && message !== null && (message.type === "object.created" || message.type === "object.deleted") && typeof message.payload?.key === "string";
90
+ }
91
+ //#endregion
5
92
  //#region src/subscribers/Subscriber.ts
6
93
  /**
7
94
  * A runnable that consumes a topic. Its handler gets `db` when it has a
@@ -31,6 +118,15 @@ var Subscriber = class extends require_Construct.Construct {
31
118
  this.topicName = topicName;
32
119
  this.databaseService = databaseService;
33
120
  }
121
+ /**
122
+ * The id of the bucket this subscriber is bound to (via
123
+ * `worker.objects(bucket)`), when its topic is the storage itself — read
124
+ * by the build to bind it, and by the adaptors to read what the storage
125
+ * sends as object events.
126
+ */
127
+ bucketName;
128
+ /** Which of the bucket's keys it watches — see `worker.objects()`. */
129
+ objectFilter;
34
130
  get subscribedEvents() {
35
131
  return this._subscribedEvents;
36
132
  }
@@ -129,6 +225,18 @@ var SubscriberBuilder = class {
129
225
  }
130
226
  };
131
227
  //#endregion
228
+ Object.defineProperty(exports, "ObjectSubscriberBuilder", {
229
+ enumerable: true,
230
+ get: function() {
231
+ return ObjectSubscriberBuilder;
232
+ }
233
+ });
234
+ Object.defineProperty(exports, "ObjectSubscriberHasNoEvents", {
235
+ enumerable: true,
236
+ get: function() {
237
+ return ObjectSubscriberHasNoEvents;
238
+ }
239
+ });
132
240
  Object.defineProperty(exports, "Subscriber", {
133
241
  enumerable: true,
134
242
  get: function() {
@@ -142,4 +250,4 @@ Object.defineProperty(exports, "SubscriberBuilder", {
142
250
  }
143
251
  });
144
252
 
145
- //# sourceMappingURL=SubscriberBuilder-M2EAgQhC.cjs.map
253
+ //# sourceMappingURL=SubscriberBuilder-CYluzubx.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubscriberBuilder-CYluzubx.cjs","names":["Construct","DEFAULT_LOGGER","DEFAULT_LOGGER","cloneWith","servicesOf","idsOf","serviceOf","databaseEdges"],"sources":["../src/subscribers/ObjectSubscriberBuilder.ts","../src/subscribers/Subscriber.ts","../src/subscribers/SubscriberBuilder.ts"],"sourcesContent":["import type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type {\n\tObjectEvent,\n\tObjectEventType,\n\tObjectFilter,\n\tObjectMessage,\n} from '@geekmidas/storage/events';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable, ServicesOf } from '../construct-interface';\nimport type { DatabaseContext } from '../functions/Function';\nimport type { Subscriber } from './Subscriber';\nimport type { SubscriberBuilder } from './SubscriberBuilder';\n\n/**\n * A subscriber bound to a bucket: a topic subscriber whose topic is the\n * storage itself, so it runs through the same adaptors — Lambda, SNS push,\n * a polled broker, a feature test.\n */\nexport type ObjectSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEvents extends ObjectEventType[] = ObjectEventType[],\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> = Subscriber<\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tEventPublisher<ObjectMessage>,\n\tTEvents,\n\tTDatabase,\n\tTDatabaseServiceName\n>;\n\n/** What a bucket's subscriber is handed: the objects, and how each changed. */\nexport type ObjectSubscriberContext<\n\tTEvents extends ObjectEventType[],\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\t/** Each object that changed, in the order the storage reported them. */\n\tobjects: ObjectEvent[];\n\t/** The same objects with what happened to each — for a handler of both. */\n\tevents: ObjectMessage<TEvents[number]>[];\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n\nexport type ObjectSubscriberHandler<\n\tTEvents extends ObjectEventType[],\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: ObjectSubscriberContext<TEvents, TServices, TLogger, TDatabase>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\n/** `.on()` was given no event to react to. */\nexport class ObjectSubscriberHasNoEvents extends Error {\n\tconstructor(readonly bucket: string) {\n\t\tsuper(\n\t\t\t`A subscriber bound to '${bucket}' names no event. Name what it reacts ` +\n\t\t\t\t`to: .on(['object.created']), .on(['object.deleted']), or both.`,\n\t\t);\n\t\tthis.name = 'ObjectSubscriberHasNoEvents';\n\t}\n}\n\n/**\n * A subscriber to a bucket's objects, from `worker.objects(bucket)`.\n *\n * Built on the topic subscriber's builder, which it wraps rather than\n * extends: the services, database, owner and edges are configured exactly as\n * a topic subscriber's, and only the trigger differs — the storage, filtered\n * by event and key.\n */\nexport class ObjectSubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEvents extends ObjectEventType[] = [],\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tconstructor(\n\t\t/** The topic subscriber's builder, already owned by its worker. */\n\t\tprivate readonly inner: SubscriberBuilder<\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany,\n\t\t\tany\n\t\t>,\n\t\t/** The bucket's id — what the build binds the subscriber to. */\n\t\tprivate readonly bucket: string,\n\t\tprivate readonly events: readonly ObjectEventType[] = [],\n\t\tprivate readonly filter: ObjectFilter = {},\n\t) {}\n\n\t/**\n\t * What it reacts to: the events, and — optionally — only keys under a\n\t * prefix and ending in a suffix. Repeatable; the last filter wins.\n\t */\n\ton<const T extends ObjectEventType[]>(\n\t\tevents: T,\n\t\tfilter: ObjectFilter = {},\n\t): ObjectSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\t[...TEvents, ...T],\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn new ObjectSubscriberBuilder(\n\t\t\tthis.inner,\n\t\t\tthis.bucket,\n\t\t\t[...new Set([...this.events, ...events])],\n\t\t\t{\n\t\t\t\t...(filter.prefix ? { prefix: filter.prefix } : {}),\n\t\t\t\t...(filter.suffix ? { suffix: filter.suffix } : {}),\n\t\t\t},\n\t\t);\n\t}\n\n\t/** See {@link SubscriberBuilder.dependsOn}. */\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): ObjectSubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.dependsOn(constructs));\n\t}\n\n\tservices<T extends Service[]>(\n\t\tservices: T,\n\t): ObjectSubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.services(services));\n\t}\n\n\t/** See {@link SubscriberBuilder.database}. */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): ObjectSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEvents,\n\t\tT,\n\t\tTDbName\n\t> {\n\t\treturn this.with(this.inner.database(source));\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn this.with(this.inner.timeout(timeout)) as this;\n\t}\n\n\toutput<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): ObjectSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\n\t\tTEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.output(schema));\n\t}\n\n\tlogger<T extends Logger>(\n\t\tlogger: T,\n\t): ObjectSubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\n\t\tTEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.logger(logger));\n\t}\n\n\thandle(\n\t\tfn: ObjectSubscriberHandler<\n\t\t\tTEvents,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase\n\t\t>,\n\t): ObjectSubscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tif (this.events.length === 0) {\n\t\t\tthrow new ObjectSubscriberHasNoEvents(this.bucket);\n\t\t}\n\t\tconst events = [...this.events];\n\t\tconst filter = this.filter;\n\n\t\t// Every adaptor hands the handler `events` as `{ type, payload }`\n\t\t// messages; this narrows them to the ones this subscriber wants — the\n\t\t// adaptor's word is final on the key, whatever filtered at the source\n\t\t// — and hands over the objects.\n\t\tconst handler = async (ctx: Record<string, any>) => {\n\t\t\tconst { matchesObjectFilter } = await import('@geekmidas/storage/events');\n\t\t\tconst wanted = (ctx.events as unknown[]).filter(\n\t\t\t\t(event): event is ObjectMessage =>\n\t\t\t\t\tisObjectMessage(event) &&\n\t\t\t\t\tevents.includes(event.type) &&\n\t\t\t\t\tmatchesObjectFilter(event.payload, filter),\n\t\t\t);\n\t\t\tif (wanted.length === 0) return undefined;\n\t\t\treturn fn({\n\t\t\t\t...ctx,\n\t\t\t\tevents: wanted,\n\t\t\t\tobjects: wanted.map((event) => event.payload),\n\t\t\t} as unknown as ObjectSubscriberContext<\n\t\t\t\tTEvents,\n\t\t\t\tTServices,\n\t\t\t\tTLogger,\n\t\t\t\tTDatabase\n\t\t\t>);\n\t\t};\n\n\t\tconst subscriber = this.inner\n\t\t\t.subscribe(events as never)\n\t\t\t.handle(handler as never) as unknown as ObjectSubscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEvents,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t\tsubscriber.bucketName = this.bucket;\n\t\tsubscriber.objectFilter = filter;\n\t\treturn subscriber;\n\t}\n\n\tprivate with(inner: SubscriberBuilder<any, any, any, any, any, any, any>) {\n\t\treturn new ObjectSubscriberBuilder<any, any, any, any, any, any>(\n\t\t\tinner,\n\t\t\tthis.bucket,\n\t\t\tthis.events,\n\t\t\tthis.filter,\n\t\t);\n\t}\n}\n\nfunction isObjectMessage(value: unknown): value is ObjectMessage {\n\tconst message = value as ObjectMessage | undefined;\n\treturn (\n\t\ttypeof message === 'object' &&\n\t\tmessage !== null &&\n\t\t(message.type === 'object.created' || message.type === 'object.deleted') &&\n\t\ttypeof message.payload?.key === 'string'\n\t);\n}\n","import type {\n\tEventPublisher,\n\tExtractPublisherMessage,\n} from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { Construct, ConstructType } from '../Construct';\nimport type { DatabaseContext } from '../functions/Function';\n\n// Helper type to extract payload types for subscribed events\ntype ExtractEventPayloads<\n\tTPublisher extends EventPublisher<any> | undefined,\n\tTEventTypes extends any[],\n> = TPublisher extends EventPublisher<any>\n\t? Extract<ExtractPublisherMessage<TPublisher>, { type: TEventTypes[number] }>\n\t: never;\n\n/**\n * A runnable that consumes a topic. Its handler gets `db` when it has a\n * database: the worker's, declared once with `worker.database(db)`, or its own\n * with `.database(other)`.\n */\nexport class Subscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\t/** The topic's message union — what types the events this subscriber receives. */\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTSubscribedEvents extends\n\t\tExtractPublisherMessage<TEventPublisher>['type'][] = ExtractPublisherMessage<TEventPublisher>['type'][],\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends Construct<\n\tTLogger,\n\tOutSchema,\n\tTServices,\n\tstring,\n\tundefined,\n\tTDatabaseServiceName,\n\tTDatabase\n> {\n\t__IS_SUBSCRIBER__ = true;\n\n\tstatic isSubscriber(\n\t\tobj: any,\n\t): obj is Subscriber<any, any, any, any, any, any> {\n\t\treturn Boolean(\n\t\t\tobj &&\n\t\t\t\tobj.__IS_SUBSCRIBER__ === true &&\n\t\t\t\tobj.type === ConstructType.Subscriber,\n\t\t);\n\t}\n\n\tconstructor(\n\t\tpublic readonly handler: SubscriberHandler<\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase\n\t\t>,\n\t\tpublic override readonly timeout: number = 30000,\n\t\tprotected _subscribedEvents?: TSubscribedEvents,\n\t\tpublic override readonly outputSchema?: OutSchema,\n\t\tpublic override readonly services: TServices = [] as unknown as TServices,\n\t\tpublic override readonly logger: TLogger = DEFAULT_LOGGER as TLogger,\n\t\t/**\n\t\t * The name of the {@link Topic} this subscriber binds to (via\n\t\t * `worker.topic(topic)`), recorded for the manifest so infra wires the\n\t\t * SNS subscription.\n\t\t */\n\t\tpublic readonly topicName?: string,\n\t\t/**\n\t\t * The construct ids `.dependsOn()` named — last, so no existing positional\n\t\t * argument moves.\n\t\t */\n\t\tconstructs: string[] = [],\n\t\t/**\n\t\t * What the handler's `db` is registered from — after `constructs`, for\n\t\t * the same reason.\n\t\t */\n\t\tdatabaseService?: Service<TDatabaseServiceName, TDatabase>,\n\t) {\n\t\tsuper(\n\t\t\tConstructType.Subscriber,\n\t\t\tlogger,\n\t\t\tservices,\n\t\t\t[],\n\t\t\toutputSchema,\n\t\t\ttimeout,\n\t\t\tundefined, // memorySize\n\t\t\tundefined, // auditorStorageService\n\t\t\tconstructs,\n\t\t);\n\n\t\tthis.databaseService = databaseService;\n\t}\n\n\t/**\n\t * The id of the bucket this subscriber is bound to (via\n\t * `worker.objects(bucket)`), when its topic is the storage itself — read\n\t * by the build to bind it, and by the adaptors to read what the storage\n\t * sends as object events.\n\t */\n\tbucketName?: string;\n\n\t/** Which of the bucket's keys it watches — see `worker.objects()`. */\n\tobjectFilter?: { prefix?: string; suffix?: string };\n\n\tget subscribedEvents(): TSubscribedEvents | undefined {\n\t\treturn this._subscribedEvents;\n\t}\n}\n\n// Handler type for subscribers that receives an array of events\nexport type SubscriberHandler<\n\tTEventPublisher extends EventPublisher<any> | undefined,\n\tTSubscribedEvents extends ExtractPublisherMessage<TEventPublisher>['type'][],\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: SubscriberContext<\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tTServices,\n\t\tTLogger,\n\t\tTDatabase\n\t>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\n// Context type for subscriber handlers — `db` only when a database is set.\nexport type SubscriberContext<\n\tTEventPublisher extends EventPublisher<any> | undefined,\n\tTSubscribedEvents extends ExtractPublisherMessage<TEventPublisher>['type'][],\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\tevents: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[];\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n","import type {\n\tEventPublisher,\n\tExtractPublisherMessage,\n} from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { cloneWith } from '../clone';\nimport {\n\ttype Consumable,\n\tdatabaseEdges,\n\tidsOf,\n\ttype ServicesOf,\n\tserviceOf,\n\tservicesOf,\n} from '../construct-interface';\nimport type { Topic, TopicEvents, TopicMessage } from '../topic/Topic';\nimport { Subscriber, type SubscriberHandler } from './Subscriber';\n\nexport class SubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTSubscribedEvents extends any[] = [],\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tprivate _subscribedEvents: TSubscribedEvents = [] as any;\n\tprivate _timeout?: number;\n\tprivate outputSchema?: OutSchema;\n\tprivate _services: TServices = [] as Service[] as TServices;\n\t/** The construct ids `.dependsOn()` named — what the manifest records. */\n\tpublic _constructs: string[] = [];\n\tprivate _logger: TLogger = DEFAULT_LOGGER;\n\t/**\n\t * The deploy unit that runs this, by construct id. Seeded by the factory a\n\t * `Worker` hands out, so a subscriber is not owned by its directory.\n\t */\n\tpublic _owner?: string;\n\tprivate _topicName?: string;\n\t/** What the handler's `db` comes from — the worker's, unless overridden. */\n\tprivate _databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\t/** The edge `.database()` added, so the next one can replace it. */\n\tprivate _databaseEdge?: string;\n\n\tconstructor() {\n\t\tthis._timeout = 30000; // Default timeout\n\t}\n\n\t/**\n\t * Bind this subscriber to a {@link Topic}: the subscribable event types (and\n\t * their payloads) come from the topic's contract, and the binding is recorded\n\t * for the manifest, so infra wires the SNS subscription.\n\t *\n\t * A consumer does not publish, so binding a topic does *not* hand it the\n\t * topic's publisher connection string (least privilege). One that publishes\n\t * follow-up events depends on the topic it publishes to: `.dependsOn([orders])`.\n\t */\n\ttopic<TName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TName, TEvents>,\n\t): SubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tEventPublisher<TopicMessage<TEvents>>,\n\t\tTSubscribedEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\t_topicName: topic.name,\n\t\t}) as unknown as SubscriberBuilder<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tEventPublisher<TopicMessage<TEvents>>,\n\t\t\tTSubscribedEvents,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn cloneWith(this, { _timeout: timeout });\n\t}\n\n\toutput<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): SubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\toutputSchema: schema as unknown as OutSchema,\n\t\t}) as any;\n\t}\n\n\t/**\n\t * Depend on constructs — a database, a bucket, a mail sender, a queue, a\n\t * topic.\n\t *\n\t * It records the edge and dissolves each construct's client into the\n\t * handler's service record under the construct's own id, so\n\t * `.dependsOn([uploads])` is what makes `services.uploads` exist and type.\n\t *\n\t * Constructs only. A `Service` does not match the shape, which is what keeps\n\t * env sniffing confined to `.services()` and the explicit lift.\n\t */\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): SubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\t// Both halves of the edge, from one call and one clone: the services the\n\t\t// handler runs with, and the ids the manifest records. Recording them\n\t\t// separately is what let them drift apart.\n\t\t//\n\t\t// `servicesOf` is the half that validates, so it runs first — recording\n\t\t// ids ahead of it left a caught `NotAConstruct` with `undefined` already\n\t\t// on a `string[]`.\n\t\tconst services = servicesOf(constructs) as unknown as Service[];\n\n\t\treturn cloneWith(this, {\n\t\t\t_services: [...this._services, ...services],\n\t\t\t_constructs: idsOf(constructs, this._constructs),\n\t\t}) as unknown as SubscriberBuilder<\n\t\t\t[...TServices, ...ServicesOf<T>],\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\tservices<T extends Service[]>(\n\t\tservices: T,\n\t): SubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\t_services: [...this._services, ...services] as any,\n\t\t}) as any;\n\t}\n\n\tlogger<T extends Logger>(\n\t\tlogger: T,\n\t): SubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, { _logger: logger as unknown as TLogger }) as any;\n\t}\n\n\t/**\n\t * The database the handler receives as `db`.\n\t *\n\t * A subscriber built from a worker already has the worker's, when the\n\t * worker named one with `.database(db)`; this replaces it — the edge as well\n\t * as the client — for a consumer that works against a different database.\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): SubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tT,\n\t\tTDbName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\t_databaseService: serviceOf(source),\n\t\t\t...databaseEdges(\n\t\t\t\t{\n\t\t\t\t\tconstructs: this._constructs,\n\t\t\t\t\tedge: this._databaseEdge,\n\t\t\t\t\tservice: this._databaseService as Service | undefined,\n\t\t\t\t\tservices: this._services,\n\t\t\t\t},\n\t\t\t\tsource,\n\t\t\t),\n\t\t}) as unknown as SubscriberBuilder<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tT,\n\t\t\tTDbName\n\t\t>;\n\t}\n\n\tsubscribe<\n\t\tTEvent extends TEventPublisher extends EventPublisher<any>\n\t\t\t?\n\t\t\t\t\t| ExtractPublisherMessage<TEventPublisher>['type']\n\t\t\t\t\t| ExtractPublisherMessage<TEventPublisher>['type'][]\n\t\t\t: never,\n\t>(\n\t\tevent: TEvent,\n\t): SubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEventPublisher,\n\t\tTEvent extends any[]\n\t\t\t? [...TSubscribedEvents, ...TEvent]\n\t\t\t: [...TSubscribedEvents, TEvent],\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst eventsToAdd = Array.isArray(event) ? event : [event];\n\t\treturn cloneWith(this, {\n\t\t\t_subscribedEvents: [...this._subscribedEvents, ...eventsToAdd] as any,\n\t\t}) as any;\n\t}\n\n\thandle(\n\t\tfn: SubscriberHandler<\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase\n\t\t>,\n\t): Subscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTEventPublisher,\n\t\tTSubscribedEvents,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst subscriber = new Subscriber(\n\t\t\tfn,\n\t\t\tthis._timeout,\n\t\t\tthis._subscribedEvents,\n\t\t\tthis.outputSchema,\n\t\t\tthis._services,\n\t\t\tthis._logger,\n\t\t\tthis._topicName,\n\t\t\tthis._constructs,\n\t\t\tthis._databaseService,\n\t\t);\n\n\t\t// Which process runs it. Carried from the factory rather than inferred\n\t\t// from the directory the file happens to sit in.\n\t\tsubscriber.owner = this._owner;\n\n\t\t// No reset: `.handle()` reads this builder and leaves it alone, so a\n\t\t// configured base stays usable for the next subscriber.\n\t\treturn subscriber;\n\t}\n}\n"],"mappings":";;;;;;AAkEA,IAAa,8BAAb,cAAiD,MAAM;CACjC;CAArB,YAAY,QAAyB;EACpC,MACC,0BAA0B,OAAO,qGAElC;EAJoB,KAAA,SAAA;EAKpB,KAAK,OAAO;CACb;AACD;;;;;;;;;AAUA,IAAa,0BAAb,MAAa,wBAOX;CAGiB;CAUA;CACA;CACA;CAdlB,YAEC,OAUA,QACA,SAAsD,CAAC,GACvD,SAAwC,CAAC,GACxC;EAbgB,KAAA,QAAA;EAUA,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;CACf;;;;;CAMH,GACC,QACA,SAAuB,CAAC,GAQvB;EACD,OAAO,IAAI,wBACV,KAAK,OACL,KAAK,QACL,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,KAAK,QAAQ,GAAG,MAAM,CAAC,CAAC,GACxC;GACC,GAAI,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;GACjD,GAAI,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;EAClD,CACD;CACD;;CAGA,UACC,YAQC;EACD,OAAO,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