@prisma-next/sql-runtime 0.3.0-pr.73.2 → 0.3.0-pr.75.2
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/{accelerate-EEKAFGN3-SHR4XFVV.js → accelerate-EEKAFGN3-P6A6XJWJ.js} +28 -28
- package/dist/{accelerate-EEKAFGN3-SHR4XFVV.js.map → accelerate-EEKAFGN3-P6A6XJWJ.js.map} +1 -1
- package/dist/codecs/decoding.d.ts +4 -0
- package/dist/codecs/decoding.d.ts.map +1 -0
- package/dist/codecs/encoding.d.ts +5 -0
- package/dist/codecs/encoding.d.ts.map +1 -0
- package/dist/codecs/validation.d.ts +6 -0
- package/dist/codecs/validation.d.ts.map +1 -0
- package/dist/{dist-LCVVJCGI.js → dist-AQ3LWXOX.js} +13 -13
- package/dist/{dist-LCVVJCGI.js.map → dist-AQ3LWXOX.js.map} +1 -1
- package/dist/exports/index.d.ts +11 -0
- package/dist/exports/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -29
- package/dist/index.d.ts.map +1 -0
- package/dist/lower-sql-plan.d.ts +15 -0
- package/dist/lower-sql-plan.d.ts.map +1 -0
- package/dist/sql-context.d.ts +65 -0
- package/dist/sql-context.d.ts.map +1 -0
- package/dist/sql-family-adapter.d.ts +10 -0
- package/dist/sql-family-adapter.d.ts.map +1 -0
- package/dist/sql-marker.d.ts +22 -0
- package/dist/sql-marker.d.ts.map +1 -0
- package/dist/sql-runtime.d.ts +25 -0
- package/dist/sql-runtime.d.ts.map +1 -0
- package/dist/test/utils.js +17 -18
- package/dist/test/utils.js.map +1 -1
- package/package.json +17 -16
- package/src/codecs/decoding.ts +140 -0
- package/src/codecs/encoding.ts +76 -0
- package/src/codecs/validation.ts +67 -0
- package/src/exports/index.ts +38 -0
- package/src/index.ts +1 -0
- package/src/lower-sql-plan.ts +32 -0
- package/src/sql-context.ts +156 -0
- package/src/sql-family-adapter.ts +43 -0
- package/src/sql-marker.ts +105 -0
- package/src/sql-runtime.ts +166 -0
- package/dist/sql-runtime-DgEbg2OP.d.ts +0 -109
- package/dist/test/utils.d.ts +0 -64
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { MarkerStatement } from '@prisma-next/runtime-executor';
|
|
2
|
+
|
|
3
|
+
export interface SqlStatement {
|
|
4
|
+
readonly sql: string;
|
|
5
|
+
readonly params: readonly unknown[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface WriteMarkerInput {
|
|
9
|
+
readonly coreHash: string;
|
|
10
|
+
readonly profileHash: string;
|
|
11
|
+
readonly contractJson?: unknown;
|
|
12
|
+
readonly canonicalVersion?: number;
|
|
13
|
+
readonly appTag?: string;
|
|
14
|
+
readonly meta?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ensureSchemaStatement: SqlStatement = {
|
|
18
|
+
sql: 'create schema if not exists prisma_contract',
|
|
19
|
+
params: [],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const ensureTableStatement: SqlStatement = {
|
|
23
|
+
sql: `create table if not exists prisma_contract.marker (
|
|
24
|
+
id smallint primary key default 1,
|
|
25
|
+
core_hash text not null,
|
|
26
|
+
profile_hash text not null,
|
|
27
|
+
contract_json jsonb,
|
|
28
|
+
canonical_version int,
|
|
29
|
+
updated_at timestamptz not null default now(),
|
|
30
|
+
app_tag text,
|
|
31
|
+
meta jsonb not null default '{}'
|
|
32
|
+
)`,
|
|
33
|
+
params: [],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function readContractMarker(): MarkerStatement {
|
|
37
|
+
return {
|
|
38
|
+
sql: `select
|
|
39
|
+
core_hash,
|
|
40
|
+
profile_hash,
|
|
41
|
+
contract_json,
|
|
42
|
+
canonical_version,
|
|
43
|
+
updated_at,
|
|
44
|
+
app_tag,
|
|
45
|
+
meta
|
|
46
|
+
from prisma_contract.marker
|
|
47
|
+
where id = $1`,
|
|
48
|
+
params: [1],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface WriteContractMarkerStatements {
|
|
53
|
+
readonly insert: SqlStatement;
|
|
54
|
+
readonly update: SqlStatement;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function writeContractMarker(input: WriteMarkerInput): WriteContractMarkerStatements {
|
|
58
|
+
const baseParams: readonly unknown[] = [
|
|
59
|
+
1,
|
|
60
|
+
input.coreHash,
|
|
61
|
+
input.profileHash,
|
|
62
|
+
input.contractJson ?? null,
|
|
63
|
+
input.canonicalVersion ?? null,
|
|
64
|
+
input.appTag ?? null,
|
|
65
|
+
JSON.stringify(input.meta ?? {}),
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const insert: SqlStatement = {
|
|
69
|
+
sql: `insert into prisma_contract.marker (
|
|
70
|
+
id,
|
|
71
|
+
core_hash,
|
|
72
|
+
profile_hash,
|
|
73
|
+
contract_json,
|
|
74
|
+
canonical_version,
|
|
75
|
+
updated_at,
|
|
76
|
+
app_tag,
|
|
77
|
+
meta
|
|
78
|
+
) values (
|
|
79
|
+
$1,
|
|
80
|
+
$2,
|
|
81
|
+
$3,
|
|
82
|
+
$4::jsonb,
|
|
83
|
+
$5,
|
|
84
|
+
now(),
|
|
85
|
+
$6,
|
|
86
|
+
$7::jsonb
|
|
87
|
+
)`,
|
|
88
|
+
params: baseParams,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const update: SqlStatement = {
|
|
92
|
+
sql: `update prisma_contract.marker set
|
|
93
|
+
core_hash = $2,
|
|
94
|
+
profile_hash = $3,
|
|
95
|
+
contract_json = $4::jsonb,
|
|
96
|
+
canonical_version = $5,
|
|
97
|
+
updated_at = now(),
|
|
98
|
+
app_tag = $6,
|
|
99
|
+
meta = $7::jsonb
|
|
100
|
+
where id = $1`,
|
|
101
|
+
params: baseParams,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return { insert, update };
|
|
105
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import type { OperationRegistry } from '@prisma-next/operations';
|
|
3
|
+
import type {
|
|
4
|
+
Log,
|
|
5
|
+
Plugin,
|
|
6
|
+
RuntimeCore,
|
|
7
|
+
RuntimeCoreOptions,
|
|
8
|
+
RuntimeTelemetryEvent,
|
|
9
|
+
RuntimeVerifyOptions,
|
|
10
|
+
TelemetryOutcome,
|
|
11
|
+
} from '@prisma-next/runtime-executor';
|
|
12
|
+
import { AsyncIterableResult, createRuntimeCore } from '@prisma-next/runtime-executor';
|
|
13
|
+
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
14
|
+
import type {
|
|
15
|
+
Adapter,
|
|
16
|
+
CodecRegistry,
|
|
17
|
+
LoweredStatement,
|
|
18
|
+
SelectAst,
|
|
19
|
+
SqlDriver,
|
|
20
|
+
} from '@prisma-next/sql-relational-core/ast';
|
|
21
|
+
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
22
|
+
import { decodeRow } from './codecs/decoding';
|
|
23
|
+
import { encodeParams } from './codecs/encoding';
|
|
24
|
+
import { validateCodecRegistryCompleteness } from './codecs/validation';
|
|
25
|
+
import { lowerSqlPlan } from './lower-sql-plan';
|
|
26
|
+
import type { RuntimeContext } from './sql-context';
|
|
27
|
+
import { SqlFamilyAdapter } from './sql-family-adapter';
|
|
28
|
+
|
|
29
|
+
export interface RuntimeOptions<
|
|
30
|
+
TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,
|
|
31
|
+
> {
|
|
32
|
+
readonly driver: SqlDriver;
|
|
33
|
+
readonly verify: RuntimeVerifyOptions;
|
|
34
|
+
readonly context: RuntimeContext<TContract>;
|
|
35
|
+
readonly plugins?: readonly Plugin<
|
|
36
|
+
TContract,
|
|
37
|
+
Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
|
|
38
|
+
SqlDriver
|
|
39
|
+
>[];
|
|
40
|
+
readonly mode?: 'strict' | 'permissive';
|
|
41
|
+
readonly log?: Log;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface Runtime {
|
|
45
|
+
execute<Row = Record<string, unknown>>(
|
|
46
|
+
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
47
|
+
): AsyncIterableResult<Row>;
|
|
48
|
+
telemetry(): RuntimeTelemetryEvent | null;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
operations(): OperationRegistry;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome };
|
|
54
|
+
|
|
55
|
+
class SqlRuntimeImpl<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>>
|
|
56
|
+
implements Runtime
|
|
57
|
+
{
|
|
58
|
+
private readonly core: RuntimeCore<
|
|
59
|
+
TContract,
|
|
60
|
+
Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
|
|
61
|
+
SqlDriver
|
|
62
|
+
>;
|
|
63
|
+
private readonly contract: TContract;
|
|
64
|
+
private readonly context: RuntimeContext<TContract>;
|
|
65
|
+
private readonly codecRegistry: CodecRegistry;
|
|
66
|
+
private codecRegistryValidated: boolean;
|
|
67
|
+
|
|
68
|
+
constructor(options: RuntimeOptions<TContract>) {
|
|
69
|
+
const { context, driver, verify, plugins, mode, log } = options;
|
|
70
|
+
this.contract = context.contract;
|
|
71
|
+
this.context = context;
|
|
72
|
+
this.codecRegistry = context.codecs;
|
|
73
|
+
this.codecRegistryValidated = false;
|
|
74
|
+
|
|
75
|
+
const familyAdapter = new SqlFamilyAdapter(context.contract);
|
|
76
|
+
|
|
77
|
+
const coreOptions: RuntimeCoreOptions<
|
|
78
|
+
TContract,
|
|
79
|
+
Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
|
|
80
|
+
SqlDriver
|
|
81
|
+
> = {
|
|
82
|
+
familyAdapter,
|
|
83
|
+
driver,
|
|
84
|
+
verify,
|
|
85
|
+
plugins: plugins as readonly Plugin<
|
|
86
|
+
TContract,
|
|
87
|
+
Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
|
|
88
|
+
SqlDriver
|
|
89
|
+
>[],
|
|
90
|
+
...(mode !== undefined ? { mode } : {}),
|
|
91
|
+
...(log !== undefined ? { log } : {}),
|
|
92
|
+
operationRegistry: context.operations,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
this.core = createRuntimeCore(coreOptions);
|
|
96
|
+
|
|
97
|
+
if (verify.mode === 'startup') {
|
|
98
|
+
validateCodecRegistryCompleteness(this.codecRegistry, context.contract);
|
|
99
|
+
this.codecRegistryValidated = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private ensureCodecRegistryValidated(contract: SqlContract<SqlStorage>): void {
|
|
104
|
+
if (!this.codecRegistryValidated) {
|
|
105
|
+
validateCodecRegistryCompleteness(this.codecRegistry, contract);
|
|
106
|
+
this.codecRegistryValidated = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
execute<Row = Record<string, unknown>>(
|
|
111
|
+
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
112
|
+
): AsyncIterableResult<Row> {
|
|
113
|
+
this.ensureCodecRegistryValidated(this.contract);
|
|
114
|
+
|
|
115
|
+
// Check if plan is SqlQueryPlan (has ast but no sql)
|
|
116
|
+
const isSqlQueryPlan = (p: ExecutionPlan<Row> | SqlQueryPlan<Row>): p is SqlQueryPlan<Row> => {
|
|
117
|
+
return 'ast' in p && !('sql' in p);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Lower SqlQueryPlan to Plan if needed
|
|
121
|
+
const executablePlan: ExecutionPlan<Row> = isSqlQueryPlan(plan)
|
|
122
|
+
? lowerSqlPlan(this.context, plan)
|
|
123
|
+
: plan;
|
|
124
|
+
|
|
125
|
+
const iterator = async function* (
|
|
126
|
+
self: SqlRuntimeImpl<TContract>,
|
|
127
|
+
): AsyncGenerator<Row, void, unknown> {
|
|
128
|
+
const encodedParams = encodeParams(executablePlan, self.codecRegistry);
|
|
129
|
+
const planWithEncodedParams: ExecutionPlan<Row> = {
|
|
130
|
+
...executablePlan,
|
|
131
|
+
params: encodedParams,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const coreIterator = self.core.execute(planWithEncodedParams);
|
|
135
|
+
|
|
136
|
+
for await (const rawRow of coreIterator) {
|
|
137
|
+
const decodedRow = decodeRow(
|
|
138
|
+
rawRow as Record<string, unknown>,
|
|
139
|
+
executablePlan,
|
|
140
|
+
self.codecRegistry,
|
|
141
|
+
);
|
|
142
|
+
yield decodedRow as Row;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return new AsyncIterableResult(iterator(this));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
telemetry(): RuntimeTelemetryEvent | null {
|
|
150
|
+
return this.core.telemetry();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
operations(): OperationRegistry {
|
|
154
|
+
return this.core.operations();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
close(): Promise<void> {
|
|
158
|
+
return this.core.close();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function createRuntime<TContract extends SqlContract<SqlStorage>>(
|
|
163
|
+
options: RuntimeOptions<TContract>,
|
|
164
|
+
): Runtime {
|
|
165
|
+
return new SqlRuntimeImpl(options);
|
|
166
|
+
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { MarkerStatement, AsyncIterableResult, RuntimeTelemetryEvent, RuntimeVerifyOptions, Plugin, Log } from '@prisma-next/runtime-executor';
|
|
2
|
-
import { ExecutionPlan } from '@prisma-next/contract/types';
|
|
3
|
-
import { OperationRegistry } from '@prisma-next/operations';
|
|
4
|
-
import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
5
|
-
import { Adapter, QueryAst, LoweredStatement, CodecRegistry, SqlDriver, SelectAst } from '@prisma-next/sql-relational-core/ast';
|
|
6
|
-
import { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
7
|
-
import { RuntimeTargetDescriptor, RuntimeAdapterDescriptor, RuntimeAdapterInstance, RuntimeExtensionDescriptor, RuntimeExtensionInstance } from '@prisma-next/core-execution-plane/types';
|
|
8
|
-
import { SqlOperationSignature } from '@prisma-next/sql-operations';
|
|
9
|
-
import { QueryLaneContext } from '@prisma-next/sql-relational-core/query-lane-context';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* SQL runtime extension instance.
|
|
13
|
-
* Extends the framework RuntimeExtensionInstance with SQL-specific hooks
|
|
14
|
-
* for contributing codecs and operations to the runtime context.
|
|
15
|
-
*
|
|
16
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
17
|
-
*/
|
|
18
|
-
interface SqlRuntimeExtensionInstance<TTargetId extends string> extends RuntimeExtensionInstance<'sql', TTargetId> {
|
|
19
|
-
/** Returns codecs to register in the runtime context. */
|
|
20
|
-
codecs?(): CodecRegistry;
|
|
21
|
-
/** Returns operations to register in the runtime context. */
|
|
22
|
-
operations?(): ReadonlyArray<SqlOperationSignature>;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* SQL runtime extension descriptor.
|
|
26
|
-
* Extends the framework RuntimeExtensionDescriptor with SQL-specific instance type.
|
|
27
|
-
*
|
|
28
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
29
|
-
*/
|
|
30
|
-
interface SqlRuntimeExtensionDescriptor<TTargetId extends string> extends RuntimeExtensionDescriptor<'sql', TTargetId, SqlRuntimeExtensionInstance<TTargetId>> {
|
|
31
|
-
create(): SqlRuntimeExtensionInstance<TTargetId>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* SQL runtime adapter instance interface.
|
|
35
|
-
* Combines RuntimeAdapterInstance identity with SQL Adapter behavior.
|
|
36
|
-
* The instance IS an Adapter (via intersection), not HAS an adapter property.
|
|
37
|
-
*
|
|
38
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
39
|
-
*/
|
|
40
|
-
type SqlRuntimeAdapterInstance<TTargetId extends string = string> = RuntimeAdapterInstance<'sql', TTargetId> & Adapter<QueryAst, SqlContract<SqlStorage>, LoweredStatement>;
|
|
41
|
-
interface RuntimeContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> extends QueryLaneContext<TContract> {
|
|
42
|
-
readonly adapter: Adapter<QueryAst, TContract, LoweredStatement> | Adapter<QueryAst, SqlContract<SqlStorage>, LoweredStatement>;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Descriptor-first options for creating a SQL runtime context.
|
|
46
|
-
* Takes the same framework composition as control-plane: target, adapter, extensionPacks.
|
|
47
|
-
*
|
|
48
|
-
* @template TContract - The SQL contract type
|
|
49
|
-
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
50
|
-
*/
|
|
51
|
-
interface CreateRuntimeContextOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, TTargetId extends string = string> {
|
|
52
|
-
readonly contract: TContract;
|
|
53
|
-
readonly target: RuntimeTargetDescriptor<'sql', TTargetId>;
|
|
54
|
-
readonly adapter: RuntimeAdapterDescriptor<'sql', TTargetId, SqlRuntimeAdapterInstance<TTargetId>>;
|
|
55
|
-
readonly extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<TTargetId>>;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Creates a SQL runtime context from descriptor-first composition.
|
|
59
|
-
*
|
|
60
|
-
* The context includes:
|
|
61
|
-
* - The validated contract
|
|
62
|
-
* - The adapter instance (created from descriptor)
|
|
63
|
-
* - Codec registry (populated from adapter + extension instances)
|
|
64
|
-
* - Operation registry (populated from extension instances)
|
|
65
|
-
*
|
|
66
|
-
* @param options - Descriptor-first composition options
|
|
67
|
-
* @returns RuntimeContext with registries wired from all components
|
|
68
|
-
*/
|
|
69
|
-
declare function createRuntimeContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, TTargetId extends string = string>(options: CreateRuntimeContextOptions<TContract, TTargetId>): RuntimeContext<TContract>;
|
|
70
|
-
|
|
71
|
-
interface SqlStatement {
|
|
72
|
-
readonly sql: string;
|
|
73
|
-
readonly params: readonly unknown[];
|
|
74
|
-
}
|
|
75
|
-
interface WriteMarkerInput {
|
|
76
|
-
readonly coreHash: string;
|
|
77
|
-
readonly profileHash: string;
|
|
78
|
-
readonly contractJson?: unknown;
|
|
79
|
-
readonly canonicalVersion?: number;
|
|
80
|
-
readonly appTag?: string;
|
|
81
|
-
readonly meta?: Record<string, unknown>;
|
|
82
|
-
}
|
|
83
|
-
declare const ensureSchemaStatement: SqlStatement;
|
|
84
|
-
declare const ensureTableStatement: SqlStatement;
|
|
85
|
-
declare function readContractMarker(): MarkerStatement;
|
|
86
|
-
interface WriteContractMarkerStatements {
|
|
87
|
-
readonly insert: SqlStatement;
|
|
88
|
-
readonly update: SqlStatement;
|
|
89
|
-
}
|
|
90
|
-
declare function writeContractMarker(input: WriteMarkerInput): WriteContractMarkerStatements;
|
|
91
|
-
|
|
92
|
-
interface RuntimeOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
|
|
93
|
-
readonly driver: SqlDriver;
|
|
94
|
-
readonly verify: RuntimeVerifyOptions;
|
|
95
|
-
readonly context: RuntimeContext<TContract>;
|
|
96
|
-
readonly plugins?: readonly Plugin<TContract, Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, SqlDriver>[];
|
|
97
|
-
readonly mode?: 'strict' | 'permissive';
|
|
98
|
-
readonly log?: Log;
|
|
99
|
-
}
|
|
100
|
-
interface Runtime {
|
|
101
|
-
execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row> | SqlQueryPlan<Row>): AsyncIterableResult<Row>;
|
|
102
|
-
telemetry(): RuntimeTelemetryEvent | null;
|
|
103
|
-
close(): Promise<void>;
|
|
104
|
-
operations(): OperationRegistry;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
declare function createRuntime<TContract extends SqlContract<SqlStorage>>(options: RuntimeOptions<TContract>): Runtime;
|
|
108
|
-
|
|
109
|
-
export { type CreateRuntimeContextOptions as C, type RuntimeContext as R, type SqlRuntimeAdapterInstance as S, type SqlRuntimeExtensionDescriptor as a, type SqlRuntimeExtensionInstance as b, createRuntimeContext as c, type SqlStatement as d, ensureSchemaStatement as e, ensureTableStatement as f, type Runtime as g, type RuntimeOptions as h, createRuntime as i, readContractMarker as r, writeContractMarker as w };
|
package/dist/test/utils.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ExecutionPlan, ResultType } from '@prisma-next/contract/types';
|
|
2
|
-
import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
|
-
import { Adapter, SelectAst, LoweredStatement } from '@prisma-next/sql-relational-core/ast';
|
|
4
|
-
import { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
5
|
-
import { Client } from 'pg';
|
|
6
|
-
import { i as createRuntime, d as SqlStatement, a as SqlRuntimeExtensionDescriptor, R as RuntimeContext } from '../sql-runtime-DgEbg2OP.js';
|
|
7
|
-
export { DevDatabase, collectAsync, createDevDatabase, teardownTestDatabase, withClient } from '@prisma-next/test-utils';
|
|
8
|
-
import '@prisma-next/runtime-executor';
|
|
9
|
-
import '@prisma-next/operations';
|
|
10
|
-
import '@prisma-next/core-execution-plane/types';
|
|
11
|
-
import '@prisma-next/sql-operations';
|
|
12
|
-
import '@prisma-next/sql-relational-core/query-lane-context';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Executes a plan and collects all results into an array.
|
|
16
|
-
* This helper DRYs up the common pattern of executing plans in tests.
|
|
17
|
-
* The return type is inferred from the plan's type parameter.
|
|
18
|
-
*/
|
|
19
|
-
declare function executePlanAndCollect<P extends ExecutionPlan<ResultType<P>> | SqlQueryPlan<ResultType<P>>>(runtime: ReturnType<typeof createRuntime>, plan: P): Promise<ResultType<P>[]>;
|
|
20
|
-
/**
|
|
21
|
-
* Drains a plan execution, consuming all results without collecting them.
|
|
22
|
-
* Useful for testing side effects without memory overhead.
|
|
23
|
-
*/
|
|
24
|
-
declare function drainPlanExecution(runtime: ReturnType<typeof createRuntime>, plan: ExecutionPlan | SqlQueryPlan<unknown>): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Executes a SQL statement on a database client.
|
|
27
|
-
*/
|
|
28
|
-
declare function executeStatement(client: Client, statement: SqlStatement): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Sets up database schema and data, then writes the contract marker.
|
|
31
|
-
* This helper DRYs up the common pattern of database setup in tests.
|
|
32
|
-
*/
|
|
33
|
-
declare function setupTestDatabase(client: Client, contract: SqlContract<SqlStorage>, setupFn: (client: Client) => Promise<void>): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Writes a contract marker to the database.
|
|
36
|
-
* This helper DRYs up the common pattern of writing contract markers in tests.
|
|
37
|
-
*/
|
|
38
|
-
declare function writeTestContractMarker(client: Client, contract: SqlContract<SqlStorage>): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a runtime context with standard test configuration.
|
|
41
|
-
* This helper DRYs up the common pattern of context creation in tests.
|
|
42
|
-
*
|
|
43
|
-
* Accepts a raw adapter and optional extension descriptors, wrapping the
|
|
44
|
-
* adapter in a descriptor internally for descriptor-first context creation.
|
|
45
|
-
*/
|
|
46
|
-
declare function createTestContext<TContract extends SqlContract<SqlStorage>>(contract: TContract, adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, options?: {
|
|
47
|
-
extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;
|
|
48
|
-
}): RuntimeContext<TContract>;
|
|
49
|
-
/**
|
|
50
|
-
* Creates a stub adapter for testing.
|
|
51
|
-
* This helper DRYs up the common pattern of adapter creation in tests.
|
|
52
|
-
*
|
|
53
|
-
* The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1)
|
|
54
|
-
* to enable type inference in tests without requiring the postgres adapter package.
|
|
55
|
-
*/
|
|
56
|
-
declare function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>;
|
|
57
|
-
/**
|
|
58
|
-
* Creates a valid test contract without using validateContract.
|
|
59
|
-
* Ensures mappings are present and returns the contract with proper typing.
|
|
60
|
-
* This helper allows tests to create contracts without depending on sql-query.
|
|
61
|
-
*/
|
|
62
|
-
declare function createTestContract<T extends SqlContract<SqlStorage>>(contract: T): T;
|
|
63
|
-
|
|
64
|
-
export { createStubAdapter, createTestContext, createTestContract, drainPlanExecution, executePlanAndCollect, executeStatement, setupTestDatabase, writeTestContractMarker };
|