@verdant-web/common 1.11.0 → 1.12.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 (159) 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 +41 -41
  6. package/dist/cjs/batching.js +88 -88
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/index.d.ts +18 -18
  10. package/dist/cjs/index.js +35 -35
  11. package/dist/cjs/indexes.d.ts +14 -14
  12. package/dist/cjs/indexes.js +115 -115
  13. package/dist/cjs/indexes.test.d.ts +1 -1
  14. package/dist/cjs/indexes.test.js +127 -127
  15. package/dist/cjs/migration.d.ts +98 -98
  16. package/dist/cjs/migration.js +127 -127
  17. package/dist/cjs/oids.d.ts +85 -87
  18. package/dist/cjs/oids.js +363 -374
  19. package/dist/cjs/oids.js.map +1 -1
  20. package/dist/cjs/oids.test.d.ts +1 -1
  21. package/dist/cjs/oids.test.js +269 -251
  22. package/dist/cjs/oids.test.js.map +1 -1
  23. package/dist/cjs/operation.d.ts +139 -139
  24. package/dist/cjs/operation.js +532 -532
  25. package/dist/cjs/operation.js.map +1 -1
  26. package/dist/cjs/operation.test.d.ts +1 -1
  27. package/dist/cjs/operation.test.js +505 -505
  28. package/dist/cjs/operation.test.js.map +1 -1
  29. package/dist/cjs/patch.d.ts +26 -26
  30. package/dist/cjs/patch.js +226 -226
  31. package/dist/cjs/patch.js.map +1 -1
  32. package/dist/cjs/presence.d.ts +27 -27
  33. package/dist/cjs/presence.js +2 -2
  34. package/dist/cjs/protocol.d.ts +145 -145
  35. package/dist/cjs/protocol.js +3 -3
  36. package/dist/cjs/refs.d.ts +5 -5
  37. package/dist/cjs/refs.js +21 -21
  38. package/dist/cjs/replica.d.ts +28 -28
  39. package/dist/cjs/replica.js +28 -28
  40. package/dist/cjs/schema/defaults.d.ts +4 -4
  41. package/dist/cjs/schema/defaults.js +71 -71
  42. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  43. package/dist/cjs/schema/defaults.test.js +20 -20
  44. package/dist/cjs/schema/defaults.test.js.map +1 -1
  45. package/dist/cjs/schema/index.d.ts +8 -8
  46. package/dist/cjs/schema/index.js +28 -28
  47. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  48. package/dist/cjs/schema/indexFilters.js +30 -30
  49. package/dist/cjs/schema/types/collection.d.ts +51 -51
  50. package/dist/cjs/schema/types/collection.js +2 -2
  51. package/dist/cjs/schema/types/compounds.d.ts +12 -12
  52. package/dist/cjs/schema/types/compounds.js +2 -2
  53. package/dist/cjs/schema/types/fields.d.ts +59 -59
  54. package/dist/cjs/schema/types/fields.js +2 -2
  55. package/dist/cjs/schema/types/filters.d.ts +29 -29
  56. package/dist/cjs/schema/types/filters.js +2 -2
  57. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  58. package/dist/cjs/schema/types/shapes.js +2 -2
  59. package/dist/cjs/schema/types/synthetics.d.ts +28 -28
  60. package/dist/cjs/schema/types/synthetics.js +2 -2
  61. package/dist/cjs/schema/types.d.ts +18 -18
  62. package/dist/cjs/schema/types.js +22 -22
  63. package/dist/cjs/timestamp.d.ts +48 -48
  64. package/dist/cjs/timestamp.js +243 -243
  65. package/dist/cjs/timestamp.test.d.ts +1 -1
  66. package/dist/cjs/timestamp.test.js +93 -93
  67. package/dist/cjs/undo.d.ts +3 -3
  68. package/dist/cjs/undo.js +198 -198
  69. package/dist/cjs/utils.d.ts +15 -15
  70. package/dist/cjs/utils.js +127 -127
  71. package/dist/cjs/utils.test.d.ts +1 -1
  72. package/dist/cjs/utils.test.js +36 -36
  73. package/dist/esm/EventSubscriber.d.ts +17 -17
  74. package/dist/esm/EventSubscriber.js +62 -62
  75. package/dist/esm/baseline.d.ts +5 -5
  76. package/dist/esm/baseline.js +1 -1
  77. package/dist/esm/batching.d.ts +41 -41
  78. package/dist/esm/batching.js +83 -83
  79. package/dist/esm/files.d.ts +19 -19
  80. package/dist/esm/files.js +12 -12
  81. package/dist/esm/index.d.ts +18 -18
  82. package/dist/esm/index.js +15 -15
  83. package/dist/esm/indexes.d.ts +14 -14
  84. package/dist/esm/indexes.js +105 -105
  85. package/dist/esm/indexes.test.d.ts +1 -1
  86. package/dist/esm/indexes.test.js +125 -125
  87. package/dist/esm/migration.d.ts +98 -98
  88. package/dist/esm/migration.js +121 -121
  89. package/dist/esm/oids.d.ts +85 -87
  90. package/dist/esm/oids.js +336 -347
  91. package/dist/esm/oids.js.map +1 -1
  92. package/dist/esm/oids.test.d.ts +1 -1
  93. package/dist/esm/oids.test.js +267 -249
  94. package/dist/esm/oids.test.js.map +1 -1
  95. package/dist/esm/operation.d.ts +139 -139
  96. package/dist/esm/operation.js +517 -517
  97. package/dist/esm/operation.js.map +1 -1
  98. package/dist/esm/operation.test.d.ts +1 -1
  99. package/dist/esm/operation.test.js +503 -503
  100. package/dist/esm/operation.test.js.map +1 -1
  101. package/dist/esm/patch.d.ts +26 -26
  102. package/dist/esm/patch.js +222 -222
  103. package/dist/esm/patch.js.map +1 -1
  104. package/dist/esm/presence.d.ts +27 -27
  105. package/dist/esm/presence.js +1 -1
  106. package/dist/esm/protocol.d.ts +145 -145
  107. package/dist/esm/protocol.js +2 -2
  108. package/dist/esm/refs.d.ts +5 -5
  109. package/dist/esm/refs.js +16 -16
  110. package/dist/esm/replica.d.ts +28 -28
  111. package/dist/esm/replica.js +25 -25
  112. package/dist/esm/schema/defaults.d.ts +4 -4
  113. package/dist/esm/schema/defaults.js +65 -65
  114. package/dist/esm/schema/defaults.test.d.ts +1 -1
  115. package/dist/esm/schema/defaults.test.js +18 -18
  116. package/dist/esm/schema/defaults.test.js.map +1 -1
  117. package/dist/esm/schema/index.d.ts +8 -8
  118. package/dist/esm/schema/index.js +9 -9
  119. package/dist/esm/schema/indexFilters.d.ts +6 -6
  120. package/dist/esm/schema/indexFilters.js +22 -22
  121. package/dist/esm/schema/types/collection.d.ts +51 -51
  122. package/dist/esm/schema/types/collection.js +1 -1
  123. package/dist/esm/schema/types/compounds.d.ts +12 -12
  124. package/dist/esm/schema/types/compounds.js +1 -1
  125. package/dist/esm/schema/types/fields.d.ts +59 -59
  126. package/dist/esm/schema/types/fields.js +1 -1
  127. package/dist/esm/schema/types/filters.d.ts +29 -29
  128. package/dist/esm/schema/types/filters.js +1 -1
  129. package/dist/esm/schema/types/shapes.d.ts +21 -21
  130. package/dist/esm/schema/types/shapes.js +1 -1
  131. package/dist/esm/schema/types/synthetics.d.ts +28 -28
  132. package/dist/esm/schema/types/synthetics.js +1 -1
  133. package/dist/esm/schema/types.d.ts +18 -18
  134. package/dist/esm/schema/types.js +6 -6
  135. package/dist/esm/timestamp.d.ts +48 -48
  136. package/dist/esm/timestamp.js +228 -228
  137. package/dist/esm/timestamp.test.d.ts +1 -1
  138. package/dist/esm/timestamp.test.js +91 -91
  139. package/dist/esm/undo.d.ts +3 -3
  140. package/dist/esm/undo.js +194 -194
  141. package/dist/esm/utils.d.ts +15 -15
  142. package/dist/esm/utils.js +113 -113
  143. package/dist/esm/utils.test.d.ts +1 -1
  144. package/dist/esm/utils.test.js +34 -34
  145. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  146. package/dist/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +1 -1
  148. package/src/oids.test.ts +62 -51
  149. package/src/oids.ts +7 -26
  150. package/src/operation.test.ts +32 -40
  151. package/src/operation.ts +4 -16
  152. package/src/patch.ts +5 -15
  153. package/src/schema/defaults.test.ts +1 -1
  154. package/dist/cjs/files.test.d.ts +0 -1
  155. package/dist/cjs/files.test.js +0 -81
  156. package/dist/cjs/files.test.js.map +0 -1
  157. package/dist/esm/files.test.d.ts +0 -1
  158. package/dist/esm/files.test.js +0 -79
  159. package/dist/esm/files.test.js.map +0 -1
