diff --git a/client/react-native/app/container/container.gen.js b/client/react-native/app/container/container.gen.js index c2667ba934..ee1f9bea36 100644 --- a/client/react-native/app/container/container.gen.js +++ b/client/react-native/app/container/container.gen.js @@ -88,7 +88,7 @@ export class SenderAliasEntity extends Component { @withStoreContext export class IDServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.id } } @@ -126,7 +126,7 @@ class EventListServiceNodePagination extends StreamPagination { this.dispose() } - get service () { + get method () { return this.props.context.node.service.eventList } } @@ -151,7 +151,7 @@ class EventUnseenServiceNodePagination extends StreamPagination { this.dispose() } - get service () { + get method () { return this.props.context.node.service.eventUnseen } } @@ -159,63 +159,63 @@ EventUnseenServiceNode.Pagination = EventUnseenServiceNodePagination @withStoreContext export class GetEventServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.getEvent } } @withStoreContext export class EventSeenServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.eventSeen } } @withStoreContext export class EventRetryServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.eventRetry } } @withStoreContext export class ConfigPublicServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.configPublic } } @withStoreContext export class ConfigUpdateServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.configUpdate } } @withStoreContext export class ContactRequestServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.contactRequest } } @withStoreContext export class ContactAcceptRequestServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.contactAcceptRequest } } @withStoreContext export class ContactRemoveServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.contactRemove } } @withStoreContext export class ContactUpdateServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.contactUpdate } } @@ -239,7 +239,7 @@ class ContactListServiceNodePagination extends StreamPagination { this.dispose() } - get service () { + get method () { return this.props.context.node.service.contactList } } @@ -247,28 +247,28 @@ ContactListServiceNode.Pagination = ContactListServiceNodePagination @withStoreContext export class ContactServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.contact } } @withStoreContext export class ContactCheckPublicKeyServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.contactCheckPublicKey } } @withStoreContext export class ConversationCreateServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationCreate } } @withStoreContext export class ConversationUpdateServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationUpdate } } @@ -292,7 +292,7 @@ class ConversationListServiceNodePagination extends StreamPagination { this.dispose() } - get service () { + get method () { return this.props.context.node.service.conversationList } } @@ -300,168 +300,168 @@ ConversationListServiceNode.Pagination = ConversationListServiceNodePagination @withStoreContext export class ConversationInviteServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationInvite } } @withStoreContext export class ConversationExcludeServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationExclude } } @withStoreContext export class ConversationAddMessageServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationAddMessage } } @withStoreContext export class ConversationServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversation } } @withStoreContext export class ConversationMemberServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationMember } } @withStoreContext export class ConversationReadServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationRead } } @withStoreContext export class ConversationRemoveServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationRemove } } @withStoreContext export class ConversationLastEventServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.conversationLastEvent } } @withStoreContext export class DevicePushConfigListServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.devicePushConfigList } } @withStoreContext export class DevicePushConfigCreateServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.devicePushConfigCreate } } @withStoreContext export class DevicePushConfigNativeRegisterServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.devicePushConfigNativeRegister } } @withStoreContext export class DevicePushConfigNativeUnregisterServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.devicePushConfigNativeUnregister } } @withStoreContext export class DevicePushConfigRemoveServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.devicePushConfigRemove } } @withStoreContext export class DevicePushConfigUpdateServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.devicePushConfigUpdate } } @withStoreContext export class HandleEventServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.handleEvent } } @withStoreContext export class GenerateFakeDataServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.generateFakeData } } @withStoreContext export class RunIntegrationTestsServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.runIntegrationTests } } @withStoreContext export class DebugPingServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.debugPing } } @withStoreContext export class DebugRequeueEventServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.debugRequeueEvent } } @withStoreContext export class DebugRequeueAllServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.debugRequeueAll } } @withStoreContext export class DeviceInfosServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.deviceInfos } } @withStoreContext export class AppVersionServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.appVersion } } @withStoreContext export class PeersServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.peers } } @withStoreContext export class ProtocolsServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.protocols } } @@ -489,35 +489,35 @@ export class LogfileReadServiceNode extends Stream { @withStoreContext export class TestLogBackgroundErrorServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.testLogBackgroundError } } @withStoreContext export class TestLogBackgroundWarnServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.testLogBackgroundWarn } } @withStoreContext export class TestLogBackgroundDebugServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.testLogBackgroundDebug } } @withStoreContext export class TestPanicServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.testPanic } } @withStoreContext export class TestErrorServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.testError } } @@ -538,21 +538,21 @@ export class MonitorPeersServiceNode extends Stream { @withStoreContext export class GetListenAddrsServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.getListenAddrs } } @withStoreContext export class GetListenInterfaceAddrsServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.getListenInterfaceAddrs } } @withStoreContext export class Libp2PPingServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.libp2PPing } } diff --git a/client/react-native/app/container/stream.js b/client/react-native/app/container/stream.js index ce6984ed6b..5451821b0d 100644 --- a/client/react-native/app/container/stream.js +++ b/client/react-native/app/container/stream.js @@ -4,8 +4,8 @@ import { Component } from 'react' import objectHash from 'object-hash' export class Stream extends Component { - get service () { - return this.props.service || async function * () {} + get method () { + return this.props.method || function () {} } get request () { return this.props.request @@ -33,7 +33,7 @@ export class Stream extends Component { } invoke = async () => { - const stream = await this.service(this.request) + const stream = await this.method(this.request) const queue = [] stream.on('data', response => { @@ -53,7 +53,8 @@ export class Stream extends Component { } } -const deepFilterEqual = (a, b) => { +const deepFilterEqual = (a, b, opts = { exclude: [] }) => { + const { exclude } = opts if (!a) { return true } @@ -65,7 +66,11 @@ const deepFilterEqual = (a, b) => { if (Array.isArray(a)) { return a.every(av => b.some(bv => deepFilterEqual(av, bv))) } - return Object.keys(a).every(k => deepFilterEqual(a[k], b[k])) + return Object.keys(a).every( + k => + exclude.some(excludeKey => excludeKey === k) || + deepFilterEqual(a[k], b[k]) + ) default: return a === b } @@ -116,7 +121,7 @@ export class StreamPagination extends Stream { let bottomIndex = this.queue.length - topIndex - 1 let itemBottom = this.queue[bottomIndex] let supBottom = cursor > itemBottom[cursorField] - if (supBottom) { + if (supBottom && bottomIndex + 1 !== this.queue.length) { this.queue.splice(bottomIndex + 1, 0, newValue) return } @@ -125,12 +130,6 @@ export class StreamPagination extends Stream { // if forced to add, push it if (change.force) { this.queue.push(newValue) - return - } - - // force to re-paginate if queue first page is not fulfilled - if (this.queue.length < this.paginate.first) { - this.invoke() } } @@ -199,7 +198,7 @@ export class StreamPagination extends Stream { this.invokeHashTable[requestHash] = true this.loading = true - const stream = await this.service(request) + const stream = await this.method(request) stream.on('data', response => { queue.push(response) @@ -213,16 +212,14 @@ export class StreamPagination extends Stream { stream.on('end', () => { this.loading = false + if (queue.length !== 0) { this.cursor = queue[queue.length - 1][this.paginate.sortedBy || 'id'] } - // permit to re-request when page not been fulfilled - if (queue.length < this.paginate.first) { - this.invokeHashTable[requestHash] = false - } - this.smartForceUpdate() + + this.invokeHashTable[requestHash] = false }) } diff --git a/client/react-native/app/store/store.gen.js b/client/react-native/app/store/store.gen.js index 51e3461d46..14b14ce40c 100644 --- a/client/react-native/app/store/store.gen.js +++ b/client/react-native/app/store/store.gen.js @@ -16,14 +16,20 @@ export class ConfigEntityStore { return this.store.entity.contact.get(this.myselfId) } set myself (myself) { - this.store.entity.contact.set(this.myselfId, myself) + this.store.entity.contact.set( + this.myselfId, + new ContactEntityStore(this.store, myself) + ) } myselfId = null @computed get currentDevice () { return this.store.entity.device.get(this.currentDeviceId) } set currentDevice (currentDevice) { - this.store.entity.device.set(this.currentDeviceId, currentDevice) + this.store.entity.device.set( + this.currentDeviceId, + new DeviceEntityStore(this.store, currentDevice) + ) } currentDeviceId = null cryptoParams = null @@ -139,7 +145,10 @@ export class ConversationMemberEntityStore { return this.store.entity.contact.get(this.contactId) } set contact (contact) { - this.store.entity.contact.set(this.contactId, contact) + this.store.entity.contact.set( + this.contactId, + new ContactEntityStore(this.store, contact) + ) } conversationId = null contactId = null @@ -258,11 +267,13 @@ export class NodeServiceStore { constructor (store, bridge) { this.store = store this.bridge = bridge - this.commitLogStream({}) + this.commitLogStream({}).then(commitLog => { + commitLog.on('data', data => { + // init the stream + }) + }) } - pages = {} - id = async input => { let output = await this.bridge.id(input) @@ -271,262 +282,257 @@ export class NodeServiceStore { commitLogStream = async input => { const stream = await this.bridge.commitLogStream(input) - stream.on('data', output => { - Object.keys(output.entity).forEach(key => { - if (output.entity[key] == null) { - return - } - switch (key) { - default: - break - case 'config': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.config.set( - output.entity[key].id, - new ConfigEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if (this.store.entity.config.has(output.entity[key].id)) { - this.store.entity.config.delete(output.entity[key].id) - } - break - } - break - case 'contact': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.contact.set( - output.entity[key].id, - new ContactEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if (this.store.entity.contact.has(output.entity[key].id)) { - this.store.entity.contact.delete(output.entity[key].id) - } - break - } - break - case 'device': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.device.set( - output.entity[key].id, - new DeviceEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if (this.store.entity.device.has(output.entity[key].id)) { - this.store.entity.device.delete(output.entity[key].id) - } - break - } - break - case 'conversation': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.conversation.set( - output.entity[key].id, - new ConversationEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if (this.store.entity.conversation.has(output.entity[key].id)) { - this.store.entity.conversation.delete(output.entity[key].id) - } - break - } - break - case 'conversationMember': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.conversationMember.set( - output.entity[key].id, - new ConversationMemberEntityStore( - this.store, - output.entity[key] + const transformStream = new Stream.Transform({ + writableObjectMode: true, + readableObjectMode: true, + transform: (output, encoding, callback) => { + Object.keys(output.entity).forEach(key => { + let entity = output.entity[key] + if (entity == null) { + return + } + switch (key) { + default: + break + case 'config': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.config.set( + entity.id, + new ConfigEntityStore(this.store, entity) ) - ) - break - case 2: - if ( - this.store.entity.conversationMember.has( - output.entity[key].id + break + case 2: + if (this.store.entity.config.has(entity.id)) { + entity = this.store.entity.config.get(entity.id) + this.store.entity.config.delete(entity.id) + } + break + } + break + case 'contact': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.contact.set( + entity.id, + new ContactEntityStore(this.store, entity) ) - ) { - this.store.entity.conversationMember.delete( - output.entity[key].id + break + case 2: + if (this.store.entity.contact.has(entity.id)) { + entity = this.store.entity.contact.get(entity.id) + this.store.entity.contact.delete(entity.id) + } + break + } + break + case 'device': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.device.set( + entity.id, + new DeviceEntityStore(this.store, entity) ) - } - break - } - break - case 'event': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.event.set( - output.entity[key].id, - new EventEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if (this.store.entity.event.has(output.entity[key].id)) { - this.store.entity.event.delete(output.entity[key].id) - } - break - } - break - case 'devicePushConfig': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.devicePushConfig.set( - output.entity[key].id, - new DevicePushConfigEntityStore( - this.store, - output.entity[key] + break + case 2: + if (this.store.entity.device.has(entity.id)) { + entity = this.store.entity.device.get(entity.id) + this.store.entity.device.delete(entity.id) + } + break + } + break + case 'conversation': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.conversation.set( + entity.id, + new ConversationEntityStore(this.store, entity) ) - ) - break - case 2: - if ( - this.store.entity.devicePushConfig.has(output.entity[key].id) - ) { - this.store.entity.devicePushConfig.delete( - output.entity[key].id + break + case 2: + if (this.store.entity.conversation.has(entity.id)) { + entity = this.store.entity.conversation.get(entity.id) + this.store.entity.conversation.delete(entity.id) + } + break + } + break + case 'conversationMember': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.conversationMember.set( + entity.id, + new ConversationMemberEntityStore(this.store, entity) ) - } - break - } - break - case 'devicePushIdentifier': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.devicePushIdentifier.set( - output.entity[key].id, - new DevicePushIdentifierEntityStore( - this.store, - output.entity[key] + break + case 2: + if (this.store.entity.conversationMember.has(entity.id)) { + entity = this.store.entity.conversationMember.get(entity.id) + this.store.entity.conversationMember.delete(entity.id) + } + break + } + break + case 'event': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.event.set( + entity.id, + new EventEntityStore(this.store, entity) ) - ) - break - case 2: - if ( - this.store.entity.devicePushIdentifier.has( - output.entity[key].id + break + case 2: + if (this.store.entity.event.has(entity.id)) { + entity = this.store.entity.event.get(entity.id) + this.store.entity.event.delete(entity.id) + } + break + } + break + case 'devicePushConfig': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.devicePushConfig.set( + entity.id, + new DevicePushConfigEntityStore(this.store, entity) ) - ) { - this.store.entity.devicePushIdentifier.delete( - output.entity[key].id + break + case 2: + if (this.store.entity.devicePushConfig.has(entity.id)) { + entity = this.store.entity.devicePushConfig.get(entity.id) + this.store.entity.devicePushConfig.delete(entity.id) + } + break + } + break + case 'devicePushIdentifier': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.devicePushIdentifier.set( + entity.id, + new DevicePushIdentifierEntityStore(this.store, entity) ) - } - break - } - break - case 'eventDispatch': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.eventDispatch.set( - output.entity[key].id, - new EventDispatchEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if ( - this.store.entity.eventDispatch.has(output.entity[key].id) - ) { - this.store.entity.eventDispatch.delete(output.entity[key].id) - } - break - } - break - case 'senderAlias': - switch (output.operation) { - default: - case 0: - case 1: - this.store.entity.senderAlias.set( - output.entity[key].id, - new SenderAliasEntityStore(this.store, output.entity[key]) - ) - break - case 2: - if (this.store.entity.senderAlias.has(output.entity[key].id)) { - this.store.entity.senderAlias.delete(output.entity[key].id) - } - break - } - break - } - }) - }) - const copyStream = new Stream.PassThrough({ - writableObjectMode: true, - readableObjectMode: true, + break + case 2: + if (this.store.entity.devicePushIdentifier.has(entity.id)) { + entity = this.store.entity.devicePushIdentifier.get( + entity.id + ) + this.store.entity.devicePushIdentifier.delete(entity.id) + } + break + } + break + case 'eventDispatch': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.eventDispatch.set( + entity.id, + new EventDispatchEntityStore(this.store, entity) + ) + break + case 2: + if (this.store.entity.eventDispatch.has(entity.id)) { + entity = this.store.entity.eventDispatch.get(entity.id) + this.store.entity.eventDispatch.delete(entity.id) + } + break + } + break + case 'senderAlias': + switch (output.operation) { + default: + case 0: + case 1: + this.store.entity.senderAlias.set( + entity.id, + new SenderAliasEntityStore(this.store, entity) + ) + break + case 2: + if (this.store.entity.senderAlias.has(entity.id)) { + entity = this.store.entity.senderAlias.get(entity.id) + this.store.entity.senderAlias.delete(entity.id) + } + break + } + break + } + output.entity[key] = entity + }) + + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } eventStream = async input => { const stream = await this.bridge.eventStream(input) - stream.on('data', output => { - output = new EventEntityStore(this.store, output) - this.store.entity.event.set(output.id, output) - }) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + output = new EventEntityStore(this.store, output) + this.store.entity.event.set(output.id, output) + + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } eventList = async input => { const stream = await this.bridge.eventList(input) - stream.on('data', output => { - output = new EventEntityStore(this.store, output) - this.store.entity.event.set(output.id, output) - }) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + output = new EventEntityStore(this.store, output) + this.store.entity.event.set(output.id, output) + + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } eventUnseen = async input => { const stream = await this.bridge.eventUnseen(input) - stream.on('data', output => { - output = new EventEntityStore(this.store, output) - this.store.entity.event.set(output.id, output) - }) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + output = new EventEntityStore(this.store, output) + this.store.entity.event.set(output.id, output) + + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } getEvent = async input => { @@ -596,6 +602,7 @@ export class NodeServiceStore { let output = await this.bridge.contactRemove(input) if (this.store.entity.contact.has(output.id)) { + output = this.store.entity.contact.get(output.id) this.store.entity.contact.delete(output.id) } @@ -613,16 +620,18 @@ export class NodeServiceStore { contactList = async input => { const stream = await this.bridge.contactList(input) - stream.on('data', output => { - output = new ContactEntityStore(this.store, output) - this.store.entity.contact.set(output.id, output) - }) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + output = new ContactEntityStore(this.store, output) + this.store.entity.contact.set(output.id, output) + + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } contact = async input => { @@ -660,16 +669,18 @@ export class NodeServiceStore { conversationList = async input => { const stream = await this.bridge.conversationList(input) - stream.on('data', output => { - output = new ConversationEntityStore(this.store, output) - this.store.entity.conversation.set(output.id, output) - }) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + output = new ConversationEntityStore(this.store, output) + this.store.entity.conversation.set(output.id, output) + + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } conversationInvite = async input => { @@ -730,6 +741,7 @@ export class NodeServiceStore { let output = await this.bridge.conversationRemove(input) if (this.store.entity.conversation.has(output.id)) { + output = this.store.entity.conversation.get(output.id) this.store.entity.conversation.delete(output.id) } @@ -776,6 +788,7 @@ export class NodeServiceStore { let output = await this.bridge.devicePushConfigRemove(input) if (this.store.entity.devicePushConfig.has(output.id)) { + output = this.store.entity.devicePushConfig.get(output.id) this.store.entity.devicePushConfig.delete(output.id) } @@ -856,35 +869,41 @@ export class NodeServiceStore { logStream = async input => { const stream = await this.bridge.logStream(input) - stream.on('data', output => {}) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } logfileList = async input => { const stream = await this.bridge.logfileList(input) - stream.on('data', output => {}) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } logfileRead = async input => { const stream = await this.bridge.logfileRead(input) - stream.on('data', output => {}) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } testLogBackgroundError = async input => { @@ -919,24 +938,28 @@ export class NodeServiceStore { monitorBandwidth = async input => { const stream = await this.bridge.monitorBandwidth(input) - stream.on('data', output => {}) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } monitorPeers = async input => { const stream = await this.bridge.monitorPeers(input) - stream.on('data', output => {}) - const copyStream = new Stream.PassThrough({ + const transformStream = new Stream.Transform({ writableObjectMode: true, readableObjectMode: true, + transform: (output, encoding, callback) => { + callback(null, output) + }, }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream } getListenAddrs = async input => { diff --git a/client/react-native/app/template/container/container.gen.js.hbs b/client/react-native/app/template/container/container.gen.js.hbs index ffbf3134ce..8e95bec14a 100644 --- a/client/react-native/app/template/container/container.gen.js.hbs +++ b/client/react-native/app/template/container/container.gen.js.hbs @@ -58,7 +58,7 @@ import { Component } from 'react' this.dispose() } - get service () { + get method () { return this.props.context.node.service.{{case 'camel' name}} } } @@ -74,7 +74,7 @@ import { Component } from 'react' @withStoreContext export class {{name}}ServiceNode extends Unary { - get service () { + get method () { return this.props.context.node.service.{{case 'camel' name}} } } diff --git a/client/react-native/app/template/store/store.gen.js.hbs b/client/react-native/app/template/store/store.gen.js.hbs index 807cf1e571..55bc0dfa76 100644 --- a/client/react-native/app/template/store/store.gen.js.hbs +++ b/client/react-native/app/template/store/store.gen.js.hbs @@ -32,7 +32,10 @@ import Stream from 'stream' new {{type}}EntityStore(this.store, _), )) {{else}} - this.store.entity.{{case 'camel' type}}.set(this.{{name}}Id, {{case 'camel' name}}) + this.store.entity.{{case 'camel' type}}.set( + this.{{name}}Id, + new {{type}}EntityStore(this.store, {{case 'camel' name}}), + ) {{/if}} } {{else}} @@ -54,22 +57,23 @@ import Stream from 'stream' constructor (store, bridge) { this.store = store this.bridge = bridge - this.commitLogStream({}) + this.commitLogStream({}).then(commitLog => { + commitLog.on('data', data => { + // init the stream + }) + }) } - pages = {} - {{#each methods}} - {{#if responseStream}} - {{case 'camel' name}} = async (input) => { - {{else}} - {{case 'camel' name}} = async (input) => { - {{/if}} + {{case 'camel' name}} = async (input) => { {{#if responseStream}} const stream = await this.bridge.{{case 'camel' name}}(input) - stream.on('data', output => { + const transformStream = new Stream.Transform({ + writableObjectMode: true, + readableObjectMode: true, + transform: (output, encoding, callback) => { {{else}} let output = await this.bridge.{{case 'camel' name}}(input) {{/if}} @@ -78,7 +82,8 @@ import Stream from 'stream' {{#with resolvedResponseType.nested.Entity}} Object.keys(output.entity).forEach( key => { - if (output.entity[key] == null) { + let entity = output.entity[key] + if (entity == null) { return } switch (key) { @@ -91,19 +96,21 @@ import Stream from 'stream' case 0: case 1: this.store.entity.{{case 'camel' resolvedType.name}}.set( - output.entity[key].id, - new {{resolvedType.name}}EntityStore(this.store, output.entity[key]), + entity.id, + new {{resolvedType.name}}EntityStore(this.store, entity), ) break case 2: - if (this.store.entity.{{case 'camel' resolvedType.name}}.has(output.entity[key].id)) { - this.store.entity.{{case 'camel' resolvedType.name}}.delete(output.entity[key].id) + if (this.store.entity.{{case 'camel' resolvedType.name}}.has(entity.id)) { + entity = this.store.entity.{{case 'camel' resolvedType.name}}.get(entity.id) + this.store.entity.{{case 'camel' resolvedType.name}}.delete(entity.id) } break } break {{/each}} } + output.entity[key] = entity } ) {{/with}} @@ -114,6 +121,7 @@ import Stream from 'stream' {{#if (eq resolvedType.name ../../resolvedResponseType.name)}} {{#if (test ../../name (toRegex '(Remove|Delete)$'))}} if (this.store.entity.{{case 'camel' resolvedType.name}}.has(output.id)) { + output = this.store.entity.{{case 'camel' resolvedType.name}}.get(output.id) this.store.entity.{{case 'camel' resolvedType.name}}.delete(output.id) } {{else}} @@ -125,13 +133,11 @@ import Stream from 'stream' {{/with}} {{#if responseStream}} + callback(null, output) + }, }) - const copyStream = new Stream.PassThrough({ - writableObjectMode: true, - readableObjectMode: true, - }) - stream.pipe(copyStream) - return copyStream + stream.pipe(transformStream) + return transformStream {{else}} return output {{/if}} diff --git a/client/react-native/app/view/screen/Contacts/Detail/Detail.js b/client/react-native/app/view/screen/Contacts/Detail/Detail.js index 8f32890819..bf98603406 100644 --- a/client/react-native/app/view/screen/Contacts/Detail/Detail.js +++ b/client/react-native/app/view/screen/Contacts/Detail/Detail.js @@ -59,10 +59,10 @@ class DetailsBase extends PureComponent { await this.props.context.node.service.contactRemove({ id: this.props.navigation.getParam('id'), }) - this.props.goBack(null) } catch (err) { console.error(err) } + this.props.goBack(null) } render () {