@lifeready/core 1.1.7 → 1.1.9

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.
@@ -3169,6 +3169,47 @@
3169
3169
  _this.variables = options.variables;
3170
3170
  return _this;
3171
3171
  }
3172
+ /**
3173
+ * Select a different set of fields from the mutation. Example usage:
3174
+ *
3175
+ * interface CreateDirectoryMutationResult {
3176
+ * createDirectory: {
3177
+ * directory: DirectoryNode;
3178
+ * };
3179
+ * };
3180
+ *
3181
+ * const CreateDirectoryMutation = gqlTyped<CreateDirectoryMutationResult>`
3182
+ * mutation CreateDirectoryMutation(...) {
3183
+ * createDirectory(...) {
3184
+ * directory {
3185
+ * id
3186
+ * }
3187
+ * }
3188
+ * }
3189
+ * `
3190
+ * interface CreateDirectoryFragmentResult {
3191
+ * createDirectory: {
3192
+ * directory: DirectoryNode;
3193
+ * };
3194
+ * };
3195
+ *
3196
+ * const CreateDirectoryFragment = gqlTyped<CreateDirectoryFragmentResult>`
3197
+ * // Note that the string 'createDirectory' can not be changed.
3198
+ * // It must match with the mutation field above.
3199
+ * // The 'CreateDirectoryPayload' is the return type of the mutation.
3200
+ * fragment createDirectory on CreateDirectoryPayload {
3201
+ * directory {
3202
+ * plainMeta
3203
+ * }
3204
+ * }
3205
+ * `
3206
+ * lrGraphQLService.lrMutate({
3207
+ * mutation: CreateDirectoryMutation
3208
+ * }).select(CreateDirectoryFragment).createDirectory.directory.plainMeta.
3209
+ *
3210
+ * @param fragments
3211
+ * @returns
3212
+ */
3172
3213
  LrMutation.prototype.select = function (fragments) {
3173
3214
  // Don't touch the original
3174
3215
  var mutationDoc = _.cloneDeep(this.mutation);
@@ -3383,7 +3424,6 @@
3383
3424
  // Rename and merge selections
3384
3425
  selections = __spread(selections, _this.renameSelections(childMutationNode.selectionSet.selections, prefix));
3385
3426
  try {
3386
- // TODO Rename and merge fragments
3387
3427
  // Rename and merge variables
3388
3428
  for (var _c = __values(Object.keys(variables)), _d = _c.next(); !_d.done; _d = _c.next()) {
3389
3429
  var key2 = _d.value;
@@ -3436,7 +3476,7 @@
3436
3476
  }
3437
3477
  LrGraphQLService.prototype.query = function (options) {
3438
3478
  return __awaiter(this, void 0, void 0, function () {
3439
- var includeKeyGraph, operation, response, data;
3479
+ var includeKeyGraph, operation, operation, response, data;
3440
3480
  return __generator(this, function (_a) {
3441
3481
  switch (_a.label) {
3442
3482
  case 0:
@@ -3449,6 +3489,13 @@
3449
3489
  keyGraphFieldAstSelection,
3450
3490
  ]);
3451
3491
  }
3492
+ if (options.name) {
3493
+ operation = getQuery(options.query);
3494
+ operation.name = {
3495
+ kind: 'Name',
3496
+ value: options.name,
3497
+ };
3498
+ }
3452
3499
  return [4 /*yield*/, this.apollo.query(options).toPromise()];
3453
3500
  case 1:
3454
3501
  response = _a.sent();
@@ -3489,7 +3536,7 @@
3489
3536
  };
3490
3537
  LrGraphQLService.prototype.apolloMutate = function (options) {
3491
3538
  return __awaiter(this, void 0, void 0, function () {
3492
- var includeKeyGraph, operation, response, data;
3539
+ var includeKeyGraph, operation, operation, response, data;
3493
3540
  return __generator(this, function (_a) {
3494
3541
  switch (_a.label) {
3495
3542
  case 0:
@@ -3502,6 +3549,13 @@
3502
3549
  fetchKeyGraphFieldAstSelection,
3503
3550
  ]);
3504
3551
  }
3552
+ if (options.name) {
3553
+ operation = getMutation(options.mutation);
3554
+ operation.name = {
3555
+ kind: 'Name',
3556
+ value: options.name,
3557
+ };
3558
+ }
3505
3559
  // Format to string and parse again. This allows the "loc": { "start": ... }
3506
3560
  // part of the DocumentNode to be correctly setup. It's extra processing
3507
3561
  // in serialising and parsing, but probably minimal overhead.
@@ -6150,6 +6204,9 @@
6150
6204
  this.assemblyController = assemblyController;
6151
6205
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6152
6206
  this.hubSubject = new rxjs.ReplaySubject(1);
6207
+ // Could use rxjs observables here. But trying to have kc-client use as little angular
6208
+ // features as possible. Rxjs is not used anywhere else in kc-client.
6209
+ this.logoutListeners = new Set();
6153
6210
  }
6154
6211
  LifeReadyAuthService.prototype.initialise = function () {
6155
6212
  return __awaiter(this, void 0, void 0, function () {
@@ -6160,6 +6217,12 @@
6160
6217
  });
6161
6218
  });
6162
6219
  };
6220
+ LifeReadyAuthService.prototype.addLogoutListener = function (callback) {
6221
+ this.logoutListeners.add(callback);
6222
+ };
6223
+ LifeReadyAuthService.prototype.removeLogoutListener = function (callback) {
6224
+ this.logoutListeners.delete(callback);
6225
+ };
6163
6226
  LifeReadyAuthService.prototype.loginIdpImpl = function (emailOrPhone, password, passIdpParams, recoveryStatus) {
6164
6227
  return __awaiter(this, void 0, void 0, function () {
6165
6228
  var passIdpResult, user;
@@ -6541,12 +6604,17 @@
6541
6604
  return __awaiter(this, void 0, void 0, function () {
6542
6605
  return __generator(this, function (_b) {
6543
6606
  switch (_b.label) {
6544
- case 0:
6607
+ case 0:
6608
+ // Notify all listeners to clean up.
6609
+ return [4 /*yield*/, Promise.all(__spread(this.logoutListeners).map(function (callback) { return callback(); }))];
6610
+ case 1:
6611
+ // Notify all listeners to clean up.
6612
+ _b.sent();
6545
6613
  this.currentUser = null;
6546
6614
  this.keyService.purgeKeys();
6547
6615
  this.keyGraphService.purgeKeys();
6548
6616
  return [4 /*yield*/, Promise.all([this.auth.signOut(), this.profileService.signOut()])];
6549
- case 1:
6617
+ case 2:
6550
6618
  _b.sent();
6551
6619
  return [2 /*return*/];
6552
6620
  }
@@ -7884,7 +7952,7 @@
7884
7952
  var CreateDirectoryMutation = gqlTyped(templateObject_1$g || (templateObject_1$g = __makeTemplateObject(["\nmutation CreateDirectoryMutation($input: CreateDirectoryInput!) {\n createDirectory(input: $input) {\n directory {\n id\n keyId\n }\n }\n}\n"], ["\nmutation CreateDirectoryMutation($input: CreateDirectoryInput!) {\n createDirectory(input: $input) {\n directory {\n id\n keyId\n }\n }\n}\n"])));
7885
7953
  var UpdateDirectoryMutation = gqlTyped(templateObject_2$d || (templateObject_2$d = __makeTemplateObject(["\nmutation UpdateDirectoryMutation($input: UpdateDirectoryInput!) {\n updateDirectory(input: $input) {\n directory {\n id\n modified\n }\n }\n}\n"], ["\nmutation UpdateDirectoryMutation($input: UpdateDirectoryInput!) {\n updateDirectory(input: $input) {\n directory {\n id\n modified\n }\n }\n}\n"])));
7886
7954
  var DeleteDirectoryMutation = gqlTyped(templateObject_3$b || (templateObject_3$b = __makeTemplateObject(["\nmutation DeleteDirectoryMutation($input: DeleteDirectoryInput!) {\n deleteDirectory(input: $input) {\n id\n }\n}\n"], ["\nmutation DeleteDirectoryMutation($input: DeleteDirectoryInput!) {\n deleteDirectory(input: $input) {\n id\n }\n}\n"])));
7887
- var CreateFileMutation$1 = gqlTyped(templateObject_4$8 || (templateObject_4$8 = __makeTemplateObject(["\nmutation CreateFileMutation($input: CreateFileInput!) {\n createFile(input: $input) {\n file {\n id\n }\n }\n}\n"], ["\nmutation CreateFileMutation($input: CreateFileInput!) {\n createFile(input: $input) {\n file {\n id\n }\n }\n}\n"])));
7955
+ var CreateFileMutation$1 = gqlTyped(templateObject_4$8 || (templateObject_4$8 = __makeTemplateObject(["\nmutation CreateFileMutation($input: CreateFileInput!) {\n createFile(input: $input) {\n file {\n id\n keyId\n }\n }\n}\n"], ["\nmutation CreateFileMutation($input: CreateFileInput!) {\n createFile(input: $input) {\n file {\n id\n keyId\n }\n }\n}\n"])));
7888
7956
  var UpdateFileMutation = gqlTyped(templateObject_5$7 || (templateObject_5$7 = __makeTemplateObject(["\nmutation UpdateFileMutation($input: UpdateFileInput!) {\n updateFile(input: $input) {\n file {\n id\n }\n }\n}\n"], ["\nmutation UpdateFileMutation($input: UpdateFileInput!) {\n updateFile(input: $input) {\n file {\n id\n }\n }\n}\n"])));
7889
7957
  var RevertFileMutation = gqlTyped(templateObject_6$6 || (templateObject_6$6 = __makeTemplateObject(["\nmutation RevertFileMutation($input: RevertFileInput!) {\n revertFile(input: $input) {\n file {\n id\n }\n }\n}\n"], ["\nmutation RevertFileMutation($input: RevertFileInput!) {\n revertFile(input: $input) {\n file {\n id\n }\n }\n}\n"])));
7890
7958
  var DeleteFileMutation$1 = gqlTyped(templateObject_7$5 || (templateObject_7$5 = __makeTemplateObject(["\nmutation DeleteFileMutation($input: DeleteFileInput!) {\n deleteFile(input: $input) {\n id\n }\n}\n"], ["\nmutation DeleteFileMutation($input: DeleteFileInput!) {\n deleteFile(input: $input) {\n id\n }\n}\n"])));
@@ -7906,7 +7974,7 @@
7906
7974
  var Item2Service_1;
7907
7975
  exports.Item2Service = Item2Service_1 = /** @class */ (function (_super) {
7908
7976
  __extends(Item2Service, _super);
7909
- function Item2Service(ngZone, injector, fileUploadService, keyService, keyFactory, keyGraph, lockService) {
7977
+ function Item2Service(ngZone, injector, fileUploadService, keyService, keyFactory, keyGraph, lockService, authService) {
7910
7978
  var _this = _super.call(this, injector) || this;
7911
7979
  _this.ngZone = ngZone;
7912
7980
  _this.injector = injector;
@@ -7915,6 +7983,10 @@
7915
7983
  _this.keyFactory = keyFactory;
7916
7984
  _this.keyGraph = keyGraph;
7917
7985
  _this.lockService = lockService;
7986
+ _this.authService = authService;
7987
+ // Caching the temp directory.
7988
+ _this.tempDirectory = null;
7989
+ _this.authService.addLogoutListener(function () { return _this.onLogout(); });
7918
7990
  return _this;
7919
7991
  }
7920
7992
  Item2Service.prototype.downloadFileContent = function (options) {
@@ -8217,6 +8289,16 @@
8217
8289
  Item2Service.prototype.beginDeleteChildItemLinksWindow = function (options) {
8218
8290
  return this.mutate(this.beginDeleteChildItemLinksWindowMutation(options));
8219
8291
  };
8292
+ /**
8293
+ * Schedule cleanup of the hard links in a directory.
8294
+ * The server will delete all hard link within the directory within a time window: starting from now and
8295
+ * ending at requestWindowMs after now.
8296
+ * The server decides _when_ it will perform the delete. It's not guaranteed that it will perform
8297
+ * the delete at "now + requestWindowMs", but it will happen at some time after "now + requestWindowMs".
8298
+ * This allows multiple overlapping calls to this function and the server allocates enough for each request.
8299
+ * The server has a setting that allows for a maximum value on requestWindowMs. If the requested value
8300
+ * is larger than this maximum, the call will fail.
8301
+ */
8220
8302
  Item2Service.prototype.beginDeleteChildItemLinksWindowMutation = function (options) {
8221
8303
  return __awaiter(this, void 0, void 0, function () {
8222
8304
  return __generator(this, function (_c) {
@@ -8246,12 +8328,16 @@
8246
8328
  var existing, createDirectory, updateLock, _c, createDirectoryResult, _d, id, keyId, _e, id, keyId;
8247
8329
  return __generator(this, function (_f) {
8248
8330
  switch (_f.label) {
8249
- case 0: return [4 /*yield*/, this.query({
8250
- query: TempDirectoryQuery,
8251
- variables: {
8252
- plainMeta: Item2Service_1.TEMP_DIRECTORY_PLAIN_META_FILTER,
8253
- },
8254
- })];
8331
+ case 0:
8332
+ if (this.tempDirectory) {
8333
+ return [2 /*return*/, this.tempDirectory];
8334
+ }
8335
+ return [4 /*yield*/, this.query({
8336
+ query: TempDirectoryQuery,
8337
+ variables: {
8338
+ plainMeta: Item2Service_1.TEMP_DIRECTORY_PLAIN_META_FILTER,
8339
+ },
8340
+ })];
8255
8341
  case 1:
8256
8342
  existing = _f.sent();
8257
8343
  if (existing.rootDirectories.edges.length > 1) {
@@ -8274,16 +8360,19 @@
8274
8360
  case 3:
8275
8361
  _c = __read.apply(void 0, [_f.sent(), 1]), createDirectoryResult = _c[0];
8276
8362
  _d = createDirectoryResult.createDirectory.directory, id = _d.id, keyId = _d.keyId;
8277
- return [2 /*return*/, {
8278
- id: id,
8279
- keyId: keyId,
8280
- }];
8363
+ this.tempDirectory = {
8364
+ id: id,
8365
+ keyId: keyId,
8366
+ };
8367
+ return [3 /*break*/, 5];
8281
8368
  case 4:
8282
8369
  _e = existing.rootDirectories.edges[0].node, id = _e.id, keyId = _e.keyId;
8283
- return [2 /*return*/, {
8284
- id: id,
8285
- keyId: keyId,
8286
- }];
8370
+ this.tempDirectory = {
8371
+ id: id,
8372
+ keyId: keyId,
8373
+ };
8374
+ _f.label = 5;
8375
+ case 5: return [2 /*return*/, this.tempDirectory];
8287
8376
  }
8288
8377
  });
8289
8378
  });
@@ -8302,7 +8391,7 @@
8302
8391
  */
8303
8392
  Item2Service.prototype.createDirectoryTreeMutation = function (options) {
8304
8393
  return __awaiter(this, void 0, void 0, function () {
8305
- var tempDir, dirId;
8394
+ var tempDir, directory;
8306
8395
  return __generator(this, function (_c) {
8307
8396
  switch (_c.label) {
8308
8397
  case 0: return [4 /*yield*/, this.ensureTempDirectory()];
@@ -8327,9 +8416,12 @@
8327
8416
  plainMetaJson: options.plainMetaJson,
8328
8417
  })];
8329
8418
  case 3:
8330
- dirId = (_c.sent()).createDirectory.directory.id;
8419
+ directory = (_c.sent()).createDirectory.directory;
8331
8420
  // Create the contents
8332
- return [4 /*yield*/, options.createContent(dirId)];
8421
+ return [4 /*yield*/, options.createContent({
8422
+ id: directory.id,
8423
+ keyId: directory.keyId,
8424
+ })];
8333
8425
  case 4:
8334
8426
  // Create the contents
8335
8427
  _c.sent();
@@ -8337,7 +8429,8 @@
8337
8429
  // TODO return the server time where delete is scheduled. Expirable mutation
8338
8430
  // Return the mutation that moves the directory into the dst directories
8339
8431
  return [2 /*return*/, this.changeDirectoryParentsMutation({
8340
- directoryId: dirId,
8432
+ directoryId: directory.id,
8433
+ directoryKeyId: directory.keyId,
8341
8434
  parentsToRemove: [tempDir.id],
8342
8435
  parentsToAdd: options.parentDirectories,
8343
8436
  })];
@@ -8476,15 +8569,23 @@
8476
8569
  };
8477
8570
  Item2Service.prototype.prepareChangeItemParents = function (options, itemKey) {
8478
8571
  return __awaiter(this, void 0, void 0, function () {
8479
- var parentsToAdd;
8572
+ var parentsToAdd, _c;
8480
8573
  var _this = this;
8481
- return __generator(this, function (_c) {
8482
- switch (_c.label) {
8483
- case 0: return [4 /*yield*/, Promise.all(options.parentsToAdd.map(function (t) { return _this.prepareParentDirectory(t, itemKey); }))];
8574
+ return __generator(this, function (_d) {
8575
+ switch (_d.label) {
8576
+ case 0:
8577
+ if (!options.parentsToAdd) return [3 /*break*/, 2];
8578
+ return [4 /*yield*/, Promise.all(options.parentsToAdd.map(function (t) { return _this.prepareParentDirectory(t, itemKey); }))];
8484
8579
  case 1:
8485
- parentsToAdd = _c.sent();
8580
+ _c = _d.sent();
8581
+ return [3 /*break*/, 3];
8582
+ case 2:
8583
+ _c = [];
8584
+ _d.label = 3;
8585
+ case 3:
8586
+ parentsToAdd = _c;
8486
8587
  return [2 /*return*/, {
8487
- directoriesToRemove: options.parentsToRemove,
8588
+ directoriesToRemove: options.parentsToRemove || [],
8488
8589
  directoriesToAdd: parentsToAdd,
8489
8590
  }];
8490
8591
  }
@@ -8649,6 +8750,10 @@
8649
8750
  });
8650
8751
  });
8651
8752
  };
8753
+ Item2Service.prototype.onLogout = function () {
8754
+ // Clear all cached data.
8755
+ this.tempDirectory = null;
8756
+ };
8652
8757
  return Item2Service;
8653
8758
  }(LrService));
8654
8759
  exports.Item2Service.TEMP_DIRECTORY_PLAIN_META = { kcType: 'temp' };
@@ -8659,7 +8764,7 @@
8659
8764
  },
8660
8765
  ],
8661
8766
  });
8662
- exports.Item2Service.ɵprov = i0.ɵɵdefineInjectable({ factory: function Item2Service_Factory() { return new exports.Item2Service(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(FileUploadService), i0.ɵɵinject(KeyService), i0.ɵɵinject(KeyFactoryService), i0.ɵɵinject(KeyGraphService), i0.ɵɵinject(exports.LockService)); }, token: exports.Item2Service, providedIn: "root" });
8767
+ exports.Item2Service.ɵprov = i0.ɵɵdefineInjectable({ factory: function Item2Service_Factory() { return new exports.Item2Service(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(FileUploadService), i0.ɵɵinject(KeyService), i0.ɵɵinject(KeyFactoryService), i0.ɵɵinject(KeyGraphService), i0.ɵɵinject(exports.LockService), i0.ɵɵinject(LifeReadyAuthService)); }, token: exports.Item2Service, providedIn: "root" });
8663
8768
  exports.Item2Service.decorators = [
8664
8769
  { type: i0.Injectable, args: [{
8665
8770
  providedIn: 'root',
@@ -8672,7 +8777,8 @@
8672
8777
  { type: KeyService },
8673
8778
  { type: KeyFactoryService },
8674
8779
  { type: KeyGraphService },
8675
- { type: exports.LockService }
8780
+ { type: exports.LockService },
8781
+ { type: LifeReadyAuthService }
8676
8782
  ]; };
8677
8783
  exports.Item2Service = Item2Service_1 = __decorate([
8678
8784
  RunOutsideAngular({