instant-cli 0.22.95-experimental.surgical.20386947966.1 → 0.22.96-experimental.add-posthog-frontend.20386914944.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "instant-cli",
3
3
  "type": "module",
4
- "version": "0.22.95-experimental.surgical.20386947966.1",
4
+ "version": "0.22.96-experimental.add-posthog-frontend.20386914944.1",
5
5
  "description": "Instant's CLI",
6
6
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/cli",
7
7
  "repository": {
@@ -21,8 +21,6 @@
21
21
  "instant-cli": "bin/index.js"
22
22
  },
23
23
  "dependencies": {
24
- "acorn": "^8.15.0",
25
- "acorn-typescript": "^1.4.13",
26
24
  "ansi-escapes": "4.3.2",
27
25
  "boxen": "^8.0.1",
28
26
  "chalk": "^5.3.0",
@@ -41,9 +39,9 @@
41
39
  "strip-ansi": "^7.1.2",
42
40
  "terminal-link": "^3.0.0",
43
41
  "unconfig": "^0.5.5",
44
- "@instantdb/version": "0.22.95-experimental.surgical.20386947966.1",
45
- "@instantdb/core": "0.22.95-experimental.surgical.20386947966.1",
46
- "@instantdb/platform": "0.22.95-experimental.surgical.20386947966.1"
42
+ "@instantdb/core": "0.22.96-experimental.add-posthog-frontend.20386914944.1",
43
+ "@instantdb/version": "0.22.96-experimental.add-posthog-frontend.20386914944.1",
44
+ "@instantdb/platform": "0.22.96-experimental.add-posthog-frontend.20386914944.1"
47
45
  },
48
46
  "devDependencies": {
49
47
  "@babel/core": "^7.17.9",
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  PlatformApi,
11
11
  } from '@instantdb/platform';
12
12
  import version from './version.js';
13
+ import { existsSync } from 'fs';
13
14
  import { mkdir, writeFile, readFile, unlink } from 'fs/promises';
14
15
  import path, { join } from 'path';
15
16
  import { randomUUID } from 'crypto';
@@ -50,8 +51,6 @@ import {
50
51
  getPermsPathToWrite,
51
52
  } from './util/findConfigCandidates.js';
52
53
 
53
- import { updateSchemaFile } from './util/updateSchemaFile.js';
54
-
55
54
  const execAsync = promisify(exec);
56
55
 
57
56
  loadEnv();
@@ -479,10 +478,6 @@ program
479
478
  '-p --package <react|react-native|core|admin>',
480
479
  'Which package to automatically install if there is not one installed already.',
481
480
  )
482
- .option(
483
- '--experimental-type-preservation',
484
- '[Experimental] Preserve manual type changes and schema edits when pulling schema',
485
- )
486
481
  .description('Pull schema and perm files from production.')
487
482
  .addHelpText(
488
483
  'after',
@@ -660,7 +655,7 @@ async function handlePull(bag, opts) {
660
655
  );
661
656
  return;
662
657
  }
663
- await pull(bag, appId, { ...pkgAndAuthInfo, ...opts });
658
+ await pull(bag, appId, pkgAndAuthInfo);
664
659
  }
665
660
 
666
661
  async function push(bag, appId, opts) {
@@ -769,6 +764,7 @@ async function login(options) {
769
764
  debugName: 'Login register',
770
765
  errorMessage: 'Failed to register login.',
771
766
  noAuth: true,
767
+ command: 'login',
772
768
  });
773
769
 
774
770
  if (!registerRes.ok) {
@@ -934,6 +930,7 @@ async function promptCreateApp(opts) {
934
930
  method: 'GET',
935
931
  path: '/dash',
936
932
  errorMessage: 'Failed to fetch apps.',
933
+ command: 'init',
937
934
  });
938
935
  if (!res.ok) {
939
936
  return { ok: false };
@@ -966,6 +963,7 @@ async function promptCreateApp(opts) {
966
963
  debugName: 'App create',
967
964
  errorMessage: 'Failed to create app.',
968
965
  body: app,
966
+ command: 'init',
969
967
  });
970
968
 
971
969
  if (!appRes.ok) return { ok: false };
@@ -984,6 +982,7 @@ async function promptImportAppOrCreateApp() {
984
982
  method: 'GET',
985
983
  path: '/dash',
986
984
  errorMessage: 'Failed to fetch apps.',
985
+ command: 'init',
987
986
  });
