instant-cli 0.22.96-experimental.drewh-ts-target.20761590091.1 → 0.22.96-experimental.surgical.20765334274.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/.turbo/turbo-build.log +1 -1
- package/__tests__/__snapshots__/updateSchemaFile.test.ts.snap +248 -0
- package/__tests__/updateSchemaFile.test.ts +438 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1152 -1044
- package/dist/index.js.map +1 -1
- package/dist/rename.js +69 -58
- package/dist/rename.js.map +1 -1
- package/dist/renderSchemaPlan.js +22 -10
- package/dist/renderSchemaPlan.js.map +1 -1
- package/dist/ui/index.js +102 -115
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/lib.js +30 -29
- package/dist/ui/lib.js.map +1 -1
- package/dist/util/fs.js +30 -17
- package/dist/util/fs.js.map +1 -1
- package/dist/util/isHeadlessEnvironment.js +1 -1
- package/dist/util/isHeadlessEnvironment.js.map +1 -1
- package/dist/util/loadConfig.js +32 -32
- package/dist/util/loadConfig.js.map +1 -1
- package/dist/util/packageManager.js +37 -26
- package/dist/util/packageManager.js.map +1 -1
- package/dist/util/projectDir.js +27 -16
- package/dist/util/projectDir.js.map +1 -1
- package/dist/util/promptOk.js +21 -14
- package/dist/util/promptOk.js.map +1 -1
- package/dist/util/renamePrompt.js +2 -4
- package/dist/util/renamePrompt.js.map +1 -1
- package/dist/util/updateSchemaFile.d.ts +3 -0
- package/dist/util/updateSchemaFile.d.ts.map +1 -0
- package/dist/util/updateSchemaFile.js +610 -0
- package/dist/util/updateSchemaFile.js.map +1 -0
- package/package.json +4 -4
- package/src/index.js +19 -10
- package/src/util/updateSchemaFile.ts +760 -0
- package/__tests__/mergeSchema.test.ts +0 -197
- package/dist/util/mergeSchema.d.ts +0 -2
- package/dist/util/mergeSchema.d.ts.map +0 -1
- package/dist/util/mergeSchema.js +0 -334
- package/dist/util/mergeSchema.js.map +0 -1
- package/src/util/mergeSchema.js +0 -364
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> instant-cli@0.22.96-experimental.
|
|
2
|
+
> instant-cli@0.22.96-experimental.surgical.20765334274.1 build /home/runner/work/instant/instant/client/packages/cli
|
|
3
3
|
> rm -rf dist; tsc -p tsconfig.json
|
|
4
4
|
|
|
@@ -0,0 +1,248 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { test, expect } from 'vitest';
|
|
2
|
+
import { i, schemaTypescriptFileToInstantSchema } from '@instantdb/platform';
|
|
3
|
+
import { updateSchemaFile } from '../src/util/updateSchemaFile';
|
|
4
|
+
|
|
5
|
+
test('throws when schema call is missing', async () => {
|
|
6
|
+
const oldFile = `
|
|
7
|
+
import { i } from '@instantdb/core';
|
|
8
|
+
|
|
9
|
+
export const nope = 1;
|
|
10
|
+
`;
|
|
11
|
+
const schema = i.schema({
|
|
12
|
+
entities: { todos: i.entity({ title: i.string() }) },
|
|
13
|
+
links: {},
|
|
14
|
+
});
|
|
15
|
+
await expect(updateSchemaFile(oldFile, schema, schema)).rejects.toThrow(
|
|
16
|
+
'Could not find i.schema',
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('throws when entities object is missing', async () => {
|
|
21
|
+
const oldFile = `
|
|
22
|
+
import { i } from '@instantdb/core';
|
|
23
|
+
|
|
24
|
+
const _schema = i.schema({
|
|
25
|
+
links: {},
|
|
26
|
+
rooms: {},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default _schema;
|
|
30
|
+
`;
|
|
31
|
+
const schema = i.schema({
|
|
32
|
+
entities: { todos: i.entity({ title: i.string() }) },
|
|
33
|
+
links: {},
|
|
34
|
+
});
|
|
35
|
+
await expect(updateSchemaFile(oldFile, schema, schema)).rejects.toThrow(
|
|
36
|
+
'entities object',
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('throws when links object is missing', async () => {
|
|
41
|
+
const oldFile = `
|
|
42
|
+
import { i } from '@instantdb/core';
|
|
43
|
+
|
|
44
|
+
const _schema = i.schema({
|
|
45
|
+
entities: {
|
|
46
|
+
todos: i.entity({
|
|
47
|
+
title: i.string(),
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
rooms: {},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default _schema;
|
|
54
|
+
`;
|
|
55
|
+
const schema = i.schema({
|
|
56
|
+
entities: { todos: i.entity({ title: i.string() }) },
|
|
57
|
+
links: {},
|
|
58
|
+
});
|
|
59
|
+
await expect(updateSchemaFile(oldFile, schema, schema)).rejects.toThrow(
|
|
60
|
+
'links object',
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('preserves type params across chained calls', async () => {
|
|
65
|
+
const oldFile = `
|
|
66
|
+
import { i } from '@instantdb/core';
|
|
67
|
+
import { Label } from './types';
|
|
68
|
+
|
|
69
|
+
const _schema = i.schema({
|
|
70
|
+
entities: {
|
|
71
|
+
todos: i.entity({
|
|
72
|
+
title: i.string(),
|
|
73
|
+
status: i.string<'todo' | 'done'>().optional().indexed(),
|
|
74
|
+
labels: i.json<Label[]>(),
|
|
75
|
+
}),
|
|
76
|
+
users: i.entity({
|
|
77
|
+
email: i.string(),
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
links: {
|
|
81
|
+
},
|
|
82
|
+
rooms: {},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export default _schema;
|
|
86
|
+
`;
|
|
87
|
+
const serverSchema = i.schema({
|
|
88
|
+
entities: {
|
|
89
|
+
todos: i.entity({
|
|
90
|
+
title: i.string(),
|
|
91
|
+
status: i.string().unique().indexed(),
|
|
92
|
+
labels: i.json(),
|
|
93
|
+
metadata: i.json(),
|
|
94
|
+
}),
|
|
95
|
+
users: i.entity({
|
|
96
|
+
email: i.string().unique(),
|
|
97
|
+
}),
|
|
98
|
+
},
|
|
99
|
+
links: {},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const result = await update(oldFile, serverSchema);
|
|
103
|
+
|
|
104
|
+
expect(result).toMatchSnapshot();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('drops constraints removed by server', async () => {
|
|
108
|
+
const oldFile = `
|
|
109
|
+
import { i } from '@instantdb/core';
|
|
110
|
+
|
|
111
|
+
const _schema = i.schema({
|
|
112
|
+
entities: {
|
|
113
|
+
todos: i.entity({
|
|
114
|
+
title: i.string().unique().indexed().optional(),
|
|
115
|
+
done: i.boolean().optional(),
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
links: {
|
|
119
|
+
},
|
|
120
|
+
rooms: {},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export default _schema;
|
|
124
|
+
`;
|
|
125
|
+
const serverSchema = i.schema({
|
|
126
|
+
entities: {
|
|
127
|
+
todos: i.entity({
|
|
128
|
+
title: i.string(),
|
|
129
|
+
done: i.boolean().optional(),
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
links: {},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const result = await update(oldFile, serverSchema);
|
|
136
|
+
|
|
137
|
+
expect(result).toMatchSnapshot();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('updates link details', async () => {
|
|
141
|
+
const oldFile = `
|
|
142
|
+
import { i } from '@instantdb/core';
|
|
143
|
+
|
|
144
|
+
const _schema = i.schema({
|
|
145
|
+
entities: {
|
|
146
|
+
todos: i.entity({
|
|
147
|
+
title: i.string(),
|
|
148
|
+
}),
|
|
149
|
+
users: i.entity({
|
|
150
|
+
email: i.string(),
|
|
151
|
+
}),
|
|
152
|
+
},
|
|
153
|
+
links: {
|
|
154
|
+
todoOwner: {
|
|
155
|
+
forward: { on: 'todos', has: 'one', label: 'owner' },
|
|
156
|
+
reverse: { on: 'users', has: 'many', label: 'todos' },
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
rooms: {},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export default _schema;
|
|
163
|
+
`;
|
|
164
|
+
const serverSchema = i.schema({
|
|
165
|
+
entities: {
|
|
166
|
+
todos: i.entity({ title: i.string() }),
|
|
167
|
+
users: i.entity({ email: i.string() }),
|
|
168
|
+
},
|
|
169
|
+
links: {
|
|
170
|
+
todoOwner: {
|
|
171
|
+
forward: {
|
|
172
|
+
on: 'todos',
|
|
173
|
+
has: 'one',
|
|
174
|
+
label: 'owner',
|
|
175
|
+
required: true,
|
|
176
|
+
onDelete: 'cascade',
|
|
177
|
+
},
|
|
178
|
+
reverse: {
|
|
179
|
+
on: 'users',
|
|
180
|
+
has: 'many',
|
|
181
|
+
label: 'todos',
|
|
182
|
+
onDelete: 'cascade',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const result = await update(oldFile, serverSchema);
|
|
189
|
+
|
|
190
|
+
expect(result).toMatchSnapshot();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('removes a link with surrounding comments and commas', async () => {
|
|
194
|
+
const oldFile = `
|
|
195
|
+
import { i } from '@instantdb/core';
|
|
196
|
+
|
|
197
|
+
const _schema = i.schema({
|
|
198
|
+
entities: {
|
|
199
|
+
todos: i.entity({
|
|
200
|
+
title: i.string(),
|
|
201
|
+
}),
|
|
202
|
+
users: i.entity({
|
|
203
|
+
email: i.string(),
|
|
204
|
+
}),
|
|
205
|
+
projects: i.entity({
|
|
206
|
+
name: i.string(),
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
209
|
+
links: {
|
|
210
|
+
// owner link
|
|
211
|
+
todoOwner: {
|
|
212
|
+
forward: { on: 'todos', has: 'one', label: 'owner' },
|
|
213
|
+
reverse: { on: 'users', has: 'many', label: 'todos' },
|
|
214
|
+
},
|
|
215
|
+
/* project link */
|
|
216
|
+
projectTodos: {
|
|
217
|
+
forward: { on: 'projects', has: 'many', label: 'todos' },
|
|
218
|
+
reverse: { on: 'todos', has: 'one', label: 'project' },
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
rooms: {},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export default _schema;
|
|
225
|
+
`;
|
|
226
|
+
const serverSchema = i.schema({
|
|
227
|
+
entities: {
|
|
228
|
+
todos: i.entity({ title: i.string() }),
|
|
229
|
+
users: i.entity({ email: i.string() }),
|
|
230
|
+
projects: i.entity({ name: i.string() }),
|
|
231
|
+
},
|
|
232
|
+
links: {
|
|
233
|
+
projectTodos: {
|
|
234
|
+
forward: { on: 'projects', has: 'many', label: 'todos' },
|
|
235
|
+
reverse: { on: 'todos', has: 'one', label: 'project' },
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const result = await update(oldFile, serverSchema);
|
|
241
|
+
|
|
242
|
+
expect(result).toMatchSnapshot();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('updates single-line entity in place', async () => {
|
|
246
|
+
const oldFile = `
|
|
247
|
+
import { i } from '@instantdb/core';
|
|
248
|
+
|
|
249
|
+
const _schema = i.schema({
|
|
250
|
+
entities: {
|
|
251
|
+
projects: i.entity({ name: i.string() }),
|
|
252
|
+
todos: i.entity({
|
|
253
|
+
title: i.string(),
|
|
254
|
+
}),
|
|
255
|
+
},
|
|
256
|
+
links: {
|
|
257
|
+
},
|
|
258
|
+
rooms: {},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
export default _schema;
|
|
262
|
+
`;
|
|
263
|
+
const serverSchema = i.schema({
|
|
264
|
+
entities: {
|
|
265
|
+
projects: i.entity({
|
|
266
|
+
name: i.string(),
|
|
267
|
+
status: i.string(),
|
|
268
|
+
}),
|
|
269
|
+
todos: i.entity({
|
|
270
|
+
title: i.string(),
|
|
271
|
+
}),
|
|
272
|
+
},
|
|
273
|
+
links: {},
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const result = await update(oldFile, serverSchema);
|
|
277
|
+
|
|
278
|
+
expect(result).toMatchSnapshot();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('inserts attrs into multi-line entities with indentation', async () => {
|
|
282
|
+
const oldFile = `
|
|
283
|
+
import { i } from '@instantdb/core';
|
|
284
|
+
|
|
285
|
+
const _schema = i.schema({
|
|
286
|
+
entities: {
|
|
287
|
+
todos: i.entity({
|
|
288
|
+
title: i.string(),
|
|
289
|
+
done: i.boolean().optional(),
|
|
290
|
+
}),
|
|
291
|
+
},
|
|
292
|
+
links: {
|
|
293
|
+
},
|
|
294
|
+
rooms: {},
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
export default _schema;
|
|
298
|
+
`;
|
|
299
|
+
const serverSchema = i.schema({
|
|
300
|
+
entities: {
|
|
301
|
+
todos: i.entity({
|
|
302
|
+
title: i.string(),
|
|
303
|
+
done: i.boolean().optional(),
|
|
304
|
+
priority: i.number(),
|
|
305
|
+
}),
|
|
306
|
+
},
|
|
307
|
+
links: {},
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const result = await update(oldFile, serverSchema);
|
|
311
|
+
|
|
312
|
+
expect(result).toMatchSnapshot();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test('handles quoted keys for entities, attrs, and links', async () => {
|
|
316
|
+
const oldFile = `
|
|
317
|
+
import { i } from '@instantdb/core';
|
|
318
|
+
|
|
319
|
+
const _schema = i.schema({
|
|
320
|
+
entities: {
|
|
321
|
+
todos: i.entity({
|
|
322
|
+
title: i.string(),
|
|
323
|
+
}),
|
|
324
|
+
users: i.entity({
|
|
325
|
+
email: i.string(),
|
|
326
|
+
}),
|
|
327
|
+
'user-profiles': i.entity({
|
|
328
|
+
'display-name': i.string(),
|
|
329
|
+
}),
|
|
330
|
+
},
|
|
331
|
+
links: {
|
|
332
|
+
},
|
|
333
|
+
rooms: {},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
export default _schema;
|
|
337
|
+
`;
|
|
338
|
+
const serverSchema = i.schema({
|
|
339
|
+
entities: {
|
|
340
|
+
todos: i.entity({ title: i.string() }),
|
|
341
|
+
users: i.entity({ email: i.string() }),
|
|
342
|
+
'user-profiles': i.entity({
|
|
343
|
+
'display-name': i.string(),
|
|
344
|
+
'avatar-url': i.string(),
|
|
345
|
+
}),
|
|
346
|
+
},
|
|
347
|
+
links: {
|
|
348
|
+
'todo-owner': {
|
|
349
|
+
forward: { on: 'todos', has: 'one', label: 'owner' },
|
|
350
|
+
reverse: { on: 'users', has: 'many', label: 'todos' },
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const result = await update(oldFile, serverSchema);
|
|
356
|
+
|
|
357
|
+
expect(result).toMatchSnapshot();
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('adds a link when links object is empty', async () => {
|
|
361
|
+
const oldFile = `
|
|
362
|
+
import { i } from '@instantdb/core';
|
|
363
|
+
|
|
364
|
+
const _schema = i.schema({
|
|
365
|
+
entities: {
|
|
366
|
+
todos: i.entity({
|
|
367
|
+
title: i.string(),
|
|
368
|
+
}),
|
|
369
|
+
users: i.entity({
|
|
370
|
+
email: i.string(),
|
|
371
|
+
}),
|
|
372
|
+
},
|
|
373
|
+
links: {
|
|
374
|
+
},
|
|
375
|
+
rooms: {},
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
export default _schema;
|
|
379
|
+
`;
|
|
380
|
+
const serverSchema = i.schema({
|
|
381
|
+
entities: {
|
|
382
|
+
todos: i.entity({ title: i.string() }),
|
|
383
|
+
users: i.entity({ email: i.string() }),
|
|
384
|
+
},
|
|
385
|
+
links: {
|
|
386
|
+
todoOwner: {
|
|
387
|
+
forward: { on: 'todos', has: 'one', label: 'owner' },
|
|
388
|
+
reverse: { on: 'users', has: 'many', label: 'todos' },
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const result = await update(oldFile, serverSchema);
|
|
394
|
+
|
|
395
|
+
expect(result).toMatchSnapshot();
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('removes the last link cleanly', async () => {
|
|
399
|
+
const oldFile = `
|
|
400
|
+
import { i } from '@instantdb/core';
|
|
401
|
+
|
|
402
|
+
const _schema = i.schema({
|
|
403
|
+
entities: {
|
|
404
|
+
todos: i.entity({
|
|
405
|
+
title: i.string(),
|
|
406
|
+
}),
|
|
407
|
+
users: i.entity({
|
|
408
|
+
email: i.string(),
|
|
409
|
+
}),
|
|
410
|
+
},
|
|
411
|
+
links: {
|
|
412
|
+
todoOwner: {
|
|
413
|
+
forward: { on: 'todos', has: 'one', label: 'owner' },
|
|
414
|
+
reverse: { on: 'users', has: 'many', label: 'todos' },
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
rooms: {},
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
export default _schema;
|
|
421
|
+
`;
|
|
422
|
+
const serverSchema = i.schema({
|
|
423
|
+
entities: {
|
|
424
|
+
todos: i.entity({ title: i.string() }),
|
|
425
|
+
users: i.entity({ email: i.string() }),
|
|
426
|
+
},
|
|
427
|
+
links: {},
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
const result = await update(oldFile, serverSchema);
|
|
431
|
+
|
|
432
|
+
expect(result).toMatchSnapshot();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
async function update(oldFile: string, serverSchema: any) {
|
|
436
|
+
const localSchema = schemaTypescriptFileToInstantSchema(oldFile);
|
|
437
|
+
return updateSchemaFile(oldFile, localSchema, serverSchema);
|
|
438
|
+
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAg+DA,8EAQC;AA+ED;;;;;EAKE"}
|