@tldraw/store 3.16.0-canary.f60032f16651 → 3.16.0-canary.faec5de49906
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/README.md +11 -11
- package/dist-cjs/index.d.ts +6 -41
- package/dist-cjs/index.js +1 -2
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/RecordType.js +0 -16
- package/dist-cjs/lib/RecordType.js.map +2 -2
- package/dist-cjs/lib/RecordsDiff.js +3 -3
- package/dist-cjs/lib/RecordsDiff.js.map +2 -2
- package/dist-cjs/lib/Store.js +1 -20
- package/dist-cjs/lib/Store.js.map +2 -2
- package/dist-cjs/lib/StoreSchema.js +1 -0
- package/dist-cjs/lib/StoreSchema.js.map +2 -2
- package/dist-cjs/lib/migrate.js +57 -43
- package/dist-cjs/lib/migrate.js.map +2 -2
- package/dist-esm/index.d.mts +6 -41
- package/dist-esm/index.mjs +1 -3
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/RecordType.mjs +0 -16
- package/dist-esm/lib/RecordType.mjs.map +2 -2
- package/dist-esm/lib/RecordsDiff.mjs +3 -3
- package/dist-esm/lib/RecordsDiff.mjs.map +2 -2
- package/dist-esm/lib/Store.mjs +1 -20
- package/dist-esm/lib/Store.mjs.map +2 -2
- package/dist-esm/lib/StoreSchema.mjs +1 -0
- package/dist-esm/lib/StoreSchema.mjs.map +2 -2
- package/dist-esm/lib/migrate.mjs +57 -43
- package/dist-esm/lib/migrate.mjs.map +2 -2
- package/package.json +10 -18
- package/src/index.ts +0 -1
- package/src/lib/RecordType.ts +0 -17
- package/src/lib/RecordsDiff.ts +9 -3
- package/src/lib/Store.ts +1 -22
- package/src/lib/StoreSchema.ts +1 -0
- package/src/lib/migrate.ts +106 -57
- package/src/lib/test/AtomMap.test.ts +2 -1
- package/src/lib/test/dependsOn.test.ts +2 -2
- package/src/lib/test/recordStore.test.ts +40 -37
- package/src/lib/test/sortMigrations.test.ts +36 -4
- package/src/lib/test/validateMigrations.test.ts +8 -8
- package/src/lib/test/defineMigrations.test.ts +0 -232
|
@@ -18,7 +18,7 @@ describe(validateMigrations, () => {
|
|
|
18
18
|
sequenceId: 'foo',
|
|
19
19
|
})
|
|
20
20
|
).toThrowErrorMatchingInlineSnapshot(
|
|
21
|
-
`
|
|
21
|
+
`[Error: Every migration in sequence 'foo' must have an id starting with 'foo/'. Got invalid id: 'foo.1']`
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
expect(() =>
|
|
@@ -36,7 +36,7 @@ describe(validateMigrations, () => {
|
|
|
36
36
|
|
|
37
37
|
sequenceId: 'foo',
|
|
38
38
|
})
|
|
39
|
-
).toThrowErrorMatchingInlineSnapshot(`
|
|
39
|
+
).toThrowErrorMatchingInlineSnapshot(`[Error: Invalid migration id: 'foo/one']`)
|
|
40
40
|
|
|
41
41
|
expect(() =>
|
|
42
42
|
validateMigrations({
|
|
@@ -61,7 +61,7 @@ describe(validateMigrations, () => {
|
|
|
61
61
|
sequenceId: 'foo',
|
|
62
62
|
})
|
|
63
63
|
).toThrowErrorMatchingInlineSnapshot(
|
|
64
|
-
`
|
|
64
|
+
`[Error: Every migration in sequence 'foo' must have an id starting with 'foo/'. Got invalid id: 'foo.2']`
|
|
65
65
|
)
|
|
66
66
|
|
|
67
67
|
expect(() =>
|
|
@@ -86,7 +86,7 @@ describe(validateMigrations, () => {
|
|
|
86
86
|
|
|
87
87
|
sequenceId: 'foo',
|
|
88
88
|
})
|
|
89
|
-
).toThrowErrorMatchingInlineSnapshot(`
|
|
89
|
+
).toThrowErrorMatchingInlineSnapshot(`[Error: Invalid migration id: 'foo/two']`)
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
it('should throw if the sequenceId is invalid', () => {
|
|
@@ -96,7 +96,7 @@ describe(validateMigrations, () => {
|
|
|
96
96
|
sequence: [],
|
|
97
97
|
sequenceId: 'foo/bar',
|
|
98
98
|
})
|
|
99
|
-
).toThrowErrorMatchingInlineSnapshot(`
|
|
99
|
+
).toThrowErrorMatchingInlineSnapshot(`[Error: sequenceId cannot contain a '/', got foo/bar]`)
|
|
100
100
|
|
|
101
101
|
expect(() =>
|
|
102
102
|
validateMigrations({
|
|
@@ -104,7 +104,7 @@ describe(validateMigrations, () => {
|
|
|
104
104
|
sequence: [],
|
|
105
105
|
sequenceId: '',
|
|
106
106
|
})
|
|
107
|
-
).toThrowErrorMatchingInlineSnapshot(`
|
|
107
|
+
).toThrowErrorMatchingInlineSnapshot(`[Error: sequenceId must be a non-empty string]`)
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
it('should throw if the version numbers do not start at 1', () => {
|
|
@@ -124,7 +124,7 @@ describe(validateMigrations, () => {
|
|
|
124
124
|
sequenceId: 'foo',
|
|
125
125
|
})
|
|
126
126
|
).toThrowErrorMatchingInlineSnapshot(
|
|
127
|
-
`
|
|
127
|
+
`[Error: Expected the first migrationId to be 'foo/1' but got 'foo/2']`
|
|
128
128
|
)
|
|
129
129
|
})
|
|
130
130
|
|
|
@@ -159,7 +159,7 @@ describe(validateMigrations, () => {
|
|
|
159
159
|
sequenceId: 'foo',
|
|
160
160
|
})
|
|
161
161
|
).toThrowErrorMatchingInlineSnapshot(
|
|
162
|
-
`
|
|
162
|
+
`[Error: Migration id numbers must increase in increments of 1, expected foo/3 but got 'foo/4']`
|
|
163
163
|
)
|
|
164
164
|
})
|
|
165
165
|
})
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { defineMigrations } from '../migrate'
|
|
2
|
-
|
|
3
|
-
const Versions = {
|
|
4
|
-
Initial: 0,
|
|
5
|
-
January: 1,
|
|
6
|
-
February: 2,
|
|
7
|
-
March: 3,
|
|
8
|
-
} as const
|
|
9
|
-
|
|
10
|
-
describe('define migrations tests', () => {
|
|
11
|
-
it('defines migrations', () => {
|
|
12
|
-
expect(() => {
|
|
13
|
-
// no versions
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
15
|
-
defineMigrations({
|
|
16
|
-
firstVersion: Versions.Initial,
|
|
17
|
-
})
|
|
18
|
-
}).not.toThrow()
|
|
19
|
-
|
|
20
|
-
expect(() => {
|
|
21
|
-
// no versions
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
23
|
-
defineMigrations({
|
|
24
|
-
firstVersion: Versions.February,
|
|
25
|
-
})
|
|
26
|
-
}).not.toThrow()
|
|
27
|
-
|
|
28
|
-
expect(() => {
|
|
29
|
-
// empty migrators
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
31
|
-
defineMigrations({
|
|
32
|
-
migrators: {},
|
|
33
|
-
})
|
|
34
|
-
}).not.toThrow()
|
|
35
|
-
|
|
36
|
-
expect(() => {
|
|
37
|
-
// no versions!
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
39
|
-
defineMigrations({
|
|
40
|
-
migrators: {
|
|
41
|
-
[Versions.February]: {
|
|
42
|
-
up: (rec: any) => rec,
|
|
43
|
-
down: (rec: any) => rec,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
})
|
|
47
|
-
}).not.toThrow()
|
|
48
|
-
|
|
49
|
-
expect(() => {
|
|
50
|
-
// wrong current version!
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
52
|
-
defineMigrations({
|
|
53
|
-
currentVersion: Versions.January,
|
|
54
|
-
migrators: {
|
|
55
|
-
[Versions.February]: {
|
|
56
|
-
up: (rec: any) => rec,
|
|
57
|
-
down: (rec: any) => rec,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
}).not.toThrow()
|
|
62
|
-
|
|
63
|
-
expect(() => {
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
65
|
-
defineMigrations({
|
|
66
|
-
currentVersion: Versions.February,
|
|
67
|
-
migrators: {
|
|
68
|
-
// has a default zero version
|
|
69
|
-
[Versions.January]: {
|
|
70
|
-
up: (rec: any) => rec,
|
|
71
|
-
down: (rec: any) => rec,
|
|
72
|
-
},
|
|
73
|
-
// has a current version
|
|
74
|
-
[Versions.February]: {
|
|
75
|
-
up: (rec: any) => rec,
|
|
76
|
-
down: (rec: any) => rec,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
})
|
|
80
|
-
}).not.toThrow()
|
|
81
|
-
|
|
82
|
-
expect(() => {
|
|
83
|
-
// can't provide only first version
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
85
|
-
defineMigrations({
|
|
86
|
-
firstVersion: Versions.January,
|
|
87
|
-
migrators: {},
|
|
88
|
-
})
|
|
89
|
-
}).not.toThrow()
|
|
90
|
-
|
|
91
|
-
expect(() => {
|
|
92
|
-
// same version
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
94
|
-
defineMigrations({
|
|
95
|
-
firstVersion: Versions.Initial,
|
|
96
|
-
currentVersion: Versions.Initial,
|
|
97
|
-
migrators: {},
|
|
98
|
-
})
|
|
99
|
-
}).toThrow()
|
|
100
|
-
|
|
101
|
-
expect(() => {
|
|
102
|
-
// only first version
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
104
|
-
defineMigrations({
|
|
105
|
-
firstVersion: Versions.January,
|
|
106
|
-
migrators: {},
|
|
107
|
-
})
|
|
108
|
-
}).not.toThrow()
|
|
109
|
-
|
|
110
|
-
expect(() => {
|
|
111
|
-
// missing only version
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
113
|
-
defineMigrations({
|
|
114
|
-
firstVersion: Versions.January,
|
|
115
|
-
currentVersion: Versions.January,
|
|
116
|
-
migrators: {},
|
|
117
|
-
})
|
|
118
|
-
}).toThrow()
|
|
119
|
-
|
|
120
|
-
expect(() => {
|
|
121
|
-
// only version, explicit start and current
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
123
|
-
defineMigrations({
|
|
124
|
-
firstVersion: Versions.January,
|
|
125
|
-
currentVersion: Versions.January,
|
|
126
|
-
migrators: {
|
|
127
|
-
[Versions.January]: {
|
|
128
|
-
up: (rec: any) => rec,
|
|
129
|
-
down: (rec: any) => rec,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
})
|
|
133
|
-
}).toThrow()
|
|
134
|
-
|
|
135
|
-
expect(() => {
|
|
136
|
-
// missing later versions
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
138
|
-
defineMigrations({
|
|
139
|
-
firstVersion: Versions.January,
|
|
140
|
-
currentVersion: Versions.February,
|
|
141
|
-
migrators: {},
|
|
142
|
-
})
|
|
143
|
-
}).not.toThrow()
|
|
144
|
-
|
|
145
|
-
expect(() => {
|
|
146
|
-
// missing later versions
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
148
|
-
defineMigrations({
|
|
149
|
-
firstVersion: Versions.Initial,
|
|
150
|
-
currentVersion: Versions.February,
|
|
151
|
-
migrators: {
|
|
152
|
-
[Versions.January]: {
|
|
153
|
-
up: (rec: any) => rec,
|
|
154
|
-
down: (rec: any) => rec,
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
})
|
|
158
|
-
}).not.toThrow()
|
|
159
|
-
|
|
160
|
-
expect(() => {
|
|
161
|
-
// missing earlier versions
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
163
|
-
defineMigrations({
|
|
164
|
-
firstVersion: Versions.Initial,
|
|
165
|
-
currentVersion: Versions.February,
|
|
166
|
-
migrators: {
|
|
167
|
-
[Versions.February]: {
|
|
168
|
-
up: (rec: any) => rec,
|
|
169
|
-
down: (rec: any) => rec,
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
}).not.toThrow()
|
|
174
|
-
|
|
175
|
-
expect(() => {
|
|
176
|
-
// got em all
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
178
|
-
defineMigrations({
|
|
179
|
-
firstVersion: Versions.Initial,
|
|
180
|
-
currentVersion: Versions.February,
|
|
181
|
-
migrators: {
|
|
182
|
-
[Versions.January]: {
|
|
183
|
-
up: (rec: any) => rec,
|
|
184
|
-
down: (rec: any) => rec,
|
|
185
|
-
},
|
|
186
|
-
[Versions.February]: {
|
|
187
|
-
up: (rec: any) => rec,
|
|
188
|
-
down: (rec: any) => rec,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
})
|
|
192
|
-
}).not.toThrow()
|
|
193
|
-
|
|
194
|
-
expect(() => {
|
|
195
|
-
// got em all starting later
|
|
196
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
197
|
-
defineMigrations({
|
|
198
|
-
firstVersion: Versions.January,
|
|
199
|
-
currentVersion: Versions.March,
|
|
200
|
-
migrators: {
|
|
201
|
-
[Versions.February]: {
|
|
202
|
-
up: (rec: any) => rec,
|
|
203
|
-
down: (rec: any) => rec,
|
|
204
|
-
},
|
|
205
|
-
[Versions.March]: {
|
|
206
|
-
up: (rec: any) => rec,
|
|
207
|
-
down: (rec: any) => rec,
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
})
|
|
211
|
-
}).not.toThrow()
|
|
212
|
-
|
|
213
|
-
expect(() => {
|
|
214
|
-
// first migration should be first version + 1
|
|
215
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
216
|
-
defineMigrations({
|
|
217
|
-
firstVersion: Versions.February,
|
|
218
|
-
currentVersion: Versions.March,
|
|
219
|
-
migrators: {
|
|
220
|
-
[Versions.February]: {
|
|
221
|
-
up: (rec: any) => rec,
|
|
222
|
-
down: (rec: any) => rec,
|
|
223
|
-
},
|
|
224
|
-
[Versions.March]: {
|
|
225
|
-
up: (rec: any) => rec,
|
|
226
|
-
down: (rec: any) => rec,
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
})
|
|
230
|
-
}).not.toThrow()
|
|
231
|
-
})
|
|
232
|
-
})
|