@venizia/ignis-kernel 0.4.8-9 → 0.4.8
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/artifact-index.d.ts +3 -3
- package/dist/esm/base/applications/artifact-index.js.map +1 -1
- package/dist/esm/base/applications/body-limit.js +1 -1
- package/dist/esm/base/applications/body-limit.js.map +1 -1
- package/dist/esm/base/applications/common/types/application.d.ts +2 -2
- package/dist/esm/base/applications/common/types/application.js.map +1 -1
- package/dist/esm/base/applications/common/types/middlewares.d.ts +2 -2
- package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
- package/dist/esm/base/applications/rest.js +6 -1
- package/dist/esm/base/applications/rest.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +1 -1
- package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
- package/dist/esm/base/auth/authenticate/common/types/strategy.d.ts +2 -3
- package/dist/esm/base/auth/authenticate/common/types/strategy.js.map +1 -1
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.d.ts +1 -1
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js +1 -1
- package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js.map +1 -1
- package/dist/esm/base/auth/authorize/providers/request-domain.js +2 -1
- package/dist/esm/base/auth/authorize/providers/request-domain.js.map +1 -1
- package/dist/esm/base/controllers/common/types/route.d.ts +13 -4
- package/dist/esm/base/controllers/common/types/route.js.map +1 -1
- package/dist/esm/base/controllers/factory/controller.d.ts +3 -4
- package/dist/esm/base/controllers/factory/controller.js +0 -1
- package/dist/esm/base/controllers/factory/controller.js.map +1 -1
- package/dist/esm/base/controllers/factory/crud/abstract.d.ts +3 -4
- package/dist/esm/base/controllers/factory/crud/abstract.js.map +1 -1
- package/dist/esm/base/controllers/factory/definition.d.ts +21 -1
- package/dist/esm/base/controllers/factory/definition.js +45 -31
- package/dist/esm/base/controllers/factory/definition.js.map +1 -1
- package/dist/esm/base/controllers/factory/index.d.ts +1 -0
- package/dist/esm/base/controllers/factory/index.js +1 -0
- package/dist/esm/base/controllers/factory/index.js.map +1 -1
- package/dist/esm/base/controllers/factory/injection.d.ts +38 -0
- package/dist/esm/base/controllers/factory/injection.js +54 -0
- package/dist/esm/base/controllers/factory/injection.js.map +1 -0
- package/dist/esm/base/controllers/rest/abstract.js +1 -1
- package/dist/esm/base/controllers/rest/abstract.js.map +1 -1
- package/dist/esm/base/controllers/rest/base.d.ts +3 -3
- package/dist/esm/base/controllers/rest/base.js.map +1 -1
- package/dist/esm/base/datasources/abstract.d.ts +4 -92
- package/dist/esm/base/datasources/abstract.js +3 -217
- package/dist/esm/base/datasources/abstract.js.map +1 -1
- package/dist/esm/base/datasources/common/types.d.ts +2 -2
- package/dist/esm/base/datasources/common/types.js.map +1 -1
- package/dist/esm/base/datasources/index.d.ts +1 -0
- package/dist/esm/base/datasources/index.js +1 -0
- package/dist/esm/base/datasources/index.js.map +1 -1
- package/dist/esm/base/datasources/root.d.ts +107 -0
- package/dist/esm/base/datasources/root.js +237 -0
- package/dist/esm/base/datasources/root.js.map +1 -0
- package/dist/esm/base/events/event-bus.js.map +1 -1
- package/dist/esm/base/metadata/index.d.ts +1 -1
- package/dist/esm/base/metadata/index.js +1 -1
- package/dist/esm/base/metadata/injectors.d.ts +1 -1
- package/dist/esm/base/metadata/persistents/datasource.d.ts +21 -0
- package/dist/esm/base/metadata/persistents/datasource.js +46 -0
- package/dist/esm/base/metadata/persistents/datasource.js.map +1 -0
- package/dist/esm/base/metadata/persistents/index.d.ts +5 -0
- package/dist/esm/base/metadata/persistents/index.js +5 -0
- package/dist/esm/base/metadata/persistents/index.js.map +1 -0
- package/dist/esm/base/metadata/persistents/model.d.ts +18 -0
- package/dist/esm/base/metadata/persistents/model.js +64 -0
- package/dist/esm/base/metadata/persistents/model.js.map +1 -0
- package/dist/esm/base/metadata/persistents/repository/index.d.ts +19 -0
- package/dist/esm/base/metadata/persistents/repository/index.js +32 -0
- package/dist/esm/base/metadata/persistents/repository/index.js.map +1 -0
- package/dist/esm/base/metadata/persistents/repository/injection.d.ts +15 -0
- package/dist/esm/base/metadata/persistents/repository/injection.js +64 -0
- package/dist/esm/base/metadata/persistents/repository/injection.js.map +1 -0
- package/dist/esm/base/metadata/persistents/repository/resolve.d.ts +15 -0
- package/dist/esm/base/metadata/persistents/repository/resolve.js +76 -0
- package/dist/esm/base/metadata/persistents/repository/resolve.js.map +1 -0
- package/dist/esm/base/metadata/persistents/repository/validate.d.ts +15 -0
- package/dist/esm/base/metadata/persistents/repository/validate.js +50 -0
- package/dist/esm/base/metadata/persistents/repository/validate.js.map +1 -0
- package/dist/esm/base/models/common/utilities.d.ts +1 -1
- package/dist/esm/base/repositories/common/response-reader.d.ts +30 -0
- package/dist/esm/base/repositories/common/response-reader.js +53 -0
- package/dist/esm/base/repositories/common/response-reader.js.map +1 -1
- package/dist/esm/base/repositories/common/types/contracts.d.ts +2 -2
- package/dist/esm/base/repositories/common/types/contracts.js.map +1 -1
- package/dist/esm/base/repositories/common/types/options.d.ts +2 -2
- package/dist/esm/base/repositories/common/types/options.js.map +1 -1
- package/dist/esm/base/repositories/common/types/query.d.ts +6 -15
- package/dist/esm/base/repositories/common/types/query.js.map +1 -1
- package/dist/esm/base/repositories/core/abstract.d.ts +6 -6
- package/dist/esm/base/repositories/core/abstract.js.map +1 -1
- package/dist/esm/base/repositories/query-schemas/index.js +7 -0
- package/dist/esm/base/repositories/query-schemas/index.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/dist/esm/helpers/inversion/mixins/artifact.mixin.d.ts +4 -3
- package/dist/esm/helpers/inversion/mixins/artifact.mixin.js +1 -0
- package/dist/esm/helpers/inversion/mixins/artifact.mixin.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/controllers/controller.d.ts +4 -3
- package/dist/esm/helpers/inversion/mixins/controllers/controller.js +1 -0
- package/dist/esm/helpers/inversion/mixins/controllers/controller.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/controllers/grpc.d.ts +4 -3
- package/dist/esm/helpers/inversion/mixins/controllers/grpc.js +1 -0
- package/dist/esm/helpers/inversion/mixins/controllers/grpc.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/controllers/rest.d.ts +4 -3
- package/dist/esm/helpers/inversion/mixins/controllers/rest.js +1 -0
- package/dist/esm/helpers/inversion/mixins/controllers/rest.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/datasource.mixin.d.ts +4 -3
- package/dist/esm/helpers/inversion/mixins/datasource.mixin.js +1 -0
- package/dist/esm/helpers/inversion/mixins/datasource.mixin.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/model.mixin.d.ts +4 -3
- package/dist/esm/helpers/inversion/mixins/model.mixin.js +1 -0
- package/dist/esm/helpers/inversion/mixins/model.mixin.js.map +1 -1
- package/dist/esm/helpers/inversion/mixins/repository.mixin.d.ts +9 -8
- package/dist/esm/helpers/inversion/mixins/repository.mixin.js +6 -6
- package/dist/esm/helpers/inversion/mixins/repository.mixin.js.map +1 -1
- package/dist/esm/helpers/inversion/registry.d.ts +26 -26
- package/dist/esm/helpers/inversion/registry.js.map +1 -1
- package/dist/esm/helpers/singleton-realm.js +5 -4
- package/dist/esm/helpers/singleton-realm.js.map +1 -1
- package/dist/esm/metadata.d.ts +1 -1
- package/dist/esm/metadata.js +1 -1
- package/dist/esm/repository.d.ts +1 -0
- package/dist/esm/repository.js +1 -0
- package/dist/esm/repository.js.map +1 -1
- package/dist/esm/utilities/index.d.ts +1 -0
- package/dist/esm/utilities/index.js +1 -0
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/toggle.utility.d.ts +22 -0
- package/dist/esm/utilities/toggle.utility.js +16 -0
- package/dist/esm/utilities/toggle.utility.js.map +1 -0
- package/package.json +5 -5
- package/dist/esm/base/metadata/persistents.d.ts +0 -54
- package/dist/esm/base/metadata/persistents.js +0 -302
- package/dist/esm/base/metadata/persistents.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAYzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAE5E,gGAAgG;AAChG,yCAAyC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAG5E,mGAAmG;AACnG,mEAAmE;AACnE,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,GAChB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAKxE,mGAAmG;AACnG,qFAAqF;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAc1E,oGAAoG;AACpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAC","sourcesContent":["/**\n * The persistence contract, and nothing about how a row is served or validated.\n *\n * A repository talks to a datasource. `AbstractDataSource` is engine-neutral - its only required\n * member is `configure()` - so \"an HTTP request to another server\" is a datasource in the same sense\n * Drizzle-over-Postgres is one: same role, different transport. This entry exists so a consumer can\n * implement that without taking the OpenAPI layer, which `base/repositories` reaches through\n * `query-schemas` and `result-schemas`.\n *\n * Both halves already speak `@venizia/ignis-filter`, so a consumer on another transport shares the\n * query vocabulary rather than translating into one.\n *\n * Weight is a contract, checked by `src/__tests__/bundle/browser-weight.test.ts`.\n */\n\nexport { AbstractRepository } from '@/base/repositories/core/abstract';\nexport { AbstractDataSource } from '@/base/datasources/abstract';\nexport { DataSourceRoot } from '@/base/datasources/root';\n\nexport type {\n ICreatableRepository,\n ICrudRepository,\n IDeletableRepository,\n IPersistableRepository,\n IReadableRepository,\n IRepository,\n IUpdatableRepository,\n} from '@/base/repositories/common/types/contracts';\n\nexport { DataRangeUtility } from '@/base/repositories/common/types/results';\n\n// How a client reads what an IGNIS server answers - shared by the http connector and any client\n// that reads the same server without it.\nexport { HttpResponseReader } from '@/base/repositories/common/response-reader';\nexport { HttpExtraRequest } from '@/base/repositories/common/extra-request';\nexport type { TExtraRequest, TExtraResult } from '@/base/repositories/common/extra-request';\n\n// What a repository on any transport raises and bounds itself by - the constants, the error codes,\n// and the helper an engine that lacks an operation throws through.\nexport {\n DEFAULT_LIMIT,\n DEFAULT_MAX_LIMIT,\n RepositoryOperationScopes,\n RepositoryTypes,\n} from '@/base/repositories/common/constants';\nexport type { TRepositoryType } from '@/base/repositories/common/constants';\nexport { CoreErrorCodes, SearchErrorCodes } from '@/common/error-codes';\nexport { NotSupportedUtility } from '@/utilities/not-supported.utility';\nexport type { TCount, TDataRange, TDataWithRange } from '@/base/repositories/common/types/results';\n\nexport type { IDataSource } from '@/base/datasources/common/types';\n\n// `IRepository` names an entity, so a consumer implementing the contract needs the base to extend.\n// Engine-neutral like the datasource: a name, `getSchema({ type })`, and an id type.\nexport { AbstractEntity } from '@/base/models/base';\nexport { AuditFields, SchemaTypes } from '@/base/models/common/constants';\nexport type { TIdSchemaType, TSchemaType } from '@/base/models/common';\n\n// The query vocabulary both transports share.\nexport type {\n TByIdFilter,\n TFields,\n TFilter,\n TInclusion,\n TRow,\n TSelectedRow,\n TWhere,\n} from '@venizia/ignis-filter';\n\n// What a repository on any transport needs to refuse a request filter that names a hidden property.\nexport { RequestFilterParts } from '@/base/repositories/common/request-filter-guard';\nexport type {\n IRequestFilterJudge,\n IRequestFilterShape,\n TRequestFilterPart,\n TRequestFilterPiece,\n} from '@/base/repositories/common/request-filter-guard';\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Zod-free by design: this barrel must stay reachable from a browser bundle. The OpenAPI schema
|
|
2
2
|
// builders that used to live here are under `base/controllers/common/`, with the REST surface.
|
|
3
3
|
export * from './not-supported.utility.js';
|
|
4
|
+
export * from './toggle.utility.js';
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,+FAA+F;AAC/F,cAAc,yBAAyB,CAAC","sourcesContent":["// Zod-free by design: this barrel must stay reachable from a browser bundle. The OpenAPI schema\n// builders that used to live here are under `base/controllers/common/`, with the REST surface.\nexport * from './not-supported.utility';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,+FAA+F;AAC/F,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC","sourcesContent":["// Zod-free by design: this barrel must stay reachable from a browser bundle. The OpenAPI schema\n// builders that used to live here are under `base/controllers/common/`, with the REST surface.\nexport * from './not-supported.utility';\nexport * from './toggle.utility';\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A feature that is on or off. `{ use: false }` is the whole off state; `{ use: true, ... }` carries
|
|
3
|
+
* the options. One shape for every switch, so an option is never read from a feature that is off.
|
|
4
|
+
* Shared by components and controllers.
|
|
5
|
+
*/
|
|
6
|
+
export type TToggle<Options extends object = Record<never, never>> = {
|
|
7
|
+
use: false;
|
|
8
|
+
} | ({
|
|
9
|
+
use: true;
|
|
10
|
+
} & Options);
|
|
11
|
+
/** Reads the `{ use }` switches a component or controller option is written with. */
|
|
12
|
+
export declare class ToggleUtility {
|
|
13
|
+
/** The only place a toggle's `use` is read. Narrowing here is what lets every caller reach the options without a cast. */
|
|
14
|
+
static isUsed<Options extends object>(toggle: TToggle<Options> | undefined): toggle is Extract<TToggle<Options>, {
|
|
15
|
+
use: true;
|
|
16
|
+
}>;
|
|
17
|
+
/** The options of a toggle that is on, without `use`; `undefined` when it is off or absent. */
|
|
18
|
+
static pick<Options extends object>(toggle: TToggle<Options> | undefined): Omit<Extract<TToggle<Options>, {
|
|
19
|
+
use: true;
|
|
20
|
+
}>, 'use'> | undefined;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=toggle.utility.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Reads the `{ use }` switches a component or controller option is written with. */
|
|
2
|
+
export class ToggleUtility {
|
|
3
|
+
/** The only place a toggle's `use` is read. Narrowing here is what lets every caller reach the options without a cast. */
|
|
4
|
+
static isUsed(toggle) {
|
|
5
|
+
return toggle !== undefined && toggle.use;
|
|
6
|
+
}
|
|
7
|
+
/** The options of a toggle that is on, without `use`; `undefined` when it is off or absent. */
|
|
8
|
+
static pick(toggle) {
|
|
9
|
+
if (!ToggleUtility.isUsed(toggle)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const { use: _use, ...options } = toggle;
|
|
13
|
+
return options;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=toggle.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.utility.js","sourceRoot":"","sources":["../../../src/utilities/toggle.utility.ts"],"names":[],"mappings":"AASA,qFAAqF;AACrF,MAAM,OAAO,aAAa;IACxB,0HAA0H;IAC1H,MAAM,CAAC,MAAM,CACX,MAAoC;QAEpC,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC;IAC5C,CAAC;IAED,+FAA+F;IAC/F,MAAM,CAAC,IAAI,CACT,MAAoC;QAEpC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;QAEzC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["/**\n * A feature that is on or off. `{ use: false }` is the whole off state; `{ use: true, ... }` carries\n * the options. One shape for every switch, so an option is never read from a feature that is off.\n * Shared by components and controllers.\n */\nexport type TToggle<Options extends object = Record<never, never>> =\n | { use: false }\n | ({ use: true } & Options);\n\n/** Reads the `{ use }` switches a component or controller option is written with. */\nexport class ToggleUtility {\n /** The only place a toggle's `use` is read. Narrowing here is what lets every caller reach the options without a cast. */\n static isUsed<Options extends object>(\n toggle: TToggle<Options> | undefined,\n ): toggle is Extract<TToggle<Options>, { use: true }> {\n return toggle !== undefined && toggle.use;\n }\n\n /** The options of a toggle that is on, without `use`; `undefined` when it is off or absent. */\n static pick<Options extends object>(\n toggle: TToggle<Options> | undefined,\n ): Omit<Extract<TToggle<Options>, { use: true }>, 'use'> | undefined {\n if (!ToggleUtility.isUsed(toggle)) {\n return undefined;\n }\n\n const { use: _use, ...options } = toggle;\n\n return options;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-kernel",
|
|
3
|
-
"version": "0.4.8
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "Browser-pure kernel of the IGNIS framework: dependency injection, lifecycle, REST controllers, repository and datasource abstractions, and the authentication and authorization seams. No node builtin and no server-only peer, so the same kernel serves a Bun server and a browser Worker.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@venizia/ignis-filter": "0.4.7
|
|
77
|
-
"@venizia/ignis-helpers": "0.4.8
|
|
78
|
-
"@venizia/ignis-inversion": "0.4.7
|
|
76
|
+
"@venizia/ignis-filter": "0.4.7",
|
|
77
|
+
"@venizia/ignis-helpers": "0.4.8",
|
|
78
|
+
"@venizia/ignis-inversion": "0.4.7",
|
|
79
79
|
"reflect-metadata": "^0.2.2"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/bun": "^1.4.3",
|
|
83
|
-
"@venizia/dev-configs": "0.4.8
|
|
83
|
+
"@venizia/dev-configs": "0.4.8",
|
|
84
84
|
"casbin": "^5.51.1",
|
|
85
85
|
"eslint": "^10.13.0",
|
|
86
86
|
"oxlint": "1.89.0",
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { IDataSourceMetadata, IModelMetadata, TRepositoryMetadata } from '../../helpers/inversion/index.js';
|
|
2
|
-
import type { IDataSource } from '../datasources/index.js';
|
|
3
|
-
import type { AbstractEntity } from '../models/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Registers a model class with its static schema and relations.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { model } from '@venizia/ignis';
|
|
10
|
-
* import { ModelFactory } from '@venizia/ignis-connectors/postgres';
|
|
11
|
-
* import { pgTable, serial, text } from 'drizzle-orm/pg-core';
|
|
12
|
-
*
|
|
13
|
-
* const noteTable = pgTable('Note', { id: serial('id').primaryKey(), body: text('body') });
|
|
14
|
-
*
|
|
15
|
-
* export @model({ settings: { query: { limit: { default: 20 } } } })
|
|
16
|
-
* class Note extends ModelFactory.defineEntity({ table: noteTable }) {}
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare const model: (input?: IModelMetadata) => ClassDecorator;
|
|
20
|
-
/**
|
|
21
|
-
* Registers a datasource with driver and auto-discovery settings.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import { datasource } from '@venizia/ignis';
|
|
26
|
-
* import { BasePostgresDataSource } from '@venizia/ignis-connectors/postgres';
|
|
27
|
-
* import { NodePostgresDriver } from '@venizia/ignis-connectors/postgres/node-postgres';
|
|
28
|
-
* import { Pool } from 'pg';
|
|
29
|
-
*
|
|
30
|
-
* export @datasource({ driver: NodePostgresDriver })
|
|
31
|
-
* class AppDataSource extends BasePostgresDataSource<{ connectionString: string }> {
|
|
32
|
-
* constructor() { super({ name: AppDataSource.name, config: { connectionString: 'postgres://localhost/app' } }); }
|
|
33
|
-
* override configure(): void { this.client = new Pool(this.settings); }
|
|
34
|
-
* override getConnectionString(): string { return this.settings.connectionString; }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare const datasource: (metadata?: IDataSourceMetadata) => ClassDecorator;
|
|
39
|
-
/**
|
|
40
|
-
* Class decorator that registers a repository and binds it to a model (or, for a remote repository, only a datasource). Called without arguments on a subclass it reuses the type, model and datasource of its nearest decorated parent; registration options are not inherited.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* import { repository } from '@venizia/ignis';
|
|
45
|
-
* import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';
|
|
46
|
-
* import { AppDataSource } from './app.datasource';
|
|
47
|
-
* import { Note, noteTable } from './note.model';
|
|
48
|
-
*
|
|
49
|
-
* export @repository({ model: Note, dataSource: AppDataSource })
|
|
50
|
-
* class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare const repository: <Model extends AbstractEntity = AbstractEntity, DataSource extends IDataSource = IDataSource>(metadata?: TRepositoryMetadata<Model, DataSource>) => ClassDecorator;
|
|
54
|
-
//# sourceMappingURL=persistents.d.ts.map
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import { BindingNamespaces } from '../../common/bindings.js';
|
|
2
|
-
import { ArtifactTypes, BindingKeys, MetadataKeys, MetadataRegistry } from '../../helpers/inversion/index.js';
|
|
3
|
-
import { ClassResolver, ResolverUtility } from '@venizia/ignis-helpers/common';
|
|
4
|
-
import { getError } from '@venizia/ignis-helpers/core';
|
|
5
|
-
import { DataSourceOpenModes, isDataSourceClass } from '../datasources/index.js';
|
|
6
|
-
import { RepositoryTypes } from '../repositories/common/constants.js';
|
|
7
|
-
import { injectable, InjectableUtility } from './injectable.js';
|
|
8
|
-
import { ModelMetadataUtility } from './model-metadata.js';
|
|
9
|
-
/**
|
|
10
|
-
* Registers a model class with its static schema and relations.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { model } from '@venizia/ignis';
|
|
15
|
-
* import { ModelFactory } from '@venizia/ignis-connectors/postgres';
|
|
16
|
-
* import { pgTable, serial, text } from 'drizzle-orm/pg-core';
|
|
17
|
-
*
|
|
18
|
-
* const noteTable = pgTable('Note', { id: serial('id').primaryKey(), body: text('body') });
|
|
19
|
-
*
|
|
20
|
-
* export @model({ settings: { query: { limit: { default: 20 } } } })
|
|
21
|
-
* class Note extends ModelFactory.defineEntity({ table: noteTable }) {}
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const model = (input = {}) => {
|
|
25
|
-
return (target) => {
|
|
26
|
-
injectable({
|
|
27
|
-
type: ArtifactTypes.MODEL,
|
|
28
|
-
...InjectableUtility.pickRegistrationOptions({ metadata: input }),
|
|
29
|
-
})(target);
|
|
30
|
-
const metadata = ModelMetadataUtility.normalizeModelMetadata({
|
|
31
|
-
model: target.name,
|
|
32
|
-
metadata: input,
|
|
33
|
-
});
|
|
34
|
-
const { settings } = metadata;
|
|
35
|
-
if (settings && Reflect.has(settings, 'hiddenProperties')) {
|
|
36
|
-
throw getError({
|
|
37
|
-
message: `[model][${target.name}] hiddenProperties was replaced by properties.hidden`,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const defaultLimit = settings?.query?.limit?.default;
|
|
41
|
-
if (defaultLimit !== undefined && (!Number.isInteger(defaultLimit) || defaultLimit <= 0)) {
|
|
42
|
-
throw getError({
|
|
43
|
-
message: `[model][${target.name}] Invalid 'query.limit.default' | Expected a positive integer | Got: ${defaultLimit}`,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
// Validated at DECORATION time, like the default limit: a bad ceiling is a wiring mistake, and
|
|
47
|
-
// catching it at boot beats catching it on the one request that happens to reach the limit.
|
|
48
|
-
const maxLimit = settings?.query?.limit?.max;
|
|
49
|
-
if (maxLimit !== undefined && (!Number.isInteger(maxLimit) || maxLimit <= 0)) {
|
|
50
|
-
throw getError({
|
|
51
|
-
message: `[model][${target.name}] Invalid 'query.limit.max' | Expected a positive integer | Got: ${maxLimit}`,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// Auto-populate AUTHORIZATION_SUBJECT from authorize.principal if not already set
|
|
55
|
-
const principal = settings?.authorize?.principal;
|
|
56
|
-
if (principal && !Object.hasOwn(target, 'AUTHORIZATION_SUBJECT')) {
|
|
57
|
-
target.AUTHORIZATION_SUBJECT = principal;
|
|
58
|
-
}
|
|
59
|
-
MetadataRegistry.getInstance().registerModel({ target, metadata });
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Registers a datasource with driver and auto-discovery settings.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* import { datasource } from '@venizia/ignis';
|
|
68
|
-
* import { BasePostgresDataSource } from '@venizia/ignis-connectors/postgres';
|
|
69
|
-
* import { NodePostgresDriver } from '@venizia/ignis-connectors/postgres/node-postgres';
|
|
70
|
-
* import { Pool } from 'pg';
|
|
71
|
-
*
|
|
72
|
-
* export @datasource({ driver: NodePostgresDriver })
|
|
73
|
-
* class AppDataSource extends BasePostgresDataSource<{ connectionString: string }> {
|
|
74
|
-
* constructor() { super({ name: AppDataSource.name, config: { connectionString: 'postgres://localhost/app' } }); }
|
|
75
|
-
* override configure(): void { this.client = new Pool(this.settings); }
|
|
76
|
-
* override getConnectionString(): string { return this.settings.connectionString; }
|
|
77
|
-
* }
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export const datasource = (metadata) => {
|
|
81
|
-
return (target) => {
|
|
82
|
-
const openTimeout = metadata?.open?.timeoutMs;
|
|
83
|
-
if (openTimeout !== undefined &&
|
|
84
|
-
(typeof openTimeout !== 'number' || !Number.isInteger(openTimeout) || openTimeout < 0)) {
|
|
85
|
-
throw getError({
|
|
86
|
-
message: `[datasource][@datasource][${target.name}] Invalid metadata | 'open.timeoutMs' must be a non-negative integer (ms; 0 waits for ever) | Got: ${String(openTimeout)}`,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const openMode = metadata?.open?.on;
|
|
90
|
-
// Untyped JS callers: a misspelt mode would silently mean "start", so it is refused where it is written.
|
|
91
|
-
if (openMode !== undefined && !DataSourceOpenModes.isValid(openMode)) {
|
|
92
|
-
throw getError({
|
|
93
|
-
message: `[datasource][@datasource][${target.name}] Invalid metadata | Unknown 'open.on': ${String(openMode)} | Expected one of: ${[...DataSourceOpenModes.SCHEME_SET].join(', ')}`,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
injectable({
|
|
97
|
-
type: ArtifactTypes.DATASOURCE,
|
|
98
|
-
...InjectableUtility.pickRegistrationOptions({ metadata: metadata ?? {} }),
|
|
99
|
-
})(target);
|
|
100
|
-
MetadataRegistry.getInstance().setDataSourceMetadata({ target, metadata });
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
/** Mirrors the `TRepositoryMetadata` union for JavaScript callers: a known type, a dataSource always, a model exactly when the type is RepositoryTypes.MODEL. */
|
|
104
|
-
const validateRepositoryMetadata = (opts) => {
|
|
105
|
-
const { metadata, target } = opts;
|
|
106
|
-
const type = metadata.type ?? RepositoryTypes.MODEL;
|
|
107
|
-
if (!RepositoryTypes.isValid(type)) {
|
|
108
|
-
throw getError({
|
|
109
|
-
message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Unknown 'type': ${type} | Expected one of: ${[...RepositoryTypes.SCHEME_SET].join(', ')}`,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (type === RepositoryTypes.MODEL && !metadata.model) {
|
|
113
|
-
throw getError({
|
|
114
|
-
message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'model'`,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (type === RepositoryTypes.REMOTE && metadata.model) {
|
|
118
|
-
throw getError({
|
|
119
|
-
message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | A '${RepositoryTypes.REMOTE}' repository takes no 'model'`,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
if (!metadata.dataSource) {
|
|
123
|
-
throw getError({
|
|
124
|
-
message: `[validateRepositoryMetadata][@repository][${target.name}] Invalid metadata | Missing 'dataSource'`,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
/** Asserts the constructor's first parameter is an AbstractDataSource compatible with what @repository declared. */
|
|
129
|
-
const validateFirstConstructorParameter = (opts) => {
|
|
130
|
-
const { target, firstParamType, resolvedDataSource } = opts;
|
|
131
|
-
// NOT `instanceof`: two copies of this package give two `AbstractDataSource` classes and the
|
|
132
|
-
// check would be false across them, rejecting a perfectly valid repository at import time.
|
|
133
|
-
const isDataSourceType = isDataSourceClass(firstParamType);
|
|
134
|
-
if (!isDataSourceType) {
|
|
135
|
-
throw getError({
|
|
136
|
-
message: `[@repository][${target.name}] Invalid constructor | First parameter must extend AbstractDataSource | Received: '${firstParamType.name}'`,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (typeof resolvedDataSource !== 'function') {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const isCompatible = firstParamType === resolvedDataSource || resolvedDataSource.prototype instanceof firstParamType;
|
|
143
|
-
if (!isCompatible) {
|
|
144
|
-
throw getError({
|
|
145
|
-
message: `[@repository][${target.name}] Invalid constructor | Type mismatch | Constructor expects '${firstParamType.name}' but @repository specifies '${resolvedDataSource.name}'`,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* Auto-injects dataSource at constructor param[0] unless explicit @inject exists. A class is injected
|
|
151
|
-
* by the class itself, so the container reads the key its registration recorded: a pinned
|
|
152
|
-
* `binding` and a minified class name both resolve. Only a string reference is a key.
|
|
153
|
-
*/
|
|
154
|
-
const registerDataSourceInjection = (opts) => {
|
|
155
|
-
const { target, registry, dataSourceRef, resolvedDataSource } = opts;
|
|
156
|
-
// Own metadata only: `getInjectMetadata` walks the prototype chain, so a repository extending another @repository class would see the BASE's injection at param[0] and silently resolve the base's dataSource.
|
|
157
|
-
const ownInjects = Reflect.getOwnMetadata(MetadataKeys.INJECT, target);
|
|
158
|
-
const injectAtIndex0 = ownInjects?.find((entry) => entry?.index === 0);
|
|
159
|
-
if (injectAtIndex0) {
|
|
160
|
-
// `@inject({ target })` carries no key; read the one recorded on the class. The function form
|
|
161
|
-
// resolves through the same helper the container uses, so both paths read one class.
|
|
162
|
-
const injectedTarget = injectAtIndex0.target
|
|
163
|
-
? ResolverUtility.resolveInjectTarget({ target: injectAtIndex0.target })
|
|
164
|
-
: undefined;
|
|
165
|
-
const injectKey = injectAtIndex0.key ??
|
|
166
|
-
(injectedTarget ? registry.getBindingKey({ target: injectedTarget }) : undefined);
|
|
167
|
-
// A class is judged by its brand: its key may sit under any namespace a `binding` pinned, and
|
|
168
|
-
// a provisional key may still change at registration. Only a bare key is judged by its prefix.
|
|
169
|
-
const isDataSourceTarget = injectedTarget
|
|
170
|
-
? isDataSourceClass(injectedTarget)
|
|
171
|
-
: typeof injectKey === 'string' && injectKey.startsWith(`${BindingNamespaces.DATASOURCE}.`);
|
|
172
|
-
if (!isDataSourceTarget) {
|
|
173
|
-
throw getError({
|
|
174
|
-
message: `[@repository][${target.name}] Invalid constructor | First parameter must be a DataSource | Found @inject with key: '${String(injectKey)}' | Expected a key starting with '${BindingNamespaces.DATASOURCE}.' or a DataSource class`,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
// Checked only when this decorator writes the injection: an explicit @inject decides for itself.
|
|
180
|
-
// An interface emits `Object` and a type-only class import emits `Function` under tsc (`Object`
|
|
181
|
-
// under bun); neither names the class, so neither is judged.
|
|
182
|
-
const firstParamType = Reflect.getMetadata('design:paramtypes', target)?.[0];
|
|
183
|
-
if (firstParamType && firstParamType !== Object && firstParamType !== Function) {
|
|
184
|
-
validateFirstConstructorParameter({ target, firstParamType, resolvedDataSource });
|
|
185
|
-
}
|
|
186
|
-
// The inherited list is the base repository's own, and setInjectMetadata may write straight into it.
|
|
187
|
-
if (!ownInjects) {
|
|
188
|
-
Reflect.defineMetadata(MetadataKeys.INJECT, [...(registry.getInjectMetadata({ target }) ?? [])], target);
|
|
189
|
-
}
|
|
190
|
-
const derivedKey = BindingKeys.build({
|
|
191
|
-
namespace: BindingNamespaces.DATASOURCE,
|
|
192
|
-
key: typeof resolvedDataSource === 'string' ? resolvedDataSource : resolvedDataSource.name,
|
|
193
|
-
});
|
|
194
|
-
// The class first, decided when the repository is resolved: by then any registration - decorated,
|
|
195
|
-
// `bindingList()`, or `dataSource(X, { binding })` - has recorded its key on the class. The derived
|
|
196
|
-
// key is the fallback for a class nothing recorded, bound by hand under exactly that key.
|
|
197
|
-
registry.setInjectMetadata({
|
|
198
|
-
target,
|
|
199
|
-
index: 0,
|
|
200
|
-
metadata: typeof dataSourceRef === 'string'
|
|
201
|
-
? { key: derivedKey, index: 0, isOptional: false }
|
|
202
|
-
: { target: dataSourceRef, key: derivedKey, index: 0, isOptional: false },
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
/** Resolves repository metadata and registers bindings for schema auto-discovery. */
|
|
206
|
-
const resolveRepositoryMetadata = (opts) => {
|
|
207
|
-
const { metadata, target, registry } = opts;
|
|
208
|
-
validateRepositoryMetadata({ metadata, target });
|
|
209
|
-
const resolvedDataSource = ClassResolver.resolveClass({ ref: metadata.dataSource });
|
|
210
|
-
if (!resolvedDataSource) {
|
|
211
|
-
throw getError({
|
|
212
|
-
message: `[@repository][${target.name}] The dataSource resolver returned nothing at decoration time | An import cycle leaves the datasource class undefined here; import it without the cycle, or name it as a string`,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
// No model, so no binding: the datasource owns no schema through this repository.
|
|
216
|
-
if (metadata.type === RepositoryTypes.REMOTE) {
|
|
217
|
-
registerDataSourceInjection({
|
|
218
|
-
target,
|
|
219
|
-
registry,
|
|
220
|
-
dataSourceRef: metadata.dataSource,
|
|
221
|
-
resolvedDataSource,
|
|
222
|
-
});
|
|
223
|
-
return {
|
|
224
|
-
type: RepositoryTypes.REMOTE,
|
|
225
|
-
dataSource: resolvedDataSource,
|
|
226
|
-
operationScope: metadata.operationScope,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const resolvedModel = ResolverUtility.resolveValue({ value: metadata.model });
|
|
230
|
-
registry.registerRepositoryBinding({
|
|
231
|
-
repository: target,
|
|
232
|
-
model: resolvedModel,
|
|
233
|
-
dataSource: resolvedDataSource,
|
|
234
|
-
});
|
|
235
|
-
registerDataSourceInjection({
|
|
236
|
-
target,
|
|
237
|
-
registry,
|
|
238
|
-
dataSourceRef: metadata.dataSource,
|
|
239
|
-
resolvedDataSource,
|
|
240
|
-
});
|
|
241
|
-
return {
|
|
242
|
-
type: RepositoryTypes.MODEL,
|
|
243
|
-
model: resolvedModel,
|
|
244
|
-
dataSource: resolvedDataSource,
|
|
245
|
-
operationScope: metadata.operationScope,
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
/** A bare `@repository()` on a subclass reuses the type, model and datasource its nearest decorated parent declared; the registration options (`binding`, `when`, ...) are never inherited, so the subclass registers under its own name. */
|
|
249
|
-
const inheritRepositoryMetadata = (opts) => {
|
|
250
|
-
// Own metadata does not exist yet at decoration time, so this read walks the prototype chain.
|
|
251
|
-
const inherited = opts.registry.getRepositoryMetadata({ target: opts.target });
|
|
252
|
-
if (!inherited) {
|
|
253
|
-
throw getError({
|
|
254
|
-
message: `[@repository][${opts.target.name}] No metadata given and no decorated repository above it in the prototype chain | pass { model, dataSource } or decorate the parent`,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (inherited.type === RepositoryTypes.REMOTE) {
|
|
258
|
-
const { type, dataSource, operationScope } = inherited;
|
|
259
|
-
return { type, dataSource, operationScope };
|
|
260
|
-
}
|
|
261
|
-
const { type, model: parentModel, dataSource, operationScope } = inherited;
|
|
262
|
-
return { type, model: parentModel, dataSource, operationScope };
|
|
263
|
-
};
|
|
264
|
-
const applyRepositoryMetadata = (opts) => {
|
|
265
|
-
const { metadata, registration, target, registry } = opts;
|
|
266
|
-
injectable({
|
|
267
|
-
type: ArtifactTypes.REPOSITORY,
|
|
268
|
-
...InjectableUtility.pickRegistrationOptions({ metadata: registration }),
|
|
269
|
-
})(target);
|
|
270
|
-
const resolved = resolveRepositoryMetadata({ metadata, target, registry });
|
|
271
|
-
registry.setRepositoryMetadata({ target, metadata: { ...metadata, _resolved: resolved } });
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* Class decorator that registers a repository and binds it to a model (or, for a remote repository, only a datasource). Called without arguments on a subclass it reuses the type, model and datasource of its nearest decorated parent; registration options are not inherited.
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```typescript
|
|
278
|
-
* import { repository } from '@venizia/ignis';
|
|
279
|
-
* import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';
|
|
280
|
-
* import { AppDataSource } from './app.datasource';
|
|
281
|
-
* import { Note, noteTable } from './note.model';
|
|
282
|
-
*
|
|
283
|
-
* export @repository({ model: Note, dataSource: AppDataSource })
|
|
284
|
-
* class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
export const repository = (metadata) => {
|
|
288
|
-
return (target) => {
|
|
289
|
-
const registry = MetadataRegistry.getInstance();
|
|
290
|
-
if (!metadata) {
|
|
291
|
-
applyRepositoryMetadata({
|
|
292
|
-
metadata: inheritRepositoryMetadata({ target, registry }),
|
|
293
|
-
registration: {},
|
|
294
|
-
target,
|
|
295
|
-
registry,
|
|
296
|
-
});
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
applyRepositoryMetadata({ metadata, registration: metadata, target, registry });
|
|
300
|
-
};
|
|
301
|
-
};
|
|
302
|
-
//# sourceMappingURL=persistents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persistents.js","sourceRoot":"","sources":["../../../../src/base/metadata/persistents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAQtD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CA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UAAU,GAAG,CAIxB,QAAiD,EACjC,EAAE;IAClB,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAEhD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,uBAAuB,CAAC;gBACtB,QAAQ,EAAE,yBAAyB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACzD,YAAY,EAAE,EAAE;gBAChB,MAAM;gBACN,QAAQ;aACT,CAAC,CAAC;YAEH,OAAO;QACT,CAAC;QAED,uBAAuB,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { BindingNamespaces } from '@/common/bindings';\nimport type {\n IArtifactRegistrationOptions,\n IDataSourceMetadata,\n IModelMetadata,\n IResolvedRepositoryMetadata,\n TRepositoryMetadata,\n} from '@/helpers/inversion';\nimport { ArtifactTypes, BindingKeys, MetadataKeys, MetadataRegistry } from '@/helpers/inversion';\nimport { ClassResolver, ResolverUtility } from '@venizia/ignis-helpers/common';\nimport type { IInjectMetadata } from '@venizia/ignis-inversion';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IDataSource } from '../datasources';\nimport { DataSourceOpenModes, isDataSourceClass } from '../datasources';\nimport type { AbstractEntity } from '../models';\nimport { RepositoryTypes } from '../repositories/common/constants';\nimport { injectable, InjectableUtility } from './injectable';\nimport { ModelMetadataUtility } from './model-metadata';\n\n/**\n * Registers a model class with its static schema and relations.\n *\n * @example\n * ```typescript\n * import { model } from '@venizia/ignis';\n * import { ModelFactory } from '@venizia/ignis-connectors/postgres';\n * import { pgTable, serial, text } from 'drizzle-orm/pg-core';\n *\n * const noteTable = pgTable('Note', { id: serial('id').primaryKey(), body: text('body') });\n *\n * export @model({ settings: { query: { limit: { default: 20 } } } })\n * class Note extends ModelFactory.defineEntity({ table: noteTable }) {}\n * ```\n */\nexport const model = (input: IModelMetadata = {}): ClassDecorator => {\n return (target) => {\n injectable({\n type: ArtifactTypes.MODEL,\n ...InjectableUtility.pickRegistrationOptions({ metadata: input }),\n })(target);\n\n const metadata = ModelMetadataUtility.normalizeModelMetadata({\n model: target.name,\n metadata: input,\n });\n\n const { settings } = metadata;\n\n if (settings && Reflect.has(settings, 'hiddenProperties')) {\n throw getError({\n message: `[model][${target.name}] hiddenProperties was replaced by properties.hidden`,\n });\n }\n\n const defaultLimit = settings?.query?.limit?.default;\n\n if (defaultLimit !== undefined && (!Number.isInteger(defaultLimit) || defaultLimit <= 0)) {\n throw getError({\n message: `[model][${target.name}] Invalid 'query.limit.default' | Expected a positive integer | Got: ${defaultLimit}`,\n });\n }\n\n // Validated at DECORATION time, like the default limit: a bad ceiling is a wiring mistake, and\n // catching it at boot beats catching it on the one request that happens to reach the limit.\n const maxLimit = settings?.query?.limit?.max;\n\n if (maxLimit !== undefined && (!Number.isInteger(maxLimit) || maxLimit <= 0)) {\n throw getError({\n message: `[model][${target.name}] Invalid 'query.limit.max' | Expected a positive integer | Got: ${maxLimit}`,\n });\n }\n\n // Auto-populate AUTHORIZATION_SUBJECT from authorize.principal if not already set\n const principal = settings?.authorize?.principal;\n\n if (principal && !Object.hasOwn(target, 'AUTHORIZATION_SUBJECT')) {\n (target as Record<string, unknown>).AUTHORIZATION_SUBJECT = principal;\n }\n\n MetadataRegistry.getInstance().registerModel({ target, metadata });\n };\n};\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.SCHEME_SET].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\n/** Mirrors the `TRepositoryMetadata` union for JavaScript callers: a known type, a dataSource always, a model exactly when the type is RepositoryTypes.MODEL. */\nconst 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.SCHEME_SET].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 an AbstractDataSource compatible with what @repository declared. */\nconst 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 `AbstractDataSource` 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 | 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\n/**\n * Auto-injects dataSource at constructor param[0] unless explicit @inject exists. A class is injected\n * by the class itself, so the container reads the key its registration recorded: a pinned\n * `binding` and a minified class name both resolve. Only a string reference is a key.\n */\nconst registerDataSourceInjection = (opts: {\n target: Function;\n registry: MetadataRegistry;\n dataSourceRef: TRepositoryMetadata['dataSource'];\n resolvedDataSource: string | Function;\n}): void => {\n const { target, registry, dataSourceRef, resolvedDataSource } = opts;\n\n // Own metadata only: `getInjectMetadata` walks the prototype chain, so a repository extending another @repository class would see the BASE's injection at param[0] and silently resolve the base's dataSource.\n const ownInjects: IInjectMetadata[] | undefined = Reflect.getOwnMetadata(\n MetadataKeys.INJECT,\n target,\n );\n const injectAtIndex0 = ownInjects?.find((entry) => entry?.index === 0);\n\n if (injectAtIndex0) {\n // `@inject({ target })` carries no key; read the one recorded on the class. The function form\n // resolves through the same helper the container uses, so both paths read one class.\n const injectedTarget = injectAtIndex0.target\n ? ResolverUtility.resolveInjectTarget({ target: injectAtIndex0.target })\n : undefined;\n const injectKey =\n injectAtIndex0.key ??\n (injectedTarget ? registry.getBindingKey({ target: injectedTarget }) : undefined);\n\n // A class is judged by its brand: its key may sit under any namespace a `binding` pinned, and\n // a provisional key may still change at registration. Only a bare key is judged by its prefix.\n const isDataSourceTarget = injectedTarget\n ? isDataSourceClass(injectedTarget)\n : typeof injectKey === 'string' && injectKey.startsWith(`${BindingNamespaces.DATASOURCE}.`);\n\n if (!isDataSourceTarget) {\n throw getError({\n message: `[@repository][${target.name}] Invalid constructor | First parameter must be a DataSource | Found @inject with key: '${String(injectKey)}' | Expected a key starting with '${BindingNamespaces.DATASOURCE}.' or a DataSource class`,\n });\n }\n\n return;\n }\n\n // Checked only when this decorator writes the injection: an explicit @inject decides for itself.\n // An interface emits `Object` and a type-only class import emits `Function` under tsc (`Object`\n // under bun); neither names the class, so neither is judged.\n const firstParamType = Reflect.getMetadata('design:paramtypes', target)?.[0];\n\n if (firstParamType && firstParamType !== Object && firstParamType !== Function) {\n validateFirstConstructorParameter({ target, firstParamType, resolvedDataSource });\n }\n\n // The inherited list is the base repository's own, and setInjectMetadata may write straight into it.\n if (!ownInjects) {\n Reflect.defineMetadata(\n MetadataKeys.INJECT,\n [...(registry.getInjectMetadata({ target }) ?? [])],\n target,\n );\n }\n\n const derivedKey = BindingKeys.build({\n namespace: BindingNamespaces.DATASOURCE,\n key: typeof resolvedDataSource === 'string' ? resolvedDataSource : resolvedDataSource.name,\n });\n\n // The class first, decided when the repository is resolved: by then any registration - decorated,\n // `bindingList()`, or `dataSource(X, { binding })` - has recorded its key on the class. The derived\n // key is the fallback for a class nothing recorded, bound by hand under exactly that key.\n registry.setInjectMetadata({\n target,\n index: 0,\n metadata:\n typeof dataSourceRef === 'string'\n ? { key: derivedKey, index: 0, isOptional: false }\n : { target: dataSourceRef, key: derivedKey, index: 0, isOptional: false },\n });\n};\n\n/** Resolves repository metadata and registers bindings for schema auto-discovery. */\nconst resolveRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n target: Function;\n registry: MetadataRegistry;\n}): IResolvedRepositoryMetadata<Model, DataSource> => {\n const { metadata, target, registry } = opts;\n\n validateRepositoryMetadata({ metadata, target });\n\n const resolvedDataSource = ClassResolver.resolveClass({ ref: metadata.dataSource });\n\n if (!resolvedDataSource) {\n throw getError({\n message: `[@repository][${target.name}] The dataSource resolver returned nothing at decoration time | An import cycle leaves the datasource class undefined here; import it without the cycle, or name it as a string`,\n });\n }\n\n // No model, so no binding: the datasource owns no schema through this repository.\n if (metadata.type === RepositoryTypes.REMOTE) {\n registerDataSourceInjection({\n target,\n registry,\n dataSourceRef: metadata.dataSource,\n resolvedDataSource,\n });\n\n return {\n type: RepositoryTypes.REMOTE,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n }\n\n const resolvedModel = ResolverUtility.resolveValue({ value: metadata.model });\n\n registry.registerRepositoryBinding({\n repository: target,\n model: resolvedModel,\n dataSource: resolvedDataSource,\n });\n\n registerDataSourceInjection({\n target,\n registry,\n dataSourceRef: metadata.dataSource,\n resolvedDataSource,\n });\n\n return {\n type: RepositoryTypes.MODEL,\n model: resolvedModel,\n dataSource: resolvedDataSource,\n operationScope: metadata.operationScope,\n };\n};\n\n/** A bare `@repository()` on a subclass reuses the type, model and datasource its nearest decorated parent declared; the registration options (`binding`, `when`, ...) are never inherited, so the subclass registers under its own name. */\nconst inheritRepositoryMetadata = (opts: {\n target: Function;\n registry: MetadataRegistry;\n}): TRepositoryMetadata => {\n // Own metadata does not exist yet at decoration time, so this read walks the prototype chain.\n const inherited = opts.registry.getRepositoryMetadata({ target: opts.target });\n\n if (!inherited) {\n throw getError({\n message: `[@repository][${opts.target.name}] No metadata given and no decorated repository above it in the prototype chain | pass { model, dataSource } or decorate the parent`,\n });\n }\n\n if (inherited.type === RepositoryTypes.REMOTE) {\n const { type, dataSource, operationScope } = inherited;\n\n return { type, dataSource, operationScope };\n }\n\n const { type, model: parentModel, dataSource, operationScope } = inherited;\n\n return { type, model: parentModel, dataSource, operationScope };\n};\n\nconst applyRepositoryMetadata = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(opts: {\n metadata: TRepositoryMetadata<Model, DataSource>;\n registration: IArtifactRegistrationOptions;\n target: Function;\n registry: MetadataRegistry;\n}): void => {\n const { metadata, registration, target, registry } = opts;\n injectable({\n type: ArtifactTypes.REPOSITORY,\n ...InjectableUtility.pickRegistrationOptions({ metadata: registration }),\n })(target);\n\n const resolved = resolveRepositoryMetadata({ metadata, target, registry });\n\n registry.setRepositoryMetadata({ target, metadata: { ...metadata, _resolved: resolved } });\n};\n\n/**\n * Class decorator that registers a repository and binds it to a model (or, for a remote repository, only a datasource). Called without arguments on a subclass it reuses the type, model and datasource of its nearest decorated parent; registration options are not inherited.\n *\n * @example\n * ```typescript\n * import { repository } from '@venizia/ignis';\n * import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';\n * import { AppDataSource } from './app.datasource';\n * import { Note, noteTable } from './note.model';\n *\n * export @repository({ model: Note, dataSource: AppDataSource })\n * class NoteRepository extends DefaultCRUDRepository<typeof noteTable> {}\n * ```\n */\nexport const repository = <\n Model extends AbstractEntity = AbstractEntity,\n DataSource extends IDataSource = IDataSource,\n>(\n metadata?: TRepositoryMetadata<Model, DataSource>,\n): ClassDecorator => {\n return (target) => {\n const registry = MetadataRegistry.getInstance();\n\n if (!metadata) {\n applyRepositoryMetadata({\n metadata: inheritRepositoryMetadata({ target, registry }),\n registration: {},\n target,\n registry,\n });\n\n return;\n }\n\n applyRepositoryMetadata({ metadata, registration: metadata, target, registry });\n };\n};\n"]}
|