@sidekickdb/cli 2.0.0 → 3.0.0

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.
Files changed (265) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/README.md +5 -5
  3. package/__tests__/appCommands.test.ts +8 -8
  4. package/__tests__/auth.test.ts +11 -65
  5. package/__tests__/authClientAddApple.test.ts +3 -3
  6. package/__tests__/authClientAddClerk.test.ts +8 -13
  7. package/__tests__/authClientAddGithub.test.ts +5 -5
  8. package/__tests__/authClientAddGoogle.test.ts +3 -3
  9. package/__tests__/authClientAddLinkedin.test.ts +3 -3
  10. package/__tests__/authClientList.test.ts +4 -3
  11. package/__tests__/authClientUpdate.test.ts +6 -8
  12. package/__tests__/authOriginManagement.test.ts +11 -11
  13. package/__tests__/backups.test.ts +2 -2
  14. package/__tests__/config.test.ts +34 -34
  15. package/__tests__/configAliases.test.ts +27 -215
  16. package/__tests__/configFileNames.test.ts +118 -0
  17. package/__tests__/e2e/cli.e2e.test.ts +102 -102
  18. package/__tests__/e2e/helpers.ts +5 -5
  19. package/__tests__/effectHelpers.ts +3 -3
  20. package/__tests__/emailVerification.test.ts +31 -0
  21. package/__tests__/oldConfigFiles.test.ts +254 -0
  22. package/__tests__/webhooks.test.ts +2 -2
  23. package/dist/auth/index.d.ts.map +1 -1
  24. package/dist/auth/index.js +6 -43
  25. package/dist/auth/index.js.map +1 -1
  26. package/dist/commands/app/delete.d.ts +2 -2
  27. package/dist/commands/app/delete.d.ts.map +1 -1
  28. package/dist/commands/app/delete.js +2 -2
  29. package/dist/commands/app/delete.js.map +1 -1
  30. package/dist/commands/app/list.d.ts +2 -2
  31. package/dist/commands/app/list.d.ts.map +1 -1
  32. package/dist/commands/app/list.js +2 -2
  33. package/dist/commands/app/list.js.map +1 -1
  34. package/dist/commands/auth/client/add.d.ts +1 -1
  35. package/dist/commands/auth/client/add.d.ts.map +1 -1
  36. package/dist/commands/auth/client/delete.d.ts +2 -2
  37. package/dist/commands/auth/client/delete.d.ts.map +1 -1
  38. package/dist/commands/auth/client/delete.js +2 -2
  39. package/dist/commands/auth/client/delete.js.map +1 -1
  40. package/dist/commands/auth/client/list.d.ts +1 -1
  41. package/dist/commands/auth/client/list.d.ts.map +1 -1
  42. package/dist/commands/auth/client/update.d.ts +1 -1
  43. package/dist/commands/auth/client/update.d.ts.map +1 -1
  44. package/dist/commands/auth/email/pull.d.ts +4 -4
  45. package/dist/commands/auth/email/pull.d.ts.map +1 -1
  46. package/dist/commands/auth/email/pull.js +5 -2
  47. package/dist/commands/auth/email/pull.js.map +1 -1
  48. package/dist/commands/auth/email/push.d.ts +2 -2
  49. package/dist/commands/auth/email/push.d.ts.map +1 -1
  50. package/dist/commands/auth/email/push.js +3 -3
  51. package/dist/commands/auth/email/push.js.map +1 -1
  52. package/dist/commands/auth/email/resend.d.ts +1 -1
  53. package/dist/commands/auth/email/resend.d.ts.map +1 -1
  54. package/dist/commands/auth/email/reset.d.ts +2 -2
  55. package/dist/commands/auth/email/reset.d.ts.map +1 -1
  56. package/dist/commands/auth/email/reset.js +3 -3
  57. package/dist/commands/auth/email/reset.js.map +1 -1
  58. package/dist/commands/auth/email/status.d.ts +4 -4
  59. package/dist/commands/auth/email/status.d.ts.map +1 -1
  60. package/dist/commands/auth/email/status.js +4 -4
  61. package/dist/commands/auth/email/status.js.map +1 -1
  62. package/dist/commands/auth/email/verify.d.ts +1 -1
  63. package/dist/commands/auth/email/verify.d.ts.map +1 -1
  64. package/dist/commands/auth/email/verify.js +1 -1
  65. package/dist/commands/auth/email/verify.js.map +1 -1
  66. package/dist/commands/auth/origin/add.d.ts +1 -1
  67. package/dist/commands/auth/origin/add.d.ts.map +1 -1
  68. package/dist/commands/auth/origin/delete.d.ts +1 -1
  69. package/dist/commands/auth/origin/delete.d.ts.map +1 -1
  70. package/dist/commands/auth/origin/list.d.ts +1 -1
  71. package/dist/commands/auth/origin/list.d.ts.map +1 -1
  72. package/dist/commands/claim.d.ts +2 -2
  73. package/dist/commands/claim.d.ts.map +1 -1
  74. package/dist/commands/claim.js +2 -2
  75. package/dist/commands/claim.js.map +1 -1
  76. package/dist/commands/info.js +2 -2
  77. package/dist/commands/info.js.map +1 -1
  78. package/dist/commands/init.d.ts +1 -1
  79. package/dist/commands/init.d.ts.map +1 -1
  80. package/dist/commands/init.js +3 -0
  81. package/dist/commands/init.js.map +1 -1
  82. package/dist/commands/initWithoutFiles.d.ts.map +1 -1
  83. package/dist/commands/initWithoutFiles.js +7 -3
  84. package/dist/commands/initWithoutFiles.js.map +1 -1
  85. package/dist/commands/login.d.ts +1 -1
  86. package/dist/commands/login.d.ts.map +1 -1
  87. package/dist/commands/pull.d.ts +1 -1
  88. package/dist/commands/pull.d.ts.map +1 -1
  89. package/dist/commands/pull.js +4 -0
  90. package/dist/commands/pull.js.map +1 -1
  91. package/dist/commands/push.d.ts +1 -1
  92. package/dist/commands/push.d.ts.map +1 -1
  93. package/dist/commands/push.js +4 -0
  94. package/dist/commands/push.js.map +1 -1
  95. package/dist/commands/query.d.ts +1 -1
  96. package/dist/commands/query.d.ts.map +1 -1
  97. package/dist/commands/query.js +2 -2
  98. package/dist/commands/query.js.map +1 -1
  99. package/dist/context/authToken.d.ts +2 -2
  100. package/dist/context/authToken.d.ts.map +1 -1
  101. package/dist/context/authToken.js +6 -4
  102. package/dist/context/authToken.js.map +1 -1
  103. package/dist/context/currentApp.d.ts +3 -3
  104. package/dist/context/currentApp.d.ts.map +1 -1
  105. package/dist/context/currentApp.js +20 -20
  106. package/dist/context/currentApp.js.map +1 -1
  107. package/dist/context/globalOpts.d.ts +1 -1
  108. package/dist/context/globalOpts.js +1 -1
  109. package/dist/context/globalOpts.js.map +1 -1
  110. package/dist/context/platformApi.d.ts +3 -3
  111. package/dist/context/platformApi.d.ts.map +1 -1
  112. package/dist/context/platformApi.js +3 -3
  113. package/dist/context/platformApi.js.map +1 -1
  114. package/dist/context/projectInfo.d.ts +4 -4
  115. package/dist/context/projectInfo.d.ts.map +1 -1
  116. package/dist/context/projectInfo.js +12 -18
  117. package/dist/context/projectInfo.js.map +1 -1
  118. package/dist/index.d.ts.map +1 -1
  119. package/dist/index.js +42 -49
  120. package/dist/index.js.map +1 -1
  121. package/dist/layer.d.ts +4 -4
  122. package/dist/layer.d.ts.map +1 -1
  123. package/dist/layer.js +7 -7
  124. package/dist/layer.js.map +1 -1
  125. package/dist/lib/backupDownload.js +1 -1
  126. package/dist/lib/backupDownload.js.map +1 -1
  127. package/dist/lib/config.d.ts +2 -2
  128. package/dist/lib/config.d.ts.map +1 -1
  129. package/dist/lib/config.js +21 -23
  130. package/dist/lib/config.js.map +1 -1
  131. package/dist/lib/createApp.d.ts +2 -2
  132. package/dist/lib/createApp.d.ts.map +1 -1
  133. package/dist/lib/createApp.js +2 -2
  134. package/dist/lib/createApp.js.map +1 -1
  135. package/dist/lib/email.d.ts +38 -6
  136. package/dist/lib/email.d.ts.map +1 -1
  137. package/dist/lib/email.js +22 -13
  138. package/dist/lib/email.js.map +1 -1
  139. package/dist/lib/handleEnv.js +4 -4
  140. package/dist/lib/handleEnv.js.map +1 -1
  141. package/dist/lib/http.d.ts +13 -13
  142. package/dist/lib/http.d.ts.map +1 -1
  143. package/dist/lib/http.js +12 -12
  144. package/dist/lib/http.js.map +1 -1
  145. package/dist/lib/login.d.ts +4 -4
  146. package/dist/lib/login.d.ts.map +1 -1
  147. package/dist/lib/login.js +4 -4
  148. package/dist/lib/login.js.map +1 -1
  149. package/dist/lib/oauth.d.ts +10 -10
  150. package/dist/lib/oauth.d.ts.map +1 -1
  151. package/dist/lib/oauth.js +7 -7
  152. package/dist/lib/oauth.js.map +1 -1
  153. package/dist/lib/platformApi.d.ts +2 -2
  154. package/dist/lib/platformApi.d.ts.map +1 -1
  155. package/dist/lib/platformApi.js +2 -2
  156. package/dist/lib/platformApi.js.map +1 -1
  157. package/dist/lib/pullPerms.d.ts +2 -2
  158. package/dist/lib/pullPerms.d.ts.map +1 -1
  159. package/dist/lib/pullPerms.js +7 -4
  160. package/dist/lib/pullPerms.js.map +1 -1
  161. package/dist/lib/pullSchema.d.ts +2 -2
  162. package/dist/lib/pullSchema.d.ts.map +1 -1
  163. package/dist/lib/pullSchema.js +8 -5
  164. package/dist/lib/pullSchema.js.map +1 -1
  165. package/dist/lib/pushPerms.d.ts +2 -2
  166. package/dist/lib/pushPerms.d.ts.map +1 -1
  167. package/dist/lib/pushPerms.js +6 -3
  168. package/dist/lib/pushPerms.js.map +1 -1
  169. package/dist/lib/pushSchema.d.ts +2 -2
  170. package/dist/lib/pushSchema.d.ts.map +1 -1
  171. package/dist/lib/pushSchema.js +18 -7
  172. package/dist/lib/pushSchema.js.map +1 -1
  173. package/dist/lib/webhooks.d.ts +1 -1
  174. package/dist/lib/webhooks.d.ts.map +1 -1
  175. package/dist/old.js +9 -9
  176. package/dist/old.js.map +1 -1
  177. package/dist/renderSchemaPlan.d.ts +2 -2
  178. package/dist/renderSchemaPlan.d.ts.map +1 -1
  179. package/dist/renderSchemaPlan.js.map +1 -1
  180. package/dist/util/findConfigCandidates.d.ts +0 -20
  181. package/dist/util/findConfigCandidates.d.ts.map +1 -1
  182. package/dist/util/findConfigCandidates.js +44 -63
  183. package/dist/util/findConfigCandidates.js.map +1 -1
  184. package/dist/util/getAppName.d.ts +2 -2
  185. package/dist/util/getAppName.d.ts.map +1 -1
  186. package/dist/util/getAppName.js +2 -2
  187. package/dist/util/getAppName.js.map +1 -1
  188. package/dist/util/isHeadlessEnvironment.js +1 -1
  189. package/dist/util/isHeadlessEnvironment.js.map +1 -1
  190. package/dist/util/loadConfig.d.ts.map +1 -1
  191. package/dist/util/loadConfig.js +4 -11
  192. package/dist/util/loadConfig.js.map +1 -1
  193. package/dist/util/loadEnv.d.ts.map +1 -1
  194. package/dist/util/loadEnv.js +0 -6
  195. package/dist/util/loadEnv.js.map +1 -1
  196. package/dist/util/oldConfigFiles.d.ts +30 -0
  197. package/dist/util/oldConfigFiles.d.ts.map +1 -0
  198. package/dist/util/oldConfigFiles.js +104 -0
  199. package/dist/util/oldConfigFiles.js.map +1 -0
  200. package/dist/util/projectDir.d.ts +1 -1
  201. package/dist/util/projectDir.d.ts.map +1 -1
  202. package/dist/util/projectDir.js +6 -9
  203. package/dist/util/projectDir.js.map +1 -1
  204. package/dist/util/sidekickConfig.d.ts +9 -0
  205. package/dist/util/sidekickConfig.d.ts.map +1 -0
  206. package/dist/util/sidekickConfig.js +18 -0
  207. package/dist/util/sidekickConfig.js.map +1 -0
  208. package/package.json +6 -7
  209. package/src/auth/index.ts +6 -54
  210. package/src/commands/app/delete.ts +2 -2
  211. package/src/commands/app/list.ts +2 -2
  212. package/src/commands/auth/client/delete.ts +2 -2
  213. package/src/commands/auth/email/pull.ts +5 -2
  214. package/src/commands/auth/email/push.ts +3 -3
  215. package/src/commands/auth/email/reset.ts +5 -3
  216. package/src/commands/auth/email/status.ts +4 -4
  217. package/src/commands/auth/email/verify.ts +1 -1
  218. package/src/commands/claim.ts +2 -2
  219. package/src/commands/info.ts +2 -2
  220. package/src/commands/init.ts +3 -0
  221. package/src/commands/initWithoutFiles.ts +13 -6
  222. package/src/commands/pull.ts +6 -0
  223. package/src/commands/push.ts +6 -0
  224. package/src/commands/query.ts +2 -2
  225. package/src/context/authToken.ts +9 -5
  226. package/src/context/currentApp.ts +20 -20
  227. package/src/context/globalOpts.ts +1 -1
  228. package/src/context/platformApi.ts +3 -3
  229. package/src/context/projectInfo.ts +13 -20
  230. package/src/index.ts +42 -52
  231. package/src/layer.ts +10 -10
  232. package/src/lib/backupDownload.ts +1 -1
  233. package/src/lib/config.ts +21 -23
  234. package/src/lib/createApp.ts +2 -2
  235. package/src/lib/email.ts +30 -15
  236. package/src/lib/handleEnv.ts +4 -4
  237. package/src/lib/http.ts +28 -24
  238. package/src/lib/login.ts +4 -4
  239. package/src/lib/oauth.ts +7 -7
  240. package/src/lib/platformApi.ts +2 -2
  241. package/src/lib/pullPerms.ts +7 -4
  242. package/src/lib/pullSchema.ts +9 -6
  243. package/src/lib/pushPerms.ts +6 -3
  244. package/src/lib/pushSchema.ts +19 -7
  245. package/src/old.js +9 -9
  246. package/src/renderSchemaPlan.ts +3 -3
  247. package/src/util/findConfigCandidates.ts +45 -71
  248. package/src/util/getAppName.ts +2 -2
  249. package/src/util/isHeadlessEnvironment.ts +1 -1
  250. package/src/util/loadConfig.ts +4 -12
  251. package/src/util/loadEnv.ts +0 -8
  252. package/src/util/oldConfigFiles.ts +132 -0
  253. package/src/util/projectDir.ts +7 -9
  254. package/src/util/sidekickConfig.ts +25 -0
  255. package/__tests__/legacyPackageCompat.test.ts +0 -104
  256. package/dist/util/envAliases.d.ts +0 -25
  257. package/dist/util/envAliases.d.ts.map +0 -1
  258. package/dist/util/envAliases.js +0 -47
  259. package/dist/util/envAliases.js.map +0 -1
  260. package/dist/util/instantConfig.d.ts +0 -9
  261. package/dist/util/instantConfig.d.ts.map +0 -1
  262. package/dist/util/instantConfig.js +0 -13
  263. package/dist/util/instantConfig.js.map +0 -1
  264. package/src/util/envAliases.ts +0 -53
  265. package/src/util/instantConfig.ts +0 -21
