@geekmidas/constructs 10.0.0-alpha.141 → 10.0.0-alpha.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/worker.cjs CHANGED
@@ -7,13 +7,42 @@ const require_QueueBuilder = require("./QueueBuilder-BxsZ9o5z.cjs");
7
7
  const require_SubscriberBuilder = require("./SubscriberBuilder-CWzKwX1p.cjs");
8
8
  let _geekmidas_manifest = require("@geekmidas/manifest");
9
9
  let _geekmidas_logger_console = require("@geekmidas/logger/console");
10
+ let _geekmidas_emailkit = require("@geekmidas/emailkit");
10
11
  //#region src/subscribers/InboxSubscriberBuilder.ts
12
+ /**
13
+ * A subscriber bound to an inbox: a topic subscriber whose topic the inbox
14
+ * declares and the provider publishes to, so it runs through the same adaptors
15
+ * — Lambda, SNS push, a polled broker, a feature test.
16
+ *
17
+ * What it is delivered is a receipt notification; what its handler is handed
18
+ * is the messages, parsed, one per envelope recipient the inbox receives at.
19
+ * The inbox's own client does that, which is also why the handler can read
20
+ * its inbox's raw messages without naming it in `.dependsOn`.
21
+ *
22
+ * **Loops.** Mail sent while the handler runs is marked
23
+ * `Auto-Submitted: auto-replied`, and mail that arrives marked automatic is
24
+ * dropped before the handler sees it (RFC 3834). Together they stop a reply
25
+ * coming back to an inbox and being answered again — the app's own inboxes, or
26
+ * someone's out-of-office. `.automated()` hands a handler that mail instead.
27
+ * This is the handler every adaptor runs, so dev, tests and SES drop alike.
28
+ */
11
29
  var InboxSubscriberBuilder = class InboxSubscriberBuilder {
12
30
  inner;
13
31
  inbox;
14
- constructor(inner, inbox) {
32
+ acceptsAutomated;
33
+ constructor(inner, inbox, acceptsAutomated = false) {
15
34
  this.inner = inner;
16
35
  this.inbox = inbox;
36
+ this.acceptsAutomated = acceptsAutomated;
37
+ }
38
+ /**
39
+ * Hands this handler mail marked `Auto-Submitted` too — auto-replies,
40
+ * out-of-office notices, bounces — which are otherwise dropped so a reply
41
+ * can never be answered by another. A handler that takes them should not
42
+ * reply to them.
43
+ */
44
+ automated() {
45
+ return new InboxSubscriberBuilder(this.inner, this.inbox, true);
17
46
  }
18
47
  dependsOn(constructs) {
19
48
  return this.with(this.inner.dependsOn(constructs));
@@ -35,17 +64,27 @@ var InboxSubscriberBuilder = class InboxSubscriberBuilder {
35
64
  }
36
65
  handle(fn) {
37
66
  const key = (0, _geekmidas_manifest.serviceKey)(this.inbox.id);
67
+ const acceptsAutomated = this.acceptsAutomated;
38
68
  const handler = async (ctx) => {
39
69
  const inbox = ctx.services[key];
40
70
  const notifications = ctx.events.filter((event) => event?.type === _geekmidas_manifest.INBOX_EVENT);
41
71
  const messages = [];
42
- for (const { payload } of notifications) messages.push(...await inbox.messages(payload));
72
+ for (const { payload } of notifications) for (const message of await inbox.messages(payload)) {
73
+ if (!acceptsAutomated && (0, _geekmidas_emailkit.isAutoSubmitted)(message.headers)) {
74
+ ctx.logger.debug({
75
+ recipient: message.recipient.address,
76
+ autoSubmitted: message.headers["auto-submitted"]
77
+ }, "Dropped automatic mail: it is never answered");
78
+ continue;
79
+ }
80
+ messages.push(message);
81
+ }
43
82
  if (messages.length === 0) return void 0;
44
- return fn({
83
+ return (0, _geekmidas_emailkit.autoReplying)(() => fn({
45
84
  ...ctx,
46
85
  messages,
47
86
  inbox
48
- });
87
+ }));
49
88
  };
50
89
  const subscriber = this.inner.subscribe([_geekmidas_manifest.INBOX_EVENT]).handle(handler);
51
90
  subscriber.inboxName = this.inbox.id;
@@ -53,7 +92,7 @@ var InboxSubscriberBuilder = class InboxSubscriberBuilder {
53
92
  return subscriber;
54
93
  }
55
94
  with(inner) {
56
- return new InboxSubscriberBuilder(inner, this.inbox);
95
+ return new InboxSubscriberBuilder(inner, this.inbox, this.acceptsAutomated);
57
96
  }
58
97
  };
59
98
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"worker.cjs","names":["serviceKey","INBOX_EVENT","canonicalId","DEFAULT_LOGGER","envParserFor","edgeTo","CronBuilder","QueueBuilder","SubscriberBuilder","ObjectSubscriberBuilder","FunctionBuilder"],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"sourcesContent":["/**\n * A subscriber bound to an inbox: a topic subscriber whose topic the inbox\n * declares and the provider publishes to, so it runs through the same adaptors\n * — Lambda, SNS push, a polled broker, a feature test.\n *\n * What it is delivered is a receipt notification; what its handler is handed\n * is the messages, parsed, one per envelope recipient the inbox receives at.\n * The inbox's own client does that, which is also why the handler can read\n * its inbox's raw messages without naming it in `.dependsOn`.\n */\n\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT, serviceKey } from '@geekmidas/manifest';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable, ServicesOf } from '../construct-interface';\nimport type { DatabaseContext } from '../functions/Function';\nimport type {\n\tInbox,\n\tInboxClient,\n\tInboxMessage,\n\tReceiptNotification,\n} from '../inbox';\nimport type { Subscriber } from './Subscriber';\nimport type { SubscriberBuilder } from './SubscriberBuilder';\n\nexport type InboxSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> = Subscriber<\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tEventPublisher<{ type: typeof INBOX_EVENT; payload: ReceiptNotification }>,\n\t[typeof INBOX_EVENT],\n\tTDatabase,\n\tTDatabaseServiceName\n>;\n\nexport type InboxSubscriberContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\t/** The messages received, one per envelope recipient the inbox takes. */\n\tmessages: InboxMessage[];\n\t/** The inbox, under its own id too: its domain and its raw messages. */\n\tinbox: InboxClient;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n\nexport type InboxSubscriberHandler<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: InboxSubscriberContext<TServices, TLogger, TDatabase>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\nexport class InboxSubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tconstructor(\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\tprivate readonly inbox: Inbox<string>,\n\t) {}\n\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): InboxSubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\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): InboxSubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.services(services));\n\t}\n\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName> {\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\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: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>,\n\t): InboxSubscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst key = serviceKey(this.inbox.id);\n\n\t\t// Every adaptor hands the handler `{ type, payload }` messages; each\n\t\t// payload here is a receipt notification, and the inbox's client turns\n\t\t// it into the messages for the recipients it receives at.\n\t\tconst handler = async (ctx: Record<string, any>) => {\n\t\t\tconst inbox = ctx.services[key] as InboxClient;\n\t\t\tconst notifications = (ctx.events as unknown[]).filter(\n\t\t\t\t(event): event is { type: string; payload: ReceiptNotification } =>\n\t\t\t\t\t(event as { type?: string })?.type === INBOX_EVENT,\n\t\t\t);\n\t\t\tconst messages: InboxMessage[] = [];\n\t\t\tfor (const { payload } of notifications) {\n\t\t\t\tmessages.push(...(await inbox.messages(payload)));\n\t\t\t}\n\t\t\tif (messages.length === 0) return undefined;\n\t\t\treturn fn({\n\t\t\t\t...ctx,\n\t\t\t\tmessages,\n\t\t\t\tinbox,\n\t\t\t} as unknown as InboxSubscriberContext<TServices, TLogger, TDatabase>);\n\t\t};\n\n\t\tconst subscriber = this.inner\n\t\t\t.subscribe([INBOX_EVENT] as never)\n\t\t\t.handle(handler as never) as unknown as InboxSubscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t\tsubscriber.inboxName = this.inbox.id;\n\t\tsubscriber.inboxAddressing = this.inbox.addressing;\n\t\treturn subscriber;\n\t}\n\n\tprivate with(inner: SubscriberBuilder<any, any, any, any, any, any, any>) {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tinner,\n\t\t\tthis.inbox,\n\t\t);\n\t}\n}\n","/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * ## The database is everything's default\n *\n * The same `.database(db)` is the database every cron, queue, subscriber and\n * function built from the worker receives as `db`. The work a worker groups is\n * usually work against one database, and naming it per handler was a line\n * repeated in every file that could drift in any one of them. A runnable that\n * works against another names its own with `.database(other)`, which replaces\n * the worker's — client and manifest edge both — rather than adding to it.\n *\n * It is not an app: it declares no path, and its code lives in an app's\n * directory. But it is a process of its own. On a server target each worker\n * with work to do is built — from the app that holds that work — into an image\n * that runs its crons, consumers and subscribers and answers only a health\n * check, so a slow queue never shares a process with the requests an API\n * serves. `gkm dev` still runs everything in one process. Declare as many as\n * the shape of the work wants: each is one container.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).database(database);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ db, logger }) => { … });\n *\n * // queues/reports.ts — against another database than the worker's\n * export const reports = worker\n * .queue('Reports')\n * .database(analytics)\n * .message(z.object({ id: z.uuid() }))\n * .handle(async ({ messages, db }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport type { Inbox } from './inbox';\nimport type { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { InboxSubscriberBuilder } from './subscribers/InboxSubscriberBuilder';\nimport { ObjectSubscriberBuilder } from './subscribers/ObjectSubscriberBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Telemetry } from './telemetry';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * What the worker's process emits — the `Telemetry` construct, passed like\n\t * the logger. An edge to the node: the deploy hands the process the\n\t * `OTEL_*` keys its stage resolves.\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport class Worker<\n\tTName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them — and the database everything built from it receives as `db`.\n\t * `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.database()` carries its edge into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in, and the one everything\n\t * built from it — crons, queues, subscribers, functions — receives as `db`.\n\t * One of them that works against another database names it with its own\n\t * `.database(other)`, which replaces this one for that runnable alone.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t *\n\t * export const sweep = jobs\n\t * .cron('rate(1 hour)')\n\t * .handle(async ({ db }) => db.deleteFrom('sessions').execute());\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName, T, TDbName> {\n\t\treturn new Worker<TName, T, TDbName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(\n\t\t\tnew CronBuilder<\n\t\t\t\tComposableStandardSchema,\n\t\t\t\tService[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(\n\t\t\tnew QueueBuilder<\n\t\t\t\tstring,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).queue(name);\n\t}\n\n\t/**\n\t * A runnable that reacts to a bucket's objects changing.\n\t *\n\t * A bucket is a topic whose publisher is the storage: the binding is the\n\t * same as {@link Worker.topic}'s, and so is everything after it — the\n\t * services, the database, how it is delivered. The handler is handed the\n\t * objects; reading one still means depending on the bucket,\n\t * `.dependsOn([uploads])`.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onAvatar = worker\n\t * .objects(uploads)\n\t * .on(['object.created'], { prefix: 'avatars/', suffix: '.png' })\n\t * .handle(async ({ objects }) => { … });\n\t * ```\n\t */\n\tobjects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t\treturn new ObjectSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\t[],\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, bucket.id);\n\t}\n\n\t/**\n\t * A runnable handed the mail an {@link Inbox} receives.\n\t *\n\t * Bound, as a topic subscriber is: the inbox's topic is what it consumes,\n\t * and what it is handed is the messages on it, parsed — one per envelope\n\t * recipient the inbox receives at. It reads its inbox's raw messages\n\t * without depending on it; anything else it uses it names, as ever.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onRequest = worker\n\t * .inbox(requests)\n\t * .handle(async ({ messages, db }) => {\n\t * for (const message of messages) message.recipient.subdomain;\n\t * });\n\t * ```\n\t */\n\tinbox<TInboxName extends string>(inbox: Inbox<TInboxName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t)\n\t\t\t.topic(inbox.topic)\n\t\t\t// The inbox itself: its client reads the raw messages from the\n\t\t\t// inbox's own bucket, which is what the edge grants — and nothing\n\t\t\t// the handler did not name besides.\n\t\t\t.dependsOn([inbox]);\n\t\treturn new InboxSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, inbox);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<\n\t\t\t\tWorker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']\n\t\t\t>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(\n\t\t\tnew FunctionBuilder<\n\t\t\t\tany,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tstring,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it — and hands it the worker's database.\n\t *\n\t * The database goes through the builder's own `.database()` rather than\n\t * being written into its fields, so the default is recorded exactly as an\n\t * explicit one would be: the client the handler gets, and the edge the\n\t * manifest reads. That is also what lets a later `.database(other)` replace\n\t * it outright. The builder arrives already typed with this worker's\n\t * database; this is the runtime half of that.\n\t */\n\tprivate own<\n\t\tT extends {\n\t\t\t_owner?: string;\n\t\t\t_scheduleStore?: unknown;\n\t\t\tdatabase(source: Consumable<string, unknown>): unknown;\n\t\t},\n\t>(builder: T): T {\n\t\tconst owned = this.scheduleStore\n\t\t\t? (builder.database(this.scheduleStore) as T)\n\t\t\t: builder;\n\n\t\towned._owner = this.id;\n\t\towned._scheduleStore = this.scheduleStore;\n\n\t\treturn owned;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;AAoEA,IAAa,yBAAb,MAAa,uBAMX;CAEiB;CASA;CAVlB,YACC,OASA,OACC;EAVgB,KAAA,QAAA;EASA,KAAA,QAAA;CACf;CAEH,UACC,YAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,UAAU,UAAU,CAAC;CAClD;CAEA,SACC,UAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,QAAQ,CAAC;CAC/C;CAEA,SACC,QACoE;EACpE,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC;CAC7C;CAEA,QAAQ,SAAuB;EAC9B,OAAO,KAAK,KAAK,KAAK,MAAM,QAAQ,OAAO,CAAC;CAC7C;CAEA,OACC,QAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,CAAC;CAC3C;CAEA,OACC,QAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,CAAC;CAC3C;CAEA,OACC,IAOC;EACD,MAAM,OAAA,GA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AKF;EACD,OAAO,KAAK,mBAAmB,CAAC,CAAC,OAAO,GAAG,IAAI;CAChD;;CAGA,qBAA6B;EAC5B,OAAO,KAAK;CACb;;CAGA,IAAY,YAAY;EACvB,OAAO,KAAK,IACX,IAAIE,kBAAAA,gBASF,CAAC,CAAC,OAAO,KAAK,MAAM,CACvB;CACD;;;;;;;;;;;;CAaA,IAME,SAAe;EAChB,MAAM,QAAQ,KAAK,gBACf,QAAQ,SAAS,KAAK,aAAa,IACpC;EAEH,MAAM,SAAS,KAAK;EACpB,MAAM,iBAAiB,KAAK;EAE5B,OAAO;CACR;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAa,IAClC,CAAC;GACJ,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
1
+ {"version":3,"file":"worker.cjs","names":["serviceKey","INBOX_EVENT","isAutoSubmitted","autoReplying","canonicalId","DEFAULT_LOGGER","envParserFor","edgeTo","CronBuilder","QueueBuilder","SubscriberBuilder","ObjectSubscriberBuilder","FunctionBuilder"],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"sourcesContent":["/**\n * A subscriber bound to an inbox: a topic subscriber whose topic the inbox\n * declares and the provider publishes to, so it runs through the same adaptors\n * — Lambda, SNS push, a polled broker, a feature test.\n *\n * What it is delivered is a receipt notification; what its handler is handed\n * is the messages, parsed, one per envelope recipient the inbox receives at.\n * The inbox's own client does that, which is also why the handler can read\n * its inbox's raw messages without naming it in `.dependsOn`.\n *\n * **Loops.** Mail sent while the handler runs is marked\n * `Auto-Submitted: auto-replied`, and mail that arrives marked automatic is\n * dropped before the handler sees it (RFC 3834). Together they stop a reply\n * coming back to an inbox and being answered again — the app's own inboxes, or\n * someone's out-of-office. `.automated()` hands a handler that mail instead.\n * This is the handler every adaptor runs, so dev, tests and SES drop alike.\n */\n\nimport { autoReplying, isAutoSubmitted } from '@geekmidas/emailkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT, serviceKey } from '@geekmidas/manifest';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable, ServicesOf } from '../construct-interface';\nimport type { DatabaseContext } from '../functions/Function';\nimport type {\n\tInbox,\n\tInboxClient,\n\tInboxMessage,\n\tReceiptNotification,\n} from '../inbox';\nimport type { Subscriber } from './Subscriber';\nimport type { SubscriberBuilder } from './SubscriberBuilder';\n\nexport type InboxSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> = Subscriber<\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tEventPublisher<{ type: typeof INBOX_EVENT; payload: ReceiptNotification }>,\n\t[typeof INBOX_EVENT],\n\tTDatabase,\n\tTDatabaseServiceName\n>;\n\nexport type InboxSubscriberContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\t/** The messages received, one per envelope recipient the inbox takes. */\n\tmessages: InboxMessage[];\n\t/** The inbox, under its own id too: its domain and its raw messages. */\n\tinbox: InboxClient;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n\nexport type InboxSubscriberHandler<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: InboxSubscriberContext<TServices, TLogger, TDatabase>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\nexport class InboxSubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tconstructor(\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\tprivate readonly inbox: Inbox<string>,\n\t\tprivate readonly acceptsAutomated = false,\n\t) {}\n\n\t/**\n\t * Hands this handler mail marked `Auto-Submitted` too — auto-replies,\n\t * out-of-office notices, bounces — which are otherwise dropped so a reply\n\t * can never be answered by another. A handler that takes them should not\n\t * reply to them.\n\t */\n\tautomated(): this {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tthis.inner,\n\t\t\tthis.inbox,\n\t\t\ttrue,\n\t\t) as this;\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): InboxSubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\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): InboxSubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.services(services));\n\t}\n\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName> {\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\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: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>,\n\t): InboxSubscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst key = serviceKey(this.inbox.id);\n\t\tconst acceptsAutomated = this.acceptsAutomated;\n\n\t\t// Every adaptor hands the handler `{ type, payload }` messages; each\n\t\t// payload here is a receipt notification, and the inbox's client turns\n\t\t// it into the messages for the recipients it receives at.\n\t\tconst handler = async (ctx: Record<string, any>) => {\n\t\t\tconst inbox = ctx.services[key] as InboxClient;\n\t\t\tconst notifications = (ctx.events as unknown[]).filter(\n\t\t\t\t(event): event is { type: string; payload: ReceiptNotification } =>\n\t\t\t\t\t(event as { type?: string })?.type === INBOX_EVENT,\n\t\t\t);\n\t\t\tconst messages: InboxMessage[] = [];\n\t\t\tfor (const { payload } of notifications) {\n\t\t\t\tfor (const message of await inbox.messages(payload)) {\n\t\t\t\t\tif (!acceptsAutomated && isAutoSubmitted(message.headers)) {\n\t\t\t\t\t\tctx.logger.debug(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trecipient: message.recipient.address,\n\t\t\t\t\t\t\t\tautoSubmitted: message.headers['auto-submitted'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t'Dropped automatic mail: it is never answered',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tmessages.push(message);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (messages.length === 0) return undefined;\n\t\t\treturn autoReplying(() =>\n\t\t\t\tfn({\n\t\t\t\t\t...ctx,\n\t\t\t\t\tmessages,\n\t\t\t\t\tinbox,\n\t\t\t\t} as unknown as InboxSubscriberContext<TServices, TLogger, TDatabase>),\n\t\t\t);\n\t\t};\n\n\t\tconst subscriber = this.inner\n\t\t\t.subscribe([INBOX_EVENT] as never)\n\t\t\t.handle(handler as never) as unknown as InboxSubscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t\tsubscriber.inboxName = this.inbox.id;\n\t\tsubscriber.inboxAddressing = this.inbox.addressing;\n\t\treturn subscriber;\n\t}\n\n\tprivate with(inner: SubscriberBuilder<any, any, any, any, any, any, any>) {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tinner,\n\t\t\tthis.inbox,\n\t\t\tthis.acceptsAutomated,\n\t\t);\n\t}\n}\n","/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * ## The database is everything's default\n *\n * The same `.database(db)` is the database every cron, queue, subscriber and\n * function built from the worker receives as `db`. The work a worker groups is\n * usually work against one database, and naming it per handler was a line\n * repeated in every file that could drift in any one of them. A runnable that\n * works against another names its own with `.database(other)`, which replaces\n * the worker's — client and manifest edge both — rather than adding to it.\n *\n * It is not an app: it declares no path, and its code lives in an app's\n * directory. But it is a process of its own. On a server target each worker\n * with work to do is built — from the app that holds that work — into an image\n * that runs its crons, consumers and subscribers and answers only a health\n * check, so a slow queue never shares a process with the requests an API\n * serves. `gkm dev` still runs everything in one process. Declare as many as\n * the shape of the work wants: each is one container.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).database(database);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ db, logger }) => { … });\n *\n * // queues/reports.ts — against another database than the worker's\n * export const reports = worker\n * .queue('Reports')\n * .database(analytics)\n * .message(z.object({ id: z.uuid() }))\n * .handle(async ({ messages, db }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport type { Inbox } from './inbox';\nimport type { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { InboxSubscriberBuilder } from './subscribers/InboxSubscriberBuilder';\nimport { ObjectSubscriberBuilder } from './subscribers/ObjectSubscriberBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Telemetry } from './telemetry';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * What the worker's process emits — the `Telemetry` construct, passed like\n\t * the logger. An edge to the node: the deploy hands the process the\n\t * `OTEL_*` keys its stage resolves.\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport class Worker<\n\tTName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them — and the database everything built from it receives as `db`.\n\t * `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.database()` carries its edge into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in, and the one everything\n\t * built from it — crons, queues, subscribers, functions — receives as `db`.\n\t * One of them that works against another database names it with its own\n\t * `.database(other)`, which replaces this one for that runnable alone.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t *\n\t * export const sweep = jobs\n\t * .cron('rate(1 hour)')\n\t * .handle(async ({ db }) => db.deleteFrom('sessions').execute());\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName, T, TDbName> {\n\t\treturn new Worker<TName, T, TDbName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(\n\t\t\tnew CronBuilder<\n\t\t\t\tComposableStandardSchema,\n\t\t\t\tService[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(\n\t\t\tnew QueueBuilder<\n\t\t\t\tstring,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).queue(name);\n\t}\n\n\t/**\n\t * A runnable that reacts to a bucket's objects changing.\n\t *\n\t * A bucket is a topic whose publisher is the storage: the binding is the\n\t * same as {@link Worker.topic}'s, and so is everything after it — the\n\t * services, the database, how it is delivered. The handler is handed the\n\t * objects; reading one still means depending on the bucket,\n\t * `.dependsOn([uploads])`.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onAvatar = worker\n\t * .objects(uploads)\n\t * .on(['object.created'], { prefix: 'avatars/', suffix: '.png' })\n\t * .handle(async ({ objects }) => { … });\n\t * ```\n\t */\n\tobjects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t\treturn new ObjectSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\t[],\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, bucket.id);\n\t}\n\n\t/**\n\t * A runnable handed the mail an {@link Inbox} receives.\n\t *\n\t * Bound, as a topic subscriber is: the inbox's topic is what it consumes,\n\t * and what it is handed is the messages on it, parsed — one per envelope\n\t * recipient the inbox receives at. It reads its inbox's raw messages\n\t * without depending on it; anything else it uses it names, as ever.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onRequest = worker\n\t * .inbox(requests)\n\t * .handle(async ({ messages, db }) => {\n\t * for (const message of messages) message.recipient.subdomain;\n\t * });\n\t * ```\n\t */\n\tinbox<TInboxName extends string>(inbox: Inbox<TInboxName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t)\n\t\t\t.topic(inbox.topic)\n\t\t\t// The inbox itself: its client reads the raw messages from the\n\t\t\t// inbox's own bucket, which is what the edge grants — and nothing\n\t\t\t// the handler did not name besides.\n\t\t\t.dependsOn([inbox]);\n\t\treturn new InboxSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, inbox);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<\n\t\t\t\tWorker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']\n\t\t\t>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(\n\t\t\tnew FunctionBuilder<\n\t\t\t\tany,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tstring,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it — and hands it the worker's database.\n\t *\n\t * The database goes through the builder's own `.database()` rather than\n\t * being written into its fields, so the default is recorded exactly as an\n\t * explicit one would be: the client the handler gets, and the edge the\n\t * manifest reads. That is also what lets a later `.database(other)` replace\n\t * it outright. The builder arrives already typed with this worker's\n\t * database; this is the runtime half of that.\n\t */\n\tprivate own<\n\t\tT extends {\n\t\t\t_owner?: string;\n\t\t\t_scheduleStore?: unknown;\n\t\t\tdatabase(source: Consumable<string, unknown>): unknown;\n\t\t},\n\t>(builder: T): T {\n\t\tconst owned = this.scheduleStore\n\t\t\t? (builder.database(this.scheduleStore) as T)\n\t\t\t: builder;\n\n\t\towned._owner = this.id;\n\t\towned._scheduleStore = this.scheduleStore;\n\n\t\treturn owned;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,IAAa,yBAAb,MAAa,uBAMX;CAEiB;CASA;CACA;CAXlB,YACC,OASA,OACA,mBAAoC,OACnC;EAXgB,KAAA,QAAA;EASA,KAAA,QAAA;EACA,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AE5B,OAAO;CACR;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAa,IAClC,CAAC;GACJ,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
package/dist/worker.d.cts CHANGED
@@ -35,7 +35,15 @@ type InboxSubscriberHandler<TServices extends Service[] = [], TLogger extends Lo
35
35
  declare class InboxSubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined, TDatabaseServiceName extends string = string> {
36
36
  private readonly inner;
37
37
  private readonly inbox;
38
- constructor(inner: SubscriberBuilder<any, any, any, any, any, any, any>, inbox: Inbox<string>);
38
+ private readonly acceptsAutomated;
39
+ constructor(inner: SubscriberBuilder<any, any, any, any, any, any, any>, inbox: Inbox<string>, acceptsAutomated?: boolean);
40
+ /**
41
+ * Hands this handler mail marked `Auto-Submitted` too — auto-replies,
42
+ * out-of-office notices, bounces — which are otherwise dropped so a reply
43
+ * can never be answered by another. A handler that takes them should not
44
+ * reply to them.
45
+ */
46
+ automated(): this;
39
47
  dependsOn<const T extends readonly Consumable[]>(constructs: T): InboxSubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
40
48
  services<T extends Service[]>(services: T): InboxSubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
41
49
  database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName>;
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.cts","names":["EventPublisher","_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/subscribers/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names":["EventPublisher","_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAoCY,gBACX,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,uBACA,gDACG,WACH,WACA,SACA,WACAA;EAAiB,aAAa;EAAa,SAAS;YAC5C,cACR,WACA;KAGW,uBACX,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB;;EAGA,UAAU;;EAEV,OAAO;EACP,UAAU,cAAc;EACxB,QAAQ;IACL,gBAAgB;KAER,uBACX,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,0BAEA,KAAK,uBAAuB,WAAW,SAAS,eAC5C,kBAAkB,mBACpB,oBAAoB,aAAa,QAAQ,oBAAoB,oBACvD;cAEI,uBACZ,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,uBACA;mBAGkB;mBASA;mBACA;EAXlB,YACkB,OAAO,sDASP,OAAO,eACP;;;;;;;EASlB;EAQA,gBAAgB,mBAAmB,cAClC,YAAY,IACV,2BACE,cAAc,WAAW,KAC7B,SACA,WACA,WACA;EAKD,SAAS,UAAU,WAClB,UAAU,IACR,2BACE,cAAc,IAClB,SACA,WACA,WACA;EAKD,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAAK,QAAQ,SAAS,KAChD,uBAAuB,WAAW,SAAS,WAAW,GAAG;EAI5D,QAAQ;EAIR,OAAO,UAAU,kBAChB,QAAQ,IACN,uBACF,WACA,SACA,GACA,WACA;EAKD,OAAO,UAAU,QAChB,QAAQ,IACN,uBACF,WACA,GACA,WACA,WACA;EAKD,OACC,IAAI,uBAAuB,WAAW,SAAS,WAAW,aACxD,gBACF,WACA,SACA,WACA,WACA;UAsDO;;;;iBC/HQ;;;;;;;;;EAShB,SAAS;;;;;;;EAOT,YA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AA,sBAAA,kCAAAD,yBAAA,mBAAA,sBAAA;;UAMM;;cAKI;;;;;;;;;;;;UA0BJ;EAiBR,WAAW"}
package/dist/worker.d.mts CHANGED
@@ -35,7 +35,15 @@ type InboxSubscriberHandler<TServices extends Service[] = [], TLogger extends Lo
35
35
  declare class InboxSubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined, TDatabaseServiceName extends string = string> {
36
36
  private readonly inner;
37
37
  private readonly inbox;
38
- constructor(inner: SubscriberBuilder<any, any, any, any, any, any, any>, inbox: Inbox<string>);
38
+ private readonly acceptsAutomated;
39
+ constructor(inner: SubscriberBuilder<any, any, any, any, any, any, any>, inbox: Inbox<string>, acceptsAutomated?: boolean);
40
+ /**
41
+ * Hands this handler mail marked `Auto-Submitted` too — auto-replies,
42
+ * out-of-office notices, bounces — which are otherwise dropped so a reply
43
+ * can never be answered by another. A handler that takes them should not
44
+ * reply to them.
45
+ */
46
+ automated(): this;
39
47
  dependsOn<const T extends readonly Consumable[]>(constructs: T): InboxSubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
40
48
  services<T extends Service[]>(services: T): InboxSubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
41
49
  database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName>;
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.mts","names":["EventPublisher","_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KA4BY,gBACX,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,uBACA,gDACG,WACH,WACA,SACA,WACAA;EAAiB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AAS,KAC1B,OAAO,OAAO,GAAG;;;;;;EAcpB,KAAK,UAAU,qBAAkB,YAAA,0BAAA,WAAA,mBAAA,WAAA;;;;;;;;;;;;;;;;;EA6BjC,MAAM,2BAA2B,MAAM,aAAU,aAAA,2BAAA,QAAA,WAAA;;;;;;;;;;;;;;;;;;EA8BjD,QAAQ,4BAA4B,QAAQ,cAAc,eAAY,4BAAA,uBAAA,WAAA;;;;;;;;;;;;;;;;;;EAuCtE,MAAM,2BAA2B,OAAO,MAAM,cAAW,2BAAA,mBAAA,WAAA;;;;;;;;;;;EAoCzD,MAAM,2BAA2B,gBAAgB,aAChD,OAAO,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAAC,aAAA,iBAAA,WAAA;;;;;;;;;;;;EA0BlC,MAAM,UAAU,0BAA0B,QAAQ,IAAC,gBAAA,kBAAA,2BAAA,WAAA,sBAAA;EAInD,OAAO,UAAU,kBAAkB,QAAQ,IAAC,qBAAA,OAAA,2BAAA,WAAA,sBAAA;EAI5C,QAAQ,aAAU,oCAAA,2BAAA,WAAA,sBAAA;EAIlB,WAAW,aAAU,oCAAA,2BAAA,WAAA,sBAAA;EAIrB,gBAAgB,mBAAmB,cAAc,YAAY,IAAC,oCAAAC,WAAA,KAAA,2BAAA,WAAA,sBAAA;EAI9D,SAAS,UAAU,WAAW,UAAU,IAAC,oCAAA,IAAA,2BAAA,WAAA,sBAAA;;;;;;EASzC,UACI,MAAM,WACR,WACC,OAAO,OAAO,WAAW,0DAE1BE,kBAAA,sCAAA,WAAA,sBAAA,kCAAAD,yBAAA,mBAAA,sBAAA;;UAMM;;cAKI;;;;;;;;;;;;UA0BJ;EAiBR,WAAW"}
1
+ {"version":3,"file":"worker.d.mts","names":["EventPublisher","_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAoCY,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EC8.mjs";
6
6
  import { r as ObjectSubscriberBuilder, t as SubscriberBuilder } from "./SubscriberBuilder-BL_GTcwh.mjs";
7
7
  import { INBOX_EVENT, canonicalId, serviceKey } from "@geekmidas/manifest";
8
8
  import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
9
+ import { autoReplying, isAutoSubmitted } from "@geekmidas/emailkit";
9
10
  //#region src/subscribers/InboxSubscriberBuilder.ts
11
+ /**
12
+ * A subscriber bound to an inbox: a topic subscriber whose topic the inbox
13
+ * declares and the provider publishes to, so it runs through the same adaptors
14
+ * — Lambda, SNS push, a polled broker, a feature test.
15
+ *
16
+ * What it is delivered is a receipt notification; what its handler is handed
17
+ * is the messages, parsed, one per envelope recipient the inbox receives at.
18
+ * The inbox's own client does that, which is also why the handler can read
19
+ * its inbox's raw messages without naming it in `.dependsOn`.
20
+ *
21
+ * **Loops.** Mail sent while the handler runs is marked
22
+ * `Auto-Submitted: auto-replied`, and mail that arrives marked automatic is
23
+ * dropped before the handler sees it (RFC 3834). Together they stop a reply
24
+ * coming back to an inbox and being answered again — the app's own inboxes, or
25
+ * someone's out-of-office. `.automated()` hands a handler that mail instead.
26
+ * This is the handler every adaptor runs, so dev, tests and SES drop alike.
27
+ */
10
28
  var InboxSubscriberBuilder = class InboxSubscriberBuilder {
11
29
  inner;
12
30
  inbox;
13
- constructor(inner, inbox) {
31
+ acceptsAutomated;
32
+ constructor(inner, inbox, acceptsAutomated = false) {
14
33
  this.inner = inner;
15
34
  this.inbox = inbox;
35
+ this.acceptsAutomated = acceptsAutomated;
36
+ }
37
+ /**
38
+ * Hands this handler mail marked `Auto-Submitted` too — auto-replies,
39
+ * out-of-office notices, bounces — which are otherwise dropped so a reply
40
+ * can never be answered by another. A handler that takes them should not
41
+ * reply to them.
42
+ */
43
+ automated() {
44
+ return new InboxSubscriberBuilder(this.inner, this.inbox, true);
16
45
  }
17
46
  dependsOn(constructs) {
18
47
  return this.with(this.inner.dependsOn(constructs));
@@ -34,17 +63,27 @@ var InboxSubscriberBuilder = class InboxSubscriberBuilder {
34
63
  }
35
64
  handle(fn) {
36
65
  const key = serviceKey(this.inbox.id);
66
+ const acceptsAutomated = this.acceptsAutomated;
37
67
  const handler = async (ctx) => {
38
68
  const inbox = ctx.services[key];
39
69
  const notifications = ctx.events.filter((event) => event?.type === INBOX_EVENT);
40
70
  const messages = [];
41
- for (const { payload } of notifications) messages.push(...await inbox.messages(payload));
71
+ for (const { payload } of notifications) for (const message of await inbox.messages(payload)) {
72
+ if (!acceptsAutomated && isAutoSubmitted(message.headers)) {
73
+ ctx.logger.debug({
74
+ recipient: message.recipient.address,
75
+ autoSubmitted: message.headers["auto-submitted"]
76
+ }, "Dropped automatic mail: it is never answered");
77
+ continue;
78
+ }
79
+ messages.push(message);
80
+ }
42
81
  if (messages.length === 0) return void 0;
43
- return fn({
82
+ return autoReplying(() => fn({
44
83
  ...ctx,
45
84
  messages,
46
85
  inbox
47
- });
86
+ }));
48
87
  };
49
88
  const subscriber = this.inner.subscribe([INBOX_EVENT]).handle(handler);
50
89
  subscriber.inboxName = this.inbox.id;
@@ -52,7 +91,7 @@ var InboxSubscriberBuilder = class InboxSubscriberBuilder {
52
91
  return subscriber;
53
92
  }
54
93
  with(inner) {
55
- return new InboxSubscriberBuilder(inner, this.inbox);
94
+ return new InboxSubscriberBuilder(inner, this.inbox, this.acceptsAutomated);
56
95
  }
57
96
  };
58
97
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"worker.mjs","names":[],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"sourcesContent":["/**\n * A subscriber bound to an inbox: a topic subscriber whose topic the inbox\n * declares and the provider publishes to, so it runs through the same adaptors\n * — Lambda, SNS push, a polled broker, a feature test.\n *\n * What it is delivered is a receipt notification; what its handler is handed\n * is the messages, parsed, one per envelope recipient the inbox receives at.\n * The inbox's own client does that, which is also why the handler can read\n * its inbox's raw messages without naming it in `.dependsOn`.\n */\n\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT, serviceKey } from '@geekmidas/manifest';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable, ServicesOf } from '../construct-interface';\nimport type { DatabaseContext } from '../functions/Function';\nimport type {\n\tInbox,\n\tInboxClient,\n\tInboxMessage,\n\tReceiptNotification,\n} from '../inbox';\nimport type { Subscriber } from './Subscriber';\nimport type { SubscriberBuilder } from './SubscriberBuilder';\n\nexport type InboxSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> = Subscriber<\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tEventPublisher<{ type: typeof INBOX_EVENT; payload: ReceiptNotification }>,\n\t[typeof INBOX_EVENT],\n\tTDatabase,\n\tTDatabaseServiceName\n>;\n\nexport type InboxSubscriberContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\t/** The messages received, one per envelope recipient the inbox takes. */\n\tmessages: InboxMessage[];\n\t/** The inbox, under its own id too: its domain and its raw messages. */\n\tinbox: InboxClient;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n\nexport type InboxSubscriberHandler<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: InboxSubscriberContext<TServices, TLogger, TDatabase>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\nexport class InboxSubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tconstructor(\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\tprivate readonly inbox: Inbox<string>,\n\t) {}\n\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): InboxSubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\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): InboxSubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.services(services));\n\t}\n\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName> {\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\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: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>,\n\t): InboxSubscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst key = serviceKey(this.inbox.id);\n\n\t\t// Every adaptor hands the handler `{ type, payload }` messages; each\n\t\t// payload here is a receipt notification, and the inbox's client turns\n\t\t// it into the messages for the recipients it receives at.\n\t\tconst handler = async (ctx: Record<string, any>) => {\n\t\t\tconst inbox = ctx.services[key] as InboxClient;\n\t\t\tconst notifications = (ctx.events as unknown[]).filter(\n\t\t\t\t(event): event is { type: string; payload: ReceiptNotification } =>\n\t\t\t\t\t(event as { type?: string })?.type === INBOX_EVENT,\n\t\t\t);\n\t\t\tconst messages: InboxMessage[] = [];\n\t\t\tfor (const { payload } of notifications) {\n\t\t\t\tmessages.push(...(await inbox.messages(payload)));\n\t\t\t}\n\t\t\tif (messages.length === 0) return undefined;\n\t\t\treturn fn({\n\t\t\t\t...ctx,\n\t\t\t\tmessages,\n\t\t\t\tinbox,\n\t\t\t} as unknown as InboxSubscriberContext<TServices, TLogger, TDatabase>);\n\t\t};\n\n\t\tconst subscriber = this.inner\n\t\t\t.subscribe([INBOX_EVENT] as never)\n\t\t\t.handle(handler as never) as unknown as InboxSubscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t\tsubscriber.inboxName = this.inbox.id;\n\t\tsubscriber.inboxAddressing = this.inbox.addressing;\n\t\treturn subscriber;\n\t}\n\n\tprivate with(inner: SubscriberBuilder<any, any, any, any, any, any, any>) {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tinner,\n\t\t\tthis.inbox,\n\t\t);\n\t}\n}\n","/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * ## The database is everything's default\n *\n * The same `.database(db)` is the database every cron, queue, subscriber and\n * function built from the worker receives as `db`. The work a worker groups is\n * usually work against one database, and naming it per handler was a line\n * repeated in every file that could drift in any one of them. A runnable that\n * works against another names its own with `.database(other)`, which replaces\n * the worker's — client and manifest edge both — rather than adding to it.\n *\n * It is not an app: it declares no path, and its code lives in an app's\n * directory. But it is a process of its own. On a server target each worker\n * with work to do is built — from the app that holds that work — into an image\n * that runs its crons, consumers and subscribers and answers only a health\n * check, so a slow queue never shares a process with the requests an API\n * serves. `gkm dev` still runs everything in one process. Declare as many as\n * the shape of the work wants: each is one container.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).database(database);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ db, logger }) => { … });\n *\n * // queues/reports.ts — against another database than the worker's\n * export const reports = worker\n * .queue('Reports')\n * .database(analytics)\n * .message(z.object({ id: z.uuid() }))\n * .handle(async ({ messages, db }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport type { Inbox } from './inbox';\nimport type { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { InboxSubscriberBuilder } from './subscribers/InboxSubscriberBuilder';\nimport { ObjectSubscriberBuilder } from './subscribers/ObjectSubscriberBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Telemetry } from './telemetry';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * What the worker's process emits — the `Telemetry` construct, passed like\n\t * the logger. An edge to the node: the deploy hands the process the\n\t * `OTEL_*` keys its stage resolves.\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport class Worker<\n\tTName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them — and the database everything built from it receives as `db`.\n\t * `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.database()` carries its edge into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in, and the one everything\n\t * built from it — crons, queues, subscribers, functions — receives as `db`.\n\t * One of them that works against another database names it with its own\n\t * `.database(other)`, which replaces this one for that runnable alone.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t *\n\t * export const sweep = jobs\n\t * .cron('rate(1 hour)')\n\t * .handle(async ({ db }) => db.deleteFrom('sessions').execute());\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName, T, TDbName> {\n\t\treturn new Worker<TName, T, TDbName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(\n\t\t\tnew CronBuilder<\n\t\t\t\tComposableStandardSchema,\n\t\t\t\tService[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(\n\t\t\tnew QueueBuilder<\n\t\t\t\tstring,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).queue(name);\n\t}\n\n\t/**\n\t * A runnable that reacts to a bucket's objects changing.\n\t *\n\t * A bucket is a topic whose publisher is the storage: the binding is the\n\t * same as {@link Worker.topic}'s, and so is everything after it — the\n\t * services, the database, how it is delivered. The handler is handed the\n\t * objects; reading one still means depending on the bucket,\n\t * `.dependsOn([uploads])`.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onAvatar = worker\n\t * .objects(uploads)\n\t * .on(['object.created'], { prefix: 'avatars/', suffix: '.png' })\n\t * .handle(async ({ objects }) => { … });\n\t * ```\n\t */\n\tobjects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t\treturn new ObjectSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\t[],\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, bucket.id);\n\t}\n\n\t/**\n\t * A runnable handed the mail an {@link Inbox} receives.\n\t *\n\t * Bound, as a topic subscriber is: the inbox's topic is what it consumes,\n\t * and what it is handed is the messages on it, parsed — one per envelope\n\t * recipient the inbox receives at. It reads its inbox's raw messages\n\t * without depending on it; anything else it uses it names, as ever.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onRequest = worker\n\t * .inbox(requests)\n\t * .handle(async ({ messages, db }) => {\n\t * for (const message of messages) message.recipient.subdomain;\n\t * });\n\t * ```\n\t */\n\tinbox<TInboxName extends string>(inbox: Inbox<TInboxName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t)\n\t\t\t.topic(inbox.topic)\n\t\t\t// The inbox itself: its client reads the raw messages from the\n\t\t\t// inbox's own bucket, which is what the edge grants — and nothing\n\t\t\t// the handler did not name besides.\n\t\t\t.dependsOn([inbox]);\n\t\treturn new InboxSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, inbox);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<\n\t\t\t\tWorker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']\n\t\t\t>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(\n\t\t\tnew FunctionBuilder<\n\t\t\t\tany,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tstring,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it — and hands it the worker's database.\n\t *\n\t * The database goes through the builder's own `.database()` rather than\n\t * being written into its fields, so the default is recorded exactly as an\n\t * explicit one would be: the client the handler gets, and the edge the\n\t * manifest reads. That is also what lets a later `.database(other)` replace\n\t * it outright. The builder arrives already typed with this worker's\n\t * database; this is the runtime half of that.\n\t */\n\tprivate own<\n\t\tT extends {\n\t\t\t_owner?: string;\n\t\t\t_scheduleStore?: unknown;\n\t\t\tdatabase(source: Consumable<string, unknown>): unknown;\n\t\t},\n\t>(builder: T): T {\n\t\tconst owned = this.scheduleStore\n\t\t\t? (builder.database(this.scheduleStore) as T)\n\t\t\t: builder;\n\n\t\towned._owner = this.id;\n\t\towned._scheduleStore = this.scheduleStore;\n\n\t\treturn owned;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;AAoEA,IAAa,yBAAb,MAAa,uBAMX;CAEiB;CASA;CAVlB,YACC,OASA,OACC;EAVgB,KAAA,QAAA;EASA,KAAA,QAAA;CACf;CAEH,UACC,YAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,UAAU,UAAU,CAAC;CAClD;CAEA,SACC,UAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,QAAQ,CAAC;CAC/C;CAEA,SACC,QACoE;EACpE,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC;CAC7C;CAEA,QAAQ,SAAuB;EAC9B,OAAO,KAAK,KAAK,KAAK,MAAM,QAAQ,OAAO,CAAC;CAC7C;CAEA,OACC,QAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,CAAC;CAC3C;CAEA,OACC,QAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,CAAC;CAC3C;CAEA,OACC,IAOC;EACD,MAAM,MAAM,WAAW,KAAK,MAAM,EAAE;EAKpC,MAAM,UAAU,OAAO,QAA6B;GACnD,MAAM,QAAQ,IAAI,SAAS;GAC3B,MAAM,gBAAiB,IAAI,OAAqB,QAC9C,UACC,OAA6B,SAAS,WACzC;GACA,MAAM,WAA2B,CAAC;GAClC,KAAK,MAAM,EAAE,aAAa,eACzB,SAAS,KAAK,GAAI,MAAM,MAAM,SAAS,OAAO,CAAE;GAEjD,IAAI,SAAS,WAAW,GAAG,OAAO,KAAA;GAClC,OAAO,GAAG;IACT,GAAG;IACH;IACA;GACD,CAAqE;EAC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AAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
1
+ {"version":3,"file":"worker.mjs","names":[],"sources":["../src/subscribers/InboxSubscriberBuilder.ts","../src/worker.ts"],"sourcesContent":["/**\n * A subscriber bound to an inbox: a topic subscriber whose topic the inbox\n * declares and the provider publishes to, so it runs through the same adaptors\n * — Lambda, SNS push, a polled broker, a feature test.\n *\n * What it is delivered is a receipt notification; what its handler is handed\n * is the messages, parsed, one per envelope recipient the inbox receives at.\n * The inbox's own client does that, which is also why the handler can read\n * its inbox's raw messages without naming it in `.dependsOn`.\n *\n * **Loops.** Mail sent while the handler runs is marked\n * `Auto-Submitted: auto-replied`, and mail that arrives marked automatic is\n * dropped before the handler sees it (RFC 3834). Together they stop a reply\n * coming back to an inbox and being answered again — the app's own inboxes, or\n * someone's out-of-office. `.automated()` hands a handler that mail instead.\n * This is the handler every adaptor runs, so dev, tests and SES drop alike.\n */\n\nimport { autoReplying, isAutoSubmitted } from '@geekmidas/emailkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { INBOX_EVENT, serviceKey } from '@geekmidas/manifest';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable, ServicesOf } from '../construct-interface';\nimport type { DatabaseContext } from '../functions/Function';\nimport type {\n\tInbox,\n\tInboxClient,\n\tInboxMessage,\n\tReceiptNotification,\n} from '../inbox';\nimport type { Subscriber } from './Subscriber';\nimport type { SubscriberBuilder } from './SubscriberBuilder';\n\nexport type InboxSubscriber<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> = Subscriber<\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tEventPublisher<{ type: typeof INBOX_EVENT; payload: ReceiptNotification }>,\n\t[typeof INBOX_EVENT],\n\tTDatabase,\n\tTDatabaseServiceName\n>;\n\nexport type InboxSubscriberContext<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTDatabase = undefined,\n> = {\n\t/** The messages received, one per envelope recipient the inbox takes. */\n\tmessages: InboxMessage[];\n\t/** The inbox, under its own id too: its domain and its raw messages. */\n\tinbox: InboxClient;\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n} & DatabaseContext<TDatabase>;\n\nexport type InboxSubscriberHandler<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n> = (\n\tctx: InboxSubscriberContext<TServices, TLogger, TDatabase>,\n) => OutSchema extends StandardSchemaV1\n\t? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>>\n\t: any | Promise<any>;\n\nexport class InboxSubscriberBuilder<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tconstructor(\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\tprivate readonly inbox: Inbox<string>,\n\t\tprivate readonly acceptsAutomated = false,\n\t) {}\n\n\t/**\n\t * Hands this handler mail marked `Auto-Submitted` too — auto-replies,\n\t * out-of-office notices, bounces — which are otherwise dropped so a reply\n\t * can never be answered by another. A handler that takes them should not\n\t * reply to them.\n\t */\n\tautomated(): this {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tthis.inner,\n\t\t\tthis.inbox,\n\t\t\ttrue,\n\t\t) as this;\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): InboxSubscriberBuilder<\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\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): InboxSubscriberBuilder<\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.with(this.inner.services(services));\n\t}\n\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T> | Service<TDbName, T>,\n\t): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName> {\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\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): InboxSubscriberBuilder<\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\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: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>,\n\t): InboxSubscriber<\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst key = serviceKey(this.inbox.id);\n\t\tconst acceptsAutomated = this.acceptsAutomated;\n\n\t\t// Every adaptor hands the handler `{ type, payload }` messages; each\n\t\t// payload here is a receipt notification, and the inbox's client turns\n\t\t// it into the messages for the recipients it receives at.\n\t\tconst handler = async (ctx: Record<string, any>) => {\n\t\t\tconst inbox = ctx.services[key] as InboxClient;\n\t\t\tconst notifications = (ctx.events as unknown[]).filter(\n\t\t\t\t(event): event is { type: string; payload: ReceiptNotification } =>\n\t\t\t\t\t(event as { type?: string })?.type === INBOX_EVENT,\n\t\t\t);\n\t\t\tconst messages: InboxMessage[] = [];\n\t\t\tfor (const { payload } of notifications) {\n\t\t\t\tfor (const message of await inbox.messages(payload)) {\n\t\t\t\t\tif (!acceptsAutomated && isAutoSubmitted(message.headers)) {\n\t\t\t\t\t\tctx.logger.debug(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trecipient: message.recipient.address,\n\t\t\t\t\t\t\t\tautoSubmitted: message.headers['auto-submitted'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t'Dropped automatic mail: it is never answered',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tmessages.push(message);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (messages.length === 0) return undefined;\n\t\t\treturn autoReplying(() =>\n\t\t\t\tfn({\n\t\t\t\t\t...ctx,\n\t\t\t\t\tmessages,\n\t\t\t\t\tinbox,\n\t\t\t\t} as unknown as InboxSubscriberContext<TServices, TLogger, TDatabase>),\n\t\t\t);\n\t\t};\n\n\t\tconst subscriber = this.inner\n\t\t\t.subscribe([INBOX_EVENT] as never)\n\t\t\t.handle(handler as never) as unknown as InboxSubscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t\tsubscriber.inboxName = this.inbox.id;\n\t\tsubscriber.inboxAddressing = this.inbox.addressing;\n\t\treturn subscriber;\n\t}\n\n\tprivate with(inner: SubscriberBuilder<any, any, any, any, any, any, any>) {\n\t\treturn new InboxSubscriberBuilder<any, any, any, any, any>(\n\t\t\tinner,\n\t\t\tthis.inbox,\n\t\t\tthis.acceptsAutomated,\n\t\t);\n\t}\n}\n","/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * ## The database is everything's default\n *\n * The same `.database(db)` is the database every cron, queue, subscriber and\n * function built from the worker receives as `db`. The work a worker groups is\n * usually work against one database, and naming it per handler was a line\n * repeated in every file that could drift in any one of them. A runnable that\n * works against another names its own with `.database(other)`, which replaces\n * the worker's — client and manifest edge both — rather than adding to it.\n *\n * It is not an app: it declares no path, and its code lives in an app's\n * directory. But it is a process of its own. On a server target each worker\n * with work to do is built — from the app that holds that work — into an image\n * that runs its crons, consumers and subscribers and answers only a health\n * check, so a slow queue never shares a process with the requests an API\n * serves. `gkm dev` still runs everything in one process. Declare as many as\n * the shape of the work wants: each is one container.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).database(database);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ db, logger }) => { … });\n *\n * // queues/reports.ts — against another database than the worker's\n * export const reports = worker\n * .queue('Reports')\n * .database(analytics)\n * .message(z.object({ id: z.uuid() }))\n * .handle(async ({ messages, db }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport type { Inbox } from './inbox';\nimport type { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { InboxSubscriberBuilder } from './subscribers/InboxSubscriberBuilder';\nimport { ObjectSubscriberBuilder } from './subscribers/ObjectSubscriberBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Telemetry } from './telemetry';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * What the worker's process emits — the `Telemetry` construct, passed like\n\t * the logger. An edge to the node: the deploy hands the process the\n\t * `OTEL_*` keys its stage resolves.\n\t */\n\ttelemetry?: Telemetry;\n}\n\nexport class Worker<\n\tTName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them — and the database everything built from it receives as `db`.\n\t * `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.database()` carries its edge into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in, and the one everything\n\t * built from it — crons, queues, subscribers, functions — receives as `db`.\n\t * One of them that works against another database names it with its own\n\t * `.database(other)`, which replaces this one for that runnable alone.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t *\n\t * export const sweep = jobs\n\t * .cron('rate(1 hour)')\n\t * .handle(async ({ db }) => db.deleteFrom('sessions').execute());\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName, T, TDbName> {\n\t\treturn new Worker<TName, T, TDbName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(\n\t\t\tnew CronBuilder<\n\t\t\t\tComposableStandardSchema,\n\t\t\t\tService[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(\n\t\t\tnew QueueBuilder<\n\t\t\t\tstring,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).queue(name);\n\t}\n\n\t/**\n\t * A runnable that reacts to a bucket's objects changing.\n\t *\n\t * A bucket is a topic whose publisher is the storage: the binding is the\n\t * same as {@link Worker.topic}'s, and so is everything after it — the\n\t * services, the database, how it is delivered. The handler is handed the\n\t * objects; reading one still means depending on the bucket,\n\t * `.dependsOn([uploads])`.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onAvatar = worker\n\t * .objects(uploads)\n\t * .on(['object.created'], { prefix: 'avatars/', suffix: '.png' })\n\t * .handle(async ({ objects }) => { … });\n\t * ```\n\t */\n\tobjects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t\treturn new ObjectSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\t[],\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, bucket.id);\n\t}\n\n\t/**\n\t * A runnable handed the mail an {@link Inbox} receives.\n\t *\n\t * Bound, as a topic subscriber is: the inbox's topic is what it consumes,\n\t * and what it is handed is the messages on it, parsed — one per envelope\n\t * recipient the inbox receives at. It reads its inbox's raw messages\n\t * without depending on it; anything else it uses it names, as ever.\n\t *\n\t * @example\n\t * ```ts\n\t * export const onRequest = worker\n\t * .inbox(requests)\n\t * .handle(async ({ messages, db }) => {\n\t * for (const message of messages) message.recipient.subdomain;\n\t * });\n\t * ```\n\t */\n\tinbox<TInboxName extends string>(inbox: Inbox<TInboxName>) {\n\t\tconst inner = this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t)\n\t\t\t.topic(inbox.topic)\n\t\t\t// The inbox itself: its client reads the raw messages from the\n\t\t\t// inbox's own bucket, which is what the edge grants — and nothing\n\t\t\t// the handler did not name besides.\n\t\t\t.dependsOn([inbox]);\n\t\treturn new InboxSubscriberBuilder<\n\t\t\t[],\n\t\t\tLogger,\n\t\t\tundefined,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>(inner, inbox);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<\n\t\t\t\tWorker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']\n\t\t\t>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(\n\t\t\tnew FunctionBuilder<\n\t\t\t\tany,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tstring,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it — and hands it the worker's database.\n\t *\n\t * The database goes through the builder's own `.database()` rather than\n\t * being written into its fields, so the default is recorded exactly as an\n\t * explicit one would be: the client the handler gets, and the edge the\n\t * manifest reads. That is also what lets a later `.database(other)` replace\n\t * it outright. The builder arrives already typed with this worker's\n\t * database; this is the runtime half of that.\n\t */\n\tprivate own<\n\t\tT extends {\n\t\t\t_owner?: string;\n\t\t\t_scheduleStore?: unknown;\n\t\t\tdatabase(source: Consumable<string, unknown>): unknown;\n\t\t},\n\t>(builder: T): T {\n\t\tconst owned = this.scheduleStore\n\t\t\t? (builder.database(this.scheduleStore) as T)\n\t\t\t: builder;\n\n\t\towned._owner = this.id;\n\t\towned._scheduleStore = this.scheduleStore;\n\n\t\treturn owned;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,IAAa,yBAAb,MAAa,uBAMX;CAEiB;CASA;CACA;CAXlB,YACC,OASA,OACA,mBAAoC,OACnC;EAXgB,KAAA,QAAA;EASA,KAAA,QAAA;EACA,KAAA,mBAAA;CACf;;;;;;;CAQH,YAAkB;EACjB,OAAO,IAAI,uBACV,KAAK,OACL,KAAK,OACL,IACD;CACD;CAEA,UACC,YAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,UAAU,UAAU,CAAC;CAClD;CAEA,SACC,UAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,QAAQ,CAAC;CAC/C;CAEA,SACC,QACoE;EACpE,OAAO,KAAK,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC;CAC7C;CAEA,QAAQ,SAAuB;EAC9B,OAAO,KAAK,KAAK,KAAK,MAAM,QAAQ,OAAO,CAAC;CAC7C;CAEA,OACC,QAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,CAAC;CAC3C;CAEA,OACC,QAOC;EACD,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,MAAM,CAAC;CAC3C;CAEA,OACC,IAOC;EACD,MAAM,MAAM,WAAW,KAAK,MAAM,EAAE;EACpC,MAAM,mBAAmB,KAAK;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AAQ;CACxC;;;;;;CAOA,OACC,GAAG,MAKF;EACD,OAAO,KAAK,mBAAmB,CAAC,CAAC,OAAO,GAAG,IAAI;CAChD;;CAGA,qBAA6B;EAC5B,OAAO,KAAK;CACb;;CAGA,IAAY,YAAY;EACvB,OAAO,KAAK,IACX,IAAI,gBASF,CAAC,CAAC,OAAO,KAAK,MAAM,CACvB;CACD;;;;;;;;;;;;CAaA,IAME,SAAe;EAChB,MAAM,QAAQ,KAAK,gBACf,QAAQ,SAAS,KAAK,aAAa,IACpC;EAEH,MAAM,SAAS,KAAK;EACpB,MAAM,iBAAiB,KAAK;EAE5B,OAAO;CACR;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAa,IAClC,CAAC;GACJ,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/constructs",
3
- "version": "10.0.0-alpha.141",
3
+ "version": "10.0.0-alpha.143",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -335,13 +335,13 @@
335
335
  "lodash.uniqby": "~4.7.0",
336
336
  "openapi-types": "~12.1.3",
337
337
  "qs": "~6.16.0",
338
- "@geekmidas/envkit": "^10.0.0-alpha.141",
339
- "@geekmidas/errors": "^10.0.0-alpha.141",
340
- "@geekmidas/events": "^10.0.0-alpha.141",
341
- "@geekmidas/logger": "^10.0.0-alpha.141",
342
- "@geekmidas/manifest": "^10.0.0-alpha.141",
343
- "@geekmidas/schema": "^10.0.0-alpha.141",
344
- "@geekmidas/services": "^10.0.0-alpha.141"
338
+ "@geekmidas/envkit": "^10.0.0-alpha.143",
339
+ "@geekmidas/errors": "^10.0.0-alpha.143",
340
+ "@geekmidas/events": "^10.0.0-alpha.143",
341
+ "@geekmidas/logger": "^10.0.0-alpha.143",
342
+ "@geekmidas/manifest": "^10.0.0-alpha.143",
343
+ "@geekmidas/schema": "^10.0.0-alpha.143",
344
+ "@geekmidas/services": "^10.0.0-alpha.143"
345
345
  },
346
346
  "devDependencies": {
347
347
  "@aws-sdk/client-kms": "~3.1136.0",
@@ -360,20 +360,20 @@
360
360
  "pg": "~8.23.0",
361
361
  "ws": "~8.22.0",
362
362
  "zod": "~4.6.5",
363
- "@geekmidas/audit": "^10.0.0-alpha.141",
364
- "@geekmidas/auth": "10.0.0-alpha.141",
365
- "@geekmidas/cache": "^10.0.0-alpha.141",
366
- "@geekmidas/db": "^10.0.0-alpha.141",
367
- "@geekmidas/emailkit": "^10.0.0-alpha.141",
368
- "@geekmidas/envkit": "^10.0.0-alpha.141",
369
- "@geekmidas/errors": "^10.0.0-alpha.141",
370
- "@geekmidas/events": "^10.0.0-alpha.141",
371
- "@geekmidas/logger": "^10.0.0-alpha.141",
372
- "@geekmidas/rate-limit": "^10.0.0-alpha.141",
373
- "@geekmidas/schema": "^10.0.0-alpha.141",
374
- "@geekmidas/services": "^10.0.0-alpha.141",
375
- "@geekmidas/telescope": "10.0.0-alpha.141",
376
- "@geekmidas/testkit": "^10.0.0-alpha.141"
363
+ "@geekmidas/audit": "^10.0.0-alpha.143",
364
+ "@geekmidas/auth": "10.0.0-alpha.143",
365
+ "@geekmidas/cache": "^10.0.0-alpha.143",
366
+ "@geekmidas/db": "^10.0.0-alpha.143",
367
+ "@geekmidas/emailkit": "^10.0.0-alpha.143",
368
+ "@geekmidas/envkit": "^10.0.0-alpha.143",
369
+ "@geekmidas/errors": "^10.0.0-alpha.143",
370
+ "@geekmidas/events": "^10.0.0-alpha.143",
371
+ "@geekmidas/logger": "^10.0.0-alpha.143",
372
+ "@geekmidas/rate-limit": "^10.0.0-alpha.143",
373
+ "@geekmidas/schema": "^10.0.0-alpha.143",
374
+ "@geekmidas/services": "^10.0.0-alpha.143",
375
+ "@geekmidas/telescope": "10.0.0-alpha.143",
376
+ "@geekmidas/testkit": "^10.0.0-alpha.143"
377
377
  },
378
378
  "peerDependencies": {
379
379
  "@aws-sdk/client-kms": ">=3.1136.0",
@@ -386,15 +386,15 @@
386
386
  "msw": ">=2.15.0",
387
387
  "pg": ">=8.23.0",
388
388
  "ws": ">=8.22.0",
389
- "@geekmidas/audit": "^10.0.0-alpha.141",
390
- "@geekmidas/auth": "10.0.0-alpha.141",
391
- "@geekmidas/cache": "^10.0.0-alpha.141",
392
- "@geekmidas/db": "^10.0.0-alpha.141",
393
- "@geekmidas/emailkit": "^10.0.0-alpha.141",
394
- "@geekmidas/rate-limit": "^10.0.0-alpha.141",
395
- "@geekmidas/storage": "^10.0.0-alpha.141",
396
- "@geekmidas/telescope": "10.0.0-alpha.141",
397
- "@geekmidas/testkit": "^10.0.0-alpha.141"
389
+ "@geekmidas/audit": "^10.0.0-alpha.143",
390
+ "@geekmidas/auth": "10.0.0-alpha.143",
391
+ "@geekmidas/cache": "^10.0.0-alpha.143",
392
+ "@geekmidas/db": "^10.0.0-alpha.143",
393
+ "@geekmidas/emailkit": "^10.0.0-alpha.143",
394
+ "@geekmidas/rate-limit": "^10.0.0-alpha.143",
395
+ "@geekmidas/storage": "^10.0.0-alpha.143",
396
+ "@geekmidas/telescope": "10.0.0-alpha.143",
397
+ "@geekmidas/testkit": "^10.0.0-alpha.143"
398
398
  },
399
399
  "peerDependenciesMeta": {
400
400
  "@aws-sdk/client-kms": {