@remit/calendar-service 0.0.2 → 0.0.4

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.
@@ -0,0 +1,350 @@
1
+ import type {
2
+ CalendarCollectionItem,
3
+ CalendarEventIndexItem,
4
+ CalendarFeedTokenItem,
5
+ CalendarObjectItem,
6
+ CalendarOccurrenceInput,
7
+ CalendarSuggestionItem,
8
+ CreateCalendarCollectionInput,
9
+ ICalendarCollectionRepository,
10
+ ICalendarEventIndexRepository,
11
+ ICalendarFeedTokenRepository,
12
+ ICalendarObjectRepository,
13
+ ICalendarSuggestionRepository,
14
+ ICalendarUnitOfWork,
15
+ PutCalendarFeedTokenInput,
16
+ PutCalendarObjectInput as PutCalendarObjectRow,
17
+ PutCalendarSuggestionInput,
18
+ SettleCalendarSuggestionInput,
19
+ UpdateCalendarCollectionInput,
20
+ } from "@remit/data-ports";
21
+ import { NotFoundError } from "@remit/data-ports/errors";
22
+ import {
23
+ deriveCalendarFeedTokenId,
24
+ deriveCalendarId,
25
+ deriveCalendarObjectId,
26
+ deriveCalendarSuggestionId,
27
+ normalizeCalendarUrlSegment,
28
+ } from "@remit/data-ports/id";
29
+ import { CalendarSuggestionState } from "@remit/domain-enums";
30
+
31
+ // The class the port's conformance suite requires a repository to throw for an
32
+ // absent row, so a caller that branches on it — the calendar feed answers 404 to
33
+ // a token whose collection is gone — behaves the same against this double as
34
+ // against a real one.
35
+ export class MissingRow extends NotFoundError {}
36
+
37
+ /**
38
+ * A pass-through unit of work over plain maps — the shape the port documents
39
+ * for a backend with no cross-entity transaction. It proves the write path
40
+ * calls what it should, in the order it should; that the three writes stand or
41
+ * fall together is proven against a real transaction, in
42
+ * drizzle-service's calendar-put.sqlite.test.ts.
43
+ */
44
+ export class MemoryCalendarStore implements ICalendarUnitOfWork {
45
+ readonly collections = new Map<string, CalendarCollectionItem>();
46
+ readonly objects = new Map<string, CalendarObjectItem>();
47
+ readonly occurrences = new Map<string, CalendarEventIndexItem[]>();
48
+ readonly suggestions = new Map<string, CalendarSuggestionItem>();
49
+ readonly feedTokens = new Map<string, CalendarFeedTokenItem>();
50
+
51
+ private readonly collectionRepo: ICalendarCollectionRepository = {
52
+ create: async (input: CreateCalendarCollectionInput) => {
53
+ const urlSegment = normalizeCalendarUrlSegment(input.urlSegment);
54
+ const calendarId = deriveCalendarId(input.accountConfigId, urlSegment);
55
+ const existing = this.collections.get(calendarId);
56
+ if (existing) return existing;
57
+ const now = Date.now();
58
+ const collection: CalendarCollectionItem = {
59
+ calendarId,
60
+ accountConfigId: input.accountConfigId,
61
+ urlSegment,
62
+ displayName: input.displayName,
63
+ color: input.color ?? "Cal1",
64
+ componentSet: input.componentSet ?? "VeventOnly",
65
+ source: input.source ?? "UserCreated",
66
+ timezone: input.timezone ?? "",
67
+ syncSequence: 0,
68
+ createdAt: now,
69
+ updatedAt: now,
70
+ };
71
+ this.collections.set(calendarId, collection);
72
+ return collection;
73
+ },
74
+ get: async (_accountConfigId: string, calendarId: string) => {
75
+ const collection = this.collections.get(calendarId);
76
+ if (!collection) throw new MissingRow(calendarId);
77
+ return collection;
78
+ },
79
+ update: async (
80
+ _accountConfigId: string,
81
+ calendarId: string,
82
+ input: UpdateCalendarCollectionInput,
83
+ ) => {
84
+ const collection = this.collections.get(calendarId);
85
+ if (!collection) throw new MissingRow(calendarId);
86
+ const updated = { ...collection, ...input };
87
+ this.collections.set(calendarId, updated);
88
+ return updated;
89
+ },
90
+ delete: async (_accountConfigId: string, calendarId: string) => {
91
+ this.collections.delete(calendarId);
92
+ },
93
+ listByAccountConfig: async (accountConfigId: string) =>
94
+ [...this.collections.values()].filter(
95
+ (collection) => collection.accountConfigId === accountConfigId,
96
+ ),
97
+ createExclusive: async (input: CreateCalendarCollectionInput) => {
98
+ const calendarId = deriveCalendarId(
99
+ input.accountConfigId,
100
+ input.urlSegment,
101
+ );
102
+ if (this.collections.has(calendarId)) return null;
103
+ return this.collectionRepo.create(input);
104
+ },
105
+ findByUrlSegment: async (accountConfigId: string, urlSegment: string) =>
106
+ this.collections.get(deriveCalendarId(accountConfigId, urlSegment)) ??
107
+ null,
108
+ bumpSyncSequence: async (_accountConfigId: string, calendarId: string) => {
109
+ const collection = this.collections.get(calendarId);
110
+ if (!collection) throw new MissingRow(calendarId);
111
+ const bumped = {
112
+ ...collection,
113
+ syncSequence: collection.syncSequence + 1,
114
+ updatedAt: Date.now(),
115
+ };
116
+ this.collections.set(calendarId, bumped);
117
+ return bumped.syncSequence;
118
+ },
119
+ };
120
+
121
+ private readonly objectRepo: ICalendarObjectRepository = {
122
+ put: async (input: PutCalendarObjectRow) => {
123
+ const calendarObjectId = deriveCalendarObjectId(
124
+ input.calendarId,
125
+ input.resourceName,
126
+ );
127
+ const now = Date.now();
128
+ const object: CalendarObjectItem = {
129
+ ...input,
130
+ calendarObjectId,
131
+ createdAt: this.objects.get(calendarObjectId)?.createdAt ?? now,
132
+ updatedAt: now,
133
+ };
134
+ this.objects.set(calendarObjectId, object);
135
+ return object;
136
+ },
137
+ listIncompleteExpansions: async (calendarId: string, instant: string) =>
138
+ [...this.objects.values()].filter(
139
+ (object) =>
140
+ object.calendarId === calendarId &&
141
+ object.expandedThrough !== "" &&
142
+ object.expandedThrough < instant,
143
+ ),
144
+ find: async (_calendarId: string, calendarObjectId: string) =>
145
+ this.objects.get(calendarObjectId) ?? null,
146
+ get: async (_calendarId: string, calendarObjectId: string) => {
147
+ const object = this.objects.get(calendarObjectId);
148
+ if (!object) throw new MissingRow(calendarObjectId);
149
+ return object;
150
+ },
151
+ delete: async (_calendarId: string, calendarObjectId: string) => {
152
+ this.objects.delete(calendarObjectId);
153
+ },
154
+ findByResourceName: async (calendarId: string, resourceName: string) =>
155
+ this.objects.get(deriveCalendarObjectId(calendarId, resourceName)) ??
156
+ null,
157
+ findByUid: async (calendarId: string, icalUid: string) =>
158
+ [...this.objects.values()].find(
159
+ (object) =>
160
+ object.calendarId === calendarId && object.icalUid === icalUid,
161
+ ) ?? null,
162
+ listByCalendar: async (calendarId: string) =>
163
+ [...this.objects.values()].filter(
164
+ (object) => object.calendarId === calendarId,
165
+ ),
166
+ listChangedSince: async (calendarId: string, syncSequence: number) =>
167
+ [...this.objects.values()]
168
+ .filter(
169
+ (object) =>
170
+ object.calendarId === calendarId &&
171
+ object.syncSequence > syncSequence,
172
+ )
173
+ .sort((left, right) => left.syncSequence - right.syncSequence),
174
+ };
175
+
176
+ private readonly eventIndexRepo: ICalendarEventIndexRepository = {
177
+ replaceForObject: async (
178
+ calendarId: string,
179
+ calendarObjectId: string,
180
+ occurrences: CalendarOccurrenceInput[],
181
+ ) => {
182
+ const now = Date.now();
183
+ this.occurrences.set(
184
+ calendarObjectId,
185
+ occurrences.map((occurrence) => ({
186
+ ...occurrence,
187
+ calendarId,
188
+ calendarObjectId,
189
+ createdAt: now,
190
+ updatedAt: now,
191
+ })),
192
+ );
193
+ },
194
+ deleteForObject: async (_calendarId: string, calendarObjectId: string) => {
195
+ this.occurrences.delete(calendarObjectId);
196
+ },
197
+ listForObject: async (_calendarId: string, calendarObjectId: string) =>
198
+ this.occurrences.get(calendarObjectId) ?? [],
199
+ listByStartRange: async (
200
+ calendarId: string,
201
+ startAt: string,
202
+ endAt: string,
203
+ ) =>
204
+ [...this.occurrences.values()]
205
+ .flat()
206
+ .filter(
207
+ (row) =>
208
+ row.calendarId === calendarId &&
209
+ row.startAt >= startAt &&
210
+ row.startAt < endAt,
211
+ )
212
+ .sort((left, right) => left.startAt.localeCompare(right.startAt)),
213
+ };
214
+
215
+ private readonly suggestionRepo: ICalendarSuggestionRepository = {
216
+ put: async (input: PutCalendarSuggestionInput) => {
217
+ const suggestionId = deriveCalendarSuggestionId(
218
+ input.messageId,
219
+ input.bodyPartId,
220
+ input.icalUid,
221
+ );
222
+ const now = Date.now();
223
+ const existing = this.suggestions.get(suggestionId);
224
+ const suggestion: CalendarSuggestionItem = {
225
+ ...input,
226
+ suggestionId,
227
+ state: existing?.state ?? CalendarSuggestionState.Pending,
228
+ acceptedCalendarObjectId: existing?.acceptedCalendarObjectId ?? "",
229
+ createdAt: existing?.createdAt ?? now,
230
+ updatedAt: now,
231
+ };
232
+ this.suggestions.set(suggestionId, suggestion);
233
+ return suggestion;
234
+ },
235
+ get: async (accountConfigId: string, suggestionId: string) => {
236
+ const suggestion = this.suggestions.get(suggestionId);
237
+ if (!suggestion || suggestion.accountConfigId !== accountConfigId) {
238
+ throw new MissingRow(suggestionId);
239
+ }
240
+ return suggestion;
241
+ },
242
+ listByMessage: async (accountConfigId: string, messageId: string) =>
243
+ [...this.suggestions.values()].filter(
244
+ (suggestion) =>
245
+ suggestion.accountConfigId === accountConfigId &&
246
+ suggestion.messageId === messageId,
247
+ ),
248
+ listByState: async (
249
+ accountConfigId: string,
250
+ state: CalendarSuggestionItem["state"],
251
+ ) => ({
252
+ items: [...this.suggestions.values()].filter(
253
+ (suggestion) =>
254
+ suggestion.accountConfigId === accountConfigId &&
255
+ suggestion.state === state,
256
+ ),
257
+ continuationToken: undefined,
258
+ }),
259
+ settle: async (
260
+ accountConfigId: string,
261
+ suggestionId: string,
262
+ input: SettleCalendarSuggestionInput,
263
+ ) => {
264
+ const suggestion = this.suggestions.get(suggestionId);
265
+ if (!suggestion || suggestion.accountConfigId !== accountConfigId) {
266
+ throw new MissingRow(suggestionId);
267
+ }
268
+ const settled = { ...suggestion, ...input, updatedAt: Date.now() };
269
+ this.suggestions.set(suggestionId, settled);
270
+ return settled;
271
+ },
272
+ supersedeIfPending: async (
273
+ accountConfigId: string,
274
+ suggestionId: string,
275
+ ) => {
276
+ const suggestion = this.suggestions.get(suggestionId);
277
+ if (
278
+ !suggestion ||
279
+ suggestion.accountConfigId !== accountConfigId ||
280
+ suggestion.state !== CalendarSuggestionState.Pending
281
+ ) {
282
+ return null;
283
+ }
284
+ const retired = {
285
+ ...suggestion,
286
+ state: CalendarSuggestionState.Superseded,
287
+ acceptedCalendarObjectId: "",
288
+ updatedAt: Date.now(),
289
+ };
290
+ this.suggestions.set(suggestionId, retired);
291
+ return retired;
292
+ },
293
+ };
294
+
295
+ private readonly feedTokenRepo: ICalendarFeedTokenRepository = {
296
+ put: async (input: PutCalendarFeedTokenInput) => {
297
+ const feedTokenId = deriveCalendarFeedTokenId(input.calendarId);
298
+ const now = Date.now();
299
+ const existing = this.feedTokens.get(feedTokenId);
300
+ const token: CalendarFeedTokenItem = {
301
+ feedTokenId,
302
+ accountConfigId: input.accountConfigId,
303
+ calendarId: input.calendarId,
304
+ tokenHash: input.tokenHash,
305
+ createdAt: existing?.createdAt ?? now,
306
+ rotatedAt: existing ? now : 0,
307
+ updatedAt: now,
308
+ };
309
+ this.feedTokens.set(feedTokenId, token);
310
+ return token;
311
+ },
312
+ findByCalendar: async (accountConfigId: string, calendarId: string) => {
313
+ const token = this.feedTokens.get(deriveCalendarFeedTokenId(calendarId));
314
+ if (!token || token.accountConfigId !== accountConfigId) return null;
315
+ return token;
316
+ },
317
+ findByTokenHash: async (tokenHash: string) =>
318
+ [...this.feedTokens.values()].find(
319
+ (token) => token.tokenHash === tokenHash,
320
+ ) ?? null,
321
+ delete: async (accountConfigId: string, calendarId: string) => {
322
+ const feedTokenId = deriveCalendarFeedTokenId(calendarId);
323
+ const token = this.feedTokens.get(feedTokenId);
324
+ if (!token || token.accountConfigId !== accountConfigId) return;
325
+ this.feedTokens.delete(feedTokenId);
326
+ },
327
+ };
328
+
329
+ get calendarSuggestion(): ICalendarSuggestionRepository {
330
+ return this.suggestionRepo;
331
+ }
332
+
333
+ transaction<T>(
334
+ fn: (repos: {
335
+ calendarCollection: ICalendarCollectionRepository;
336
+ calendarObject: ICalendarObjectRepository;
337
+ calendarEventIndex: ICalendarEventIndexRepository;
338
+ calendarSuggestion: ICalendarSuggestionRepository;
339
+ calendarFeedToken: ICalendarFeedTokenRepository;
340
+ }) => Promise<T>,
341
+ ): Promise<T> {
342
+ return fn({
343
+ calendarCollection: this.collectionRepo,
344
+ calendarObject: this.objectRepo,
345
+ calendarEventIndex: this.eventIndexRepo,
346
+ calendarSuggestion: this.suggestionRepo,
347
+ calendarFeedToken: this.feedTokenRepo,
348
+ });
349
+ }
350
+ }
package/src/parse.test.ts CHANGED
@@ -56,6 +56,17 @@ describe("parseCalendar", () => {
56
56
  );
57
57
  });