@@ -4,7 +4,7 @@ import {
4
4
  HttpClientResponse,
5
5
  } from '@effect/platform';
6
6
  import {
7
- apiSchemaToInstantSchemaDef,
7
+ apiSchemaToSidekickSchemaDef,
8
8
  buildAutoRenameSelector,
9
9
  collectSystemCatalogIdentNames,
10
10
  convertTxSteps,
@@ -20,7 +20,7 @@ import {
20
20
  resolveRenames,
21
21
  waitForIndexingJobsToFinish,
22
22
  } from '../old.js';
23
- import { getBaseUrl, InstantHttpAuthed, withCommand } from './http.ts';
23
+ import { getBaseUrl, SidekickHttpAuthed, withCommand } from './http.ts';
24
24
 
25
25
  import boxen from 'boxen';
26
26
  import { GlobalOpts } from '../context/globalOpts.ts';
@@ -30,6 +30,7 @@ import { groupSteps, renderSchemaPlan } from '../renderSchemaPlan.ts';
30
30
  import type { SuperMigrationTx } from '../renderSchemaPlan.ts';
31
31
  import { promptOk } from './ui.ts';
32
32
  import { AuthToken } from '../context/authToken.ts';
33
+ import { failOnOldConfigFiles } from '../util/oldConfigFiles.ts';
33
34
 
34
35
  const FetchSchemaResponse = Schema.Struct({
35
36
  schema: Schema.Struct({
@@ -69,6 +70,8 @@ export const pushSchema = (
69
70
  rename?: OptsFromCommand<typeof pushDef>['rename'],
70
71
  ) =>
71
72
  Effect.gen(function* () {
73
+ // SidekickDB: stop when only an old-named schema file exists.
74
+ yield* failOnOldConfigFiles(['schema']);
72
75
  const localSchemaFile = yield* Effect.tryPromise({
73
76
  try: readLocalSchemaFile,
74
77
  catch: (e) =>
@@ -78,16 +81,25 @@ export const pushSchema = (
78
81
  });
79
82
  if (!localSchemaFile || !localSchemaFile?.schema) {
80
83
  return yield* ReadSchemaFileError.make({
81
- message: `We couldn't find your ${chalk.yellow('`instant.schema.ts`')} file. Make sure it's in the root directory. (Hint: You can use an INSTANT_SCHEMA_FILE_PATH environment variable to specify it.)`,
84
+ message: `We couldn't find your ${chalk.yellow('`sidekick.schema.ts`')} file. Make sure it's in the root directory. (Hint: You can use an SIDEKICK_SCHEMA_FILE_PATH environment variable to specify it.)`,
82
85
  });
83
86
  }
84
- if (localSchemaFile.schema?.constructor?.name !== 'InstantSchemaDef') {
87
+ // SidekickDB: a schema built with the @sidekickdb/* packages from before
88
+ // the rename has the old class name; say so instead of "couldn't find".
89
+ // Spelled in two parts so that the rename leaves it alone.
90
+ if (localSchemaFile.schema?.constructor?.name === 'Ins' + 'tantSchemaDef') {
85
91
  return yield* SchemaValidationError.make({
86
- message: `We couldn't find your schema export.\nIn your ${chalk.yellow('`instant.schema.ts`')} file, make sure you ${chalk.green('`export default schema`')}`,
92
+ message:
93
+ "Your project's @sidekickdb/* packages are older than this CLI. Upgrade the @sidekickdb/* packages to the same release as the CLI, then push again.",
94
+ });
95
+ }
96
+ if (localSchemaFile.schema?.constructor?.name !== 'SidekickSchemaDef') {
97
+ return yield* SchemaValidationError.make({
98
+ message: `We couldn't find your schema export.\nIn your ${chalk.yellow('`sidekick.schema.ts`')} file, make sure you ${chalk.green('`export default schema`')}`,
87
99
  });
88
100
  }
89
101
 
90
- const http = yield* InstantHttpAuthed;
102
+ const http = yield* SidekickHttpAuthed;
91
103
  const { appId } = yield* CurrentApp;
92
104
  const res = yield* http
93
105
  .pipe(withCommand('push'))
@@ -99,7 +111,7 @@ export const pushSchema = (
99
111
 
100
112
  const currentAttrs = res['attrs'];
101
113
  const currentApiSchema = res['schema'];
102
- const oldSchema = apiSchemaToInstantSchemaDef(currentApiSchema);
114
+ const oldSchema = apiSchemaToSidekickSchemaDef(currentApiSchema);
103
115
  const systemCatalogIdentNames =
104
116
  collectSystemCatalogIdentNames(currentAttrs);
105
117
 
package/src/old.js CHANGED
@@ -17,19 +17,19 @@ import { link } from './logging.ts';
17
17
  import { Effect, Option } from 'effect';
18
18
  import { getOptionalDashUrl } from './lib/config.ts';
19
19
 
20
- const verbose = Boolean(process.env.INSTANT_CLI_VERBOSE);
20
+ const verbose = Boolean(process.env.SIDEKICK_CLI_VERBOSE);
21
21
 
22
22
  function error(firstArg, ...rest) {
23
23
  console.error(chalk.red('[error]') + ' ' + firstArg, ...rest);
24
24
  }
25
25
 
26
26
  const potentialAdminTokenEnvs = {
27
- default: 'INSTANT_APP_ADMIN_TOKEN',
28
- short: 'INSTANT_ADMIN_TOKEN',
27
+ default: 'SIDEKICK_APP_ADMIN_TOKEN',
28
+ short: 'SIDEKICK_ADMIN_TOKEN',
29
29
  };
30
30
 
31
31
  // No default dashboard: links are only printed when one is configured
32
- // (INSTANT_CLI_DASH_URI, dashURI in instant.config.ts, or INSTANT_CLI_DEV).
32
+ // (SIDEKICK_CLI_DASH_URI, dashURI in sidekick.config.ts, or SIDEKICK_CLI_DEV).
33
33
  export async function readDashOrigin() {
34
34
  try {
35
35
  return Option.getOrNull(await Effect.runPromise(getOptionalDashUrl));
@@ -358,9 +358,9 @@ async function fetchJson({
358
358
  headers: {
359
359
  ...(withAuth ? { Authorization: `Bearer ${authToken}` } : {}),
360
360
  'Content-Type': 'application/json',
361
- 'X-Instant-Source': 'instant-cli',
362
- 'X-Instant-Version': version,
363
- ...(command ? { 'X-Instant-Command': command } : {}),
361
+ 'X-Sidekick-Source': 'sidekick-cli',
362
+ 'X-Sidekick-Version': version,
363
+ ...(command ? { 'X-Sidekick-Command': command } : {}),
364
364
  ...extraHeaders,
365
365
  },
366
366
  body: body ? JSON.stringify(body) : undefined,
@@ -458,8 +458,8 @@ async function readConfigAuthToken(apiURI, allowAdminToken = true) {
458
458
  return options.token;
459
459
  }
460
460
 
461
- if (process.env.INSTANT_CLI_AUTH_TOKEN) {
462
- return process.env.INSTANT_CLI_AUTH_TOKEN;
461
+ if (process.env.SIDEKICK_CLI_AUTH_TOKEN) {
462
+ return process.env.SIDEKICK_CLI_AUTH_TOKEN;
463
463
  }
464
464
 
465
465
  if (allowAdminToken) {
@@ -8,11 +8,11 @@ import chalk from 'chalk';
8
8
  import stripAnsi from 'strip-ansi';
9
9
 
10
10
  // Hack to prevent using @sidekickdb/core as a dependency for cli
11
- type InstantDBAttr = Parameters<typeof convertTxSteps>[1][0];
11
+ type SidekickDBAttr = Parameters<typeof convertTxSteps>[1][0];
12
12
 
13
13
  const renderLinkUpdate = (
14
14
  tx: MigrationTxTypes['update-attr'],
15
- possiblePrevAttrs?: InstantDBAttr[],
15
+ possiblePrevAttrs?: SidekickDBAttr[],
16
16
  ): string => {
17
17
  if (tx.partialAttr['value-type'] !== 'ref') {
18
18
  throw new Error('Invalid value type for link update');
@@ -181,7 +181,7 @@ const isRename = (step: MigrationTxSpecific<'update-attr'>) => {
181
181
 
182
182
  export const renderSchemaPlan = (
183
183
  planSteps: SuperMigrationTx[],
184
- prevAttrs?: InstantDBAttr[],
184
+ prevAttrs?: SidekickDBAttr[],
185
185
  ): string[] => {
186
186
  const result: string[] = [];
187
187
 
@@ -1,7 +1,6 @@
1
1
  import { existsSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import chalk from 'chalk';
4
- import { envNameForDisplay } from './envAliases.ts';
5
4
 
6
5
  type ConfigCandidate = {
7
6
  files: string;
@@ -18,40 +17,15 @@ type ConfigCandidate = {
18
17
  * Since schema files only need schema types (i, id, tx, etc.) which all
19
18
  * come from @sidekickdb/core, we rewrite these imports to a safe export
20
19
  * in the package that only re-exports from @sidekickdb/core.
21
- *
22
- * Legacy @instantdb/* imports are rewritten the same way so existing
23
- * schema files keep loading.
24
20
  */
25
- export function transformImports(code: string): string {
21
+ function transformImports(code: string): string {
26
22
  return code
27
23
  .replace(
28
- /["']@(sidekickdb|instantdb)\/react-native["']/g,
29
- '"@$1/react-native/dist/cli"',
30
- )
31
- .replace(
32
- /["']@(sidekickdb|instantdb)\/svelte["']/g,
33
- '"@$1/svelte/dist/cli"',
24
+ /["']@sidekickdb\/react-native["']/g,
25
+ '"@sidekickdb/react-native/dist/cli"',
34
26
  )
35
- .replace(/["']@(sidekickdb|instantdb)\/vue["']/g, '"@$1/vue/dist/cli"');
36
- }
37
-
38
- const LEGACY_CONFIG_FILE = /(^|[\\/])instant\.(?=(?:schema|perms|email)$)/;
39
-
40
- /**
41
- * `sidekick.schema`, `sidekick.perms` and `sidekick.email` are the SidekickDB
42
- * names for the `instant.*` files, in the same places. They are listed first,
43
- * so a `sidekick.*` file wins over an `instant.*` one.
44
- */
45
- export function withSidekickFileNames(
46
- candidates: ConfigCandidate[],
47
- ): ConfigCandidate[] {
48
- const renamed = candidates
49
- .filter((candidate) => LEGACY_CONFIG_FILE.test(candidate.files))
50
- .map((candidate) => ({
51
- ...candidate,
52
- files: candidate.files.replace(LEGACY_CONFIG_FILE, '$1sidekick.'),
53
- }));
54
- return [...renamed, ...candidates];
27
+ .replace(/["']@sidekickdb\/svelte["']/g, '"@sidekickdb/svelte/dist/cli"')
28
+ .replace(/["']@sidekickdb\/vue["']/g, '"@sidekickdb/vue/dist/cli"');
55
29
  }
56
30
 
57
31
  function findPathsRecursive(
@@ -93,30 +67,30 @@ function findPathsRecursive(
93
67
  }
94
68
 
95
69
  function getEnvSchemaPathWithLogging(): string | undefined {
96
- const path = process.env.INSTANT_SCHEMA_FILE_PATH;
70
+ const path = process.env.SIDEKICK_SCHEMA_FILE_PATH;
97
71
  if (path) {
98
72
  console.log(
99
- `Using ${envNameForDisplay('INSTANT_SCHEMA_FILE_PATH')}=${chalk.green(process.env.INSTANT_SCHEMA_FILE_PATH)}`,
73
+ `Using SIDEKICK_SCHEMA_FILE_PATH=${chalk.green(process.env.SIDEKICK_SCHEMA_FILE_PATH)}`,
100
74
  );
101
75
  }
102
76
  return path;
103
77
  }
104
78
 
105
79
  function getEnvPermsPathWithLogging(): string | undefined {
106
- const path = process.env.INSTANT_PERMS_FILE_PATH;
80
+ const path = process.env.SIDEKICK_PERMS_FILE_PATH;
107
81
  if (path) {
108
82
  console.log(
109
- `Using ${envNameForDisplay('INSTANT_PERMS_FILE_PATH')}=${chalk.green(process.env.INSTANT_PERMS_FILE_PATH)}`,
83
+ `Using SIDEKICK_PERMS_FILE_PATH=${chalk.green(process.env.SIDEKICK_PERMS_FILE_PATH)}`,
110
84
  );
111
85
  }
112
86
  return path;
113
87
  }
114
88
 
115
89
  function getEnvEmailPathWithLogging(): string | undefined {
116
- const path = process.env.INSTANT_EMAIL_FILE_PATH;
90
+ const path = process.env.SIDEKICK_EMAIL_FILE_PATH;
117
91
  if (path) {
118
92
  console.log(
119
- `Using ${envNameForDisplay('INSTANT_EMAIL_FILE_PATH')}=${chalk.green(process.env.INSTANT_EMAIL_FILE_PATH)}`,
93
+ `Using SIDEKICK_EMAIL_FILE_PATH=${chalk.green(process.env.SIDEKICK_EMAIL_FILE_PATH)}`,
120
94
  );
121
95
  }
122
96
  return path;
@@ -132,16 +106,16 @@ export function getSchemaReadCandidates(): ConfigCandidate[] {
132
106
  const candidates: ConfigCandidate[] = [];
133
107
 
134
108
  candidates.push({
135
- files: 'instant.schema',
109
+ files: 'sidekick.schema',
136
110
  extensions,
137
111
  transform: transformImports,
138
112
  });
139
113
 
140
- // matches: src/any-folder/any-folder/instant.schema
141
- // src/any-folder/instant.schema
142
- // src/instant.schema
143
- // 3 levels in case someone does src/lib/db/instant.schema
144
- const srcPaths = findPathsRecursive('src', 3, 'instant.schema');
114
+ // matches: src/any-folder/any-folder/sidekick.schema
115
+ // src/any-folder/sidekick.schema
116
+ // src/sidekick.schema
117
+ // 3 levels in case someone does src/lib/db/sidekick.schema
118
+ const srcPaths = findPathsRecursive('src', 3, 'sidekick.schema');
145
119
  for (const srcPath of srcPaths) {
146
120
  candidates.push({
147
121
  files: srcPath,
@@ -150,10 +124,10 @@ export function getSchemaReadCandidates(): ConfigCandidate[] {
150
124
  });
151
125
  }
152
126
 
153
- // matches: lib/any-folder/instant.schema
154
- // lib/instant.schema
155
- // 2 levels in case someone does lib/db/instant.schema
156
- const libPaths = findPathsRecursive('lib', 2, 'instant.schema');
127
+ // matches: lib/any-folder/sidekick.schema
128
+ // lib/sidekick.schema
129
+ // 2 levels in case someone does lib/db/sidekick.schema
130
+ const libPaths = findPathsRecursive('lib', 2, 'sidekick.schema');
157
131
  for (const libPath of libPaths) {
158
132
  candidates.push({
159
133
  files: libPath,
@@ -163,12 +137,12 @@ export function getSchemaReadCandidates(): ConfigCandidate[] {
163
137
  }
164
138
 
165
139
  candidates.push({
166
- files: 'app/instant.schema',
140
+ files: 'app/sidekick.schema',
167
141
  extensions,
168
142
  transform: transformImports,
169
143
  });
170
144
 
171
- return withSidekickFileNames(candidates);
145
+ return candidates;
172
146
  }
173
147
 
174
148
  export function getPermsReadCandidates(): ConfigCandidate[] {
@@ -181,12 +155,12 @@ export function getPermsReadCandidates(): ConfigCandidate[] {
181
155
  const candidates: ConfigCandidate[] = [];
182
156
 
183
157
  candidates.push({
184
- files: 'instant.perms',
158
+ files: 'sidekick.perms',
185
159
  extensions,
186
160
  transform: transformImports,
187
161
  });
188
162
 
189
- const srcPaths = findPathsRecursive('src', 3, 'instant.perms');
163
+ const srcPaths = findPathsRecursive('src', 3, 'sidekick.perms');
190
164
  for (const srcPath of srcPaths) {
191
165
  candidates.push({
192
166
  files: srcPath,
@@ -195,7 +169,7 @@ export function getPermsReadCandidates(): ConfigCandidate[] {
195
169
  });
196
170
  }
197
171
 
198
- const libPaths = findPathsRecursive('lib', 2, 'instant.perms');
172
+ const libPaths = findPathsRecursive('lib', 2, 'sidekick.perms');
199
173
  for (const libPath of libPaths) {
200
174
  candidates.push({
201
175
  files: libPath,
@@ -205,12 +179,12 @@ export function getPermsReadCandidates(): ConfigCandidate[] {
205
179
  }
206
180
 
207
181
  candidates.push({
208
- files: 'app/instant.perms',
182
+ files: 'app/sidekick.perms',
209
183
  extensions,
210
184
  transform: transformImports,
211
185
  });
212
186
 
213
- return withSidekickFileNames(candidates);
187
+ return candidates;
214
188
  }
215
189
 
216
190
  export function getEmailReadCandidates(emailPath?: string): ConfigCandidate[] {
@@ -223,12 +197,12 @@ export function getEmailReadCandidates(emailPath?: string): ConfigCandidate[] {
223
197
  const candidates: ConfigCandidate[] = [];
224
198
 
225
199
  candidates.push({
226
- files: 'instant.email',
200
+ files: 'sidekick.email',
227
201
  extensions,
228
202
  transform: transformImports,
229
203
  });
230
204
 
231
- const srcPaths = findPathsRecursive('src', 3, 'instant.email');
205
+ const srcPaths = findPathsRecursive('src', 3, 'sidekick.email');
232
206
  for (const srcPath of srcPaths) {
233
207
  candidates.push({
234
208
  files: srcPath,
@@ -237,7 +211,7 @@ export function getEmailReadCandidates(emailPath?: string): ConfigCandidate[] {
237
211
  });
238
212
  }
239
213
 
240
- const libPaths = findPathsRecursive('lib', 2, 'instant.email');
214
+ const libPaths = findPathsRecursive('lib', 2, 'sidekick.email');
241
215
  for (const libPath of libPaths) {
242
216
  candidates.push({
243
217
  files: libPath,
@@ -247,42 +221,42 @@ export function getEmailReadCandidates(emailPath?: string): ConfigCandidate[] {
247
221
  }
248
222
 
249
223
  candidates.push({
250
- files: 'app/instant.email',
224
+ files: 'app/sidekick.email',
251
225
  extensions,
252
226
  transform: transformImports,
253
227
  });
254
228
 
255
- return withSidekickFileNames(candidates);
229
+ return candidates;
256
230
  }
257
231
 
258
232
  export function getSchemaPathToWrite(existingPath?: string): string {
259
233
  if (existingPath) return existingPath;
260
- if (process.env.INSTANT_SCHEMA_FILE_PATH) {
261
- return process.env.INSTANT_SCHEMA_FILE_PATH;
234
+ if (process.env.SIDEKICK_SCHEMA_FILE_PATH) {
235
+ return process.env.SIDEKICK_SCHEMA_FILE_PATH;
262
236
  }
263
237
  if (existsSync(join(process.cwd(), 'src'))) {
264
- return join('src', 'instant.schema.ts');
238
+ return join('src', 'sidekick.schema.ts');
265
239
  }
266
240
 
267
- return 'instant.schema.ts';
241
+ return 'sidekick.schema.ts';
268
242
  }
269
243
 
270
244
  export function getPermsPathToWrite(): string {
271
- if (process.env.INSTANT_PERMS_FILE_PATH) {
272
- return process.env.INSTANT_PERMS_FILE_PATH;
245
+ if (process.env.SIDEKICK_PERMS_FILE_PATH) {
246
+ return process.env.SIDEKICK_PERMS_FILE_PATH;
273
247
  }
274
248
  if (existsSync(join(process.cwd(), 'src'))) {
275
- return join('src', 'instant.perms.ts');
249
+ return join('src', 'sidekick.perms.ts');
276
250
  }
277
- return 'instant.perms.ts';
251
+ return 'sidekick.perms.ts';
278
252
  }
279
253
 
280
254
  export function getEmailPathToWrite(): string {
281
- if (process.env.INSTANT_EMAIL_FILE_PATH) {
282
- return process.env.INSTANT_EMAIL_FILE_PATH;
255
+ if (process.env.SIDEKICK_EMAIL_FILE_PATH) {
256
+ return process.env.SIDEKICK_EMAIL_FILE_PATH;
283
257
  }
284
258
  if (existsSync(join(process.cwd(), 'src'))) {
285
- return join('src', 'instant.email.ts');
259
+ return join('src', 'sidekick.email.ts');
286
260
  }
287
- return 'instant.email.ts';
261
+ return 'sidekick.email.ts';
288
262
  }
@@ -1,11 +1,11 @@
1
1
  import { Effect } from 'effect';
2
- import { InstantHttpAuthed } from '../lib/http.ts';
2
+ import { SidekickHttpAuthed } from '../lib/http.ts';
3
3
  import { CurrentApp } from '../context/currentApp.ts';
4
4
  import { HttpClientResponse } from '@effect/platform';
5
5
  import { DashAppResponse } from '../commands/info.ts';
6
6
 
7
7
  export const getAppName = Effect.gen(function* () {
8
- const authedHttp = yield* InstantHttpAuthed;
8
+ const authedHttp = yield* SidekickHttpAuthed;
9
9
  const { appId } = yield* CurrentApp;
10
10
  const appInfo = yield* authedHttp
11
11
  .get(`/dash/apps/${appId}`)
@@ -1,6 +1,6 @@
1
1
  export function isHeadlessEnvironment(opts?: { headless?: boolean }) {
2
2
  const noBrowserMode = Boolean(
3
- process.env.INSTANT_CLI_NO_BROWSER || process.env.CI || opts?.headless,
3
+ process.env.SIDEKICK_CLI_NO_BROWSER || process.env.CI || opts?.headless,
4
4
  );
5
5
 
6
6
  // Check for common headless environment indicators
@@ -17,10 +17,8 @@ const toArray = <T>(value: Arrayable<T>): T[] =>
17
17
  * Resolve @sidekickdb packages from the CLI's own dependencies for
18
18
  * projects without node_modules. All @sidekickdb packages re-export
19
19
  * schema types from core, so a single core alias covers them all.
20
- * Legacy @instantdb/* names are aliased too so existing schema files
21
- * keep loading.
22
20
  */
23
- function getInstantAliases(): Record<string, string> | null {
21
+ function getSidekickAliases(): Record<string, string> | null {
24
22
  try {
25
23
  const require = createRequire(import.meta.url);
26
24
  const corePackageJson = require.resolve('@sidekickdb/core/package.json');
@@ -32,12 +30,6 @@ function getInstantAliases(): Record<string, string> | null {
32
30
  '@sidekickdb/svelte': coreDir,
33
31
  '@sidekickdb/vue': coreDir,
34
32
  '@sidekickdb/admin': coreDir,
35
- '@instantdb/core': coreDir,
36
- '@instantdb/react': coreDir,
37
- '@instantdb/react-native': coreDir,
38
- '@instantdb/svelte': coreDir,
39
- '@instantdb/vue': coreDir,
40
- '@instantdb/admin': coreDir,
41
33
  };
42
34
  } catch {
43
35
  return null;
@@ -81,12 +73,12 @@ export async function loadConfig<T>(
81
73
  opts: LoadConfigOptions<T>,
82
74
  ): Promise<LoadConfigResult<T>> {
83
75
  const projectInfo = await findProjectDir();
84
- const needsAliases =
85
- projectInfo?.type === 'deno' || projectInfo?.type === 'python';
76
+ // SidekickDB: Deno only, the Python SDK is removed.
77
+ const needsAliases = projectInfo?.type === 'deno';
86
78
 
87
79
  let res;
88
80
  if (needsAliases) {
89
- const alias = getInstantAliases();
81
+ const alias = getSidekickAliases();
90
82
  res = await _loadConfig(alias ? withAliases(opts, alias) : opts);
91
83
  } else {
92
84
  res = await _loadConfig(opts);
@@ -1,9 +1,4 @@
1
1
  import dotenvFlow from 'dotenv-flow';
2
- import { applyEnvAliases } from './envAliases.ts';
3
-
4
- // index.ts imports this module first, so this runs before any other module is
5
- // evaluated: some of them read INSTANT_ variables when they load.
6
- applyEnvAliases();
7
2
 
8
3
  export const loadEnv = () => {
9
4
  const envIndex = process.argv.indexOf('--env');
@@ -13,7 +8,4 @@ export const loadEnv = () => {
13
8
  silent: true,
14
9
  files: envFile ? [envFile] : undefined,
15
10
  });
16
-
17
- // After the env files: a SIDEKICK_ variable can come from them too.
18
- applyEnvAliases();
19
11
  };
@@ -0,0 +1,132 @@
1
+ // SidekickDB: the CLI reads its config files only under their sidekick.*
2
+ // names. A project that still has a file under the name from before the
3
+ // rename stops with a message that names both files, instead of the file
4
+ // being ignored (push would report it missing, pull would write a second
5
+ // file next to it). Only the old file's existence is checked; it is never
6
+ // read. The old prefix is spelled in two parts so that the rename rules
7
+ // leave it alone. Everything for this check is in this file.
8
+ import { statSync } from 'node:fs';
9
+ import { basename, dirname, join, parse, relative } from 'node:path';
10
+ import { Data, Effect } from 'effect';
11
+ import {
12
+ getEmailReadCandidates,
13
+ getPermsReadCandidates,
14
+ getSchemaReadCandidates,
15
+ } from './findConfigCandidates.ts';
16
+
17
+ const OLD_PREFIX = 'ins' + 'tant.';
18
+
19
+ export class OldConfigFileError extends Data.TaggedError('OldConfigFileError')<{
20
+ message: string;
21
+ }> {}
22
+
23
+ export type ConfigFileKind = 'schema' | 'perms' | 'email' | 'config';
24
+
25
+ const CONFIG_CANDIDATE = {
26
+ files: 'sidekick.config',
27
+ extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json'],
28
+ };
29
+
30
+ function candidates(kind: ConfigFileKind, emailPath?: string) {
31
+ switch (kind) {
32
+ case 'schema':
33
+ return getSchemaReadCandidates();
34
+ case 'perms':
35
+ return getPermsReadCandidates();
36
+ case 'email':
37
+ return getEmailReadCandidates(emailPath);
38
+ case 'config':
39
+ return [CONFIG_CANDIDATE];
40
+ }
41
+ }
42
+
43
+ const isFile = (path: string) => {
44
+ try {
45
+ return statSync(path).isFile();
46
+ } catch {
47
+ return false;
48
+ }
49
+ };
50
+
51
+ // The directories the loader (unconfig's findUp) searches: the working
52
+ // directory and each parent, up to but not including the filesystem root.
53
+ function searchedDirs(cwd: string) {
54
+ const root = parse(cwd).root;
55
+ const dirs: string[] = [];
56
+ let current = cwd;
57
+ while (current && current !== root) {
58
+ dirs.push(current);
59
+ const parent = dirname(current);
60
+ if (parent === current) break;
61
+ current = parent;
62
+ }
63
+ return dirs;
64
+ }
65
+
66
+ /**
67
+ * The old-named file to rename and its new name. The search covers the same
68
+ * directories and candidate places as the loader, but level by level: at
69
+ * each directory, from the working directory up, a sidekick.* file of this
70
+ * kind ends it, otherwise an old-named one at one of those places is
71
+ * reported. The loader goes candidate by candidate instead (each candidate
72
+ * through every level, the first with a match wins), so it may load a
73
+ * sidekick.* file further up than an old-named one this reports. That errs
74
+ * on the safe side: it stops whenever an old-named file is nearer than every
75
+ * sidekick.* file. An explicit path (an environment variable, --file) is used
76
+ * as given, so it is not checked.
77
+ */
78
+ export function findOldConfigFile(
79
+ kind: ConfigFileKind,
80
+ emailPath?: string,
81
+ ): { found: string; rename: string } | null {
82
+ if (
83
+ kind !== 'config' &&
84
+ (emailPath || process.env[`SIDEKICK_${kind.toUpperCase()}_FILE_PATH`])
85
+ )
86
+ return null;
87
+ const list = candidates(kind, emailPath);
88
+ if (list.some((c) => !c.extensions)) return null;
89
+ const cwd = process.cwd();
90
+ const paths = list.flatMap((c) =>
91
+ c.extensions!.map((ext) => `${c.files}.${ext}`),
92
+ );
93
+ for (const dir of searchedDirs(cwd)) {
94
+ if (paths.some((p) => isFile(join(dir, p)))) return null;
95
+ for (const p of paths) {
96
+ const old = join(
97
+ dirname(p),
98
+ basename(p).replace(/^sidekick\./, OLD_PREFIX),
99
+ );
100
+ if (isFile(join(dir, old)))
101
+ return {
102
+ found: relative(cwd, join(dir, old)),
103
+ rename: relative(cwd, join(dir, p)),
104
+ };
105
+ }
106
+ }
107
+ return null;
108
+ }
109
+
110
+ export function oldConfigFileError(
111
+ found: string,
112
+ rename: string,
113
+ kind: ConfigFileKind,
114
+ ) {
115
+ // Nothing imports the config file; the others are imported by the app.
116
+ const imports = kind === 'config' ? '' : ' (and update the imports of it)';
117
+ return new OldConfigFileError({
118
+ message: `Found ${found}, which SidekickDB no longer reads. Rename it to ${rename}${imports}.`,
119
+ });
120
+ }
121
+
122
+ /** Fails with OldConfigFileError for the first kind that has an old file. */
123
+ export const failOnOldConfigFiles = (
124
+ kinds: ConfigFileKind[],
125
+ emailPath?: string,
126
+ ) =>
127
+ Effect.gen(function* () {
128
+ for (const kind of kinds) {
129
+ const old = findOldConfigFile(kind, emailPath);
130
+ if (old) return yield* oldConfigFileError(old.found, old.rename, kind);
131
+ }
132
+ });
@@ -2,19 +2,19 @@ import { packageDirectory } from 'package-directory';
2
2
  import { findUp } from 'find-up-simple';
3
3
  import path from 'node:path';
4
4
 
5
- export type ProjectType = 'node' | 'deno' | 'python';
5
+ export type ProjectType = 'node' | 'deno';
6
6
 
7
7
  export interface ProjectInfo {
8
8
  dir: string;
9
9
  type: ProjectType;
10
10
  }
11
11
 
12
- // Same-directory tie-breaker: Deno > Python > Node. Deno may coexist
13
- // with package.json for npm interop; pyproject.toml signals Python.
12
+ // Same-directory tie-breaker: Deno > Node. Deno may coexist with
13
+ // package.json for npm interop.
14
+ // SidekickDB: no Python project type, the Python SDK is removed.
14
15
  const TYPE_PRIORITY: Record<ProjectType, number> = {
15
16
  deno: 0,
16
- python: 1,
17
- node: 2,
17
+ node: 1,
18
18
  };
19
19
 
20
20
  const depth = (filepath: string) => filepath.split(path.sep).length;
@@ -22,10 +22,9 @@ const depth = (filepath: string) => filepath.split(path.sep).length;
22
22
  export async function findProjectDir(
23
23
  cwd?: string,
24
24
  ): Promise<ProjectInfo | null> {
25
- const [denoJson, denoJsonc, pyproject, nodeDir] = await Promise.all([
25
+ const [denoJson, denoJsonc, nodeDir] = await Promise.all([
26
26
  findUp('deno.json', { cwd }),
27
27
  findUp('deno.jsonc', { cwd }),
28
- findUp('pyproject.toml', { cwd }),
29
28
  packageDirectory({ cwd }),
30
29
  ]);
31
30
 
@@ -34,14 +33,13 @@ export async function findProjectDir(
34
33
  const candidates: { file: string; type: ProjectType }[] = [];
35
34
  if (denoJson) candidates.push({ file: denoJson, type: 'deno' });
36
35
  if (denoJsonc) candidates.push({ file: denoJsonc, type: 'deno' });
37
- if (pyproject) candidates.push({ file: pyproject, type: 'python' });
38
36
  if (nodeDir) {
39
37
  candidates.push({ file: path.join(nodeDir, 'package.json'), type: 'node' });
40
38
  }
41
39
 
42
40
  if (candidates.length === 0) return null;
43
41
 
44
- // Nearest marker wins (deepest path), so a Python project nested in a
42
+ // Nearest marker wins (deepest path), so a Deno project nested in a
45
43
  // Node monorepo isn't misclassified by a parent's package.json.
46
44
  candidates.sort((a, b) => {
47
45
  const depthDiff = depth(b.file) - depth(a.file);