prisma-guard 1.26.0 → 1.26.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.
@@ -4429,10 +4429,30 @@ function isGuardShape(obj) {
4429
4429
  function isSingleShape(input) {
4430
4430
  return typeof input === "function" || isGuardShape(input);
4431
4431
  }
4432
+ function toPlainObject(value) {
4433
+ if (value === null || typeof value !== "object")
4434
+ return value;
4435
+ if (Array.isArray(value))
4436
+ return value.map(toPlainObject);
4437
+ if (value instanceof Date)
4438
+ return value;
4439
+ if (value instanceof Uint8Array)
4440
+ return value;
4441
+ if (value instanceof RegExp)
4442
+ return value;
4443
+ if (typeof value.toFixed === "function" && typeof value.toNumber === "function")
4444
+ return value;
4445
+ const result = {};
4446
+ for (const [k, v] of Object.entries(value)) {
4447
+ result[k] = toPlainObject(v);
4448
+ }
4449
+ return result;
4450
+ }
4432
4451
  function requireBody(body) {
4433
- if (!isPlainObject(body))
4452
+ const normalized = toPlainObject(body);
4453
+ if (!isPlainObject(normalized))
4434
4454
  throw new ShapeError("Request body must be an object");
4435
- return body;
4455
+ return normalized;
4436
4456
  }
4437
4457
  function resolveDynamicShape(fn, contextFn) {
4438
4458
  const ctx = validateContext(contextFn());
@@ -5490,15 +5510,15 @@ function createModelGuardExtension(config) {
5490
5510
  }
5491
5511
  return wrapped;
5492
5512
  }
5493
- return {
5494
- $allModels: {
5513
+ const extension = {};
5514
+ for (const modelName of Object.keys(typeMap)) {
5515
+ const key = toDelegateKey(modelName);
5516
+ extension[key] = {
5495
5517
  guard(input, caller) {
5496
- const modelName = this.$name;
5497
- const delegateKey = toDelegateKey(modelName);
5498
- const modelDelegate = this.$parent[delegateKey];
5518
+ const modelDelegate = this.$parent[key];
5499
5519
  if (!modelDelegate) {
5500
5520
  throw new ShapeError(
5501
- `Could not resolve Prisma delegate for model "${modelName}" (key: "${delegateKey}")`
5521
+ `Could not resolve Prisma delegate for model "${modelName}" (key: "${key}")`
5502
5522
  );
5503
5523
  }
5504
5524
  const methods = createGuardedMethods(
@@ -5511,8 +5531,9 @@ function createModelGuardExtension(config) {
5511
5531
  return methods;
5512
5532
  return wrapMethods(methods);
5513
5533
  }
5514
- }
5515
- };
5534
+ };
5535
+ }
5536
+ return extension;
5516
5537
  }
5517
5538
 
5518
5539
  // src/runtime/guard.ts