core-3nweb-client-lib 0.27.3 → 0.27.4

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.
Files changed (45) hide show
  1. package/build/api-defs/files.d.ts +52 -19
  2. package/build/core/asmail/config/index.d.ts +2 -2
  3. package/build/core/asmail/config/index.js +2 -2
  4. package/build/core/asmail/config/invitations-anon.d.ts +10 -24
  5. package/build/core/asmail/config/invitations-anon.js +43 -31
  6. package/build/core/asmail/config/published-intro-key.d.ts +11 -22
  7. package/build/core/asmail/config/published-intro-key.js +47 -38
  8. package/build/core/asmail/inbox/index.js +1 -1
  9. package/build/core/asmail/index.d.ts +1 -1
  10. package/build/core/asmail/index.js +2 -2
  11. package/build/core/asmail/keyring/correspondent-keys.d.ts +2 -2
  12. package/build/core/asmail/keyring/correspondent-keys.js +1 -1
  13. package/build/core/asmail/keyring/index.d.ts +9 -29
  14. package/build/core/asmail/keyring/index.js +82 -69
  15. package/build/core/index.js +1 -2
  16. package/build/core/sign-in.js +1 -1
  17. package/build/core/storage/synced/obj-files.d.ts +2 -0
  18. package/build/core/storage/synced/obj-files.js +18 -1
  19. package/build/core/storage/synced/obj-status.d.ts +1 -0
  20. package/build/core/storage/synced/obj-status.js +10 -0
  21. package/build/core/storage/synced/storage.js +4 -21
  22. package/build/ipc-via-protobuf/file.d.ts +7 -0
  23. package/build/ipc-via-protobuf/file.js +60 -27
  24. package/build/ipc-via-protobuf/fs.js +55 -38
  25. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +5 -10
  26. package/build/lib-client/3nstorage/xsp-fs/file-node.js +43 -45
  27. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +7 -6
  28. package/build/lib-client/3nstorage/xsp-fs/file.js +12 -18
  29. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +5 -0
  30. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +7 -1
  31. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +18 -17
  32. package/build/lib-client/3nstorage/xsp-fs/fs.js +17 -18
  33. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +11 -2
  34. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +56 -5
  35. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  36. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  37. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +5 -2
  38. package/build/lib-client/objs-on-disk/obj-on-disk.js +16 -1
  39. package/build/lib-common/objs-on-disk/file-layout.js +1 -1
  40. package/build/protos/asmail.proto.js +5943 -4348
  41. package/build/protos/file.proto.js +874 -0
  42. package/build/protos/fs.proto.js +7014 -5419
  43. package/package.json +1 -1
  44. package/protos/file.proto +23 -7
  45. package/protos/fs.proto +27 -13
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2018 3NSoft Inc.
3
+ Copyright (C) 2015 - 2018, 2022 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.KeyRing = exports.KEY_USE = void 0;
19
+ exports.makeAndKeyRing = exports.KEY_USE = void 0;
20
20
  const correspondent_keys_1 = require("./correspondent-keys");
21
21
  const id_to_email_map_1 = require("./id-to-email-map");
22
22
  const common_1 = require("./common");
@@ -27,9 +27,14 @@ const buffer_utils_1 = require("../../../lib-common/buffer-utils");
27
27
  const canonical_address_1 = require("../../../lib-common/canonical-address");
28
28
  const common_2 = require("../delivery/common");
29
29
  const keyring_storage_1 = require("./keyring-storage");
30
+ const assert_1 = require("../../../lib-common/assert");
30
31
  var common_3 = require("./common");
31
32
  Object.defineProperty(exports, "KEY_USE", { enumerable: true, get: function () { return common_3.KEY_USE; } });
