@amityco/ts-sdk 7.11.1-d19e0f3d.0 → 7.11.1-ed060e83.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.
- package/dist/@types/core/payload.d.ts +4 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +5 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +3 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +8 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +33 -7
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +2 -2
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/eventRepository/api/createEvent.d.ts +2 -2
- package/dist/eventRepository/api/deleteEvent.d.ts +15 -0
- package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -0
- package/dist/eventRepository/api/index.d.ts +2 -0
- package/dist/eventRepository/api/index.d.ts.map +1 -1
- package/dist/eventRepository/api/updateEvent.d.ts +17 -0
- package/dist/eventRepository/api/updateEvent.d.ts.map +1 -0
- package/dist/eventRepository/events/enums.d.ts +6 -0
- package/dist/eventRepository/events/enums.d.ts.map +1 -0
- package/dist/eventRepository/events/index.d.ts +4 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/index.d.ts +2 -0
- package/dist/eventRepository/index.d.ts.map +1 -1
- package/dist/eventRepository/internalApi/getEvent.d.ts +32 -0
- package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/index.d.ts +2 -0
- package/dist/eventRepository/internalApi/index.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvent.d.ts +21 -0
- package/dist/eventRepository/observers/getEvent.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/index.d.ts +4 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -0
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +2 -0
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -0
- package/dist/eventRepository/utils/index.d.ts +1 -0
- package/dist/eventRepository/utils/index.d.ts.map +1 -1
- package/dist/index.cjs.js +519 -6
- package/dist/index.esm.js +520 -7
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -209,6 +209,12 @@ exports.AmityEventStatus = void 0;
|
|
|
209
209
|
AmityEventStatus["Ended"] = "ended";
|
|
210
210
|
AmityEventStatus["Cancelled"] = "cancelled";
|
|
211
211
|
})(exports.AmityEventStatus || (exports.AmityEventStatus = {}));
|
|
212
|
+
exports.AmityEventResponseStatus = void 0;
|
|
213
|
+
(function (AmityEventResponseStatus) {
|
|
214
|
+
AmityEventResponseStatus["Going"] = "going";
|
|
215
|
+
AmityEventResponseStatus["Interested"] = "interested";
|
|
216
|
+
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
217
|
+
})(exports.AmityEventResponseStatus || (exports.AmityEventResponseStatus = {}));
|
|
212
218
|
|
|
213
219
|
function getVersion() {
|
|
214
220
|
try {
|
|
@@ -658,6 +664,7 @@ const idResolvers = {
|
|
|
658
664
|
notificationTraySeen: ({ userId }) => userId,
|
|
659
665
|
invitation: ({ _id }) => _id,
|
|
660
666
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
667
|
+
event: ({ eventId }) => eventId,
|
|
661
668
|
};
|
|
662
669
|
/**
|
|
663
670
|
* Retrieve the id resolver matching a domain name
|
|
@@ -713,6 +720,8 @@ const PAYLOAD2MODEL = {
|
|
|
713
720
|
notificationTrayItems: 'notificationTrayItem',
|
|
714
721
|
invitations: 'invitation',
|
|
715
722
|
joinRequests: 'joinRequest',
|
|
723
|
+
events: 'event',
|
|
724
|
+
discussionCommunities: 'community',
|
|
716
725
|
};
|
|
717
726
|
/** hidden */
|
|
718
727
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -13684,9 +13693,13 @@ const eventLinkedObject = (event) => {
|
|
|
13684
13693
|
return userLinkedObject(cacheData.data);
|
|
13685
13694
|
},
|
|
13686
13695
|
get discussionCommunity() {
|
|
13687
|
-
if (!event.
|
|
13696
|
+
if (!event.discussionCommunityId)
|
|
13688
13697
|
return;
|
|
13689
|
-
const cacheData = pullFromCache([
|
|
13698
|
+
const cacheData = pullFromCache([
|
|
13699
|
+
'community',
|
|
13700
|
+
'get',
|
|
13701
|
+
event.discussionCommunityId,
|
|
13702
|
+
]);
|
|
13690
13703
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13691
13704
|
return;
|
|
13692
13705
|
return communityLinkedObject(cacheData.data);
|
|
@@ -30341,13 +30354,33 @@ const prepareEventPayload = (rawPayload) => {
|
|
|
30341
30354
|
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
30342
30355
|
};
|
|
30343
30356
|
|
|
30357
|
+
const createEventEventSubscriber = (event, callback) => {
|
|
30358
|
+
const client = getActiveClient();
|
|
30359
|
+
const filter = (payload) => {
|
|
30360
|
+
const unpackedPayload = prepareEventPayload(payload);
|
|
30361
|
+
if (!client.cache) {
|
|
30362
|
+
callback(unpackedPayload.events[0]);
|
|
30363
|
+
}
|
|
30364
|
+
else {
|
|
30365
|
+
ingestInCache(unpackedPayload);
|
|
30366
|
+
const event = pullFromCache([
|
|
30367
|
+
'event',
|
|
30368
|
+
'get',
|
|
30369
|
+
unpackedPayload.events[0].eventId,
|
|
30370
|
+
]);
|
|
30371
|
+
callback(event.data);
|
|
30372
|
+
}
|
|
30373
|
+
};
|
|
30374
|
+
return createEventSubscriber(client, event, event, filter);
|
|
30375
|
+
};
|
|
30376
|
+
|
|
30344
30377
|
/* begin_public_function
|
|
30345
30378
|
id: event.create
|
|
30346
30379
|
*/
|
|
30347
30380
|
/**
|
|
30348
30381
|
* ```js
|
|
30349
|
-
* import {
|
|
30350
|
-
* const
|
|
30382
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30383
|
+
* const response = await EventRepository.createEvent(bundle)
|
|
30351
30384
|
* ```
|
|
30352
30385
|
*
|
|
30353
30386
|
* Creates an {@link Amity.Event}
|
|
@@ -30362,11 +30395,11 @@ const createEvent = async (bundle) => {
|
|
|
30362
30395
|
const client = getActiveClient();
|
|
30363
30396
|
client.log('event/createEvent', bundle);
|
|
30364
30397
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
30398
|
+
fireEvent('event.created', payload);
|
|
30365
30399
|
const preparedPayload = prepareEventPayload(payload);
|
|
30366
30400
|
const cachedAt = client.cache && Date.now();
|
|
30367
30401
|
if (client.cache)
|
|
30368
30402
|
ingestInCache(preparedPayload, { cachedAt });
|
|
30369
|
-
fireEvent('event.created', preparedPayload);
|
|
30370
30403
|
return {
|
|
30371
30404
|
data: eventLinkedObject(preparedPayload.events[0]),
|
|
30372
30405
|
cachedAt,
|
|
@@ -30374,9 +30407,489 @@ const createEvent = async (bundle) => {
|
|
|
30374
30407
|
};
|
|
30375
30408
|
/* end_public_function */
|
|
30376
30409
|
|
|
30410
|
+
/* begin_public_function
|
|
30411
|
+
id: event.update
|
|
30412
|
+
*/
|
|
30413
|
+
/**
|
|
30414
|
+
* ```js
|
|
30415
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30416
|
+
* const response = await EventRepository.updateEvent(eventId, bundle)
|
|
30417
|
+
* ```
|
|
30418
|
+
*
|
|
30419
|
+
* Updates an {@link Amity.Event}
|
|
30420
|
+
*
|
|
30421
|
+
* @param eventId The ID of the {@link Amity.Event} to edit
|
|
30422
|
+
* @param bundle The data necessary to update an existing {@link Amity.Event}
|
|
30423
|
+
* @returns the updated {@link Amity.Event}
|
|
30424
|
+
*
|
|
30425
|
+
* @category Event API
|
|
30426
|
+
* @async
|
|
30427
|
+
*/
|
|
30428
|
+
const updateEvent = async (eventId, bundle) => {
|
|
30429
|
+
const client = getActiveClient();
|
|
30430
|
+
client.log('event/updateEvent', eventId, bundle);
|
|
30431
|
+
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
30432
|
+
fireEvent('event.updated', payload);
|
|
30433
|
+
const preparedPayload = prepareEventPayload(payload);
|
|
30434
|
+
const cachedAt = client.cache && Date.now();
|
|
30435
|
+
if (client.cache)
|
|
30436
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
30437
|
+
return {
|
|
30438
|
+
data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
|
|
30439
|
+
cachedAt,
|
|
30440
|
+
};
|
|
30441
|
+
};
|
|
30442
|
+
/* end_public_function */
|
|
30443
|
+
|
|
30444
|
+
/* begin_public_function
|
|
30445
|
+
id: event.get
|
|
30446
|
+
*/
|
|
30447
|
+
/**
|
|
30448
|
+
* ```js
|
|
30449
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30450
|
+
* const event = await EventRepository.getEvent(eventId)
|
|
30451
|
+
* ```
|
|
30452
|
+
*
|
|
30453
|
+
* Fetches a {@link Amity.Event} object
|
|
30454
|
+
*
|
|
30455
|
+
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
30456
|
+
* @returns the associated {@link Amity.Event} object
|
|
30457
|
+
*
|
|
30458
|
+
* @category Event API
|
|
30459
|
+
* @async
|
|
30460
|
+
*/
|
|
30461
|
+
const getEvent$1 = async (eventId) => {
|
|
30462
|
+
const client = getActiveClient();
|
|
30463
|
+
client.log('event/getEvent', eventId);
|
|
30464
|
+
const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
|
|
30465
|
+
const data = prepareEventPayload(payload);
|
|
30466
|
+
const cachedAt = client.cache && Date.now();
|
|
30467
|
+
if (client.cache)
|
|
30468
|
+
ingestInCache(data, { cachedAt });
|
|
30469
|
+
return {
|
|
30470
|
+
data: data.events.find(event => event.eventId === eventId),
|
|
30471
|
+
cachedAt,
|
|
30472
|
+
};
|
|
30473
|
+
};
|
|
30474
|
+
/* end_public_function */
|
|
30475
|
+
/**
|
|
30476
|
+
* ```js
|
|
30477
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30478
|
+
* const event = EventRepository.getEvent.locally(eventId)
|
|
30479
|
+
* ```
|
|
30480
|
+
*
|
|
30481
|
+
* Fetches a {@link Amity.Event} object in cache
|
|
30482
|
+
*
|
|
30483
|
+
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
30484
|
+
* @returns the associated {@link Amity.Event} object
|
|
30485
|
+
*
|
|
30486
|
+
* @category Event API
|
|
30487
|
+
*/
|
|
30488
|
+
getEvent$1.locally = (eventId) => {
|
|
30489
|
+
const client = getActiveClient();
|
|
30490
|
+
client.log('event/getEvent.locally', eventId);
|
|
30491
|
+
if (!client.cache)
|
|
30492
|
+
return;
|
|
30493
|
+
const cache = pullFromCache(['event', 'get', eventId]);
|
|
30494
|
+
if (!cache)
|
|
30495
|
+
return;
|
|
30496
|
+
return {
|
|
30497
|
+
data: cache.data,
|
|
30498
|
+
cachedAt: cache.cachedAt,
|
|
30499
|
+
};
|
|
30500
|
+
};
|
|
30501
|
+
|
|
30502
|
+
/* begin_public_function
|
|
30503
|
+
id: event.delete
|
|
30504
|
+
*/
|
|
30505
|
+
/**
|
|
30506
|
+
* ```js
|
|
30507
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30508
|
+
* const { success } = await EventRepository.deleteEvent(eventId)
|
|
30509
|
+
* ```
|
|
30510
|
+
*
|
|
30511
|
+
* Deletes a {@link Amity.Event}
|
|
30512
|
+
*
|
|
30513
|
+
* @param eventId The {@link Amity.Event} ID to delete
|
|
30514
|
+
*
|
|
30515
|
+
* @category Event API
|
|
30516
|
+
* @async
|
|
30517
|
+
*/
|
|
30518
|
+
const deleteEvent = async (eventId) => {
|
|
30519
|
+
const client = getActiveClient();
|
|
30520
|
+
client.log('event/deleteEvent', eventId);
|
|
30521
|
+
const event = await getEvent$1(eventId);
|
|
30522
|
+
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
30523
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
30524
|
+
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
30525
|
+
fireEvent('event.deleted', {
|
|
30526
|
+
users: [],
|
|
30527
|
+
files: [],
|
|
30528
|
+
communities: [],
|
|
30529
|
+
videoStreamings: [],
|
|
30530
|
+
events: [deletedEvent],
|
|
30531
|
+
discussionCommunities: [],
|
|
30532
|
+
});
|
|
30533
|
+
};
|
|
30534
|
+
/* end_public_function */
|
|
30535
|
+
|
|
30536
|
+
/**
|
|
30537
|
+
* ```js
|
|
30538
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30539
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
30540
|
+
* // ...
|
|
30541
|
+
* })
|
|
30542
|
+
* ```
|
|
30543
|
+
*
|
|
30544
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30545
|
+
*
|
|
30546
|
+
* @param callback The function to call when the event was fired
|
|
30547
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30548
|
+
*
|
|
30549
|
+
* @category Event Events
|
|
30550
|
+
*/
|
|
30551
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30552
|
+
|
|
30553
|
+
/**
|
|
30554
|
+
* ```js
|
|
30555
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30556
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30557
|
+
* // ...
|
|
30558
|
+
* })
|
|
30559
|
+
* ```
|
|
30560
|
+
*
|
|
30561
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30562
|
+
*
|
|
30563
|
+
* @param callback The function to call when the event was fired
|
|
30564
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30565
|
+
*
|
|
30566
|
+
* @category Event Events
|
|
30567
|
+
*/
|
|
30568
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30569
|
+
|
|
30570
|
+
/**
|
|
30571
|
+
* ```js
|
|
30572
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30573
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30574
|
+
* // ...
|
|
30575
|
+
* })
|
|
30576
|
+
* ```
|
|
30577
|
+
*
|
|
30578
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30579
|
+
*
|
|
30580
|
+
* @param callback The function to call when the event was fired
|
|
30581
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30582
|
+
*
|
|
30583
|
+
* @category Event Events
|
|
30584
|
+
*/
|
|
30585
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30586
|
+
|
|
30587
|
+
/* begin_public_function
|
|
30588
|
+
id: event.get
|
|
30589
|
+
*/
|
|
30590
|
+
/**
|
|
30591
|
+
* ```js
|
|
30592
|
+
* import { EventRepository } from '@amityco/ts-sdk';
|
|
30593
|
+
*
|
|
30594
|
+
* let event;
|
|
30595
|
+
*
|
|
30596
|
+
* const unsubscribe = EventRepository.getEvent(eventId, response => {
|
|
30597
|
+
* event = response.data;
|
|
30598
|
+
* });
|
|
30599
|
+
* ```
|
|
30600
|
+
*
|
|
30601
|
+
* Observe all mutation on a given {@link Amity.Event}
|
|
30602
|
+
*
|
|
30603
|
+
* @param eventId the ID of the event to observe
|
|
30604
|
+
* @param callback the function to call when new snapshot of event are available
|
|
30605
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
|
|
30606
|
+
*
|
|
30607
|
+
* @category Event Live Object
|
|
30608
|
+
*/
|
|
30609
|
+
const getEvent = (eventId, callback) => {
|
|
30610
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
|
|
30611
|
+
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
30612
|
+
});
|
|
30613
|
+
};
|
|
30614
|
+
/* end_public_function */
|
|
30615
|
+
|
|
30616
|
+
var EventActionsEnum;
|
|
30617
|
+
(function (EventActionsEnum) {
|
|
30618
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
30619
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
30620
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
30621
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
30622
|
+
|
|
30623
|
+
class EventPaginationController extends PaginationController {
|
|
30624
|
+
async getRequest(queryParams, token) {
|
|
30625
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30626
|
+
const options = token ? { token } : { limit };
|
|
30627
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30628
|
+
return response;
|
|
30629
|
+
}
|
|
30630
|
+
}
|
|
30631
|
+
|
|
30632
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
30633
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30634
|
+
super(query, cacheKey);
|
|
30635
|
+
this.notifyChange = notifyChange;
|
|
30636
|
+
this.preparePayload = preparePayload;
|
|
30637
|
+
}
|
|
30638
|
+
async saveToMainDB(response) {
|
|
30639
|
+
const processedPayload = this.preparePayload(response);
|
|
30640
|
+
const client = getActiveClient();
|
|
30641
|
+
const cachedAt = client.cache && Date.now();
|
|
30642
|
+
if (client.cache)
|
|
30643
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30644
|
+
}
|
|
30645
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30646
|
+
var _a, _b;
|
|
30647
|
+
if (refresh) {
|
|
30648
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30649
|
+
}
|
|
30650
|
+
else {
|
|
30651
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30652
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30653
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30654
|
+
}
|
|
30655
|
+
}
|
|
30656
|
+
reactor(action) {
|
|
30657
|
+
return (event) => {
|
|
30658
|
+
var _a;
|
|
30659
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30660
|
+
if (!collection)
|
|
30661
|
+
return;
|
|
30662
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
30663
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30664
|
+
}
|
|
30665
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30666
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30667
|
+
}
|
|
30668
|
+
pushToCache(this.cacheKey, collection);
|
|
30669
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30670
|
+
};
|
|
30671
|
+
}
|
|
30672
|
+
subscribeRTE(createSubscriber) {
|
|
30673
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30674
|
+
}
|
|
30675
|
+
}
|
|
30676
|
+
|
|
30677
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
30678
|
+
constructor(query, callback) {
|
|
30679
|
+
const queryStreamId = hash__default["default"](query);
|
|
30680
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30681
|
+
const paginationController = new EventPaginationController(query);
|
|
30682
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30683
|
+
this.query = query;
|
|
30684
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30685
|
+
this.callback = callback.bind(this);
|
|
30686
|
+
this.loadPage({ initial: true });
|
|
30687
|
+
}
|
|
30688
|
+
setup() {
|
|
30689
|
+
var _a;
|
|
30690
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30691
|
+
if (!collection)
|
|
30692
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30693
|
+
}
|
|
30694
|
+
async persistModel(queryPayload) {
|
|
30695
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30696
|
+
}
|
|
30697
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30698
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30699
|
+
}
|
|
30700
|
+
startSubscription() {
|
|
30701
|
+
return this.queryStreamController.subscribeRTE([
|
|
30702
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30703
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30704
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30705
|
+
]);
|
|
30706
|
+
}
|
|
30707
|
+
notifyChange({ origin, loading, error }) {
|
|
30708
|
+
var _a, _b;
|
|
30709
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30710
|
+
if (!collection)
|
|
30711
|
+
return;
|
|
30712
|
+
const data = ((_b = collection.data
|
|
30713
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30714
|
+
.filter(isNonNullable)
|
|
30715
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30716
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30717
|
+
return;
|
|
30718
|
+
this.callback({
|
|
30719
|
+
data,
|
|
30720
|
+
error,
|
|
30721
|
+
loading,
|
|
30722
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30723
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30724
|
+
});
|
|
30725
|
+
}
|
|
30726
|
+
}
|
|
30727
|
+
|
|
30728
|
+
/**
|
|
30729
|
+
* Get events
|
|
30730
|
+
*
|
|
30731
|
+
* @param params the query parameters
|
|
30732
|
+
* @param callback the callback to be called when the events are updated
|
|
30733
|
+
* @returns events
|
|
30734
|
+
*
|
|
30735
|
+
* @category Event Live Collection
|
|
30736
|
+
*
|
|
30737
|
+
*/
|
|
30738
|
+
const getEvents = (params, callback, config) => {
|
|
30739
|
+
const { log, cache } = getActiveClient();
|
|
30740
|
+
if (!cache)
|
|
30741
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30742
|
+
const timestamp = Date.now();
|
|
30743
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
30744
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
30745
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
30746
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
30747
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30748
|
+
return () => {
|
|
30749
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
30750
|
+
disposers.forEach(fn => fn());
|
|
30751
|
+
};
|
|
30752
|
+
};
|
|
30753
|
+
|
|
30754
|
+
class MyEventPaginationController extends PaginationController {
|
|
30755
|
+
async getRequest(queryParams, token) {
|
|
30756
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30757
|
+
const options = token ? { token } : { limit };
|
|
30758
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30759
|
+
return response;
|
|
30760
|
+
}
|
|
30761
|
+
}
|
|
30762
|
+
|
|
30763
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
30764
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30765
|
+
super(query, cacheKey);
|
|
30766
|
+
this.notifyChange = notifyChange;
|
|
30767
|
+
this.preparePayload = preparePayload;
|
|
30768
|
+
}
|
|
30769
|
+
async saveToMainDB(response) {
|
|
30770
|
+
const processedPayload = this.preparePayload(response);
|
|
30771
|
+
const client = getActiveClient();
|
|
30772
|
+
const cachedAt = client.cache && Date.now();
|
|
30773
|
+
if (client.cache)
|
|
30774
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30775
|
+
}
|
|
30776
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30777
|
+
var _a, _b;
|
|
30778
|
+
if (refresh) {
|
|
30779
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30780
|
+
}
|
|
30781
|
+
else {
|
|
30782
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30783
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30784
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30785
|
+
}
|
|
30786
|
+
}
|
|
30787
|
+
reactor(action) {
|
|
30788
|
+
return (event) => {
|
|
30789
|
+
var _a;
|
|
30790
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30791
|
+
if (!collection)
|
|
30792
|
+
return;
|
|
30793
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30794
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30795
|
+
}
|
|
30796
|
+
pushToCache(this.cacheKey, collection);
|
|
30797
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30798
|
+
};
|
|
30799
|
+
}
|
|
30800
|
+
subscribeRTE(createSubscriber) {
|
|
30801
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30802
|
+
}
|
|
30803
|
+
}
|
|
30804
|
+
|
|
30805
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
30806
|
+
constructor(query, callback) {
|
|
30807
|
+
const queryStreamId = hash__default["default"](query);
|
|
30808
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30809
|
+
const paginationController = new MyEventPaginationController(query);
|
|
30810
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30811
|
+
this.query = query;
|
|
30812
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30813
|
+
this.callback = callback.bind(this);
|
|
30814
|
+
this.loadPage({ initial: true });
|
|
30815
|
+
}
|
|
30816
|
+
setup() {
|
|
30817
|
+
var _a;
|
|
30818
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30819
|
+
if (!collection)
|
|
30820
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30821
|
+
}
|
|
30822
|
+
async persistModel(queryPayload) {
|
|
30823
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30824
|
+
}
|
|
30825
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30826
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30827
|
+
}
|
|
30828
|
+
startSubscription() {
|
|
30829
|
+
return this.queryStreamController.subscribeRTE([
|
|
30830
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30831
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30832
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30833
|
+
]);
|
|
30834
|
+
}
|
|
30835
|
+
notifyChange({ origin, loading, error }) {
|
|
30836
|
+
var _a, _b;
|
|
30837
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30838
|
+
if (!collection)
|
|
30839
|
+
return;
|
|
30840
|
+
const data = ((_b = collection.data
|
|
30841
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30842
|
+
.filter(isNonNullable)
|
|
30843
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30844
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30845
|
+
return;
|
|
30846
|
+
this.callback({
|
|
30847
|
+
data,
|
|
30848
|
+
error,
|
|
30849
|
+
loading,
|
|
30850
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30851
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30852
|
+
});
|
|
30853
|
+
}
|
|
30854
|
+
}
|
|
30855
|
+
|
|
30856
|
+
/**
|
|
30857
|
+
* Get my events
|
|
30858
|
+
*
|
|
30859
|
+
* @param params the query parameters
|
|
30860
|
+
* @param callback the callback to be called when the events are updated
|
|
30861
|
+
* @returns events
|
|
30862
|
+
*
|
|
30863
|
+
* @category Event Live Collection
|
|
30864
|
+
*
|
|
30865
|
+
*/
|
|
30866
|
+
const getMyEvents = (params, callback, config) => {
|
|
30867
|
+
const { log, cache } = getActiveClient();
|
|
30868
|
+
if (!cache)
|
|
30869
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30870
|
+
const timestamp = Date.now();
|
|
30871
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
30872
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
30873
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
30874
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
30875
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30876
|
+
return () => {
|
|
30877
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
30878
|
+
disposers.forEach(fn => fn());
|
|
30879
|
+
};
|
|
30880
|
+
};
|
|
30881
|
+
|
|
30377
30882
|
var index = /*#__PURE__*/Object.freeze({
|
|
30378
30883
|
__proto__: null,
|
|
30379
|
-
createEvent: createEvent
|
|
30884
|
+
createEvent: createEvent,
|
|
30885
|
+
updateEvent: updateEvent,
|
|
30886
|
+
deleteEvent: deleteEvent,
|
|
30887
|
+
onEventCreated: onEventCreated,
|
|
30888
|
+
onEventUpdated: onEventUpdated,
|
|
30889
|
+
onEventDeleted: onEventDeleted,
|
|
30890
|
+
getEvent: getEvent,
|
|
30891
|
+
getEvents: getEvents,
|
|
30892
|
+
getMyEvents: getMyEvents
|
|
30380
30893
|
});
|
|
30381
30894
|
|
|
30382
30895
|
exports.API_REGIONS = API_REGIONS;
|