@nuclia/sync-agent
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -49,41 +49,41 @@ "use strict"; | ||
} | ||
processSyncEntity(syncEntity) { | ||
return syncEntity.getLastModified().pipe((0, rxjs_1.map)((result) => { | ||
return { result, syncEntity }; | ||
}), (0, rxjs_1.switchMap)(({ result, syncEntity }) => { | ||
var _a, _b; | ||
server_1.eventEmitter.emit(events_1.EVENTS.START_SYNCHRONIZATION_SYNC_OBJECT, { | ||
from: syncEntity.id, | ||
to: ((_a = syncEntity.kb) === null || _a === void 0 ? void 0 : _a.knowledgeBox) || 'Unknown kb', | ||
date: new Date().toISOString(), | ||
total: ((_b = result.results) === null || _b === void 0 ? void 0 : _b.length) || 0, | ||
}); | ||
if (!result.success || result.results.length === 0) { | ||
this.callbackFinishSync(syncEntity, [], 0, result.error); | ||
return (0, rxjs_1.of)(undefined); | ||
} | ||
return this.processItems(syncEntity, result.results); | ||
})); | ||
} | ||
processItems(syncEntity, items) { | ||
return (0, rxjs_1.of)(...items).pipe((0, rxjs_1.concatMap)((item) => new sync_single_file_use_case_1.SyncSingleFile(syncEntity, item).execute().pipe((0, rxjs_1.map)((res) => ({ id: item.originalId, success: res.success })), | ||
// do not overwhelm the source | ||
(0, rxjs_1.delay)(500))), (0, rxjs_1.toArray)()); | ||
} | ||
execute() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const syncObjects = yield this.repository.getAllSync(); | ||
(0, rxjs_1.of)(Object.values(syncObjects)) | ||
.pipe((0, rxjs_1.switchMap)((syncObjectValues) => { | ||
if (syncObjectValues.length === 0) { | ||
return (0, rxjs_1.of)(undefined); | ||
} | ||
else { | ||
return (0, rxjs_1.forkJoin)(syncObjectValues.map((syncObj) => (0, rxjs_1.of)(syncObj).pipe((0, rxjs_1.switchMap)((syncObj) => new refresh_access_token_use_case_1.RefreshAccessToken(this.repository).execute(new sync_entity_1.SyncEntity(syncObj))), (0, rxjs_1.switchMap)((syncEntity) => syncEntity.getLastModified().pipe((0, rxjs_1.map)((result) => { | ||
return { result, syncEntity }; | ||
}))), (0, rxjs_1.switchMap)(({ result, syncEntity }) => { | ||
var _a, _b; | ||
server_1.eventEmitter.emit(events_1.EVENTS.START_SYNCHRONIZATION_SYNC_OBJECT, { | ||
from: syncEntity.id, | ||
to: ((_a = syncEntity.kb) === null || _a === void 0 ? void 0 : _a.knowledgeBox) || 'Unknown kb', | ||
date: new Date().toISOString(), | ||
total: ((_b = result.results) === null || _b === void 0 ? void 0 : _b.length) || 0, | ||
}); | ||
if (!result.success || result.results.length === 0) { | ||
this.callbackFinishSync(syncEntity, [], 0, result.error); | ||
return (0, rxjs_1.of)(undefined); | ||
} | ||
const batch = result.results.map((item) => (0, rxjs_1.of)(item).pipe((0, rxjs_1.switchMap)((item) => new sync_single_file_use_case_1.SyncSingleFile(syncEntity, item).execute().pipe((0, rxjs_1.map)((res) => ({ id: item.originalId, success: res.success })), | ||
// do not overwhelm the source | ||
(0, rxjs_1.delay)(500))))); | ||
return (0, rxjs_1.forkJoin)(batch).pipe((0, rxjs_1.tap)((result) => { | ||
if (result) { | ||
const processed = result.map((res) => res.id); | ||
const successCount = result.filter((res) => res.success).length; | ||
console.log('processed', processed); | ||
console.log('successCount', successCount); | ||
this.callbackFinishSync(syncEntity, processed, successCount, ''); | ||
} | ||
})); | ||
})))); | ||
} | ||
})) | ||
.subscribe(() => console.log('Finish sync folders data')); | ||
const syncObjectValues = Object.values(syncObjects); | ||
if (syncObjectValues.length > 0) { | ||
yield (0, rxjs_1.lastValueFrom)((0, rxjs_1.of)(...syncObjectValues).pipe((0, rxjs_1.switchMap)((syncObj) => new refresh_access_token_use_case_1.RefreshAccessToken(this.repository).execute(new sync_entity_1.SyncEntity(syncObj))), (0, rxjs_1.switchMap)((syncEntity) => this.processSyncEntity(syncEntity).pipe((0, rxjs_1.tap)((result) => { | ||
if (result) { | ||
const processed = result.map((res) => res.id); | ||
const successCount = result.filter((res) => res.success).length; | ||
console.log('processed', processed); | ||
console.log('successCount', successCount); | ||
this.callbackFinishSync(syncEntity, processed, successCount, ''); | ||
} | ||
}))))); | ||
console.log('Finish sync folders data'); | ||
} | ||
}); | ||
@@ -90,0 +90,0 @@ } |
@@ -0,1 +1,2 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
@@ -2,0 +3,0 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
@@ -0,1 +1,2 @@ | ||
import { SyncItem } from '../../../connector/domain/connector'; | ||
import { SyncEntity } from '../sync.entity'; | ||
@@ -10,3 +11,11 @@ import { ISyncRepository } from '../sync.repository'; | ||
callbackFinishSync: (syncEntity: SyncEntity, processed: string[], successCount: number, error?: string) => void; | ||
processSyncEntity(syncEntity: SyncEntity): import("rxjs").Observable<{ | ||
id: string; | ||
success: boolean; | ||
}[] | undefined>; | ||
processItems(syncEntity: SyncEntity, items: SyncItem[]): import("rxjs").Observable<{ | ||
id: string; | ||
success: boolean; | ||
}[]>; | ||
execute(): Promise<void>; | ||
} |
@@ -0,1 +1,2 @@ | ||
#!/usr/bin/env node | ||
export {}; |
{ | ||
"name": "@nuclia/sync-agent", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "This is a sync agent to synchronize user files from diferent sources to nuclia", | ||
@@ -28,3 +28,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@nuclia/core": "^1.11.6", | ||
"@nuclia/core": "^1.13.0", | ||
"cheerio": "^1.0.0-rc.12", | ||
@@ -31,0 +31,0 @@ "commander": "^11.1.0", |
@@ -10,4 +10,4 @@ # Nuclia Sync Agent server | ||
```bash | ||
npm install -g nuclia-sync-agent-server | ||
nuclia-sync-agent-server | ||
npm install -g @nuclia/sync-agent | ||
nuclia-sync-agent | ||
``` |
169395
104
4012
+ Added@nuclia/core@1.24.1(transitive)
+ Addedobject-inspect@1.13.4(transitive)
- Removed@nuclia/core@1.24.0(transitive)
- Removedobject-inspect@1.13.3(transitive)
Updated@nuclia/core@^1.13.0