@stratal/framework 0.0.0-canary-ccb3f17 → 0.0.0-canary-e5681b8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +655 -0
- package/README.md +166 -24
- package/dist/access-control/index.d.mts +8 -8
- package/dist/access-control/index.d.mts.map +1 -1
- package/dist/access-control/index.mjs +2 -2
- package/dist/{access.service-rsEreT-4.mjs → access.service-BjmnWBEo.mjs} +3 -3
- package/dist/{access.service-rsEreT-4.mjs.map → access.service-BjmnWBEo.mjs.map} +1 -1
- package/dist/auth/index.d.mts +49 -48
- package/dist/auth/index.d.mts.map +1 -1
- package/dist/auth/index.mjs +86 -17
- package/dist/auth/index.mjs.map +1 -1
- package/dist/{auth-context-CE_-TV27.mjs → auth-context-cNSS1rmh.mjs} +2 -2
- package/dist/{auth-context-CE_-TV27.mjs.map → auth-context-cNSS1rmh.mjs.map} +1 -1
- package/dist/context/index.d.mts +3 -3
- package/dist/context/index.d.mts.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/database/index.d.mts +3 -3
- package/dist/database/index.mjs +288 -9
- package/dist/database/index.mjs.map +1 -1
- package/dist/{decorate-ZDdbRmsv.mjs → decorate-RQD1h28J.mjs} +1 -1
- package/dist/{decorateParam-DQ95ttaa.mjs → decorateParam-xwTkq9gO.mjs} +2 -2
- package/dist/{decorateParam-DQ95ttaa.mjs.map → decorateParam-xwTkq9gO.mjs.map} +1 -1
- package/dist/factory/index.d.mts +3 -4
- package/dist/factory/index.d.mts.map +1 -1
- package/dist/guards/index.d.mts +3 -3
- package/dist/guards/index.d.mts.map +1 -1
- package/dist/guards/index.mjs +4 -4
- package/dist/index-e_u1SRyd.d.mts +921 -0
- package/dist/index-e_u1SRyd.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/{types-DjLXYLlD.d.mts → types-B35g-lXi.d.mts} +18 -3
- package/dist/types-B35g-lXi.d.mts.map +1 -0
- package/package.json +29 -25
- package/dist/index-B8EVn7T5.d.mts +0 -481
- package/dist/index-B8EVn7T5.d.mts.map +0 -1
- package/dist/types-DjLXYLlD.d.mts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-e_u1SRyd.d.mts","names":[],"sources":["../src/database/database.module.ts","../src/database/pagination/cursor.ts","../src/database/pagination/cursor-reader.ts","../src/database/database.service.ts","../src/database/database.tokens.ts","../src/database/pool.ts","../src/database/decorators/inject-db.decorator.ts","../src/database/errors/cursor-model-unavailable.error.ts","../src/database/errors/cursor-ordering.error.ts","../src/database/errors/malformed-cursor.error.ts","../src/database/errors/record-not-found.error.ts","../src/database/errors/unique-constraint.error.ts","../src/database/errors/from-zenstack-error.ts","../src/database/event-types.ts","../src/database/i18n/en.ts","../src/database/plugins/error-handler.plugin.ts","../src/database/plugins/event-emitter.plugin.ts","../src/database/plugins/schema-switcher.ts","../src/database/commands/zenstack.command.ts","../src/database/commands/db-generate.command.ts","../src/database/commands/db-pull.command.ts","../src/database/commands/db-push.command.ts","../src/database/commands/migrate-deploy.command.ts","../src/database/commands/migrate-dev.command.ts","../src/database/commands/migrate-reset.command.ts","../src/database/commands/migrate-status.command.ts"],"mappings":";;;;;;;;;UA0BiB,yBACf,eAAe,YAAY,WAC3B,aAAa,iBAAiB;EAE9B,MAAM;EACN,QAAQ;EACR,eAAe,cAAc;EAC7B,UAAU;;;;;;EAMV,iBAAiB,sBAAsB;;UAGxB;EACf,SAAS;EACT,aAAa;;cAiBF,0BAA0B,cAAc;mBAClC;SAEV,QAAQ,QAAQ,uBAAuB;SASvC,aAAa,SAAS,mBAAmB,wBAAwB;EAalE,aAAa,SAAS,gBAAgB;EA8BtC,WAAW,SAAS,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;KC7FhC;;;;;;;;;KAUA,gBAAgB,eAAe;UAE1B;;;;;;EAMf;;EAEA;;;;;;EAMA,SAAS,gBAAgB;;;;;;;;EAQzB;;EAEA,QAAQ;;;;;;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,OAAA,WAAA,MAAA;IACL;IACA;IACA,MAAM;IACN,UAAU,MAAM,wCAAwC;QACtD;;;;;;;;;;;;;;;cCjHO;SACJ,MAAM,GAAG,QAAQ,GAAG,qBAAqB;;;;;;;;uBCX5B,wBAAwB;YAC5B,SAAS,iBAAiB;;;;cCL/B,0BAA0B;SAC9B;SACA;EAED,UAAU;;;;cCJL,sBAAsB;SAC1B;SACA;EAED,UAAU;;;;cCJL,sBAAsB;SAC1B;SACA;EAED,UAAU;;;;cCJL,6BAA6B;SACjC;SACA;EAED,UAAU;;;;cCJL,0BAA0B;SAC9B;SACA;EAED,UAAU;;;;cCJL,4BAA4B;SAChC;SACA;EAED,UAAU;;;;cCJL,6BAA6B;SACjC;SACA;EAED,UAAU"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as InferAnySchema, l as StratalDatabase, o as InferConnectionExtensions, r as DefaultConnectionName, s as InferConnectionSchema, t as ConnectionName } from "./types-B35g-lXi.mjs";
|
|
2
2
|
import { CustomEventRegistry, EventName } from "stratal/events";
|
|
3
3
|
export type { ConnectionName, CustomEventRegistry, DefaultConnectionName, EventName, InferAnySchema, InferConnectionExtensions, InferConnectionSchema, StratalDatabase };
|
|
@@ -32,7 +32,22 @@ import { SchemaDef } from "@zenstackhq/schema";
|
|
|
32
32
|
interface StratalDatabase {}
|
|
33
33
|
/** Extract `ExtQueryArgs` from a `RuntimePlugin` */
|
|
34
34
|
type ExtractPluginQueryArgs<P> = P extends RuntimePlugin<infer _S, infer Q, infer _M, infer _R> ? Q : {};
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Drops index signatures, keeping the members a type actually declares.
|
|
37
|
+
*
|
|
38
|
+
* `ExtClientMembers` is constrained to `Record<string, unknown>`, so every
|
|
39
|
+
* plugin's member type carries an index signature. Letting one reach the client
|
|
40
|
+
* type is not cosmetic: it survives `$transaction`'s `Omit` and collapses every
|
|
41
|
+
* model delegate on a transaction client to `unknown`.
|
|
42
|
+
*/
|
|
43
|
+
type DeclaredMembers<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]; };
|
|
44
|
+
/**
|
|
45
|
+
* Extract `ExtClientMembers` from a `RuntimePlugin`.
|
|
46
|
+
*
|
|
47
|
+
* Exported because the built-in plugins `createDatabaseService` always registers
|
|
48
|
+
* go through this same extraction, so their members reach the client type by the
|
|
49
|
+
* path an app's own plugins take rather than by a second hand-written copy.
|
|
50
|
+
*/
|
|
36
51
|
type ExtractPluginClientMembers<P> = P extends RuntimePlugin<infer _S, infer _Q, infer M, infer _R> ? M : {};
|
|
37
52
|
/** Extract `ExtResult` from a `RuntimePlugin` */
|
|
38
53
|
type ExtractPluginResult<P> = P extends RuntimePlugin<infer _S, infer _Q, infer _M, infer R> ? R : {};
|
|
@@ -87,5 +102,5 @@ interface InternalDatabaseEventContext {
|
|
|
87
102
|
result?: unknown;
|
|
88
103
|
}
|
|
89
104
|
//#endregion
|
|
90
|
-
export {
|
|
91
|
-
//# sourceMappingURL=types-
|
|
105
|
+
export { InferAnySchema as a, InternalDatabaseEventContext as c, ExtractPluginClientMembers as i, StratalDatabase as l, DeclaredMembers as n, InferConnectionExtensions as o, DefaultConnectionName as r, InferConnectionSchema as s, ConnectionName as t };
|
|
106
|
+
//# sourceMappingURL=types-B35g-lXi.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-B35g-lXi.d.mts","names":[],"sources":["../src/database/types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+BiB;;KAGZ,uBAAuB,KAC1B,UAAU,oBAAoB,UAAU,SAAS,UAAU,MAAM;;;;;;;;;KAUvD,gBAAgB,QACzB,WAAW,oBAAoB,2BAA2B,YAAY,IAAI,EAAE;;;;;;;;KAUnE,2BAA2B,KACrC,UAAU,oBAAoB,UAAU,UAAU,SAAS,MAAM;;KAG9D,oBAAoB,KACvB,UAAU,oBAAoB,UAAU,UAAU,UAAU,KAAK;;KAG9D,aAAa,6BAChB,uBAAuB,YAAY;EAE7B,cAAc,uBAAuB,KAAK,aAAa;EACvD,kBAAkB,2BAA2B,KAAK,aAAa;EAC/D,WAAW,oBAAoB,KAAK,aAAa;;EAEjD;EAAkB;EAAsB;;;KAGpC,0BAA0B,oBACpC;EAA0B,eAAe;IACrC,gBAAgB,IACd,EAAE,uBACA,aAAa,EAAE;EACb;EAAkB;EAAsB;;EAC1C;EAAkB;EAAsB;;EAC1C;EAAkB;EAAsB;;;KAGpC,sBAAsB,oBAChC;EAA0B,eAAe;IACrC,gBAAgB,IAAI,EAAE,WAAW,YAAY,EAAE,KAAK,YAAY,YAChE;;KAGM,iBACV;EAA0B,eAAe;IACrC,QAAQ,WAAW,YAAY,QAAQ,KAAK,YAC5C;;KAGM,iBACV;EAA0B,eAAe;UAC/B,2BAA2B,cAAc;;KAIzC,wBACV;EAA0B,yBAAyB;IAAqB;;;;;UAMzD;EACf;EACA"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stratal/framework",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-e5681b8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"author":
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Temitayo Fadojutimi",
|
|
8
|
+
"url": "https://x.com/adesege_"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://stratal.dev",
|
|
7
11
|
"repository": {
|
|
8
12
|
"type": "git",
|
|
9
13
|
"url": "git+https://github.com/strataljs/stratal.git",
|
|
@@ -67,7 +71,7 @@
|
|
|
67
71
|
"lint:fix": "npx oxlint --fix ."
|
|
68
72
|
},
|
|
69
73
|
"dependencies": {
|
|
70
|
-
"@faker-js/faker": "^10.
|
|
74
|
+
"@faker-js/faker": "^10.6.0",
|
|
71
75
|
"postgres-array": "^3.0.4"
|
|
72
76
|
},
|
|
73
77
|
"peerDependencies": {
|
|
@@ -76,30 +80,30 @@
|
|
|
76
80
|
"@zenstackhq/schema": ">=3.6",
|
|
77
81
|
"better-auth": ">=1.6",
|
|
78
82
|
"pg": "^8.0.0",
|
|
79
|
-
"stratal": "0.0.0-canary-
|
|
83
|
+
"stratal": "0.0.0-canary-e5681b8"
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
82
|
-
"@better-auth/core": "^1.
|
|
83
|
-
"@cloudflare/vitest-
|
|
84
|
-
"@cloudflare/workers-types": "5.
|
|
85
|
-
"@stratal/testing": "
|
|
86
|
-
"@types/node": "^26.
|
|
87
|
-
"@types/pg": "^8.
|
|
88
|
-
"@vitest/coverage-istanbul": "~4.1.
|
|
89
|
-
"@vitest/runner": "~4.1.
|
|
90
|
-
"@vitest/snapshot": "~4.1.
|
|
91
|
-
"@zenstackhq/better-auth": "^3.
|
|
92
|
-
"@zenstackhq/cli": "^3.
|
|
93
|
-
"@zenstackhq/orm": "^3.
|
|
94
|
-
"@zenstackhq/schema": "^3.
|
|
95
|
-
"better-auth": "^1.
|
|
96
|
-
"better-call": "1.
|
|
86
|
+
"@better-auth/core": "^1.7.5",
|
|
87
|
+
"@cloudflare/vitest-plugin": "^1.1.13",
|
|
88
|
+
"@cloudflare/workers-types": "5.20260919.1",
|
|
89
|
+
"@stratal/testing": "^0.0.0-canary-e5681b8",
|
|
90
|
+
"@types/node": "^26.6.2",
|
|
91
|
+
"@types/pg": "^8.23.1",
|
|
92
|
+
"@vitest/coverage-istanbul": "~4.1.11",
|
|
93
|
+
"@vitest/runner": "~4.1.11",
|
|
94
|
+
"@vitest/snapshot": "~4.1.11",
|
|
95
|
+
"@zenstackhq/better-auth": "^3.9.4",
|
|
96
|
+
"@zenstackhq/cli": "^3.9.4",
|
|
97
|
+
"@zenstackhq/orm": "^3.9.4",
|
|
98
|
+
"@zenstackhq/schema": "^3.9.4",
|
|
99
|
+
"better-auth": "^1.7.5",
|
|
100
|
+
"better-call": "1.4.0",
|
|
97
101
|
"dotenv-cli": "^11.0.0",
|
|
98
|
-
"pg": "^8.
|
|
99
|
-
"stratal": "
|
|
100
|
-
"tsdown": "^0.
|
|
102
|
+
"pg": "^8.23.0",
|
|
103
|
+
"stratal": "0.0.0-canary-e5681b8",
|
|
104
|
+
"tsdown": "^0.23.0",
|
|
101
105
|
"typescript": "^7.0.2",
|
|
102
|
-
"vitest": "~4.1.
|
|
103
|
-
"wrangler": "^4.
|
|
106
|
+
"vitest": "~4.1.11",
|
|
107
|
+
"wrangler": "^4.135.0"
|
|
104
108
|
}
|
|
105
|
-
}
|
|
109
|
+
}
|
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import { a as InferConnectionSchema, i as InferConnectionExtensions, n as DefaultConnectionName, r as InferAnySchema, t as ConnectionName } from "./types-DjLXYLlD.mjs";
|
|
2
|
-
import { AsyncModuleOptions, DynamicModule, ModuleContext, OnInitialize, OnShutdown } from "stratal/module";
|
|
3
|
-
import { ApplicationError, HttpException } from "stratal/errors";
|
|
4
|
-
import { Command } from "stratal/quarry";
|
|
5
|
-
import { AggregateArgs, AllCrudOperations, AnyPlugin, ClientContract, ClientOptions, ComputedFieldsOptions, CountArgs, CreateArgs, CreateManyArgs, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, FindFirstArgs, FindManyArgs, FindUniqueArgs, GroupByArgs, ModelResult, RuntimePlugin, UpdateArgs, UpdateManyArgs, UpsertArgs } from "@zenstackhq/orm";
|
|
6
|
-
import { SchemaDef } from "@zenstackhq/schema";
|
|
7
|
-
import { SchemaDef as SchemaDef$1 } from "@zenstackhq/orm/schema";
|
|
8
|
-
import { IEventRegistry } from "stratal/events";
|
|
9
|
-
//#region src/database/database.module.d.ts
|
|
10
|
-
interface DatabaseConnectionConfig<Schema extends SchemaDef = SchemaDef, Name extends ConnectionName = ConnectionName> {
|
|
11
|
-
name: Name;
|
|
12
|
-
schema: Schema;
|
|
13
|
-
dialect: () => ClientOptions<SchemaDef>['dialect'];
|
|
14
|
-
plugins?: AnyPlugin[];
|
|
15
|
-
/**
|
|
16
|
-
* Schema-level @computed field implementations. Required when the schema
|
|
17
|
-
* declares any `@computed` fields. Keyed by uncapitalized model name; values
|
|
18
|
-
* map field name to a Kysely-expression compute callback.
|
|
19
|
-
*/
|
|
20
|
-
computedFields?: ComputedFieldsOptions<Schema>;
|
|
21
|
-
}
|
|
22
|
-
interface DatabaseModuleConfig {
|
|
23
|
-
default: DefaultConnectionName;
|
|
24
|
-
connections: DatabaseConnectionConfig[];
|
|
25
|
-
}
|
|
26
|
-
declare class DatabaseModule implements OnInitialize, OnShutdown {
|
|
27
|
-
private readonly services;
|
|
28
|
-
static forRoot(config: DatabaseModuleConfig): DynamicModule;
|
|
29
|
-
static forRootAsync(options: AsyncModuleOptions<DatabaseModuleConfig>): DynamicModule;
|
|
30
|
-
onInitialize(context: ModuleContext): Promise<void>;
|
|
31
|
-
onShutdown(context: ModuleContext): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/database/database.service.d.ts
|
|
35
|
-
/**
|
|
36
|
-
* DatabaseService type
|
|
37
|
-
*
|
|
38
|
-
* Each connection has its own schema and plugin extensions.
|
|
39
|
-
* Plugin extension types are automatically inferred from `StratalDatabase.plugins`.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // Typed to default connection (includes plugin extensions)
|
|
44
|
-
* constructor(@inject(DI_TOKENS.Database) private db: DatabaseService) {}
|
|
45
|
-
*
|
|
46
|
-
* // Typed to a specific named connection
|
|
47
|
-
* constructor(@InjectDB('analytics') private analytics: DatabaseService<'analytics'>) {}
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
type DatabaseService<K extends ConnectionName = DefaultConnectionName> = ClientContract<InferConnectionSchema<K>, ClientOptions<InferConnectionSchema<K>>, InferConnectionExtensions<K>['extQueryArgs'], InferConnectionExtensions<K>['extClientMembers'], InferConnectionExtensions<K>['extResult']>;
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/database/database.tokens.d.ts
|
|
53
|
-
declare const DATABASE_TOKENS: {
|
|
54
|
-
readonly Options: symbol;
|
|
55
|
-
readonly Services: symbol;
|
|
56
|
-
};
|
|
57
|
-
declare function connectionSymbol(name: ConnectionName): symbol;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/database/pool.d.ts
|
|
60
|
-
/**
|
|
61
|
-
* Env binding the framework reads to decide DB connection topology. Set by
|
|
62
|
-
* `@stratal/testing` (the test harness runs against a DIRECT Postgres with no
|
|
63
|
-
* Hyperdrive in front); never set in dev / staging / production.
|
|
64
|
-
*/
|
|
65
|
-
declare const DB_SHARED_POOL_ENV = "STRATAL_DB_SHARED_POOL";
|
|
66
|
-
/**
|
|
67
|
-
* Build the lazy pool factory a consumer hands to its ZenStack dialect,
|
|
68
|
-
* choosing the connection topology from the environment instead of hard-coding
|
|
69
|
-
* one. The consumer writes `dialect: () => new PostgresDialect({ pool })` where
|
|
70
|
-
* `pool = createPoolFactory(env, () => new Pool(poolConfig))` — so the prod-vs-
|
|
71
|
-
* test decision lives here, in the framework, not as an `IS_TEST` branch in app
|
|
72
|
-
* config.
|
|
73
|
-
*
|
|
74
|
-
* - **Default (dev / staging / production):** returns a FRESH pool on every
|
|
75
|
-
* call. The dialect is rebuilt per request resolution, so each request owns
|
|
76
|
-
* its own pool/socket — mandatory on workerd, where a pool opened in one
|
|
77
|
-
* request's I/O context cannot be reused by another (the cross-request I/O is
|
|
78
|
-
* cancelled and the request hangs forever). Hyperdrive fronts these pools and
|
|
79
|
-
* multiplexes the real server connections, so they never accumulate.
|
|
80
|
-
* - **Shared (`DB_SHARED_POOL_ENV === 'true'`):** memoizes ONE pool per
|
|
81
|
-
* connection, reused across every resolution. `@stratal/testing` sets this
|
|
82
|
-
* because the test harness hits a direct Postgres with no Hyperdrive — a fresh
|
|
83
|
-
* pool per resolution would exhaust `max_connections` across parallel test
|
|
84
|
-
* files. One shared pool per connection mirrors what Hyperdrive does in prod.
|
|
85
|
-
*
|
|
86
|
-
* This single pool is forced **persistent** ({@link withPersistentConnection}):
|
|
87
|
-
* its idle reaper is disabled regardless of the config `makePool` passed. A pool
|
|
88
|
-
* reused for the whole worker run must never idle-close — a non-zero
|
|
89
|
-
* `idleTimeoutMillis` reaps its connection between operations, and under real
|
|
90
|
-
* network latency (a CI Postgres service, not a local socket) that eviction
|
|
91
|
-
* races in-flight and subsequent queries → "Connection terminated unexpectedly",
|
|
92
|
-
* cascading into half-applied writes and cross-test row leakage. It passes on a
|
|
93
|
-
* fast local socket and only surfaces under latency, so consumers can't be
|
|
94
|
-
* trusted to configure it right — the shared branch enforces it. The consumer's
|
|
95
|
-
* own idle settings still apply to the fresh-per-resolution prod pools (below).
|
|
96
|
-
*
|
|
97
|
-
* Either way the pool is created LAZILY: `makePool` is invoked by Kysely on the
|
|
98
|
-
* first query, inside the request's I/O context — never at module-eval / global
|
|
99
|
-
* scope, which workerd forbids ("Disallowed operation within global scope").
|
|
100
|
-
*/
|
|
101
|
-
declare function createPoolFactory<TPool>(env: object, makePool: () => TPool): () => Promise<TPool>;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/database/decorators/inject-db.decorator.d.ts
|
|
104
|
-
declare function InjectDB(name: ConnectionName): ParameterDecorator;
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region src/database/errors/record-not-found.error.d.ts
|
|
107
|
-
declare class RecordNotFoundError extends HttpException {
|
|
108
|
-
readonly details?: string | undefined;
|
|
109
|
-
constructor(details?: string | undefined, cause?: unknown);
|
|
110
|
-
}
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/database/errors/unique-constraint.error.d.ts
|
|
113
|
-
declare class UniqueConstraintError extends HttpException {
|
|
114
|
-
readonly fields?: string[] | undefined;
|
|
115
|
-
constructor(fields?: string[] | undefined, cause?: unknown);
|
|
116
|
-
}
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/database/errors/from-zenstack-error.d.ts
|
|
119
|
-
declare function fromZenStackError(error: unknown): ApplicationError;
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/database/event-types.d.ts
|
|
122
|
-
/**
|
|
123
|
-
* Event phase: before or after operation
|
|
124
|
-
*/
|
|
125
|
-
type EventPhase = 'before' | 'after';
|
|
126
|
-
/**
|
|
127
|
-
* All database operations that can trigger events
|
|
128
|
-
*/
|
|
129
|
-
type DatabaseOperation = AllCrudOperations;
|
|
130
|
-
/**
|
|
131
|
-
* Distributive helper — extracts model names from each schema member individually.
|
|
132
|
-
* Using a naked type parameter ensures TypeScript distributes over unions:
|
|
133
|
-
* `_ExtractModelNames<A | B>` = `_ExtractModelNames<A> | _ExtractModelNames<B>`
|
|
134
|
-
*/
|
|
135
|
-
type _ExtractModelNames<S> = S extends {
|
|
136
|
-
models: infer M;
|
|
137
|
-
} ? Extract<keyof M, string> : never;
|
|
138
|
-
/**
|
|
139
|
-
* Model names derived from the shared database schema.
|
|
140
|
-
* Distributes over all schema types so models from every connection are included.
|
|
141
|
-
*/
|
|
142
|
-
type ModelName = _ExtractModelNames<InferAnySchema>;
|
|
143
|
-
/**
|
|
144
|
-
* Database event names with all supported patterns.
|
|
145
|
-
*/
|
|
146
|
-
type DatabaseEventName = `${EventPhase}.${ModelName}.${DatabaseOperation}` | `${EventPhase}.${ModelName}` | `${EventPhase}.${DatabaseOperation}` | EventPhase;
|
|
147
|
-
/**
|
|
148
|
-
* Map operation name to ZenStack Args type for a given schema and model
|
|
149
|
-
*/
|
|
150
|
-
type OperationArgsMap<S extends SchemaDef, M extends Extract<keyof S['models'], string>, O extends DatabaseOperation> = O extends 'create' ? CreateArgs<S, M> : O extends 'createMany' ? CreateManyArgs<S, M> : O extends 'update' ? UpdateArgs<S, M> : O extends 'updateMany' ? UpdateManyArgs<S, M> : O extends 'delete' ? DeleteArgs<S, M> : O extends 'deleteMany' ? DeleteManyArgs<S, M> : O extends 'findUnique' ? FindUniqueArgs<S, M> : O extends 'findFirst' ? FindFirstArgs<S, M> : O extends 'findMany' ? FindManyArgs<S, M> : O extends 'upsert' ? UpsertArgs<S, M> : O extends 'count' ? CountArgs<S, M> : O extends 'aggregate' ? AggregateArgs<S, M> : O extends 'groupBy' ? GroupByArgs<S, M> : never;
|
|
151
|
-
/**
|
|
152
|
-
* Distributive helper — resolves data/where args for a model against each schema individually.
|
|
153
|
-
*/
|
|
154
|
-
type _ExtractData<S, M extends string, O extends DatabaseOperation> = S extends SchemaDef ? M extends Extract<keyof S['models'], string> ? OperationArgsMap<S, M, O> extends {
|
|
155
|
-
data: infer D;
|
|
156
|
-
} ? D : OperationArgsMap<S, M, O> extends {
|
|
157
|
-
where: infer W;
|
|
158
|
-
} ? W : OperationArgsMap<S, M, O> : never : never;
|
|
159
|
-
/**
|
|
160
|
-
* Extract the data/where property from operation args.
|
|
161
|
-
* Distributes over all schemas to find the matching model.
|
|
162
|
-
*/
|
|
163
|
-
type GetData<M extends ModelName, O extends DatabaseOperation> = _ExtractData<InferAnySchema, M, O> extends never ? unknown : _ExtractData<InferAnySchema, M, O>;
|
|
164
|
-
/**
|
|
165
|
-
* Distributive helper — resolves result type for a model against each schema individually.
|
|
166
|
-
*/
|
|
167
|
-
type _ExtractResult<S, M extends string, O extends DatabaseOperation> = S extends SchemaDef ? M extends Extract<keyof S['models'], string> ? O extends 'findMany' | 'createMany' | 'updateMany' | 'deleteMany' ? ModelResult<S, M>[] : O extends 'count' ? number : ModelResult<S, M> : never : never;
|
|
168
|
-
/**
|
|
169
|
-
* Extract result type for a model operation.
|
|
170
|
-
* Distributes over all schemas to find the matching model.
|
|
171
|
-
*/
|
|
172
|
-
type GetResult<M extends ModelName, O extends DatabaseOperation> = _ExtractResult<InferAnySchema, M, O> extends never ? unknown : _ExtractResult<InferAnySchema, M, O>;
|
|
173
|
-
/**
|
|
174
|
-
* Verb suffix for entity-mutation events (`entity.{Model}.{verb}`).
|
|
175
|
-
*/
|
|
176
|
-
type EntityMutationVerb = 'created' | 'updated' | 'deleted';
|
|
177
|
-
/**
|
|
178
|
-
* Entity-mutation event names with all supported patterns.
|
|
179
|
-
*
|
|
180
|
-
* Unlike `before.*`/`after.*` (raw query args/result), entity events carry
|
|
181
|
-
* full entity snapshots: `created` has `after`, `updated` has `before` and
|
|
182
|
-
* `after`, `deleted` has `before`. The pre-mutation snapshot is loaded inside
|
|
183
|
-
* the mutation's transaction, and only when a listener matches — a wildcard
|
|
184
|
-
* subscription (`entity`) makes every model pay that pre-read, so subscribe
|
|
185
|
-
* per model when cost matters.
|
|
186
|
-
*/
|
|
187
|
-
type EntityEventName = `entity.${ModelName}.${EntityMutationVerb}` | `entity.${ModelName}` | `entity.${EntityMutationVerb}` | 'entity';
|
|
188
|
-
/**
|
|
189
|
-
* Distributive helper — resolves the full entity shape for a model.
|
|
190
|
-
*/
|
|
191
|
-
type _ExtractEntity<S, M extends string> = S extends SchemaDef ? M extends Extract<keyof S['models'], string> ? ModelResult<S, M> : never : never;
|
|
192
|
-
/**
|
|
193
|
-
* Full entity snapshot type for a model, across all connections' schemas.
|
|
194
|
-
*/
|
|
195
|
-
type GetEntity<M extends ModelName> = _ExtractEntity<InferAnySchema, M> extends never ? unknown : _ExtractEntity<InferAnySchema, M>;
|
|
196
|
-
interface EntityCreatedEventContext<M extends ModelName> {
|
|
197
|
-
model: M;
|
|
198
|
-
action: 'created';
|
|
199
|
-
before: undefined;
|
|
200
|
-
after: GetEntity<M>;
|
|
201
|
-
}
|
|
202
|
-
interface EntityUpdatedEventContext<M extends ModelName> {
|
|
203
|
-
model: M;
|
|
204
|
-
action: 'updated';
|
|
205
|
-
before: GetEntity<M>;
|
|
206
|
-
after: GetEntity<M>;
|
|
207
|
-
}
|
|
208
|
-
interface EntityDeletedEventContext<M extends ModelName> {
|
|
209
|
-
model: M;
|
|
210
|
-
action: 'deleted';
|
|
211
|
-
before: GetEntity<M>;
|
|
212
|
-
after: undefined;
|
|
213
|
-
}
|
|
214
|
-
/** Context for model wildcard subscriptions (e.g. "entity.User") */
|
|
215
|
-
interface EntityModelWildcardContext<M extends ModelName> {
|
|
216
|
-
model: M;
|
|
217
|
-
action: EntityMutationVerb;
|
|
218
|
-
before: GetEntity<M> | undefined;
|
|
219
|
-
after: GetEntity<M> | undefined;
|
|
220
|
-
}
|
|
221
|
-
/** Context for verb wildcard subscriptions (e.g. "entity.updated") */
|
|
222
|
-
interface EntityVerbWildcardContext<V extends EntityMutationVerb> {
|
|
223
|
-
model: ModelName;
|
|
224
|
-
action: V;
|
|
225
|
-
before: V extends 'created' ? undefined : unknown;
|
|
226
|
-
after: V extends 'deleted' ? undefined : unknown;
|
|
227
|
-
}
|
|
228
|
-
/** Context for the global wildcard subscription ("entity") */
|
|
229
|
-
interface EntityWildcardContext {
|
|
230
|
-
model: ModelName;
|
|
231
|
-
action: EntityMutationVerb;
|
|
232
|
-
before: unknown;
|
|
233
|
-
after: unknown;
|
|
234
|
-
}
|
|
235
|
-
type EntityEventContext<E extends string> = E extends `entity.${infer M extends ModelName}.created` ? EntityCreatedEventContext<M> : E extends `entity.${infer M extends ModelName}.updated` ? EntityUpdatedEventContext<M> : E extends `entity.${infer M extends ModelName}.deleted` ? EntityDeletedEventContext<M> : E extends `entity.${infer M extends ModelName}` ? EntityModelWildcardContext<M> : E extends `entity.${infer V extends EntityMutationVerb}` ? EntityVerbWildcardContext<V> : EntityWildcardContext;
|
|
236
|
-
/**
|
|
237
|
-
* Mapped type producing all entity-mutation event name → context pairs.
|
|
238
|
-
*/
|
|
239
|
-
type EntityEvents = { [E in EntityEventName]: EntityEventContext<E>; };
|
|
240
|
-
/**
|
|
241
|
-
* Parse event string into structured type for discriminated unions
|
|
242
|
-
*/
|
|
243
|
-
type ParseEvent<E extends string> = E extends `${infer Phase extends EventPhase}.${infer Model extends ModelName}.${infer Op extends DatabaseOperation}` ? {
|
|
244
|
-
phase: Phase;
|
|
245
|
-
model: Model;
|
|
246
|
-
operation: Op;
|
|
247
|
-
type: 'exact';
|
|
248
|
-
} : E extends `${infer Phase extends EventPhase}.${infer Second}` ? Second extends ModelName ? {
|
|
249
|
-
phase: Phase;
|
|
250
|
-
model: Second;
|
|
251
|
-
type: 'model-wildcard';
|
|
252
|
-
} : Second extends DatabaseOperation ? {
|
|
253
|
-
phase: Phase;
|
|
254
|
-
operation: Second;
|
|
255
|
-
type: 'operation-wildcard';
|
|
256
|
-
} : never : E extends EventPhase ? {
|
|
257
|
-
phase: E;
|
|
258
|
-
type: 'phase-wildcard';
|
|
259
|
-
} : never;
|
|
260
|
-
/** Base context fields present in all events */
|
|
261
|
-
interface BaseEventContext {}
|
|
262
|
-
/** Context for exact database events (e.g., "after.User.create") */
|
|
263
|
-
interface ExactDatabaseEventContext<M extends ModelName, O extends DatabaseOperation, Phase extends EventPhase> extends BaseEventContext {
|
|
264
|
-
data: Phase extends 'before' ? GetData<M, O> : Readonly<GetData<M, O>>;
|
|
265
|
-
result: Phase extends 'after' ? GetResult<M, O> : undefined;
|
|
266
|
-
}
|
|
267
|
-
/** Context for model wildcard events (e.g., "after.User") */
|
|
268
|
-
interface ModelWildcardEventContext<Phase extends EventPhase> extends BaseEventContext {
|
|
269
|
-
operation: DatabaseOperation;
|
|
270
|
-
data: Phase extends 'before' ? unknown : Readonly<unknown>;
|
|
271
|
-
result: Phase extends 'after' ? unknown : undefined;
|
|
272
|
-
}
|
|
273
|
-
/** Context for operation wildcard events (e.g., "after.create") */
|
|
274
|
-
interface OperationWildcardEventContext<Phase extends EventPhase> extends BaseEventContext {
|
|
275
|
-
model: ModelName;
|
|
276
|
-
data: Phase extends 'before' ? unknown : Readonly<unknown>;
|
|
277
|
-
result: Phase extends 'after' ? unknown : undefined;
|
|
278
|
-
}
|
|
279
|
-
/** Context for phase wildcard events (e.g., "after" or "before") */
|
|
280
|
-
interface PhaseWildcardEventContext<Phase extends EventPhase> extends BaseEventContext {
|
|
281
|
-
model: ModelName;
|
|
282
|
-
operation: DatabaseOperation;
|
|
283
|
-
data: Phase extends 'before' ? unknown : Readonly<unknown>;
|
|
284
|
-
result: Phase extends 'after' ? unknown : undefined;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Type-safe event context with discriminated unions.
|
|
288
|
-
*/
|
|
289
|
-
type DatabaseEventContext<E extends string> = ParseEvent<E> extends {
|
|
290
|
-
phase: infer P extends EventPhase;
|
|
291
|
-
model: infer M extends ModelName;
|
|
292
|
-
operation: infer O extends DatabaseOperation;
|
|
293
|
-
type: 'exact';
|
|
294
|
-
} ? ExactDatabaseEventContext<M, O, P> : ParseEvent<E> extends {
|
|
295
|
-
phase: infer P extends EventPhase;
|
|
296
|
-
model: infer _M extends ModelName;
|
|
297
|
-
type: 'model-wildcard';
|
|
298
|
-
} ? ModelWildcardEventContext<P> : ParseEvent<E> extends {
|
|
299
|
-
phase: infer P extends EventPhase;
|
|
300
|
-
operation: infer _O extends DatabaseOperation;
|
|
301
|
-
type: 'operation-wildcard';
|
|
302
|
-
} ? OperationWildcardEventContext<P> : ParseEvent<E> extends {
|
|
303
|
-
phase: infer P extends EventPhase;
|
|
304
|
-
type: 'phase-wildcard';
|
|
305
|
-
} ? PhaseWildcardEventContext<P> : BaseEventContext;
|
|
306
|
-
/**
|
|
307
|
-
* Mapped type that produces all database event name to context pairs.
|
|
308
|
-
*
|
|
309
|
-
* Used to augment core's `CustomEventRegistry`:
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```typescript
|
|
313
|
-
* declare module 'stratal/events' {
|
|
314
|
-
* interface CustomEventRegistry extends DatabaseEvents {}
|
|
315
|
-
* }
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
type DatabaseEvents = { [E in DatabaseEventName]: DatabaseEventContext<E>; };
|
|
319
|
-
declare module 'stratal/events' {
|
|
320
|
-
interface CustomEventRegistry extends DatabaseEvents, EntityEvents {}
|
|
321
|
-
}
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/database/i18n/en.d.ts
|
|
324
|
-
declare const databaseMessages: {
|
|
325
|
-
readonly en: {
|
|
326
|
-
readonly connectionNameRequired: 'Connection name is required';
|
|
327
|
-
readonly defaultConnectionRequired: 'Default connection name is required';
|
|
328
|
-
readonly connectionRequired: 'At least one connection is required';
|
|
329
|
-
readonly duplicateConnections: 'Duplicate connection names found';
|
|
330
|
-
readonly defaultConnectionNotFound: 'Default connection not found in connections';
|
|
331
|
-
};
|
|
332
|
-
};
|
|
333
|
-
declare module 'stratal/i18n' {
|
|
334
|
-
interface AppMessageNamespaces {
|
|
335
|
-
database: typeof databaseMessages['en'];
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/database/plugins/error-handler.plugin.d.ts
|
|
340
|
-
/**
|
|
341
|
-
* ZenStack runtime plugin that transforms ORM errors into ApplicationError instances.
|
|
342
|
-
*
|
|
343
|
-
* @example
|
|
344
|
-
* ```typescript
|
|
345
|
-
* super(schema, {
|
|
346
|
-
* dialect: new PostgresDialect({ pool }),
|
|
347
|
-
* plugins: [new ErrorHandlerPlugin()]
|
|
348
|
-
* })
|
|
349
|
-
* ```
|
|
350
|
-
*/
|
|
351
|
-
declare class ErrorHandlerPlugin implements RuntimePlugin<SchemaDef$1, Record<string, unknown>, Record<string, unknown>, {}> {
|
|
352
|
-
readonly id = "error-handler";
|
|
353
|
-
onQuery: ({ args, proceed }: {
|
|
354
|
-
args: Record<string, unknown> | undefined;
|
|
355
|
-
proceed: (args: Record<string, unknown> | undefined) => Promise<unknown>;
|
|
356
|
-
}) => Promise<unknown>;
|
|
357
|
-
}
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region src/database/plugins/event-emitter.plugin.d.ts
|
|
360
|
-
interface EventEmitterPluginOptions {
|
|
361
|
-
eventRegistry: IEventRegistry;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* ZenStack runtime plugin that emits before/after events for database operations.
|
|
365
|
-
*
|
|
366
|
-
* Emits events in the format:
|
|
367
|
-
* - `before.{Model}.{operation}` - Before the database operation
|
|
368
|
-
* - `after.{Model}.{operation}` - After the database operation
|
|
369
|
-
*
|
|
370
|
-
* Additionally emits entity-mutation events carrying full entity snapshots:
|
|
371
|
-
* - `entity.{Model}.created` - `{ after }`
|
|
372
|
-
* - `entity.{Model}.updated` - `{ before, after }`
|
|
373
|
-
* - `entity.{Model}.deleted` - `{ before }`
|
|
374
|
-
*
|
|
375
|
-
* Entity events are listener-driven: the pre-mutation snapshot is only
|
|
376
|
-
* loaded (inside the mutation's transaction) when `hasListeners()` reports
|
|
377
|
-
* a matching subscription, so models nobody observes pay no cost. Note that
|
|
378
|
-
* a wildcard subscription (`entity`) therefore makes every model pay the
|
|
379
|
-
* pre-read — subscribe per model when cost matters.
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
* ```typescript
|
|
383
|
-
* super(schema, {
|
|
384
|
-
* dialect: new PostgresDialect({ pool }),
|
|
385
|
-
* plugins: [
|
|
386
|
-
* new EventEmitterPlugin({
|
|
387
|
-
* eventRegistry,
|
|
388
|
-
* })
|
|
389
|
-
* ]
|
|
390
|
-
* })
|
|
391
|
-
* ```
|
|
392
|
-
*/
|
|
393
|
-
declare class EventEmitterPlugin implements RuntimePlugin<SchemaDef$1, Record<string, unknown>, Record<string, unknown>, {}> {
|
|
394
|
-
private options;
|
|
395
|
-
readonly id = "event-emitter";
|
|
396
|
-
constructor(options: EventEmitterPluginOptions);
|
|
397
|
-
onEntityMutation: EntityMutationHooksDef<SchemaDef$1>;
|
|
398
|
-
onQuery: ({ model, operation, args, proceed }: {
|
|
399
|
-
model: string;
|
|
400
|
-
operation: string;
|
|
401
|
-
args: Record<string, unknown> | undefined;
|
|
402
|
-
proceed: (args: Record<string, unknown> | undefined) => Promise<unknown>;
|
|
403
|
-
}) => Promise<unknown>;
|
|
404
|
-
}
|
|
405
|
-
//#endregion
|
|
406
|
-
//#region src/database/plugins/schema-switcher.d.ts
|
|
407
|
-
/**
|
|
408
|
-
* Switches the active schema on a ZenStack/Kysely database client by mutating
|
|
409
|
-
* `$schema.provider.defaultSchema`. This causes ZenStack's QueryNameMapper to
|
|
410
|
-
* generate fully-qualified table references (e.g. `"tenant_123"."User"`).
|
|
411
|
-
*
|
|
412
|
-
* Must be called BEFORE any queries are made on the client.
|
|
413
|
-
*
|
|
414
|
-
* Note: The ZenStack RuntimePlugin `onQuery` hook fires after table names are
|
|
415
|
-
* already resolved, so a plugin-based approach cannot set the schema prefix.
|
|
416
|
-
* Direct client mutation is the only supported method.
|
|
417
|
-
*/
|
|
418
|
-
declare class SchemaSwitcher {
|
|
419
|
-
static apply<T>(client: T, schemaName: string): T;
|
|
420
|
-
}
|
|
421
|
-
//#endregion
|
|
422
|
-
//#region src/database/commands/zenstack.command.d.ts
|
|
423
|
-
/**
|
|
424
|
-
* Base command for ZenStack CLI wrappers.
|
|
425
|
-
* Uses execFileSync with array arguments to prevent shell injection.
|
|
426
|
-
*/
|
|
427
|
-
declare abstract class ZenStackCommand extends Command {
|
|
428
|
-
protected zenstack(args: string[]): Promise<number>;
|
|
429
|
-
}
|
|
430
|
-
//#endregion
|
|
431
|
-
//#region src/database/commands/db-generate.command.d.ts
|
|
432
|
-
declare class DbGenerateCommand extends ZenStackCommand {
|
|
433
|
-
static command: string;
|
|
434
|
-
static description: string;
|
|
435
|
-
handle(): Promise<number>;
|
|
436
|
-
}
|
|
437
|
-
//#endregion
|
|
438
|
-
//#region src/database/commands/db-pull.command.d.ts
|
|
439
|
-
declare class DbPullCommand extends ZenStackCommand {
|
|
440
|
-
static command: string;
|
|
441
|
-
static description: string;
|
|
442
|
-
handle(): Promise<number>;
|
|
443
|
-
}
|
|
444
|
-
//#endregion
|
|
445
|
-
//#region src/database/commands/db-push.command.d.ts
|
|
446
|
-
declare class DbPushCommand extends ZenStackCommand {
|
|
447
|
-
static command: string;
|
|
448
|
-
static description: string;
|
|
449
|
-
handle(): Promise<number>;
|
|
450
|
-
}
|
|
451
|
-
//#endregion
|
|
452
|
-
//#region src/database/commands/migrate-deploy.command.d.ts
|
|
453
|
-
declare class MigrateDeployCommand extends ZenStackCommand {
|
|
454
|
-
static command: string;
|
|
455
|
-
static description: string;
|
|
456
|
-
handle(): Promise<number>;
|
|
457
|
-
}
|
|
458
|
-
//#endregion
|
|
459
|
-
//#region src/database/commands/migrate-dev.command.d.ts
|
|
460
|
-
declare class MigrateDevCommand extends ZenStackCommand {
|
|
461
|
-
static command: string;
|
|
462
|
-
static description: string;
|
|
463
|
-
handle(): Promise<number>;
|
|
464
|
-
}
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region src/database/commands/migrate-reset.command.d.ts
|
|
467
|
-
declare class MigrateResetCommand extends ZenStackCommand {
|
|
468
|
-
static command: string;
|
|
469
|
-
static description: string;
|
|
470
|
-
handle(): Promise<number>;
|
|
471
|
-
}
|
|
472
|
-
//#endregion
|
|
473
|
-
//#region src/database/commands/migrate-status.command.d.ts
|
|
474
|
-
declare class MigrateStatusCommand extends ZenStackCommand {
|
|
475
|
-
static command: string;
|
|
476
|
-
static description: string;
|
|
477
|
-
handle(): Promise<number>;
|
|
478
|
-
}
|
|
479
|
-
//#endregion
|
|
480
|
-
export { DB_SHARED_POOL_ENV as A, GetResult as C, UniqueConstraintError as D, fromZenStackError as E, DatabaseConnectionConfig as F, DatabaseModule as I, DatabaseModuleConfig as L, DATABASE_TOKENS as M, connectionSymbol as N, RecordNotFoundError as O, DatabaseService as P, GetEntity as S, ParseEvent as T, EntityEventName as _, DbPushCommand as a, EventPhase as b, ZenStackCommand as c, EventEmitterPluginOptions as d, ErrorHandlerPlugin as f, DatabaseOperation as g, DatabaseEvents as h, MigrateDeployCommand as i, createPoolFactory as j, InjectDB as k, SchemaSwitcher as l, DatabaseEventName as m, MigrateResetCommand as n, DbPullCommand as o, databaseMessages as p, MigrateDevCommand as r, DbGenerateCommand as s, MigrateStatusCommand as t, EventEmitterPlugin as u, EntityEvents as v, ModelName as w, GetData as x, EntityMutationVerb as y };
|
|
481
|
-
//# sourceMappingURL=index-B8EVn7T5.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-B8EVn7T5.d.mts","names":[],"sources":["../src/database/database.module.ts","../src/database/database.service.ts","../src/database/database.tokens.ts","../src/database/pool.ts","../src/database/decorators/inject-db.decorator.ts","../src/database/errors/record-not-found.error.ts","../src/database/errors/unique-constraint.error.ts","../src/database/errors/from-zenstack-error.ts","../src/database/event-types.ts","../src/database/i18n/en.ts","../src/database/plugins/error-handler.plugin.ts","../src/database/plugins/event-emitter.plugin.ts","../src/database/plugins/schema-switcher.ts","../src/database/commands/zenstack.command.ts","../src/database/commands/db-generate.command.ts","../src/database/commands/db-pull.command.ts","../src/database/commands/db-push.command.ts","../src/database/commands/migrate-deploy.command.ts","../src/database/commands/migrate-dev.command.ts","../src/database/commands/migrate-reset.command.ts","../src/database/commands/migrate-status.command.ts"],"mappings":";;;;;;;;;UA0BiB,yBACf,eAAe,YAAY,WAC3B,aAAa,iBAAiB;EAE9B,MAAM;EACN,QAAQ;EACR,eAAe,cAAc;EAC7B,UAAU;;;;;;EAMV,iBAAiB,sBAAsB;;UAGxB;EACf,SAAS;EACT,aAAa;;cAiBF,0BAA0B,cAAc;mBAClC;SAEV,QAAQ,QAAQ,uBAAuB;SASvC,aAAa,SAAS,mBAAmB,wBAAwB;EAalE,aAAa,SAAS,gBAAgB;EAkBtC,WAAW,SAAS,gBAAgB;;;;;;;;;;;;;;;;;;;KCtFhC,gBACV,UAAU,iBAAiB,yBACzB,eACF,sBAAsB,IACtB,cAAc,sBAAsB,KACpC,0BAA0B,oBAC1B,0BAA0B,wBAE1B,0BAA0B;;;cC1Bf;WACX;WACA;;iBAKc,iBAAiB,MAAM;;;;;;;;cCF1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqCG,kBAAkB,OAChC,aACA,gBAAgB,cACT,QAAQ;;;iBCzCD,SAAS,MAAM,iBAAiB;;;cCFnC,4BAA4B;WACX;EAA5B,YAA4B,8BAAkB;;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