@geekmidas/constructs 10.0.0-alpha.139 → 10.0.0-alpha.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/{ObjectSubscriberBuilder-l-64yUiF.d.cts → ObjectSubscriberBuilder-BuuaYcrm.d.cts} +2 -2
  2. package/dist/{ObjectSubscriberBuilder-HmBwFn2o.d.mts.map → ObjectSubscriberBuilder-BuuaYcrm.d.cts.map} +1 -1
  3. package/dist/{ObjectSubscriberBuilder-HmBwFn2o.d.mts → ObjectSubscriberBuilder-CzgYmOUH.d.mts} +2 -2
  4. package/dist/{ObjectSubscriberBuilder-l-64yUiF.d.cts.map → ObjectSubscriberBuilder-CzgYmOUH.d.mts.map} +1 -1
  5. package/dist/{Subscriber-BdCtfFXL.d.cts → Subscriber-5rCX1Nph.d.cts} +11 -1
  6. package/dist/{Subscriber-BdCtfFXL.d.cts.map → Subscriber-5rCX1Nph.d.cts.map} +1 -1
  7. package/dist/{Subscriber-DDo4HFNn.d.mts → Subscriber-CW_Dl-YR.d.mts} +11 -1
  8. package/dist/{Subscriber-DDo4HFNn.d.mts.map → Subscriber-CW_Dl-YR.d.mts.map} +1 -1
  9. package/dist/{SubscriberBuilder-3msj1U2w.mjs → SubscriberBuilder-BL_GTcwh.mjs} +8 -1
  10. package/dist/SubscriberBuilder-BL_GTcwh.mjs.map +1 -0
  11. package/dist/{SubscriberBuilder-CQst6Iz3.cjs → SubscriberBuilder-CWzKwX1p.cjs} +8 -1
  12. package/dist/SubscriberBuilder-CWzKwX1p.cjs.map +1 -0
  13. package/dist/adaptors/aws.cjs +1 -1
  14. package/dist/adaptors/aws.d.cts +1 -1
  15. package/dist/adaptors/aws.d.mts +1 -1
  16. package/dist/adaptors/aws.mjs +1 -1
  17. package/dist/adaptors/testing.cjs +121 -3
  18. package/dist/adaptors/testing.cjs.map +1 -1
  19. package/dist/adaptors/testing.d.cts +73 -4
  20. package/dist/adaptors/testing.d.cts.map +1 -1
  21. package/dist/adaptors/testing.d.mts +73 -4
  22. package/dist/adaptors/testing.d.mts.map +1 -1
  23. package/dist/adaptors/testing.mjs +119 -5
  24. package/dist/adaptors/testing.mjs.map +1 -1
  25. package/dist/inbox-DZdICa8F.d.mts +195 -0
  26. package/dist/inbox-DZdICa8F.d.mts.map +1 -0
  27. package/dist/inbox-DqaxrpEk.d.cts +195 -0
  28. package/dist/inbox-DqaxrpEk.d.cts.map +1 -0
  29. package/dist/inbox.cjs +291 -0
  30. package/dist/inbox.cjs.map +1 -0
  31. package/dist/inbox.d.cts +2 -0
  32. package/dist/inbox.d.mts +2 -0
  33. package/dist/inbox.mjs +283 -0
  34. package/dist/inbox.mjs.map +1 -0
  35. package/dist/{runSubscriber-B1Yg4dID.cjs → runSubscriber-CC_2C9F2.cjs} +7 -2
  36. package/dist/runSubscriber-CC_2C9F2.cjs.map +1 -0
  37. package/dist/{runSubscriber-JCgkeYbE.mjs → runSubscriber-DyHWp_Lf.mjs} +7 -2
  38. package/dist/runSubscriber-DyHWp_Lf.mjs.map +1 -0
  39. package/dist/subscribers/index.cjs +2 -2
  40. package/dist/subscribers/index.d.cts +2 -2
  41. package/dist/subscribers/index.d.mts +2 -2
  42. package/dist/subscribers/index.mjs +2 -2
  43. package/dist/worker.cjs +71 -1
  44. package/dist/worker.cjs.map +1 -1
  45. package/dist/worker.d.cts +54 -5
  46. package/dist/worker.d.cts.map +1 -1
  47. package/dist/worker.d.mts +54 -5
  48. package/dist/worker.d.mts.map +1 -1
  49. package/dist/worker.mjs +72 -2
  50. package/dist/worker.mjs.map +1 -1
  51. package/package.json +41 -31
  52. package/dist/SubscriberBuilder-3msj1U2w.mjs.map +0 -1
  53. package/dist/SubscriberBuilder-CQst6Iz3.cjs.map +0 -1
  54. package/dist/runSubscriber-B1Yg4dID.cjs.map +0 -1
  55. package/dist/runSubscriber-JCgkeYbE.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"worker.cjs","names":["canonicalId","DEFAULT_LOGGER","envParserFor","edgeTo","CronBuilder","QueueBuilder","SubscriberBuilder","ObjectSubscriberBuilder","FunctionBuilder"],"sources":["../src/worker.ts"],"sourcesContent":["/**\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 { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\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 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":";;;;;;;;;;AA8HA,IAAa,SAAb,MAAa,OAKb;CAkBmB;CAEA;CAnBlB;;CAGA;;CAGA;;;;;;CAOA;CAEA,YACC,IACA,SAAwC,CAAC,GAEzC,eAAuD,CAAC,GACxD,eACC;EAJgB,KAAA,SAAA;EAEA,KAAA,eAAA;EAGjB,MAAM,aAAA,GAAYA,oBAAAA,YAAAA,CAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,SAAS,OAAO,UAAUC,0BAAAA;EAC/B,KAAK,YAAYC,mBAAAA,aAChB,OAAO,YACJ;GAAE,IAAI;GAAW,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;;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,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","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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J,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
@@ -1,20 +1,51 @@
1
1
  import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.cjs";
2
2
  import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-127M7yrl.cjs";
3
- import { i as FunctionHandler, n as Function } from "./Function-BIEsY0Hm.cjs";
3
+ import { i as FunctionHandler, n as Function, t as DatabaseContext } from "./Function-BIEsY0Hm.cjs";
4
4
  import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-B1AfqRl4.cjs";
5
5
  import { t as FunctionBuilder } from "./index-BtzMzhMA.cjs";
6
6
  import { i as ScheduleExpression } from "./Cron-CFkpEys6.cjs";
7
7
  import { n as Telemetry } from "./telemetry-B48RLjyk.cjs";
8
+ import { t as Subscriber } from "./Subscriber-5rCX1Nph.cjs";
9
+ import { i as InboxClient, l as ReceiptNotification, n as Inbox, o as InboxMessage } from "./inbox-DqaxrpEk.cjs";
8
10
  import { t as CronBuilder } from "./CronBuilder-OaCRRFVk.cjs";
9
11
  import { ObjectStorage } from "./object-storage.cjs";
10
12
  import { t as QueueBuilder } from "./QueueBuilder-BcPBQSSX.cjs";
11
- import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-l-64yUiF.cjs";
13
+ import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-BuuaYcrm.cjs";
12
14
  import "./topic/index.cjs";
13
15
  import { EnvironmentParser } from "@geekmidas/envkit";
14
16
  import { Logger } from "@geekmidas/logger";
15
- import { ComposableStandardSchema } from "@geekmidas/schema";
16
- import { Service } from "@geekmidas/services";
17
- import { ConstructName, Declaration, Dependency } from "@geekmidas/manifest";
17
+ import { ComposableStandardSchema, InferStandardSchema } from "@geekmidas/schema";
18
+ import { Service, ServiceRecord } from "@geekmidas/services";
19
+ import { EventPublisher as EventPublisher$1 } from "@geekmidas/events";
20
+ import { ConstructName, Declaration, Dependency, INBOX_EVENT } from "@geekmidas/manifest";
21
+ //#region src/subscribers/InboxSubscriberBuilder.d.ts
22
+ type InboxSubscriber<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined, TDatabaseServiceName extends string = string> = Subscriber<TServices, TLogger, OutSchema, EventPublisher$1<{
23
+ type: typeof INBOX_EVENT;
24
+ payload: ReceiptNotification;
25
+ }>, [typeof INBOX_EVENT], TDatabase, TDatabaseServiceName>;
26
+ type InboxSubscriberContext<TServices extends Service[] = [], TLogger extends Logger = Logger, TDatabase = undefined> = {
27
+ /** The messages received, one per envelope recipient the inbox takes. */
28
+ messages: InboxMessage[];
29
+ /** The inbox, under its own id too: its domain and its raw messages. */
30
+ inbox: InboxClient;
31
+ services: ServiceRecord<TServices>;
32
+ logger: TLogger;
33
+ } & DatabaseContext<TDatabase>;
34
+ type InboxSubscriberHandler<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined> = (ctx: InboxSubscriberContext<TServices, TLogger, TDatabase>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
35
+ declare class InboxSubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined, TDatabaseServiceName extends string = string> {
36
+ private readonly inner;
37
+ private readonly inbox;
38
+ constructor(inner: SubscriberBuilder<any, any, any, any, any, any, any>, inbox: Inbox<string>);
39
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): InboxSubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
40
+ services<T extends Service[]>(services: T): InboxSubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
41
+ database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName>;
42
+ timeout(timeout: number): this;
43
+ output<T extends StandardSchemaV1>(schema: T): InboxSubscriberBuilder<TServices, TLogger, T, TDatabase, TDatabaseServiceName>;
44
+ logger<T extends Logger>(logger: T): InboxSubscriberBuilder<TServices, T, OutSchema, TDatabase, TDatabaseServiceName>;
45
+ handle(fn: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>): InboxSubscriber<TServices, TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
46
+ private with;
47
+ }
48
+ //#endregion
18
49
  //#region src/worker.d.ts
19
50
  export interface WorkerConfig {
20
51
  /**
@@ -127,6 +158,24 @@ export declare class Worker<TName extends string = string, TDatabase = undefined
127
158
  * ```
128
159
  */
129
160
  objects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>): ObjectSubscriberBuilder<[], Logger, undefined, [], TDatabase, TDatabaseServiceName>;
161
+ /**
162
+ * A runnable handed the mail an {@link Inbox} receives.
163
+ *
164
+ * Bound, as a topic subscriber is: the inbox's topic is what it consumes,
165
+ * and what it is handed is the messages on it, parsed — one per envelope
166
+ * recipient the inbox receives at. It reads its inbox's raw messages
167
+ * without depending on it; anything else it uses it names, as ever.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * export const onRequest = worker
172
+ * .inbox(requests)
173
+ * .handle(async ({ messages, db }) => {
174
+ * for (const message of messages) message.recipient.subdomain;
175
+ * });
176
+ * ```
177
+ */
178
+ inbox<TInboxName extends string>(inbox: Inbox<TInboxName>): InboxSubscriberBuilder<[], Logger, undefined, TDatabase, TDatabaseServiceName>;
130
179
  /**
131
180
  * A runnable that consumes a topic.
132
181
  *
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.cts","names":["_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],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,sCAAA,WAAA,sBAAA,kCAAAD,yBAAA,mBAAA,sBAAA;;UAMM;;cAKI;;;;;;;;;;;;UA0BJ;EAiBR,WAAW"}
1
+ {"version":3,"file":"worker.d.cts","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,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;EAVlB,YACkB,OAAO,sDASP,OAAO;EAGzB,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,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AA,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"}
package/dist/worker.d.mts CHANGED
@@ -1,20 +1,51 @@
1
1
  import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.mjs";
2
2
  import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-DySlwh8o.mjs";
3
- import { i as FunctionHandler, n as Function } from "./Function-DfMzTGS4.mjs";
3
+ import { i as FunctionHandler, n as Function, t as DatabaseContext } from "./Function-DfMzTGS4.mjs";
4
4
  import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-ZvYQbivO.mjs";
5
5
  import { t as FunctionBuilder } from "./index-DuriFjYD.mjs";
6
6
  import { i as ScheduleExpression } from "./Cron-CQoDSu-n.mjs";
7
7
  import { n as Telemetry } from "./telemetry-BEoBn6GO.mjs";
8
+ import { t as Subscriber } from "./Subscriber-CW_Dl-YR.mjs";
9
+ import { i as InboxClient, l as ReceiptNotification, n as Inbox, o as InboxMessage } from "./inbox-DZdICa8F.mjs";
8
10
  import { t as CronBuilder } from "./CronBuilder-1W-G_i15.mjs";
9
11
  import { ObjectStorage } from "./object-storage.mjs";
10
12
  import { t as QueueBuilder } from "./QueueBuilder-B3vL1ED2.mjs";
11
- import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-HmBwFn2o.mjs";
13
+ import { n as ObjectSubscriberBuilder, o as SubscriberBuilder } from "./ObjectSubscriberBuilder-CzgYmOUH.mjs";
12
14
  import "./topic/index.mjs";
13
- import { ConstructName, Declaration, Dependency } from "@geekmidas/manifest";
14
- import { Service } from "@geekmidas/services";
15
+ import { ConstructName, Declaration, Dependency, INBOX_EVENT } from "@geekmidas/manifest";
16
+ import { EventPublisher as EventPublisher$1 } from "@geekmidas/events";
17
+ import { Service, ServiceRecord } from "@geekmidas/services";
15
18
  import { EnvironmentParser } from "@geekmidas/envkit";
16
19
  import { Logger } from "@geekmidas/logger";
17
- import { ComposableStandardSchema } from "@geekmidas/schema";
20
+ import { ComposableStandardSchema, InferStandardSchema } from "@geekmidas/schema";
21
+ //#region src/subscribers/InboxSubscriberBuilder.d.ts
22
+ type InboxSubscriber<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined, TDatabaseServiceName extends string = string> = Subscriber<TServices, TLogger, OutSchema, EventPublisher$1<{
23
+ type: typeof INBOX_EVENT;
24
+ payload: ReceiptNotification;
25
+ }>, [typeof INBOX_EVENT], TDatabase, TDatabaseServiceName>;
26
+ type InboxSubscriberContext<TServices extends Service[] = [], TLogger extends Logger = Logger, TDatabase = undefined> = {
27
+ /** The messages received, one per envelope recipient the inbox takes. */
28
+ messages: InboxMessage[];
29
+ /** The inbox, under its own id too: its domain and its raw messages. */
30
+ inbox: InboxClient;
31
+ services: ServiceRecord<TServices>;
32
+ logger: TLogger;
33
+ } & DatabaseContext<TDatabase>;
34
+ type InboxSubscriberHandler<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined> = (ctx: InboxSubscriberContext<TServices, TLogger, TDatabase>) => OutSchema extends StandardSchemaV1 ? InferStandardSchema<OutSchema> | Promise<InferStandardSchema<OutSchema>> : any | Promise<any>;
35
+ declare class InboxSubscriberBuilder<TServices extends Service[] = [], TLogger extends Logger = Logger, OutSchema extends StandardSchemaV1 | undefined = undefined, TDatabase = undefined, TDatabaseServiceName extends string = string> {
36
+ private readonly inner;
37
+ private readonly inbox;
38
+ constructor(inner: SubscriberBuilder<any, any, any, any, any, any, any>, inbox: Inbox<string>);
39
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): InboxSubscriberBuilder<[...TServices, ...ServicesOf<T>], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
40
+ services<T extends Service[]>(services: T): InboxSubscriberBuilder<[...TServices, ...T], TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
41
+ database<T, TDbName extends string>(source: Consumable<TDbName, T> | Service<TDbName, T>): InboxSubscriberBuilder<TServices, TLogger, OutSchema, T, TDbName>;
42
+ timeout(timeout: number): this;
43
+ output<T extends StandardSchemaV1>(schema: T): InboxSubscriberBuilder<TServices, TLogger, T, TDatabase, TDatabaseServiceName>;
44
+ logger<T extends Logger>(logger: T): InboxSubscriberBuilder<TServices, T, OutSchema, TDatabase, TDatabaseServiceName>;
45
+ handle(fn: InboxSubscriberHandler<TServices, TLogger, OutSchema, TDatabase>): InboxSubscriber<TServices, TLogger, OutSchema, TDatabase, TDatabaseServiceName>;
46
+ private with;
47
+ }
48
+ //#endregion
18
49
  //#region src/worker.d.ts
