@ghentcdh/crouton-api 0.0.1-alpha.67 → 0.0.1-alpha.69

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 CHANGED
@@ -161,6 +161,15 @@ var ResponseSchema = import_zod4.z.object({
161
161
  // ../crouton-core/src/lib/create-schema.ts
162
162
  var import_zod6 = require("zod");
163
163
 
164
+ // ../crouton-core/src/lib/schema.utils.ts
165
+ var isNullableProperty = /* @__PURE__ */ __name((property) => {
166
+ const prop = property;
167
+ if (!prop) return false;
168
+ if (Array.isArray(prop["type"]) && prop["type"].includes("null")) return true;
169
+ const anyOf = prop["anyOf"];
170
+ return Array.isArray(anyOf) && anyOf.some((s) => s?.["type"] === "null");
171
+ }, "isNullableProperty");
172
+
164
173
  // ../crouton-core/src/lib/layout/base.builder.ts
165
174
  var Builder = class {
166
175
  static {
@@ -1669,10 +1678,6 @@ var allowAdditionalProperties = /* @__PURE__ */ __name((schema) => {
1669
1678
  allowAdditionalProperties(schema["items"]);
1670
1679
  }
1671
1680
  }, "allowAdditionalProperties");
1672
- var isNullableProperty = /* @__PURE__ */ __name((prop) => {
1673
- const anyOf = prop?.["anyOf"];
1674
- return Array.isArray(anyOf) && anyOf.some((s) => s?.["type"] === "null");
1675
- }, "isNullableProperty");
1676
1681
  var dropNullableFromRequired = /* @__PURE__ */ __name((schema) => {
1677
1682
  if (schema["type"] !== "object") return;
1678
1683
  const props = schema["properties"];
@@ -1824,6 +1829,11 @@ var buildDetailLayout = /* @__PURE__ */ __name((detail) => {
1824
1829
  var defaultControlFormat = /* @__PURE__ */ __name((col) => {
1825
1830
  if (isObjectColumn(col)) return "object";
1826
1831
  if (isArrayColumn(col)) return "array";
1832
+ const typeName = columnTypeName(col.type);
1833
+ if (typeName === "number" || typeName === "integer") return typeName;
1834
+ const format = columnTypeToJsonSchema(col.type).format;
1835
+ if (format === "date") return "date";
1836
+ if (format === "date-time") return "dateTime";
1827
1837
  return "text";
1828
1838
  }, "defaultControlFormat");
1829
1839
  var buildFormControl = /* @__PURE__ */ __name((col) => {
@@ -3755,7 +3765,10 @@ var isTableProcedureAction = /* @__PURE__ */ __name((action) => action.type !==
3755
3765
  var import_node_fs4 = require("fs");
3756
3766
  var import_node_module = require("module");
3757
3767
  var import_node_path5 = require("path");
3768
+ var import_node_url = require("url");
3769
+ var import_meta = {};
3758
3770
  var _require = (0, import_node_module.createRequire)(importMetaUrl ?? __filename);
3771
+ var IS_ESM = typeof import_meta !== "undefined" && typeof importMetaUrl === "string";
3759
3772
  var findModule = /* @__PURE__ */ __name((dir, name) => {
3760
3773
  for (const ext of [
3761
3774
  ".ts",
@@ -3773,6 +3786,9 @@ var importDefault = /* @__PURE__ */ __name(async (filePath, onError) => {
3773
3786
  const importPath = IS_DEV ? `${filePath}?t=${Date.now()}` : filePath;
3774
3787
  const mod = await import(importPath);
3775
3788
  return mod.default ?? mod;
3789
+ } else if (IS_ESM) {
3790
+ const mod = await import((0, import_node_url.pathToFileURL)(filePath).href);
3791
+ return mod.default ?? mod;
3776
3792
  } else {
3777
3793
  const mod = _require(filePath);
3778
3794
  return mod.default;
@@ -5326,14 +5342,10 @@ function isZodSchema(schema) {
5326
5342
  return schema instanceof import_zod40.ZodObject;
5327
5343
  }
5328
5344
  __name(isZodSchema, "isZodSchema");
5329
- var isNullableProperty2 = /* @__PURE__ */ __name((property) => {
5330
- const anyOf = property?.["anyOf"];
5331
- return Array.isArray(anyOf) && anyOf.some((s) => s?.["type"] === "null");
5332
- }, "isNullableProperty");
5333
5345
  var dropNullableFromRequired2 = /* @__PURE__ */ __name((jsonSchema) => {
5334
5346
  const { properties, required } = jsonSchema;
5335
5347
  if (!properties || !Array.isArray(required)) return;
5336
- jsonSchema.required = required.filter((key) => !isNullableProperty2(properties[key]));
5348
+ jsonSchema.required = required.filter((key) => !isNullableProperty(properties[key]));
5337
5349
  }, "dropNullableFromRequired");
5338
5350
  function toJsonSchema2(schema) {
5339
5351
  if (isZodSchema(schema)) {
@@ -8130,65 +8142,29 @@ var prismaGenerate = /* @__PURE__ */ __name(async (cwd, prismaConfig) => {
8130
8142
  ${stderr}`.trim()
8131
8143
  };
8132
8144
  }, "prismaGenerate");
8133
- var fixZodImports = /* @__PURE__ */ __name(async (zodOutputDir) => {
8134
- let fixed = 0;
8135
- const walk = /* @__PURE__ */ __name(async (dir) => {
8136
- let entries;
8137
- try {
8138
- entries = await (0, import_promises7.readdir)(dir, {
8139
- withFileTypes: true
8140
- });
8141
- } catch {
8142
- return;
8143
- }
8144
- for (const entry of entries) {
8145
- const full = (0, import_node_path15.join)(dir, entry.name);
8146
- if (entry.isDirectory()) {
8147
- await walk(full);
8148
- } else if (entry.name.endsWith(".ts")) {
8149
- const src = await (0, import_promises7.readFile)(full, "utf-8");
8150
- if (src.includes("z.") && !src.includes("from 'zod'") && !src.includes('from "zod"')) {
8151
- await (0, import_promises7.writeFile)(full, `import { z } from 'zod';
8152
- ${src}`, "utf-8");
8153
- fixed++;
8154
- }
8155
- }
8156
- }
8157
- }, "walk");
8158
- await walk(zodOutputDir);
8159
- return fixed;
8160
- }, "fixZodImports");
8161
8145
  var pullAndGenerate = /* @__PURE__ */ __name(async (input) => {
8162
- const { root, prismaConfigPath, schemaPath, zodOutputDir } = input;
8146
+ const { root, prismaConfigPath, schemaPath } = input;
8163
8147
  loadDotenv(root);
8164
8148
  const backupPath = await backupSchema(schemaPath);
8165
8149
  const dbPull = await prismaDbPull(root, prismaConfigPath);
8166
- if (!dbPull.ok) {
8167
- return {
8168
- ok: false,
8169
- backupPath,
8170
- dbPull
8171
- };
8172
- }
8150
+ if (!dbPull.ok) return {
8151
+ ok: false,
8152
+ backupPath,
8153
+ dbPull
8154
+ };
8173
8155
  const caseFormat = await prismaCaseFormat(root, schemaPath);
8174
8156
  const normalized = await normalizeSchema(schemaPath);
8175
- const normalizeResult = {
8176
- ok: true,
8177
- renamed: normalized.renamed
8178
- };
8179
8157
  const generate = await prismaGenerate(root, prismaConfigPath);
8180
- let zodImportsFixed;
8181
- if (generate.ok && zodOutputDir) {
8182
- zodImportsFixed = await fixZodImports(zodOutputDir);
8183
- }
8184
8158
  return {
8185
8159
  ok: true,
8186
8160
  backupPath,
8187
8161
  dbPull,
8188
8162
  caseFormat,
8189
- normalizeSchema: normalizeResult,
8190
- generate,
8191
- zodImportsFixed
8163
+ normalizeSchema: {
8164
+ ok: true,
8165
+ renamed: normalized.renamed
8166
+ },
8167
+ generate
8192
8168
  };
8193
8169
  }, "pullAndGenerate");
8194
8170
  var normalizeSchema = /* @__PURE__ */ __name(async (schemaPath, configDir) => {
@@ -8889,6 +8865,8 @@ var injectEnumValues2 = /* @__PURE__ */ __name((columns, enums) => {
8889
8865
  };
8890
8866
  const options = col.fieldInput.options ?? {};
8891
8867
  if (!("values" in options)) options.values = values;
8868
+ if (!("emitObject" in options)) options.emitObject = true;
8869
+ if (!("displayKey" in options)) options.displayKey = "label";
8892
8870
  col.fieldInput.options = options;
8893
8871
  }
8894
8872
  }, "injectEnumValues");
@@ -9176,7 +9154,10 @@ var buildSubResources = /* @__PURE__ */ __name((columns, parentRoute, parentMode
9176
9154
  // A custom child has no Prisma model. Leave it empty rather than
9177
9155
  // falling back to the column id, which would produce a bogus
9178
9156
  // `prisma[<column>]` lookup at query time.
9179
- childModel: childKind === "custom" ? "" : c.id,
9157
+ // Use the child resource's declared model name so plural column ids
9158
+ // (e.g. "books") resolve to the correct Prisma delegate (prisma.book).
9159
+ // ponytail: charAt toLowerCase is cheap; Prisma model names are always PascalCase
9160
+ childModel: childKind === "custom" ? "" : childJson?.model ? childJson.model.charAt(0).toLowerCase() + childJson.model.slice(1) : c.id,
9180
9161
  foreignKey: c.fieldInput?.foreignKey ?? `${parentModel}Id`,
9181
9162
  name: childJson?.name ?? childRoute,
9182
9163
  title: childJson?.title ?? childJson?.tag ?? childRoute,
@@ -9624,12 +9605,12 @@ var FileSystemResourceConfigLoader = class extends ResourceConfigLoader2 {
9624
9605
  // src/lib/crud/status/status.service.ts
9625
9606
  var import_node_fs11 = require("fs");
9626
9607
  var import_node_path19 = require("path");
9627
- var import_node_url = require("url");
9608
+ var import_node_url2 = require("url");
9628
9609
  var CONNECTION_STRING_PATTERN = /(?:postgresql|postgres|mysql|mongodb|sqlserver|sqlite):\/\/[^\s"')]+/gi;
9629
9610
  var stripConnectionStrings = /* @__PURE__ */ __name((message) => message.replace(CONNECTION_STRING_PATTERN, "[REDACTED]"), "stripConnectionStrings");
9630
9611
  var getCroutonVersion = /* @__PURE__ */ __name(() => {
9631
9612
  try {
9632
- const startDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path19.dirname)((0, import_node_url.fileURLToPath)(importMetaUrl));
9613
+ const startDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path19.dirname)((0, import_node_url2.fileURLToPath)(importMetaUrl));
9633
9614
  let dir = startDir;
9634
9615
  while (dir !== (0, import_node_path19.dirname)(dir)) {
9635
9616
  const pkgPath = (0, import_node_path19.join)(dir, "package.json");
@@ -9954,7 +9935,7 @@ var createStatusController = /* @__PURE__ */ __name((enumRegistry, translationRe
9954
9935
 
9955
9936
  // src/lib/crouton-api.module.ts
9956
9937
  var import_node_path20 = require("path");
9957
- var import_node_url2 = require("url");
9938
+ var import_node_url3 = require("url");
9958
9939
  function _ts_decorate11(decorators, target, key, desc2) {
9959
9940
  var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
9960
9941
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -9992,7 +9973,7 @@ var CroutonApiModule = class _CroutonApiModule {
9992
9973
  const dataSourceRegistry = new DataSourceRegistry(dataSources);
9993
9974
  const guardRegistry = new SecurityGuardRegistry(security?.guards ?? {});
9994
9975
  const moduleDefaultSecurity = security?.default;
9995
- const startDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path20.dirname)((0, import_node_url2.fileURLToPath)(importMetaUrl));
9976
+ const startDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path20.dirname)((0, import_node_url3.fileURLToPath)(importMetaUrl));
9996
9977
  const enumRegistry = loadEnumRegistry(startDir, config.enumsFile);
9997
9978
  const validConfigs = [];
9998
9979
  for (const c of configs) {