@prisma/param-graph 7.4.0-integration-parameterization.9 → 7.4.0-integration-parameterization.10
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/serialization.js +222 -246
- package/dist/serialization.mjs +222 -246
- package/package.json +1 -1
package/dist/serialization.js
CHANGED
|
@@ -22,6 +22,12 @@ __export(serialization_exports, {
|
|
|
22
22
|
serializeParamGraph: () => serializeParamGraph
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(serialization_exports);
|
|
25
|
+
function serializeParamGraph(data) {
|
|
26
|
+
return new Serializer(data).serialize();
|
|
27
|
+
}
|
|
28
|
+
function deserializeParamGraph(serialized) {
|
|
29
|
+
return new Deserializer(serialized).deserialize();
|
|
30
|
+
}
|
|
25
31
|
const FORMAT_COMPACT = 0;
|
|
26
32
|
const FORMAT_WIDE = 1;
|
|
27
33
|
const NONE_16 = 65535;
|
|
@@ -33,277 +39,247 @@ function encodeBase64url(bytes) {
|
|
|
33
39
|
function decodeBase64url(str) {
|
|
34
40
|
return Buffer.from(str, "base64url");
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
class Serializer {
|
|
43
|
+
#data;
|
|
44
|
+
#useWide;
|
|
45
|
+
#buffer;
|
|
46
|
+
#view;
|
|
47
|
+
#offset = 0;
|
|
48
|
+
#rootKeys;
|
|
49
|
+
constructor(data) {
|
|
50
|
+
this.#data = data;
|
|
51
|
+
this.#rootKeys = Object.keys(data.roots);
|
|
52
|
+
const maxIndex = Math.max(
|
|
53
|
+
data.strings.length,
|
|
54
|
+
data.inputNodes.length,
|
|
55
|
+
data.outputNodes.length,
|
|
56
|
+
this.#rootKeys.length
|
|
57
|
+
);
|
|
58
|
+
this.#useWide = maxIndex > MAX_COMPACT_INDEX;
|
|
59
|
+
const size = this.#calculateBufferSize();
|
|
60
|
+
this.#buffer = new ArrayBuffer(size);
|
|
61
|
+
this.#view = new DataView(this.#buffer);
|
|
62
|
+
}
|
|
63
|
+
serialize() {
|
|
64
|
+
this.#writeHeader();
|
|
65
|
+
this.#writeInputNodes();
|
|
66
|
+
this.#writeOutputNodes();
|
|
67
|
+
this.#writeRoots();
|
|
68
|
+
return {
|
|
69
|
+
strings: this.#data.strings,
|
|
70
|
+
graph: encodeBase64url(new Uint8Array(this.#buffer))
|
|
71
|
+
};
|
|
46
72
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const edgeCount = Object.keys(node.edges).length;
|
|
50
|
-
size += edgeCount * (useWide ? 12 : 6);
|
|
73
|
+
get #wordSize() {
|
|
74
|
+
return this.#useWide ? 4 : 2;
|
|
51
75
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const view = new DataView(buffer);
|
|
55
|
-
let offset = 0;
|
|
56
|
-
view.setUint8(offset++, useWide ? FORMAT_WIDE : FORMAT_COMPACT);
|
|
57
|
-
if (useWide) {
|
|
58
|
-
view.setUint32(offset, data.inputNodes.length, true);
|
|
59
|
-
offset += 4;
|
|
60
|
-
view.setUint32(offset, data.outputNodes.length, true);
|
|
61
|
-
offset += 4;
|
|
62
|
-
view.setUint32(offset, rootKeys.length, true);
|
|
63
|
-
offset += 4;
|
|
64
|
-
} else {
|
|
65
|
-
view.setUint16(offset, data.inputNodes.length, true);
|
|
66
|
-
offset += 2;
|
|
67
|
-
view.setUint16(offset, data.outputNodes.length, true);
|
|
68
|
-
offset += 2;
|
|
69
|
-
view.setUint16(offset, rootKeys.length, true);
|
|
70
|
-
offset += 2;
|
|
76
|
+
get #noneValue() {
|
|
77
|
+
return this.#useWide ? NONE_32 : NONE_16;
|
|
71
78
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
view.setUint32(offset, fieldIndices.length, true);
|
|
76
|
-
offset += 4;
|
|
79
|
+
#writeWord(value) {
|
|
80
|
+
if (this.#useWide) {
|
|
81
|
+
this.#view.setUint32(this.#offset, value, true);
|
|
77
82
|
} else {
|
|
78
|
-
view.setUint16(offset,
|
|
79
|
-
offset += 2;
|
|
83
|
+
this.#view.setUint16(this.#offset, value, true);
|
|
80
84
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
offset += 2;
|
|
105
|
-
view.setUint8(offset, edge.flags);
|
|
106
|
-
offset += 1;
|
|
107
|
-
offset += 1;
|
|
108
|
-
}
|
|
85
|
+
this.#offset += this.#wordSize;
|
|
86
|
+
}
|
|
87
|
+
#writeOptionalWord(value) {
|
|
88
|
+
this.#writeWord(value ?? this.#noneValue);
|
|
89
|
+
}
|
|
90
|
+
#writeByte(value) {
|
|
91
|
+
this.#view.setUint8(this.#offset, value);
|
|
92
|
+
this.#offset += 1;
|
|
93
|
+
}
|
|
94
|
+
#writeU16(value) {
|
|
95
|
+
this.#view.setUint16(this.#offset, value, true);
|
|
96
|
+
this.#offset += 2;
|
|
97
|
+
}
|
|
98
|
+
#skip(bytes) {
|
|
99
|
+
this.#offset += bytes;
|
|
100
|
+
}
|
|
101
|
+
#calculateBufferSize() {
|
|
102
|
+
let size = 1;
|
|
103
|
+
size += this.#useWide ? 12 : 6;
|
|
104
|
+
for (const node of this.#data.inputNodes) {
|
|
105
|
+
size += this.#wordSize;
|
|
106
|
+
const edgeCount = Object.keys(node.edges).length;
|
|
107
|
+
size += edgeCount * (this.#useWide ? 20 : 10);
|
|
109
108
|
}
|
|
109
|
+
for (const node of this.#data.outputNodes) {
|
|
110
|
+
size += this.#wordSize;
|
|
111
|
+
const edgeCount = Object.keys(node.edges).length;
|
|
112
|
+
size += edgeCount * (this.#useWide ? 12 : 6);
|
|
113
|
+
}
|
|
114
|
+
size += this.#rootKeys.length * (this.#useWide ? 12 : 6);
|
|
115
|
+
return size;
|
|
110
116
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
#writeHeader() {
|
|
118
|
+
this.#writeByte(this.#useWide ? FORMAT_WIDE : FORMAT_COMPACT);
|
|
119
|
+
this.#writeWord(this.#data.inputNodes.length);
|
|
120
|
+
this.#writeWord(this.#data.outputNodes.length);
|
|
121
|
+
this.#writeWord(this.#rootKeys.length);
|
|
122
|
+
}
|
|
123
|
+
#writeInputNodes() {
|
|
124
|
+
for (const node of this.#data.inputNodes) {
|
|
125
|
+
const fieldIndices = Object.keys(node.edges).map(Number);
|
|
126
|
+
this.#writeWord(fieldIndices.length);
|
|
127
|
+
for (const fieldIndex of fieldIndices) {
|
|
128
|
+
const edge = node.edges[fieldIndex];
|
|
129
|
+
this.#writeWord(fieldIndex);
|
|
130
|
+
this.#writeU16(edge.scalarMask ?? 0);
|
|
131
|
+
if (this.#useWide) {
|
|
132
|
+
this.#skip(2);
|
|
133
|
+
}
|
|
134
|
+
this.#writeOptionalWord(edge.childNodeId);
|
|
135
|
+
this.#writeOptionalWord(edge.enumNameIndex);
|
|
136
|
+
this.#writeByte(edge.flags);
|
|
137
|
+
this.#skip(this.#useWide ? 3 : 1);
|
|
138
|
+
}
|
|
119
139
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
view.setUint16(offset, fieldIndex, true);
|
|
131
|
-
offset += 2;
|
|
132
|
-
view.setUint16(offset, edge.argsNodeId ?? NONE_16, true);
|
|
133
|
-
offset += 2;
|
|
134
|
-
view.setUint16(offset, edge.outputNodeId ?? NONE_16, true);
|
|
135
|
-
offset += 2;
|
|
140
|
+
}
|
|
141
|
+
#writeOutputNodes() {
|
|
142
|
+
for (const node of this.#data.outputNodes) {
|
|
143
|
+
const fieldIndices = Object.keys(node.edges).map(Number);
|
|
144
|
+
this.#writeWord(fieldIndices.length);
|
|
145
|
+
for (const fieldIndex of fieldIndices) {
|
|
146
|
+
const edge = node.edges[fieldIndex];
|
|
147
|
+
this.#writeWord(fieldIndex);
|
|
148
|
+
this.#writeOptionalWord(edge.argsNodeId);
|
|
149
|
+
this.#writeOptionalWord(edge.outputNodeId);
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
offset += 4;
|
|
147
|
-
view.setUint32(offset, root.outputNodeId ?? NONE_32, true);
|
|
148
|
-
offset += 4;
|
|
149
|
-
} else {
|
|
150
|
-
view.setUint16(offset, keyIndex, true);
|
|
151
|
-
offset += 2;
|
|
152
|
-
view.setUint16(offset, root.argsNodeId ?? NONE_16, true);
|
|
153
|
-
offset += 2;
|
|
154
|
-
view.setUint16(offset, root.outputNodeId ?? NONE_16, true);
|
|
155
|
-
offset += 2;
|
|
153
|
+
#writeRoots() {
|
|
154
|
+
for (const key of this.#rootKeys) {
|
|
155
|
+
const root = this.#data.roots[key];
|
|
156
|
+
const keyIndex = this.#data.strings.indexOf(key);
|
|
157
|
+
this.#writeWord(keyIndex);
|
|
158
|
+
this.#writeOptionalWord(root.argsNodeId);
|
|
159
|
+
this.#writeOptionalWord(root.outputNodeId);
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
|
-
return {
|
|
159
|
-
strings: data.strings,
|
|
160
|
-
graph: encodeBase64url(new Uint8Array(buffer))
|
|
161
|
-
};
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
rootCount = view.getUint16(offset, true);
|
|
185
|
-
offset += 2;
|
|
163
|
+
class Deserializer {
|
|
164
|
+
#serialized;
|
|
165
|
+
#view;
|
|
166
|
+
#offset = 0;
|
|
167
|
+
#useWide = false;
|
|
168
|
+
constructor(serialized) {
|
|
169
|
+
this.#serialized = serialized;
|
|
170
|
+
const bytes = decodeBase64url(serialized.graph);
|
|
171
|
+
this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
172
|
+
}
|
|
173
|
+
deserialize() {
|
|
174
|
+
const { inputNodeCount, outputNodeCount, rootCount } = this.#readHeader();
|
|
175
|
+
const inputNodes = this.#readInputNodes(inputNodeCount);
|
|
176
|
+
const outputNodes = this.#readOutputNodes(outputNodeCount);
|
|
177
|
+
const roots = this.#readRoots(rootCount);
|
|
178
|
+
return {
|
|
179
|
+
strings: this.#serialized.strings,
|
|
180
|
+
inputNodes,
|
|
181
|
+
outputNodes,
|
|
182
|
+
roots
|
|
183
|
+
};
|
|
186
184
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
185
|
+
get #wordSize() {
|
|
186
|
+
return this.#useWide ? 4 : 2;
|
|
187
|
+
}
|
|
188
|
+
get #noneValue() {
|
|
189
|
+
return this.#useWide ? NONE_32 : NONE_16;
|
|
190
|
+
}
|
|
191
|
+
#readWord() {
|
|
192
|
+
let value;
|
|
193
|
+
if (this.#useWide) {
|
|
194
|
+
value = this.#view.getUint32(this.#offset, true);
|
|
193
195
|
} else {
|
|
194
|
-
|
|
195
|
-
offset += 2;
|
|
196
|
+
value = this.#view.getUint16(this.#offset, true);
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
198
|
+
this.#offset += this.#wordSize;
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
#readOptionalWord() {
|
|
202
|
+
const value = this.#readWord();
|
|
203
|
+
return value === this.#noneValue ? void 0 : value;
|
|
204
|
+
}
|
|
205
|
+
#readByte() {
|
|
206
|
+
const value = this.#view.getUint8(this.#offset);
|
|
207
|
+
this.#offset += 1;
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
#readU16() {
|
|
211
|
+
const value = this.#view.getUint16(this.#offset, true);
|
|
212
|
+
this.#offset += 2;
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
#skip(bytes) {
|
|
216
|
+
this.#offset += bytes;
|
|
217
|
+
}
|
|
218
|
+
#readHeader() {
|
|
219
|
+
const format = this.#readByte();
|
|
220
|
+
this.#useWide = format === FORMAT_WIDE;
|
|
221
|
+
const inputNodeCount = this.#readWord();
|
|
222
|
+
const outputNodeCount = this.#readWord();
|
|
223
|
+
const rootCount = this.#readWord();
|
|
224
|
+
return { inputNodeCount, outputNodeCount, rootCount };
|
|
225
|
+
}
|
|
226
|
+
#readInputNodes(count) {
|
|
227
|
+
const inputNodes = [];
|
|
228
|
+
for (let i = 0; i < count; i++) {
|
|
229
|
+
const edgeCount = this.#readWord();
|
|
230
|
+
const edges = {};
|
|
231
|
+
for (let j = 0; j < edgeCount; j++) {
|
|
232
|
+
const fieldIndex = this.#readWord();
|
|
233
|
+
const scalarMask = this.#readU16();
|
|
234
|
+
if (this.#useWide) {
|
|
235
|
+
this.#skip(2);
|
|
236
|
+
}
|
|
237
|
+
const childNodeId = this.#readOptionalWord();
|
|
238
|
+
const enumNameIndex = this.#readOptionalWord();
|
|
239
|
+
const flags = this.#readByte();
|
|
240
|
+
this.#skip(this.#useWide ? 3 : 1);
|
|
241
|
+
const edge = { flags };
|
|
242
|
+
if (scalarMask !== 0) edge.scalarMask = scalarMask;
|
|
243
|
+
if (childNodeId !== void 0) edge.childNodeId = childNodeId;
|
|
244
|
+
if (enumNameIndex !== void 0) edge.enumNameIndex = enumNameIndex;
|
|
245
|
+
edges[fieldIndex] = edge;
|
|
229
246
|
}
|
|
230
|
-
|
|
231
|
-
if (scalarMask !== 0) edge.scalarMask = scalarMask;
|
|
232
|
-
if (childNodeId !== (useWide ? NONE_32 : NONE_16)) edge.childNodeId = childNodeId;
|
|
233
|
-
if (enumNameIndex !== (useWide ? NONE_32 : NONE_16)) edge.enumNameIndex = enumNameIndex;
|
|
234
|
-
edges[fieldIndex] = edge;
|
|
247
|
+
inputNodes.push({ edges });
|
|
235
248
|
}
|
|
236
|
-
inputNodes
|
|
249
|
+
return inputNodes;
|
|
237
250
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
let
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
let argsNodeId;
|
|
252
|
-
let outputNodeId;
|
|
253
|
-
if (useWide) {
|
|
254
|
-
fieldIndex = view.getUint32(offset, true);
|
|
255
|
-
offset += 4;
|
|
256
|
-
argsNodeId = view.getUint32(offset, true);
|
|
257
|
-
offset += 4;
|
|
258
|
-
outputNodeId = view.getUint32(offset, true);
|
|
259
|
-
offset += 4;
|
|
260
|
-
} else {
|
|
261
|
-
fieldIndex = view.getUint16(offset, true);
|
|
262
|
-
offset += 2;
|
|
263
|
-
argsNodeId = view.getUint16(offset, true);
|
|
264
|
-
offset += 2;
|
|
265
|
-
outputNodeId = view.getUint16(offset, true);
|
|
266
|
-
offset += 2;
|
|
251
|
+
#readOutputNodes(count) {
|
|
252
|
+
const outputNodes = [];
|
|
253
|
+
for (let i = 0; i < count; i++) {
|
|
254
|
+
const edgeCount = this.#readWord();
|
|
255
|
+
const edges = {};
|
|
256
|
+
for (let j = 0; j < edgeCount; j++) {
|
|
257
|
+
const fieldIndex = this.#readWord();
|
|
258
|
+
const argsNodeId = this.#readOptionalWord();
|
|
259
|
+
const outputNodeId = this.#readOptionalWord();
|
|
260
|
+
const edge = {};
|
|
261
|
+
if (argsNodeId !== void 0) edge.argsNodeId = argsNodeId;
|
|
262
|
+
if (outputNodeId !== void 0) edge.outputNodeId = outputNodeId;
|
|
263
|
+
edges[fieldIndex] = edge;
|
|
267
264
|
}
|
|
268
|
-
|
|
269
|
-
if (argsNodeId !== (useWide ? NONE_32 : NONE_16)) edge.argsNodeId = argsNodeId;
|
|
270
|
-
if (outputNodeId !== (useWide ? NONE_32 : NONE_16)) edge.outputNodeId = outputNodeId;
|
|
271
|
-
edges[fieldIndex] = edge;
|
|
265
|
+
outputNodes.push({ edges });
|
|
272
266
|
}
|
|
273
|
-
outputNodes
|
|
267
|
+
return outputNodes;
|
|
274
268
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
let
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
argsNodeId
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
offset += 4;
|
|
287
|
-
} else {
|
|
288
|
-
keyIndex = view.getUint16(offset, true);
|
|
289
|
-
offset += 2;
|
|
290
|
-
argsNodeId = view.getUint16(offset, true);
|
|
291
|
-
offset += 2;
|
|
292
|
-
outputNodeId = view.getUint16(offset, true);
|
|
293
|
-
offset += 2;
|
|
269
|
+
#readRoots(count) {
|
|
270
|
+
const roots = {};
|
|
271
|
+
for (let i = 0; i < count; i++) {
|
|
272
|
+
const keyIndex = this.#readWord();
|
|
273
|
+
const argsNodeId = this.#readOptionalWord();
|
|
274
|
+
const outputNodeId = this.#readOptionalWord();
|
|
275
|
+
const key = this.#serialized.strings[keyIndex];
|
|
276
|
+
const root = {};
|
|
277
|
+
if (argsNodeId !== void 0) root.argsNodeId = argsNodeId;
|
|
278
|
+
if (outputNodeId !== void 0) root.outputNodeId = outputNodeId;
|
|
279
|
+
roots[key] = root;
|
|
294
280
|
}
|
|
295
|
-
|
|
296
|
-
const root = {};
|
|
297
|
-
if (argsNodeId !== (useWide ? NONE_32 : NONE_16)) root.argsNodeId = argsNodeId;
|
|
298
|
-
if (outputNodeId !== (useWide ? NONE_32 : NONE_16)) root.outputNodeId = outputNodeId;
|
|
299
|
-
roots[key] = root;
|
|
281
|
+
return roots;
|
|
300
282
|
}
|
|
301
|
-
return {
|
|
302
|
-
strings: serialized.strings,
|
|
303
|
-
inputNodes,
|
|
304
|
-
outputNodes,
|
|
305
|
-
roots
|
|
306
|
-
};
|
|
307
283
|
}
|
|
308
284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
309
285
|
0 && (module.exports = {
|
package/dist/serialization.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function serializeParamGraph(data) {
|
|
2
|
+
return new Serializer(data).serialize();
|
|
3
|
+
}
|
|
4
|
+
function deserializeParamGraph(serialized) {
|
|
5
|
+
return new Deserializer(serialized).deserialize();
|
|
6
|
+
}
|
|
1
7
|
const FORMAT_COMPACT = 0;
|
|
2
8
|
const FORMAT_WIDE = 1;
|
|
3
9
|
const NONE_16 = 65535;
|
|
@@ -9,277 +15,247 @@ function encodeBase64url(bytes) {
|
|
|
9
15
|
function decodeBase64url(str) {
|
|
10
16
|
return Buffer.from(str, "base64url");
|
|
11
17
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
class Serializer {
|
|
19
|
+
#data;
|
|
20
|
+
#useWide;
|
|
21
|
+
#buffer;
|
|
22
|
+
#view;
|
|
23
|
+
#offset = 0;
|
|
24
|
+
#rootKeys;
|
|
25
|
+
constructor(data) {
|
|
26
|
+
this.#data = data;
|
|
27
|
+
this.#rootKeys = Object.keys(data.roots);
|
|
28
|
+
const maxIndex = Math.max(
|
|
29
|
+
data.strings.length,
|
|
30
|
+
data.inputNodes.length,
|
|
31
|
+
data.outputNodes.length,
|
|
32
|
+
this.#rootKeys.length
|
|
33
|
+
);
|
|
34
|
+
this.#useWide = maxIndex > MAX_COMPACT_INDEX;
|
|
35
|
+
const size = this.#calculateBufferSize();
|
|
36
|
+
this.#buffer = new ArrayBuffer(size);
|
|
37
|
+
this.#view = new DataView(this.#buffer);
|
|
38
|
+
}
|
|
39
|
+
serialize() {
|
|
40
|
+
this.#writeHeader();
|
|
41
|
+
this.#writeInputNodes();
|
|
42
|
+
this.#writeOutputNodes();
|
|
43
|
+
this.#writeRoots();
|
|
44
|
+
return {
|
|
45
|
+
strings: this.#data.strings,
|
|
46
|
+
graph: encodeBase64url(new Uint8Array(this.#buffer))
|
|
47
|
+
};
|
|
22
48
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const edgeCount = Object.keys(node.edges).length;
|
|
26
|
-
size += edgeCount * (useWide ? 12 : 6);
|
|
49
|
+
get #wordSize() {
|
|
50
|
+
return this.#useWide ? 4 : 2;
|
|
27
51
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const view = new DataView(buffer);
|
|
31
|
-
let offset = 0;
|
|
32
|
-
view.setUint8(offset++, useWide ? FORMAT_WIDE : FORMAT_COMPACT);
|
|
33
|
-
if (useWide) {
|
|
34
|
-
view.setUint32(offset, data.inputNodes.length, true);
|
|
35
|
-
offset += 4;
|
|
36
|
-
view.setUint32(offset, data.outputNodes.length, true);
|
|
37
|
-
offset += 4;
|
|
38
|
-
view.setUint32(offset, rootKeys.length, true);
|
|
39
|
-
offset += 4;
|
|
40
|
-
} else {
|
|
41
|
-
view.setUint16(offset, data.inputNodes.length, true);
|
|
42
|
-
offset += 2;
|
|
43
|
-
view.setUint16(offset, data.outputNodes.length, true);
|
|
44
|
-
offset += 2;
|
|
45
|
-
view.setUint16(offset, rootKeys.length, true);
|
|
46
|
-
offset += 2;
|
|
52
|
+
get #noneValue() {
|
|
53
|
+
return this.#useWide ? NONE_32 : NONE_16;
|
|
47
54
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
view.setUint32(offset, fieldIndices.length, true);
|
|
52
|
-
offset += 4;
|
|
55
|
+
#writeWord(value) {
|
|
56
|
+
if (this.#useWide) {
|
|
57
|
+
this.#view.setUint32(this.#offset, value, true);
|
|
53
58
|
} else {
|
|
54
|
-
view.setUint16(offset,
|
|
55
|
-
offset += 2;
|
|
59
|
+
this.#view.setUint16(this.#offset, value, true);
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
offset += 2;
|
|
81
|
-
view.setUint8(offset, edge.flags);
|
|
82
|
-
offset += 1;
|
|
83
|
-
offset += 1;
|
|
84
|
-
}
|
|
61
|
+
this.#offset += this.#wordSize;
|
|
62
|
+
}
|
|
63
|
+
#writeOptionalWord(value) {
|
|
64
|
+
this.#writeWord(value ?? this.#noneValue);
|
|
65
|
+
}
|
|
66
|
+
#writeByte(value) {
|
|
67
|
+
this.#view.setUint8(this.#offset, value);
|
|
68
|
+
this.#offset += 1;
|
|
69
|
+
}
|
|
70
|
+
#writeU16(value) {
|
|
71
|
+
this.#view.setUint16(this.#offset, value, true);
|
|
72
|
+
this.#offset += 2;
|
|
73
|
+
}
|
|
74
|
+
#skip(bytes) {
|
|
75
|
+
this.#offset += bytes;
|
|
76
|
+
}
|
|
77
|
+
#calculateBufferSize() {
|
|
78
|
+
let size = 1;
|
|
79
|
+
size += this.#useWide ? 12 : 6;
|
|
80
|
+
for (const node of this.#data.inputNodes) {
|
|
81
|
+
size += this.#wordSize;
|
|
82
|
+
const edgeCount = Object.keys(node.edges).length;
|
|
83
|
+
size += edgeCount * (this.#useWide ? 20 : 10);
|
|
85
84
|
}
|
|
85
|
+
for (const node of this.#data.outputNodes) {
|
|
86
|
+
size += this.#wordSize;
|
|
87
|
+
const edgeCount = Object.keys(node.edges).length;
|
|
88
|
+
size += edgeCount * (this.#useWide ? 12 : 6);
|
|
89
|
+
}
|
|
90
|
+
size += this.#rootKeys.length * (this.#useWide ? 12 : 6);
|
|
91
|
+
return size;
|
|
86
92
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
#writeHeader() {
|
|
94
|
+
this.#writeByte(this.#useWide ? FORMAT_WIDE : FORMAT_COMPACT);
|
|
95
|
+
this.#writeWord(this.#data.inputNodes.length);
|
|
96
|
+
this.#writeWord(this.#data.outputNodes.length);
|
|
97
|
+
this.#writeWord(this.#rootKeys.length);
|
|
98
|
+
}
|
|
99
|
+
#writeInputNodes() {
|
|
100
|
+
for (const node of this.#data.inputNodes) {
|
|
101
|
+
const fieldIndices = Object.keys(node.edges).map(Number);
|
|
102
|
+
this.#writeWord(fieldIndices.length);
|
|
103
|
+
for (const fieldIndex of fieldIndices) {
|
|
104
|
+
const edge = node.edges[fieldIndex];
|
|
105
|
+
this.#writeWord(fieldIndex);
|
|
106
|
+
this.#writeU16(edge.scalarMask ?? 0);
|
|
107
|
+
if (this.#useWide) {
|
|
108
|
+
this.#skip(2);
|
|
109
|
+
}
|
|
110
|
+
this.#writeOptionalWord(edge.childNodeId);
|
|
111
|
+
this.#writeOptionalWord(edge.enumNameIndex);
|
|
112
|
+
this.#writeByte(edge.flags);
|
|
113
|
+
this.#skip(this.#useWide ? 3 : 1);
|
|
114
|
+
}
|
|
95
115
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
view.setUint16(offset, fieldIndex, true);
|
|
107
|
-
offset += 2;
|
|
108
|
-
view.setUint16(offset, edge.argsNodeId ?? NONE_16, true);
|
|
109
|
-
offset += 2;
|
|
110
|
-
view.setUint16(offset, edge.outputNodeId ?? NONE_16, true);
|
|
111
|
-
offset += 2;
|
|
116
|
+
}
|
|
117
|
+
#writeOutputNodes() {
|
|
118
|
+
for (const node of this.#data.outputNodes) {
|
|
119
|
+
const fieldIndices = Object.keys(node.edges).map(Number);
|
|
120
|
+
this.#writeWord(fieldIndices.length);
|
|
121
|
+
for (const fieldIndex of fieldIndices) {
|
|
122
|
+
const edge = node.edges[fieldIndex];
|
|
123
|
+
this.#writeWord(fieldIndex);
|
|
124
|
+
this.#writeOptionalWord(edge.argsNodeId);
|
|
125
|
+
this.#writeOptionalWord(edge.outputNodeId);
|
|
112
126
|
}
|
|
113
127
|
}
|
|
114
128
|
}
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
offset += 4;
|
|
123
|
-
view.setUint32(offset, root.outputNodeId ?? NONE_32, true);
|
|
124
|
-
offset += 4;
|
|
125
|
-
} else {
|
|
126
|
-
view.setUint16(offset, keyIndex, true);
|
|
127
|
-
offset += 2;
|
|
128
|
-
view.setUint16(offset, root.argsNodeId ?? NONE_16, true);
|
|
129
|
-
offset += 2;
|
|
130
|
-
view.setUint16(offset, root.outputNodeId ?? NONE_16, true);
|
|
131
|
-
offset += 2;
|
|
129
|
+
#writeRoots() {
|
|
130
|
+
for (const key of this.#rootKeys) {
|
|
131
|
+
const root = this.#data.roots[key];
|
|
132
|
+
const keyIndex = this.#data.strings.indexOf(key);
|
|
133
|
+
this.#writeWord(keyIndex);
|
|
134
|
+
this.#writeOptionalWord(root.argsNodeId);
|
|
135
|
+
this.#writeOptionalWord(root.outputNodeId);
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
return {
|
|
135
|
-
strings: data.strings,
|
|
136
|
-
graph: encodeBase64url(new Uint8Array(buffer))
|
|
137
|
-
};
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
rootCount = view.getUint16(offset, true);
|
|
161
|
-
offset += 2;
|
|
139
|
+
class Deserializer {
|
|
140
|
+
#serialized;
|
|
141
|
+
#view;
|
|
142
|
+
#offset = 0;
|
|
143
|
+
#useWide = false;
|
|
144
|
+
constructor(serialized) {
|
|
145
|
+
this.#serialized = serialized;
|
|
146
|
+
const bytes = decodeBase64url(serialized.graph);
|
|
147
|
+
this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
148
|
+
}
|
|
149
|
+
deserialize() {
|
|
150
|
+
const { inputNodeCount, outputNodeCount, rootCount } = this.#readHeader();
|
|
151
|
+
const inputNodes = this.#readInputNodes(inputNodeCount);
|
|
152
|
+
const outputNodes = this.#readOutputNodes(outputNodeCount);
|
|
153
|
+
const roots = this.#readRoots(rootCount);
|
|
154
|
+
return {
|
|
155
|
+
strings: this.#serialized.strings,
|
|
156
|
+
inputNodes,
|
|
157
|
+
outputNodes,
|
|
158
|
+
roots
|
|
159
|
+
};
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
161
|
+
get #wordSize() {
|
|
162
|
+
return this.#useWide ? 4 : 2;
|
|
163
|
+
}
|
|
164
|
+
get #noneValue() {
|
|
165
|
+
return this.#useWide ? NONE_32 : NONE_16;
|
|
166
|
+
}
|
|
167
|
+
#readWord() {
|
|
168
|
+
let value;
|
|
169
|
+
if (this.#useWide) {
|
|
170
|
+
value = this.#view.getUint32(this.#offset, true);
|
|
169
171
|
} else {
|
|
170
|
-
|
|
171
|
-
offset += 2;
|
|
172
|
+
value = this.#view.getUint16(this.#offset, true);
|
|
172
173
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
174
|
+
this.#offset += this.#wordSize;
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
#readOptionalWord() {
|
|
178
|
+
const value = this.#readWord();
|
|
179
|
+
return value === this.#noneValue ? void 0 : value;
|
|
180
|
+
}
|
|
181
|
+
#readByte() {
|
|
182
|
+
const value = this.#view.getUint8(this.#offset);
|
|
183
|
+
this.#offset += 1;
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
#readU16() {
|
|
187
|
+
const value = this.#view.getUint16(this.#offset, true);
|
|
188
|
+
this.#offset += 2;
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
#skip(bytes) {
|
|
192
|
+
this.#offset += bytes;
|
|
193
|
+
}
|
|
194
|
+
#readHeader() {
|
|
195
|
+
const format = this.#readByte();
|
|
196
|
+
this.#useWide = format === FORMAT_WIDE;
|
|
197
|
+
const inputNodeCount = this.#readWord();
|
|
198
|
+
const outputNodeCount = this.#readWord();
|
|
199
|
+
const rootCount = this.#readWord();
|
|
200
|
+
return { inputNodeCount, outputNodeCount, rootCount };
|
|
201
|
+
}
|
|
202
|
+
#readInputNodes(count) {
|
|
203
|
+
const inputNodes = [];
|
|
204
|
+
for (let i = 0; i < count; i++) {
|
|
205
|
+
const edgeCount = this.#readWord();
|
|
206
|
+
const edges = {};
|
|
207
|
+
for (let j = 0; j < edgeCount; j++) {
|
|
208
|
+
const fieldIndex = this.#readWord();
|
|
209
|
+
const scalarMask = this.#readU16();
|
|
210
|
+
if (this.#useWide) {
|
|
211
|
+
this.#skip(2);
|
|
212
|
+
}
|
|
213
|
+
const childNodeId = this.#readOptionalWord();
|
|
214
|
+
const enumNameIndex = this.#readOptionalWord();
|
|
215
|
+
const flags = this.#readByte();
|
|
216
|
+
this.#skip(this.#useWide ? 3 : 1);
|
|
217
|
+
const edge = { flags };
|
|
218
|
+
if (scalarMask !== 0) edge.scalarMask = scalarMask;
|
|
219
|
+
if (childNodeId !== void 0) edge.childNodeId = childNodeId;
|
|
220
|
+
if (enumNameIndex !== void 0) edge.enumNameIndex = enumNameIndex;
|
|
221
|
+
edges[fieldIndex] = edge;
|
|
205
222
|
}
|
|
206
|
-
|
|
207
|
-
if (scalarMask !== 0) edge.scalarMask = scalarMask;
|
|
208
|
-
if (childNodeId !== (useWide ? NONE_32 : NONE_16)) edge.childNodeId = childNodeId;
|
|
209
|
-
if (enumNameIndex !== (useWide ? NONE_32 : NONE_16)) edge.enumNameIndex = enumNameIndex;
|
|
210
|
-
edges[fieldIndex] = edge;
|
|
223
|
+
inputNodes.push({ edges });
|
|
211
224
|
}
|
|
212
|
-
inputNodes
|
|
225
|
+
return inputNodes;
|
|
213
226
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
let
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
let argsNodeId;
|
|
228
|
-
let outputNodeId;
|
|
229
|
-
if (useWide) {
|
|
230
|
-
fieldIndex = view.getUint32(offset, true);
|
|
231
|
-
offset += 4;
|
|
232
|
-
argsNodeId = view.getUint32(offset, true);
|
|
233
|
-
offset += 4;
|
|
234
|
-
outputNodeId = view.getUint32(offset, true);
|
|
235
|
-
offset += 4;
|
|
236
|
-
} else {
|
|
237
|
-
fieldIndex = view.getUint16(offset, true);
|
|
238
|
-
offset += 2;
|
|
239
|
-
argsNodeId = view.getUint16(offset, true);
|
|
240
|
-
offset += 2;
|
|
241
|
-
outputNodeId = view.getUint16(offset, true);
|
|
242
|
-
offset += 2;
|
|
227
|
+
#readOutputNodes(count) {
|
|
228
|
+
const outputNodes = [];
|
|
229
|
+
for (let i = 0; i < count; i++) {
|
|
230
|
+
const edgeCount = this.#readWord();
|
|
231
|
+
const edges = {};
|
|
232
|
+
for (let j = 0; j < edgeCount; j++) {
|
|
233
|
+
const fieldIndex = this.#readWord();
|
|
234
|
+
const argsNodeId = this.#readOptionalWord();
|
|
235
|
+
const outputNodeId = this.#readOptionalWord();
|
|
236
|
+
const edge = {};
|
|
237
|
+
if (argsNodeId !== void 0) edge.argsNodeId = argsNodeId;
|
|
238
|
+
if (outputNodeId !== void 0) edge.outputNodeId = outputNodeId;
|
|
239
|
+
edges[fieldIndex] = edge;
|
|
243
240
|
}
|
|
244
|
-
|
|
245
|
-
if (argsNodeId !== (useWide ? NONE_32 : NONE_16)) edge.argsNodeId = argsNodeId;
|
|
246
|
-
if (outputNodeId !== (useWide ? NONE_32 : NONE_16)) edge.outputNodeId = outputNodeId;
|
|
247
|
-
edges[fieldIndex] = edge;
|
|
241
|
+
outputNodes.push({ edges });
|
|
248
242
|
}
|
|
249
|
-
outputNodes
|
|
243
|
+
return outputNodes;
|
|
250
244
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
let
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
argsNodeId
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
offset += 4;
|
|
263
|
-
} else {
|
|
264
|
-
keyIndex = view.getUint16(offset, true);
|
|
265
|
-
offset += 2;
|
|
266
|
-
argsNodeId = view.getUint16(offset, true);
|
|
267
|
-
offset += 2;
|
|
268
|
-
outputNodeId = view.getUint16(offset, true);
|
|
269
|
-
offset += 2;
|
|
245
|
+
#readRoots(count) {
|
|
246
|
+
const roots = {};
|
|
247
|
+
for (let i = 0; i < count; i++) {
|
|
248
|
+
const keyIndex = this.#readWord();
|
|
249
|
+
const argsNodeId = this.#readOptionalWord();
|
|
250
|
+
const outputNodeId = this.#readOptionalWord();
|
|
251
|
+
const key = this.#serialized.strings[keyIndex];
|
|
252
|
+
const root = {};
|
|
253
|
+
if (argsNodeId !== void 0) root.argsNodeId = argsNodeId;
|
|
254
|
+
if (outputNodeId !== void 0) root.outputNodeId = outputNodeId;
|
|
255
|
+
roots[key] = root;
|
|
270
256
|
}
|
|
271
|
-
|
|
272
|
-
const root = {};
|
|
273
|
-
if (argsNodeId !== (useWide ? NONE_32 : NONE_16)) root.argsNodeId = argsNodeId;
|
|
274
|
-
if (outputNodeId !== (useWide ? NONE_32 : NONE_16)) root.outputNodeId = outputNodeId;
|
|
275
|
-
roots[key] = root;
|
|
257
|
+
return roots;
|
|
276
258
|
}
|
|
277
|
-
return {
|
|
278
|
-
strings: serialized.strings,
|
|
279
|
-
inputNodes,
|
|
280
|
-
outputNodes,
|
|
281
|
-
roots
|
|
282
|
-
};
|
|
283
259
|
}
|
|
284
260
|
export {
|
|
285
261
|
deserializeParamGraph,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/param-graph",
|
|
3
|
-
"version": "7.4.0-integration-parameterization.
|
|
3
|
+
"version": "7.4.0-integration-parameterization.10",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|