@fluojs/drizzle 1.1.1 → 2.0.0

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.
@@ -0,0 +1,120 @@
1
+ import { DrizzleDatabase } from './database.js';
2
+ import { getDrizzleDatabaseToken, getDrizzleDisposeToken, getDrizzleHandleProviderToken, getDrizzleOptionsToken } from './tokens.js';
3
+ import { DrizzleTransactionInterceptor } from './transaction.js';
4
+
5
+ /**
6
+ * Normalized runtime options consumed by lifecycle-aware Drizzle providers.
7
+ *
8
+ * @internal
9
+ */
10
+
11
+ /**
12
+ * Fully normalized module options stored behind an internal registration token.
13
+ *
14
+ * @internal
15
+ */
16
+
17
+ const DRIZZLE_NORMALIZED_OPTIONS = Symbol('fluo.drizzle.normalized-options');
18
+ const DRIZZLE_REGISTRATION_IDENTITIES = Symbol.for('fluo.drizzle.registration-identities');
19
+
20
+ /**
21
+ * Returns the internal options token for a default or named registration.
22
+ *
23
+ * @internal
24
+ * @param name Optional normalized registration name.
25
+ * @returns The internal token that stores normalized module options.
26
+ */
27
+ export function getNormalizedOptionsToken(name) {
28
+ return name === undefined ? DRIZZLE_NORMALIZED_OPTIONS : Symbol.for(`fluo.drizzle.normalized-options:${name}`);
29
+ }
30
+
31
+ /**
32
+ * Returns the globally stable duplicate-registration guard token for a name.
33
+ *
34
+ * @internal
35
+ * @param name Normalized named-registration identity.
36
+ * @returns The guard token shared by registrations using the same name.
37
+ */
38
+ export function getRegistrationGuardToken(name) {
39
+ return Symbol.for(`fluo.drizzle.registration-guard:${name}`);
40
+ }
41
+ function assertUniqueDrizzleRegistrationIdentities(identities) {
42
+ const seen = new Set();
43
+ for (const identity of identities) {
44
+ if (seen.has(identity)) {
45
+ throw new Error(`Duplicate @fluojs/drizzle registration identity "${identity}". Every named DrizzleModule.forRoot(...) registration owns one lifecycle-managed database, so pass a distinct name to each additional registration.`);
46
+ }
47
+ seen.add(identity);
48
+ }
49
+ }
50
+ function createRuntimeOptionsProviderValue(strictTransactions) {
51
+ return {
52
+ strictTransactions
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Builds the provider graph for a default or named Drizzle registration.
58
+ *
59
+ * @internal
60
+ * @param normalizedOptionsProvider Provider that supplies normalized module options.
61
+ * @param name Optional normalized registration name.
62
+ * @returns Providers for the registration's raw handle, lifecycle wrapper, options, and disposal hook.
63
+ */
64
+ export function createDrizzleRuntimeProviders(normalizedOptionsProvider, name) {
65
+ const normalizedOptionsToken = getNormalizedOptionsToken(name);
66
+ const databaseToken = getDrizzleDatabaseToken(name);
67
+ const disposeToken = getDrizzleDisposeToken(name);
68
+ const optionsToken = getDrizzleOptionsToken(name);
69
+ const handleProviderToken = getDrizzleHandleProviderToken(name);
70
+ const registrationGuardToken = name === undefined ? undefined : getRegistrationGuardToken(name);
71
+ const registrationProviders = registrationGuardToken === undefined ? [] : [{
72
+ multi: true,
73
+ provide: DRIZZLE_REGISTRATION_IDENTITIES,
74
+ useValue: name
75
+ }, {
76
+ inject: [DRIZZLE_REGISTRATION_IDENTITIES],
77
+ provide: registrationGuardToken,
78
+ scope: 'singleton',
79
+ useFactory: identities => {
80
+ assertUniqueDrizzleRegistrationIdentities(identities);
81
+ }
82
+ }];
83
+ const withRegistrationGuard = dependencies => registrationGuardToken === undefined ? [...dependencies] : [registrationGuardToken, ...dependencies];
84
+ return [...registrationProviders, normalizedOptionsProvider, {
85
+ inject: withRegistrationGuard([normalizedOptionsToken]),
86
+ provide: databaseToken,
87
+ useFactory: (...dependencies) => {
88
+ const options = dependencies.at(-1);
89
+ return options.database;
90
+ }
91
+ }, {
92
+ inject: withRegistrationGuard([normalizedOptionsToken]),
93
+ provide: disposeToken,
94
+ useFactory: (...dependencies) => {
95
+ const options = dependencies.at(-1);
96
+ return options.dispose;
97
+ }
98
+ }, {
99
+ inject: withRegistrationGuard([normalizedOptionsToken]),
100
+ provide: optionsToken,
101
+ useFactory: (...dependencies) => {
102
+ const options = dependencies.at(-1);
103
+ return createRuntimeOptionsProviderValue(options.strictTransactions);
104
+ }
105
+ }, ...(name === undefined ? [{
106
+ inject: [databaseToken, disposeToken, optionsToken],
107
+ provide: DrizzleDatabase,
108
+ useFactory: (database, dispose, databaseOptions) => DrizzleDatabase.createFacade(database, dispose, databaseOptions)
109
+ }, {
110
+ provide: handleProviderToken,
111
+ useExisting: DrizzleDatabase
112
+ }, DrizzleTransactionInterceptor] : [{
113
+ inject: withRegistrationGuard([databaseToken, disposeToken, optionsToken]),
114
+ provide: handleProviderToken,
115
+ useFactory: (...dependencies) => {
116
+ const [database, dispose, databaseOptions] = dependencies.slice(-3);
117
+ return DrizzleDatabase.createFacade(database, dispose, databaseOptions);
118
+ }
119
+ }])];
120
+ }
package/dist/tokens.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Token } from '@fluojs/core';
1
2
  /** Dependency-injection token for the raw Drizzle database handle. */
2
3
  export declare const DRIZZLE_DATABASE: unique symbol;
3
4
  /** Dependency-injection token for the lifecycle-aware Drizzle database wrapper. */
@@ -6,4 +7,32 @@ export declare const DRIZZLE_HANDLE_PROVIDER: unique symbol;
6
7
  export declare const DRIZZLE_DISPOSE: unique symbol;
7
8
  /** Dependency-injection token for normalized Drizzle runtime options. */
8
9
  export declare const DRIZZLE_OPTIONS: unique symbol;
10
+ /**
11
+ * Returns the DI token for the raw Drizzle database bound to a registration name.
12
+ *
13
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
14
+ * @returns The token that resolves the matching raw Drizzle database handle.
15
+ */
16
+ export declare function getDrizzleDatabaseToken(name?: string): Token;
17
+ /**
18
+ * Returns the DI token for the optional Drizzle disposal hook bound to a registration name.
19
+ *
20
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
21
+ * @returns The token that resolves the matching optional disposal hook.
22
+ */
23
+ export declare function getDrizzleDisposeToken(name?: string): Token;
24
+ /**
25
+ * Returns the DI token for the lifecycle-aware Drizzle handle bound to a registration name.
26
+ *
27
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
28
+ * @returns The token that resolves the matching lifecycle-aware Drizzle handle.
29
+ */
30
+ export declare function getDrizzleHandleProviderToken(name?: string): Token;
31
+ /**
32
+ * Returns the DI token for normalized Drizzle runtime options bound to a registration name.
33
+ *
34
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
35
+ * @returns The token that resolves the matching normalized runtime options.
36
+ */
37
+ export declare function getDrizzleOptionsToken(name?: string): Token;
9
38
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,eAAsC,CAAC;AACpE,mFAAmF;AACnF,eAAO,MAAM,uBAAuB,eAA6C,CAAC;AAClF,iFAAiF;AACjF,eAAO,MAAM,eAAe,eAAqC,CAAC;AAClE,yEAAyE;AACzE,eAAO,MAAM,eAAe,eAAqC,CAAC"}
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAI1C,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,eAAsC,CAAC;AACpE,mFAAmF;AACnF,eAAO,MAAM,uBAAuB,eAA6C,CAAC;AAClF,iFAAiF;AACjF,eAAO,MAAM,eAAe,eAAqC,CAAC;AAClE,yEAAyE;AACzE,eAAO,MAAM,eAAe,eAAqC,CAAC;AAElE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAM5D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAM3D;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAMlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAM3D"}
package/dist/tokens.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { normalizeDrizzleRegistrationName } from './registration-name.js';
2
+
1
3
  /** Dependency-injection token for the raw Drizzle database handle. */
2
4
  export const DRIZZLE_DATABASE = Symbol.for('fluo.drizzle.database');
3
5
  /** Dependency-injection token for the lifecycle-aware Drizzle database wrapper. */
@@ -5,4 +7,48 @@ export const DRIZZLE_HANDLE_PROVIDER = Symbol.for('fluo.drizzle.handle-provider'
5
7
  /** Dependency-injection token for the optional Drizzle shutdown dispose hook. */
6
8
  export const DRIZZLE_DISPOSE = Symbol.for('fluo.drizzle.dispose');
7
9
  /** Dependency-injection token for normalized Drizzle runtime options. */
8
- export const DRIZZLE_OPTIONS = Symbol.for('fluo.drizzle.options');
10
+ export const DRIZZLE_OPTIONS = Symbol.for('fluo.drizzle.options');
11
+
12
+ /**
13
+ * Returns the DI token for the raw Drizzle database bound to a registration name.
14
+ *
15
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
16
+ * @returns The token that resolves the matching raw Drizzle database handle.
17
+ */
18
+ export function getDrizzleDatabaseToken(name) {
19
+ const normalizedName = normalizeDrizzleRegistrationName(name);
20
+ return normalizedName === undefined ? DRIZZLE_DATABASE : Symbol.for(`fluo.drizzle.database:${normalizedName}`);
21
+ }
22
+
23
+ /**
24
+ * Returns the DI token for the optional Drizzle disposal hook bound to a registration name.
25
+ *
26
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
27
+ * @returns The token that resolves the matching optional disposal hook.
28
+ */
29
+ export function getDrizzleDisposeToken(name) {
30
+ const normalizedName = normalizeDrizzleRegistrationName(name);
31
+ return normalizedName === undefined ? DRIZZLE_DISPOSE : Symbol.for(`fluo.drizzle.dispose:${normalizedName}`);
32
+ }
33
+
34
+ /**
35
+ * Returns the DI token for the lifecycle-aware Drizzle handle bound to a registration name.
36
+ *
37
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
38
+ * @returns The token that resolves the matching lifecycle-aware Drizzle handle.
39
+ */
40
+ export function getDrizzleHandleProviderToken(name) {
41
+ const normalizedName = normalizeDrizzleRegistrationName(name);
42
+ return normalizedName === undefined ? DRIZZLE_HANDLE_PROVIDER : Symbol.for(`fluo.drizzle.handle-provider:${normalizedName}`);
43
+ }
44
+
45
+ /**
46
+ * Returns the DI token for normalized Drizzle runtime options bound to a registration name.
47
+ *
48
+ * @param name Optional registration name. Omit it to target the default unnamed Drizzle registration.
49
+ * @returns The token that resolves the matching normalized runtime options.
50
+ */
51
+ export function getDrizzleOptionsToken(name) {
52
+ const normalizedName = normalizeDrizzleRegistrationName(name);
53
+ return normalizedName === undefined ? DRIZZLE_OPTIONS : Symbol.for(`fluo.drizzle.options:${normalizedName}`);
54
+ }
@@ -1,3 +1,6 @@
1
+ import type { CallHandler, Interceptor, InterceptorContext } from '@fluojs/http';
2
+ import { DrizzleDatabase } from './database.js';
3
+ import type { DrizzleDatabaseLike } from './types.js';
1
4
  type TransactionCapableDrizzle<TTransactionOptions = unknown> = {
2
5
  transaction<T>(fn: () => Promise<T>, options?: TTransactionOptions): Promise<T>;
3
6
  };
@@ -17,5 +20,26 @@ type TransactionMethod<THost, TArgs extends unknown[], TResult> = (this: THost,
17
20
  * @returns A standard 2023-11 method decorator.
18
21
  */
19
22
  export declare function Transaction<THost, TTransactionOptions = unknown>(accessorOrOptions?: TransactionAccessor<THost, TTransactionOptions> | TTransactionOptions, options?: TTransactionOptions): <TArgs extends unknown[], TResult>(value: TransactionMethod<THost, TArgs, TResult>, context: ClassMethodDecoratorContext<THost, TransactionMethod<THost, TArgs, TResult>>) => TransactionMethod<THost, TArgs, TResult>;
23
+ /**
24
+ * Compatibility HTTP interceptor that opens a Drizzle request transaction around a routed handler.
25
+ *
26
+ * @remarks
27
+ * This deprecated 1.x bridge forwards the request `AbortSignal` to `DrizzleDatabase.requestTransaction(...)`.
28
+ * Prefer service-layer `@Transaction()` or an explicit request boundary for new code.
29
+ *
30
+ * @deprecated Prefer service-layer `@Transaction()` or explicit `DrizzleDatabase.requestTransaction(...)`.
31
+ */
32
+ export declare class DrizzleTransactionInterceptor implements Interceptor {
33
+ private readonly database;
34
+ constructor(database: DrizzleDatabase<DrizzleDatabaseLike<unknown, unknown>, unknown, unknown>);
35
+ /**
36
+ * Runs the downstream handler inside the compatibility request transaction.
37
+ *
38
+ * @param context Interceptor context containing the request cancellation signal.
39
+ * @param next Downstream handler chain.
40
+ * @returns The downstream result after the request transaction settles.
41
+ */
42
+ intercept(context: InterceptorContext, next: CallHandler): Promise<unknown>;
43
+ }
20
44
  export {};
21
45
  //# sourceMappingURL=transaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,CAAC,mBAAmB,GAAG,OAAO,IAAI;IAC9D,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACjF,CAAC;AAEF,KAAK,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,IAAI,CACrD,IAAI,EAAE,KAAK,KACR,yBAAyB,CAAC,mBAAmB,CAAC,CAAC;AAEpD,KAAK,iBAAiB,CAAC,KAAK,EAAE,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,IAAI,CAChE,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,KAAK,KACX,OAAO,CAAC,OAAO,CAAC,CAAC;AAwCtB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,EAC9D,iBAAiB,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,CAAC,GAAG,mBAAmB,EACzF,OAAO,CAAC,EAAE,mBAAmB,IAOr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,OAAO,EAAE,EAAE,OAAO,EACtC,OAAO,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAC/C,SAAS,2BAA2B,CAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,KACpF,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAc5C;AAED;;;;;;;;GAQG;AACH,qBACa,6BAA8B,YAAW,WAAW;IAE7D,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC;IAGrG;;;;;;OAMG;IACG,SAAS,CAAC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CAGlF"}
@@ -1,3 +1,11 @@
1
+ let _initClass;
2
+ function _applyDecs(e, t, n, r, o, i) { var a, c, u, s, f, l, p, d = Symbol.metadata || Symbol.for("Symbol.metadata"), m = Object.defineProperty, h = Object.create, y = [h(null), h(null)], v = t.length; function g(t, n, r) { return function (o, i) { n && (i = o, o = e); for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []); return r ? i : o; }; } function b(e, t, n, r) { if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined")); return e; } function applyDec(e, t, n, r, o, i, u, s, f, l, p) { function d(e) { if (!p(e)) throw new TypeError("Attempted to access private element on non-instance"); } var h = [].concat(t[0]), v = t[3], w = !u, D = 1 === o, S = 3 === o, j = 4 === o, E = 2 === o; function I(t, n, r) { return function (o, i) { return n && (i = o, o = e), r && r(o), P[t].call(o, i); }; } if (!w) { var P = {}, k = [], F = S ? "get" : j || D ? "set" : "value"; if (f ? (l || D ? P = { get: _setFunctionName(function () { return v(this); }, r, "get"), set: function (e) { t[4](this, e); } } : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) { if ((c = y[+s][r]) && 7 !== (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet"); y[+s][r] = o < 3 ? 1 : o; } } for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) { var T = b(h[O], "A decorator", "be", !0), z = n ? h[O - 1] : void 0, A = {}, H = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o], name: r, metadata: a, addInitializer: function (e, t) { if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished"); b(t, "An initializer", "be", !0), i.push(t); }.bind(null, A) }; if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);else if (H.static = s, H.private = f, c = H.access = { has: f ? p.bind() : function (e) { return r in e; } }, j || (c.get = f ? E ? function (e) { return d(e), P.value; } : I("get", 0, d) : function (e) { return e[r]; }), E || S || (c.set = f ? I("set", 0, d) : function (e, t) { e[r] = t; }), N = T.call(z, D ? { get: P.get, set: P.set } : P[F], H), A.v = 1, D) { if ("object" == typeof N && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined"); } else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N); } return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N; } function w(e) { return m(e, d, { configurable: !0, enumerable: !0, value: a }); } return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function (e) { e && f.push(g(e)); }, p = function (t, r) { for (var i = 0; i < n.length; i++) { var a = n[i], c = a[1], l = 7 & c; if ((8 & c) == t && !l == r) { var p = a[2], d = !!a[3], m = 16 & c; applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) { return _checkInRHS(t) === e; } : o); } } }, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), { e: c, get c() { var n = []; return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)]; } }; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
6
+ function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
7
+ import { Inject } from '@fluojs/core';
8
+ import { DrizzleDatabase } from './database.js';
1
9
  function isTransactionCapableDrizzle(value) {
2
10
  return typeof value?.transaction === 'function';
3
11
  }
