@ghentcdh/create-crouton 0.0.1-alpha.53 → 0.0.1-alpha.55

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
@@ -18857,6 +18857,39 @@ var ResourceTableActionSchema = external_exports.union([
18857
18857
  ResourceLinkActionSchema
18858
18858
  ]);
18859
18859
 
18860
+ // ../crouton-core/src/lib/resource/Layout.schema.ts
18861
+ var LayoutControlSchema = external_exports.union([
18862
+ external_exports.string(),
18863
+ external_exports.object({
18864
+ id: external_exports.string(),
18865
+ colspan: external_exports.number().int().min(1).max(12).optional(),
18866
+ rowspan: external_exports.number().int().min(1).optional(),
18867
+ width: external_exports.string().optional(),
18868
+ label: external_exports.string().optional(),
18869
+ hideLabel: external_exports.boolean().optional(),
18870
+ type: external_exports.string().optional(),
18871
+ options: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
18872
+ })
18873
+ ]);
18874
+ var LayoutNodeSchema = external_exports.lazy(
18875
+ () => external_exports.object({
18876
+ type: external_exports.enum(["grid", "vertical", "horizontal", "collapse", "group"]).optional(),
18877
+ columns: external_exports.number().int().min(1).max(12).optional(),
18878
+ title: external_exports.string().optional(),
18879
+ titleKey: external_exports.string().optional(),
18880
+ colspan: external_exports.number().int().min(1).max(12).optional(),
18881
+ rowspan: external_exports.number().int().min(1).optional(),
18882
+ label: external_exports.string().optional(),
18883
+ controls: external_exports.array(LayoutControlSchema).optional(),
18884
+ items: external_exports.array(LayoutNodeSchema).optional()
18885
+ })
18886
+ );
18887
+ var LayoutSchema = external_exports.object({
18888
+ form: LayoutNodeSchema.optional(),
18889
+ view: LayoutNodeSchema.optional(),
18890
+ table: LayoutNodeSchema.optional()
18891
+ });
18892
+
18860
18893
  // ../crouton-core/src/lib/resource/FieldInput.schema.ts
