@btravstack/prisma 0.13.0 → 0.15.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.cjs +9 -8
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +9 -8
- package/dist/rls.d.cts +5 -6
- package/dist/rls.d.mts +5 -6
- package/package.json +13 -14
package/dist/index.cjs
CHANGED
|
@@ -6,8 +6,8 @@ let _prisma_adapter_pg = require("@prisma/adapter-pg");
|
|
|
6
6
|
let unthrown = require("unthrown");
|
|
7
7
|
//#region src/instrument.ts
|
|
8
8
|
/**
|
|
9
|
-
* Every query,
|
|
10
|
-
* line if it failed.
|
|
9
|
+
* Every query, handed to the graph's observers: a count of how it came out, and
|
|
10
|
+
* a log line if it failed.
|
|
11
11
|
*
|
|
12
12
|
* **This is why a generated client can be instrumented at all.** Prisma's
|
|
13
13
|
* `$extends` takes a `query` component, and `$allModels.$allOperations`
|
|
@@ -16,10 +16,11 @@ let unthrown = require("unthrown");
|
|
|
16
16
|
* revision of this package claimed instrumentation was impossible for that
|
|
17
17
|
* reason; it was wrong, and this is the mechanism it missed.
|
|
18
18
|
*
|
|
19
|
-
* **It deliberately opens no span.** `@
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* **It deliberately opens no span.** Prisma's own `@prisma/instrumentation`,
|
|
20
|
+
* which this package offers to `Instrumentations` and
|
|
21
|
+
* `@btravstack/observability/otel` enables, traces at the ENGINE level — the
|
|
22
|
+
* real SQL, the connection acquisition, the serialisation — all of it below
|
|
23
|
+
* what a client-level wrapper can see. Emitting a span here as well would put two
|
|
23
24
|
* spans on every query for strictly less information. What this wrapper keeps
|
|
24
25
|
* is the pair Prisma's instrumentation does not do at all: a metric, and an
|
|
25
26
|
* error line correlated with the ambient unit.
|
|
@@ -143,7 +144,7 @@ const prismaDatabase = (name) => ({ client }) => {
|
|
|
143
144
|
inject: { logger: _btravstack_core.Logger },
|
|
144
145
|
sync: ({ logger }) => () => loadPrismaInstrumentation(logger)
|
|
145
146
|
});
|
|
146
|
-
const
|
|
147
|
+
const database = (0, _btravstack_di.Module)(name)({
|
|
147
148
|
needs: [_btravstack_config.Env, _btravstack_core.Logger],
|
|
148
149
|
provides: [
|
|
149
150
|
config,
|
|
@@ -161,7 +162,7 @@ const prismaDatabase = (name) => ({ client }) => {
|
|
|
161
162
|
_btravstack_core.Instrumentations
|
|
162
163
|
]
|
|
163
164
|
});
|
|
164
|
-
return Object.assign(
|
|
165
|
+
return Object.assign(database, { port: DatabasePort });
|
|
165
166
|
};
|
|
166
167
|
//#endregion
|
|
167
168
|
exports.prismaDatabase = prismaDatabase;
|
package/dist/index.d.cts
CHANGED
|
@@ -50,7 +50,7 @@ type PrismaOptions<C extends PrismaLike> = {
|
|
|
50
50
|
* against this same URL *before the process starts*; an application that
|
|
51
51
|
* migrates itself at boot races every other replica.
|
|
52
52
|
*/
|
|
53
|
-
declare const prismaDatabase: <const N extends string>(name: N) => <C extends PrismaLike>({ client }: PrismaOptions<C>) => Module<HealthChecks | Instrumentations | (PortClassOf<N, C> extends (infer T) ? T extends PortClassOf<N, C> ? T extends import("@btravstack/di").AnyPort ? InstanceType<T> : T extends import("@btravstack/di").AnyProvider ? InstanceType<T["port"]> : never : never : never), import("@btravstack/config").ConfigInvalid, Exclude<Env, HealthChecks | Instrumentations | Observers | import("@btravstack/di").PortInstance<string, C> | import("@btravstack/di").PortInstance<`${N}Config`, {
|
|
53
|
+
export declare const prismaDatabase: <const N extends string>(name: N) => <C extends PrismaLike>({ client }: PrismaOptions<C>) => Module<HealthChecks | Instrumentations | (PortClassOf<N, C> extends (infer T) ? T extends PortClassOf<N, C> ? T extends import("@btravstack/di").AnyPort ? InstanceType<T> : T extends import("@btravstack/di").AnyProvider ? InstanceType<T["port"]> : never : never : never), import("@btravstack/config").ConfigInvalid, Exclude<Env, HealthChecks | Instrumentations | Observers | import("@btravstack/di").PortInstance<string, C> | import("@btravstack/di").PortInstance<`${N}Config`, {
|
|
54
54
|
readonly url: string;
|
|
55
55
|
}>> | Exclude<Logger, HealthChecks | Instrumentations | Observers | import("@btravstack/di").PortInstance<string, C> | import("@btravstack/di").PortInstance<`${N}Config`, {
|
|
56
56
|
readonly url: string;
|
|
@@ -58,4 +58,4 @@ declare const prismaDatabase: <const N extends string>(name: N) => <C extends Pr
|
|
|
58
58
|
readonly port: PortClassOf<N, C>;
|
|
59
59
|
};
|
|
60
60
|
//#endregion
|
|
61
|
-
export {
|
|
61
|
+
export type { PrismaLike, PrismaOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -50,7 +50,7 @@ type PrismaOptions<C extends PrismaLike> = {
|
|
|
50
50
|
* against this same URL *before the process starts*; an application that
|
|
51
51
|
* migrates itself at boot races every other replica.
|
|
52
52
|
*/
|
|
53
|
-
declare const prismaDatabase: <const N extends string>(name: N) => <C extends PrismaLike>({ client }: PrismaOptions<C>) => Module<HealthChecks | Instrumentations | (PortClassOf<N, C> extends (infer T) ? T extends PortClassOf<N, C> ? T extends import("@btravstack/di").AnyPort ? InstanceType<T> : T extends import("@btravstack/di").AnyProvider ? InstanceType<T["port"]> : never : never : never), import("@btravstack/config").ConfigInvalid, Exclude<Env, HealthChecks | Instrumentations | Observers | import("@btravstack/di").PortInstance<string, C> | import("@btravstack/di").PortInstance<`${N}Config`, {
|
|
53
|
+
export declare const prismaDatabase: <const N extends string>(name: N) => <C extends PrismaLike>({ client }: PrismaOptions<C>) => Module<HealthChecks | Instrumentations | (PortClassOf<N, C> extends (infer T) ? T extends PortClassOf<N, C> ? T extends import("@btravstack/di").AnyPort ? InstanceType<T> : T extends import("@btravstack/di").AnyProvider ? InstanceType<T["port"]> : never : never : never), import("@btravstack/config").ConfigInvalid, Exclude<Env, HealthChecks | Instrumentations | Observers | import("@btravstack/di").PortInstance<string, C> | import("@btravstack/di").PortInstance<`${N}Config`, {
|
|
54
54
|
readonly url: string;
|
|
55
55
|
}>> | Exclude<Logger, HealthChecks | Instrumentations | Observers | import("@btravstack/di").PortInstance<string, C> | import("@btravstack/di").PortInstance<`${N}Config`, {
|
|
56
56
|
readonly url: string;
|
|
@@ -58,4 +58,4 @@ declare const prismaDatabase: <const N extends string>(name: N) => <C extends Pr
|
|
|
58
58
|
readonly port: PortClassOf<N, C>;
|
|
59
59
|
};
|
|
60
60
|
//#endregion
|
|
61
|
-
export {
|
|
61
|
+
export type { PrismaLike, PrismaOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import { PrismaPg } from "@prisma/adapter-pg";
|
|
|
5
5
|
import { fromPromise, fromSafePromise } from "unthrown";
|
|
6
6
|
//#region src/instrument.ts
|
|
7
7
|
/**
|
|
8
|
-
* Every query,
|
|
9
|
-
* line if it failed.
|
|
8
|
+
* Every query, handed to the graph's observers: a count of how it came out, and
|
|
9
|
+
* a log line if it failed.
|
|
10
10
|
*
|
|
11
11
|
* **This is why a generated client can be instrumented at all.** Prisma's
|
|
12
12
|
* `$extends` takes a `query` component, and `$allModels.$allOperations`
|
|
@@ -15,10 +15,11 @@ import { fromPromise, fromSafePromise } from "unthrown";
|
|
|
15
15
|
* revision of this package claimed instrumentation was impossible for that
|
|
16
16
|
* reason; it was wrong, and this is the mechanism it missed.
|
|
17
17
|
*
|
|
18
|
-
* **It deliberately opens no span.** `@
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* **It deliberately opens no span.** Prisma's own `@prisma/instrumentation`,
|
|
19
|
+
* which this package offers to `Instrumentations` and
|
|
20
|
+
* `@btravstack/observability/otel` enables, traces at the ENGINE level — the
|
|
21
|
+
* real SQL, the connection acquisition, the serialisation — all of it below
|
|
22
|
+
* what a client-level wrapper can see. Emitting a span here as well would put two
|
|
22
23
|
* spans on every query for strictly less information. What this wrapper keeps
|
|
23
24
|
* is the pair Prisma's instrumentation does not do at all: a metric, and an
|
|
24
25
|
* error line correlated with the ambient unit.
|
|
@@ -142,7 +143,7 @@ const prismaDatabase = (name) => ({ client }) => {
|
|
|
142
143
|
inject: { logger: Logger },
|
|
143
144
|
sync: ({ logger }) => () => loadPrismaInstrumentation(logger)
|
|
144
145
|
});
|
|
145
|
-
const
|
|
146
|
+
const database = Module(name)({
|
|
146
147
|
needs: [Env, Logger],
|
|
147
148
|
provides: [
|
|
148
149
|
config,
|
|
@@ -160,7 +161,7 @@ const prismaDatabase = (name) => ({ client }) => {
|
|
|
160
161
|
Instrumentations
|
|
161
162
|
]
|
|
162
163
|
});
|
|
163
|
-
return Object.assign(
|
|
164
|
+
return Object.assign(database, { port: DatabasePort });
|
|
164
165
|
};
|
|
165
166
|
//#endregion
|
|
166
167
|
export { prismaDatabase };
|
package/dist/rls.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/rls.d.ts
|
|
2
2
|
/** Options of {@link tenantScoped}. */
|
|
3
|
-
type TenantScopedOptions = {
|
|
3
|
+
export type TenantScopedOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* The PostgreSQL run-time setting the policy reads. Defaults to
|
|
6
6
|
* `app.tenant_id`, matching `current_setting('app.tenant_id', true)`.
|
|
@@ -15,7 +15,7 @@ type TenantScopedOptions = {
|
|
|
15
15
|
* Not `@unthrown/prisma`'s `TransactionClient`, which denies a longer list; an
|
|
16
16
|
* application applying both extensions imports both names.
|
|
17
17
|
*/
|
|
18
|
-
type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends" | "$on" | "$use">;
|
|
18
|
+
export type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends" | "$on" | "$use">;
|
|
19
19
|
/**
|
|
20
20
|
* The `$transaction` a {@link tenantScoped} client exposes: the callback form
|
|
21
21
|
* only, with `this` carrying the extended client through to `tx`.
|
|
@@ -25,7 +25,7 @@ type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends
|
|
|
25
25
|
* generated client, so the receiver is the only place that type can come from.
|
|
26
26
|
* The array form is absent because it cannot be pinned atomically.
|
|
27
27
|
*/
|
|
28
|
-
type ScopedTransaction = <C, R>(this: C, fn: (tx: ScopedTransactionClient<C>) => Promise<R>, options?: {
|
|
28
|
+
export type ScopedTransaction = <C, R>(this: C, fn: (tx: ScopedTransactionClient<C>) => Promise<R>, options?: {
|
|
29
29
|
maxWait?: number;
|
|
30
30
|
timeout?: number;
|
|
31
31
|
isolationLevel?: string;
|
|
@@ -48,8 +48,7 @@ type ScopedTransaction = <C, R>(this: C, fn: (tx: ScopedTransactionClient<C>) =>
|
|
|
48
48
|
* const db = new PrismaClient({ adapter }).$extends(unthrownPrisma).$extends(tenantScoped(tenant));
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
declare const tenantScoped: (tenant: string, options?: TenantScopedOptions) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client").InternalArgs<{}, {}, {}, {
|
|
51
|
+
export declare const tenantScoped: (tenant: string, options?: TenantScopedOptions) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client").InternalArgs<{}, {}, {}, {
|
|
52
52
|
$transaction: ScopedTransaction;
|
|
53
53
|
}> & import("@prisma/client/runtime/client").DefaultArgs>;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { ScopedTransaction, ScopedTransactionClient, TenantScopedOptions, tenantScoped };
|
|
54
|
+
//#endregion
|
package/dist/rls.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/rls.d.ts
|
|
2
2
|
/** Options of {@link tenantScoped}. */
|
|
3
|
-
type TenantScopedOptions = {
|
|
3
|
+
export type TenantScopedOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* The PostgreSQL run-time setting the policy reads. Defaults to
|
|
6
6
|
* `app.tenant_id`, matching `current_setting('app.tenant_id', true)`.
|
|
@@ -15,7 +15,7 @@ type TenantScopedOptions = {
|
|
|
15
15
|
* Not `@unthrown/prisma`'s `TransactionClient`, which denies a longer list; an
|
|
16
16
|
* application applying both extensions imports both names.
|
|
17
17
|
*/
|
|
18
|
-
type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends" | "$on" | "$use">;
|
|
18
|
+
export type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends" | "$on" | "$use">;
|
|
19
19
|
/**
|
|
20
20
|
* The `$transaction` a {@link tenantScoped} client exposes: the callback form
|
|
21
21
|
* only, with `this` carrying the extended client through to `tx`.
|
|
@@ -25,7 +25,7 @@ type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends
|
|
|
25
25
|
* generated client, so the receiver is the only place that type can come from.
|
|
26
26
|
* The array form is absent because it cannot be pinned atomically.
|
|
27
27
|
*/
|
|
28
|
-
type ScopedTransaction = <C, R>(this: C, fn: (tx: ScopedTransactionClient<C>) => Promise<R>, options?: {
|
|
28
|
+
export type ScopedTransaction = <C, R>(this: C, fn: (tx: ScopedTransactionClient<C>) => Promise<R>, options?: {
|
|
29
29
|
maxWait?: number;
|
|
30
30
|
timeout?: number;
|
|
31
31
|
isolationLevel?: string;
|
|
@@ -48,8 +48,7 @@ type ScopedTransaction = <C, R>(this: C, fn: (tx: ScopedTransactionClient<C>) =>
|
|
|
48
48
|
* const db = new PrismaClient({ adapter }).$extends(unthrownPrisma).$extends(tenantScoped(tenant));
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
declare const tenantScoped: (tenant: string, options?: TenantScopedOptions) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client").InternalArgs<{}, {}, {}, {
|
|
51
|
+
export declare const tenantScoped: (tenant: string, options?: TenantScopedOptions) => (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client").InternalArgs<{}, {}, {}, {
|
|
52
52
|
$transaction: ScopedTransaction;
|
|
53
53
|
}> & import("@prisma/client/runtime/client").DefaultArgs>;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { ScopedTransaction, ScopedTransactionClient, TenantScopedOptions, tenantScoped };
|
|
54
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btravstack/prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "The Prisma starter for @btravstack/core: DATABASE_URL through Config, the Postgres driver adapter, and a client whose pool is the application scope's",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -53,29 +53,29 @@
|
|
|
53
53
|
"./package.json": "./package.json"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
+
"@btravstack/config": "0.15.0",
|
|
57
|
+
"@btravstack/core": "0.15.0",
|
|
58
|
+
"@btravstack/di": "0.15.0",
|
|
56
59
|
"@btravstack/tsconfig": "0.4.0",
|
|
57
60
|
"@prisma/adapter-pg": "7.10.0",
|
|
58
61
|
"@prisma/client": "7.10.0",
|
|
59
62
|
"@prisma/instrumentation": "7.10.0",
|
|
60
|
-
"@types/node": "26.4.
|
|
61
|
-
"@unthrown/vitest": "5.
|
|
63
|
+
"@types/node": "26.4.1",
|
|
64
|
+
"@unthrown/vitest": "5.8.0",
|
|
62
65
|
"@vitest/coverage-v8": "4.1.11",
|
|
63
|
-
"tsdown": "0.
|
|
66
|
+
"tsdown": "0.23.0",
|
|
64
67
|
"typescript": "7.0.2",
|
|
65
|
-
"unthrown": "5.
|
|
66
|
-
"vitest": "4.1.11"
|
|
67
|
-
"@btravstack/config": "0.13.0",
|
|
68
|
-
"@btravstack/core": "0.13.0",
|
|
69
|
-
"@btravstack/di": "0.13.0"
|
|
68
|
+
"unthrown": "5.8.0",
|
|
69
|
+
"vitest": "4.1.11"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
+
"@btravstack/config": "^0.15.0",
|
|
73
|
+
"@btravstack/core": "^0.15.0",
|
|
74
|
+
"@btravstack/di": "^0.15.0",
|
|
72
75
|
"@prisma/adapter-pg": "^7.0.0",
|
|
73
76
|
"@prisma/client": "^7.10.0",
|
|
74
77
|
"@prisma/instrumentation": "^7.0.0",
|
|
75
|
-
"unthrown": "^5.0.0"
|
|
76
|
-
"@btravstack/config": "^0.13.0",
|
|
77
|
-
"@btravstack/core": "^0.13.0",
|
|
78
|
-
"@btravstack/di": "^0.13.0"
|
|
78
|
+
"unthrown": "^5.0.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependenciesMeta": {
|
|
81
81
|
"@prisma/client": {
|
|
@@ -92,7 +92,6 @@
|
|
|
92
92
|
"build": "tsdown src/index.ts src/rls.ts --format cjs,esm --dts --clean",
|
|
93
93
|
"dev": "tsdown src/index.ts src/rls.ts --format cjs,esm --dts --watch",
|
|
94
94
|
"test": "vitest run --coverage",
|
|
95
|
-
"test:types": "tsc -p tsconfig.test-d.json --noEmit",
|
|
96
95
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test-d.json"
|
|
97
96
|
}
|
|
98
97
|
}
|