@@ -13,6 +21,8 @@ function findNestedTransactionTarget(value) {
13
21
  if (isTransactionCapableDrizzle(propertyValue)) {
14
22
  return propertyValue;
15
23
  }
24
+ }
25
+ for (const propertyValue of Object.values(value)) {
16
26
  const nestedDatabase = propertyValue?.db;
17
27
  if (isTransactionCapableDrizzle(nestedDatabase)) {
18
28
  return nestedDatabase;
@@ -50,4 +60,38 @@ export function Transaction(accessorOrOptions, options) {
50
60
  return drizzleDatabase.transaction(() => value.apply(this, args), transactionOptions);
51
61
  };
52
62
  };
53
- }
63
+ }
64
+
65
+ /**
66
+ * Compatibility HTTP interceptor that opens a Drizzle request transaction around a routed handler.
67
+ *
68
+ * @remarks
69
+ * This deprecated 1.x bridge forwards the request `AbortSignal` to `DrizzleDatabase.requestTransaction(...)`.
70
+ * Prefer service-layer `@Transaction()` or an explicit request boundary for new code.
71
+ *
72
+ * @deprecated Prefer service-layer `@Transaction()` or explicit `DrizzleDatabase.requestTransaction(...)`.
73
+ */
74
+ let _DrizzleTransactionIn;
75
+ class DrizzleTransactionInterceptor {
76
+ static {
77
+ [_DrizzleTransactionIn, _initClass] = _applyDecs(this, [Inject(DrizzleDatabase)], []).c;
78
+ }
79
+ constructor(database) {
80
+ this.database = database;
81
+ }
82
+
83
+ /**
84
+ * Runs the downstream handler inside the compatibility request transaction.
85
+ *
86
+ * @param context Interceptor context containing the request cancellation signal.
87
+ * @param next Downstream handler chain.
88
+ * @returns The downstream result after the request transaction settles.
89
+ */
90
+ async intercept(context, next) {
91
+ return this.database.requestTransaction(() => next.handle(), context.requestContext.request.signal);
92
+ }
93
+ static {
94
+ _initClass();
95
+ }
96
+ }
97
+ export { _DrizzleTransactionIn as DrizzleTransactionInterceptor };
package/dist/types.d.ts CHANGED
@@ -25,6 +25,14 @@ export interface DrizzleModuleOptions<TDatabase extends DrizzleDatabaseLike<TTra
25
25
  dispose?: (database: TDatabase) => MaybePromise<void>;
