core-3nweb-client-lib 0.43.3 → 0.43.5

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.
@@ -603,16 +603,19 @@ declare namespace web3n.files {
603
603
 
604
604
  /**
605
605
  * Adopts remote version.
606
- * @param opts options let one to pass exact remote version, to trigger download.
606
+ * In conflicting state remote version must be present in options.
607
+ * @param opts options let one to pass exact remote version.
607
608
  */
608
609
  adoptRemote(opts?: OptionsToAdopteRemote): Promise<void>;
609
610
 
610
611
  }
611
612
 
612
613
  interface OptionsToAdopteRemote {
613
- dropLocalVer?: boolean;
614
+ /**
615
+ * Identifies remote version that should be adopted.
616
+ * In conflicting state this must be present.
617
+ */
614
618
  remoteVersion?: number;
615
- download?: boolean;
616
619
  }
617
620
 
618
621
  interface WritableFileSyncAPI extends ReadonlyFileSyncAPI {
@@ -1228,9 +1231,10 @@ declare namespace web3n.files {
1228
1231
  download(path: string, version: number): Promise<void>;
1229
1232
 
1230
1233
  /**
1231
- * Adopts remote version of fs object at given path
1234
+ * Adopts remote version of fs object at given path.
1235
+ * In conflicting state remote version must be present in options.
1232
1236
  * @param path
1233
- * @param opts options let one to pass exact remote version, to trigger download.
1237
+ * @param opts options let one to pass exact remote version.
1234
1238
  */
1235
1239
  adoptRemote(path: string, opts?: OptionsToAdopteRemote): Promise<void>;
1236
1240
 
@@ -124,7 +124,7 @@ export declare class ObjStatus implements SyncedObjStatus, UploadStatusRecorder
124
124
  syncStatus(): SyncStatus;
125
125
  neverUploaded(): boolean;
126
126
  versionBeforeUnsyncedRemoval(): number | undefined;
127
- adoptRemoteVersion(version?: number, dropLocalVer?: boolean): Promise<void>;
127
+ adoptRemoteVersion(version?: number): Promise<void>;
128
128
  isAmongRemote(version: number): boolean;
129
129
  }
130
130
  export declare function readAndCheckStatus(objFolder: string, objId: ObjId): Promise<ObjStatusInfo>;
@@ -510,14 +510,14 @@ class ObjStatus {
510
510
  return this.status.upload.localVersion;
511
511
  }
512
512
  }
