@ghentcdh/create-crouton 0.0.1-alpha.52 → 0.0.1-alpha.54

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
@@ -19294,8 +19294,14 @@ var SecuritySchema = external_exports.union([
19294
19294
  ]);
19295
19295
 
19296
19296
  // ../crouton-core/src/lib/data-source/Operations.schema.ts
19297
+ var ExternalOpEntry = external_exports.object({
19298
+ uri: external_exports.string(),
19299
+ method: external_exports.string().optional(),
19300
+ security: SecuritySchema.optional()
19301
+ });
19297
19302
  var OpEntry = external_exports.union([
19298
19303
  external_exports.boolean(),
19304
+ ExternalOpEntry,
19299
19305
  external_exports.object({ security: SecuritySchema.optional() })
19300
19306
  ]);
19301
19307
  var BoolOrUpsertSchema = external_exports.union([
@@ -19459,12 +19465,6 @@ var refineByKind = (obj, ctx) => {
19459
19465
  path: ["parent"],
19460
19466
  message: '"parent" is only supported on a custom resource. A prisma resource is nested by declaring a relation column on its parent.'
19461
19467
  });
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
19468
  }
19469
19469
  };
19470
19470
  var buildResourceJsonSchema = () => {
@@ -19477,11 +19477,8 @@ var buildResourceJsonSchema = () => {
19477
19477
  (raw) => {
19478
19478
  if (raw && typeof raw === "object" && !Array.isArray(raw)) {
19479
19479
  const obj = raw;
19480
- if (obj["kind"] === void 0) {
19481
- return {
19482
- ...obj,
19483
- kind: obj["model"] !== void 0 ? "prisma" : "custom"
19484
- };
19480
+ if (obj["kind"] === void 0 && obj["model"] !== void 0) {
19481
+ return { ...obj, kind: "prisma" };
19485
19482
  }
19486
19483
  }
19487
19484
  return raw;
@@ -19625,8 +19622,13 @@ var SchemaInputSchema = external_exports.union([
19625
19622
  ]);
19626
19623
 
19627
19624
  // ../crouton-core/src/lib/compile/definition.schema.ts
19625
+ var ExternalOperationDefSchema = external_exports.object({
19626
+ uri: external_exports.string(),
19627
+ method: external_exports.string().optional()
19628
+ });
19628
19629
  var OperationDefSchema = external_exports.union([
19629
19630
  external_exports.literal(true),
19631
+ ExternalOperationDefSchema,
19630
19632
  external_exports.object({
19631
19633
  schema: SchemaInputSchema.optional(),
19632
19634
  security: SecuritySchema.optional()
@@ -38663,6 +38665,7 @@ var PRISMA_PROVIDERS = {
38663
38665
  mongodb: "mongodb",
38664
38666
  cockroachdb: "cockroachdb"
38665
38667
  };
38668
+ var toPascalCase = (s) => s.replace(/[-_](.)/g, (_3, c) => c.toUpperCase()).replace(/^(.)/, (_3, c) => c.toUpperCase());
38666
38669
  var relImport = (fromDir, toDir) => {
38667
38670
  const rel = relative(fromDir, toDir).split(/[\\/]/).join(posix.sep);
38668
38671
  return rel.startsWith(".") ? rel : `./${rel}`;
@@ -38679,25 +38682,36 @@ var buildDatasourceFiles = (opts) => {
38679
38682
  ...opts.urlEnv ? { urlEnv: opts.urlEnv } : {},
38680
38683
  ...isDefault ? { default: true } : {}
38681
38684
  };
38682
- const indexTs2 = `import type { DataSourceAdapter } from '@ghentcdh/crouton-api';
38683
-
38684
- const adapter: DataSourceAdapter = {
38685
- kind: 'custom',
38685
+ const indexTs2 = `import { PrismaDataSourceAdapter } from '@ghentcdh/crouton-api';
38686
+ import type { AdapterCrudContext } from '@ghentcdh/crouton-api';
38687
+ import type { ListRequest } from '@ghentcdh/crouton-core';
38686
38688
 
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;
38689
+ /**
38690
+ * ${name} datasource adapter.
38691
+ *
38692
+ * Extends PrismaDataSourceAdapter so every Prisma-backed method is available
38693
+ * by default. Override only the methods you need to customise.
38694
+ *
38695
+ * Example \u2014 enrich findAll results:
38696
+ *
38697
+ * override async findAll(model: string, params: ListRequest, ctx: AdapterCrudContext) {
38698
+ * const result = await super.findAll(model, params, ctx);
38699
+ * return { ...result, data: result.data.map(decorate) };
38700
+ * }
38701
+ *
38702
+ * To use a non-Prisma backend, remove the super() call and implement methods directly.
38703
+ */
38704
+ export default class ${toPascalCase(name)}Adapter extends PrismaDataSourceAdapter {
38705
+ constructor() {
38706
+ // Replace with your own client if not using Prisma.
38707
+ super(null);
38708
+ }
38709
+ }
38697
38710
  `;
38698
38711
  const notes2 = [];
38699
38712
  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")}.`);
38713
+ notes2.push(`Implement your adapter in ${posix.join(dsDir, "index.ts")} \u2014 override only the methods you need.`);
38714
+ notes2.push("Pass your client to super() in the constructor, or replace super() with direct calls for a non-Prisma backend.");
38701
38715
  return {
38702
38716
  files: [
38703
38717
  { path: posix.join(dsDir, "data-source.json"), contents: `${JSON.stringify(dataSourceJson2, null, 2)}
@@ -38931,7 +38945,7 @@ var runCreate = async (name, opts) => {
38931
38945
  const tokens = {
38932
38946
  name,
38933
38947
  Name: toTitle(name),
38934
- version: true ? "0.0.1-alpha.52" : "latest",
38948
+ version: true ? "0.0.1-alpha.54" : "latest",
38935
38949
  year: String((/* @__PURE__ */ new Date()).getFullYear()),
38936
38950
  pmRun: pm === "npm" ? "npm run" : pm,
38937
38951
  urlEnv: "DATABASE_URL",