@sprucelabs/spruce-calendar-components 28.3.103 → 29.0.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 (70) hide show
  1. package/build/.spruce/errors/errors.types.d.ts +12 -12
  2. package/build/.spruce/errors/errors.types.js +0 -2
  3. package/build/.spruce/errors/options.types.d.ts +2 -2
  4. package/build/.spruce/schemas/schemas.types.d.ts +3287 -2737
  5. package/build/.spruce/schemas/schemas.types.js +1 -2
  6. package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +24 -13
  7. package/build/__tests__/support/SpyEventManager.js +1 -1
  8. package/build/__tests__/support/SpyPeopleManager.js +4 -4
  9. package/build/__tests__/support/SpyRemoteEventStore.js +4 -4
  10. package/build/__tests__/support/utilities/calendarAssert.js +2 -4
  11. package/build/__tests__/support/utilities/calendarSkillAssert.js +25 -10
  12. package/build/__tests__/support/utilities/calendarToolBeltInteractor.js +3 -1
  13. package/build/calendar/Calendar.vc.js +52 -43
  14. package/build/calendar/CalendarEventManager.js +86 -66
  15. package/build/calendar/CalendarPeopleManager.js +17 -16
  16. package/build/calendar/CalendarPersister.d.ts +2 -2
  17. package/build/calendar/CalendarPersister.js +13 -8
  18. package/build/calendar/calculateCalendarEventDifferences.js +6 -3
  19. package/build/constants.js +1 -2
  20. package/build/errors/SpruceError.d.ts +1 -1
  21. package/build/errors/SpruceError.js +1 -1
  22. package/build/esm/.spruce/errors/errors.types.d.ts +12 -12
  23. package/build/esm/.spruce/errors/errors.types.js +0 -2
  24. package/build/esm/.spruce/errors/options.types.d.ts +2 -2
  25. package/build/esm/.spruce/schemas/schemas.types.d.ts +3287 -2737
  26. package/build/esm/.spruce/schemas/schemas.types.js +1 -2
  27. package/build/esm/__tests__/support/utilities/calendarAssert.js +0 -1
  28. package/build/esm/__tests__/support/utilities/calendarSkillAssert.js +2 -2
  29. package/build/esm/calendar/Calendar.vc.js +0 -3
  30. package/build/esm/calendar/CalendarEventManager.js +3 -2
  31. package/build/esm/calendar/CalendarPeopleManager.js +0 -2
  32. package/build/esm/calendar/CalendarPersister.d.ts +2 -2
  33. package/build/esm/errors/SpruceError.d.ts +1 -1
  34. package/build/esm/noSchedules/peopleToPeopleWithoutSchedules.d.ts +1 -1
  35. package/build/esm/root/Root.svc.d.ts +2 -2
  36. package/build/esm/root/Root.svc.js +4 -2
  37. package/build/esm/stores/RemoteEventStore.js +7 -4
  38. package/build/esm/toolBelt/CalendarToolRegistrar.js +4 -1
  39. package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +5 -2
  40. package/build/esm/toolBelt/states/RootToolBeltState.js +2 -1
  41. package/build/esm/tools/CalendarSelectTool.vc.js +5 -2
  42. package/build/esm/tools/EventRepeatingTool.vc.js +3 -1
  43. package/build/esm/tools/PersonSelectTool.vc.js +8 -3
  44. package/build/esm/viewControllers/DateSelectCard.vc.js +1 -4
  45. package/build/esm/viewControllers/RepeatingControlsList.vc.js +2 -1
  46. package/build/noSchedules/peopleToPeopleWithoutSchedules.d.ts +1 -1
  47. package/build/root/Root.svc.d.ts +2 -2
  48. package/build/root/Root.svc.js +73 -48
  49. package/build/stores/RemoteEventStore.js +60 -38
  50. package/build/stores/RemotePreferencesStore.js +10 -4
  51. package/build/toolBelt/CalendarToolRegistrar.js +8 -9
  52. package/build/toolBelt/CalendarToolTestFactory.js +10 -4
  53. package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +37 -27
  54. package/build/toolBelt/states/PrerequisitesToolBeltState.js +31 -22
  55. package/build/toolBelt/states/RootToolBeltState.js +23 -19
  56. package/build/toolBelt/states/UniversalEventToolBeltState.js +1 -4
  57. package/build/toolBelt/states/makeEventTyped.js +1 -2
  58. package/build/tools/CalendarSelectTool.vc.js +12 -6
  59. package/build/tools/EventDateTimeTool.vc.js +10 -6
  60. package/build/tools/EventDurationTool.vc.js +8 -5
  61. package/build/tools/EventRepeatingTool.vc.js +23 -7
  62. package/build/tools/EventTitleTool.vc.js +8 -5
  63. package/build/tools/PersonSelectTool.vc.js +17 -9
  64. package/build/utilities/draftGenerator.js +1 -1
  65. package/build/viewControllers/DateSelectCard.vc.js +12 -7
  66. package/build/viewControllers/EventControlsCard.vc.js +9 -5
  67. package/build/viewControllers/RepeatingControlsList.vc.js +52 -58
  68. package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +7 -4
  69. package/build/viewControllers/UniversalCalendarEvent.vc.js +1 -1
  70. package/package.json +1 -1
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -22,16 +11,32 @@ const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"))
22
11
  const calculateCalendarEventDifferences_1 = __importDefault(require("./calculateCalendarEventDifferences"));
