@verdant-web/common 1.15.2 → 1.15.3-next.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 (163) hide show
  1. package/dist/cjs/EventSubscriber.d.ts +17 -17
  2. package/dist/cjs/EventSubscriber.js +66 -66
  3. package/dist/cjs/baseline.d.ts +5 -5
  4. package/dist/cjs/baseline.js +2 -2
  5. package/dist/cjs/batching.d.ts +42 -42
  6. package/dist/cjs/batching.js +91 -91
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/files.test.d.ts +1 -0
  10. package/dist/cjs/files.test.js +81 -0
  11. package/dist/cjs/files.test.js.map +1 -0
  12. package/dist/cjs/index.d.ts +19 -18
  13. package/dist/cjs/index.js +41 -36
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/indexes.d.ts +17 -17
  16. package/dist/cjs/indexes.js +142 -142
  17. package/dist/cjs/indexes.test.d.ts +1 -1
  18. package/dist/cjs/indexes.test.js +127 -127
  19. package/dist/cjs/migration.d.ts +172 -172
  20. package/dist/cjs/migration.js +301 -301
  21. package/dist/cjs/oids.d.ts +100 -96
  22. package/dist/cjs/oids.js +457 -439
  23. package/dist/cjs/oids.js.map +1 -1
  24. package/dist/cjs/oids.test.d.ts +1 -1
  25. package/dist/cjs/oids.test.js +348 -272
  26. package/dist/cjs/oids.test.js.map +1 -1
  27. package/dist/cjs/operation.d.ts +139 -139
  28. package/dist/cjs/operation.js +545 -545
  29. package/dist/cjs/operation.test.d.ts +1 -1
  30. package/dist/cjs/operation.test.js +529 -529
  31. package/dist/cjs/patch.d.ts +26 -26
  32. package/dist/cjs/patch.js +226 -226
  33. package/dist/cjs/presence.d.ts +27 -27
  34. package/dist/cjs/presence.js +2 -2
  35. package/dist/cjs/protocol.d.ts +145 -145
  36. package/dist/cjs/protocol.js +3 -3
  37. package/dist/cjs/refs.d.ts +7 -5
  38. package/dist/cjs/refs.js +29 -21
  39. package/dist/cjs/refs.js.map +1 -1
  40. package/dist/cjs/replica.d.ts +28 -28
  41. package/dist/cjs/replica.js +28 -28
  42. package/dist/cjs/schema/defaults.d.ts +4 -0
  43. package/dist/cjs/schema/defaults.js +72 -0
  44. package/dist/cjs/schema/defaults.js.map +1 -0
  45. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  46. package/dist/cjs/schema/defaults.test.js +20 -20
  47. package/dist/cjs/schema/fields.d.ts +9 -9
  48. package/dist/cjs/schema/fields.js +144 -144
  49. package/dist/cjs/schema/index.d.ts +8 -8
  50. package/dist/cjs/schema/index.js +51 -51
  51. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  52. package/dist/cjs/schema/indexFilters.js +30 -30
  53. package/dist/cjs/schema/types/collection.d.ts +23 -23
  54. package/dist/cjs/schema/types/collection.js +2 -2
  55. package/dist/cjs/schema/types/compounds.d.ts +11 -11
  56. package/dist/cjs/schema/types/compounds.js +2 -2
  57. package/dist/cjs/schema/types/fields.d.ts +75 -75
  58. package/dist/cjs/schema/types/fields.js +2 -2
  59. package/dist/cjs/schema/types/filters.d.ts +29 -29
  60. package/dist/cjs/schema/types/filters.js +2 -2
  61. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  62. package/dist/cjs/schema/types/shapes.js +2 -2
  63. package/dist/cjs/schema/types/synthetics.d.ts +37 -37
  64. package/dist/cjs/schema/types/synthetics.js +2 -2
  65. package/dist/cjs/schema/types.d.ts +18 -18
  66. package/dist/cjs/schema/types.js +22 -22
  67. package/dist/cjs/schema/validation.d.ts +3 -3
  68. package/dist/cjs/schema/validation.js +86 -86
  69. package/dist/cjs/timestamp.d.ts +50 -50
  70. package/dist/cjs/timestamp.js +251 -251
  71. package/dist/cjs/timestamp.test.d.ts +1 -1
  72. package/dist/cjs/timestamp.test.js +104 -104
  73. package/dist/cjs/undo.d.ts +3 -3
  74. package/dist/cjs/undo.js +198 -198
  75. package/dist/cjs/utils.d.ts +20 -20
  76. package/dist/cjs/utils.js +145 -145
  77. package/dist/cjs/utils.test.d.ts +1 -1
  78. package/dist/cjs/utils.test.js +36 -36
  79. package/dist/esm/EventSubscriber.d.ts +17 -17
  80. package/dist/esm/EventSubscriber.js +62 -62
  81. package/dist/esm/baseline.d.ts +5 -5
  82. package/dist/esm/baseline.js +1 -1
  83. package/dist/esm/batching.d.ts +42 -42
  84. package/dist/esm/batching.js +86 -86
  85. package/dist/esm/files.d.ts +19 -19
  86. package/dist/esm/files.js +12 -12
  87. package/dist/esm/files.test.d.ts +1 -0
  88. package/dist/esm/files.test.js +79 -0
  89. package/dist/esm/files.test.js.map +1 -0
  90. package/dist/esm/index.d.ts +19 -18
  91. package/dist/esm/index.js +16 -15
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/indexes.d.ts +17 -17
  94. package/dist/esm/indexes.js +130 -130
  95. package/dist/esm/indexes.test.d.ts +1 -1
  96. package/dist/esm/indexes.test.js +125 -125
  97. package/dist/esm/migration.d.ts +172 -172
  98. package/dist/esm/migration.js +294 -294
  99. package/dist/esm/oids.d.ts +100 -96
  100. package/dist/esm/oids.js +422 -407
  101. package/dist/esm/oids.js.map +1 -1
  102. package/dist/esm/oids.test.d.ts +1 -1
  103. package/dist/esm/oids.test.js +346 -270
  104. package/dist/esm/oids.test.js.map +1 -1
  105. package/dist/esm/operation.d.ts +139 -139
  106. package/dist/esm/operation.js +530 -530
  107. package/dist/esm/operation.test.d.ts +1 -1
  108. package/dist/esm/operation.test.js +527 -527
  109. package/dist/esm/patch.d.ts +26 -26
  110. package/dist/esm/patch.js +222 -222
  111. package/dist/esm/presence.d.ts +27 -27
  112. package/dist/esm/presence.js +1 -1
  113. package/dist/esm/protocol.d.ts +145 -145
  114. package/dist/esm/protocol.js +2 -2
  115. package/dist/esm/refs.d.ts +7 -5
  116. package/dist/esm/refs.js +22 -16
  117. package/dist/esm/refs.js.map +1 -1
  118. package/dist/esm/replica.d.ts +28 -28
  119. package/dist/esm/replica.js +25 -25
  120. package/dist/esm/schema/defaults.d.ts +4 -0
  121. package/dist/esm/schema/defaults.js +66 -0
  122. package/dist/esm/schema/defaults.js.map +1 -0
  123. package/dist/esm/schema/defaults.test.d.ts +1 -1
  124. package/dist/esm/schema/defaults.test.js +18 -18
  125. package/dist/esm/schema/fields.d.ts +9 -9
  126. package/dist/esm/schema/fields.js +133 -133
  127. package/dist/esm/schema/index.d.ts +8 -8
  128. package/dist/esm/schema/index.js +32 -32
  129. package/dist/esm/schema/indexFilters.d.ts +6 -6
  130. package/dist/esm/schema/indexFilters.js +22 -22
  131. package/dist/esm/schema/types/collection.d.ts +23 -23
  132. package/dist/esm/schema/types/collection.js +1 -1
  133. package/dist/esm/schema/types/compounds.d.ts +11 -11
  134. package/dist/esm/schema/types/compounds.js +1 -1
  135. package/dist/esm/schema/types/fields.d.ts +75 -75
  136. package/dist/esm/schema/types/fields.js +1 -1
  137. package/dist/esm/schema/types/filters.d.ts +29 -29
  138. package/dist/esm/schema/types/filters.js +1 -1
  139. package/dist/esm/schema/types/shapes.d.ts +21 -21
  140. package/dist/esm/schema/types/shapes.js +1 -1
  141. package/dist/esm/schema/types/synthetics.d.ts +37 -37
  142. package/dist/esm/schema/types/synthetics.js +1 -1
  143. package/dist/esm/schema/types.d.ts +18 -18
  144. package/dist/esm/schema/types.js +6 -6
  145. package/dist/esm/schema/validation.d.ts +3 -3
  146. package/dist/esm/schema/validation.js +81 -81
  147. package/dist/esm/timestamp.d.ts +50 -50
  148. package/dist/esm/timestamp.js +234 -234
  149. package/dist/esm/timestamp.test.d.ts +1 -1
  150. package/dist/esm/timestamp.test.js +102 -102
  151. package/dist/esm/undo.d.ts +3 -3
  152. package/dist/esm/undo.js +194 -194
  153. package/dist/esm/utils.d.ts +20 -20
  154. package/dist/esm/utils.js +127 -127
  155. package/dist/esm/utils.test.d.ts +1 -1
  156. package/dist/esm/utils.test.js +34 -34
  157. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +1 -1
  160. package/src/index.ts +1 -0
  161. package/src/oids.test.ts +82 -0
  162. package/src/oids.ts +17 -0
  163. package/src/refs.ts +8 -0
