@fluojs/prisma 1.1.0 → 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.
@@ -1,5 +1,14 @@
1
- function hasTransaction(value) {
2
- return typeof value === 'object' && value !== null && 'transaction' in value && typeof value.transaction === 'function';
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 { isPrismaServiceHandle } from './prisma-service-brand.js';
9
+ import { PrismaService } from './service.js';
10
+ function isPrismaServiceLike(value) {
11
+ return typeof value === 'object' && value !== null && isPrismaServiceHandle(value) && 'createPlatformStatusSnapshot' in value && typeof value.createPlatformStatusSnapshot === 'function' && 'current' in value && typeof value.current === 'function' && 'transaction' in value && typeof value.transaction === 'function';
3
12
  }
4
13
  function readProperty(value, property) {
5
14
  if (typeof value !== 'object' && typeof value !== 'function' || value === null) {
@@ -7,22 +16,27 @@ function readProperty(value, property) {
7
16
  }
8
17
  return Reflect.get(value, property);
9
18
  }
19
+ function addPrismaServiceCandidate(candidates, value) {
20
+ if (!isPrismaServiceLike(value) || candidates.includes(value)) {
21
+ return;
22
+ }
23
+ candidates.push(value);
24
+ }
10
25
  function resolveDefaultPrismaService(self) {
26
+ const candidates = [];
11
27
  const directPrisma = readProperty(self, 'prisma');
12
- if (hasTransaction(directPrisma)) {
13
- return directPrisma;
14
- }
15
- if (hasTransaction(self)) {
16
- return self;
17
- }
28
+ addPrismaServiceCandidate(candidates, directPrisma);
29
+ addPrismaServiceCandidate(candidates, self);
18
30
  for (const value of Object.values(Object(self))) {
19
- if (hasTransaction(value)) {
20
- return value;
21
- }
31
+ addPrismaServiceCandidate(candidates, value);
22
32
  const nestedPrisma = readProperty(value, 'prisma');
23
- if (hasTransaction(nestedPrisma)) {
24
- return nestedPrisma;
25
- }
33
+ addPrismaServiceCandidate(candidates, nestedPrisma);
34
+ }
35
+ if (candidates.length === 1) {
36
+ return candidates[0];
37
+ }
38
+ if (candidates.length > 1) {
39
+ throw new Error('Ambiguous PrismaService resolution for @Transaction(). Provide an explicit accessor function.');
26
40
  }
27
41
  throw new Error('Unable to resolve PrismaService for @Transaction(). Provide an accessor function.');
28
42
  }
@@ -65,4 +79,39 @@ export function Transaction(input) {
65
79
  return prisma.transaction(() => value.apply(this, args), options);
66
80
  };
67
81
  };
68
- }
82
+ }
83
+
84
+ /**
85
+ * Compatibility HTTP interceptor that opens a Prisma request transaction around a routed handler.
86
+ *
87
+ * @remarks
88
+ * This deprecated 1.x bridge forwards the request `AbortSignal` to `PrismaService.requestTransaction(...)` and is
89
+ * registered only by the unnamed `PrismaModule` entrypoint. Prefer service-layer `@Transaction()` or an explicit
90
+ * request boundary for new code.
91
+ *
92
+ * @deprecated Prefer service-layer `@Transaction()` or explicit `PrismaService.requestTransaction(...)`.
93
+ */
94
+ let _PrismaTransactionInt;
95
+ class PrismaTransactionInterceptor {
96
+ static {
97
+ [_PrismaTransactionInt, _initClass] = _applyDecs(this, [Inject(PrismaService)], []).c;
98
+ }
99
+ constructor(prisma) {
100
+ this.prisma = prisma;
101
+ }
102
+
103
+ /**
104
+ * Runs the downstream handler inside the compatibility request transaction.
105
+ *
106
+ * @param context Interceptor context containing the request cancellation signal.
107
+ * @param next Downstream handler chain.
108
+ * @returns The downstream result after the request transaction settles.
109
+ */
110
+ async intercept(context, next) {
111
+ return this.prisma.requestTransaction(() => next.handle(), context.requestContext.request.signal);
112
+ }
113
+ static {
114
+ _initClass();
115
+ }
116
+ }
117
+ export { _PrismaTransactionInt as PrismaTransactionInterceptor };
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "transaction",
10
10
  "als"
11
11
  ],
12
- "version": "1.1.0",
12
+ "version": "2.0.0",
13
13
  "private": false,
14
14
  "license": "MIT",
15
15
  "repository": {
@@ -18,7 +18,7 @@
18
18
  "directory": "packages/prisma"
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,10 +36,9 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@fluojs/core": "^1.0.3",
40
- "@fluojs/http": "^1.1.2",
41
- "@fluojs/di": "^1.1.0",
42
- "@fluojs/runtime": "^1.1.8"
39
+ "@fluojs/core": "^2.0.0",
40
+ "@fluojs/http": "^3.0.0",
41
+ "@fluojs/di": "^3.0.0"
43
42
  },
44
43
  "peerDependencies": {
45
44
  "@prisma/client": ">=5.0.0"
@@ -50,8 +49,9 @@
50
49
  }
51
50
  },
52
51
  "devDependencies": {
53
- "vitest": "^3.2.4",
54
- "@fluojs/validation": "^1.0.5"
52
+ "vitest": "^4.1.11",
53
+ "@fluojs/runtime": "^3.0.0",
54
+ "@fluojs/validation": "^2.0.0"
55
55
  },
56
56
  "scripts": {
57
57
  "prebuild": "node ../../tooling/scripts/clean-dist.mjs",