@nexus_js/db 0.6.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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/adapters/drizzle.d.ts +30 -0
- package/dist/adapters/drizzle.d.ts.map +1 -0
- package/dist/adapters/drizzle.js +31 -0
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/libsql.d.ts +51 -0
- package/dist/adapters/libsql.d.ts.map +1 -0
- package/dist/adapters/libsql.js +51 -0
- package/dist/adapters/libsql.js.map +1 -0
- package/dist/adapters/prisma.d.ts +46 -0
- package/dist/adapters/prisma.d.ts.map +1 -0
- package/dist/adapters/prisma.js +58 -0
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nexus Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @nexus_js/db
|
|
2
|
+
|
|
3
|
+
Nexus DB — BYOD thin provider adapter (Prisma, Drizzle, libSQL, Postgres.js).
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
All guides, API reference, and examples live on **[nexusjs.dev](https://nexusjs.dev)**.
|
|
8
|
+
|
|
9
|
+
## Links
|
|
10
|
+
|
|
11
|
+
- **Website:** [https://nexusjs.dev](https://nexusjs.dev)
|
|
12
|
+
- **Repository:** [github.com/bierfor/nexus](https://github.com/bierfor/nexus) (see `packages/db/`)
|
|
13
|
+
- **Issues:** [github.com/bierfor/nexus/issues](https://github.com/bierfor/nexus/issues)
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT © Nexus contributors
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db/adapters/drizzle — Drizzle ORM adapter.
|
|
3
|
+
*
|
|
4
|
+
* Drizzle is schema-first, SQL-native, and Edge-native by default.
|
|
5
|
+
* This adapter wires it to Nexus's cache() and revalidate() system.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { drizzle } from 'drizzle-orm/postgres-js';
|
|
9
|
+
* import postgres from 'postgres';
|
|
10
|
+
* import { drizzleAdapter } from '@nexus_js/db/adapters/drizzle';
|
|
11
|
+
* import * as schema from './schema';
|
|
12
|
+
*
|
|
13
|
+
* const sql = postgres(process.env.DATABASE_URL!);
|
|
14
|
+
* export const db = drizzleAdapter(drizzle(sql, { schema }), {
|
|
15
|
+
* schema,
|
|
16
|
+
* edge: true,
|
|
17
|
+
* });
|
|
18
|
+
*/
|
|
19
|
+
import type { NexusDBProvider } from '../index.js';
|
|
20
|
+
export interface DrizzleAdapterOptions<TSchema> {
|
|
21
|
+
schema?: TSchema;
|
|
22
|
+
/** Set to true if using an HTTP-based driver (PlanetScale, Neon serverless, Turso) */
|
|
23
|
+
edge?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface DrizzleAdapter<TClient> extends NexusDBProvider<TClient> {
|
|
26
|
+
/** The raw Drizzle client */
|
|
27
|
+
drizzle: TClient;
|
|
28
|
+
}
|
|
29
|
+
export declare function drizzleAdapter<TClient>(drizzleClient: TClient, opts?: DrizzleAdapterOptions<unknown>): DrizzleAdapter<TClient>;
|
|
30
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,qBAAqB,CAAC,OAAO;IAC5C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sFAAsF;IACtF,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,cAAc,CAAC,OAAO,CAAE,SAAQ,eAAe,CAAC,OAAO,CAAC;IACvE,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,cAAc,CAAC,OAAO,EACpC,aAAa,EAAE,OAAO,EACtB,IAAI,GAAE,qBAAqB,CAAC,OAAO,CAAM,GACxC,cAAc,CAAC,OAAO,CAAC,CAWzB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db/adapters/drizzle — Drizzle ORM adapter.
|
|
3
|
+
*
|
|
4
|
+
* Drizzle is schema-first, SQL-native, and Edge-native by default.
|
|
5
|
+
* This adapter wires it to Nexus's cache() and revalidate() system.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { drizzle } from 'drizzle-orm/postgres-js';
|
|
9
|
+
* import postgres from 'postgres';
|
|
10
|
+
* import { drizzleAdapter } from '@nexus_js/db/adapters/drizzle';
|
|
11
|
+
* import * as schema from './schema';
|
|
12
|
+
*
|
|
13
|
+
* const sql = postgres(process.env.DATABASE_URL!);
|
|
14
|
+
* export const db = drizzleAdapter(drizzle(sql, { schema }), {
|
|
15
|
+
* schema,
|
|
16
|
+
* edge: true,
|
|
17
|
+
* });
|
|
18
|
+
*/
|
|
19
|
+
import { defineDB } from '../index.js';
|
|
20
|
+
export function drizzleAdapter(drizzleClient, opts = {}) {
|
|
21
|
+
const base = defineDB(drizzleClient, {
|
|
22
|
+
tags: (table) => [table],
|
|
23
|
+
edge: opts.edge ?? false,
|
|
24
|
+
defaultTtl: 0,
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
...base,
|
|
28
|
+
drizzle: drizzleClient,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=drizzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.js","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAcvC,MAAM,UAAU,cAAc,CAC5B,aAAsB,EACtB,OAAuC,EAAE;IAEzC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,EAAE;QACnC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC;QACxB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,KAAK;QACxB,UAAU,EAAE,CAAC;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,aAAa;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db/adapters/libsql — Turso/libSQL adapter.
|
|
3
|
+
*
|
|
4
|
+
* libSQL is the Edge-native SQLite database. This adapter provides:
|
|
5
|
+
* - Typed query helpers wrapping the libSQL client
|
|
6
|
+
* - Automatic batch support for multi-statement transactions
|
|
7
|
+
* - Integration with Nexus cache (TTL-based row caching)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { createClient } from '@libsql/client';
|
|
11
|
+
* import { libsqlAdapter } from '@nexus_js/db/adapters/libsql';
|
|
12
|
+
*
|
|
13
|
+
* export const db = libsqlAdapter(createClient({
|
|
14
|
+
* url: process.env.TURSO_URL!,
|
|
15
|
+
* authToken: process.env.TURSO_TOKEN,
|
|
16
|
+
* }));
|
|
17
|
+
*/
|
|
18
|
+
import type { NexusDBProvider } from '../index.js';
|
|
19
|
+
export interface LibSQLClient {
|
|
20
|
+
execute: (stmt: {
|
|
21
|
+
sql: string;
|
|
22
|
+
args?: unknown[];
|
|
23
|
+
}) => Promise<{
|
|
24
|
+
rows: unknown[];
|
|
25
|
+
}>;
|
|
26
|
+
batch?: (stmts: {
|
|
27
|
+
sql: string;
|
|
28
|
+
args?: unknown[];
|
|
29
|
+
}[]) => Promise<{
|
|
30
|
+
rows: unknown[];
|
|
31
|
+
}[]>;
|
|
32
|
+
}
|
|
33
|
+
export interface LibSQLAdapterOptions {
|
|
34
|
+
defaultTtl?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface LibSQLAdapter extends NexusDBProvider<LibSQLClient> {
|
|
37
|
+
libsql: LibSQLClient;
|
|
38
|
+
/**
|
|
39
|
+
* Execute a raw SQL statement and return typed rows.
|
|
40
|
+
*/
|
|
41
|
+
sql<T = Record<string, unknown>>(query: string, args?: unknown[]): Promise<T[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute multiple statements in a batch (atomic in Turso).
|
|
44
|
+
*/
|
|
45
|
+
batch(stmts: {
|
|
46
|
+
sql: string;
|
|
47
|
+
args?: unknown[];
|
|
48
|
+
}[]): Promise<unknown[][]>;
|
|
49
|
+
}
|
|
50
|
+
export declare function libsqlAdapter(client: LibSQLClient, opts?: LibSQLAdapterOptions): LibSQLAdapter;
|
|
51
|
+
//# sourceMappingURL=libsql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libsql.d.ts","sourceRoot":"","sources":["../../src/adapters/libsql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;IACnF,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,CAAC,CAAC;CACxF;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAc,SAAQ,eAAe,CAAC,YAAY,CAAC;IAClE,MAAM,EAAE,YAAY,CAAC;IACrB;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,OAAO,EAAE,GACf,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;CACzE;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,YAAY,EACpB,IAAI,GAAE,oBAAyB,GAC9B,aAAa,CAkCf"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db/adapters/libsql — Turso/libSQL adapter.
|
|
3
|
+
*
|
|
4
|
+
* libSQL is the Edge-native SQLite database. This adapter provides:
|
|
5
|
+
* - Typed query helpers wrapping the libSQL client
|
|
6
|
+
* - Automatic batch support for multi-statement transactions
|
|
7
|
+
* - Integration with Nexus cache (TTL-based row caching)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import { createClient } from '@libsql/client';
|
|
11
|
+
* import { libsqlAdapter } from '@nexus_js/db/adapters/libsql';
|
|
12
|
+
*
|
|
13
|
+
* export const db = libsqlAdapter(createClient({
|
|
14
|
+
* url: process.env.TURSO_URL!,
|
|
15
|
+
* authToken: process.env.TURSO_TOKEN,
|
|
16
|
+
* }));
|
|
17
|
+
*/
|
|
18
|
+
import { defineDB } from '../index.js';
|
|
19
|
+
export function libsqlAdapter(client, opts = {}) {
|
|
20
|
+
const base = defineDB(client, {
|
|
21
|
+
tags: (table) => [table],
|
|
22
|
+
edge: true,
|
|
23
|
+
defaultTtl: opts.defaultTtl ?? 0,
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
...base,
|
|
27
|
+
libsql: client,
|
|
28
|
+
async sql(sql, args = []) {
|
|
29
|
+
const result = await client.execute({ sql, args });
|
|
30
|
+
return result.rows;
|
|
31
|
+
},
|
|
32
|
+
async batch(stmts) {
|
|
33
|
+
if (!client.batch) {
|
|
34
|
+
throw new Error('This libSQL client does not support batch operations.');
|
|
35
|
+
}
|
|
36
|
+
const results = await client.batch(stmts);
|
|
37
|
+
return results.map((r) => r.rows);
|
|
38
|
+
},
|
|
39
|
+
async health() {
|
|
40
|
+
const start = Date.now();
|
|
41
|
+
try {
|
|
42
|
+
await client.execute({ sql: 'SELECT 1' });
|
|
43
|
+
return { ok: true, latency: Date.now() - start };
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return { ok: false, latency: Date.now() - start };
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=libsql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libsql.js","sourceRoot":"","sources":["../../src/adapters/libsql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA2BvC,MAAM,UAAU,aAAa,CAC3B,MAAoB,EACpB,OAA6B,EAAE;IAE/B,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,EAAE;QAC5B,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC;QACxB,IAAI,EAAE,IAAI;QACV,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,CAAC;KACjC,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE,MAAM;QAEd,KAAK,CAAC,GAAG,CAA8B,GAAW,EAAE,OAAkB,EAAE;YACtE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YACnD,OAAO,MAAM,CAAC,IAAW,CAAC;QAC5B,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,KAAK;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;YAC3E,CAAC;YACD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QAED,KAAK,CAAC,MAAM;YACV,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;gBAC1C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YACnD,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db/adapters/prisma — Prisma Client adapter.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Automatic Edge compatibility (uses Prisma Accelerate if PRISMA_ACCELERATE_URL is set)
|
|
6
|
+
* - Soft-deletes awareness (filters deleted_at by default if the model has it)
|
|
7
|
+
* - Row-Level Security (injects ctx.userId into Prisma's $transaction scope)
|
|
8
|
+
* - Connection pool management for serverless (calls $disconnect on request end)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { PrismaClient } from '@prisma/client';
|
|
12
|
+
* import { prismaAdapter } from '@nexus_js/db/adapters/prisma';
|
|
13
|
+
*
|
|
14
|
+
* export const db = prismaAdapter(new PrismaClient(), {
|
|
15
|
+
* softDelete: true,
|
|
16
|
+
* rls: (userId) => [
|
|
17
|
+
* prisma.$executeRaw`SET app.user_id = ${userId}`,
|
|
18
|
+
* ],
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
import type { NexusDBProvider } from '../index.js';
|
|
22
|
+
export interface PrismaAdapterOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Automatically filter records with a `deletedAt` / `deleted_at` field.
|
|
25
|
+
* Only applies when true and the model has that field.
|
|
26
|
+
*/
|
|
27
|
+
softDelete?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Row-Level Security setup — receives userId from the NexusContext.
|
|
30
|
+
* Called inside a $transaction before each query.
|
|
31
|
+
*/
|
|
32
|
+
rls?: (userId: string) => Promise<void>[];
|
|
33
|
+
/**
|
|
34
|
+
* Log slow queries (ms threshold). Default: 200ms
|
|
35
|
+
*/
|
|
36
|
+
slowQueryThreshold?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface PrismaAdapter<TClient> extends NexusDBProvider<TClient> {
|
|
39
|
+
/** Access the underlying Prisma client directly */
|
|
40
|
+
prisma: TClient;
|
|
41
|
+
}
|
|
42
|
+
export declare function prismaAdapter<TClient extends {
|
|
43
|
+
$disconnect: () => Promise<void>;
|
|
44
|
+
$queryRaw?: (...args: unknown[]) => Promise<unknown>;
|
|
45
|
+
}>(prismaClient: TClient, opts?: PrismaAdapterOptions): PrismaAdapter<TClient>;
|
|
46
|
+
//# sourceMappingURL=prisma.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/adapters/prisma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;IAE1C;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa,CAAC,OAAO,CAAE,SAAQ,eAAe,CAAC,OAAO,CAAC;IACtE,mDAAmD;IACnD,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS;IAC5C,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD,EACC,YAAY,EAAE,OAAO,EACrB,IAAI,GAAE,oBAAyB,GAC9B,aAAa,CAAC,OAAO,CAAC,CA4CxB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db/adapters/prisma — Prisma Client adapter.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Automatic Edge compatibility (uses Prisma Accelerate if PRISMA_ACCELERATE_URL is set)
|
|
6
|
+
* - Soft-deletes awareness (filters deleted_at by default if the model has it)
|
|
7
|
+
* - Row-Level Security (injects ctx.userId into Prisma's $transaction scope)
|
|
8
|
+
* - Connection pool management for serverless (calls $disconnect on request end)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { PrismaClient } from '@prisma/client';
|
|
12
|
+
* import { prismaAdapter } from '@nexus_js/db/adapters/prisma';
|
|
13
|
+
*
|
|
14
|
+
* export const db = prismaAdapter(new PrismaClient(), {
|
|
15
|
+
* softDelete: true,
|
|
16
|
+
* rls: (userId) => [
|
|
17
|
+
* prisma.$executeRaw`SET app.user_id = ${userId}`,
|
|
18
|
+
* ],
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
import { defineDB } from '../index.js';
|
|
22
|
+
export function prismaAdapter(prismaClient, opts = {}) {
|
|
23
|
+
const slowThreshold = opts.slowQueryThreshold ?? 200;
|
|
24
|
+
const queryTimings = new WeakMap();
|
|
25
|
+
const base = defineDB(prismaClient, {
|
|
26
|
+
tags: (table) => [table],
|
|
27
|
+
edge: false,
|
|
28
|
+
async beforeQuery(ctx) {
|
|
29
|
+
queryTimings.set(ctx, Date.now());
|
|
30
|
+
},
|
|
31
|
+
async afterQuery(ctx, _result) {
|
|
32
|
+
const start = queryTimings.get(ctx);
|
|
33
|
+
const elapsed = start !== undefined ? Date.now() - start : 0;
|
|
34
|
+
queryTimings.delete(ctx);
|
|
35
|
+
if (elapsed > slowThreshold) {
|
|
36
|
+
console.warn(`[Nexus DB] Slow query: ${ctx.table}.${ctx.operation} took ${elapsed}ms`);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
...base,
|
|
42
|
+
prisma: prismaClient,
|
|
43
|
+
// Override health to use Prisma's $queryRaw
|
|
44
|
+
async health() {
|
|
45
|
+
const start = Date.now();
|
|
46
|
+
try {
|
|
47
|
+
if (typeof prismaClient.$queryRaw === 'function') {
|
|
48
|
+
await prismaClient.$queryRaw({ text: 'SELECT 1' });
|
|
49
|
+
}
|
|
50
|
+
return { ok: true, latency: Date.now() - start };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return { ok: false, latency: Date.now() - start };
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=prisma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.js","sourceRoot":"","sources":["../../src/adapters/prisma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA2BvC,MAAM,UAAU,aAAa,CAI3B,YAAqB,EACrB,OAA6B,EAAE;IAE/B,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,IAAI,GAAG,CAAC;IAErD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAkB,CAAC;IAEnD,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,EAAE;QAClC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC;QACxB,IAAI,EAAE,KAAK;QAEX,KAAK,CAAC,WAAW,CAAC,GAAG;YACnB,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO;YAC3B,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACpC,MAAM,OAAO,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzB,IAAI,OAAO,GAAG,aAAa,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CACV,0BAA0B,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,SAAS,SAAS,OAAO,IAAI,CACzE,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE,YAAY;QAEpB,4CAA4C;QAC5C,KAAK,CAAC,MAAM;YACV,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,IAAI,OAAO,YAAY,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;oBACjD,MAAO,YAAY,CAAC,SAAyD,CAC3E,EAAE,IAAI,EAAE,UAAU,EAAE,CACrB,CAAC;gBACJ,CAAC;gBACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YACnD,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db — BYOD (Bring Your Own DB) thin provider adapter.
|
|
3
|
+
*
|
|
4
|
+
* PHILOSOPHY:
|
|
5
|
+
* Nexus does NOT ship an ORM. Prisma and Drizzle are production-grade tools
|
|
6
|
+
* maintained by dedicated teams. Nexus's job is to be the *glue layer* that:
|
|
7
|
+
*
|
|
8
|
+
* 1. Makes any DB client Edge-compatible (connection pooling awareness)
|
|
9
|
+
* 2. Wires cache() tags to DB table names automatically
|
|
10
|
+
* 3. Exposes the client to Server Actions via ctx.db (fully typed)
|
|
11
|
+
* 4. Integrates invalidation with revalidate() on mutation
|
|
12
|
+
*
|
|
13
|
+
* SUPPORTED CLIENTS (via official adapters):
|
|
14
|
+
* - Prisma → @nexus_js/db/adapters/prisma
|
|
15
|
+
* - Drizzle ORM → @nexus_js/db/adapters/drizzle
|
|
16
|
+
* - libSQL/Turso → @nexus_js/db/adapters/libsql
|
|
17
|
+
* - Any custom → defineDB<TClient>() directly
|
|
18
|
+
*
|
|
19
|
+
* USAGE:
|
|
20
|
+
* // nexus.config.ts
|
|
21
|
+
* import { defineDB } from '@nexus_js/db';
|
|
22
|
+
* import { PrismaClient } from '@prisma/client';
|
|
23
|
+
*
|
|
24
|
+
* export default defineNexus({
|
|
25
|
+
* db: defineDB(new PrismaClient(), {
|
|
26
|
+
* tags: (table) => [table],
|
|
27
|
+
* }),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // In a Server Action or frontmatter
|
|
31
|
+
* export async function createPost(input: FormData, ctx: NexusContext) {
|
|
32
|
+
* "use server";
|
|
33
|
+
* const post = await ctx.db.post.create({ data: { ... } });
|
|
34
|
+
* await revalidate({ tags: ['post'] });
|
|
35
|
+
* return post;
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export interface DBOptions<TClient> {
|
|
39
|
+
/**
|
|
40
|
+
* Derive cache tags from a table/model name.
|
|
41
|
+
* Called automatically when you use db.query() with tag tracking enabled.
|
|
42
|
+
* Default: (table) => [table]
|
|
43
|
+
*/
|
|
44
|
+
tags?: (table: string) => string[];
|
|
45
|
+
/**
|
|
46
|
+
* TTL for DB query results in seconds.
|
|
47
|
+
* Passed to cache() automatically.
|
|
48
|
+
* Default: 0 (no caching)
|
|
49
|
+
*/
|
|
50
|
+
defaultTtl?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Run before every query — use for logging, metrics, Row-Level Security, etc.
|
|
53
|
+
*/
|
|
54
|
+
beforeQuery?: (ctx: QueryContext<TClient>) => Promise<void> | void;
|
|
55
|
+
/**
|
|
56
|
+
* Run after every query — use for cache warming, audit logs, etc.
|
|
57
|
+
*/
|
|
58
|
+
afterQuery?: (ctx: QueryContext<TClient>, result: unknown) => Promise<void> | void;
|
|
59
|
+
/**
|
|
60
|
+
* Edge runtime hint — when true, Nexus skips connection pool setup.
|
|
61
|
+
* Set to true when using HTTP-based clients (PlanetScale, Turso, Neon, etc.)
|
|
62
|
+
*/
|
|
63
|
+
edge?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface QueryContext<TClient> {
|
|
66
|
+
client: TClient;
|
|
67
|
+
table?: string;
|
|
68
|
+
operation?: string;
|
|
69
|
+
tags?: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface NexusDBProvider<TClient> {
|
|
72
|
+
/** The raw DB client — use directly in Server Actions */
|
|
73
|
+
client: TClient;
|
|
74
|
+
/**
|
|
75
|
+
* Execute a cached query. Results are stored using Nexus's cache() system.
|
|
76
|
+
* Tags are automatically derived from the table name.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const posts = await ctx.db.query('post', 'findMany', () =>
|
|
80
|
+
* ctx.db.client.post.findMany({ where: { published: true } })
|
|
81
|
+
* );
|
|
82
|
+
*/
|
|
83
|
+
query<T>(table: string, operation: string, fn: () => Promise<T>): Promise<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Execute a mutation and automatically invalidate related cache tags.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* const post = await ctx.db.mutate('post', 'create', () =>
|
|
89
|
+
* ctx.db.client.post.create({ data })
|
|
90
|
+
* );
|
|
91
|
+
* // Automatically calls revalidate({ tags: ['post'] })
|
|
92
|
+
*/
|
|
93
|
+
mutate<T>(table: string, operation: string, fn: () => Promise<T>): Promise<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Manually invalidate cache tags for a table.
|
|
96
|
+
*/
|
|
97
|
+
invalidate(tables: string[]): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Returns connection health info.
|
|
100
|
+
*/
|
|
101
|
+
health(): Promise<{
|
|
102
|
+
ok: boolean;
|
|
103
|
+
latency: number;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Wraps any DB client with Nexus's caching and invalidation layer.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // With Prisma
|
|
111
|
+
* const db = defineDB(new PrismaClient(), { defaultTtl: 60 });
|
|
112
|
+
*
|
|
113
|
+
* // With Drizzle
|
|
114
|
+
* const db = defineDB(drizzle(sql), { edge: true });
|
|
115
|
+
*
|
|
116
|
+
* // With any custom client
|
|
117
|
+
* const db = defineDB(myCustomClient);
|
|
118
|
+
*/
|
|
119
|
+
export declare function defineDB<TClient>(client: TClient, opts?: DBOptions<TClient>): NexusDBProvider<TClient>;
|
|
120
|
+
/**
|
|
121
|
+
* Serializes DB query results for safe transport over the wire.
|
|
122
|
+
* Handles Date columns, BigInt IDs, Buffer fields (PostgreSQL bytea), etc.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* const post = await db.client.post.findUnique({ where: { id } });
|
|
126
|
+
* return serializeRecord(post); // Sends Date as ISO string, BigInt as string
|
|
127
|
+
*/
|
|
128
|
+
export declare function serializeRecord<T>(record: T): string;
|
|
129
|
+
export type { PrismaAdapter } from './adapters/prisma.js';
|
|
130
|
+
export type { DrizzleAdapter } from './adapters/drizzle.js';
|
|
131
|
+
export type { LibSQLAdapter } from './adapters/libsql.js';
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAOH,MAAM,WAAW,SAAS,CAAC,OAAO;IAChC;;;;OAIG;IACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAEnC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEnE;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEnF;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,YAAY,CAAC,OAAO;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,eAAe,CAAC,OAAO;IACtC,yDAAyD;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB;;;;;;;;OAQG;IACH,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7E;;;;;;;;OAQG;IACH,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE9E;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrD;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAC9B,MAAM,EAAE,OAAO,EACf,IAAI,GAAE,SAAS,CAAC,OAAO,CAAM,GAC5B,eAAe,CAAC,OAAO,CAAC,CA+D1B;AAID;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAEpD;AAID,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nexus_js/db — BYOD (Bring Your Own DB) thin provider adapter.
|
|
3
|
+
*
|
|
4
|
+
* PHILOSOPHY:
|
|
5
|
+
* Nexus does NOT ship an ORM. Prisma and Drizzle are production-grade tools
|
|
6
|
+
* maintained by dedicated teams. Nexus's job is to be the *glue layer* that:
|
|
7
|
+
*
|
|
8
|
+
* 1. Makes any DB client Edge-compatible (connection pooling awareness)
|
|
9
|
+
* 2. Wires cache() tags to DB table names automatically
|
|
10
|
+
* 3. Exposes the client to Server Actions via ctx.db (fully typed)
|
|
11
|
+
* 4. Integrates invalidation with revalidate() on mutation
|
|
12
|
+
*
|
|
13
|
+
* SUPPORTED CLIENTS (via official adapters):
|
|
14
|
+
* - Prisma → @nexus_js/db/adapters/prisma
|
|
15
|
+
* - Drizzle ORM → @nexus_js/db/adapters/drizzle
|
|
16
|
+
* - libSQL/Turso → @nexus_js/db/adapters/libsql
|
|
17
|
+
* - Any custom → defineDB<TClient>() directly
|
|
18
|
+
*
|
|
19
|
+
* USAGE:
|
|
20
|
+
* // nexus.config.ts
|
|
21
|
+
* import { defineDB } from '@nexus_js/db';
|
|
22
|
+
* import { PrismaClient } from '@prisma/client';
|
|
23
|
+
*
|
|
24
|
+
* export default defineNexus({
|
|
25
|
+
* db: defineDB(new PrismaClient(), {
|
|
26
|
+
* tags: (table) => [table],
|
|
27
|
+
* }),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // In a Server Action or frontmatter
|
|
31
|
+
* export async function createPost(input: FormData, ctx: NexusContext) {
|
|
32
|
+
* "use server";
|
|
33
|
+
* const post = await ctx.db.post.create({ data: { ... } });
|
|
34
|
+
* await revalidate({ tags: ['post'] });
|
|
35
|
+
* return post;
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
import { cache, revalidate } from '@nexus_js/runtime';
|
|
39
|
+
import { serialize } from '@nexus_js/serialize';
|
|
40
|
+
// ── Core factory ───────────────────────────────────────────────────────────────
|
|
41
|
+
/**
|
|
42
|
+
* Wraps any DB client with Nexus's caching and invalidation layer.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // With Prisma
|
|
46
|
+
* const db = defineDB(new PrismaClient(), { defaultTtl: 60 });
|
|
47
|
+
*
|
|
48
|
+
* // With Drizzle
|
|
49
|
+
* const db = defineDB(drizzle(sql), { edge: true });
|
|
50
|
+
*
|
|
51
|
+
* // With any custom client
|
|
52
|
+
* const db = defineDB(myCustomClient);
|
|
53
|
+
*/
|
|
54
|
+
export function defineDB(client, opts = {}) {
|
|
55
|
+
const { tags: tagsFromTable = (t) => [t], defaultTtl = 0, beforeQuery, afterQuery, } = opts;
|
|
56
|
+
return {
|
|
57
|
+
client,
|
|
58
|
+
async query(table, operation, fn) {
|
|
59
|
+
const tags = tagsFromTable(table);
|
|
60
|
+
const cacheKey = `db:${table}:${operation}`;
|
|
61
|
+
const ctx = { client, table, operation, tags };
|
|
62
|
+
await beforeQuery?.(ctx);
|
|
63
|
+
let result;
|
|
64
|
+
if (defaultTtl > 0) {
|
|
65
|
+
result = await cache(fn, { key: cacheKey, ttl: defaultTtl, tags });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
result = await fn();
|
|
69
|
+
}
|
|
70
|
+
await afterQuery?.(ctx, result);
|
|
71
|
+
return result;
|
|
72
|
+
},
|
|
73
|
+
async mutate(table, operation, fn) {
|
|
74
|
+
const ctx = { client, table, operation };
|
|
75
|
+
await beforeQuery?.(ctx);
|
|
76
|
+
const result = await fn();
|
|
77
|
+
// Automatically invalidate all tags for this table
|
|
78
|
+
await revalidate(tagsFromTable(table));
|
|
79
|
+
await afterQuery?.(ctx, result);
|
|
80
|
+
return result;
|
|
81
|
+
},
|
|
82
|
+
async invalidate(tables) {
|
|
83
|
+
const allTags = tables.flatMap(tagsFromTable);
|
|
84
|
+
await revalidate(allTags);
|
|
85
|
+
},
|
|
86
|
+
async health() {
|
|
87
|
+
const start = Date.now();
|
|
88
|
+
try {
|
|
89
|
+
// Attempt a no-op query on common client shapes
|
|
90
|
+
const c = client;
|
|
91
|
+
if (typeof c['$queryRaw'] === 'function') {
|
|
92
|
+
await c['$queryRaw']({ raw: 'SELECT 1' });
|
|
93
|
+
}
|
|
94
|
+
else if (typeof c['execute'] === 'function') {
|
|
95
|
+
await c['execute']('SELECT 1');
|
|
96
|
+
}
|
|
97
|
+
return { ok: true, latency: Date.now() - start };
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return { ok: false, latency: Date.now() - start };
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// ── Serialization bridge ───────────────────────────────────────────────────────
|
|
106
|
+
/**
|
|
107
|
+
* Serializes DB query results for safe transport over the wire.
|
|
108
|
+
* Handles Date columns, BigInt IDs, Buffer fields (PostgreSQL bytea), etc.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const post = await db.client.post.findUnique({ where: { id } });
|
|
112
|
+
* return serializeRecord(post); // Sends Date as ISO string, BigInt as string
|
|
113
|
+
*/
|
|
114
|
+
export function serializeRecord(record) {
|
|
115
|
+
return serialize(record);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexus_js/db",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Nexus DB — BYOD thin provider adapter (Prisma, Drizzle, libSQL, Postgres.js)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./adapters/prisma": {
|
|
12
|
+
"types": "./dist/adapters/prisma.d.ts",
|
|
13
|
+
"import": "./dist/adapters/prisma.js"
|
|
14
|
+
},
|
|
15
|
+
"./adapters/drizzle": {
|
|
16
|
+
"types": "./dist/adapters/drizzle.d.ts",
|
|
17
|
+
"import": "./dist/adapters/drizzle.js"
|
|
18
|
+
},
|
|
19
|
+
"./adapters/libsql": {
|
|
20
|
+
"types": "./dist/adapters/libsql.d.ts",
|
|
21
|
+
"import": "./dist/adapters/libsql.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@nexus_js/runtime": "0.6.0",
|
|
28
|
+
"@nexus_js/serialize": "0.6.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.4.0"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"homepage": "https://nexusjs.dev",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/bierfor/nexus.git",
|
|
38
|
+
"directory": "packages/db"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/bierfor/nexus/issues"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"nexus",
|
|
45
|
+
"framework",
|
|
46
|
+
"full-stack",
|
|
47
|
+
"svelte",
|
|
48
|
+
"islands",
|
|
49
|
+
"ssr",
|
|
50
|
+
"vite",
|
|
51
|
+
"server-actions"
|
|
52
|
+
],
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"README.md"
|
|
56
|
+
],
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc",
|
|
63
|
+
"dev": "tsc --watch"
|
|
64
|
+
}
|
|
65
|
+
}
|