@@ -1,128 +1,128 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const indexes_js_1 = require("./indexes.js");
5
- (0, vitest_1.describe)('compound indexes', () => {
6
- (0, vitest_1.it)('can be created from two string values', () => {
7
- (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`);
8
- });
9
- (0, vitest_1.it)('can be created from two number values', () => {
10
- (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(1, 2)).toEqual(`1${indexes_js_1.COMPOUND_INDEX_SEPARATOR}2`);
11
- });
12
- (0, vitest_1.it)('can be created from an array and string value', () => {
13
- (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b'], 'c')).toEqual([
14
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
15
- `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
16
- ]);
17
- });
18
- (0, vitest_1.it)('can be created from a string and array of numbers', () => {
19
- (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)('a', [1, 2])).toEqual([
20
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}1`,
21
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}2`,
22
- ]);
23
- });
24
- (0, vitest_1.it)('can be created from an array of strings and an array of booleans', () => {
25
- (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b'], [true, false])).toEqual([
26
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
27
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
28
- `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
29
- `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
30
- ]);
31
- });
32
- (0, vitest_1.it)('remove duplicate array compound index values', () => {
33
- (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b', 'b'], [true, false, true])).toEqual([
34
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
35
- `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
36
- `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
37
- `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
38
- ]);
39
- });
40
- (0, vitest_1.it)('creates lower bound value for multi-value indexes', () => {
41
- (0, vitest_1.expect)((0, indexes_js_1.createLowerBoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}${indexes_js_1.COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
42
- });
43
- (0, vitest_1.it)('creates upper bound value for multi-value indexes', () => {
44
- (0, vitest_1.expect)((0, indexes_js_1.createUpperBoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b${indexes_js_1.COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
45
- }),
46
- (0, vitest_1.it)('will always be grouped by the first item', () => {
47
- (0, vitest_1.expect)([
48
- (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'b'),
49
- (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'c'),
50
- (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'd'),
51
- (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'e'),
52
- // extra nefarious!
53
- (0, indexes_js_1.createCompoundIndexValue)('aaaaaaa', 'no!'),
54
- (0, indexes_js_1.createCompoundIndexValue)('aaaaaa ', 'no!'),
55
- (0, indexes_js_1.createCompoundIndexValue)(`aaaaaa😎`, 'no!'),
56
- (0, indexes_js_1.createCompoundIndexValue)(`aaaaaa😎😎`, 'no!'),
57
- (0, indexes_js_1.createCompoundIndexValue)('aaa', 'no!'),
58
- (0, indexes_js_1.createCompoundIndexValue)(`aaaaaaa😎no!`, 'no!'),
59
- ].sort()).toEqual([
60
- `aaaaaa ${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
61
- `aaaaaaa😎no!${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
62
- `aaaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
63
- `aaaaaa😎😎${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
64
- `aaaaaa😎${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
65
- // this is the contiguous block of relevant values
66
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
67
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
68
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
69
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
70
- // here ends the block
71
- `aaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
72
- ]);
73
- });
74
- (0, vitest_1.it)('will be bounded by upper and lower bound values', () => {
75
- const match = 'aaaaaa';
76
- const sorted = [
77
- (0, indexes_js_1.createCompoundIndexValue)(match, 'b'),
78
- (0, indexes_js_1.createCompoundIndexValue)(match, 'c'),
79
- (0, indexes_js_1.createCompoundIndexValue)(match, 'd'),
80
- (0, indexes_js_1.createCompoundIndexValue)(match, 'e'),
81
- // extra nefarious!
82
- (0, indexes_js_1.createCompoundIndexValue)(`${match}a`, 'no!'),
83
- (0, indexes_js_1.createCompoundIndexValue)(`${match} `, 'no!'),
84
- (0, indexes_js_1.createCompoundIndexValue)(`${match}😎`, 'no!'),
85
- (0, indexes_js_1.createCompoundIndexValue)(`${match}😎😎`, 'no!'),
86
- (0, indexes_js_1.createCompoundIndexValue)('aaa', 'no!'),
87
- (0, indexes_js_1.createCompoundIndexValue)(`${match}a😎no!`, 'no!'),
88
- ].sort();
89
- const boundedBlock = sorted.filter((value) => value > (0, indexes_js_1.createLowerBoundIndexValue)(match) &&
90
- value < (0, indexes_js_1.createUpperBoundIndexValue)(match));
91
- (0, vitest_1.expect)(boundedBlock).toEqual([
92
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
93
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
94
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
95
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
96
- ]);
97
- });
98
- (0, vitest_1.it)('will be bounded by upper and lower bounds when matching multiple sections', () => {
99
- const match1 = 'aaaaaa';
100
- const match2 = 'bbbbbb';
101
- const sorted = [
102
- (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'b'),
103
- (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'c'),
104
- (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'd'),
105
- (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'e'),
106
- // extra nefarious!
107
- (0, indexes_js_1.createCompoundIndexValue)(`${match1}a`, match2, 'no!'),
108
- (0, indexes_js_1.createCompoundIndexValue)(`${match1} `, match2, 'no!'),
109
- (0, indexes_js_1.createCompoundIndexValue)(`${match1}😎`, match2, 'no!'),
110
- (0, indexes_js_1.createCompoundIndexValue)(`${match1}😎😎`, match2, 'no!'),
111
- (0, indexes_js_1.createCompoundIndexValue)('aaa', match2, 'no!'),
112
- (0, indexes_js_1.createCompoundIndexValue)(`${match1}a😎no!`, match2, 'no!'),
113
- (0, indexes_js_1.createCompoundIndexValue)(match1, `${match2}a😎no!`, 'no!'),
114
- (0, indexes_js_1.createCompoundIndexValue)(match1, `${match2} `, 'no!'),
115
- (0, indexes_js_1.createCompoundIndexValue)(match1, ' ', 'no!'),
116
- (0, indexes_js_1.createCompoundIndexValue)(match1, '\u00001', 'no!'),
117
- (0, indexes_js_1.createCompoundIndexValue)(match1, '\uE007f', 'no!'),
118
- ].sort();
119
- (0, vitest_1.expect)(sorted.filter((value) => value > (0, indexes_js_1.createLowerBoundIndexValue)(match1, match2) &&
120
- value < (0, indexes_js_1.createUpperBoundIndexValue)(match1, match2))).toEqual([
121
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
122
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
123
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
124
- `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
125
- ]);
126
- });
127
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const indexes_js_1 = require("./indexes.js");
5
+ (0, vitest_1.describe)('compound indexes', () => {
6
+ (0, vitest_1.it)('can be created from two string values', () => {
7
+ (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`);
8
+ });
9
+ (0, vitest_1.it)('can be created from two number values', () => {
10
+ (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(1, 2)).toEqual(`1${indexes_js_1.COMPOUND_INDEX_SEPARATOR}2`);
11
+ });
12
+ (0, vitest_1.it)('can be created from an array and string value', () => {
13
+ (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b'], 'c')).toEqual([
14
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
15
+ `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
16
+ ]);
17
+ });
18
+ (0, vitest_1.it)('can be created from a string and array of numbers', () => {
19
+ (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)('a', [1, 2])).toEqual([
20
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}1`,
21
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}2`,
22
+ ]);
23
+ });
24
+ (0, vitest_1.it)('can be created from an array of strings and an array of booleans', () => {
25
+ (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b'], [true, false])).toEqual([
26
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
27
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
28
+ `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
29
+ `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
30
+ ]);
31
+ });
32
+ (0, vitest_1.it)('remove duplicate array compound index values', () => {
33
+ (0, vitest_1.expect)((0, indexes_js_1.createCompoundIndexValue)(['a', 'b', 'b'], [true, false, true])).toEqual([
34
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
35
+ `a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
36
+ `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}true`,
37
+ `b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}false`,
38
+ ]);
39
+ });
40
+ (0, vitest_1.it)('creates lower bound value for multi-value indexes', () => {
41
+ (0, vitest_1.expect)((0, indexes_js_1.createLowerBoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b${indexes_js_1.COMPOUND_INDEX_SEPARATOR}${indexes_js_1.COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
42
+ });
43
+ (0, vitest_1.it)('creates upper bound value for multi-value indexes', () => {
44
+ (0, vitest_1.expect)((0, indexes_js_1.createUpperBoundIndexValue)('a', 'b')).toEqual(`a${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b${indexes_js_1.COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
45
+ }),
46
+ (0, vitest_1.it)('will always be grouped by the first item', () => {
47
+ (0, vitest_1.expect)([
48
+ (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'b'),
49
+ (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'c'),
50
+ (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'd'),
51
+ (0, indexes_js_1.createCompoundIndexValue)('aaaaaa', 'e'),
52
+ // extra nefarious!
53
+ (0, indexes_js_1.createCompoundIndexValue)('aaaaaaa', 'no!'),
54
+ (0, indexes_js_1.createCompoundIndexValue)('aaaaaa ', 'no!'),
55
+ (0, indexes_js_1.createCompoundIndexValue)(`aaaaaa😎`, 'no!'),
56
+ (0, indexes_js_1.createCompoundIndexValue)(`aaaaaa😎😎`, 'no!'),
57
+ (0, indexes_js_1.createCompoundIndexValue)('aaa', 'no!'),
58
+ (0, indexes_js_1.createCompoundIndexValue)(`aaaaaaa😎no!`, 'no!'),
59
+ ].sort()).toEqual([
60
+ `aaaaaa ${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
61
+ `aaaaaaa😎no!${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
62
+ `aaaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
63
+ `aaaaaa😎😎${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
64
+ `aaaaaa😎${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
65
+ // this is the contiguous block of relevant values
66
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
67
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
68
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
69
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
70
+ // here ends the block
71
+ `aaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}no!`,
72
+ ]);
73
+ });
74
+ (0, vitest_1.it)('will be bounded by upper and lower bound values', () => {
75
+ const match = 'aaaaaa';
76
+ const sorted = [
77
+ (0, indexes_js_1.createCompoundIndexValue)(match, 'b'),
78
+ (0, indexes_js_1.createCompoundIndexValue)(match, 'c'),
79
+ (0, indexes_js_1.createCompoundIndexValue)(match, 'd'),
80
+ (0, indexes_js_1.createCompoundIndexValue)(match, 'e'),
81
+ // extra nefarious!
82
+ (0, indexes_js_1.createCompoundIndexValue)(`${match}a`, 'no!'),
83
+ (0, indexes_js_1.createCompoundIndexValue)(`${match} `, 'no!'),
84
+ (0, indexes_js_1.createCompoundIndexValue)(`${match}😎`, 'no!'),
85
+ (0, indexes_js_1.createCompoundIndexValue)(`${match}😎😎`, 'no!'),
86
+ (0, indexes_js_1.createCompoundIndexValue)('aaa', 'no!'),
87
+ (0, indexes_js_1.createCompoundIndexValue)(`${match}a😎no!`, 'no!'),
88
+ ].sort();
89
+ const boundedBlock = sorted.filter((value) => value > (0, indexes_js_1.createLowerBoundIndexValue)(match) &&
90
+ value < (0, indexes_js_1.createUpperBoundIndexValue)(match));
91
+ (0, vitest_1.expect)(boundedBlock).toEqual([
92
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
93
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
94
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
95
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
96
+ ]);
97
+ });
98
+ (0, vitest_1.it)('will be bounded by upper and lower bounds when matching multiple sections', () => {
99
+ const match1 = 'aaaaaa';
100
+ const match2 = 'bbbbbb';
101
+ const sorted = [
102
+ (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'b'),
103
+ (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'c'),
104
+ (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'd'),
105
+ (0, indexes_js_1.createCompoundIndexValue)(match1, match2, 'e'),
106
+ // extra nefarious!
107
+ (0, indexes_js_1.createCompoundIndexValue)(`${match1}a`, match2, 'no!'),
108
+ (0, indexes_js_1.createCompoundIndexValue)(`${match1} `, match2, 'no!'),
109
+ (0, indexes_js_1.createCompoundIndexValue)(`${match1}😎`, match2, 'no!'),
110
+ (0, indexes_js_1.createCompoundIndexValue)(`${match1}😎😎`, match2, 'no!'),
111
+ (0, indexes_js_1.createCompoundIndexValue)('aaa', match2, 'no!'),
112
+ (0, indexes_js_1.createCompoundIndexValue)(`${match1}a😎no!`, match2, 'no!'),
113
+ (0, indexes_js_1.createCompoundIndexValue)(match1, `${match2}a😎no!`, 'no!'),
114
+ (0, indexes_js_1.createCompoundIndexValue)(match1, `${match2} `, 'no!'),
115
+ (0, indexes_js_1.createCompoundIndexValue)(match1, ' ', 'no!'),
116
+ (0, indexes_js_1.createCompoundIndexValue)(match1, '\u00001', 'no!'),
117
+ (0, indexes_js_1.createCompoundIndexValue)(match1, '\uE007f', 'no!'),
118
+ ].sort();
119
+ (0, vitest_1.expect)(sorted.filter((value) => value > (0, indexes_js_1.createLowerBoundIndexValue)(match1, match2) &&
120
+ value < (0, indexes_js_1.createUpperBoundIndexValue)(match1, match2))).toEqual([
121
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}b`,
122
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}c`,
123
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}d`,
124
+ `aaaaaa${indexes_js_1.COMPOUND_INDEX_SEPARATOR}bbbbbb${indexes_js_1.COMPOUND_INDEX_SEPARATOR}e`,
125
+ ]);
126
+ });
127
+ });
128
128
  //# sourceMappingURL=indexes.test.js.map
