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