26
26
  /** Whether Drizzle providers should be visible globally. Defaults to `false`. */
27
27
  global?: boolean;
28
+ /**
29
+ * Optional identity for an additional Drizzle registration.
30
+ *
31
+ * @remarks
32
+ * Named registrations are non-global. Consumers must import a module that exports the matching token;
33
+ * names do not create isolated runtime containers.
34
+ */
35
+ name?: string;
28
36
  /**
29
37
  * Throws when transaction helpers are used against a database that does not expose `transaction(...)`.
30
38
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AAEzE,KA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KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IACtD,iFAAiF;IACjF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB,CAAC,SAAS,SAAS,mBAAmB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,EAAE,oBAAoB,GAAG,SAAS,EAAE,mBAAmB,GAAG,OAAO;IACtL,wFAAwF;IACxF,4BAA4B,IAAI,iCAAiC,CAAC;IAClE,mGAAmG;IACnG,OAAO,IAAI,SAAS,GAAG,oBAAoB,CAAC;IAC5C;;;;;;;OAOG;IACH,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7G;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACjF"}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "transaction",
10
10
  "als"
11
11
  ],
12
- "version": "1.1.1",
12
+ "version": "2.0.0",
13
13
  "private": false,
14
14
  "license": "MIT",
15
15
  "repository": {
@@ -18,7 +18,7 @@
18
18
  "directory": "packages/drizzle"
19
19
  },
20
20
  "engines": {
21
- "node": ">=20.0.0"
21
+ "node": ">=24.0.0 <27"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"
@@ -36,12 +36,13 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@fluojs/core": "^1.1.0",
40
- "@fluojs/di": "^2.0.0",
41
- "@fluojs/runtime": "^2.0.1"
39
+ "@fluojs/core": "^2.0.0",
40
+ "@fluojs/di": "^3.0.0",
41
+ "@fluojs/http": "^3.0.0",
42
+ "@fluojs/runtime": "^3.0.0"
42
43
  },
43
44
  "peerDependencies": {
44
- "drizzle-orm": ">=0.30.0"
45
+ "drizzle-orm": ">=0.45.2"
45
46
  },
46
47
  "peerDependenciesMeta": {
47
48
  "drizzle-orm": {
@@ -49,8 +50,7 @@
49
50
  }
50
51
  },
51
52
  "devDependencies": {
52
- "vitest": "^3.2.4",
53
- "@fluojs/http": "^2.0.1"
53
+ "vitest": "^4.1.11"
54
54
  },
55
55
  "scripts": {
56
56
  "prebuild": "node ../../tooling/scripts/clean-dist.mjs",