instant-cli 0.22.96-experimental.surgical.20765334274.1 → 0.22.96-experimental.surgical.20765817844.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > instant-cli@0.22.96-experimental.surgical.20765334274.1 build /home/runner/work/instant/instant/client/packages/cli
2
+ > instant-cli@0.22.96-experimental.surgical.20765817844.1 build /home/runner/work/instant/instant/client/packages/cli
3
3
  > rm -rf dist; tsc -p tsconfig.json
4
4
 
@@ -1,5 +1,9 @@
1
1
  import { test, expect } from 'vitest';
2
- import { i, schemaTypescriptFileToInstantSchema } from '@instantdb/platform';
2
+ import {
3
+ diffSchemas,
4
+ i,
5
+ schemaTypescriptFileToInstantSchema,
6
+ } from '@instantdb/platform';
3
7
  import { updateSchemaFile } from '../src/util/updateSchemaFile';
4
8
 
5
9
  test('throws when schema call is missing', async () => {
@@ -278,6 +282,37 @@ export default _schema;
278
282
  expect(result).toMatchSnapshot();
279
283
  });
280
284
 
285
+ test('adds multiple attrs to a single-line entity', async () => {
286
+ const oldFile = `
287
+ import { i } from '@instantdb/core';
288
+
289
+ const _schema = i.schema({
290
+ entities: {
291
+ projects: i.entity({ name: i.string() }),
292
+ },
293
+ links: {
294
+ },
295
+ rooms: {},
296
+ });
297
+
298
+ export default _schema;
299
+ `;
300
+ const serverSchema = i.schema({
301
+ entities: {
302
+ projects: i.entity({
303
+ name: i.string(),
304
+ status: i.string(),
305
+ priority: i.number(),
306
+ }),
307
+ },
308
+ links: {},
309
+ });
310
+
311
+ const result = await update(oldFile, serverSchema);
312
+
313
+ await expectNoDiff(result, serverSchema);
314
+ });
315
+
281
316
  test('inserts attrs into multi-line entities with indentation', async () => {
282
317
  const oldFile = `
283
318
  import { i } from '@instantdb/core';
@@ -312,6 +347,38 @@ export default _schema;
312
347
  expect(result).toMatchSnapshot();
313
348
  });
314
349
 
350
+ test('adds and updates attrs in a single-line entity', async () => {
351
+ const oldFile = `
352
+ import { i } from '@instantdb/core';
353
+
354
+ const _schema = i.schema({
355
+ entities: {
356
+ projects: i.entity({ name: i.string().optional(), code: i.string() }),
357
+ },
358
+ links: {
359
+ },
360
+ rooms: {},
361
+ });
362
+
363
+ export default _schema;
364
+ `;
365
+ const serverSchema = i.schema({
366
+ entities: {
367
+ projects: i.entity({
368
+ name: i.string(),
369
+ code: i.string().unique(),
370
+ status: i.string(),
371
+ priority: i.number(),
372
+ }),
373
+ },
374
+ links: {},
375
+ });
376
+
377
+ const result = await update(oldFile, serverSchema);
378
+
379
+ await expectNoDiff(result, serverSchema);
380
+ });
381
+
315
382
  test('handles quoted keys for entities, attrs, and links', async () => {
316
383
  const oldFile = `
317
384
  import { i } from '@instantdb/core';
@@ -395,6 +462,52 @@ export default _schema;
395
462
  expect(result).toMatchSnapshot();
396
463
  });
397
464
 
465
+ test('adds multiple links when links object is empty', async () => {
466
+ const oldFile = `
467
+ import { i } from '@instantdb/core';
468
+
469
+ const _schema = i.schema({
470
+ entities: {
471
+ todos: i.entity({
472
+ title: i.string(),
473
+ }),
474
+ users: i.entity({
475
+ email: i.string(),
476
+ }),
477
+ projects: i.entity({
478
+ name: i.string(),
479
+ }),
480
+ },
481
+ links: {
482
+ },
483
+ rooms: {},
484
+ });
485
+
486
+ export default _schema;
487
+ `;
488
+ const serverSchema = i.schema({
489
+ entities: {
490
+ todos: i.entity({ title: i.string() }),
491
+ users: i.entity({ email: i.string() }),
492
+ projects: i.entity({ name: i.string() }),
493
+ },
494
+ links: {
495
+ todoOwner: {
496
+ forward: { on: 'todos', has: 'one', label: 'owner' },
497
+ reverse: { on: 'users', has: 'many', label: 'todos' },
498
+ },
499
+ projectTodos: {
500
+ forward: { on: 'projects', has: 'many', label: 'todos' },
501
+ reverse: { on: 'todos', has: 'one', label: 'project' },
502
+ },
503
+ },
504
+ });
505
+
506
+ const result = await update(oldFile, serverSchema);
507
+
508
+ await expectNoDiff(result, serverSchema);
509
+ });
510
+
398
511
  test('removes the last link cleanly', async () => {
399
512
  const oldFile = `
400
513
  import { i } from '@instantdb/core';
@@ -436,3 +549,9 @@ async function update(oldFile: string, serverSchema: any) {
436
549
  const localSchema = schemaTypescriptFileToInstantSchema(oldFile);
437
550
  return updateSchemaFile(oldFile, localSchema, serverSchema);
438
551
  }
552
+
553
+ async function expectNoDiff(result: string, serverSchema: any) {
554
+ const parsed = schemaTypescriptFileToInstantSchema(result);
555
+ const diff = await diffSchemas(parsed, serverSchema, async (created) => created, {});
556
+ expect(diff).toEqual([]);
557
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "instant-cli",
3
3
  "type": "module",
4
- "version": "0.22.96-experimental.surgical.20765334274.1",
4
+ "version": "0.22.96-experimental.surgical.20765817844.1",
5
5
  "description": "Instant's CLI",
6
6
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/cli",
7
7
  "repository": {
@@ -41,9 +41,9 @@
41
41
  "strip-ansi": "^7.1.2",
42
42
  "terminal-link": "^3.0.0",
43
43
  "unconfig": "^0.5.5",
44
- "@instantdb/core": "0.22.96-experimental.surgical.20765334274.1",
45
- "@instantdb/platform": "0.22.96-experimental.surgical.20765334274.1",
46
- "@instantdb/version": "0.22.96-experimental.surgical.20765334274.1"
44
+ "@instantdb/core": "0.22.96-experimental.surgical.20765817844.1",
45
+ "@instantdb/platform": "0.22.96-experimental.surgical.20765817844.1",
46
+ "@instantdb/version": "0.22.96-experimental.surgical.20765817844.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@babel/core": "^7.17.9",