@prisma/security-rules 0.3.6 → 0.3.7
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 +53 -63
- package/assets/rpc.png +0 -0
- package/dist/index.cjs +1 -1137
- package/dist/index.d.cts +20 -170
- package/dist/index.d.ts +20 -170
- package/dist/index.js +1 -1109
- package/package.json +2 -4
package/dist/index.cjs
CHANGED
@@ -1,1137 +1 @@
|
|
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
|
-
|
20
|
-
// src/index.ts
|
21
|
-
var src_exports = {};
|
22
|
-
__export(src_exports, {
|
23
|
-
PolicyClient: () => PolicyClient,
|
24
|
-
withPolicy: () => withPolicy
|
25
|
-
});
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
27
|
-
|
28
|
-
// src/withPolicy.ts
|
29
|
-
var import_extension = require("@prisma/client/extension");
|
30
|
-
function withPolicy(args) {
|
31
|
-
const { rules } = args;
|
32
|
-
return (prisma) => {
|
33
|
-
const extension = import_extension.Prisma.defineExtension({
|
34
|
-
name: "@prisma/extension-policy",
|
35
|
-
client: {
|
36
|
-
$policy: {
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
38
|
-
setGlobalContext(ctx) {
|
39
|
-
},
|
40
|
-
// virtual, doesn't do anything
|
41
|
-
contextSchema: args.contextSchema?.["~standard"],
|
42
|
-
rules
|
43
|
-
}
|
44
|
-
}
|
45
|
-
});
|
46
|
-
return extension(prisma).$extends({}).$extends({});
|
47
|
-
};
|
48
|
-
}
|
49
|
-
|
50
|
-
// ../protocol/index.ts
|
51
|
-
var import_zod = require("zod");
|
52
|
-
|
53
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/double-indexed-kv.js
|
54
|
-
var DoubleIndexedKV = class {
|
55
|
-
constructor() {
|
56
|
-
this.keyToValue = /* @__PURE__ */ new Map();
|
57
|
-
this.valueToKey = /* @__PURE__ */ new Map();
|
58
|
-
}
|
59
|
-
set(key, value) {
|
60
|
-
this.keyToValue.set(key, value);
|
61
|
-
this.valueToKey.set(value, key);
|
62
|
-
}
|
63
|
-
getByKey(key) {
|
64
|
-
return this.keyToValue.get(key);
|
65
|
-
}
|
66
|
-
getByValue(value) {
|
67
|
-
return this.valueToKey.get(value);
|
68
|
-
}
|
69
|
-
clear() {
|
70
|
-
this.keyToValue.clear();
|
71
|
-
this.valueToKey.clear();
|
72
|
-
}
|
73
|
-
};
|
74
|
-
|
75
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/registry.js
|
76
|
-
var Registry = class {
|
77
|
-
constructor(generateIdentifier) {
|
78
|
-
this.generateIdentifier = generateIdentifier;
|
79
|
-
this.kv = new DoubleIndexedKV();
|
80
|
-
}
|
81
|
-
register(value, identifier) {
|
82
|
-
if (this.kv.getByValue(value)) {
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
if (!identifier) {
|
86
|
-
identifier = this.generateIdentifier(value);
|
87
|
-
}
|
88
|
-
this.kv.set(identifier, value);
|
89
|
-
}
|
90
|
-
clear() {
|
91
|
-
this.kv.clear();
|
92
|
-
}
|
93
|
-
getIdentifier(value) {
|
94
|
-
return this.kv.getByValue(value);
|
95
|
-
}
|
96
|
-
getValue(identifier) {
|
97
|
-
return this.kv.getByKey(identifier);
|
98
|
-
}
|
99
|
-
};
|
100
|
-
|
101
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/class-registry.js
|
102
|
-
var ClassRegistry = class extends Registry {
|
103
|
-
constructor() {
|
104
|
-
super((c) => c.name);
|
105
|
-
this.classToAllowedProps = /* @__PURE__ */ new Map();
|
106
|
-
}
|
107
|
-
register(value, options) {
|
108
|
-
if (typeof options === "object") {
|
109
|
-
if (options.allowProps) {
|
110
|
-
this.classToAllowedProps.set(value, options.allowProps);
|
111
|
-
}
|
112
|
-
super.register(value, options.identifier);
|
113
|
-
} else {
|
114
|
-
super.register(value, options);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
getAllowedProps(value) {
|
118
|
-
return this.classToAllowedProps.get(value);
|
119
|
-
}
|
120
|
-
};
|
121
|
-
|
122
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/util.js
|
123
|
-
function valuesOfObj(record) {
|
124
|
-
if ("values" in Object) {
|
125
|
-
return Object.values(record);
|
126
|
-
}
|
127
|
-
const values = [];
|
128
|
-
for (const key in record) {
|
129
|
-
if (record.hasOwnProperty(key)) {
|
130
|
-
values.push(record[key]);
|
131
|
-
}
|
132
|
-
}
|
133
|
-
return values;
|
134
|
-
}
|
135
|
-
function find(record, predicate) {
|
136
|
-
const values = valuesOfObj(record);
|
137
|
-
if ("find" in values) {
|
138
|
-
return values.find(predicate);
|
139
|
-
}
|
140
|
-
const valuesNotNever = values;
|
141
|
-
for (let i = 0; i < valuesNotNever.length; i++) {
|
142
|
-
const value = valuesNotNever[i];
|
143
|
-
if (predicate(value)) {
|
144
|
-
return value;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
return void 0;
|
148
|
-
}
|
149
|
-
function forEach(record, run) {
|
150
|
-
Object.entries(record).forEach(([key, value]) => run(value, key));
|
151
|
-
}
|
152
|
-
function includes(arr, value) {
|
153
|
-
return arr.indexOf(value) !== -1;
|
154
|
-
}
|
155
|
-
function findArr(record, predicate) {
|
156
|
-
for (let i = 0; i < record.length; i++) {
|
157
|
-
const value = record[i];
|
158
|
-
if (predicate(value)) {
|
159
|
-
return value;
|
160
|
-
}
|
161
|
-
}
|
162
|
-
return void 0;
|
163
|
-
}
|
164
|
-
|
165
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/custom-transformer-registry.js
|
166
|
-
var CustomTransformerRegistry = class {
|
167
|
-
constructor() {
|
168
|
-
this.transfomers = {};
|
169
|
-
}
|
170
|
-
register(transformer) {
|
171
|
-
this.transfomers[transformer.name] = transformer;
|
172
|
-
}
|
173
|
-
findApplicable(v) {
|
174
|
-
return find(this.transfomers, (transformer) => transformer.isApplicable(v));
|
175
|
-
}
|
176
|
-
findByName(name) {
|
177
|
-
return this.transfomers[name];
|
178
|
-
}
|
179
|
-
};
|
180
|
-
|
181
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/is.js
|
182
|
-
var getType = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
183
|
-
var isUndefined = (payload) => typeof payload === "undefined";
|
184
|
-
var isNull = (payload) => payload === null;
|
185
|
-
var isPlainObject = (payload) => {
|
186
|
-
if (typeof payload !== "object" || payload === null)
|
187
|
-
return false;
|
188
|
-
if (payload === Object.prototype)
|
189
|
-
return false;
|
190
|
-
if (Object.getPrototypeOf(payload) === null)
|
191
|
-
return true;
|
192
|
-
return Object.getPrototypeOf(payload) === Object.prototype;
|
193
|
-
};
|
194
|
-
var isEmptyObject = (payload) => isPlainObject(payload) && Object.keys(payload).length === 0;
|
195
|
-
var isArray = (payload) => Array.isArray(payload);
|
196
|
-
var isString = (payload) => typeof payload === "string";
|
197
|
-
var isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
|
198
|
-
var isBoolean = (payload) => typeof payload === "boolean";
|
199
|
-
var isRegExp = (payload) => payload instanceof RegExp;
|
200
|
-
var isMap = (payload) => payload instanceof Map;
|
201
|
-
var isSet = (payload) => payload instanceof Set;
|
202
|
-
var isSymbol = (payload) => getType(payload) === "Symbol";
|
203
|
-
var isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
204
|
-
var isError = (payload) => payload instanceof Error;
|
205
|
-
var isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
|
206
|
-
var isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
207
|
-
var isBigint = (payload) => typeof payload === "bigint";
|
208
|
-
var isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
209
|
-
var isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
210
|
-
var isURL = (payload) => payload instanceof URL;
|
211
|
-
|
212
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
|
213
|
-
var escapeKey = (key) => key.replace(/\./g, "\\.");
|
214
|
-
var stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
|
215
|
-
var parsePath = (string) => {
|
216
|
-
const result = [];
|
217
|
-
let segment = "";
|
218
|
-
for (let i = 0; i < string.length; i++) {
|
219
|
-
let char = string.charAt(i);
|
220
|
-
const isEscapedDot = char === "\\" && string.charAt(i + 1) === ".";
|
221
|
-
if (isEscapedDot) {
|
222
|
-
segment += ".";
|
223
|
-
i++;
|
224
|
-
continue;
|
225
|
-
}
|
226
|
-
const isEndOfSegment = char === ".";
|
227
|
-
if (isEndOfSegment) {
|
228
|
-
result.push(segment);
|
229
|
-
segment = "";
|
230
|
-
continue;
|
231
|
-
}
|
232
|
-
segment += char;
|
233
|
-
}
|
234
|
-
const lastSegment = segment;
|
235
|
-
result.push(lastSegment);
|
236
|
-
return result;
|
237
|
-
};
|
238
|
-
|
239
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/transformer.js
|
240
|
-
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
241
|
-
return {
|
242
|
-
isApplicable,
|
243
|
-
annotation,
|
244
|
-
transform,
|
245
|
-
untransform
|
246
|
-
};
|
247
|
-
}
|
248
|
-
var simpleRules = [
|
249
|
-
simpleTransformation(isUndefined, "undefined", () => null, () => void 0),
|
250
|
-
simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
|
251
|
-
if (typeof BigInt !== "undefined") {
|
252
|
-
return BigInt(v);
|
253
|
-
}
|
254
|
-
console.error("Please add a BigInt polyfill.");
|
255
|
-
return v;
|
256
|
-
}),
|
257
|
-
simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
|
258
|
-
simpleTransformation(isError, "Error", (v, superJson) => {
|
259
|
-
const baseError = {
|
260
|
-
name: v.name,
|
261
|
-
message: v.message
|
262
|
-
};
|
263
|
-
superJson.allowedErrorProps.forEach((prop) => {
|
264
|
-
baseError[prop] = v[prop];
|
265
|
-
});
|
266
|
-
return baseError;
|
267
|
-
}, (v, superJson) => {
|
268
|
-
const e = new Error(v.message);
|
269
|
-
e.name = v.name;
|
270
|
-
e.stack = v.stack;
|
271
|
-
superJson.allowedErrorProps.forEach((prop) => {
|
272
|
-
e[prop] = v[prop];
|
273
|
-
});
|
274
|
-
return e;
|
275
|
-
}),
|
276
|
-
simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
|
277
|
-
const body = regex.slice(1, regex.lastIndexOf("/"));
|
278
|
-
const flags = regex.slice(regex.lastIndexOf("/") + 1);
|
279
|
-
return new RegExp(body, flags);
|
280
|
-
}),
|
281
|
-
simpleTransformation(
|
282
|
-
isSet,
|
283
|
-
"set",
|
284
|
-
// (sets only exist in es6+)
|
285
|
-
// eslint-disable-next-line es5/no-es6-methods
|
286
|
-
(v) => [...v.values()],
|
287
|
-
(v) => new Set(v)
|
288
|
-
),
|
289
|
-
simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
|
290
|
-
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
|
291
|
-
if (isNaNValue(v)) {
|
292
|
-
return "NaN";
|
293
|
-
}
|
294
|
-
if (v > 0) {
|
295
|
-
return "Infinity";
|
296
|
-
} else {
|
297
|
-
return "-Infinity";
|
298
|
-
}
|
299
|
-
}, Number),
|
300
|
-
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
|
301
|
-
return "-0";
|
302
|
-
}, Number),
|
303
|
-
simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
|
304
|
-
];
|
305
|
-
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
306
|
-
return {
|
307
|
-
isApplicable,
|
308
|
-
annotation,
|
309
|
-
transform,
|
310
|
-
untransform
|
311
|
-
};
|
312
|
-
}
|
313
|
-
var symbolRule = compositeTransformation((s, superJson) => {
|
314
|
-
if (isSymbol(s)) {
|
315
|
-
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s);
|
316
|
-
return isRegistered;
|
317
|
-
}
|
318
|
-
return false;
|
319
|
-
}, (s, superJson) => {
|
320
|
-
const identifier = superJson.symbolRegistry.getIdentifier(s);
|
321
|
-
return ["symbol", identifier];
|
322
|
-
}, (v) => v.description, (_, a, superJson) => {
|
323
|
-
const value = superJson.symbolRegistry.getValue(a[1]);
|
324
|
-
if (!value) {
|
325
|
-
throw new Error("Trying to deserialize unknown symbol");
|
326
|
-
}
|
327
|
-
return value;
|
328
|
-
});
|
329
|
-
var constructorToName = [
|
330
|
-
Int8Array,
|
331
|
-
Uint8Array,
|
332
|
-
Int16Array,
|
333
|
-
Uint16Array,
|
334
|
-
Int32Array,
|
335
|
-
Uint32Array,
|
336
|
-
Float32Array,
|
337
|
-
Float64Array,
|
338
|
-
Uint8ClampedArray
|
339
|
-
].reduce((obj, ctor) => {
|
340
|
-
obj[ctor.name] = ctor;
|
341
|
-
return obj;
|
342
|
-
}, {});
|
343
|
-
var typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => {
|
344
|
-
const ctor = constructorToName[a[1]];
|
345
|
-
if (!ctor) {
|
346
|
-
throw new Error("Trying to deserialize unknown typed array");
|
347
|
-
}
|
348
|
-
return new ctor(v);
|
349
|
-
});
|
350
|
-
function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
351
|
-
if (potentialClass?.constructor) {
|
352
|
-
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
353
|
-
return isRegistered;
|
354
|
-
}
|
355
|
-
return false;
|
356
|
-
}
|
357
|
-
var classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
358
|
-
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
359
|
-
return ["class", identifier];
|
360
|
-
}, (clazz, superJson) => {
|
361
|
-
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
362
|
-
if (!allowedProps) {
|
363
|
-
return { ...clazz };
|
364
|
-
}
|
365
|
-
const result = {};
|
366
|
-
allowedProps.forEach((prop) => {
|
367
|
-
result[prop] = clazz[prop];
|
368
|
-
});
|
369
|
-
return result;
|
370
|
-
}, (v, a, superJson) => {
|
371
|
-
const clazz = superJson.classRegistry.getValue(a[1]);
|
372
|
-
if (!clazz) {
|
373
|
-
throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
374
|
-
}
|
375
|
-
return Object.assign(Object.create(clazz.prototype), v);
|
376
|
-
});
|
377
|
-
var customRule = compositeTransformation((value, superJson) => {
|
378
|
-
return !!superJson.customTransformerRegistry.findApplicable(value);
|
379
|
-
}, (value, superJson) => {
|
380
|
-
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
381
|
-
return ["custom", transformer.name];
|
382
|
-
}, (value, superJson) => {
|
383
|
-
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
384
|
-
return transformer.serialize(value);
|
385
|
-
}, (v, a, superJson) => {
|
386
|
-
const transformer = superJson.customTransformerRegistry.findByName(a[1]);
|
387
|
-
if (!transformer) {
|
388
|
-
throw new Error("Trying to deserialize unknown custom value");
|
389
|
-
}
|
390
|
-
return transformer.deserialize(v);
|
391
|
-
});
|
392
|
-
var compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
|
393
|
-
var transformValue = (value, superJson) => {
|
394
|
-
const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
|
395
|
-
if (applicableCompositeRule) {
|
396
|
-
return {
|
397
|
-
value: applicableCompositeRule.transform(value, superJson),
|
398
|
-
type: applicableCompositeRule.annotation(value, superJson)
|
399
|
-
};
|
400
|
-
}
|
401
|
-
const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
|
402
|
-
if (applicableSimpleRule) {
|
403
|
-
return {
|
404
|
-
value: applicableSimpleRule.transform(value, superJson),
|
405
|
-
type: applicableSimpleRule.annotation
|
406
|
-
};
|
407
|
-
}
|
408
|
-
return void 0;
|
409
|
-
};
|
410
|
-
var simpleRulesByAnnotation = {};
|
411
|
-
simpleRules.forEach((rule) => {
|
412
|
-
simpleRulesByAnnotation[rule.annotation] = rule;
|
413
|
-
});
|
414
|
-
var untransformValue = (json, type, superJson) => {
|
415
|
-
if (isArray(type)) {
|
416
|
-
switch (type[0]) {
|
417
|
-
case "symbol":
|
418
|
-
return symbolRule.untransform(json, type, superJson);
|
419
|
-
case "class":
|
420
|
-
return classRule.untransform(json, type, superJson);
|
421
|
-
case "custom":
|
422
|
-
return customRule.untransform(json, type, superJson);
|
423
|
-
case "typed-array":
|
424
|
-
return typedArrayRule.untransform(json, type, superJson);
|
425
|
-
default:
|
426
|
-
throw new Error("Unknown transformation: " + type);
|
427
|
-
}
|
428
|
-
} else {
|
429
|
-
const transformation = simpleRulesByAnnotation[type];
|
430
|
-
if (!transformation) {
|
431
|
-
throw new Error("Unknown transformation: " + type);
|
432
|
-
}
|
433
|
-
return transformation.untransform(json, superJson);
|
434
|
-
}
|
435
|
-
};
|
436
|
-
|
437
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/accessDeep.js
|
438
|
-
var getNthKey = (value, n) => {
|
439
|
-
if (n > value.size)
|
440
|
-
throw new Error("index out of bounds");
|
441
|
-
const keys = value.keys();
|
442
|
-
while (n > 0) {
|
443
|
-
keys.next();
|
444
|
-
n--;
|
445
|
-
}
|
446
|
-
return keys.next().value;
|
447
|
-
};
|
448
|
-
function validatePath(path) {
|
449
|
-
if (includes(path, "__proto__")) {
|
450
|
-
throw new Error("__proto__ is not allowed as a property");
|
451
|
-
}
|
452
|
-
if (includes(path, "prototype")) {
|
453
|
-
throw new Error("prototype is not allowed as a property");
|
454
|
-
}
|
455
|
-
if (includes(path, "constructor")) {
|
456
|
-
throw new Error("constructor is not allowed as a property");
|
457
|
-
}
|
458
|
-
}
|
459
|
-
var getDeep = (object, path) => {
|
460
|
-
validatePath(path);
|
461
|
-
for (let i = 0; i < path.length; i++) {
|
462
|
-
const key = path[i];
|
463
|
-
if (isSet(object)) {
|
464
|
-
object = getNthKey(object, +key);
|
465
|
-
} else if (isMap(object)) {
|
466
|
-
const row = +key;
|
467
|
-
const type = +path[++i] === 0 ? "key" : "value";
|
468
|
-
const keyOfRow = getNthKey(object, row);
|
469
|
-
switch (type) {
|
470
|
-
case "key":
|
471
|
-
object = keyOfRow;
|
472
|
-
break;
|
473
|
-
case "value":
|
474
|
-
object = object.get(keyOfRow);
|
475
|
-
break;
|
476
|
-
}
|
477
|
-
} else {
|
478
|
-
object = object[key];
|
479
|
-
}
|
480
|
-
}
|
481
|
-
return object;
|
482
|
-
};
|
483
|
-
var setDeep = (object, path, mapper) => {
|
484
|
-
validatePath(path);
|
485
|
-
if (path.length === 0) {
|
486
|
-
return mapper(object);
|
487
|
-
}
|
488
|
-
let parent = object;
|
489
|
-
for (let i = 0; i < path.length - 1; i++) {
|
490
|
-
const key = path[i];
|
491
|
-
if (isArray(parent)) {
|
492
|
-
const index = +key;
|
493
|
-
parent = parent[index];
|
494
|
-
} else if (isPlainObject(parent)) {
|
495
|
-
parent = parent[key];
|
496
|
-
} else if (isSet(parent)) {
|
497
|
-
const row = +key;
|
498
|
-
parent = getNthKey(parent, row);
|
499
|
-
} else if (isMap(parent)) {
|
500
|
-
const isEnd = i === path.length - 2;
|
501
|
-
if (isEnd) {
|
502
|
-
break;
|
503
|
-
}
|
504
|
-
const row = +key;
|
505
|
-
const type = +path[++i] === 0 ? "key" : "value";
|
506
|
-
const keyOfRow = getNthKey(parent, row);
|
507
|
-
switch (type) {
|
508
|
-
case "key":
|
509
|
-
parent = keyOfRow;
|
510
|
-
break;
|
511
|
-
case "value":
|
512
|
-
parent = parent.get(keyOfRow);
|
513
|
-
break;
|
514
|
-
}
|
515
|
-
}
|
516
|
-
}
|
517
|
-
const lastKey = path[path.length - 1];
|
518
|
-
if (isArray(parent)) {
|
519
|
-
parent[+lastKey] = mapper(parent[+lastKey]);
|
520
|
-
} else if (isPlainObject(parent)) {
|
521
|
-
parent[lastKey] = mapper(parent[lastKey]);
|
522
|
-
}
|
523
|
-
if (isSet(parent)) {
|
524
|
-
const oldValue = getNthKey(parent, +lastKey);
|
525
|
-
const newValue = mapper(oldValue);
|
526
|
-
if (oldValue !== newValue) {
|
527
|
-
parent.delete(oldValue);
|
528
|
-
parent.add(newValue);
|
529
|
-
}
|
530
|
-
}
|
531
|
-
if (isMap(parent)) {
|
532
|
-
const row = +path[path.length - 2];
|
533
|
-
const keyToRow = getNthKey(parent, row);
|
534
|
-
const type = +lastKey === 0 ? "key" : "value";
|
535
|
-
switch (type) {
|
536
|
-
case "key": {
|
537
|
-
const newKey = mapper(keyToRow);
|
538
|
-
parent.set(newKey, parent.get(keyToRow));
|
539
|
-
if (newKey !== keyToRow) {
|
540
|
-
parent.delete(keyToRow);
|
541
|
-
}
|
542
|
-
break;
|
543
|
-
}
|
544
|
-
case "value": {
|
545
|
-
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
546
|
-
break;
|
547
|
-
}
|
548
|
-
}
|
549
|
-
}
|
550
|
-
return object;
|
551
|
-
};
|
552
|
-
|
553
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/plainer.js
|
554
|
-
function traverse(tree, walker2, origin = []) {
|
555
|
-
if (!tree) {
|
556
|
-
return;
|
557
|
-
}
|
558
|
-
if (!isArray(tree)) {
|
559
|
-
forEach(tree, (subtree, key) => traverse(subtree, walker2, [...origin, ...parsePath(key)]));
|
560
|
-
return;
|
561
|
-
}
|
562
|
-
const [nodeValue, children] = tree;
|
563
|
-
if (children) {
|
564
|
-
forEach(children, (child, key) => {
|
565
|
-
traverse(child, walker2, [...origin, ...parsePath(key)]);
|
566
|
-
});
|
567
|
-
}
|
568
|
-
walker2(nodeValue, origin);
|
569
|
-
}
|
570
|
-
function applyValueAnnotations(plain, annotations, superJson) {
|
571
|
-
traverse(annotations, (type, path) => {
|
572
|
-
plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
|
573
|
-
});
|
574
|
-
return plain;
|
575
|
-
}
|
576
|
-
function applyReferentialEqualityAnnotations(plain, annotations) {
|
577
|
-
function apply(identicalPaths, path) {
|
578
|
-
const object = getDeep(plain, parsePath(path));
|
579
|
-
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
580
|
-
plain = setDeep(plain, identicalObjectPath, () => object);
|
581
|
-
});
|
582
|
-
}
|
583
|
-
if (isArray(annotations)) {
|
584
|
-
const [root, other] = annotations;
|
585
|
-
root.forEach((identicalPath) => {
|
586
|
-
plain = setDeep(plain, parsePath(identicalPath), () => plain);
|
587
|
-
});
|
588
|
-
if (other) {
|
589
|
-
forEach(other, apply);
|
590
|
-
}
|
591
|
-
} else {
|
592
|
-
forEach(annotations, apply);
|
593
|
-
}
|
594
|
-
return plain;
|
595
|
-
}
|
596
|
-
var isDeep = (object, superJson) => isPlainObject(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson);
|
597
|
-
function addIdentity(object, path, identities) {
|
598
|
-
const existingSet = identities.get(object);
|
599
|
-
if (existingSet) {
|
600
|
-
existingSet.push(path);
|
601
|
-
} else {
|
602
|
-
identities.set(object, [path]);
|
603
|
-
}
|
604
|
-
}
|
605
|
-
function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
606
|
-
const result = {};
|
607
|
-
let rootEqualityPaths = void 0;
|
608
|
-
identitites.forEach((paths) => {
|
609
|
-
if (paths.length <= 1) {
|
610
|
-
return;
|
611
|
-
}
|
612
|
-
if (!dedupe) {
|
613
|
-
paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
|
614
|
-
}
|
615
|
-
const [representativePath, ...identicalPaths] = paths;
|
616
|
-
if (representativePath.length === 0) {
|
617
|
-
rootEqualityPaths = identicalPaths.map(stringifyPath);
|
618
|
-
} else {
|
619
|
-
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
620
|
-
}
|
621
|
-
});
|
622
|
-
if (rootEqualityPaths) {
|
623
|
-
if (isEmptyObject(result)) {
|
624
|
-
return [rootEqualityPaths];
|
625
|
-
} else {
|
626
|
-
return [rootEqualityPaths, result];
|
627
|
-
}
|
628
|
-
} else {
|
629
|
-
return isEmptyObject(result) ? void 0 : result;
|
630
|
-
}
|
631
|
-
}
|
632
|
-
var walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
633
|
-
const primitive = isPrimitive(object);
|
634
|
-
if (!primitive) {
|
635
|
-
addIdentity(object, path, identities);
|
636
|
-
const seen = seenObjects.get(object);
|
637
|
-
if (seen) {
|
638
|
-
return dedupe ? {
|
639
|
-
transformedValue: null
|
640
|
-
} : seen;
|
641
|
-
}
|
642
|
-
}
|
643
|
-
if (!isDeep(object, superJson)) {
|
644
|
-
const transformed2 = transformValue(object, superJson);
|
645
|
-
const result2 = transformed2 ? {
|
646
|
-
transformedValue: transformed2.value,
|
647
|
-
annotations: [transformed2.type]
|
648
|
-
} : {
|
649
|
-
transformedValue: object
|
650
|
-
};
|
651
|
-
if (!primitive) {
|
652
|
-
seenObjects.set(object, result2);
|
653
|
-
}
|
654
|
-
return result2;
|
655
|
-
}
|
656
|
-
if (includes(objectsInThisPath, object)) {
|
657
|
-
return {
|
658
|
-
transformedValue: null
|
659
|
-
};
|
660
|
-
}
|
661
|
-
const transformationResult = transformValue(object, superJson);
|
662
|
-
const transformed = transformationResult?.value ?? object;
|
663
|
-
const transformedValue = isArray(transformed) ? [] : {};
|
664
|
-
const innerAnnotations = {};
|
665
|
-
forEach(transformed, (value, index) => {
|
666
|
-
if (index === "__proto__" || index === "constructor" || index === "prototype") {
|
667
|
-
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
668
|
-
}
|
669
|
-
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
|
670
|
-
transformedValue[index] = recursiveResult.transformedValue;
|
671
|
-
if (isArray(recursiveResult.annotations)) {
|
672
|
-
innerAnnotations[index] = recursiveResult.annotations;
|
673
|
-
} else if (isPlainObject(recursiveResult.annotations)) {
|
674
|
-
forEach(recursiveResult.annotations, (tree, key) => {
|
675
|
-
innerAnnotations[escapeKey(index) + "." + key] = tree;
|
676
|
-
});
|
677
|
-
}
|
678
|
-
});
|
679
|
-
const result = isEmptyObject(innerAnnotations) ? {
|
680
|
-
transformedValue,
|
681
|
-
annotations: !!transformationResult ? [transformationResult.type] : void 0
|
682
|
-
} : {
|
683
|
-
transformedValue,
|
684
|
-
annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
|
685
|
-
};
|
686
|
-
if (!primitive) {
|
687
|
-
seenObjects.set(object, result);
|
688
|
-
}
|
689
|
-
return result;
|
690
|
-
};
|
691
|
-
|
692
|
-
// ../../node_modules/.pnpm/is-what@4.1.16/node_modules/is-what/dist/index.js
|
693
|
-
function getType2(payload) {
|
694
|
-
return Object.prototype.toString.call(payload).slice(8, -1);
|
695
|
-
}
|
696
|
-
function isArray2(payload) {
|
697
|
-
return getType2(payload) === "Array";
|
698
|
-
}
|
699
|
-
function isPlainObject2(payload) {
|
700
|
-
if (getType2(payload) !== "Object")
|
701
|
-
return false;
|
702
|
-
const prototype = Object.getPrototypeOf(payload);
|
703
|
-
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
704
|
-
}
|
705
|
-
function isNull2(payload) {
|
706
|
-
return getType2(payload) === "Null";
|
707
|
-
}
|
708
|
-
function isOneOf(a, b, c, d, e) {
|
709
|
-
return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
|
710
|
-
}
|
711
|
-
function isUndefined2(payload) {
|
712
|
-
return getType2(payload) === "Undefined";
|
713
|
-
}
|
714
|
-
var isNullOrUndefined = isOneOf(isNull2, isUndefined2);
|
715
|
-
|
716
|
-
// ../../node_modules/.pnpm/copy-anything@3.0.5/node_modules/copy-anything/dist/index.js
|
717
|
-
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
718
|
-
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
719
|
-
if (propType === "enumerable")
|
720
|
-
carry[key] = newVal;
|
721
|
-
if (includeNonenumerable && propType === "nonenumerable") {
|
722
|
-
Object.defineProperty(carry, key, {
|
723
|
-
value: newVal,
|
724
|
-
enumerable: false,
|
725
|
-
writable: true,
|
726
|
-
configurable: true
|
727
|
-
});
|
728
|
-
}
|
729
|
-
}
|
730
|
-
function copy(target, options = {}) {
|
731
|
-
if (isArray2(target)) {
|
732
|
-
return target.map((item) => copy(item, options));
|
733
|
-
}
|
734
|
-
if (!isPlainObject2(target)) {
|
735
|
-
return target;
|
736
|
-
}
|
737
|
-
const props = Object.getOwnPropertyNames(target);
|
738
|
-
const symbols = Object.getOwnPropertySymbols(target);
|
739
|
-
return [...props, ...symbols].reduce((carry, key) => {
|
740
|
-
if (isArray2(options.props) && !options.props.includes(key)) {
|
741
|
-
return carry;
|
742
|
-
}
|
743
|
-
const val = target[key];
|
744
|
-
const newVal = copy(val, options);
|
745
|
-
assignProp(carry, key, newVal, target, options.nonenumerable);
|
746
|
-
return carry;
|
747
|
-
}, {});
|
748
|
-
}
|
749
|
-
|
750
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/index.js
|
751
|
-
var SuperJSON = class {
|
752
|
-
/**
|
753
|
-
* @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
754
|
-
*/
|
755
|
-
constructor({ dedupe = false } = {}) {
|
756
|
-
this.classRegistry = new ClassRegistry();
|
757
|
-
this.symbolRegistry = new Registry((s) => s.description ?? "");
|
758
|
-
this.customTransformerRegistry = new CustomTransformerRegistry();
|
759
|
-
this.allowedErrorProps = [];
|
760
|
-
this.dedupe = dedupe;
|
761
|
-
}
|
762
|
-
serialize(object) {
|
763
|
-
const identities = /* @__PURE__ */ new Map();
|
764
|
-
const output = walker(object, identities, this, this.dedupe);
|
765
|
-
const res = {
|
766
|
-
json: output.transformedValue
|
767
|
-
};
|
768
|
-
if (output.annotations) {
|
769
|
-
res.meta = {
|
770
|
-
...res.meta,
|
771
|
-
values: output.annotations
|
772
|
-
};
|
773
|
-
}
|
774
|
-
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
775
|
-
if (equalityAnnotations) {
|
776
|
-
res.meta = {
|
777
|
-
...res.meta,
|
778
|
-
referentialEqualities: equalityAnnotations
|
779
|
-
};
|
780
|
-
}
|
781
|
-
return res;
|
782
|
-
}
|
783
|
-
deserialize(payload) {
|
784
|
-
const { json, meta } = payload;
|
785
|
-
let result = copy(json);
|
786
|
-
if (meta?.values) {
|
787
|
-
result = applyValueAnnotations(result, meta.values, this);
|
788
|
-
}
|
789
|
-
if (meta?.referentialEqualities) {
|
790
|
-
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities);
|
791
|
-
}
|
792
|
-
return result;
|
793
|
-
}
|
794
|
-
stringify(object) {
|
795
|
-
return JSON.stringify(this.serialize(object));
|
796
|
-
}
|
797
|
-
parse(string) {
|
798
|
-
return this.deserialize(JSON.parse(string));
|
799
|
-
}
|
800
|
-
registerClass(v, options) {
|
801
|
-
this.classRegistry.register(v, options);
|
802
|
-
}
|
803
|
-
registerSymbol(v, identifier) {
|
804
|
-
this.symbolRegistry.register(v, identifier);
|
805
|
-
}
|
806
|
-
registerCustom(transformer, name) {
|
807
|
-
this.customTransformerRegistry.register({
|
808
|
-
name,
|
809
|
-
...transformer
|
810
|
-
});
|
811
|
-
}
|
812
|
-
allowErrorProps(...props) {
|
813
|
-
this.allowedErrorProps.push(...props);
|
814
|
-
}
|
815
|
-
};
|
816
|
-
SuperJSON.defaultInstance = new SuperJSON();
|
817
|
-
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
818
|
-
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
819
|
-
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
820
|
-
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
821
|
-
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
822
|
-
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
823
|
-
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
824
|
-
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
825
|
-
var serialize = SuperJSON.serialize;
|
826
|
-
var deserialize = SuperJSON.deserialize;
|
827
|
-
var stringify = SuperJSON.stringify;
|
828
|
-
var parse = SuperJSON.parse;
|
829
|
-
var registerClass = SuperJSON.registerClass;
|
830
|
-
var registerCustom = SuperJSON.registerCustom;
|
831
|
-
var registerSymbol = SuperJSON.registerSymbol;
|
832
|
-
var allowErrorProps = SuperJSON.allowErrorProps;
|
833
|
-
|
834
|
-
// ../protocol/serde.ts
|
835
|
-
var registerBufferSerde = () => registerCustom(
|
836
|
-
{
|
837
|
-
isApplicable: (v) => v?.constructor?.name === "Buffer",
|
838
|
-
serialize: (v) => stringify(new Uint8Array(v)),
|
839
|
-
deserialize: (v) => parse(v)
|
840
|
-
},
|
841
|
-
"buffer"
|
842
|
-
);
|
843
|
-
var registerDecimalSerde = () => registerCustom(
|
844
|
-
{
|
845
|
-
isApplicable: (v) => {
|
846
|
-
return v !== null && typeof v === "object" && typeof Reflect.get(v, "s") === "number" && typeof Reflect.get(v, "e") === "number" && typeof Reflect.get(v, "toFixed") === "function" && Array.isArray(Reflect.get(v, "d"));
|
847
|
-
},
|
848
|
-
serialize: (_v) => {
|
849
|
-
throw new Error("Decimal is not yet supported");
|
850
|
-
},
|
851
|
-
deserialize: (_v) => {
|
852
|
-
new Error("Decimal is not yet supported");
|
853
|
-
}
|
854
|
-
},
|
855
|
-
"decimaljs"
|
856
|
-
);
|
857
|
-
var registerSerde = () => {
|
858
|
-
registerBufferSerde();
|
859
|
-
registerDecimalSerde();
|
860
|
-
};
|
861
|
-
|
862
|
-
// ../protocol/index.ts
|
863
|
-
var getModelSequenceStep = import_zod.z.tuple([import_zod.z.literal("GET").describe("kind"), import_zod.z.string().min(1).describe("model")]);
|
864
|
-
var operation = import_zod.z.enum([
|
865
|
-
"findMany",
|
866
|
-
"findFirst",
|
867
|
-
"count",
|
868
|
-
"findFirstOrThrow",
|
869
|
-
"findUnique",
|
870
|
-
"findUniqueOrThrow",
|
871
|
-
// "findRaw",
|
872
|
-
"create",
|
873
|
-
"update",
|
874
|
-
"delete",
|
875
|
-
"upsert",
|
876
|
-
"createMany",
|
877
|
-
"updateMany",
|
878
|
-
"deleteMany",
|
879
|
-
"createManyAndReturn",
|
880
|
-
"updateManyAndReturn",
|
881
|
-
"aggregate",
|
882
|
-
"groupBy",
|
883
|
-
// "aggregateRaw",
|
884
|
-
"subscribe"
|
885
|
-
// 'stream'
|
886
|
-
]);
|
887
|
-
var getOperationSequenceStep = import_zod.z.tuple([import_zod.z.literal("GET").describe("kind"), operation]);
|
888
|
-
var callSequenceStep = import_zod.z.tuple([
|
889
|
-
import_zod.z.literal("CALL").describe("kind"),
|
890
|
-
import_zod.z.array(import_zod.z.unknown()).readonly().describe("args")
|
891
|
-
]);
|
892
|
-
var waitSequenceStep = import_zod.z.tuple([import_zod.z.literal("WAIT").describe("kind")]);
|
893
|
-
var commitITXSequenceStep = import_zod.z.tuple([import_zod.z.literal("COMMIT_ITX").describe("kind")]);
|
894
|
-
var rollbackITXSequenceStep = import_zod.z.tuple([import_zod.z.literal("ROLLBACK_ITX").describe("kind")]);
|
895
|
-
var modelOperationSequence = import_zod.z.tuple([
|
896
|
-
getModelSequenceStep,
|
897
|
-
getOperationSequenceStep,
|
898
|
-
callSequenceStep.describe("args"),
|
899
|
-
waitSequenceStep.describe("then")
|
900
|
-
]);
|
901
|
-
var commitTransactionSequence = import_zod.z.tuple([commitITXSequenceStep]);
|
902
|
-
var rollbackTransactionSequence = import_zod.z.tuple([rollbackITXSequenceStep]);
|
903
|
-
var sequence = import_zod.z.union([modelOperationSequence, commitTransactionSequence, rollbackTransactionSequence]);
|
904
|
-
var sequenceRequest = import_zod.z.object({
|
905
|
-
kind: import_zod.z.literal("SEQUENCE_REQUEST"),
|
906
|
-
globalContext: import_zod.z.unknown().nullish(),
|
907
|
-
uuid: import_zod.z.string().min(1),
|
908
|
-
sequence,
|
909
|
-
version: import_zod.z.string().nullish()
|
910
|
-
});
|
911
|
-
var serializedSequenceResponseSymbol = Symbol("SequenceResponse");
|
912
|
-
|
913
|
-
// src/policyClient.ts
|
914
|
-
registerSerde();
|
915
|
-
var kind = "SEQUENCE_REQUEST";
|
916
|
-
var PROD_DISPATCHER_URL = "wss://policy-dispatcher.datacdn.workers.dev/";
|
917
|
-
var CONNECTION_TIMEOUT = 3e4;
|
918
|
-
var CONNECTION_STALE = 15e3;
|
919
|
-
function trap(ctx) {
|
920
|
-
return new Proxy(() => {
|
921
|
-
}, {
|
922
|
-
apply: onCall(ctx),
|
923
|
-
get: onGet(ctx)
|
924
|
-
});
|
925
|
-
}
|
926
|
-
function forkPayload(payload) {
|
927
|
-
return {
|
928
|
-
kind,
|
929
|
-
uuid: crypto.randomUUID(),
|
930
|
-
sequence: [...payload?.sequence ?? []],
|
931
|
-
globalContext: payload?.globalContext
|
932
|
-
};
|
933
|
-
}
|
934
|
-
async function callItx({ ws: prevWs, args }) {
|
935
|
-
const { url, searchParams } = prevWs.args;
|
936
|
-
const [cb, ..._txArgs] = args;
|
937
|
-
const uuid = crypto.randomUUID();
|
938
|
-
const itxws = createWsScheduler({ url, searchParams: { ...searchParams, itx: JSON.stringify(args) } });
|
939
|
-
const result = cb(trap({ ws: itxws }));
|
940
|
-
void result.then(() => itxws.send({ kind, uuid, sequence: [["COMMIT_ITX"]] })).catch(() => itxws.send({ kind, uuid, sequence: [["ROLLBACK_ITX"]] }));
|
941
|
-
return await result;
|
942
|
-
}
|
943
|
-
async function callBatchTx() {
|
944
|
-
throw new Error("Batch transactions are not yet supported");
|
945
|
-
}
|
946
|
-
function onCall({ ws, ...ctx }) {
|
947
|
-
return (_target, _that, args) => {
|
948
|
-
if (ctx.prop === "$transaction") {
|
949
|
-
if (typeof args[0] === "function") {
|
950
|
-
return callItx({ ws, args });
|
951
|
-
} else {
|
952
|
-
return callBatchTx();
|
953
|
-
}
|
954
|
-
}
|
955
|
-
const payload = forkPayload(ctx.payload);
|
956
|
-
payload.sequence.push(["CALL", args]);
|
957
|
-
return trap({ ws, payload });
|
958
|
-
};
|
959
|
-
}
|
960
|
-
function onGetAsyncProp({ ws, payload, prop }) {
|
961
|
-
payload.sequence.push(["WAIT"]);
|
962
|
-
if (payload.sequence?.[1]?.[1] === "subscribe") {
|
963
|
-
const model = payload.sequence?.[0]?.[1];
|
964
|
-
const queue = ws.pulseQueue.get(model);
|
965
|
-
if (queue === void 0) {
|
966
|
-
const response3 = ws.send(payload).then(() => {
|
967
|
-
return ws.pulseQueue.subscribe(model, payload);
|
968
|
-
});
|
969
|
-
return response3[prop].bind(response3);
|
970
|
-
}
|
971
|
-
const response2 = Promise.resolve(queue);
|
972
|
-
return response2[prop].bind(response2);
|
973
|
-
}
|
974
|
-
const response = ws.send(payload);
|
975
|
-
return response[prop].bind(response);
|
976
|
-
}
|
977
|
-
function onGetPolicyProp(_) {
|
978
|
-
return {
|
979
|
-
setGlobalContext(context) {
|
980
|
-
globalContext = context;
|
981
|
-
}
|
982
|
-
};
|
983
|
-
}
|
984
|
-
function onGet({ ws, ...ctx }) {
|
985
|
-
return (_target, prop) => {
|
986
|
-
const payload = forkPayload(ctx.payload);
|
987
|
-
if (prop === "then" || prop === "catch" || prop === "finally") {
|
988
|
-
return onGetAsyncProp({ ws, payload, prop });
|
989
|
-
}
|
990
|
-
if (prop === "$policy") {
|
991
|
-
return onGetPolicyProp({ ws, payload, prop });
|
992
|
-
}
|
993
|
-
payload.sequence.push(["GET", prop]);
|
994
|
-
if (isModelFieldReferenceGet(payload.sequence)) {
|
995
|
-
throw new Error("Model field references are not yet supported");
|
996
|
-
}
|
997
|
-
return trap({ ...ctx, ws, payload, prop });
|
998
|
-
};
|
999
|
-
}
|
1000
|
-
function isModelFieldReferenceGet(sequence2) {
|
1001
|
-
return sequence2[0]?.[0] === "GET" && sequence2[1]?.[0] === "GET" && sequence2[1]?.[1] === "fields";
|
1002
|
-
}
|
1003
|
-
function createWsScheduler(args = {}) {
|
1004
|
-
const waited = {};
|
1005
|
-
const { url = PROD_DISPATCHER_URL, searchParams = {} } = args;
|
1006
|
-
const pulseQueue = createPulseMessageQueueManager();
|
1007
|
-
let primaryConnection;
|
1008
|
-
async function getConnection() {
|
1009
|
-
if (primaryConnection === void 0) {
|
1010
|
-
return await openConnection();
|
1011
|
-
}
|
1012
|
-
const { ws, date } = primaryConnection;
|
1013
|
-
if (ws === void 0 || Date.now() - date >= CONNECTION_STALE) {
|
1014
|
-
setTimeout(() => ws?.close(), CONNECTION_TIMEOUT);
|
1015
|
-
return await openConnection();
|
1016
|
-
}
|
1017
|
-
return { ws, date };
|
1018
|
-
}
|
1019
|
-
async function openConnection(retries = 0) {
|
1020
|
-
const isFirstConnection = primaryConnection === void 0;
|
1021
|
-
const connection = await new Promise((res, rej) => {
|
1022
|
-
const ws = new WebSocket(`${url}?${new URLSearchParams(searchParams).toString()}`);
|
1023
|
-
const date = Date.now();
|
1024
|
-
ws.addEventListener("error", () => rej());
|
1025
|
-
ws.addEventListener("open", () => res({ ws, date }));
|
1026
|
-
ws.addEventListener("close", () => delete connection.ws);
|
1027
|
-
ws.addEventListener("message", ({ data }) => {
|
1028
|
-
const response = parse(data);
|
1029
|
-
if (response.kind === "SEQUENCE_PULSE_EVENT") {
|
1030
|
-
pulseQueue.push(response.result);
|
1031
|
-
}
|
1032
|
-
if (response.kind === "SEQUENCE_RESPONSE_ALLOW") {
|
1033
|
-
waited[response.uuid]?.resolve(response.result);
|
1034
|
-
}
|
1035
|
-
if (response.kind === "SEQUENCE_RESPONSE_DENY") {
|
1036
|
-
waited[response.uuid]?.reject(new Error(response.reason));
|
1037
|
-
}
|
1038
|
-
if (response.kind === "SEQUENCE_RESPONSE_ERROR") {
|
1039
|
-
waited[response.uuid]?.reject(new Error(response.reason));
|
1040
|
-
}
|
1041
|
-
if (response.uuid)
|
1042
|
-
delete waited[response.uuid];
|
1043
|
-
});
|
1044
|
-
}).catch(async () => {
|
1045
|
-
await new Promise((r) => setTimeout(r, 1e3 * retries));
|
1046
|
-
console.warn(`Failed to connect to the server, retrying...`);
|
1047
|
-
return await openConnection(retries + 1);
|
1048
|
-
});
|
1049
|
-
primaryConnection = connection;
|
1050
|
-
if (isFirstConnection === false) {
|
1051
|
-
pulseQueue.getSequenceRequests().forEach((request) => {
|
1052
|
-
send(request).catch(console.error);
|
1053
|
-
});
|
1054
|
-
}
|
1055
|
-
return primaryConnection;
|
1056
|
-
}
|
1057
|
-
async function send(request) {
|
1058
|
-
let res;
|
1059
|
-
const promise = new Promise((...args2) => res = args2);
|
1060
|
-
const [resolve, reject] = res;
|
1061
|
-
request.globalContext = globalContext;
|
1062
|
-
waited[request.uuid] = { resolve, reject };
|
1063
|
-
(await getConnection()).ws.send(stringify(request));
|
1064
|
-
const timeout = setTimeout(() => {
|
1065
|
-
waited[request.uuid]?.reject(new Error("Operation timed out"));
|
1066
|
-
delete waited[request.uuid];
|
1067
|
-
}, CONNECTION_TIMEOUT);
|
1068
|
-
return await promise.finally(() => clearTimeout(timeout));
|
1069
|
-
}
|
1070
|
-
return { send, args, pulseQueue };
|
1071
|
-
}
|
1072
|
-
function createMessageQueue() {
|
1073
|
-
let queue = [];
|
1074
|
-
let unlock;
|
1075
|
-
return {
|
1076
|
-
push(item) {
|
1077
|
-
queue.push(item);
|
1078
|
-
unlock?.();
|
1079
|
-
},
|
1080
|
-
async *[Symbol.asyncIterator]() {
|
1081
|
-
yield* queue;
|
1082
|
-
queue = [];
|
1083
|
-
await new Promise((r) => unlock = r);
|
1084
|
-
yield* this[Symbol.asyncIterator]();
|
1085
|
-
}
|
1086
|
-
};
|
1087
|
-
}
|
1088
|
-
function createPulseMessageQueueManager() {
|
1089
|
-
const queues = {};
|
1090
|
-
const sequenceRequests = {};
|
1091
|
-
const seenEvents = {};
|
1092
|
-
setInterval(() => {
|
1093
|
-
for (const [id, date] of Object.entries(seenEvents)) {
|
1094
|
-
if (Date.now() - date >= CONNECTION_TIMEOUT) {
|
1095
|
-
delete seenEvents[id];
|
1096
|
-
}
|
1097
|
-
}
|
1098
|
-
}, CONNECTION_TIMEOUT);
|
1099
|
-
return {
|
1100
|
-
get(model) {
|
1101
|
-
return queues[model];
|
1102
|
-
},
|
1103
|
-
subscribe(model, payload) {
|
1104
|
-
if (this.get(model) === void 0) {
|
1105
|
-
queues[model] = createMessageQueue();
|
1106
|
-
sequenceRequests[model] = payload;
|
1107
|
-
}
|
1108
|
-
return queues[model];
|
1109
|
-
},
|
1110
|
-
unsubscribe(model) {
|
1111
|
-
delete queues[model];
|
1112
|
-
},
|
1113
|
-
push(result) {
|
1114
|
-
if (seenEvents[result.id] === void 0) {
|
1115
|
-
queues[getPulseModelName(result)]?.push(result);
|
1116
|
-
seenEvents[result.id] = Date.now();
|
1117
|
-
}
|
1118
|
-
},
|
1119
|
-
getSequenceRequests() {
|
1120
|
-
return Object.values(sequenceRequests);
|
1121
|
-
}
|
1122
|
-
};
|
1123
|
-
}
|
1124
|
-
function getPulseModelName(result) {
|
1125
|
-
return result.modelName[0].toLowerCase() + result.modelName.slice(1);
|
1126
|
-
}
|
1127
|
-
function policyClient(args) {
|
1128
|
-
const { url, publicKey } = args;
|
1129
|
-
return trap({ ws: createWsScheduler({ url, searchParams: { publicKey } }) });
|
1130
|
-
}
|
1131
|
-
var globalContext;
|
1132
|
-
var PolicyClient = policyClient;
|
1133
|
-
// Annotate the CommonJS export names for ESM import in node:
|
1134
|
-
0 && (module.exports = {
|
1135
|
-
PolicyClient,
|
1136
|
-
withPolicy
|
1137
|
-
});
|
1
|
+
"use strict";var B=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},Ke=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ie(t))!Ne.call(e,s)&&s!==n&&B(e,s,{get:()=>t[s],enumerable:!(r=Pe(t,s))||r.enumerable});return e};var Me=e=>Ke(B({},"__esModule",{value:!0}),e);var gt={};_e(gt,{AuthorizedClient:()=>Te,defineRules:()=>ee});module.exports=Me(gt);function ee(e){let{prisma:t,rules:n}=e;return Object.assign(t,{$rules:{setGlobalContext(r){},contextSchema:e.contextSchema?.["~standard"],rules:n}})}var c=require("zod");var P=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(t,n){this.keyToValue.set(t,n),this.valueToKey.set(n,t)}getByKey(t){return this.keyToValue.get(t)}getByValue(t){return this.valueToKey.get(t)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}};var b=class{constructor(t){this.generateIdentifier=t,this.kv=new P}register(t,n){this.kv.getByValue(t)||(n||(n=this.generateIdentifier(t)),this.kv.set(n,t))}clear(){this.kv.clear()}getIdentifier(t){return this.kv.getByValue(t)}getValue(t){return this.kv.getByKey(t)}};var I=class extends b{constructor(){super(t=>t.name),this.classToAllowedProps=new Map}register(t,n){typeof n=="object"?(n.allowProps&&this.classToAllowedProps.set(t,n.allowProps),super.register(t,n.identifier)):super.register(t,n)}getAllowedProps(t){return this.classToAllowedProps.get(t)}};function Ve(e){if("values"in Object)return Object.values(e);let t=[];for(let n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t}function te(e,t){let n=Ve(e);if("find"in n)return n.find(t);let r=n;for(let s=0;s<r.length;s++){let o=r[s];if(t(o))return o}}function w(e,t){Object.entries(e).forEach(([n,r])=>t(r,n))}function A(e,t){return e.indexOf(t)!==-1}function L(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return r}}var N=class{constructor(){this.transfomers={}}register(t){this.transfomers[t.name]=t}findApplicable(t){return te(this.transfomers,n=>n.isApplicable(t))}findByName(t){return this.transfomers[t]}};var Ue=e=>Object.prototype.toString.call(e).slice(8,-1),v=e=>typeof e>"u",ze=e=>e===null,C=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,_=e=>C(e)&&Object.keys(e).length===0,x=e=>Array.isArray(e),De=e=>typeof e=="string",Be=e=>typeof e=="number"&&!isNaN(e),Le=e=>typeof e=="boolean",ne=e=>e instanceof RegExp,R=e=>e instanceof Map,h=e=>e instanceof Set,$=e=>Ue(e)==="Symbol",re=e=>e instanceof Date&&!isNaN(e.valueOf()),se=e=>e instanceof Error,j=e=>typeof e=="number"&&isNaN(e),oe=e=>Le(e)||ze(e)||v(e)||Be(e)||De(e)||$(e),ie=e=>typeof e=="bigint",ae=e=>e===1/0||e===-1/0,ue=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),ce=e=>e instanceof URL;var G=e=>e.replace(/\./g,"\\."),K=e=>e.map(String).map(G).join("."),E=e=>{let t=[],n="";for(let s=0;s<e.length;s++){let o=e.charAt(s);if(o==="\\"&&e.charAt(s+1)==="."){n+=".",s++;continue}if(o==="."){t.push(n),n="";continue}n+=o}let r=n;return t.push(r),t};function O(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var le=[O(v,"undefined",()=>null,()=>{}),O(ie,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):(console.error("Please add a BigInt polyfill."),e)),O(re,"Date",e=>e.toISOString(),e=>new Date(e)),O(se,"Error",(e,t)=>{let n={name:e.name,message:e.message};return t.allowedErrorProps.forEach(r=>{n[r]=e[r]}),n},(e,t)=>{let n=new Error(e.message);return n.name=e.name,n.stack=e.stack,t.allowedErrorProps.forEach(r=>{n[r]=e[r]}),n}),O(ne,"regexp",e=>""+e,e=>{let t=e.slice(1,e.lastIndexOf("/")),n=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,n)}),O(h,"set",e=>[...e.values()],e=>new Set(e)),O(R,"map",e=>[...e.entries()],e=>new Map(e)),O(e=>j(e)||ae(e),"number",e=>j(e)?"NaN":e>0?"Infinity":"-Infinity",Number),O(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),O(ce,"URL",e=>e.toString(),e=>new URL(e))];function M(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var pe=M((e,t)=>$(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,n)=>{let r=n.symbolRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown symbol");return r}),ve=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),fe=M(ue,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{let n=ve[t[1]];if(!n)throw new Error("Trying to deserialize unknown typed array");return new n(e)});function F(e,t){return e?.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var de=M(F,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{let n=t.classRegistry.getAllowedProps(e.constructor);if(!n)return{...e};let r={};return n.forEach(s=>{r[s]=e[s]}),r},(e,t,n)=>{let r=n.classRegistry.getValue(t[1]);if(!r)throw new Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(r.prototype),e)}),ye=M((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,n)=>{let r=n.customTransformerRegistry.findByName(t[1]);if(!r)throw new Error("Trying to deserialize unknown custom value");return r.deserialize(e)}),$e=[de,pe,ye,fe],X=(e,t)=>{let n=L($e,s=>s.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation(e,t)};let r=L(le,s=>s.isApplicable(e,t));if(r)return{value:r.transform(e,t),type:r.annotation}},me={};le.forEach(e=>{me[e.annotation]=e});var xe=(e,t,n)=>{if(x(t))switch(t[0]){case"symbol":return pe.untransform(e,t,n);case"class":return de.untransform(e,t,n);case"custom":return ye.untransform(e,t,n);case"typed-array":return fe.untransform(e,t,n);default:throw new Error("Unknown transformation: "+t)}else{let r=me[t];if(!r)throw new Error("Unknown transformation: "+t);return r.untransform(e,n)}};var T=(e,t)=>{if(t>e.size)throw new Error("index out of bounds");let n=e.keys();for(;t>0;)n.next(),t--;return n.next().value};function Se(e){if(A(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(A(e,"prototype"))throw new Error("prototype is not allowed as a property");if(A(e,"constructor"))throw new Error("constructor is not allowed as a property")}var Oe=(e,t)=>{Se(t);for(let n=0;n<t.length;n++){let r=t[n];if(h(e))e=T(e,+r);else if(R(e)){let s=+r,o=+t[++n]==0?"key":"value",i=T(e,s);switch(o){case"key":e=i;break;case"value":e=e.get(i);break}}else e=e[r]}return e},V=(e,t,n)=>{if(Se(t),t.length===0)return n(e);let r=e;for(let o=0;o<t.length-1;o++){let i=t[o];if(x(r)){let l=+i;r=r[l]}else if(C(r))r=r[i];else if(h(r)){let l=+i;r=T(r,l)}else if(R(r)){if(o===t.length-2)break;let u=+i,d=+t[++o]==0?"key":"value",y=T(r,u);switch(d){case"key":r=y;break;case"value":r=r.get(y);break}}}let s=t[t.length-1];if(x(r)?r[+s]=n(r[+s]):C(r)&&(r[s]=n(r[s])),h(r)){let o=T(r,+s),i=n(o);o!==i&&(r.delete(o),r.add(i))}if(R(r)){let o=+t[t.length-2],i=T(r,o);switch(+s==0?"key":"value"){case"key":{let u=n(i);r.set(u,r.get(i)),u!==i&&r.delete(i);break}case"value":{r.set(i,n(r.get(i)));break}}}return e};function Q(e,t,n=[]){if(!e)return;if(!x(e)){w(e,(o,i)=>Q(o,t,[...n,...E(i)]));return}let[r,s]=e;s&&w(s,(o,i)=>{Q(o,t,[...n,...E(i)])}),t(r,n)}function ge(e,t,n){return Q(t,(r,s)=>{e=V(e,s,o=>xe(o,r,n))}),e}function Re(e,t){function n(r,s){let o=Oe(e,E(s));r.map(E).forEach(i=>{e=V(e,i,()=>o)})}if(x(t)){let[r,s]=t;r.forEach(o=>{e=V(e,E(o),()=>e)}),s&&w(s,n)}else w(t,n);return e}var je=(e,t)=>C(e)||x(e)||R(e)||h(e)||F(e,t);function Ge(e,t,n){let r=n.get(e);r?r.push(t):n.set(e,[t])}function he(e,t){let n={},r;return e.forEach(s=>{if(s.length<=1)return;t||(s=s.map(l=>l.map(String)).sort((l,u)=>l.length-u.length));let[o,...i]=s;o.length===0?r=i.map(K):n[K(o)]=i.map(K)}),r?_(n)?[r]:[r,n]:_(n)?void 0:n}var Y=(e,t,n,r,s=[],o=[],i=new Map)=>{let l=oe(e);if(!l){Ge(e,s,t);let m=i.get(e);if(m)return r?{transformedValue:null}:m}if(!je(e,n)){let m=X(e,n),f=m?{transformedValue:m.value,annotations:[m.type]}:{transformedValue:e};return l||i.set(e,f),f}if(A(o,e))return{transformedValue:null};let u=X(e,n),d=u?.value??e,y=x(d)?[]:{},g={};w(d,(m,f)=>{if(f==="__proto__"||f==="constructor"||f==="prototype")throw new Error(`Detected property ${f}. This is a prototype pollution risk, please remove it from your object.`);let p=Y(m,t,n,r,[...s,f],[...o,e],i);y[f]=p.transformedValue,x(p.annotations)?g[f]=p.annotations:C(p.annotations)&&w(p.annotations,(qe,ke)=>{g[G(f)+"."+ke]=qe})});let S=_(g)?{transformedValue:y,annotations:u?[u.type]:void 0}:{transformedValue:y,annotations:u?[u.type,g]:g};return l||i.set(e,S),S};function U(e){return Object.prototype.toString.call(e).slice(8,-1)}function W(e){return U(e)==="Array"}function we(e){if(U(e)!=="Object")return!1;let t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function Fe(e){return U(e)==="Null"}function Xe(e,t,n,r,s){return o=>e(o)||t(o)||!!n&&n(o)||!!r&&r(o)||!!s&&s(o)}function Qe(e){return U(e)==="Undefined"}var Gt=Xe(Fe,Qe);function Ye(e,t,n,r,s){let o={}.propertyIsEnumerable.call(r,t)?"enumerable":"nonenumerable";o==="enumerable"&&(e[t]=n),s&&o==="nonenumerable"&&Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})}function z(e,t={}){if(W(e))return e.map(s=>z(s,t));if(!we(e))return e;let n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertySymbols(e);return[...n,...r].reduce((s,o)=>{if(W(t.props)&&!t.props.includes(o))return s;let i=e[o],l=z(i,t);return Ye(s,o,l,e,t.nonenumerable),s},{})}var a=class{constructor({dedupe:t=!1}={}){this.classRegistry=new I,this.symbolRegistry=new b(n=>n.description??""),this.customTransformerRegistry=new N,this.allowedErrorProps=[],this.dedupe=t}serialize(t){let n=new Map,r=Y(t,n,this,this.dedupe),s={json:r.transformedValue};r.annotations&&(s.meta={...s.meta,values:r.annotations});let o=he(n,this.dedupe);return o&&(s.meta={...s.meta,referentialEqualities:o}),s}deserialize(t){let{json:n,meta:r}=t,s=z(n);return r?.values&&(s=ge(s,r.values,this)),r?.referentialEqualities&&(s=Re(s,r.referentialEqualities)),s}stringify(t){return JSON.stringify(this.serialize(t))}parse(t){return this.deserialize(JSON.parse(t))}registerClass(t,n){this.classRegistry.register(t,n)}registerSymbol(t,n){this.symbolRegistry.register(t,n)}registerCustom(t,n){this.customTransformerRegistry.register({name:n,...t})}allowErrorProps(...t){this.allowedErrorProps.push(...t)}};a.defaultInstance=new a;a.serialize=a.defaultInstance.serialize.bind(a.defaultInstance);a.deserialize=a.defaultInstance.deserialize.bind(a.defaultInstance);a.stringify=a.defaultInstance.stringify.bind(a.defaultInstance);a.parse=a.defaultInstance.parse.bind(a.defaultInstance);a.registerClass=a.defaultInstance.registerClass.bind(a.defaultInstance);a.registerSymbol=a.defaultInstance.registerSymbol.bind(a.defaultInstance);a.registerCustom=a.defaultInstance.registerCustom.bind(a.defaultInstance);a.allowErrorProps=a.defaultInstance.allowErrorProps.bind(a.defaultInstance);var en=a.serialize,tn=a.deserialize,q=a.stringify,k=a.parse,nn=a.registerClass,H=a.registerCustom,rn=a.registerSymbol,sn=a.allowErrorProps;var We=()=>H({isApplicable:e=>e?.constructor?.name==="Buffer",serialize:e=>q(new Uint8Array(e)),deserialize:e=>k(e)},"buffer"),He=()=>H({isApplicable:e=>e!==null&&typeof e=="object"&&typeof Reflect.get(e,"s")=="number"&&typeof Reflect.get(e,"e")=="number"&&typeof Reflect.get(e,"toFixed")=="function"&&Array.isArray(Reflect.get(e,"d")),serialize:e=>{throw new Error("Decimal is not yet supported")},deserialize:e=>{new Error("Decimal is not yet supported")}},"decimaljs"),Z=()=>{We(),He()};var Ze=c.z.tuple([c.z.literal("GET").describe("kind"),c.z.string().min(1).describe("model")]),Je=c.z.enum(["findMany","findFirst","count","findFirstOrThrow","findUnique","findUniqueOrThrow","create","update","delete","upsert","createMany","updateMany","deleteMany","createManyAndReturn","updateManyAndReturn","aggregate","groupBy"]),et=c.z.tuple([c.z.literal("GET").describe("kind"),Je]),tt=c.z.tuple([c.z.literal("CALL").describe("kind"),c.z.array(c.z.unknown()).readonly().describe("args")]),nt=c.z.tuple([c.z.literal("WAIT").describe("kind")]),rt=c.z.tuple([c.z.literal("COMMIT_ITX").describe("kind")]),st=c.z.tuple([c.z.literal("ROLLBACK_ITX").describe("kind")]),ot=c.z.tuple([Ze,et,tt.describe("args"),nt.describe("then")]),it=c.z.tuple([rt]),at=c.z.tuple([st]),ut=c.z.union([ot,it,at]),ln=c.z.object({kind:c.z.literal("SEQUENCE_REQUEST"),globalContext:c.z.unknown().nullish(),uuid:c.z.string().min(1),sequence:ut,version:c.z.string().nullish()});var pn=Symbol("SequenceResponse");Z();var J="SEQUENCE_REQUEST",ct="wss://rules-dispatcher.datacdn.workers.dev/",Ce=3e4,lt=15e3;function D(e){return new Proxy(()=>{},{apply:dt(e),get:xt(e)})}function be(e){return{kind:J,uuid:crypto.randomUUID(),sequence:[...e?.sequence??[]],globalContext:e?.globalContext}}async function pt({ws:e,args:t}){let{url:n,searchParams:r}=e.args,[s,...o]=t,i=crypto.randomUUID(),l=Ae({url:n,searchParams:{...r,itx:JSON.stringify(t)}}),u=s(D({ws:l}));return u.then(()=>l.send({kind:J,uuid:i,sequence:[["COMMIT_ITX"]]})).catch(()=>l.send({kind:J,uuid:i,sequence:[["ROLLBACK_ITX"]]})),await u}async function ft(){throw new Error("Batch transactions are not yet supported")}function dt({ws:e,...t}){return(n,r,s)=>{if(t.prop==="$transaction")return typeof s[0]=="function"?pt({ws:e,args:s}):ft();let o=be(t.payload);return o.sequence.push(["CALL",s]),D({ws:e,payload:o})}}function yt({ws:e,payload:t,prop:n}){t.sequence.push(["WAIT"]);let r=e.send(t);return r[n].bind(r)}function mt(e){return{setGlobalContext(t){Ee=t}}}function xt({ws:e,...t}){return(n,r)=>{let s=be(t.payload);if(r==="then"||r==="catch"||r==="finally")return yt({ws:e,payload:s,prop:r});if(r==="$rules")return mt({ws:e,payload:s,prop:r});if(s.sequence.push(["GET",r]),St(s.sequence))throw new Error("Model field references are not yet supported");return D({...t,ws:e,payload:s,prop:r})}}function St(e){return e[0]?.[0]==="GET"&&e[1]?.[0]==="GET"&&e[1]?.[1]==="fields"}function Ae(e={}){let t={},{url:n=ct,searchParams:r={}}=e,s;async function o(){if(s===void 0)return await i();let{ws:u,date:d}=s;return u===void 0||Date.now()-d>=lt?(setTimeout(()=>u?.close(),Ce),await i()):{ws:u,date:d}}async function i(u=0){let d=await new Promise((y,g)=>{let S=new WebSocket(`${n}?${new URLSearchParams(r).toString()}`),m=Date.now();S.addEventListener("error",()=>g()),S.addEventListener("open",()=>y({ws:S,date:m})),S.addEventListener("close",()=>delete d.ws),S.addEventListener("message",({data:f})=>{let p=k(f);p.kind==="SEQUENCE_RESPONSE_ALLOW"&&t[p.uuid]?.resolve(p.result),p.kind==="SEQUENCE_RESPONSE_DENY"&&t[p.uuid]?.reject(new Error(p.reason)),p.kind==="SEQUENCE_RESPONSE_ERROR"&&t[p.uuid]?.reject(new Error(p.reason)),p.uuid&&delete t[p.uuid]})}).catch(async()=>(await new Promise(y=>setTimeout(y,1e3*u)),console.warn("Failed to connect to the server, retrying..."),await i(u+1)));return s=d}async function l(u){let d,y=new Promise((...f)=>d=f),[g,S]=d;u.globalContext=Ee,t[u.uuid]={resolve:g,reject:S},(await o()).ws.send(q(u));let m=setTimeout(()=>{t[u.uuid]?.reject(new Error("Operation timed out")),delete t[u.uuid]},Ce);return await y.finally(()=>clearTimeout(m))}return{send:l,args:e}}function Ot(e){let{url:t,publicKey:n}=e;return D({ws:Ae({url:t,searchParams:{publicKey:n}})})}var Ee,Te=Ot;0&&(module.exports={AuthorizedClient,defineRules});
|