@cedarjs/cli 7.0.0-canary.3237 → 7.0.0-canary.3238

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.
@@ -13,7 +13,7 @@ import {
13
13
  } from "@cedarjs/cli-helpers/packageManager/packages";
14
14
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
15
15
  import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
16
- import { getConfig } from "@cedarjs/project-config";
16
+ import { getConfig, getParsedScalars } from "@cedarjs/project-config";
17
17
  import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
18
18
  import {
19
19
  generateTemplate,
@@ -190,6 +190,7 @@ const assetFiles = async (name, tailwind) => {
190
190
  }
191
191
  return fileList;
192
192
  };
193
+ const isDateTimeParsed = () => getParsedScalars().DateTime === "Date";
193
194
  const formatters = async (name, isTypescript) => {
194
195
  const outputPath = path.join(
195
196
  getPaths().web.src,
@@ -211,7 +212,8 @@ const formatters = async (name, isTypescript) => {
211
212
  templatePath: path.join("lib", "formatters.tsx.template")
212
213
  }),
213
214
  {
214
- name
215
+ name,
216
+ parsedDateTime: isDateTimeParsed()
215
217
  }
216
218
  );
217
219
  const templateTest = await generateTemplate(
@@ -221,7 +223,8 @@ const formatters = async (name, isTypescript) => {
221
223
  templatePath: path.join("lib", "formatters.test.tsx.template")
222
224
  }),
223
225
  {
224
- name
226
+ name,
227
+ parsedDateTime: isDateTimeParsed()
225
228
  }
226
229
  );
227
230
  return {
@@ -341,7 +344,8 @@ const modelRelatedVariables = (model) => {
341
344
  fieldsToImport,
342
345
  editableColumns,
343
346
  listFormattersImports,
344
- formattersImports
347
+ formattersImports,
348
+ parsedDateTime: isDateTimeParsed()
345
349
  };
346
350
  };
