@cedarjs/cli 5.0.0-canary.2584 → 5.0.0-canary.2585

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.
@@ -5,9 +5,18 @@ import { transformTSToJS } from "../../../lib/index.js";
5
5
  import { getSchema, verifyModelName } from "../../../lib/schemaHelpers.js";
6
6
  import { relationsForModel } from "../helpers.js";
7
7
  import { createHandler, templateForFile } from "../yargsHandlerHelpers.js";
8
+ function isServiceModel(schema) {
9
+ return typeof schema === "object" && schema !== null && "fields" in schema && "name" in schema;
10
+ }
8
11
  const DEFAULT_SCENARIO_NAMES = ["one", "two"];
9
12
  const parseSchema = async (model) => {
10
- const schema = await getSchema(model);
13
+ const schemaResult = await getSchema(model);
14
+ if (!isServiceModel(schemaResult)) {
15
+ throw new Error(
16
+ `No schema definition found for \`${model}\` in schema.prisma file`
17
+ );
18
+ }
19
+ const schema = schemaResult;
11
20
  const relations = {};
12
21
  let foreignKeys = [];
13
22
  const scalarFields = schema.fields.filter((field) => {
@@ -60,6 +69,7 @@ function scenarioFieldValue(field) {
60
69
  }
61
70
  }
62
71
  }
72
+ return void 0;
63
73
  }
64
74
  const fieldsToScenario = async (scalarFields, relations, foreignKeys) => {
65
75
  const data = {};
@@ -225,8 +235,11 @@ const fieldsToUpdate = async (model) => {
225
235
  return { [fieldName]: newValue };
226
236
  };
227
237
  const getIdName = async (model) => {
228
- const schema = await getSchema(model);
229
- return schema.fields.find((field) => field.isId)?.name;
238
+ const schemaResult = await getSchema(model);
239
+ if (!isServiceModel(schemaResult)) {
240
+ return void 0;
241
+ }
242
+ return schemaResult.fields.find((field) => field.isId)?.name;
230
243
  };
231
244
  const files = async ({
232
245
  name,
@@ -239,7 +252,15 @@ const files = async ({
239
252
  const model = name;
240
253
  const idName = await getIdName(model);
241
254
  const prismaImportSource = "src/lib/db";
242
- const modelRelations = relations || relationsForModel(await getSchema(model));
255
+ let modelRelations;
256
+ if (relations) {
257
+ modelRelations = relations;
258
+ } else {
259
+ const schemaResult = await getSchema(model);
260
+ if (isServiceModel(schemaResult)) {
261
+ modelRelations = relationsForModel(schemaResult);
262
+ }
263
+ }
243
264
  const serviceFile = await templateForFile({
244
265
  name,
245
266
  side: "api",
@@ -51,7 +51,7 @@ const getSchema = async (name) => {
51
51
  const getEnum = async (name) => {
52
52
  const schema = await getSchemaDefinitions();
53
53
  if (!name) {
54
- return schema.metadata.datamodel.enums;
54
+ return [...schema.metadata.datamodel.enums];
55
55
  }
56
56
  const model = schema.datamodel.enums.find((e) => e.name === name);
57
57
  if (!model) {
@@ -66,7 +66,8 @@ const getDataModel = async () => {
66
66
  return result.schemas;
67
67
  };
68
68
  const getSchemaDefinitions = async () => {
69
- return getDMMF({ datamodel: await getDataModel() });
69
+ const document = await getDMMF({ datamodel: await getDataModel() });
70
+ return document;
70
71
  };
71
72
  const getSchemaConfig = async () => {
72
73
  return getConfig({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2584",
3
+ "version": "5.0.0-canary.2585",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,17 +33,17 @@
33
33
  "dependencies": {
34
34
  "@babel/parser": "7.29.7",
35
35
  "@babel/preset-typescript": "7.29.7",
36
- "@cedarjs/api-server": "5.0.0-canary.2584",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2584",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2584",
39
- "@cedarjs/internal": "5.0.0-canary.2584",
40
- "@cedarjs/prerender": "5.0.0-canary.2584",
41
- "@cedarjs/project-config": "5.0.0-canary.2584",
42
- "@cedarjs/structure": "5.0.0-canary.2584",
43
- "@cedarjs/telemetry": "5.0.0-canary.2584",
44
- "@cedarjs/utils": "5.0.0-canary.2584",
45
- "@cedarjs/vite": "5.0.0-canary.2584",
46
- "@cedarjs/web-server": "5.0.0-canary.2584",
36
+ "@cedarjs/api-server": "5.0.0-canary.2585",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2585",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2585",
39
+ "@cedarjs/internal": "5.0.0-canary.2585",
40
+ "@cedarjs/prerender": "5.0.0-canary.2585",
41
+ "@cedarjs/project-config": "5.0.0-canary.2585",
42
+ "@cedarjs/structure": "5.0.0-canary.2585",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2585",
44
+ "@cedarjs/utils": "5.0.0-canary.2585",
45
+ "@cedarjs/vite": "5.0.0-canary.2585",
46
+ "@cedarjs/web-server": "5.0.0-canary.2585",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.1",
49
49
  "@opentelemetry/core": "1.30.1",