@ghentcdh/crouton-api 0.0.1-alpha.55 → 0.0.1-alpha.57
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 +73 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +79 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -270,6 +270,7 @@ var ControlType = {
|
|
|
270
270
|
custom: "custom",
|
|
271
271
|
select: "select",
|
|
272
272
|
mutliSelect: "mutliSelect",
|
|
273
|
+
toggle: "toggle",
|
|
273
274
|
boolean: "boolean",
|
|
274
275
|
link: "link",
|
|
275
276
|
relation: "relation",
|
|
@@ -397,6 +398,12 @@ var ControlBuilder = class _ControlBuilder extends ElementBuilder {
|
|
|
397
398
|
...options
|
|
398
399
|
});
|
|
399
400
|
}
|
|
401
|
+
toggle(options) {
|
|
402
|
+
return this.opt({
|
|
403
|
+
format: ControlType.toggle,
|
|
404
|
+
...options
|
|
405
|
+
});
|
|
406
|
+
}
|
|
400
407
|
width(width) {
|
|
401
408
|
const named = [
|
|
402
409
|
"xs",
|
|
@@ -1996,13 +2003,26 @@ var jsonSchemaOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
|
|
|
1996
2003
|
if (zodSchema instanceof import_zod21.z.ZodBigInt) {
|
|
1997
2004
|
jsonSchema.type = "integer";
|
|
1998
2005
|
}
|
|
1999
|
-
if (isInstanceOf(zodSchema, "Decimal")) {
|
|
2006
|
+
if (isInstanceOf(zodSchema, "Decimal") || isInstanceOf(zodSchema, "Decimal2")) {
|
|
2000
2007
|
jsonSchema.type = "number";
|
|
2001
2008
|
}
|
|
2002
2009
|
if (isInstanceOf(zodSchema, "Buffer")) {
|
|
2003
2010
|
jsonSchema.type = "string";
|
|
2004
2011
|
}
|
|
2005
2012
|
}, "jsonSchemaOverride");
|
|
2013
|
+
var unwrap = /* @__PURE__ */ __name((schema) => {
|
|
2014
|
+
let s = schema;
|
|
2015
|
+
let t = s._zod?.def?.type;
|
|
2016
|
+
while (t === "optional" || t === "nullable" || t === "default" || t === "readonly") {
|
|
2017
|
+
s = s._zod?.def?.innerType ?? s;
|
|
2018
|
+
t = s._zod?.def?.type;
|
|
2019
|
+
}
|
|
2020
|
+
return s;
|
|
2021
|
+
}, "unwrap");
|
|
2022
|
+
var isDecimalField = /* @__PURE__ */ __name((zodType) => {
|
|
2023
|
+
const inner = unwrap(zodType);
|
|
2024
|
+
return isInstanceOf(inner, "Decimal") || isInstanceOf(inner, "Decimal2");
|
|
2025
|
+
}, "isDecimalField");
|
|
2006
2026
|
var jsonSchemaOpts = {
|
|
2007
2027
|
unrepresentable: "any",
|
|
2008
2028
|
override: jsonSchemaOverride
|
|
@@ -5264,7 +5284,7 @@ function toJsonSchema2(schema) {
|
|
|
5264
5284
|
return schema;
|
|
5265
5285
|
}
|
|
5266
5286
|
__name(toJsonSchema2, "toJsonSchema");
|
|
5267
|
-
var
|
|
5287
|
+
var unwrap2 = /* @__PURE__ */ __name((schema) => {
|
|
5268
5288
|
let s = schema;
|
|
5269
5289
|
let t = s?._zod?.def?.type;
|
|
5270
5290
|
while (t === "optional" || t === "nullable" || t === "default" || t === "readonly") {
|
|
@@ -5283,7 +5303,7 @@ function toSelectFields(schema) {
|
|
|
5283
5303
|
}
|
|
5284
5304
|
const result = {};
|
|
5285
5305
|
for (const [key, value] of Object.entries(schema.shape)) {
|
|
5286
|
-
const inner =
|
|
5306
|
+
const inner = unwrap2(value);
|
|
5287
5307
|
const t = typeOf(inner);
|
|
5288
5308
|
if (t === "object") {
|
|
5289
5309
|
result[key] = {
|
|
@@ -5292,7 +5312,7 @@ function toSelectFields(schema) {
|
|
|
5292
5312
|
continue;
|
|
5293
5313
|
}
|
|
5294
5314
|
if (t === "array") {
|
|
5295
|
-
const element =
|
|
5315
|
+
const element = unwrap2(inner._zod.def.element);
|
|
5296
5316
|
if (typeOf(element) === "object") {
|
|
5297
5317
|
result[key] = {
|
|
5298
5318
|
select: toSelectFields(element)
|
|
@@ -6028,16 +6048,28 @@ var ZodValidationPipe = class {
|
|
|
6028
6048
|
schema;
|
|
6029
6049
|
/** Top-level field names that accept `null` (i.e. are nullable). */
|
|
6030
6050
|
nullableKeys;
|
|
6051
|
+
/** Top-level field names whose unwrapped type is a Prisma Decimal. */
|
|
6052
|
+
decimalKeys;
|
|
6053
|
+
/** Prisma Decimal constructor resolved once per pipe instance; null if unavailable. */
|
|
6054
|
+
decimalCtor;
|
|
6031
6055
|
/** Whether to coerce `undefined` → `null` on nullable fields (create/upsert only). */
|
|
6032
6056
|
coerceUndefinedToNull;
|
|
6033
6057
|
constructor(schema, options = {}) {
|
|
6034
6058
|
this.schema = schema;
|
|
6035
6059
|
this.nullableKeys = Object.entries(schema.shape).filter(([, field]) => field.safeParse(null).success).map(([key]) => key);
|
|
6060
|
+
let decimalCtor = null;
|
|
6061
|
+
try {
|
|
6062
|
+
decimalCtor = require("@prisma/client/runtime/client").Decimal;
|
|
6063
|
+
} catch {
|
|
6064
|
+
}
|
|
6065
|
+
this.decimalCtor = decimalCtor;
|
|
6066
|
+
this.decimalKeys = decimalCtor ? Object.entries(schema.shape).filter(([, field]) => isDecimalField(field)).map(([key]) => key) : [];
|
|
6036
6067
|
this.coerceUndefinedToNull = options.coerceNullableUndefinedToNull ?? false;
|
|
6037
6068
|
}
|
|
6038
6069
|
transform(value) {
|
|
6039
6070
|
const stripped = this.stripEmptyStrings(value);
|
|
6040
|
-
const
|
|
6071
|
+
const coerced = this.coerceNullable(stripped);
|
|
6072
|
+
const input = this.coerceDecimals(coerced);
|
|
6041
6073
|
const result = this.schema.safeParse(input);
|
|
6042
6074
|
if (!result.success) {
|
|
6043
6075
|
throw new CroutonValidationError(this.formatErrors(result.error));
|
|
@@ -6078,6 +6110,31 @@ var ZodValidationPipe = class {
|
|
|
6078
6110
|
}
|
|
6079
6111
|
return out;
|
|
6080
6112
|
}
|
|
6113
|
+
/**
|
|
6114
|
+
* Coerce `number` / `string` values on Decimal fields to `Prisma.Decimal`.
|
|
6115
|
+
* `null` / `undefined` / omitted keys are left untouched (PATCH-safe).
|
|
6116
|
+
* An invalid numeric string is left as-is so Zod emits a proper validation error.
|
|
6117
|
+
* Known limitation: only top-level fields are coerced (nested Decimals in relations/arrays
|
|
6118
|
+
* are out of scope — matches how nullableKeys works today).
|
|
6119
|
+
*/
|
|
6120
|
+
coerceDecimals(value) {
|
|
6121
|
+
if (!this.decimalCtor || this.decimalKeys.length === 0 || value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
6122
|
+
return value;
|
|
6123
|
+
}
|
|
6124
|
+
const out = {
|
|
6125
|
+
...value
|
|
6126
|
+
};
|
|
6127
|
+
for (const key of this.decimalKeys) {
|
|
6128
|
+
const v = out[key];
|
|
6129
|
+
if (v == null) continue;
|
|
6130
|
+
if (typeof v !== "number" && typeof v !== "string") continue;
|
|
6131
|
+
try {
|
|
6132
|
+
out[key] = new this.decimalCtor(v);
|
|
6133
|
+
} catch {
|
|
6134
|
+
}
|
|
6135
|
+
}
|
|
6136
|
+
return out;
|
|
6137
|
+
}
|
|
6081
6138
|
formatErrors(error) {
|
|
6082
6139
|
return error.issues.map((e) => ({
|
|
6083
6140
|
field: e.path.join("."),
|
|
@@ -8973,6 +9030,9 @@ var buildSubResources = /* @__PURE__ */ __name((columns, parentRoute, parentMode
|
|
|
8973
9030
|
...childJson?.modalSize && {
|
|
8974
9031
|
modalSize: childJson.modalSize
|
|
8975
9032
|
},
|
|
9033
|
+
...childJson?.display && {
|
|
9034
|
+
display: childJson.display
|
|
9035
|
+
},
|
|
8976
9036
|
...mergedIncludes.length && {
|
|
8977
9037
|
include: mergedIncludes
|
|
8978
9038
|
},
|
|
@@ -9730,12 +9790,19 @@ var CroutonApiModule = class _CroutonApiModule {
|
|
|
9730
9790
|
static {
|
|
9731
9791
|
__name(this, "CroutonApiModule");
|
|
9732
9792
|
}
|
|
9733
|
-
onModuleInit() {
|
|
9793
|
+
async onModuleInit() {
|
|
9734
9794
|
if (!BigInt.prototype.toJSON) {
|
|
9735
9795
|
BigInt.prototype.toJSON = function() {
|
|
9736
9796
|
return Number(this);
|
|
9737
9797
|
};
|
|
9738
9798
|
}
|
|
9799
|
+
try {
|
|
9800
|
+
const { Decimal } = await import("@prisma/client/runtime/client");
|
|
9801
|
+
Decimal.prototype.toJSON = function() {
|
|
9802
|
+
return parseFloat(this.toString());
|
|
9803
|
+
};
|
|
9804
|
+
} catch {
|
|
9805
|
+
}
|
|
9739
9806
|
}
|
|
9740
9807
|
static forResources(configs, dataSources, loader, appConfig, config) {
|
|
9741
9808
|
const { baseUrl, prefix, security } = appConfig;
|