988
987
  if (!res.ok) {
989
988
  return { ok: false };
@@ -1003,6 +1002,7 @@ async function promptImportAppOrCreateApp() {
1003
1002
  method: 'GET',
1004
1003
  path: `/dash/orgs/${orgId}`,
1005
1004
  errorMessage: 'Failed to fetch apps.',
1005
+ command: 'init',
1006
1006
  });
1007
1007
  if (!orgsRes.ok) {
1008
1008
  throw new Error('Failed to fetch org apps');
@@ -1032,6 +1032,7 @@ async function createApp(title, orgId) {
1032
1032
  debugName: 'App create',
1033
1033
  errorMessage: 'Failed to create app.',
1034
1034
  body: app,
1035
+ command: 'init',
1035
1036
  });
1036
1037
  if (!appRes.ok) throw new Error('Failed to create app');
1037
1038
  return { appId: id, adminToken: token };
@@ -1188,16 +1189,14 @@ async function getOrPromptPackageAndAuthInfoWithErrorLogging(opts) {
1188
1189
  return { pkgDir, projectType, instantModuleName, authToken };
1189
1190
  }
1190
1191
 
1191
- async function pullSchema(
1192
- appId,
1193
- { pkgDir, instantModuleName, experimentalTypePreservation },
1194
- ) {
1192
+ async function pullSchema(appId, { pkgDir, instantModuleName }) {
1195
1193
  console.log('Pulling schema...');
1196
1194
 
1197
1195
  const pullRes = await fetchJson({
1198
1196
  path: `/dash/apps/${appId}/schema/pull`,
1199
1197
  debugName: 'Schema pull',
1200
1198
  errorMessage: 'Failed to pull schema.',
1199
+ command: 'pull',
1201
1200
  });
1202
1201
 
1203
1202
  if (!pullRes.ok) return pullRes;
@@ -1229,34 +1228,15 @@ async function pullSchema(
1229
1228
  const shortSchemaPath = getSchemaPathToWrite(prev?.path);
1230
1229
  const schemaPath = join(pkgDir, shortSchemaPath);
1231
1230
 
1232
- const serverSchema = apiSchemaToInstantSchemaDef(pullRes.data.schema);
1233
- let newSchemaContent;
1234
-
1235
- if (prev && experimentalTypePreservation) {
1236
- try {
1237
- const oldSchemaContent = await readFile(prev.path, 'utf-8');
1238
- newSchemaContent = await updateSchemaFile(
1239
- oldSchemaContent,
1240
- prev.schema,
1241
- serverSchema,
1242
- );
1243
- } catch (e) {
1244
- warn(
1245
- 'Failed to update schema with existing file. Overwriting instead.',
1246
- e,
1247
- );
1248
- }
1249
- }
1250
-
1251
- if (!newSchemaContent) {
1252
- newSchemaContent = generateSchemaTypescriptFile(
1231
+ await writeTypescript(
1232
+ schemaPath,
1233
+ generateSchemaTypescriptFile(
1253
1234
  prev?.schema,
1254
- serverSchema,
1235
+ apiSchemaToInstantSchemaDef(pullRes.data.schema),
1255
1236
  instantModuleName,
1256
- );
1257
- }
1258
-
1259
- await writeTypescript(schemaPath, newSchemaContent, 'utf-8');
1237
+ ),
1238
+ 'utf-8',
1239
+ );
1260
1240
 
1261
1241
  console.log('✅ Wrote schema to ' + shortSchemaPath);
1262
1242
 
@@ -1270,6 +1250,7 @@ async function pullPerms(appId, { pkgDir, instantModuleName }) {
1270
1250
  path: `/dash/apps/${appId}/perms/pull`,
1271
1251
  debugName: 'Perms pull',
1272
1252
  errorMessage: 'Failed to pull perms.',
1253
+ command: 'pull',
1273
1254
  });
1274
1255
 
1275
1256
  if (!pullRes.ok) return pullRes;
@@ -1516,6 +1497,7 @@ async function waitForIndexingJobsToFinish(appId, data) {
1516
1497
  method: 'GET',
1517
1498
  path: `/dash/apps/${appId}/indexing-jobs/group/${groupId}`,
1518
1499
  errorMessage: 'Failed to check indexing status.',
1500
+ command: 'push',
1519
1501
  });
1520
1502
  if (!res.ok) {
1521
1503
  break;
@@ -1585,6 +1567,7 @@ async function pushSchema(appId, opts) {
1585
1567
  path: `/dash/apps/${appId}/schema/pull`,
1586
1568
  debugName: 'Schema plan',
1587
1569
  errorMessage: 'Failed to get old schema.',
1570
+ command: 'push',
1588
1571
  });
1589
1572
 
1590
1573
  if (!pulledSchemaResponse.ok) return pulledSchemaResponse;
@@ -1675,6 +1658,7 @@ async function pushSchema(appId, opts) {
1675
1658
  body: {
1676
1659
  steps: txSteps,
1677
1660
  },
1661
+ command: 'push',
1678
1662
  });
