equipped 5.3.1 → 5.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/cjs/cache/adapters/in-memory/index.cjs +155 -155
- package/dist/cjs/cache/adapters/in-memory/index.cjs.map +1 -1
- package/dist/cjs/cache/adapters/in-memory/index.min.cjs +3 -3
- package/dist/cjs/cache/adapters/in-memory/index.min.cjs.map +1 -1
- package/dist/cjs/dbs/adapters/mongodb/index.cjs.map +1 -1
- package/dist/cjs/dbs/adapters/mongodb/index.min.cjs +2 -2
- package/dist/cjs/dbs/adapters/mongodb/index.min.cjs.map +1 -1
- package/dist/cjs/dbs/index.cjs +181 -179
- package/dist/cjs/dbs/index.cjs.map +1 -1
- package/dist/cjs/dbs/index.min.cjs +3 -3
- package/dist/cjs/dbs/index.min.cjs.map +1 -1
- package/dist/cjs/events/adapters/kafka/index.cjs.map +1 -1
- package/dist/cjs/events/adapters/kafka/index.min.cjs +2 -2
- package/dist/cjs/events/adapters/kafka/index.min.cjs.map +1 -1
- package/dist/cjs/events/adapters/rabbitmq/index.cjs +179 -179
- package/dist/cjs/events/adapters/rabbitmq/index.cjs.map +1 -1
- package/dist/cjs/events/adapters/rabbitmq/index.min.cjs +3 -3
- package/dist/cjs/events/adapters/rabbitmq/index.min.cjs.map +1 -1
- package/dist/cjs/orm/adapters/mongodb/index.cjs +144 -144
- package/dist/cjs/orm/adapters/mongodb/index.cjs.map +1 -1
- package/dist/cjs/orm/adapters/mongodb/index.min.cjs +1 -1
- package/dist/cjs/orm/adapters/mongodb/index.min.cjs.map +1 -1
- package/dist/cjs/orm/adapters/postgresql/index.cjs +144 -215
- package/dist/cjs/orm/adapters/postgresql/index.cjs.map +1 -1
- package/dist/cjs/orm/adapters/postgresql/index.min.cjs +11 -11
- package/dist/cjs/orm/adapters/postgresql/index.min.cjs.map +1 -1
- package/dist/cjs/server/adapters/express/index.cjs +291 -225
- package/dist/cjs/server/adapters/express/index.cjs.map +1 -1
- package/dist/cjs/server/adapters/express/index.min.cjs +7 -7
- package/dist/cjs/server/adapters/express/index.min.cjs.map +1 -1
- package/dist/cjs/server/adapters/fastify/index.cjs +276 -210
- package/dist/cjs/server/adapters/fastify/index.cjs.map +1 -1
- package/dist/cjs/server/adapters/fastify/index.min.cjs +7 -7
- package/dist/cjs/server/adapters/fastify/index.min.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +81 -15
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.min.cjs +7 -7
- package/dist/cjs/server/index.min.cjs.map +1 -1
- package/dist/cjs/utilities/index.cjs +0 -5
- package/dist/cjs/utilities/index.cjs.map +1 -1
- package/dist/cjs/utilities/index.min.cjs +2 -2
- package/dist/cjs/utilities/index.min.cjs.map +1 -1
- package/dist/esm/cache/adapters/in-memory/index.min.mjs +1 -1
- package/dist/esm/cache/adapters/in-memory/index.min.mjs.map +1 -1
- package/dist/esm/cache/adapters/in-memory/index.mjs +6 -3
- package/dist/esm/cache/adapters/in-memory/index.mjs.map +1 -1
- package/dist/esm/cache/adapters/redis/index.min.mjs +1 -1
- package/dist/esm/cache/adapters/redis/index.mjs +5 -3
- package/dist/esm/cache/index.min.mjs +1 -1
- package/dist/esm/cache/index.mjs +2 -2
- package/dist/esm/{chunk-5PZACGPI.mjs → chunk-26BOI6IL.mjs} +7 -5
- package/dist/esm/{chunk-5PZACGPI.mjs.map → chunk-26BOI6IL.mjs.map} +1 -1
- package/dist/esm/{chunk-7SQ5JQYR.min.mjs → chunk-AODOD22O.min.mjs} +2 -2
- package/dist/esm/chunk-APSDCRY5.min.mjs +32 -0
- package/dist/esm/chunk-APSDCRY5.min.mjs.map +1 -0
- package/dist/esm/{chunk-A4P7P6BU.mjs → chunk-CEYT5YBA.mjs} +157 -347
- package/dist/esm/chunk-CEYT5YBA.mjs.map +1 -0
- package/dist/esm/chunk-CU2HU5UE.min.mjs +2 -0
- package/dist/esm/chunk-CU2HU5UE.min.mjs.map +1 -0
- package/dist/esm/chunk-DAK7OKSH.min.mjs +2 -0
- package/dist/esm/{chunk-MQXTTWPS.min.mjs.map → chunk-DAK7OKSH.min.mjs.map} +1 -1
- package/dist/esm/{chunk-IRYCN6PI.min.mjs → chunk-DAUQA32Q.min.mjs} +2 -2
- package/dist/esm/{chunk-BWUFPMVG.mjs → chunk-FQYRVHQT.mjs} +2 -2
- package/dist/esm/chunk-NEF3UYFA.mjs +144 -0
- package/dist/esm/chunk-NEF3UYFA.mjs.map +1 -0
- package/dist/esm/chunk-NNFUYHQ7.mjs +135 -0
- package/dist/esm/chunk-NNFUYHQ7.mjs.map +1 -0
- package/dist/esm/{chunk-7CP7ZE2O.mjs → chunk-PCEHFZ6G.mjs} +9 -5
- package/dist/esm/{chunk-7CP7ZE2O.mjs.map → chunk-PCEHFZ6G.mjs.map} +1 -1
- package/dist/esm/{chunk-P4PRHHIY.min.mjs → chunk-QCCDJLBH.min.mjs} +2 -2
- package/dist/esm/{chunk-3TP7NINX.mjs → chunk-RIXTQQUU.mjs} +2 -2
- package/dist/esm/{chunk-LKS5ZE45.mjs → chunk-RPPYCWXW.mjs} +2 -2
- package/dist/esm/{chunk-HXFNN6RI.mjs → chunk-T2O72JBW.mjs} +3 -3
- package/dist/esm/{chunk-TSVHZZE4.mjs → chunk-VQO4MSEC.mjs} +5 -5
- package/dist/esm/{chunk-676VIABN.min.mjs → chunk-X7VNAGLR.min.mjs} +2 -2
- package/dist/esm/chunk-XTXAEBXY.min.mjs +2 -0
- package/dist/esm/{chunk-7NF7PV6S.min.mjs.map → chunk-XTXAEBXY.min.mjs.map} +1 -1
- package/dist/esm/{chunk-2GGMLKRP.min.mjs → chunk-YDQW6ETS.min.mjs} +2 -2
- package/dist/esm/chunk-ZDBDR3IB.min.mjs +2 -0
- package/dist/esm/chunk-ZDBDR3IB.min.mjs.map +1 -0
- package/dist/esm/dbs/adapters/mongodb/index.min.mjs +1 -1
- package/dist/esm/dbs/adapters/mongodb/index.min.mjs.map +1 -1
- package/dist/esm/dbs/adapters/mongodb/index.mjs +8 -5
- package/dist/esm/dbs/adapters/mongodb/index.mjs.map +1 -1
- package/dist/esm/dbs/index.min.mjs +1 -1
- package/dist/esm/dbs/index.mjs +5 -3
- package/dist/esm/errors/index.min.mjs +1 -1
- package/dist/esm/errors/index.mjs +1 -1
- package/dist/esm/events/adapters/kafka/index.min.mjs +1 -1
- package/dist/esm/events/adapters/kafka/index.mjs +4 -2
- package/dist/esm/events/adapters/rabbitmq/index.min.mjs +1 -1
- package/dist/esm/events/adapters/rabbitmq/index.min.mjs.map +1 -1
- package/dist/esm/events/adapters/rabbitmq/index.mjs +7 -3
- package/dist/esm/events/adapters/rabbitmq/index.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/instance/index.min.mjs +1 -1
- package/dist/esm/instance/index.mjs +1 -1
- package/dist/esm/{introspection-YJF3QAUK.mjs → introspection-FGDVYTPP.mjs} +3 -3
- package/dist/esm/introspection-UDWDS6DV.min.mjs +2 -0
- package/dist/esm/jobs/adapters/redis/index.min.mjs +1 -1
- package/dist/esm/jobs/adapters/redis/index.min.mjs.map +1 -1
- package/dist/esm/jobs/adapters/redis/index.mjs +10 -6
- package/dist/esm/jobs/adapters/redis/index.mjs.map +1 -1
- package/dist/esm/orm/adapters/in-memory/index.min.mjs +1 -1
- package/dist/esm/orm/adapters/in-memory/index.mjs +4 -3
- package/dist/esm/orm/adapters/json/index.min.mjs +1 -1
- package/dist/esm/orm/adapters/json/index.min.mjs.map +1 -1
- package/dist/esm/orm/adapters/json/index.mjs +6 -5
- package/dist/esm/orm/adapters/json/index.mjs.map +1 -1
- package/dist/esm/orm/adapters/mongodb/index.min.mjs +1 -1
- package/dist/esm/orm/adapters/mongodb/index.min.mjs.map +1 -1
- package/dist/esm/orm/adapters/mongodb/index.mjs +6 -4
- package/dist/esm/orm/adapters/mongodb/index.mjs.map +1 -1
- package/dist/esm/orm/adapters/postgresql/index.min.mjs +2 -2
- package/dist/esm/orm/adapters/postgresql/index.min.mjs.map +1 -1
- package/dist/esm/orm/adapters/postgresql/index.mjs +8 -5
- package/dist/esm/orm/adapters/postgresql/index.mjs.map +1 -1
- package/dist/esm/orm/index.min.mjs +1 -1
- package/dist/esm/orm/index.mjs +3 -3
- package/dist/esm/server/adapters/express/index.min.mjs +1 -1
- package/dist/esm/server/adapters/express/index.min.mjs.map +1 -1
- package/dist/esm/server/adapters/express/index.mjs +7 -3
- package/dist/esm/server/adapters/express/index.mjs.map +1 -1
- package/dist/esm/server/adapters/fastify/index.min.mjs +1 -1
- package/dist/esm/server/adapters/fastify/index.min.mjs.map +1 -1
- package/dist/esm/server/adapters/fastify/index.mjs +7 -3
- package/dist/esm/server/adapters/fastify/index.mjs.map +1 -1
- package/dist/esm/server/index.min.mjs +1 -1
- package/dist/esm/server/index.mjs +1 -1
- package/dist/esm/utilities/index.min.mjs +1 -1
- package/dist/esm/utilities/index.mjs +5 -4
- package/dist/esm/validations/index.min.mjs +1 -1
- package/dist/esm/validations/index.mjs +1 -1
- package/dist/types/{base-BDTBLZ9a.d.ts → base-qDndMBf8.d.ts} +2 -2
- package/dist/types/cache/adapters/in-memory/index.js +7 -4
- package/dist/types/cache/adapters/redis/index.js +5 -3
- package/dist/types/cache/index.js +2 -2
- package/dist/types/{chunk-4DH3POYM.js → chunk-35CDCTLR.js} +4 -4
- package/dist/types/{chunk-J3TGB5YQ.js → chunk-4YQA5GPT.js} +8 -4
- package/dist/types/{chunk-YLJNBL6J.js → chunk-AQIV47BY.js} +6 -4
- package/dist/types/{chunk-TT5EORDK.js → chunk-BKDWUJRG.js} +156 -346
- package/dist/types/{chunk-5Z26ZURE.js → chunk-DA2VYP7D.js} +1 -1
- package/dist/types/{chunk-LPB5LS7A.js → chunk-GDMGPX4C.js} +1 -1
- package/dist/types/chunk-H5V6ADFD.js +134 -0
- package/dist/types/{chunk-IZDJDGOV.js → chunk-OOKJEMQI.js} +2 -2
- package/dist/types/chunk-PPD4WDG6.js +143 -0
- package/dist/types/{chunk-55CTVK7R.js → chunk-T7K7PO6G.js} +1 -1
- package/dist/types/dbs/adapters/mongodb/index.js +8 -5
- package/dist/types/dbs/index.js +5 -3
- package/dist/types/errors/index.js +1 -1
- package/dist/types/events/adapters/kafka/index.js +4 -2
- package/dist/types/events/adapters/rabbitmq/index.js +7 -3
- package/dist/types/index.js +1 -1
- package/dist/types/instance/index.js +1 -1
- package/dist/types/{introspection-EHGM4RMO.js → introspection-FSNS33CQ.js} +2 -2
- package/dist/types/jobs/adapters/redis/index.js +10 -6
- package/dist/types/orm/adapters/in-memory/index.js +4 -3
- package/dist/types/orm/adapters/json/index.js +6 -5
- package/dist/types/orm/adapters/mongodb/index.js +6 -4
- package/dist/types/orm/adapters/postgresql/index.js +8 -5
- package/dist/types/orm/index.js +3 -3
- package/dist/types/server/adapters/express/index.d.ts +1 -1
- package/dist/types/server/adapters/express/index.js +7 -3
- package/dist/types/server/adapters/fastify/index.d.ts +1 -1
- package/dist/types/server/adapters/fastify/index.js +7 -3
- package/dist/types/server/index.d.ts +2 -2
- package/dist/types/server/index.js +1 -1
- package/dist/types/utilities/index.d.ts +1 -2
- package/dist/types/utilities/index.js +5 -4
- package/dist/types/validations/index.js +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-7NF7PV6S.min.mjs +0 -2
- package/dist/esm/chunk-A4P7P6BU.mjs.map +0 -1
- package/dist/esm/chunk-IN5YKIJ7.min.mjs +0 -32
- package/dist/esm/chunk-IN5YKIJ7.min.mjs.map +0 -1
- package/dist/esm/chunk-MQXTTWPS.min.mjs +0 -2
- package/dist/esm/introspection-THKMXV5V.min.mjs +0 -2
- /package/dist/esm/{chunk-7SQ5JQYR.min.mjs.map → chunk-AODOD22O.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-IRYCN6PI.min.mjs.map → chunk-DAUQA32Q.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-BWUFPMVG.mjs.map → chunk-FQYRVHQT.mjs.map} +0 -0
- /package/dist/esm/{chunk-P4PRHHIY.min.mjs.map → chunk-QCCDJLBH.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-3TP7NINX.mjs.map → chunk-RIXTQQUU.mjs.map} +0 -0
- /package/dist/esm/{chunk-LKS5ZE45.mjs.map → chunk-RPPYCWXW.mjs.map} +0 -0
- /package/dist/esm/{chunk-HXFNN6RI.mjs.map → chunk-T2O72JBW.mjs.map} +0 -0
- /package/dist/esm/{chunk-TSVHZZE4.mjs.map → chunk-VQO4MSEC.mjs.map} +0 -0
- /package/dist/esm/{chunk-676VIABN.min.mjs.map → chunk-X7VNAGLR.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-2GGMLKRP.min.mjs.map → chunk-YDQW6ETS.min.mjs.map} +0 -0
- /package/dist/esm/{introspection-THKMXV5V.min.mjs.map → introspection-FGDVYTPP.mjs.map} +0 -0
- /package/dist/esm/{introspection-YJF3QAUK.mjs.map → introspection-UDWDS6DV.min.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/events/adapters/kafka/index.ts","../../../../../src/errors/equippedError.ts","../../../../../src/events/adapters/base.ts","../../../../../src/instance/index.ts","../../../../../src/instance/hooks.ts","../../../../../src/instance/settings.ts","../../../../../src/utilities/configurable.ts","../../../../../src/utilities/json.ts","../../../../../src/utilities/random.ts"],"sourcesContent":["import { KafkaJS } from '@confluentinc/kafka-javascript'\nimport { v } from 'valleyed'\n\nimport { EquippedError } from '../../../errors'\nimport { Instance } from '../../../instance'\nimport type { Events } from '../../../types'\nimport { Random, configurable, parseJSONValue } from '../../../utilities'\nimport { EventBus, type Stream, type StreamOptions } from '../base'\n\nexport const kafkaConfigPipe = () =>\n\tv.meta(\n\t\tv.object({\n\t\t\tbrokers: v.array(v.string()),\n\t\t\tssl: v.optional(v.boolean()),\n\t\t\tsasl: v.optional(\n\t\t\t\tv.object({\n\t\t\t\t\tmechanism: v.is('plain' as const),\n\t\t\t\t\tusername: v.string(),\n\t\t\t\t\tpassword: v.string(),\n\t\t\t\t}),\n\t\t\t),\n\t\t\tclientId: v.optional(v.string()),\n\t\t}),\n\t\t{ title: 'Kafka Config', $refId: 'KafkaConfig' },\n\t)\n\nexport class KafkaEventBus extends configurable(kafkaConfigPipe, EventBus) {\n\t#client: KafkaJS.Kafka\n\t#admin: Promise<KafkaJS.Admin> | null = null\n\n\tprotected constructor(config: typeof KafkaEventBus.Config) {\n\t\tsuper(config)\n\t\tthis.#client = new KafkaJS.Kafka({\n\t\t\tkafkaJS: { ...config, logLevel: KafkaJS.logLevel.NOTHING },\n\t\t})\n\t}\n\n\tasync #getAdmin() {\n\t\tif (!this.#admin)\n\t\t\tthis.#admin = (async () => {\n\t\t\t\tconst admin = this.#client.admin()\n\t\t\t\tawait admin.connect()\n\t\t\t\treturn admin\n\t\t\t})()\n\t\treturn this.#admin\n\t}\n\n\tasync #createTopic(topic: string) {\n\t\tconst admin = await this.#getAdmin()\n\t\tawait admin.createTopics({ topics: [{ topic }], timeout: 5000 })\n\t}\n\n\tasync #deleteGroup(groupId: string) {\n\t\tconst admin = await this.#getAdmin()\n\t\tawait admin.deleteGroups([groupId]).catch(() => {})\n\t}\n\n\tstream<Event extends Events[keyof Events]>(topicName: Event['topic'], options: Partial<StreamOptions> = {}): Stream<Event['data']> {\n\t\tconst topic = options.skipScope ? topicName : Instance.get().getScopedName(topicName)\n\t\treturn {\n\t\t\tpublish: async (data) => {\n\t\t\t\tconst producer = this.#client.producer()\n\t\t\t\tawait producer.connect()\n\t\t\t\tawait producer.send({\n\t\t\t\t\ttopic,\n\t\t\t\t\tmessages: [{ value: JSON.stringify(data) }],\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t\tsubscribe: (onMessage) => {\n\t\t\t\tconst subscribe = async () => {\n\t\t\t\t\tawait this.#createTopic(topic)\n\t\t\t\t\tconst groupId = options.fanout\n\t\t\t\t\t\t? Instance.get().getScopedName(`${Instance.get().id}-fanout-${Random.string(10)}`)\n\t\t\t\t\t\t: topic\n\t\t\t\t\tconst consumer = this.#client.consumer({ kafkaJS: { groupId } })\n\n\t\t\t\t\tawait consumer.connect()\n\t\t\t\t\tawait consumer.subscribe({ topic })\n\n\t\t\t\t\tawait consumer.run({\n\t\t\t\t\t\teachMessage: async ({ message }) => {\n\t\t\t\t\t\t\tawait Instance.resolveBeforeCrash(async () => {\n\t\t\t\t\t\t\t\tif (!message.value) return\n\t\t\t\t\t\t\t\tawait onMessage(parseJSONValue(message.value.toString()))\n\t\t\t\t\t\t\t}).catch((error) =>\n\t\t\t\t\t\t\t\tInstance.crash(new EquippedError('Error processing kafka event', { topic, groupId, options }, error)),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\tif (options.fanout)\n\t\t\t\t\t\tInstance.on('close', async () => {\n\t\t\t\t\t\t\tawait consumer.disconnect()\n\t\t\t\t\t\t\tawait this.#deleteGroup(groupId)\n\t\t\t\t\t\t}, { class: KafkaEventBus })\n\t\t\t\t}\n\t\t\t\tInstance.on('start', subscribe, { class: KafkaEventBus })\n\t\t\t},\n\t\t}\n\t}\n}\n","export class EquippedError extends Error {\n\tconstructor(\n\t\tpublic readonly message: string,\n\t\tpublic readonly context: Record<string, unknown>,\n\t\tpublic readonly cause?: unknown,\n\t) {\n\t\tsuper(message, { cause })\n\t}\n}\n","import type { Events } from '../../types'\n\nexport type StreamOptions = { skipScope?: boolean; fanout: boolean }\n\nexport type Stream<EventData> = {\n\tpublish: (data: EventData) => Promise<boolean>\n\tsubscribe: (onMessage: (data: EventData) => Promise<void>) => void\n}\n\nexport abstract class EventBus {\n\tabstract stream<Event extends Events[keyof Events]>(topic: Event['topic'], options?: Partial<StreamOptions>): Stream<Event['data']>\n}\n","import pino, { type Logger } from 'pino'\nimport { ulid } from 'ulid'\nimport { type Pipe, v } from 'valleyed'\n\nimport { EquippedError } from '../errors'\nimport { type ClassRef, type HookCb, type HookEvent, type HookOptions, type HookRecord, registerHook, runHooks } from './hooks'\nimport { instanceSettingsPipe, type Settings, type SettingsInput } from './settings'\n\nexport type { ClassRef, HookCb, HookEvent, HookOptions }\n\nexport class Instance {\n\tstatic #id: string | undefined\n\tstatic #instance: Instance | undefined\n\tstatic #hooks: Partial<Record<HookEvent, HookRecord[]>> = {}\n\treadonly settings: Readonly<Settings>\n\treadonly log: Logger<never>\n\n\tprivate constructor(settings: Settings) {\n\t\tInstance.#instance = this\n\t\tthis.settings = Object.freeze(settings)\n\t\tthis.log = pino<never>({\n\t\t\tlevel: this.settings.log.level,\n\t\t\tserializers: {\n\t\t\t\terr: pino.stdSerializers.err,\n\t\t\t\terror: pino.stdSerializers.err,\n\t\t\t\treq: pino.stdSerializers.req,\n\t\t\t\tres: pino.stdSerializers.res,\n\t\t\t},\n\t\t\tmixin: () => ({\n\t\t\t\tinstanceId: Instance.#id,\n\t\t\t}),\n\t\t})\n\t\tInstance.#registerOnExitHandler()\n\t}\n\n\talias(id: string) {\n\t\tif (Instance.#id !== undefined) return Instance.crash(new EquippedError('Instance already has an alias', {}))\n\t\tInstance.#id = id\n\t}\n\n\tget id() {\n\t\tif (Instance.#id === undefined) return Instance.crash(new EquippedError('Instance doesnt have an alias yet', {}))\n\t\treturn Instance.#id\n\t}\n\n\tgetScopedName(name: string, key = '.') {\n\t\treturn [this.settings.app.name, name].join(key)\n\t}\n\n\tasync start() {\n\t\ttry {\n\t\t\tawait runHooks(Instance.#hooks['setup'] ?? [])\n\t\t\tawait runHooks(Instance.#hooks['start'] ?? [])\n\t\t} catch (error) {\n\t\t\tInstance.crash(new EquippedError(`Error starting instance`, {}, error))\n\t\t}\n\t}\n\n\tstatic envs<E extends object>(envsPipe: Pipe<unknown, E>): E {\n\t\tconst envValidity = v.validate(envsPipe, process.env)\n\t\tif (!envValidity.valid) {\n\t\t\tInstance.crash(\n\t\t\t\tnew EquippedError(`Environment variables are not valid\\n${envValidity.error.toString()}`, {\n\t\t\t\t\tmessages: envValidity.error.messages,\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t\treturn envValidity.value\n\t}\n\n\tstatic create(settings: SettingsInput) {\n\t\tif (Instance.#instance) return Instance.crash(new EquippedError('Instance has been initialized already', {}))\n\t\tconst settingsValidity = v.validate(instanceSettingsPipe(), settings)\n\t\tif (!settingsValidity.valid) {\n\t\t\tInstance.crash(\n\t\t\t\tnew EquippedError(`Settings are not valid\\n${settingsValidity.error.toString()}`, {\n\t\t\t\t\tmessages: settingsValidity.error.messages,\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t\treturn new Instance(settingsValidity.value)\n\t}\n\n\tstatic get() {\n\t\tif (!Instance.#instance)\n\t\t\treturn Instance.crash(\n\t\t\t\tnew EquippedError('Has not been initialized. Make sure an instance has been created before you get an instance', {}),\n\t\t\t)\n\t\treturn Instance.#instance\n\t}\n\n\tstatic maybeGet() {\n\t\treturn Instance.#instance\n\t}\n\n\tstatic on(event: HookEvent, cb: HookCb, options?: HookOptions) {\n\t\tInstance.#hooks[event] ??= []\n\t\tconst record: HookRecord = { cb, class: options?.class, after: options?.after ?? [] }\n\t\tregisterHook(Instance.#hooks[event], record)\n\t}\n\n\tstatic #registerOnExitHandler() {\n\t\tconst signals = {\n\t\t\tSIGHUP: 1,\n\t\t\tSIGINT: 2,\n\t\t\tSIGTERM: 15,\n\t\t}\n\n\t\tObject.entries(signals).forEach(([signal, code]) => {\n\t\t\tprocess.on(signal, async () => {\n\t\t\t\tawait runHooks(Instance.#hooks['close'] ?? [], () => {}, true)\n\t\t\t\tprocess.exit(128 + code)\n\t\t\t})\n\t\t})\n\t}\n\n\tstatic resolveBeforeCrash<T>(cb: () => Promise<T>) {\n\t\tconst value = cb()\n\t\tInstance.on('close', async () => await value)\n\t\treturn value\n\t}\n\n\tstatic crash(error: EquippedError): never {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(error)\n\t\tprocess.exit(1)\n\t}\n\n\tstatic createId(opts?: { prefix?: string; time?: Date }) {\n\t\treturn `${opts?.prefix ?? ''}${ulid(opts?.time?.getTime())}`\n\t}\n}\n","export type HookEvent = 'setup' | 'start' | 'close'\nexport type HookCb = Promise<unknown | void> | (() => void | unknown | Promise<void | unknown>)\n\nexport type ClassRef = Function & { prototype: unknown; name: string }\nexport type HookOptions = {\n\tclass?: ClassRef\n\tafter?: ClassRef[]\n}\nexport type HookRecord = { cb: HookCb; class?: ClassRef; after: ClassRef[] }\n\nexport function registerHook(hooks: HookRecord[], record: HookRecord): void {\n\tfor (const dep of record.after) {\n\t\tif (!hooks.some((h) => h.class === dep)) {\n\t\t\tconst depName = dep.name || 'unknown'\n\t\t\tconst ownerName = record.class?.name || 'anonymous'\n\t\t\tthrow new Error(`Missing dependency: ${ownerName} declares after: [${depName}], but ${depName} is not registered`)\n\t\t}\n\t}\n\n\tif (record.class) {\n\t\tconst tentative = [...hooks, record]\n\t\tdetectCycle(tentative)\n\t}\n\n\thooks.push(record)\n}\n\nfunction detectCycle(hooks: HookRecord[]): void {\n\tconst classToAfter = new Map<ClassRef, ClassRef[]>()\n\tfor (const h of hooks) {\n\t\tif (!h.class) continue\n\t\tconst existing = classToAfter.get(h.class)\n\t\tif (existing) {\n\t\t\tfor (const dep of h.after) {\n\t\t\t\tif (!existing.includes(dep)) existing.push(dep)\n\t\t\t}\n\t\t} else {\n\t\t\tclassToAfter.set(h.class, [...h.after])\n\t\t}\n\t}\n\n\tconst visited = new Set<ClassRef>()\n\tconst stack = new Set<ClassRef>()\n\n\tfunction visit(cls: ClassRef, path: ClassRef[]): void {\n\t\tif (stack.has(cls)) {\n\t\t\tconst cycleStart = path.indexOf(cls)\n\t\t\tconst cycle = [...path.slice(cycleStart), cls]\n\t\t\tconst names = cycle.map((c) => c.name || 'unknown')\n\t\t\tthrow new Error(`Cycle detected: ${names.join(' → ')}`)\n\t\t}\n\t\tif (visited.has(cls)) return\n\t\tstack.add(cls)\n\t\tpath.push(cls)\n\t\tfor (const dep of classToAfter.get(cls) ?? []) {\n\t\t\tvisit(dep, path)\n\t\t}\n\t\tpath.pop()\n\t\tstack.delete(cls)\n\t\tvisited.add(cls)\n\t}\n\n\tfor (const cls of classToAfter.keys()) {\n\t\tvisit(cls, [])\n\t}\n}\n\nexport type HookLayer = HookRecord[]\n\nexport function resolveHookDAG(hooks: HookRecord[], invert: boolean = false): HookLayer[] {\n\tif (hooks.length === 0) return []\n\n\tconst classToHooks = new Map<ClassRef, HookRecord[]>()\n\tconst anonymous: HookRecord[] = []\n\n\tfor (const h of hooks) {\n\t\tif (h.class) {\n\t\t\tconst list = classToHooks.get(h.class)\n\t\t\tif (list) list.push(h)\n\t\t\telse classToHooks.set(h.class, [h])\n\t\t} else {\n\t\t\tanonymous.push(h)\n\t\t}\n\t}\n\n\tconst classes = [...classToHooks.keys()]\n\n\tconst inDegree = new Map<ClassRef, number>()\n\tconst graph = new Map<ClassRef, ClassRef[]>()\n\n\tfor (const cls of classes) {\n\t\tinDegree.set(cls, 0)\n\t\tgraph.set(cls, [])\n\t}\n\n\tfor (const h of hooks) {\n\t\tif (!h.class) continue\n\t\tfor (const dep of h.after) {\n\t\t\tconst [from, to] = invert ? [h.class, dep] : [dep, h.class]\n\t\t\tconst edges = graph.get(from)!\n\t\t\tif (!edges.includes(to)) {\n\t\t\t\tedges.push(to)\n\t\t\t\tinDegree.set(to, inDegree.get(to)! + 1)\n\t\t\t}\n\t\t}\n\t}\n\n\tconst layers: HookLayer[] = []\n\tlet queue = classes.filter((c) => inDegree.get(c) === 0)\n\n\twhile (queue.length > 0) {\n\t\tconst layer: HookRecord[] = []\n\t\tconst next: ClassRef[] = []\n\n\t\tfor (const cls of queue) {\n\t\t\tlayer.push(...(classToHooks.get(cls) ?? []))\n\t\t}\n\t\tlayers.push(layer)\n\n\t\tfor (const cls of queue) {\n\t\t\tfor (const neighbor of graph.get(cls) ?? []) {\n\t\t\t\tconst d = inDegree.get(neighbor)! - 1\n\t\t\t\tinDegree.set(neighbor, d)\n\t\t\t\tif (d === 0) next.push(neighbor)\n\t\t\t}\n\t\t}\n\n\t\tqueue = next\n\t}\n\n\tif (anonymous.length > 0) {\n\t\tconst anonWithDeps = anonymous.filter((h) => h.after.length > 0)\n\t\tconst anonWithoutDeps = anonymous.filter((h) => h.after.length === 0)\n\n\t\tif (anonWithDeps.length > 0) {\n\t\t\tlet maxLayer = -1\n\t\t\tfor (const h of anonWithDeps) {\n\t\t\t\tfor (const dep of h.after) {\n\t\t\t\t\tconst depLayer = layers.findIndex((l) => l.some((r) => r.class === dep))\n\t\t\t\t\tif (depLayer > maxLayer) maxLayer = depLayer\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst insertAt = maxLayer + 1\n\t\t\tif (insertAt < layers.length) {\n\t\t\t\tlayers[insertAt].push(...anonWithDeps)\n\t\t\t} else {\n\t\t\t\tlayers.push(anonWithDeps)\n\t\t\t}\n\t\t}\n\n\t\tif (anonWithoutDeps.length > 0) {\n\t\t\tif (layers.length > 0) {\n\t\t\t\tlayers[layers.length - 1].push(...anonWithoutDeps)\n\t\t\t} else {\n\t\t\t\tlayers.push(anonWithoutDeps)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn layers\n}\n\nexport async function runHooks(\n\thooks: HookRecord[],\n\tonError: (error: Error) => void = (error) => {\n\t\tthrow error\n\t},\n\tinvert: boolean = false,\n) {\n\tconst layers = resolveHookDAG(hooks, invert)\n\tfor (const layer of layers)\n\t\tawait Promise.all(\n\t\t\tlayer.map(async (h) => {\n\t\t\t\ttry {\n\t\t\t\t\tif (typeof h.cb === 'function') return await h.cb()\n\t\t\t\t\treturn await h.cb\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn onError(error instanceof Error ? error : new Error(`${error}`))\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n}\n\nif (import.meta.vitest) {\n\tconst { describe, test, expect } = import.meta.vitest\n\n\tclass A {}\n\tclass B {}\n\tclass C {}\n\tclass D {}\n\n\tconst noop = () => {}\n\n\tdescribe('registerHook', () => {\n\t\ttest('registers a hook with no dependencies', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\texpect(hooks).toHaveLength(1)\n\t\t})\n\n\t\ttest('throws on missing dependency', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\texpect(() => registerHook(hooks, { cb: noop, class: B, after: [A] })).toThrow(/Missing dependency.*B.*A/)\n\t\t})\n\n\t\ttest('throws on cycle: A→B→A', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\tregisterHook(hooks, { cb: noop, class: B, after: [A] })\n\t\t\texpect(() => registerHook(hooks, { cb: noop, class: A, after: [B] })).toThrow(/Cycle detected/)\n\t\t})\n\n\t\ttest('throws on transitive cycle: A→B→C→A', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\tregisterHook(hooks, { cb: noop, class: B, after: [A] })\n\t\t\tregisterHook(hooks, { cb: noop, class: C, after: [B] })\n\t\t\texpect(() => registerHook(hooks, { cb: noop, class: A, after: [C] })).toThrow(/Cycle detected/)\n\t\t})\n\n\t\ttest('allows anonymous hooks with dependencies', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\tregisterHook(hooks, { cb: noop, after: [A] })\n\t\t\texpect(hooks).toHaveLength(2)\n\t\t})\n\n\t\ttest('anonymous hook throws on missing dependency', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\texpect(() => registerHook(hooks, { cb: noop, after: [A] })).toThrow(/Missing dependency.*anonymous.*A/)\n\t\t})\n\t})\n\n\tdescribe('resolveHookDAG', () => {\n\t\ttest('linear chain: A → B → C', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [B] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(3)\n\t\t\texpect(layers[0].every((h) => h.class === A)).toBe(true)\n\t\t\texpect(layers[1].every((h) => h.class === B)).toBe(true)\n\t\t\texpect(layers[2].every((h) => h.class === C)).toBe(true)\n\t\t})\n\n\t\ttest('fan-out: A → B, A → C (B and C are parallel)', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\texpect(layers[0].every((h) => h.class === A)).toBe(true)\n\t\t\tconst secondClasses = layers[1].map((h) => h.class)\n\t\t\texpect(secondClasses).toContain(B)\n\t\t\texpect(secondClasses).toContain(C)\n\t\t})\n\n\t\ttest('fan-in: B → D, C → D', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: B, after: [] },\n\t\t\t\t{ cb: noop, class: C, after: [] },\n\t\t\t\t{ cb: noop, class: D, after: [B, C] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\tconst firstClasses = layers[0].map((h) => h.class)\n\t\t\texpect(firstClasses).toContain(B)\n\t\t\texpect(firstClasses).toContain(C)\n\t\t\texpect(layers[1].every((h) => h.class === D)).toBe(true)\n\t\t})\n\n\t\ttest('diamond: A → B, A → C, B → D, C → D', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [A] },\n\t\t\t\t{ cb: noop, class: D, after: [B, C] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(3)\n\t\t\texpect(layers[0][0].class).toBe(A)\n\t\t\tconst midClasses = layers[1].map((h) => h.class)\n\t\t\texpect(midClasses).toContain(B)\n\t\t\texpect(midClasses).toContain(C)\n\t\t\texpect(layers[2][0].class).toBe(D)\n\t\t})\n\n\t\ttest('close-event inversion reverses the graph', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [B] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks, true)\n\t\t\texpect(layers).toHaveLength(3)\n\t\t\texpect(layers[0].every((h) => h.class === C)).toBe(true)\n\t\t\texpect(layers[1].every((h) => h.class === B)).toBe(true)\n\t\t\texpect(layers[2].every((h) => h.class === A)).toBe(true)\n\t\t})\n\n\t\ttest('close inversion: fan-out becomes fan-in', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks, true)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\tconst firstClasses = layers[0].map((h) => h.class)\n\t\t\texpect(firstClasses).toContain(B)\n\t\t\texpect(firstClasses).toContain(C)\n\t\t\texpect(layers[1].every((h) => h.class === A)).toBe(true)\n\t\t})\n\n\t\ttest('multiple hooks per class are all in the same layer', () => {\n\t\t\tconst cb1 = () => {}\n\t\t\tconst cb2 = () => {}\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: cb1, class: A, after: [] },\n\t\t\t\t{ cb: cb2, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\texpect(layers[0]).toHaveLength(2)\n\t\t\texpect(layers[0].every((h) => h.class === A)).toBe(true)\n\t\t})\n\n\t\ttest('anonymous hooks without deps run at deepest level', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, after: [] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\tconst lastLayer = layers[layers.length - 1]\n\t\t\texpect(lastLayer.some((h) => h.class === undefined)).toBe(true)\n\t\t})\n\n\t\ttest('anonymous hooks with deps run after their dependencies', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [B] },\n\t\t\t\t{ cb: noop, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\tconst anonLayer = layers.findIndex((l) => l.some((h) => h.class === undefined))\n\t\t\tconst aLayer = layers.findIndex((l) => l.some((h) => h.class === A))\n\t\t\texpect(anonLayer).toBeGreaterThan(aLayer)\n\t\t})\n\n\t\ttest('empty hooks returns empty layers', () => {\n\t\t\texpect(resolveHookDAG([])).toEqual([])\n\t\t})\n\t})\n\n\tdescribe('runHooks', () => {\n\t\ttest('same-depth siblings observably overlap', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('B-start')\n\t\t\t\t\t\tawait new Promise((r) => setTimeout(r, 20))\n\t\t\t\t\t\tlog.push('B-end')\n\t\t\t\t\t},\n\t\t\t\t\tclass: B,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('C-start')\n\t\t\t\t\t\tawait new Promise((r) => setTimeout(r, 20))\n\t\t\t\t\t\tlog.push('C-end')\n\t\t\t\t\t},\n\t\t\t\t\tclass: C,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks)\n\t\t\texpect(log[0]).toBe('B-start')\n\t\t\texpect(log[1]).toBe('C-start')\n\t\t})\n\n\t\ttest('different depths run sequentially', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('A')\n\t\t\t\t\t},\n\t\t\t\t\tclass: A,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('B')\n\t\t\t\t\t},\n\t\t\t\t\tclass: B,\n\t\t\t\t\tafter: [A],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks)\n\t\t\texpect(log).toEqual(['A', 'B'])\n\t\t})\n\n\t\ttest('close inversion runs hooks in reverse dependency order', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: async () => log.push('A'), class: A, after: [] },\n\t\t\t\t{ cb: async () => log.push('B'), class: B, after: [A] },\n\t\t\t\t{ cb: async () => log.push('C'), class: C, after: [B] },\n\t\t\t]\n\t\t\tawait runHooks(hooks, undefined, true)\n\t\t\texpect(log).toEqual(['C', 'B', 'A'])\n\t\t})\n\n\t\ttest('errors are routed to onError handler', async () => {\n\t\t\tconst errors: Error[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: () => {\n\t\t\t\t\t\tthrow new Error('boom')\n\t\t\t\t\t},\n\t\t\t\t\tclass: A,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks, (e) => {\n\t\t\t\terrors.push(e)\n\t\t\t})\n\t\t\texpect(errors).toHaveLength(1)\n\t\t\texpect(errors[0].message).toBe('boom')\n\t\t})\n\n\t\ttest('raw promise callbacks are awaited', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: Promise.resolve().then(() => log.push('resolved')),\n\t\t\t\t\tclass: A,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks)\n\t\t\texpect(log).toContain('resolved')\n\t\t})\n\t})\n}\n","import { type ConditionalObjectKeys, type PipeInput, type PipeOutput, v } from 'valleyed'\n\nexport const instanceSettingsPipe = () =>\n\tv.object({\n\t\tapp: v.object({\n\t\t\tname: v.string(),\n\t\t}),\n\t\tlog: v.defaults(\n\t\t\tv.object({\n\t\t\t\tlevel: v.defaults(v.in(['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'] as const), 'info'),\n\t\t\t}),\n\t\t\t{},\n\t\t),\n\t\tutils: v.defaults(\n\t\t\tv.object({\n\t\t\t\thashSaltRounds: v.defaults(v.number(), 10),\n\t\t\t\tpaginationDefaultLimit: v.defaults(v.number(), 100),\n\t\t\t\tmaxFileUploadSizeInMb: v.defaults(v.number(), 500),\n\t\t\t}),\n\t\t\t{},\n\t\t),\n\t})\n\nexport type Settings = PipeOutput<ReturnType<typeof instanceSettingsPipe>>\nexport type SettingsInput = ConditionalObjectKeys<PipeInput<ReturnType<typeof instanceSettingsPipe>>>\n","import { v, type ConditionalObjectKeys, type Pipe, type PipeInput, type PipeOutput } from 'valleyed'\n\ntype CtorParams<T> = ConstructorParameters<T & (abstract new (...args: any[]) => any)>\ntype BaseCtorParams<T> = T extends abstract new (...args: infer A) => any ? A : never\n\nexport function configurable<P extends Pipe<any, any>, Base extends abstract new (...args: any[]) => any>(pipeFn: () => P, base: Base) {\n\tconst pipe = pipeFn()\n\tv.compile(pipe)\n\n\tabstract class Configurable extends (base as unknown as new (...args: any[]) => any) {\n\t\tdeclare static readonly Config: PipeOutput<P>\n\n\t\tprotected constructor (protected readonly config: PipeOutput<P>, ...baseArgs: BaseCtorParams<Base>) {\n\t\t\t// eslint-disable-next-line constructor-super\n\t\t\tsuper(...baseArgs)\n\t\t}\n\n\t\tstatic create<This extends Function & { prototype: any }>(\n\t\t\tthis: This,\n\t\t\tinput: ConditionalObjectKeys<PipeInput<P>>,\n\t\t\t...args: CtorParams<This> extends [PipeOutput<P>, ...infer R] ? R : never\n\t\t): This['prototype'] {\n\t\t\tconst r = v.validate(pipe, input)\n\t\t\tif (!r.valid) throw r.error\n\t\t\treturn new (this as any)(r.value, ...args) as This['prototype']\n\t\t}\n\t}\n\n\treturn Configurable as unknown as (abstract new (validated: PipeOutput<P>, ...baseArgs: BaseCtorParams<Base>) => InstanceType<Base> & { readonly config: PipeOutput<P> }) & {\n\t\treadonly Config: PipeOutput<P>\n\t\tcreate<This extends Function & { prototype: any }>(\n\t\t\tthis: This,\n\t\t\tinput: ConditionalObjectKeys<PipeInput<P>>,\n\t\t\t...args: CtorParams<This> extends [PipeOutput<P>, ...infer R] ? R : never\n\t\t): This['prototype']\n\t}\n}\n\nif (import.meta.vitest) {\n\tconst { describe, test, expect, expectTypeOf } = import.meta.vitest\n\tconst { v } = await import('valleyed')\n\n\tconst testPipe = () =>\n\t\tv.object({\n\t\t\thost: v.string(),\n\t\t\tport: v.number(),\n\t\t})\n\n\ttype TestConfig = PipeOutput<ReturnType<typeof testPipe>>\n\n\tclass TestBase {\n\t\tbaseValue: string\n\t\tconstructor() {\n\t\t\tthis.baseValue = 'base'\n\t\t}\n\t}\n\n\tclass TestBaseWithArgs {\n\t\tlabel: string\n\t\tconstructor(label: string) {\n\t\t\tthis.label = label\n\t\t}\n\t}\n\n\tdescribe('configurable', () => {\n\t\ttest('validation runs in static create before constructor body executes', () => {\n\t\t\tlet constructorRan = false\n\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t\tconstructorRan = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\texpect(() => MyClass.create({ host: 123, port: 'bad' } as any)).toThrow()\n\t\t\texpect(constructorRan).toBe(false)\n\n\t\t\tMyClass.create({ host: 'localhost', port: 3000 })\n\t\t\texpect(constructorRan).toBe(true)\n\t\t})\n\n\t\ttest('constructor receives validated value', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tlet receivedConfig: unknown\n\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t\treceivedConfig = this.config\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMyClass.create({ host: 'localhost', port: 3000 })\n\n\t\t\texpect(receivedConfig).toEqual({ host: 'localhost', port: 3000 })\n\t\t})\n\n\t\ttest('external new is a compile error', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// @ts-expect-error — external `new` on a class with protected constructor is a compile error\n\t\t\tvoid (() => new MyClass({ host: 'localhost', port: 3000 }))\n\t\t})\n\n\t\ttest('static Config resolves to PipeOutput<P> at the type level', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\texpectTypeOf<typeof MyClass.Config>().toEqualTypeOf<TestConfig>()\n\t\t\texpect(MyClass.create).toBeTypeOf('function')\n\t\t})\n\n\t\ttest('ConstructorParameters<This>-based extras inference works for non-zero-arg leaf signatures', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\textra: number\n\t\t\t\tprotected constructor(config: typeof MyClass.Config, extra: number) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t\tthis.extra = extra\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = MyClass.create({ host: 'localhost', port: 3000 }, 42)\n\n\t\t\texpect(instance.extra).toBe(42)\n\t\t\texpectTypeOf(instance).toHaveProperty('extra')\n\t\t\texpectTypeOf(instance.extra).toEqualTypeOf<number>()\n\n\t\t\t// @ts-expect-error — wrong extra type\n\t\t\tvoid (() => MyClass.create({ host: 'localhost', port: 3000 }, 'not-a-number'))\n\t\t})\n\n\t\ttest('base-args forwarding works for non-zero-arg bases', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBaseWithArgs)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config, label: string) {\n\t\t\t\t\tsuper(config, label)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = MyClass.create({ host: 'localhost', port: 3000 }, 'test-label')\n\n\t\t\texpect(instance.label).toBe('test-label')\n\t\t})\n\n\t\ttest('config is accessible as protected readonly on instances', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\n\t\t\t\tgetHost() {\n\t\t\t\t\treturn this.config.host\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = MyClass.create({ host: 'localhost', port: 3000 })\n\t\t\texpect(instance.getHost()).toBe('localhost')\n\t\t})\n\n\t\ttest('accepts an abstract base class', () => {\n\t\t\tabstract class AbstractBase {\n\t\t\t\tabstract greet(): string\n\t\t\t}\n\n\t\t\tconst Wrapped = configurable(testPipe, AbstractBase)\n\t\t\tclass Concrete extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof Concrete.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\t\t\t\tgreet() {\n\t\t\t\t\treturn `hello from ${this.config.host}`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = Concrete.create({ host: 'localhost', port: 3000 })\n\t\t\texpect(instance.greet()).toBe('hello from localhost')\n\t\t\texpectTypeOf(instance).toHaveProperty('config')\n\t\t})\n\t})\n}\n","export const parseJSONValue = (data: any) => {\n\ttry {\n\t\tif (data?.constructor?.name !== 'String') return data\n\t\treturn JSON.parse(data)\n\t} catch {\n\t\treturn data\n\t}\n}\n\nexport function parseJSONObject<T extends object>(data: T) {\n\treturn Object.fromEntries(Object.entries(data).map(([key, value]) => [key, parseJSONValue(value)])) as T\n}\n","import crypto from 'crypto'\n\nexport function string(length = 20) {\n\treturn crypto.randomBytes(length).toString('hex').slice(0, length)\n}\n\nexport function number(min = 0, max = 2 ** 48 - 1) {\n\treturn crypto.randomInt(min, max)\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,oBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAwB,0CACxBC,EAAkB,oBCDX,IAAMC,EAAN,cAA4B,KAAM,CACxC,YACiBC,EACAC,EACAC,EACf,CACD,MAAMF,EAAS,CAAE,MAAAE,CAAM,CAAC,EAJR,aAAAF,EACA,aAAAC,EACA,WAAAC,CAGjB,CACD,ECCO,IAAeC,EAAf,KAAwB,CAE/B,ECXA,IAAAC,EAAkC,qBAClCC,EAAqB,gBACrBC,EAA6B,oBCQtB,SAASC,EAAaC,EAAqBC,EAA0B,CAC3E,QAAWC,KAAOD,EAAO,MACxB,GAAI,CAACD,EAAM,KAAMG,GAAMA,EAAE,QAAUD,CAAG,EAAG,CACxC,IAAME,EAAUF,EAAI,MAAQ,UACtBG,EAAYJ,EAAO,OAAO,MAAQ,YACxC,MAAM,IAAI,MAAM,uBAAuBI,CAAS,qBAAqBD,CAAO,UAAUA,CAAO,oBAAoB,CAClH,CAGD,GAAIH,EAAO,MAAO,CACjB,IAAMK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D,CACD","names":["kafka_exports","__export","KafkaEventBus","kafkaConfigPipe","__toCommonJS","import_kafka_javascript","import_valleyed","EquippedError","message","context","cause","EventBus","import_pino","import_ulid","import_valleyed","registerHook","hooks","record","dep","h","depName","ownerName","tentative","detectCycle","classToAfter","existing","visited","stack","visit","cls","path","cycleStart","names","c","resolveHookDAG","invert","classToHooks","anonymous","list","classes","inDegree","graph","from","to","edges","layers","queue","layer","next","neighbor","d","anonWithDeps","anonWithoutDeps","maxLayer","depLayer","l","r","insertAt","runHooks","onError","error","import_valleyed","instanceSettingsPipe","Instance","_Instance","#id","#instance","#hooks","settings","pino","#registerOnExitHandler","id","EquippedError","name","key","runHooks","error","envsPipe","envValidity","settingsValidity","instanceSettingsPipe","event","cb","options","record","registerHook","signal","code","value","opts","import_valleyed","configurable","pipeFn","base","pipe","Configurable","config","baseArgs","input","args","r","parseJSONValue","data","random_exports","__export","number","string","import_crypto","length","crypto","min","max","kafkaConfigPipe","KafkaEventBus","_KafkaEventBus","configurable","EventBus","#client","#admin","config","#getAdmin","admin","#createTopic","topic","#deleteGroup","groupId","topicName","options","Instance","data","producer","onMessage","subscribe","random_exports","consumer","message","parseJSONValue","error","EquippedError"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/events/adapters/kafka/index.ts","../../../../../src/errors/equippedError.ts","../../../../../src/events/adapters/base.ts","../../../../../src/instance/index.ts","../../../../../src/instance/hooks.ts","../../../../../src/instance/settings.ts","../../../../../src/utilities/configurable.ts","../../../../../src/utilities/json.ts","../../../../../src/utilities/random.ts"],"sourcesContent":["import { KafkaJS } from '@confluentinc/kafka-javascript'\nimport { v } from 'valleyed'\n\nimport { EquippedError } from '../../../errors'\nimport { Instance } from '../../../instance'\nimport type { Events } from '../../../types'\nimport { Random, configurable, parseJSONValue } from '../../../utilities'\nimport { EventBus, type Stream, type StreamOptions } from '../base'\n\nexport const kafkaConfigPipe = () =>\n\tv.meta(\n\t\tv.object({\n\t\t\tbrokers: v.array(v.string()),\n\t\t\tssl: v.optional(v.boolean()),\n\t\t\tsasl: v.optional(\n\t\t\t\tv.object({\n\t\t\t\t\tmechanism: v.is('plain' as const),\n\t\t\t\t\tusername: v.string(),\n\t\t\t\t\tpassword: v.string(),\n\t\t\t\t}),\n\t\t\t),\n\t\t\tclientId: v.optional(v.string()),\n\t\t}),\n\t\t{ title: 'Kafka Config', $refId: 'KafkaConfig' },\n\t)\n\nexport class KafkaEventBus extends configurable(kafkaConfigPipe, EventBus) {\n\t#client: KafkaJS.Kafka\n\t#admin: Promise<KafkaJS.Admin> | null = null\n\n\tprotected constructor(config: typeof KafkaEventBus.Config) {\n\t\tsuper(config)\n\t\tthis.#client = new KafkaJS.Kafka({\n\t\t\tkafkaJS: { ...config, logLevel: KafkaJS.logLevel.NOTHING },\n\t\t})\n\t}\n\n\tasync #getAdmin() {\n\t\tif (!this.#admin)\n\t\t\tthis.#admin = (async () => {\n\t\t\t\tconst admin = this.#client.admin()\n\t\t\t\tawait admin.connect()\n\t\t\t\treturn admin\n\t\t\t})()\n\t\treturn this.#admin\n\t}\n\n\tasync #createTopic(topic: string) {\n\t\tconst admin = await this.#getAdmin()\n\t\tawait admin.createTopics({ topics: [{ topic }], timeout: 5000 })\n\t}\n\n\tasync #deleteGroup(groupId: string) {\n\t\tconst admin = await this.#getAdmin()\n\t\tawait admin.deleteGroups([groupId]).catch(() => {})\n\t}\n\n\tstream<Event extends Events[keyof Events]>(topicName: Event['topic'], options: Partial<StreamOptions> = {}): Stream<Event['data']> {\n\t\tconst topic = options.skipScope ? topicName : Instance.get().getScopedName(topicName)\n\t\treturn {\n\t\t\tpublish: async (data) => {\n\t\t\t\tconst producer = this.#client.producer()\n\t\t\t\tawait producer.connect()\n\t\t\t\tawait producer.send({\n\t\t\t\t\ttopic,\n\t\t\t\t\tmessages: [{ value: JSON.stringify(data) }],\n\t\t\t\t})\n\t\t\t\treturn true\n\t\t\t},\n\t\t\tsubscribe: (onMessage) => {\n\t\t\t\tconst subscribe = async () => {\n\t\t\t\t\tawait this.#createTopic(topic)\n\t\t\t\t\tconst groupId = options.fanout\n\t\t\t\t\t\t? Instance.get().getScopedName(`${Instance.get().id}-fanout-${Random.string(10)}`)\n\t\t\t\t\t\t: topic\n\t\t\t\t\tconst consumer = this.#client.consumer({ kafkaJS: { groupId } })\n\n\t\t\t\t\tawait consumer.connect()\n\t\t\t\t\tawait consumer.subscribe({ topic })\n\n\t\t\t\t\tawait consumer.run({\n\t\t\t\t\t\teachMessage: async ({ message }) => {\n\t\t\t\t\t\t\tawait Instance.resolveBeforeCrash(async () => {\n\t\t\t\t\t\t\t\tif (!message.value) return\n\t\t\t\t\t\t\t\tawait onMessage(parseJSONValue(message.value.toString()))\n\t\t\t\t\t\t\t}).catch((error) =>\n\t\t\t\t\t\t\t\tInstance.crash(new EquippedError('Error processing kafka event', { topic, groupId, options }, error)),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\n\t\t\t\t\tif (options.fanout)\n\t\t\t\t\t\tInstance.on('close', async () => {\n\t\t\t\t\t\t\tawait consumer.disconnect()\n\t\t\t\t\t\t\tawait this.#deleteGroup(groupId)\n\t\t\t\t\t\t}, { class: KafkaEventBus })\n\t\t\t\t}\n\t\t\t\tInstance.on('start', subscribe, { class: KafkaEventBus })\n\t\t\t},\n\t\t}\n\t}\n}\n","export class EquippedError extends Error {\n\tconstructor(\n\t\tpublic readonly message: string,\n\t\tpublic readonly context: Record<string, unknown>,\n\t\tpublic readonly cause?: unknown,\n\t) {\n\t\tsuper(message, { cause })\n\t}\n}\n","import type { Events } from '../../types'\n\nexport type StreamOptions = { skipScope?: boolean; fanout: boolean }\n\nexport type Stream<EventData> = {\n\tpublish: (data: EventData) => Promise<boolean>\n\tsubscribe: (onMessage: (data: EventData) => Promise<void>) => void\n}\n\nexport abstract class EventBus {\n\tabstract stream<Event extends Events[keyof Events]>(topic: Event['topic'], options?: Partial<StreamOptions>): Stream<Event['data']>\n}\n","import pino, { type Logger } from 'pino'\nimport { ulid } from 'ulid'\nimport { type Pipe, v } from 'valleyed'\n\nimport { EquippedError } from '../errors'\nimport { type ClassRef, type HookCb, type HookEvent, type HookOptions, type HookRecord, registerHook, runHooks } from './hooks'\nimport { instanceSettingsPipe, type Settings, type SettingsInput } from './settings'\n\nexport type { ClassRef, HookCb, HookEvent, HookOptions }\n\nexport class Instance {\n\tstatic #id: string | undefined\n\tstatic #instance: Instance | undefined\n\tstatic #hooks: Partial<Record<HookEvent, HookRecord[]>> = {}\n\treadonly settings: Readonly<Settings>\n\treadonly log: Logger<never>\n\n\tprivate constructor(settings: Settings) {\n\t\tInstance.#instance = this\n\t\tthis.settings = Object.freeze(settings)\n\t\tthis.log = pino<never>({\n\t\t\tlevel: this.settings.log.level,\n\t\t\tserializers: {\n\t\t\t\terr: pino.stdSerializers.err,\n\t\t\t\terror: pino.stdSerializers.err,\n\t\t\t\treq: pino.stdSerializers.req,\n\t\t\t\tres: pino.stdSerializers.res,\n\t\t\t},\n\t\t\tmixin: () => ({\n\t\t\t\tinstanceId: Instance.#id,\n\t\t\t}),\n\t\t})\n\t\tInstance.#registerOnExitHandler()\n\t}\n\n\talias(id: string) {\n\t\tif (Instance.#id !== undefined) return Instance.crash(new EquippedError('Instance already has an alias', {}))\n\t\tInstance.#id = id\n\t}\n\n\tget id() {\n\t\tif (Instance.#id === undefined) return Instance.crash(new EquippedError('Instance doesnt have an alias yet', {}))\n\t\treturn Instance.#id\n\t}\n\n\tgetScopedName(name: string, key = '.') {\n\t\treturn [this.settings.app.name, name].join(key)\n\t}\n\n\tasync start() {\n\t\ttry {\n\t\t\tawait runHooks(Instance.#hooks['setup'] ?? [])\n\t\t\tawait runHooks(Instance.#hooks['start'] ?? [])\n\t\t} catch (error) {\n\t\t\tInstance.crash(new EquippedError(`Error starting instance`, {}, error))\n\t\t}\n\t}\n\n\tstatic envs<E extends object>(envsPipe: Pipe<unknown, E>): E {\n\t\tconst envValidity = v.validate(envsPipe, process.env)\n\t\tif (!envValidity.valid) {\n\t\t\tInstance.crash(\n\t\t\t\tnew EquippedError(`Environment variables are not valid\\n${envValidity.error.toString()}`, {\n\t\t\t\t\tmessages: envValidity.error.messages,\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t\treturn envValidity.value\n\t}\n\n\tstatic create(settings: SettingsInput) {\n\t\tif (Instance.#instance) return Instance.crash(new EquippedError('Instance has been initialized already', {}))\n\t\tconst settingsValidity = v.validate(instanceSettingsPipe(), settings)\n\t\tif (!settingsValidity.valid) {\n\t\t\tInstance.crash(\n\t\t\t\tnew EquippedError(`Settings are not valid\\n${settingsValidity.error.toString()}`, {\n\t\t\t\t\tmessages: settingsValidity.error.messages,\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\t\treturn new Instance(settingsValidity.value)\n\t}\n\n\tstatic get() {\n\t\tif (!Instance.#instance)\n\t\t\treturn Instance.crash(\n\t\t\t\tnew EquippedError('Has not been initialized. Make sure an instance has been created before you get an instance', {}),\n\t\t\t)\n\t\treturn Instance.#instance\n\t}\n\n\tstatic maybeGet() {\n\t\treturn Instance.#instance\n\t}\n\n\tstatic on(event: HookEvent, cb: HookCb, options?: HookOptions) {\n\t\tInstance.#hooks[event] ??= []\n\t\tconst record: HookRecord = { cb, class: options?.class, after: options?.after ?? [] }\n\t\tregisterHook(Instance.#hooks[event], record)\n\t}\n\n\tstatic #registerOnExitHandler() {\n\t\tconst signals = {\n\t\t\tSIGHUP: 1,\n\t\t\tSIGINT: 2,\n\t\t\tSIGTERM: 15,\n\t\t}\n\n\t\tObject.entries(signals).forEach(([signal, code]) => {\n\t\t\tprocess.on(signal, async () => {\n\t\t\t\tawait runHooks(Instance.#hooks['close'] ?? [], () => {}, true)\n\t\t\t\tprocess.exit(128 + code)\n\t\t\t})\n\t\t})\n\t}\n\n\tstatic resolveBeforeCrash<T>(cb: () => Promise<T>) {\n\t\tconst value = cb()\n\t\tInstance.on('close', async () => await value)\n\t\treturn value\n\t}\n\n\tstatic crash(error: EquippedError): never {\n\t\t// eslint-disable-next-line no-console\n\t\tconsole.error(error)\n\t\tprocess.exit(1)\n\t}\n\n\tstatic createId(opts?: { prefix?: string; time?: Date }) {\n\t\treturn `${opts?.prefix ?? ''}${ulid(opts?.time?.getTime())}`\n\t}\n}\n","export type HookEvent = 'setup' | 'start' | 'close'\nexport type HookCb = Promise<unknown | void> | (() => void | unknown | Promise<void | unknown>)\n\nexport type ClassRef = Function & { prototype: unknown; name: string }\nexport type HookOptions = {\n\tclass?: ClassRef\n\tafter?: ClassRef[]\n}\nexport type HookRecord = { cb: HookCb; class?: ClassRef; after: ClassRef[] }\n\nexport function registerHook(hooks: HookRecord[], record: HookRecord): void {\n\tfor (const dep of record.after) {\n\t\tif (!hooks.some((h) => h.class === dep)) {\n\t\t\tconst depName = dep.name || 'unknown'\n\t\t\tconst ownerName = record.class?.name || 'anonymous'\n\t\t\tthrow new Error(`Missing dependency: ${ownerName} declares after: [${depName}], but ${depName} is not registered`)\n\t\t}\n\t}\n\n\tif (record.class) {\n\t\tconst tentative = [...hooks, record]\n\t\tdetectCycle(tentative)\n\t}\n\n\thooks.push(record)\n}\n\nfunction detectCycle(hooks: HookRecord[]): void {\n\tconst classToAfter = new Map<ClassRef, ClassRef[]>()\n\tfor (const h of hooks) {\n\t\tif (!h.class) continue\n\t\tconst existing = classToAfter.get(h.class)\n\t\tif (existing) {\n\t\t\tfor (const dep of h.after) {\n\t\t\t\tif (!existing.includes(dep)) existing.push(dep)\n\t\t\t}\n\t\t} else {\n\t\t\tclassToAfter.set(h.class, [...h.after])\n\t\t}\n\t}\n\n\tconst visited = new Set<ClassRef>()\n\tconst stack = new Set<ClassRef>()\n\n\tfunction visit(cls: ClassRef, path: ClassRef[]): void {\n\t\tif (stack.has(cls)) {\n\t\t\tconst cycleStart = path.indexOf(cls)\n\t\t\tconst cycle = [...path.slice(cycleStart), cls]\n\t\t\tconst names = cycle.map((c) => c.name || 'unknown')\n\t\t\tthrow new Error(`Cycle detected: ${names.join(' → ')}`)\n\t\t}\n\t\tif (visited.has(cls)) return\n\t\tstack.add(cls)\n\t\tpath.push(cls)\n\t\tfor (const dep of classToAfter.get(cls) ?? []) {\n\t\t\tvisit(dep, path)\n\t\t}\n\t\tpath.pop()\n\t\tstack.delete(cls)\n\t\tvisited.add(cls)\n\t}\n\n\tfor (const cls of classToAfter.keys()) {\n\t\tvisit(cls, [])\n\t}\n}\n\nexport type HookLayer = HookRecord[]\n\nexport function resolveHookDAG(hooks: HookRecord[], invert: boolean = false): HookLayer[] {\n\tif (hooks.length === 0) return []\n\n\tconst classToHooks = new Map<ClassRef, HookRecord[]>()\n\tconst anonymous: HookRecord[] = []\n\n\tfor (const h of hooks) {\n\t\tif (h.class) {\n\t\t\tconst list = classToHooks.get(h.class)\n\t\t\tif (list) list.push(h)\n\t\t\telse classToHooks.set(h.class, [h])\n\t\t} else {\n\t\t\tanonymous.push(h)\n\t\t}\n\t}\n\n\tconst classes = [...classToHooks.keys()]\n\n\tconst inDegree = new Map<ClassRef, number>()\n\tconst graph = new Map<ClassRef, ClassRef[]>()\n\n\tfor (const cls of classes) {\n\t\tinDegree.set(cls, 0)\n\t\tgraph.set(cls, [])\n\t}\n\n\tfor (const h of hooks) {\n\t\tif (!h.class) continue\n\t\tfor (const dep of h.after) {\n\t\t\tconst [from, to] = invert ? [h.class, dep] : [dep, h.class]\n\t\t\tconst edges = graph.get(from)!\n\t\t\tif (!edges.includes(to)) {\n\t\t\t\tedges.push(to)\n\t\t\t\tinDegree.set(to, inDegree.get(to)! + 1)\n\t\t\t}\n\t\t}\n\t}\n\n\tconst layers: HookLayer[] = []\n\tlet queue = classes.filter((c) => inDegree.get(c) === 0)\n\n\twhile (queue.length > 0) {\n\t\tconst layer: HookRecord[] = []\n\t\tconst next: ClassRef[] = []\n\n\t\tfor (const cls of queue) {\n\t\t\tlayer.push(...(classToHooks.get(cls) ?? []))\n\t\t}\n\t\tlayers.push(layer)\n\n\t\tfor (const cls of queue) {\n\t\t\tfor (const neighbor of graph.get(cls) ?? []) {\n\t\t\t\tconst d = inDegree.get(neighbor)! - 1\n\t\t\t\tinDegree.set(neighbor, d)\n\t\t\t\tif (d === 0) next.push(neighbor)\n\t\t\t}\n\t\t}\n\n\t\tqueue = next\n\t}\n\n\tif (anonymous.length > 0) {\n\t\tconst anonWithDeps = anonymous.filter((h) => h.after.length > 0)\n\t\tconst anonWithoutDeps = anonymous.filter((h) => h.after.length === 0)\n\n\t\tif (anonWithDeps.length > 0) {\n\t\t\tlet maxLayer = -1\n\t\t\tfor (const h of anonWithDeps) {\n\t\t\t\tfor (const dep of h.after) {\n\t\t\t\t\tconst depLayer = layers.findIndex((l) => l.some((r) => r.class === dep))\n\t\t\t\t\tif (depLayer > maxLayer) maxLayer = depLayer\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst insertAt = maxLayer + 1\n\t\t\tif (insertAt < layers.length) {\n\t\t\t\tlayers[insertAt].push(...anonWithDeps)\n\t\t\t} else {\n\t\t\t\tlayers.push(anonWithDeps)\n\t\t\t}\n\t\t}\n\n\t\tif (anonWithoutDeps.length > 0) {\n\t\t\tif (layers.length > 0) {\n\t\t\t\tlayers[layers.length - 1].push(...anonWithoutDeps)\n\t\t\t} else {\n\t\t\t\tlayers.push(anonWithoutDeps)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn layers\n}\n\nexport async function runHooks(\n\thooks: HookRecord[],\n\tonError: (error: Error) => void = (error) => {\n\t\tthrow error\n\t},\n\tinvert: boolean = false,\n) {\n\tconst layers = resolveHookDAG(hooks, invert)\n\tfor (const layer of layers)\n\t\tawait Promise.all(\n\t\t\tlayer.map(async (h) => {\n\t\t\t\ttry {\n\t\t\t\t\tif (typeof h.cb === 'function') return await h.cb()\n\t\t\t\t\treturn await h.cb\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn onError(error instanceof Error ? error : new Error(`${error}`))\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n}\n\nif (import.meta.vitest) {\n\tconst { describe, test, expect } = import.meta.vitest\n\n\tclass A {}\n\tclass B {}\n\tclass C {}\n\tclass D {}\n\n\tconst noop = () => {}\n\n\tdescribe('registerHook', () => {\n\t\ttest('registers a hook with no dependencies', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\texpect(hooks).toHaveLength(1)\n\t\t})\n\n\t\ttest('throws on missing dependency', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\texpect(() => registerHook(hooks, { cb: noop, class: B, after: [A] })).toThrow(/Missing dependency.*B.*A/)\n\t\t})\n\n\t\ttest('throws on cycle: A→B→A', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\tregisterHook(hooks, { cb: noop, class: B, after: [A] })\n\t\t\texpect(() => registerHook(hooks, { cb: noop, class: A, after: [B] })).toThrow(/Cycle detected/)\n\t\t})\n\n\t\ttest('throws on transitive cycle: A→B→C→A', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\tregisterHook(hooks, { cb: noop, class: B, after: [A] })\n\t\t\tregisterHook(hooks, { cb: noop, class: C, after: [B] })\n\t\t\texpect(() => registerHook(hooks, { cb: noop, class: A, after: [C] })).toThrow(/Cycle detected/)\n\t\t})\n\n\t\ttest('allows anonymous hooks with dependencies', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\tregisterHook(hooks, { cb: noop, class: A, after: [] })\n\t\t\tregisterHook(hooks, { cb: noop, after: [A] })\n\t\t\texpect(hooks).toHaveLength(2)\n\t\t})\n\n\t\ttest('anonymous hook throws on missing dependency', () => {\n\t\t\tconst hooks: HookRecord[] = []\n\t\t\texpect(() => registerHook(hooks, { cb: noop, after: [A] })).toThrow(/Missing dependency.*anonymous.*A/)\n\t\t})\n\t})\n\n\tdescribe('resolveHookDAG', () => {\n\t\ttest('linear chain: A → B → C', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [B] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(3)\n\t\t\texpect(layers[0].every((h) => h.class === A)).toBe(true)\n\t\t\texpect(layers[1].every((h) => h.class === B)).toBe(true)\n\t\t\texpect(layers[2].every((h) => h.class === C)).toBe(true)\n\t\t})\n\n\t\ttest('fan-out: A → B, A → C (B and C are parallel)', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\texpect(layers[0].every((h) => h.class === A)).toBe(true)\n\t\t\tconst secondClasses = layers[1].map((h) => h.class)\n\t\t\texpect(secondClasses).toContain(B)\n\t\t\texpect(secondClasses).toContain(C)\n\t\t})\n\n\t\ttest('fan-in: B → D, C → D', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: B, after: [] },\n\t\t\t\t{ cb: noop, class: C, after: [] },\n\t\t\t\t{ cb: noop, class: D, after: [B, C] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\tconst firstClasses = layers[0].map((h) => h.class)\n\t\t\texpect(firstClasses).toContain(B)\n\t\t\texpect(firstClasses).toContain(C)\n\t\t\texpect(layers[1].every((h) => h.class === D)).toBe(true)\n\t\t})\n\n\t\ttest('diamond: A → B, A → C, B → D, C → D', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [A] },\n\t\t\t\t{ cb: noop, class: D, after: [B, C] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(3)\n\t\t\texpect(layers[0][0].class).toBe(A)\n\t\t\tconst midClasses = layers[1].map((h) => h.class)\n\t\t\texpect(midClasses).toContain(B)\n\t\t\texpect(midClasses).toContain(C)\n\t\t\texpect(layers[2][0].class).toBe(D)\n\t\t})\n\n\t\ttest('close-event inversion reverses the graph', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [B] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks, true)\n\t\t\texpect(layers).toHaveLength(3)\n\t\t\texpect(layers[0].every((h) => h.class === C)).toBe(true)\n\t\t\texpect(layers[1].every((h) => h.class === B)).toBe(true)\n\t\t\texpect(layers[2].every((h) => h.class === A)).toBe(true)\n\t\t})\n\n\t\ttest('close inversion: fan-out becomes fan-in', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks, true)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\tconst firstClasses = layers[0].map((h) => h.class)\n\t\t\texpect(firstClasses).toContain(B)\n\t\t\texpect(firstClasses).toContain(C)\n\t\t\texpect(layers[1].every((h) => h.class === A)).toBe(true)\n\t\t})\n\n\t\ttest('multiple hooks per class are all in the same layer', () => {\n\t\t\tconst cb1 = () => {}\n\t\t\tconst cb2 = () => {}\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: cb1, class: A, after: [] },\n\t\t\t\t{ cb: cb2, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\texpect(layers[0]).toHaveLength(2)\n\t\t\texpect(layers[0].every((h) => h.class === A)).toBe(true)\n\t\t})\n\n\t\ttest('anonymous hooks without deps run at deepest level', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, after: [] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\texpect(layers).toHaveLength(2)\n\t\t\tconst lastLayer = layers[layers.length - 1]\n\t\t\texpect(lastLayer.some((h) => h.class === undefined)).toBe(true)\n\t\t})\n\n\t\ttest('anonymous hooks with deps run after their dependencies', () => {\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: noop, class: A, after: [] },\n\t\t\t\t{ cb: noop, class: B, after: [A] },\n\t\t\t\t{ cb: noop, class: C, after: [B] },\n\t\t\t\t{ cb: noop, after: [A] },\n\t\t\t]\n\t\t\tconst layers = resolveHookDAG(hooks)\n\t\t\tconst anonLayer = layers.findIndex((l) => l.some((h) => h.class === undefined))\n\t\t\tconst aLayer = layers.findIndex((l) => l.some((h) => h.class === A))\n\t\t\texpect(anonLayer).toBeGreaterThan(aLayer)\n\t\t})\n\n\t\ttest('empty hooks returns empty layers', () => {\n\t\t\texpect(resolveHookDAG([])).toEqual([])\n\t\t})\n\t})\n\n\tdescribe('runHooks', () => {\n\t\ttest('same-depth siblings observably overlap', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('B-start')\n\t\t\t\t\t\tawait new Promise((r) => setTimeout(r, 20))\n\t\t\t\t\t\tlog.push('B-end')\n\t\t\t\t\t},\n\t\t\t\t\tclass: B,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('C-start')\n\t\t\t\t\t\tawait new Promise((r) => setTimeout(r, 20))\n\t\t\t\t\t\tlog.push('C-end')\n\t\t\t\t\t},\n\t\t\t\t\tclass: C,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks)\n\t\t\texpect(log[0]).toBe('B-start')\n\t\t\texpect(log[1]).toBe('C-start')\n\t\t})\n\n\t\ttest('different depths run sequentially', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('A')\n\t\t\t\t\t},\n\t\t\t\t\tclass: A,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcb: async () => {\n\t\t\t\t\t\tlog.push('B')\n\t\t\t\t\t},\n\t\t\t\t\tclass: B,\n\t\t\t\t\tafter: [A],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks)\n\t\t\texpect(log).toEqual(['A', 'B'])\n\t\t})\n\n\t\ttest('close inversion runs hooks in reverse dependency order', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{ cb: async () => log.push('A'), class: A, after: [] },\n\t\t\t\t{ cb: async () => log.push('B'), class: B, after: [A] },\n\t\t\t\t{ cb: async () => log.push('C'), class: C, after: [B] },\n\t\t\t]\n\t\t\tawait runHooks(hooks, undefined, true)\n\t\t\texpect(log).toEqual(['C', 'B', 'A'])\n\t\t})\n\n\t\ttest('errors are routed to onError handler', async () => {\n\t\t\tconst errors: Error[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: () => {\n\t\t\t\t\t\tthrow new Error('boom')\n\t\t\t\t\t},\n\t\t\t\t\tclass: A,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks, (e) => {\n\t\t\t\terrors.push(e)\n\t\t\t})\n\t\t\texpect(errors).toHaveLength(1)\n\t\t\texpect(errors[0].message).toBe('boom')\n\t\t})\n\n\t\ttest('raw promise callbacks are awaited', async () => {\n\t\t\tconst log: string[] = []\n\t\t\tconst hooks: HookRecord[] = [\n\t\t\t\t{\n\t\t\t\t\tcb: Promise.resolve().then(() => log.push('resolved')),\n\t\t\t\t\tclass: A,\n\t\t\t\t\tafter: [],\n\t\t\t\t},\n\t\t\t]\n\t\t\tawait runHooks(hooks)\n\t\t\texpect(log).toContain('resolved')\n\t\t})\n\t})\n}\n","import { type ConditionalObjectKeys, type PipeInput, type PipeOutput, v } from 'valleyed'\n\nexport const instanceSettingsPipe = () =>\n\tv.object({\n\t\tapp: v.object({\n\t\t\tname: v.string(),\n\t\t}),\n\t\tlog: v.defaults(\n\t\t\tv.object({\n\t\t\t\tlevel: v.defaults(v.in(['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'] as const), 'info'),\n\t\t\t}),\n\t\t\t{},\n\t\t),\n\t\tutils: v.defaults(\n\t\t\tv.object({\n\t\t\t\thashSaltRounds: v.defaults(v.number(), 10),\n\t\t\t\tpaginationDefaultLimit: v.defaults(v.number(), 100),\n\t\t\t\tmaxFileUploadSizeInMb: v.defaults(v.number(), 500),\n\t\t\t}),\n\t\t\t{},\n\t\t),\n\t})\n\nexport type Settings = PipeOutput<ReturnType<typeof instanceSettingsPipe>>\nexport type SettingsInput = ConditionalObjectKeys<PipeInput<ReturnType<typeof instanceSettingsPipe>>>\n","import { v, type ConditionalObjectKeys, type Pipe, type PipeInput, type PipeOutput } from 'valleyed'\n\ntype CtorParams<T> = ConstructorParameters<T & (abstract new (...args: any[]) => any)>\ntype BaseCtorParams<T> = T extends abstract new (...args: infer A) => any ? A : never\n\nexport function configurable<P extends Pipe<any, any>, Base extends abstract new (...args: any[]) => any>(pipeFn: () => P, base: Base) {\n\tconst pipe = pipeFn()\n\tv.compile(pipe)\n\n\tabstract class Configurable extends (base as unknown as new (...args: any[]) => any) {\n\t\tdeclare static readonly Config: PipeOutput<P>\n\n\t\tprotected constructor (protected readonly config: PipeOutput<P>, ...baseArgs: BaseCtorParams<Base>) {\n\t\t\t// eslint-disable-next-line constructor-super\n\t\t\tsuper(...baseArgs)\n\t\t}\n\n\t\tstatic create<This extends Function & { prototype: any }>(\n\t\t\tthis: This,\n\t\t\tinput: ConditionalObjectKeys<PipeInput<P>>,\n\t\t\t...args: CtorParams<This> extends [PipeOutput<P>, ...infer R] ? R : never\n\t\t): This['prototype'] {\n\t\t\tconst r = v.validate(pipe, input)\n\t\t\tif (!r.valid) throw r.error\n\t\t\treturn new (this as any)(r.value, ...args) as This['prototype']\n\t\t}\n\t}\n\n\treturn Configurable as unknown as (abstract new (validated: PipeOutput<P>, ...baseArgs: BaseCtorParams<Base>) => InstanceType<Base> & { readonly config: PipeOutput<P> }) & {\n\t\treadonly Config: PipeOutput<P>\n\t\tcreate<This extends Function & { prototype: any }>(\n\t\t\tthis: This,\n\t\t\tinput: ConditionalObjectKeys<PipeInput<P>>,\n\t\t\t...args: CtorParams<This> extends [PipeOutput<P>, ...infer R] ? R : never\n\t\t): This['prototype']\n\t}\n}\n\nif (import.meta.vitest) {\n\tconst { describe, test, expect, expectTypeOf } = import.meta.vitest\n\tconst { v } = await import('valleyed')\n\n\tconst testPipe = () =>\n\t\tv.object({\n\t\t\thost: v.string(),\n\t\t\tport: v.number(),\n\t\t})\n\n\ttype TestConfig = PipeOutput<ReturnType<typeof testPipe>>\n\n\tclass TestBase {\n\t\tbaseValue: string\n\t\tconstructor() {\n\t\t\tthis.baseValue = 'base'\n\t\t}\n\t}\n\n\tclass TestBaseWithArgs {\n\t\tlabel: string\n\t\tconstructor(label: string) {\n\t\t\tthis.label = label\n\t\t}\n\t}\n\n\tdescribe('configurable', () => {\n\t\ttest('validation runs in static create before constructor body executes', () => {\n\t\t\tlet constructorRan = false\n\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t\tconstructorRan = true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\texpect(() => MyClass.create({ host: 123, port: 'bad' } as any)).toThrow()\n\t\t\texpect(constructorRan).toBe(false)\n\n\t\t\tMyClass.create({ host: 'localhost', port: 3000 })\n\t\t\texpect(constructorRan).toBe(true)\n\t\t})\n\n\t\ttest('constructor receives validated value', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tlet receivedConfig: unknown\n\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t\treceivedConfig = this.config\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMyClass.create({ host: 'localhost', port: 3000 })\n\n\t\t\texpect(receivedConfig).toEqual({ host: 'localhost', port: 3000 })\n\t\t})\n\n\t\ttest('external new is a compile error', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// @ts-expect-error — external `new` on a class with protected constructor is a compile error\n\t\t\tvoid (() => new MyClass({ host: 'localhost', port: 3000 }))\n\t\t})\n\n\t\ttest('static Config resolves to PipeOutput<P> at the type level', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\texpectTypeOf<typeof MyClass.Config>().toEqualTypeOf<TestConfig>()\n\t\t\texpect(MyClass.create).toBeTypeOf('function')\n\t\t})\n\n\t\ttest('ConstructorParameters<This>-based extras inference works for non-zero-arg leaf signatures', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\textra: number\n\t\t\t\tprotected constructor(config: typeof MyClass.Config, extra: number) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t\tthis.extra = extra\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = MyClass.create({ host: 'localhost', port: 3000 }, 42)\n\n\t\t\texpect(instance.extra).toBe(42)\n\t\t\texpectTypeOf(instance).toHaveProperty('extra')\n\t\t\texpectTypeOf(instance.extra).toEqualTypeOf<number>()\n\n\t\t\t// @ts-expect-error — wrong extra type\n\t\t\tvoid (() => MyClass.create({ host: 'localhost', port: 3000 }, 'not-a-number'))\n\t\t})\n\n\t\ttest('base-args forwarding works for non-zero-arg bases', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBaseWithArgs)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config, label: string) {\n\t\t\t\t\tsuper(config, label)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = MyClass.create({ host: 'localhost', port: 3000 }, 'test-label')\n\n\t\t\texpect(instance.label).toBe('test-label')\n\t\t})\n\n\t\ttest('config is accessible as protected readonly on instances', () => {\n\t\t\tconst Wrapped = configurable(testPipe, TestBase)\n\t\t\tclass MyClass extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof MyClass.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\n\t\t\t\tgetHost() {\n\t\t\t\t\treturn this.config.host\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = MyClass.create({ host: 'localhost', port: 3000 })\n\t\t\texpect(instance.getHost()).toBe('localhost')\n\t\t})\n\n\t\ttest('accepts an abstract base class', () => {\n\t\t\tabstract class AbstractBase {\n\t\t\t\tabstract greet(): string\n\t\t\t}\n\n\t\t\tconst Wrapped = configurable(testPipe, AbstractBase)\n\t\t\tclass Concrete extends Wrapped {\n\t\t\t\tprotected constructor(config: typeof Concrete.Config) {\n\t\t\t\t\tsuper(config)\n\t\t\t\t}\n\t\t\t\tgreet() {\n\t\t\t\t\treturn `hello from ${this.config.host}`\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst instance = Concrete.create({ host: 'localhost', port: 3000 })\n\t\t\texpect(instance.greet()).toBe('hello from localhost')\n\t\t\texpectTypeOf(instance).toHaveProperty('config')\n\t\t})\n\t})\n}\n","export const parseJSONValue = (data: any) => {\n\ttry {\n\t\tif (data?.constructor?.name !== 'String') return data\n\t\treturn JSON.parse(data)\n\t} catch {\n\t\treturn data\n\t}\n}\n","import crypto from 'crypto'\n\nexport function string(length = 20) {\n\treturn crypto.randomBytes(length).toString('hex').slice(0, length)\n}\n\nexport function number(min = 0, max = 2 ** 48 - 1) {\n\treturn crypto.randomInt(min, max)\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,oBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAwB,0CACxBC,EAAkB,oBCDX,IAAMC,EAAN,cAA4B,KAAM,CACxC,YACiBC,EACAC,EACAC,EACf,CACD,MAAMF,EAAS,CAAE,MAAAE,CAAM,CAAC,EAJR,aAAAF,EACA,aAAAC,EACA,WAAAC,CAGjB,CACD,ECCO,IAAeC,EAAf,KAAwB,CAE/B,ECXA,IAAAC,EAAkC,qBAClCC,EAAqB,gBACrBC,EAA6B,oBCQtB,SAASC,EAAaC,EAAqBC,EAA0B,CAC3E,QAAWC,KAAOD,EAAO,MACxB,GAAI,CAACD,EAAM,KAAMG,GAAMA,EAAE,QAAUD,CAAG,EAAG,CACxC,IAAME,EAAUF,EAAI,MAAQ,UACtBG,EAAYJ,EAAO,OAAO,MAAQ,YACxC,MAAM,IAAI,MAAM,uBAAuBI,CAAS,qBAAqBD,CAAO,UAAUA,CAAO,oBAAoB,CAClH,CAGD,GAAIH,EAAO,MAAO,CACjB,IAAMK,EAAY,CAAC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afka_exports","__export","KafkaEventBus","kafkaConfigPipe","__toCommonJS","import_kafka_javascript","import_valleyed","EquippedError","message","context","cause","EventBus","import_pino","import_ulid","import_valleyed","registerHook","hooks","record","dep","h","depName","ownerName","tentative","detectCycle","classToAfter","existing","visited","stack","visit","cls","path","cycleStart","names","c","resolveHookDAG","invert","classToHooks","anonymous","list","classes","inDegree","graph","from","to","edges","layers","queue","layer","next","neighbor","d","anonWithDeps","anonWithoutDeps","maxLayer","depLayer","l","r","insertAt","runHooks","onError","error","import_valleyed","instanceSettingsPipe","Instance","_Instance","#id","#instance","#hooks","settings","pino","#registerOnExitHandler","id","EquippedError","name","key","runHooks","error","envsPipe","envValidity","settingsValidity","instanceSettingsPipe","event","cb","options","record","registerHook","signal","code","value","opts","import_valleyed","configurable","pipeFn","base","pipe","Configurable","config","baseArgs","input","args","r","parseJSONValue","data","random_exports","__export","number","string","import_crypto","length","crypto","min","max","kafkaConfigPipe","KafkaEventBus","_KafkaEventBus","configurable","EventBus","#client","#admin","config","#getAdmin","admin","#createTopic","topic","#deleteGroup","groupId","topicName","options","Instance","data","producer","onMessage","subscribe","random_exports","consumer","message","parseJSONValue","error","EquippedError"]}
|
|
@@ -40,7 +40,7 @@ var import_valleyed4 = require("valleyed");
|
|
|
40
40
|
// src/instance/index.ts
|
|
41
41
|
var import_pino = __toESM(require("pino"), 1);
|
|
42
42
|
var import_ulid = require("ulid");
|
|
43
|
-
var
|
|
43
|
+
var import_valleyed2 = require("valleyed");
|
|
44
44
|
|
|
45
45
|
// src/errors/equippedError.ts
|
|
46
46
|
var EquippedError = class extends Error {
|
|
@@ -56,170 +56,6 @@ var EquippedError = class extends Error {
|
|
|
56
56
|
var EventBus = class {
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
// src/utilities/configurable.ts
|
|
60
|
-
var import_valleyed = require("valleyed");
|
|
61
|
-
function configurable(pipeFn, base) {
|
|
62
|
-
const pipe = pipeFn();
|
|
63
|
-
import_valleyed.v.compile(pipe);
|
|
64
|
-
class Configurable extends base {
|
|
65
|
-
constructor(config, ...baseArgs) {
|
|
66
|
-
super(...baseArgs);
|
|
67
|
-
this.config = config;
|
|
68
|
-
}
|
|
69
|
-
static create(input, ...args) {
|
|
70
|
-
const r = import_valleyed.v.validate(pipe, input);
|
|
71
|
-
if (!r.valid) throw r.error;
|
|
72
|
-
return new this(r.value, ...args);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return Configurable;
|
|
76
|
-
}
|
|
77
|
-
if (void 0) {
|
|
78
|
-
const { describe, test, expect, expectTypeOf } = void 0;
|
|
79
|
-
const { v: v5 } = null;
|
|
80
|
-
const testPipe = () => v5.object({
|
|
81
|
-
host: v5.string(),
|
|
82
|
-
port: v5.number()
|
|
83
|
-
});
|
|
84
|
-
class TestBase {
|
|
85
|
-
baseValue;
|
|
86
|
-
constructor() {
|
|
87
|
-
this.baseValue = "base";
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
class TestBaseWithArgs {
|
|
91
|
-
label;
|
|
92
|
-
constructor(label) {
|
|
93
|
-
this.label = label;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
describe("configurable", () => {
|
|
97
|
-
test("validation runs in static create before constructor body executes", () => {
|
|
98
|
-
let constructorRan = false;
|
|
99
|
-
const Wrapped = configurable(testPipe, TestBase);
|
|
100
|
-
class MyClass extends Wrapped {
|
|
101
|
-
constructor(config) {
|
|
102
|
-
super(config);
|
|
103
|
-
constructorRan = true;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
expect(() => MyClass.create({ host: 123, port: "bad" })).toThrow();
|
|
107
|
-
expect(constructorRan).toBe(false);
|
|
108
|
-
MyClass.create({ host: "localhost", port: 3e3 });
|
|
109
|
-
expect(constructorRan).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
test("constructor receives validated value", () => {
|
|
112
|
-
const Wrapped = configurable(testPipe, TestBase);
|
|
113
|
-
let receivedConfig;
|
|
114
|
-
class MyClass extends Wrapped {
|
|
115
|
-
constructor(config) {
|
|
116
|
-
super(config);
|
|
117
|
-
receivedConfig = this.config;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
MyClass.create({ host: "localhost", port: 3e3 });
|
|
121
|
-
expect(receivedConfig).toEqual({ host: "localhost", port: 3e3 });
|
|
122
|
-
});
|
|
123
|
-
test("external new is a compile error", () => {
|
|
124
|
-
const Wrapped = configurable(testPipe, TestBase);
|
|
125
|
-
class MyClass extends Wrapped {
|
|
126
|
-
constructor(config) {
|
|
127
|
-
super(config);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
void (() => new MyClass({ host: "localhost", port: 3e3 }));
|
|
131
|
-
});
|
|
132
|
-
test("static Config resolves to PipeOutput<P> at the type level", () => {
|
|
133
|
-
const Wrapped = configurable(testPipe, TestBase);
|
|
134
|
-
class MyClass extends Wrapped {
|
|
135
|
-
constructor(config) {
|
|
136
|
-
super(config);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
expectTypeOf().toEqualTypeOf();
|
|
140
|
-
expect(MyClass.create).toBeTypeOf("function");
|
|
141
|
-
});
|
|
142
|
-
test("ConstructorParameters<This>-based extras inference works for non-zero-arg leaf signatures", () => {
|
|
143
|
-
const Wrapped = configurable(testPipe, TestBase);
|
|
144
|
-
class MyClass extends Wrapped {
|
|
145
|
-
extra;
|
|
146
|
-
constructor(config, extra) {
|
|
147
|
-
super(config);
|
|
148
|
-
this.extra = extra;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const instance = MyClass.create({ host: "localhost", port: 3e3 }, 42);
|
|
152
|
-
expect(instance.extra).toBe(42);
|
|
153
|
-
expectTypeOf(instance).toHaveProperty("extra");
|
|
154
|
-
expectTypeOf(instance.extra).toEqualTypeOf();
|
|
155
|
-
void (() => MyClass.create({ host: "localhost", port: 3e3 }, "not-a-number"));
|
|
156
|
-
});
|
|
157
|
-
test("base-args forwarding works for non-zero-arg bases", () => {
|
|
158
|
-
const Wrapped = configurable(testPipe, TestBaseWithArgs);
|
|
159
|
-
class MyClass extends Wrapped {
|
|
160
|
-
constructor(config, label) {
|
|
161
|
-
super(config, label);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const instance = MyClass.create({ host: "localhost", port: 3e3 }, "test-label");
|
|
165
|
-
expect(instance.label).toBe("test-label");
|
|
166
|
-
});
|
|
167
|
-
test("config is accessible as protected readonly on instances", () => {
|
|
168
|
-
const Wrapped = configurable(testPipe, TestBase);
|
|
169
|
-
class MyClass extends Wrapped {
|
|
170
|
-
constructor(config) {
|
|
171
|
-
super(config);
|
|
172
|
-
}
|
|
173
|
-
getHost() {
|
|
174
|
-
return this.config.host;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
const instance = MyClass.create({ host: "localhost", port: 3e3 });
|
|
178
|
-
expect(instance.getHost()).toBe("localhost");
|
|
179
|
-
});
|
|
180
|
-
test("accepts an abstract base class", () => {
|
|
181
|
-
class AbstractBase {
|
|
182
|
-
}
|
|
183
|
-
const Wrapped = configurable(testPipe, AbstractBase);
|
|
184
|
-
class Concrete extends Wrapped {
|
|
185
|
-
constructor(config) {
|
|
186
|
-
super(config);
|
|
187
|
-
}
|
|
188
|
-
greet() {
|
|
189
|
-
return `hello from ${this.config.host}`;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const instance = Concrete.create({ host: "localhost", port: 3e3 });
|
|
193
|
-
expect(instance.greet()).toBe("hello from localhost");
|
|
194
|
-
expectTypeOf(instance).toHaveProperty("config");
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// src/utilities/json.ts
|
|
200
|
-
var parseJSONValue = (data) => {
|
|
201
|
-
try {
|
|
202
|
-
if (data?.constructor?.name !== "String") return data;
|
|
203
|
-
return JSON.parse(data);
|
|
204
|
-
} catch {
|
|
205
|
-
return data;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// src/utilities/random.ts
|
|
210
|
-
var random_exports = {};
|
|
211
|
-
__export(random_exports, {
|
|
212
|
-
number: () => number,
|
|
213
|
-
string: () => string
|
|
214
|
-
});
|
|
215
|
-
var import_crypto = __toESM(require("crypto"), 1);
|
|
216
|
-
function string(length = 20) {
|
|
217
|
-
return import_crypto.default.randomBytes(length).toString("hex").slice(0, length);
|
|
218
|
-
}
|
|
219
|
-
function number(min = 0, max = 2 ** 48 - 1) {
|
|
220
|
-
return import_crypto.default.randomInt(min, max);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
59
|
// src/instance/hooks.ts
|
|
224
60
|
function registerHook(hooks, record) {
|
|
225
61
|
for (const dep of record.after) {
|
|
@@ -622,22 +458,22 @@ if (void 0) {
|
|
|
622
458
|
}
|
|
623
459
|
|
|
624
460
|
// src/instance/settings.ts
|
|
625
|
-
var
|
|
626
|
-
var instanceSettingsPipe = () =>
|
|
627
|
-
app:
|
|
628
|
-
name:
|
|
461
|
+
var import_valleyed = require("valleyed");
|
|
462
|
+
var instanceSettingsPipe = () => import_valleyed.v.object({
|
|
463
|
+
app: import_valleyed.v.object({
|
|
464
|
+
name: import_valleyed.v.string()
|
|
629
465
|
}),
|
|
630
|
-
log:
|
|
631
|
-
|
|
632
|
-
level:
|
|
466
|
+
log: import_valleyed.v.defaults(
|
|
467
|
+
import_valleyed.v.object({
|
|
468
|
+
level: import_valleyed.v.defaults(import_valleyed.v.in(["fatal", "error", "warn", "info", "debug", "trace", "silent"]), "info")
|
|
633
469
|
}),
|
|
634
470
|
{}
|
|
635
471
|
),
|
|
636
|
-
utils:
|
|
637
|
-
|
|
638
|
-
hashSaltRounds:
|
|
639
|
-
paginationDefaultLimit:
|
|
640
|
-
maxFileUploadSizeInMb:
|
|
472
|
+
utils: import_valleyed.v.defaults(
|
|
473
|
+
import_valleyed.v.object({
|
|
474
|
+
hashSaltRounds: import_valleyed.v.defaults(import_valleyed.v.number(), 10),
|
|
475
|
+
paginationDefaultLimit: import_valleyed.v.defaults(import_valleyed.v.number(), 100),
|
|
476
|
+
maxFileUploadSizeInMb: import_valleyed.v.defaults(import_valleyed.v.number(), 500)
|
|
641
477
|
}),
|
|
642
478
|
{}
|
|
643
479
|
)
|
|
@@ -687,7 +523,7 @@ var Instance = class _Instance {
|
|
|
687
523
|
}
|
|
688
524
|
}
|
|
689
525
|
static envs(envsPipe) {
|
|
690
|
-
const envValidity =
|
|
526
|
+
const envValidity = import_valleyed2.v.validate(envsPipe, process.env);
|
|
691
527
|
if (!envValidity.valid) {
|
|
692
528
|
_Instance.crash(
|
|
693
529
|
new EquippedError(`Environment variables are not valid
|
|
@@ -700,7 +536,7 @@ ${envValidity.error.toString()}`, {
|
|
|
700
536
|
}
|
|
701
537
|
static create(settings) {
|
|
702
538
|
if (_Instance.#instance) return _Instance.crash(new EquippedError("Instance has been initialized already", {}));
|
|
703
|
-
const settingsValidity =
|
|
539
|
+
const settingsValidity = import_valleyed2.v.validate(instanceSettingsPipe(), settings);
|
|
704
540
|
if (!settingsValidity.valid) {
|
|
705
541
|
_Instance.crash(
|
|
706
542
|
new EquippedError(`Settings are not valid
|
|
@@ -754,6 +590,170 @@ ${settingsValidity.error.toString()}`, {
|
|
|
754
590
|
}
|
|
755
591
|
};
|
|
756
592
|
|
|
593
|
+
// src/utilities/configurable.ts
|
|
594
|
+
var import_valleyed3 = require("valleyed");
|
|
595
|
+
function configurable(pipeFn, base) {
|
|
596
|
+
const pipe = pipeFn();
|
|
597
|
+
import_valleyed3.v.compile(pipe);
|
|
598
|
+
class Configurable extends base {
|
|
599
|
+
constructor(config, ...baseArgs) {
|
|
600
|
+
super(...baseArgs);
|
|
601
|
+
this.config = config;
|
|
602
|
+
}
|
|
603
|
+
static create(input, ...args) {
|
|
604
|
+
const r = import_valleyed3.v.validate(pipe, input);
|
|
605
|
+
if (!r.valid) throw r.error;
|
|
606
|
+
return new this(r.value, ...args);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return Configurable;
|
|
610
|
+
}
|
|
611
|
+
if (void 0) {
|
|
612
|
+
const { describe, test, expect, expectTypeOf } = void 0;
|
|
613
|
+
const { v: v5 } = null;
|
|
614
|
+
const testPipe = () => v5.object({
|
|
615
|
+
host: v5.string(),
|
|
616
|
+
port: v5.number()
|
|
617
|
+
});
|
|
618
|
+
class TestBase {
|
|
619
|
+
baseValue;
|
|
620
|
+
constructor() {
|
|
621
|
+
this.baseValue = "base";
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
class TestBaseWithArgs {
|
|
625
|
+
label;
|
|
626
|
+
constructor(label) {
|
|
627
|
+
this.label = label;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
describe("configurable", () => {
|
|
631
|
+
test("validation runs in static create before constructor body executes", () => {
|
|
632
|
+
let constructorRan = false;
|
|
633
|
+
const Wrapped = configurable(testPipe, TestBase);
|
|
634
|
+
class MyClass extends Wrapped {
|
|
635
|
+
constructor(config) {
|
|
636
|
+
super(config);
|
|
637
|
+
constructorRan = true;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
expect(() => MyClass.create({ host: 123, port: "bad" })).toThrow();
|
|
641
|
+
expect(constructorRan).toBe(false);
|
|
642
|
+
MyClass.create({ host: "localhost", port: 3e3 });
|
|
643
|
+
expect(constructorRan).toBe(true);
|
|
644
|
+
});
|
|
645
|
+
test("constructor receives validated value", () => {
|
|
646
|
+
const Wrapped = configurable(testPipe, TestBase);
|
|
647
|
+
let receivedConfig;
|
|
648
|
+
class MyClass extends Wrapped {
|
|
649
|
+
constructor(config) {
|
|
650
|
+
super(config);
|
|
651
|
+
receivedConfig = this.config;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
MyClass.create({ host: "localhost", port: 3e3 });
|
|
655
|
+
expect(receivedConfig).toEqual({ host: "localhost", port: 3e3 });
|
|
656
|
+
});
|
|
657
|
+
test("external new is a compile error", () => {
|
|
658
|
+
const Wrapped = configurable(testPipe, TestBase);
|
|
659
|
+
class MyClass extends Wrapped {
|
|
660
|
+
constructor(config) {
|
|
661
|
+
super(config);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
void (() => new MyClass({ host: "localhost", port: 3e3 }));
|
|
665
|
+
});
|
|
666
|
+
test("static Config resolves to PipeOutput<P> at the type level", () => {
|
|
667
|
+
const Wrapped = configurable(testPipe, TestBase);
|
|
668
|
+
class MyClass extends Wrapped {
|
|
669
|
+
constructor(config) {
|
|
670
|
+
super(config);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
expectTypeOf().toEqualTypeOf();
|
|
674
|
+
expect(MyClass.create).toBeTypeOf("function");
|
|
675
|
+
});
|
|
676
|
+
test("ConstructorParameters<This>-based extras inference works for non-zero-arg leaf signatures", () => {
|
|
677
|
+
const Wrapped = configurable(testPipe, TestBase);
|
|
678
|
+
class MyClass extends Wrapped {
|
|
679
|
+
extra;
|
|
680
|
+
constructor(config, extra) {
|
|
681
|
+
super(config);
|
|
682
|
+
this.extra = extra;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const instance = MyClass.create({ host: "localhost", port: 3e3 }, 42);
|
|
686
|
+
expect(instance.extra).toBe(42);
|
|
687
|
+
expectTypeOf(instance).toHaveProperty("extra");
|
|
688
|
+
expectTypeOf(instance.extra).toEqualTypeOf();
|
|
689
|
+
void (() => MyClass.create({ host: "localhost", port: 3e3 }, "not-a-number"));
|
|
690
|
+
});
|
|
691
|
+
test("base-args forwarding works for non-zero-arg bases", () => {
|
|
692
|
+
const Wrapped = configurable(testPipe, TestBaseWithArgs);
|
|
693
|
+
class MyClass extends Wrapped {
|
|
694
|
+
constructor(config, label) {
|
|
695
|
+
super(config, label);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
const instance = MyClass.create({ host: "localhost", port: 3e3 }, "test-label");
|
|
699
|
+
expect(instance.label).toBe("test-label");
|
|
700
|
+
});
|
|
701
|
+
test("config is accessible as protected readonly on instances", () => {
|
|
702
|
+
const Wrapped = configurable(testPipe, TestBase);
|
|
703
|
+
class MyClass extends Wrapped {
|
|
704
|
+
constructor(config) {
|
|
705
|
+
super(config);
|
|
706
|
+
}
|
|
707
|
+
getHost() {
|
|
708
|
+
return this.config.host;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const instance = MyClass.create({ host: "localhost", port: 3e3 });
|
|
712
|
+
expect(instance.getHost()).toBe("localhost");
|
|
713
|
+
});
|
|
714
|
+
test("accepts an abstract base class", () => {
|
|
715
|
+
class AbstractBase {
|
|
716
|
+
}
|
|
717
|
+
const Wrapped = configurable(testPipe, AbstractBase);
|
|
718
|
+
class Concrete extends Wrapped {
|
|
719
|
+
constructor(config) {
|
|
720
|
+
super(config);
|
|
721
|
+
}
|
|
722
|
+
greet() {
|
|
723
|
+
return `hello from ${this.config.host}`;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const instance = Concrete.create({ host: "localhost", port: 3e3 });
|
|
727
|
+
expect(instance.greet()).toBe("hello from localhost");
|
|
728
|
+
expectTypeOf(instance).toHaveProperty("config");
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/utilities/json.ts
|
|
734
|
+
var parseJSONValue = (data) => {
|
|
735
|
+
try {
|
|
736
|
+
if (data?.constructor?.name !== "String") return data;
|
|
737
|
+
return JSON.parse(data);
|
|
738
|
+
} catch {
|
|
739
|
+
return data;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// src/utilities/random.ts
|
|
744
|
+
var random_exports = {};
|
|
745
|
+
__export(random_exports, {
|
|
746
|
+
number: () => number,
|
|
747
|
+
string: () => string
|
|
748
|
+
});
|
|
749
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
750
|
+
function string(length = 20) {
|
|
751
|
+
return import_crypto.default.randomBytes(length).toString("hex").slice(0, length);
|
|
752
|
+
}
|
|
753
|
+
function number(min = 0, max = 2 ** 48 - 1) {
|
|
754
|
+
return import_crypto.default.randomInt(min, max);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
757
|
// src/events/adapters/rabbitmq/index.ts
|
|
758
758
|
var rabbitmqConfigPipe = () => import_valleyed4.v.meta(
|
|
759
759
|
import_valleyed4.v.object({
|