@venizia/ignis-kernel 0.5.0-2 → 0.5.0-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/base/applications/boot-sequence.d.ts +2 -3
- package/dist/esm/base/applications/boot-sequence.js +2 -17
- package/dist/esm/base/applications/boot-sequence.js.map +1 -1
- package/dist/esm/base/applications/common/constants.d.ts +3 -6
- package/dist/esm/base/applications/common/constants.js +3 -17
- package/dist/esm/base/applications/common/constants.js.map +1 -1
- package/dist/esm/base/applications/rest.js +3 -3
- package/dist/esm/base/applications/rest.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/constants/authentication.d.ts +3 -7
- package/dist/esm/base/auth/authenticate/common/constants/authentication.js +3 -11
- package/dist/esm/base/auth/authenticate/common/constants/authentication.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/constants/jose.d.ts +6 -15
- package/dist/esm/base/auth/authenticate/common/constants/jose.js +6 -25
- package/dist/esm/base/auth/authenticate/common/constants/jose.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/authorization.d.ts +4 -9
- package/dist/esm/base/auth/authorize/common/constants/authorization.js +4 -15
- package/dist/esm/base/auth/authorize/common/constants/authorization.js.map +1 -1
- package/dist/esm/base/auth/authorize/common/constants/enforcer.d.ts +5 -12
- package/dist/esm/base/auth/authorize/common/constants/enforcer.js +5 -26
- package/dist/esm/base/auth/authorize/common/constants/enforcer.js.map +1 -1
- package/dist/esm/base/controllers/common/constants.d.ts +3 -6
- package/dist/esm/base/controllers/common/constants.js +3 -11
- package/dist/esm/base/controllers/common/constants.js.map +1 -1
- package/dist/esm/base/controllers/factory/controller.js +1 -1
- package/dist/esm/base/controllers/factory/controller.js.map +1 -1
- package/dist/esm/base/datasources/common/types.d.ts +2 -3
- package/dist/esm/base/datasources/common/types.js +2 -5
- package/dist/esm/base/datasources/common/types.js.map +1 -1
- package/dist/esm/base/events/common/constants.d.ts +3 -4
- package/dist/esm/base/events/common/constants.js +3 -6
- package/dist/esm/base/events/common/constants.js.map +1 -1
- package/dist/esm/base/events/event-bus.d.ts +2 -2
- package/dist/esm/base/events/event-bus.js +6 -6
- package/dist/esm/base/events/event-bus.js.map +1 -1
- package/dist/esm/base/metadata/injectable.js +1 -1
- package/dist/esm/base/metadata/injectable.js.map +1 -1
- package/dist/esm/base/metadata/model-metadata.js +1 -1
- package/dist/esm/base/metadata/model-metadata.js.map +1 -1
- package/dist/esm/base/metadata/persistents/datasource.js +1 -1
- package/dist/esm/base/metadata/persistents/datasource.js.map +1 -1
- package/dist/esm/base/metadata/persistents/repository/validate.js +1 -1
- package/dist/esm/base/metadata/persistents/repository/validate.js.map +1 -1
- package/dist/esm/base/models/common/constants.d.ts +5 -11
- package/dist/esm/base/models/common/constants.js +5 -23
- package/dist/esm/base/models/common/constants.js.map +1 -1
- package/dist/esm/base/repositories/common/constants.d.ts +7 -18
- package/dist/esm/base/repositories/common/constants.js +7 -35
- package/dist/esm/base/repositories/common/constants.js.map +1 -1
- package/dist/esm/base/repositories/core/abstract.js +2 -2
- package/dist/esm/base/repositories/core/abstract.js.map +1 -1
- package/dist/esm/common/statuses/user.d.ts +2 -3
- package/dist/esm/common/statuses/user.js +2 -5
- package/dist/esm/common/statuses/user.js.map +1 -1
- package/dist/esm/helpers/inversion/common/constants.d.ts +3 -6
- package/dist/esm/helpers/inversion/common/constants.js +3 -18
- package/dist/esm/helpers/inversion/common/constants.js.map +1 -1
- package/dist/esm/helpers/inversion/common/types/model.d.ts +1 -1
- package/dist/esm/helpers/inversion/common/types/model.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/** Names of the supported datasource drivers, split into relational and search sets. `isValid` checks a value against all of them. */
|
|
2
3
|
export class DataSourceDrivers {
|
|
3
4
|
// Relational - PGlite is a Postgres DRIVER (Postgres compiled to WASM), not a separate engine.
|
|
@@ -30,13 +31,9 @@ export class DataSourceDrivers {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
/** When a datasource opens: with the application (`start`, the default) or at the first call that needs it (`first-use`). */
|
|
33
|
-
export class DataSourceOpenModes {
|
|
34
|
+
export class DataSourceOpenModes extends ConstClass {
|
|
34
35
|
static { this.START = 'start'; }
|
|
35
36
|
static { this.FIRST_USE = 'first-use'; }
|
|
36
|
-
static { this.SCHEME_SET = new Set([this.START, this.FIRST_USE]); }
|
|
37
|
-
static isValid(value) {
|
|
38
|
-
return this.SCHEME_SET.has(value);
|
|
39
|
-
}
|
|
40
37
|
}
|
|
41
38
|
/** Defaults of the `open` option. */
|
|
42
39
|
export class DataSourceOpenDefaults {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/base/datasources/common/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/base/datasources/common/types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,sIAAsI;AACtI,MAAM,OAAO,iBAAiB;IAC5B,+FAA+F;aAC/E,kBAAa,GAAG,eAAe,CAAC;aAChC,gBAAW,GAAG,aAAa,CAAC;aAC5B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;IAElC,SAAS;aACO,cAAS,GAAG,WAAW,CAAC;aACxB,gBAAW,GAAG,aAAa,CAAC;aAE5B,0BAAqB,GAAG,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,aAAa;QAClB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;aAEa,sBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;aAEhE,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,aAAa;QACb,IAAI,CAAC,aAAa;QAClB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QAEX,SAAS;QACT,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAGH,6HAA6H;AAC7H,MAAM,OAAO,mBAAoB,SAAQ,UAAU;aACjC,UAAK,GAAG,OAAO,CAAC;aAChB,cAAS,GAAG,WAAW,CAAC;;AAG1C,qCAAqC;AACrC,MAAM,OAAO,sBAAsB;IACjC,qKAAqK;aACrJ,eAAU,GAAG,MAAM,CAAC","sourcesContent":["import type {\n IConfigurable,\n TClass,\n TConstValue,\n ValueOrPromise,\n} from '@venizia/ignis-helpers/common';\nimport { ConstClass } from '@venizia/ignis-helpers/common';\n\n/** Names of the supported datasource drivers, split into relational and search sets. `isValid` checks a value against all of them. */\nexport class DataSourceDrivers {\n // Relational - PGlite is a Postgres DRIVER (Postgres compiled to WASM), not a separate engine.\n static readonly NODE_POSTGRES = 'node-postgres';\n static readonly POSTGRES_JS = 'postgres-js';\n static readonly PGLITE = 'pglite';\n static readonly LIBSQL = 'libsql';\n\n // Search\n static readonly TYPESENSE = 'typesense';\n static readonly MEILISEARCH = 'meilisearch';\n\n static readonly RELATIONAL_SCHEME_SET = new Set([\n this.NODE_POSTGRES,\n this.POSTGRES_JS,\n this.PGLITE,\n this.LIBSQL,\n ]);\n\n static readonly SEARCH_SCHEME_SET = new Set([this.TYPESENSE, this.MEILISEARCH]);\n\n static readonly SCHEME_SET = new Set([\n // Relational\n this.NODE_POSTGRES,\n this.POSTGRES_JS,\n this.PGLITE,\n this.LIBSQL,\n\n // Search\n this.TYPESENSE,\n this.MEILISEARCH,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** When a datasource opens: with the application (`start`, the default) or at the first call that needs it (`first-use`). */\nexport class DataSourceOpenModes extends ConstClass {\n static readonly START = 'start';\n static readonly FIRST_USE = 'first-use';\n}\n\n/** Defaults of the `open` option. */\nexport class DataSourceOpenDefaults {\n /** How long a first use waits for the open before it gives up (ms): a WASM boot on a slow link fits, a `configure()` that waits on itself does not hang for ever. */\n static readonly TIMEOUT_MS = 60_000;\n}\n\n/** One of the {@link DataSourceOpenModes} values. */\nexport type TDataSourceOpenMode = TConstValue<typeof DataSourceOpenModes>;\n\n/** The `open` option of `@datasource`. */\nexport interface IDataSourceOpenOptions {\n /**\n * `start`: `configure()` runs when the application starts, and `listen()` waits for it. `first-use`: the application\n * starts without opening the datasource; the first call that needs it runs `configure()` once, and every call that\n * arrives meanwhile waits for that one open. A failed open rejects every waiting call, leaves nothing half-open, and is\n * tried again by the next call.\n *\n * @default 'start'\n */\n on?: TDataSourceOpenMode;\n\n /**\n * `first-use` only: how long the open may take (ms) before every waiting call is rejected with a named error and the\n * attempt is abandoned. An abandoned `configure()` that finishes later is closed and never published, and the next call\n * waits until it has settled before trying again. `0` waits for ever.\n *\n * @default 60000\n */\n timeoutMs?: number;\n}\n\n/**\n * What `configure()` is given to do its database work while the datasource is opening: the connector, the client and a\n * transaction, through the datasource's own ungated internals. Only `configure()` receives it, so nothing outside can use it\n * and every other caller still waits for the open to finish. Generic over the datasource's connector, client and\n * transaction types, so `opening.getClient()` of a PGlite datasource is a `PGlite`.\n *\n * Inside the open of a datasource that opens on first use, the public `getConnector()`, `getClient()` and\n * `beginTransaction()` are gated (they wait for the open, which waits for `configure()`), and a repository cannot be used:\n * use these handles instead.\n */\nexport interface IDataSourceOpening<\n TConnector = unknown,\n Client = unknown,\n TTransaction extends ITransaction = ITransaction,\n TTransactionOptions extends ITransactionOptions = ITransactionOptions,\n> {\n getConnector(): TConnector;\n getClient(): Client;\n beginTransaction(opts?: TTransactionOptions): Promise<TTransaction>;\n}\n\n// `(string & {})` keeps autocomplete for the known values\n// while still accepting any other engine-driver string.\n/** A driver name: one of `DataSourceDrivers`, or any other string for an unlisted engine. */\nexport type TDataSourceDriver = TConstValue<typeof DataSourceDrivers> | (string & {});\n\n/**\n * A driver CLASS, named by `@datasource({ driver })`. The class reference is what pulls the peer\n * package into a bundle - a name string pulls nothing, and a bare side-effect import may be\n * dropped. Untyped because `IRelationalDriver` lives under `connectors/`, off-limits to `base/`.\n */\nexport type TDataSourceDriverClass = TClass<unknown>;\n\n/** Loose schema record of a datasource; the default `Schema` type argument of `IDataSource`. */\nexport type TAnyDataSourceSchema = Record<string, any>;\n\n/** Engine-neutral datasource contract - the root every connector family implements. */\nexport interface IDataSource<\n Settings extends object = {},\n Schema extends TAnyDataSourceSchema = TAnyDataSourceSchema,\n ConfigurableOptions extends object = {},\n> extends IConfigurable<ConfigurableOptions> {\n name: string;\n settings: Settings;\n schema: Schema;\n\n getSettings(): Settings;\n getSchema(): Schema;\n\n /** Releases what `configure()` opened. `stop()` calls it on every datasource the boot configured. */\n close?(): Promise<void>;\n\n /** The datasource's own `configure()` receives the handles of {@link IDataSourceOpening} as its second argument. */\n configure(opts?: ConfigurableOptions, opening?: IDataSourceOpening): ValueOrPromise<void>;\n\n /** True when the datasource opens on first use (`@datasource({ open: { on: 'first-use' } })`): the boot then calls {@link deferOpen} instead of `configure()`. */\n isOpenDeferred?(): boolean;\n\n /** Records the options `configure()` will get when the datasource opens on first use; nothing is opened. */\n deferOpen?(opts: { options?: ConfigurableOptions }): void;\n\n /** Resolves once the datasource is open: at once when it opens with the application or is already open, else after the one open that the first use starts. */\n ensureOpen?(): Promise<void>;\n}\n\n/**\n * Neutral transaction options - isolation levels are engine vocabulary, so `isolationLevel` stays\n * a loose string here and connectors narrow it in their own `ITransactionOptions` extension.\n */\nexport interface ITransactionOptions {\n isolationLevel?: string;\n}\n\n/** Neutral transaction handle - the minimum shape every connector's transaction satisfies. */\nexport interface ITransaction {\n isActive: boolean;\n commit(): Promise<void>;\n rollback(): Promise<void>;\n}\n\n/** What a datasource supports. `transactions` tells whether it can open transactions. */\nexport interface IDataSourceCapabilities {\n transactions: boolean;\n}\n\n/** Capabilities of a search datasource. Each `search` flag tells whether the engine supports that feature. */\nexport interface ISearchableDataSourceCapabilities extends IDataSourceCapabilities {\n search?: {\n /** Vector / semantic / hybrid search (search engines). */\n vector?: boolean;\n\n /** Batched multi-query search across collections. */\n multi?: boolean;\n\n /** Merged (union) result set across a multi-search. */\n union?: boolean;\n\n /** Synonym sets (multi-way / one-way). */\n synonyms?: boolean;\n };\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
3
|
/** Defaults and ceilings of event dispatch retry: the `*_CEILING` and `*_WINDOW_MS` values cap what `register` may ask for. */
|
|
3
4
|
export declare class EventDispatchRetry {
|
|
4
5
|
/** Attempts per dispatch when `register` gives no `retry.maxAttempts`. */
|
|
@@ -15,7 +16,7 @@ export declare class EventDispatchRetry {
|
|
|
15
16
|
/**
|
|
16
17
|
* Ceiling, in ms, on the total backoff window `register`'s `retry` can produce (the sum of every
|
|
17
18
|
* inter-attempt delay, computed without jitter since jitter only shrinks it). Matches
|
|
18
|
-
* `
|
|
19
|
+
* `RetryUtility`'s own default cap on a SINGLE delay: a dispatch holds a handler's resources - e.g.
|
|
19
20
|
* a database connection - for its entire retry window, so the sum across every attempt gets the
|
|
20
21
|
* same "unreasonable beyond this" line the framework already draws for one attempt.
|
|
21
22
|
*/
|
|
@@ -28,13 +29,11 @@ export declare class EventDispatchRetry {
|
|
|
28
29
|
* error there rather than a runtime surprise later, inside a `queueMicrotask` where nobody is
|
|
29
30
|
* watching.
|
|
30
31
|
*/
|
|
31
|
-
export declare class EventHandlerTypes {
|
|
32
|
+
export declare class EventHandlerTypes extends ConstClass {
|
|
32
33
|
/** `handler.key` is resolved from the container on every retry attempt - a rebind reaches an attempt already in flight. */
|
|
33
34
|
static readonly BINDING_KEY = "binding-key";
|
|
34
35
|
/** `handler.fn` is invoked directly as a captured closure - there is nothing to rebind, so every attempt in a retry window calls the exact function registered here. */
|
|
35
36
|
static readonly FUNCTION = "function";
|
|
36
|
-
static readonly SCHEME_SET: Set<string>;
|
|
37
|
-
static isValid(value: string): value is TEventHandlerType;
|
|
38
37
|
}
|
|
39
38
|
/** Union of the `EventHandlerTypes` values. */
|
|
40
39
|
export type TEventHandlerType = TConstValue<typeof EventHandlerTypes>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/** Defaults and ceilings of event dispatch retry: the `*_CEILING` and `*_WINDOW_MS` values cap what `register` may ask for. */
|
|
2
3
|
export class EventDispatchRetry {
|
|
3
4
|
/** Attempts per dispatch when `register` gives no `retry.maxAttempts`. */
|
|
@@ -14,7 +15,7 @@ export class EventDispatchRetry {
|
|
|
14
15
|
/**
|
|
15
16
|
* Ceiling, in ms, on the total backoff window `register`'s `retry` can produce (the sum of every
|
|
16
17
|
* inter-attempt delay, computed without jitter since jitter only shrinks it). Matches
|
|
17
|
-
* `
|
|
18
|
+
* `RetryUtility`'s own default cap on a SINGLE delay: a dispatch holds a handler's resources - e.g.
|
|
18
19
|
* a database connection - for its entire retry window, so the sum across every attempt gets the
|
|
19
20
|
* same "unreasonable beyond this" line the framework already draws for one attempt.
|
|
20
21
|
*/
|
|
@@ -27,14 +28,10 @@ export class EventDispatchRetry {
|
|
|
27
28
|
* error there rather than a runtime surprise later, inside a `queueMicrotask` where nobody is
|
|
28
29
|
* watching.
|
|
29
30
|
*/
|
|
30
|
-
export class EventHandlerTypes {
|
|
31
|
+
export class EventHandlerTypes extends ConstClass {
|
|
31
32
|
/** `handler.key` is resolved from the container on every retry attempt - a rebind reaches an attempt already in flight. */
|
|
32
33
|
static { this.BINDING_KEY = 'binding-key'; }
|
|
33
34
|
/** `handler.fn` is invoked directly as a captured closure - there is nothing to rebind, so every attempt in a retry window calls the exact function registered here. */
|
|
34
35
|
static { this.FUNCTION = 'function'; }
|
|
35
|
-
static { this.SCHEME_SET = new Set([this.BINDING_KEY, this.FUNCTION]); }
|
|
36
|
-
static isValid(value) {
|
|
37
|
-
return this.SCHEME_SET.has(value);
|
|
38
|
-
}
|
|
39
36
|
}
|
|
40
37
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/events/common/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/events/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,+HAA+H;AAC/H,MAAM,OAAO,kBAAkB;IAC7B,0EAA0E;aAC1D,iBAAY,GAAG,CAAC,CAAC;IAEjC,8EAA8E;aAC9D,kBAAa,GAAG,GAAG,CAAC;IAEpC;;;;;OAKG;aACa,yBAAoB,GAAG,EAAE,CAAC;IAE1C;;;;;;OAMG;aACa,wBAAmB,GAAG,MAAM,CAAC;;AAG/C;;;;;;GAMG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC/C,2HAA2H;aAC3G,gBAAW,GAAG,aAAa,CAAC;IAE5C,wKAAwK;aACxJ,aAAQ,GAAG,UAAU,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { ConstClass } from '@venizia/ignis-helpers/common';\n\n/** Defaults and ceilings of event dispatch retry: the `*_CEILING` and `*_WINDOW_MS` values cap what `register` may ask for. */\nexport class EventDispatchRetry {\n /** Attempts per dispatch when `register` gives no `retry.maxAttempts`. */\n static readonly MAX_ATTEMPTS = 3;\n\n /** First backoff delay in ms when `register` gives no `retry.baseDelayMs`. */\n static readonly BASE_DELAY_MS = 100;\n\n /**\n * Ceiling on `register`'s `retry.maxAttempts`. Dispatch is fire-and-forget - nobody awaits it - so\n * an attempt count high enough to matter is already high enough to hammer a struggling downstream\n * resource attempt after attempt. Twice the highest count any known consumer has asked for (5)\n * leaves room to tune without permitting an attempt storm.\n */\n static readonly MAX_ATTEMPTS_CEILING = 10;\n\n /**\n * Ceiling, in ms, on the total backoff window `register`'s `retry` can produce (the sum of every\n * inter-attempt delay, computed without jitter since jitter only shrinks it). Matches\n * `RetryUtility`'s own default cap on a SINGLE delay: a dispatch holds a handler's resources - e.g.\n * a database connection - for its entire retry window, so the sum across every attempt gets the\n * same \"unreasonable beyond this\" line the framework already draws for one attempt.\n */\n static readonly MAX_TOTAL_WINDOW_MS = 30_000;\n}\n\n/**\n * Tag for `EventBus.register`'s `handler` union (`TEventHandlerReference`). The tag makes the\n * caller's choice explicit at the call site instead of implicit in whichever field is present, so a\n * mismatched `type`/field pair (`BINDING_KEY` with `fn`, or `FUNCTION` with `key`) is a compile\n * error there rather than a runtime surprise later, inside a `queueMicrotask` where nobody is\n * watching.\n */\nexport class EventHandlerTypes extends ConstClass {\n /** `handler.key` is resolved from the container on every retry attempt - a rebind reaches an attempt already in flight. */\n static readonly BINDING_KEY = 'binding-key';\n\n /** `handler.fn` is invoked directly as a captured closure - there is nothing to rebind, so every attempt in a retry window calls the exact function registered here. */\n static readonly FUNCTION = 'function';\n}\n\n/** Union of the `EventHandlerTypes` values. */\nexport type TEventHandlerType = TConstValue<typeof EventHandlerTypes>;\n"]}
|
|
@@ -66,10 +66,10 @@ export declare class EventBus<TPayloadMap extends object> extends BaseHelper {
|
|
|
66
66
|
* once (`FUNCTION`) - see `buildHandlerInvoker` - so this method calls it uniformly. A handler that
|
|
67
67
|
* throws synchronously is caught exactly like one that returns a rejected promise: `execution`
|
|
68
68
|
* here is itself `async`, and JS converts a synchronous throw inside an async function body into a
|
|
69
|
-
* rejection of that function's own promise - `
|
|
69
|
+
* rejection of that function's own promise - `RetryUtility.executeWithRetry`'s attempt loop never
|
|
70
70
|
* sees the difference.
|
|
71
71
|
*
|
|
72
|
-
* `
|
|
72
|
+
* `RetryUtility.executeWithRetry` is used without its own `logger` - its internal per-attempt/exhaustion
|
|
73
73
|
* logging knows nothing about the event name or `traceId`, so it cannot be the trace anyone
|
|
74
74
|
* relies on. The one line below, logged only on final failure, is.
|
|
75
75
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectUtility } from '@venizia/ignis-helpers/common';
|
|
2
|
-
import { BaseHelper, getError, RetryBackoffStrategies,
|
|
2
|
+
import { BaseHelper, getError, RetryBackoffStrategies, RetryUtility, RetryJitterModes, } from '@venizia/ignis-helpers/core';
|
|
3
3
|
import { EventDispatchRetry, EventHandlerTypes } from './common/constants.js';
|
|
4
4
|
/** In-process, fire-and-forget domain event bus. `TPayloadMap` keys the event names, so a wrong name
|
|
5
5
|
* or payload shape is a compile error. Delivery is always async. Retry timing is a property of the
|
|
@@ -21,7 +21,7 @@ export class EventBus extends BaseHelper {
|
|
|
21
21
|
const { maxAttempts, baseDelayMs } = opts;
|
|
22
22
|
let totalWindowMs = 0;
|
|
23
23
|
for (let attempt = 1; attempt < maxAttempts; attempt++) {
|
|
24
|
-
totalWindowMs +=
|
|
24
|
+
totalWindowMs += RetryUtility.computeBackoffDelayMs({
|
|
25
25
|
attempt,
|
|
26
26
|
backoff: {
|
|
27
27
|
strategy: RetryBackoffStrategies.EXPONENTIAL,
|
|
@@ -99,7 +99,7 @@ export class EventBus extends BaseHelper {
|
|
|
99
99
|
}
|
|
100
100
|
default: {
|
|
101
101
|
throw getError({
|
|
102
|
-
message: `[EventBus][register] Unknown handler.type | name: ${name} | Expected one of: ${
|
|
102
|
+
message: `[EventBus][register] Unknown handler.type | name: ${name} | Expected one of: ${EventHandlerTypes.values().join(', ')} | Got: ${handler.type}`,
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -177,10 +177,10 @@ export class EventBus extends BaseHelper {
|
|
|
177
177
|
* once (`FUNCTION`) - see `buildHandlerInvoker` - so this method calls it uniformly. A handler that
|
|
178
178
|
* throws synchronously is caught exactly like one that returns a rejected promise: `execution`
|
|
179
179
|
* here is itself `async`, and JS converts a synchronous throw inside an async function body into a
|
|
180
|
-
* rejection of that function's own promise - `
|
|
180
|
+
* rejection of that function's own promise - `RetryUtility.executeWithRetry`'s attempt loop never
|
|
181
181
|
* sees the difference.
|
|
182
182
|
*
|
|
183
|
-
* `
|
|
183
|
+
* `RetryUtility.executeWithRetry` is used without its own `logger` - its internal per-attempt/exhaustion
|
|
184
184
|
* logging knows nothing about the event name or `traceId`, so it cannot be the trace anyone
|
|
185
185
|
* relies on. The one line below, logged only on final failure, is.
|
|
186
186
|
*/
|
|
@@ -189,7 +189,7 @@ export class EventBus extends BaseHelper {
|
|
|
189
189
|
const { invokeHandler, description, maxAttempts, baseDelayMs } = registration;
|
|
190
190
|
let lastAttempt = 0;
|
|
191
191
|
try {
|
|
192
|
-
await
|
|
192
|
+
await RetryUtility.executeWithRetry({
|
|
193
193
|
operation: `EventBus.dispatch:${event.name}`,
|
|
194
194
|
maxAttempts,
|
|
195
195
|
backoff: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../../src/base/events/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG9D,OAAO,EACL,UAAU,EACV,QAAQ,EACR,sBAAsB,EACtB,WAAW,EACX,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAmB3E;;;;;;;+EAO+E;AAC/E,MAAM,OAAO,QAAqC,SAAQ,UAAU;IAOlE,YAAY,IAA8C;QACxD,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,I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AAE,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;oBAC9D,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,8DAA8D,EAC9D,KAAK,CAAC,IAAI,EACV,KAAK,CACN,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACK,KAAK,CAAC,QAAQ,CAAC,IAGtB;QACC,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QACrC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;QAC9E,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,IAAI,CAAC;YACH,MAAM,WAAW,CAAC,gBAAgB,CAAC;gBACjC,SAAS,EAAE,qBAAqB,KAAK,CAAC,IAAI,EAAE;gBAC5C,WAAW;gBACX,OAAO,EAAE;oBACP,QAAQ,EAAE,sBAAsB,CAAC,WAAW;oBAC5C,cAAc,EAAE,WAAW;oBAC3B,MAAM,EAAE,gBAAgB,CAAC,IAAI;iBAC9B;gBACD,SAAS,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;oBAC/B,WAAW,GAAG,OAAO,CAAC;oBACtB,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACjC,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4FAA4F;YAC5F,6EAA6E;YAC7E,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,wGAAwG,EACxG,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,OAAO,EACb,WAAW,EACX,WAAW,EACX,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-helpers/common';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n BaseHelper,\n getError,\n RetryBackoffStrategies,\n RetryHelper,\n RetryJitterModes,\n} from '@venizia/ignis-helpers/core';\nimport { EventDispatchRetry, EventHandlerTypes } from './common/constants';\nimport type {\n IDomainEvent,\n IEventHandlerRetryOptions,\n TEventHandlerReference,\n} from './common/types';\n\n/** One `register`ed handler, resolved to concrete retry numbers and a ready-to-call invoker -\n * `EventDispatchRetry`'s defaults already applied and `handler`'s shape already resolved, so\n * `dispatch` never has to branch on either. */\ninterface IResolvedEventRegistration {\n // A method signature on purpose: its parameter is bivariant, so a registration holds the invoker of any payload type, which the registry cannot tell apart.\n invokeHandler(opts: { event: IDomainEvent<unknown> }): ValueOrPromise<void>;\n /** For the exhaustion log line only - a binding key or `<function fn.name>`. */\n description: string;\n maxAttempts: number;\n baseDelayMs: number;\n}\n\n/** In-process, fire-and-forget domain event bus. `TPayloadMap` keys the event names, so a wrong name\n * or payload shape is a compile error. Delivery is always async. Retry timing is a property of the\n * handler's own failure mode, not of the event, so `register` may tune it per registration. But\n * nobody awaits a fire-and-forget dispatch, so an unbounded window would let one event hold a\n * handler - and whatever it holds open, e.g. a database connection - for an unbounded time with no\n * one to report it. What the bus guarantees instead: a bounded MAXIMUM time a single dispatch can\n * occupy, enforced as a hard ceiling at `register()` - see `EventDispatchRetry`. Retry makes\n * delivery at-least-once: handlers must be idempotent, see `IEventHandler`. */\nexport class EventBus<TPayloadMap extends object> extends BaseHelper {\n private readonly container: Container;\n\n /** `register` appends, never replaces - two handlers may share an event name, and replacing would\n * drop the first with no way for the caller to notice. */\n private readonly registrationsByName: Map<string, IResolvedEventRegistration[]>;\n\n constructor(opts: { scope?: string; container: Container }) {\n super({ scope: opts.scope ?? EventBus.name });\n this.container = opts.container;\n this.registrationsByName = new Map();\n }\n\n /** The pre-jitter total of every inter-attempt delay `maxAttempts`/`baseDelayMs` would produce -\n * jitter (always on, see `dispatch`) only ever shrinks a delay, so this is a true upper bound. */\n private static computeTotalWindowMs(opts: { maxAttempts: number; baseDelayMs: number }): number {\n const { maxAttempts, baseDelayMs } = opts;\n let totalWindowMs = 0;\n\n for (let attempt = 1; attempt < maxAttempts; attempt++) {\n totalWindowMs += RetryHelper.computeBackoffDelayMs({\n attempt,\n backoff: {\n strategy: RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs: baseDelayMs,\n jitter: RetryJitterModes.NONE,\n },\n });\n }\n\n return totalWindowMs;\n }\n\n /** Loud rejection, never a silent clamp: a caller who believes a number the bus does not honour is\n * worse off than one who sees the ceiling at boot. */\n private static assertValidRetry(opts: {\n name: string;\n maxAttempts: number;\n baseDelayMs: number;\n }): void {\n const { name, maxAttempts, baseDelayMs } = opts;\n\n if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {\n throw getError({\n message: `[EventBus][register] retry.maxAttempts must be a positive integer | name: ${name} | Got: ${maxAttempts}`,\n });\n }\n\n if (!Number.isInteger(baseDelayMs) || baseDelayMs < 1) {\n throw getError({\n message: `[EventBus][register] retry.baseDelayMs must be a positive integer | name: ${name} | Got: ${baseDelayMs}`,\n });\n }\n\n if (maxAttempts > EventDispatchRetry.MAX_ATTEMPTS_CEILING) {\n throw getError({\n message: `[EventBus][register] retry.maxAttempts exceeds the ceiling | name: ${name} | Got: ${maxAttempts} | Ceiling: ${EventDispatchRetry.MAX_ATTEMPTS_CEILING} | Lower retry.maxAttempts`,\n });\n }\n\n const totalWindowMs = EventBus.computeTotalWindowMs({ maxAttempts, baseDelayMs });\n\n if (totalWindowMs > EventDispatchRetry.MAX_TOTAL_WINDOW_MS) {\n throw getError({\n message: `[EventBus][register] retry window exceeds the ceiling | name: ${name} | Got: ${totalWindowMs}ms | Ceiling: ${EventDispatchRetry.MAX_TOTAL_WINDOW_MS}ms | Lower retry.maxAttempts or retry.baseDelayMs`,\n });\n }\n }\n\n /**\n * Turns `handler` into a uniform invoker plus a description for the exhaustion log line.\n * `BINDING_KEY` resolves through the container INSIDE the returned closure, so every call re-reads\n * the current binding; `FUNCTION` calls `fn` directly, so the closure IS the resolution - there is\n * nothing left to re-read on a later attempt. The tag (`handler.type`) is what this switches on,\n * not which field happens to be present - see `EventHandlerTypes`' doc.\n */\n private static buildHandlerInvoker<TPayload>(opts: {\n container: Container;\n handler: TEventHandlerReference<TPayload>;\n name: string;\n }): {\n invokeHandler: (opts: { event: IDomainEvent<TPayload> }) => ValueOrPromise<void>;\n description: string;\n } {\n const { container, handler, name } = opts;\n\n if (ObjectUtility.isEmpty({ value: handler })) {\n throw getError({\n message: `[EventBus][register] Invalid handler | name: ${name} | Got: ${handler}`,\n });\n }\n\n switch (handler.type) {\n case EventHandlerTypes.BINDING_KEY: {\n const { key } = handler;\n\n if (ObjectUtility.isEmpty({ value: key })) {\n throw getError({\n message: `[EventBus][register] Invalid handler.key | name: ${name} | Got: ${key}`,\n });\n }\n\n return {\n invokeHandler: ({ event }) => container.get({ key }).handle({ event }),\n description: `binding-key:${key}`,\n };\n }\n\n case EventHandlerTypes.FUNCTION: {\n const { fn } = handler;\n\n if (typeof fn !== 'function') {\n throw getError({\n message: `[EventBus][register] Invalid handler.fn | name: ${name} | Expected a function | Got: ${typeof fn}`,\n });\n }\n\n return {\n invokeHandler: ({ event }) => fn({ event }),\n description: `function:${fn.name || 'anonymous'}`,\n };\n }\n\n default: {\n throw getError({\n message: `[EventBus][register] Unknown handler.type | name: ${name} | Expected one of: ${[...EventHandlerTypes.SCHEME_SET].join(', ')} | Got: ${(handler as { type?: unknown }).type}`,\n });\n }\n }\n }\n\n /**\n * `retry` is optional and per REGISTRATION, not per publish: the right window belongs to the\n * handler's own failure mode, and two handlers on the same event name may each pick their own.\n * Omitting it reproduces today's `EventDispatchRetry` defaults exactly. Both `maxAttempts` and the\n * total backoff window it implies are bounded - see `EventDispatchRetry` - and exceeding either\n * throws here, at boot where a human sees it, rather than being silently clamped at dispatch time.\n */\n register<K extends keyof TPayloadMap & string>(opts: {\n name: K;\n /** A `BINDING_KEY` reference re-resolves through the container on every retry attempt, so a\n * rebind reaches a dispatch already in flight. A `FUNCTION` reference is captured as-is: a\n * rebind has nothing to reach, and every attempt in a long retry window calls the exact `fn`\n * registered here. */\n handler: TEventHandlerReference<TPayloadMap[K]>;\n retry?: IEventHandlerRetryOptions;\n }): void {\n const { name, handler, retry } = opts;\n\n if (ObjectUtility.isEmpty({ value: name })) {\n throw getError({\n message: `[EventBus][register] Invalid registration | name: ${String(name)}`,\n });\n }\n\n const maxAttempts = retry?.maxAttempts ?? EventDispatchRetry.MAX_ATTEMPTS;\n const baseDelayMs = retry?.baseDelayMs ?? EventDispatchRetry.BASE_DELAY_MS;\n EventBus.assertValidRetry({ name, maxAttempts, baseDelayMs });\n\n const { invokeHandler, description } = EventBus.buildHandlerInvoker({\n container: this.container,\n handler,\n name,\n });\n\n const registration: IResolvedEventRegistration = {\n invokeHandler,\n description,\n maxAttempts,\n baseDelayMs,\n };\n\n const existing = this.registrationsByName.get(name);\n\n if (existing) {\n existing.push(registration);\n\n return;\n }\n\n this.registrationsByName.set(name, [registration]);\n }\n\n /**\n * Never blocks and never throws back to the caller: dispatch runs outside this call's flow via\n * `queueMicrotask`, and a handler failure is caught and logged where it happens (`dispatch`),\n * never here.\n */\n publish<K extends keyof TPayloadMap & string>(opts: {\n name: K;\n payload: TPayloadMap[K];\n traceId?: string;\n }): void {\n const { name, payload, traceId } = opts;\n\n const event: IDomainEvent<TPayloadMap[K]> = {\n name,\n payload,\n occurredAt: new Date().toISOString(),\n traceId,\n };\n\n const registrations = this.registrationsByName.get(name);\n\n if (!registrations?.length) {\n // A typo is already a compile error, so at runtime this only means nobody is listening yet -\n // a legitimate state on a fire-and-forget bus, not an incident.\n this.logger.debug('[publish] No handler registered | name: %s | traceId: %s', name, traceId);\n\n return;\n }\n\n for (const registration of registrations) {\n queueMicrotask(() => {\n // `dispatch` catches every failure path itself and never rejects - this `.catch` is an\n // unreachable backstop, kept (and logged) rather than left floating, for the day it isn't.\n this.dispatch({ event, registration }).catch((error: unknown) => {\n this.logger.error(\n '[publish] Unexpected dispatch failure | name: %s | Error: %s',\n event.name,\n error,\n );\n });\n });\n }\n }\n\n /**\n * Attempts/backoff come from the registration (`EventDispatchRetry`'s defaults when omitted),\n * always with full jitter - `RetryJitterModes.FULL` decorrelates a shared-resource pile-up hardest,\n * so many handlers retrying the same lock do not collide on the same instant a second and third\n * time. `invokeHandler` already encodes whether that re-resolves (`BINDING_KEY`) or was captured\n * once (`FUNCTION`) - see `buildHandlerInvoker` - so this method calls it uniformly. A handler that\n * throws synchronously is caught exactly like one that returns a rejected promise: `execution`\n * here is itself `async`, and JS converts a synchronous throw inside an async function body into a\n * rejection of that function's own promise - `RetryHelper.executeWithRetry`'s attempt loop never\n * sees the difference.\n *\n * `RetryHelper.executeWithRetry` is used without its own `logger` - its internal per-attempt/exhaustion\n * logging knows nothing about the event name or `traceId`, so it cannot be the trace anyone\n * relies on. The one line below, logged only on final failure, is.\n */\n private async dispatch(opts: {\n event: IDomainEvent<unknown>;\n registration: IResolvedEventRegistration;\n }): Promise<void> {\n const { event, registration } = opts;\n const { invokeHandler, description, maxAttempts, baseDelayMs } = registration;\n let lastAttempt = 0;\n\n try {\n await RetryHelper.executeWithRetry({\n operation: `EventBus.dispatch:${event.name}`,\n maxAttempts,\n backoff: {\n strategy: RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs: baseDelayMs,\n jitter: RetryJitterModes.FULL,\n },\n execution: async ({ attempt }) => {\n lastAttempt = attempt;\n await invokeHandler({ event });\n },\n });\n } catch (error) {\n // The only trace this failure leaves: it is caught here and never reaches the publisher, so\n // the event name, traceId and attempt count all have to be on this one line.\n this.logger.error(\n '[dispatch] Handler exhausted retries | name: %s | traceId: %s | attempts: %d | handler: %s | Error: %s',\n event.name,\n event.traceId,\n lastAttempt,\n description,\n error,\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../../src/base/events/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,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AAC;oBACtB,MAAM,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACjC,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4FAA4F;YAC5F,6EAA6E;YAC7E,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,wGAAwG,EACxG,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,OAAO,EACb,WAAW,EACX,WAAW,EACX,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-helpers/common';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport {\n BaseHelper,\n getError,\n RetryBackoffStrategies,\n RetryUtility,\n RetryJitterModes,\n} from '@venizia/ignis-helpers/core';\nimport { EventDispatchRetry, EventHandlerTypes } from './common/constants';\nimport type {\n IDomainEvent,\n IEventHandlerRetryOptions,\n TEventHandlerReference,\n} from './common/types';\n\n/** One `register`ed handler, resolved to concrete retry numbers and a ready-to-call invoker -\n * `EventDispatchRetry`'s defaults already applied and `handler`'s shape already resolved, so\n * `dispatch` never has to branch on either. */\ninterface IResolvedEventRegistration {\n // A method signature on purpose: its parameter is bivariant, so a registration holds the invoker of any payload type, which the registry cannot tell apart.\n invokeHandler(opts: { event: IDomainEvent<unknown> }): ValueOrPromise<void>;\n /** For the exhaustion log line only - a binding key or `<function fn.name>`. */\n description: string;\n maxAttempts: number;\n baseDelayMs: number;\n}\n\n/** In-process, fire-and-forget domain event bus. `TPayloadMap` keys the event names, so a wrong name\n * or payload shape is a compile error. Delivery is always async. Retry timing is a property of the\n * handler's own failure mode, not of the event, so `register` may tune it per registration. But\n * nobody awaits a fire-and-forget dispatch, so an unbounded window would let one event hold a\n * handler - and whatever it holds open, e.g. a database connection - for an unbounded time with no\n * one to report it. What the bus guarantees instead: a bounded MAXIMUM time a single dispatch can\n * occupy, enforced as a hard ceiling at `register()` - see `EventDispatchRetry`. Retry makes\n * delivery at-least-once: handlers must be idempotent, see `IEventHandler`. */\nexport class EventBus<TPayloadMap extends object> extends BaseHelper {\n private readonly container: Container;\n\n /** `register` appends, never replaces - two handlers may share an event name, and replacing would\n * drop the first with no way for the caller to notice. */\n private readonly registrationsByName: Map<string, IResolvedEventRegistration[]>;\n\n constructor(opts: { scope?: string; container: Container }) {\n super({ scope: opts.scope ?? EventBus.name });\n this.container = opts.container;\n this.registrationsByName = new Map();\n }\n\n /** The pre-jitter total of every inter-attempt delay `maxAttempts`/`baseDelayMs` would produce -\n * jitter (always on, see `dispatch`) only ever shrinks a delay, so this is a true upper bound. */\n private static computeTotalWindowMs(opts: { maxAttempts: number; baseDelayMs: number }): number {\n const { maxAttempts, baseDelayMs } = opts;\n let totalWindowMs = 0;\n\n for (let attempt = 1; attempt < maxAttempts; attempt++) {\n totalWindowMs += RetryUtility.computeBackoffDelayMs({\n attempt,\n backoff: {\n strategy: RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs: baseDelayMs,\n jitter: RetryJitterModes.NONE,\n },\n });\n }\n\n return totalWindowMs;\n }\n\n /** Loud rejection, never a silent clamp: a caller who believes a number the bus does not honour is\n * worse off than one who sees the ceiling at boot. */\n private static assertValidRetry(opts: {\n name: string;\n maxAttempts: number;\n baseDelayMs: number;\n }): void {\n const { name, maxAttempts, baseDelayMs } = opts;\n\n if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {\n throw getError({\n message: `[EventBus][register] retry.maxAttempts must be a positive integer | name: ${name} | Got: ${maxAttempts}`,\n });\n }\n\n if (!Number.isInteger(baseDelayMs) || baseDelayMs < 1) {\n throw getError({\n message: `[EventBus][register] retry.baseDelayMs must be a positive integer | name: ${name} | Got: ${baseDelayMs}`,\n });\n }\n\n if (maxAttempts > EventDispatchRetry.MAX_ATTEMPTS_CEILING) {\n throw getError({\n message: `[EventBus][register] retry.maxAttempts exceeds the ceiling | name: ${name} | Got: ${maxAttempts} | Ceiling: ${EventDispatchRetry.MAX_ATTEMPTS_CEILING} | Lower retry.maxAttempts`,\n });\n }\n\n const totalWindowMs = EventBus.computeTotalWindowMs({ maxAttempts, baseDelayMs });\n\n if (totalWindowMs > EventDispatchRetry.MAX_TOTAL_WINDOW_MS) {\n throw getError({\n message: `[EventBus][register] retry window exceeds the ceiling | name: ${name} | Got: ${totalWindowMs}ms | Ceiling: ${EventDispatchRetry.MAX_TOTAL_WINDOW_MS}ms | Lower retry.maxAttempts or retry.baseDelayMs`,\n });\n }\n }\n\n /**\n * Turns `handler` into a uniform invoker plus a description for the exhaustion log line.\n * `BINDING_KEY` resolves through the container INSIDE the returned closure, so every call re-reads\n * the current binding; `FUNCTION` calls `fn` directly, so the closure IS the resolution - there is\n * nothing left to re-read on a later attempt. The tag (`handler.type`) is what this switches on,\n * not which field happens to be present - see `EventHandlerTypes`' doc.\n */\n private static buildHandlerInvoker<TPayload>(opts: {\n container: Container;\n handler: TEventHandlerReference<TPayload>;\n name: string;\n }): {\n invokeHandler: (opts: { event: IDomainEvent<TPayload> }) => ValueOrPromise<void>;\n description: string;\n } {\n const { container, handler, name } = opts;\n\n if (ObjectUtility.isEmpty({ value: handler })) {\n throw getError({\n message: `[EventBus][register] Invalid handler | name: ${name} | Got: ${handler}`,\n });\n }\n\n switch (handler.type) {\n case EventHandlerTypes.BINDING_KEY: {\n const { key } = handler;\n\n if (ObjectUtility.isEmpty({ value: key })) {\n throw getError({\n message: `[EventBus][register] Invalid handler.key | name: ${name} | Got: ${key}`,\n });\n }\n\n return {\n invokeHandler: ({ event }) => container.get({ key }).handle({ event }),\n description: `binding-key:${key}`,\n };\n }\n\n case EventHandlerTypes.FUNCTION: {\n const { fn } = handler;\n\n if (typeof fn !== 'function') {\n throw getError({\n message: `[EventBus][register] Invalid handler.fn | name: ${name} | Expected a function | Got: ${typeof fn}`,\n });\n }\n\n return {\n invokeHandler: ({ event }) => fn({ event }),\n description: `function:${fn.name || 'anonymous'}`,\n };\n }\n\n default: {\n throw getError({\n message: `[EventBus][register] Unknown handler.type | name: ${name} | Expected one of: ${EventHandlerTypes.values().join(', ')} | Got: ${(handler as { type?: unknown }).type}`,\n });\n }\n }\n }\n\n /**\n * `retry` is optional and per REGISTRATION, not per publish: the right window belongs to the\n * handler's own failure mode, and two handlers on the same event name may each pick their own.\n * Omitting it reproduces today's `EventDispatchRetry` defaults exactly. Both `maxAttempts` and the\n * total backoff window it implies are bounded - see `EventDispatchRetry` - and exceeding either\n * throws here, at boot where a human sees it, rather than being silently clamped at dispatch time.\n */\n register<K extends keyof TPayloadMap & string>(opts: {\n name: K;\n /** A `BINDING_KEY` reference re-resolves through the container on every retry attempt, so a\n * rebind reaches a dispatch already in flight. A `FUNCTION` reference is captured as-is: a\n * rebind has nothing to reach, and every attempt in a long retry window calls the exact `fn`\n * registered here. */\n handler: TEventHandlerReference<TPayloadMap[K]>;\n retry?: IEventHandlerRetryOptions;\n }): void {\n const { name, handler, retry } = opts;\n\n if (ObjectUtility.isEmpty({ value: name })) {\n throw getError({\n message: `[EventBus][register] Invalid registration | name: ${String(name)}`,\n });\n }\n\n const maxAttempts = retry?.maxAttempts ?? EventDispatchRetry.MAX_ATTEMPTS;\n const baseDelayMs = retry?.baseDelayMs ?? EventDispatchRetry.BASE_DELAY_MS;\n EventBus.assertValidRetry({ name, maxAttempts, baseDelayMs });\n\n const { invokeHandler, description } = EventBus.buildHandlerInvoker({\n container: this.container,\n handler,\n name,\n });\n\n const registration: IResolvedEventRegistration = {\n invokeHandler,\n description,\n maxAttempts,\n baseDelayMs,\n };\n\n const existing = this.registrationsByName.get(name);\n\n if (existing) {\n existing.push(registration);\n\n return;\n }\n\n this.registrationsByName.set(name, [registration]);\n }\n\n /**\n * Never blocks and never throws back to the caller: dispatch runs outside this call's flow via\n * `queueMicrotask`, and a handler failure is caught and logged where it happens (`dispatch`),\n * never here.\n */\n publish<K extends keyof TPayloadMap & string>(opts: {\n name: K;\n payload: TPayloadMap[K];\n traceId?: string;\n }): void {\n const { name, payload, traceId } = opts;\n\n const event: IDomainEvent<TPayloadMap[K]> = {\n name,\n payload,\n occurredAt: new Date().toISOString(),\n traceId,\n };\n\n const registrations = this.registrationsByName.get(name);\n\n if (!registrations?.length) {\n // A typo is already a compile error, so at runtime this only means nobody is listening yet -\n // a legitimate state on a fire-and-forget bus, not an incident.\n this.logger.debug('[publish] No handler registered | name: %s | traceId: %s', name, traceId);\n\n return;\n }\n\n for (const registration of registrations) {\n queueMicrotask(() => {\n // `dispatch` catches every failure path itself and never rejects - this `.catch` is an\n // unreachable backstop, kept (and logged) rather than left floating, for the day it isn't.\n this.dispatch({ event, registration }).catch((error: unknown) => {\n this.logger.error(\n '[publish] Unexpected dispatch failure | name: %s | Error: %s',\n event.name,\n error,\n );\n });\n });\n }\n }\n\n /**\n * Attempts/backoff come from the registration (`EventDispatchRetry`'s defaults when omitted),\n * always with full jitter - `RetryJitterModes.FULL` decorrelates a shared-resource pile-up hardest,\n * so many handlers retrying the same lock do not collide on the same instant a second and third\n * time. `invokeHandler` already encodes whether that re-resolves (`BINDING_KEY`) or was captured\n * once (`FUNCTION`) - see `buildHandlerInvoker` - so this method calls it uniformly. A handler that\n * throws synchronously is caught exactly like one that returns a rejected promise: `execution`\n * here is itself `async`, and JS converts a synchronous throw inside an async function body into a\n * rejection of that function's own promise - `RetryUtility.executeWithRetry`'s attempt loop never\n * sees the difference.\n *\n * `RetryUtility.executeWithRetry` is used without its own `logger` - its internal per-attempt/exhaustion\n * logging knows nothing about the event name or `traceId`, so it cannot be the trace anyone\n * relies on. The one line below, logged only on final failure, is.\n */\n private async dispatch(opts: {\n event: IDomainEvent<unknown>;\n registration: IResolvedEventRegistration;\n }): Promise<void> {\n const { event, registration } = opts;\n const { invokeHandler, description, maxAttempts, baseDelayMs } = registration;\n let lastAttempt = 0;\n\n try {\n await RetryUtility.executeWithRetry({\n operation: `EventBus.dispatch:${event.name}`,\n maxAttempts,\n backoff: {\n strategy: RetryBackoffStrategies.EXPONENTIAL,\n initialDelayMs: baseDelayMs,\n jitter: RetryJitterModes.FULL,\n },\n execution: async ({ attempt }) => {\n lastAttempt = attempt;\n await invokeHandler({ event });\n },\n });\n } catch (error) {\n // The only trace this failure leaves: it is caught here and never reaches the publisher, so\n // the event name, traceId and attempt count all have to be on this one line.\n this.logger.error(\n '[dispatch] Handler exhausted retries | name: %s | traceId: %s | attempts: %d | handler: %s | Error: %s',\n event.name,\n event.traceId,\n lastAttempt,\n description,\n error,\n );\n }\n }\n}\n"]}
|
|
@@ -7,7 +7,7 @@ export const injectable = (opts) => {
|
|
|
7
7
|
return (target) => {
|
|
8
8
|
if (!ArtifactTypes.isValid(opts.type)) {
|
|
9
9
|
throw getError({
|
|
10
|
-
message: `[injectable][${target.name}] Invalid artifact type: '${opts.type}' | Expected one of: ${
|
|
10
|
+
message: `[injectable][${target.name}] Invalid artifact type: '${opts.type}' | Expected one of: ${ArtifactTypes.values().join(', ')}`,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
// At import time, so the failure lands where the binding is written, not at boot.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../../src/base/metadata/injectable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAoB,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,oJAAoJ;AACpJ,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAwC,EACxB,EAAE;IAClB,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,gBAAgB,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BACvB,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC7C;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,sFAAsF;AACtF,MAAM,OAAO,iBAAiB;IAC5B,gIAAgI;IAChI,MAAM,CAAC,uBAAuB,CAA4B,IAEzD;QACC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC5E,MAAM,YAAY,GAAkD,EAAE,CAAC;QAEvE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;QACjC,CAAC;QAED,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAChC,YAAY,CAAC,aAAa,GAAG,aAAa,CAAC;QAC7C,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;QAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;QAC3B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF","sourcesContent":["import type {\n IArtifactMetadata,\n IArtifactRegistrationOptions,\n TBindingScope,\n} from '@/helpers/inversion';\nimport { ArtifactNamespaces, BindingNamespaces } from '@/common/bindings';\nimport { ArtifactTypes, MetadataRegistry, type TBindingKey } from '@/helpers/inversion';\nimport { ArtifactBindingKeys } from './artifact-keys';\nimport { getError } from '@venizia/ignis-helpers/core';\n\n/** The root stereotype: marks a class as an artifact the application registers, with its registration defaults. Every other stereotype calls it. */\nexport const injectable = <ApplicationType = unknown>(\n opts: IArtifactMetadata<ApplicationType>,\n): ClassDecorator => {\n return (target) => {\n if (!ArtifactTypes.isValid(opts.type)) {\n throw getError({\n message: `[injectable][${target.name}] Invalid artifact type: '${opts.type}' | Expected one of: ${ArtifactTypes.values().join(', ')}`,\n });\n }\n\n // At import time, so the failure lands where the binding is written, not at boot.\n if (opts.binding) {\n BindingNamespaces.assertArtifactNamespace({\n namespace: opts.binding.namespace,\n artifact: target.name,\n caller: 'injectable',\n });\n }\n\n const registry = MetadataRegistry.getInstance();\n registry.setArtifactMetadata({ target, metadata: opts });\n\n // Discovery happens HERE, at import time. A boot-time filesystem scan cannot see a compiled\n // single-file binary, and a class exists at run time only because something imported it.\n registry.addDiscoveredArtifact({ target });\n\n // The key this class WOULD get; `registerArtifact` overwrites it with the one actually bound.\n registry.setBindingKey({\n target,\n key: ArtifactBindingKeys.resolve({\n target,\n namespace: ArtifactNamespaces.resolve({ type: opts.type }),\n binding: opts.binding,\n }).key,\n isProvisional: true,\n });\n };\n};\n\n/**\n * Class decorator that registers the class as a service artifact; accepts the same registration options as `injectable`.\n *\n * @example\n * ```typescript\n * import { BaseService, service } from '@venizia/ignis';\n *\n * export @service()\n * class MailService extends BaseService {\n * constructor() {\n * super({ scope: MailService.name });\n * }\n * }\n * ```\n */\nexport const service = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.SERVICE, ...opts });\n};\n\n/**\n * Class decorator that registers the class as a component artifact; accepts the same registration options as `injectable`.\n *\n * @example\n * ```typescript\n * import { BaseComponent, component } from '@venizia/ignis';\n *\n * export @component()\n * class AuditComponent extends BaseComponent {\n * constructor() {\n * super({ scope: AuditComponent.name });\n * }\n *\n * override binding(): void {}\n * }\n * ```\n */\nexport const component = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.COMPONENT, ...opts });\n};\n\n/**\n * Class decorator that registers the class as a configuration artifact; `after` orders it behind other configuration classes.\n *\n * @example\n * ```typescript\n * import { BaseConfiguration, configuration } from '@venizia/ignis';\n *\n * export @configuration()\n * class SeedConfiguration extends BaseConfiguration {}\n *\n * export @configuration({ after: [SeedConfiguration] })\n * class IndexConfiguration extends BaseConfiguration {}\n * ```\n */\nexport const configuration = <ApplicationType = unknown>(\n opts?: IArtifactRegistrationOptions<ApplicationType>,\n): ClassDecorator => {\n return injectable<ApplicationType>({ type: ArtifactTypes.CONFIGURATION, ...opts });\n};\n\n/** Marks a component method as the provider of `key`. `registerArtifacts` binds the key to a lazy provider that resolves the component and calls the method; SINGLETON unless `scope` says otherwise. */\nexport const provide = (opts: { key: TBindingKey; scope?: TBindingScope }): MethodDecorator => {\n return (target, propertyKey) => {\n MetadataRegistry.getInstance().addProvideMetadata({\n target: target.constructor,\n metadata: {\n methodName: propertyKey,\n key: opts.key,\n ...(opts.scope ? { scope: opts.scope } : {}),\n },\n });\n };\n};\n\n/** Helpers of the stereotype decorators; the decorators themselves stay functions. */\nexport class InjectableUtility {\n /** The registration defaults a stereotype forwards to `@injectable`, copied field by field so an absent option stays absent. */\n static pickRegistrationOptions<ApplicationType = unknown>(opts: {\n metadata: IArtifactRegistrationOptions<ApplicationType>;\n }): IArtifactRegistrationOptions<ApplicationType> {\n const { binding, allowOverride, scope, order, when, after } = opts.metadata;\n const registration: IArtifactRegistrationOptions<ApplicationType> = {};\n\n if (binding !== undefined) {\n registration.binding = binding;\n }\n\n if (allowOverride !== undefined) {\n registration.allowOverride = allowOverride;\n }\n\n if (scope !== undefined) {\n registration.scope = scope;\n }\n\n if (order !== undefined) {\n registration.order = order;\n }\n\n if (when !== undefined) {\n registration.when = when;\n }\n\n if (after !== undefined) {\n registration.after = after;\n }\n\n return registration;\n }\n}\n"]}
|
|
@@ -14,7 +14,7 @@ export class ModelMetadataUtility {
|
|
|
14
14
|
const { type, migration } = metadata;
|
|
15
15
|
if (type !== undefined && !ModelTypes.isValid(type)) {
|
|
16
16
|
throw getError({
|
|
17
|
-
message: `[model][${model}] Invalid 'type' | Expected one of: ${
|
|
17
|
+
message: `[model][${model}] Invalid 'type' | Expected one of: ${ModelTypes.values().join(', ')} (or leave it out) | Got: ${String(type)}`,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
if (migration === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-metadata.js","sourceRoot":"","sources":["../../../../src/base/metadata/model-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;OAOG;IACH,MAAM,CAAC,sBAAsB,CAAC,IAAiD;QAC7E,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACjC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;QAErC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,WAAW,KAAK,uCAAuC,
|
|
1
|
+
{"version":3,"file":"model-metadata.js","sourceRoot":"","sources":["../../../../src/base/metadata/model-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;OAOG;IACH,MAAM,CAAC,sBAAsB,CAAC,IAAiD;QAC7E,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACjC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;QAErC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,WAAW,KAAK,uCAAuC,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,MAAM,CAAC,IAAI,CAAC,EAAE;aAC1I,CAAC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,OAAO,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,KAAK,KAAK,EAAE,EAAE,CAAC;IACpF,CAAC;CACF","sourcesContent":["import { getError } from '@venizia/ignis-helpers/core';\nimport type { IModelMetadata } from '@/helpers/inversion';\nimport { ModelTypes } from '../models/common/constants';\n\nexport class ModelMetadataUtility {\n /**\n * The one place the `@model` metadata outside `settings` is checked and normalised.\n *\n * - `type` is optional; a value must be one of {@link ModelTypes}.\n * - The old keys (`skipMigrate`, and the flat `defaultFilter`, `defaultLimit`, `maxLimit`, `scopeFilter` of `settings`)\n * are not read: the types refuse them as excess properties, and an untyped caller's key is ignored.\n * - When the model declares `migration`, the registry entry carries it with `use` filled in.\n */\n static normalizeModelMetadata(opts: { model: string; metadata: IModelMetadata }): IModelMetadata {\n const { model, metadata } = opts;\n const { type, migration } = metadata;\n\n if (type !== undefined && !ModelTypes.isValid(type)) {\n throw getError({\n message: `[model][${model}] Invalid 'type' | Expected one of: ${ModelTypes.values().join(', ')} (or leave it out) | Got: ${String(type)}`,\n });\n }\n\n if (migration === undefined) {\n return metadata;\n }\n\n return { ...metadata, migration: { ...migration, use: migration.use !== false } };\n }\n}\n"]}
|
|
@@ -33,7 +33,7 @@ export const datasource = (metadata) => {
|
|
|
33
33
|
// Untyped JS callers: a misspelt mode would silently mean "start", so it is refused where it is written.
|
|
34
34
|
if (openMode !== undefined && !DataSourceOpenModes.isValid(openMode)) {
|
|
35
35
|
throw getError({
|
|
36
|
-
message: `[datasource][@datasource][${target.name}] Invalid metadata | Unknown 'open.on': ${String(openMode)} | Expected one of: ${
|
|
36
|
+
message: `[datasource][@datasource][${target.name}] Invalid metadata | Unknown 'open.on': ${String(openMode)} | Expected one of: ${DataSourceOpenModes.values().join(', ')}`,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
injectable({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../../../../src/base/metadata/persistents/datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE9D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAA8B,EAAkB,EAAE;IAC3E,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,WAAW,GAAG,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC;QAE9C,IACE,WAAW,KAAK,SAAS;YACzB,CAAC,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC,EACtF,CAAC;YACD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,6BAA6B,MAAM,CAAC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C;QAEpC,yGAAyG;QACzG,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACrE,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,6BAA6B,MAAM,CAAC,IAAI,2CAA2C,MAAM,CAAC,QAAQ,CAAC,uBAAuB,mBAAmB,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAC7K,CAAC,CAAC;QACL,CAAC;QAED,UAAU,CAAC;YACT,IAAI,EAAE,aAAa,CAAC,UAAU;YAC9B,GAAG,iBAAiB,CAAC,uBAAuB,CAAC,EAAE,QAAQ,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC;SAC3E,CAAC,CAAC,MAAM,CAAC,CAAC;QACX,gBAAgB,CAAC,WAAW,EAAE,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ArtifactTypes, MetadataRegistry } from '@/helpers/inversion';\nimport type { IDataSourceMetadata } from '@/helpers/inversion';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport { DataSourceOpenModes } from '../../datasources';\nimport { injectable, InjectableUtility } from '../injectable';\n\n/**\n * Registers a datasource with driver and auto-discovery settings.\n *\n * @example\n * ```typescript\n * import { datasource } from '@venizia/ignis';\n * import { BasePostgresDataSource } from '@venizia/ignis-connectors/postgres';\n * import { NodePostgresDriver } from '@venizia/ignis-connectors/postgres/node-postgres';\n * import { Pool } from 'pg';\n *\n * export @datasource({ driver: NodePostgresDriver })\n * class AppDataSource extends BasePostgresDataSource<{ connectionString: string }> {\n * constructor() { super({ name: AppDataSource.name, config: { connectionString: 'postgres://localhost/app' } }); }\n * override configure(): void { this.client = new Pool(this.settings); }\n * override getConnectionString(): string { return this.settings.connectionString; }\n * }\n * ```\n */\nexport const datasource = (metadata?: IDataSourceMetadata): ClassDecorator => {\n return (target) => {\n const openTimeout = metadata?.open?.timeoutMs;\n\n if (\n openTimeout !== undefined &&\n (typeof openTimeout !== 'number' || !Number.isInteger(openTimeout) || openTimeout < 0)\n ) {\n throw getError({\n message: `[datasource][@datasource][${target.name}] Invalid metadata | 'open.timeoutMs' must be a non-negative integer (ms; 0 waits for ever) | Got: ${String(openTimeout)}`,\n });\n }\n\n const openMode = metadata?.open?.on;\n\n // Untyped JS callers: a misspelt mode would silently mean \"start\", so it is refused where it is written.\n if (openMode !== undefined && !DataSourceOpenModes.isValid(openMode)) {\n throw getError({\n message: `[datasource][@datasource][${target.name}] Invalid metadata | Unknown 'open.on': ${String(openMode)} | Expected one of: ${DataSourceOpenModes.values().join(', ')}`,\n });\n }\n\n injectable({\n type: ArtifactTypes.DATASOURCE,\n ...InjectableUtility.pickRegistrationOptions({ metadata: metadata ?? {} }),\n })(target);\n MetadataRegistry.getInstance().setDataSourceMetadata({ target, metadata });\n };\n};\n"]}
|
|
@@ -7,7 +7,7 @@ export const validateRepositoryMetadata = (opts) => {
|
|
|
7
7
|
const type = metadata.type ?? RepositoryTypes.MODEL;
|
|
8
8
|
if (!RepositoryTypes.isValid(type)) {
|
|
9
9
|
throw getError({
|
|
10
|
-
message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Unknown 'type': ${type} | Expected one of: ${
|
|
10
|
+
message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Unknown 'type': ${type} | Expected one of: ${RepositoryTypes.values().join(', ')}`,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
if (type === RepositoryTypes.MODEL && !metadata.model) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../../../src/base/metadata/persistents/repository/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD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;IACL,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { TRepositoryMetadata } from '@/helpers/inversion';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IDataSource } from '../../../datasources';\nimport { isDataSourceClass } from '../../../datasources';\nimport type { AbstractEntity } from '../../../models';\nimport { RepositoryTypes } from '../../../repositories/common/constants';\n\n/** Mirrors the `TRepositoryMetadata` union for JavaScript callers: a known type, a dataSource always, a model exactly when the type is RepositoryTypes.MODEL. */\nexport const validateRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n target: Function;\n}): void => {\n const { metadata, target } = opts;\n const type = metadata.type ?? RepositoryTypes.MODEL;\n\n if (!RepositoryTypes.isValid(type)) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Unknown 'type': ${type} | Expected one of: ${RepositoryTypes.values().join(', ')}`,\n });\n }\n\n if (type === RepositoryTypes.MODEL && !metadata.model) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'model'`,\n });\n }\n\n if (type === RepositoryTypes.REMOTE && metadata.model) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | A '${RepositoryTypes.REMOTE}' repository takes no 'model'`,\n });\n }\n\n if (!metadata.dataSource) {\n throw getError({\n message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'dataSource'`,\n });\n }\n};\n\n/** Asserts the constructor's first parameter is a datasource class (`AbstractDataSource` or the `DataSourceRoot` it extends) compatible with what @repository declared. */\nexport const validateFirstConstructorParameter = (opts: {\n target: Function;\n firstParamType: Function;\n resolvedDataSource: string | Function;\n}): void => {\n const { target, firstParamType, resolvedDataSource } = opts;\n\n // NOT `instanceof`: two copies of this package give two `DataSourceRoot` classes and the\n // check would be false across them, rejecting a perfectly valid repository at import time.\n const isDataSourceType = isDataSourceClass(firstParamType);\n\n if (!isDataSourceType) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | First parameter must extend AbstractDataSource (or DataSourceRoot) | Received: '${firstParamType.name}'`,\n });\n }\n\n if (typeof resolvedDataSource !== 'function') {\n return;\n }\n\n const isCompatible =\n firstParamType === resolvedDataSource || resolvedDataSource.prototype instanceof firstParamType;\n\n if (!isCompatible) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | Type mismatch | Constructor expects '${firstParamType.name}' but @repository specifies '${resolvedDataSource.name}'`,\n });\n }\n};\n"]}
|
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
2
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
2
3
|
/** The schema variants an entity can produce (`getSchema({ type })`): select, create, update and execute. */
|
|
3
|
-
export declare class SchemaTypes {
|
|
4
|
+
export declare class SchemaTypes extends ConstClass {
|
|
4
5
|
static readonly SELECT = "select";
|
|
5
6
|
static readonly UPDATE = "update";
|
|
6
7
|
static readonly CREATE = "create";
|
|
7
8
|
static readonly EXECUTE = "execute";
|
|
8
|
-
static readonly SCHEME_SET: Set<string>;
|
|
9
|
-
static isValid(input: string): input is TSchemaType;
|
|
10
9
|
}
|
|
11
10
|
/** Valid `SchemaTypes` values. */
|
|
12
11
|
export type TSchemaType = TConstValue<typeof SchemaTypes>;
|
|
13
12
|
/** The keys a write stamps, which a generated create or update body leaves out by default (`@model` `settings.properties.stamped`). */
|
|
14
|
-
export declare class AuditFields {
|
|
13
|
+
export declare class AuditFields extends ConstClass {
|
|
15
14
|
static readonly CREATED_BY = "createdBy";
|
|
16
15
|
static readonly MODIFIED_BY = "modifiedBy";
|
|
17
16
|
static readonly CREATED_AT = "createdAt";
|
|
18
17
|
static readonly MODIFIED_AT = "modifiedAt";
|
|
19
18
|
static readonly DELETED_AT = "deletedAt";
|
|
20
|
-
static readonly SCHEME_SET: Set<string>;
|
|
21
19
|
}
|
|
22
20
|
/** What `@model` declares. Only ENTITY (a table-backed model) exists; `type` may be left out. */
|
|
23
|
-
export declare class ModelTypes {
|
|
21
|
+
export declare class ModelTypes extends ConstClass {
|
|
24
22
|
static readonly ENTITY = "entity";
|
|
25
|
-
static readonly SCHEME_SET: Set<string>;
|
|
26
|
-
static isValid(value: string): boolean;
|
|
27
23
|
}
|
|
28
24
|
/** Valid model type values. */
|
|
29
25
|
export type TModelType = TConstValue<typeof ModelTypes>;
|
|
30
26
|
/** The path-param id shape an entity family resolves to (`AbstractEntity.getIdType()`). */
|
|
31
|
-
export declare class IdSchemaTypes {
|
|
27
|
+
export declare class IdSchemaTypes extends ConstClass {
|
|
32
28
|
static readonly NUMBER = "number";
|
|
33
29
|
static readonly STRING = "string";
|
|
34
|
-
static readonly SCHEME_SET: Set<string>;
|
|
35
|
-
static isValid(value: string): boolean;
|
|
36
30
|
}
|
|
37
31
|
/** Valid id schema type values. */
|
|
38
32
|
export type TIdSchemaType = TConstValue<typeof IdSchemaTypes>;
|
|
@@ -1,44 +1,26 @@
|
|
|
1
|
+
import { ConstClass } from '@venizia/ignis-helpers/common';
|
|
1
2
|
/** The schema variants an entity can produce (`getSchema({ type })`): select, create, update and execute. */
|
|
2
|
-
export class SchemaTypes {
|
|
3
|
+
export class SchemaTypes extends ConstClass {
|
|
3
4
|
static { this.SELECT = 'select'; }
|
|
4
5
|
static { this.UPDATE = 'update'; }
|
|
5
6
|
static { this.CREATE = 'create'; }
|
|
6
7
|
static { this.EXECUTE = 'execute'; }
|
|
7
|
-
static { this.SCHEME_SET = new Set([this.SELECT, this.UPDATE, this.CREATE, this.EXECUTE]); }
|
|
8
|
-
static isValid(input) {
|
|
9
|
-
return this.SCHEME_SET.has(input);
|
|
10
|
-
}
|
|
11
8
|
}
|
|
12
9
|
/** The keys a write stamps, which a generated create or update body leaves out by default (`@model` `settings.properties.stamped`). */
|
|
13
|
-
export class AuditFields {
|
|
10
|
+
export class AuditFields extends ConstClass {
|
|
14
11
|
static { this.CREATED_BY = 'createdBy'; }
|
|
15
12
|
static { this.MODIFIED_BY = 'modifiedBy'; }
|
|
16
13
|
static { this.CREATED_AT = 'createdAt'; }
|
|
17
14
|
static { this.MODIFIED_AT = 'modifiedAt'; }
|
|
18
15
|
static { this.DELETED_AT = 'deletedAt'; }
|
|
19
|
-
static { this.SCHEME_SET = new Set([
|
|
20
|
-
this.CREATED_BY,
|
|
21
|
-
this.MODIFIED_BY,
|
|
22
|
-
this.CREATED_AT,
|
|
23
|
-
this.MODIFIED_AT,
|
|
24
|
-
this.DELETED_AT,
|
|
25
|
-
]); }
|
|
26
16
|
}
|
|
27
17
|
/** What `@model` declares. Only ENTITY (a table-backed model) exists; `type` may be left out. */
|
|
28
|
-
export class ModelTypes {
|
|
18
|
+
export class ModelTypes extends ConstClass {
|
|
29
19
|
static { this.ENTITY = 'entity'; }
|
|
30
|
-
static { this.SCHEME_SET = new Set([this.ENTITY]); }
|
|
31
|
-
static isValid(value) {
|
|
32
|
-
return this.SCHEME_SET.has(value);
|
|
33
|
-
}
|
|
34
20
|
}
|
|
35
21
|
/** The path-param id shape an entity family resolves to (`AbstractEntity.getIdType()`). */
|
|
36
|
-
export class IdSchemaTypes {
|
|
22
|
+
export class IdSchemaTypes extends ConstClass {
|
|
37
23
|
static { this.NUMBER = 'number'; }
|
|
38
24
|
static { this.STRING = 'string'; }
|
|
39
|
-
static { this.SCHEME_SET = new Set([this.NUMBER, this.STRING]); }
|
|
40
|
-
static isValid(value) {
|
|
41
|
-
return this.SCHEME_SET.has(value);
|
|
42
|
-
}
|
|
43
25
|
}
|
|
44
26
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/models/common/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/base/models/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,6GAA6G;AAC7G,MAAM,OAAO,WAAY,SAAQ,UAAU;aACzB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;;AAMtC,uIAAuI;AACvI,MAAM,OAAO,WAAY,SAAQ,UAAU;aACzB,eAAU,GAAG,WAAW,CAAC;aACzB,gBAAW,GAAG,YAAY,CAAC;aAC3B,eAAU,GAAG,WAAW,CAAC;aACzB,gBAAW,GAAG,YAAY,CAAC;aAC3B,eAAU,GAAG,WAAW,CAAC;;AAG3C,iGAAiG;AACjG,MAAM,OAAO,UAAW,SAAQ,UAAU;aACxB,WAAM,GAAG,QAAQ,CAAC;;AAMpC,2FAA2F;AAC3F,MAAM,OAAO,aAAc,SAAQ,UAAU;aAC3B,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { ConstClass } from '@venizia/ignis-helpers/common';\n\n/** The schema variants an entity can produce (`getSchema({ type })`): select, create, update and execute. */\nexport class SchemaTypes extends ConstClass {\n static readonly SELECT = 'select';\n static readonly UPDATE = 'update';\n static readonly CREATE = 'create';\n static readonly EXECUTE = 'execute';\n}\n\n/** Valid `SchemaTypes` values. */\nexport type TSchemaType = TConstValue<typeof SchemaTypes>;\n\n/** The keys a write stamps, which a generated create or update body leaves out by default (`@model` `settings.properties.stamped`). */\nexport class AuditFields extends ConstClass {\n static readonly CREATED_BY = 'createdBy';\n static readonly MODIFIED_BY = 'modifiedBy';\n static readonly CREATED_AT = 'createdAt';\n static readonly MODIFIED_AT = 'modifiedAt';\n static readonly DELETED_AT = 'deletedAt';\n}\n\n/** What `@model` declares. Only ENTITY (a table-backed model) exists; `type` may be left out. */\nexport class ModelTypes extends ConstClass {\n static readonly ENTITY = 'entity';\n}\n\n/** Valid model type values. */\nexport type TModelType = TConstValue<typeof ModelTypes>;\n\n/** The path-param id shape an entity family resolves to (`AbstractEntity.getIdType()`). */\nexport class IdSchemaTypes extends ConstClass {\n static readonly NUMBER = 'number';\n static readonly STRING = 'string';\n}\n\n/** Valid id schema type values. */\nexport type TIdSchemaType = TConstValue<typeof IdSchemaTypes>;\n"]}
|