@prisma-next/sql-runtime 0.3.0-dev.13 → 0.3.0-dev.146
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 +201 -0
- package/README.md +141 -24
- package/dist/exports-DGa0ipuP.mjs +956 -0
- package/dist/exports-DGa0ipuP.mjs.map +1 -0
- package/dist/index-CDbmlDcn.d.mts +177 -0
- package/dist/index-CDbmlDcn.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/test/utils.d.mts +77 -0
- package/dist/test/utils.d.mts.map +1 -0
- package/dist/test/utils.mjs +221 -0
- package/dist/test/utils.mjs.map +1 -0
- package/package.json +29 -22
- package/src/codecs/decoding.ts +84 -3
- package/src/codecs/encoding.ts +5 -15
- package/src/codecs/json-schema-validation.ts +61 -0
- package/src/codecs/validation.ts +6 -5
- package/src/exports/index.ts +19 -7
- package/src/lower-sql-plan.ts +9 -9
- package/src/plugins/budgets.ts +375 -0
- package/src/plugins/lints.ts +211 -0
- package/src/sql-context.ts +454 -108
- package/src/sql-family-adapter.ts +16 -22
- package/src/sql-marker.ts +2 -2
- package/src/sql-runtime.ts +136 -47
- package/test/async-iterable-result.test.ts +42 -37
- package/test/budgets.test.ts +481 -0
- package/test/context.types.test-d.ts +68 -0
- package/test/execution-stack.test.ts +164 -0
- package/test/json-schema-validation.test.ts +571 -0
- package/test/lints.test.ts +161 -0
- package/test/mutation-default-generators.test.ts +254 -0
- package/test/parameterized-types.test.ts +529 -0
- package/test/sql-context.test.ts +301 -134
- package/test/sql-family-adapter.test.ts +37 -20
- package/test/sql-runtime.test.ts +220 -49
- package/test/utils.ts +102 -64
- 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/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/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.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/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/src/codecs/decoding.d.ts +0 -4
- package/dist/src/codecs/decoding.d.ts.map +0 -1
- package/dist/src/codecs/encoding.d.ts +0 -5
- package/dist/src/codecs/encoding.d.ts.map +0 -1
- package/dist/src/codecs/validation.d.ts +0 -6
- package/dist/src/codecs/validation.d.ts.map +0 -1
- package/dist/src/exports/index.d.ts +0 -11
- package/dist/src/exports/index.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lower-sql-plan.d.ts +0 -15
- package/dist/src/lower-sql-plan.d.ts.map +0 -1
- package/dist/src/sql-context.d.ts +0 -65
- package/dist/src/sql-context.d.ts.map +0 -1
- package/dist/src/sql-family-adapter.d.ts +0 -10
- package/dist/src/sql-family-adapter.d.ts.map +0 -1
- package/dist/src/sql-marker.d.ts +0 -22
- package/dist/src/sql-marker.d.ts.map +0 -1
- package/dist/src/sql-runtime.d.ts +0 -25
- package/dist/src/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.d.ts +0 -59
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js +0 -24634
- 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/src/index.ts +0 -1
package/src/sql-marker.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface SqlStatement {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface WriteMarkerInput {
|
|
9
|
-
readonly
|
|
9
|
+
readonly storageHash: string;
|
|
10
10
|
readonly profileHash: string;
|
|
11
11
|
readonly contractJson?: unknown;
|
|
12
12
|
readonly canonicalVersion?: number;
|
|
@@ -57,7 +57,7 @@ export interface WriteContractMarkerStatements {
|
|
|
57
57
|
export function writeContractMarker(input: WriteMarkerInput): WriteContractMarkerStatements {
|
|
58
58
|
const baseParams: readonly unknown[] = [
|
|
59
59
|
1,
|
|
60
|
-
input.
|
|
60
|
+
input.storageHash,
|
|
61
61
|
input.profileHash,
|
|
62
62
|
input.contractJson ?? null,
|
|
63
63
|
input.canonicalVersion ?? null,
|
package/src/sql-runtime.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { Contract, ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import type {
|
|
3
|
+
ExecutionStackInstance,
|
|
4
|
+
RuntimeDriverInstance,
|
|
5
|
+
} from '@prisma-next/framework-components/execution';
|
|
3
6
|
import type {
|
|
4
7
|
Log,
|
|
5
8
|
Plugin,
|
|
@@ -10,86 +13,133 @@ import type {
|
|
|
10
13
|
TelemetryOutcome,
|
|
11
14
|
} from '@prisma-next/runtime-executor';
|
|
12
15
|
import { AsyncIterableResult, createRuntimeCore } from '@prisma-next/runtime-executor';
|
|
13
|
-
import type {
|
|
16
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
14
17
|
import type {
|
|
15
18
|
Adapter,
|
|
19
|
+
AnyQueryAst,
|
|
16
20
|
CodecRegistry,
|
|
17
21
|
LoweredStatement,
|
|
18
22
|
SelectAst,
|
|
19
23
|
SqlDriver,
|
|
20
24
|
} from '@prisma-next/sql-relational-core/ast';
|
|
21
25
|
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
26
|
+
import type { JsonSchemaValidatorRegistry } from '@prisma-next/sql-relational-core/query-lane-context';
|
|
27
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
22
28
|
import { decodeRow } from './codecs/decoding';
|
|
23
29
|
import { encodeParams } from './codecs/encoding';
|
|
24
30
|
import { validateCodecRegistryCompleteness } from './codecs/validation';
|
|
25
31
|
import { lowerSqlPlan } from './lower-sql-plan';
|
|
26
|
-
import type {
|
|
32
|
+
import type {
|
|
33
|
+
ExecutionContext,
|
|
34
|
+
SqlRuntimeAdapterInstance,
|
|
35
|
+
SqlRuntimeExtensionInstance,
|
|
36
|
+
} from './sql-context';
|
|
27
37
|
import { SqlFamilyAdapter } from './sql-family-adapter';
|
|
28
38
|
|
|
29
|
-
export interface RuntimeOptions<
|
|
30
|
-
|
|
39
|
+
export interface RuntimeOptions<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> {
|
|
40
|
+
readonly context: ExecutionContext<TContract>;
|
|
41
|
+
readonly adapter: Adapter<AnyQueryAst, Contract<SqlStorage>, LoweredStatement>;
|
|
42
|
+
readonly driver: SqlDriver<unknown>;
|
|
43
|
+
readonly verify: RuntimeVerifyOptions;
|
|
44
|
+
readonly plugins?: readonly Plugin<
|
|
45
|
+
TContract,
|
|
46
|
+
Adapter<SelectAst, Contract<SqlStorage>, LoweredStatement>,
|
|
47
|
+
SqlDriver<unknown>
|
|
48
|
+
>[];
|
|
49
|
+
readonly mode?: 'strict' | 'permissive';
|
|
50
|
+
readonly log?: Log;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface CreateRuntimeOptions<
|
|
54
|
+
TContract extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
55
|
+
TTargetId extends string = string,
|
|
31
56
|
> {
|
|
32
|
-
readonly
|
|
57
|
+
readonly stackInstance: ExecutionStackInstance<
|
|
58
|
+
'sql',
|
|
59
|
+
TTargetId,
|
|
60
|
+
SqlRuntimeAdapterInstance<TTargetId>,
|
|
61
|
+
RuntimeDriverInstance<'sql', TTargetId>,
|
|
62
|
+
SqlRuntimeExtensionInstance<TTargetId>
|
|
63
|
+
>;
|
|
64
|
+
readonly context: ExecutionContext<TContract>;
|
|
65
|
+
readonly driver: SqlDriver<unknown>;
|
|
33
66
|
readonly verify: RuntimeVerifyOptions;
|
|
34
|
-
readonly context: RuntimeContext<TContract>;
|
|
35
67
|
readonly plugins?: readonly Plugin<
|
|
36
68
|
TContract,
|
|
37
|
-
Adapter<SelectAst,
|
|
38
|
-
SqlDriver
|
|
69
|
+
Adapter<SelectAst, Contract<SqlStorage>, LoweredStatement>,
|
|
70
|
+
SqlDriver<unknown>
|
|
39
71
|
>[];
|
|
40
72
|
readonly mode?: 'strict' | 'permissive';
|
|
41
73
|
readonly log?: Log;
|
|
42
74
|
}
|
|
43
75
|
|
|
44
|
-
export interface Runtime {
|
|
76
|
+
export interface Runtime extends RuntimeQueryable {
|
|
77
|
+
connection(): Promise<RuntimeConnection>;
|
|
78
|
+
telemetry(): RuntimeTelemetryEvent | null;
|
|
79
|
+
close(): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface RuntimeConnection extends RuntimeQueryable {
|
|
83
|
+
transaction(): Promise<RuntimeTransaction>;
|
|
84
|
+
release(): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface RuntimeTransaction extends RuntimeQueryable {
|
|
88
|
+
commit(): Promise<void>;
|
|
89
|
+
rollback(): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface RuntimeQueryable {
|
|
45
93
|
execute<Row = Record<string, unknown>>(
|
|
46
94
|
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
47
95
|
): AsyncIterableResult<Row>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface CoreQueryable {
|
|
99
|
+
execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row>): AsyncIterableResult<Row>;
|
|
51
100
|
}
|
|
52
101
|
|
|
53
102
|
export type { RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome };
|
|
54
103
|
|
|
55
|
-
class SqlRuntimeImpl<TContract extends
|
|
104
|
+
class SqlRuntimeImpl<TContract extends Contract<SqlStorage> = Contract<SqlStorage>>
|
|
56
105
|
implements Runtime
|
|
57
106
|
{
|
|
58
107
|
private readonly core: RuntimeCore<
|
|
59
108
|
TContract,
|
|
60
|
-
Adapter<SelectAst,
|
|
61
|
-
SqlDriver
|
|
109
|
+
Adapter<SelectAst, Contract<SqlStorage>, LoweredStatement>,
|
|
110
|
+
SqlDriver<unknown>
|
|
62
111
|
>;
|
|
63
112
|
private readonly contract: TContract;
|
|
64
|
-
private readonly
|
|
113
|
+
private readonly adapter: Adapter<AnyQueryAst, Contract<SqlStorage>, LoweredStatement>;
|
|
65
114
|
private readonly codecRegistry: CodecRegistry;
|
|
115
|
+
private readonly jsonSchemaValidators: JsonSchemaValidatorRegistry | undefined;
|
|
66
116
|
private codecRegistryValidated: boolean;
|
|
67
117
|
|
|
68
118
|
constructor(options: RuntimeOptions<TContract>) {
|
|
69
|
-
const { context, driver, verify, plugins, mode, log } = options;
|
|
119
|
+
const { context, adapter, driver, verify, plugins, mode, log } = options;
|
|
70
120
|
this.contract = context.contract;
|
|
71
|
-
this.
|
|
121
|
+
this.adapter = adapter;
|
|
72
122
|
this.codecRegistry = context.codecs;
|
|
123
|
+
this.jsonSchemaValidators = context.jsonSchemaValidators;
|
|
73
124
|
this.codecRegistryValidated = false;
|
|
74
125
|
|
|
75
|
-
const familyAdapter = new SqlFamilyAdapter(context.contract);
|
|
126
|
+
const familyAdapter = new SqlFamilyAdapter(context.contract, adapter.profile);
|
|
76
127
|
|
|
77
128
|
const coreOptions: RuntimeCoreOptions<
|
|
78
129
|
TContract,
|
|
79
|
-
Adapter<SelectAst,
|
|
80
|
-
SqlDriver
|
|
130
|
+
Adapter<SelectAst, Contract<SqlStorage>, LoweredStatement>,
|
|
131
|
+
SqlDriver<unknown>
|
|
81
132
|
> = {
|
|
82
133
|
familyAdapter,
|
|
83
134
|
driver,
|
|
84
135
|
verify,
|
|
85
136
|
plugins: plugins as readonly Plugin<
|
|
86
137
|
TContract,
|
|
87
|
-
Adapter<SelectAst,
|
|
88
|
-
SqlDriver
|
|
138
|
+
Adapter<SelectAst, Contract<SqlStorage>, LoweredStatement>,
|
|
139
|
+
SqlDriver<unknown>
|
|
89
140
|
>[],
|
|
90
|
-
...(mode
|
|
91
|
-
...(log
|
|
92
|
-
operationRegistry: context.operations,
|
|
141
|
+
...ifDefined('mode', mode),
|
|
142
|
+
...ifDefined('log', log),
|
|
93
143
|
};
|
|
94
144
|
|
|
95
145
|
this.core = createRuntimeCore(coreOptions);
|
|
@@ -100,27 +150,27 @@ class SqlRuntimeImpl<TContract extends SqlContract<SqlStorage> = SqlContract<Sql
|
|
|
100
150
|
}
|
|
101
151
|
}
|
|
102
152
|
|
|
103
|
-
private ensureCodecRegistryValidated(contract:
|
|
153
|
+
private ensureCodecRegistryValidated(contract: Contract<SqlStorage>): void {
|
|
104
154
|
if (!this.codecRegistryValidated) {
|
|
105
155
|
validateCodecRegistryCompleteness(this.codecRegistry, contract);
|
|
106
156
|
this.codecRegistryValidated = true;
|
|
107
157
|
}
|
|
108
158
|
}
|
|
109
159
|
|
|
110
|
-
|
|
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)
|
|
160
|
+
private toExecutionPlan<Row>(plan: ExecutionPlan<Row> | SqlQueryPlan<Row>): ExecutionPlan<Row> {
|
|
116
161
|
const isSqlQueryPlan = (p: ExecutionPlan<Row> | SqlQueryPlan<Row>): p is SqlQueryPlan<Row> => {
|
|
117
162
|
return 'ast' in p && !('sql' in p);
|
|
118
163
|
};
|
|
119
164
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
165
|
+
return isSqlQueryPlan(plan) ? lowerSqlPlan(this.adapter, this.contract, plan) : plan;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private executeAgainstQueryable<Row = Record<string, unknown>>(
|
|
169
|
+
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
170
|
+
queryable: CoreQueryable,
|
|
171
|
+
): AsyncIterableResult<Row> {
|
|
172
|
+
this.ensureCodecRegistryValidated(this.contract);
|
|
173
|
+
const executablePlan = this.toExecutionPlan(plan);
|
|
124
174
|
|
|
125
175
|
const iterator = async function* (
|
|
126
176
|
self: SqlRuntimeImpl<TContract>,
|
|
@@ -131,13 +181,14 @@ class SqlRuntimeImpl<TContract extends SqlContract<SqlStorage> = SqlContract<Sql
|
|
|
131
181
|
params: encodedParams,
|
|
132
182
|
};
|
|
133
183
|
|
|
134
|
-
const coreIterator =
|
|
184
|
+
const coreIterator = queryable.execute(planWithEncodedParams);
|
|
135
185
|
|
|
136
186
|
for await (const rawRow of coreIterator) {
|
|
137
187
|
const decodedRow = decodeRow(
|
|
138
188
|
rawRow as Record<string, unknown>,
|
|
139
189
|
executablePlan,
|
|
140
190
|
self.codecRegistry,
|
|
191
|
+
self.jsonSchemaValidators,
|
|
141
192
|
);
|
|
142
193
|
yield decodedRow as Row;
|
|
143
194
|
}
|
|
@@ -146,12 +197,40 @@ class SqlRuntimeImpl<TContract extends SqlContract<SqlStorage> = SqlContract<Sql
|
|
|
146
197
|
return new AsyncIterableResult(iterator(this));
|
|
147
198
|
}
|
|
148
199
|
|
|
149
|
-
|
|
150
|
-
|
|
200
|
+
execute<Row = Record<string, unknown>>(
|
|
201
|
+
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
202
|
+
): AsyncIterableResult<Row> {
|
|
203
|
+
return this.executeAgainstQueryable(plan, this.core);
|
|
151
204
|
}
|
|
152
205
|
|
|
153
|
-
|
|
154
|
-
|
|
206
|
+
async connection(): Promise<RuntimeConnection> {
|
|
207
|
+
const coreConn = await this.core.connection();
|
|
208
|
+
const self = this;
|
|
209
|
+
const wrappedConnection: RuntimeConnection = {
|
|
210
|
+
async transaction(): Promise<RuntimeTransaction> {
|
|
211
|
+
const coreTx = await coreConn.transaction();
|
|
212
|
+
return {
|
|
213
|
+
commit: coreTx.commit.bind(coreTx),
|
|
214
|
+
rollback: coreTx.rollback.bind(coreTx),
|
|
215
|
+
execute<Row = Record<string, unknown>>(
|
|
216
|
+
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
217
|
+
): AsyncIterableResult<Row> {
|
|
218
|
+
return self.executeAgainstQueryable(plan, coreTx);
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
release: coreConn.release.bind(coreConn),
|
|
223
|
+
execute<Row = Record<string, unknown>>(
|
|
224
|
+
plan: ExecutionPlan<Row> | SqlQueryPlan<Row>,
|
|
225
|
+
): AsyncIterableResult<Row> {
|
|
226
|
+
return self.executeAgainstQueryable(plan, coreConn);
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
return wrappedConnection;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
telemetry(): RuntimeTelemetryEvent | null {
|
|
233
|
+
return this.core.telemetry();
|
|
155
234
|
}
|
|
156
235
|
|
|
157
236
|
close(): Promise<void> {
|
|
@@ -159,8 +238,18 @@ class SqlRuntimeImpl<TContract extends SqlContract<SqlStorage> = SqlContract<Sql
|
|
|
159
238
|
}
|
|
160
239
|
}
|
|
161
240
|
|
|
162
|
-
export function createRuntime<TContract extends
|
|
163
|
-
options:
|
|
241
|
+
export function createRuntime<TContract extends Contract<SqlStorage>, TTargetId extends string>(
|
|
242
|
+
options: CreateRuntimeOptions<TContract, TTargetId>,
|
|
164
243
|
): Runtime {
|
|
165
|
-
|
|
244
|
+
const { stackInstance, context, driver, verify, plugins, mode, log } = options;
|
|
245
|
+
|
|
246
|
+
return new SqlRuntimeImpl({
|
|
247
|
+
context,
|
|
248
|
+
adapter: stackInstance.adapter,
|
|
249
|
+
driver,
|
|
250
|
+
verify,
|
|
251
|
+
...ifDefined('plugins', plugins),
|
|
252
|
+
...ifDefined('mode', mode),
|
|
253
|
+
...ifDefined('log', log),
|
|
254
|
+
});
|
|
166
255
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import { instantiateExecutionStack } from '@prisma-next/framework-components/execution';
|
|
2
3
|
import type { AsyncIterableResult } from '@prisma-next/runtime-executor';
|
|
3
4
|
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import type { Runtime } from '../src/exports';
|
|
6
|
+
import { createRuntime, createSqlExecutionStack } from '../src/exports';
|
|
7
|
+
import {
|
|
8
|
+
createStubAdapter,
|
|
9
|
+
createTestAdapterDescriptor,
|
|
10
|
+
createTestContext,
|
|
11
|
+
createTestContract,
|
|
12
|
+
createTestTargetDescriptor,
|
|
13
|
+
} from './utils';
|
|
6
14
|
|
|
7
|
-
// Mock driver that implements SqlDriver interface
|
|
8
15
|
class MockDriver {
|
|
9
16
|
private rows: ReadonlyArray<Record<string, unknown>> = [];
|
|
10
17
|
|
|
@@ -12,11 +19,10 @@ class MockDriver {
|
|
|
12
19
|
this.rows = rows;
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
async query(
|
|
22
|
+
async query<Row = Record<string, unknown>>(
|
|
16
23
|
_sql: string,
|
|
17
|
-
_params
|
|
18
|
-
): Promise<{ rows: ReadonlyArray<
|
|
19
|
-
// Return empty marker result for contract verification
|
|
24
|
+
_params?: readonly unknown[],
|
|
25
|
+
): Promise<{ rows: ReadonlyArray<Row> }> {
|
|
20
26
|
return { rows: [] };
|
|
21
27
|
}
|
|
22
28
|
|
|
@@ -29,20 +35,19 @@ class MockDriver {
|
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
async
|
|
33
|
-
|
|
38
|
+
async acquireConnection(): Promise<never> {
|
|
39
|
+
throw new Error('Not implemented in mock');
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
async
|
|
37
|
-
|
|
38
|
-
}
|
|
42
|
+
async connect(): Promise<void> {}
|
|
43
|
+
|
|
44
|
+
async close(): Promise<void> {}
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
const fixtureContract = createTestContract({
|
|
42
|
-
schemaVersion: '1',
|
|
43
48
|
targetFamily: 'sql',
|
|
44
49
|
target: 'postgres',
|
|
45
|
-
|
|
50
|
+
storageHash: 'test-hash',
|
|
46
51
|
profileHash: 'test-profile-hash',
|
|
47
52
|
storage: {
|
|
48
53
|
tables: {
|
|
@@ -58,24 +63,33 @@ const fixtureContract = createTestContract({
|
|
|
58
63
|
},
|
|
59
64
|
},
|
|
60
65
|
models: {},
|
|
61
|
-
relations: {},
|
|
62
|
-
mappings: { codecTypes: {}, operationTypes: {} },
|
|
63
66
|
});
|
|
64
67
|
|
|
68
|
+
function createTestRuntime(mockDriver: MockDriver): Runtime {
|
|
69
|
+
const adapter = createStubAdapter();
|
|
70
|
+
const stack = createSqlExecutionStack({
|
|
71
|
+
target: createTestTargetDescriptor(),
|
|
72
|
+
adapter: createTestAdapterDescriptor(adapter),
|
|
73
|
+
extensionPacks: [],
|
|
74
|
+
});
|
|
75
|
+
const stackInstance = instantiateExecutionStack(stack);
|
|
76
|
+
const context = createTestContext(fixtureContract, adapter);
|
|
77
|
+
return createRuntime({
|
|
78
|
+
stackInstance,
|
|
79
|
+
context,
|
|
80
|
+
driver: mockDriver,
|
|
81
|
+
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
65
85
|
describe('SqlRuntime AsyncIterableResult integration', () => {
|
|
66
86
|
it('returns AsyncIterableResult from execute', async () => {
|
|
67
|
-
const adapter = createStubAdapter();
|
|
68
87
|
const driver = new MockDriver();
|
|
69
88
|
driver.setRows([
|
|
70
89
|
{ id: 1, email: 'test1@example.com' },
|
|
71
90
|
{ id: 2, email: 'test2@example.com' },
|
|
72
91
|
]);
|
|
73
|
-
const
|
|
74
|
-
const runtime = createRuntime({
|
|
75
|
-
driver: driver as unknown as Parameters<typeof createRuntime>[0]['driver'],
|
|
76
|
-
context,
|
|
77
|
-
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
78
|
-
});
|
|
92
|
+
const runtime = createTestRuntime(driver);
|
|
79
93
|
|
|
80
94
|
const plan: ExecutionPlan<{ id: number; email: string }> = {
|
|
81
95
|
sql: 'SELECT id, email FROM "user" ORDER BY id',
|
|
@@ -83,7 +97,7 @@ describe('SqlRuntime AsyncIterableResult integration', () => {
|
|
|
83
97
|
meta: {
|
|
84
98
|
target: 'postgres',
|
|
85
99
|
targetFamily: 'sql',
|
|
86
|
-
|
|
100
|
+
storageHash: 'test-hash',
|
|
87
101
|
lane: 'sql',
|
|
88
102
|
paramDescriptors: [],
|
|
89
103
|
},
|
|
@@ -91,7 +105,6 @@ describe('SqlRuntime AsyncIterableResult integration', () => {
|
|
|
91
105
|
|
|
92
106
|
const result = runtime.execute(plan);
|
|
93
107
|
|
|
94
|
-
// Verify it's an AsyncIterableResult
|
|
95
108
|
expect(result).toBeInstanceOf(Object);
|
|
96
109
|
expect(typeof result.toArray).toBe('function');
|
|
97
110
|
expect(typeof result[Symbol.asyncIterator]).toBe('function');
|
|
@@ -100,15 +113,9 @@ describe('SqlRuntime AsyncIterableResult integration', () => {
|
|
|
100
113
|
});
|
|
101
114
|
|
|
102
115
|
it('preserves type information', async () => {
|
|
103
|
-
const adapter = createStubAdapter();
|
|
104
116
|
const driver = new MockDriver();
|
|
105
117
|
driver.setRows([{ id: 1, email: 'test@example.com' }]);
|
|
106
|
-
const
|
|
107
|
-
const runtime = createRuntime({
|
|
108
|
-
driver: driver as unknown as Parameters<typeof createRuntime>[0]['driver'],
|
|
109
|
-
context,
|
|
110
|
-
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
111
|
-
});
|
|
118
|
+
const runtime = createTestRuntime(driver);
|
|
112
119
|
|
|
113
120
|
const plan: ExecutionPlan<{ id: number; email: string }> = {
|
|
114
121
|
sql: 'SELECT id, email FROM "user" LIMIT 1',
|
|
@@ -116,7 +123,7 @@ describe('SqlRuntime AsyncIterableResult integration', () => {
|
|
|
116
123
|
meta: {
|
|
117
124
|
target: 'postgres',
|
|
118
125
|
targetFamily: 'sql',
|
|
119
|
-
|
|
126
|
+
storageHash: 'test-hash',
|
|
120
127
|
lane: 'sql',
|
|
121
128
|
paramDescriptors: [],
|
|
122
129
|
},
|
|
@@ -126,10 +133,8 @@ describe('SqlRuntime AsyncIterableResult integration', () => {
|
|
|
126
133
|
const rows = await result.toArray();
|
|
127
134
|
|
|
128
135
|
expect(rows.length).toBe(1);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
expect(typeof rows[0].email).toBe('string');
|
|
132
|
-
}
|
|
136
|
+
expect(typeof rows[0]!.id).toBe('number');
|
|
137
|
+
expect(typeof rows[0]!.email).toBe('string');
|
|
133
138
|
|
|
134
139
|
await runtime.close();
|
|
135
140
|
});
|