@ghentcdh/create-crouton 0.0.1-alpha.38 → 0.0.1-alpha.42

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.js CHANGED
@@ -18945,6 +18945,14 @@ var FieldInputSchema = external_exports.object({
18945
18945
  /** Override the display order in form views. Lower values come first. */
18946
18946
  position: external_exports.number().optional(),
18947
18947
  // default: source order
18948
+ /**
18949
+ * Value to pre-fill this field with on the create form. Injected into the
18950
+ * generated form view's JSON Schema as `properties[id].default`, which
18951
+ * `parseValue({})` (see `@ghentcdh/crouton-vue`'s `form-def.ts`) applies when
18952
+ * opening a blank record. Not applicable to `format: "relation"` fields —
18953
+ * relation columns are excluded from the picked data schema entirely.
18954
+ */
18955
+ defaultValue: external_exports.unknown().optional(),
18948
18956
  options: external_exports.union([RelationFieldInputOptionsSchema, external_exports.unknown()]).optional(),
18949
18957
  /** Nested array detail layout (renders via `detailFixed`). */
18950
18958
  detail: DetailConfigSchema.optional()
@@ -18994,6 +19002,57 @@ var CalculatedColumnSchema = external_exports.object({
18994
19002
  fieldInput: FieldInputSchema.optional()
18995
19003
  }).transform(normalizeLabel);
18996
19004
 
19005
+ // ../crouton-core/src/lib/resource/ColumnType.schema.ts
19006
+ var ColumnTypeShorthandSchema = external_exports.enum([
19007
+ "string",
19008
+ "number",
19009
+ "integer",
19010
+ "boolean",
19011
+ "date",
19012
+ "date-time",
19013
+ "object",
19014
+ "array"
19015
+ ]);
19016
+ var JsonSchemaFragmentSchema = external_exports.lazy(
19017
+ () => external_exports.object({
19018
+ type: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
19019
+ format: external_exports.string().optional(),
19020
+ enum: external_exports.array(external_exports.unknown()).optional(),
19021
+ const: external_exports.unknown().optional(),
19022
+ nullable: external_exports.boolean().optional(),
19023
+ properties: external_exports.record(external_exports.string(), JsonSchemaFragmentSchema).optional(),
19024
+ required: external_exports.array(external_exports.string()).optional(),
19025
+ items: JsonSchemaFragmentSchema.optional(),
19026
+ additionalProperties: external_exports.union([external_exports.boolean(), JsonSchemaFragmentSchema]).optional(),
19027
+ title: external_exports.string().optional(),
19028
+ description: external_exports.string().optional(),
19029
+ default: external_exports.unknown().optional(),
19030
+ minimum: external_exports.number().optional(),
19031
+ maximum: external_exports.number().optional(),
19032
+ minLength: external_exports.number().optional(),
19033
+ maxLength: external_exports.number().optional(),
19034
+ pattern: external_exports.string().optional()
19035
+ }).catchall(external_exports.unknown())
19036
+ );
19037
+ var ColumnTypeSchema = external_exports.union([
19038
+ ColumnTypeShorthandSchema,
19039
+ JsonSchemaFragmentSchema
19040
+ ]);
19041
+ var SHORTHAND_FRAGMENTS = {
19042
+ string: { type: "string" },
19043
+ number: { type: "number" },
19044
+ integer: { type: "integer" },
19045
+ boolean: { type: "boolean" },
19046
+ date: { type: "string", format: "date" },
19047
+ "date-time": { type: "string", format: "date-time" },
19048
+ object: { type: "object" },
19049
+ array: { type: "array" }
19050
+ };
19051
+ var NESTED_SHORTHANDS = {
19052
+ date: SHORTHAND_FRAGMENTS.date,
19053
+ "date-time": SHORTHAND_FRAGMENTS["date-time"]
19054
+ };
19055
+
18997
19056
  // ../crouton-core/src/lib/resource/Column.ts
18998
19057
  var WhenConditionSchema = external_exports.object({
18999
19058
  field: external_exports.string(),
@@ -19048,6 +19107,41 @@ var JsonColumnSchema = external_exports.object({
19048
19107
  // default: false — exactly one column should set this
19049
19108
  showInLookup: external_exports.boolean().default(false),
19050
19109
  // default: false
19110
+ /**
19111
+ * Data type of the column, as a shorthand name (`"string"`, `"integer"`, …)
19112
+ * or a full JSON Schema fragment:
19113
+ *
19114
+ * ```json
19115
+ * "type": {
19116
+ * "type": "object",
19117
+ * "properties": { "id": { "type": "string" }, "name": { "type": "string" } }
19118
+ * }
19119
+ * ```
19120
+ *
19121
+ * Required on every column of a `kind: "custom"` resource, where it is the
19122
+ * only source of the resource's json_schema. Optional on a `prisma`
19123
+ * resource, whose schema is derived from the Zod model.
19124
+ */
19125
+ type: ColumnTypeSchema.optional(),
19126
+ /**
19127
+ * Whether the form requires a value.
19128
+ *
19129
+ * A prisma resource derives `required` from its Zod model, so this is an
19130
+ * override in either direction: `true` adds the column to the form schema's
19131
+ * `required` array, `false` removes it, and omitting it leaves the model's
19132
+ * answer alone. A `kind: "custom"` resource has no model, so this is the only
19133
+ * way to mark one of its fields required.
19134
+ *
19135
+ * Applies to the **form** view only — a required filter input would make the
19136
+ * filter panel unsubmittable, and the table and view schemas are read-only.
19137
+ * Ignored on the id column and on columns that are neither createable nor
19138
+ * updateable, since the form cannot supply a value for those.
19139
+ */
19140
+ required: external_exports.boolean().optional(),
19141
+ /**
19142
+ * @deprecated Use `type` instead. Retained because it is still consumed by
19143
+ * the boolean predicate and the schema-less sub-resource view builder.
19144
+ */
19051
19145
  columnType: external_exports.string().default("string"),
19052
19146
  // default: 'string'
19053
19147
  fieldInput: FieldInputSchema.optional(),
@@ -19084,6 +19178,22 @@ var JsonColumnSchema = external_exports.object({
19084
19178
  // per-sub-column overrides, only used with `extend`
19085
19179
  });
19086
19180
 
19181
+ // ../crouton-core/src/lib/resource/ParentRef.schema.ts
19182
+ var ParentRefSchema = external_exports.object({
19183
+ /** Route segment of the parent, e.g. `"group"`. */
19184
+ route: external_exports.string(),
19185
+ /**
19186
+ * Name of the path parameter carrying the parent id, e.g. `"groupId"`.
19187
+ * Avoid `"id"` — that is the child's own id in `/:id` routes.
19188
+ */
19189
+ param: external_exports.string().default("parentId"),
19190
+ /** Type of the parent id, used to coerce the path param. Defaults to `'string'`. */
19191
+ idType: external_exports.enum(["string", "number"]).optional()
19192
+ });
19193
+
19194
+ // ../crouton-core/src/lib/resource/ResourceKind.ts
19195
+ var ResourceKindSchema = external_exports.enum(["prisma", "custom"]).default("prisma");
19196
+
19087
19197
  // ../crouton-core/src/lib/resource/Sidebar.schema.ts
19088
19198
  var SidebarGroupSchema = zod_default.object({
19089
19199
  /** Human-readable heading shown in the sidebar. Defaults to a title-cased version of the slug. */
@@ -19226,20 +19336,40 @@ var ResourceJsonShape = external_exports.object({
19226
19336
  schemaVersion: external_exports.number().int().positive().optional(),
19227
19337
  /** When `true`, the resource lives in the repo but is NOT loaded/served (work in progress). */
19228
19338
  draft: external_exports.boolean().optional().default(false),
19339
+ /**
19340
+ * Where the data comes from. `prisma` (the default) is backed by a Prisma
19341
+ * model plus a `schema.ts`; `custom` is configuration only and the developer
19342
+ * supplies a `repository.ts`. See `./ResourceKind`.
19343
+ */
19344
+ kind: ResourceKindSchema,
19229
19345
  name: external_exports.string(),
19230
19346
  // required — unique id, used as the frontend form id
19231
19347
  route: external_exports.string(),
19232
19348
  // required — URL segment for generated endpoints
19233
- model: external_exports.string(),
19234
- // required — Prisma model name
19349
+ /**
19350
+ * Prisma model name. Required when `kind` is `prisma` (enforced by the
19351
+ * refinement on `ResourceJsonSchema`), and must be absent when `kind` is
19352
+ * `custom` — there is no Prisma delegate to address.
19353
+ */
19354
+ model: external_exports.string().optional(),
19235
19355
  tag: external_exports.string(),
19236
19356
  // required — OpenAPI tag
19237
19357
  title: external_exports.string().optional(),
19238
19358
  // no computed default — used as UI display title
19239
19359
  table: external_exports.string().optional(),
19240
19360
  // default: same as `model`
19361
+ /**
19362
+ * Type of the resource's primary key, used to coerce `:id` route params.
19363
+ * Written by codegen from the Prisma model; defaults to `'string'`.
19364
+ */
19365
+ idType: external_exports.enum(["string", "number"]).optional(),
19241
19366
  database: external_exports.string().optional(),
19242
19367
  // default: project's default data source
19368
+ /**
19369
+ * Mount this resource under a parent route instead of at the top level —
19370
+ * see `./ParentRef.schema`. Only valid on a `kind: "custom"` resource.
19371
+ */
19372
+ parent: ParentRefSchema.optional(),
19243
19373
  sidebar: SidebarSchema.default(SidebarSchema.parse({})),
19244
19374
  // default: shown, alphabetically ordered, ungrouped
19245
19375
  display: JsonDisplaySchema.default(JsonDisplaySchema.parse({})),
@@ -19264,7 +19394,58 @@ var ResourceJsonShape = external_exports.object({
19264
19394
  */
19265
19395
  include: external_exports.array(JsonIncludeEntrySchema).default([])
19266
19396
  });
19267
- var ResourceJsonSchema = ResourceJsonShape.transform((obj) => {
19397
+ var refineByKind = (obj, ctx) => {
19398
+ if (obj.kind === "custom") {
19399
+ if (obj.model !== void 0) {
19400
+ ctx.addIssue({
19401
+ code: "custom",
19402
+ path: ["model"],
19403
+ message: 'A custom resource has no Prisma model. Remove "model" \u2014 data access comes from repository.ts.'
19404
+ });
19405
+ }
19406
+ if (obj.calculatedColumns?.length) {
19407
+ ctx.addIssue({
19408
+ code: "custom",
19409
+ path: ["calculatedColumns"],
19410
+ message: "calculatedColumns run raw SQL against a database table and are not supported on a custom resource. Compute the value in repository.ts instead."
19411
+ });
19412
+ }
19413
+ for (const [id, col] of Object.entries(obj.columns ?? {})) {
19414
+ if (col.fieldInput?.format === "relation" || col.fieldInput?.type === "autocomplete") {
19415
+ continue;
19416
+ }
19417
+ if (col.type === void 0) {
19418
+ ctx.addIssue({
19419
+ code: "custom",
19420
+ path: ["columns", id, "type"],
19421
+ message: `Column "${id}" needs a "type": a custom resource has no schema.ts, so its json_schema is built from the column types.`
19422
+ });
19423
+ }
19424
+ }
19425
+ if (obj.parent && obj.parent.param === "id") {
19426
+ ctx.addIssue({
19427
+ code: "custom",
19428
+ path: ["parent", "param"],
19429
+ message: `parent.param cannot be "id" \u2014 that is the child's own id in /:id routes. Use something like "groupId".`
19430
+ });
19431
+ }
19432
+ } else if (obj.parent !== void 0) {
19433
+ ctx.addIssue({
19434
+ code: "custom",
19435
+ path: ["parent"],
19436
+ message: '"parent" is only supported on a custom resource. A prisma resource is nested by declaring a relation column on its parent.'
19437
+ });
19438
+ } else if (obj.model === void 0) {
19439
+ ctx.addIssue({
19440
+ code: "custom",
19441
+ path: ["model"],
19442
+ message: '"model" is required for a prisma-backed resource. Set "kind": "custom" for a resource with no Prisma model.'
19443
+ });
19444
+ }
19445
+ };
19446
+ var ResourceJsonSchema = ResourceJsonShape.superRefine(
19447
+ refineByKind
19448
+ ).transform((obj) => {
19268
19449
  const title = obj.title ?? labelFromId(obj.name);
19269
19450
  const schemaVersion = obj.schemaVersion ?? BASELINE_RESOURCE_VERSION;
19270
19451
  return {
@@ -19282,7 +19463,7 @@ var RulesetSchema = external_exports.object({
19282
19463
  hideIdInView: external_exports.boolean().default(true),
19283
19464
  hideTimestamps: external_exports.boolean().default(true),
19284
19465
  hideForeignKeys: external_exports.boolean().default(true),
19285
- includeRelations: external_exports.boolean().default(false),
19466
+ includeRelations: external_exports.boolean().default(true),
19286
19467
  hideRelationsInTable: external_exports.boolean().default(true),
19287
19468
  showRelationsInForm: external_exports.boolean().default(true),
19288
19469
  enumValueLabel: external_exports.boolean().default(true),
@@ -19291,6 +19472,14 @@ var RulesetSchema = external_exports.object({
19291
19472
  JsonOperationsSchema.parse({})
19292
19473
  )
19293
19474
  });
19475
+ var I18nConfigSchema = external_exports.object({
19476
+ /** Default / fallback language. */
19477
+ defaultLanguage: external_exports.string().default("en"),
19478
+ /** All supported language codes. */
19479
+ languages: external_exports.array(external_exports.string()).min(1),
19480
+ /** Directory containing `<lang>.json` bundles, relative to project root. */
19481
+ translationsDir: external_exports.string().default("translations")
19482
+ });
19294
19483
  var CroutonConfigSchema = external_exports.object({
19295
19484
  /**
19296
19485
  * Application title served to the frontend via `GET /_app/layout`.
@@ -19320,7 +19509,9 @@ var CroutonConfigSchema = external_exports.object({
19320
19509
  * Whether form fields are saved automatically as the user edits them.
19321
19510
  * @default true
19322
19511
  */
19323
- autoSave: external_exports.boolean().default(true)
19512
+ autoSave: external_exports.boolean().default(true),
19513
+ /** Optional i18n / translation configuration. */
19514
+ i18n: I18nConfigSchema.optional()
19324
19515
  });
19325
19516
 
19326
19517
  // ../crouton-core/src/lib/view/view.schema.ts
@@ -19338,6 +19529,36 @@ var ViewConfigSchema = external_exports.object({
19338
19529
  defaultSort: external_exports.string().optional()
19339
19530
  });
19340
19531
 
19532
+ // ../crouton-core/src/lib/i18n/Translations.schema.ts
19533
+ var NestedStringRecord = external_exports.lazy(
19534
+ () => external_exports.record(external_exports.string(), external_exports.union([external_exports.string(), NestedStringRecord]))
19535
+ );
19536
+ var TranslationBundleSchema = external_exports.object({
19537
+ app: external_exports.object({
19538
+ title: external_exports.string().optional()
19539
+ }).optional(),
19540
+ sidebarGroups: external_exports.record(external_exports.string(), external_exports.string()).optional(),
19541
+ resources: external_exports.record(
19542
+ external_exports.string(),
19543
+ external_exports.object({
19544
+ title: external_exports.string().optional(),
19545
+ sidebar: external_exports.string().optional(),
19546
+ columns: external_exports.record(external_exports.string(), external_exports.string()).optional(),
19547
+ actions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
19548
+ subResources: external_exports.record(
19549
+ external_exports.string(),
19550
+ external_exports.object({
19551
+ title: external_exports.string().optional(),
19552
+ columns: external_exports.record(external_exports.string(), external_exports.string()).optional()
19553
+ }).optional()
19554
+ ).optional()
19555
+ }).optional()
19556
+ ).optional(),
19557
+ enums: external_exports.record(external_exports.string(), external_exports.record(external_exports.string(), external_exports.string())).optional(),
19558
+ ui: NestedStringRecord.optional(),
19559
+ validation: external_exports.record(external_exports.string(), external_exports.string()).optional()
19560
+ }).passthrough();
19561
+
19341
19562
  // ../crouton-codegen/src/util.ts
19342
19563
  import { access } from "fs/promises";
19343
19564
 
@@ -19599,7 +19820,7 @@ var runCreate = async (name, opts) => {
19599
19820
  const tokens = {
19600
19821
  name,
19601
19822
  Name: toTitle(name),
19602
- version: true ? "0.0.1-alpha.38" : "latest",
19823
+ version: true ? "0.0.1-alpha.42" : "latest",
19603
19824
  year: String((/* @__PURE__ */ new Date()).getFullYear()),
19604
19825
  pmRun: pm === "npm" ? "npm run" : pm,
19605
19826
  urlEnv: "DATABASE_URL",