@cedarjs/cli 7.0.0 → 8.0.0-canary.3263
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/commands/build/buildHandler.js +2 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/check.js +2 -1
- package/dist/commands/deploy/baremetal/baremetalHandler.js +1 -1
- package/dist/commands/deploy/baremetal.js +1 -1
- package/dist/commands/deploy/flightcontrolHandler.js +1 -1
- package/dist/commands/deploy/helpers/deployHandler.js +1 -1
- package/dist/commands/deploy/netlify.js +1 -1
- package/dist/commands/deploy/renderHandler.js +1 -1
- package/dist/commands/deploy/serverlessHandler.js +2 -1
- package/dist/commands/deploy/vercel.js +1 -1
- package/dist/commands/destroy/handlerHelpers.js +1 -1
- package/dist/commands/destroy/page/pageHandler.js +2 -1
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +2 -1
- package/dist/commands/destroy/sdl/sdlHandler.js +2 -1
- package/dist/commands/dev/devHandler.js +3 -4
- package/dist/commands/dev/packageWatchCommands.js +8 -3
- package/dist/commands/dev.js +1 -1
- package/dist/commands/execHandler.js +2 -1
- package/dist/commands/experimental/live-queries/liveQueries.js +1 -1
- package/dist/commands/experimental/live-queries/liveQueriesHandler.js +3 -3
- package/dist/commands/experimental/setupInngest.js +1 -1
- package/dist/commands/experimental/setupInngestHandler.js +1 -1
- package/dist/commands/experimental/setupOpentelemetry.js +1 -1
- package/dist/commands/experimental/setupOpentelemetryHandler.js +2 -1
- package/dist/commands/experimental/setupReactCompiler.js +1 -1
- package/dist/commands/experimental/setupReactCompilerHandler.js +4 -4
- package/dist/commands/experimental/setupRsc.js +1 -1
- package/dist/commands/experimental/setupRscHandler.js +2 -1
- package/dist/commands/experimental/setupStreamingSsr.js +1 -1
- package/dist/commands/experimental/setupStreamingSsrHandler.js +3 -2
- package/dist/commands/generate/cell/cell.js +20 -0
- package/dist/commands/generate/cell/cellHandler.js +68 -20
- package/dist/commands/generate/cell/templates/cell.tsx.template +21 -2
- package/dist/commands/generate/cell/templates/cellFragment.tsx.template +43 -0
- package/dist/commands/generate/cell/templates/cellList.tsx.template +21 -2
- package/dist/commands/generate/cell/templates/storiesFragment.tsx.template +23 -0
- package/dist/commands/generate/cell/templates/test.js.template +1 -1
- package/dist/commands/generate/cell/templates/testFragment.js.template +30 -0
- package/dist/commands/generate/dataMigration/dataMigration.js +2 -1
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +23 -3
- package/dist/commands/generate/dbAuth/templates/login.oauth.tsx.template +164 -0
- package/dist/commands/generate/dbAuth/templates/signup.oauth.tsx.template +147 -0
- package/dist/commands/generate/directive/directiveHandler.js +2 -1
- package/dist/commands/generate/function/functionHandler.js +2 -1
- package/dist/commands/generate/job/jobHandler.js +2 -1
- package/dist/commands/generate/model/modelHandler.js +2 -1
- package/dist/commands/generate/ogImage/ogImageHandler.js +2 -1
- package/dist/commands/generate/package/filesTask.js +9 -12
- package/dist/commands/generate/package/packageHandler.js +3 -4
- package/dist/commands/generate/page/pageHandler.js +2 -1
- package/dist/commands/generate/realtime/realtime.js +1 -1
- package/dist/commands/generate/realtime/realtimeHandler.js +2 -9
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +1 -1
- package/dist/commands/generate/scaffold/scaffoldHandler.js +10 -5
- package/dist/commands/generate/scaffold/templates/components/NameForm.tsx.template +3 -3
- package/dist/commands/generate/scaffold/templates/lib/formatters.test.tsx.template +11 -0
- package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +13 -1
- package/dist/commands/generate/script/scriptHandler.js +2 -1
- package/dist/commands/generate/sdl/sdlHandler.js +2 -1
- package/dist/commands/generate/secret/secret.js +1 -1
- package/dist/commands/generate/service/serviceHandler.js +47 -38
- package/dist/commands/generate/service/templates/service.ts.template +22 -8
- package/dist/commands/generate/service/templates/test.ts.template +1 -1
- package/dist/commands/generate/yargsCommandHelpers.js +1 -1
- package/dist/commands/generate/yargsHandlerHelpers.js +2 -1
- package/dist/commands/generate.js +1 -1
- package/dist/commands/info.js +1 -1
- package/dist/commands/lint.js +1 -1
- package/dist/commands/prerenderHandler.js +11 -4
- package/dist/commands/prismaHandler.js +7 -2
- package/dist/commands/record/init.js +1 -1
- package/dist/commands/serve.js +2 -1
- package/dist/commands/setup/auth/auth.js +2 -4
- package/dist/commands/setup/cache/cache.js +1 -1
- package/dist/commands/setup/cache/cacheHandler.js +2 -1
- package/dist/commands/setup/database/postgres.js +1 -1
- package/dist/commands/setup/database/postgresHandler.js +3 -1
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +2 -1
- package/dist/commands/setup/deploy/providers/coherence.js +1 -1
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +7 -6
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +2 -1
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +2 -1
- package/dist/commands/setup/deploy/providers/renderHandler.js +2 -1
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +2 -1
- package/dist/commands/setup/deploy/providers/universalDeployHandler.js +4 -6
- package/dist/commands/setup/deploy/providers/vercelHandler.js +2 -1
- package/dist/commands/setup/docker/docker.js +1 -1
- package/dist/commands/setup/docker/dockerHandler.js +2 -1
- package/dist/commands/setup/generator/generator.js +1 -1
- package/dist/commands/setup/generator/generatorHandler.js +1 -1
- package/dist/commands/setup/graphql/features/fragments/fragments.js +1 -1
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +3 -5
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +1 -1
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +2 -1
- package/dist/commands/setup/i18n/i18n.js +1 -1
- package/dist/commands/setup/i18n/i18nHandler.js +1 -1
- package/dist/commands/setup/jobs/jobs.js +1 -1
- package/dist/commands/setup/jobs/jobsHandler.js +2 -1
- package/dist/commands/setup/mailer/mailer.js +1 -1
- package/dist/commands/setup/mailer/mailerHandler.js +2 -1
- package/dist/commands/setup/middleware/ogImage/ogImage.js +1 -1
- package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +2 -1
- package/dist/commands/setup/monitoring/sentry/sentry.js +1 -1
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +8 -7
- package/dist/commands/setup/neon/neon.js +1 -1
- package/dist/commands/setup/neon/neonHandler.js +5 -9
- package/dist/commands/setup/package/package.js +1 -1
- package/dist/commands/setup/package/packageHandler.js +4 -4
- package/dist/commands/setup/realtime/addRealtimeToGraphql.js +1 -1
- package/dist/commands/setup/realtime/realtime.js +1 -1
- package/dist/commands/setup/realtime/realtimeHandler.js +4 -16
- package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +1 -1
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +1 -1
- package/dist/commands/setup/server-file/serverFile.js +1 -1
- package/dist/commands/setup/server-file/serverFileHandler.js +2 -1
- package/dist/commands/setup/tenancy/authCodemod.js +66 -0
- package/dist/commands/setup/tenancy/dbCodemod.js +64 -0
- package/dist/commands/setup/tenancy/graphqlCodemod.js +88 -0
- package/dist/commands/setup/tenancy/preflight.js +49 -0
- package/dist/commands/setup/tenancy/schemaPrisma.js +81 -0
- package/dist/commands/setup/tenancy/signupCodemod.js +153 -0
- package/dist/commands/setup/tenancy/templates/InvitePage.tsx.template +63 -0
- package/dist/commands/setup/tenancy/templates/OrgScope.tsx.template +40 -0
- package/dist/commands/setup/tenancy/templates/ensureDefaultOrganizations.dataMigration.ts.template +39 -0
- package/dist/commands/setup/tenancy/templates/organizations.scenarios.ts.template +59 -0
- package/dist/commands/setup/tenancy/templates/organizations.sdl.ts.template +89 -0
- package/dist/commands/setup/tenancy/templates/organizations.test.ts.template +389 -0
- package/dist/commands/setup/tenancy/templates/organizations.ts.template +394 -0
- package/dist/commands/setup/tenancy/templates/requireMembership.test.ts.template +35 -0
- package/dist/commands/setup/tenancy/templates/requireMembership.ts.template +25 -0
- package/dist/commands/setup/tenancy/tenancy.js +30 -0
- package/dist/commands/setup/tenancy/tenancyHandler.js +425 -0
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +2 -1
- package/dist/commands/setup/ui/libraries/mantineHandler.js +2 -1
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +2 -1
- package/dist/commands/setup/uploads/schemaPrisma.js +41 -0
- package/dist/commands/setup/uploads/serverFile.js +151 -0
- package/dist/commands/setup/uploads/templates/requireUploadToken.ts.template +15 -0
- package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +23 -24
- package/dist/commands/setup/uploads/templates/uploads.sdl.ts.template +79 -0
- package/dist/commands/setup/uploads/templates/uploads.ts.template +89 -0
- package/dist/commands/setup/uploads/templates/withDataUri.ts.template +14 -0
- package/dist/commands/setup/uploads/templates/withSignedUrl.ts.template +16 -0
- package/dist/commands/setup/uploads/uploads.js +49 -7
- package/dist/commands/setup/uploads/uploadsHandler.js +256 -69
- package/dist/commands/setup.js +2 -1
- package/dist/commands/studio.js +1 -1
- package/dist/commands/test/testHandler.js +25 -71
- package/dist/commands/test/viteVersionCheck.js +75 -0
- package/dist/commands/test.js +10 -18
- package/dist/commands/type-checkHandler.js +1 -1
- package/dist/commands/upgrade/preUpgradeScripts.js +3 -3
- package/dist/commands/upgrade/upgrade.js +1 -1
- package/dist/commands/upgrade/upgradeHandler.js +2 -1
- package/dist/index.js +5 -8
- package/dist/lib/exit.js +1 -1
- package/dist/lib/index.js +6 -25
- package/dist/lib/loadEnvFiles.js +1 -1
- package/dist/lib/plugin.js +1 -1
- package/dist/lib/test.js +1 -1
- package/dist/lib/updateCheck.js +4 -4
- package/dist/middleware/checkNodeVersion.js +4 -4
- package/package.json +18 -18
- package/dist/commands/setup/uploads/dbCodemod.js +0 -28
- package/dist/commands/setup/uploads/templates/signedUrl.ts.template +0 -21
- package/dist/commands/test/testHandlerEsm.js +0 -109
- package/dist/commands/testEsm.js +0 -41
|
@@ -5,14 +5,15 @@ import { paramCase } from "change-case";
|
|
|
5
5
|
import humanize from "humanize-string";
|
|
6
6
|
import { Listr } from "listr2";
|
|
7
7
|
import pascalcase from "pascalcase";
|
|
8
|
-
import {
|
|
8
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
9
9
|
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
10
10
|
import {
|
|
11
11
|
addWorkspacePackages,
|
|
12
12
|
removeWorkspacePackages
|
|
13
13
|
} from "@cedarjs/cli-helpers/packageManager/packages";
|
|
14
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
14
15
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
15
|
-
import { getConfig } from "@cedarjs/project-config";
|
|
16
|
+
import { getConfig, getParsedScalars } from "@cedarjs/project-config";
|
|
16
17
|
import { pluralize, singularize } from "@cedarjs/utils/cedarPluralize";
|
|
17
18
|
import {
|
|
18
19
|
generateTemplate,
|
|
@@ -189,6 +190,7 @@ const assetFiles = async (name, tailwind) => {
|
|
|
189
190
|
}
|
|
190
191
|
return fileList;
|
|
191
192
|
};
|
|
193
|
+
const isDateTimeParsed = () => getParsedScalars().DateTime === "Date";
|
|
192
194
|
const formatters = async (name, isTypescript) => {
|
|
193
195
|
const outputPath = path.join(
|
|
194
196
|
getPaths().web.src,
|
|
@@ -210,7 +212,8 @@ const formatters = async (name, isTypescript) => {
|
|
|
210
212
|
templatePath: path.join("lib", "formatters.tsx.template")
|
|
211
213
|
}),
|
|
212
214
|
{
|
|
213
|
-
name
|
|
215
|
+
name,
|
|
216
|
+
parsedDateTime: isDateTimeParsed()
|
|
214
217
|
}
|
|
215
218
|
);
|
|
216
219
|
const templateTest = await generateTemplate(
|
|
@@ -220,7 +223,8 @@ const formatters = async (name, isTypescript) => {
|
|
|
220
223
|
templatePath: path.join("lib", "formatters.test.tsx.template")
|
|
221
224
|
}),
|
|
222
225
|
{
|
|
223
|
-
name
|
|
226
|
+
name,
|
|
227
|
+
parsedDateTime: isDateTimeParsed()
|
|
224
228
|
}
|
|
225
229
|
);
|
|
226
230
|
return {
|
|
@@ -340,7 +344,8 @@ const modelRelatedVariables = (model) => {
|
|
|
340
344
|
fieldsToImport,
|
|
341
345
|
editableColumns,
|
|
342
346
|
listFormattersImports,
|
|
343
|
-
formattersImports
|
|
347
|
+
formattersImports,
|
|
348
|
+
parsedDateTime: isDateTimeParsed()
|
|
344
349
|
};
|
|
345
350
|
};
|
|
346
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
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
|
-
import {
|
|
4
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
5
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
5
6
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
6
7
|
import {
|
|
7
8
|
getPaths,
|
|
@@ -2,8 +2,9 @@ import ansis from "ansis";
|
|
|
2
2
|
import boxen from "boxen";
|
|
3
3
|
import camelcase from "camelcase";
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
|
-
import {
|
|
5
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
6
6
|
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
7
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
7
8
|
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
8
9
|
import { getConfig } from "@cedarjs/project-config";
|
|
9
10
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { terminalLink } from "termi-link";
|
|
3
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
3
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
4
4
|
const DEFAULT_LENGTH = 32;
|
|
5
5
|
const generateSecret = (length = DEFAULT_LENGTH) => {
|
|
6
6
|
return crypto.randomBytes(Math.trunc(length)).toString("base64");
|
|
@@ -250,6 +250,10 @@ const getIdName = async (model) => {
|
|
|
250
250
|
if (!isServiceModel(schemaResult)) {
|
|
251
251
|
return void 0;
|
|
252
252
|
}
|
|
253
|
+
if (schemaResult.primaryKey?.fields.length) {
|
|
254
|
+
const { fields, name } = schemaResult.primaryKey;
|
|
255
|
+
return { fields, whereArg: name || fields.join("_") };
|
|
256
|
+
}
|
|
253
257
|
return schemaResult.fields.find((field) => field.isId)?.name;
|
|
254
258
|
};
|
|
255
259
|
const files = async ({
|
|
@@ -262,6 +266,11 @@ const files = async ({
|
|
|
262
266
|
const componentName = camelcase(pluralize(name));
|
|
263
267
|
const model = name;
|
|
264
268
|
const idName = await getIdName(model);
|
|
269
|
+
if (tests && rest.crud && idName !== void 0 && typeof idName !== "string") {
|
|
270
|
+
throw new Error(
|
|
271
|
+
`Cannot generate CRUD tests for "${model}": it has a compound primary key (@@id([${idName.fields.join(", ")}])), which isn't supported by the generated test file yet. Re-run with \`--tests=false\`.`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
265
274
|
const prismaImportSource = "src/lib/db";
|
|
266
275
|
let modelRelations;
|
|
267
276
|
if (relations) {
|
|
@@ -286,46 +295,46 @@ const files = async ({
|
|
|
286
295
|
...rest
|
|
287
296
|
}
|
|
288
297
|
});
|
|
289
|
-
const testFile = await templateForFile({
|
|
290
|
-
name,
|
|
291
|
-
side: "api",
|
|
292
|
-
sidePathSection: "services",
|
|
293
|
-
generator: "service",
|
|
294
|
-
outputPath: path.join(componentName, componentName + ".test.ts"),
|
|
295
|
-
templatePath: "test.ts.template",
|
|
296
|
-
templateVars: {
|
|
297
|
-
relations: relations || [],
|
|
298
|
-
create: await fieldsToInput(model),
|
|
299
|
-
update: await fieldsToUpdate(model),
|
|
300
|
-
types: await fieldTypes(model),
|
|
301
|
-
prismaImport: (await parseSchema(model)).scalarFields.some(
|
|
302
|
-
(field) => field.type === "Decimal"
|
|
303
|
-
),
|
|
304
|
-
prismaModel: model,
|
|
305
|
-
idName,
|
|
306
|
-
prismaImportSource,
|
|
307
|
-
...rest
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
const scenariosFile = await templateForFile({
|
|
311
|
-
name,
|
|
312
|
-
side: "api",
|
|
313
|
-
sidePathSection: "services",
|
|
314
|
-
generator: "service",
|
|
315
|
-
outputPath: path.join(componentName, componentName + ".scenarios.ts"),
|
|
316
|
-
templatePath: "scenarios.ts.template",
|
|
317
|
-
templateVars: {
|
|
318
|
-
scenario: await buildScenario(model),
|
|
319
|
-
stringifiedScenario: await buildStringifiedScenario(model),
|
|
320
|
-
prismaModel: model,
|
|
321
|
-
idName,
|
|
322
|
-
relations: modelRelations,
|
|
323
|
-
prismaImportSource,
|
|
324
|
-
...rest
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
298
|
const files2 = [serviceFile];
|
|
328
299
|
if (tests) {
|
|
300
|
+
const testFile = await templateForFile({
|
|
301
|
+
name,
|
|
302
|
+
side: "api",
|
|
303
|
+
sidePathSection: "services",
|
|
304
|
+
generator: "service",
|
|
305
|
+
outputPath: path.join(componentName, componentName + ".test.ts"),
|
|
306
|
+
templatePath: "test.ts.template",
|
|
307
|
+
templateVars: {
|
|
308
|
+
relations: relations || [],
|
|
309
|
+
create: await fieldsToInput(model),
|
|
310
|
+
update: await fieldsToUpdate(model),
|
|
311
|
+
types: await fieldTypes(model),
|
|
312
|
+
prismaImport: (await parseSchema(model)).scalarFields.some(
|
|
313
|
+
(field) => field.type === "Decimal"
|
|
314
|
+
),
|
|
315
|
+
prismaModel: model,
|
|
316
|
+
idName,
|
|
317
|
+
prismaImportSource,
|
|
318
|
+
...rest
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
const scenariosFile = await templateForFile({
|
|
322
|
+
name,
|
|
323
|
+
side: "api",
|
|
324
|
+
sidePathSection: "services",
|
|
325
|
+
generator: "service",
|
|
326
|
+
outputPath: path.join(componentName, componentName + ".scenarios.ts"),
|
|
327
|
+
templatePath: "scenarios.ts.template",
|
|
328
|
+
templateVars: {
|
|
329
|
+
scenario: await buildScenario(model),
|
|
330
|
+
stringifiedScenario: await buildStringifiedScenario(model),
|
|
331
|
+
prismaModel: model,
|
|
332
|
+
idName,
|
|
333
|
+
relations: modelRelations,
|
|
334
|
+
prismaImportSource,
|
|
335
|
+
...rest
|
|
336
|
+
}
|
|
337
|
+
});
|
|
329
338
|
files2.push(testFile);
|
|
330
339
|
files2.push(scenariosFile);
|
|
331
340
|
}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import type { QueryResolvers<% if (crud) { %>, MutationResolvers<% } %><% if (relations.length) { %>, ${singularPascalName}RelationResolvers<% } %> } from 'types/graphql'
|
|
2
2
|
|
|
3
3
|
import { db } from 'src/lib/db'
|
|
4
|
-
|
|
4
|
+
<%
|
|
5
|
+
// A compound `@@id([...])` key comes through as `{ fields, whereArg }`
|
|
6
|
+
// instead of a single field name -- build the destructure/where-clause
|
|
7
|
+
// snippets for both shapes here so the rest of the template can stay
|
|
8
|
+
// shape-agnostic.
|
|
9
|
+
const idIsComposite = idName != null && typeof idName === 'object'
|
|
10
|
+
const idFields = idIsComposite ? idName.fields : [idName]
|
|
11
|
+
const idArgs = idFields.join(', ')
|
|
12
|
+
const idWhere = idIsComposite
|
|
13
|
+
? `${idName.whereArg}: { ${idFields.join(', ')} }`
|
|
14
|
+
: idName
|
|
15
|
+
const idWhereFromRoot = idIsComposite
|
|
16
|
+
? `${idName.whereArg}: { ${idFields.map((f) => `${f}: root?.${f}`).join(', ')} }`
|
|
17
|
+
: `${idName}: root?.${idName}`
|
|
18
|
+
%>
|
|
5
19
|
export const ${pluralCamelName}: QueryResolvers['${pluralCamelName}'] = () => {
|
|
6
20
|
return db.${singularCamelName}.findMany()
|
|
7
21
|
}<% if (crud || relations.length) { %>
|
|
8
22
|
|
|
9
|
-
export const ${singularCamelName}: QueryResolvers['${singularCamelName}'] = ({ ${
|
|
23
|
+
export const ${singularCamelName}: QueryResolvers['${singularCamelName}'] = ({ ${idArgs} }) => {
|
|
10
24
|
return db.${singularCamelName}.findUnique({
|
|
11
|
-
where: { ${
|
|
25
|
+
where: { ${idWhere} },
|
|
12
26
|
})
|
|
13
27
|
}<% } %><% if (crud) { %>
|
|
14
28
|
|
|
@@ -18,21 +32,21 @@ export const create${singularPascalName}: MutationResolvers['create${singularPas
|
|
|
18
32
|
})
|
|
19
33
|
}
|
|
20
34
|
|
|
21
|
-
export const update${singularPascalName}: MutationResolvers['update${singularPascalName}'] = ({ ${
|
|
35
|
+
export const update${singularPascalName}: MutationResolvers['update${singularPascalName}'] = ({ ${idArgs}, input }) => {
|
|
22
36
|
return db.${singularCamelName}.update({
|
|
23
37
|
data: input,
|
|
24
|
-
where: { ${
|
|
38
|
+
where: { ${idWhere} },
|
|
25
39
|
})
|
|
26
40
|
}
|
|
27
41
|
|
|
28
|
-
export const delete${singularPascalName}: MutationResolvers['delete${singularPascalName}'] = ({ ${
|
|
42
|
+
export const delete${singularPascalName}: MutationResolvers['delete${singularPascalName}'] = ({ ${idArgs} }) => {
|
|
29
43
|
return db.${singularCamelName}.delete({
|
|
30
|
-
where: { ${
|
|
44
|
+
where: { ${idWhere} },
|
|
31
45
|
})
|
|
32
46
|
}<% } %><% if (relations.length) { %>
|
|
33
47
|
|
|
34
48
|
export const ${singularPascalName}: ${singularPascalName}RelationResolvers = {<% relations.forEach(relation => { %>
|
|
35
49
|
${relation}: (_obj, { root }) => {
|
|
36
|
-
return db.${singularCamelName}.findUnique({ where: { ${
|
|
50
|
+
return db.${singularCamelName}.findUnique({ where: { ${idWhereFromRoot} } }).${relation}()
|
|
37
51
|
},<% }) %>
|
|
38
52
|
}<% } %>
|
|
@@ -40,7 +40,7 @@ import type { StandardScenario } from './${pluralCamelName}.scenarios.js'
|
|
|
40
40
|
// and can fail without adjustments, e.g. Float.
|
|
41
41
|
// Please refer to the RedwoodJS Testing Docs:
|
|
42
42
|
// https://cedarjs.com/docs/testing#testing-services
|
|
43
|
-
// https://cedarjs.com/docs/testing#
|
|
43
|
+
// https://cedarjs.com/docs/testing#expect-type-considerations
|
|
44
44
|
|
|
45
45
|
describe('${pluralCamelName}', () => {
|
|
46
46
|
scenario('returns all ${pluralCamelName}', async (scenario: StandardScenario) => {
|
|
@@ -3,7 +3,8 @@ import path from "node:path";
|
|
|
3
3
|
import { camelCase } from "change-case";
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
5
|
import pascalcase from "pascalcase";
|
|
6
|
-
import {
|
|
6
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
7
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
7
8
|
import { ensurePosixPath, getConfig } from "@cedarjs/project-config";
|
|
8
9
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
9
10
|
import { generateTemplate, getPaths, writeFilesTask } from "../../lib/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { terminalLink } from "termi-link";
|
|
2
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
3
2
|
import { runBinSync } from "@cedarjs/cli-helpers/packageManager/exec";
|
|
3
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
4
4
|
import * as generateCell from "./generate/cell/cell.js";
|
|
5
5
|
import * as generateComponent from "./generate/component/component.js";
|
|
6
6
|
import * as generateDataMigration from "./generate/dataMigration/dataMigration.js";
|
package/dist/commands/info.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import envinfo from "envinfo";
|
|
4
4
|
import { terminalLink } from "termi-link";
|
|
5
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
5
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
6
6
|
import { getConfigPath } from "@cedarjs/project-config";
|
|
7
7
|
const command = "info";
|
|
8
8
|
const description = "Print your system environment information";
|
package/dist/commands/lint.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { terminalLink } from "termi-link";
|
|
3
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
4
3
|
import { runBin } from "@cedarjs/cli-helpers/packageManager/exec";
|
|
4
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
5
5
|
import { getPaths } from "@cedarjs/project-config";
|
|
6
6
|
const command = "lint [paths..]";
|
|
7
7
|
const description = "Lint your files";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
|
-
import {
|
|
4
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
5
5
|
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
6
|
-
import {
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
7
|
+
import { getConfig, getParsedScalars, getPaths } from "@cedarjs/project-config";
|
|
7
8
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
8
9
|
import { runScriptFunction } from "../lib/exec.js";
|
|
9
10
|
import { configureBabel } from "../lib/execBabel.js";
|
|
@@ -93,7 +94,7 @@ async function expandRouteParameters(route) {
|
|
|
93
94
|
return [route];
|
|
94
95
|
}
|
|
95
96
|
const getTasks = async (dryrun, routerPathFilter = null) => {
|
|
96
|
-
const detector =
|
|
97
|
+
const detector = await import("@cedarjs/prerender/detection");
|
|
97
98
|
const detectedRoutes = detector.detectPrerenderRoutes();
|
|
98
99
|
const prerenderRoutes = detectedRoutes.filter(hasPath).map(normalizeRoute);
|
|
99
100
|
if (prerenderRoutes.length === 0) {
|
|
@@ -105,6 +106,12 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
|
|
|
105
106
|
);
|
|
106
107
|
return [];
|
|
107
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
|
+
}
|
|
108
115
|
const indexHtmlPath = path.join(getPaths().web.dist, "index.html");
|
|
109
116
|
if (!fs.existsSync(indexHtmlPath)) {
|
|
110
117
|
console.error(
|
|
@@ -116,7 +123,7 @@ const getTasks = async (dryrun, routerPathFilter = null) => {
|
|
|
116
123
|
const expandedRouteParameters = await Promise.all(
|
|
117
124
|
prerenderRoutes.map((route) => expandRouteParameters(route))
|
|
118
125
|
);
|
|
119
|
-
const prerenderer =
|
|
126
|
+
const prerenderer = await import("@cedarjs/prerender");
|
|
120
127
|
const listrTasks = expandedRouteParameters.flatMap((routesToPrerender) => {
|
|
121
128
|
const queryCache = {};
|
|
122
129
|
const shouldFold = routesToPrerender.length > 16;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import boxen from "boxen";
|
|
3
|
-
import {
|
|
3
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
4
4
|
import {
|
|
5
5
|
formatCedarCommand,
|
|
6
6
|
formatRunBinCommand,
|
|
7
7
|
formatRunTransitiveBinCommand
|
|
8
8
|
} from "@cedarjs/cli-helpers/packageManager/display";
|
|
9
9
|
import { runTransitiveBinSync } from "@cedarjs/cli-helpers/packageManager/exec";
|
|
10
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
10
11
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
11
12
|
import { getPaths } from "../lib/index.js";
|
|
12
13
|
const getErrorMessage = (error) => {
|
|
@@ -62,7 +63,11 @@ const handler = async ({
|
|
|
62
63
|
try {
|
|
63
64
|
runTransitiveBinSync("prisma", args, {
|
|
64
65
|
cwd: cedarPaths.base,
|
|
65
|
-
stdio:
|
|
66
|
+
stdio: [
|
|
67
|
+
process.stdin.isTTY && !process.env.CI ? "inherit" : "pipe",
|
|
68
|
+
"inherit",
|
|
69
|
+
"inherit"
|
|
70
|
+
]
|
|
66
71
|
});
|
|
67
72
|
if (hasHelpOption || args.length === 0) {
|
|
68
73
|
printWrapInfo();
|
package/dist/commands/serve.js
CHANGED
|
@@ -5,7 +5,8 @@ import { serve as serveSrvx } from "srvx";
|
|
|
5
5
|
import { terminalLink } from "termi-link";
|
|
6
6
|
import * as apiServerCLIConfig from "@cedarjs/api-server/apiCliConfig";
|
|
7
7
|
import * as bothServerCLIConfig from "@cedarjs/api-server/bothCliConfig";
|
|
8
|
-
import {
|
|
8
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
9
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
9
10
|
import * as webServerCLIConfig from "@cedarjs/web-server";
|
|
10
11
|
import { getPaths, getConfig } from "../lib/index.js";
|
|
11
12
|
import { serverFileExists } from "../lib/project.js";
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { terminalLink } from "termi-link";
|
|
4
|
-
import {
|
|
5
|
-
recordTelemetryAttributes,
|
|
6
|
-
standardAuthBuilder
|
|
7
|
-
} from "@cedarjs/cli-helpers";
|
|
4
|
+
import { standardAuthBuilder } from "@cedarjs/cli-helpers/auth/setupHelpers";
|
|
8
5
|
import { addRootPackages } from "@cedarjs/cli-helpers/packageManager/packages";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
9
7
|
import { getPaths } from "../../../lib/index.js";
|
|
10
8
|
const command = "auth <provider>";
|
|
11
9
|
const description = "Set up an auth configuration";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { terminalLink } from "termi-link";
|
|
2
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
2
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
3
3
|
const command = "cache <client>";
|
|
4
4
|
const description = "Sets up an init file for service caching";
|
|
5
5
|
const builder = (yargs) => {
|
|
@@ -2,7 +2,8 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import { terminalLink } from "termi-link";
|
|
5
|
-
import {
|
|
5
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { addEnvVarTask } from "@cedarjs/cli-helpers/project";
|
|
6
7
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
8
|
import { addPackagesTask, getPaths, writeFile } from "../../../lib/index.js";
|
|
8
9
|
import { isTypeScriptProject } from "../../../lib/project.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
1
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
2
2
|
const command = "postgres";
|
|
3
3
|
const description = "Switch your project from SQLite to PostgreSQL (schema, dependencies, and database adapter)";
|
|
4
4
|
function builder(yargs) {
|
|
@@ -2,9 +2,11 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import execa from "execa";
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
|
-
import { colors
|
|
5
|
+
import { colors } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { installPackages } from "@cedarjs/cli-helpers/installHelpers";
|
|
6
7
|
import { prettyPrintCedarCommand } from "@cedarjs/cli-helpers/packageManager";
|
|
7
8
|
import { addWorkspacePackages } from "@cedarjs/cli-helpers/packageManager/packages";
|
|
9
|
+
import { getPaths } from "@cedarjs/cli-helpers/paths";
|
|
8
10
|
import { resolveFile } from "@cedarjs/project-config";
|
|
9
11
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
10
12
|
function checkProjectShape(cedarPaths) {
|
|
@@ -2,7 +2,8 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import prompts from "prompts";
|
|
5
|
-
import {
|
|
5
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
6
7
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
8
|
import {
|
|
8
9
|
addPackagesTask,
|
|
@@ -3,16 +3,17 @@ import path from "path";
|
|
|
3
3
|
import prismaInternals from "@prisma/internals";
|
|
4
4
|
import { Listr } from "listr2";
|
|
5
5
|
import * as toml from "smol-toml";
|
|
6
|
-
import {
|
|
7
|
-
colors as c,
|
|
8
|
-
isTypeScriptProject,
|
|
9
|
-
getConfigPath
|
|
10
|
-
} from "@cedarjs/cli-helpers";
|
|
6
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
11
7
|
import {
|
|
12
8
|
formatCedarCommand,
|
|
13
9
|
formatRunBinCommand
|
|
14
10
|
} from "@cedarjs/cli-helpers/packageManager/display";
|
|
15
|
-
import {
|
|
11
|
+
import { isTypeScriptProject } from "@cedarjs/cli-helpers/project";
|
|
12
|
+
import {
|
|
13
|
+
getConfigPath,
|
|
14
|
+
getPaths,
|
|
15
|
+
getPrismaSchemas
|
|
16
|
+
} from "@cedarjs/project-config";
|
|
16
17
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
17
18
|
import { printSetupNotes } from "../../../../lib/index.js";
|
|
18
19
|
import { serverFileExists } from "../../../../lib/project.js";
|
|
@@ -3,8 +3,9 @@ import { EOL } from "os";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import prismaInternals from "@prisma/internals";
|
|
5
5
|
import { Listr } from "listr2";
|
|
6
|
-
import {
|
|
6
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
7
7
|
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
8
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
8
9
|
import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
|
|
9
10
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
10
11
|
import { writeFilesTask, printSetupNotes } from "../../../../lib/index.js";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
|
-
import {
|
|
4
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
5
5
|
import { formatCedarCommand } from "@cedarjs/cli-helpers/packageManager/display";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
6
7
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
8
|
import {
|
|
8
9
|
addPackagesTask,
|
|
@@ -2,7 +2,8 @@ import path from "path";
|
|
|
2
2
|
import prismaInternals from "@prisma/internals";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
4
|
import prompts from "prompts";
|
|
5
|
-
import {
|
|
5
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
6
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
6
7
|
import { getPaths, getPrismaSchemas } from "@cedarjs/project-config";
|
|
7
8
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
8
9
|
import { writeFilesTask, printSetupNotes } from "../../../../lib/index.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Listr } from "listr2";
|
|
4
|
-
import {
|
|
4
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
5
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
5
6
|
import { getSchemaPath, getConfigPath } from "@cedarjs/project-config";
|
|
6
7
|
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
8
|
import {
|