@ghentcdh/crouton-api 0.0.1-alpha.79 → 0.0.1-alpha.81
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 +297 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +303 -239
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -3383,8 +3383,263 @@ var CompiledResourceSchema = ResourceJsonShape.extend({
|
|
|
3383
3383
|
]).default("string")
|
|
3384
3384
|
});
|
|
3385
3385
|
|
|
3386
|
+
// ../crouton-core/src/lib/compile/crud-config.ts
|
|
3387
|
+
var resolveDefinition = /* @__PURE__ */ __name((config) => {
|
|
3388
|
+
const def2 = config.definition;
|
|
3389
|
+
return typeof def2 === "function" ? def2() : def2;
|
|
3390
|
+
}, "resolveDefinition");
|
|
3391
|
+
var isOperationEnabled = /* @__PURE__ */ __name((def2, op) => def2[op] != null, "isOperationEnabled");
|
|
3392
|
+
var schemaFor = /* @__PURE__ */ __name((def2, op) => {
|
|
3393
|
+
const entry = def2[op];
|
|
3394
|
+
if (!entry || entry === true) return void 0;
|
|
3395
|
+
return entry.schema;
|
|
3396
|
+
}, "schemaFor");
|
|
3397
|
+
var isOperationExternal = /* @__PURE__ */ __name((def2, op) => {
|
|
3398
|
+
const entry = def2[op];
|
|
3399
|
+
return typeof entry === "object" && entry !== null && "uri" in entry;
|
|
3400
|
+
}, "isOperationExternal");
|
|
3401
|
+
var externalRouteFor = /* @__PURE__ */ __name((def2, op) => {
|
|
3402
|
+
const entry = def2[op];
|
|
3403
|
+
if (typeof entry === "object" && entry !== null && "uri" in entry) {
|
|
3404
|
+
return entry.uri;
|
|
3405
|
+
}
|
|
3406
|
+
return void 0;
|
|
3407
|
+
}, "externalRouteFor");
|
|
3408
|
+
|
|
3386
3409
|
// ../crouton-core/src/lib/compile/to-json-schema.ts
|
|
3387
3410
|
var import_zod44 = require("zod");
|
|
3411
|
+
var isZodSchema = /* @__PURE__ */ __name((schema) => schema instanceof import_zod44.ZodObject, "isZodSchema");
|
|
3412
|
+
var dropNullableFromRequired2 = /* @__PURE__ */ __name((jsonSchema) => {
|
|
3413
|
+
const { properties, required } = jsonSchema;
|
|
3414
|
+
if (!properties || !Array.isArray(required)) return;
|
|
3415
|
+
jsonSchema.required = required.filter((key) => !isNullableProperty(properties[key]));
|
|
3416
|
+
}, "dropNullableFromRequired");
|
|
3417
|
+
var toJsonSchema = /* @__PURE__ */ __name((schema) => {
|
|
3418
|
+
if (isZodSchema(schema)) {
|
|
3419
|
+
let jsonSchema;
|
|
3420
|
+
try {
|
|
3421
|
+
jsonSchema = (0, import_zod44.toJSONSchema)(schema, {
|
|
3422
|
+
target: "openApi3",
|
|
3423
|
+
...jsonSchemaOpts
|
|
3424
|
+
});
|
|
3425
|
+
} catch {
|
|
3426
|
+
return {
|
|
3427
|
+
type: "object"
|
|
3428
|
+
};
|
|
3429
|
+
}
|
|
3430
|
+
dropNullableFromRequired2(jsonSchema);
|
|
3431
|
+
return jsonSchema;
|
|
3432
|
+
}
|
|
3433
|
+
return schema;
|
|
3434
|
+
}, "toJsonSchema");
|
|
3435
|
+
|
|
3436
|
+
// ../crouton-core/src/lib/compile/payload-builders.ts
|
|
3437
|
+
var pickExtensions = /* @__PURE__ */ __name((config) => Object.fromEntries([
|
|
3438
|
+
...getResourceExtensions().keys()
|
|
3439
|
+
].filter((k) => config[k] !== void 0).map((k) => [
|
|
3440
|
+
k,
|
|
3441
|
+
config[k]
|
|
3442
|
+
])), "pickExtensions");
|
|
3443
|
+
var resolveEnvPlaceholders = /* @__PURE__ */ __name((value) => value.replace(/\{env\.([^}]+)\}/g, (match, varName) => (
|
|
3444
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3445
|
+
(typeof globalThis.process !== "undefined" ? globalThis.process?.env?.[varName] : void 0) ?? match
|
|
3446
|
+
)), "resolveEnvPlaceholders");
|
|
3447
|
+
var RESOURCE_OPS = [
|
|
3448
|
+
"findAll",
|
|
3449
|
+
"findOne",
|
|
3450
|
+
"create",
|
|
3451
|
+
"update",
|
|
3452
|
+
"patch",
|
|
3453
|
+
"delete"
|
|
3454
|
+
];
|
|
3455
|
+
var OP_SUFFIX = {
|
|
3456
|
+
findAll: "",
|
|
3457
|
+
findOne: "/{id}",
|
|
3458
|
+
create: "",
|
|
3459
|
+
update: "/{id}",
|
|
3460
|
+
patch: "/{id}",
|
|
3461
|
+
delete: "/{id}"
|
|
3462
|
+
};
|
|
3463
|
+
var OP_METHOD = {
|
|
3464
|
+
findAll: "get",
|
|
3465
|
+
findOne: "get",
|
|
3466
|
+
create: "post",
|
|
3467
|
+
update: "put",
|
|
3468
|
+
patch: "patch",
|
|
3469
|
+
delete: "delete"
|
|
3470
|
+
};
|
|
3471
|
+
var buildResourceOperations = /* @__PURE__ */ __name((definition, baseUri) => Object.fromEntries(RESOURCE_OPS.filter((op) => isOperationEnabled(definition, op)).map((op) => {
|
|
3472
|
+
const extRoute = externalRouteFor(definition, op);
|
|
3473
|
+
const uri = extRoute ? resolveEnvPlaceholders(extRoute) : `${baseUri}${OP_SUFFIX[op]}`;
|
|
3474
|
+
const entry = definition[op];
|
|
3475
|
+
const method = (extRoute && typeof entry === "object" && entry !== null && "method" in entry ? entry.method : void 0) ?? OP_METHOD[op];
|
|
3476
|
+
return [
|
|
3477
|
+
op,
|
|
3478
|
+
{
|
|
3479
|
+
uri,
|
|
3480
|
+
method
|
|
3481
|
+
}
|
|
3482
|
+
];
|
|
3483
|
+
})), "buildResourceOperations");
|
|
3484
|
+
var _resolveActions = /* @__PURE__ */ __name((baseUrl, actions) => {
|
|
3485
|
+
if (!actions?.length) return [];
|
|
3486
|
+
return actions.map((a) => a.type === "link" ? {
|
|
3487
|
+
...a,
|
|
3488
|
+
href: resolveEnvPlaceholders(a.href)
|
|
3489
|
+
} : {
|
|
3490
|
+
...a,
|
|
3491
|
+
uri: baseUrl.map((b) => b === "{actionId}" ? a.id : b).join("/"),
|
|
3492
|
+
method: a.method ?? "post"
|
|
3493
|
+
});
|
|
3494
|
+
}, "_resolveActions");
|
|
3495
|
+
var resolveActions = /* @__PURE__ */ __name((baseUrl, actions) => _resolveActions([
|
|
3496
|
+
baseUrl,
|
|
3497
|
+
"procedure",
|
|
3498
|
+
"{actionId}",
|
|
3499
|
+
"{id}"
|
|
3500
|
+
], actions), "resolveActions");
|
|
3501
|
+
var resolveTableActions = /* @__PURE__ */ __name((baseUrl, actions) => _resolveActions([
|
|
3502
|
+
baseUrl,
|
|
3503
|
+
"table-action",
|
|
3504
|
+
"{actionId}"
|
|
3505
|
+
], actions), "resolveTableActions");
|
|
3506
|
+
var buildDefinitionPayload = /* @__PURE__ */ __name((config) => {
|
|
3507
|
+
const { route, name, tag, idType = "string" } = config;
|
|
3508
|
+
const definition = resolveDefinition(config);
|
|
3509
|
+
const listSchema = schemaFor(definition, "findAll");
|
|
3510
|
+
const oneSchema = schemaFor(definition, "findOne") ?? listSchema;
|
|
3511
|
+
const createSchema = schemaFor(definition, "create");
|
|
3512
|
+
const updateSchema = schemaFor(definition, "update");
|
|
3513
|
+
const patchSchema = schemaFor(definition, "patch");
|
|
3514
|
+
const operations = [
|
|
3515
|
+
"findAll",
|
|
3516
|
+
"findOne",
|
|
3517
|
+
"create",
|
|
3518
|
+
"update",
|
|
3519
|
+
"patch",
|
|
3520
|
+
"delete"
|
|
3521
|
+
].filter((op) => isOperationEnabled(definition, op));
|
|
3522
|
+
return {
|
|
3523
|
+
name,
|
|
3524
|
+
route,
|
|
3525
|
+
idType,
|
|
3526
|
+
tag,
|
|
3527
|
+
operations,
|
|
3528
|
+
display: config.display,
|
|
3529
|
+
schemas: {
|
|
3530
|
+
...listSchema && {
|
|
3531
|
+
findAll: toJsonSchema(listSchema)
|
|
3532
|
+
},
|
|
3533
|
+
...oneSchema && {
|
|
3534
|
+
findOne: toJsonSchema(oneSchema)
|
|
3535
|
+
},
|
|
3536
|
+
...createSchema && {
|
|
3537
|
+
create: toJsonSchema(createSchema)
|
|
3538
|
+
},
|
|
3539
|
+
...updateSchema && {
|
|
3540
|
+
update: toJsonSchema(updateSchema)
|
|
3541
|
+
},
|
|
3542
|
+
...patchSchema && {
|
|
3543
|
+
patch: toJsonSchema(patchSchema)
|
|
3544
|
+
}
|
|
3545
|
+
},
|
|
3546
|
+
...pickExtensions(config)
|
|
3547
|
+
};
|
|
3548
|
+
}, "buildDefinitionPayload");
|
|
3549
|
+
var buildResourceJsonPayload = /* @__PURE__ */ __name((config, baseUrl) => {
|
|
3550
|
+
const { route } = config;
|
|
3551
|
+
const definition = resolveDefinition(config);
|
|
3552
|
+
const uri = `${baseUrl}/${route}`;
|
|
3553
|
+
const operations = Object.fromEntries(RESOURCE_OPS.map((op) => [
|
|
3554
|
+
op,
|
|
3555
|
+
isOperationEnabled(definition, op)
|
|
3556
|
+
]));
|
|
3557
|
+
if (!isOperationExternal(definition, "findAll")) {
|
|
3558
|
+
operations["lookup"] = `${uri}?q={text}`;
|
|
3559
|
+
}
|
|
3560
|
+
const form = config.views?.["form"];
|
|
3561
|
+
const schema = form?.json_schema ? {
|
|
3562
|
+
data: form.json_schema,
|
|
3563
|
+
ui: form.ui_schema
|
|
3564
|
+
} : null;
|
|
3565
|
+
return {
|
|
3566
|
+
id: config.id ?? route,
|
|
3567
|
+
uri,
|
|
3568
|
+
operations,
|
|
3569
|
+
schema,
|
|
3570
|
+
...pickExtensions(config)
|
|
3571
|
+
};
|
|
3572
|
+
}, "buildResourceJsonPayload");
|
|
3573
|
+
var buildViewsPayload = /* @__PURE__ */ __name((config, baseUrl) => {
|
|
3574
|
+
if (!config.views || !Object.keys(config.views).length) return void 0;
|
|
3575
|
+
const definition = resolveDefinition(config);
|
|
3576
|
+
const baseUri = config.parent ? `${baseUrl}/${config.parent.route}/{${config.parent.param}}/${config.route}` : `${baseUrl}/${config.route}`;
|
|
3577
|
+
const operations = buildResourceOperations(definition, baseUri);
|
|
3578
|
+
if (isOperationEnabled(definition, "findAll") && !isOperationExternal(definition, "findAll")) {
|
|
3579
|
+
operations["lookup"] = `${baseUri}?q={text}`;
|
|
3580
|
+
}
|
|
3581
|
+
const schemas = Object.fromEntries(Object.entries(config.views).map(([key, v]) => [
|
|
3582
|
+
key,
|
|
3583
|
+
{
|
|
3584
|
+
data: v.json_schema,
|
|
3585
|
+
ui: v.ui_schema,
|
|
3586
|
+
...v.defaultSort !== void 0 && {
|
|
3587
|
+
defaultSort: v.defaultSort
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
]));
|
|
3591
|
+
return {
|
|
3592
|
+
id: config.id ?? config.route,
|
|
3593
|
+
name: config.name,
|
|
3594
|
+
route: config.route,
|
|
3595
|
+
uri: baseUri,
|
|
3596
|
+
title: config.title ?? config.tag,
|
|
3597
|
+
idField: config.lookup?.key ?? "id",
|
|
3598
|
+
idType: config.idType ?? "string",
|
|
3599
|
+
...config.modalSize && {
|
|
3600
|
+
modalSize: config.modalSize
|
|
3601
|
+
},
|
|
3602
|
+
operations,
|
|
3603
|
+
display: config.display,
|
|
3604
|
+
schemas,
|
|
3605
|
+
actions: resolveActions(baseUri, config.actions),
|
|
3606
|
+
tableActions: resolveTableActions(baseUri, config.tableActions),
|
|
3607
|
+
...pickExtensions(config)
|
|
3608
|
+
};
|
|
3609
|
+
}, "buildViewsPayload");
|
|
3610
|
+
var buildSubResourceViewsPayload = /* @__PURE__ */ __name((config, sub, baseUrl) => {
|
|
3611
|
+
if (!sub.views) return void 0;
|
|
3612
|
+
const { route } = config;
|
|
3613
|
+
const childUri = `${baseUrl}/${route}/{parent.id}/${sub.childRoute}`;
|
|
3614
|
+
return {
|
|
3615
|
+
id: `${route}/${sub.childRoute}`,
|
|
3616
|
+
name: sub.name ?? sub.childRoute,
|
|
3617
|
+
route: sub.childRoute,
|
|
3618
|
+
uri: childUri,
|
|
3619
|
+
title: sub.title ?? sub.childRoute,
|
|
3620
|
+
idField: sub.idField ?? "id",
|
|
3621
|
+
idType: sub.idType ?? "string",
|
|
3622
|
+
...sub.modalSize && {
|
|
3623
|
+
modalSize: sub.modalSize
|
|
3624
|
+
},
|
|
3625
|
+
...sub.display && {
|
|
3626
|
+
display: sub.display
|
|
3627
|
+
},
|
|
3628
|
+
// ponytail: cast because JsonOperationsSchema uses boolean|{security?} but buildSubResourceOperations wants boolean
|
|
3629
|
+
operations: buildSubResourceOperations(sub.operations, childUri, sub.idField ?? "id"),
|
|
3630
|
+
schemas: Object.fromEntries(Object.entries(sub.views).map(([key, v]) => [
|
|
3631
|
+
key,
|
|
3632
|
+
{
|
|
3633
|
+
data: v.json_schema,
|
|
3634
|
+
ui: v.ui_schema,
|
|
3635
|
+
...v.defaultSort !== void 0 && {
|
|
3636
|
+
defaultSort: v.defaultSort
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3639
|
+
])),
|
|
3640
|
+
actions: resolveActions(`${baseUrl}/${sub.childRoute}`, sub.actions)
|
|
3641
|
+
};
|
|
3642
|
+
}, "buildSubResourceViewsPayload");
|
|
3388
3643
|
|
|
3389
3644
|
// ../crouton-core/src/lib/config/CroutonConfig.schema.ts
|
|
3390
3645
|
var import_zod45 = require("zod");
|
|
@@ -4246,9 +4501,12 @@ var loadConfig = /* @__PURE__ */ __name(async () => {
|
|
|
4246
4501
|
config = mod.default ?? mod;
|
|
4247
4502
|
}
|
|
4248
4503
|
const parsed = CroutonConfigSchema.parse(config);
|
|
4504
|
+
const configDir = (0, import_node_path3.dirname)(path);
|
|
4505
|
+
const enumsFile = (0, import_node_path3.isAbsolute)(parsed.enumsFile) ? parsed.enumsFile : (0, import_node_path3.resolve)(configDir, parsed.enumsFile);
|
|
4249
4506
|
return {
|
|
4250
4507
|
...parsed,
|
|
4251
|
-
configDir
|
|
4508
|
+
configDir,
|
|
4509
|
+
enumsFile
|
|
4252
4510
|
};
|
|
4253
4511
|
}, "loadConfig");
|
|
4254
4512
|
|
|
@@ -4462,9 +4720,8 @@ var import_node_fs4 = require("fs");
|
|
|
4462
4720
|
var import_node_module = require("module");
|
|
4463
4721
|
var import_node_path5 = require("path");
|
|
4464
4722
|
var import_node_url = require("url");
|
|
4465
|
-
var import_meta = {};
|
|
4466
4723
|
var _require = (0, import_node_module.createRequire)(importMetaUrl ?? __filename);
|
|
4467
|
-
var IS_ESM = typeof
|
|
4724
|
+
var IS_ESM = typeof __filename === "undefined";
|
|
4468
4725
|
var findModule = /* @__PURE__ */ __name((dir, name) => {
|
|
4469
4726
|
for (const ext of [
|
|
4470
4727
|
".ts",
|
|
@@ -5157,8 +5414,13 @@ var ReadRepository = class {
|
|
|
5157
5414
|
...mergedInclude
|
|
5158
5415
|
};
|
|
5159
5416
|
} else {
|
|
5160
|
-
|
|
5161
|
-
|
|
5417
|
+
const includeClause = {
|
|
5418
|
+
...mergedInclude ?? {},
|
|
5419
|
+
...countClause ? {
|
|
5420
|
+
_count: countClause
|
|
5421
|
+
} : {}
|
|
5422
|
+
};
|
|
5423
|
+
if (Object.keys(includeClause).length) query.include = includeClause;
|
|
5162
5424
|
}
|
|
5163
5425
|
const rows = await this.prismaModel.findMany(query);
|
|
5164
5426
|
const mapped = countableSubResources.length ? rows.map((row) => {
|
|
@@ -6168,17 +6430,17 @@ var validateCustomRepository = /* @__PURE__ */ __name((config, repository, adapt
|
|
|
6168
6430
|
|
|
6169
6431
|
// src/lib/crud/schema.utils.ts
|
|
6170
6432
|
var import_zod51 = require("zod");
|
|
6171
|
-
function
|
|
6433
|
+
function isZodSchema2(schema) {
|
|
6172
6434
|
return schema instanceof import_zod51.ZodObject;
|
|
6173
6435
|
}
|
|
6174
|
-
__name(
|
|
6175
|
-
var
|
|
6436
|
+
__name(isZodSchema2, "isZodSchema");
|
|
6437
|
+
var dropNullableFromRequired3 = /* @__PURE__ */ __name((jsonSchema) => {
|
|
6176
6438
|
const { properties, required } = jsonSchema;
|
|
6177
6439
|
if (!properties || !Array.isArray(required)) return;
|
|
6178
6440
|
jsonSchema.required = required.filter((key) => !isNullableProperty(properties[key]));
|
|
6179
6441
|
}, "dropNullableFromRequired");
|
|
6180
6442
|
function toJsonSchema2(schema) {
|
|
6181
|
-
if (
|
|
6443
|
+
if (isZodSchema2(schema)) {
|
|
6182
6444
|
let jsonSchema;
|
|
6183
6445
|
try {
|
|
6184
6446
|
jsonSchema = (0, import_zod51.toJSONSchema)(schema, {
|
|
@@ -6190,7 +6452,7 @@ function toJsonSchema2(schema) {
|
|
|
6190
6452
|
type: "object"
|
|
6191
6453
|
};
|
|
6192
6454
|
}
|
|
6193
|
-
|
|
6455
|
+
dropNullableFromRequired3(jsonSchema);
|
|
6194
6456
|
return jsonSchema;
|
|
6195
6457
|
}
|
|
6196
6458
|
return schema;
|
|
@@ -6207,7 +6469,7 @@ var unwrap2 = /* @__PURE__ */ __name((schema) => {
|
|
|
6207
6469
|
}, "unwrap");
|
|
6208
6470
|
var typeOf = /* @__PURE__ */ __name((schema) => schema?._zod?.def?.type, "typeOf");
|
|
6209
6471
|
function toSelectFields(schema) {
|
|
6210
|
-
if (!
|
|
6472
|
+
if (!isZodSchema2(schema)) {
|
|
6211
6473
|
return Object.keys(schema.properties).reduce((acc, key) => {
|
|
6212
6474
|
acc[key] = true;
|
|
6213
6475
|
return acc;
|
|
@@ -6975,7 +7237,7 @@ var ZodValidationPipe = class {
|
|
|
6975
7237
|
decimalKeys;
|
|
6976
7238
|
/** Prisma Decimal constructor resolved once per pipe instance; null if unavailable. */
|
|
6977
7239
|
decimalCtor;
|
|
6978
|
-
/** Whether to coerce `undefined` → `null` on nullable fields (create
|
|
7240
|
+
/** Whether to coerce `undefined` → `null` on nullable fields (create only). */
|
|
6979
7241
|
coerceUndefinedToNull;
|
|
6980
7242
|
constructor(schema, options = {}) {
|
|
6981
7243
|
this.schema = schema;
|
|
@@ -7020,7 +7282,7 @@ var ZodValidationPipe = class {
|
|
|
7020
7282
|
}
|
|
7021
7283
|
return out;
|
|
7022
7284
|
}
|
|
7023
|
-
/** Replace `undefined` with `null` on nullable fields (create
|
|
7285
|
+
/** Replace `undefined` with `null` on nullable fields (create only). */
|
|
7024
7286
|
coerceNullable(value) {
|
|
7025
7287
|
if (!this.coerceUndefinedToNull || value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
7026
7288
|
return value;
|
|
@@ -7396,207 +7658,10 @@ var writeRawResourceJson = /* @__PURE__ */ __name((jsonPath, raw) => {
|
|
|
7396
7658
|
}, "writeRawResourceJson");
|
|
7397
7659
|
|
|
7398
7660
|
// src/lib/crud/operations/payload-builders.ts
|
|
7399
|
-
var
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
config[k]
|
|
7404
|
-
])), "pickExtensions");
|
|
7405
|
-
var resolveEnvPlaceholders = /* @__PURE__ */ __name((value) => value.replace(/\{env\.([^}]+)\}/g, (match, varName) => process.env[varName] ?? match), "resolveEnvPlaceholders");
|
|
7406
|
-
var RESOURCE_OPS = [
|
|
7407
|
-
"findAll",
|
|
7408
|
-
"findOne",
|
|
7409
|
-
"create",
|
|
7410
|
-
"update",
|
|
7411
|
-
"patch",
|
|
7412
|
-
"delete"
|
|
7413
|
-
];
|
|
7414
|
-
var OP_METHOD = {
|
|
7415
|
-
findAll: "get",
|
|
7416
|
-
findOne: "get",
|
|
7417
|
-
create: "post",
|
|
7418
|
-
update: "put",
|
|
7419
|
-
patch: "patch",
|
|
7420
|
-
delete: "delete"
|
|
7421
|
-
};
|
|
7422
|
-
var OP_SUFFIX = {
|
|
7423
|
-
findAll: "",
|
|
7424
|
-
findOne: "/{id}",
|
|
7425
|
-
create: "",
|
|
7426
|
-
update: "/{id}",
|
|
7427
|
-
patch: "/{id}",
|
|
7428
|
-
delete: "/{id}"
|
|
7429
|
-
};
|
|
7430
|
-
var buildResourceOperations = /* @__PURE__ */ __name((definition, baseUri) => Object.fromEntries(RESOURCE_OPS.filter((op) => isOperationEnabled2(definition, op)).map((op) => {
|
|
7431
|
-
const extUri = externalRouteFor2(definition, op);
|
|
7432
|
-
const uri = extUri ? resolveEnvPlaceholders(extUri) : `${baseUri}${OP_SUFFIX[op]}`;
|
|
7433
|
-
const entry = definition[op];
|
|
7434
|
-
const method = (extUri && typeof entry === "object" && entry !== null && "method" in entry ? entry.method : void 0) ?? OP_METHOD[op];
|
|
7435
|
-
return [
|
|
7436
|
-
op,
|
|
7437
|
-
{
|
|
7438
|
-
uri,
|
|
7439
|
-
method
|
|
7440
|
-
}
|
|
7441
|
-
];
|
|
7442
|
-
})), "buildResourceOperations");
|
|
7443
|
-
var buildDefinitionPayload2 = /* @__PURE__ */ __name((config) => {
|
|
7444
|
-
const { route, name, tag, idType = "string" } = config;
|
|
7445
|
-
const definition = resolveDefinition2(config);
|
|
7446
|
-
const listSchema = schemaFor2(definition, "findAll");
|
|
7447
|
-
const oneSchema = schemaFor2(definition, "findOne") ?? listSchema;
|
|
7448
|
-
const createSchema = schemaFor2(definition, "create");
|
|
7449
|
-
const updateSchema = schemaFor2(definition, "update");
|
|
7450
|
-
const patchSchema = schemaFor2(definition, "patch");
|
|
7451
|
-
const operations = [
|
|
7452
|
-
"findAll",
|
|
7453
|
-
"findOne",
|
|
7454
|
-
"create",
|
|
7455
|
-
"update",
|
|
7456
|
-
"patch",
|
|
7457
|
-
"delete"
|
|
7458
|
-
].filter((op) => isOperationEnabled2(definition, op));
|
|
7459
|
-
return {
|
|
7460
|
-
name,
|
|
7461
|
-
route,
|
|
7462
|
-
idType,
|
|
7463
|
-
tag,
|
|
7464
|
-
operations,
|
|
7465
|
-
display: config.display,
|
|
7466
|
-
schemas: {
|
|
7467
|
-
...listSchema && {
|
|
7468
|
-
findAll: toJsonSchema2(listSchema)
|
|
7469
|
-
},
|
|
7470
|
-
...oneSchema && {
|
|
7471
|
-
findOne: toJsonSchema2(oneSchema)
|
|
7472
|
-
},
|
|
7473
|
-
...createSchema && {
|
|
7474
|
-
create: toJsonSchema2(createSchema)
|
|
7475
|
-
},
|
|
7476
|
-
...updateSchema && {
|
|
7477
|
-
update: toJsonSchema2(updateSchema)
|
|
7478
|
-
},
|
|
7479
|
-
...patchSchema && {
|
|
7480
|
-
patch: toJsonSchema2(patchSchema)
|
|
7481
|
-
}
|
|
7482
|
-
},
|
|
7483
|
-
...pickExtensions(config)
|
|
7484
|
-
};
|
|
7485
|
-
}, "buildDefinitionPayload");
|
|
7486
|
-
var buildResourceJsonPayload2 = /* @__PURE__ */ __name((config, baseUrl) => {
|
|
7487
|
-
const { name, route } = config;
|
|
7488
|
-
const definition = resolveDefinition2(config);
|
|
7489
|
-
const uri = `${baseUrl}/${route}`;
|
|
7490
|
-
const operations = Object.fromEntries(RESOURCE_OPS.map((op) => [
|
|
7491
|
-
op,
|
|
7492
|
-
isOperationEnabled2(definition, op)
|
|
7493
|
-
]));
|
|
7494
|
-
if (!isOperationExternal2(definition, "findAll")) {
|
|
7495
|
-
operations.lookup = `${uri}?q={text}`;
|
|
7496
|
-
}
|
|
7497
|
-
const form = config.views?.["form"];
|
|
7498
|
-
const schema = form?.json_schema ? {
|
|
7499
|
-
data: form.json_schema,
|
|
7500
|
-
ui: form.ui_schema
|
|
7501
|
-
} : null;
|
|
7502
|
-
return {
|
|
7503
|
-
id: config.id ?? route,
|
|
7504
|
-
uri,
|
|
7505
|
-
operations,
|
|
7506
|
-
schema,
|
|
7507
|
-
...pickExtensions(config)
|
|
7508
|
-
};
|
|
7509
|
-
}, "buildResourceJsonPayload");
|
|
7510
|
-
var _resolveActions = /* @__PURE__ */ __name((baseUrl, actions) => {
|
|
7511
|
-
if (!actions?.length) return [];
|
|
7512
|
-
const resolved = actions.map((a) => a.type === "link" ? {
|
|
7513
|
-
...a,
|
|
7514
|
-
href: resolveEnvPlaceholders(a.href)
|
|
7515
|
-
} : {
|
|
7516
|
-
...a,
|
|
7517
|
-
uri: baseUrl.map((b) => b === "{actionId}" ? a.id : b).join("/"),
|
|
7518
|
-
method: a.method ?? "post"
|
|
7519
|
-
});
|
|
7520
|
-
return resolved;
|
|
7521
|
-
}, "_resolveActions");
|
|
7522
|
-
var resolveActions = /* @__PURE__ */ __name((baseUrl, actions) => {
|
|
7523
|
-
return _resolveActions([
|
|
7524
|
-
baseUrl,
|
|
7525
|
-
"procedure",
|
|
7526
|
-
"{actionId}",
|
|
7527
|
-
"{id}"
|
|
7528
|
-
], actions);
|
|
7529
|
-
}, "resolveActions");
|
|
7530
|
-
var buildViewsPayload2 = /* @__PURE__ */ __name((config, baseUrl) => {
|
|
7531
|
-
if (!config.views || !Object.keys(config.views).length) return void 0;
|
|
7532
|
-
const definition = resolveDefinition2(config);
|
|
7533
|
-
const baseUri = config.parent ? `${baseUrl}/${config.parent.route}/{${config.parent.param}}/${config.route}` : `${baseUrl}/${config.route}`;
|
|
7534
|
-
const operations = buildResourceOperations(definition, baseUri);
|
|
7535
|
-
if (isOperationEnabled2(definition, "findAll") && !isOperationExternal2(definition, "findAll")) {
|
|
7536
|
-
operations["lookup"] = `${baseUri}?q={text}`;
|
|
7537
|
-
}
|
|
7538
|
-
const schemas = Object.fromEntries(Object.entries(config.views).map(([key, v]) => [
|
|
7539
|
-
key,
|
|
7540
|
-
{
|
|
7541
|
-
data: v.json_schema,
|
|
7542
|
-
ui: v.ui_schema,
|
|
7543
|
-
...v.defaultSort !== void 0 && {
|
|
7544
|
-
defaultSort: v.defaultSort
|
|
7545
|
-
}
|
|
7546
|
-
}
|
|
7547
|
-
]));
|
|
7548
|
-
const baseAction = `${baseUri}${config.route}`;
|
|
7549
|
-
return {
|
|
7550
|
-
id: config.id ?? config.route,
|
|
7551
|
-
name: config.name,
|
|
7552
|
-
route: config.route,
|
|
7553
|
-
uri: baseUri,
|
|
7554
|
-
title: config.title ?? config.tag,
|
|
7555
|
-
idField: config.lookup?.key ?? "id",
|
|
7556
|
-
idType: config.idType ?? "string",
|
|
7557
|
-
...config.modalSize && {
|
|
7558
|
-
modalSize: config.modalSize
|
|
7559
|
-
},
|
|
7560
|
-
operations,
|
|
7561
|
-
display: config.display,
|
|
7562
|
-
schemas,
|
|
7563
|
-
actions: resolveActions(baseAction, config.actions),
|
|
7564
|
-
tableActions: resolveActions(baseAction, config.tableActions),
|
|
7565
|
-
...pickExtensions(config)
|
|
7566
|
-
};
|
|
7567
|
-
}, "buildViewsPayload");
|
|
7568
|
-
var buildSubResourceViewsPayload = /* @__PURE__ */ __name((config, sub, baseUrl) => {
|
|
7569
|
-
if (!sub.views) return void 0;
|
|
7570
|
-
const { route } = config;
|
|
7571
|
-
const childUri = `${baseUrl}/${route}/{parent.id}/${sub.childRoute}`;
|
|
7572
|
-
return {
|
|
7573
|
-
id: `${route}/${sub.childRoute}`,
|
|
7574
|
-
name: sub.name ?? sub.childRoute,
|
|
7575
|
-
route: sub.childRoute,
|
|
7576
|
-
uri: childUri,
|
|
7577
|
-
title: sub.title ?? sub.childRoute,
|
|
7578
|
-
idField: sub.idField ?? "id",
|
|
7579
|
-
idType: sub.idType ?? "string",
|
|
7580
|
-
...sub.modalSize && {
|
|
7581
|
-
modalSize: sub.modalSize
|
|
7582
|
-
},
|
|
7583
|
-
...sub.display && {
|
|
7584
|
-
display: sub.display
|
|
7585
|
-
},
|
|
7586
|
-
operations: buildSubResourceOperations(sub.operations, childUri, sub.idField ?? "id"),
|
|
7587
|
-
schemas: Object.fromEntries(Object.entries(sub.views).map(([key, v]) => [
|
|
7588
|
-
key,
|
|
7589
|
-
{
|
|
7590
|
-
data: v.json_schema,
|
|
7591
|
-
ui: v.ui_schema,
|
|
7592
|
-
...v.defaultSort !== void 0 && {
|
|
7593
|
-
defaultSort: v.defaultSort
|
|
7594
|
-
}
|
|
7595
|
-
}
|
|
7596
|
-
])),
|
|
7597
|
-
actions: resolveActions(`${baseUrl}/${sub.childRoute}`, sub.actions)
|
|
7598
|
-
};
|
|
7599
|
-
}, "buildSubResourceViewsPayload");
|
|
7661
|
+
var buildDefinitionPayload2 = /* @__PURE__ */ __name((config) => buildDefinitionPayload(config), "buildDefinitionPayload");
|
|
7662
|
+
var buildResourceJsonPayload2 = /* @__PURE__ */ __name((config, baseUrl) => buildResourceJsonPayload(config, baseUrl), "buildResourceJsonPayload");
|
|
7663
|
+
var buildViewsPayload2 = /* @__PURE__ */ __name((config, baseUrl) => buildViewsPayload(config, baseUrl), "buildViewsPayload");
|
|
7664
|
+
var buildSubResourceViewsPayload2 = /* @__PURE__ */ __name((config, sub, baseUrl) => buildSubResourceViewsPayload(config, sub, baseUrl), "buildSubResourceViewsPayload");
|
|
7600
7665
|
var buildEditableColumnsPayload = /* @__PURE__ */ __name((config) => {
|
|
7601
7666
|
const columns = config.columns ?? [];
|
|
7602
7667
|
return {
|
|
@@ -7836,7 +7901,7 @@ var childSchemas = /* @__PURE__ */ __name((sub) => (ctx) => {
|
|
|
7836
7901
|
if (!sub.views) return null;
|
|
7837
7902
|
const { config, baseUrl } = ctx;
|
|
7838
7903
|
const { route } = config;
|
|
7839
|
-
const schemasPayload =
|
|
7904
|
+
const schemasPayload = buildSubResourceViewsPayload2(config, sub, baseUrl);
|
|
7840
7905
|
return {
|
|
7841
7906
|
route: `${sub.childRoute}/schemas`,
|
|
7842
7907
|
methodName: `getSchemas_${sub.childRoute}`,
|
|
@@ -7848,7 +7913,7 @@ var childSchemas = /* @__PURE__ */ __name((sub) => (ctx) => {
|
|
|
7848
7913
|
if (localizedParent) {
|
|
7849
7914
|
const localizedSub = (localizedParent.subResources ?? []).find((s) => s.childRoute === sub.childRoute);
|
|
7850
7915
|
if (localizedSub) {
|
|
7851
|
-
return
|
|
7916
|
+
return buildSubResourceViewsPayload2(localizedParent, localizedSub, baseUrl) ?? schemasPayload;
|
|
7852
7917
|
}
|
|
7853
7918
|
}
|
|
7854
7919
|
}
|
|
@@ -8080,10 +8145,10 @@ function createCrudController(config, baseUrl, moduleDefaultSecurity, securityEn
|
|
|
8080
8145
|
const createSchema = schemaFor2(definition, "create");
|
|
8081
8146
|
const updateSchema = schemaFor2(definition, "update");
|
|
8082
8147
|
const explicitPatchSchema = schemaFor2(definition, "patch");
|
|
8083
|
-
const patchSchema = explicitPatchSchema ?? (updateSchema &&
|
|
8148
|
+
const patchSchema = explicitPatchSchema ?? (updateSchema && isZodSchema2(updateSchema) ? updateSchema.partial() : void 0) ?? updateSchema;
|
|
8084
8149
|
const bodyDecorator = /* @__PURE__ */ __name((schema, options) => {
|
|
8085
8150
|
if (!schema) return (0, import_common24.Body)();
|
|
8086
|
-
if (
|
|
8151
|
+
if (isZodSchema2(schema)) return (0, import_common24.Body)(new ZodValidationPipe(schema, options));
|
|
8087
8152
|
return (0, import_common24.Body)();
|
|
8088
8153
|
}, "bodyDecorator");
|
|
8089
8154
|
const resolveClient = /* @__PURE__ */ __name((registry2, resource) => {
|
|
@@ -8960,22 +9025,19 @@ var import_promises7 = require("fs/promises");
|
|
|
8960
9025
|
var import_node_module2 = require("module");
|
|
8961
9026
|
var import_node_path15 = require("path");
|
|
8962
9027
|
var loadDotenv = /* @__PURE__ */ __name((dir) => {
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
const
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
dotenv.config({
|
|
8970
|
-
path: (0, import_node_path15.join)(d, ".env")
|
|
8971
|
-
});
|
|
8972
|
-
return;
|
|
8973
|
-
}
|
|
8974
|
-
const parent = (0, import_node_path15.dirname)(d);
|
|
8975
|
-
if (parent === d) break;
|
|
8976
|
-
d = parent;
|
|
9028
|
+
let d = dir;
|
|
9029
|
+
for (let i = 0; i < 6; i++) {
|
|
9030
|
+
const file = (0, import_node_path15.join)(d, ".env");
|
|
9031
|
+
if ((0, import_node_fs7.existsSync)(file)) {
|
|
9032
|
+
process.loadEnvFile(file);
|
|
9033
|
+
return;
|
|
8977
9034
|
}
|
|
8978
|
-
|
|
9035
|
+
const parent = (0, import_node_path15.dirname)(d);
|
|
9036
|
+
if (parent === d) break;
|
|
9037
|
+
d = parent;
|
|
9038
|
+
}
|
|
9039
|
+
if (!process.env["DATABASE_URL"]) {
|
|
9040
|
+
console.warn("[crouton] No .env found and DATABASE_URL is not set \u2014 prisma commands may fail");
|
|
8979
9041
|
}
|
|
8980
9042
|
}, "loadDotenv");
|
|
8981
9043
|
var resolveBin = /* @__PURE__ */ __name((name, cwd) => {
|
|
@@ -9000,7 +9062,8 @@ var resolveBin = /* @__PURE__ */ __name((name, cwd) => {
|
|
|
9000
9062
|
var run = /* @__PURE__ */ __name((cmd, args, cwd) => new Promise((resolve7) => {
|
|
9001
9063
|
const child = (0, import_node_child_process.spawn)(cmd, args, {
|
|
9002
9064
|
cwd,
|
|
9003
|
-
shell: process.platform === "win32"
|
|
9065
|
+
shell: process.platform === "win32",
|
|
9066
|
+
env: process.env
|
|
9004
9067
|
});
|
|
9005
9068
|
let stdout = "";
|
|
9006
9069
|
let stderr = "";
|