@juzi/wechaty 1.0.83 → 1.0.85
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/cjs/src/package-json.d.ts.map +1 -1
- package/dist/cjs/src/package-json.js +5 -4
- package/dist/cjs/src/package-json.js.map +1 -1
- package/dist/cjs/src/pure-functions/retry-policy.d.ts +2 -1
- package/dist/cjs/src/pure-functions/retry-policy.d.ts.map +1 -1
- package/dist/cjs/src/pure-functions/retry-policy.js +12 -1
- package/dist/cjs/src/pure-functions/retry-policy.js.map +1 -1
- package/dist/cjs/src/schemas/contact-events.d.ts +1 -4
- package/dist/cjs/src/schemas/contact-events.d.ts.map +1 -1
- package/dist/cjs/src/schemas/contact-events.js.map +1 -1
- package/dist/cjs/src/schemas/room-events.d.ts +1 -5
- package/dist/cjs/src/schemas/room-events.d.ts.map +1 -1
- package/dist/cjs/src/schemas/room-events.js +0 -1
- package/dist/cjs/src/schemas/room-events.js.map +1 -1
- package/dist/cjs/src/schemas/wechaty-events.d.ts +1 -5
- package/dist/cjs/src/schemas/wechaty-events.d.ts.map +1 -1
- package/dist/cjs/src/schemas/wechaty-events.js +0 -1
- package/dist/cjs/src/schemas/wechaty-events.js.map +1 -1
- package/dist/cjs/src/user-modules/room.d.ts +1 -0
- package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/room.js +7 -0
- package/dist/cjs/src/user-modules/room.js.map +1 -1
- package/dist/cjs/src/wechaty/wechaty-base.d.ts +7 -7
- package/dist/cjs/src/wechaty/wechaty-base.spec.js +3 -3
- package/dist/cjs/src/wechaty/wechaty-base.spec.js.map +1 -1
- package/dist/cjs/src/wechaty-mixins/gerror-mixin.d.ts +1 -1
- package/dist/cjs/src/wechaty-mixins/io-mixin.d.ts +2 -2
- package/dist/cjs/src/wechaty-mixins/login-mixin.d.ts +5 -5
- package/dist/cjs/src/wechaty-mixins/misc-mixin.d.ts +5 -5
- package/dist/cjs/src/wechaty-mixins/plugin-mixin.d.ts +6 -6
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts +4 -4
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js +13 -103
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/dist/cjs/src/wechaty-mixins/wechatify-user-module-mixin.d.ts +1 -1
- package/dist/esm/src/package-json.d.ts.map +1 -1
- package/dist/esm/src/package-json.js +5 -4
- package/dist/esm/src/package-json.js.map +1 -1
- package/dist/esm/src/pure-functions/retry-policy.d.ts +2 -1
- package/dist/esm/src/pure-functions/retry-policy.d.ts.map +1 -1
- package/dist/esm/src/pure-functions/retry-policy.js +11 -1
- package/dist/esm/src/pure-functions/retry-policy.js.map +1 -1
- package/dist/esm/src/schemas/contact-events.d.ts +1 -4
- package/dist/esm/src/schemas/contact-events.d.ts.map +1 -1
- package/dist/esm/src/schemas/contact-events.js.map +1 -1
- package/dist/esm/src/schemas/room-events.d.ts +1 -5
- package/dist/esm/src/schemas/room-events.d.ts.map +1 -1
- package/dist/esm/src/schemas/room-events.js +0 -1
- package/dist/esm/src/schemas/room-events.js.map +1 -1
- package/dist/esm/src/schemas/wechaty-events.d.ts +1 -5
- package/dist/esm/src/schemas/wechaty-events.d.ts.map +1 -1
- package/dist/esm/src/schemas/wechaty-events.js +0 -1
- package/dist/esm/src/schemas/wechaty-events.js.map +1 -1
- package/dist/esm/src/user-modules/room.d.ts +1 -0
- package/dist/esm/src/user-modules/room.d.ts.map +1 -1
- package/dist/esm/src/user-modules/room.js +7 -0
- package/dist/esm/src/user-modules/room.js.map +1 -1
- package/dist/esm/src/wechaty/wechaty-base.d.ts +7 -7
- package/dist/esm/src/wechaty/wechaty-base.spec.js +3 -3
- package/dist/esm/src/wechaty/wechaty-base.spec.js.map +1 -1
- package/dist/esm/src/wechaty-mixins/gerror-mixin.d.ts +1 -1
- package/dist/esm/src/wechaty-mixins/io-mixin.d.ts +2 -2
- package/dist/esm/src/wechaty-mixins/login-mixin.d.ts +5 -5
- package/dist/esm/src/wechaty-mixins/misc-mixin.d.ts +5 -5
- package/dist/esm/src/wechaty-mixins/plugin-mixin.d.ts +6 -6
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts +4 -4
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js +11 -101
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/dist/esm/src/wechaty-mixins/wechatify-user-module-mixin.d.ts +1 -1
- package/package.json +4 -3
- package/src/package-json.ts +5 -4
- package/src/pure-functions/retry-policy.ts +12 -0
- package/src/schemas/contact-events.ts +0 -4
- package/src/schemas/room-events.ts +0 -5
- package/src/schemas/wechaty-events.ts +0 -5
- package/src/user-modules/room.ts +10 -0
- package/src/wechaty/wechaty-base.spec.ts +3 -3
- package/src/wechaty-mixins/puppet-mixin.ts +11 -106
- package/dist/cjs/src/pure-functions/update.d.ts +0 -10
- package/dist/cjs/src/pure-functions/update.d.ts.map +0 -1
- package/dist/cjs/src/pure-functions/update.js +0 -85
- package/dist/cjs/src/pure-functions/update.js.map +0 -1
- package/dist/cjs/src/schemas/update.d.ts +0 -31
- package/dist/cjs/src/schemas/update.d.ts.map +0 -1
- package/dist/cjs/src/schemas/update.js +0 -35
- package/dist/cjs/src/schemas/update.js.map +0 -1
- package/dist/esm/src/pure-functions/update.d.ts +0 -10
- package/dist/esm/src/pure-functions/update.d.ts.map +0 -1
- package/dist/esm/src/pure-functions/update.js +0 -80
- package/dist/esm/src/pure-functions/update.js.map +0 -1
- package/dist/esm/src/schemas/update.d.ts +0 -31
- package/dist/esm/src/schemas/update.d.ts.map +0 -1
- package/dist/esm/src/schemas/update.js +0 -9
- package/dist/esm/src/schemas/update.js.map +0 -1
- package/src/pure-functions/update.ts +0 -80
- package/src/schemas/update.ts +0 -43
|
@@ -28,8 +28,7 @@ import type {
|
|
|
28
28
|
|
|
29
29
|
import type { GErrorMixin } from './gerror-mixin.js'
|
|
30
30
|
import type { IoMixin } from './io-mixin.js'
|
|
31
|
-
import {
|
|
32
|
-
import { checkUntilChanged, diffPayload } from '../pure-functions/update.js'
|
|
31
|
+
import { checkUntilChanged } from '../pure-functions/retry-policy.js'
|
|
33
32
|
|
|
34
33
|
const PUPPET_MEMORY_NAME = 'puppet'
|
|
35
34
|
|
|
@@ -260,6 +259,16 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
260
259
|
throw new Error('no contact found for id: ' + payload.contactId)
|
|
261
260
|
}
|
|
262
261
|
this.emit('login', contact)
|
|
262
|
+
const readyTimeout = setTimeout(() => {
|
|
263
|
+
if (this.puppet.readyIndicator.value()) {
|
|
264
|
+
this.emit('ready')
|
|
265
|
+
}
|
|
266
|
+
}, 15 * 1000)
|
|
267
|
+
puppet.once('ready', () => {
|
|
268
|
+
// if we got ready from puppet, we don't have to fire it here.
|
|
269
|
+
// it will be fired by ready listener
|
|
270
|
+
clearTimeout(readyTimeout)
|
|
271
|
+
})
|
|
263
272
|
} catch (e) {
|
|
264
273
|
this.emit('error', GError.from(e))
|
|
265
274
|
}
|
|
@@ -642,116 +651,12 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
642
651
|
switch (payloadType) {
|
|
643
652
|
case PUPPET.types.Payload.Contact: {
|
|
644
653
|
const contact = await this.Contact.find({ id: payloadId }) as unknown as undefined | ContactImpl
|
|
645
|
-
const oldPayload = JSON.parse(JSON.stringify(contact?.payload || {}))
|
|
646
654
|
await contact?.ready(true)
|
|
647
|
-
const newPayload = JSON.parse(JSON.stringify(contact?.payload || {}))
|
|
648
|
-
|
|
649
|
-
const differences = diffPayload<PUPPET.payloads.Contact>(oldPayload, newPayload)
|
|
650
|
-
if (differences.length === 0) {
|
|
651
|
-
log.info('WechatyPuppetMixin', `got dirty for contact ${payloadId} but cannot find any difference. old payload: ${JSON.stringify(oldPayload)}, new payload: ${JSON.stringify(newPayload)}`)
|
|
652
|
-
break
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
const importantDifferences = differences.filter(ele => ele && ContactImportantFields.some(key => key === ele.key))
|
|
656
|
-
const regularDifferences = differences.filter(ele => ele && !ContactImportantFields.some(key => key === ele.key)) as ContactUpdatableValuePair[]
|
|
657
|
-
if (regularDifferences.length > 0) {
|
|
658
|
-
const updateEvent: InfoUpdateInterface = {
|
|
659
|
-
type: payloadType,
|
|
660
|
-
id: payloadId,
|
|
661
|
-
updates: regularDifferences,
|
|
662
|
-
}
|
|
663
|
-
this.emit('update', updateEvent)
|
|
664
|
-
contact?.emit('update', updateEvent)
|
|
665
|
-
}
|
|
666
|
-
for (const difference of importantDifferences) {
|
|
667
|
-
switch (difference?.key) {
|
|
668
|
-
case 'tags': {
|
|
669
|
-
const oldTagsSet = new Set(difference.oldValue)
|
|
670
|
-
const newTagsSet = new Set(difference.newValue)
|
|
671
|
-
const addedTagPromises = difference.newValue?.filter(ele => !oldTagsSet.has(ele)).map(ele => this.Tag.find({ id: ele })) || []
|
|
672
|
-
const removedTagPromises = difference.oldValue?.filter(ele => !newTagsSet.has(ele)).map(ele => this.Tag.find({ id: ele })) || []
|
|
673
|
-
if (addedTagPromises.length > 0) {
|
|
674
|
-
const addedTags = await Promise.all(addedTagPromises)
|
|
675
|
-
this.emit('contact-tag-add', contact, addedTags)
|
|
676
|
-
}
|
|
677
|
-
if (removedTagPromises.length > 0) {
|
|
678
|
-
const removedTags = await Promise.all(removedTagPromises)
|
|
679
|
-
this.emit('contact-tag-remove', contact, removedTags)
|
|
680
|
-
}
|
|
681
|
-
break
|
|
682
|
-
}
|
|
683
|
-
case 'name': {
|
|
684
|
-
this.emit('contact-name', contact, difference.newValue || '', difference.oldValue || '')
|
|
685
|
-
contact?.emit('name', difference.newValue || '', difference.oldValue || '')
|
|
686
|
-
break
|
|
687
|
-
}
|
|
688
|
-
case 'alias': {
|
|
689
|
-
this.emit('contact-alias', contact, difference.newValue || '', difference.oldValue || '')
|
|
690
|
-
contact?.emit('alias', difference.newValue || '', difference.oldValue || '')
|
|
691
|
-
break
|
|
692
|
-
}
|
|
693
|
-
case 'phone': {
|
|
694
|
-
this.emit('contact-phone', contact, difference.newValue || [], difference.oldValue || [])
|
|
695
|
-
contact?.emit('phone', difference.newValue || [], difference.oldValue || [])
|
|
696
|
-
break
|
|
697
|
-
}
|
|
698
|
-
case 'description': {
|
|
699
|
-
this.emit('contact-description', contact, difference.newValue || '', difference.oldValue || '')
|
|
700
|
-
contact?.emit('description', difference.newValue || '', difference.oldValue || '')
|
|
701
|
-
break
|
|
702
|
-
}
|
|
703
|
-
case 'corporation': {
|
|
704
|
-
this.emit('contact-corporation', contact, difference.newValue || '', difference.oldValue || '')
|
|
705
|
-
contact?.emit('corporation', difference.newValue || '', difference.oldValue || '')
|
|
706
|
-
break
|
|
707
|
-
}
|
|
708
|
-
default:
|
|
709
|
-
log.warn('WechatyPuppetMixin', 'puppet dirty unsupported difference type: %s', JSON.stringify(difference))
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
655
|
break
|
|
713
656
|
}
|
|
714
657
|
case PUPPET.types.Payload.Room: {
|
|
715
658
|
const room = await this.Room.find({ id: payloadId }) as unknown as undefined | RoomImpl
|
|
716
|
-
const oldPayload = JSON.parse(JSON.stringify(room?.payload || {}))
|
|
717
659
|
await room?.ready(true)
|
|
718
|
-
const newPayload = JSON.parse(JSON.stringify(room?.payload || {}))
|
|
719
|
-
|
|
720
|
-
const differences = diffPayload<PUPPET.payloads.Room>(oldPayload, newPayload)
|
|
721
|
-
|
|
722
|
-
if (differences.length === 0) {
|
|
723
|
-
log.info('WechatyPuppetMixin', `got dirty for room ${payloadId} but cannot find any difference. old payload: ${JSON.stringify(oldPayload)}, new payload: ${JSON.stringify(newPayload)}`)
|
|
724
|
-
break
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
const importantDifferences = differences.filter(ele => ele && RoomImportantFields.some(key => key === ele.key))
|
|
728
|
-
const regularDifferences = differences.filter(ele => ele && !RoomImportantFields.some(key => key === ele.key)) as RoomUpdatableValuePair[]
|
|
729
|
-
if (regularDifferences.length > 0) {
|
|
730
|
-
const updateEvent: InfoUpdateInterface = {
|
|
731
|
-
type: payloadType,
|
|
732
|
-
id: payloadId,
|
|
733
|
-
updates: regularDifferences,
|
|
734
|
-
}
|
|
735
|
-
this.emit('update', updateEvent)
|
|
736
|
-
room?.emit('update', updateEvent)
|
|
737
|
-
}
|
|
738
|
-
for (const difference of importantDifferences) {
|
|
739
|
-
switch (difference?.key) {
|
|
740
|
-
case 'ownerId': {
|
|
741
|
-
const oldOwner = (await this.Contact.find({ id: difference.oldValue }))!
|
|
742
|
-
const newOwner = (await this.Contact.find({ id: difference.newValue }))!
|
|
743
|
-
this.emit('room-owner', room, newOwner, oldOwner)
|
|
744
|
-
room?.emit('owner', newOwner, oldOwner)
|
|
745
|
-
break
|
|
746
|
-
}
|
|
747
|
-
case 'memberIdList':
|
|
748
|
-
break // this diff has been handled by room-join and room-leave events
|
|
749
|
-
case 'topic':
|
|
750
|
-
break // this diff has been handled by room-topic event
|
|
751
|
-
default:
|
|
752
|
-
log.warn('WechatyPuppetMixin', 'puppet dirty unsupported difference type: %s', JSON.stringify(difference))
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
660
|
break
|
|
756
661
|
}
|
|
757
662
|
case PUPPET.types.Payload.RoomMember: {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { InfoUpdateValuePair } from '../schemas/update';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* No need to go recursive on payload diff becasue
|
|
5
|
-
* 1. most fields of payloads are primitive values
|
|
6
|
-
* 2. users does not want to compare array items, they just need to know this field has changed. And we don't offer methods to get a subObject value
|
|
7
|
-
*/
|
|
8
|
-
export declare const diffPayload: <T>(objectOld: any, objectNew: any) => InfoUpdateValuePair<T>[];
|
|
9
|
-
export declare const checkUntilChanged: (gapMilliseconds: number, maxRetry: number, judgement: () => Promise<boolean> | boolean) => Promise<boolean>;
|
|
10
|
-
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/pure-functions/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,iBAAkB,GAAG,aAAa,GAAG,6BAyC5D,CAAA;AAqBD,eAAO,MAAM,iBAAiB,oBAA2B,MAAM,YAAY,MAAM,aAAa,MAAM,QAAQ,OAAO,CAAC,GAAG,OAAO,KAAG,QAAQ,OAAO,CAS/I,CAAA"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkUntilChanged = exports.diffPayload = void 0;
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* No need to go recursive on payload diff becasue
|
|
7
|
-
* 1. most fields of payloads are primitive values
|
|
8
|
-
* 2. users does not want to compare array items, they just need to know this field has changed. And we don't offer methods to get a subObject value
|
|
9
|
-
*/
|
|
10
|
-
const diffPayload = (objectOld, objectNew) => {
|
|
11
|
-
const keys = new Set([...Object.keys(objectOld || {}), ...Object.keys(objectNew || {})]);
|
|
12
|
-
const result = [];
|
|
13
|
-
for (const item of keys) {
|
|
14
|
-
const key = item;
|
|
15
|
-
const subObjectOld = objectOld[key];
|
|
16
|
-
const subObjectNew = objectNew[key];
|
|
17
|
-
if (typeof subObjectOld !== typeof subObjectNew) {
|
|
18
|
-
result.push({
|
|
19
|
-
key,
|
|
20
|
-
oldValue: subObjectOld,
|
|
21
|
-
newValue: subObjectNew,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
if (typeof subObjectOld !== 'object') {
|
|
26
|
-
if (subObjectOld === subObjectNew) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
result.push({
|
|
31
|
-
key,
|
|
32
|
-
oldValue: subObjectOld,
|
|
33
|
-
newValue: subObjectNew,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
// for objects, we just judge if they were same or not, but do not record every different value
|
|
39
|
-
if (objectDeepDiff(subObjectOld, subObjectNew)) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
result.push({
|
|
44
|
-
key,
|
|
45
|
-
oldValue: subObjectOld,
|
|
46
|
-
newValue: subObjectNew,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
};
|
|
54
|
-
exports.diffPayload = diffPayload;
|
|
55
|
-
const objectDeepDiff = (objectA, objectB) => {
|
|
56
|
-
const keys = new Set([...Object.keys(objectA), ...Object.keys(objectB)]);
|
|
57
|
-
for (const key of keys) {
|
|
58
|
-
if (typeof objectA[key] !== typeof objectB[key]) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
if (typeof objectA[key] !== 'object') {
|
|
62
|
-
if (objectA[key] !== objectB[key]) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
if (!objectDeepDiff(objectA[key], objectB[key])) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
73
|
-
};
|
|
74
|
-
const checkUntilChanged = async (gapMilliseconds, maxRetry, judgement) => {
|
|
75
|
-
let changed = await judgement();
|
|
76
|
-
let currentTry = 1;
|
|
77
|
-
while (!changed && (currentTry < maxRetry)) {
|
|
78
|
-
await new Promise(resolve => setTimeout(resolve, gapMilliseconds));
|
|
79
|
-
changed = await judgement();
|
|
80
|
-
currentTry++;
|
|
81
|
-
}
|
|
82
|
-
return changed;
|
|
83
|
-
};
|
|
84
|
-
exports.checkUntilChanged = checkUntilChanged;
|
|
85
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/pure-functions/update.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAI,SAAc,EAAE,SAAc,EAA4B,EAAE;IACzF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAE,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAE,CAAC,CAAA;IAC1F,MAAM,MAAM,GAAG,EAAE,CAAA;IACjB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACvB,MAAM,GAAG,GAAG,IAAe,CAAA;QAC3B,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAkB,CAAA;QACpD,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAkB,CAAA;QAEpD,IAAI,OAAO,YAAY,KAAK,OAAO,YAAY,EAAE;YAC/C,MAAM,CAAC,IAAI,CAAC;gBACV,GAAG;gBACH,QAAQ,EAAE,YAAY;gBACtB,QAAQ,EAAE,YAAY;aACvB,CAAC,CAAA;SACH;aAAM;YACL,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;gBACpC,IAAI,YAAY,KAAK,YAAY,EAAE;oBACjC,SAAQ;iBACT;qBAAM;oBACL,MAAM,CAAC,IAAI,CAAC;wBACV,GAAG;wBACH,QAAQ,EAAE,YAAY;wBACtB,QAAQ,EAAE,YAAY;qBACvB,CAAC,CAAA;iBACH;aACF;iBAAM;gBACL,+FAA+F;gBAC/F,IAAI,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,E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,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAA;QAClE,OAAO,GAAG,MAAM,SAAS,EAAE,CAAA;QAC3B,UAAU,EAAE,CAAA;KACb;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AATY,QAAA,iBAAiB,qBAS7B"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as PUPPET from '@juzi/wechaty-puppet';
|
|
2
|
-
export declare const ContactImportantFields: readonly ["name", "tags", "alias", "phone", "description", "corporation"];
|
|
3
|
-
export declare const RoomImportantFields: readonly ["topic", "memberIdList", "ownerId"];
|
|
4
|
-
declare type ContactImportantKeys = typeof ContactImportantFields[number];
|
|
5
|
-
declare type RoomImportantKeys = typeof RoomImportantFields[number];
|
|
6
|
-
declare type ContactUpdatableKeys = Omit<PUPPET.payloads.Contact, ContactImportantKeys>;
|
|
7
|
-
declare type RoomUpdateableKeys = Omit<PUPPET.payloads.Room, RoomImportantKeys>;
|
|
8
|
-
declare type PayloadTypeToUpdateInterface<U> = {
|
|
9
|
-
[SubType in keyof U]: {
|
|
10
|
-
type: SubType;
|
|
11
|
-
id: string;
|
|
12
|
-
updates: InfoUpdateValuePair<U[SubType]>[];
|
|
13
|
-
};
|
|
14
|
-
}[keyof U];
|
|
15
|
-
export declare type InfoUpdateValuePair<U> = {
|
|
16
|
-
[SubType in keyof U]: {
|
|
17
|
-
key: SubType;
|
|
18
|
-
oldValue?: U[SubType];
|
|
19
|
-
newValue?: U[SubType];
|
|
20
|
-
};
|
|
21
|
-
}[keyof U];
|
|
22
|
-
export declare type InfoUpdateInterface = PayloadTypeToUpdateInterface<{
|
|
23
|
-
[PUPPET.types.Payload.Contact]: ContactUpdatableKeys;
|
|
24
|
-
[PUPPET.types.Payload.Room]: RoomUpdateableKeys;
|
|
25
|
-
}>;
|
|
26
|
-
export declare type ContactUpdatableValuePair = InfoUpdateValuePair<ContactUpdatableKeys>;
|
|
27
|
-
export declare type RoomUpdatableValuePair = InfoUpdateValuePair<RoomUpdateableKeys>;
|
|
28
|
-
export declare type ContactValuePair = InfoUpdateValuePair<PUPPET.payloads.Contact>;
|
|
29
|
-
export declare type RoomValuePair = InfoUpdateValuePair<PUPPET.payloads.Room>;
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/schemas/update.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C,eAAO,MAAM,sBAAsB,2EAEzB,CAAA;AAEV,eAAO,MAAM,mBAAmB,+CAEtB,CAAA;AAEV,aAAK,oBAAoB,GAAG,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAA;AACjE,aAAK,iBAAiB,GAAG,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAA;AAE3D,aAAK,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA;AAC/E,aAAK,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AAEvE,aAAK,4BAA4B,CAAC,CAAC,IAAI;KACpC,OAAO,IAAI,MAAM,CAAC,GAAG;QACpB,IAAI,EAAE,OAAO,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;KAC5C;CACF,CAAC,MAAM,CAAC,CAAC,CAAA;AAEV,oBAAY,mBAAmB,CAAC,CAAC,IAAI;KAClC,OAAO,IAAI,MAAM,CAAC,GAAG;QACpB,GAAG,EAAE,OAAO,CAAC;QACb,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QACtB,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;KACvB;CACF,CAAC,MAAM,CAAC,CAAC,CAAA;AAEV,oBAAY,mBAAmB,GAAG,4BAA4B,CAAC;IAC7D,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IACrD,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC;CACjD,CAAC,CAAA;AAEF,oBAAY,yBAAyB,GAAG,mBAAmB,CAAC,oBAAoB,CAAC,CAAA;AACjF,oBAAY,sBAAsB,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAA;AAE5E,oBAAY,gBAAgB,GAAG,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AAC3E,oBAAY,aAAa,GAAG,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.RoomImportantFields = exports.ContactImportantFields = void 0;
|
|
27
|
-
/* eslint-disable valid-typeof */
|
|
28
|
-
const PUPPET = __importStar(require("@juzi/wechaty-puppet"));
|
|
29
|
-
exports.ContactImportantFields = [
|
|
30
|
-
'name', 'tags', 'alias', 'phone', 'description', 'corporation',
|
|
31
|
-
];
|
|
32
|
-
exports.RoomImportantFields = [
|
|
33
|
-
'topic', 'memberIdList', 'ownerId',
|
|
34
|
-
];
|
|
35
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/schemas/update.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,6DAA8C;AAEjC,QAAA,sBAAsB,GAAG;IACpC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa;CACtD,CAAA;AAEG,QAAA,mBAAmB,GAAG;IACjC,OAAO,EAAE,cAAc,EAAE,SAAS;CAC1B,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { InfoUpdateValuePair } from '../schemas/update';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* No need to go recursive on payload diff becasue
|
|
5
|
-
* 1. most fields of payloads are primitive values
|
|
6
|
-
* 2. users does not want to compare array items, they just need to know this field has changed. And we don't offer methods to get a subObject value
|
|
7
|
-
*/
|
|
8
|
-
export declare const diffPayload: <T>(objectOld: any, objectNew: any) => InfoUpdateValuePair<T>[];
|
|
9
|
-
export declare const checkUntilChanged: (gapMilliseconds: number, maxRetry: number, judgement: () => Promise<boolean> | boolean) => Promise<boolean>;
|
|
10
|
-
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/pure-functions/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,iBAAkB,GAAG,aAAa,GAAG,6BAyC5D,CAAA;AAqBD,eAAO,MAAM,iBAAiB,oBAA2B,MAAM,YAAY,MAAM,aAAa,MAAM,QAAQ,OAAO,CAAC,GAAG,OAAO,KAAG,QAAQ,OAAO,CAS/I,CAAA"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* No need to go recursive on payload diff becasue
|
|
4
|
-
* 1. most fields of payloads are primitive values
|
|
5
|
-
* 2. users does not want to compare array items, they just need to know this field has changed. And we don't offer methods to get a subObject value
|
|
6
|
-
*/
|
|
7
|
-
export const diffPayload = (objectOld, objectNew) => {
|
|
8
|
-
const keys = new Set([...Object.keys(objectOld || {}), ...Object.keys(objectNew || {})]);
|
|
9
|
-
const result = [];
|
|
10
|
-
for (const item of keys) {
|
|
11
|
-
const key = item;
|
|
12
|
-
const subObjectOld = objectOld[key];
|
|
13
|
-
const subObjectNew = objectNew[key];
|
|
14
|
-
if (typeof subObjectOld !== typeof subObjectNew) {
|
|
15
|
-
result.push({
|
|
16
|
-
key,
|
|
17
|
-
oldValue: subObjectOld,
|
|
18
|
-
newValue: subObjectNew,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
if (typeof subObjectOld !== 'object') {
|
|
23
|
-
if (subObjectOld === subObjectNew) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
result.push({
|
|
28
|
-
key,
|
|
29
|
-
oldValue: subObjectOld,
|
|
30
|
-
newValue: subObjectNew,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
// for objects, we just judge if they were same or not, but do not record every different value
|
|
36
|
-
if (objectDeepDiff(subObjectOld, subObjectNew)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
result.push({
|
|
41
|
-
key,
|
|
42
|
-
oldValue: subObjectOld,
|
|
43
|
-
newValue: subObjectNew,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
const objectDeepDiff = (objectA, objectB) => {
|
|
52
|
-
const keys = new Set([...Object.keys(objectA), ...Object.keys(objectB)]);
|
|
53
|
-
for (const key of keys) {
|
|
54
|
-
if (typeof objectA[key] !== typeof objectB[key]) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
if (typeof objectA[key] !== 'object') {
|
|
58
|
-
if (objectA[key] !== objectB[key]) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
if (!objectDeepDiff(objectA[key], objectB[key])) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
};
|
|
70
|
-
export const checkUntilChanged = async (gapMilliseconds, maxRetry, judgement) => {
|
|
71
|
-
let changed = await judgement();
|
|
72
|
-
let currentTry = 1;
|
|
73
|
-
while (!changed && (currentTry < maxRetry)) {
|
|
74
|
-
await new Promise(resolve => setTimeout(resolve, gapMilliseconds));
|
|
75
|
-
changed = await judgement();
|
|
76
|
-
currentTry++;
|
|
77
|
-
}
|
|
78
|
-
return changed;
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
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 @@
|
|
|
1
|
-
import * as PUPPET from '@juzi/wechaty-puppet';
|
|
2
|
-
export declare const ContactImportantFields: readonly ["name", "tags", "alias", "phone", "description", "corporation"];
|
|
3
|
-
export declare const RoomImportantFields: readonly ["topic", "memberIdList", "ownerId"];
|
|
4
|
-
declare type ContactImportantKeys = typeof ContactImportantFields[number];
|
|
5
|
-
declare type RoomImportantKeys = typeof RoomImportantFields[number];
|
|
6
|
-
declare type ContactUpdatableKeys = Omit<PUPPET.payloads.Contact, ContactImportantKeys>;
|
|
7
|
-
declare type RoomUpdateableKeys = Omit<PUPPET.payloads.Room, RoomImportantKeys>;
|
|
8
|
-
declare type PayloadTypeToUpdateInterface<U> = {
|
|
9
|
-
[SubType in keyof U]: {
|
|
10
|
-
type: SubType;
|
|
11
|
-
id: string;
|
|
12
|
-
updates: InfoUpdateValuePair<U[SubType]>[];
|
|
13
|
-
};
|
|
14
|
-
}[keyof U];
|
|
15
|
-
export declare type InfoUpdateValuePair<U> = {
|
|
16
|
-
[SubType in keyof U]: {
|
|
17
|
-
key: SubType;
|
|
18
|
-
oldValue?: U[SubType];
|
|
19
|
-
newValue?: U[SubType];
|
|
20
|
-
};
|
|
21
|
-
}[keyof U];
|
|
22
|
-
export declare type InfoUpdateInterface = PayloadTypeToUpdateInterface<{
|
|
23
|
-
[PUPPET.types.Payload.Contact]: ContactUpdatableKeys;
|
|
24
|
-
[PUPPET.types.Payload.Room]: RoomUpdateableKeys;
|
|
25
|
-
}>;
|
|
26
|
-
export declare type ContactUpdatableValuePair = InfoUpdateValuePair<ContactUpdatableKeys>;
|
|
27
|
-
export declare type RoomUpdatableValuePair = InfoUpdateValuePair<RoomUpdateableKeys>;
|
|
28
|
-
export declare type ContactValuePair = InfoUpdateValuePair<PUPPET.payloads.Contact>;
|
|
29
|
-
export declare type RoomValuePair = InfoUpdateValuePair<PUPPET.payloads.Room>;
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +0,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AAE,kBAAkB,CAAC;CACjD,CAAC,CAAA;AAEF,oBAAY,yBAAyB,GAAG,mBAAmB,CAAC,oBAAoB,CAAC,CAAA;AACjF,oBAAY,sBAAsB,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAA;AAE5E,oBAAY,gBAAgB,GAAG,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AAC3E,oBAAY,aAAa,GAAG,mBAAmB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/* eslint-disable valid-typeof */
|
|
2
|
-
import * as PUPPET from '@juzi/wechaty-puppet';
|
|
3
|
-
export const ContactImportantFields = [
|
|
4
|
-
'name', 'tags', 'alias', 'phone', 'description', 'corporation',
|
|
5
|
-
];
|
|
6
|
-
export const RoomImportantFields = [
|
|
7
|
-
'topic', 'memberIdList', 'ownerId',
|
|
8
|
-
];
|
|
9
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/schemas/update.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa;CACtD,CAAA;AAEV,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,cAAc,EAAE,SAAS;CAC1B,CAAA"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { InfoUpdateValuePair } from '../schemas/update'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* No need to go recursive on payload diff becasue
|
|
6
|
-
* 1. most fields of payloads are primitive values
|
|
7
|
-
* 2. users does not want to compare array items, they just need to know this field has changed. And we don't offer methods to get a subObject value
|
|
8
|
-
*/
|
|
9
|
-
export const diffPayload = <T>(objectOld: any, objectNew: any): InfoUpdateValuePair<T>[] => {
|
|
10
|
-
const keys = new Set([ ...Object.keys(objectOld || {}), ...Object.keys(objectNew || {}) ])
|
|
11
|
-
const result = []
|
|
12
|
-
for (const item of keys) {
|
|
13
|
-
const key = item as keyof T
|
|
14
|
-
const subObjectOld = objectOld[key] as T[typeof key]
|
|
15
|
-
const subObjectNew = objectNew[key] as T[typeof key]
|
|
16
|
-
|
|
17
|
-
if (typeof subObjectOld !== typeof subObjectNew) {
|
|
18
|
-
result.push({
|
|
19
|
-
key,
|
|
20
|
-
oldValue: subObjectOld,
|
|
21
|
-
newValue: subObjectNew,
|
|
22
|
-
})
|
|
23
|
-
} else {
|
|
24
|
-
if (typeof subObjectOld !== 'object') {
|
|
25
|
-
if (subObjectOld === subObjectNew) {
|
|
26
|
-
continue
|
|
27
|
-
} else {
|
|
28
|
-
result.push({
|
|
29
|
-
key,
|
|
30
|
-
oldValue: subObjectOld,
|
|
31
|
-
newValue: subObjectNew,
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
// for objects, we just judge if they were same or not, but do not record every different value
|
|
36
|
-
if (objectDeepDiff(subObjectOld, subObjectNew)) {
|
|
37
|
-
continue
|
|
38
|
-
} else {
|
|
39
|
-
result.push({
|
|
40
|
-
key,
|
|
41
|
-
oldValue: subObjectOld,
|
|
42
|
-
newValue: subObjectNew,
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return result
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const objectDeepDiff = (objectA: any, objectB: any) => {
|
|
53
|
-
const keys = new Set([ ...Object.keys(objectA), ...Object.keys(objectB) ])
|
|
54
|
-
for (const key of keys) {
|
|
55
|
-
if (typeof objectA[key] !== typeof objectB[key]) {
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
if (typeof objectA[key] !== 'object') {
|
|
59
|
-
if (objectA[key] !== objectB[key]) {
|
|
60
|
-
return false
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
if (!objectDeepDiff(objectA[key], objectB[key])) {
|
|
64
|
-
return false
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const checkUntilChanged = async (gapMilliseconds: number, maxRetry: number, judgement: () => Promise<boolean> | boolean): Promise<boolean> => {
|
|
72
|
-
let changed = await judgement()
|
|
73
|
-
let currentTry = 1
|
|
74
|
-
while (!changed && (currentTry < maxRetry)) {
|
|
75
|
-
await new Promise(resolve => setTimeout(resolve, gapMilliseconds))
|
|
76
|
-
changed = await judgement()
|
|
77
|
-
currentTry++
|
|
78
|
-
}
|
|
79
|
-
return changed
|
|
80
|
-
}
|
package/src/schemas/update.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable valid-typeof */
|
|
2
|
-
import * as PUPPET from '@juzi/wechaty-puppet'
|
|
3
|
-
|
|
4
|
-
export const ContactImportantFields = [
|
|
5
|
-
'name', 'tags', 'alias', 'phone', 'description', 'corporation',
|
|
6
|
-
] as const
|
|
7
|
-
|
|
8
|
-
export const RoomImportantFields = [
|
|
9
|
-
'topic', 'memberIdList', 'ownerId',
|
|
10
|
-
] as const
|
|
11
|
-
|
|
12
|
-
type ContactImportantKeys = typeof ContactImportantFields[number]
|
|
13
|
-
type RoomImportantKeys = typeof RoomImportantFields[number]
|
|
14
|
-
|
|
15
|
-
type ContactUpdatableKeys = Omit<PUPPET.payloads.Contact, ContactImportantKeys>
|
|
16
|
-
type RoomUpdateableKeys = Omit<PUPPET.payloads.Room, RoomImportantKeys>
|
|
17
|
-
|
|
18
|
-
type PayloadTypeToUpdateInterface<U> = {
|
|
19
|
-
[SubType in keyof U]: {
|
|
20
|
-
type: SubType,
|
|
21
|
-
id: string,
|
|
22
|
-
updates: InfoUpdateValuePair<U[SubType]>[],
|
|
23
|
-
}
|
|
24
|
-
}[keyof U]
|
|
25
|
-
|
|
26
|
-
export type InfoUpdateValuePair<U> = {
|
|
27
|
-
[SubType in keyof U]: {
|
|
28
|
-
key: SubType,
|
|
29
|
-
oldValue?: U[SubType],
|
|
30
|
-
newValue?: U[SubType],
|
|
31
|
-
}
|
|
32
|
-
}[keyof U]
|
|
33
|
-
|
|
34
|
-
export type InfoUpdateInterface = PayloadTypeToUpdateInterface<{
|
|
35
|
-
[PUPPET.types.Payload.Contact]: ContactUpdatableKeys,
|
|
36
|
-
[PUPPET.types.Payload.Room]: RoomUpdateableKeys,
|
|
37
|
-
}>
|
|
38
|
-
|
|
39
|
-
export type ContactUpdatableValuePair = InfoUpdateValuePair<ContactUpdatableKeys>
|
|
40
|
-
export type RoomUpdatableValuePair = InfoUpdateValuePair<RoomUpdateableKeys>
|
|
41
|
-
|
|
42
|
-
export type ContactValuePair = InfoUpdateValuePair<PUPPET.payloads.Contact>
|
|
43
|
-
export type RoomValuePair = InfoUpdateValuePair<PUPPET.payloads.Room>
|