1679
1663
  console.log(chalk.green('Schema updated!'));
1680
1664
  if (!applyRes.ok) return applyRes;
@@ -1699,6 +1683,7 @@ async function claimEphemeralApp(appId, adminToken) {
1699
1683
  path: `/dash/apps/ephemeral/${appId}/claim`,
1700
1684
  debugName: 'Claim ephemeral app',
1701
1685
  errorMessage: 'Failed to claim ephemeral app.',
1686
+ command: 'claim',
1702
1687
  });
1703
1688
 
1704
1689
  if (!res.ok) return res;
@@ -1719,6 +1704,7 @@ async function pushPerms(appId) {
1719
1704
  path: `/dash/apps/${appId}/perms/pull`,
1720
1705
  debugName: 'Perms pull',
1721
1706
  errorMessage: 'Failed to pull perms.',
1707
+ command: 'push',
1722
1708
  });
1723
1709
 
1724
1710
  if (!prodPerms.ok) return prodPerms;
@@ -1758,6 +1744,7 @@ async function pushPerms(appId) {
1758
1744
  body: {
1759
1745
  code: res.perms,
1760
1746
  },
1747
+ command: 'push',
1761
1748
  });
1762
1749
 
1763
1750
  if (!permsRes.ok) return permsRes;
@@ -1778,6 +1765,7 @@ async function waitForAuthToken({ secret }) {
1778
1765
  body: { secret },
1779
1766
  noAuth: true,
1780
1767
  noLogError: true,
1768
+ command: 'login',
1781
1769
  });
