@amityco/ts-sdk 7.11.1-38ad45e1.0 → 7.11.1-4788cb4b.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/permissions.d.ts +5 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -1
- 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 -9
- 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/deleteEvent.d.ts +0 -1
- package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -1
- 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 +3 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -1
- package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
- 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 +2 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
- package/dist/index.cjs.js +372 -10
- package/dist/index.esm.js +373 -11
- 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,13 +13693,33 @@ 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);
|
|
13693
13706
|
},
|
|
13707
|
+
get targetCommunity() {
|
|
13708
|
+
if (!event.originId)
|
|
13709
|
+
return;
|
|
13710
|
+
const cacheData = pullFromCache(['community', 'get', event.originId]);
|
|
13711
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13712
|
+
return;
|
|
13713
|
+
return communityLinkedObject(cacheData.data);
|
|
13714
|
+
},
|
|
13715
|
+
get coverImage() {
|
|
13716
|
+
if (!event.coverImageFileId)
|
|
13717
|
+
return;
|
|
13718
|
+
const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
|
|
13719
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
13720
|
+
return;
|
|
13721
|
+
return cacheData.data;
|
|
13722
|
+
},
|
|
13694
13723
|
get liveStream() {
|
|
13695
13724
|
if (!event.livestreamId)
|
|
13696
13725
|
return;
|
|
@@ -30382,7 +30411,7 @@ const createEvent = async (bundle) => {
|
|
|
30382
30411
|
const client = getActiveClient();
|
|
30383
30412
|
client.log('event/createEvent', bundle);
|
|
30384
30413
|
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
30385
|
-
fireEvent('event.created', payload);
|
|
30414
|
+
fireEvent('local.event.created', payload);
|
|
30386
30415
|
const preparedPayload = prepareEventPayload(payload);
|
|
30387
30416
|
const cachedAt = client.cache && Date.now();
|
|
30388
30417
|
if (client.cache)
|
|
@@ -30416,7 +30445,7 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
30416
30445
|
const client = getActiveClient();
|
|
30417
30446
|
client.log('event/updateEvent', eventId, bundle);
|
|
30418
30447
|
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
30419
|
-
fireEvent('event.updated', payload);
|
|
30448
|
+
fireEvent('local.event.updated', payload);
|
|
30420
30449
|
const preparedPayload = prepareEventPayload(payload);
|
|
30421
30450
|
const cachedAt = client.cache && Date.now();
|
|
30422
30451
|
if (client.cache)
|
|
@@ -30498,7 +30527,6 @@ getEvent$1.locally = (eventId) => {
|
|
|
30498
30527
|
* Deletes a {@link Amity.Event}
|
|
30499
30528
|
*
|
|
30500
30529
|
* @param eventId The {@link Amity.Event} ID to delete
|
|
30501
|
-
* @return A success boolean if the {@link Amity.Event} was deleted
|
|
30502
30530
|
*
|
|
30503
30531
|
* @category Event API
|
|
30504
30532
|
* @async
|
|
@@ -30507,10 +30535,10 @@ const deleteEvent = async (eventId) => {
|
|
|
30507
30535
|
const client = getActiveClient();
|
|
30508
30536
|
client.log('event/deleteEvent', eventId);
|
|
30509
30537
|
const event = await getEvent$1(eventId);
|
|
30510
|
-
|
|
30511
|
-
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted:
|
|
30538
|
+
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
30539
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
30512
30540
|
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
30513
|
-
fireEvent('event.deleted', {
|
|
30541
|
+
fireEvent('local.event.deleted', {
|
|
30514
30542
|
users: [],
|
|
30515
30543
|
files: [],
|
|
30516
30544
|
communities: [],
|
|
@@ -30572,6 +30600,57 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
|
|
|
30572
30600
|
*/
|
|
30573
30601
|
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30574
30602
|
|
|
30603
|
+
/**
|
|
30604
|
+
* ```js
|
|
30605
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30606
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
30607
|
+
* // ...
|
|
30608
|
+
* })
|
|
30609
|
+
* ```
|
|
30610
|
+
*
|
|
30611
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30612
|
+
*
|
|
30613
|
+
* @param callback The function to call when the event was fired
|
|
30614
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30615
|
+
*
|
|
30616
|
+
* @category Event Events
|
|
30617
|
+
*/
|
|
30618
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
30619
|
+
|
|
30620
|
+
/**
|
|
30621
|
+
* ```js
|
|
30622
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30623
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
30624
|
+
* // ...
|
|
30625
|
+
* })
|
|
30626
|
+
* ```
|
|
30627
|
+
*
|
|
30628
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30629
|
+
*
|
|
30630
|
+
* @param callback The function to call when the event was fired
|
|
30631
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30632
|
+
*
|
|
30633
|
+
* @category Event Events
|
|
30634
|
+
*/
|
|
30635
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
30636
|
+
|
|
30637
|
+
/**
|
|
30638
|
+
* ```js
|
|
30639
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30640
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
30641
|
+
* // ...
|
|
30642
|
+
* })
|
|
30643
|
+
* ```
|
|
30644
|
+
*
|
|
30645
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30646
|
+
*
|
|
30647
|
+
* @param callback The function to call when the event was fired
|
|
30648
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30649
|
+
*
|
|
30650
|
+
* @category Event Events
|
|
30651
|
+
*/
|
|
30652
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
30653
|
+
|
|
30575
30654
|
/* begin_public_function
|
|
30576
30655
|
id: event.get
|
|
30577
30656
|
*/
|
|
@@ -30595,12 +30674,290 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
|
|
|
30595
30674
|
* @category Event Live Object
|
|
30596
30675
|
*/
|
|
30597
30676
|
const getEvent = (eventId, callback) => {
|
|
30598
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [
|
|
30677
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
30599
30678
|
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
30600
30679
|
});
|
|
30601
30680
|
};
|
|
30602
30681
|
/* end_public_function */
|
|
30603
30682
|
|
|
30683
|
+
var EventActionsEnum;
|
|
30684
|
+
(function (EventActionsEnum) {
|
|
30685
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
30686
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
30687
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
30688
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
30689
|
+
|
|
30690
|
+
class EventPaginationController extends PaginationController {
|
|
30691
|
+
async getRequest(queryParams, token) {
|
|
30692
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30693
|
+
const options = token ? { token } : { limit };
|
|
30694
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30695
|
+
return response;
|
|
30696
|
+
}
|
|
30697
|
+
}
|
|
30698
|
+
|
|
30699
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
30700
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30701
|
+
super(query, cacheKey);
|
|
30702
|
+
this.notifyChange = notifyChange;
|
|
30703
|
+
this.preparePayload = preparePayload;
|
|
30704
|
+
}
|
|
30705
|
+
async saveToMainDB(response) {
|
|
30706
|
+
const processedPayload = this.preparePayload(response);
|
|
30707
|
+
const client = getActiveClient();
|
|
30708
|
+
const cachedAt = client.cache && Date.now();
|
|
30709
|
+
if (client.cache)
|
|
30710
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30711
|
+
}
|
|
30712
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30713
|
+
var _a, _b;
|
|
30714
|
+
if (refresh) {
|
|
30715
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30716
|
+
}
|
|
30717
|
+
else {
|
|
30718
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30719
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30720
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30721
|
+
}
|
|
30722
|
+
}
|
|
30723
|
+
reactor(action) {
|
|
30724
|
+
return (event) => {
|
|
30725
|
+
var _a;
|
|
30726
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30727
|
+
if (!collection)
|
|
30728
|
+
return;
|
|
30729
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
30730
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30731
|
+
}
|
|
30732
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30733
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30734
|
+
}
|
|
30735
|
+
pushToCache(this.cacheKey, collection);
|
|
30736
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30737
|
+
};
|
|
30738
|
+
}
|
|
30739
|
+
subscribeRTE(createSubscriber) {
|
|
30740
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30741
|
+
}
|
|
30742
|
+
}
|
|
30743
|
+
|
|
30744
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
30745
|
+
constructor(query, callback) {
|
|
30746
|
+
const queryStreamId = hash__default["default"](query);
|
|
30747
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30748
|
+
const paginationController = new EventPaginationController(query);
|
|
30749
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30750
|
+
this.query = query;
|
|
30751
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30752
|
+
this.callback = callback.bind(this);
|
|
30753
|
+
this.loadPage({ initial: true });
|
|
30754
|
+
}
|
|
30755
|
+
setup() {
|
|
30756
|
+
var _a;
|
|
30757
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30758
|
+
if (!collection)
|
|
30759
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30760
|
+
}
|
|
30761
|
+
async persistModel(queryPayload) {
|
|
30762
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30763
|
+
}
|
|
30764
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30765
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30766
|
+
}
|
|
30767
|
+
startSubscription() {
|
|
30768
|
+
return this.queryStreamController.subscribeRTE([
|
|
30769
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30770
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30771
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30772
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30773
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30774
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30775
|
+
]);
|
|
30776
|
+
}
|
|
30777
|
+
notifyChange({ origin, loading, error }) {
|
|
30778
|
+
var _a, _b;
|
|
30779
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30780
|
+
if (!collection)
|
|
30781
|
+
return;
|
|
30782
|
+
const data = ((_b = collection.data
|
|
30783
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30784
|
+
.filter(isNonNullable)
|
|
30785
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30786
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30787
|
+
return;
|
|
30788
|
+
this.callback({
|
|
30789
|
+
data,
|
|
30790
|
+
error,
|
|
30791
|
+
loading,
|
|
30792
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30793
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30794
|
+
});
|
|
30795
|
+
}
|
|
30796
|
+
}
|
|
30797
|
+
|
|
30798
|
+
/**
|
|
30799
|
+
* Get events
|
|
30800
|
+
*
|
|
30801
|
+
* @param params the query parameters
|
|
30802
|
+
* @param callback the callback to be called when the events are updated
|
|
30803
|
+
* @returns events
|
|
30804
|
+
*
|
|
30805
|
+
* @category Event Live Collection
|
|
30806
|
+
*
|
|
30807
|
+
*/
|
|
30808
|
+
const getEvents = (params, callback, config) => {
|
|
30809
|
+
const { log, cache } = getActiveClient();
|
|
30810
|
+
if (!cache)
|
|
30811
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30812
|
+
const timestamp = Date.now();
|
|
30813
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
30814
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
30815
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
30816
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
30817
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30818
|
+
return () => {
|
|
30819
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
30820
|
+
disposers.forEach(fn => fn());
|
|
30821
|
+
};
|
|
30822
|
+
};
|
|
30823
|
+
|
|
30824
|
+
class MyEventPaginationController extends PaginationController {
|
|
30825
|
+
async getRequest(queryParams, token) {
|
|
30826
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
30827
|
+
const options = token ? { token } : { limit };
|
|
30828
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30829
|
+
return response;
|
|
30830
|
+
}
|
|
30831
|
+
}
|
|
30832
|
+
|
|
30833
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
30834
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30835
|
+
super(query, cacheKey);
|
|
30836
|
+
this.notifyChange = notifyChange;
|
|
30837
|
+
this.preparePayload = preparePayload;
|
|
30838
|
+
}
|
|
30839
|
+
async saveToMainDB(response) {
|
|
30840
|
+
const processedPayload = this.preparePayload(response);
|
|
30841
|
+
const client = getActiveClient();
|
|
30842
|
+
const cachedAt = client.cache && Date.now();
|
|
30843
|
+
if (client.cache)
|
|
30844
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30845
|
+
}
|
|
30846
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30847
|
+
var _a, _b;
|
|
30848
|
+
if (refresh) {
|
|
30849
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
30850
|
+
}
|
|
30851
|
+
else {
|
|
30852
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30853
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30854
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
30855
|
+
}
|
|
30856
|
+
}
|
|
30857
|
+
reactor(action) {
|
|
30858
|
+
return (event) => {
|
|
30859
|
+
var _a;
|
|
30860
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30861
|
+
if (!collection)
|
|
30862
|
+
return;
|
|
30863
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
30864
|
+
const client = getActiveClient();
|
|
30865
|
+
if (client.userId !== event.userId)
|
|
30866
|
+
return;
|
|
30867
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30868
|
+
}
|
|
30869
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30870
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30871
|
+
}
|
|
30872
|
+
pushToCache(this.cacheKey, collection);
|
|
30873
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30874
|
+
};
|
|
30875
|
+
}
|
|
30876
|
+
subscribeRTE(createSubscriber) {
|
|
30877
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30878
|
+
}
|
|
30879
|
+
}
|
|
30880
|
+
|
|
30881
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
30882
|
+
constructor(query, callback) {
|
|
30883
|
+
const queryStreamId = hash__default["default"](query);
|
|
30884
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
30885
|
+
const paginationController = new MyEventPaginationController(query);
|
|
30886
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30887
|
+
this.query = query;
|
|
30888
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
30889
|
+
this.callback = callback.bind(this);
|
|
30890
|
+
this.loadPage({ initial: true });
|
|
30891
|
+
}
|
|
30892
|
+
setup() {
|
|
30893
|
+
var _a;
|
|
30894
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30895
|
+
if (!collection)
|
|
30896
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30897
|
+
}
|
|
30898
|
+
async persistModel(queryPayload) {
|
|
30899
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30900
|
+
}
|
|
30901
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30902
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30903
|
+
}
|
|
30904
|
+
startSubscription() {
|
|
30905
|
+
return this.queryStreamController.subscribeRTE([
|
|
30906
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30907
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30908
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30909
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
30910
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
30911
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
30912
|
+
]);
|
|
30913
|
+
}
|
|
30914
|
+
notifyChange({ origin, loading, error }) {
|
|
30915
|
+
var _a, _b;
|
|
30916
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30917
|
+
if (!collection)
|
|
30918
|
+
return;
|
|
30919
|
+
const data = ((_b = collection.data
|
|
30920
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
30921
|
+
.filter(isNonNullable)
|
|
30922
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
30923
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30924
|
+
return;
|
|
30925
|
+
this.callback({
|
|
30926
|
+
data,
|
|
30927
|
+
error,
|
|
30928
|
+
loading,
|
|
30929
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30930
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30931
|
+
});
|
|
30932
|
+
}
|
|
30933
|
+
}
|
|
30934
|
+
|
|
30935
|
+
/**
|
|
30936
|
+
* Get my events
|
|
30937
|
+
*
|
|
30938
|
+
* @param params the query parameters
|
|
30939
|
+
* @param callback the callback to be called when the events are updated
|
|
30940
|
+
* @returns events
|
|
30941
|
+
*
|
|
30942
|
+
* @category Event Live Collection
|
|
30943
|
+
*
|
|
30944
|
+
*/
|
|
30945
|
+
const getMyEvents = (params, callback, config) => {
|
|
30946
|
+
const { log, cache } = getActiveClient();
|
|
30947
|
+
if (!cache)
|
|
30948
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30949
|
+
const timestamp = Date.now();
|
|
30950
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
30951
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
30952
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
30953
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
30954
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30955
|
+
return () => {
|
|
30956
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
30957
|
+
disposers.forEach(fn => fn());
|
|
30958
|
+
};
|
|
30959
|
+
};
|
|
30960
|
+
|
|
30604
30961
|
var index = /*#__PURE__*/Object.freeze({
|
|
30605
30962
|
__proto__: null,
|
|
30606
30963
|
createEvent: createEvent,
|
|
@@ -30609,7 +30966,12 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
30609
30966
|
onEventCreated: onEventCreated,
|
|
30610
30967
|
onEventUpdated: onEventUpdated,
|
|
30611
30968
|
onEventDeleted: onEventDeleted,
|
|
30612
|
-
|
|
30969
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
30970
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
30971
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
30972
|
+
getEvent: getEvent,
|
|
30973
|
+
getEvents: getEvents,
|
|
30974
|
+
getMyEvents: getMyEvents
|
|
30613
30975
|
});
|
|
30614
30976
|
|
|
30615
30977
|
exports.API_REGIONS = API_REGIONS;
|