347
351
  const layoutFiles = async (name, force, generateTypescript, templateStrings) => {
@@ -12,17 +12,17 @@ import {
12
12
 
13
13
  <% if (fieldsToImport.includes('DatetimeLocalField')) { %>
14
14
  /**
15
- * Formats a DateTime string from the API, which is a UTC timestamp, for use as
15
+ * Formats a DateTime <%= parsedDateTime ? 'Date object' : 'string' %> from the API, which is a UTC timestamp, for use as
16
16
  * the value of a `datetime-local` input. The input takes `YYYY-MM-DDTHH:mm` in
17
17
  * the user's local time, with no seconds, milliseconds or timezone, and the
18
18
  * form reads its value back as local time when it is submitted.
19
19
  */
20
- function formatDatetime(value: string | undefined | null) {
20
+ function formatDatetime(value: <%= parsedDateTime ? 'Date' : 'string' %> | undefined | null) {
21
21
  if (!value) {
22
22
  return undefined
23
23
  }
24
24
 
25
- const date = new Date(value)
25
+ const date = <%= parsedDateTime ? 'value' : 'new Date(value)' %>
26
26
 
27
27
  if (Number.isNaN(date.getTime())) {
28
28
  return undefined
@@ -83,14 +83,25 @@ describe('jsonTruncate', () => {
83
83
 
84
84
  describe('timeTag', () => {
85
85
  it('renders a date', async () => {
86
+ <% if (parsedDateTime) { %>
87
+ render(<div>{timeTag(new Date('1970-08-20'))}</div>)
88
+ <% } else { %>
86
89
  render(<div>{timeTag(new Date('1970-08-20').toUTCString())}</div>)
90
+ <% } %>
87
91
 
88
92
  await waitFor(() => screen.getByText(/1970.*00:00:00/))
89
93
  })
90
94
 
95
+ <% if (parsedDateTime) { %>
96
+ it('can take an empty input', async () => {
97
+ expect(timeTag(null)).toEqual('')
98
+ expect(timeTag(undefined)).toEqual('')
99
+ })
100
+ <% } else { %>
91
101
  it('can take an empty input string', async () => {
92
102
  expect(timeTag('')).toEqual('')
93
103
  })
104
+ <% } %>
94
105
  })
95
106
 
96
107
  describe('jsonDisplay', () => {
@@ -39,15 +39,27 @@ export const jsonTruncate = (obj: unknown) => {
39
39
  return truncate(JSON.stringify(obj, null, 2))
40
40
  }
41
41
 
42
- export function timeTag(dateTime: string | undefined | null) {
42
+ export function timeTag(dateTime: <%= parsedDateTime ? 'Date' : 'string' %> | undefined | null) {
43
43
  let output: string | React.JSX.Element = ''
44
44
 
45
45
  if (dateTime) {
46
+ <% if (parsedDateTime) { %>
47
+ if (!Number.isNaN(dateTime.getTime())) {
48
+ const isoString = dateTime.toISOString()
49
+
50
+ output = (
51
+ <time dateTime={isoString} title={isoString}>
52
+ {dateTime.toUTCString()}
53
+ </time>
54
+ )
55
+ }
56
+ <% } else { %>
46
57
  output = (
47
58
  <time dateTime={dateTime} title={dateTime}>
48
59
  {new Date(dateTime).toUTCString()}
49
60
  </time>
50
61
  )
62
+ <% } %>
51
63
  }
52
64
 
53
65
  return output
@@ -4,7 +4,7 @@ import { Listr } from "listr2";
4
4
  import { colors as c } from "@cedarjs/cli-helpers/colors";
5
5
  import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
6
6
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
7
- import { getConfig, getPaths } from "@cedarjs/project-config";
7
+ import { getConfig, getParsedScalars, getPaths } from "@cedarjs/project-config";
8
8
  import { errorTelemetry } from "@cedarjs/telemetry";
9
9
  import { runScriptFunction } from "../lib/exec.js";
10
10
  import { configureBabel } from "../lib/execBabel.js";
@@ -106,6 +106,12 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
106
106
  );
107
107
  return [];
108
108
  }
109
+ const parsedScalars = Object.keys(getParsedScalars());
110
+ if (parsedScalars.length > 0) {
111
+ throw new Error(
112
+ "Prerendering does not support `graphql.parsedScalars` yet. A prerendered Cell gets the raw GraphQL response, so " + parsedScalars.join(", ") + " would be a string when prerendering and parsed in the browser. Either remove the `prerender` prop from your routes, or remove `graphql.parsedScalars` from cedar.toml."
113
+ );
114
+ }
109
115
  const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
110
116
  if (!fs.existsSync(indexHtmlPath)) {
111
117
  console.error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "7.0.0-canary.3237",
3
+ "version": "7.0.0-canary.3238",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,17 +36,17 @@
36
36
  "@babel/preset-typescript": "7.29.7",
37
37
  "@babel/traverse": "7.29.8",
38
38
  "@babel/types": "7.29.8",
39
- "@cedarjs/api-server": "7.0.0-canary.3237",
40
- "@cedarjs/babel-config": "7.0.0-canary.3237",
41
- "@cedarjs/cli-helpers": "7.0.0-canary.3237",
42
- "@cedarjs/internal": "7.0.0-canary.3237",
43
- "@cedarjs/prerender": "7.0.0-canary.3237",
44
- "@cedarjs/project-config": "7.0.0-canary.3237",
45
- "@cedarjs/structure": "7.0.0-canary.3237",
46
- "@cedarjs/telemetry": "7.0.0-canary.3237",
47
- "@cedarjs/utils": "7.0.0-canary.3237",
48
- "@cedarjs/vite": "7.0.0-canary.3237",
49
- "@cedarjs/web-server": "7.0.0-canary.3237",
39
+ "@cedarjs/api-server": "7.0.0-canary.3238",
40
+ "@cedarjs/babel-config": "7.0.0-canary.3238",
41
+ "@cedarjs/cli-helpers": "7.0.0-canary.3238",
42
+ "@cedarjs/internal": "7.0.0-canary.3238",
43
+ "@cedarjs/prerender": "7.0.0-canary.3238",
44
+ "@cedarjs/project-config": "7.0.0-canary.3238",
45
+ "@cedarjs/structure": "7.0.0-canary.3238",
46
+ "@cedarjs/telemetry": "7.0.0-canary.3238",
47
+ "@cedarjs/utils": "7.0.0-canary.3238",
48
+ "@cedarjs/vite": "7.0.0-canary.3238",
49
+ "@cedarjs/web-server": "7.0.0-canary.3238",
50
50
  "@listr2/prompt-adapter-enquirer": "4.3.2",
51
51
  "@opentelemetry/api": "1.9.1",
52
52
  "@opentelemetry/core": "2.11.0",
@@ -94,7 +94,7 @@
94
94
  "yargs": "17.7.3"
95
95
  },
96
96
  "devDependencies": {
97
- "@cedarjs/framework-tools": "7.0.0-canary.3237",
97
+ "@cedarjs/framework-tools": "7.0.0-canary.3238",
98
98
  "@prisma/dmmf": "7.10.0",
99
99
  "@types/archiver": "^7.0.0",
100
100
  "memfs": "4.78.1",