@prisma-next/sql-runtime 0.3.0-pr.93.5 → 0.3.0-pr.94.1
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/exports-BI-iW86w.mjs +402 -0
- package/dist/exports-BI-iW86w.mjs.map +1 -0
- package/dist/index-Bycr1UG5.d.mts +130 -0
- package/dist/index-Bycr1UG5.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/test/utils.d.mts +63 -0
- package/dist/test/utils.d.mts.map +1 -0
- package/dist/test/utils.mjs +184 -0
- package/dist/test/utils.mjs.map +1 -0
- package/package.json +22 -20
- package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js +0 -137863
- package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js.map +0 -1
- package/dist/amcheck-24VY6X5V.js +0 -13
- package/dist/amcheck-24VY6X5V.js.map +0 -1
- package/dist/bloom-VS74NLHT.js +0 -13
- package/dist/bloom-VS74NLHT.js.map +0 -1
- package/dist/btree_gin-WBC4EAAI.js +0 -13
- package/dist/btree_gin-WBC4EAAI.js.map +0 -1
- package/dist/btree_gist-UNC6QD3M.js +0 -13
- package/dist/btree_gist-UNC6QD3M.js.map +0 -1
- package/dist/chunk-3KTOEDFX.js +0 -49
- package/dist/chunk-3KTOEDFX.js.map +0 -1
- package/dist/chunk-47DZBRQC.js +0 -1280
- package/dist/chunk-47DZBRQC.js.map +0 -1
- package/dist/chunk-52N6AFZM.js +0 -133
- package/dist/chunk-52N6AFZM.js.map +0 -1
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-7D4SUZUM.js.map +0 -1
- package/dist/chunk-C6I3V3DM.js +0 -455
- package/dist/chunk-C6I3V3DM.js.map +0 -1
- package/dist/chunk-ECWIHLAT.js +0 -37
- package/dist/chunk-ECWIHLAT.js.map +0 -1
- package/dist/chunk-EI626SDC.js +0 -105
- package/dist/chunk-EI626SDC.js.map +0 -1
- package/dist/chunk-UKKOYUGL.js +0 -578
- package/dist/chunk-UKKOYUGL.js.map +0 -1
- package/dist/chunk-XPLNMXQV.js +0 -1537
- package/dist/chunk-XPLNMXQV.js.map +0 -1
- package/dist/citext-T7MXGUY7.js +0 -13
- package/dist/citext-T7MXGUY7.js.map +0 -1
- package/dist/client-5FENX6AW.js +0 -299
- package/dist/client-5FENX6AW.js.map +0 -1
- package/dist/codecs/decoding.d.ts +0 -4
- package/dist/codecs/decoding.d.ts.map +0 -1
- package/dist/codecs/encoding.d.ts +0 -5
- package/dist/codecs/encoding.d.ts.map +0 -1
- package/dist/codecs/validation.d.ts +0 -6
- package/dist/codecs/validation.d.ts.map +0 -1
- package/dist/cube-TFDQBZCI.js +0 -13
- package/dist/cube-TFDQBZCI.js.map +0 -1
- package/dist/dict_int-AEUOPGWP.js +0 -13
- package/dist/dict_int-AEUOPGWP.js.map +0 -1
- package/dist/dict_xsyn-DAAYX3FL.js +0 -13
- package/dist/dict_xsyn-DAAYX3FL.js.map +0 -1
- package/dist/dist-AQ3LWXOX.js +0 -570
- package/dist/dist-AQ3LWXOX.js.map +0 -1
- package/dist/dist-LBVX6BJW.js +0 -189
- package/dist/dist-LBVX6BJW.js.map +0 -1
- package/dist/dist-WLKUVDN2.js +0 -5127
- package/dist/dist-WLKUVDN2.js.map +0 -1
- package/dist/earthdistance-KIGTF4LE.js +0 -13
- package/dist/earthdistance-KIGTF4LE.js.map +0 -1
- package/dist/exports/index.d.ts +0 -11
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/file_fdw-5N55UP6I.js +0 -13
- package/dist/file_fdw-5N55UP6I.js.map +0 -1
- package/dist/fuzzystrmatch-KN3YWBFP.js +0 -13
- package/dist/fuzzystrmatch-KN3YWBFP.js.map +0 -1
- package/dist/hstore-YX726NKN.js +0 -13
- package/dist/hstore-YX726NKN.js.map +0 -1
- package/dist/http-exception-FZY2H4OF.js +0 -8
- package/dist/http-exception-FZY2H4OF.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -1
- package/dist/intarray-NKVXNO2D.js +0 -13
- package/dist/intarray-NKVXNO2D.js.map +0 -1
- package/dist/isn-FTEMJGEV.js +0 -13
- package/dist/isn-FTEMJGEV.js.map +0 -1
- package/dist/lo-DB7L4NGI.js +0 -13
- package/dist/lo-DB7L4NGI.js.map +0 -1
- package/dist/logger-WQ7SHNDD.js +0 -68
- package/dist/logger-WQ7SHNDD.js.map +0 -1
- package/dist/lower-sql-plan.d.ts +0 -15
- package/dist/lower-sql-plan.d.ts.map +0 -1
- package/dist/ltree-Z32TZT6W.js +0 -13
- package/dist/ltree-Z32TZT6W.js.map +0 -1
- package/dist/nodefs-NM46ACH7.js +0 -31
- package/dist/nodefs-NM46ACH7.js.map +0 -1
- package/dist/opfs-ahp-NJO33LVZ.js +0 -332
- package/dist/opfs-ahp-NJO33LVZ.js.map +0 -1
- package/dist/pageinspect-YP3IZR4X.js +0 -13
- package/dist/pageinspect-YP3IZR4X.js.map +0 -1
- package/dist/pg_buffercache-7TD5J2FB.js +0 -13
- package/dist/pg_buffercache-7TD5J2FB.js.map +0 -1
- package/dist/pg_dump-SG4KYBUB.js +0 -2492
- package/dist/pg_dump-SG4KYBUB.js.map +0 -1
- package/dist/pg_freespacemap-DZDNCPZK.js +0 -13
- package/dist/pg_freespacemap-DZDNCPZK.js.map +0 -1
- package/dist/pg_surgery-J2MUEWEP.js +0 -13
- package/dist/pg_surgery-J2MUEWEP.js.map +0 -1
- package/dist/pg_trgm-7VNQOYS6.js +0 -13
- package/dist/pg_trgm-7VNQOYS6.js.map +0 -1
- package/dist/pg_visibility-TTSIPHFL.js +0 -13
- package/dist/pg_visibility-TTSIPHFL.js.map +0 -1
- package/dist/pg_walinspect-KPFHSHRJ.js +0 -13
- package/dist/pg_walinspect-KPFHSHRJ.js.map +0 -1
- package/dist/proxy-signals-GUDAMDHV.js +0 -39
- package/dist/proxy-signals-GUDAMDHV.js.map +0 -1
- package/dist/seg-IYVDLE4O.js +0 -13
- package/dist/seg-IYVDLE4O.js.map +0 -1
- package/dist/sql-context.d.ts +0 -65
- package/dist/sql-context.d.ts.map +0 -1
- package/dist/sql-family-adapter.d.ts +0 -10
- package/dist/sql-family-adapter.d.ts.map +0 -1
- package/dist/sql-marker.d.ts +0 -22
- package/dist/sql-marker.d.ts.map +0 -1
- package/dist/sql-runtime.d.ts +0 -25
- package/dist/sql-runtime.d.ts.map +0 -1
- package/dist/tablefunc-EF4RCS7S.js +0 -13
- package/dist/tablefunc-EF4RCS7S.js.map +0 -1
- package/dist/tcn-3VT5BQYW.js +0 -13
- package/dist/tcn-3VT5BQYW.js.map +0 -1
- package/dist/test/utils.js +0 -24635
- package/dist/test/utils.js.map +0 -1
- package/dist/tiny-CW6F4GX6.js +0 -10
- package/dist/tiny-CW6F4GX6.js.map +0 -1
- package/dist/tsm_system_rows-ES7KNUQH.js +0 -13
- package/dist/tsm_system_rows-ES7KNUQH.js.map +0 -1
- package/dist/tsm_system_time-76WEIMBG.js +0 -13
- package/dist/tsm_system_time-76WEIMBG.js.map +0 -1
- package/dist/unaccent-7RYF3R64.js +0 -13
- package/dist/unaccent-7RYF3R64.js.map +0 -1
- package/dist/utility-Q5A254LJ-J4HTKZPT.js +0 -347
- package/dist/utility-Q5A254LJ-J4HTKZPT.js.map +0 -1
- package/dist/uuid_ossp-4ETE4FPE.js +0 -13
- package/dist/uuid_ossp-4ETE4FPE.js.map +0 -1
- package/dist/vector-74GPNV7V.js +0 -13
- package/dist/vector-74GPNV7V.js.map +0 -1
- package/test/tsconfig.json +0 -4
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { S as RuntimeContext, h as SqlStatement, m as createRuntime, w as SqlRuntimeExtensionDescriptor } from "../index-Bycr1UG5.mjs";
|
|
2
|
+
import { Adapter, LoweredStatement, SelectAst } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
+
import { DevDatabase, collectAsync, createDevDatabase, teardownTestDatabase, withClient } from "@prisma-next/test-utils";
|
|
4
|
+
import { SqlContract, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
5
|
+
import { ExecutionPlan, ResultType } from "@prisma-next/contract/types";
|
|
6
|
+
import { SqlQueryPlan } from "@prisma-next/sql-relational-core/plan";
|
|
7
|
+
import { Client } from "pg";
|
|
8
|
+
|
|
9
|
+
//#region test/utils.d.ts
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Executes a plan and collects all results into an array.
|
|
13
|
+
* This helper DRYs up the common pattern of executing plans in tests.
|
|
14
|
+
* The return type is inferred from the plan's type parameter.
|
|
15
|
+
*/
|
|
16
|
+
declare function executePlanAndCollect<P extends ExecutionPlan<ResultType<P>> | SqlQueryPlan<ResultType<P>>>(runtime: ReturnType<typeof createRuntime>, plan: P): Promise<ResultType<P>[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Drains a plan execution, consuming all results without collecting them.
|
|
19
|
+
* Useful for testing side effects without memory overhead.
|
|
20
|
+
*/
|
|
21
|
+
declare function drainPlanExecution(runtime: ReturnType<typeof createRuntime>, plan: ExecutionPlan | SqlQueryPlan<unknown>): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Executes a SQL statement on a database client.
|
|
24
|
+
*/
|
|
25
|
+
declare function executeStatement(client: Client, statement: SqlStatement): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Sets up database schema and data, then writes the contract marker.
|
|
28
|
+
* This helper DRYs up the common pattern of database setup in tests.
|
|
29
|
+
*/
|
|
30
|
+
declare function setupTestDatabase(client: Client, contract: SqlContract<SqlStorage>, setupFn: (client: Client) => Promise<void>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Writes a contract marker to the database.
|
|
33
|
+
* This helper DRYs up the common pattern of writing contract markers in tests.
|
|
34
|
+
*/
|
|
35
|
+
declare function writeTestContractMarker(client: Client, contract: SqlContract<SqlStorage>): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a runtime context with standard test configuration.
|
|
38
|
+
* This helper DRYs up the common pattern of context creation in tests.
|
|
39
|
+
*
|
|
40
|
+
* Accepts a raw adapter and optional extension descriptors, wrapping the
|
|
41
|
+
* adapter in a descriptor internally for descriptor-first context creation.
|
|
42
|
+
*/
|
|
43
|
+
declare function createTestContext<TContract extends SqlContract<SqlStorage>>(contract: TContract, adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, options?: {
|
|
44
|
+
extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;
|
|
45
|
+
}): RuntimeContext<TContract>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a stub adapter for testing.
|
|
48
|
+
* This helper DRYs up the common pattern of adapter creation in tests.
|
|
49
|
+
*
|
|
50
|
+
* The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1)
|
|
51
|
+
* to enable type inference in tests without requiring the postgres adapter package.
|
|
52
|
+
*/
|
|
53
|
+
declare function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a valid test contract without using validateContract.
|
|
56
|
+
* Ensures all required fields are present (mappings, capabilities, extensionPacks, meta, sources)
|
|
57
|
+
* and returns the contract with proper typing.
|
|
58
|
+
* This helper allows tests to create contracts without depending on sql-query.
|
|
59
|
+
*/
|
|
60
|
+
declare function createTestContract<T extends SqlContract<SqlStorage>>(contract: Partial<T> & Omit<T, 'mappings' | 'capabilities' | 'extensionPacks' | 'meta' | 'sources'>): T;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { type DevDatabase, collectAsync, createDevDatabase, createStubAdapter, createTestContext, createTestContract, drainPlanExecution, executePlanAndCollect, executeStatement, setupTestDatabase, teardownTestDatabase, withClient, writeTestContractMarker };
|
|
63
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"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B,CAAA,EAAA,OACrB,CADqB,EAAA;EAC5B,cAAA,CAAA,EAuGkB,aAvGlB,CAuGgC,6BAvGhC,CAAA,UAAA,CAAA,CAAA;CAAO,CAAA,EAyGP,cAzGO,CAyGQ,SAzGR,CAAA;AAqBV;;;;;;AA8EA;AAAgE,iBAsBhD,iBAAA,CAAA,CAtBgD,EAsB3B,OAtB2B,CAsBnB,SAtBmB,EAsBR,WAtBQ,CAsBI,UAtBJ,CAAA,EAsBiB,gBAtBjB,CAAA;;;;;;;AAErD,iBA+EK,kBA/EL,CAAA,UA+EkC,WA/ElC,CA+E8C,UA/E9C,CAAA,CAAA,CAAA,QAAA,EAgFC,OAhFD,CAgFS,CAhFT,CAAA,GAiFP,IAjFO,CAiFF,CAjFE,EAAA,UAAA,GAAA,cAAA,GAAA,gBAAA,GAAA,MAAA,GAAA,SAAA,CAAA,CAAA,EAkFR,CAlFQ"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { a as ensureTableStatement, c as createRuntimeContext, i as ensureSchemaStatement, s as writeContractMarker } from "../exports-BI-iW86w.mjs";
|
|
2
|
+
import { codec, createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
+
import { collectAsync, collectAsync as collectAsync$1, createDevDatabase, drainAsyncIterable, teardownTestDatabase, withClient } from "@prisma-next/test-utils";
|
|
4
|
+
|
|
5
|
+
//#region test/utils.ts
|
|
6
|
+
/**
|
|
7
|
+
* Executes a plan and collects all results into an array.
|
|
8
|
+
* This helper DRYs up the common pattern of executing plans in tests.
|
|
9
|
+
* The return type is inferred from the plan's type parameter.
|
|
10
|
+
*/
|
|
11
|
+
async function executePlanAndCollect(runtime, plan) {
|
|
12
|
+
return collectAsync$1(runtime.execute(plan));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Drains a plan execution, consuming all results without collecting them.
|
|
16
|
+
* Useful for testing side effects without memory overhead.
|
|
17
|
+
*/
|
|
18
|
+
async function drainPlanExecution(runtime, plan) {
|
|
19
|
+
return drainAsyncIterable(runtime.execute(plan));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Executes a SQL statement on a database client.
|
|
23
|
+
*/
|
|
24
|
+
async function executeStatement(client, statement) {
|
|
25
|
+
if (statement.params.length > 0) {
|
|
26
|
+
await client.query(statement.sql, [...statement.params]);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
await client.query(statement.sql);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sets up database schema and data, then writes the contract marker.
|
|
33
|
+
* This helper DRYs up the common pattern of database setup in tests.
|
|
34
|
+
*/
|
|
35
|
+
async function setupTestDatabase(client, contract, setupFn) {
|
|
36
|
+
await client.query("drop schema if exists prisma_contract cascade");
|
|
37
|
+
await client.query("create schema if not exists public");
|
|
38
|
+
await setupFn(client);
|
|
39
|
+
await executeStatement(client, ensureSchemaStatement);
|
|
40
|
+
await executeStatement(client, ensureTableStatement);
|
|
41
|
+
await executeStatement(client, writeContractMarker({
|
|
42
|
+
coreHash: contract.coreHash,
|
|
43
|
+
profileHash: contract.profileHash ?? contract.coreHash,
|
|
44
|
+
contractJson: contract,
|
|
45
|
+
canonicalVersion: 1
|
|
46
|
+
}).insert);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Writes a contract marker to the database.
|
|
50
|
+
* This helper DRYs up the common pattern of writing contract markers in tests.
|
|
51
|
+
*/
|
|
52
|
+
async function writeTestContractMarker(client, contract) {
|
|
53
|
+
await executeStatement(client, writeContractMarker({
|
|
54
|
+
coreHash: contract.coreHash,
|
|
55
|
+
profileHash: contract.profileHash ?? contract.coreHash,
|
|
56
|
+
contractJson: contract,
|
|
57
|
+
canonicalVersion: 1
|
|
58
|
+
}).insert);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a test adapter descriptor from a raw adapter.
|
|
62
|
+
* This wraps the adapter in a descriptor for descriptor-first context creation in tests.
|
|
63
|
+
* The adapter instance IS an Adapter (via intersection), with identity properties added.
|
|
64
|
+
*/
|
|
65
|
+
function createTestAdapterDescriptor(adapter) {
|
|
66
|
+
return {
|
|
67
|
+
kind: "adapter",
|
|
68
|
+
id: "test-adapter",
|
|
69
|
+
version: "0.0.1",
|
|
70
|
+
familyId: "sql",
|
|
71
|
+
targetId: "postgres",
|
|
72
|
+
create() {
|
|
73
|
+
return Object.assign({
|
|
74
|
+
familyId: "sql",
|
|
75
|
+
targetId: "postgres"
|
|
76
|
+
}, adapter);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a test target descriptor.
|
|
82
|
+
* This is a minimal descriptor for descriptor-first context creation in tests.
|
|
83
|
+
*/
|
|
84
|
+
function createTestTargetDescriptor() {
|
|
85
|
+
return {
|
|
86
|
+
kind: "target",
|
|
87
|
+
id: "postgres",
|
|
88
|
+
version: "0.0.1",
|
|
89
|
+
familyId: "sql",
|
|
90
|
+
targetId: "postgres",
|
|
91
|
+
create() {
|
|
92
|
+
return {
|
|
93
|
+
familyId: "sql",
|
|
94
|
+
targetId: "postgres"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a runtime context with standard test configuration.
|
|
101
|
+
* This helper DRYs up the common pattern of context creation in tests.
|
|
102
|
+
*
|
|
103
|
+
* Accepts a raw adapter and optional extension descriptors, wrapping the
|
|
104
|
+
* adapter in a descriptor internally for descriptor-first context creation.
|
|
105
|
+
*/
|
|
106
|
+
function createTestContext(contract, adapter, options) {
|
|
107
|
+
return createRuntimeContext({
|
|
108
|
+
contract,
|
|
109
|
+
target: createTestTargetDescriptor(),
|
|
110
|
+
adapter: createTestAdapterDescriptor(adapter),
|
|
111
|
+
extensionPacks: options?.extensionPacks ?? []
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Creates a stub adapter for testing.
|
|
116
|
+
* This helper DRYs up the common pattern of adapter creation in tests.
|
|
117
|
+
*
|
|
118
|
+
* The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1)
|
|
119
|
+
* to enable type inference in tests without requiring the postgres adapter package.
|
|
120
|
+
*/
|
|
121
|
+
function createStubAdapter() {
|
|
122
|
+
const codecRegistry = createCodecRegistry();
|
|
123
|
+
codecRegistry.register(codec({
|
|
124
|
+
typeId: "pg/int4@1",
|
|
125
|
+
targetTypes: ["int4"],
|
|
126
|
+
encode: (value) => value,
|
|
127
|
+
decode: (wire) => wire
|
|
128
|
+
}));
|
|
129
|
+
codecRegistry.register(codec({
|
|
130
|
+
typeId: "pg/text@1",
|
|
131
|
+
targetTypes: ["text"],
|
|
132
|
+
encode: (value) => value,
|
|
133
|
+
decode: (wire) => wire
|
|
134
|
+
}));
|
|
135
|
+
codecRegistry.register(codec({
|
|
136
|
+
typeId: "pg/timestamptz@1",
|
|
137
|
+
targetTypes: ["timestamptz"],
|
|
138
|
+
encode: (value) => value instanceof Date ? value.toISOString() : value,
|
|
139
|
+
decode: (wire) => typeof wire === "string" ? wire : wire instanceof Date ? wire.toISOString() : String(wire)
|
|
140
|
+
}));
|
|
141
|
+
return {
|
|
142
|
+
profile: {
|
|
143
|
+
id: "stub-profile",
|
|
144
|
+
target: "postgres",
|
|
145
|
+
capabilities: {},
|
|
146
|
+
codecs() {
|
|
147
|
+
return codecRegistry;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
lower(ast, ctx) {
|
|
151
|
+
const sqlText = JSON.stringify(ast);
|
|
152
|
+
return {
|
|
153
|
+
profileId: this.profile.id,
|
|
154
|
+
body: Object.freeze({
|
|
155
|
+
sql: sqlText,
|
|
156
|
+
params: ctx.params ? [...ctx.params] : []
|
|
157
|
+
})
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a valid test contract without using validateContract.
|
|
164
|
+
* Ensures all required fields are present (mappings, capabilities, extensionPacks, meta, sources)
|
|
165
|
+
* and returns the contract with proper typing.
|
|
166
|
+
* This helper allows tests to create contracts without depending on sql-query.
|
|
167
|
+
*/
|
|
168
|
+
function createTestContract(contract) {
|
|
169
|
+
return {
|
|
170
|
+
...contract,
|
|
171
|
+
mappings: contract.mappings ?? {
|
|
172
|
+
codecTypes: {},
|
|
173
|
+
operationTypes: {}
|
|
174
|
+
},
|
|
175
|
+
capabilities: contract.capabilities ?? {},
|
|
176
|
+
extensionPacks: contract.extensionPacks ?? {},
|
|
177
|
+
meta: contract.meta ?? {},
|
|
178
|
+
sources: contract.sources ?? {}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { collectAsync, createDevDatabase, createStubAdapter, createTestContext, createTestContract, drainPlanExecution, executePlanAndCollect, executeStatement, setupTestDatabase, teardownTestDatabase, withClient, writeTestContractMarker };
|
|
184
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["collectAsync"],"sources":["../../test/utils.ts"],"sourcesContent":["import type { ExecutionPlan, ResultType } from '@prisma-next/contract/types';\nimport type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { Adapter, LoweredStatement, SelectAst } from '@prisma-next/sql-relational-core/ast';\nimport { codec, createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport { collectAsync, drainAsyncIterable } from '@prisma-next/test-utils';\nimport type { Client } from 'pg';\nimport type { SqlStatement } from '../src/exports';\nimport {\n type createRuntime,\n createRuntimeContext,\n ensureSchemaStatement,\n ensureTableStatement,\n writeContractMarker,\n} from '../src/exports';\nimport type {\n RuntimeContext,\n SqlRuntimeAdapterInstance,\n SqlRuntimeExtensionDescriptor,\n} from '../src/sql-context';\n\n/**\n * Executes a plan and collects all results into an array.\n * This helper DRYs up the common pattern of executing plans in tests.\n * The return type is inferred from the plan's type parameter.\n */\nexport async function executePlanAndCollect<\n P extends ExecutionPlan<ResultType<P>> | SqlQueryPlan<ResultType<P>>,\n>(runtime: ReturnType<typeof createRuntime>, plan: P): Promise<ResultType<P>[]> {\n type Row = ResultType<P>;\n return collectAsync<Row>(runtime.execute<Row>(plan));\n}\n\n/**\n * Drains a plan execution, consuming all results without collecting them.\n * Useful for testing side effects without memory overhead.\n */\nexport async function drainPlanExecution(\n runtime: ReturnType<typeof createRuntime>,\n plan: ExecutionPlan | SqlQueryPlan<unknown>,\n): Promise<void> {\n return drainAsyncIterable(runtime.execute(plan));\n}\n\n/**\n * Executes a SQL statement on a database client.\n */\nexport async function executeStatement(client: Client, statement: SqlStatement): Promise<void> {\n if (statement.params.length > 0) {\n await client.query(statement.sql, [...statement.params]);\n return;\n }\n\n await client.query(statement.sql);\n}\n\n/**\n * Sets up database schema and data, then writes the contract marker.\n * This helper DRYs up the common pattern of database setup in tests.\n */\nexport async function setupTestDatabase(\n client: Client,\n contract: SqlContract<SqlStorage>,\n setupFn: (client: Client) => Promise<void>,\n): Promise<void> {\n await client.query('drop schema if exists prisma_contract cascade');\n await client.query('create schema if not exists public');\n\n await setupFn(client);\n\n await executeStatement(client, ensureSchemaStatement);\n await executeStatement(client, ensureTableStatement);\n const write = writeContractMarker({\n coreHash: contract.coreHash,\n profileHash: contract.profileHash ?? contract.coreHash,\n contractJson: contract,\n canonicalVersion: 1,\n });\n await executeStatement(client, write.insert);\n}\n\n/**\n * Writes a contract marker to the database.\n * This helper DRYs up the common pattern of writing contract markers in tests.\n */\nexport async function writeTestContractMarker(\n client: Client,\n contract: SqlContract<SqlStorage>,\n): Promise<void> {\n const write = writeContractMarker({\n coreHash: contract.coreHash,\n profileHash: contract.profileHash ?? contract.coreHash,\n contractJson: contract,\n canonicalVersion: 1,\n });\n await executeStatement(client, write.insert);\n}\n\n/**\n * Creates a test adapter descriptor from a raw adapter.\n * This wraps the adapter in a descriptor for descriptor-first context creation in tests.\n * The adapter instance IS an Adapter (via intersection), with identity properties added.\n */\nfunction createTestAdapterDescriptor(\n adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,\n): {\n readonly kind: 'adapter';\n readonly id: string;\n readonly version: string;\n readonly familyId: 'sql';\n readonly targetId: 'postgres';\n create(): SqlRuntimeAdapterInstance<'postgres'>;\n} {\n return {\n kind: 'adapter' as const,\n id: 'test-adapter',\n version: '0.0.1',\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n create(): SqlRuntimeAdapterInstance<'postgres'> {\n // Return an object that combines identity properties with the adapter's methods\n return Object.assign(\n {\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n },\n adapter,\n );\n },\n };\n}\n\n/**\n * Creates a test target descriptor.\n * This is a minimal descriptor for descriptor-first context creation in tests.\n */\nfunction createTestTargetDescriptor(): {\n readonly kind: 'target';\n readonly id: string;\n readonly version: string;\n readonly familyId: 'sql';\n readonly targetId: 'postgres';\n create(): { readonly familyId: 'sql'; readonly targetId: 'postgres' };\n} {\n return {\n kind: 'target' as const,\n id: 'postgres',\n version: '0.0.1',\n familyId: 'sql' as const,\n targetId: 'postgres' as const,\n create() {\n return { familyId: 'sql' as const, targetId: 'postgres' as const };\n },\n };\n}\n\n/**\n * Creates a runtime context with standard test configuration.\n * This helper DRYs up the common pattern of context creation in tests.\n *\n * Accepts a raw adapter and optional extension descriptors, wrapping the\n * adapter in a descriptor internally for descriptor-first context creation.\n */\nexport function createTestContext<TContract extends SqlContract<SqlStorage>>(\n contract: TContract,\n adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,\n options?: {\n extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;\n },\n): RuntimeContext<TContract> {\n return createRuntimeContext<TContract, 'postgres'>({\n contract,\n target: createTestTargetDescriptor(),\n adapter: createTestAdapterDescriptor(adapter),\n extensionPacks: options?.extensionPacks ?? [],\n });\n}\n\n/**\n * Creates a stub adapter for testing.\n * This helper DRYs up the common pattern of adapter creation in tests.\n *\n * The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1)\n * to enable type inference in tests without requiring the postgres adapter package.\n */\nexport function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement> {\n const codecRegistry = createCodecRegistry();\n\n // Register stub codecs for common test types\n // These match the codec IDs used in test contracts (pg/int4@1, pg/text@1, pg/timestamptz@1)\n // but don't require importing from the postgres adapter package\n codecRegistry.register(\n codec({\n typeId: 'pg/int4@1',\n targetTypes: ['int4'],\n encode: (value: number) => value,\n decode: (wire: number) => wire,\n }),\n );\n\n codecRegistry.register(\n codec({\n typeId: 'pg/text@1',\n targetTypes: ['text'],\n encode: (value: string) => value,\n decode: (wire: string) => wire,\n }),\n );\n\n codecRegistry.register(\n codec({\n typeId: 'pg/timestamptz@1',\n targetTypes: ['timestamptz'],\n encode: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),\n decode: (wire: string | Date) =>\n typeof wire === 'string' ? wire : wire instanceof Date ? wire.toISOString() : String(wire),\n }),\n );\n\n return {\n profile: {\n id: 'stub-profile',\n target: 'postgres',\n capabilities: {},\n codecs() {\n return codecRegistry;\n },\n },\n lower(ast: SelectAst, ctx: { contract: SqlContract<SqlStorage>; params?: readonly unknown[] }) {\n const sqlText = JSON.stringify(ast);\n return {\n profileId: this.profile.id,\n body: Object.freeze({ sql: sqlText, params: ctx.params ? [...ctx.params] : [] }),\n };\n },\n };\n}\n\n/**\n * Creates a valid test contract without using validateContract.\n * Ensures all required fields are present (mappings, capabilities, extensionPacks, meta, sources)\n * and returns the contract with proper typing.\n * This helper allows tests to create contracts without depending on sql-query.\n */\nexport function createTestContract<T extends SqlContract<SqlStorage>>(\n contract: Partial<T> &\n Omit<T, 'mappings' | 'capabilities' | 'extensionPacks' | 'meta' | 'sources'>,\n): T {\n return {\n ...contract,\n mappings: contract.mappings ?? { codecTypes: {}, operationTypes: {} },\n capabilities: contract.capabilities ?? {},\n extensionPacks: contract.extensionPacks ?? {},\n meta: contract.meta ?? {},\n sources: contract.sources ?? {},\n } as T;\n}\n\n// Re-export generic utilities from test-utils\nexport {\n collectAsync,\n createDevDatabase,\n type DevDatabase,\n teardownTestDatabase,\n withClient,\n} from '@prisma-next/test-utils';\n"],"mappings":";;;;;;;;;;AA0BA,eAAsB,sBAEpB,SAA2C,MAAmC;AAE9E,QAAOA,eAAkB,QAAQ,QAAa,KAAK,CAAC;;;;;;AAOtD,eAAsB,mBACpB,SACA,MACe;AACf,QAAO,mBAAmB,QAAQ,QAAQ,KAAK,CAAC;;;;;AAMlD,eAAsB,iBAAiB,QAAgB,WAAwC;AAC7F,KAAI,UAAU,OAAO,SAAS,GAAG;AAC/B,QAAM,OAAO,MAAM,UAAU,KAAK,CAAC,GAAG,UAAU,OAAO,CAAC;AACxD;;AAGF,OAAM,OAAO,MAAM,UAAU,IAAI;;;;;;AAOnC,eAAsB,kBACpB,QACA,UACA,SACe;AACf,OAAM,OAAO,MAAM,gDAAgD;AACnE,OAAM,OAAO,MAAM,qCAAqC;AAExD,OAAM,QAAQ,OAAO;AAErB,OAAM,iBAAiB,QAAQ,sBAAsB;AACrD,OAAM,iBAAiB,QAAQ,qBAAqB;AAOpD,OAAM,iBAAiB,QANT,oBAAoB;EAChC,UAAU,SAAS;EACnB,aAAa,SAAS,eAAe,SAAS;EAC9C,cAAc;EACd,kBAAkB;EACnB,CAAC,CACmC,OAAO;;;;;;AAO9C,eAAsB,wBACpB,QACA,UACe;AAOf,OAAM,iBAAiB,QANT,oBAAoB;EAChC,UAAU,SAAS;EACnB,aAAa,SAAS,eAAe,SAAS;EAC9C,cAAc;EACd,kBAAkB;EACnB,CAAC,CACmC,OAAO;;;;;;;AAQ9C,SAAS,4BACP,SAQA;AACA,QAAO;EACL,MAAM;EACN,IAAI;EACJ,SAAS;EACT,UAAU;EACV,UAAU;EACV,SAAgD;AAE9C,UAAO,OAAO,OACZ;I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QAAO;EACL,GAAG;EACH,UAAU,SAAS,YAAY;GAAE,YAAY,EAAE;GAAE,gBAAgB,EAAE;GAAE;EACrE,cAAc,SAAS,gBAAgB,EAAE;EACzC,gBAAgB,SAAS,kBAAkB,EAAE;EAC7C,MAAM,SAAS,QAAQ,EAAE;EACzB,SAAS,SAAS,WAAW,EAAE;EAChC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-runtime",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.94.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
6
9
|
"description": "SQL runtime implementation for Prisma Next",
|
|
7
10
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.3.0-pr.
|
|
9
|
-
"@prisma-next/core-execution-plane": "0.3.0-pr.
|
|
10
|
-
"@prisma-next/operations": "0.3.0-pr.
|
|
11
|
-
"@prisma-next/runtime-executor": "0.3.0-pr.
|
|
12
|
-
"@prisma-next/sql-contract": "0.3.0-pr.
|
|
13
|
-
"@prisma-next/sql-operations": "0.3.0-pr.
|
|
14
|
-
"@prisma-next/sql-relational-core": "0.3.0-pr.
|
|
11
|
+
"@prisma-next/contract": "0.3.0-pr.94.1",
|
|
12
|
+
"@prisma-next/core-execution-plane": "0.3.0-pr.94.1",
|
|
13
|
+
"@prisma-next/operations": "0.3.0-pr.94.1",
|
|
14
|
+
"@prisma-next/runtime-executor": "0.3.0-pr.94.1",
|
|
15
|
+
"@prisma-next/sql-contract": "0.3.0-pr.94.1",
|
|
16
|
+
"@prisma-next/sql-operations": "0.3.0-pr.94.1",
|
|
17
|
+
"@prisma-next/sql-relational-core": "0.3.0-pr.94.1",
|
|
18
|
+
"@prisma-next/test-utils": "0.0.1"
|
|
15
19
|
},
|
|
16
20
|
"devDependencies": {
|
|
17
21
|
"@types/pg": "8.16.0",
|
|
18
22
|
"pg": "8.16.3",
|
|
19
|
-
"
|
|
23
|
+
"tsdown": "0.18.4",
|
|
20
24
|
"typescript": "5.9.3",
|
|
21
25
|
"vitest": "4.0.16",
|
|
22
|
-
"@prisma-next/
|
|
23
|
-
"@prisma-next/
|
|
26
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
27
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
24
28
|
},
|
|
25
29
|
"files": [
|
|
26
30
|
"dist",
|
|
@@ -28,17 +32,15 @@
|
|
|
28
32
|
"test"
|
|
29
33
|
],
|
|
30
34
|
"exports": {
|
|
31
|
-
".":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
"./test/utils": {
|
|
36
|
-
"types": "./dist/test/utils.d.ts",
|
|
37
|
-
"import": "./dist/test/utils.js"
|
|
38
|
-
}
|
|
35
|
+
".": "./dist/index.mjs",
|
|
36
|
+
"./test/utils": "./dist/test/utils.mjs",
|
|
37
|
+
"./package.json": "./package.json"
|
|
39
38
|
},
|
|
39
|
+
"main": "./dist/index.mjs",
|
|
40
|
+
"module": "./dist/index.mjs",
|
|
41
|
+
"types": "./dist/index.d.mts",
|
|
40
42
|
"scripts": {
|
|
41
|
-
"build": "
|
|
43
|
+
"build": "tsdown",
|
|
42
44
|
"test": "vitest run --passWithNoTests",
|
|
43
45
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
44
46
|
"typecheck": "tsc --noEmit",
|