@@ -1,126 +1,126 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { COMPOUND_INDEX_LOWER_BOUND_SEPARATOR, COMPOUND_INDEX_SEPARATOR, COMPOUND_INDEX_UPPER_BOUND_SEPARATOR, createCompoundIndexValue, createLowerBoundIndexValue, createUpperBoundIndexValue, } from './indexes.js';
3
- describe('compound indexes', () => {
4
- it('can be created from two string values', () => {
5
- expect(createCompoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b`);
6
- });
7
- it('can be created from two number values', () => {
8
- expect(createCompoundIndexValue(1, 2)).toEqual(`1${COMPOUND_INDEX_SEPARATOR}2`);
9
- });
10
- it('can be created from an array and string value', () => {
11
- expect(createCompoundIndexValue(['a', 'b'], 'c')).toEqual([
12
- `a${COMPOUND_INDEX_SEPARATOR}c`,
13
- `b${COMPOUND_INDEX_SEPARATOR}c`,
14
- ]);
15
- });
16
- it('can be created from a string and array of numbers', () => {
17
- expect(createCompoundIndexValue('a', [1, 2])).toEqual([
18
- `a${COMPOUND_INDEX_SEPARATOR}1`,
19
- `a${COMPOUND_INDEX_SEPARATOR}2`,
20
- ]);
21
- });
22
- it('can be created from an array of strings and an array of booleans', () => {
23
- expect(createCompoundIndexValue(['a', 'b'], [true, false])).toEqual([
24
- `a${COMPOUND_INDEX_SEPARATOR}true`,
25
- `a${COMPOUND_INDEX_SEPARATOR}false`,
26
- `b${COMPOUND_INDEX_SEPARATOR}true`,
27
- `b${COMPOUND_INDEX_SEPARATOR}false`,
28
- ]);
29
- });
30
- it('remove duplicate array compound index values', () => {
31
- expect(createCompoundIndexValue(['a', 'b', 'b'], [true, false, true])).toEqual([
32
- `a${COMPOUND_INDEX_SEPARATOR}true`,
33
- `a${COMPOUND_INDEX_SEPARATOR}false`,
34
- `b${COMPOUND_INDEX_SEPARATOR}true`,
35
- `b${COMPOUND_INDEX_SEPARATOR}false`,
36
- ]);
37
- });
38
- it('creates lower bound value for multi-value indexes', () => {
39
- expect(createLowerBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
40
- });
41
- it('creates upper bound value for multi-value indexes', () => {
42
- expect(createUpperBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
43
- }),
44
- it('will always be grouped by the first item', () => {
45
- expect([
46
- createCompoundIndexValue('aaaaaa', 'b'),
47
- createCompoundIndexValue('aaaaaa', 'c'),
48
- createCompoundIndexValue('aaaaaa', 'd'),
49
- createCompoundIndexValue('aaaaaa', 'e'),
50
- // extra nefarious!
51
- createCompoundIndexValue('aaaaaaa', 'no!'),
52
- createCompoundIndexValue('aaaaaa ', 'no!'),
53
- createCompoundIndexValue(`aaaaaa😎`, 'no!'),
54
- createCompoundIndexValue(`aaaaaa😎😎`, 'no!'),
55
- createCompoundIndexValue('aaa', 'no!'),
56
- createCompoundIndexValue(`aaaaaaa😎no!`, 'no!'),
57
- ].sort()).toEqual([
58
- `aaaaaa ${COMPOUND_INDEX_SEPARATOR}no!`,
59
- `aaaaaaa😎no!${COMPOUND_INDEX_SEPARATOR}no!`,
60
- `aaaaaaa${COMPOUND_INDEX_SEPARATOR}no!`,
61
- `aaaaaa😎😎${COMPOUND_INDEX_SEPARATOR}no!`,
62
- `aaaaaa😎${COMPOUND_INDEX_SEPARATOR}no!`,
63
- // this is the contiguous block of relevant values
64
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
65
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
66
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
67
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
68
- // here ends the block
69
- `aaa${COMPOUND_INDEX_SEPARATOR}no!`,
70
- ]);
71
- });
72
- it('will be bounded by upper and lower bound values', () => {
73
- const match = 'aaaaaa';
74
- const sorted = [
75
- createCompoundIndexValue(match, 'b'),
76
- createCompoundIndexValue(match, 'c'),
77
- createCompoundIndexValue(match, 'd'),
78
- createCompoundIndexValue(match, 'e'),
79
- // extra nefarious!
80
- createCompoundIndexValue(`${match}a`, 'no!'),
81
- createCompoundIndexValue(`${match} `, 'no!'),
82
- createCompoundIndexValue(`${match}😎`, 'no!'),
83
- createCompoundIndexValue(`${match}😎😎`, 'no!'),
84
- createCompoundIndexValue('aaa', 'no!'),
85
- createCompoundIndexValue(`${match}a😎no!`, 'no!'),
86
- ].sort();
87
- const boundedBlock = sorted.filter((value) => value > createLowerBoundIndexValue(match) &&
88
- value < createUpperBoundIndexValue(match));
89
- expect(boundedBlock).toEqual([
90
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
91
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
92
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
93
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
94
- ]);
95
- });
96
- it('will be bounded by upper and lower bounds when matching multiple sections', () => {
97
- const match1 = 'aaaaaa';
98
- const match2 = 'bbbbbb';
99
- const sorted = [
100
- createCompoundIndexValue(match1, match2, 'b'),
101
- createCompoundIndexValue(match1, match2, 'c'),
102
- createCompoundIndexValue(match1, match2, 'd'),
103
- createCompoundIndexValue(match1, match2, 'e'),
104
- // extra nefarious!
105
- createCompoundIndexValue(`${match1}a`, match2, 'no!'),
106
- createCompoundIndexValue(`${match1} `, match2, 'no!'),
107
- createCompoundIndexValue(`${match1}😎`, match2, 'no!'),
108
- createCompoundIndexValue(`${match1}😎😎`, match2, 'no!'),
109
- createCompoundIndexValue('aaa', match2, 'no!'),
110
- createCompoundIndexValue(`${match1}a😎no!`, match2, 'no!'),
111
- createCompoundIndexValue(match1, `${match2}a😎no!`, 'no!'),
112
- createCompoundIndexValue(match1, `${match2} `, 'no!'),
113
- createCompoundIndexValue(match1, ' ', 'no!'),
114
- createCompoundIndexValue(match1, '\u00001', 'no!'),
115
- createCompoundIndexValue(match1, '\uE007f', 'no!'),
116
- ].sort();
117
- expect(sorted.filter((value) => value > createLowerBoundIndexValue(match1, match2) &&
118
- value < createUpperBoundIndexValue(match1, match2))).toEqual([
119
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}b`,
120
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}c`,
121
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}d`,
122
- `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}e`,
123
- ]);
124
- });
125
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { COMPOUND_INDEX_LOWER_BOUND_SEPARATOR, COMPOUND_INDEX_SEPARATOR, COMPOUND_INDEX_UPPER_BOUND_SEPARATOR, createCompoundIndexValue, createLowerBoundIndexValue, createUpperBoundIndexValue, } from './indexes.js';
3
+ describe('compound indexes', () => {
4
+ it('can be created from two string values', () => {
5
+ expect(createCompoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b`);
6
+ });
7
+ it('can be created from two number values', () => {
8
+ expect(createCompoundIndexValue(1, 2)).toEqual(`1${COMPOUND_INDEX_SEPARATOR}2`);
9
+ });
10
+ it('can be created from an array and string value', () => {
11
+ expect(createCompoundIndexValue(['a', 'b'], 'c')).toEqual([
12
+ `a${COMPOUND_INDEX_SEPARATOR}c`,
13
+ `b${COMPOUND_INDEX_SEPARATOR}c`,
14
+ ]);
15
+ });
16
+ it('can be created from a string and array of numbers', () => {
17
+ expect(createCompoundIndexValue('a', [1, 2])).toEqual([
18
+ `a${COMPOUND_INDEX_SEPARATOR}1`,
19
+ `a${COMPOUND_INDEX_SEPARATOR}2`,
20
+ ]);
21
+ });
22
+ it('can be created from an array of strings and an array of booleans', () => {
23
+ expect(createCompoundIndexValue(['a', 'b'], [true, false])).toEqual([
24
+ `a${COMPOUND_INDEX_SEPARATOR}true`,
25
+ `a${COMPOUND_INDEX_SEPARATOR}false`,
26
+ `b${COMPOUND_INDEX_SEPARATOR}true`,
27
+ `b${COMPOUND_INDEX_SEPARATOR}false`,
28
+ ]);
29
+ });
30
+ it('remove duplicate array compound index values', () => {
31
+ expect(createCompoundIndexValue(['a', 'b', 'b'], [true, false, true])).toEqual([
32
+ `a${COMPOUND_INDEX_SEPARATOR}true`,
33
+ `a${COMPOUND_INDEX_SEPARATOR}false`,
34
+ `b${COMPOUND_INDEX_SEPARATOR}true`,
35
+ `b${COMPOUND_INDEX_SEPARATOR}false`,
36
+ ]);
37
+ });
38
+ it('creates lower bound value for multi-value indexes', () => {
39
+ expect(createLowerBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_SEPARATOR}${COMPOUND_INDEX_LOWER_BOUND_SEPARATOR}`);
40
+ });
41
+ it('creates upper bound value for multi-value indexes', () => {
42
+ expect(createUpperBoundIndexValue('a', 'b')).toEqual(`a${COMPOUND_INDEX_SEPARATOR}b${COMPOUND_INDEX_UPPER_BOUND_SEPARATOR}`);
43
+ }),
44
+ it('will always be grouped by the first item', () => {
45
+ expect([
46
+ createCompoundIndexValue('aaaaaa', 'b'),
47
+ createCompoundIndexValue('aaaaaa', 'c'),
48
+ createCompoundIndexValue('aaaaaa', 'd'),
49
+ createCompoundIndexValue('aaaaaa', 'e'),
50
+ // extra nefarious!
51
+ createCompoundIndexValue('aaaaaaa', 'no!'),
52
+ createCompoundIndexValue('aaaaaa ', 'no!'),
53
+ createCompoundIndexValue(`aaaaaa😎`, 'no!'),
54
+ createCompoundIndexValue(`aaaaaa😎😎`, 'no!'),
55
+ createCompoundIndexValue('aaa', 'no!'),
56
+ createCompoundIndexValue(`aaaaaaa😎no!`, 'no!'),
57
+ ].sort()).toEqual([
58
+ `aaaaaa ${COMPOUND_INDEX_SEPARATOR}no!`,
59
+ `aaaaaaa😎no!${COMPOUND_INDEX_SEPARATOR}no!`,
60
+ `aaaaaaa${COMPOUND_INDEX_SEPARATOR}no!`,
61
+ `aaaaaa😎😎${COMPOUND_INDEX_SEPARATOR}no!`,
62
+ `aaaaaa😎${COMPOUND_INDEX_SEPARATOR}no!`,
63
+ // this is the contiguous block of relevant values
64
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
65
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
66
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
67
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
68
+ // here ends the block
69
+ `aaa${COMPOUND_INDEX_SEPARATOR}no!`,
70
+ ]);
71
+ });
72
+ it('will be bounded by upper and lower bound values', () => {
73
+ const match = 'aaaaaa';
74
+ const sorted = [
75
+ createCompoundIndexValue(match, 'b'),
76
+ createCompoundIndexValue(match, 'c'),
77
+ createCompoundIndexValue(match, 'd'),
78
+ createCompoundIndexValue(match, 'e'),
79
+ // extra nefarious!
80
+ createCompoundIndexValue(`${match}a`, 'no!'),
81
+ createCompoundIndexValue(`${match} `, 'no!'),
82
+ createCompoundIndexValue(`${match}😎`, 'no!'),
83
+ createCompoundIndexValue(`${match}😎😎`, 'no!'),
84
+ createCompoundIndexValue('aaa', 'no!'),
85
+ createCompoundIndexValue(`${match}a😎no!`, 'no!'),
86
+ ].sort();
87
+ const boundedBlock = sorted.filter((value) => value > createLowerBoundIndexValue(match) &&
88
+ value < createUpperBoundIndexValue(match));
89
+ expect(boundedBlock).toEqual([
90
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}b`,
91
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}c`,
92
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}d`,
93
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}e`,
94
+ ]);
95
+ });
96
+ it('will be bounded by upper and lower bounds when matching multiple sections', () => {
97
+ const match1 = 'aaaaaa';
98
+ const match2 = 'bbbbbb';
99
+ const sorted = [
100
+ createCompoundIndexValue(match1, match2, 'b'),
101
+ createCompoundIndexValue(match1, match2, 'c'),
102
+ createCompoundIndexValue(match1, match2, 'd'),
103
+ createCompoundIndexValue(match1, match2, 'e'),
104
+ // extra nefarious!
105
+ createCompoundIndexValue(`${match1}a`, match2, 'no!'),
106
+ createCompoundIndexValue(`${match1} `, match2, 'no!'),
107
+ createCompoundIndexValue(`${match1}😎`, match2, 'no!'),
108
+ createCompoundIndexValue(`${match1}😎😎`, match2, 'no!'),
109
+ createCompoundIndexValue('aaa', match2, 'no!'),
110
+ createCompoundIndexValue(`${match1}a😎no!`, match2, 'no!'),
111
+ createCompoundIndexValue(match1, `${match2}a😎no!`, 'no!'),
112
+ createCompoundIndexValue(match1, `${match2} `, 'no!'),
113
+ createCompoundIndexValue(match1, ' ', 'no!'),
114
+ createCompoundIndexValue(match1, '\u00001', 'no!'),
115
+ createCompoundIndexValue(match1, '\uE007f', 'no!'),
116
+ ].sort();
117
+ expect(sorted.filter((value) => value > createLowerBoundIndexValue(match1, match2) &&
118
+ value < createUpperBoundIndexValue(match1, match2))).toEqual([
119
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}b`,
120
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}c`,
121
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}d`,
122
+ `aaaaaa${COMPOUND_INDEX_SEPARATOR}bbbbbb${COMPOUND_INDEX_SEPARATOR}e`,
123
+ ]);
124
+ });
125
+ });
126
126
  //# sourceMappingURL=indexes.test.js.map
@@ -1,98 +1,98 @@
1
- import { StorageCollectionSchema, StorageSchema, StorageDocument, CollectionFilter, StorageDocumentInit } from './index.js';
2
- export interface DroppedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>> {
3
- (old: Old): void | Promise<void>;
4
- }
5
- export interface PreservedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> {
6
- (old: StorageDocument<Old>): StorageDocument<New> | Promise<StorageDocument<New>>;
7
- }
8
- declare type MigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> = DroppedCollectionMigrationStrategy<Old> | PreservedCollectionMigrationStrategy<Old, New>;
9
- export declare type MigrationsKeyedOnCollection<Old extends StorageSchema<any>, New extends StorageSchema<any>> = PreservedCollectionMigrations<Old, New> | DroppedCollectionMigrations<Old, New>;
10
- declare type NotInSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? never : Name;
11
- declare type InSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? Name : never;
12
- declare type DroppedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
13
- [Key in keyof Old['collections'] as NotInSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
14
- };
15
- declare type PreservedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
16
- [Key in keyof Old['collections'] as InSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
17
- };
18
- declare type DroppedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
19
- [Key in keyof DroppedCollections<Old, New>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
20
- };
21
- declare type PreservedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
22
- [Key in keyof PreservedCollections<Old, New>]: PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]>;
23
- };
24
- 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]>;
25
- declare type MigrationRunner<Old extends StorageSchema<any>, New extends StorageSchema<any>> = <Collection extends Extract<keyof Old['collections'], string>>(collection: Collection, strategy: StrategyFor<Collection, Old, New>) => Promise<void>;
26
- declare type MigrationQueryMaker<Collection extends StorageCollectionSchema<any, any, any>> = {
27
- get(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;
28
- findOne(query: CollectionFilter): Promise<StorageDocument<Collection> | undefined>;
29
- findAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;
30
- };
31
- declare type MigrationQueries<Old extends StorageSchema<any>> = {
32
- [Key in keyof Old['collections']]: MigrationQueryMaker<Old['collections'][Key]>;
33
- };
34
- declare type MigrationMutations<New extends StorageSchema> = {
35
- [Key in keyof New['collections']]: {
36
- put(document: StorageDocumentInit<New['collections'][Key]>): Promise<StorageDocument<New['collections'][Key]>>;
37
- delete(primaryKey: string): Promise<void>;
38
- };
39
- };
40
- export interface MigrationTools<Old extends StorageSchema<any>, New extends StorageSchema<any>> {
41
- migrate: MigrationRunner<Old, New>;
42
- identity: <T>(val: T) => T;
43
- withDefaults: (collectionName: string, value: any) => any;
44
- queries: MigrationQueries<Old>;
45
- mutations: MigrationMutations<New>;
46
- info: {
47
- changedCollections: keyof Old['collections'][];
48
- addedCollections: keyof New['collections'][];
49
- removedCollections: keyof Old['collections'][];
50
- };
51
- }
52
- export interface MigrationEngine<Old extends StorageSchema, New extends StorageSchema> {
53
- migrate: (collection: string, strategy: MigrationStrategy<any, any>) => Promise<void>;
54
- queries: MigrationQueries<Old>;
55
- mutations: MigrationMutations<New>;
56
- /** OIDs of any new documents created during the migration */
57
- newOids: string[];
58
- /** Promises that should be resolved before completing the migration */
59
- awaitables: Promise<any>[];
60
- }
61
- declare type MigrationProcedure<Old extends StorageSchema, New extends StorageSchema> = (tools: MigrationTools<Old, New>) => Promise<void>;
62
- declare type EmptySchema = {
63
- version: 0;
64
- collections: {};
65
- };
66
- export declare function migrate<Schema extends StorageSchema>(schema: Schema, procedure: MigrationProcedure<EmptySchema, Schema>): Migration<EmptySchema, Schema>;
67
- export declare function migrate<Old extends StorageSchema, New extends StorageSchema>(oldSchema: Old, newSchema: New, procedure: MigrationProcedure<Old, New>): Migration<Old, New>;
68
- export interface MigrationIndexDescription {
69
- name: string;
70
- multiEntry: boolean;
71
- synthetic: boolean;
72
- compound: boolean;
73
- }
74
- export interface Migration<Old extends StorageSchema = any, New extends StorageSchema = any> {
75
- version: number;
76
- oldSchema: Old;
77
- newSchema: New;
78
- migrate: (engine: MigrationEngine<Old, New>) => Promise<void>;
79
- /** Collections which are added in the new schema and not present in the old */
80
- addedCollections: string[];
81
- /** Collections which were removed from the old schema */
82
- removedCollections: string[];
83
- /** All collections which exist after the migration has completed - i.e. the ones in the new schema */
84
- allCollections: string[];
85
- /** Only the collections which were in the old schema */
86
- oldCollections: string[];
87
- /** Collections whose fields or indexes changed between schemas */
88
- changedCollections: string[];
89
- addedIndexes: Record<string, MigrationIndexDescription[]>;
90
- removedIndexes: Record<string, MigrationIndexDescription[]>;
91
- }
92
- export declare function migrationRange(from: number, to: number): number[];
93
- export declare function createDefaultMigration(schema: StorageSchema): Migration<{
94
- version: 0;
95
- collections: {};
96
- }>;
97
- export declare function createDefaultMigration<Old extends StorageSchema>(oldSchema: Old, newSchema: StorageSchema): Migration<Old>;
98
- export {};
1
+ import { StorageCollectionSchema, StorageSchema, StorageDocument, CollectionFilter, StorageDocumentInit } from './index.js';
2
+ export interface DroppedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>> {
3
+ (old: Old): void | Promise<void>;
4
+ }
5
+ export interface PreservedCollectionMigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> {
6
+ (old: StorageDocument<Old>): StorageDocument<New> | Promise<StorageDocument<New>>;
7
+ }
8
+ declare type MigrationStrategy<Old extends StorageCollectionSchema<any, any, any>, New extends StorageCollectionSchema<any, any, any>> = DroppedCollectionMigrationStrategy<Old> | PreservedCollectionMigrationStrategy<Old, New>;
9
+ export declare type MigrationsKeyedOnCollection<Old extends StorageSchema<any>, New extends StorageSchema<any>> = PreservedCollectionMigrations<Old, New> | DroppedCollectionMigrations<Old, New>;
10
+ declare type NotInSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? never : Name;
11
+ declare type InSchema<Name extends string | number | symbol, Schema extends StorageSchema<any>> = Name extends keyof Schema['collections'] ? Name : never;
12
+ declare type DroppedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
13
+ [Key in keyof Old['collections'] as NotInSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
14
+ };
15
+ declare type PreservedCollections<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
16
+ [Key in keyof Old['collections'] as InSchema<Key, New>]: StorageCollectionSchema<any, any, any>;
17
+ };
18
+ declare type DroppedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
19
+ [Key in keyof DroppedCollections<Old, New>]: DroppedCollectionMigrationStrategy<Old['collections'][Key]>;
20
+ };
21
+ declare type PreservedCollectionMigrations<Old extends StorageSchema<any>, New extends StorageSchema<any>> = {
22
+ [Key in keyof PreservedCollections<Old, New>]: PreservedCollectionMigrationStrategy<Old['collections'][Key], New['collections'][Key]>;
23
+ };
24
+ 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]>;
25
+ declare type MigrationRunner<Old extends StorageSchema<any>, New extends StorageSchema<any>> = <Collection extends Extract<keyof Old['collections'], string>>(collection: Collection, strategy: StrategyFor<Collection, Old, New>) => Promise<void>;
26
+ declare type MigrationQueryMaker<Collection extends StorageCollectionSchema<any, any, any>> = {
27
+ get(primaryKey: string): Promise<StorageDocument<Collection> | undefined>;
28
+ findOne(query: CollectionFilter): Promise<StorageDocument<Collection> | undefined>;
29
+ findAll(query?: CollectionFilter): Promise<StorageDocument<Collection>[]>;
30
+ };
31
+ declare type MigrationQueries<Old extends StorageSchema<any>> = {
32
+ [Key in keyof Old['collections']]: MigrationQueryMaker<Old['collections'][Key]>;
33
+ };
34
+ declare type MigrationMutations<New extends StorageSchema> = {
35
+ [Key in keyof New['collections']]: {
36
+ put(document: StorageDocumentInit<New['collections'][Key]>): Promise<StorageDocument<New['collections'][Key]>>;
37
+ delete(primaryKey: string): Promise<void>;
38
+ };
39
+ };
40
+ export interface MigrationTools<Old extends StorageSchema<any>, New extends StorageSchema<any>> {
41
+ migrate: MigrationRunner<Old, New>;
42
+ identity: <T>(val: T) => T;
43
+ withDefaults: (collectionName: string, value: any) => any;
44
+ queries: MigrationQueries<Old>;
45
+ mutations: MigrationMutations<New>;
46
+ info: {
47
+ changedCollections: keyof Old['collections'][];
48
+ addedCollections: keyof New['collections'][];
49
+ removedCollections: keyof Old['collections'][];
50
+ };
51
+ }
52
+ export interface MigrationEngine<Old extends StorageSchema, New extends StorageSchema> {
53
+ migrate: (collection: string, strategy: MigrationStrategy<any, any>) => Promise<void>;
54
+ queries: MigrationQueries<Old>;
55
+ mutations: MigrationMutations<New>;
56
+ /** OIDs of any new documents created during the migration */
57
+ newOids: string[];
58
+ /** Promises that should be resolved before completing the migration */
59
+ awaitables: Promise<any>[];
60
+ }
61
+ declare type MigrationProcedure<Old extends StorageSchema, New extends StorageSchema> = (tools: MigrationTools<Old, New>) => Promise<void>;
62
+ declare type EmptySchema = {
63
+ version: 0;
64
+ collections: {};
65
+ };
66
+ export declare function migrate<Schema extends StorageSchema>(schema: Schema, procedure: MigrationProcedure<EmptySchema, Schema>): Migration<EmptySchema, Schema>;
67
+ export declare function migrate<Old extends StorageSchema, New extends StorageSchema>(oldSchema: Old, newSchema: New, procedure: MigrationProcedure<Old, New>): Migration<Old, New>;
68
+ export interface MigrationIndexDescription {
69
+ name: string;
70
+ multiEntry: boolean;
71
+ synthetic: boolean;
72
+ compound: boolean;
73
+ }
74
+ export interface Migration<Old extends StorageSchema = any, New extends StorageSchema = any> {
75
+ version: number;
76
+ oldSchema: Old;
77
+ newSchema: New;
78
+ migrate: (engine: MigrationEngine<Old, New>) => Promise<void>;
79
+ /** Collections which are added in the new schema and not present in the old */
80
+ addedCollections: string[];
81
+ /** Collections which were removed from the old schema */
82
+ removedCollections: string[];
83
+ /** All collections which exist after the migration has completed - i.e. the ones in the new schema */
84
+ allCollections: string[];
85
+ /** Only the collections which were in the old schema */
86
+ oldCollections: string[];
87
+ /** Collections whose fields or indexes changed between schemas */
88
+ changedCollections: string[];
89
+ addedIndexes: Record<string, MigrationIndexDescription[]>;
90
+ removedIndexes: Record<string, MigrationIndexDescription[]>;
91
+ }
92
+ export declare function migrationRange(from: number, to: number): number[];
93
+ export declare function createDefaultMigration(schema: StorageSchema): Migration<{
94
+ version: 0;
95
+ collections: {};
96
+ }>;
97
+ export declare function createDefaultMigration<Old extends StorageSchema>(oldSchema: Old, newSchema: StorageSchema): Migration<Old>;
98
+ export {};