@cedarjs/cli 5.0.0-canary.2547 → 5.0.0-canary.2549

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.
@@ -8,7 +8,11 @@ import {
8
8
  } from "@cedarjs/cli-helpers/packageManager/exec";
9
9
  import { installPackages } from "@cedarjs/cli-helpers/packageManager/packages";
10
10
  import { getPaths } from "@cedarjs/project-config";
11
- const handler = async ({ side, prisma, dataMigrate }) => {
11
+ const handler = async ({
12
+ side,
13
+ prisma,
14
+ dataMigrate
15
+ }) => {
12
16
  recordTelemetryAttributes({
13
17
  command: "deploy render",
14
18
  side,
@@ -35,7 +39,7 @@ const handler = async ({ side, prisma, dataMigrate }) => {
35
39
  const packageJson = JSON.parse(
36
40
  fs.readFileSync(path.join(cedarPaths.base, "package.json"), "utf-8")
37
41
  );
38
- const hasDataMigratePackage = !!packageJson.devDependencies["@cedarjs/cli-data-migrate"];
42
+ const hasDataMigratePackage = !!packageJson.devDependencies?.["@cedarjs/cli-data-migrate"];
39
43
  if (!hasDataMigratePackage) {
40
44
  console.error(
41
45
  [
@@ -57,8 +61,8 @@ const handler = async ({ side, prisma, dataMigrate }) => {
57
61
  if (hasServerFile) {
58
62
  runWithNode(serverFilePath, execaConfig);
59
63
  } else {
60
- const { handler: handler2 } = await import("@cedarjs/api-server/apiCliConfigHandler");
61
- handler2();
64
+ const { handler: apiHandler } = await import("@cedarjs/api-server/apiCliConfigHandler");
65
+ apiHandler();
62
66
  }
63
67
  }
64
68
  async function runWebCommands() {
@@ -41,7 +41,7 @@ const handler = async ({ name, path }) => {
41
41
  try {
42
42
  await t.run();
43
43
  } catch (e) {
44
- console.log(c.error(e.message));
44
+ console.log(c.error(e instanceof Error ? e.message : String(e)));
45
45
  }
46
46
  };
47
47
  export {
@@ -15,7 +15,11 @@ import {
15
15
  routes as scaffoldRoutes,
16
16
  splitPathAndModel
17
17
  } from "../../generate/scaffold/scaffoldHandler.js";
18
- const removeRoutesWithSet = async ({ model, path, nestScaffoldByModel }) => {
18
+ const removeRoutesWithSet = async ({
19
+ model,
20
+ path,
21
+ nestScaffoldByModel
22
+ }) => {
19
23
  const routes = await scaffoldRoutes({ model, path, nestScaffoldByModel });
20
24
  const routeNames = routes.map(extractRouteName);
21
25
  const pluralPascalName = pascalcase(pluralize(model));
@@ -28,9 +32,13 @@ const removeSetImport = () => {
28
32
  if (routesContent.match("<Set")) {
29
33
  return "Skipping removal of Set import in Routes.{jsx,tsx}";
30
34
  }
31
- const [cedarRouterImport] = routesContent.match(
35
+ const cedarRouterImportMatch = routesContent.match(
32
36
  /import {[^]*} from '@cedarjs\/router'/
33
37
  );
38
+ if (!cedarRouterImportMatch) {
39
+ return "No @cedarjs/router import found in Routes.{jsx,tsx}";
40
+ }
41
+ const [cedarRouterImport] = cedarRouterImportMatch;
34
42
  const removedSetImport = cedarRouterImport.replace(/,*\s*Set,*/, "");
35
43
  const newRoutesContent = routesContent.replace(
36
44
  cedarRouterImport,
@@ -39,7 +47,10 @@ const removeSetImport = () => {
39
47
  writeFile(routesPath, newRoutesContent, { overwriteExisting: true });
40
48
  return "Removed Set import in Routes.{jsx,tsx}";
41
49
  };
42
- const removeLayoutImport = ({ model: name, path: scaffoldPath = "" }) => {
50
+ const removeLayoutImport = ({
51
+ model: name,
52
+ path: scaffoldPath = ""
53
+ }) => {
43
54
  const pluralPascalName = pascalcase(pluralize(name));
44
55
  const pascalScaffoldPath = scaffoldPath === "" ? scaffoldPath : scaffoldPath.split("/").map(pascalcase).join("/") + "/";
45
56
  const layoutName = `${pluralPascalName}Layout`;
@@ -53,7 +64,12 @@ const removeLayoutImport = ({ model: name, path: scaffoldPath = "" }) => {
53
64
  writeFile(routesPath, newRoutesContent, { overwriteExisting: true });
54
65
  return "Removed layout import from Routes.{jsx,tsx}";
55
66
  };
56
- const tasks = ({ model, path, tests, nestScaffoldByModel }) => new Listr(
67
+ const tasks = ({
68
+ model,
69
+ path,
70
+ tests,
71
+ nestScaffoldByModel
72
+ }) => new Listr(
57
73
  [
58
74
  {
59
75
  title: "Destroying scaffold files...",
@@ -91,12 +107,15 @@ const handler = async ({ model: modelArg }) => {
91
107
  const { name } = await verifyModelName({ name: model, isDestroyer: true });
92
108
  await tasks({ model: name, path }).run();
93
109
  } catch (e) {
94
- console.log(c.error(e.message));
110
+ console.log(c.error(e instanceof Error ? e.message : String(e)));
95
111
  }
96
112
  };
97
113
  const extractRouteName = (route) => {
98
- const { groups } = route.match(/.*name="?(?<routeName>\w+)"?/);
99
- return groups.routeName;
114
+ const match = route.match(/.*name="?(?<routeName>\w+)"?/);
115
+ if (!match?.groups?.routeName) {
116
+ throw new Error(`Could not extract route name from route: ${route}`);
117
+ }
118
+ return match.groups.routeName;
100
119
  };
101
120
  export {
102
121
  handler,
@@ -5,13 +5,16 @@ import { addApiPackages, colors as c } from "@cedarjs/cli-helpers";
5
5
  import { errorTelemetry } from "@cedarjs/telemetry";
6
6
  import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
7
7
  import { isTypeScriptProject } from "../../../lib/project.js";
8
- const { version } = JSON.parse(
8
+ const packageJson = JSON.parse(
9
9
  fs.readFileSync(
10
10
  path.resolve(import.meta.dirname, "../../../../package.json"),
11
11
  "utf-8"
12
12
  )
13
13
  );
14
- function setupServerFileTasks({ force = false } = {}) {
14
+ const { version } = packageJson;
15
+ function setupServerFileTasks({
16
+ force = false
17
+ } = {}) {
15
18
  return [
16
19
  {
17
20
  title: "Adding the server file...",
@@ -36,17 +39,22 @@ function setupServerFileTasks({ force = false } = {}) {
36
39
  addApiPackages([`@cedarjs/api-server@${version}`])
37
40
  ];
38
41
  }
39
- async function handler({ force, verbose }) {
40
- const tasks = new Listr(setupServerFileTasks({ force }), {
42
+ async function handler({
43
+ force,
44
+ verbose
45
+ }) {
46
+ const listr = new Listr(setupServerFileTasks({ force }), {
41
47
  rendererOptions: { collapseSubtasks: false, persistentOutput: true },
42
48
  renderer: verbose ? "verbose" : "default"
43
49
  });
44
50
  try {
45
- await tasks.run();
51
+ await listr.run();
46
52
  } catch (e) {
47
- errorTelemetry(process.argv, e.message);
48
- console.error(c.error(e.message));
49
- process.exit(e?.exitCode || 1);
53
+ const message = e instanceof Error ? e.message : String(e);
54
+ errorTelemetry(process.argv, message);
55
+ console.error(c.error(message));
56
+ const exitCode = typeof e === "object" && e !== null && "exitCode" in e && typeof e.exitCode === "number" ? e.exitCode : 1;
57
+ process.exit(exitCode);
50
58
  }
51
59
  }
52
60
  export {
@@ -10,11 +10,11 @@ import {
10
10
  } from "./merge/strategy.js";
11
11
  import { isTypeScriptProject } from "./project.js";
12
12
  import { getPaths, transformTSToJS, writeFile } from "./index.js";
13
- async function extendStorybookConfiguration(newConfigPath = void 0) {
13
+ async function extendStorybookConfiguration(newConfigPath) {
14
14
  const webPaths = getPaths().web;
15
15
  const ts = isTypeScriptProject();
16
16
  const sbPreviewConfigPath = webPaths.storybookPreviewConfig ?? `${webPaths.storybook}/preview.${ts ? "tsx" : "js"}`;
17
- const read = (path2) => fse.readFileSync(path2, { encoding: "utf-8" });
17
+ const read = (filePath) => fse.readFileSync(filePath, { encoding: "utf-8" });
18
18
  if (!fse.existsSync(sbPreviewConfigPath)) {
19
19
  const templateContent = read(
20
20
  path.resolve(
package/dist/lib/exec.js CHANGED
@@ -67,11 +67,11 @@ async function runScriptFunction({
67
67
  customResolver: (id, importer, _options) => {
68
68
  const apiImportBase = importStatementPath(getPaths().api.base);
69
69
  const webImportBase = importStatementPath(getPaths().web.base);
70
- if (importer.startsWith(apiImportBase)) {
70
+ if (importer?.startsWith(apiImportBase)) {
71
71
  const apiImportSrc = importStatementPath(getPaths().api.src);
72
72
  const resolvedId = id.replace("src", apiImportSrc);
73
73
  return { id: resolveExtension(resolvedId) };
74
- } else if (importer.startsWith(webImportBase)) {
74
+ } else if (importer?.startsWith(webImportBase)) {
75
75
  const webImportSrc = importStatementPath(getPaths().web.src);
76
76
  const resolvedId = id.replace("src", webImportSrc);
77
77
  return { id: resolveExtension(resolvedId) };
@@ -97,22 +97,23 @@ async function runScriptFunction({
97
97
  throw new Error("Vite environment is not runnable.");
98
98
  }
99
99
  let returnValue;
100
- let scriptError = null;
101
100
  try {
102
- const script = await env.runner.import(scriptPath);
103
- returnValue = await script[functionName](args);
104
- } catch (error) {
105
- scriptError = error;
106
- }
107
- try {
108
- const { db } = await env.runner.import(path.join(getPaths().api.lib, "db"));
109
- db.$disconnect();
110
- } catch (e) {
111
- }
112
- await server.close();
113
- process.env.NODE_ENV = NODE_ENV;
114
- if (scriptError) {
115
- throw scriptError;
101
+ const module = await env.runner.import(scriptPath);
102
+ const fn = module[functionName];
103
+ if (typeof fn !== "function") {
104
+ throw new Error(`Function '${functionName}' not found in script`);
105
+ }
106
+ returnValue = await fn(args);
107
+ } finally {
108
+ try {
109
+ const dbModule = await env.runner.import(
110
+ path.join(getPaths().api.lib, "db")
111
+ );
112
+ dbModule.db?.$disconnect?.();
113
+ } catch {
114
+ }
115
+ await server.close();
116
+ process.env.NODE_ENV = NODE_ENV;
116
117
  }
117
118
  return returnValue;
118
119
  }
@@ -1,8 +1,8 @@
1
1
  import fs from "node:fs";
2
- function fileIncludes(path, str) {
3
- return fs.existsSync(path) && fs.readFileSync(path).toString().includes(str);
2
+ function fileIncludes(filePath, str) {
3
+ return fs.existsSync(filePath) && fs.readFileSync(filePath).toString().includes(str);
4
4
  }
5
- function extendJSXFile(path, {
5
+ function extendJSXFile(filePath, {
6
6
  insertComponent: {
7
7
  name = void 0,
8
8
  props = void 0,
@@ -14,7 +14,7 @@ function extendJSXFile(path, {
14
14
  imports = [],
15
15
  moduleScopeLines = []
16
16
  }) {
17
- const content = fs.readFileSync(path).toString().split("\n");
17
+ const content = fs.readFileSync(filePath).toString().split("\n");
18
18
  if (moduleScopeLines?.length) {
19
19
  content.splice(
20
20
  content.findLastIndex((l) => l.trimStart().startsWith("import")) + 1,
@@ -41,9 +41,16 @@ function extendJSXFile(path, {
41
41
  insertAfter
42
42
  });
43
43
  }
44
- fs.writeFileSync(path, content.filter((e) => e !== void 0).join("\n"));
44
+ fs.writeFileSync(filePath, content.join("\n"));
45
45
  }
46
- function insertComponent(content, { component, props, around, within, insertBefore, insertAfter }) {
46
+ function insertComponent(content, {
47
+ component,
48
+ props,
49
+ around,
50
+ within,
51
+ insertBefore,
52
+ insertAfter
53
+ }) {
47
54
  if (around && within || !(around || within)) {
48
55
  throw new Error(
49
56
  "Exactly one of (around | within) must be defined. Choose one."
@@ -62,16 +69,16 @@ function insertComponent(content, { component, props, around, within, insertBefo
62
69
  open++;
63
70
  close--;
64
71
  }
65
- const [, componentDepth] = content[open].match(/([^\S\r\n]*).*/);
72
+ const depthMatch = content[open].match(/([^\S\r\n]*).*/);
73
+ const componentDepth = depthMatch?.[1] ?? "";
66
74
  content.splice(
67
75
  open,
68
76
  close - open,
69
- // "Delete" the wrapped component contents. We put it back below.
70
- insertBefore && componentDepth + insertBefore,
77
+ ...insertBefore ? [componentDepth + insertBefore] : [],
71
78
  componentDepth + buildOpeningTag(component, props),
72
79
  ...content.slice(open, close).map((line) => " " + line),
73
80
  componentDepth + `</${component}>`,
74
- insertAfter && componentDepth + insertAfter
81
+ ...insertAfter ? [componentDepth + insertAfter] : []
75
82
  );
76
83
  }
77
84
  function buildOpeningTag(componentName, props) {
@@ -92,11 +99,14 @@ function buildOpeningTag(componentName, props) {
92
99
  const possibleSpace = propsString.length ? " " : "";
93
100
  return `<${componentName}${possibleSpace}${propsString}>`;
94
101
  }
95
- function objectToComponentProps(obj, options = { exclude: [], raw: false }) {
102
+ function objectToComponentProps(obj, options = {
103
+ exclude: [],
104
+ raw: false
105
+ }) {
96
106
  const props = [];
97
107
  const doRaw = (key) => options.raw === true || Array.isArray(options.raw) && options.raw.includes(key);
98
108
  for (const [key, value] of Object.entries(obj)) {
99
- if (options.exclude && options.exclude.includes(key)) {
109
+ if (options.exclude?.includes(key)) {
100
110
  continue;
101
111
  }
102
112
  if (doRaw(key)) {
@@ -1,7 +1,7 @@
1
1
  import * as t from "@babel/types";
2
2
  import uniqWith from "lodash/uniqWith.js";
3
3
  import { nodeIs, sieve } from "./algorithms.js";
4
- const OPAQUE_UID_TAG = "RW_MERGE_OPAQUE_UID_Q2xldmVyIHlvdSEgSGF2ZSBhIGNvb2tpZS4=";
4
+ const OPAQUE_UID_TAG = "CEDAR_MERGE_OPAQUE_UID_Q2xldmVyIHlvdSEgSGF2ZSBhIGNvb2tpZS4=";
5
5
  function requireSameType(base, ext) {
6
6
  if (base.path.type !== ext.path.type) {
7
7
  throw new Error(
@@ -17,9 +17,21 @@ function requireStrategyExists(base, _ext, strategy, strategyName) {
17
17
  }
18
18
  }
19
19
  const strictEquality = (lhs, rhs) => lhs === rhs;
20
- const byName = (lhs, rhs) => lhs.name === rhs.name;
21
- const byKeyName = (lhs, rhs) => lhs.key.name === rhs.key.name;
22
- const byValue = (lhs, rhs) => lhs.value === rhs.value;
20
+ function hasName(v) {
21
+ return typeof v === "object" && v !== null && "name" in v;
22
+ }
23
+ function hasKey(v) {
24
+ return typeof v === "object" && v !== null && "key" in v;
25
+ }
26
+ function hasKeyName(v) {
27
+ return hasKey(v) && hasName(v.key);
28
+ }
29
+ function hasValue(v) {
30
+ return typeof v === "object" && v !== null && "value" in v;
31
+ }
32
+ const byName = (lhs, rhs) => hasName(lhs) && hasName(rhs) && lhs.name === rhs.name;
33
+ const byKeyName = (lhs, rhs) => hasKeyName(lhs) && hasKeyName(rhs) && lhs.key.name === rhs.key.name;
34
+ const byValue = (lhs, rhs) => hasValue(lhs) && hasValue(rhs) && lhs.value === rhs.value;
23
35
  function defaultEquality(baseContainer, extContainer) {
24
36
  const sample = baseContainer.length && baseContainer[0] || extContainer.length && extContainer[0];
25
37
  const defaults = {
@@ -30,14 +42,13 @@ function defaultEquality(baseContainer, extContainer) {
30
42
  ObjectProperty: byKeyName,
31
43
  StringLiteral: byValue
32
44
  };
33
- return sample && sample.type in defaults ? defaults[sample.type] : strictEquality;
45
+ return sample && typeof sample === "object" && "type" in sample && typeof sample.type === "string" && sample.type in defaults ? defaults[sample.type] : strictEquality;
34
46
  }
35
- function opaquely(strategy) {
36
- strategy[OPAQUE_UID_TAG] = true;
37
- return strategy;
47
+ function opaquely(reducer) {
48
+ return Object.assign(reducer, { [OPAQUE_UID_TAG]: true });
38
49
  }
39
- function isOpaque(strategy) {
40
- return strategy[OPAQUE_UID_TAG] === true;
50
+ function isOpaque(fn) {
51
+ return OPAQUE_UID_TAG in fn && fn[OPAQUE_UID_TAG] === true;
41
52
  }
42
53
  const keepBase = opaquely(() => {
43
54
  });
@@ -47,20 +58,36 @@ const keepBoth = opaquely((base, ext) => {
47
58
  const keepExtension = opaquely((base, ext) => {
48
59
  base.path.replaceWith(ext.path);
49
60
  });
50
- const keepBothStatementParents = opaquely((base, ext) => {
51
- base.path.getStatementParent().insertAfter(ext.path.getStatementParent().node);
52
- });
61
+ const keepBothStatementParents = opaquely(
62
+ (base, ext) => {
63
+ const extParent = ext.path.getStatementParent();
64
+ if (extParent) {
65
+ base.path.getStatementParent()?.insertAfter(extParent.node);
66
+ }
67
+ }
68
+ );
53
69
  const interleaveStrategy = {
54
- ImportDeclaration(baseImport, extImport) {
55
- const baseSpecs = baseImport.specifiers;
56
- const extSpecs = extImport.specifiers;
57
- const importSpecifierEquality = (lhs, rhs) => lhs.type === rhs.type && lhs.imported?.name === rhs.imported?.name && lhs.local?.name == rhs.local?.name;
70
+ ImportDeclaration(base, ext) {
71
+ if (!t.isImportDeclaration(base) || !t.isImportDeclaration(ext)) {
72
+ return;
73
+ }
74
+ const baseSpecs = base.specifiers;
75
+ const extSpecs = ext.specifiers;
76
+ const importSpecifierEquality = (lhs, rhs) => {
77
+ if (lhs.type !== rhs.type) {
78
+ return false;
79
+ }
80
+ if (lhs.type === "ImportSpecifier" && rhs.type === "ImportSpecifier") {
81
+ return lhs.imported.type === "Identifier" && rhs.imported.type === "Identifier" && lhs.imported.name === rhs.imported.name && lhs.local?.name === rhs.local?.name;
82
+ }
83
+ return lhs.local?.name === rhs.local?.name;
84
+ };
58
85
  const uniqueSpecifiersOfType = (type) => uniqWith(
59
86
  [...baseSpecs, ...extSpecs].filter(nodeIs(type)),
60
87
  importSpecifierEquality
61
88
  );
62
89
  if (!baseSpecs.length !== !extSpecs.length) {
63
- return keepBothStatementParents(baseImport, extImport);
90
+ return keepBothStatementParents(base, ext);
64
91
  }
65
92
  const defaultPosition = (specs) => specs.some(nodeIs("ImportDefaultSpecifier")) ? -1 : 0;
66
93
  const namespacePosition = (specs) => specs.some(nodeIs("ImportNamespaceSpecifier")) || specs.some(nodeIs("ImportSpecifier")) ? -1 : specs.length;
@@ -70,10 +97,10 @@ const interleaveStrategy = {
70
97
  [uniqueSpecifiersOfType("ImportNamespaceSpecifier"), namespacePosition],
71
98
  [uniqueSpecifiersOfType("ImportSpecifier"), importPosition]
72
99
  );
73
- baseImport.specifiers = firstSpecifierList;
100
+ base.specifiers = firstSpecifierList;
74
101
  if (rest.length) {
75
- baseImport.path.insertAfter(
76
- rest.map((specs) => t.importDeclaration(specs, baseImport.source))
102
+ base.path.insertAfter(
103
+ rest.map((specs) => t.importDeclaration(specs, base.source))
77
104
  );
78
105
  }
79
106
  }
@@ -81,47 +108,70 @@ const interleaveStrategy = {
81
108
  function interleave(base, ext) {
82
109
  requireSameType(base, ext);
83
110
  requireStrategyExists(base, ext, interleaveStrategy, "interleave");
84
- return interleaveStrategy[base.path.type](base, ext);
111
+ interleaveStrategy[base.path.type]?.(base, ext);
85
112
  }
86
113
  const concatStrategy = {
87
114
  ArrayExpression(base, ext) {
115
+ if (!t.isArrayExpression(base) || !t.isArrayExpression(ext)) {
116
+ return;
117
+ }
88
118
  base.elements = [...base.elements, ...ext.elements];
89
119
  },
90
120
  ObjectExpression(base, ext) {
121
+ if (!t.isObjectExpression(base) || !t.isObjectExpression(ext)) {
122
+ return;
123
+ }
91
124
  base.properties = [...base.properties, ...ext.properties];
92
125
  },
93
126
  StringLiteral(base, ext) {
127
+ if (!t.isStringLiteral(base) || !t.isStringLiteral(ext)) {
128
+ return;
129
+ }
94
130
  base.value = base.value.concat(ext.value);
95
131
  }
96
132
  };
97
133
  function concat(base, ext) {
98
134
  requireSameType(base, ext);
99
135
  requireStrategyExists(base, ext, concatStrategy, "concat");
100
- return concatStrategy[base.path.type](base, ext);
136
+ concatStrategy[base.path.type]?.(base, ext);
101
137
  }
102
138
  const concatUniqueStrategy = {
103
139
  ArrayExpression(base, ext, eq) {
104
- eq ||= defaultEquality(base.elements, ext.elements);
105
- base.elements = uniqWith([...base.elements, ...ext.elements], eq);
140
+ if (!t.isArrayExpression(base) || !t.isArrayExpression(ext)) {
141
+ return;
142
+ }
143
+ const equalFn = eq ?? defaultEquality(base.elements, ext.elements);
144
+ base.elements = uniqWith([...base.elements, ...ext.elements], equalFn);
106
145
  },
107
146
  ObjectExpression(base, ext, eq) {
108
- eq ||= defaultEquality(base.properties, ext.properties);
109
- base.properties = uniqWith([...base.properties, ...ext.properties], eq);
147
+ if (!t.isObjectExpression(base) || !t.isObjectExpression(ext)) {
148
+ return;
149
+ }
150
+ const equalFn = eq ?? defaultEquality(base.properties, ext.properties);
151
+ base.properties = uniqWith([...base.properties, ...ext.properties], equalFn);
110
152
  }
111
153
  };
112
154
  function concatUnique(baseOrEq, ext) {
113
- if (arguments.length === 1) {
114
- return (base, ext2) => {
115
- requireSameType(base, ext2);
116
- requireStrategyExists(base, ext2, concatUniqueStrategy, "concatUnique");
117
- return concatUniqueStrategy[base.path.type](base, ext2, baseOrEq);
155
+ if (typeof baseOrEq === "function") {
156
+ const eq = baseOrEq;
157
+ return (base2, innerExt) => {
158
+ requireSameType(base2, innerExt);
159
+ requireStrategyExists(
160
+ base2,
161
+ innerExt,
162
+ concatUniqueStrategy,
163
+ "concatUnique"
164
+ );
165
+ concatUniqueStrategy[base2.path.type]?.(base2, innerExt, eq);
118
166
  };
119
167
  }
120
- if (arguments.length === 2) {
121
- requireSameType(baseOrEq, ext);
122
- requireStrategyExists(baseOrEq, ext, concatUniqueStrategy, "concatUnique");
123
- return concatUniqueStrategy[baseOrEq.path.type](baseOrEq, ext);
168
+ const base = baseOrEq;
169
+ if (!ext) {
170
+ return;
124
171
  }
172
+ requireSameType(base, ext);
173
+ requireStrategyExists(base, ext, concatUniqueStrategy, "concatUnique");
174
+ concatUniqueStrategy[base.path.type]?.(base, ext);
125
175
  }
126
176
  export {
127
177
  concat,
@@ -9,13 +9,13 @@ const getExistingModelName = async (name) => {
9
9
  return void 0;
10
10
  }
11
11
  const modelName = name.replace(/[_-]/g, "").toLowerCase();
12
- for (let model of Object.values(schemaMemo)) {
12
+ for (const model of Object.values(schemaMemo)) {
13
13
  if (model.name.toLowerCase() === modelName) {
14
14
  return model.name;
15
15
  }
16
16
  }
17
17
  const schema = (await getSchemaDefinitions()).datamodel;
18
- for (let model of schema.models) {
18
+ for (const model of schema.models) {
19
19
  if (model.name.toLowerCase() === modelName) {
20
20
  return model.name;
21
21
  }
@@ -36,25 +36,24 @@ const getSchema = async (name) => {
36
36
  if (schemaMemo[modelName]) {
37
37
  return schemaMemo[modelName];
38
38
  }
39
- const model = schema.models.find((model2) => model2.name === modelName);
39
+ const model = schema.models.find((m) => m.name === modelName);
40
40
  if (!model) {
41
41
  return void 0;
42
42
  }
43
- model.fields.forEach((field) => {
43
+ const enrichedFields = model.fields.map((field) => {
44
44
  const fieldEnum = schema.enums.find((e) => field.type === e.name);
45
- if (fieldEnum) {
46
- field.enumValues = fieldEnum.values;
47
- }
45
+ return fieldEnum ? { ...field, enumValues: fieldEnum.values } : { ...field };
48
46
  });
49
- schemaMemo[modelName] = model;
50
- return model;
47
+ const enrichedModel = { ...model, fields: enrichedFields };
48
+ schemaMemo[modelName] = enrichedModel;
49
+ return enrichedModel;
51
50
  };
52
51
  const getEnum = async (name) => {
53
52
  const schema = await getSchemaDefinitions();
54
53
  if (!name) {
55
54
  return schema.metadata.datamodel.enums;
56
55
  }
57
- const model = schema.datamodel.enums.find((model2) => model2.name === name);
56
+ const model = schema.datamodel.enums.find((e) => e.name === name);
58
57
  if (!model) {
59
58
  throw new Error(
60
59
  `No enum schema definition found for \`${name}\` in schema.prisma file`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "5.0.0-canary.2547",
3
+ "version": "5.0.0-canary.2549",
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.2547",
37
- "@cedarjs/cli-helpers": "5.0.0-canary.2547",
38
- "@cedarjs/fastify-web": "5.0.0-canary.2547",
39
- "@cedarjs/internal": "5.0.0-canary.2547",
40
- "@cedarjs/prerender": "5.0.0-canary.2547",
41
- "@cedarjs/project-config": "5.0.0-canary.2547",
42
- "@cedarjs/structure": "5.0.0-canary.2547",
43
- "@cedarjs/telemetry": "5.0.0-canary.2547",
44
- "@cedarjs/utils": "5.0.0-canary.2547",
45
- "@cedarjs/vite": "5.0.0-canary.2547",
46
- "@cedarjs/web-server": "5.0.0-canary.2547",
36
+ "@cedarjs/api-server": "5.0.0-canary.2549",
37
+ "@cedarjs/cli-helpers": "5.0.0-canary.2549",
38
+ "@cedarjs/fastify-web": "5.0.0-canary.2549",
39
+ "@cedarjs/internal": "5.0.0-canary.2549",
40
+ "@cedarjs/prerender": "5.0.0-canary.2549",
41
+ "@cedarjs/project-config": "5.0.0-canary.2549",
42
+ "@cedarjs/structure": "5.0.0-canary.2549",
43
+ "@cedarjs/telemetry": "5.0.0-canary.2549",
44
+ "@cedarjs/utils": "5.0.0-canary.2549",
45
+ "@cedarjs/vite": "5.0.0-canary.2549",
46
+ "@cedarjs/web-server": "5.0.0-canary.2549",
47
47
  "@listr2/prompt-adapter-enquirer": "4.2.1",
48
48
  "@opentelemetry/api": "1.9.1",
49
49
  "@opentelemetry/core": "1.30.1",