@ghentcdh/crouton-api 0.0.1-alpha.56 → 0.0.1-alpha.58
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.cjs +81 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1993,7 +1993,9 @@ var import_zod21 = require("zod");
|
|
|
1993
1993
|
var isInstanceOf = /* @__PURE__ */ __name((zodSchema, className) => {
|
|
1994
1994
|
if (!(zodSchema instanceof import_zod21.z.ZodCustom)) return false;
|
|
1995
1995
|
const result = zodSchema.safeParse(null);
|
|
1996
|
-
|
|
1996
|
+
if (result.success) return false;
|
|
1997
|
+
const issue = result.error.issues[0];
|
|
1998
|
+
return issue?.expected === className || (issue?.message?.includes(className) ?? false);
|
|
1997
1999
|
}, "isInstanceOf");
|
|
1998
2000
|
var jsonSchemaOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
|
|
1999
2001
|
if (zodSchema instanceof import_zod21.z.ZodDate) {
|
|
@@ -2003,13 +2005,26 @@ var jsonSchemaOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
|
|
|
2003
2005
|
if (zodSchema instanceof import_zod21.z.ZodBigInt) {
|
|
2004
2006
|
jsonSchema.type = "integer";
|
|
2005
2007
|
}
|
|
2006
|
-
if (isInstanceOf(zodSchema, "Decimal")) {
|
|
2008
|
+
if (isInstanceOf(zodSchema, "Decimal") || isInstanceOf(zodSchema, "Decimal2")) {
|
|
2007
2009
|
jsonSchema.type = "number";
|
|
2008
2010
|
}
|
|
2009
2011
|
if (isInstanceOf(zodSchema, "Buffer")) {
|
|
2010
2012
|
jsonSchema.type = "string";
|
|
2011
2013
|
}
|
|
2012
2014
|
}, "jsonSchemaOverride");
|
|
2015
|
+
var unwrap = /* @__PURE__ */ __name((schema) => {
|
|
2016
|
+
let s = schema;
|
|
2017
|
+
let t = s._zod?.def?.type;
|
|
2018
|
+
while (t === "optional" || t === "nullable" || t === "default" || t === "readonly") {
|
|
2019
|
+
s = s._zod?.def?.innerType ?? s;
|
|
2020
|
+
t = s._zod?.def?.type;
|
|
2021
|
+
}
|
|
2022
|
+
return s;
|
|
2023
|
+
}, "unwrap");
|
|
2024
|
+
var isDecimalField = /* @__PURE__ */ __name((zodType) => {
|
|
2025
|
+
const inner = unwrap(zodType);
|
|
2026
|
+
return isInstanceOf(inner, "Decimal") || isInstanceOf(inner, "Decimal2");
|
|
2027
|
+
}, "isDecimalField");
|
|
2013
2028
|
var jsonSchemaOpts = {
|
|
2014
2029
|
unrepresentable: "any",
|
|
2015
2030
|
override: jsonSchemaOverride
|
|
@@ -5271,7 +5286,7 @@ function toJsonSchema2(schema) {
|
|
|
5271
5286
|
return schema;
|
|
5272
5287
|
}
|
|
5273
5288
|
__name(toJsonSchema2, "toJsonSchema");
|
|
5274
|
-
var
|
|
5289
|
+
var unwrap2 = /* @__PURE__ */ __name((schema) => {
|
|
5275
5290
|
let s = schema;
|
|
5276
5291
|
let t = s?._zod?.def?.type;
|
|
5277
5292
|
while (t === "optional" || t === "nullable" || t === "default" || t === "readonly") {
|
|
@@ -5290,7 +5305,7 @@ function toSelectFields(schema) {
|
|
|
5290
5305
|
}
|
|
5291
5306
|
const result = {};
|
|
5292
5307
|
for (const [key, value] of Object.entries(schema.shape)) {
|
|
5293
|
-
const inner =
|
|
5308
|
+
const inner = unwrap2(value);
|
|
5294
5309
|
const t = typeOf(inner);
|
|
5295
5310
|
if (t === "object") {
|
|
5296
5311
|
result[key] = {
|
|
@@ -5299,7 +5314,7 @@ function toSelectFields(schema) {
|
|
|
5299
5314
|
continue;
|
|
5300
5315
|
}
|
|
5301
5316
|
if (t === "array") {
|
|
5302
|
-
const element =
|
|
5317
|
+
const element = unwrap2(inner._zod.def.element);
|
|
5303
5318
|
if (typeOf(element) === "object") {
|
|
5304
5319
|
result[key] = {
|
|
5305
5320
|
select: toSelectFields(element)
|
|
@@ -6035,16 +6050,28 @@ var ZodValidationPipe = class {
|
|
|
6035
6050
|
schema;
|
|
6036
6051
|
/** Top-level field names that accept `null` (i.e. are nullable). */
|
|
6037
6052
|
nullableKeys;
|
|
6053
|
+
/** Top-level field names whose unwrapped type is a Prisma Decimal. */
|
|
6054
|
+
decimalKeys;
|
|
6055
|
+
/** Prisma Decimal constructor resolved once per pipe instance; null if unavailable. */
|
|
6056
|
+
decimalCtor;
|
|
6038
6057
|
/** Whether to coerce `undefined` → `null` on nullable fields (create/upsert only). */
|
|
6039
6058
|
coerceUndefinedToNull;
|
|
6040
6059
|
constructor(schema, options = {}) {
|
|
6041
6060
|
this.schema = schema;
|
|
6042
6061
|
this.nullableKeys = Object.entries(schema.shape).filter(([, field]) => field.safeParse(null).success).map(([key]) => key);
|
|
6062
|
+
let decimalCtor = null;
|
|
6063
|
+
try {
|
|
6064
|
+
decimalCtor = require("@prisma/client/runtime/client").Decimal;
|
|
6065
|
+
} catch {
|
|
6066
|
+
}
|
|
6067
|
+
this.decimalCtor = decimalCtor;
|
|
6068
|
+
this.decimalKeys = decimalCtor ? Object.entries(schema.shape).filter(([, field]) => isDecimalField(field)).map(([key]) => key) : [];
|
|
6043
6069
|
this.coerceUndefinedToNull = options.coerceNullableUndefinedToNull ?? false;
|
|
6044
6070
|
}
|
|
6045
6071
|
transform(value) {
|
|
6046
6072
|
const stripped = this.stripEmptyStrings(value);
|
|
6047
|
-
const
|
|
6073
|
+
const coerced = this.coerceNullable(stripped);
|
|
6074
|
+
const input = this.coerceDecimals(coerced);
|
|
6048
6075
|
const result = this.schema.safeParse(input);
|
|
6049
6076
|
if (!result.success) {
|
|
6050
6077
|
throw new CroutonValidationError(this.formatErrors(result.error));
|
|
@@ -6085,6 +6112,31 @@ var ZodValidationPipe = class {
|
|
|
6085
6112
|
}
|
|
6086
6113
|
return out;
|
|
6087
6114
|
}
|
|
6115
|
+
/**
|
|
6116
|
+
* Coerce `number` / `string` values on Decimal fields to `Prisma.Decimal`.
|
|
6117
|
+
* `null` / `undefined` / omitted keys are left untouched (PATCH-safe).
|
|
6118
|
+
* An invalid numeric string is left as-is so Zod emits a proper validation error.
|
|
6119
|
+
* Known limitation: only top-level fields are coerced (nested Decimals in relations/arrays
|
|
6120
|
+
* are out of scope — matches how nullableKeys works today).
|
|
6121
|
+
*/
|
|
6122
|
+
coerceDecimals(value) {
|
|
6123
|
+
if (!this.decimalCtor || this.decimalKeys.length === 0 || value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
6124
|
+
return value;
|
|
6125
|
+
}
|
|
6126
|
+
const out = {
|
|
6127
|
+
...value
|
|
6128
|
+
};
|
|
6129
|
+
for (const key of this.decimalKeys) {
|
|
6130
|
+
const v = out[key];
|
|
6131
|
+
if (v == null) continue;
|
|
6132
|
+
if (typeof v !== "number" && typeof v !== "string") continue;
|
|
6133
|
+
try {
|
|
6134
|
+
out[key] = new this.decimalCtor(v);
|
|
6135
|
+
} catch {
|
|
6136
|
+
}
|
|
6137
|
+
}
|
|
6138
|
+
return out;
|
|
6139
|
+
}
|
|
6088
6140
|
formatErrors(error) {
|
|
6089
6141
|
return error.issues.map((e) => ({
|
|
6090
6142
|
field: e.path.join("."),
|
|
@@ -7866,6 +7918,7 @@ var buildResourceDiffs = /* @__PURE__ */ __name(async (models, deps) => {
|
|
|
7866
7918
|
var import_node_child_process = require("child_process");
|
|
7867
7919
|
var import_node_fs7 = require("fs");
|
|
7868
7920
|
var import_promises7 = require("fs/promises");
|
|
7921
|
+
var import_node_module2 = require("module");
|
|
7869
7922
|
var import_node_path15 = require("path");
|
|
7870
7923
|
var run = /* @__PURE__ */ __name((cmd, args, cwd) => new Promise((resolve7) => {
|
|
7871
7924
|
const child = (0, import_node_child_process.spawn)(cmd, args, {
|
|
@@ -7917,11 +7970,28 @@ ${stderr}`.trim()
|
|
|
7917
7970
|
};
|
|
7918
7971
|
}, "prismaDbPull");
|
|
7919
7972
|
var prismaCaseFormat = /* @__PURE__ */ __name(async (cwd, schemaPath) => {
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7973
|
+
let binPath;
|
|
7974
|
+
try {
|
|
7975
|
+
const _require2 = (0, import_node_module2.createRequire)(importMetaUrl);
|
|
7976
|
+
binPath = _require2.resolve("prisma-case-format/bin/cli.js");
|
|
7977
|
+
} catch {
|
|
7978
|
+
}
|
|
7979
|
+
const [cmd, args] = binPath ? [
|
|
7980
|
+
process.execPath,
|
|
7981
|
+
[
|
|
7982
|
+
binPath,
|
|
7983
|
+
"--file",
|
|
7984
|
+
schemaPath
|
|
7985
|
+
]
|
|
7986
|
+
] : [
|
|
7987
|
+
"npx",
|
|
7988
|
+
[
|
|
7989
|
+
"prisma-case-format",
|
|
7990
|
+
"--file",
|
|
7991
|
+
schemaPath
|
|
7992
|
+
]
|
|
7993
|
+
];
|
|
7994
|
+
const { code, stdout, stderr } = await run(cmd, args, cwd);
|
|
7925
7995
|
return {
|
|
7926
7996
|
ok: code === 0,
|
|
7927
7997
|
output: `${stdout}
|