32
- class KeyRing {
33
+ function makeAndKeyRing(cryptor, fs, publishedKeys) {
34
+ return KRing.makeAndStart(cryptor, fs, publishedKeys);
35
+ }
36
+ exports.makeAndKeyRing = makeAndKeyRing;
37
+ class KRing {
33
38
  constructor(cryptor, publishedKeys) {
34
39
  this.cryptor = cryptor;
35
40
  this.publishedKeys = publishedKeys;
@@ -39,7 +44,11 @@ class KeyRing {
39
44
  this.corrKeys = new Map();
40
45
  this.pairIdToEmailMap = new id_to_email_map_1.IdToEmailMap();
41
46
  this.storage = undefined;
42
- this.needIntroKeyFor = (address) => {
47
+ this.asKeyPairsStorage = {
48
+ pairIdToEmailMap: this.pairIdToEmailMap,
49
+ saveChanges: this.saveChanges.bind(this)
50
+ };
51
+ this.needIntroKeyFor = address => {
43
52
  address = (0, canonical_address_1.toCanonicalAddress)(address);
44
53
  return !this.corrKeys.has(address);
45
54
  };
@@ -68,65 +77,14 @@ class KeyRing {
68
77
  const suggestPair = await ck.suggestPair();
69
78
  return suggestPair;
70
79
  };
71
- this.decrypt = async (msgMeta, getMainObjHeader, getOpenedMsg, checkMidKeyCerts) => {
72
- let decrInfo;
73
- let incrMsgCount;
74
- let openedMsg;
75
- if (msgMeta.pid) {
76
- const r = await this.decryptMsgKeyWithEstablishedPair(msgMeta.pid, getMainObjHeader);
77
- if (!r) {
78
- return;
79
- }
80
- decrInfo = r.keyInfo;
81
- incrMsgCount = r.incrMsgCount;
82
- openedMsg = await getOpenedMsg(decrInfo.key, decrInfo.msgKeyPackLen);
83
- }
84
- else {
85
- decrInfo = await this.decryptMsgKeyWithIntroPair(msgMeta.recipientKid, msgMeta.senderPKey, getMainObjHeader);
86
- if (!decrInfo) {
87
- return;
88
- }
89
- openedMsg = await getOpenedMsg(decrInfo.key, decrInfo.msgKeyPackLen);
90
- const certs = openedMsg.introCryptoCerts;
91
- const { address, pkey } = await checkMidKeyCerts(certs);
92
- if (pkey.k !== msgMeta.senderPKey) {
93
- throw new Error(`Key certificates in the message are not for a key that encrypted this message.`);
94
- }
95
- decrInfo.correspondent = (0, canonical_address_1.toCanonicalAddress)(address);
96
- }
97
- // check that sender is the same as the trusted correspondent
98
- const sender = openedMsg.sender;
99
- if (!sender || !(0, canonical_address_1.areAddressesEqual)(sender, decrInfo.correspondent)) {
100
- throw new Error(`Mismatch between message sender field '${sender}', and address '${decrInfo.correspondent}', associated with decrypting key.`);
101
- }
102
- // update received msg counts and a time stamp
103
- if (incrMsgCount) {
104
- incrMsgCount(openedMsg.msgCount);
105
- }
106
- // absorb next crypto
107
- const pair = openedMsg.nextCrypto;
108
- if (pair) {
109
- if (msgMeta.recipientKid) {
110
- if (!pair.isSenderIntroKey) {
111
- throw new Error(`Introductory message is not referencing used intro key in the next crypto`);
112
- }
113
- if (msgMeta.recipientKid !== pair.senderKid) {
114
- throw new Error(`Introductory message is referencing wrong key in the next crypto`);
115
- }
116
- }
117
- this.absorbSuggestedNextKeyPair(decrInfo.correspondent, pair);
118
- }
119
- return { decrInfo, openedMsg };
120
- };
121
80
  Object.seal(this);
122
81
  }
123
82
  addCorrespondent(address, serialForm) {
124
83
  const ck = (serialForm ?
125
- new correspondent_keys_1.CorrespondentKeys(this, undefined, serialForm) :
126
- new correspondent_keys_1.CorrespondentKeys(this, address));
84
+ new correspondent_keys_1.CorrespondentKeys(this.asKeyPairsStorage, undefined, serialForm) :
85
+ new correspondent_keys_1.CorrespondentKeys(this.asKeyPairsStorage, address));
127
86
  if (this.corrKeys.has(ck.correspondent)) {
128
- throw new Error("Correspondent with address " + ck.correspondent +
129
- " is already present.");
87
+ throw new Error(`Correspondent with address ${ck.correspondent} is already present.`);
130
88
  }
131
89
  this.corrKeys.set(ck.correspondent, ck);
132
90
  if (serialForm) {
@@ -135,9 +93,7 @@ class KeyRing {
135
93
  return ck;
136
94
  }
137
95
  async init(fs) {
138
- if (this.storage) {
139
- throw new Error("Keyring has already been initialized.");
140
- }
96
+ (0, assert_1.assert)(!this.storage);
141
97
  this.storage = (0, keyring_storage_1.makeKeyringStorage)(fs);
142
98
  await this.storage.start();
143
99
  const serialForm = await this.storage.load();
@@ -155,9 +111,15 @@ class KeyRing {
155
111
  }
156
112
  }
157
113
  static async makeAndStart(cryptor, fs, publishedKeys) {
158
- const kr = new KeyRing(cryptor, publishedKeys);
114
+ const kr = new KRing(cryptor, publishedKeys);
159
115
  await kr.init(fs);
160
- return kr;
116
+ return {
117
+ close: kr.close.bind(kr),
118
+ decrypt: kr.decrypt.bind(kr),
119
+ generateKeysToSend: kr.generateKeysToSend.bind(kr),
120
+ needIntroKeyFor: kr.needIntroKeyFor.bind(kr),
121
+ nextCrypto: kr.nextCrypto.bind(kr)
122
+ };
161
123
  }
162
124
  saveChanges() {
163
125
  // pack bytes that need to be encrypted and saved
@@ -253,9 +215,10 @@ class KeyRing {
253
215
  const corrKeys = this.corrKeys.get(keyInfo.correspondent);
254
216
  corrKeys.markPairAsInUse(pair);
255
217
  }
256
- // prepare msg count incrementor that will be "called back"
257
- const incrMsgCount = (msgCount) => this.updateReceivedMsgCountIn(pair, msgCount);
258
- return { keyInfo, incrMsgCount };
218
+ return {
219
+ keyInfo,
220
+ incrMsgCount: msgCount => this.updateReceivedMsgCountIn(pair, msgCount)
221
+ };
259
222
  }
260
223
  catch (err) {
261
224
  if (!err.failedCipherVerification) {
@@ -301,13 +264,63 @@ class KeyRing {
301
264
  }
302
265
  this.saveChanges();
303
266
  }
267
+ async decrypt(msgMeta, getMainObjHeader, getOpenedMsg, checkMidKeyCerts) {
268
+ let decrInfo;
269
+ let incrMsgCount;
270
+ let openedMsg;
271
+ if (msgMeta.pid) {
272
+ const r = await this.decryptMsgKeyWithEstablishedPair(msgMeta.pid, getMainObjHeader);
273
+ if (!r) {
274
+ return;
275
+ }
276
+ decrInfo = r.keyInfo;
277
+ incrMsgCount = r.incrMsgCount;
278
+ openedMsg = await getOpenedMsg(decrInfo.key, decrInfo.msgKeyPackLen);
279
+ }
280
+ else {
281
+ decrInfo = await this.decryptMsgKeyWithIntroPair(msgMeta.recipientKid, msgMeta.senderPKey, getMainObjHeader);
282
+ if (!decrInfo) {
283
+ return;
284
+ }
285
+ openedMsg = await getOpenedMsg(decrInfo.key, decrInfo.msgKeyPackLen);
286
+ const certs = openedMsg.introCryptoCerts;
287
+ const { address, pkey } = await checkMidKeyCerts(certs);
288
+ if (pkey.k !== msgMeta.senderPKey) {
289
+ throw new Error(`Key certificates in the message are not for a key that encrypted this message.`);
290
+ }
291
+ decrInfo.correspondent = (0, canonical_address_1.toCanonicalAddress)(address);
292
+ }
293
+ // check that sender is the same as the trusted correspondent
294
+ const sender = openedMsg.sender;
295
+ if (!sender || !(0, canonical_address_1.areAddressesEqual)(sender, decrInfo.correspondent)) {
296
+ throw new Error(`Mismatch between message sender field '${sender}', and address '${decrInfo.correspondent}', associated with decrypting key.`);
297
+ }
298
+ // update received msg counts and a time stamp
299
+ if (incrMsgCount) {
300
+ incrMsgCount(openedMsg.msgCount);
301
+ }
302
+ // absorb next crypto
303
+ const pair = openedMsg.nextCrypto;
304
+ if (pair) {
305
+ if (msgMeta.recipientKid) {
306
+ if (!pair.isSenderIntroKey) {
307
+ throw new Error(`Introductory message is not referencing used intro key in the next crypto`);
308
+ }
309
+ if (msgMeta.recipientKid !== pair.senderKid) {
310
+ throw new Error(`Introductory message is referencing wrong key in the next crypto`);
311
+ }
312
+ }
313
+ this.absorbSuggestedNextKeyPair(decrInfo.correspondent, pair);
314
+ }
315
+ return { decrInfo, openedMsg };
316
+ }
317
+ ;
304
318
  close() {
305
319
  return this.storage.close();
306
320
  }
307
321
  }
308
- exports.KeyRing = KeyRing;
309
- Object.freeze(KeyRing.prototype);
310
- Object.freeze(KeyRing);
322
+ Object.freeze(KRing.prototype);
323
+ Object.freeze(KRing);
311
324
  function msgKeyPackLenForPair(p) {
312
325
  return (0, common_1.msgKeyPackSizeFor)(p.recipientKey.skey.alg);
313
326
  }
@@ -225,8 +225,7 @@ function makeStoragePolicy(appDomain, requestedCAPs) {
225
225
  }
226
226
  else if (Array.isArray(capReq.appFS)) {
227
227
  const okDomains = capReq.appFS
228
- .filter(fsInfo => (fsInfo.domain === appDomain) ||
229
- fsInfo.domain.endsWith('.' + appDomain))
228
+ .filter(fsInfo => (fsInfo.domain === appDomain) || fsInfo.domain.endsWith('.' + appDomain))
230
229
  .map(fsInfo => (0, json_utils_1.copy)(fsInfo));
231
230
  policy = {
232
231
  canOpenAppFS: severalDomainsAppFSChecker(okDomains)
@@ -45,7 +45,7 @@ class SignIn {
45
45
  const midKeyProgressCB = makeKeyGenProgressCB(0, 50, progressCB);
46
46
  const midKeyGen = async (params) => (await (0, key_derivation_1.deriveMidKeyPair)(this.cryptor, pass, params, midKeyProgressCB)).skey;
47
47
  const storeKeyProgressCB = makeKeyGenProgressCB(51, 100, progressCB);
48
- const storeKeyGen = (params) => (0, key_derivation_1.deriveStorageSKey)(this.cryptor, pass, params, storeKeyProgressCB);
48
+ const storeKeyGen = params => (0, key_derivation_1.deriveStorageSKey)(this.cryptor, pass, params, storeKeyProgressCB);
49
49
  const idManager = await this.completeInitWithoutCache(midKeyGen, storeKeyGen);
50
50
  if (!idManager) {
51
51
  return false;
@@ -89,4 +89,6 @@ export declare class SyncedObj {
89
89
  syncStatus(): SyncedObjStatus;
90
90
  statusObj(): ObjStatus;
91
91
  recordRemovalUploadAndGC(): Promise<void>;
92
+ isRemoteVersionOnDisk(version: number): Promise<'complete' | 'partial' | 'none'>;
93
+ downloadRemoteVersion(version: number): Promise<void>;
92
94
  }
@@ -32,6 +32,7 @@ const obj_status_1 = require("./obj-status");
32
32
  const timed_cache_1 = require("../../../lib-common/timed-cache");
33
33
  const upload_header_file_1 = require("./upload-header-file");
34
34
  const utils_1 = require("../common/utils");
35
+ const exceptions_1 = require("../../../lib-client/3nstorage/exceptions");
35
36
  exports.UNSYNCED_FILE_NAME_EXT = 'unsynced';
36
37
  exports.REMOTE_FILE_NAME_EXT = 'v';
37
38
  /**
@@ -338,7 +339,8 @@ class SyncedObj {
338
339
  this.remoteVers.set(uploadVersion, syncedVerObj);
339
340
  }
340
341
  else {
341
- await fs.rename(this.localVerPath(localVersion), remotePath);
342
+ const localPath = this.localVerPath(localVersion);
343
+ await fs.rename(localPath, remotePath);
342
344
  }
343
345
  await this.status.recordUploadCompletion(localVersion, uploadVersion);
344
346
  this.scheduleSelfGC();
@@ -395,6 +397,21 @@ class SyncedObj {
395
397
  await this.status.recordRemoteRemovalCompletion();
396
398
  this.scheduleSelfGC();
397
399
  }
400
+ async isRemoteVersionOnDisk(version) {
401
+ if (!this.status.isAmongRemote(version)) {
402
+ throw (0, exceptions_1.makeObjVersionNotFoundExc)(this.objId, version);
403
+ }
404
+ const verPath = this.remoteVerPath(version);
405
+ if (!(await isOnDisk(verPath))) {
406
+ return 'none';
407
+ }
408
+ const objVer = await this.instanceOfRemoteObjVer(version);
409
+ return (objVer.doesFileNeedDownload() ? 'complete' : 'partial');
410
+ }
411
+ async downloadRemoteVersion(version) {
412
+ const objVer = await this.instanceOfRemoteObjVer(version);
413
+ await objVer.downloadMissingSections();
414
+ }
398
415
  }
399
416
  exports.SyncedObj = SyncedObj;
400
417
  Object.freeze(SyncedObj.prototype);
@@ -125,6 +125,7 @@ export declare class ObjStatus implements SyncedObjStatus, UploadStatusRecorder
125
125
  neverUploaded(): boolean;
126
126
  versionBeforeUnsyncedRemoval(): number | undefined;
127
127
  adoptRemoteVersion(version?: number, dropLocalVer?: boolean): Promise<void>;
128
+ isAmongRemote(version: number): boolean;
128
129
  }
129
130
  export declare function readAndCheckStatus(objFolder: string, objId: ObjId): Promise<ObjStatusInfo>;
130
131
  export {};
@@ -551,6 +551,16 @@ class ObjStatus {
551
551
  this.updateStateIndicator();
552
552
  await this.triggerSaveProc();
553
553
  }
554
+ isAmongRemote(version) {
555
+ var _a;
556
+ if (this.status.remote.current === version) {
557
+ return true;
558
+ }
559
+ if ((_a = this.status.remote.archived) === null || _a === void 0 ? void 0 : _a.includes(version)) {
560
+ return true;
561
+ }
562
+ return false;
563
+ }
554
564
  }
555
565
  exports.ObjStatus = ObjStatus;
556
566
  Object.freeze(ObjStatus.prototype);
@@ -47,8 +47,6 @@ class SyncedStore {
47
47
  const objFiles = await obj_files_1.ObjFiles.makeFor(path, remote, logError);
48
48
  const s = new SyncedStore(objFiles, remote, getStorages, cryptor, logError);
49
49
  s.uploader.start();
50
- // XXX ??
51
- // s.remoteEvents.startAbsorbingRemoteEvents();
52
50
  return {
53
51
  syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
54
52
  startObjProcs: () => {
@@ -60,8 +58,6 @@ class SyncedStore {
60
58
  const { remote, setMid } = service_1.StorageOwner.makeBeforeMidSetup(user, remoteServiceUrl, net);
61
59
  const objFiles = await obj_files_1.ObjFiles.makeFor(path, remote, logError);
62
60
  const s = new SyncedStore(objFiles, remote, getStorages, cryptor, logError);
63
- // XXX ??
64
- // s.remoteEvents.startAbsorbingRemoteEvents();
65
61
  return {
66
62
  syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
67
63
  setupRemoteAndStartObjProcs: getSigner => {
@@ -126,25 +122,12 @@ class SyncedStore {
126
122
  return !!obj;
127
123
  }
128
124
  async isRemoteVersionOnDisk(objId, version) {
129
- var _a;
130
125
  const obj = await this.getObjOrThrow(objId, true);
131
- const status = obj.statusObj();
132
- const { remote } = status.syncStatus();
133
- if (((remote === null || remote === void 0 ? void 0 : remote.latest) !== version)
134
- || !((_a = remote.archived) === null || _a === void 0 ? void 0 : _a.includes(version))) {
135
- throw (0, exceptions_1.makeObjVersionNotFoundExc)(objId, version);
136
- }
137
- // XXX
138
- // - get state of file
139
- throw new Error('SyncedStore.isRemoteVersionOnDisk() not implemented.');
126
+ return obj.isRemoteVersionOnDisk(version);
140
127
  }
141
- download(objId, version) {
142
- // XXX
143
- // - check if on disk
144
- // - download header
145
- // - want result of DC-296, calculation of diff to download, relative to
146
- // latest version on the disk, using headers of both versions.
147
- throw new Error('SyncedStore.download() not implemented.');
128
+ async download(objId, version) {
129
+ const obj = await this.getObjOrThrow(objId, true);
130
+ return obj.downloadRemoteVersion(version);
148
131
  }
149
132
  async upload(objId, localVersion, uploadVersion, uploadHeader, createOnRemote) {
150
133
  const obj = await this.getObjOrThrow(objId, true);
@@ -14,6 +14,7 @@ declare type FileEvent = web3n.files.FileEvent;
14
14
  declare type RemoteEvent = web3n.files.RemoteEvent;
15
15
  declare type OptionsToAdopteRemote = web3n.files.OptionsToAdopteRemote;
16
16
  declare type OptionsToUploadLocal = web3n.files.OptionsToUploadLocal;
17
+ declare type VersionedReadFlags = web3n.files.VersionedReadFlags;
17
18
  export declare function makeFileCaller(caller: Caller, fileMsg: FileMsg): File;
18
19
  export declare function exposeFileService(file: File, expServices: ExposedServices): FileMsg;
19
20
  export interface FileMsg {
@@ -41,6 +42,12 @@ export declare function packJSON(json: any): EnvelopeBody;
41
42
  export declare function unpackJSON(buf: EnvelopeBody): any;
42
43
  export declare function packFileEvent(e: FileEvent | RemoteEvent): Buffer;
43
44
  export declare function unpackFileEvent(buf: EnvelopeBody): FileEvent | RemoteEvent;
45
+ export interface VersionedReadFlagsMsg {
46
+ archivedVersion?: Value<number>;
47
+ remoteVersion?: Value<number>;
48
+ }
49
+ export declare function versionedReadFlagsFromMsg(msg: VersionedReadFlagsMsg | undefined): VersionedReadFlags | undefined;
50
+ export declare function versionedReadFlagsToMsg(flags: VersionedReadFlags | undefined): VersionedReadFlagsMsg | undefined;
44
51
  export declare namespace vGetXAttr {
45
52
  interface Reply {
46
53
  version: number;
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.vListVersions = exports.remoteAdoptionOptsFromMsg = exports.remoteAdoptionOptsToMsg = exports.optionsToUploadLocalFromMsg = exports.optionsToUploadLocalToMsg = exports.vGetByteSink = exports.updateXAttrs = exports.xattrFromMsg = exports.xattrToMsg = exports.vGetByteSource = exports.vReadJSON = exports.vReadTxt = exports.vReadBytes = exports.vListXAttrs = exports.vGetXAttr = exports.unpackFileEvent = exports.packFileEvent = exports.unpackJSON = exports.packJSON = exports.readBytes = exports.unpackXAttrValue = exports.packXAttrValue = exports.unpackSyncStatus = exports.packSyncStatus = exports.unpackStats = exports.packStats = exports.fileMsgType = exports.exposeFileService = exports.makeFileCaller = void 0;
19
+ exports.vListVersions = exports.remoteAdoptionOptsFromMsg = exports.remoteAdoptionOptsToMsg = exports.optionsToUploadLocalFromMsg = exports.optionsToUploadLocalToMsg = exports.vGetByteSink = exports.updateXAttrs = exports.xattrFromMsg = exports.xattrToMsg = exports.vGetByteSource = exports.vReadJSON = exports.vReadTxt = exports.vReadBytes = exports.vListXAttrs = exports.vGetXAttr = exports.versionedReadFlagsToMsg = exports.versionedReadFlagsFromMsg = exports.unpackFileEvent = exports.packFileEvent = exports.unpackJSON = exports.packJSON = exports.readBytes = exports.unpackXAttrValue = exports.packXAttrValue = exports.unpackSyncStatus = exports.packSyncStatus = exports.unpackStats = exports.packStats = exports.fileMsgType = exports.exposeFileService = exports.makeFileCaller = void 0;
20
20
  const protobuf_msg_1 = require("./protobuf-msg");
21
21
  const protobuf_type_1 = require("../lib-client/protobuf-type");
22
22
  const file_proto_1 = require("../protos/file.proto");
@@ -533,9 +533,29 @@ var watch;
533
533
  watch.makeCaller = makeCaller;
534
534
  })(watch || (watch = {}));
535
535
  Object.freeze(watch);
536
+ function versionedReadFlagsFromMsg(msg) {
537
+ if (!msg) {
538
+ return;
539
+ }
540
+ return {
541
+ archivedVersion: (0, protobuf_msg_1.valOfOptInt)(msg.archivedVersion),
542
+ remoteVersion: (0, protobuf_msg_1.valOfOptInt)(msg.remoteVersion)
543
+ };
544
+ }
545
+ exports.versionedReadFlagsFromMsg = versionedReadFlagsFromMsg;
546
+ function versionedReadFlagsToMsg(flags) {
547
+ if (!flags) {
548
+ return;
549
+ }
550
+ return {
551
+ archivedVersion: (0, protobuf_msg_1.toOptVal)(flags.archivedVersion),
552
+ remoteVersion: (0, protobuf_msg_1.toOptVal)(flags.remoteVersion)
553
+ };
554
+ }
555
+ exports.versionedReadFlagsToMsg = versionedReadFlagsToMsg;
536
556
  var vGetXAttr;
537
557
  (function (vGetXAttr) {
538
- const requestType = protobuf_type_1.ProtoType.for(file_proto_1.file.GetXAttrRequestBody);
558
+ const requestType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedGetXAttrRequestBody);
539
559
  vGetXAttr.replyType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedGetXAttrReplyBody);
540
560
  function unpackReply(buf) {
541
561
  const { json, str, bytes, version: v } = vGetXAttr.replyType.unpack(buf);
@@ -553,8 +573,8 @@ var vGetXAttr;
553
573
  vGetXAttr.unpackReply = unpackReply;
554
574
  function wrapService(fn) {
555
575
  return buf => {
556
- const { xaName } = requestType.unpack(buf);
557
- const promise = fn(xaName)
576
+ const { xaName, flags } = requestType.unpack(buf);
577
+ const promise = fn(xaName, versionedReadFlagsFromMsg(flags))
558
578
  .then(({ attr, version }) => {
559
579
  if (Buffer.isBuffer(attr)) {
560
580
  return vGetXAttr.replyType.pack({ version, bytes: (0, protobuf_msg_1.toVal)(attr) });
@@ -572,19 +592,31 @@ var vGetXAttr;
572
592
  vGetXAttr.wrapService = wrapService;
573
593
  function makeCaller(caller, objPath) {
574
594
  const path = objPath.concat('getXAttr');
575
- return () => caller
576
- .startPromiseCall(path, undefined)
595
+ return (xaName, flags) => caller
596
+ .startPromiseCall(path, requestType.pack({
597
+ xaName, flags: versionedReadFlagsToMsg(flags)
598
+ }))
577
599
  .then(unpackReply);
578
600
  }
579
601
  vGetXAttr.makeCaller = makeCaller;
580
602
  })(vGetXAttr = exports.vGetXAttr || (exports.vGetXAttr = {}));
581
603
  Object.freeze(vGetXAttr);
604
+ const requestWithReadFlags = protobuf_type_1.ProtoType.for(file_proto_1.file.RequestWithVersionedReadFlags);
605
+ function packVersionedReadFlagsRequest(flags) {
606
+ return requestWithReadFlags.pack({
607
+ flags: versionedReadFlagsToMsg(flags)
608
+ });
609
+ }
610
+ function unpackVersionedReadFlagsRequest(buf) {
611
+ const { flags } = requestWithReadFlags.unpack(buf);
612
+ return versionedReadFlagsFromMsg(flags);
613
+ }
582
614
  var vListXAttrs;
583
615
  (function (vListXAttrs) {
584
616
  vListXAttrs.replyType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedListXAttrsReplyBody);
585
617
  function wrapService(fn) {
586
- return () => {
587
- const promise = fn()
618
+ return buf => {
619
+ const promise = fn(unpackVersionedReadFlagsRequest(buf))
588
620
  .then(({ version, lst }) => vListXAttrs.replyType.pack({ version, xaNames: lst }));
589
621
  return { promise };
590
622
  };
@@ -592,8 +624,8 @@ var vListXAttrs;
592
624
  vListXAttrs.wrapService = wrapService;
593
625
  function makeCaller(caller, objPath) {
594
626
  const path = objPath.concat('listXAttrs');
595
- return () => caller
596
- .startPromiseCall(path, undefined)
627
+ return flags => caller
628
+ .startPromiseCall(path, packVersionedReadFlagsRequest(flags))
597
629
  .then(buf => {
598
630
  const { xaNames, version: v } = vListXAttrs.replyType.unpack(buf);
599
631
  return { version: (0, protobuf_msg_1.fixInt)(v), lst: (xaNames ? xaNames : []) };
@@ -604,7 +636,7 @@ var vListXAttrs;
604
636
  Object.freeze(vListXAttrs);
605
637
  var vReadBytes;
606
638
  (function (vReadBytes) {
607
- const requestType = protobuf_type_1.ProtoType.for(file_proto_1.file.ReadBytesRequestBody);
639
+ const requestType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedReadBytesRequestBody);
608
640
  const replyType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedReadBytesReplyBody);
609
641
  function packReply(r) {
610
642
  return replyType.pack({
@@ -619,8 +651,8 @@ var vReadBytes;
619
651
  vReadBytes.unpackReply = unpackReply;
620
652
  function wrapService(fn) {
621
653
  return buf => {
622
- const { start, end } = requestType.unpack(buf);
623
- const promise = fn((0, protobuf_msg_1.valOfOptInt)(start), (0, protobuf_msg_1.valOfOptInt)(end))
654
+ const { start, end, flags } = requestType.unpack(buf);
655
+ const promise = fn((0, protobuf_msg_1.valOfOptInt)(start), (0, protobuf_msg_1.valOfOptInt)(end), versionedReadFlagsFromMsg(flags))
624
656
  .then(packReply);
625
657
  return { promise };
626
658
  };
@@ -628,9 +660,10 @@ var vReadBytes;
628
660
  vReadBytes.wrapService = wrapService;
629
661
  function makeCaller(caller, objPath) {
630
662
  const path = objPath.concat('readBytes');
631
- return (start, end) => caller
663
+ return (start, end, flags) => caller
632
664
  .startPromiseCall(path, requestType.pack({
633
- start: (0, protobuf_msg_1.toOptVal)(start), end: (0, protobuf_msg_1.toOptVal)(end)
665
+ start: (0, protobuf_msg_1.toOptVal)(start), end: (0, protobuf_msg_1.toOptVal)(end),
666
+ flags: versionedReadFlagsToMsg(flags)
634
667
  }))
635
668
  .then(unpackReply);
636
669
  }
@@ -641,8 +674,8 @@ var vReadTxt;
641
674
  (function (vReadTxt) {
642
675
  vReadTxt.replyType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedReadTxtReplyBody);
643
676
  function wrapService(fn) {
644
- return () => {
645
- const promise = fn()
677
+ return buf => {
678
+ const promise = fn(unpackVersionedReadFlagsRequest(buf))
646
679
  .then(verAndTxt => vReadTxt.replyType.pack(verAndTxt));
647
680
  return { promise };
648
681
  };
@@ -650,8 +683,8 @@ var vReadTxt;
650
683
  vReadTxt.wrapService = wrapService;
651
684
  function makeCaller(caller, objPath) {
652
685
  const path = objPath.concat('readTxt');
653
- return () => caller
654
- .startPromiseCall(path, undefined)
686
+ return flags => caller
687
+ .startPromiseCall(path, packVersionedReadFlagsRequest(flags))
655
688
  .then(buf => {
656
689
  const { version: v, txt } = vReadTxt.replyType.unpack(buf);
657
690
  return { version: (0, protobuf_msg_1.fixInt)(v), txt };
@@ -664,8 +697,8 @@ var vReadJSON;
664
697
  (function (vReadJSON) {
665
698
  vReadJSON.replyType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedReadJsonReplyBody);
666
699
  function wrapService(fn) {
667
- return () => {
668
- const promise = fn()
700
+ return buf => {
701
+ const promise = fn(unpackVersionedReadFlagsRequest(buf))
669
702
  .then(({ version, json }) => {
670
703
  return vReadJSON.replyType.pack({ version, json: JSON.stringify(json) });
671
704
  });
@@ -675,8 +708,8 @@ var vReadJSON;
675
708
  vReadJSON.wrapService = wrapService;
676
709
  function makeCaller(caller, objPath) {
677
710
  const path = objPath.concat('readJSON');
678
- return () => caller
679
- .startPromiseCall(path, undefined)
711
+ return flags => caller
712
+ .startPromiseCall(path, packVersionedReadFlagsRequest(flags))
680
713
  .then(buf => {
681
714
  const { version: v, json } = vReadJSON.replyType.unpack(buf);
682
715
  try {
@@ -694,8 +727,8 @@ var vGetByteSource;
694
727
  (function (vGetByteSource) {
695
728
  vGetByteSource.replyType = protobuf_type_1.ProtoType.for(file_proto_1.file.VersionedGetByteSourceReplyBody);
696
729
  function wrapService(fn, expServices) {
697
- return () => {
698
- const promise = fn()
730
+ return buf => {
731
+ const promise = fn(unpackVersionedReadFlagsRequest(buf))
699
732
  .then(({ version, src }) => {
700
733
  const ref = (0, bytes_1.exposeSrcService)(src, expServices);
701
734
  return vGetByteSource.replyType.pack({ version, src: ref });
@@ -706,8 +739,8 @@ var vGetByteSource;
706
739
  vGetByteSource.wrapService = wrapService;
707
740
  function makeCaller(caller, objPath) {
708
741
  const path = objPath.concat('getByteSource');
709
- return () => caller
710
- .startPromiseCall(path, undefined)
742
+ return flags => caller
743
+ .startPromiseCall(path, packVersionedReadFlagsRequest(flags))
711
744
  .then(buf => {
712
745
  const { version: v, src: ref } = vGetByteSource.replyType.unpack(buf);
713
746
  return { version: (0, protobuf_msg_1.fixInt)(v), src: (0, bytes_1.makeSrcCaller)(caller, ref) };