1782
1770
  if (authCheckRes.ok) {
1783
1771
  return authCheckRes.data;
@@ -1806,6 +1794,7 @@ async function waitForAuthToken({ secret }) {
1806
1794
  * @param {Object} [options.body=undefined]
1807
1795
  * @param {boolean} [options.noAuth]
1808
1796
  * @param {boolean} [options.noLogError]
1797
+ * @param {string} [options.command] - The CLI command being executed (e.g., 'push', 'pull', 'login')
1809
1798
  * @returns {Promise<{ ok: boolean; data: any }>}
1810
1799
  */
1811
1800
  async function fetchJson({
@@ -1816,6 +1805,7 @@ async function fetchJson({
1816
1805
  method,
1817
1806
  noAuth,
1818
1807
  noLogError,
1808
+ command,
1819
1809
  }) {
1820
1810
  const withAuth = !noAuth;
1821
1811
  const withErrorLogging = !noLogError;
@@ -1834,7 +1824,9 @@ async function fetchJson({
1834
1824
  headers: {
1835
1825
  ...(withAuth ? { Authorization: `Bearer ${authToken}` } : {}),
1836
1826
  'Content-Type': 'application/json',
1837
- 'Instant-CLI-Version': version,
1827
+ 'X-Instant-Source': 'instant-cli',
1828
+ 'X-Instant-Version': version,
1829
+ ...(command ? { 'X-Instant-Command': command } : {}),
1838
1830
  },
1839
1831
  body: body ? JSON.stringify(body) : undefined,
1840
1832
  signal: AbortSignal.timeout(timeoutMs),
@@ -1,248 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`adds a link when links object is empty 1`] = `
4
- "
5
- import { i } from '@instantdb/core';
6
-
7
- const _schema = i.schema({
8
- entities: {
9
- todos: i.entity({
10
- title: i.string(),
11
- }),
12
- users: i.entity({
13
- email: i.string(),
14
- }),
15
- },
16
- links: {
17
- todoOwner: {
18
- forward: {
19
- on: 'todos',
20
- has: 'one',
21
- label: 'owner',
22
- },
23
- reverse: {
24
- on: 'users',
25
- has: 'many',
26
- label: 'todos',
27
- },
28
- },
29
- },
30
- rooms: {},
31
- });
32
-
33
- export default _schema;
34
- "
35
- `;
36
-
37
- exports[`drops constraints removed by server 1`] = `
38
- "
39
- import { i } from '@instantdb/core';
40
-
41
- const _schema = i.schema({
42
- entities: {
43
- todos: i.entity({
44
- title: i.string(),
45
- done: i.boolean().optional(),
46
- }),
47
- },
48
- links: {},
49
- rooms: {},
50
- });
51
-
52
- export default _schema;
53
- "
54
- `;
55
-
56
- exports[`handles quoted keys for entities, attrs, and links 1`] = `
57
- "
58
- import { i } from '@instantdb/core';
59
-
60
- const _schema = i.schema({
61
- entities: {
62
- todos: i.entity({
63
- title: i.string(),
64
- }),
65
- users: i.entity({
66
- email: i.string(),
67
- }),
68
- 'user-profiles': i.entity({
69
- 'display-name': i.string(),
70
- 'avatar-url': i.string(),
71
- }),
72
- },
73
- links: {
74
- 'todo-owner': {
75
- forward: {
76
- on: 'todos',
77
- has: 'one',
78
- label: 'owner',
79
- },
80
- reverse: {
81
- on: 'users',
82
- has: 'many',
83
- label: 'todos',
84
- },
85
- },
86
- },
87
- rooms: {},
88
- });
89
-
90
- export default _schema;
91
- "
92
- `;
93
-
94
- exports[`inserts attrs into multi-line entities with indentation 1`] = `
95
- "
96
- import { i } from '@instantdb/core';
97
-
98
- const _schema = i.schema({
99
- entities: {
100
- todos: i.entity({
101
- title: i.string(),
102
- done: i.boolean().optional(),
103
- priority: i.number(),
104
- }),
105
- },
106
- links: {},
107
- rooms: {},
108
- });
109
-
110
- export default _schema;
111
- "
112
- `;
113
-
114
- exports[`preserves type params across chained calls 1`] = `
115
- "
116
- import { i } from '@instantdb/core';
117
- import { Label } from './types';
118
-
119
- const _schema = i.schema({
120
- entities: {
121
- todos: i.entity({
122
- title: i.string(),
123
- status: i.string<'todo' | 'done'>().unique().indexed(),
124
- labels: i.json<Label[]>(),
125
- metadata: i.json(),
126
- }),
127
- users: i.entity({
128
- email: i.string().unique(),
129
- }),
130
- },
131
- links: {},
132
- rooms: {},
133
- });
134
-
135
- export default _schema;
136
- "
137
- `;
138
-
139
- exports[`removes a link with surrounding comments and commas 1`] = `
140
- "
141
- import { i } from '@instantdb/core';
142
-
143
- const _schema = i.schema({
144
- entities: {
145
- todos: i.entity({
146
- title: i.string(),
147
- }),
148
- users: i.entity({
149
- email: i.string(),
150
- }),
151
- projects: i.entity({
152
- name: i.string(),
153
- }),
154
- },
155
- links: {
156
- // owner link
157
- /* project link */
158
- projectTodos: {
159
- forward: { on: 'projects', has: 'many', label: 'todos' },
160
- reverse: { on: 'todos', has: 'one', label: 'project' },
161
- },
162
- },
163
- rooms: {},
164
- });
165
-
166
- export default _schema;
167
- "
168
- `;
169
-
170
- exports[`removes the last link cleanly 1`] = `
171
- "
172
- import { i } from '@instantdb/core';
173
-
174
- const _schema = i.schema({
175
- entities: {
176
- todos: i.entity({
177
- title: i.string(),
178
- }),
179
- users: i.entity({
180
- email: i.string(),
181
- }),
182
- },
183
- links: {},
184
- rooms: {},
185
- });
186
-
187
- export default _schema;
188
- "
189
- `;
190
-
191
- exports[`updates link details 1`] = `
192
- "
193
- import { i } from '@instantdb/core';
194
-
195
- const _schema = i.schema({
196
- entities: {
197
- todos: i.entity({
198
- title: i.string(),
199
- }),
200
- users: i.entity({
201
- email: i.string(),
202
- }),
203
- },
204
- links: {
205
- todoOwner: {
206
- forward: {
207
- on: 'todos',
208
- has: 'one',
209
- label: 'owner',
210
- required: true,
211
- onDelete: 'cascade',
212
- },
213
- reverse: {
214
- on: 'users',
215
- has: 'many',
216
- label: 'todos',
217
- onDelete: 'cascade',
218
- },
219
- },
220
- },
221
- rooms: {},
222
- });
223
-
224
- export default _schema;
225
- "
226
- `;
227
-
228
- exports[`updates single-line entity in place 1`] = `
229
- "
230
- import { i } from '@instantdb/core';
231
-
232
- const _schema = i.schema({
233
- entities: {
234
- projects: i.entity({
235
- name: i.string(),
236
- status: i.string(),
237
- }),
238
- todos: i.entity({
239
- title: i.string(),
240
- }),
241
- },
242
- links: {},
243
- rooms: {},
244
- });
245
-
246
- export default _schema;
247
- "
248
- `;