@sprucelabs/spruce-calendar-components 20.9.34 → 20.9.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/.spruce/schemas/schemas.types.d.ts +605 -605
- package/build/esm/.spruce/schemas/schemas.types.d.ts +605 -605
- package/build/esm/stores/RemoteEventStore.d.ts +24 -11
- package/build/esm/stores/RemoteEventStore.js +56 -10
- package/build/esm/viewControllers/Calendar.vc.d.ts +1 -1
- package/build/esm/viewControllers/Calendar.vc.js +9 -4
- package/build/stores/RemoteEventStore.d.ts +24 -11
- package/build/stores/RemoteEventStore.js +48 -10
- package/build/viewControllers/Calendar.vc.d.ts +1 -1
- package/build/viewControllers/Calendar.vc.js +9 -4
- package/package.json +1 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
3
3
|
import { UpdateEvent } from '../types/calendar.types';
|
|
4
|
-
export interface RemoteEventStoreOptions {
|
|
5
|
-
client: MercuryClient;
|
|
6
|
-
calendarId?: string;
|
|
7
|
-
locationId: string;
|
|
8
|
-
}
|
|
9
|
-
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
10
4
|
export default class RemoteEventStore {
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
private connectToApi;
|
|
6
|
+
protected calendarId?: string;
|
|
7
|
+
protected locationId: string;
|
|
8
|
+
protected organizationId: string;
|
|
9
|
+
protected client: MercuryClient;
|
|
10
|
+
private pendingEvents;
|
|
15
11
|
private draftIdMap;
|
|
16
12
|
private promises;
|
|
17
13
|
private queueByEventId;
|
|
18
14
|
private busyByEvent;
|
|
19
15
|
private lastSavedById;
|
|
20
16
|
constructor(options: RemoteEventStoreOptions);
|
|
17
|
+
load(options: {
|
|
18
|
+
organizationId: string;
|
|
19
|
+
locationId: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
21
|
persist(event: UpdateEvent): Promise<FullEvent>;
|
|
22
22
|
private startQueueForEvent;
|
|
23
23
|
private getId;
|
|
@@ -32,6 +32,19 @@ export default class RemoteEventStore {
|
|
|
32
32
|
clearCalendarId(): void;
|
|
33
33
|
getCalendarId(): string | undefined;
|
|
34
34
|
waitForPendingSaves(): Promise<void>;
|
|
35
|
-
|
|
35
|
+
cancelEvent(id: string): Promise<void>;
|
|
36
|
+
getSchedules(options: {
|
|
37
|
+
calendarIds: string[];
|
|
38
|
+
personIds: string[];
|
|
39
|
+
startDate: number;
|
|
40
|
+
endDate: number;
|
|
41
|
+
}): Promise<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventSchema, false>>[]>;
|
|
42
|
+
loadEventTypes(): Promise<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Calendar.v2021_05_19.CalendarEventTypeSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Calendar.v2021_05_19.CalendarEventTypeSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Calendar.v2021_05_19.CalendarEventTypeSchema, false>>[]>;
|
|
43
|
+
loadCalendars(): Promise<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false>>[]>;
|
|
36
44
|
}
|
|
45
|
+
export interface RemoteEventStoreOptions {
|
|
46
|
+
connectToApi: () => Promise<MercuryClient>;
|
|
47
|
+
calendarId?: string;
|
|
48
|
+
}
|
|
49
|
+
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
37
50
|
export {};
|
|
@@ -23,20 +23,33 @@ import { assertOptions, normalizeSchemaValues } from '@sprucelabs/schema';
|
|
|
23
23
|
import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
24
24
|
export default class RemoteEventStore {
|
|
25
25
|
constructor(options) {
|
|
26
|
+
this.pendingEvents = {};
|
|
26
27
|
this.draftIdMap = {};
|
|
27
28
|
this.promises = [];
|
|
28
29
|
this.queueByEventId = {};
|
|
29
30
|
this.busyByEvent = {};
|
|
30
31
|
this.lastSavedById = {};
|
|
31
|
-
assertOptions(options, [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
32
|
+
const { connectToApi, calendarId } = assertOptions(options, [
|
|
33
|
+
'connectToApi',
|
|
34
|
+
]);
|
|
35
|
+
this.connectToApi = connectToApi;
|
|
36
|
+
this.calendarId = calendarId;
|
|
37
|
+
}
|
|
38
|
+
load(options) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const { organizationId, locationId } = assertOptions(options, [
|
|
41
|
+
'locationId',
|
|
42
|
+
'organizationId',
|
|
43
|
+
]);
|
|
44
|
+
this.locationId = locationId;
|
|
45
|
+
this.organizationId = organizationId;
|
|
46
|
+
this.client = yield this.connectToApi();
|
|
47
|
+
});
|
|
35
48
|
}
|
|
36
49
|
persist(event) {
|
|
37
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
51
|
if (!this.resolveCalendarId(event)) {
|
|
39
|
-
this.
|
|
52
|
+
this.pendingEvents[event.id] = event;
|
|
40
53
|
return event;
|
|
41
54
|
}
|
|
42
55
|
if (!this.queueByEventId[this.getId(event.id)]) {
|
|
@@ -105,7 +118,8 @@ export default class RemoteEventStore {
|
|
|
105
118
|
updateEvent(event) {
|
|
106
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
120
|
const { target, payload } = this.splitPayloadAndTarget(event);
|
|
108
|
-
const
|
|
121
|
+
const client = yield this.connectToApi();
|
|
122
|
+
const results = yield client.emitAndFlattenResponses('calendar.update-calendar-event::v2021_05_19', {
|
|
109
123
|
target: Object.assign({ calendarEventId: event.id }, target),
|
|
110
124
|
payload: Object.assign({}, payload),
|
|
111
125
|
});
|
|
@@ -197,11 +211,10 @@ export default class RemoteEventStore {
|
|
|
197
211
|
yield Promise.all(this.promises);
|
|
198
212
|
});
|
|
199
213
|
}
|
|
200
|
-
|
|
201
|
-
var _a;
|
|
214
|
+
cancelEvent(id) {
|
|
202
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
if (
|
|
204
|
-
delete this.
|
|
216
|
+
if (this.pendingEvents[id]) {
|
|
217
|
+
delete this.pendingEvents[id];
|
|
205
218
|
}
|
|
206
219
|
else {
|
|
207
220
|
yield this.client.emitAndFlattenResponses('calendar.cancel-calendar-event::v2021_05_19', {
|
|
@@ -213,6 +226,39 @@ export default class RemoteEventStore {
|
|
|
213
226
|
}
|
|
214
227
|
});
|
|
215
228
|
}
|
|
229
|
+
getSchedules(options) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const { calendarIds, personIds, startDate, endDate } = options;
|
|
232
|
+
const [{ events }] = yield this.client.emitAndFlattenResponses('calendar.get-schedules::v2021_05_19', {
|
|
233
|
+
target: {
|
|
234
|
+
calendarIds,
|
|
235
|
+
locationId: this.locationId,
|
|
236
|
+
},
|
|
237
|
+
payload: {
|
|
238
|
+
startDateTimeMs: startDate,
|
|
239
|
+
endDateTimeMs: endDate,
|
|
240
|
+
personIds,
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
return events;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
loadEventTypes() {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
const [{ calendarEventTypes }] = yield this.client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19');
|
|
249
|
+
return calendarEventTypes;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
loadCalendars() {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
const [{ calendars }] = yield this.client.emitAndFlattenResponses('calendar.list-calendars::v2021_05_19', {
|
|
255
|
+
target: {
|
|
256
|
+
organizationId: this.organizationId,
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
return calendars;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
216
262
|
}
|
|
217
263
|
const equals = (a, b) => {
|
|
218
264
|
if (a === b) {
|
|
@@ -69,7 +69,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
69
69
|
}>;
|
|
70
70
|
getIsSwappingEvent(): boolean;
|
|
71
71
|
private swapEvent;
|
|
72
|
-
updateEvent(id: string, updates: Partial<UpdateEvent>):
|
|
72
|
+
updateEvent(id: string, updates: Partial<UpdateEvent>): any;
|
|
73
73
|
private persist;
|
|
74
74
|
getPeople(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarPerson[];
|
|
75
75
|
render(): {
|
|
@@ -102,7 +102,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
102
102
|
this.removeEvent(id);
|
|
103
103
|
yield ((_a = this.draftRemovedHandler) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
104
104
|
try {
|
|
105
|
-
yield ((_b = this.remoteEventStore) === null || _b === void 0 ? void 0 : _b.
|
|
105
|
+
yield ((_b = this.remoteEventStore) === null || _b === void 0 ? void 0 : _b.cancelEvent(id));
|
|
106
106
|
// eslint-disable-next-line no-empty
|
|
107
107
|
}
|
|
108
108
|
catch (err) {
|
|
@@ -171,9 +171,14 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
updateEvent(id, updates) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
try {
|
|
175
|
+
const updated = super.updateEvent(id, Object.assign(Object.assign({}, updates), { isBusy: true }));
|
|
176
|
+
void this.persist(updated);
|
|
177
|
+
return updated;
|
|
178
|
+
// eslint-disable-next-line no-empty
|
|
179
|
+
}
|
|
180
|
+
catch (_a) { }
|
|
181
|
+
return Object.assign({}, updates);
|
|
177
182
|
}
|
|
178
183
|
persist(event, options) {
|
|
179
184
|
const _super = Object.create(null, {
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
3
3
|
import { UpdateEvent } from '../types/calendar.types';
|
|
4
|
-
export interface RemoteEventStoreOptions {
|
|
5
|
-
client: MercuryClient;
|
|
6
|
-
calendarId?: string;
|
|
7
|
-
locationId: string;
|
|
8
|
-
}
|
|
9
|
-
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
10
4
|
export default class RemoteEventStore {
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
private connectToApi;
|
|
6
|
+
protected calendarId?: string;
|
|
7
|
+
protected locationId: string;
|
|
8
|
+
protected organizationId: string;
|
|
9
|
+
protected client: MercuryClient;
|
|
10
|
+
private pendingEvents;
|
|
15
11
|
private draftIdMap;
|
|
16
12
|
private promises;
|
|
17
13
|
private queueByEventId;
|
|
18
14
|
private busyByEvent;
|
|
19
15
|
private lastSavedById;
|
|
20
16
|
constructor(options: RemoteEventStoreOptions);
|
|
17
|
+
load(options: {
|
|
18
|
+
organizationId: string;
|
|
19
|
+
locationId: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
21
|
persist(event: UpdateEvent): Promise<FullEvent>;
|
|
22
22
|
private startQueueForEvent;
|
|
23
23
|
private getId;
|
|
@@ -32,6 +32,19 @@ export default class RemoteEventStore {
|
|
|
32
32
|
clearCalendarId(): void;
|
|
33
33
|
getCalendarId(): string | undefined;
|
|
34
34
|
waitForPendingSaves(): Promise<void>;
|
|
35
|
-
|
|
35
|
+
cancelEvent(id: string): Promise<void>;
|
|
36
|
+
getSchedules(options: {
|
|
37
|
+
calendarIds: string[];
|
|
38
|
+
personIds: string[];
|
|
39
|
+
startDate: number;
|
|
40
|
+
endDate: number;
|
|
41
|
+
}): Promise<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventSchema, false>>[]>;
|
|
42
|
+
loadEventTypes(): Promise<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Calendar.v2021_05_19.CalendarEventTypeSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Calendar.v2021_05_19.CalendarEventTypeSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Calendar.v2021_05_19.CalendarEventTypeSchema, false>>[]>;
|
|
43
|
+
loadCalendars(): Promise<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false>>[]>;
|
|
36
44
|
}
|
|
45
|
+
export interface RemoteEventStoreOptions {
|
|
46
|
+
connectToApi: () => Promise<MercuryClient>;
|
|
47
|
+
calendarId?: string;
|
|
48
|
+
}
|
|
49
|
+
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
37
50
|
export {};
|
|
@@ -19,19 +19,30 @@ const schema_1 = require("@sprucelabs/schema");
|
|
|
19
19
|
const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"));
|
|
20
20
|
class RemoteEventStore {
|
|
21
21
|
constructor(options) {
|
|
22
|
+
this.pendingEvents = {};
|
|
22
23
|
this.draftIdMap = {};
|
|
23
24
|
this.promises = [];
|
|
24
25
|
this.queueByEventId = {};
|
|
25
26
|
this.busyByEvent = {};
|
|
26
27
|
this.lastSavedById = {};
|
|
27
|
-
(0, schema_1.assertOptions)(options, [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.
|
|
28
|
+
const { connectToApi, calendarId } = (0, schema_1.assertOptions)(options, [
|
|
29
|
+
'connectToApi',
|
|
30
|
+
]);
|
|
31
|
+
this.connectToApi = connectToApi;
|
|
32
|
+
this.calendarId = calendarId;
|
|
33
|
+
}
|
|
34
|
+
async load(options) {
|
|
35
|
+
const { organizationId, locationId } = (0, schema_1.assertOptions)(options, [
|
|
36
|
+
'locationId',
|
|
37
|
+
'organizationId',
|
|
38
|
+
]);
|
|
39
|
+
this.locationId = locationId;
|
|
40
|
+
this.organizationId = organizationId;
|
|
41
|
+
this.client = await this.connectToApi();
|
|
31
42
|
}
|
|
32
43
|
async persist(event) {
|
|
33
44
|
if (!this.resolveCalendarId(event)) {
|
|
34
|
-
this.
|
|
45
|
+
this.pendingEvents[event.id] = event;
|
|
35
46
|
return event;
|
|
36
47
|
}
|
|
37
48
|
if (!this.queueByEventId[this.getId(event.id)]) {
|
|
@@ -96,7 +107,8 @@ class RemoteEventStore {
|
|
|
96
107
|
}
|
|
97
108
|
async updateEvent(event) {
|
|
98
109
|
const { target, payload } = this.splitPayloadAndTarget(event);
|
|
99
|
-
const
|
|
110
|
+
const client = await this.connectToApi();
|
|
111
|
+
const results = await client.emitAndFlattenResponses('calendar.update-calendar-event::v2021_05_19', {
|
|
100
112
|
target: Object.assign({ calendarEventId: event.id }, target),
|
|
101
113
|
payload: Object.assign({}, payload),
|
|
102
114
|
});
|
|
@@ -181,10 +193,9 @@ class RemoteEventStore {
|
|
|
181
193
|
async waitForPendingSaves() {
|
|
182
194
|
await Promise.all(this.promises);
|
|
183
195
|
}
|
|
184
|
-
async
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
delete this.pendingEvent;
|
|
196
|
+
async cancelEvent(id) {
|
|
197
|
+
if (this.pendingEvents[id]) {
|
|
198
|
+
delete this.pendingEvents[id];
|
|
188
199
|
}
|
|
189
200
|
else {
|
|
190
201
|
await this.client.emitAndFlattenResponses('calendar.cancel-calendar-event::v2021_05_19', {
|
|
@@ -195,6 +206,33 @@ class RemoteEventStore {
|
|
|
195
206
|
});
|
|
196
207
|
}
|
|
197
208
|
}
|
|
209
|
+
async getSchedules(options) {
|
|
210
|
+
const { calendarIds, personIds, startDate, endDate } = options;
|
|
211
|
+
const [{ events }] = await this.client.emitAndFlattenResponses('calendar.get-schedules::v2021_05_19', {
|
|
212
|
+
target: {
|
|
213
|
+
calendarIds,
|
|
214
|
+
locationId: this.locationId,
|
|
215
|
+
},
|
|
216
|
+
payload: {
|
|
217
|
+
startDateTimeMs: startDate,
|
|
218
|
+
endDateTimeMs: endDate,
|
|
219
|
+
personIds,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
return events;
|
|
223
|
+
}
|
|
224
|
+
async loadEventTypes() {
|
|
225
|
+
const [{ calendarEventTypes }] = await this.client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19');
|
|
226
|
+
return calendarEventTypes;
|
|
227
|
+
}
|
|
228
|
+
async loadCalendars() {
|
|
229
|
+
const [{ calendars }] = await this.client.emitAndFlattenResponses('calendar.list-calendars::v2021_05_19', {
|
|
230
|
+
target: {
|
|
231
|
+
organizationId: this.organizationId,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
return calendars;
|
|
235
|
+
}
|
|
198
236
|
}
|
|
199
237
|
exports.default = RemoteEventStore;
|
|
200
238
|
const equals = (a, b) => {
|
|
@@ -69,7 +69,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
69
69
|
}>;
|
|
70
70
|
getIsSwappingEvent(): boolean;
|
|
71
71
|
private swapEvent;
|
|
72
|
-
updateEvent(id: string, updates: Partial<UpdateEvent>):
|
|
72
|
+
updateEvent(id: string, updates: Partial<UpdateEvent>): any;
|
|
73
73
|
private persist;
|
|
74
74
|
getPeople(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarPerson[];
|
|
75
75
|
render(): {
|
|
@@ -93,7 +93,7 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
93
93
|
this.removeEvent(id);
|
|
94
94
|
await ((_a = this.draftRemovedHandler) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
95
95
|
try {
|
|
96
|
-
await ((_b = this.remoteEventStore) === null || _b === void 0 ? void 0 : _b.
|
|
96
|
+
await ((_b = this.remoteEventStore) === null || _b === void 0 ? void 0 : _b.cancelEvent(id));
|
|
97
97
|
// eslint-disable-next-line no-empty
|
|
98
98
|
}
|
|
99
99
|
catch (err) {
|
|
@@ -152,9 +152,14 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
152
152
|
this.enableAnimation();
|
|
153
153
|
}
|
|
154
154
|
updateEvent(id, updates) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
try {
|
|
156
|
+
const updated = super.updateEvent(id, Object.assign(Object.assign({}, updates), { isBusy: true }));
|
|
157
|
+
void this.persist(updated);
|
|
158
|
+
return updated;
|
|
159
|
+
// eslint-disable-next-line no-empty
|
|
160
|
+
}
|
|
161
|
+
catch (_a) { }
|
|
162
|
+
return Object.assign({}, updates);
|
|
158
163
|
}
|
|
159
164
|
async persist(event, options) {
|
|
160
165
|
var _a, _b;
|