@prisma/param-graph 7.7.0-integration-feat-prisma-bootstrap.7 → 7.7.0-integration-feat-bootstrap-ux-fixes.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/index.mjs CHANGED
@@ -1,6 +1,456 @@
1
- import { ParamGraph } from "./param-graph";
2
- import { EdgeFlag, getScalarMask, hasFlag, ScalarMask, scalarTypeToMask } from "./param-graph";
3
- import { deserializeParamGraph, serializeParamGraph } from "./serialization";
1
+ // src/serialization.ts
2
+ function serializeParamGraph(data) {
3
+ return new Serializer(data).serialize();
4
+ }
5
+ function deserializeParamGraph(serialized) {
6
+ return new Deserializer(serialized).deserialize();
7
+ }
8
+ function encodeBase64url(bytes) {
9
+ return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64url");
10
+ }
11
+ function decodeBase64url(str) {
12
+ return Buffer.from(str, "base64url");
13
+ }
14
+ function varuintSize(value) {
15
+ let size = 1;
16
+ while (value >= 128) {
17
+ size++;
18
+ value >>>= 7;
19
+ }
20
+ return size;
21
+ }
22
+ var Serializer = class {
23
+ #data;
24
+ #buffer;
25
+ #view;
26
+ #offset = 0;
27
+ #rootKeys;
28
+ constructor(data) {
29
+ this.#data = data;
30
+ this.#rootKeys = Object.keys(data.roots);
31
+ const size = this.#calculateBufferSize();
32
+ this.#buffer = new ArrayBuffer(size);
33
+ this.#view = new DataView(this.#buffer);
34
+ }
35
+ serialize() {
36
+ this.#writeHeader();
37
+ this.#writeInputNodes();
38
+ this.#writeOutputNodes();
39
+ this.#writeRoots();
40
+ return {
41
+ strings: this.#data.strings,
42
+ graph: encodeBase64url(new Uint8Array(this.#buffer, 0, this.#offset))
43
+ };
44
+ }
45
+ #writeVaruint(value) {
46
+ while (value >= 128) {
47
+ this.#view.setUint8(this.#offset++, value & 127 | 128);
48
+ value >>>= 7;
49
+ }
50
+ this.#view.setUint8(this.#offset++, value);
51
+ }
52
+ #writeOptionalVaruint(value) {
53
+ this.#writeVaruint(value === void 0 ? 0 : value + 1);
54
+ }
55
+ #writeByte(value) {
56
+ this.#view.setUint8(this.#offset, value);
57
+ this.#offset += 1;
58
+ }
59
+ #writeU16(value) {
60
+ this.#view.setUint16(this.#offset, value, true);
61
+ this.#offset += 2;
62
+ }
63
+ #calculateBufferSize() {
64
+ let size = 0;
65
+ size += varuintSize(this.#data.inputNodes.length);
66
+ size += varuintSize(this.#data.outputNodes.length);
67
+ size += varuintSize(this.#rootKeys.length);
68
+ for (const node of this.#data.inputNodes) {
69
+ const fieldIndices = Object.keys(node.edges).map(Number);
70
+ size += varuintSize(fieldIndices.length);
71
+ for (const fieldIndex of fieldIndices) {
72
+ const edge = node.edges[fieldIndex];
73
+ size += varuintSize(fieldIndex);
74
+ size += 2;
75
+ size += varuintSize(edge.childNodeId === void 0 ? 0 : edge.childNodeId + 1);
76
+ size += varuintSize(edge.enumNameIndex === void 0 ? 0 : edge.enumNameIndex + 1);
77
+ size += 1;
78
+ }
79
+ }
80
+ for (const node of this.#data.outputNodes) {
81
+ const fieldIndices = Object.keys(node.edges).map(Number);
82
+ size += varuintSize(fieldIndices.length);
83
+ for (const fieldIndex of fieldIndices) {
84
+ const edge = node.edges[fieldIndex];
85
+ size += varuintSize(fieldIndex);
86
+ size += varuintSize(edge.argsNodeId === void 0 ? 0 : edge.argsNodeId + 1);
87
+ size += varuintSize(edge.outputNodeId === void 0 ? 0 : edge.outputNodeId + 1);
88
+ }
89
+ }
90
+ for (const key of this.#rootKeys) {
91
+ const root = this.#data.roots[key];
92
+ const keyIndex = this.#data.strings.indexOf(key);
93
+ size += varuintSize(keyIndex);
94
+ size += varuintSize(root.argsNodeId === void 0 ? 0 : root.argsNodeId + 1);
95
+ size += varuintSize(root.outputNodeId === void 0 ? 0 : root.outputNodeId + 1);
96
+ }
97
+ return size;
98
+ }
99
+ #writeHeader() {
100
+ this.#writeVaruint(this.#data.inputNodes.length);
101
+ this.#writeVaruint(this.#data.outputNodes.length);
102
+ this.#writeVaruint(this.#rootKeys.length);
103
+ }
104
+ #writeInputNodes() {
105
+ for (const node of this.#data.inputNodes) {
106
+ const fieldIndices = Object.keys(node.edges).map(Number);
107
+ this.#writeVaruint(fieldIndices.length);
108
+ for (const fieldIndex of fieldIndices) {
109
+ const edge = node.edges[fieldIndex];
110
+ this.#writeVaruint(fieldIndex);
111
+ this.#writeU16(edge.scalarMask ?? 0);
112
+ this.#writeOptionalVaruint(edge.childNodeId);
113
+ this.#writeOptionalVaruint(edge.enumNameIndex);
114
+ this.#writeByte(edge.flags);
115
+ }
116
+ }
117
+ }
118
+ #writeOutputNodes() {
119
+ for (const node of this.#data.outputNodes) {
120
+ const fieldIndices = Object.keys(node.edges).map(Number);
121
+ this.#writeVaruint(fieldIndices.length);
122
+ for (const fieldIndex of fieldIndices) {
123
+ const edge = node.edges[fieldIndex];
124
+ this.#writeVaruint(fieldIndex);
125
+ this.#writeOptionalVaruint(edge.argsNodeId);
126
+ this.#writeOptionalVaruint(edge.outputNodeId);
127
+ }
128
+ }
129
+ }
130
+ #writeRoots() {
131
+ for (const key of this.#rootKeys) {
132
+ const root = this.#data.roots[key];
133
+ const keyIndex = this.#data.strings.indexOf(key);
134
+ if (keyIndex === -1) {
135
+ throw new Error(`Root key "${key}" not found in strings table`);
136
+ }
137
+ this.#writeVaruint(keyIndex);
138
+ this.#writeOptionalVaruint(root.argsNodeId);
139
+ this.#writeOptionalVaruint(root.outputNodeId);
140
+ }
141
+ }
142
+ };
143
+ var Deserializer = class {
144
+ #serialized;
145
+ #view;
146
+ #offset = 0;
147
+ constructor(serialized) {
148
+ this.#serialized = serialized;
149
+ const bytes = decodeBase64url(serialized.graph);
150
+ this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
151
+ }
152
+ deserialize() {
153
+ const { inputNodeCount, outputNodeCount, rootCount } = this.#readHeader();
154
+ const inputNodes = this.#readInputNodes(inputNodeCount);
155
+ const outputNodes = this.#readOutputNodes(outputNodeCount);
156
+ const roots = this.#readRoots(rootCount);
157
+ return {
158
+ strings: this.#serialized.strings,
159
+ inputNodes,
160
+ outputNodes,
161
+ roots
162
+ };
163
+ }
164
+ #readVaruint() {
165
+ let value = 0;
166
+ let shift = 0;
167
+ let byte;
168
+ do {
169
+ byte = this.#view.getUint8(this.#offset++);
170
+ value |= (byte & 127) << shift;
171
+ shift += 7;
172
+ } while (byte >= 128);
173
+ return value;
174
+ }
175
+ #readOptionalVaruint() {
176
+ const value = this.#readVaruint();
177
+ return value === 0 ? void 0 : value - 1;
178
+ }
179
+ #readByte() {
180
+ const value = this.#view.getUint8(this.#offset);
181
+ this.#offset += 1;
182
+ return value;
183
+ }
184
+ #readU16() {
185
+ const value = this.#view.getUint16(this.#offset, true);
186
+ this.#offset += 2;
187
+ return value;
188
+ }
189
+ #readHeader() {
190
+ const inputNodeCount = this.#readVaruint();
191
+ const outputNodeCount = this.#readVaruint();
192
+ const rootCount = this.#readVaruint();
193
+ return { inputNodeCount, outputNodeCount, rootCount };
194
+ }
195
+ #readInputNodes(count) {
196
+ const inputNodes = [];
197
+ for (let i = 0; i < count; i++) {
198
+ const edgeCount = this.#readVaruint();
199
+ const edges = {};
200
+ for (let j = 0; j < edgeCount; j++) {
201
+ const fieldIndex = this.#readVaruint();
202
+ const scalarMask = this.#readU16();
203
+ const childNodeId = this.#readOptionalVaruint();
204
+ const enumNameIndex = this.#readOptionalVaruint();
205
+ const flags = this.#readByte();
206
+ const edge = { flags };
207
+ if (scalarMask !== 0) edge.scalarMask = scalarMask;
208
+ if (childNodeId !== void 0) edge.childNodeId = childNodeId;
209
+ if (enumNameIndex !== void 0) edge.enumNameIndex = enumNameIndex;
210
+ edges[fieldIndex] = edge;
211
+ }
212
+ inputNodes.push({ edges });
213
+ }
214
+ return inputNodes;
215
+ }
216
+ #readOutputNodes(count) {
217
+ const outputNodes = [];
218
+ for (let i = 0; i < count; i++) {
219
+ const edgeCount = this.#readVaruint();
220
+ const edges = {};
221
+ for (let j = 0; j < edgeCount; j++) {
222
+ const fieldIndex = this.#readVaruint();
223
+ const argsNodeId = this.#readOptionalVaruint();
224
+ const outputNodeId = this.#readOptionalVaruint();
225
+ const edge = {};
226
+ if (argsNodeId !== void 0) edge.argsNodeId = argsNodeId;
227
+ if (outputNodeId !== void 0) edge.outputNodeId = outputNodeId;
228
+ edges[fieldIndex] = edge;
229
+ }
230
+ outputNodes.push({ edges });
231
+ }
232
+ return outputNodes;
233
+ }
234
+ #readRoots(count) {
235
+ const roots = {};
236
+ for (let i = 0; i < count; i++) {
237
+ const keyIndex = this.#readVaruint();
238
+ const argsNodeId = this.#readOptionalVaruint();
239
+ const outputNodeId = this.#readOptionalVaruint();
240
+ const key = this.#serialized.strings[keyIndex];
241
+ const root = {};
242
+ if (argsNodeId !== void 0) root.argsNodeId = argsNodeId;
243
+ if (outputNodeId !== void 0) root.outputNodeId = outputNodeId;
244
+ roots[key] = root;
245
+ }
246
+ return roots;
247
+ }
248
+ };
249
+
250
+ // src/param-graph.ts
251
+ var ParamGraph = class _ParamGraph {
252
+ #data;
253
+ #stringIndex;
254
+ #enumLookup;
255
+ constructor(data, enumLookup) {
256
+ this.#data = data;
257
+ this.#enumLookup = enumLookup;
258
+ this.#stringIndex = /* @__PURE__ */ new Map();
259
+ for (let i = 0; i < data.strings.length; i++) {
260
+ this.#stringIndex.set(data.strings[i], i);
261
+ }
262
+ }
263
+ /**
264
+ * Creates a ParamGraph from serialized format.
265
+ * This is the primary factory method for runtime use.
266
+ */
267
+ static deserialize(serialized, enumLookup) {
268
+ const data = deserializeParamGraph(serialized);
269
+ return new _ParamGraph(data, enumLookup);
270
+ }
271
+ /**
272
+ * Creates a ParamGraph from builder data.
273
+ * Used by the builder for testing and direct construction.
274
+ */
275
+ static fromData(data, enumLookup) {
276
+ return new _ParamGraph(data, enumLookup);
277
+ }
278
+ /**
279
+ * Look up a root entry by "Model.action" or "action".
280
+ */
281
+ root(key) {
282
+ const entry = this.#data.roots[key];
283
+ if (!entry) {
284
+ return void 0;
285
+ }
286
+ return {
287
+ argsNodeId: entry.argsNodeId,
288
+ outputNodeId: entry.outputNodeId
289
+ };
290
+ }
291
+ /**
292
+ * Get an input node by ID.
293
+ */
294
+ inputNode(id) {
295
+ if (id === void 0 || id < 0 || id >= this.#data.inputNodes.length) {
296
+ return void 0;
297
+ }
298
+ return { id };
299
+ }
300
+ /**
301
+ * Get an output node by ID.
302
+ */
303
+ outputNode(id) {
304
+ if (id === void 0 || id < 0 || id >= this.#data.outputNodes.length) {
305
+ return void 0;
306
+ }
307
+ return { id };
308
+ }
309
+ /**
310
+ * Get an input edge for a field name within a node.
311
+ */
312
+ inputEdge(node, fieldName) {
313
+ if (!node) {
314
+ return void 0;
315
+ }
316
+ const nodeData = this.#data.inputNodes[node.id];
317
+ if (!nodeData) {
318
+ return void 0;
319
+ }
320
+ const fieldIndex = this.#stringIndex.get(fieldName);
321
+ if (fieldIndex === void 0) {
322
+ return void 0;
323
+ }
324
+ const edge = nodeData.edges[fieldIndex];
325
+ if (!edge) {
326
+ return void 0;
327
+ }
328
+ return {
329
+ flags: edge.flags,
330
+ childNodeId: edge.childNodeId,
331
+ scalarMask: edge.scalarMask ?? 0,
332
+ enumNameIndex: edge.enumNameIndex
333
+ };
334
+ }
335
+ /**
336
+ * Get an output edge for a field name within a node.
337
+ */
338
+ outputEdge(node, fieldName) {
339
+ if (!node) {
340
+ return void 0;
341
+ }
342
+ const nodeData = this.#data.outputNodes[node.id];
343
+ if (!nodeData) {
344
+ return void 0;
345
+ }
346
+ const fieldIndex = this.#stringIndex.get(fieldName);
347
+ if (fieldIndex === void 0) {
348
+ return void 0;
349
+ }
350
+ const edge = nodeData.edges[fieldIndex];
351
+ if (!edge) {
352
+ return void 0;
353
+ }
354
+ return {
355
+ argsNodeId: edge.argsNodeId,
356
+ outputNodeId: edge.outputNodeId
357
+ };
358
+ }
359
+ /**
360
+ * Get enum values for an edge that references a user enum.
361
+ * Returns undefined if the edge doesn't reference an enum.
362
+ */
363
+ enumValues(edge) {
364
+ if (edge?.enumNameIndex === void 0) {
365
+ return void 0;
366
+ }
367
+ const enumName = this.#data.strings[edge.enumNameIndex];
368
+ if (!enumName) {
369
+ return void 0;
370
+ }
371
+ return this.#enumLookup(enumName);
372
+ }
373
+ /**
374
+ * Get a string from the string table by index.
375
+ */
376
+ getString(index) {
377
+ return this.#data.strings[index];
378
+ }
379
+ };
380
+ var EdgeFlag = {
381
+ /**
382
+ * Field may be parameterized as a scalar value.
383
+ * Check ScalarMask to validate the value type.
384
+ */
385
+ ParamScalar: 1,
386
+ /**
387
+ * Field may be parameterized as an enum.
388
+ * Check enum ID to validate the value type.
389
+ */
390
+ ParamEnum: 2,
391
+ /**
392
+ * Field accepts list-of-scalar values.
393
+ * Parameterize the whole list if all elements match ScalarMask.
394
+ */
395
+ ParamListScalar: 4,
396
+ /**
397
+ * Field accepts list-of-enum values.
398
+ * Parameterize the whole list if all elements match enum ID.
399
+ */
400
+ ParamListEnum: 8,
401
+ /**
402
+ * Field accepts list-of-object values.
403
+ * Recurse into each element using the child node.
404
+ */
405
+ ListObject: 16,
406
+ /**
407
+ * Field accepts object values.
408
+ * Recurse into child input node.
409
+ */
410
+ Object: 32
411
+ };
412
+ var ScalarMask = {
413
+ String: 1,
414
+ Int: 2,
415
+ BigInt: 4,
416
+ Float: 8,
417
+ Decimal: 16,
418
+ Boolean: 32,
419
+ DateTime: 64,
420
+ Json: 128,
421
+ Bytes: 256
422
+ };
423
+ function hasFlag(edge, flag) {
424
+ return (edge.flags & flag) !== 0;
425
+ }
426
+ function getScalarMask(edge) {
427
+ return edge.scalarMask;
428
+ }
429
+ function scalarTypeToMask(typeName) {
430
+ switch (typeName) {
431
+ case "String":
432
+ case "UUID":
433
+ return ScalarMask.String;
434
+ case "Int":
435
+ return ScalarMask.Int;
436
+ case "BigInt":
437
+ return ScalarMask.BigInt;
438
+ case "Float":
439
+ return ScalarMask.Float;
440
+ case "Decimal":
441
+ return ScalarMask.Decimal;
442
+ case "Boolean":
443
+ return ScalarMask.Boolean;
444
+ case "DateTime":
445
+ return ScalarMask.DateTime;
446
+ case "Json":
447
+ return ScalarMask.Json;
448
+ case "Bytes":
449
+ return ScalarMask.Bytes;
450
+ default:
451
+ return 0;
452
+ }
453
+ }
4
454
  export {
5
455
  EdgeFlag,
6
456
  ParamGraph,
@@ -7,11 +7,15 @@
7
7
  */
8
8
  import type { SerializedParamGraph } from './serialization';
9
9
  import type { InputEdgeData, InputNodeData, OutputEdgeData, OutputNodeData, ParamGraphData, RootEntryData } from './types';
10
+ /**
11
+ * Map of enum names to their respective values.
12
+ */
13
+ export type EnumNameToValueMap = Record<string, string>;
10
14
  /**
11
15
  * Function type for looking up enum values by name.
12
16
  * This allows ParamGraph to remain decoupled from RuntimeDataModel.
13
17
  */
14
- export type EnumLookup = (enumName: string) => readonly string[] | undefined;
18
+ export type EnumLookup = (enumName: string) => Readonly<EnumNameToValueMap> | undefined;
15
19
  /**
16
20
  * Readable view of root entry.
17
21
  */
@@ -88,7 +92,7 @@ export declare class ParamGraph {
88
92
  * Get enum values for an edge that references a user enum.
89
93
  * Returns undefined if the edge doesn't reference an enum.
90
94
  */
91
- enumValues(edge: InputEdge | undefined): readonly string[] | undefined;
95
+ enumValues(edge: InputEdge | undefined): Readonly<EnumNameToValueMap> | undefined;
92
96
  /**
93
97
  * Get a string from the string table by index.
94
98
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/param-graph",
3
- "version": "7.7.0-integration-feat-prisma-bootstrap.7",
3
+ "version": "7.7.0-integration-feat-bootstrap-ux-fixes.2",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",