@stratal/framework 0.0.6 → 0.0.7
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/database/database.helpers.d.ts +6 -7
- package/dist/database/database.helpers.d.ts.map +1 -1
- package/dist/database/database.helpers.js +25 -4
- package/dist/database/database.helpers.js.map +1 -1
- package/dist/database/database.module.d.ts +10 -8
- package/dist/database/database.module.d.ts.map +1 -1
- package/dist/database/database.module.js +6 -14
- package/dist/database/database.module.js.map +1 -1
- package/dist/database/database.service.d.ts +7 -5
- package/dist/database/database.service.d.ts.map +1 -1
- package/dist/database/database.tokens.d.ts +2 -1
- package/dist/database/database.tokens.d.ts.map +1 -1
- package/dist/database/database.tokens.js.map +1 -1
- package/dist/database/event-types.d.ts +34 -41
- package/dist/database/event-types.d.ts.map +1 -1
- package/dist/database/event-types.js +1 -1
- package/dist/database/types.d.ts +23 -28
- package/dist/database/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +12 -12
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZenStackClient } from '@zenstackhq/orm';
|
|
2
|
+
import type { SchemaDef } from '@zenstackhq/schema';
|
|
2
3
|
import type { IEventRegistry } from 'stratal/events';
|
|
3
4
|
import { z } from 'stratal/validation';
|
|
4
5
|
import type { DatabaseConnectionConfig } from './database.module';
|
|
5
6
|
export declare const databaseModuleConfigSchema: z.ZodObject<{
|
|
7
|
+
schema: z.ZodObject<{}, z.core.$loose>;
|
|
6
8
|
default: z.ZodString;
|
|
7
9
|
connections: z.ZodArray<z.ZodObject<{
|
|
8
10
|
name: z.ZodString;
|
|
9
|
-
|
|
10
|
-
dialect: z.ZodObject<{}, z.core.$loose>;
|
|
11
|
+
dialect: z.ZodFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
|
|
11
12
|
plugins: z.ZodOptional<z.ZodArray<z.ZodObject<{}, z.core.$loose>>>;
|
|
13
|
+
slicing: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
12
14
|
}, z.core.$strip>>;
|
|
13
15
|
}, z.core.$strip>;
|
|
14
|
-
export declare function createDatabaseService(conn: DatabaseConnectionConfig, eventRegistry: IEventRegistry):
|
|
15
|
-
dialect: import("kysely").Dialect;
|
|
16
|
-
plugins: AnyPlugin[];
|
|
17
|
-
}, {}, {}>;
|
|
16
|
+
export declare function createDatabaseService(schema: SchemaDef, conn: DatabaseConnectionConfig, eventRegistry: IEventRegistry): new () => InstanceType<typeof ZenStackClient>;
|
|
18
17
|
//# sourceMappingURL=database.helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.helpers.d.ts","sourceRoot":"","sources":["../../src/database/database.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"database.helpers.d.ts","sourceRoot":"","sources":["../../src/database/database.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAkB,MAAM,iBAAiB,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAUjE,eAAO,MAAM,0BAA0B;;;;;;;;;iBAatC,CAAA;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,wBAAwB,EAC9B,aAAa,EAAE,cAAc,GAC5B,UAAU,YAAY,CAAC,OAAO,cAAc,CAAC,CAkB/C"}
|
|
@@ -1,20 +1,31 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
1
10
|
import { ZenStackClient } from '@zenstackhq/orm';
|
|
11
|
+
import { Transient } from 'stratal/di';
|
|
2
12
|
import { z } from 'stratal/validation';
|
|
3
13
|
import { ErrorHandlerPlugin, EventEmitterPlugin } from './plugins';
|
|
4
14
|
const databaseConnectionSchema = z.object({
|
|
5
15
|
name: z.string().min(1, 'Connection name is required'),
|
|
6
|
-
|
|
7
|
-
dialect: z.object({}).loose(),
|
|
16
|
+
dialect: z.function(),
|
|
8
17
|
plugins: z.array(z.object({}).loose()).optional(),
|
|
18
|
+
slicing: z.object({}).loose().optional(),
|
|
9
19
|
});
|
|
10
20
|
export const databaseModuleConfigSchema = z.object({
|
|
21
|
+
schema: z.object({}).loose(),
|
|
11
22
|
default: z.string().min(1, 'Default connection name is required'),
|
|
12
23
|
connections: z.array(databaseConnectionSchema).min(1, 'At least one connection is required'),
|
|
13
24
|
}).refine((config) => {
|
|
14
25
|
const names = config.connections.map(c => c.name);
|
|
15
26
|
return new Set(names).size === names.length;
|
|
16
27
|
}, { message: 'Duplicate connection names found' }).refine((config) => config.connections.some(c => c.name === config.default), { message: 'Default connection not found in connections' });
|
|
17
|
-
export function createDatabaseService(conn, eventRegistry) {
|
|
28
|
+
export function createDatabaseService(schema, conn, eventRegistry) {
|
|
18
29
|
const plugins = [
|
|
19
30
|
new ErrorHandlerPlugin(),
|
|
20
31
|
new EventEmitterPlugin({
|
|
@@ -22,6 +33,16 @@ export function createDatabaseService(conn, eventRegistry) {
|
|
|
22
33
|
}),
|
|
23
34
|
...(conn.plugins ?? []),
|
|
24
35
|
];
|
|
25
|
-
|
|
36
|
+
let DatabaseClient = class DatabaseClient extends ZenStackClient {
|
|
37
|
+
constructor() {
|
|
38
|
+
const dialect = conn.dialect();
|
|
39
|
+
super(schema, { dialect, plugins, slicing: conn.slicing });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
DatabaseClient = __decorate([
|
|
43
|
+
Transient(),
|
|
44
|
+
__metadata("design:paramtypes", [])
|
|
45
|
+
], DatabaseClient);
|
|
46
|
+
return DatabaseClient;
|
|
26
47
|
}
|
|
27
48
|
//# sourceMappingURL=database.helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.helpers.js","sourceRoot":"","sources":["../../src/database/database.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAkB,MAAM,iBAAiB,CAAA;AAEhE,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAElE,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,6BAA6B,CAAC;IACtD,
|
|
1
|
+
{"version":3,"file":"database.helpers.js","sourceRoot":"","sources":["../../src/database/database.helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAkB,MAAM,iBAAiB,CAAA;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW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AA6C,EAAE,CAC3D,CAAA;AAED,MAAM,UAAU,qBAAqB,CACnC,MAAiB,EACjB,IAA8B,EAC9B,aAA6B;IAE7B,MAAM,OAAO,GAAgB;QAC3B,IAAI,kBAAkB,EAAE;QACxB,IAAI,kBAAkB,CAAC;YACrB,aAAa;SACd,CAAC;QACF,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;KACxB,CAAA;IAED,IACM,cAAc,GADpB,MACM,cAAe,SAAQ,cAA6B;QACxD;YACE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;YAC9B,KAAK,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QAC5D,CAAC;KACF,CAAA;IALK,cAAc;QADnB,SAAS,EAAE;;OACN,cAAc,CAKnB;IAED,OAAO,cAAc,CAAA;AACvB,CAAC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import type { AnyPlugin } from '@zenstackhq/orm';
|
|
1
|
+
import type { AnyPlugin, SlicingOptions } from '@zenstackhq/orm';
|
|
2
2
|
import type { SchemaDef } from '@zenstackhq/schema';
|
|
3
3
|
import type { Dialect } from 'kysely';
|
|
4
4
|
import { type AsyncModuleOptions, type DynamicModule, type ModuleContext, type OnInitialize, type OnShutdown } from 'stratal/module';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
dialect: Dialect;
|
|
5
|
+
import type { ConnectionName, DefaultConnectionName } from './types';
|
|
6
|
+
export interface DatabaseConnectionConfig<Schema extends SchemaDef = SchemaDef, Name extends ConnectionName = ConnectionName> {
|
|
7
|
+
name: Name;
|
|
8
|
+
dialect: () => Dialect;
|
|
9
9
|
plugins?: AnyPlugin[];
|
|
10
|
+
slicing?: SlicingOptions<Schema>;
|
|
10
11
|
}
|
|
11
|
-
export interface DatabaseModuleConfig {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export interface DatabaseModuleConfig<Schema extends SchemaDef = SchemaDef> {
|
|
13
|
+
schema: Schema;
|
|
14
|
+
default: DefaultConnectionName;
|
|
15
|
+
connections: DatabaseConnectionConfig<Schema>[];
|
|
14
16
|
}
|
|
15
17
|
export declare class DatabaseModule implements OnInitialize, OnShutdown {
|
|
16
18
|
static forRoot(config: DatabaseModuleConfig): DynamicModule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.module.d.ts","sourceRoot":"","sources":["../../src/database/database.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"database.module.d.ts","sourceRoot":"","sources":["../../src/database/database.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpE,MAAM,WAAW,wBAAwB,CACvC,MAAM,SAAS,SAAS,GAAG,SAAS,EACpC,IAAI,SAAS,cAAc,GAAG,cAAc;IAE5C,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,MAAM,OAAO,CAAA;IACtB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAA;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,oBAAoB,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IACxE,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,qBAAqB,CAAA;IAC9B,WAAW,EAAE,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAA;CAChD;AAED,qBACa,cAAe,YAAW,YAAY,EAAE,UAAU;IAC7D,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa;IAS3D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,GAAG,aAAa;IAarF,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAmB1C,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;CAGzC"}
|
|
@@ -5,12 +5,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
var DatabaseModule_1;
|
|
8
|
-
import { DI_TOKENS } from 'stratal/di';
|
|
8
|
+
import { DI_TOKENS, Scope, delay } from 'stratal/di';
|
|
9
9
|
import { Module, } from 'stratal/module';
|
|
10
|
-
import { instancePerContainerCachingFactory } from 'tsyringe';
|
|
11
10
|
import { createDatabaseService } from './database.helpers';
|
|
12
11
|
import { DATABASE_TOKENS, connectionSymbol } from './database.tokens';
|
|
13
|
-
import { DatabaseConfigError } from './errors/database-config.error';
|
|
14
12
|
let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
15
13
|
static forRoot(config) {
|
|
16
14
|
return {
|
|
@@ -34,19 +32,13 @@ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
|
34
32
|
}
|
|
35
33
|
onInitialize(context) {
|
|
36
34
|
const config = context.container.resolve(DATABASE_TOKENS.Options);
|
|
35
|
+
const eventRegistry = context.container.resolve(DI_TOKENS.EventRegistry);
|
|
37
36
|
const container = context.container.getTsyringeContainer();
|
|
38
37
|
for (const conn of config.connections) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!resolvedConn) {
|
|
44
|
-
throw new DatabaseConfigError('Connection not found');
|
|
45
|
-
}
|
|
46
|
-
const eventRegistry = c.resolve(DI_TOKENS.EventRegistry);
|
|
47
|
-
return createDatabaseService(resolvedConn, eventRegistry);
|
|
48
|
-
})
|
|
49
|
-
});
|
|
38
|
+
const Service = createDatabaseService(config.schema, conn, eventRegistry);
|
|
39
|
+
container.register(connectionSymbol(conn.name),
|
|
40
|
+
// @ts-expect-error Overload error
|
|
41
|
+
delay(() => Service), { lifecycle: Scope.Request });
|
|
50
42
|
}
|
|
51
43
|
context.container.registerExisting(DI_TOKENS.Database, connectionSymbol(config.default));
|
|
52
44
|
context.logger.info('DatabaseModule initialized');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.module.js","sourceRoot":"","sources":["../../src/database/database.module.ts"],"names":[],"mappings":";;;;;;;AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"database.module.js","sourceRoot":"","sources":["../../src/database/database.module.ts"],"names":[],"mappings":";;;;;;;AAGA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEpD,OAAO,EAEL,MAAM,GAMP,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAoB9D,IAAM,cAAc,sBAApB,MAAM,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,MAA4B;QACzC,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAA2B,EAAE;aAC5E;SACF,CAAA;IACH,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAiD;QACnE,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,SAAS,EAAE;gBACT;o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
|
-
import type { ConnectionName, DefaultConnectionName,
|
|
2
|
+
import type { ConnectionName, DefaultConnectionName, InferConnectionSlicing, InferDatabaseSchema } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* DatabaseService type
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* All connections share a single schema. Slicing narrows the available models per connection.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
|
-
* // Typed to default connection
|
|
10
|
+
* // Typed to default connection
|
|
11
11
|
* constructor(@inject(DI_TOKENS.Database) private db: DatabaseService) {}
|
|
12
12
|
*
|
|
13
|
-
* // Typed to a specific named connection
|
|
13
|
+
* // Typed to a specific named connection
|
|
14
14
|
* constructor(@InjectDB('analytics') private analytics: DatabaseService<'analytics'>) {}
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export type DatabaseService<K extends ConnectionName = DefaultConnectionName
|
|
17
|
+
export type DatabaseService<K extends ConnectionName = DefaultConnectionName> = ClientContract<InferDatabaseSchema, ClientOptions<InferDatabaseSchema> & {
|
|
18
|
+
slicing: InferConnectionSlicing<K>;
|
|
19
|
+
}>;
|
|
18
20
|
//# sourceMappingURL=database.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.service.d.ts","sourceRoot":"","sources":["../../src/database/database.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"database.service.d.ts","sourceRoot":"","sources":["../../src/database/database.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAEjH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,cAAc,GAAG,qBAAqB,IAC9C,cAAc,CAChB,mBAAmB,EACnB,aAAa,CAAC,mBAAmB,CAAC,GAAG;IAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAA;CAAE,CAC5E,CAAA"}
|
|
@@ -2,5 +2,6 @@ export declare const DATABASE_TOKENS: {
|
|
|
2
2
|
readonly Options: symbol;
|
|
3
3
|
readonly Services: symbol;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
import type { ConnectionName } from './types';
|
|
6
|
+
export declare function connectionSymbol(name: ConnectionName): symbol;
|
|
6
7
|
//# sourceMappingURL=database.tokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.tokens.d.ts","sourceRoot":"","sources":["../../src/database/database.tokens.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;CAGlB,CAAA;AAEV,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"database.tokens.d.ts","sourceRoot":"","sources":["../../src/database/database.tokens.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;CAGlB,CAAA;AAEV,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAE7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.tokens.js","sourceRoot":"","sources":["../../src/database/database.tokens.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC;CAChC,CAAA;
|
|
1
|
+
{"version":3,"file":"database.tokens.js","sourceRoot":"","sources":["../../src/database/database.tokens.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC;CAChC,CAAA;AAIV,MAAM,UAAU,gBAAgB,CAAC,IAAoB;IACnD,OAAO,MAAM,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAA;AACjD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Database Event Types
|
|
3
3
|
*
|
|
4
|
-
* All ZenStack-dependent event types
|
|
4
|
+
* All ZenStack-dependent event types derived from the shared database schema.
|
|
5
5
|
* These types power the auto-complete and type-safe event contexts for
|
|
6
6
|
* database events like `after.User.create`.
|
|
7
7
|
*
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { AggregateArgs, AllCrudOperations, CountArgs, CreateArgs, CreateManyArgs, DeleteArgs, DeleteManyArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, GroupByArgs, ModelResult, UpdateArgs, UpdateManyArgs, UpsertArgs } from '@zenstackhq/orm';
|
|
13
13
|
import type { SchemaDef } from '@zenstackhq/schema';
|
|
14
|
-
import type {
|
|
14
|
+
import type { InferDatabaseSchema } from './types';
|
|
15
15
|
/**
|
|
16
16
|
* Event phase: before or after operation
|
|
17
17
|
*/
|
|
@@ -21,41 +21,41 @@ export type EventPhase = 'before' | 'after';
|
|
|
21
21
|
*/
|
|
22
22
|
export type DatabaseOperation = AllCrudOperations;
|
|
23
23
|
/**
|
|
24
|
-
* Model names derived from
|
|
25
|
-
* Falls back to `never` if no
|
|
24
|
+
* Model names derived from the shared database schema.
|
|
25
|
+
* Falls back to `never` if no schema is registered.
|
|
26
26
|
*/
|
|
27
|
-
export type ModelName
|
|
27
|
+
export type ModelName = InferDatabaseSchema extends {
|
|
28
28
|
models: infer M;
|
|
29
29
|
} ? Extract<keyof M, string> : never;
|
|
30
30
|
/**
|
|
31
|
-
* Database event names with all supported patterns
|
|
31
|
+
* Database event names with all supported patterns.
|
|
32
32
|
*/
|
|
33
|
-
export type DatabaseEventName
|
|
33
|
+
export type DatabaseEventName = `${EventPhase}.${ModelName}.${DatabaseOperation}` | `${EventPhase}.${ModelName}` | `${EventPhase}.${DatabaseOperation}` | EventPhase;
|
|
34
34
|
/**
|
|
35
35
|
* Map operation name to ZenStack Args type for a given schema and model
|
|
36
36
|
*/
|
|
37
37
|
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;
|
|
38
38
|
/**
|
|
39
|
-
* Extract the data/where property from operation args
|
|
39
|
+
* Extract the data/where property from operation args.
|
|
40
40
|
*/
|
|
41
|
-
export type GetData<
|
|
41
|
+
export type GetData<M extends ModelName, O extends DatabaseOperation> = M extends Extract<keyof InferDatabaseSchema['models'], string> ? OperationArgsMap<InferDatabaseSchema, M, O> extends {
|
|
42
42
|
data: infer D;
|
|
43
|
-
} ? D : OperationArgsMap<
|
|
43
|
+
} ? D : OperationArgsMap<InferDatabaseSchema, M, O> extends {
|
|
44
44
|
where: infer W;
|
|
45
|
-
} ? W : OperationArgsMap<
|
|
45
|
+
} ? W : OperationArgsMap<InferDatabaseSchema, M, O> : unknown;
|
|
46
46
|
/**
|
|
47
|
-
* Extract result type for a model operation
|
|
47
|
+
* Extract result type for a model operation.
|
|
48
48
|
*/
|
|
49
|
-
export type GetResult<
|
|
49
|
+
export type GetResult<M extends ModelName, O extends DatabaseOperation> = M extends Extract<keyof InferDatabaseSchema['models'], string> ? O extends 'findMany' | 'createMany' | 'updateMany' | 'deleteMany' ? ModelResult<InferDatabaseSchema, M>[] : O extends 'count' ? number : ModelResult<InferDatabaseSchema, M> : unknown;
|
|
50
50
|
/**
|
|
51
51
|
* Parse event string into structured type for discriminated unions
|
|
52
52
|
*/
|
|
53
|
-
export type ParseEvent<
|
|
53
|
+
export type ParseEvent<E extends string> = E extends `${infer Phase extends EventPhase}.${infer Model extends ModelName}.${infer Op extends DatabaseOperation}` ? {
|
|
54
54
|
phase: Phase;
|
|
55
55
|
model: Model;
|
|
56
56
|
operation: Op;
|
|
57
57
|
type: 'exact';
|
|
58
|
-
} : E extends `${infer Phase extends EventPhase}.${infer Second}` ? Second extends ModelName
|
|
58
|
+
} : E extends `${infer Phase extends EventPhase}.${infer Second}` ? Second extends ModelName ? {
|
|
59
59
|
phase: Phase;
|
|
60
60
|
model: Second;
|
|
61
61
|
type: 'model-wildcard';
|
|
@@ -71,9 +71,9 @@ export type ParseEvent<K extends ConnectionName, E extends string> = E extends `
|
|
|
71
71
|
interface BaseEventContext {
|
|
72
72
|
}
|
|
73
73
|
/** Context for exact database events (e.g., "after.User.create") */
|
|
74
|
-
interface ExactDatabaseEventContext<
|
|
75
|
-
data: Phase extends 'before' ? GetData<
|
|
76
|
-
result: Phase extends 'after' ? GetResult<
|
|
74
|
+
interface ExactDatabaseEventContext<M extends ModelName, O extends DatabaseOperation, Phase extends EventPhase> extends BaseEventContext {
|
|
75
|
+
data: Phase extends 'before' ? GetData<M, O> : Readonly<GetData<M, O>>;
|
|
76
|
+
result: Phase extends 'after' ? GetResult<M, O> : undefined;
|
|
77
77
|
}
|
|
78
78
|
/** Context for model wildcard events (e.g., "after.User") */
|
|
79
79
|
interface ModelWildcardEventContext<Phase extends EventPhase> extends BaseEventContext {
|
|
@@ -82,59 +82,52 @@ interface ModelWildcardEventContext<Phase extends EventPhase> extends BaseEventC
|
|
|
82
82
|
result: Phase extends 'after' ? unknown : undefined;
|
|
83
83
|
}
|
|
84
84
|
/** Context for operation wildcard events (e.g., "after.create") */
|
|
85
|
-
interface OperationWildcardEventContext<
|
|
86
|
-
model: ModelName
|
|
85
|
+
interface OperationWildcardEventContext<Phase extends EventPhase> extends BaseEventContext {
|
|
86
|
+
model: ModelName;
|
|
87
87
|
data: Phase extends 'before' ? unknown : Readonly<unknown>;
|
|
88
88
|
result: Phase extends 'after' ? unknown : undefined;
|
|
89
89
|
}
|
|
90
90
|
/** Context for phase wildcard events (e.g., "after" or "before") */
|
|
91
|
-
interface PhaseWildcardEventContext<
|
|
92
|
-
model: ModelName
|
|
91
|
+
interface PhaseWildcardEventContext<Phase extends EventPhase> extends BaseEventContext {
|
|
92
|
+
model: ModelName;
|
|
93
93
|
operation: DatabaseOperation;
|
|
94
94
|
data: Phase extends 'before' ? unknown : Readonly<unknown>;
|
|
95
95
|
result: Phase extends 'after' ? unknown : undefined;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
-
* Type-safe event context with discriminated unions
|
|
98
|
+
* Type-safe event context with discriminated unions.
|
|
99
99
|
*/
|
|
100
|
-
type DatabaseEventContext<
|
|
100
|
+
type DatabaseEventContext<E extends string> = ParseEvent<E> extends {
|
|
101
101
|
phase: infer P extends EventPhase;
|
|
102
|
-
model: infer M extends ModelName
|
|
102
|
+
model: infer M extends ModelName;
|
|
103
103
|
operation: infer O extends DatabaseOperation;
|
|
104
104
|
type: 'exact';
|
|
105
|
-
} ? ExactDatabaseEventContext<
|
|
105
|
+
} ? ExactDatabaseEventContext<M, O, P> : ParseEvent<E> extends {
|
|
106
106
|
phase: infer P extends EventPhase;
|
|
107
|
-
model: infer _M extends ModelName
|
|
107
|
+
model: infer _M extends ModelName;
|
|
108
108
|
type: 'model-wildcard';
|
|
109
|
-
} ? ModelWildcardEventContext<P> : ParseEvent<
|
|
109
|
+
} ? ModelWildcardEventContext<P> : ParseEvent<E> extends {
|
|
110
110
|
phase: infer P extends EventPhase;
|
|
111
111
|
operation: infer _O extends DatabaseOperation;
|
|
112
112
|
type: 'operation-wildcard';
|
|
113
|
-
} ? OperationWildcardEventContext<
|
|
113
|
+
} ? OperationWildcardEventContext<P> : ParseEvent<E> extends {
|
|
114
114
|
phase: infer P extends EventPhase;
|
|
115
115
|
type: 'phase-wildcard';
|
|
116
|
-
} ? PhaseWildcardEventContext<
|
|
116
|
+
} ? PhaseWildcardEventContext<P> : BaseEventContext;
|
|
117
117
|
/**
|
|
118
|
-
* Mapped type that produces all database event name
|
|
118
|
+
* Mapped type that produces all database event name to context pairs.
|
|
119
119
|
*
|
|
120
120
|
* Used to augment core's `CustomEventRegistry`:
|
|
121
121
|
*
|
|
122
|
-
* @example
|
|
122
|
+
* @example
|
|
123
123
|
* ```typescript
|
|
124
124
|
* declare module 'stratal/events' {
|
|
125
125
|
* interface CustomEventRegistry extends DatabaseEvents {}
|
|
126
126
|
* }
|
|
127
127
|
* ```
|
|
128
|
-
*
|
|
129
|
-
* @example Narrow to a specific connection
|
|
130
|
-
* ```typescript
|
|
131
|
-
* declare module 'stratal/events' {
|
|
132
|
-
* interface CustomEventRegistry extends DatabaseEvents<'main'> {}
|
|
133
|
-
* }
|
|
134
|
-
* ```
|
|
135
128
|
*/
|
|
136
|
-
export type DatabaseEvents
|
|
137
|
-
[E in DatabaseEventName
|
|
129
|
+
export type DatabaseEvents = {
|
|
130
|
+
[E in DatabaseEventName]: DatabaseEventContext<E>;
|
|
138
131
|
};
|
|
139
132
|
declare module 'stratal/events' {
|
|
140
133
|
interface CustomEventRegistry extends DatabaseEvents {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../../src/database/event-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../../src/database/event-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAMlD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAEjD;;;GAGG;AACH,MAAM,MAAM,SAAS,GACnB,mBAAmB,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAC7C,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GACxB,KAAK,CAAA;AAMT;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,GAAG,UAAU,IAAI,SAAS,IAAI,iBAAiB,EAAE,GACjD,GAAG,UAAU,IAAI,SAAS,EAAE,GAC5B,GAAG,UAAU,IAAI,iBAAiB,EAAE,GACpC,UAAU,CAAA;AAMd;;GAEG;AACH,KAAK,gBAAgB,CACn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oBAAoB,CAAC,CAAC,CAAC;CAClD,CAAA;AAMD,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,mBAAoB,SAAQ,cAAc;KAAI;CACzD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Database Event Types
|
|
3
3
|
*
|
|
4
|
-
* All ZenStack-dependent event types
|
|
4
|
+
* All ZenStack-dependent event types derived from the shared database schema.
|
|
5
5
|
* These types power the auto-complete and type-safe event contexts for
|
|
6
6
|
* database events like `after.User.create`.
|
|
7
7
|
*
|
package/dist/database/types.d.ts
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
1
|
import type { SchemaDef } from '@zenstackhq/schema';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Users augment this interface to register their ZenStack schemas per connection:
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* declare module '@stratal/framework/database' {
|
|
10
|
-
* interface DatabaseSchemaRegistry {
|
|
11
|
-
* main: typeof mainSchema
|
|
12
|
-
* analytics: typeof analyticsSchema
|
|
13
|
-
* }
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export interface DatabaseSchemaRegistry {
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Augmentable interface to declare the default database connection.
|
|
3
|
+
* Augment with schema, default connection, and per-connection slicing
|
|
4
|
+
* (auto-generated by @stratal/zenstack-plugin).
|
|
21
5
|
*
|
|
22
6
|
* @example
|
|
23
7
|
* ```typescript
|
|
24
8
|
* declare module '@stratal/framework/database' {
|
|
25
|
-
* interface
|
|
26
|
-
*
|
|
9
|
+
* interface StratalDatabase {
|
|
10
|
+
* schema: SchemaType
|
|
11
|
+
* defaultConnection: 'main'
|
|
12
|
+
* slicing: {
|
|
13
|
+
* main: { includedModels: readonly ['User', 'Post'] }
|
|
14
|
+
* analytics: { includedModels: readonly ['AnalyticsEvent'] }
|
|
15
|
+
* }
|
|
27
16
|
* }
|
|
28
17
|
* }
|
|
29
18
|
* ```
|
|
30
19
|
*/
|
|
31
|
-
export interface
|
|
20
|
+
export interface StratalDatabase {
|
|
32
21
|
}
|
|
22
|
+
/** Infer the shared schema type from augmentation, falling back to SchemaDef */
|
|
23
|
+
export type InferDatabaseSchema = StratalDatabase extends {
|
|
24
|
+
schema: infer S extends SchemaDef;
|
|
25
|
+
} ? S : SchemaDef;
|
|
33
26
|
/** Connection name with autocomplete when augmented, string fallback otherwise */
|
|
34
|
-
export type ConnectionName =
|
|
27
|
+
export type ConnectionName = StratalDatabase extends {
|
|
28
|
+
slicing: infer R;
|
|
29
|
+
} ? keyof R extends never ? string : Extract<keyof R, string> : string;
|
|
35
30
|
/** Default connection name from augmentation */
|
|
36
|
-
export type DefaultConnectionName =
|
|
37
|
-
|
|
31
|
+
export type DefaultConnectionName = StratalDatabase extends {
|
|
32
|
+
defaultConnection: infer N extends string;
|
|
38
33
|
} ? N : string;
|
|
39
|
-
/** Resolve
|
|
40
|
-
export type
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
/** Resolve slicing options for a named connection */
|
|
35
|
+
export type InferConnectionSlicing<K extends string> = StratalDatabase extends {
|
|
36
|
+
slicing: infer R;
|
|
37
|
+
} ? K extends keyof R ? R[K] : never : never;
|
|
43
38
|
/**
|
|
44
39
|
* Internal context used by database service for dynamic event emission
|
|
45
40
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAe;CAAG;AAEnC,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,GAC7B,eAAe,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,SAAS,SAAS,CAAA;CAAE,GAAG,CAAC,GAAG,SAAS,CAAA;AAE/E,kFAAkF;AAClF,MAAM,MAAM,cAAc,GACxB,eAAe,SAAS;IAAE,OAAO,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,MAAM,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GACzD,MAAM,CAAA;AAEZ,gDAAgD;AAChD,MAAM,MAAM,qBAAqB,GAC/B,eAAe,SAAS;IAAE,iBAAiB,EAAE,MAAM,CAAC,SAAS,MAAM,CAAA;CAAE,GAAG,CAAC,GAAG,MAAM,CAAA;AAEpF,qDAAqD;AACrD,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,IACjD,eAAe,SAAS;IAAE,OAAO,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAChC,KAAK,CAAA;AAEX;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { StratalDatabase, ConnectionName, DefaultConnectionName, InferDatabaseSchema, InferConnectionSlicing } from './database/types';
|
|
2
2
|
export type { CustomEventRegistry, EventName } from 'stratal/events';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAC3I,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stratal/framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Temitayo Fadojutimi",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"better-auth": "^1.4.9",
|
|
79
79
|
"casbin": "^5.41.0",
|
|
80
80
|
"pg": "^8.0.0",
|
|
81
|
-
"stratal": "0.0.
|
|
81
|
+
"stratal": "0.0.7"
|
|
82
82
|
},
|
|
83
83
|
"peerDependenciesMeta": {
|
|
84
84
|
"@better-auth/core": {
|
|
@@ -98,24 +98,24 @@
|
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@better-auth/core": "^1.5.
|
|
102
|
-
"@cloudflare/vitest-pool-workers": "^0.12.
|
|
103
|
-
"@cloudflare/workers-types": "4.
|
|
101
|
+
"@better-auth/core": "^1.5.4",
|
|
102
|
+
"@cloudflare/vitest-pool-workers": "^0.12.20",
|
|
103
|
+
"@cloudflare/workers-types": "4.20260307.1",
|
|
104
104
|
"@faker-js/faker": "^10.3.0",
|
|
105
105
|
"@stratal/testing": "workspace:^",
|
|
106
|
-
"@types/node": "^
|
|
106
|
+
"@types/node": "^25.3.5",
|
|
107
107
|
"@types/pg": "^8.18.0",
|
|
108
108
|
"@vitest/coverage-istanbul": "3.2.4",
|
|
109
|
-
"@zenstackhq/better-auth": "^3.4.
|
|
110
|
-
"@zenstackhq/cli": "^3.4.
|
|
111
|
-
"@zenstackhq/orm": "^3.4.
|
|
112
|
-
"better-auth": "^1.5.
|
|
109
|
+
"@zenstackhq/better-auth": "^3.4.4",
|
|
110
|
+
"@zenstackhq/cli": "^3.4.4",
|
|
111
|
+
"@zenstackhq/orm": "^3.4.4",
|
|
112
|
+
"better-auth": "^1.5.4",
|
|
113
113
|
"casbin": "^5.49.0",
|
|
114
|
-
"pg": "^8.
|
|
114
|
+
"pg": "^8.20.0",
|
|
115
115
|
"reflect-metadata": "^0.2.2",
|
|
116
116
|
"stratal": "workspace:*",
|
|
117
117
|
"typescript": "^5.9.3",
|
|
118
118
|
"vitest": "~3.2.0",
|
|
119
|
-
"wrangler": "^4.
|
|
119
|
+
"wrangler": "^4.71.0"
|
|
120
120
|
}
|
|
121
121
|
}
|