18861
18894
  var RelationType = external_exports.enum([
18862
18895
  "oneToOne",
@@ -19294,17 +19327,16 @@ var SecuritySchema = external_exports.union([
19294
19327
  ]);
19295
19328
 
19296
19329
  // ../crouton-core/src/lib/data-source/Operations.schema.ts
19330
+ var ExternalOpEntry = external_exports.object({
19331
+ uri: external_exports.string(),
19332
+ method: external_exports.string().optional(),
19333
+ security: SecuritySchema.optional()
19334
+ });
19297
19335
  var OpEntry = external_exports.union([
19298
19336
  external_exports.boolean(),
19337
+ ExternalOpEntry,
19299
19338
  external_exports.object({ security: SecuritySchema.optional() })
19300
19339
  ]);
19301
- var BoolOrUpsertSchema = external_exports.union([
19302
- external_exports.boolean(),
19303
- external_exports.object({
19304
- upsertOn: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]),
19305
- security: SecuritySchema.optional()
19306
- })
19307
- ]);
19308
19340
  var JsonOperationsSchema = external_exports.object({
19309
19341
  findAll: OpEntry.default(true),
19310
19342
  // default: true — only explicit `false` disables it
@@ -19316,8 +19348,6 @@ var JsonOperationsSchema = external_exports.object({
19316
19348
  // default: true
19317
19349
  patch: OpEntry.default(true),
19318
19350
  // default: true
19319
- upsert: BoolOrUpsertSchema.default(false),
19320
- // default: disabled; `true` throws at load time — must be `{ upsertOn }`
19321
19351
  delete: OpEntry.default(true)
19322
19352
  // default: true
19323
19353
  });
@@ -19416,7 +19446,9 @@ var ResourceJsonShape = external_exports.object({
19416
19446
  * `{ "relation": "text_author", "include": ["author"] }` →
19417
19447
  * `include: { text_author: { include: { author: true } } }`
19418
19448
  */
19419
- include: external_exports.array(JsonIncludeEntrySchema).default([])
19449
+ include: external_exports.array(JsonIncludeEntrySchema).default([]),
19450
+ /** Explicit layout for generated views (`form`, `view`, `table`). When absent, source-order grid is used. */
19451
+ layout: LayoutSchema.optional()
19420
19452
  });
19421
19453
  var refineByKind = (obj, ctx) => {
19422
19454
  if (obj.kind === "custom") {
@@ -19459,12 +19491,6 @@ var refineByKind = (obj, ctx) => {
19459
19491
  path: ["parent"],
19460
19492
  message: '"parent" is only supported on a custom resource. A prisma resource is nested by declaring a relation column on its parent.'
19461
19493
  });
19462
- } else if (obj.model === void 0) {
19463
- ctx.addIssue({
19464
- code: "custom",
19465
- path: ["model"],
19466
- message: '"model" is required for a prisma-backed resource. Set "kind": "custom" for a resource with no Prisma model.'
19467
- });
19468
19494
  }
19469
19495
  };
19470
19496
  var buildResourceJsonSchema = () => {
@@ -19477,11 +19503,8 @@ var buildResourceJsonSchema = () => {
19477
19503
  (raw) => {
19478
19504
  if (raw && typeof raw === "object" && !Array.isArray(raw)) {
19479
19505
  const obj = raw;
19480
- if (obj["kind"] === void 0) {
19481
- return {
19482
- ...obj,
19483
- kind: obj["model"] !== void 0 ? "prisma" : "custom"
19484
- };
19506
+ if (obj["kind"] === void 0 && obj["model"] !== void 0) {
19507
+ return { ...obj, kind: "prisma" };
19485
19508
  }
19486
19509
  }
19487
19510
  return raw;
@@ -19603,6 +19626,7 @@ var CompiledSubResourceConfigSchema = external_exports.object({
19603
19626
  operations: JsonOperationsSchema,
19604
19627
  actions: external_exports.array(JsonActionSchema).optional(),
19605
19628
  modalSize: external_exports.enum(["xs", "sm", "lg", "xl"]).optional(),
19629
+ display: JsonDisplaySchema.optional(),
19606
19630
  include: external_exports.array(JsonIncludeEntrySchema).optional(),
19607
19631
  calculatedColumns: external_exports.array(CalculatedColumnSchema).optional(),
19608
19632
  includeInFindOne: external_exports.boolean().optional(),
@@ -19625,25 +19649,24 @@ var SchemaInputSchema = external_exports.union([
19625
19649
  ]);
19626
19650
 
19627
19651
  // ../crouton-core/src/lib/compile/definition.schema.ts
19652
+ var ExternalOperationDefSchema = external_exports.object({
19653
+ uri: external_exports.string(),
19654
+ method: external_exports.string().optional()
19655
+ });
19628
19656
  var OperationDefSchema = external_exports.union([
19629
19657
  external_exports.literal(true),
19658
+ ExternalOperationDefSchema,
19630
19659
  external_exports.object({
19631
19660
  schema: SchemaInputSchema.optional(),
19632
19661
  security: SecuritySchema.optional()
19633
19662
  })
19634
19663
  ]);
19635
- var UpsertOperationDefSchema = external_exports.object({
19636
- schema: SchemaInputSchema.optional(),
19637
- upsertOn: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]),
19638
- security: SecuritySchema.optional()
19639
- });
19640
19664
  var ResourceDefinitionSchema = external_exports.object({
19641
19665
  findAll: OperationDefSchema.optional(),
19642
19666
  findOne: OperationDefSchema.optional(),
19643
19667
  create: OperationDefSchema.optional(),
19644
19668
  update: OperationDefSchema.optional(),
19645
19669
  patch: OperationDefSchema.optional(),
19646
- upsert: UpsertOperationDefSchema.optional(),
19647
19670
  delete: OperationDefSchema.optional()
19648
19671
  });
19649
19672
  var DefinitionCallbackSchema = external_exports.function({
@@ -38663,6 +38686,7 @@ var PRISMA_PROVIDERS = {
38663
38686
  mongodb: "mongodb",
38664
38687
  cockroachdb: "cockroachdb"
38665
38688
  };
38689
+ var toPascalCase = (s) => s.replace(/[-_](.)/g, (_3, c) => c.toUpperCase()).replace(/^(.)/, (_3, c) => c.toUpperCase());
38666
38690
  var relImport = (fromDir, toDir) => {
38667
38691
  const rel = relative(fromDir, toDir).split(/[\\/]/).join(posix.sep);
38668
38692
  return rel.startsWith(".") ? rel : `./${rel}`;
@@ -38679,25 +38703,36 @@ var buildDatasourceFiles = (opts) => {
38679
38703
  ...opts.urlEnv ? { urlEnv: opts.urlEnv } : {},
38680
38704
  ...isDefault ? { default: true } : {}
38681
38705
  };
38682
- const indexTs2 = `import type { DataSourceAdapter } from '@ghentcdh/crouton-api';
38706
+ const indexTs2 = `import { PrismaDataSourceAdapter } from '@ghentcdh/crouton-api';
38707
+ import type { AdapterCrudContext } from '@ghentcdh/crouton-api';
38708
+ import type { ListRequest } from '@ghentcdh/crouton-core';
38683
38709
 
38684
- const adapter: DataSourceAdapter = {
38685
- kind: 'custom',
38686
-
38687
- supports(_model: string): boolean {
38688
- return true;
38689
- },
38690
-
38691
- async disconnect(): Promise<void> {
38692
- // clean up connections
38693
- },
38694
- };
38695
-
38696
- export default adapter;
38710
+ /**
38711
+ * ${name} datasource adapter.
38712
+ *
38713
+ * Extends PrismaDataSourceAdapter so every Prisma-backed method is available
38714
+ * by default. Override only the methods you need to customise.
38715
+ *
38716
+ * Example \u2014 enrich findAll results:
38717
+ *
38718
+ * override async findAll(model: string, params: ListRequest, ctx: AdapterCrudContext) {
38719
+ * const result = await super.findAll(model, params, ctx);
38720
+ * return { ...result, data: result.data.map(decorate) };
38721
+ * }
38722
+ *
38723
+ * To use a non-Prisma backend, remove the super() call and implement methods directly.
38724
+ */
38725
+ export default class ${toPascalCase(name)}Adapter extends PrismaDataSourceAdapter {
38726
+ constructor() {
38727
+ // Replace with your own client if not using Prisma.
38728
+ super(null);
38729
+ }
38730
+ }
38697
38731
  `;
38698
38732
  const notes2 = [];
38699
38733
  if (opts.urlEnv) notes2.push(`Add ${opts.urlEnv} to your .env (and .env.example).`);
38700
- notes2.push(`Implement your DataSourceAdapter in ${posix.join(dsDir, "index.ts")}.`);
38734
+ notes2.push(`Implement your adapter in ${posix.join(dsDir, "index.ts")} \u2014 override only the methods you need.`);
38735
+ notes2.push("Pass your client to super() in the constructor, or replace super() with direct calls for a non-Prisma backend.");
38701
38736
  return {
38702
38737
  files: [
38703
38738
  { path: posix.join(dsDir, "data-source.json"), contents: `${JSON.stringify(dataSourceJson2, null, 2)}
@@ -38931,7 +38966,7 @@ var runCreate = async (name, opts) => {
38931
38966
  const tokens = {
38932
38967
  name,
38933
38968
  Name: toTitle(name),
38934
- version: true ? "0.0.1-alpha.53" : "latest",
38969
+ version: true ? "0.0.1-alpha.55" : "latest",
38935
38970
  year: String((/* @__PURE__ */ new Date()).getFullYear()),
38936
38971
  pmRun: pm === "npm" ? "npm run" : pm,
38937
38972
  urlEnv: "DATABASE_URL",