23
12
  const CalendarPersister_1 = __importDefault(require("./CalendarPersister"));
24
13
  class CalendarEventManager {
14
+ static shouldBatchEvents = false;
15
+ calendarVc;
16
+ allEvents = [];
17
+ inclusiveCalendarIds = [];
18
+ events;
19
+ eventTypes;
20
+ remoteVc;
21
+ hasVcForEventTypeBeenLoaded = {};
22
+ sm;
23
+ shouldIgnoreNextContextUpdate = false;
24
+ askForUpdateStrategy;
25
+ dateToUpdate;
26
+ shouldUpdateAllEventsGoingForward;
27
+ prefs;
28
+ calendars = [];
29
+ isLoaded = false;
30
+ updateContext;
31
+ updateOperations = [];
32
+ isRunningUpdateQueue = false;
33
+ updateQueuePromise;
34
+ persister;
35
+ hasPendingContextChanges = false;
36
+ //@ts-ignore
37
+ loadEventsStartTimeMs;
38
+ activeChunk;
25
39
  constructor(options) {
26
- this.allEvents = [];
27
- this.inclusiveCalendarIds = [];
28
- this.hasVcForEventTypeBeenLoaded = {};
29
- this.shouldIgnoreNextContextUpdate = false;
30
- this.calendars = [];
31
- this.isLoaded = false;
32
- this.updateOperations = [];
33
- this.isRunningUpdateQueue = false;
34
- this.hasPendingContextChanges = false;
35
40
  const { calendarVc, events, remoteVc, sm, askForUpdateStrategy, preferences, } = (0, schema_1.assertOptions)(options, [
36
41
  'calendarVc',
37
42
  'events',
@@ -58,13 +63,12 @@ class CalendarEventManager {
58
63
  return this.calendars.map((c) => c.id);
59
64
  }
60
65
  get visibleCalendarIds() {
61
- var _a;
62
- return (_a = this.prefs.getVisibleCalendarIds()) !== null && _a !== void 0 ? _a : this.calendars.map((c) => c.id);
66
+ return (this.prefs.getVisibleCalendarIds() ??
67
+ this.calendars.map((c) => c.id));
63
68
  }
64
69
  async handleStreamEvents(options) {
65
- var _a;
66
70
  const { events, chunkingId } = options;
67
- const { id, startDate, endDate } = (_a = this.activeChunk) !== null && _a !== void 0 ? _a : {};
71
+ const { id, startDate, endDate } = this.activeChunk ?? {};
68
72
  if (id !== chunkingId || !startDate || !endDate) {
69
73
  return;
70
74
  }
@@ -86,8 +90,7 @@ class CalendarEventManager {
86
90
  this.calendarVc.setShifts([...shifts]);
87
91
  }
88
92
  doShiftsMatchWhatIsInCalendar(shifts) {
89
- var _a;
90
- const currentShifts = this.generateShiftKeys((_a = this.calendarVc.getShifts()) !== null && _a !== void 0 ? _a : []);
93
+ const currentShifts = this.generateShiftKeys(this.calendarVc.getShifts() ?? []);
91
94
  const newShifts = this.generateShiftKeys(shifts);
92
95
  const areShiftsTheSame = newShifts === currentShifts;
93
96
  return areShiftsTheSame;
@@ -133,7 +136,7 @@ class CalendarEventManager {
133
136
  return this.persister.persist(event);
134
137
  }
135
138
  addEvent(event) {
136
- this.allEvents.push(Object.assign({}, event));
139
+ this.allEvents.push({ ...event });
137
140
  this.calendarVc.addEvent(event);
138
141
  }
139
142
  addEvents(events) {
@@ -141,19 +144,24 @@ class CalendarEventManager {
141
144
  this.calendarVc.mixinEvents(events);
142
145
  }
143
146
  async silentlySwapEvent(oldId, event) {
144
- var _a;
145
147
  const events = this.getEvents().filter((e) => e.id !== oldId);
146
148
  this.allEvents = [...events, event];
147
- if (((_a = this.sm.getContext().event) === null || _a === void 0 ? void 0 : _a.id) === oldId) {
149
+ if (this.sm.getContext().event?.id === oldId) {
148
150
  await this.updateEventInContext(event);
149
151
  }
150
152
  }
151
153
  async handleDropEvent(id, updates) {
152
- const event = Object.assign(Object.assign({}, this.calendarVc.getEvent(id)), updates);
154
+ const event = {
155
+ ...this.calendarVc.getEvent(id),
156
+ ...updates,
157
+ };
153
158
  const { pass, dateToUpdate, shouldUpdateAllEventsGoingForward } = await this.optionallyAskForUpdateRepeatingStrategy(event);
154
159
  if (pass) {
155
- this.updateEvent(id, Object.assign(Object.assign({}, event), { dateToUpdate,
156
- shouldUpdateAllEventsGoingForward }));
160
+ this.updateEvent(id, {
161
+ ...event,
162
+ dateToUpdate,
163
+ shouldUpdateAllEventsGoingForward,
164
+ });
157
165
  }
158
166
  return pass;
159
167
  }
@@ -164,9 +172,8 @@ class CalendarEventManager {
164
172
  }
165
173
  }
166
174
  async reset() {
167
- var _a;
168
175
  await this.setEventInContext(undefined);
169
- (_a = this.events) === null || _a === void 0 ? void 0 : _a.clearCalendarId();
176
+ this.events?.clearCalendarId();
170
177
  }
171
178
  async restoreEventToDraftOnStateLoadError() {
172
179
  const updated = await this.updateEventInContext({
@@ -180,8 +187,7 @@ class CalendarEventManager {
180
187
  return this.visibleCalendarIds;
181
188
  }
182
189
  async cancelEvent(id, options) {
183
- var _a;
184
- const { shouldPersist = true } = options !== null && options !== void 0 ? options : {};
190
+ const { shouldPersist = true } = options ?? {};
185
191
  const event = this.calendarVc.getEvent(id);
186
192
  if (shouldPersist) {
187
193
  const { pass } = await this.optionallyAskForUpdateRepeatingStrategy(event, 'cancel');
@@ -202,8 +208,8 @@ class CalendarEventManager {
202
208
  this.refreshShifts();
203
209
  }
204
210
  catch (err) {
205
- console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
206
- this.calendarVc.addEvent(Object.assign(Object.assign({}, event), { error: err }));
211
+ console.error(err.stack ?? err.message);
212
+ this.calendarVc.addEvent({ ...event, error: err });
207
213
  }
208
214
  this.clearRepeatingStrategyOptions();
209
215
  }
@@ -236,7 +242,6 @@ class CalendarEventManager {
236
242
  await this.updateQueuePromise;
237
243
  }
238
244
  async runUpdateQueue() {
239
- var _a;
240
245
  this.isRunningUpdateQueue = true;
241
246
  let next;
242
247
  const savedEvents = [];
@@ -244,23 +249,25 @@ class CalendarEventManager {
244
249
  const e = await next.execute();
245
250
  savedEvents.push(e);
246
251
  }
247
- const currentId = (_a = this.sm.getContext().event) === null || _a === void 0 ? void 0 : _a.id;
252
+ const currentId = this.sm.getContext().event?.id;
248
253
  savedEvents.reverse();
249
254
  const eventMatching = savedEvents.find((e) => e.id === currentId);
250
- if (!this.hasPendingContextChanges && currentId === (eventMatching === null || eventMatching === void 0 ? void 0 : eventMatching.id)) {
255
+ if (!this.hasPendingContextChanges && currentId === eventMatching?.id) {
251
256
  await this.updateEventInContext(eventMatching);
252
257
  }
253
258
  this.isRunningUpdateQueue = false;
254
259
  }
255
260
  async _updateEvent(id, updates) {
256
- var _a;
257
- let { shouldPersist = true, dateToUpdate, shouldUpdateAllEventsGoingForward } = updates, rest = __rest(updates, ["shouldPersist", "dateToUpdate", "shouldUpdateAllEventsGoingForward"]);
261
+ let { shouldPersist = true, dateToUpdate, shouldUpdateAllEventsGoingForward, ...rest } = updates;
258
262
  const { isTheSame, isTheSameWithoutBusy, match: originalEvent, } = this.calculateDifferences(id, updates);
259
263
  if (isTheSame) {
260
264
  return originalEvent;
261
265
  }
262
266
  const idx = this.allEvents.findIndex((e) => e.id === id);
263
- let updatedEvent = Object.assign(Object.assign({}, originalEvent), rest);
267
+ let updatedEvent = {
268
+ ...originalEvent,
269
+ ...rest,
270
+ };
264
271
  if (typeof shouldUpdateAllEventsGoingForward === 'undefined') {
265
272
  const { pass, dateToUpdate: date, shouldUpdateAllEventsGoingForward: should, } = await this.optionallyAskForUpdateRepeatingStrategy(updatedEvent);
266
273
  dateToUpdate = date;
@@ -278,7 +285,10 @@ class CalendarEventManager {
278
285
  }
279
286
  try {
280
287
  const isGoodToPersist = shouldPersist && !isTheSameWithoutBusy;
281
- this.calendarVc.updateEvent(id, Object.assign(Object.assign({}, rest), { shouldPersist: false }));
288
+ this.calendarVc.updateEvent(id, {
289
+ ...rest,
290
+ shouldPersist: false,
291
+ });
282
292
  if (isGoodToPersist) {
283
293
  const response = await this.persister.persist(updatedEvent);
284
294
  if (response) {
@@ -287,7 +297,7 @@ class CalendarEventManager {
287
297
  }
288
298
  }
289
299
  catch (err) {
290
- console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
300
+ console.error(err.stack ?? err.message);
291
301
  return originalEvent;
292
302
  }
293
303
  this.allEvents[idx] = updatedEvent;
@@ -319,7 +329,10 @@ class CalendarEventManager {
319
329
  startDate,
320
330
  endDate,
321
331
  };
322
- await this.events.sendSchedules(Object.assign(Object.assign({}, scheduleOptions), { chunkingId: this.activeChunk.id }));
332
+ await this.events.sendSchedules({
333
+ ...scheduleOptions,
334
+ chunkingId: this.activeChunk.id,
335
+ });
323
336
  return;
324
337
  }
325
338
  const events = await this.events.getSchedules(scheduleOptions);
@@ -334,9 +347,8 @@ class CalendarEventManager {
334
347
  this.eventTypes = await this.events.getEventTypes();
335
348
  }
336
349
  await Promise.all(events.map(async (e) => {
337
- var _a;
338
- const type = (_a = this.eventTypes) === null || _a === void 0 ? void 0 : _a.find((t) => t.slug === e.eventTypeSlug);
339
- if (type === null || type === void 0 ? void 0 : type.viewControllerId) {
350
+ const type = this.eventTypes?.find((t) => t.slug === e.eventTypeSlug);
351
+ if (type?.viewControllerId) {
340
352
  await this.setupVcForEventType(type.viewControllerId, type.slug);
341
353
  }
342
354
  }));
@@ -376,15 +388,18 @@ class CalendarEventManager {
376
388
  }
377
389
  async updateEventInContext(updates) {
378
390
  const { event } = this.sm.getContext();
379
- const updated = Object.assign(Object.assign(Object.assign({}, event), updates), { isBusy: false });
391
+ const updated = {
392
+ ...event,
393
+ ...updates,
394
+ isBusy: false,
395
+ };
380
396
  await this.setEventInContext(updated);
381
397
  return updated;
382
398
  }
383
399
  async setEventInContext(newEvent, options) {
384
- var _a;
385
400
  this.shouldIgnoreNextContextUpdate =
386
- (options === null || options === void 0 ? void 0 : options.shouldHandleDidUpdateContext) !== false;
387
- const didTrigger = await ((_a = this.updateContext) !== null && _a !== void 0 ? _a : this.sm.updateContext.bind(this.sm))({
401
+ options?.shouldHandleDidUpdateContext !== false;
402
+ const didTrigger = await (this.updateContext ?? this.sm.updateContext.bind(this.sm))({
388
403
  event: newEvent,
389
404
  });
390
405
  if (!didTrigger) {
@@ -401,7 +416,7 @@ class CalendarEventManager {
401
416
  const lastSelected = this.getSelectedEvent();
402
417
  const event = this.calendarVc.getEvent(eventId);
403
418
  await this.calendarVc.selectEvent(event.id);
404
- if ((lastSelected === null || lastSelected === void 0 ? void 0 : lastSelected.id) !== event.id) {
419
+ if (lastSelected?.id !== event.id) {
405
420
  await this.setEventInContext(event);
406
421
  }
407
422
  }
@@ -434,8 +449,8 @@ class CalendarEventManager {
434
449
  const { event: originalEvent } = options.current;
435
450
  const { event } = options.updates;
436
451
  let pass = true;
437
- if ((event === null || event === void 0 ? void 0 : event.id) &&
438
- (originalEvent === null || originalEvent === void 0 ? void 0 : originalEvent.id) === (event === null || event === void 0 ? void 0 : event.id) &&
452
+ if (event?.id &&
453
+ originalEvent?.id === event?.id &&
439
454
  !this.shouldIgnoreNextContextUpdate) {
440
455
  const strat = await this.optionallyAskForUpdateRepeatingStrategy(event);
441
456
  pass = strat.pass;
@@ -462,17 +477,21 @@ class CalendarEventManager {
462
477
  return;
463
478
  }
464
479
  const { event } = this.sm.getContext();
465
- if (event === null || event === void 0 ? void 0 : event.id) {
480
+ if (event?.id) {
466
481
  this.hasPendingContextChanges = false;
467
482
  await this.saveEvent(event);
468
483
  }
469
484
  }
470
485
  async saveEvent(event) {
471
486
  try {
472
- const cleaned = (0, schema_1.normalizeSchemaValues)(heartwood_view_controllers_1.calendarEventSchema, Object.assign({}, event), {
487
+ const cleaned = (0, schema_1.normalizeSchemaValues)(heartwood_view_controllers_1.calendarEventSchema, { ...event }, {
473
488
  shouldIncludeNullAndUndefinedFields: true,
474
489
  });
475
- this.updateEvent(event.id, Object.assign(Object.assign({}, cleaned), { dateToUpdate: this.dateToUpdate, shouldUpdateAllEventsGoingForward: this.shouldUpdateAllEventsGoingForward }));
490
+ this.updateEvent(event.id, {
491
+ ...cleaned,
492
+ dateToUpdate: this.dateToUpdate,
493
+ shouldUpdateAllEventsGoingForward: this.shouldUpdateAllEventsGoingForward,
494
+ });
476
495
  this.clearRepeatingStrategyOptions();
477
496
  }
478
497
  catch (err) {
@@ -490,17 +509,15 @@ class CalendarEventManager {
490
509
  return !!this.allEvents.find((e) => e.id === id);
491
510
  }
492
511
  getLastChunkingId() {
493
- var _a;
494
- return (_a = this.activeChunk) === null || _a === void 0 ? void 0 : _a.id;
512
+ return this.activeChunk?.id;
495
513
  }
496
514
  async optionallyAskForUpdateRepeatingStrategy(event, action = 'update') {
497
- var _a;
498
515
  if (!event.id) {
499
516
  return { pass: true };
500
517
  }
501
518
  let dateToUpdate = undefined;
502
519
  let shouldUpdateAllEventsGoingForward = undefined;
503
- if (((_a = event.totalInRepeating) !== null && _a !== void 0 ? _a : 0) > 1) {
520
+ if ((event.totalInRepeating ?? 0) > 1) {
504
521
  const cleaned = (0, schema_1.normalizeSchemaValues)(heartwood_view_controllers_1.calendarEventSchema, event, {
505
522
  shouldIncludeNullAndUndefinedFields: false,
506
523
  });
@@ -521,14 +538,17 @@ class CalendarEventManager {
521
538
  shouldUpdateAllEventsGoingForward = false;
522
539
  }
523
540
  this.dateToUpdate = dateToUpdate;
524
- this.shouldUpdateAllEventsGoingForward = shouldUpdateAllEventsGoingForward;
541
+ this.shouldUpdateAllEventsGoingForward =
542
+ shouldUpdateAllEventsGoingForward;
525
543
  }
526
544
  return { pass: true, dateToUpdate, shouldUpdateAllEventsGoingForward };
527
545
  }
528
546
  }
529
- CalendarEventManager.shouldBatchEvents = false;
530
547
  exports.default = CalendarEventManager;
531
548
  class UpdateOperation {
549
+ id;
550
+ updates;
551
+ onComplete;
532
552
  constructor(options) {
533
553
  const { id, updates, onComplete } = options;
534
554
  this.id = id;
@@ -9,18 +9,25 @@ const schema_1 = require("@sprucelabs/schema");
9
9
  const spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
10
10
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
11
11
  class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter {
12
+ connectToApi;
13
+ prefs;
14
+ client;
15
+ loggedInPerson;
16
+ locationId;
17
+ organizationId;
18
+ team = [];
19
+ getVisibleEvents;
12
20
  constructor(options) {
13
21
  super(peopleContract);
14
- this.team = [];
15
22
  const { connectToApi, preferences, getVisibleEvents } = (0, schema_1.assertOptions)(options, ['connectToApi', 'preferences', 'calendarVc', 'getVisibleEvents']);
16
23
  this.connectToApi = connectToApi;
17
24
  this.prefs = preferences;
18
25
  this.getVisibleEvents = getVisibleEvents;
19
26
  }
20
27
  async load(options) {
21
- const { loggedInPerson, organizationId, locationId } = options !== null && options !== void 0 ? options : {};
28
+ const { loggedInPerson, organizationId, locationId } = options ?? {};
22
29
  this.client = await this.connectToApi();
23
- this.loggedInPerson = loggedInPerson !== null && loggedInPerson !== void 0 ? loggedInPerson : undefined;
30
+ this.loggedInPerson = loggedInPerson ?? undefined;
24
31
  this.organizationId = organizationId;
25
32
  this.locationId = locationId;
26
33
  await this.loadTeam();
@@ -45,17 +52,15 @@ class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter
45
52
  .map((i) => {
46
53
  try {
47
54
  return this.teammateById(i);
48
- // eslint-disable-next-line no-empty
49
55
  }
50
- catch (_a) { }
56
+ catch { }
51
57
  return null;
52
58
  })
53
59
  .filter((t) => !!t);
54
60
  return people;
55
61
  }
56
62
  teammateById(id) {
57
- var _a;
58
- const teammate = (_a = this.team) === null || _a === void 0 ? void 0 : _a.find((t) => t.id === id);
63
+ const teammate = this.team?.find((t) => t.id === id);
59
64
  if (!teammate) {
60
65
  throw new SpruceError_1.default({
61
66
  code: 'PERSON_NOT_FOUND',
@@ -71,18 +76,16 @@ class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter
71
76
  return this.loggedInPerson;
72
77
  }
73
78
  getVisiblePeopleIds() {
74
- var _a;
75
79
  if (this.getVisibilityMode() === 'working') {
76
80
  return this.getWorkingPeopleIds();
77
81
  }
78
- return (_a = this.getSavedVisiblePeopleIds()) !== null && _a !== void 0 ? _a : [];
82
+ return this.getSavedVisiblePeopleIds() ?? [];
79
83
  }
80
84
  getSavedVisiblePeopleIds() {
81
85
  return this.prefs.getVisiblePeopleIds();
82
86
  }
83
87
  getVisibilityMode() {
84
- var _a;
85
- return (_a = this.prefs.getVisiblePeopleMode()) !== null && _a !== void 0 ? _a : 'me';
88
+ return this.prefs.getVisiblePeopleMode() ?? 'me';
86
89
  }
87
90
  async setVisibilityMode(mode) {
88
91
  if (this.getVisibilityMode() === mode) {
@@ -118,18 +121,16 @@ class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter
118
121
  .map((id) => {
119
122
  try {
120
123
  return this.teammateById(id);
121
- // eslint-disable-next-line no-empty
122
124
  }
123
- catch (_a) { }
125
+ catch { }
124
126
  return false;
125
127
  })
126
128
  .filter((p) => !!p);
127
129
  }
128
130
  async setVisiblePeopleIds(visible, options) {
129
- var _a;
130
- const { shouldForceEmitDidChange } = options !== null && options !== void 0 ? options : {};
131
+ const { shouldForceEmitDidChange } = options ?? {};
131
132
  const newVisibile = visible.filter((id, idx) => visible.indexOf(id) === idx);
132
- const oldVisible = (_a = this.getSavedVisiblePeopleIds()) !== null && _a !== void 0 ? _a : [];
133
+ const oldVisible = this.getSavedVisiblePeopleIds() ?? [];
133
134
  const newKey = newVisibile.join('');
134
135
  const oldKey = oldVisible.join('');
135
136
  const didChange = newKey !== oldKey;
@@ -19,9 +19,9 @@ export default class CalendarPersister {
19
19
  cancelEvent(id: string, options?: CancelEventRecurringOptions): Promise<void>;
20
20
  }
21
21
  type DraftHandlerCalendar = Pick<CalendarViewController, 'hasEvent' | 'updateEvent' | 'swapEvent' | 'removeEvent'>;
22
- export type CalendarPersisterOptions = {
22
+ export interface CalendarPersisterOptions {
23
23
  calendarVc: DraftHandlerCalendar;
24
24
  events?: RemoteEventStore;
25
25
  onEventSwapped?: EventSwappedHandler;
26
- };
26
+ }
27
27
  export {};
@@ -1,16 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class CalendarPersister {
4
+ static Class;
5
+ activelyPersisting = {};
6
+ persistPromise;
7
+ events;
8
+ lastSwappedId;
9
+ calendarVc;
10
+ eventSwappedHandler;
4
11
  constructor(options) {
5
- this.activelyPersisting = {};
6
12
  const { events, calendarVc, onEventSwapped } = options;
7
13
  this.events = events;
8
14
  this.calendarVc = calendarVc;
9
15
  this.eventSwappedHandler = onEventSwapped;
10
16
  }
11
17
  static Persister(options) {
12
- var _a;
13
- return new ((_a = this.Class) !== null && _a !== void 0 ? _a : CalendarPersister)(options);
18
+ return new (this.Class ?? CalendarPersister)(options);
14
19
  }
15
20
  async persist(event) {
16
21
  this.persistPromise = this._persist(event);
@@ -26,7 +31,6 @@ class CalendarPersister {
26
31
  return this.events;
27
32
  }
28
33
  async _persist(event) {
29
- var _a, _b;
30
34
  let updated = event;
31
35
  const id = updated.id;
32
36
  try {
@@ -40,7 +44,9 @@ class CalendarPersister {
40
44
  isBusy: true,
41
45
  shouldPersist: false,
42
46
  });
43
- const saved = await ((_a = this.events) === null || _a === void 0 ? void 0 : _a.persist(Object.assign({}, event)));
47
+ const saved = await this.events?.persist({
48
+ ...event,
49
+ });
44
50
  this.activelyPersisting[id]--;
45
51
  if (!saved) {
46
52
  return undefined;
@@ -54,7 +60,7 @@ class CalendarPersister {
54
60
  await this.calendarVc.swapEvent(event, saved);
55
61
  }
56
62
  if (this.activelyPersisting[id] === 0) {
57
- await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, event, saved));
63
+ await this.eventSwappedHandler?.(event, saved);
58
64
  }
59
65
  }
60
66
  else {
@@ -78,8 +84,7 @@ class CalendarPersister {
78
84
  return event;
79
85
  }
80
86
  async cancelEvent(id, options) {
81
- var _a;
82
- await ((_a = this.events) === null || _a === void 0 ? void 0 : _a.cancelEvent(id, options));
87
+ await this.events?.cancelEvent(id, options);
83
88
  }
84
89
  }
85
90
  exports.default = CalendarPersister;
@@ -2,11 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
4
4
  function calculateCalendarEventDifferences(event, updates) {
5
- const updated = Object.assign(Object.assign({}, event), updates);
5
+ const updated = {
6
+ ...event,
7
+ ...updates,
8
+ };
6
9
  const isTheSame = (0, spruce_skill_utils_1.isEqual)(event, updated);
7
- const updatesWithoutBusy = Object.assign({}, updated);
10
+ const updatesWithoutBusy = { ...updated };
8
11
  delete updatesWithoutBusy.isBusy;
9
- const matchWithoutBusy = Object.assign({}, event);
12
+ const matchWithoutBusy = { ...event };
10
13
  delete matchWithoutBusy.isBusy;
11
14
  const isTheSameWithoutBusy = (0, spruce_skill_utils_1.isEqual)(matchWithoutBusy, updatesWithoutBusy);
12
15
  return { isTheSame, isTheSameWithoutBusy };
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.UPDATE_STRATEGY_ALL = exports.UPDATE_STRATEGY_THIS_AND_ALL_GOING_FORWARD = exports.UPDATE_STRATEGY_SPECIFIC_DATES = exports.MAX_GET_SCHEDULE_DAYS = void 0;
5
4
  require('dotenv').config();
6
- exports.MAX_GET_SCHEDULE_DAYS = parseInt((_a = process.env.MAX_GETSCHEDULE_DAYS) !== null && _a !== void 0 ? _a : '365');
5
+ exports.MAX_GET_SCHEDULE_DAYS = parseInt(process.env.MAX_GETSCHEDULE_DAYS ?? '365');
7
6
  exports.UPDATE_STRATEGY_SPECIFIC_DATES = 'only-this-one';
8
7
  exports.UPDATE_STRATEGY_THIS_AND_ALL_GOING_FORWARD = 'all-going-forward';
9
8
  exports.UPDATE_STRATEGY_ALL = 'all';
@@ -1,5 +1,5 @@
1
1
  import AbstractSpruceError from '@sprucelabs/error';
2
- import ErrorOptions from "./../.spruce/errors/options.types";
2
+ import ErrorOptions from './../.spruce/errors/options.types';
3
3
  export default class SpruceError extends AbstractSpruceError<ErrorOptions> {
4
4
  friendlyMessage(): string;
5
5
  }
@@ -8,7 +8,7 @@ class SpruceError extends error_1.default {
8
8
  friendlyMessage() {
9
9
  const { options } = this;
10
10
  let message;
11
- switch (options === null || options === void 0 ? void 0 : options.code) {
11
+ switch (options?.code) {
12
12
  case 'CALENDAR_NOT_FOUND':
13
13
  message = 'I could not find that calendar!';
14
14
  break;
@@ -24,7 +24,7 @@ export declare namespace SpruceErrors.Calendar {
24
24
  }
25
25
  export declare namespace SpruceErrors.Calendar {
26
26
  interface RecordNotFound {
27
- 'parameters': string[];
27
+ parameters: string[];
28
28
  }
29
29
  interface RecordNotFoundSchema extends SpruceSchema.Schema {
30
30
  id: 'recordNotFound';
@@ -32,7 +32,7 @@ export declare namespace SpruceErrors.Calendar {
32
32
  name: 'record not found';
33
33
  fields: {
34
34
  /** . */
35
- 'parameters': {
35
+ parameters: {
36
36
  type: 'text';
37
37
  isRequired: true;
38
38
  isArray: true;
@@ -44,7 +44,7 @@ export declare namespace SpruceErrors.Calendar {
44
44
  }
45
45
  export declare namespace SpruceErrors.Calendar {
46
46
  interface PersonNotFound {
47
- 'personId': string;
47
+ personId: string;
48
48
  }
49
49
  interface PersonNotFoundSchema extends SpruceSchema.Schema {
50
50
  id: 'personNotFound';
@@ -52,7 +52,7 @@ export declare namespace SpruceErrors.Calendar {
52
52
  name: 'Person not found';
53
53
  fields: {
54
54
  /** . */
55
- 'personId': {
55
+ personId: {
56
56
  type: 'id';
57
57
  isRequired: true;
58
58
  options: undefined;
@@ -63,7 +63,7 @@ export declare namespace SpruceErrors.Calendar {
63
63
  }
64
64
  export declare namespace SpruceErrors.Calendar {
65
65
  interface EventNotFound {
66
- 'id': string;
66
+ id: string;
67
67
  }
68
68
  interface EventNotFoundSchema extends SpruceSchema.Schema {
69
69
  id: 'eventNotFound';
@@ -71,7 +71,7 @@ export declare namespace SpruceErrors.Calendar {
71
71
  name: 'Event Not Found';
72
72
  fields: {
73
73
  /** . */
74
- 'id': {
74
+ id: {
75
75
  type: 'id';
76
76
  isRequired: true;
77
77
  options: undefined;
@@ -104,7 +104,7 @@ export declare namespace SpruceErrors.Calendar {
104
104
  }
105
105
  export declare namespace SpruceErrors.Calendar {
106
106
  interface CalendarToolInterface {
107
- 'vcId': string;
107
+ vcId: string;
108
108
  }
109
109
  interface CalendarToolInterfaceSchema extends SpruceSchema.Schema {
110
110
  id: 'calendarToolInterface';
@@ -112,7 +112,7 @@ export declare namespace SpruceErrors.Calendar {
112
112
  name: 'Calendar tool interface';
113
113
  fields: {
114
114
  /** . */
115
- 'vcId': {
115
+ vcId: {
116
116
  type: 'id';
117
117
  isRequired: true;
118
118
  options: undefined;
@@ -123,8 +123,8 @@ export declare namespace SpruceErrors.Calendar {
123
123
  }
124
124
  export declare namespace SpruceErrors.Calendar {
125
125
  interface CalendarNotFound {
126
- 'calendarIds'?: string[] | undefined | null;
127
- 'calendarSlugs'?: string[] | undefined | null;
126
+ calendarIds?: string[] | undefined | null;
127
+ calendarSlugs?: string[] | undefined | null;
128
128
  }
129
129
  interface CalendarNotFoundSchema extends SpruceSchema.Schema {
130
130
  id: 'calendarNotFound';
@@ -132,13 +132,13 @@ export declare namespace SpruceErrors.Calendar {
132
132
  name: 'calendar not found';
133
133
  fields: {
134
134
  /** . */
135
- 'calendarIds': {
135
+ calendarIds: {
136
136
  type: 'text';
137
137
  isArray: true;
138
138
  options: undefined;
139
139
  };
140
140
  /** . */
141
- 'calendarSlugs': {
141
+ calendarSlugs: {
142
142
  type: 'text';
143
143
  isArray: true;
144
144
  options: undefined;
@@ -1,3 +1 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
- /* eslint-disable no-redeclare */
3
1
  export {};
@@ -1,5 +1,5 @@
1
- import { SpruceErrors } from "./errors.types";
2
- import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
1
+ import { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
2
+ import { SpruceErrors } from './errors.types';
3
3
  export interface ValidatorNotInitializedErrorOptions extends SpruceErrors.Calendar.ValidatorNotInitialized, ISpruceErrorOptions {
4
4
  code: 'VALIDATOR_NOT_INITIALIZED';
5
5
  }