@cedarjs/cli 0.0.4
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/LICENSE +21 -0
- package/README.md +706 -0
- package/dist/commands/build.js +54 -0
- package/dist/commands/buildHandler.js +134 -0
- package/dist/commands/check.js +28 -0
- package/dist/commands/console.js +13 -0
- package/dist/commands/consoleHandler.js +68 -0
- package/dist/commands/deploy/baremetal/SshExecutor.js +41 -0
- package/dist/commands/deploy/baremetal/baremetalHandler.js +558 -0
- package/dist/commands/deploy/baremetal.js +89 -0
- package/dist/commands/deploy/flightcontrol.js +40 -0
- package/dist/commands/deploy/flightcontrolHandler.js +58 -0
- package/dist/commands/deploy/helpers/deployBuilder.js +25 -0
- package/dist/commands/deploy/helpers/deployHandler.js +31 -0
- package/dist/commands/deploy/netlify.js +21 -0
- package/dist/commands/deploy/packing/nft.js +61 -0
- package/dist/commands/deploy/render.js +37 -0
- package/dist/commands/deploy/renderHandler.js +70 -0
- package/dist/commands/deploy/serverless.js +51 -0
- package/dist/commands/deploy/serverlessHandler.js +211 -0
- package/dist/commands/deploy/vercel.js +21 -0
- package/dist/commands/deploy.js +21 -0
- package/dist/commands/destroy/cell/cell.js +12 -0
- package/dist/commands/destroy/cell/cellHandler.js +10 -0
- package/dist/commands/destroy/component/component.js +15 -0
- package/dist/commands/destroy/component/componentHandler.js +10 -0
- package/dist/commands/destroy/directive/directive.js +14 -0
- package/dist/commands/destroy/directive/directiveHandler.js +12 -0
- package/dist/commands/destroy/function/function.js +20 -0
- package/dist/commands/destroy/function/functionHandler.js +10 -0
- package/dist/commands/destroy/handlerHelpers.js +34 -0
- package/dist/commands/destroy/helpers.js +22 -0
- package/dist/commands/destroy/layout/layout.js +12 -0
- package/dist/commands/destroy/layout/layoutHandler.js +10 -0
- package/dist/commands/destroy/page/page.js +20 -0
- package/dist/commands/destroy/page/pageHandler.js +51 -0
- package/dist/commands/destroy/scaffold/scaffold.js +16 -0
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +105 -0
- package/dist/commands/destroy/sdl/sdl.js +16 -0
- package/dist/commands/destroy/sdl/sdlHandler.js +33 -0
- package/dist/commands/destroy/service/service.js +10 -0
- package/dist/commands/destroy/service/serviceHandler.js +17 -0
- package/dist/commands/destroy.js +25 -0
- package/dist/commands/dev.js +47 -0
- package/dist/commands/devHandler.js +202 -0
- package/dist/commands/exec.js +38 -0
- package/dist/commands/execHandler.js +180 -0
- package/dist/commands/experimental/setupInngest.js +28 -0
- package/dist/commands/experimental/setupInngestHandler.js +46 -0
- package/dist/commands/experimental/setupOpentelemetry.js +34 -0
- package/dist/commands/experimental/setupOpentelemetryHandler.js +215 -0
- package/dist/commands/experimental/setupReactCompiler.js +28 -0
- package/dist/commands/experimental/setupReactCompilerHandler.js +124 -0
- package/dist/commands/experimental/setupRsc.js +28 -0
- package/dist/commands/experimental/setupRscHandler.js +408 -0
- package/dist/commands/experimental/setupStreamingSsr.js +28 -0
- package/dist/commands/experimental/setupStreamingSsrHandler.js +208 -0
- package/dist/commands/experimental/templates/opentelemetry.ts.template +55 -0
- package/dist/commands/experimental/templates/rsc/AboutCounter.tsx.template +20 -0
- package/dist/commands/experimental/templates/rsc/AboutPage.css.template +2 -0
- package/dist/commands/experimental/templates/rsc/AboutPage.tsx.template +17 -0
- package/dist/commands/experimental/templates/rsc/Counter.css.template +7 -0
- package/dist/commands/experimental/templates/rsc/Counter.module.css.template +3 -0
- package/dist/commands/experimental/templates/rsc/Counter.tsx.template +18 -0
- package/dist/commands/experimental/templates/rsc/Document.tsx.template +27 -0
- package/dist/commands/experimental/templates/rsc/HomePage.css.template +2 -0
- package/dist/commands/experimental/templates/rsc/HomePage.module.css.template +3 -0
- package/dist/commands/experimental/templates/rsc/HomePage.tsx.template +19 -0
- package/dist/commands/experimental/templates/rsc/NavigationLayout.css.template +32 -0
- package/dist/commands/experimental/templates/rsc/NavigationLayout.tsx.template +31 -0
- package/dist/commands/experimental/templates/rsc/Routes.tsx.template +29 -0
- package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +35 -0
- package/dist/commands/experimental/templates/rsc/entry.server.tsx.template +20 -0
- package/dist/commands/experimental/templates/rsc/index.css.template +4 -0
- package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +27 -0
- package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +40 -0
- package/dist/commands/experimental/templates/streamingSsr/entry.server.tsx.template +20 -0
- package/dist/commands/experimental/templates/streamingSsr/tsconfig.json.template +54 -0
- package/dist/commands/experimental/util.js +69 -0
- package/dist/commands/experimental.js +22 -0
- package/dist/commands/generate/cell/cell.js +35 -0
- package/dist/commands/generate/cell/cellHandler.js +153 -0
- package/dist/commands/generate/cell/templates/cell.tsx.template +34 -0
- package/dist/commands/generate/cell/templates/cellList.tsx.template +40 -0
- package/dist/commands/generate/cell/templates/mock.ts.template +7 -0
- package/dist/commands/generate/cell/templates/mockList.ts.template +14 -0
- package/dist/commands/generate/cell/templates/stories.tsx.template +35 -0
- package/dist/commands/generate/cell/templates/test.js.template +42 -0
- package/dist/commands/generate/cell/utils/utils.js +43 -0
- package/dist/commands/generate/component/component.js +15 -0
- package/dist/commands/generate/component/componentHandler.js +55 -0
- package/dist/commands/generate/component/templates/component.tsx.template +10 -0
- package/dist/commands/generate/component/templates/stories.jsx.template +17 -0
- package/dist/commands/generate/component/templates/stories.tsx.template +26 -0
- package/dist/commands/generate/component/templates/test.tsx.template +14 -0
- package/dist/commands/generate/dataMigration/dataMigration.js +105 -0
- package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +7 -0
- package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +5 -0
- package/dist/commands/generate/dbAuth/dbAuth.js +55 -0
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +375 -0
- package/dist/commands/generate/dbAuth/templates/forgotPassword.tsx.template +94 -0
- package/dist/commands/generate/dbAuth/templates/login.tsx.template +130 -0
- package/dist/commands/generate/dbAuth/templates/login.webAuthn.tsx.template +264 -0
- package/dist/commands/generate/dbAuth/templates/resetPassword.tsx.template +121 -0
- package/dist/commands/generate/dbAuth/templates/signup.tsx.template +123 -0
- package/dist/commands/generate/directive/directive.js +15 -0
- package/dist/commands/generate/directive/directiveHandler.js +159 -0
- package/dist/commands/generate/directive/templates/transformer.directive.test.ts.template +18 -0
- package/dist/commands/generate/directive/templates/transformer.directive.ts.template +38 -0
- package/dist/commands/generate/directive/templates/validator.directive.test.ts.template +17 -0
- package/dist/commands/generate/directive/templates/validator.directive.ts.template +39 -0
- package/dist/commands/generate/function/function.js +29 -0
- package/dist/commands/generate/function/functionHandler.js +131 -0
- package/dist/commands/generate/function/templates/function.ts.template +33 -0
- package/dist/commands/generate/function/templates/scenarios.ts.template +8 -0
- package/dist/commands/generate/function/templates/test.ts.template +30 -0
- package/dist/commands/generate/helpers.js +71 -0
- package/dist/commands/generate/job/job.js +39 -0
- package/dist/commands/generate/job/jobHandler.js +138 -0
- package/dist/commands/generate/job/templates/job.ts.template +8 -0
- package/dist/commands/generate/job/templates/scenarios.ts.template +8 -0
- package/dist/commands/generate/job/templates/test.ts.template +7 -0
- package/dist/commands/generate/layout/layout.js +25 -0
- package/dist/commands/generate/layout/layoutHandler.js +59 -0
- package/dist/commands/generate/layout/templates/layout.tsx.a11y.template +27 -0
- package/dist/commands/generate/layout/templates/layout.tsx.template +9 -0
- package/dist/commands/generate/layout/templates/stories.tsx.template +13 -0
- package/dist/commands/generate/layout/templates/test.tsx.template +14 -0
- package/dist/commands/generate/model/model.js +29 -0
- package/dist/commands/generate/model/modelHandler.js +63 -0
- package/dist/commands/generate/model/templates/model.js.template +3 -0
- package/dist/commands/generate/ogImage/ogImage.js +43 -0
- package/dist/commands/generate/ogImage/ogImageHandler.js +111 -0
- package/dist/commands/generate/ogImage/templates/ogImage.og.tsx.template +13 -0
- package/dist/commands/generate/page/page.js +22 -0
- package/dist/commands/generate/page/pageHandler.js +227 -0
- package/dist/commands/generate/page/templates/page.tsx.template +35 -0
- package/dist/commands/generate/page/templates/stories.tsx.parameters.template +13 -0
- package/dist/commands/generate/page/templates/stories.tsx.template +13 -0
- package/dist/commands/generate/page/templates/test.tsx.template +14 -0
- package/dist/commands/generate/realtime/realtime.js +41 -0
- package/dist/commands/generate/realtime/realtimeHandler.js +215 -0
- package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.sdl.ts.template +27 -0
- package/dist/commands/generate/realtime/templates/liveQueries/blank/blank.service.ts.template +73 -0
- package/dist/commands/generate/realtime/templates/realtime.ts.template +42 -0
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.sdl.ts.template +20 -0
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.service.ts.template +19 -0
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +58 -0
- package/dist/commands/generate/scaffold/scaffold.js +38 -0
- package/dist/commands/generate/scaffold/scaffoldHandler.js +663 -0
- package/dist/commands/generate/scaffold/templates/assets/scaffold.css.template +398 -0
- package/dist/commands/generate/scaffold/templates/assets/scaffold.tailwind.css.template +243 -0
- package/dist/commands/generate/scaffold/templates/components/EditNameCell.tsx.template +74 -0
- package/dist/commands/generate/scaffold/templates/components/Name.tsx.template +79 -0
- package/dist/commands/generate/scaffold/templates/components/NameCell.tsx.template +32 -0
- package/dist/commands/generate/scaffold/templates/components/NameForm.tsx.template +123 -0
- package/dist/commands/generate/scaffold/templates/components/Names.tsx.template +88 -0
- package/dist/commands/generate/scaffold/templates/components/NamesCell.tsx.template +45 -0
- package/dist/commands/generate/scaffold/templates/components/NewName.tsx.template +55 -0
- package/dist/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template +37 -0
- package/dist/commands/generate/scaffold/templates/lib/formatters.test.tsx.template +192 -0
- package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +58 -0
- package/dist/commands/generate/scaffold/templates/pages/EditNamePage.tsx.template +11 -0
- package/dist/commands/generate/scaffold/templates/pages/NamePage.tsx.template +11 -0
- package/dist/commands/generate/scaffold/templates/pages/NamesPage.tsx.template +7 -0
- package/dist/commands/generate/scaffold/templates/pages/NewNamePage.tsx.template +7 -0
- package/dist/commands/generate/script/script.js +29 -0
- package/dist/commands/generate/script/scriptHandler.js +85 -0
- package/dist/commands/generate/script/templates/script.ts.template +15 -0
- package/dist/commands/generate/script/templates/tsconfig.json.template +33 -0
- package/dist/commands/generate/sdl/sdl.js +48 -0
- package/dist/commands/generate/sdl/sdlHandler.js +282 -0
- package/dist/commands/generate/sdl/templates/sdl.js.template +70 -0
- package/dist/commands/generate/sdl/templates/sdl.ts.template +70 -0
- package/dist/commands/generate/secret/secret.js +52 -0
- package/dist/commands/generate/service/service.js +50 -0
- package/dist/commands/generate/service/serviceHandler.js +301 -0
- package/dist/commands/generate/service/templates/scenarios.ts.template +7 -0
- package/dist/commands/generate/service/templates/service.ts.template +38 -0
- package/dist/commands/generate/service/templates/test.ts.template +84 -0
- package/dist/commands/generate/yargsCommandHelpers.js +77 -0
- package/dist/commands/generate/yargsHandlerHelpers.js +155 -0
- package/dist/commands/generate.js +44 -0
- package/dist/commands/info.js +36 -0
- package/dist/commands/jobs.js +17 -0
- package/dist/commands/jobsHandler.js +30 -0
- package/dist/commands/lint.js +57 -0
- package/dist/commands/prerender.js +34 -0
- package/dist/commands/prerenderHandler.js +282 -0
- package/dist/commands/prisma.js +17 -0
- package/dist/commands/prismaHandler.js +90 -0
- package/dist/commands/record/init.js +11 -0
- package/dist/commands/record.js +19 -0
- package/dist/commands/serve.js +139 -0
- package/dist/commands/serveApiHandler.js +15 -0
- package/dist/commands/serveBothHandler.js +95 -0
- package/dist/commands/serveWebHandler.js +17 -0
- package/dist/commands/setup/auth/auth.js +265 -0
- package/dist/commands/setup/cache/cache.js +37 -0
- package/dist/commands/setup/cache/cacheHandler.js +69 -0
- package/dist/commands/setup/cache/templates/memcached.ts.template +30 -0
- package/dist/commands/setup/cache/templates/redis.ts.template +24 -0
- package/dist/commands/setup/deploy/deploy.js +26 -0
- package/dist/commands/setup/deploy/helpers/helpers.js +9 -0
- package/dist/commands/setup/deploy/helpers/index.js +110 -0
- package/dist/commands/setup/deploy/providers/baremetal.js +9 -0
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +64 -0
- package/dist/commands/setup/deploy/providers/coherence.js +24 -0
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +203 -0
- package/dist/commands/setup/deploy/providers/flightcontrol.js +19 -0
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +294 -0
- package/dist/commands/setup/deploy/providers/netlify.js +9 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +42 -0
- package/dist/commands/setup/deploy/providers/render.js +17 -0
- package/dist/commands/setup/deploy/providers/renderHandler.js +111 -0
- package/dist/commands/setup/deploy/providers/serverless.js +11 -0
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +141 -0
- package/dist/commands/setup/deploy/providers/vercel.js +9 -0
- package/dist/commands/setup/deploy/providers/vercelHandler.js +56 -0
- package/dist/commands/setup/deploy/templates/baremetal.js +128 -0
- package/dist/commands/setup/deploy/templates/flightcontrol.js +85 -0
- package/dist/commands/setup/deploy/templates/netlify.js +32 -0
- package/dist/commands/setup/deploy/templates/render.js +72 -0
- package/dist/commands/setup/deploy/templates/serverless/api.js +78 -0
- package/dist/commands/setup/deploy/templates/serverless/web.js +32 -0
- package/dist/commands/setup/docker/docker.js +26 -0
- package/dist/commands/setup/docker/dockerHandler.js +265 -0
- package/dist/commands/setup/docker/templates/Dockerfile +154 -0
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +58 -0
- package/dist/commands/setup/docker/templates/docker-compose.prod.yml +63 -0
- package/dist/commands/setup/docker/templates/dockerignore +18 -0
- package/dist/commands/setup/generator/generator.js +49 -0
- package/dist/commands/setup/generator/generatorHandler.js +55 -0
- package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +117 -0
- package/dist/commands/setup/graphql/features/fragments/appImportTransform.js +20 -0
- package/dist/commands/setup/graphql/features/fragments/fragments.js +25 -0
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +89 -0
- package/dist/commands/setup/graphql/features/trustedDocuments/graphqlTransform.js +51 -0
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +25 -0
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +74 -0
- package/dist/commands/setup/graphql/graphql.js +18 -0
- package/dist/commands/setup/i18n/i18n.js +25 -0
- package/dist/commands/setup/i18n/i18nHandler.js +169 -0
- package/dist/commands/setup/i18n/templates/en.json.template +11 -0
- package/dist/commands/setup/i18n/templates/fr.json.template +11 -0
- package/dist/commands/setup/i18n/templates/i18n.js.template +52 -0
- package/dist/commands/setup/i18n/templates/storybook.preview.tsx.template +43 -0
- package/dist/commands/setup/jobs/jobs.js +31 -0
- package/dist/commands/setup/jobs/jobsHandler.js +122 -0
- package/dist/commands/setup/jobs/templates/jobs.ts.template +32 -0
- package/dist/commands/setup/mailer/mailer.js +30 -0
- package/dist/commands/setup/mailer/mailerHandler.js +106 -0
- package/dist/commands/setup/mailer/templates/mailer.ts.template +30 -0
- package/dist/commands/setup/mailer/templates/re-example.tsx.template +40 -0
- package/dist/commands/setup/middleware/middleware.js +17 -0
- package/dist/commands/setup/middleware/ogImage/__codemod_tests__/middleware.js +15 -0
- package/dist/commands/setup/middleware/ogImage/__codemod_tests__/vitePlugin.js +6 -0
- package/dist/commands/setup/middleware/ogImage/codemodMiddleware.js +97 -0
- package/dist/commands/setup/middleware/ogImage/codemodVitePlugin.js +65 -0
- package/dist/commands/setup/middleware/ogImage/ogImage.js +27 -0
- package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +121 -0
- package/dist/commands/setup/monitoring/monitoring.js +17 -0
- package/dist/commands/setup/monitoring/sentry/sentry.js +25 -0
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +163 -0
- package/dist/commands/setup/monitoring/sentry/templates/sentryApi.ts.template +15 -0
- package/dist/commands/setup/monitoring/sentry/templates/sentryWeb.ts.template +31 -0
- package/dist/commands/setup/package/package.js +33 -0
- package/dist/commands/setup/package/packageHandler.js +134 -0
- package/dist/commands/setup/realtime/realtime.js +37 -0
- package/dist/commands/setup/realtime/realtimeHandler.js +309 -0
- package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.sdl.template +14 -0
- package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.ts.template +14 -0
- package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.sdl.ts.template +27 -0
- package/dist/commands/setup/realtime/templates/liveQueries/auctions/auctions.ts.template +73 -0
- package/dist/commands/setup/realtime/templates/realtime.ts.template +46 -0
- package/dist/commands/setup/realtime/templates/stream/alphabet/alphabet.sdl.template +9 -0
- package/dist/commands/setup/realtime/templates/stream/alphabet/alphabet.ts.template +31 -0
- package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +58 -0
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +57 -0
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/rooms.sdl.ts.template +20 -0
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/rooms.ts.template +20 -0
- package/dist/commands/setup/server-file/serverFile.js +31 -0
- package/dist/commands/setup/server-file/serverFileHandler.js +56 -0
- package/dist/commands/setup/server-file/templates/server.ts.template +13 -0
- package/dist/commands/setup/tsconfig/tsconfig.js +25 -0
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +59 -0
- package/dist/commands/setup/ui/helpers/helpers.js +9 -0
- package/dist/commands/setup/ui/libraries/chakra-ui.js +24 -0
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +98 -0
- package/dist/commands/setup/ui/libraries/mantine.js +32 -0
- package/dist/commands/setup/ui/libraries/mantineHandler.js +138 -0
- package/dist/commands/setup/ui/libraries/tailwindcss.js +26 -0
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +386 -0
- package/dist/commands/setup/ui/templates/chakra.storybook.preview.tsx.template +20 -0
- package/dist/commands/setup/ui/templates/mantine-postcss.config.js.template +35 -0
- package/dist/commands/setup/ui/templates/mantine.storybook.preview.tsx.template +18 -0
- package/dist/commands/setup/ui/templates/postcss.config.js.template +9 -0
- package/dist/commands/setup/ui/ui.js +17 -0
- package/dist/commands/setup/uploads/dbCodemod.js +28 -0
- package/dist/commands/setup/uploads/templates/signedUrl.ts.template +21 -0
- package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +25 -0
- package/dist/commands/setup/uploads/uploads.js +26 -0
- package/dist/commands/setup/uploads/uploadsHandler.js +147 -0
- package/dist/commands/setup/vite/templates/vite.config.ts.template +19 -0
- package/dist/commands/setup/vite/vite.js +38 -0
- package/dist/commands/setup/vite/viteHandler.js +83 -0
- package/dist/commands/setup.js +33 -0
- package/dist/commands/studio.js +23 -0
- package/dist/commands/studioHandler.js +61 -0
- package/dist/commands/test.js +44 -0
- package/dist/commands/testHandler.js +138 -0
- package/dist/commands/ts-to-js.js +20 -0
- package/dist/commands/type-check.js +41 -0
- package/dist/commands/type-checkHandler.js +71 -0
- package/dist/commands/upgrade.js +441 -0
- package/dist/index.d.js +0 -0
- package/dist/index.js +146 -0
- package/dist/lib/background.js +45 -0
- package/dist/lib/colors.js +18 -0
- package/dist/lib/configureStorybook.js +50 -0
- package/dist/lib/exec.js +85 -0
- package/dist/lib/exit.js +44 -0
- package/dist/lib/extendFile.js +114 -0
- package/dist/lib/generatePrismaClient.js +60 -0
- package/dist/lib/index.js +485 -0
- package/dist/lib/loadEnvFiles.js +12 -0
- package/dist/lib/locking.js +60 -0
- package/dist/lib/merge/algorithms.js +30 -0
- package/dist/lib/merge/index.js +163 -0
- package/dist/lib/merge/semanticIdentity.js +18 -0
- package/dist/lib/merge/strategy.js +136 -0
- package/dist/lib/mockTelemetry.js +7 -0
- package/dist/lib/packages.js +77 -0
- package/dist/lib/plugin.js +206 -0
- package/dist/lib/pluralHelpers.js +50 -0
- package/dist/lib/ports.js +17 -0
- package/dist/lib/project.js +30 -0
- package/dist/lib/rollback.js +72 -0
- package/dist/lib/runTransform.js +66 -0
- package/dist/lib/rwPluralize.js +56 -0
- package/dist/lib/schemaHelpers.js +95 -0
- package/dist/lib/templates/storybook.preview.tsx.template +19 -0
- package/dist/lib/test.js +106 -0
- package/dist/lib/updateCheck.js +202 -0
- package/dist/lib/updateCheckExecute.js +2 -0
- package/dist/middleware/checkNodeVersion.js +23 -0
- package/dist/middleware/detectProjectRxVersion.js +12 -0
- package/dist/plugin.js +223 -0
- package/dist/rwfw.js +47 -0
- package/dist/telemetry/exporter.js +63 -0
- package/dist/telemetry/index.js +84 -0
- package/dist/telemetry/resource.js +98 -0
- package/dist/telemetry/send.js +80 -0
- package/dist/testLib/cells.js +188 -0
- package/dist/testLib/fetchFileFromTemplate.js +9 -0
- package/dist/testLib/getFilesWithPattern.js +21 -0
- package/dist/testLib/getRootPackageJSON.js +14 -0
- package/dist/testLib/isTSProject.js +9 -0
- package/dist/testLib/runTransform.js +42 -0
- package/package.json +102 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { Listr } from "listr2";
|
|
4
|
+
import { addApiPackages } from "@cedarjs/cli-helpers";
|
|
5
|
+
import { generate as generateTypes } from "@cedarjs/internal/dist/generate/generate";
|
|
6
|
+
import { errorTelemetry } from "@cedarjs/telemetry";
|
|
7
|
+
import c from "../../../lib/colors.js";
|
|
8
|
+
import { getPaths, transformTSToJS, writeFile } from "../../../lib/index.js";
|
|
9
|
+
import { isTypeScriptProject, serverFileExists } from "../../../lib/project.js";
|
|
10
|
+
import { setupServerFileTasks } from "../server-file/serverFileHandler.js";
|
|
11
|
+
const { version } = JSON.parse(
|
|
12
|
+
fs.readFileSync(
|
|
13
|
+
path.resolve(import.meta.dirname, "../../../../package.json"),
|
|
14
|
+
"utf-8"
|
|
15
|
+
)
|
|
16
|
+
);
|
|
17
|
+
async function handler({ force, includeExamples, verbose }) {
|
|
18
|
+
const redwoodPaths = getPaths();
|
|
19
|
+
const ts = isTypeScriptProject();
|
|
20
|
+
const realtimeLibFilePath = path.join(
|
|
21
|
+
redwoodPaths.api.lib,
|
|
22
|
+
`realtime.${isTypeScriptProject() ? "ts" : "js"}`
|
|
23
|
+
);
|
|
24
|
+
const tasks = new Listr(
|
|
25
|
+
[
|
|
26
|
+
addApiPackages(["ioredis@^5", `@cedarjs/realtime@${version}`]),
|
|
27
|
+
{
|
|
28
|
+
title: "Adding the realtime api lib ...",
|
|
29
|
+
task: async () => {
|
|
30
|
+
const serverFileTemplateContent = fs.readFileSync(
|
|
31
|
+
path.resolve(
|
|
32
|
+
import.meta.dirname,
|
|
33
|
+
"templates",
|
|
34
|
+
"realtime.ts.template"
|
|
35
|
+
),
|
|
36
|
+
"utf-8"
|
|
37
|
+
);
|
|
38
|
+
const setupScriptContent = ts ? serverFileTemplateContent : await transformTSToJS(
|
|
39
|
+
realtimeLibFilePath,
|
|
40
|
+
serverFileTemplateContent
|
|
41
|
+
);
|
|
42
|
+
return [
|
|
43
|
+
writeFile(realtimeLibFilePath, setupScriptContent, {
|
|
44
|
+
overwriteExisting: force
|
|
45
|
+
})
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
title: "Adding Countdown example subscription ...",
|
|
51
|
+
enabled: () => includeExamples,
|
|
52
|
+
task: async () => {
|
|
53
|
+
const exampleSubscriptionTemplateContent = fs.readFileSync(
|
|
54
|
+
path.resolve(
|
|
55
|
+
import.meta.dirname,
|
|
56
|
+
"templates",
|
|
57
|
+
"subscriptions",
|
|
58
|
+
"countdown",
|
|
59
|
+
`countdown.ts.template`
|
|
60
|
+
),
|
|
61
|
+
"utf-8"
|
|
62
|
+
);
|
|
63
|
+
const exampleFile = path.join(
|
|
64
|
+
redwoodPaths.api.subscriptions,
|
|
65
|
+
"countdown",
|
|
66
|
+
`countdown.${isTypeScriptProject() ? "ts" : "js"}`
|
|
67
|
+
);
|
|
68
|
+
const setupScriptContent = ts ? exampleSubscriptionTemplateContent : await transformTSToJS(
|
|
69
|
+
exampleFile,
|
|
70
|
+
exampleSubscriptionTemplateContent
|
|
71
|
+
);
|
|
72
|
+
return [
|
|
73
|
+
writeFile(exampleFile, setupScriptContent, {
|
|
74
|
+
overwriteExisting: force
|
|
75
|
+
})
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
title: "Adding NewMessage example subscription ...",
|
|
81
|
+
enabled: () => includeExamples,
|
|
82
|
+
task: async () => {
|
|
83
|
+
const exampleSdlTemplateContent = fs.readFileSync(
|
|
84
|
+
path.resolve(
|
|
85
|
+
import.meta.dirname,
|
|
86
|
+
"templates",
|
|
87
|
+
"subscriptions",
|
|
88
|
+
"newMessage",
|
|
89
|
+
`rooms.sdl.ts.template`
|
|
90
|
+
),
|
|
91
|
+
"utf-8"
|
|
92
|
+
);
|
|
93
|
+
const sdlFile = path.join(
|
|
94
|
+
redwoodPaths.api.graphql,
|
|
95
|
+
`rooms.sdl.${isTypeScriptProject() ? "ts" : "js"}`
|
|
96
|
+
);
|
|
97
|
+
const sdlContent = ts ? exampleSdlTemplateContent : await transformTSToJS(sdlFile, exampleSdlTemplateContent);
|
|
98
|
+
const exampleServiceTemplateContent = fs.readFileSync(
|
|
99
|
+
path.resolve(
|
|
100
|
+
import.meta.dirname,
|
|
101
|
+
"templates",
|
|
102
|
+
"subscriptions",
|
|
103
|
+
"newMessage",
|
|
104
|
+
`rooms.ts.template`
|
|
105
|
+
),
|
|
106
|
+
"utf-8"
|
|
107
|
+
);
|
|
108
|
+
const serviceFile = path.join(
|
|
109
|
+
redwoodPaths.api.services,
|
|
110
|
+
"rooms",
|
|
111
|
+
`rooms.${isTypeScriptProject() ? "ts" : "js"}`
|
|
112
|
+
);
|
|
113
|
+
const serviceContent = ts ? exampleServiceTemplateContent : await transformTSToJS(serviceFile, exampleServiceTemplateContent);
|
|
114
|
+
const exampleSubscriptionTemplateContent = fs.readFileSync(
|
|
115
|
+
path.resolve(
|
|
116
|
+
import.meta.dirname,
|
|
117
|
+
"templates",
|
|
118
|
+
"subscriptions",
|
|
119
|
+
"newMessage",
|
|
120
|
+
`newMessage.ts.template`
|
|
121
|
+
),
|
|
122
|
+
"utf-8"
|
|
123
|
+
);
|
|
124
|
+
const exampleFile = path.join(
|
|
125
|
+
redwoodPaths.api.subscriptions,
|
|
126
|
+
"newMessage",
|
|
127
|
+
`newMessage.${isTypeScriptProject() ? "ts" : "js"}`
|
|
128
|
+
);
|
|
129
|
+
const setupScriptContent = ts ? exampleSubscriptionTemplateContent : await transformTSToJS(
|
|
130
|
+
exampleFile,
|
|
131
|
+
exampleSubscriptionTemplateContent
|
|
132
|
+
);
|
|
133
|
+
return [
|
|
134
|
+
writeFile(sdlFile, sdlContent, {
|
|
135
|
+
overwriteExisting: force
|
|
136
|
+
}),
|
|
137
|
+
writeFile(serviceFile, serviceContent, {
|
|
138
|
+
overwriteExisting: force
|
|
139
|
+
}),
|
|
140
|
+
writeFile(exampleFile, setupScriptContent, {
|
|
141
|
+
overwriteExisting: force
|
|
142
|
+
})
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
title: "Adding Auctions example live query ...",
|
|
148
|
+
enabled: () => includeExamples,
|
|
149
|
+
task: async () => {
|
|
150
|
+
const exampleSdlTemplateContent = fs.readFileSync(
|
|
151
|
+
path.resolve(
|
|
152
|
+
import.meta.dirname,
|
|
153
|
+
"templates",
|
|
154
|
+
"liveQueries",
|
|
155
|
+
"auctions",
|
|
156
|
+
`auctions.sdl.ts.template`
|
|
157
|
+
),
|
|
158
|
+
"utf-8"
|
|
159
|
+
);
|
|
160
|
+
const sdlFile = path.join(
|
|
161
|
+
redwoodPaths.api.graphql,
|
|
162
|
+
`auctions.sdl.${isTypeScriptProject() ? "ts" : "js"}`
|
|
163
|
+
);
|
|
164
|
+
const sdlContent = ts ? exampleSdlTemplateContent : await transformTSToJS(sdlFile, exampleSdlTemplateContent);
|
|
165
|
+
const exampleServiceTemplateContent = fs.readFileSync(
|
|
166
|
+
path.resolve(
|
|
167
|
+
import.meta.dirname,
|
|
168
|
+
"templates",
|
|
169
|
+
"liveQueries",
|
|
170
|
+
"auctions",
|
|
171
|
+
`auctions.ts.template`
|
|
172
|
+
),
|
|
173
|
+
"utf-8"
|
|
174
|
+
);
|
|
175
|
+
const serviceFile = path.join(
|
|
176
|
+
redwoodPaths.api.services,
|
|
177
|
+
"auctions",
|
|
178
|
+
`auctions.${isTypeScriptProject() ? "ts" : "js"}`
|
|
179
|
+
);
|
|
180
|
+
const serviceContent = ts ? exampleServiceTemplateContent : await transformTSToJS(serviceFile, exampleServiceTemplateContent);
|
|
181
|
+
return [
|
|
182
|
+
writeFile(sdlFile, sdlContent, {
|
|
183
|
+
overwriteExisting: force
|
|
184
|
+
}),
|
|
185
|
+
writeFile(serviceFile, serviceContent, {
|
|
186
|
+
overwriteExisting: force
|
|
187
|
+
})
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
title: "Adding Defer example queries ...",
|
|
193
|
+
enabled: () => includeExamples,
|
|
194
|
+
task: async () => {
|
|
195
|
+
const exampleSdlTemplateContent = fs.readFileSync(
|
|
196
|
+
path.resolve(
|
|
197
|
+
import.meta.dirname,
|
|
198
|
+
"templates",
|
|
199
|
+
"defer",
|
|
200
|
+
"fastAndSlowFields",
|
|
201
|
+
`fastAndSlowFields.sdl.template`
|
|
202
|
+
),
|
|
203
|
+
"utf-8"
|
|
204
|
+
);
|
|
205
|
+
const sdlFile = path.join(
|
|
206
|
+
redwoodPaths.api.graphql,
|
|
207
|
+
`fastAndSlowFields.sdl.${isTypeScriptProject() ? "ts" : "js"}`
|
|
208
|
+
);
|
|
209
|
+
const sdlContent = ts ? exampleSdlTemplateContent : await transformTSToJS(sdlFile, exampleSdlTemplateContent);
|
|
210
|
+
const exampleServiceTemplateContent = fs.readFileSync(
|
|
211
|
+
path.resolve(
|
|
212
|
+
import.meta.dirname,
|
|
213
|
+
"templates",
|
|
214
|
+
"defer",
|
|
215
|
+
"fastAndSlowFields",
|
|
216
|
+
`fastAndSlowFields.ts.template`
|
|
217
|
+
),
|
|
218
|
+
"utf-8"
|
|
219
|
+
);
|
|
220
|
+
const serviceFile = path.join(
|
|
221
|
+
redwoodPaths.api.services,
|
|
222
|
+
"fastAndSlowFields",
|
|
223
|
+
`fastAndSlowFields.${isTypeScriptProject() ? "ts" : "js"}`
|
|
224
|
+
);
|
|
225
|
+
const serviceContent = ts ? exampleServiceTemplateContent : await transformTSToJS(serviceFile, exampleServiceTemplateContent);
|
|
226
|
+
return [
|
|
227
|
+
writeFile(sdlFile, sdlContent, {
|
|
228
|
+
overwriteExisting: force
|
|
229
|
+
}),
|
|
230
|
+
writeFile(serviceFile, serviceContent, {
|
|
231
|
+
overwriteExisting: force
|
|
232
|
+
})
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
title: "Adding Stream example queries ...",
|
|
238
|
+
enabled: () => includeExamples,
|
|
239
|
+
task: async () => {
|
|
240
|
+
const exampleSdlTemplateContent = fs.readFileSync(
|
|
241
|
+
path.resolve(
|
|
242
|
+
import.meta.dirname,
|
|
243
|
+
"templates",
|
|
244
|
+
"stream",
|
|
245
|
+
"alphabet",
|
|
246
|
+
`alphabet.sdl.template`
|
|
247
|
+
),
|
|
248
|
+
"utf-8"
|
|
249
|
+
);
|
|
250
|
+
const sdlFile = path.join(
|
|
251
|
+
redwoodPaths.api.graphql,
|
|
252
|
+
`alphabet.sdl.${isTypeScriptProject() ? "ts" : "js"}`
|
|
253
|
+
);
|
|
254
|
+
const sdlContent = ts ? exampleSdlTemplateContent : await transformTSToJS(sdlFile, exampleSdlTemplateContent);
|
|
255
|
+
const exampleServiceTemplateContent = fs.readFileSync(
|
|
256
|
+
path.resolve(
|
|
257
|
+
import.meta.dirname,
|
|
258
|
+
"templates",
|
|
259
|
+
"stream",
|
|
260
|
+
"alphabet",
|
|
261
|
+
`alphabet.ts.template`
|
|
262
|
+
),
|
|
263
|
+
"utf-8"
|
|
264
|
+
);
|
|
265
|
+
const serviceFile = path.join(
|
|
266
|
+
redwoodPaths.api.services,
|
|
267
|
+
"alphabet",
|
|
268
|
+
`alphabet.${isTypeScriptProject() ? "ts" : "js"}`
|
|
269
|
+
);
|
|
270
|
+
const serviceContent = ts ? exampleServiceTemplateContent : await transformTSToJS(serviceFile, exampleServiceTemplateContent);
|
|
271
|
+
return [
|
|
272
|
+
writeFile(sdlFile, sdlContent, {
|
|
273
|
+
overwriteExisting: force
|
|
274
|
+
}),
|
|
275
|
+
writeFile(serviceFile, serviceContent, {
|
|
276
|
+
overwriteExisting: force
|
|
277
|
+
})
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
title: `Generating types ...`,
|
|
283
|
+
task: async () => {
|
|
284
|
+
await generateTypes();
|
|
285
|
+
console.log(
|
|
286
|
+
"Note: You may need to manually restart GraphQL in VSCode to see the new types take effect.\n\n"
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
],
|
|
291
|
+
{
|
|
292
|
+
rendererOptions: { collapseSubtasks: false, persistentOutput: true },
|
|
293
|
+
renderer: verbose ? "verbose" : "default"
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
try {
|
|
297
|
+
if (!serverFileExists()) {
|
|
298
|
+
tasks.add(setupServerFileTasks({ force }));
|
|
299
|
+
}
|
|
300
|
+
await tasks.run();
|
|
301
|
+
} catch (e) {
|
|
302
|
+
errorTelemetry(process.argv, e.message);
|
|
303
|
+
console.error(c.error(e.message));
|
|
304
|
+
process.exit(e?.exitCode || 1);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
export {
|
|
308
|
+
handler
|
|
309
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const schema = gql`
|
|
2
|
+
type Query {
|
|
3
|
+
"""
|
|
4
|
+
A field that resolves fast.
|
|
5
|
+
"""
|
|
6
|
+
fastField: String! @skipAuth
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
A field that resolves slowly.
|
|
10
|
+
Maybe you want to @defer this field ;)
|
|
11
|
+
"""
|
|
12
|
+
slowField(waitFor: Int! = 5000): String @skipAuth
|
|
13
|
+
}
|
|
14
|
+
`
|
package/dist/commands/setup/realtime/templates/defer/fastAndSlowFields/fastAndSlowFields.ts.template
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { logger } from 'src/lib/logger'
|
|
2
|
+
|
|
3
|
+
const wait = (time: number) =>
|
|
4
|
+
new Promise((resolve) => setTimeout(resolve, time))
|
|
5
|
+
|
|
6
|
+
export const fastField = async () => {
|
|
7
|
+
return 'I am fast'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const slowField = async (_, { waitFor = 5000 }) => {
|
|
11
|
+
logger.debug('waiting on slowField')
|
|
12
|
+
await wait(waitFor)
|
|
13
|
+
return 'I am slow'
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// api/src/graphql/auctions.sdl.ts
|
|
2
|
+
|
|
3
|
+
export const schema = gql`
|
|
4
|
+
type Query {
|
|
5
|
+
auction(id: ID!): Auction @requireAuth
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type Auction {
|
|
9
|
+
id: ID!
|
|
10
|
+
title: String!
|
|
11
|
+
highestBid: Bid
|
|
12
|
+
bids: [Bid!]!
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type Bid {
|
|
16
|
+
amount: Int!
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Mutation {
|
|
20
|
+
bid(input: BidInput!): Bid @requireAuth
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
input BidInput {
|
|
24
|
+
auctionId: ID!
|
|
25
|
+
amount: Int!
|
|
26
|
+
}
|
|
27
|
+
`
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// api/src/services/auctions/auctions.ts
|
|
2
|
+
import type { LiveQueryStorageMechanism } from '@cedarjs/realtime'
|
|
3
|
+
|
|
4
|
+
import { logger } from 'src/lib/logger'
|
|
5
|
+
|
|
6
|
+
const auctions = [
|
|
7
|
+
{ id: '1', title: 'RedwoodJS Logo Shirt', bids: [{ amount: 20 }] },
|
|
8
|
+
{ id: '2', title: 'RedwoodJS Lapel Pin', bids: [{ amount: 5 }] },
|
|
9
|
+
{ id: '3', title: 'RedwoodJS Beanie', bids: [{ amount: 15 }] },
|
|
10
|
+
{ id: '4', title: 'RedwoodJS Dad Hat', bids: [{ amount: 20 }] },
|
|
11
|
+
{ id: '5', title: 'RedwoodJS Skater Hat', bids: [{ amount: 20 }] },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* To test this live query, run the following in the GraphQL Playground:
|
|
16
|
+
*
|
|
17
|
+
* query GetCurrentAuctionBids @live {
|
|
18
|
+
* auction(id: "1") {
|
|
19
|
+
* bids {
|
|
20
|
+
* amount
|
|
21
|
+
* }
|
|
22
|
+
* highestBid {
|
|
23
|
+
* amount
|
|
24
|
+
* }
|
|
25
|
+
* id
|
|
26
|
+
* title
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* And then make a bid with the following mutation:
|
|
31
|
+
*
|
|
32
|
+
* mutation MakeBid {
|
|
33
|
+
* bid(input: {auctionId: "1", amount: 10}) {
|
|
34
|
+
* amount
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export const auction = async ({ id }) => {
|
|
39
|
+
const foundAuction = auctions.find((a) => a.id === id)
|
|
40
|
+
logger.debug({ id, auction: foundAuction }, 'auction')
|
|
41
|
+
return foundAuction
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const bid = async (
|
|
45
|
+
{ input },
|
|
46
|
+
{ context }: { context: { liveQueryStore: LiveQueryStorageMechanism } }
|
|
47
|
+
) => {
|
|
48
|
+
const { auctionId, amount } = input
|
|
49
|
+
|
|
50
|
+
const index = auctions.findIndex((a) => a.id === auctionId)
|
|
51
|
+
|
|
52
|
+
const bid = { amount }
|
|
53
|
+
|
|
54
|
+
auctions[index].bids.push(bid)
|
|
55
|
+
logger.debug({ auctionId, bid }, 'Added bid to auction')
|
|
56
|
+
|
|
57
|
+
const key = `Auction:${auctionId}`
|
|
58
|
+
context.liveQueryStore.invalidate(key)
|
|
59
|
+
|
|
60
|
+
logger.debug({ key }, 'Invalidated auction key in liveQueryStore')
|
|
61
|
+
|
|
62
|
+
return bid
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const Auction = {
|
|
66
|
+
highestBid: (obj, { root }) => {
|
|
67
|
+
const [max] = root.bids.sort((a, b) => b.amount - a.amount)
|
|
68
|
+
|
|
69
|
+
logger.debug({ obj, root }, 'highestBid')
|
|
70
|
+
|
|
71
|
+
return max
|
|
72
|
+
},
|
|
73
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RedwoodRealtimeOptions } from '@cedarjs/realtime'
|
|
2
|
+
|
|
3
|
+
import subscriptions from 'src/subscriptions/**/*.{js,ts}'
|
|
4
|
+
|
|
5
|
+
// if using a Redis store
|
|
6
|
+
// import { Redis } from 'ioredis'
|
|
7
|
+
// const publishClient = new Redis()
|
|
8
|
+
// const subscribeClient = new Redis()
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configure RedwoodJS Realtime
|
|
12
|
+
*
|
|
13
|
+
* See https://redwoodjs.com/docs/realtime
|
|
14
|
+
*
|
|
15
|
+
* Realtime supports Live Queries and Subscriptions over GraphQL SSE.
|
|
16
|
+
*
|
|
17
|
+
* Live Queries are GraphQL queries that are automatically re-run when the data they depend on changes.
|
|
18
|
+
*
|
|
19
|
+
* Subscriptions are GraphQL queries that are run when a client subscribes to a channel.
|
|
20
|
+
*
|
|
21
|
+
* Redwood Realtime
|
|
22
|
+
* - uses a publish/subscribe model to broadcast data to clients.
|
|
23
|
+
* - uses a store to persist Live Query and Subscription data.
|
|
24
|
+
* - and enable defer and stream directives to improve latency
|
|
25
|
+
* for clients by sending data the most important data as soon as it's ready.
|
|
26
|
+
*
|
|
27
|
+
* Redwood Realtime supports in-memory and Redis stores:
|
|
28
|
+
* - In-memory stores are useful for development and testing.
|
|
29
|
+
* - Redis stores are useful for production.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export const realtime: RedwoodRealtimeOptions = {
|
|
33
|
+
subscriptions: {
|
|
34
|
+
subscriptions,
|
|
35
|
+
store: 'in-memory',
|
|
36
|
+
// if using a Redis store
|
|
37
|
+
// store: { redis: { publishClient, subscribeClient } },
|
|
38
|
+
},
|
|
39
|
+
liveQueries: {
|
|
40
|
+
store: 'in-memory',
|
|
41
|
+
// if using a Redis store
|
|
42
|
+
// store: { redis: { publishClient, subscribeClient } },
|
|
43
|
+
},
|
|
44
|
+
// To enable defer and streaming, set to true.
|
|
45
|
+
// enableDeferStream: true,
|
|
46
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Repeater } from '@cedarjs/realtime'
|
|
2
|
+
|
|
3
|
+
import { logger } from 'src/lib/logger'
|
|
4
|
+
|
|
5
|
+
export const alphabet = async () => {
|
|
6
|
+
return new Repeater<string>(async (push, stop) => {
|
|
7
|
+
const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
|
|
8
|
+
|
|
9
|
+
const publish = () => {
|
|
10
|
+
const letter = letters.shift()
|
|
11
|
+
|
|
12
|
+
if (letter) {
|
|
13
|
+
logger.debug({ letter }, 'publishing letter...')
|
|
14
|
+
push(letter)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (letters.length === 0) {
|
|
18
|
+
stop()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const interval = setInterval(publish, 1000)
|
|
23
|
+
|
|
24
|
+
stop.then(() => {
|
|
25
|
+
logger.debug('cancel')
|
|
26
|
+
clearInterval(interval)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
publish()
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import gql from 'graphql-tag'
|
|
2
|
+
|
|
3
|
+
import { Repeater } from '@cedarjs/realtime'
|
|
4
|
+
|
|
5
|
+
import { logger } from 'src/lib/logger'
|
|
6
|
+
|
|
7
|
+
export const schema = gql`
|
|
8
|
+
type Subscription {
|
|
9
|
+
countdown(from: Int!, interval: Int!): Int! @requireAuth
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* To test this Countdown subscription, run the following in the GraphQL Playground:
|
|
15
|
+
*
|
|
16
|
+
* subscription CountdownFromInterval {
|
|
17
|
+
* countdown(from: 100, interval: 10)
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
const countdown = {
|
|
21
|
+
countdown: {
|
|
22
|
+
subscribe: (
|
|
23
|
+
_,
|
|
24
|
+
{
|
|
25
|
+
from = 100,
|
|
26
|
+
interval = 10,
|
|
27
|
+
}: {
|
|
28
|
+
from: number
|
|
29
|
+
interval: number
|
|
30
|
+
}
|
|
31
|
+
) =>
|
|
32
|
+
new Repeater((push, stop) => {
|
|
33
|
+
function decrement() {
|
|
34
|
+
from -= interval
|
|
35
|
+
|
|
36
|
+
if (from < 0) {
|
|
37
|
+
logger.debug({ from }, 'stopping as countdown is less than 0')
|
|
38
|
+
stop()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
logger.debug({ from }, 'pushing countdown value ...')
|
|
42
|
+
push(from)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
decrement()
|
|
46
|
+
|
|
47
|
+
const delay = setInterval(decrement, 500)
|
|
48
|
+
|
|
49
|
+
stop.then(() => {
|
|
50
|
+
clearInterval(delay)
|
|
51
|
+
logger.debug('stopping countdown')
|
|
52
|
+
})
|
|
53
|
+
}),
|
|
54
|
+
resolve: (payload: number) => payload,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default countdown
|
package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import gql from 'graphql-tag'
|
|
2
|
+
|
|
3
|
+
import type { PubSub } from '@cedarjs/realtime'
|
|
4
|
+
|
|
5
|
+
import { logger } from 'src/lib/logger'
|
|
6
|
+
|
|
7
|
+
export const schema = gql`
|
|
8
|
+
type Subscription {
|
|
9
|
+
newMessage(roomId: ID!): Message! @requireAuth
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
export type NewMessageChannel = {
|
|
13
|
+
newMessage: [roomId: string, payload: { from: string; body: string }]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type NewMessageChannelType = PubSub<NewMessageChannel>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* To test this NewMessage subscription, run the following in one GraphQL Playground to subscribe:
|
|
20
|
+
*
|
|
21
|
+
* subscription ListenForNewMessagesInRoom {
|
|
22
|
+
* newMessage(roomId: "1") {
|
|
23
|
+
* body
|
|
24
|
+
* from
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
*
|
|
29
|
+
* And run the following in another GraphQL Playground to publish and send a message to the room:
|
|
30
|
+
*
|
|
31
|
+
* mutation SendMessageToRoom {
|
|
32
|
+
* sendMessage(input: {roomId: "1", from: "hello", body: "bob"}) {
|
|
33
|
+
* body
|
|
34
|
+
* from
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
const newMessage = {
|
|
39
|
+
newMessage: {
|
|
40
|
+
subscribe: (
|
|
41
|
+
_,
|
|
42
|
+
{ roomId },
|
|
43
|
+
{ pubSub }: { pubSub: NewMessageChannelType }
|
|
44
|
+
) => {
|
|
45
|
+
logger.debug({ roomId }, 'newMessage subscription')
|
|
46
|
+
|
|
47
|
+
return pubSub.subscribe('newMessage', roomId)
|
|
48
|
+
},
|
|
49
|
+
resolve: (payload) => {
|
|
50
|
+
logger.debug({ payload }, 'newMessage subscription resolve')
|
|
51
|
+
|
|
52
|
+
return payload
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default newMessage
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const schema = gql`
|
|
2
|
+
type Message {
|
|
3
|
+
from: String
|
|
4
|
+
body: String
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type Query {
|
|
8
|
+
room(id: ID!): [Message!]! @skipAuth
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
input SendMessageInput {
|
|
12
|
+
roomId: ID!
|
|
13
|
+
from: String!
|
|
14
|
+
body: String!
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Mutation {
|
|
18
|
+
sendMessage(input: SendMessageInput!): Message! @skipAuth
|
|
19
|
+
}
|
|
20
|
+
`
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SendMessageInput } from 'types/graphql'
|
|
2
|
+
|
|
3
|
+
import type { NewMessageChannelType } from 'src/subscriptions/newMessage/newMessage'
|
|
4
|
+
|
|
5
|
+
import { logger } from 'src/lib/logger'
|
|
6
|
+
|
|
7
|
+
export const room = ({ id }) => [id]
|
|
8
|
+
|
|
9
|
+
export const sendMessage = async (
|
|
10
|
+
{ input }: { input: SendMessageInput },
|
|
11
|
+
{ context }: { context: { pubSub: NewMessageChannelType } }
|
|
12
|
+
) => {
|
|
13
|
+
logger.debug({ input }, 'sending message ....')
|
|
14
|
+
|
|
15
|
+
const { roomId, from, body } = input
|
|
16
|
+
|
|
17
|
+
context.pubSub.publish('newMessage', roomId, { from, body })
|
|
18
|
+
|
|
19
|
+
return input
|
|
20
|
+
}
|