@beezer-pet/instant-cli 0.0.0-stage → 1.0.67-beezer.3
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/.turbo/turbo-build.log +4 -0
- package/LICENSE.md +202 -0
- package/README.md +34 -2
- package/__tests__/appCommands.test.ts +228 -0
- package/__tests__/args.test.ts +358 -0
- package/__tests__/auth.test.ts +128 -0
- package/__tests__/authClientAddApple.test.ts +376 -0
- package/__tests__/authClientAddClerk.test.ts +222 -0
- package/__tests__/authClientAddGithub.test.ts +245 -0
- package/__tests__/authClientAddGoogle.test.ts +373 -0
- package/__tests__/authClientAddLinkedin.test.ts +262 -0
- package/__tests__/authClientList.test.ts +90 -0
- package/__tests__/authClientUpdate.test.ts +583 -0
- package/__tests__/authOriginManagement.test.ts +308 -0
- package/__tests__/backupDownload.test.ts +206 -0
- package/__tests__/backups.test.ts +221 -0
- package/__tests__/config.test.ts +57 -0
- package/__tests__/e2e/cli.e2e.test.ts +1267 -0
- package/__tests__/e2e/helpers.ts +177 -0
- package/__tests__/effectHelpers.ts +45 -0
- package/__tests__/mergeSchema.test.ts +197 -0
- package/__tests__/multiSelect.test.ts +236 -0
- package/__tests__/oauthMock.ts +76 -0
- package/__tests__/promptOk.test.ts +44 -0
- package/__tests__/redirectUriPrompt.test.ts +40 -0
- package/__tests__/sdkInstallSpec.test.ts +36 -0
- package/__tests__/select.test.ts +224 -0
- package/__tests__/webhooks.test.ts +728 -0
- package/bin/index.js +3 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +103 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/commands/app/delete.d.ts +7 -0
- package/dist/commands/app/delete.d.ts.map +1 -0
- package/dist/commands/app/delete.js +57 -0
- package/dist/commands/app/delete.js.map +1 -0
- package/dist/commands/app/list.d.ts +6 -0
- package/dist/commands/app/list.d.ts.map +1 -0
- package/dist/commands/app/list.js +29 -0
- package/dist/commands/app/list.js.map +1 -0
- package/dist/commands/auth/client/add.d.ts +9 -0
- package/dist/commands/auth/client/add.d.ts.map +1 -0
- package/dist/commands/auth/client/add.js +409 -0
- package/dist/commands/auth/client/add.js.map +1 -0
- package/dist/commands/auth/client/delete.d.ts +11 -0
- package/dist/commands/auth/client/delete.d.ts.map +1 -0
- package/dist/commands/auth/client/delete.js +48 -0
- package/dist/commands/auth/client/delete.js.map +1 -0
- package/dist/commands/auth/client/list.d.ts +6 -0
- package/dist/commands/auth/client/list.d.ts.map +1 -0
- package/dist/commands/auth/client/list.js +38 -0
- package/dist/commands/auth/client/list.js.map +1 -0
- package/dist/commands/auth/client/shared.d.ts +70 -0
- package/dist/commands/auth/client/shared.d.ts.map +1 -0
- package/dist/commands/auth/client/shared.js +140 -0
- package/dist/commands/auth/client/shared.js.map +1 -0
- package/dist/commands/auth/client/update.d.ts +8 -0
- package/dist/commands/auth/client/update.d.ts.map +1 -0
- package/dist/commands/auth/client/update.js +445 -0
- package/dist/commands/auth/client/update.js.map +1 -0
- package/dist/commands/auth/email/pull.d.ts +24 -0
- package/dist/commands/auth/email/pull.d.ts.map +1 -0
- package/dist/commands/auth/email/pull.js +100 -0
- package/dist/commands/auth/email/pull.js.map +1 -0
- package/dist/commands/auth/email/push.d.ts +8 -0
- package/dist/commands/auth/email/push.d.ts.map +1 -0
- package/dist/commands/auth/email/push.js +58 -0
- package/dist/commands/auth/email/push.js.map +1 -0
- package/dist/commands/auth/email/resend.d.ts +3 -0
- package/dist/commands/auth/email/resend.d.ts.map +1 -0
- package/dist/commands/auth/email/resend.js +7 -0
- package/dist/commands/auth/email/resend.js.map +1 -0
- package/dist/commands/auth/email/reset.d.ts +5 -0
- package/dist/commands/auth/email/reset.d.ts.map +1 -0
- package/dist/commands/auth/email/reset.js +25 -0
- package/dist/commands/auth/email/reset.js.map +1 -0
- package/dist/commands/auth/email/status.d.ts +57 -0
- package/dist/commands/auth/email/status.d.ts.map +1 -0
- package/dist/commands/auth/email/status.js +96 -0
- package/dist/commands/auth/email/status.js.map +1 -0
- package/dist/commands/auth/email/verify.d.ts +5 -0
- package/dist/commands/auth/email/verify.d.ts.map +1 -0
- package/dist/commands/auth/email/verify.js +12 -0
- package/dist/commands/auth/email/verify.js.map +1 -0
- package/dist/commands/auth/origin/add.d.ts +12 -0
- package/dist/commands/auth/origin/add.d.ts.map +1 -0
- package/dist/commands/auth/origin/add.js +153 -0
- package/dist/commands/auth/origin/add.js.map +1 -0
- package/dist/commands/auth/origin/delete.d.ts +8 -0
- package/dist/commands/auth/origin/delete.d.ts.map +1 -0
- package/dist/commands/auth/origin/delete.js +38 -0
- package/dist/commands/auth/origin/delete.js.map +1 -0
- package/dist/commands/auth/origin/list.d.ts +9 -0
- package/dist/commands/auth/origin/list.d.ts.map +1 -0
- package/dist/commands/auth/origin/list.js +52 -0
- package/dist/commands/auth/origin/list.js.map +1 -0
- package/dist/commands/backup/download.d.ts +10 -0
- package/dist/commands/backup/download.d.ts.map +1 -0
- package/dist/commands/backup/download.js +174 -0
- package/dist/commands/backup/download.js.map +1 -0
- package/dist/commands/backup/list.d.ts +11 -0
- package/dist/commands/backup/list.d.ts.map +1 -0
- package/dist/commands/backup/list.js +74 -0
- package/dist/commands/backup/list.js.map +1 -0
- package/dist/commands/claim.d.ts +6 -0
- package/dist/commands/claim.d.ts.map +1 -0
- package/dist/commands/claim.js +22 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/explorer.d.ts +6 -0
- package/dist/commands/explorer.d.ts.map +1 -0
- package/dist/commands/explorer.js +13 -0
- package/dist/commands/explorer.js.map +1 -0
- package/dist/commands/info.d.ts +9 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +41 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +41 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/initWithoutFiles.d.ts +6 -0
- package/dist/commands/initWithoutFiles.d.ts.map +1 -0
- package/dist/commands/initWithoutFiles.js +64 -0
- package/dist/commands/initWithoutFiles.js.map +1 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +44 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +14 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/pull.d.ts +5 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +15 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +6 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +20 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/query.d.ts +7 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +52 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/webhooks/add.d.ts +9 -0
- package/dist/commands/webhooks/add.d.ts.map +1 -0
- package/dist/commands/webhooks/add.js +75 -0
- package/dist/commands/webhooks/add.js.map +1 -0
- package/dist/commands/webhooks/delete.d.ts +6 -0
- package/dist/commands/webhooks/delete.d.ts.map +1 -0
- package/dist/commands/webhooks/delete.js +17 -0
- package/dist/commands/webhooks/delete.js.map +1 -0
- package/dist/commands/webhooks/disable.d.ts +7 -0
- package/dist/commands/webhooks/disable.d.ts.map +1 -0
- package/dist/commands/webhooks/disable.js +18 -0
- package/dist/commands/webhooks/disable.js.map +1 -0
- package/dist/commands/webhooks/enable.d.ts +6 -0
- package/dist/commands/webhooks/enable.d.ts.map +1 -0
- package/dist/commands/webhooks/enable.js +18 -0
- package/dist/commands/webhooks/enable.js.map +1 -0
- package/dist/commands/webhooks/events/list.d.ts +7 -0
- package/dist/commands/webhooks/events/list.d.ts.map +1 -0
- package/dist/commands/webhooks/events/list.js +31 -0
- package/dist/commands/webhooks/events/list.js.map +1 -0
- package/dist/commands/webhooks/events/payload.d.ts +8 -0
- package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
- package/dist/commands/webhooks/events/payload.js +39 -0
- package/dist/commands/webhooks/events/payload.js.map +1 -0
- package/dist/commands/webhooks/events/resend.d.ts +8 -0
- package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
- package/dist/commands/webhooks/events/resend.js +43 -0
- package/dist/commands/webhooks/events/resend.js.map +1 -0
- package/dist/commands/webhooks/list.d.ts +8 -0
- package/dist/commands/webhooks/list.d.ts.map +1 -0
- package/dist/commands/webhooks/list.js +29 -0
- package/dist/commands/webhooks/list.js.map +1 -0
- package/dist/commands/webhooks/shared.d.ts +40 -0
- package/dist/commands/webhooks/shared.d.ts.map +1 -0
- package/dist/commands/webhooks/shared.js +248 -0
- package/dist/commands/webhooks/shared.js.map +1 -0
- package/dist/commands/webhooks/update.d.ts +10 -0
- package/dist/commands/webhooks/update.d.ts.map +1 -0
- package/dist/commands/webhooks/update.js +189 -0
- package/dist/commands/webhooks/update.js.map +1 -0
- package/dist/context/authToken.d.ts +29 -0
- package/dist/context/authToken.d.ts.map +1 -0
- package/dist/context/authToken.js +73 -0
- package/dist/context/authToken.js.map +1 -0
- package/dist/context/currentApp.d.ts +38 -0
- package/dist/context/currentApp.d.ts.map +1 -0
- package/dist/context/currentApp.js +222 -0
- package/dist/context/currentApp.js.map +1 -0
- package/dist/context/globalOpts.d.ts +11 -0
- package/dist/context/globalOpts.d.ts.map +1 -0
- package/dist/context/globalOpts.js +13 -0
- package/dist/context/globalOpts.js.map +1 -0
- package/dist/context/platformApi.d.ts +19 -0
- package/dist/context/platformApi.d.ts.map +1 -0
- package/dist/context/platformApi.js +24 -0
- package/dist/context/platformApi.js.map +1 -0
- package/dist/context/projectInfo.d.ts +30 -0
- package/dist/context/projectInfo.d.ts.map +1 -0
- package/dist/context/projectInfo.js +153 -0
- package/dist/context/projectInfo.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +714 -0
- package/dist/index.js.map +1 -0
- package/dist/layer.d.ts +25 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +119 -0
- package/dist/layer.js.map +1 -0
- package/dist/lib/args.d.ts +212 -0
- package/dist/lib/args.d.ts.map +1 -0
- package/dist/lib/args.js +313 -0
- package/dist/lib/args.js.map +1 -0
- package/dist/lib/backupDownload.d.ts +21 -0
- package/dist/lib/backupDownload.d.ts.map +1 -0
- package/dist/lib/backupDownload.js +151 -0
- package/dist/lib/backupDownload.js.map +1 -0
- package/dist/lib/backups.d.ts +12 -0
- package/dist/lib/backups.d.ts.map +1 -0
- package/dist/lib/backups.js +26 -0
- package/dist/lib/backups.js.map +1 -0
- package/dist/lib/config.d.ts +6 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +39 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/createApp.d.ts +12 -0
- package/dist/lib/createApp.d.ts.map +1 -0
- package/dist/lib/createApp.js +15 -0
- package/dist/lib/createApp.js.map +1 -0
- package/dist/lib/email.d.ts +47 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/email.js +71 -0
- package/dist/lib/email.js.map +1 -0
- package/dist/lib/handleEnv.d.ts +7 -0
- package/dist/lib/handleEnv.d.ts.map +1 -0
- package/dist/lib/handleEnv.js +99 -0
- package/dist/lib/handleEnv.js.map +1 -0
- package/dist/lib/http.d.ts +30 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +55 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/login.d.ts +12 -0
- package/dist/lib/login.d.ts.map +1 -0
- package/dist/lib/login.js +38 -0
- package/dist/lib/login.js.map +1 -0
- package/dist/lib/oauth.d.ts +306 -0
- package/dist/lib/oauth.d.ts.map +1 -0
- package/dist/lib/oauth.js +195 -0
- package/dist/lib/oauth.js.map +1 -0
- package/dist/lib/platformApi.d.ts +5 -0
- package/dist/lib/platformApi.d.ts.map +1 -0
- package/dist/lib/platformApi.js +11 -0
- package/dist/lib/platformApi.js.map +1 -0
- package/dist/lib/pullPerms.d.ts +7 -0
- package/dist/lib/pullPerms.d.ts.map +1 -0
- package/dist/lib/pullPerms.js +41 -0
- package/dist/lib/pullPerms.js.map +1 -0
- package/dist/lib/pullSchema.d.ts +12 -0
- package/dist/lib/pullSchema.d.ts.map +1 -0
- package/dist/lib/pullSchema.js +62 -0
- package/dist/lib/pullSchema.js.map +1 -0
- package/dist/lib/pushPerms.d.ts +13 -0
- package/dist/lib/pushPerms.d.ts.map +1 -0
- package/dist/lib/pushPerms.js +54 -0
- package/dist/lib/pushPerms.js.map +1 -0
- package/dist/lib/pushSchema.d.ts +53 -0
- package/dist/lib/pushSchema.d.ts.map +1 -0
- package/dist/lib/pushSchema.js +165 -0
- package/dist/lib/pushSchema.js.map +1 -0
- package/dist/lib/ui.d.ts +18 -0
- package/dist/lib/ui.d.ts.map +1 -0
- package/dist/lib/ui.js +32 -0
- package/dist/lib/ui.js.map +1 -0
- package/dist/lib/webhooks.d.ts +27 -0
- package/dist/lib/webhooks.d.ts.map +1 -0
- package/dist/lib/webhooks.js +95 -0
- package/dist/lib/webhooks.js.map +1 -0
- package/dist/logging.d.ts +5 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +25 -0
- package/dist/logging.js.map +1 -0
- package/dist/old.d.ts +17 -0
- package/dist/old.d.ts.map +1 -0
- package/dist/old.js +410 -0
- package/dist/old.js.map +1 -0
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +3 -0
- package/dist/program.js.map +1 -0
- package/dist/renderSchemaPlan.d.ts +19 -0
- package/dist/renderSchemaPlan.d.ts.map +1 -0
- package/dist/renderSchemaPlan.js +220 -0
- package/dist/renderSchemaPlan.js.map +1 -0
- package/dist/ui/index.d.ts +292 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1296 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/lib.d.ts +124 -0
- package/dist/ui/lib.d.ts.map +1 -0
- package/dist/ui/lib.js +333 -0
- package/dist/ui/lib.js.map +1 -0
- package/dist/util/findConfigCandidates.d.ts +13 -0
- package/dist/util/findConfigCandidates.d.ts.map +1 -0
- package/dist/util/findConfigCandidates.js +211 -0
- package/dist/util/findConfigCandidates.js.map +1 -0
- package/dist/util/fs.d.ts +4 -0
- package/dist/util/fs.d.ts.map +1 -0
- package/dist/util/fs.js +22 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/getAppName.d.ts +5 -0
- package/dist/util/getAppName.d.ts.map +1 -0
- package/dist/util/getAppName.js +14 -0
- package/dist/util/getAppName.js.map +1 -0
- package/dist/util/instantConfig.d.ts +9 -0
- package/dist/util/instantConfig.d.ts.map +1 -0
- package/dist/util/instantConfig.js +13 -0
- package/dist/util/instantConfig.js.map +1 -0
- package/dist/util/isHeadlessEnvironment.d.ts +4 -0
- package/dist/util/isHeadlessEnvironment.d.ts.map +1 -0
- package/dist/util/isHeadlessEnvironment.js +11 -0
- package/dist/util/isHeadlessEnvironment.js.map +1 -0
- package/dist/util/loadConfig.d.ts +3 -0
- package/dist/util/loadConfig.d.ts.map +1 -0
- package/dist/util/loadConfig.js +72 -0
- package/dist/util/loadConfig.js.map +1 -0
- package/dist/util/loadEnv.d.ts +2 -0
- package/dist/util/loadEnv.d.ts.map +1 -0
- package/dist/util/loadEnv.js +10 -0
- package/dist/util/loadEnv.js.map +1 -0
- package/dist/util/mergeSchema.d.ts +10 -0
- package/dist/util/mergeSchema.d.ts.map +1 -0
- package/dist/util/mergeSchema.js +338 -0
- package/dist/util/mergeSchema.js.map +1 -0
- package/dist/util/projectDir.d.ts +7 -0
- package/dist/util/projectDir.d.ts.map +1 -0
- package/dist/util/projectDir.js +43 -0
- package/dist/util/projectDir.js.map +1 -0
- package/dist/util/renamePrompt.d.ts +15 -0
- package/dist/util/renamePrompt.d.ts.map +1 -0
- package/dist/util/renamePrompt.js +57 -0
- package/dist/util/renamePrompt.js.map +1 -0
- package/dist/util/sdkInstallSpec.d.ts +13 -0
- package/dist/util/sdkInstallSpec.d.ts.map +1 -0
- package/dist/util/sdkInstallSpec.js +37 -0
- package/dist/util/sdkInstallSpec.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +91 -3
- package/src/auth/index.ts +125 -0
- package/src/commands/app/delete.ts +82 -0
- package/src/commands/app/list.ts +44 -0
- package/src/commands/auth/client/add.ts +744 -0
- package/src/commands/auth/client/delete.ts +60 -0
- package/src/commands/auth/client/list.ts +60 -0
- package/src/commands/auth/client/shared.ts +190 -0
- package/src/commands/auth/client/update.ts +830 -0
- package/src/commands/auth/email/pull.ts +143 -0
- package/src/commands/auth/email/push.ts +94 -0
- package/src/commands/auth/email/resend.ts +8 -0
- package/src/commands/auth/email/reset.ts +37 -0
- package/src/commands/auth/email/status.ts +154 -0
- package/src/commands/auth/email/verify.ts +20 -0
- package/src/commands/auth/origin/add.ts +237 -0
- package/src/commands/auth/origin/delete.ts +50 -0
- package/src/commands/auth/origin/list.ts +66 -0
- package/src/commands/backup/download.ts +231 -0
- package/src/commands/backup/list.ts +94 -0
- package/src/commands/claim.ts +31 -0
- package/src/commands/explorer.ts +21 -0
- package/src/commands/info.ts +57 -0
- package/src/commands/init.ts +60 -0
- package/src/commands/initWithoutFiles.ts +107 -0
- package/src/commands/login.ts +62 -0
- package/src/commands/logout.ts +22 -0
- package/src/commands/pull.ts +22 -0
- package/src/commands/push.ts +25 -0
- package/src/commands/query.ts +61 -0
- package/src/commands/webhooks/add.ts +111 -0
- package/src/commands/webhooks/delete.ts +23 -0
- package/src/commands/webhooks/disable.ts +24 -0
- package/src/commands/webhooks/enable.ts +24 -0
- package/src/commands/webhooks/events/list.ts +38 -0
- package/src/commands/webhooks/events/payload.ts +56 -0
- package/src/commands/webhooks/events/resend.ts +66 -0
- package/src/commands/webhooks/list.ts +41 -0
- package/src/commands/webhooks/shared.ts +339 -0
- package/src/commands/webhooks/update.ts +276 -0
- package/src/context/authToken.ts +134 -0
- package/src/context/currentApp.ts +301 -0
- package/src/context/globalOpts.ts +22 -0
- package/src/context/platformApi.ts +35 -0
- package/src/context/projectInfo.ts +219 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +1212 -0
- package/src/layer.ts +211 -0
- package/src/lib/args.ts +453 -0
- package/src/lib/backupDownload.ts +188 -0
- package/src/lib/backups.ts +33 -0
- package/src/lib/config.ts +73 -0
- package/src/lib/createApp.ts +28 -0
- package/src/lib/email.ts +93 -0
- package/src/lib/handleEnv.ts +122 -0
- package/src/lib/http.ts +128 -0
- package/src/lib/login.ts +48 -0
- package/src/lib/oauth.ts +310 -0
- package/src/lib/platformApi.ts +11 -0
- package/src/lib/pullPerms.ts +50 -0
- package/src/lib/pullSchema.ts +95 -0
- package/src/lib/pushPerms.ts +80 -0
- package/src/lib/pushSchema.ts +248 -0
- package/src/lib/ui.ts +48 -0
- package/src/lib/webhooks.ts +118 -0
- package/src/logging.ts +41 -0
- package/src/old.js +487 -0
- package/src/program.ts +3 -0
- package/src/renderSchemaPlan.ts +324 -0
- package/src/ui/index.ts +1615 -0
- package/src/ui/lib.ts +424 -0
- package/src/util/findConfigCandidates.ts +262 -0
- package/src/util/fs.ts +26 -0
- package/src/util/getAppName.ts +14 -0
- package/src/util/instantConfig.ts +21 -0
- package/src/util/isHeadlessEnvironment.ts +15 -0
- package/src/util/loadConfig.ts +93 -0
- package/src/util/loadEnv.ts +11 -0
- package/src/util/mergeSchema.ts +374 -0
- package/src/util/projectDir.ts +54 -0
- package/src/util/renamePrompt.ts +79 -0
- package/src/util/sdkInstallSpec.ts +45 -0
- package/src/version.js +3 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +23 -0
- package/vitest.config.ts +22 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { InstantHttpAuthed } from '../lib/http.ts';
|
|
3
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
|
+
import { HttpClientResponse } from '@effect/platform';
|
|
5
|
+
import { DashAppResponse } from '../commands/info.ts';
|
|
6
|
+
|
|
7
|
+
export const getAppName = Effect.gen(function* () {
|
|
8
|
+
const authedHttp = yield* InstantHttpAuthed;
|
|
9
|
+
const { appId } = yield* CurrentApp;
|
|
10
|
+
const appInfo = yield* authedHttp
|
|
11
|
+
.get(`/dash/apps/${appId}`)
|
|
12
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(DashAppResponse)));
|
|
13
|
+
return appInfo.app.title;
|
|
14
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { loadConfig } from './loadConfig.ts';
|
|
2
|
+
|
|
3
|
+
export type InstantConfig = {
|
|
4
|
+
apiURI?: string;
|
|
5
|
+
dashURI?: string;
|
|
6
|
+
apps?: Record<string, { id: string }>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export async function readInstantConfigFile() {
|
|
10
|
+
return (
|
|
11
|
+
await loadConfig<InstantConfig>({
|
|
12
|
+
sources: [
|
|
13
|
+
{
|
|
14
|
+
files: 'instant.config',
|
|
15
|
+
extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json'],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
merge: false,
|
|
19
|
+
})
|
|
20
|
+
).config;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function isHeadlessEnvironment(opts?: { headless?: boolean }) {
|
|
2
|
+
const noBrowserMode = Boolean(
|
|
3
|
+
process.env.INSTANT_CLI_NO_BROWSER || process.env.CI || opts?.headless,
|
|
4
|
+
);
|
|
5
|
+
|
|
6
|
+
// Check for common headless environment indicators
|
|
7
|
+
return (
|
|
8
|
+
noBrowserMode ||
|
|
9
|
+
process.env.TERM === 'dumb' ||
|
|
10
|
+
process.env.SSH_CONNECTION !== undefined ||
|
|
11
|
+
process.env.SSH_CLIENT !== undefined ||
|
|
12
|
+
(!process.env.DISPLAY && process.platform === 'linux') ||
|
|
13
|
+
process.env.WSL_DISTRO_NAME !== undefined
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { loadConfig as _loadConfig } from 'unconfig';
|
|
2
|
+
import type {
|
|
3
|
+
LoadConfigOptions,
|
|
4
|
+
LoadConfigResult,
|
|
5
|
+
LoadConfigSource,
|
|
6
|
+
} from 'unconfig';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { findProjectDir } from './projectDir.ts';
|
|
10
|
+
|
|
11
|
+
type Arrayable<T> = T | T[];
|
|
12
|
+
|
|
13
|
+
const toArray = <T>(value: Arrayable<T>): T[] =>
|
|
14
|
+
Array.isArray(value) ? value : [value];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve @instantdb packages from the CLI's own dependencies for
|
|
18
|
+
* projects without node_modules. All @instantdb packages re-export
|
|
19
|
+
* schema types from core, so a single core alias covers them all.
|
|
20
|
+
*/
|
|
21
|
+
function getInstantAliases(): Record<string, string> | null {
|
|
22
|
+
try {
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
24
|
+
const corePackageJson = require.resolve('@instantdb/core/package.json');
|
|
25
|
+
const coreDir = path.dirname(corePackageJson);
|
|
26
|
+
return {
|
|
27
|
+
'@instantdb/core': coreDir,
|
|
28
|
+
'@instantdb/react': coreDir,
|
|
29
|
+
'@instantdb/react-native': coreDir,
|
|
30
|
+
'@instantdb/svelte': coreDir,
|
|
31
|
+
'@instantdb/vue': coreDir,
|
|
32
|
+
'@instantdb/admin': coreDir,
|
|
33
|
+
};
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function withAliases<T>(
|
|
40
|
+
opts: LoadConfigOptions<T>,
|
|
41
|
+
alias: Record<string, string>,
|
|
42
|
+
): LoadConfigOptions<T> {
|
|
43
|
+
return {
|
|
44
|
+
...opts,
|
|
45
|
+
sources: toArray(opts.sources).map((source): LoadConfigSource<T> => {
|
|
46
|
+
if (source.parser === 'json' || typeof source.parser === 'function') {
|
|
47
|
+
return source;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...source,
|
|
52
|
+
parser: async (filepath) => {
|
|
53
|
+
const localRequire = createRequire(import.meta.url);
|
|
54
|
+
const unconfigRequire = createRequire(
|
|
55
|
+
localRequire.resolve('unconfig/package.json'),
|
|
56
|
+
);
|
|
57
|
+
const { createJiti } = unconfigRequire('jiti');
|
|
58
|
+
const jiti = createJiti(import.meta.url, {
|
|
59
|
+
fsCache: false,
|
|
60
|
+
moduleCache: false,
|
|
61
|
+
interopDefault: true,
|
|
62
|
+
alias,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return jiti.import(filepath, { default: true });
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function loadConfig<T>(
|
|
73
|
+
opts: LoadConfigOptions<T>,
|
|
74
|
+
): Promise<LoadConfigResult<T>> {
|
|
75
|
+
const projectInfo = await findProjectDir();
|
|
76
|
+
const needsAliases =
|
|
77
|
+
projectInfo?.type === 'deno' || projectInfo?.type === 'python';
|
|
78
|
+
|
|
79
|
+
let res;
|
|
80
|
+
if (needsAliases) {
|
|
81
|
+
const alias = getInstantAliases();
|
|
82
|
+
res = await _loadConfig(alias ? withAliases(opts, alias) : opts);
|
|
83
|
+
} else {
|
|
84
|
+
res = await _loadConfig(opts);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Unconfig seems to add an __esModule property to the config object
|
|
88
|
+
// Removing it.
|
|
89
|
+
if (typeof res.config === 'object' && '__esModule' in res.config!) {
|
|
90
|
+
delete res.config.__esModule;
|
|
91
|
+
}
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import dotenvFlow from 'dotenv-flow';
|
|
2
|
+
|
|
3
|
+
export const loadEnv = () => {
|
|
4
|
+
const envIndex = process.argv.indexOf('--env');
|
|
5
|
+
const envFile = envIndex !== -1 ? process.argv[envIndex + 1] : undefined;
|
|
6
|
+
|
|
7
|
+
dotenvFlow.config({
|
|
8
|
+
silent: true,
|
|
9
|
+
files: envFile ? [envFile] : undefined,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import * as acorn from 'acorn';
|
|
2
|
+
import tsPlugin from 'acorn-typescript';
|
|
3
|
+
import { Data } from 'effect';
|
|
4
|
+
|
|
5
|
+
export class MergeSchemaError extends Data.TaggedError('MergeSchemaError')<{
|
|
6
|
+
message: string;
|
|
7
|
+
}> {}
|
|
8
|
+
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const node = acorn.Parser.extend(tsPlugin({ dts: false }));
|
|
11
|
+
|
|
12
|
+
// --- Import Handling Helpers ---
|
|
13
|
+
|
|
14
|
+
function collectImports(ast: any) {
|
|
15
|
+
const imports = new Map(); // localName -> { source, importedName, type, importKind }
|
|
16
|
+
|
|
17
|
+
for (const node of ast.body) {
|
|
18
|
+
if (node.type === 'ImportDeclaration') {
|
|
19
|
+
const source = node.source.value;
|
|
20
|
+
const declImportKind = node.importKind;
|
|
21
|
+
|
|
22
|
+
for (const specifier of node.specifiers) {
|
|
23
|
+
let kind = 'value';
|
|
24
|
+
if (declImportKind === 'type' || specifier.importKind === 'type') {
|
|
25
|
+
kind = 'type';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
29
|
+
imports.set(specifier.local.name, {
|
|
30
|
+
source,
|
|
31
|
+
importedName: specifier.imported.name,
|
|
32
|
+
type: 'named',
|
|
33
|
+
importKind: kind,
|
|
34
|
+
});
|
|
35
|
+
} else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
36
|
+
imports.set(specifier.local.name, {
|
|
37
|
+
source,
|
|
38
|
+
type: 'default',
|
|
39
|
+
importKind: kind,
|
|
40
|
+
});
|
|
41
|
+
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
42
|
+
imports.set(specifier.local.name, {
|
|
43
|
+
source,
|
|
44
|
+
type: 'namespace',
|
|
45
|
+
importKind: kind,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return imports;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function collectExistingImports(ast: any) {
|
|
55
|
+
const existing = new Map(); // source -> Set<localName>
|
|
56
|
+
|
|
57
|
+
for (const node of ast.body) {
|
|
58
|
+
if (node.type === 'ImportDeclaration') {
|
|
59
|
+
const source = node.source.value;
|
|
60
|
+
if (!existing.has(source)) existing.set(source, new Set());
|
|
61
|
+
|
|
62
|
+
for (const specifier of node.specifiers) {
|
|
63
|
+
existing.get(source).add(specifier.local.name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return existing;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function findIdentifiers(node: any, set: Set<string> = new Set<string>()) {
|
|
71
|
+
if (!node) return set;
|
|
72
|
+
|
|
73
|
+
// If it's a Type Reference, grab the name
|
|
74
|
+
if (node.type === 'TSTypeReference') {
|
|
75
|
+
if (node.typeName.type === 'Identifier') {
|
|
76
|
+
set.add(node.typeName.name);
|
|
77
|
+
} else if (node.typeName.type === 'TSQualifiedName') {
|
|
78
|
+
// For A.B, we need A
|
|
79
|
+
let left = node.typeName.left;
|
|
80
|
+
while (left.type === 'TSQualifiedName') {
|
|
81
|
+
left = left.left;
|
|
82
|
+
}
|
|
83
|
+
if (left.type === 'Identifier') {
|
|
84
|
+
set.add(left.name);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Recursive walk
|
|
90
|
+
for (const key in node) {
|
|
91
|
+
if (key === 'loc' || key === 'start' || key === 'end') continue;
|
|
92
|
+
if (typeof node[key] === 'object' && node[key] !== null) {
|
|
93
|
+
if (Array.isArray(node[key])) {
|
|
94
|
+
node[key].forEach((child) => findIdentifiers(child, set));
|
|
95
|
+
} else {
|
|
96
|
+
findIdentifiers(node[key], set);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return set;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// --- Schema Traversal Helpers ---
|
|
104
|
+
|
|
105
|
+
function getPropName(prop: any) {
|
|
106
|
+
if (prop.key.type === 'Identifier') return prop.key.name;
|
|
107
|
+
if (prop.key.type === 'Literal') return prop.key.value;
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function analyzeChain(node: any): { typeParams: any; baseCall: any } {
|
|
112
|
+
let curr = node;
|
|
113
|
+
let typeParams = null;
|
|
114
|
+
let baseCall = null;
|
|
115
|
+
|
|
116
|
+
while (curr.type === 'CallExpression') {
|
|
117
|
+
if (curr.typeParameters) {
|
|
118
|
+
typeParams = curr.typeParameters;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (
|
|
122
|
+
curr.callee.type === 'MemberExpression' &&
|
|
123
|
+
curr.callee.object.type === 'Identifier' &&
|
|
124
|
+
curr.callee.object.name === 'i'
|
|
125
|
+
) {
|
|
126
|
+
baseCall = curr;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (curr.callee.type === 'MemberExpression') {
|
|
130
|
+
curr = curr.callee.object;
|
|
131
|
+
} else {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { typeParams, baseCall };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function traverseSchema(
|
|
139
|
+
node: any,
|
|
140
|
+
path: string,
|
|
141
|
+
callback: (node: any, path: string) => void,
|
|
142
|
+
) {
|
|
143
|
+
if (node.type === 'ObjectExpression') {
|
|
144
|
+
for (const prop of node.properties) {
|
|
145
|
+
const name = getPropName(prop);
|
|
146
|
+
if (!name) continue;
|
|
147
|
+
const newPath = path ? `${path}.${name}` : name;
|
|
148
|
+
|
|
149
|
+
if (prop.value.type === 'ObjectExpression') {
|
|
150
|
+
traverseSchema(prop.value, newPath, callback);
|
|
151
|
+
} else if (prop.value.type === 'CallExpression') {
|
|
152
|
+
let isEntity = false;
|
|
153
|
+
if (
|
|
154
|
+
prop.value.callee.type === 'MemberExpression' &&
|
|
155
|
+
prop.value.callee.property.name === 'entity' &&
|
|
156
|
+
prop.value.callee.object.type === 'Identifier' &&
|
|
157
|
+
prop.value.callee.object.name === 'i'
|
|
158
|
+
) {
|
|
159
|
+
isEntity = true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isEntity) {
|
|
163
|
+
callback(prop.value, newPath);
|
|
164
|
+
if (prop.value.arguments.length > 0) {
|
|
165
|
+
traverseSchema(prop.value.arguments[0], newPath, callback);
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
callback(prop.value, newPath);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function findSchemaObject(ast: any) {
|
|
176
|
+
let schemaObj: any = null;
|
|
177
|
+
function walk(node: any) {
|
|
178
|
+
if (!node) return;
|
|
179
|
+
if (schemaObj) return;
|
|
180
|
+
if (
|
|
181
|
+
node.type === 'CallExpression' &&
|
|
182
|
+
node.callee.type === 'MemberExpression' &&
|
|
183
|
+
node.callee.object.name === 'i' &&
|
|
184
|
+
node.callee.property.name === 'schema' &&
|
|
185
|
+
node.arguments.length > 0
|
|
186
|
+
) {
|
|
187
|
+
schemaObj = node.arguments[0];
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
for (const key in node) {
|
|
191
|
+
if (key === 'loc' || key === 'start' || key === 'end') continue;
|
|
192
|
+
if (node[key] && typeof node[key] === 'object') {
|
|
193
|
+
if (Array.isArray(node[key])) {
|
|
194
|
+
node[key].forEach(walk);
|
|
195
|
+
} else {
|
|
196
|
+
walk(node[key]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
walk(ast);
|
|
202
|
+
return schemaObj;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function mergeSchema(oldFile: string, newFile: string): string {
|
|
206
|
+
const oldParsed = node.parse(oldFile, {
|
|
207
|
+
sourceType: 'module',
|
|
208
|
+
ecmaVersion: 'latest',
|
|
209
|
+
locations: true,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const newParsed = node.parse(newFile, {
|
|
213
|
+
sourceType: 'module',
|
|
214
|
+
ecmaVersion: 'latest',
|
|
215
|
+
locations: true,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const schemaMap = new Map(); // Path -> { src, ast }
|
|
219
|
+
|
|
220
|
+
// 1. Extract from old file
|
|
221
|
+
const oldSchemaObj = findSchemaObject(oldParsed);
|
|
222
|
+
if (oldSchemaObj) {
|
|
223
|
+
traverseSchema(oldSchemaObj, '', (node: any, path: string) => {
|
|
224
|
+
const { typeParams } = analyzeChain(node);
|
|
225
|
+
if (typeParams) {
|
|
226
|
+
const src = oldFile.slice(typeParams.start, typeParams.end);
|
|
227
|
+
schemaMap.set(path, { src, ast: typeParams });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 2. Collect Imports
|
|
233
|
+
const oldImports = collectImports(oldParsed);
|
|
234
|
+
const newExistingImports = collectExistingImports(newParsed);
|
|
235
|
+
const neededIdentifiers = new Set<string>();
|
|
236
|
+
|
|
237
|
+
// 3. Apply to new file & Collect needed identifiers
|
|
238
|
+
const edits: any[] = [];
|
|
239
|
+
const newSchemaObj = findSchemaObject(newParsed);
|
|
240
|
+
|
|
241
|
+
if (newSchemaObj) {
|
|
242
|
+
traverseSchema(newSchemaObj, '', (node: any, path: string) => {
|
|
243
|
+
const { typeParams, baseCall } = analyzeChain(node);
|
|
244
|
+
const stored = schemaMap.get(path);
|
|
245
|
+
|
|
246
|
+
if (stored) {
|
|
247
|
+
// Collect identifiers from the type params we are about to inject
|
|
248
|
+
findIdentifiers(stored.ast, neededIdentifiers);
|
|
249
|
+
|
|
250
|
+
if (typeParams) {
|
|
251
|
+
edits.push({
|
|
252
|
+
start: typeParams.start,
|
|
253
|
+
end: typeParams.end,
|
|
254
|
+
text: stored.src,
|
|
255
|
+
});
|
|
256
|
+
} else if (baseCall) {
|
|
257
|
+
edits.push({
|
|
258
|
+
start: baseCall.callee.end,
|
|
259
|
+
end: baseCall.callee.end,
|
|
260
|
+
text: stored.src,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 4. Generate Import Statements
|
|
268
|
+
const importsToAdd = new Map(); // source -> { named: Map<string, {str, isType}>, default: {str, isType}, namespace: {str, isType} }
|
|
269
|
+
|
|
270
|
+
for (const id of neededIdentifiers) {
|
|
271
|
+
const importInfo = oldImports.get(id);
|
|
272
|
+
if (importInfo) {
|
|
273
|
+
// Check if already imported in new file
|
|
274
|
+
const existing = newExistingImports.get(importInfo.source);
|
|
275
|
+
if (existing && existing.has(id)) {
|
|
276
|
+
continue; // Already imported
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!importsToAdd.has(importInfo.source)) {
|
|
280
|
+
importsToAdd.set(importInfo.source, {
|
|
281
|
+
named: new Map(),
|
|
282
|
+
default: null,
|
|
283
|
+
namespace: null,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const group = importsToAdd.get(importInfo.source);
|
|
287
|
+
const isType = importInfo.importKind === 'type';
|
|
288
|
+
|
|
289
|
+
if (importInfo.type === 'named') {
|
|
290
|
+
let importStr = id;
|
|
291
|
+
if (importInfo.importedName !== id) {
|
|
292
|
+
importStr = `${importInfo.importedName} as ${id}`;
|
|
293
|
+
}
|
|
294
|
+
group.named.set(importStr, { str: importStr, isType });
|
|
295
|
+
} else if (importInfo.type === 'default') {
|
|
296
|
+
group.default = { str: id, isType };
|
|
297
|
+
} else if (importInfo.type === 'namespace') {
|
|
298
|
+
group.namespace = { str: id, isType };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const importBlocks: string[] = [];
|
|
304
|
+
|
|
305
|
+
for (const [source, info] of importsToAdd) {
|
|
306
|
+
// Check if source exists in new file to merge?
|
|
307
|
+
// For simplicity, we append new import lines.
|
|
308
|
+
// But we can try to be smart.
|
|
309
|
+
|
|
310
|
+
// If we have named imports
|
|
311
|
+
if (info.named.size > 0) {
|
|
312
|
+
const namedImports: any[] = Array.from(info.named.values());
|
|
313
|
+
const allTypes = namedImports.every((x) => x.isType);
|
|
314
|
+
|
|
315
|
+
if (allTypes) {
|
|
316
|
+
const names = namedImports.map((x) => x.str).join(', ');
|
|
317
|
+
importBlocks.push(`import type { ${names} } from '${source}';`);
|
|
318
|
+
} else {
|
|
319
|
+
const names = namedImports
|
|
320
|
+
.map((x) => (x.isType ? `type ${x.str}` : x.str))
|
|
321
|
+
.join(', ');
|
|
322
|
+
importBlocks.push(`import { ${names} } from '${source}';`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (info.default) {
|
|
326
|
+
if (info.default.isType) {
|
|
327
|
+
importBlocks.push(`import type ${info.default.str} from '${source}';`);
|
|
328
|
+
} else {
|
|
329
|
+
importBlocks.push(`import ${info.default.str} from '${source}';`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (info.namespace) {
|
|
333
|
+
if (info.namespace.isType) {
|
|
334
|
+
importBlocks.push(
|
|
335
|
+
`import type * as ${info.namespace.str} from '${source}';`,
|
|
336
|
+
);
|
|
337
|
+
} else {
|
|
338
|
+
importBlocks.push(
|
|
339
|
+
`import * as ${info.namespace.str} from '${source}';`,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 5. Apply edits
|
|
346
|
+
edits.sort((a, b) => b.start - a.start);
|
|
347
|
+
|
|
348
|
+
let output = newFile;
|
|
349
|
+
for (const edit of edits) {
|
|
350
|
+
output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Prepend imports
|
|
354
|
+
if (importBlocks.length > 0) {
|
|
355
|
+
// Check for leading comments (e.g. // Docs: ...)
|
|
356
|
+
// We want to insert imports AFTER the leading comments but BEFORE the first code/import
|
|
357
|
+
|
|
358
|
+
// Simple heuristic: match consecutive lines at start that begin with //
|
|
359
|
+
const commentMatch = output.match(/^(\s*\/\/.*(\r?\n|$))+/);
|
|
360
|
+
|
|
361
|
+
if (commentMatch) {
|
|
362
|
+
const commentEnd = commentMatch[0].length;
|
|
363
|
+
output =
|
|
364
|
+
output.slice(0, commentEnd) +
|
|
365
|
+
'\n' +
|
|
366
|
+
importBlocks.join('\n') +
|
|
367
|
+
output.slice(commentEnd);
|
|
368
|
+
} else {
|
|
369
|
+
output = importBlocks.join('\n') + '\n' + output;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return output;
|
|
374
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { packageDirectory } from 'package-directory';
|
|
2
|
+
import { findUp } from 'find-up-simple';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export type ProjectType = 'node' | 'deno' | 'python';
|
|
6
|
+
|
|
7
|
+
export interface ProjectInfo {
|
|
8
|
+
dir: string;
|
|
9
|
+
type: ProjectType;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Same-directory tie-breaker: Deno > Python > Node. Deno may coexist
|
|
13
|
+
// with package.json for npm interop; pyproject.toml signals Python.
|
|
14
|
+
const TYPE_PRIORITY: Record<ProjectType, number> = {
|
|
15
|
+
deno: 0,
|
|
16
|
+
python: 1,
|
|
17
|
+
node: 2,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const depth = (filepath: string) => filepath.split(path.sep).length;
|
|
21
|
+
|
|
22
|
+
export async function findProjectDir(
|
|
23
|
+
cwd?: string,
|
|
24
|
+
): Promise<ProjectInfo | null> {
|
|
25
|
+
const [denoJson, denoJsonc, pyproject, nodeDir] = await Promise.all([
|
|
26
|
+
findUp('deno.json', { cwd }),
|
|
27
|
+
findUp('deno.jsonc', { cwd }),
|
|
28
|
+
findUp('pyproject.toml', { cwd }),
|
|
29
|
+
packageDirectory({ cwd }),
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
// Push deno.json and deno.jsonc independently so the depth-sort can
|
|
33
|
+
// pick the nearer one when both exist at different levels.
|
|
34
|
+
const candidates: { file: string; type: ProjectType }[] = [];
|
|
35
|
+
if (denoJson) candidates.push({ file: denoJson, type: 'deno' });
|
|
36
|
+
if (denoJsonc) candidates.push({ file: denoJsonc, type: 'deno' });
|
|
37
|
+
if (pyproject) candidates.push({ file: pyproject, type: 'python' });
|
|
38
|
+
if (nodeDir) {
|
|
39
|
+
candidates.push({ file: path.join(nodeDir, 'package.json'), type: 'node' });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (candidates.length === 0) return null;
|
|
43
|
+
|
|
44
|
+
// Nearest marker wins (deepest path), so a Python project nested in a
|
|
45
|
+
// Node monorepo isn't misclassified by a parent's package.json.
|
|
46
|
+
candidates.sort((a, b) => {
|
|
47
|
+
const depthDiff = depth(b.file) - depth(a.file);
|
|
48
|
+
return depthDiff !== 0
|
|
49
|
+
? depthDiff
|
|
50
|
+
: TYPE_PRIORITY[a.type] - TYPE_PRIORITY[b.type];
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return { dir: path.dirname(candidates[0].file), type: candidates[0].type };
|
|
54
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Prompt, SelectState } from '../ui/lib.ts';
|
|
3
|
+
import type { ModifyOutputFn } from '../ui/lib.ts';
|
|
4
|
+
import { isRenamePromptItem } from '@instantdb/platform';
|
|
5
|
+
|
|
6
|
+
export interface RenamePromptItem<T> {
|
|
7
|
+
from: T;
|
|
8
|
+
to: T;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ResolveRenamePrompt<T extends string> extends Prompt<
|
|
12
|
+
RenamePromptItem<T> | T
|
|
13
|
+
> {
|
|
14
|
+
private readonly state: SelectState<RenamePromptItem<T> | T>;
|
|
15
|
+
|
|
16
|
+
result(): RenamePromptItem<T> | T {
|
|
17
|
+
return this.state.items[this.state.selectedIdx]!;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private thingType = 'attr';
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly base: string,
|
|
24
|
+
data: (RenamePromptItem<T> | T)[],
|
|
25
|
+
extraInfo?: any,
|
|
26
|
+
modifyOutput?: ModifyOutputFn,
|
|
27
|
+
) {
|
|
28
|
+
super(modifyOutput);
|
|
29
|
+
this.on('attach', (terminal) => terminal.toggleCursor('hide'));
|
|
30
|
+
this.state = new SelectState(data);
|
|
31
|
+
this.state.bind(this);
|
|
32
|
+
this.base = base;
|
|
33
|
+
if (extraInfo?.type) {
|
|
34
|
+
this.thingType = extraInfo.type;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
render(status: 'idle' | 'submitted' | 'aborted'): string {
|
|
38
|
+
if (status === 'submitted' || status === 'aborted') {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let text = `Is ${chalk.bold.hex('#EA570B')(
|
|
43
|
+
this.base,
|
|
44
|
+
)} created or renamed from another ${this.thingType}?\n`;
|
|
45
|
+
const isSelectedRenamed = isRenamePromptItem(
|
|
46
|
+
this.state.items[this.state.selectedIdx],
|
|
47
|
+
);
|
|
48
|
+
const selectedPrefix = isSelectedRenamed
|
|
49
|
+
? chalk.yellow('❯ ')
|
|
50
|
+
: chalk.green('❯ ');
|
|
51
|
+
|
|
52
|
+
const labelLength: number = this.state.items
|
|
53
|
+
.filter((it) => isRenamePromptItem(it))
|
|
54
|
+
.map((it: RenamePromptItem<T>) => {
|
|
55
|
+
return this.base.length + 3 + it['from'].length;
|
|
56
|
+
})
|
|
57
|
+
.reduce((a, b) => {
|
|
58
|
+
if (a > b) {
|
|
59
|
+
return a;
|
|
60
|
+
}
|
|
61
|
+
return b;
|
|
62
|
+
}, 0);
|
|
63
|
+
|
|
64
|
+
this.state.items.forEach((it, idx) => {
|
|
65
|
+
const isSelected = idx === this.state.selectedIdx;
|
|
66
|
+
const isRenamed = isRenamePromptItem(it);
|
|
67
|
+
const title = isRenamed
|
|
68
|
+
? `${it.from} › ${it.to}`.padEnd(labelLength, ' ')
|
|
69
|
+
: it.padEnd(labelLength, ' ');
|
|
70
|
+
const label = isRenamed
|
|
71
|
+
? `${chalk.yellow('~')} ${title} ${chalk.gray(` rename ${this.thingType}`)}`
|
|
72
|
+
: `${chalk.green('+')} ${title} ${chalk.gray(` create ${this.thingType}`)}`;
|
|
73
|
+
|
|
74
|
+
text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`;
|
|
75
|
+
text += idx != this.state.items.length - 1 ? '\n' : '';
|
|
76
|
+
});
|
|
77
|
+
return text;
|
|
78
|
+
}
|
|
79
|
+
}
|