@ghentcdh/create-crouton 0.0.1-alpha.39 → 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
@@ -19002,6 +19002,57 @@ var CalculatedColumnSchema = external_exports.object({
19002
19002
  fieldInput: FieldInputSchema.optional()
19003
19003
  }).transform(normalizeLabel);
19004
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
+
19005
19056
  // ../crouton-core/src/lib/resource/Column.ts
19006
19057
  var WhenConditionSchema = external_exports.object({
19007
19058
  field: external_exports.string(),
@@ -19056,6 +19107,41 @@ var JsonColumnSchema = external_exports.object({
19056
19107
  // default: false — exactly one column should set this
19057
19108
  showInLookup: external_exports.boolean().default(false),
19058
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
+ */
19059
19145
  columnType: external_exports.string().default("string"),
19060
19146
  // default: 'string'
19061
19147
  fieldInput: FieldInputSchema.optional(),
@@ -19092,6 +19178,22 @@ var JsonColumnSchema = external_exports.object({
19092
19178
  // per-sub-column overrides, only used with `extend`
19093
19179
  });
19094
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
+
19095
19197
  // ../crouton-core/src/lib/resource/Sidebar.schema.ts
19096
19198
  var SidebarGroupSchema = zod_default.object({
19097
19199
  /** Human-readable heading shown in the sidebar. Defaults to a title-cased version of the slug. */
@@ -19234,20 +19336,40 @@ var ResourceJsonShape = external_exports.object({
19234
19336
  schemaVersion: external_exports.number().int().positive().optional(),
19235
19337
  /** When `true`, the resource lives in the repo but is NOT loaded/served (work in progress). */
19236
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,
19237
19345
  name: external_exports.string(),
19238
19346
  // required — unique id, used as the frontend form id
19239
19347
  route: external_exports.string(),
19240
19348
  // required — URL segment for generated endpoints
19241
- model: external_exports.string(),
19242
- // 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(),
19243
19355
  tag: external_exports.string(),
19244
19356
  // required — OpenAPI tag
19245
19357
  title: external_exports.string().optional(),
19246
19358
  // no computed default — used as UI display title
19247
19359
  table: external_exports.string().optional(),
19248
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(),
19249
19366
  database: external_exports.string().optional(),
19250
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(),
19251
19373
  sidebar: SidebarSchema.default(SidebarSchema.parse({})),
19252
19374
  // default: shown, alphabetically ordered, ungrouped
19253
19375
  display: JsonDisplaySchema.default(JsonDisplaySchema.parse({})),
@@ -19272,7 +19394,58 @@ var ResourceJsonShape = external_exports.object({
19272
19394
  */
19273
19395
  include: external_exports.array(JsonIncludeEntrySchema).default([])
19274
19396
  });
19275
- 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) => {
19276
19449
  const title = obj.title ?? labelFromId(obj.name);
19277
19450
  const schemaVersion = obj.schemaVersion ?? BASELINE_RESOURCE_VERSION;
19278
19451
  return {
@@ -19290,7 +19463,7 @@ var RulesetSchema = external_exports.object({
19290
19463
  hideIdInView: external_exports.boolean().default(true),
19291
19464
  hideTimestamps: external_exports.boolean().default(true),
19292
19465
  hideForeignKeys: external_exports.boolean().default(true),
19293
- includeRelations: external_exports.boolean().default(false),
19466
+ includeRelations: external_exports.boolean().default(true),
19294
19467
  hideRelationsInTable: external_exports.boolean().default(true),
19295
19468
  showRelationsInForm: external_exports.boolean().default(true),
19296
19469
  enumValueLabel: external_exports.boolean().default(true),
@@ -19299,6 +19472,14 @@ var RulesetSchema = external_exports.object({
19299
19472
  JsonOperationsSchema.parse({})
19300
19473
  )
19301
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
+ });
19302
19483
  var CroutonConfigSchema = external_exports.object({
19303
19484
  /**
19304
19485
  * Application title served to the frontend via `GET /_app/layout`.
@@ -19328,7 +19509,9 @@ var CroutonConfigSchema = external_exports.object({
19328
19509
  * Whether form fields are saved automatically as the user edits them.
19329
19510
  * @default true
19330
19511
  */
19331
- autoSave: external_exports.boolean().default(true)
19512
+ autoSave: external_exports.boolean().default(true),
19513
+ /** Optional i18n / translation configuration. */
19514
+ i18n: I18nConfigSchema.optional()
19332
19515
  });
19333
19516
 
19334
19517
  // ../crouton-core/src/lib/view/view.schema.ts
@@ -19346,6 +19529,36 @@ var ViewConfigSchema = external_exports.object({
19346
19529
  defaultSort: external_exports.string().optional()
19347
19530
  });
19348
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
+
19349
19562
  // ../crouton-codegen/src/util.ts
19350
19563
  import { access } from "fs/promises";
19351
19564
 
@@ -19607,7 +19820,7 @@ var runCreate = async (name, opts) => {
19607
19820
  const tokens = {
19608
19821
  name,
19609
19822
  Name: toTitle(name),
19610
- version: true ? "0.0.1-alpha.39" : "latest",
19823
+ version: true ? "0.0.1-alpha.42" : "latest",
19611
19824
  year: String((/* @__PURE__ */ new Date()).getFullYear()),
19612
19825
  pmRun: pm === "npm" ? "npm run" : pm,
19613
19826
  urlEnv: "DATABASE_URL",