@forinda/kickjs-prisma 1.6.0 → 1.7.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.
- package/dist/index.js +53 -53
- package/dist/prisma.adapter.d.ts +2 -2
- package/dist/prisma.adapter.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { Logger as
|
|
2
|
-
var
|
|
1
|
+
import { Logger as u, Scope as l } from "@forinda/kickjs-core";
|
|
2
|
+
var h = /* @__PURE__ */ Symbol("PrismaClient"), c = u.for("PrismaAdapter"), m = class {
|
|
3
3
|
name = "PrismaAdapter";
|
|
4
4
|
client;
|
|
5
|
-
constructor(
|
|
6
|
-
this.options =
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.options = e, this.client = e.client;
|
|
7
7
|
}
|
|
8
|
-
beforeStart(
|
|
9
|
-
this.options.logging && (typeof this.client.$on == "function" ? this.client.$on("query", (
|
|
10
|
-
c.debug(`Query: ${
|
|
11
|
-
}) : typeof this.client.$extends == "function" && (this.client = this.client.$extends({ query: { $allOperations({ operation:
|
|
12
|
-
const
|
|
13
|
-
return
|
|
14
|
-
const
|
|
15
|
-
return c.debug(`${
|
|
8
|
+
beforeStart({ container: e }) {
|
|
9
|
+
this.options.logging && (typeof this.client.$on == "function" ? this.client.$on("query", (r) => {
|
|
10
|
+
c.debug(`Query: ${r.query}`), c.debug(`Params: ${r.params}`), c.debug(`Duration: ${r.duration}ms`);
|
|
11
|
+
}) : typeof this.client.$extends == "function" && (this.client = this.client.$extends({ query: { $allOperations({ operation: r, model: t, args: o, query: i }) {
|
|
12
|
+
const s = performance.now();
|
|
13
|
+
return i(o).then((n) => {
|
|
14
|
+
const a = Math.round(performance.now() - s);
|
|
15
|
+
return c.debug(`${t}.${r} — ${a}ms`), n;
|
|
16
16
|
});
|
|
17
|
-
} } }))),
|
|
17
|
+
} } }))), e.registerFactory(h, () => this.client, l.SINGLETON), c.info("PrismaClient registered in DI container");
|
|
18
18
|
}
|
|
19
19
|
async shutdown() {
|
|
20
20
|
typeof this.client.$disconnect == "function" && (await this.client.$disconnect(), c.info("PrismaClient disconnected"));
|
|
21
21
|
}
|
|
22
|
-
},
|
|
22
|
+
}, f = class {
|
|
23
23
|
name = "PrismaQueryAdapter";
|
|
24
|
-
build(
|
|
25
|
-
const
|
|
26
|
-
if (o.length > 0 ||
|
|
24
|
+
build(e, r = {}) {
|
|
25
|
+
const t = {}, o = this.buildFilters(e.filters), i = this.buildSearch(e.search, r.searchColumns);
|
|
26
|
+
if (o.length > 0 || i) {
|
|
27
27
|
const n = [];
|
|
28
|
-
o.length > 0 && n.push(...o),
|
|
28
|
+
o.length > 0 && n.push(...o), i && n.push(i), t.where = n.length === 1 ? n[0] : { AND: n };
|
|
29
29
|
}
|
|
30
|
-
const s = this.buildSort(
|
|
31
|
-
return s.length > 0 && (
|
|
30
|
+
const s = this.buildSort(e.sort);
|
|
31
|
+
return s.length > 0 && (t.orderBy = s), t.skip = e.pagination.offset, t.take = e.pagination.limit, t;
|
|
32
32
|
}
|
|
33
|
-
buildFilters(
|
|
34
|
-
return
|
|
35
|
-
const { field:
|
|
33
|
+
buildFilters(e) {
|
|
34
|
+
return e.map((r) => {
|
|
35
|
+
const { field: t, operator: o, value: i } = r;
|
|
36
36
|
switch (o) {
|
|
37
37
|
case "eq":
|
|
38
|
-
return { [
|
|
38
|
+
return { [t]: { equals: this.coerce(i) } };
|
|
39
39
|
case "neq":
|
|
40
|
-
return { [
|
|
40
|
+
return { [t]: { not: this.coerce(i) } };
|
|
41
41
|
case "gt":
|
|
42
|
-
return { [
|
|
42
|
+
return { [t]: { gt: this.coerce(i) } };
|
|
43
43
|
case "gte":
|
|
44
|
-
return { [
|
|
44
|
+
return { [t]: { gte: this.coerce(i) } };
|
|
45
45
|
case "lt":
|
|
46
|
-
return { [
|
|
46
|
+
return { [t]: { lt: this.coerce(i) } };
|
|
47
47
|
case "lte":
|
|
48
|
-
return { [
|
|
48
|
+
return { [t]: { lte: this.coerce(i) } };
|
|
49
49
|
case "contains":
|
|
50
|
-
return { [
|
|
51
|
-
contains:
|
|
50
|
+
return { [t]: {
|
|
51
|
+
contains: i,
|
|
52
52
|
mode: "insensitive"
|
|
53
53
|
} };
|
|
54
54
|
case "starts":
|
|
55
|
-
return { [
|
|
56
|
-
startsWith:
|
|
55
|
+
return { [t]: {
|
|
56
|
+
startsWith: i,
|
|
57
57
|
mode: "insensitive"
|
|
58
58
|
} };
|
|
59
59
|
case "ends":
|
|
60
|
-
return { [
|
|
61
|
-
endsWith:
|
|
60
|
+
return { [t]: {
|
|
61
|
+
endsWith: i,
|
|
62
62
|
mode: "insensitive"
|
|
63
63
|
} };
|
|
64
64
|
case "in": {
|
|
65
|
-
const s =
|
|
66
|
-
return { [
|
|
65
|
+
const s = i.split(",").map((n) => this.coerce(n.trim()));
|
|
66
|
+
return { [t]: { in: s } };
|
|
67
67
|
}
|
|
68
68
|
case "between": {
|
|
69
|
-
const [s, n] =
|
|
70
|
-
return { [
|
|
69
|
+
const [s, n] = i.split(",").map((a) => this.coerce(a.trim()));
|
|
70
|
+
return { [t]: {
|
|
71
71
|
gte: s,
|
|
72
72
|
lte: n
|
|
73
73
|
} };
|
|
74
74
|
}
|
|
75
75
|
default:
|
|
76
|
-
return { [
|
|
76
|
+
return { [t]: { equals: this.coerce(i) } };
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
buildSort(
|
|
81
|
-
return
|
|
80
|
+
buildSort(e) {
|
|
81
|
+
return e.map((r) => ({ [r.field]: r.direction }));
|
|
82
82
|
}
|
|
83
|
-
buildSearch(
|
|
84
|
-
return !
|
|
85
|
-
contains:
|
|
83
|
+
buildSearch(e, r) {
|
|
84
|
+
return !e || !r || r.length === 0 ? null : { OR: r.map((t) => ({ [t]: {
|
|
85
|
+
contains: e,
|
|
86
86
|
mode: "insensitive"
|
|
87
87
|
} })) };
|
|
88
88
|
}
|
|
89
|
-
coerce(
|
|
90
|
-
if (
|
|
91
|
-
if (
|
|
92
|
-
const
|
|
93
|
-
return !Number.isNaN(
|
|
89
|
+
coerce(e) {
|
|
90
|
+
if (e === "true") return !0;
|
|
91
|
+
if (e === "false") return !1;
|
|
92
|
+
const r = Number(e);
|
|
93
|
+
return !Number.isNaN(r) && e.trim() !== "" ? r : e;
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
h as PRISMA_CLIENT,
|
|
98
|
+
m as PrismaAdapter,
|
|
99
|
+
f as PrismaQueryAdapter
|
|
100
100
|
};
|
package/dist/prisma.adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AppAdapter, type
|
|
1
|
+
import { type AppAdapter, type AdapterContext } from '@forinda/kickjs-core';
|
|
2
2
|
import { type PrismaAdapterOptions } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Prisma adapter — registers a PrismaClient in the DI container and manages
|
|
@@ -38,7 +38,7 @@ export declare class PrismaAdapter implements AppAdapter {
|
|
|
38
38
|
private client;
|
|
39
39
|
constructor(options: PrismaAdapterOptions);
|
|
40
40
|
/** Register the PrismaClient in the DI container */
|
|
41
|
-
beforeStart(
|
|
41
|
+
beforeStart({ container }: AdapterContext): void;
|
|
42
42
|
/** Disconnect the PrismaClient on shutdown */
|
|
43
43
|
shutdown(): Promise<void>;
|
|
44
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.adapter.d.ts","sourceRoot":"","sources":["../src/prisma.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"prisma.adapter.d.ts","sourceRoot":"","sources":["../src/prisma.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAC1F,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAIlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,aAAc,YAAW,UAAU;IAIlC,OAAO,CAAC,OAAO;IAH3B,IAAI,SAAkB;IACtB,OAAO,CAAC,MAAM,CAAK;gBAEC,OAAO,EAAE,oBAAoB;IAIjD,oDAAoD;IACpD,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,cAAc,GAAG,IAAI;IAiChD,8CAA8C;IACxC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAMhC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forinda/kickjs-prisma",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Prisma ORM adapter with DI integration, transaction support, and query building for KickJS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kickjs",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"reflect-metadata": "^0.2.2",
|
|
56
|
-
"@forinda/kickjs-
|
|
57
|
-
"@forinda/kickjs-
|
|
56
|
+
"@forinda/kickjs-http": "1.7.0",
|
|
57
|
+
"@forinda/kickjs-core": "1.7.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@prisma/client": ">=5.0.0"
|