@@ -1,172 +1,172 @@
1
- import { StorageCollectionSchema, StorageSchema, StorageDocument, CollectionFilter, StorageDocumentInit } from './index.js';
2
- /**@deprecated */
3
- export interface DroppedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>> {
4
- (old: Old): void | Promise<void>;
5
- }
6
- /**@deprecated */
7
- export interface PreservedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> {
8
- (old: StorageDocument<Old>): StorageDocument<New> | Promise<StorageDocument<New>>;
9
- }
10
- /** @deprecated */
11
- export declare type MigrationsKeyedOnCollection<Old extends StorageSchema<any>, New extends StorageSchema<any>> = PreservedCollectionMigrations<Old, New> | DroppedCollectionMigrations<Old, New>;
12
- /**@deprecated */
13
- declare type NotInSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? never : Name;
14
- /** @deprecated */
15
- declare type InSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? Name : never;
16
- /** @deprecated */
17
- declare type DroppedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
18
- [Key in keyof Old['collections'] as NotInSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
19
- };
20
- /** @deprecated */
21
- declare type PreservedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
22
- [Key in keyof Old['collections'] as InSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
23
- };
24
- /** @deprecated */
25
- declare type DroppedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
26
- [Key in keyof DroppedCollections<Old, New>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
27
- };
28
- /** @deprecated */
29
- declare type PreservedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
30
- [Key in keyof PreservedCollections<Old, New>]: PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]>;
31
- };
32
- /** @deprecated */
33
- declare type StrategyFor<Key extends string, Old extends StorageSchema<any>, New extends StorageSchema<any>> = Key extends keyof New['collections'] ? PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]> : DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
34
- /** @deprecated */
35
- declare type DeprecatedMigrationRunner<Old extends StorageSchema<any>, New extends StorageSchema<any>> = <Collection extends Extract<keyof Old['collections'], string>>(collection: Collection, strategy: StrategyFor<Collection, Old, New>) => Promise<void>;
36
- /** @deprecated */
37
- declare type DeprecatedMigrationQueryMaker<Collection extends StorageCollectionSchema<any, any, any>> = {
38
- get(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;
39
- findOne(query: CollectionFilter): Promise<StorageDocument<Collection> | undefined>;
40
- findAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;
41
- };
42
- /** @deprecated */
43
- declare type DeprecatedMigrationQueries<Old extends StorageSchema<any>> = {
44
- [Key in keyof Old['collections']]: DeprecatedMigrationQueryMaker<Old['collections'][Key]>;
45
- };
46
- /** @deprecated */
47
- declare type DeprecatedMigrationMutations<New extends StorageSchema> = {
48
- [Key in keyof New['collections']]: {
49
- put(document: StorageDocumentInit<New['collections'][Key]>): Promise<StorageDocument<New['collections'][Key]>>;
50
- delete(primaryKey: string): Promise<void>;
51
- };
52
- };
53
- /** @deprecated */
54
- export interface DeprecatedMigrationTools<Old extends StorageSchema<any>, New extends StorageSchema<any>> {
55
- migrate: DeprecatedMigrationRunner<Old, New>;
56
- identity: <T>(val: T) => T;
57
- /**
58
- * @deprecated - default field values are automatically
59
- * applied during migration, you don't need to use this.
60
- * Please remove it from your migrations - even old ones
61
- * (old migrations can be updated!)
62
- */
63
- withDefaults: (collectionName: string, value: any) => any;
64
- queries: DeprecatedMigrationQueries<Old>;
65
- mutations: DeprecatedMigrationMutations<New>;
66
- info: {
67
- changedCollections: keyof Old['collections'][];
68
- addedCollections: keyof New['collections'][];
69
- removedCollections: keyof Old['collections'][];
70
- };
71
- }
72
- export interface MigrationEngine {
73
- migrate: (collection: string, strategy: (val: any) => any) => Promise<void>;
74
- queries: MigrationQueries<any>;
75
- mutations: MigrationMutations<any>;
76
- /** OIDs of any new documents created during the migration */
77
- newOids: string[];
78
- /** Promises that should be resolved before completing the migration */
79
- awaitables: Promise<any>[];
80
- log: (...messages: any[]) => void;
81
- }
82
- /** @deprecated */
83
- declare type DeprecatedMigrationProcedure<Old extends StorageSchema, New extends StorageSchema> = (tools: DeprecatedMigrationTools<Old, New>) => Promise<void>;
84
- declare type EmptySchema = {
85
- version: 0;
86
- collections: {};
87
- };
88
- /** @deprecated - use createMigration */
89
- export declare function migrate<Schema extends StorageSchema>(schema: Schema, procedure: DeprecatedMigrationProcedure<EmptySchema, Schema>): Migration<EmptySchema, Schema>;
90
- /** @deprecated = use createMigration */
91
- export declare function migrate<Old extends StorageSchema, New extends StorageSchema>(oldSchema: Old, newSchema: New, procedure: DeprecatedMigrationProcedure<Old, New>): Migration<Old, New>;
92
- export interface MigrationIndexDescription {
93
- name: string;
94
- multiEntry: boolean;
95
- synthetic: boolean;
96
- compound: boolean;
97
- }
98
- export interface Migration<Old extends StorageSchema = any, New extends StorageSchema = any> {
99
- version: number;
100
- oldSchema: Old;
101
- newSchema: New;
102
- migrate: (engine: MigrationEngine) => Promise<void>;
103
- /** Collections which are added in the new schema and not present in the old */
104
- addedCollections: string[];
105
- /** Collections which were removed from the old schema */
106
- removedCollections: string[];
107
- /** All collections which exist after the migration has completed - i.e. the ones in the new schema */
108
- allCollections: string[];
109
- /** Only the collections which were in the old schema */
110
- oldCollections: string[];
111
- /** Collections whose fields or indexes changed between schemas */
112
- changedCollections: string[];
113
- addedIndexes: Record<string, MigrationIndexDescription[]>;
114
- removedIndexes: Record<string, MigrationIndexDescription[]>;
115
- }
116
- export declare function migrationRange(from: number, to: number): number[];
117
- /** @deprecated - use createMigration with no procedure function */
118
- export declare function createDefaultMigration(schema: StorageSchema): Migration<{
119
- version: 0;
120
- collections: {};
121
- }>;
122
- /** @deprecated - use createMigration with no procedure function */
123
- export declare function createDefaultMigration<Old extends StorageSchema>(oldSchema: Old, newSchema: StorageSchema): Migration<Old>;
124
- /** New, simpler type-safety migration tools */
125
- declare type DocumentShape<Init = any, Snapshot = any> = {
126
- init: Init;
127
- snapshot: Snapshot;
128
- };
129
- declare type SchemaDocuments = Record<string, DocumentShape>;
130
- declare type CollectionProcedure<OldSnapshot, NewInit> = {
131
- (old: OldSnapshot): NewInit | Promise<NewInit>;
132
- };
133
- declare type MigrationQueries<Old extends SchemaDocuments> = {
134
- [Key in keyof Old]: {
135
- get(primaryKey: string): Promise<Old[Key]['snapshot'] | undefined>;
136
- findOne(query: CollectionFilter): Promise<Old[Key]['snapshot'] | undefined>;
137
- findAll(query?: CollectionFilter): Promise<Old[Key]['snapshot'][]>;
138
- };
139
- };
140
- declare type MigrationMutations<New extends SchemaDocuments> = {
141
- [Key in keyof New]: {
142
- put(document: New[Key]['init']): Promise<New[Key]['snapshot']>;
143
- delete(primaryKey: string): Promise<void>;
144
- };
145
- };
146
- declare type MigrationTools<Old extends SchemaDocuments, New extends SchemaDocuments> = {
147
- /**
148
- * Process a change in a collection's documents by taking in each existing
149
- * document and returning its new shape. This is typed so you can be
150
- * confident the proper transformations are made.
151
- */
152
- migrate: <Collection extends keyof Old & keyof New>(collection: Collection, strategy: CollectionProcedure<Old[Collection]['snapshot'], New[Collection]['init']>) => Promise<void>;
153
- mutations: MigrationMutations<New>;
154
- queries: MigrationQueries<Old>;
155
- info: {
156
- changedCollections: (keyof Old & keyof New)[];
157
- addedCollections: (keyof New)[];
158
- removedCollections: (keyof Old)[];
159
- };
160
- };
161
- declare type MigrationProcedure<Old extends SchemaDocuments, New extends SchemaDocuments> = {
162
- (tools: MigrationTools<Old, New>): Promise<void>;
163
- };
164
- declare type InitialMigrationTools<New extends SchemaDocuments> = {
165
- mutations: MigrationMutations<New>;
166
- };
167
- declare type InitialMigrationProcedure<New extends SchemaDocuments> = {
168
- (tools: InitialMigrationTools<New>): Promise<void>;
169
- };
170
- export declare function createMigration<New extends SchemaDocuments>(newSchema: StorageSchema, procedure?: InitialMigrationProcedure<New>): any;
171
- export declare function createMigration<Old extends SchemaDocuments, New extends SchemaDocuments>(oldSchema: StorageSchema, newSchema: StorageSchema, procedure?: MigrationProcedure<Old, New>): any;
172
- export {};
1
+ import { StorageCollectionSchema, StorageSchema, StorageDocument, CollectionFilter, StorageDocumentInit } from './index.js';
2
+ /**@deprecated */
3
+ export interface DroppedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>> {
4
+ (old: Old): void | Promise<void>;
5
+ }
6
+ /**@deprecated */
7
+ export interface PreservedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> {
8
+ (old: StorageDocument<Old>): StorageDocument<New> | Promise<StorageDocument<New>>;
9
+ }
10
+ /** @deprecated */
11
+ export declare type MigrationsKeyedOnCollection<Old extends StorageSchema<any>, New extends StorageSchema<any>> = PreservedCollectionMigrations<Old, New> | DroppedCollectionMigrations<Old, New>;
12
+ /**@deprecated */
13
+ declare type NotInSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? never : Name;
14
+ /** @deprecated */
15
+ declare type InSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? Name : never;
16
+ /** @deprecated */
17
+ declare type DroppedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
18
+ [Key in keyof Old['collections'] as NotInSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
19
+ };
20
+ /** @deprecated */
21
+ declare type PreservedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
22
+ [Key in keyof Old['collections'] as InSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
23
+ };
24
+ /** @deprecated */
25
+ declare type DroppedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
26
+ [Key in keyof DroppedCollections<Old, New>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
27
+ };
28
+ /** @deprecated */
29
+ declare type PreservedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
30
+ [Key in keyof PreservedCollections<Old, New>]: PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]>;
31
+ };
32
+ /** @deprecated */
33
+ declare type StrategyFor<Key extends string, Old extends StorageSchema<any>, New extends StorageSchema<any>> = Key extends keyof New['collections'] ? PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]> : DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
34
+ /** @deprecated */
35
+ declare type DeprecatedMigrationRunner<Old extends StorageSchema<any>, New extends StorageSchema<any>> = <Collection extends Extract<keyof Old['collections'], string>>(collection: Collection, strategy: StrategyFor<Collection, Old, New>) => Promise<void>;
36
+ /** @deprecated */
37
+ declare type DeprecatedMigrationQueryMaker<Collection extends StorageCollectionSchema<any, any, any>> = {
38
+ get(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;
39
+ findOne(query: CollectionFilter): Promise<StorageDocument<Collection> | undefined>;
40
+ findAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;
41
+ };
42
+ /** @deprecated */
43
+ declare type DeprecatedMigrationQueries<Old extends StorageSchema<any>> = {
44
+ [Key in keyof Old['collections']]: DeprecatedMigrationQueryMaker<Old['collections'][Key]>;
45
+ };
46
+ /** @deprecated */
47
+ declare type DeprecatedMigrationMutations<New extends StorageSchema> = {
48
+ [Key in keyof New['collections']]: {
49
+ put(document: StorageDocumentInit<New['collections'][Key]>): Promise<StorageDocument<New['collections'][Key]>>;
50
+ delete(primaryKey: string): Promise<void>;
51
+ };
52
+ };
53
+ /** @deprecated */
54
+ export interface DeprecatedMigrationTools<Old extends StorageSchema<any>, New extends StorageSchema<any>> {
55
+ migrate: DeprecatedMigrationRunner<Old, New>;
56
+ identity: <T>(val: T) => T;
57
+ /**
58
+ * @deprecated - default field values are automatically
59
+ * applied during migration, you don't need to use this.
60
+ * Please remove it from your migrations - even old ones
61
+ * (old migrations can be updated!)
62
+ */
63
+ withDefaults: (collectionName: string, value: any) => any;
64
+ queries: DeprecatedMigrationQueries<Old>;
65
+ mutations: DeprecatedMigrationMutations<New>;
66
+ info: {
67
+ changedCollections: keyof Old['collections'][];
68
+ addedCollections: keyof New['collections'][];
69
+ removedCollections: keyof Old['collections'][];
70
+ };
71
+ }
72
+ export interface MigrationEngine {
73
+ migrate: (collection: string, strategy: (val: any) => any) => Promise<void>;
74
+ queries: MigrationQueries<any>;
75
+ mutations: MigrationMutations<any>;
76
+ /** OIDs of any new documents created during the migration */
77
+ newOids: string[];
78
+ /** Promises that should be resolved before completing the migration */
79
+ awaitables: Promise<any>[];
80
+ log: (...messages: any[]) => void;
81
+ }
82
+ /** @deprecated */
83
+ declare type DeprecatedMigrationProcedure<Old extends StorageSchema, New extends StorageSchema> = (tools: DeprecatedMigrationTools<Old, New>) => Promise<void>;
84
+ declare type EmptySchema = {
85
+ version: 0;
86
+ collections: {};
87
+ };
88
+ /** @deprecated - use createMigration */
89
+ export declare function migrate<Schema extends StorageSchema>(schema: Schema, procedure: DeprecatedMigrationProcedure<EmptySchema, Schema>): Migration<EmptySchema, Schema>;
90
+ /** @deprecated = use createMigration */
91
+ export declare function migrate<Old extends StorageSchema, New extends StorageSchema>(oldSchema: Old, newSchema: New, procedure: DeprecatedMigrationProcedure<Old, New>): Migration<Old, New>;
92
+ export interface MigrationIndexDescription {
93
+ name: string;
94
+ multiEntry: boolean;
95
+ synthetic: boolean;
96
+ compound: boolean;
97
+ }
98
+ export interface Migration<Old extends StorageSchema = any, New extends StorageSchema = any> {
99
+ version: number;
100
+ oldSchema: Old;
101
+ newSchema: New;
102
+ migrate: (engine: MigrationEngine) => Promise<void>;
103
+ /** Collections which are added in the new schema and not present in the old */
104
+ addedCollections: string[];
105
+ /** Collections which were removed from the old schema */
106
+ removedCollections: string[];
107
+ /** All collections which exist after the migration has completed - i.e. the ones in the new schema */
108
+ allCollections: string[];
109
+ /** Only the collections which were in the old schema */
110
+ oldCollections: string[];
111
+ /** Collections whose fields or indexes changed between schemas */
112
+ changedCollections: string[];
113
+ addedIndexes: Record<string, MigrationIndexDescription[]>;
114
+ removedIndexes: Record<string, MigrationIndexDescription[]>;
115
+ }
116
+ export declare function migrationRange(from: number, to: number): number[];
117
+ /** @deprecated - use createMigration with no procedure function */
118
+ export declare function createDefaultMigration(schema: StorageSchema): Migration<{
119
+ version: 0;
120
+ collections: {};
121
+ }>;
122
+ /** @deprecated - use createMigration with no procedure function */
123
+ export declare function createDefaultMigration<Old extends StorageSchema>(oldSchema: Old, newSchema: StorageSchema): Migration<Old>;
124
+ /** New, simpler type-safety migration tools */
125
+ declare type DocumentShape<Init = any, Snapshot = any> = {
126
+ init: Init;
127
+ snapshot: Snapshot;
128
+ };
129
+ declare type SchemaDocuments = Record<string, DocumentShape>;
130
+ declare type CollectionProcedure<OldSnapshot, NewInit> = {
131
+ (old: OldSnapshot): NewInit | Promise<NewInit>;
132
+ };
133
+ declare type MigrationQueries<Old extends SchemaDocuments> = {
134
+ [Key in keyof Old]: {
135
+ get(primaryKey: string): Promise<Old[Key]['snapshot'] | undefined>;
136
+ findOne(query: CollectionFilter): Promise<Old[Key]['snapshot'] | undefined>;
137
+ findAll(query?: CollectionFilter): Promise<Old[Key]['snapshot'][]>;
138
+ };
139
+ };
140
+ declare type MigrationMutations<New extends SchemaDocuments> = {
141
+ [Key in keyof New]: {
142
+ put(document: New[Key]['init']): Promise<New[Key]['snapshot']>;
143
+ delete(primaryKey: string): Promise<void>;
144
+ };
145
+ };
146
+ declare type MigrationTools<Old extends SchemaDocuments, New extends SchemaDocuments> = {
147
+ /**
148
+ * Process a change in a collection's documents by taking in each existing
149
+ * document and returning its new shape. This is typed so you can be
150
+ * confident the proper transformations are made.
151
+ */
152
+ migrate: <Collection extends keyof Old & keyof New>(collection: Collection, strategy: CollectionProcedure<Old[Collection]['snapshot'], New[Collection]['init']>) => Promise<void>;
153
+ mutations: MigrationMutations<New>;
154
+ queries: MigrationQueries<Old>;
155
+ info: {
156
+ changedCollections: (keyof Old & keyof New)[];
157
+ addedCollections: (keyof New)[];
158
+ removedCollections: (keyof Old)[];
159
+ };
160
+ };
161
+ declare type MigrationProcedure<Old extends SchemaDocuments, New extends SchemaDocuments> = {
162
+ (tools: MigrationTools<Old, New>): Promise<void>;
163
+ };
164
+ declare type InitialMigrationTools<New extends SchemaDocuments> = {
165
+ mutations: MigrationMutations<New>;
166
+ };
167
+ declare type InitialMigrationProcedure<New extends SchemaDocuments> = {
168
+ (tools: InitialMigrationTools<New>): Promise<void>;
169
+ };
170
+ export declare function createMigration<New extends SchemaDocuments>(newSchema: StorageSchema, procedure?: InitialMigrationProcedure<New>): any;
171
+ export declare function createMigration<Old extends SchemaDocuments, New extends SchemaDocuments>(oldSchema: StorageSchema, newSchema: StorageSchema, procedure?: MigrationProcedure<Old, New>): any;
172
+ export {};