58
58
 
59
+ it("refuses empty bytes as a value, naming nothing rather than crashing", async () => {
60
+ // A suggestion read out of prose carries no iCalendar at all, and the
61
+ // accept path reaches this with `""`. ical.js reads empty bytes as a
62
+ // component with no name, so naming what arrived would throw here — a
63
+ // crash on ordinary input rather than the refusal every caller renders.
64
+ const refusal = await refusalCode("");
65
+
66
+ assert.equal(refusal.code, "NotACalendar");
67
+ assert.match(refusal.message, /found nothing/);
68
+ });
69
+
59
70
  it("refuses a document whose root is not a VCALENDAR", async () => {
60
71
  assert.equal(
61
72
  (
package/src/parse.ts CHANGED
@@ -64,9 +64,15 @@ export const parseCalendar = async (
64
64
  const component = read.value;
65
65
 
66
66
  if (component.name !== "vcalendar") {
67
+ // A document with nothing in it names nothing: ical.js reads empty bytes
68
+ // as a component with no name at all, and a suggestion read out of prose
69
+ // carries exactly that. Naming what arrived is for a document that has a
70
+ // root to name.
67
71
  return calendarFailure(
68
72
  "NotACalendar",
69
- `expected a VCALENDAR, found ${component.name.toUpperCase()}`,
73
+ component.name
74
+ ? `expected a VCALENDAR, found ${component.name.toUpperCase()}`
75
+ : "expected a VCALENDAR, found nothing",
70
76
  );
71
77
  }
72
78
 
package/src/put.test.ts CHANGED
@@ -1,25 +1,8 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
- import type {
4
- CalendarCollectionItem,
5
- CalendarEventIndexItem,
6
- CalendarObjectItem,
7
- CalendarOccurrenceInput,
8
- CreateCalendarCollectionInput,
9
- ICalendarCollectionRepository,
10
- ICalendarEventIndexRepository,
11
- ICalendarObjectRepository,
12
- ICalendarUnitOfWork,
13
- PutCalendarObjectInput as PutCalendarObjectRow,
14
- UpdateCalendarCollectionInput,
15
- } from "@remit/data-ports";
16
- import {
17
- deriveCalendarId,
18
- deriveCalendarObjectId,
19
- normalizeCalendarUrlSegment,
20
- } from "@remit/data-ports/id";
21
3
  import { computeEtag } from "./etag.js";
22
4
  import { asLf, singleEvent } from "./fixtures.js";
5
+ import { MemoryCalendarStore, MissingRow } from "./memory-store.js";
23
6
  import { parseCalendar, serializeCalendar } from "./parse.js";
24
7
  import {
25
8
  DEFAULT_CALENDAR_URL_SEGMENT,
@@ -28,198 +11,6 @@ import {
28
11
  putCalendarObject,
29
12
  } from "./put.js";
30
13
 
31
- class MissingRow extends Error {}
32
-
33
- /**
34
- * A pass-through unit of work over plain maps — the shape the port documents
35
- * for a backend with no cross-entity transaction. It proves the write path
36
- * calls what it should, in the order it should; that the three writes stand or
37
- * fall together is proven against a real transaction, in
38
- * drizzle-service's calendar-put.sqlite.test.ts.
39
- */
40
- class MemoryCalendarStore implements ICalendarUnitOfWork {
41
- readonly collections = new Map<string, CalendarCollectionItem>();
42
- readonly objects = new Map<string, CalendarObjectItem>();
43
- readonly occurrences = new Map<string, CalendarEventIndexItem[]>();
44
-
45
- private readonly collectionRepo: ICalendarCollectionRepository = {
46
- create: async (input: CreateCalendarCollectionInput) => {
47
- const urlSegment = normalizeCalendarUrlSegment(input.urlSegment);
48
- const calendarId = deriveCalendarId(input.accountConfigId, urlSegment);
49
- const existing = this.collections.get(calendarId);
50
- if (existing) return existing;
51
- const now = Date.now();
52
- const collection: CalendarCollectionItem = {
53
- calendarId,
54
- accountConfigId: input.accountConfigId,
55
- urlSegment,
56
- displayName: input.displayName,
57
- color: input.color ?? "Cal1",
58
- componentSet: input.componentSet ?? "VeventOnly",
59
- source: input.source ?? "UserCreated",
60
- timezone: input.timezone ?? "",
61
- syncSequence: 0,
62
- createdAt: now,
63
- updatedAt: now,
64
- };
65
- this.collections.set(calendarId, collection);
66
- return collection;
67
- },
68
- get: async (_accountConfigId: string, calendarId: string) => {
69
- const collection = this.collections.get(calendarId);
70
- if (!collection) throw new MissingRow(calendarId);
71
- return collection;
72
- },
73
- update: async (
74
- _accountConfigId: string,
75
- calendarId: string,
76
- input: UpdateCalendarCollectionInput,
77
- ) => {
78
- const collection = this.collections.get(calendarId);
79
- if (!collection) throw new MissingRow(calendarId);
80
- const updated = { ...collection, ...input };
81
- this.collections.set(calendarId, updated);
82
- return updated;
83
- },
84
- delete: async (_accountConfigId: string, calendarId: string) => {
85
- this.collections.delete(calendarId);
86
- },
87
- listByAccountConfig: async (accountConfigId: string) =>
88
- [...this.collections.values()].filter(
89
- (collection) => collection.accountConfigId === accountConfigId,
90
- ),
91
- createExclusive: async (input: CreateCalendarCollectionInput) => {
92
- const calendarId = deriveCalendarId(
93
- input.accountConfigId,
94
- input.urlSegment,
95
- );
96
- if (this.collections.has(calendarId)) return null;
97
- return this.collectionRepo.create(input);
98
- },
99
- findByUrlSegment: async (accountConfigId: string, urlSegment: string) =>
100
- this.collections.get(deriveCalendarId(accountConfigId, urlSegment)) ??
101
- null,
102
- bumpSyncSequence: async (_accountConfigId: string, calendarId: string) => {
103
- const collection = this.collections.get(calendarId);
104
- if (!collection) throw new MissingRow(calendarId);
105
- const bumped = {
106
- ...collection,
107
- syncSequence: collection.syncSequence + 1,
108
- };
109
- this.collections.set(calendarId, bumped);
110
- return bumped.syncSequence;
111
- },
112
- };
113
-
114
- private readonly objectRepo: ICalendarObjectRepository = {
115
- put: async (input: PutCalendarObjectRow) => {
116
- const calendarObjectId = deriveCalendarObjectId(
117
- input.calendarId,
118
- input.resourceName,
119
- );
120
- const now = Date.now();
121
- const object: CalendarObjectItem = {
122
- ...input,
123
- calendarObjectId,
124
- createdAt: this.objects.get(calendarObjectId)?.createdAt ?? now,
125
- updatedAt: now,
126
- };
127
- this.objects.set(calendarObjectId, object);
128
- return object;
129
- },
130
- listIncompleteExpansions: async (calendarId: string, instant: string) =>
131
- [...this.objects.values()].filter(
132
- (object) =>
133
- object.calendarId === calendarId &&
134
- object.expandedThrough !== "" &&
135
- object.expandedThrough < instant,
136
- ),
137
- find: async (_calendarId: string, calendarObjectId: string) =>
138
- this.objects.get(calendarObjectId) ?? null,
139
- get: async (_calendarId: string, calendarObjectId: string) => {
140
- const object = this.objects.get(calendarObjectId);
141
- if (!object) throw new MissingRow(calendarObjectId);
142
- return object;
143
- },
144
- delete: async (_calendarId: string, calendarObjectId: string) => {
145
- this.objects.delete(calendarObjectId);
146
- },
147
- findByResourceName: async (calendarId: string, resourceName: string) =>
148
- this.objects.get(deriveCalendarObjectId(calendarId, resourceName)) ??
149
- null,
150
- findByUid: async (calendarId: string, icalUid: string) =>
151
- [...this.objects.values()].find(
152
- (object) =>
153
- object.calendarId === calendarId && object.icalUid === icalUid,
154
- ) ?? null,
155
- listByCalendar: async (calendarId: string) =>
156
- [...this.objects.values()].filter(
157
- (object) => object.calendarId === calendarId,
158
- ),
159
- listChangedSince: async (calendarId: string, syncSequence: number) =>
160
- [...this.objects.values()]
161
- .filter(
162
- (object) =>
163
- object.calendarId === calendarId &&
164
- object.syncSequence > syncSequence,
165
- )
166
- .sort((left, right) => left.syncSequence - right.syncSequence),
167
- };
168
-
169
- private readonly eventIndexRepo: ICalendarEventIndexRepository = {
170
- replaceForObject: async (
171
- calendarId: string,
172
- calendarObjectId: string,
173
- occurrences: CalendarOccurrenceInput[],
174
- ) => {
175
- const now = Date.now();
176
- this.occurrences.set(
177
- calendarObjectId,
178
- occurrences.map((occurrence) => ({
179
- ...occurrence,
180
- calendarId,
181
- calendarObjectId,
182
- createdAt: now,
183
- updatedAt: now,
184
- })),
185
- );
186
- },
187
- deleteForObject: async (_calendarId: string, calendarObjectId: string) => {
188
- this.occurrences.delete(calendarObjectId);
189
- },
190
- listForObject: async (_calendarId: string, calendarObjectId: string) =>
191
- this.occurrences.get(calendarObjectId) ?? [],
192
- listByStartRange: async (
193
- calendarId: string,
194
- startAt: string,
195
- endAt: string,
196
- ) =>
197
- [...this.occurrences.values()]
198
- .flat()
199
- .filter(
200
- (row) =>
201
- row.calendarId === calendarId &&
202
- row.startAt >= startAt &&
203
- row.startAt < endAt,
204
- )
205
- .sort((left, right) => left.startAt.localeCompare(right.startAt)),
206
- };
207
-
208
- transaction<T>(
209
- fn: (repos: {
210
- calendarCollection: ICalendarCollectionRepository;
211
- calendarObject: ICalendarObjectRepository;
212
- calendarEventIndex: ICalendarEventIndexRepository;
213
- }) => Promise<T>,
214
- ): Promise<T> {
215
- return fn({
216
- calendarCollection: this.collectionRepo,
217
- calendarObject: this.objectRepo,
218
- calendarEventIndex: this.eventIndexRepo,
219
- });
220
- }
221
- }
222
-
223
14
  const ACCOUNT_CONFIG_ID = "account-config-1";
224
15
 
225
16
  const provisioned = async (): Promise<{