513
- async adoptRemoteVersion(version, dropLocalVer = false) {
513
+ async adoptRemoteVersion(version) {
514
514
  var _a;
515
515
  const { local, remote } = this.status;
516
516
  if (this.stateIndicator !== 'behind') {
517
517
  if (this.stateIndicator === 'synced') {
518
518
  return;
519
519
  }
520
- else if (!dropLocalVer) {
520
+ else if ((this.stateIndicator === 'conflicting') && !version) {
521
521
  throw (0, exceptions_1.makeFSSyncException)('', {
522
522
  localVersion: local === null || local === void 0 ? void 0 : local.current,
523
523
  remoteVersion: remote.current,
@@ -92,11 +92,7 @@ class SyncedStore {
92
92
  async adoptRemote(objId, opts) {
93
93
  const obj = await this.getObjOrThrow(objId);
94
94
  const objStatus = obj.statusObj();
95
- await objStatus.adoptRemoteVersion(opts === null || opts === void 0 ? void 0 : opts.remoteVersion, opts === null || opts === void 0 ? void 0 : opts.dropLocalVer);
96
- if (opts && opts.download) {
97
- // XXX this needs implementation
98
- throw new Error('SyncedStore.adoptRemote() with download option needs implementation, probably using SyncedStore.download().');
99
- }
95
+ await objStatus.adoptRemoteVersion(opts === null || opts === void 0 ? void 0 : opts.remoteVersion);
100
96
  this.files.scheduleGC(obj);
101
97
  return objStatus.syncStatus().synced.latest;
102
98
  }
@@ -1199,7 +1199,7 @@ function remoteAdoptionOptsToMsg(opts) {
1199
1199
  return;
1200
1200
  }
1201
1201
  return {
1202
- dropLocalVer: (0, protobuf_msg_1.toOptVal)(opts.dropLocalVer),
1202
+ // dropLocalVer: toOptVal(opts.dropLocalVer),
1203
1203
  remoteVersion: (0, protobuf_msg_1.toOptVal)(opts.remoteVersion)
1204
1204
  };
1205
1205
  }
@@ -1208,7 +1208,7 @@ function remoteAdoptionOptsFromMsg(msg) {
1208
1208
  return;
1209
1209
  }
1210
1210
  return {
1211
- dropLocalVer: (0, protobuf_msg_1.valOfOpt)(msg.dropLocalVer),
1211
+ // dropLocalVer: valOfOpt(msg.dropLocalVer),
1212
1212
  remoteVersion: (0, protobuf_msg_1.valOfOptInt)(msg.remoteVersion)
1213
1213
  };
1214
1214
  }
@@ -28,8 +28,11 @@ function openSocket(url, sessionId) {
28
28
  const headers = {};
29
29
  headers[request_utils_1.SESSION_ID_HEADER] = sessionId;
30
30
  const ws = new WebSocket(url, { headers, agent: https_1.globalAgent });
31
- const opening = (0, deferred_1.defer)();
32
- const initOnError = (err) => opening.reject((0, http_1.makeConnectionException)(url, undefined, `Cannot open websocket connection due to error: ${err.message}`));
31
+ let opening = (0, deferred_1.defer)();
32
+ const initOnError = (err) => {
33
+ opening === null || opening === void 0 ? void 0 : opening.reject((0, http_1.makeConnectionException)(url, undefined, `WebSocket connection error: ${err.message}`));
34
+ opening = undefined;
35
+ };
33
36
  const onNonOkReply = (req, res) => {
34
37
  const errReply = {
35
38
  url,
@@ -37,7 +40,8 @@ function openSocket(url, sessionId) {
37
40
  status: res.statusCode,
38
41
  data: undefined
39
42
  };
40
- opening.resolve(errReply);
43
+ opening === null || opening === void 0 ? void 0 : opening.resolve(errReply);
44
+ opening = undefined;
41
45
  };
42
46
  ws.on('error', initOnError);
43
47
  ws.on('unexpected-response', onNonOkReply);
@@ -48,10 +52,15 @@ function openSocket(url, sessionId) {
48
52
  status: 200,
49
53
  data: ws
50
54
  };
51
- opening.resolve(okReply);
55
+ opening === null || opening === void 0 ? void 0 : opening.resolve(okReply);
56
+ opening = undefined;
52
57
  ws.removeListener('error', initOnError);
53
58
  ws.removeListener('unexpected-response', onNonOkReply);
54
59
  });
60
+ ws.on('error', err => {
61
+ // XXX we need
62
+ console.error(`Error in ${ws.url} connection`, err);
63
+ });
55
64
  return opening.promise;
56
65
  }
57
66
  Object.freeze(exports);
@@ -383,10 +383,10 @@ class FolderNode extends node_in_fs_1.NodeInFS {
383
383
  const attrs = this.attrs.copy();
384
384
  // do action within transition state
385
385
  const changeEvents = await change(state, version);
386
- // save transition state
386
+ // save new state
387
387
  const encSub = await this.crypto.write(state, version, attrs, this.xattrs);
388
388
  await this.storage.saveObj(this.objId, version, encSub);
389
- // complete transition
389
+ // apply new state to in-memory object
390
390
  this.currentState = state;
391
391
  this.setCurrentVersion(version);
392
392
  this.attrs = attrs;
@@ -681,7 +681,7 @@ class FolderNode extends node_in_fs_1.NodeInFS {
681
681
  }
682
682
  async removeFolderObj(src, passIdsForRmUpload = false) {
683
683
  const childrenNodes = await this.doChange(true, async () => {
684
- if (this.version < 0) {
684
+ if (this.isMarkedRemoved) {
685
685
  return;
686
686
  }
687
687
  const childrenNodes = await this.getAllNodes();
@@ -692,12 +692,7 @@ class FolderNode extends node_in_fs_1.NodeInFS {
692
692
  return;
693
693
  }
694
694
  if (this.isInSyncedStorage) {
695
- if (passIdsForRmUpload) {
696
- return this.removeChildrenObjsInSyncedStorage(childrenNodes, src, true);
697
- }
698
- else {
699
- this.removeChildrenObjsInSyncedStorage(childrenNodes, src, false);
700
- }
695
+ return await this.removeChildrenObjsInSyncedStorage(childrenNodes, src, passIdsForRmUpload);
701
696
  }
702
697
  else {
703
698
  this.callRemoveObjOnAll(src, childrenNodes);
@@ -709,7 +704,7 @@ class FolderNode extends node_in_fs_1.NodeInFS {
709
704
  }
710
705
  }
711
706
  async removeChildrenObjsInSyncedStorage(childrenNodes, src, passIdsForRmUpload) {
712
- if (this.version < 0) {
707
+ if (this.isMarkedRemoved) {
713
708
  return;
714
709
  }
715
710
  let uploadRmsHere;
@@ -23,6 +23,8 @@ export declare abstract class NodeInFS<P extends NodePersistance> implements Nod
23
23
  private writeProc;
24
24
  get version(): number;
25
25
  protected setCurrentVersion(newVersion: number): void;
26
+ private markRemoved;
27
+ protected get isMarkedRemoved(): boolean;
26
28
  readonly isInSyncedStorage: boolean;
27
29
  protected constructor(storage: Storage, type: NodeType, name: string, objId: string, currentVersion: number, parentId: string | undefined);
28
30
  protected getObjSrcOfVersion(flags: VersionedReadFlags | undefined): Promise<ObjSource>;
@@ -37,11 +37,17 @@ class NodeInFS {
37
37
  return this.currentVersion;
38
38
  }
39
39
  setCurrentVersion(newVersion) {
40
- if (!Number.isInteger(newVersion)) {
41
- throw new TypeError(`Version parameter must be an integer, but ${newVersion} is given`);
40
+ if (!Number.isInteger(newVersion) || (newVersion < 0)) {
41
+ throw new TypeError(`Version parameter must be a non-negative integer, but ${newVersion} is given`);
42
42
  }
43
43
  this.currentVersion = newVersion;
44
44
  }
45
+ markRemoved() {
46
+ this.currentVersion = -1;
47
+ }
48
+ get isMarkedRemoved() {
49
+ return (this.currentVersion < 0);
50
+ }
45
51
  constructor(storage, type, name, objId, currentVersion, parentId) {
46
52
  this.storage = storage;
47
53
  this.type = type;
@@ -184,12 +190,12 @@ class NodeInFS {
184
190
  return this.doChange(true, () => this.removeThisFromStorageNodes(src));
185
191
  }
186
192
  async removeThisFromStorageNodes(src) {
187
- if (this.currentVersion < 0) {
193
+ if (this.isMarkedRemoved) {
188
194
  return;
189
195
  }
190
196
  await this.storage.removeObj(this.objId);
191
197
  this.storage.nodes.delete(this);
192
- this.currentVersion = -1;
198
+ this.markRemoved();
193
199
  const event = {
194
200
  type: 'removed',
195
201
  path: this.name,
@@ -217,7 +223,7 @@ class NodeInFS {
217
223
  throw (0, runtime_1.makeRuntimeException)('file', { path: this.name, fsEtityType: this.type }, { concurrentUpdate: true });
218
224
  }
219
225
  const res = await this.writeProc.startOrChain(async () => {
220
- if (this.currentVersion < 0) {
226
+ if (this.isMarkedRemoved) {
221
227
  throw (0, runtime_1.makeRuntimeException)('file', {
222
228
  path: this.name, fsEtityType: this.type,
223
229
  message: `NodeInFS is marked removed`
@@ -38,15 +38,12 @@ function makeJsonCommPoint(ws) {
38
38
  const observers = new generic_ipc_1.MultiObserverWrap();
39
39
  const { heartbeat, healthyBeat, otherBeat } = makeHeartbeat(ws.url);
40
40
  ws.on('message', data => {
41
- if (typeof data !== 'string') {
42
- return;
43
- }
44
41
  if (observers.done) {
45
42
  return;
46
43
  }
47
44
  let env;
48
45
  try {
49
- env = JSON.parse(data);
46
+ env = JSON.parse(data.toString('utf8'));
50
47
  }
51
48
  catch (err) {
52
49
  ws.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.43.3",
3
+ "version": "0.43.5",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",
@@ -32,13 +32,13 @@
32
32
  "protobufjs": "^7.0.1",
33
33
  "punycode": "^2.1.1",
34
34
  "rxjs": "^7.5.7",
35
- "ws": "^7.4.6",
35
+ "ws": "^8.18.3",
36
36
  "xsp-files": "^4.2.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/jasmine": "^3.9.1",
40
40
  "@types/node": "^16.11.7",
41
- "@types/ws": "^7.4.7",
41
+ "@types/ws": "^8.18.1",
42
42
  "jasmine": "^3.9.0",
43
43
  "protobufjs-cli": "^1.0.2",
44
44
  "spec-3nweb-server": "^1.8.0",