19
50
  export interface WorkerConfig {
20
51
  /**
@@ -127,6 +158,24 @@ export declare class Worker<TName extends string = string, TDatabase = undefined
127
158
  * ```
128
159
  */
129
160
  objects<TBucketName extends string>(bucket: ObjectStorage<TBucketName>): ObjectSubscriberBuilder<[], Logger, undefined, [], TDatabase, TDatabaseServiceName>;
161
+ /**
162
+ * A runnable handed the mail an {@link Inbox} receives.
163
+ *
164
+ * Bound, as a topic subscriber is: the inbox's topic is what it consumes,
165
+ * and what it is handed is the messages on it, parsed — one per envelope
166
+ * recipient the inbox receives at. It reads its inbox's raw messages
167
+ * without depending on it; anything else it uses it names, as ever.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * export const onRequest = worker
172
+ * .inbox(requests)
173
+ * .handle(async ({ messages, db }) => {
174
+ * for (const message of messages) message.recipient.subdomain;
175
+ * });
176
+ * ```
177
+ */
178
+ inbox<TInboxName extends string>(inbox: Inbox<TInboxName>): InboxSubscriberBuilder<[], Logger, undefined, TDatabase, TDatabaseServiceName>;
130
179
  /**
131
180
  * A runnable that consumes a topic.
132
181
  *
@@ -1 +1 @@
1
- {"version":3,"file":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AA,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":";;;;;;;;;;;;;;;;;;;;;KA4BY,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;EAVlB,YACkB,OAAO,sDASP,OAAO;EAGzB,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;EAK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,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"}
package/dist/worker.mjs CHANGED
@@ -3,9 +3,59 @@ import { t as FunctionBuilder } from "./functions-BvIDQKAA.mjs";
3
3
  import { n as envParserFor } from "./surfaceEnv-wMT5QzgZ.mjs";
4
4
  import { t as CronBuilder } from "./CronBuilder-BJ5LoadF.mjs";
5
5
  import { t as QueueBuilder } from "./QueueBuilder-2wP5lEC8.mjs";
6
- import { r as ObjectSubscriberBuilder, t as SubscriberBuilder } from "./SubscriberBuilder-3msj1U2w.mjs";
7
- import { canonicalId } from "@geekmidas/manifest";
6
+ import { r as ObjectSubscriberBuilder, t as SubscriberBuilder } from "./SubscriberBuilder-BL_GTcwh.mjs";
7
+ import { INBOX_EVENT, canonicalId, serviceKey } from "@geekmidas/manifest";
8
8
  import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
9
+ //#region src/subscribers/InboxSubscriberBuilder.ts
10
+ var InboxSubscriberBuilder = class InboxSubscriberBuilder {
11
+ inner;
12
+ inbox;
13
+ constructor(inner, inbox) {
14
+ this.inner = inner;
15
+ this.inbox = inbox;
16
+ }
17
+ dependsOn(constructs) {
18
+ return this.with(this.inner.dependsOn(constructs));
19
+ }
20
+ services(services) {
21
+ return this.with(this.inner.services(services));
22
+ }
23
+ database(source) {
24
+ return this.with(this.inner.database(source));
25
+ }
26
+ timeout(timeout) {
27
+ return this.with(this.inner.timeout(timeout));
28
+ }
29
+ output(schema) {
30
+ return this.with(this.inner.output(schema));
31
+ }
32
+ logger(logger) {
33
+ return this.with(this.inner.logger(logger));
34
+ }
35
+ handle(fn) {
36
+ const key = serviceKey(this.inbox.id);
37
+ const handler = async (ctx) => {
38
+ const inbox = ctx.services[key];
39
+ const notifications = ctx.events.filter((event) => event?.type === INBOX_EVENT);
40
+ const messages = [];
41
+ for (const { payload } of notifications) messages.push(...await inbox.messages(payload));
42
+ if (messages.length === 0) return void 0;
43
+ return fn({
44
+ ...ctx,
45
+ messages,
46
+ inbox
47
+ });
48
+ };
49
+ const subscriber = this.inner.subscribe([INBOX_EVENT]).handle(handler);
50
+ subscriber.inboxName = this.inbox.id;
51
+ subscriber.inboxAddressing = this.inbox.addressing;
52
+ return subscriber;
53
+ }
54
+ with(inner) {
55
+ return new InboxSubscriberBuilder(inner, this.inbox);
56
+ }
57
+ };
58
+ //#endregion
9
59
  //#region src/worker.ts
10
60
  var Worker = class Worker {
11
61
  config;
@@ -112,6 +162,26 @@ var Worker = class Worker {
112
162
  return new ObjectSubscriberBuilder(inner, bucket.id);
113
163
  }
114
164
  /**
165
+ * A runnable handed the mail an {@link Inbox} receives.
166
+ *
167
+ * Bound, as a topic subscriber is: the inbox's topic is what it consumes,
168
+ * and what it is handed is the messages on it, parsed — one per envelope
169
+ * recipient the inbox receives at. It reads its inbox's raw messages
170
+ * without depending on it; anything else it uses it names, as ever.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * export const onRequest = worker
175
+ * .inbox(requests)
176
+ * .handle(async ({ messages, db }) => {
177
+ * for (const message of messages) message.recipient.subdomain;
178
+ * });
179
+ * ```
180
+ */
181
+ inbox(inbox) {
182
+ return new InboxSubscriberBuilder(this.own(new SubscriberBuilder().logger(this.logger)).topic(inbox.topic).dependsOn([inbox]), inbox);
183
+ }
184
+ /**
115
185
  * A runnable that consumes a topic.
116
186
  *
117
187
  * Binding is not publishing: a consumer is handed the topic's event types
@@ -1 +1 @@
1
- {"version":3,"file":"worker.mjs","names":[],"sources":["../src/worker.ts"],"sourcesContent":["/**\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 { ObjectStorage } from './object-storage';\nimport { QueueBuilder } from './queue/QueueBuilder';\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 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":";;;;;;;;;AA8HA,IAAa,SAAb,MAAa,OAKb;CAkBmB;CAEA;CAnBlB;;CAGA;;CAGA;;;;;;CAOA;CAEA,YACC,IACA,SAAwC,CAAC,GAEzC,eAAuD,CAAC,GACxD,eACC;EAJgB,KAAA,SAAA;EAEA,KAAA,eAAA;EAGjB,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,SAAS,OAAO,UAAU;EAC/B,KAAK,YAAY,aAChB,OAAO,YACJ;GAAE,IAAI;GAAW,WAAW,OAAO;EAAU,IAC7C,KAAA,CACJ;EACA,KAAK,gBAAgB;CACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BA,SACC,QAC4B;EAC5B,OAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,OAAO,MAAM,CAAC,GACrC,MACD;CACD;;;;;;CAOA,KAAK,UA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,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.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,KA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AW,EAAE;CACpC;CAEA,UAAiD,YAAe;EAC/D,OAAO,KAAK,UAAU,UAAU,UAAU;CAC3C;CAEA,SAA8B,UAAa;EAC1C,OAAO,KAAK,UAAU,SAAS,QAAQ;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.139",
3
+ "version": "10.0.0-alpha.140",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -164,6 +164,16 @@
164
164
  "default": "./dist/email.cjs"
165
165
  }
166
166
  },
167
+ "./inbox": {
168
+ "import": {
169
+ "types": "./dist/inbox.d.mts",
170
+ "default": "./dist/inbox.mjs"
171
+ },
172
+ "require": {
173
+ "types": "./dist/inbox.d.cts",
174
+ "default": "./dist/inbox.cjs"
175
+ }
176
+ },
167
177
  "./cache": {
168
178
  "import": {
169
179
  "types": "./dist/cache.d.mts",
@@ -325,13 +335,13 @@
325
335
  "lodash.uniqby": "~4.7.0",
326
336
  "openapi-types": "~12.1.3",
327
337
  "qs": "~6.16.0",
328
- "@geekmidas/envkit": "^10.0.0-alpha.139",
329
- "@geekmidas/errors": "^10.0.0-alpha.139",
330
- "@geekmidas/events": "^10.0.0-alpha.139",
331
- "@geekmidas/logger": "^10.0.0-alpha.139",
332
- "@geekmidas/manifest": "^10.0.0-alpha.139",
333
- "@geekmidas/schema": "^10.0.0-alpha.139",
334
- "@geekmidas/services": "^10.0.0-alpha.139"
338
+ "@geekmidas/envkit": "^10.0.0-alpha.140",
339
+ "@geekmidas/errors": "^10.0.0-alpha.140",
340
+ "@geekmidas/events": "^10.0.0-alpha.140",
341
+ "@geekmidas/logger": "^10.0.0-alpha.140",
342
+ "@geekmidas/manifest": "^10.0.0-alpha.140",
343
+ "@geekmidas/schema": "^10.0.0-alpha.140",
344
+ "@geekmidas/services": "^10.0.0-alpha.140"
335
345
  },
336
346
  "devDependencies": {
337
347
  "@aws-sdk/client-kms": "~3.1136.0",
@@ -350,20 +360,20 @@
350
360
  "pg": "~8.23.0",
351
361
  "ws": "~8.22.0",
352
362
  "zod": "~4.6.5",
353
- "@geekmidas/audit": "^10.0.0-alpha.139",
354
- "@geekmidas/auth": "10.0.0-alpha.139",
355
- "@geekmidas/cache": "^10.0.0-alpha.139",
356
- "@geekmidas/db": "^10.0.0-alpha.139",
357
- "@geekmidas/emailkit": "^10.0.0-alpha.139",
358
- "@geekmidas/envkit": "^10.0.0-alpha.139",
359
- "@geekmidas/errors": "^10.0.0-alpha.139",
360
- "@geekmidas/events": "^10.0.0-alpha.139",
361
- "@geekmidas/logger": "^10.0.0-alpha.139",
362
- "@geekmidas/rate-limit": "^10.0.0-alpha.139",
363
- "@geekmidas/schema": "^10.0.0-alpha.139",
364
- "@geekmidas/services": "^10.0.0-alpha.139",
365
- "@geekmidas/telescope": "10.0.0-alpha.139",
366
- "@geekmidas/testkit": "^10.0.0-alpha.139"
363
+ "@geekmidas/audit": "^10.0.0-alpha.140",
364
+ "@geekmidas/auth": "10.0.0-alpha.140",
365
+ "@geekmidas/cache": "^10.0.0-alpha.140",
366
+ "@geekmidas/db": "^10.0.0-alpha.140",
367
+ "@geekmidas/emailkit": "^10.0.0-alpha.140",
368
+ "@geekmidas/envkit": "^10.0.0-alpha.140",
369
+ "@geekmidas/errors": "^10.0.0-alpha.140",
370
+ "@geekmidas/events": "^10.0.0-alpha.140",
371
+ "@geekmidas/logger": "^10.0.0-alpha.140",
372
+ "@geekmidas/rate-limit": "^10.0.0-alpha.140",
373
+ "@geekmidas/schema": "^10.0.0-alpha.140",
374
+ "@geekmidas/services": "^10.0.0-alpha.140",
375
+ "@geekmidas/telescope": "10.0.0-alpha.140",
376
+ "@geekmidas/testkit": "^10.0.0-alpha.140"
367
377
  },
368
378
  "peerDependencies": {
369
379
  "@aws-sdk/client-kms": ">=3.1136.0",
@@ -376,15 +386,15 @@
376
386
  "msw": ">=2.15.0",
377
387
  "pg": ">=8.23.0",
378
388
  "ws": ">=8.22.0",
379
- "@geekmidas/audit": "^10.0.0-alpha.139",
380
- "@geekmidas/auth": "10.0.0-alpha.139",
381
- "@geekmidas/cache": "^10.0.0-alpha.139",
382
- "@geekmidas/db": "^10.0.0-alpha.139",
383
- "@geekmidas/emailkit": "^10.0.0-alpha.139",
384
- "@geekmidas/rate-limit": "^10.0.0-alpha.139",
385
- "@geekmidas/storage": "^10.0.0-alpha.139",
386
- "@geekmidas/telescope": "10.0.0-alpha.139",
387
- "@geekmidas/testkit": "^10.0.0-alpha.139"
389
+ "@geekmidas/audit": "^10.0.0-alpha.140",
390
+ "@geekmidas/auth": "10.0.0-alpha.140",
391
+ "@geekmidas/cache": "^10.0.0-alpha.140",
392
+ "@geekmidas/db": "^10.0.0-alpha.140",
393
+ "@geekmidas/emailkit": "^10.0.0-alpha.140",
394
+ "@geekmidas/rate-limit": "^10.0.0-alpha.140",
395
+ "@geekmidas/storage": "^10.0.0-alpha.140",
396
+ "@geekmidas/telescope": "10.0.0-alpha.140",
397
+ "@geekmidas/testkit": "^10.0.0-alpha.140"
388
398
  },
389
399
  "peerDependenciesMeta": {
390
400
  "@aws-sdk/client-kms": {