@prisma/param-graph 0.0.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/README.md +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +36 -0
- package/dist/index.mjs +8 -0
- package/dist/param-graph.d.ts +171 -0
- package/dist/param-graph.js +103 -0
- package/dist/param-graph.mjs +75 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @prisma/param-graph
|
|
2
|
+
|
|
3
|
+
This package is intended for Prisma's internal use.
|
|
4
|
+
|
|
5
|
+
Contains the ParamGraph types and utilities for schema-aware query parameterization in Prisma Client.
|
|
6
|
+
|
|
7
|
+
ParamGraph is a compact data structure generated from DMMF (Data Model Metadata Format) at client generation time. It enables precise, schema-driven parameterization of query values at runtime.
|
|
8
|
+
|
|
9
|
+
## Contents
|
|
10
|
+
|
|
11
|
+
- `ParamGraph` - The main type representing the compact schema
|
|
12
|
+
- `InputNode` / `OutputNode` - Node types for input arguments and output selections
|
|
13
|
+
- `InputEdge` / `OutputEdge` - Edge types describing field capabilities
|
|
14
|
+
- `EdgeFlag` - Bit flags for input field capabilities
|
|
15
|
+
- `ScalarMask` - Bit mask for scalar type categories
|
|
16
|
+
- `scalarTypeToMask` - Maps DMMF scalar type names to mask values
|
|
17
|
+
- `hasFlag` / `getScalarMask` - Helper functions for edge inspection
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
EdgeFlag: () => import_param_graph.EdgeFlag,
|
|
22
|
+
ScalarMask: () => import_param_graph.ScalarMask,
|
|
23
|
+
getScalarMask: () => import_param_graph.getScalarMask,
|
|
24
|
+
hasFlag: () => import_param_graph.hasFlag,
|
|
25
|
+
scalarTypeToMask: () => import_param_graph.scalarTypeToMask
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_param_graph = require("./param-graph");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
EdgeFlag,
|
|
32
|
+
ScalarMask,
|
|
33
|
+
getScalarMask,
|
|
34
|
+
hasFlag,
|
|
35
|
+
scalarTypeToMask
|
|
36
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ParamGraph: Compact schema for runtime parameterization.
|
|
3
|
+
*
|
|
4
|
+
* This data structure is generated from DMMF at client generation time
|
|
5
|
+
* and embedded in the generated client. It enables schema-aware
|
|
6
|
+
* parameterization where values are only parameterized when both schema
|
|
7
|
+
* rules and runtime value types agree.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Compact schema embedded in the generated client.
|
|
11
|
+
*/
|
|
12
|
+
export type ParamGraph = {
|
|
13
|
+
/**
|
|
14
|
+
* String table to avoid repeating field names.
|
|
15
|
+
* Field names are referenced by index throughout the graph.
|
|
16
|
+
*/
|
|
17
|
+
s: string[];
|
|
18
|
+
/**
|
|
19
|
+
* User enum names for runtime membership checks.
|
|
20
|
+
* Values are looked up via `runtimeDataModel.enums[enumName].values`.
|
|
21
|
+
*/
|
|
22
|
+
en: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Input nodes used for argument objects and input types.
|
|
25
|
+
* Each node describes which fields are parameterizable or lead to
|
|
26
|
+
* parameterizable descendants.
|
|
27
|
+
*/
|
|
28
|
+
i: InputNode[];
|
|
29
|
+
/**
|
|
30
|
+
* Output nodes used for selection traversal.
|
|
31
|
+
* Each node describes which fields have arguments or lead to
|
|
32
|
+
* nested selections with arguments.
|
|
33
|
+
*/
|
|
34
|
+
o: OutputNode[];
|
|
35
|
+
/**
|
|
36
|
+
* Root mapping: "Model.action" or "action" (for non-model ops).
|
|
37
|
+
* Points to the args node (input) and root output node.
|
|
38
|
+
*/
|
|
39
|
+
r: Record<string, RootEntry>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Entry point for a root operation.
|
|
43
|
+
*/
|
|
44
|
+
export type RootEntry = {
|
|
45
|
+
/** Args node id (into `i` array) */
|
|
46
|
+
a?: NodeId;
|
|
47
|
+
/** Output node id (into `o` array) */
|
|
48
|
+
o?: NodeId;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Node ID is an index into `i` or `o` array.
|
|
52
|
+
*/
|
|
53
|
+
export type NodeId = number;
|
|
54
|
+
/**
|
|
55
|
+
* Input node: describes parameterizable fields in an input object.
|
|
56
|
+
* Only fields that are parameterizable or lead to parameterizable
|
|
57
|
+
* descendants are present.
|
|
58
|
+
*/
|
|
59
|
+
export type InputNode = {
|
|
60
|
+
/**
|
|
61
|
+
* Map from string-table index to edge descriptor.
|
|
62
|
+
* Omitted if the node has no fields (shouldn't happen in practice).
|
|
63
|
+
*/
|
|
64
|
+
f?: Record<number, InputEdge>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Output node: describes fields in a selection set that have args
|
|
68
|
+
* or nested selections that may contain parameterizable args.
|
|
69
|
+
*/
|
|
70
|
+
export type OutputNode = {
|
|
71
|
+
/**
|
|
72
|
+
* Map from string-table index to edge descriptor.
|
|
73
|
+
*/
|
|
74
|
+
f?: Record<number, OutputEdge>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Edge descriptor for input fields.
|
|
78
|
+
* Encodes what kinds of values the field accepts and how to handle them.
|
|
79
|
+
*/
|
|
80
|
+
export type InputEdge = {
|
|
81
|
+
/**
|
|
82
|
+
* Bit flags describing field capabilities.
|
|
83
|
+
* See EdgeFlag enum below.
|
|
84
|
+
*/
|
|
85
|
+
k: number;
|
|
86
|
+
/**
|
|
87
|
+
* Child input node id (for object values or list of objects).
|
|
88
|
+
* Present when the field accepts input object types.
|
|
89
|
+
*/
|
|
90
|
+
c?: NodeId;
|
|
91
|
+
/**
|
|
92
|
+
* Scalar type mask for allowed scalar categories.
|
|
93
|
+
* Present when field accepts scalar values.
|
|
94
|
+
* See ScalarMask enum below.
|
|
95
|
+
*/
|
|
96
|
+
m?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Enum name id (index into `en` array).
|
|
99
|
+
* Present when field accepts a user enum without a plain String scalar.
|
|
100
|
+
* Used for runtime membership validation.
|
|
101
|
+
*/
|
|
102
|
+
e?: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Edge descriptor for output fields.
|
|
106
|
+
*/
|
|
107
|
+
export type OutputEdge = {
|
|
108
|
+
/** Args node for this field (if it accepts arguments) */
|
|
109
|
+
a?: NodeId;
|
|
110
|
+
/** Next output node for nested selection traversal */
|
|
111
|
+
o?: NodeId;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Bit flags for InputEdge.k describing what the field accepts.
|
|
115
|
+
*/
|
|
116
|
+
export declare const EdgeFlag: {
|
|
117
|
+
/**
|
|
118
|
+
* Field may be parameterized as a scalar value.
|
|
119
|
+
* Check ScalarMask to validate the value type.
|
|
120
|
+
*/
|
|
121
|
+
readonly ParamScalar: 1;
|
|
122
|
+
/**
|
|
123
|
+
* Field accepts list-of-scalar values.
|
|
124
|
+
* Parameterize the whole list if all elements match ScalarMask.
|
|
125
|
+
*/
|
|
126
|
+
readonly ListScalar: 2;
|
|
127
|
+
/**
|
|
128
|
+
* Field accepts list-of-object values.
|
|
129
|
+
* Recurse into each element using the child node.
|
|
130
|
+
*/
|
|
131
|
+
readonly ListObject: 4;
|
|
132
|
+
/**
|
|
133
|
+
* Field accepts object values.
|
|
134
|
+
* Recurse into child input node.
|
|
135
|
+
*/
|
|
136
|
+
readonly Object: 8;
|
|
137
|
+
/**
|
|
138
|
+
* Field accepts null as a valid value.
|
|
139
|
+
* Note: Null values are NEVER parameterized at runtime regardless of this flag.
|
|
140
|
+
* This flag is informational only (reflects isNullable from DMMF).
|
|
141
|
+
*/
|
|
142
|
+
readonly Nullable: 16;
|
|
143
|
+
};
|
|
144
|
+
export type EdgeFlagValue = (typeof EdgeFlag)[keyof typeof EdgeFlag];
|
|
145
|
+
/**
|
|
146
|
+
* Bit mask for scalar type categories.
|
|
147
|
+
* Used in InputEdge.m to validate runtime value types.
|
|
148
|
+
*/
|
|
149
|
+
export declare const ScalarMask: {
|
|
150
|
+
readonly String: 1;
|
|
151
|
+
readonly Number: 2;
|
|
152
|
+
readonly Boolean: 4;
|
|
153
|
+
readonly DateTime: 8;
|
|
154
|
+
readonly Decimal: 16;
|
|
155
|
+
readonly BigInt: 32;
|
|
156
|
+
readonly Bytes: 64;
|
|
157
|
+
readonly Json: 128;
|
|
158
|
+
};
|
|
159
|
+
export type ScalarMaskValue = (typeof ScalarMask)[keyof typeof ScalarMask];
|
|
160
|
+
/**
|
|
161
|
+
* Helper function to check if an edge has a specific flag.
|
|
162
|
+
*/
|
|
163
|
+
export declare function hasFlag(edge: InputEdge, flag: number): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Helper function to get the scalar mask from an edge.
|
|
166
|
+
*/
|
|
167
|
+
export declare function getScalarMask(edge: InputEdge): number;
|
|
168
|
+
/**
|
|
169
|
+
* Maps DMMF scalar type names to ScalarMask values.
|
|
170
|
+
*/
|
|
171
|
+
export declare function scalarTypeToMask(typeName: string): number;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var param_graph_exports = {};
|
|
20
|
+
__export(param_graph_exports, {
|
|
21
|
+
EdgeFlag: () => EdgeFlag,
|
|
22
|
+
ScalarMask: () => ScalarMask,
|
|
23
|
+
getScalarMask: () => getScalarMask,
|
|
24
|
+
hasFlag: () => hasFlag,
|
|
25
|
+
scalarTypeToMask: () => scalarTypeToMask
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(param_graph_exports);
|
|
28
|
+
const EdgeFlag = {
|
|
29
|
+
/**
|
|
30
|
+
* Field may be parameterized as a scalar value.
|
|
31
|
+
* Check ScalarMask to validate the value type.
|
|
32
|
+
*/
|
|
33
|
+
ParamScalar: 1,
|
|
34
|
+
/**
|
|
35
|
+
* Field accepts list-of-scalar values.
|
|
36
|
+
* Parameterize the whole list if all elements match ScalarMask.
|
|
37
|
+
*/
|
|
38
|
+
ListScalar: 2,
|
|
39
|
+
/**
|
|
40
|
+
* Field accepts list-of-object values.
|
|
41
|
+
* Recurse into each element using the child node.
|
|
42
|
+
*/
|
|
43
|
+
ListObject: 4,
|
|
44
|
+
/**
|
|
45
|
+
* Field accepts object values.
|
|
46
|
+
* Recurse into child input node.
|
|
47
|
+
*/
|
|
48
|
+
Object: 8,
|
|
49
|
+
/**
|
|
50
|
+
* Field accepts null as a valid value.
|
|
51
|
+
* Note: Null values are NEVER parameterized at runtime regardless of this flag.
|
|
52
|
+
* This flag is informational only (reflects isNullable from DMMF).
|
|
53
|
+
*/
|
|
54
|
+
Nullable: 16
|
|
55
|
+
};
|
|
56
|
+
const ScalarMask = {
|
|
57
|
+
String: 1,
|
|
58
|
+
Number: 2,
|
|
59
|
+
// Int, Float
|
|
60
|
+
Boolean: 4,
|
|
61
|
+
DateTime: 8,
|
|
62
|
+
Decimal: 16,
|
|
63
|
+
BigInt: 32,
|
|
64
|
+
Bytes: 64,
|
|
65
|
+
Json: 128
|
|
66
|
+
};
|
|
67
|
+
function hasFlag(edge, flag) {
|
|
68
|
+
return (edge.k & flag) !== 0;
|
|
69
|
+
}
|
|
70
|
+
function getScalarMask(edge) {
|
|
71
|
+
return edge.m ?? 0;
|
|
72
|
+
}
|
|
73
|
+
function scalarTypeToMask(typeName) {
|
|
74
|
+
switch (typeName) {
|
|
75
|
+
case "String":
|
|
76
|
+
return ScalarMask.String;
|
|
77
|
+
case "Int":
|
|
78
|
+
case "Float":
|
|
79
|
+
return ScalarMask.Number;
|
|
80
|
+
case "Boolean":
|
|
81
|
+
return ScalarMask.Boolean;
|
|
82
|
+
case "DateTime":
|
|
83
|
+
return ScalarMask.DateTime;
|
|
84
|
+
case "Decimal":
|
|
85
|
+
return ScalarMask.Decimal;
|
|
86
|
+
case "BigInt":
|
|
87
|
+
return ScalarMask.BigInt;
|
|
88
|
+
case "Bytes":
|
|
89
|
+
return ScalarMask.Bytes;
|
|
90
|
+
case "Json":
|
|
91
|
+
return ScalarMask.Json;
|
|
92
|
+
default:
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
EdgeFlag,
|
|
99
|
+
ScalarMask,
|
|
100
|
+
getScalarMask,
|
|
101
|
+
hasFlag,
|
|
102
|
+
scalarTypeToMask
|
|
103
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const EdgeFlag = {
|
|
2
|
+
/**
|
|
3
|
+
* Field may be parameterized as a scalar value.
|
|
4
|
+
* Check ScalarMask to validate the value type.
|
|
5
|
+
*/
|
|
6
|
+
ParamScalar: 1,
|
|
7
|
+
/**
|
|
8
|
+
* Field accepts list-of-scalar values.
|
|
9
|
+
* Parameterize the whole list if all elements match ScalarMask.
|
|
10
|
+
*/
|
|
11
|
+
ListScalar: 2,
|
|
12
|
+
/**
|
|
13
|
+
* Field accepts list-of-object values.
|
|
14
|
+
* Recurse into each element using the child node.
|
|
15
|
+
*/
|
|
16
|
+
ListObject: 4,
|
|
17
|
+
/**
|
|
18
|
+
* Field accepts object values.
|
|
19
|
+
* Recurse into child input node.
|
|
20
|
+
*/
|
|
21
|
+
Object: 8,
|
|
22
|
+
/**
|
|
23
|
+
* Field accepts null as a valid value.
|
|
24
|
+
* Note: Null values are NEVER parameterized at runtime regardless of this flag.
|
|
25
|
+
* This flag is informational only (reflects isNullable from DMMF).
|
|
26
|
+
*/
|
|
27
|
+
Nullable: 16
|
|
28
|
+
};
|
|
29
|
+
const ScalarMask = {
|
|
30
|
+
String: 1,
|
|
31
|
+
Number: 2,
|
|
32
|
+
// Int, Float
|
|
33
|
+
Boolean: 4,
|
|
34
|
+
DateTime: 8,
|
|
35
|
+
Decimal: 16,
|
|
36
|
+
BigInt: 32,
|
|
37
|
+
Bytes: 64,
|
|
38
|
+
Json: 128
|
|
39
|
+
};
|
|
40
|
+
function hasFlag(edge, flag) {
|
|
41
|
+
return (edge.k & flag) !== 0;
|
|
42
|
+
}
|
|
43
|
+
function getScalarMask(edge) {
|
|
44
|
+
return edge.m ?? 0;
|
|
45
|
+
}
|
|
46
|
+
function scalarTypeToMask(typeName) {
|
|
47
|
+
switch (typeName) {
|
|
48
|
+
case "String":
|
|
49
|
+
return ScalarMask.String;
|
|
50
|
+
case "Int":
|
|
51
|
+
case "Float":
|
|
52
|
+
return ScalarMask.Number;
|
|
53
|
+
case "Boolean":
|
|
54
|
+
return ScalarMask.Boolean;
|
|
55
|
+
case "DateTime":
|
|
56
|
+
return ScalarMask.DateTime;
|
|
57
|
+
case "Decimal":
|
|
58
|
+
return ScalarMask.Decimal;
|
|
59
|
+
case "BigInt":
|
|
60
|
+
return ScalarMask.BigInt;
|
|
61
|
+
case "Bytes":
|
|
62
|
+
return ScalarMask.Bytes;
|
|
63
|
+
case "Json":
|
|
64
|
+
return ScalarMask.Json;
|
|
65
|
+
default:
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
EdgeFlag,
|
|
71
|
+
ScalarMask,
|
|
72
|
+
getScalarMask,
|
|
73
|
+
hasFlag,
|
|
74
|
+
scalarTypeToMask
|
|
75
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prisma/param-graph",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "This package is intended for Prisma's internal use",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/prisma/prisma.git",
|
|
23
|
+
"directory": "packages/param-graph"
|
|
24
|
+
},
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "DEV=true tsx helpers/build.ts",
|
|
28
|
+
"build": "tsx helpers/build.ts",
|
|
29
|
+
"prepublishOnly": "pnpm run build"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"sideEffects": false
|
|
35
|
+
}
|