@milaboratories/pl-client 2.7.12 → 2.7.14

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 (116) hide show
  1. package/dist/core/auth.d.ts.map +1 -1
  2. package/dist/core/cache.d.ts.map +1 -1
  3. package/dist/core/client.d.ts +1 -1
  4. package/dist/core/client.d.ts.map +1 -1
  5. package/dist/core/default_client.d.ts.map +1 -1
  6. package/dist/core/driver.d.ts.map +1 -1
  7. package/dist/core/errors.d.ts.map +1 -1
  8. package/dist/core/final.d.ts.map +1 -1
  9. package/dist/core/ll_client.d.ts.map +1 -1
  10. package/dist/core/ll_transaction.d.ts.map +1 -1
  11. package/dist/core/transaction.d.ts +1 -1
  12. package/dist/core/transaction.d.ts.map +1 -1
  13. package/dist/core/type_conversion.d.ts.map +1 -1
  14. package/dist/core/types.d.ts +1 -1
  15. package/dist/core/types.d.ts.map +1 -1
  16. package/dist/core/unauth_client.d.ts.map +1 -1
  17. package/dist/helpers/pl.d.ts.map +1 -1
  18. package/dist/helpers/poll.d.ts.map +1 -1
  19. package/dist/helpers/state_helpers.d.ts.map +1 -1
  20. package/dist/helpers/tx_helpers.d.ts.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +4069 -4075
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +15 -15
  26. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +1 -1
  27. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +4 -4
  28. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +1 -1
  29. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +16 -16
  30. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +1 -1
  31. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +4 -4
  32. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +1 -1
  33. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +59 -59
  34. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +1 -1
  35. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +8 -8
  36. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +1 -1
  37. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +22 -22
  38. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +1 -1
  39. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +72 -72
  40. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +1 -1
  41. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +152 -152
  42. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +1 -1
  43. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +156 -156
  44. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +1 -1
  45. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +773 -773
  46. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +1 -1
  47. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +163 -163
  48. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +1 -1
  49. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +22 -22
  50. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +1 -1
  51. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +32 -32
  52. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +1 -1
  53. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +78 -78
  54. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +1 -1
  55. package/dist/proto/google/api/http.d.ts +89 -89
  56. package/dist/proto/google/api/http.d.ts.map +1 -1
  57. package/dist/proto/google/protobuf/any.d.ts +52 -52
  58. package/dist/proto/google/protobuf/any.d.ts.map +1 -1
  59. package/dist/proto/google/protobuf/descriptor.d.ts +1151 -1151
  60. package/dist/proto/google/protobuf/descriptor.d.ts.map +1 -1
  61. package/dist/proto/google/protobuf/duration.d.ts +19 -19
  62. package/dist/proto/google/protobuf/duration.d.ts.map +1 -1
  63. package/dist/proto/google/protobuf/empty.d.ts.map +1 -1
  64. package/dist/proto/google/protobuf/struct.d.ts +56 -56
  65. package/dist/proto/google/protobuf/struct.d.ts.map +1 -1
  66. package/dist/proto/google/protobuf/timestamp.d.ts +25 -25
  67. package/dist/proto/google/protobuf/timestamp.d.ts.map +1 -1
  68. package/dist/proto/google/protobuf/wrappers.d.ts +72 -72
  69. package/dist/proto/google/protobuf/wrappers.d.ts.map +1 -1
  70. package/dist/test/test_config.d.ts.map +1 -1
  71. package/dist/util/util.d.ts.map +1 -1
  72. package/package.json +17 -13
  73. package/src/core/auth.ts +3 -3
  74. package/src/core/cache.ts +1 -1
  75. package/src/core/client.ts +39 -31
  76. package/src/core/config.ts +21 -21
  77. package/src/core/default_client.ts +15 -14
  78. package/src/core/driver.ts +4 -4
  79. package/src/core/errors.ts +3 -3
  80. package/src/core/final.ts +7 -4
  81. package/src/core/ll_client.ts +31 -27
  82. package/src/core/ll_transaction.ts +17 -17
  83. package/src/core/stat.ts +2 -2
  84. package/src/core/transaction.ts +93 -95
  85. package/src/core/type_conversion.ts +11 -8
  86. package/src/core/types.ts +25 -26
  87. package/src/core/unauth_client.ts +6 -6
  88. package/src/helpers/pl.ts +8 -7
  89. package/src/helpers/poll.ts +25 -21
  90. package/src/helpers/state_helpers.ts +2 -1
  91. package/src/helpers/tx_helpers.ts +4 -3
  92. package/src/proto/github.com/googleapis/googleapis/google/rpc/status.ts +74 -71
  93. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.ts +21 -20
  94. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.ts +240 -225
  95. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.ts +21 -20
  96. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.ts +290 -275
  97. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.ts +32 -30
  98. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.ts +388 -364
  99. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.ts +58 -53
  100. package/src/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.ts +490 -469
  101. package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.ts +262 -237
  102. package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api.ts +11751 -11032
  103. package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.ts +1155 -1114
  104. package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.ts +131 -125
  105. package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/import.ts +203 -200
  106. package/src/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.ts +559 -540
  107. package/src/proto/google/api/http.ts +280 -271
  108. package/src/proto/google/protobuf/any.ts +149 -139
  109. package/src/proto/google/protobuf/descriptor.ts +2952 -2853
  110. package/src/proto/google/protobuf/duration.ts +107 -102
  111. package/src/proto/google/protobuf/empty.ts +41 -38
  112. package/src/proto/google/protobuf/struct.ts +336 -322
  113. package/src/proto/google/protobuf/timestamp.ts +131 -123
  114. package/src/proto/google/protobuf/wrappers.ts +536 -491
  115. package/src/test/test_config.ts +21 -19
  116. package/src/util/util.ts +1 -0
@@ -1,9 +1,8 @@
1
- import {
1
+ // TODO: fix this
2
+ /* eslint-disable no-prototype-builtins */
3
+ import type {
2
4
  AnyResourceId,
3
- createLocalResourceId,
4
- ensureResourceIdNotNull,
5
5
  LocalResourceId,
6
- MaxTxId,
7
6
  OptionalResourceId,
8
7
  BasicResourceData,
9
8
  FieldData,
@@ -11,26 +10,31 @@ import {
11
10
  ResourceData,
12
11
  ResourceId,
13
12
  ResourceType,
14
- FutureFieldType,
13
+ FutureFieldType } from './types';
14
+ import {
15
+ createLocalResourceId,
16
+ ensureResourceIdNotNull,
17
+ MaxTxId,
15
18
  isLocalResourceId,
16
- extractBasicResourceData
19
+ extractBasicResourceData,
17
20
  } from './types';
18
- import {
21
+ import type {
19
22
  ClientMessageRequest,
20
23
  LLPlTransaction,
21
24
  OneOfKind,
22
- ServerMessageResponse
25
+ ServerMessageResponse,
23
26
  } from './ll_transaction';
24
27
  import { TxAPI_Open_Request_WritableTx } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
25
- import { NonUndefined } from 'utility-types';
28
+ import type { NonUndefined } from 'utility-types';
26
29
  import { toBytes } from '../util/util';
27
30
  import { fieldTypeToProto, protoToField, protoToResource } from './type_conversion';
28
31
  import { notEmpty } from '@milaboratories/ts-helpers';
29
32
  import { isNotFoundError } from './errors';
30
- import { FinalResourceDataPredicate } from './final';
31
- import { LRUCache } from 'lru-cache';
32
- import { ResourceDataCacheRecord } from './cache';
33
- import { initialTxStat, TxStat } from './stat';
33
+ import type { FinalResourceDataPredicate } from './final';
34
+ import type { LRUCache } from 'lru-cache';
35
+ import type { ResourceDataCacheRecord } from './cache';
36
+ import type { TxStat } from './stat';
37
+ import { initialTxStat } from './stat';
34
38
 
35
39
  /** Reference to resource, used only within transaction */
36
40
  export interface ResourceRef {
@@ -120,7 +124,7 @@ export class TxCommitConflict extends Error {}
120
124
  async function notFoundToUndefined<T>(cb: () => Promise<T>): Promise<T | undefined> {
121
125
  try {
122
126
  return await cb();
123
- } catch (e: any) {
127
+ } catch (e) {
124
128
  if (isNotFoundError(e)) return undefined;
125
129
  throw e;
126
130
  }
@@ -145,7 +149,7 @@ export class PlTransaction {
145
149
 
146
150
  /** Store logical tx open / closed state to prevent invalid sequence of requests.
147
151
  * True means output stream was completed.
148
- * Contract: there must be no async operations between setting this field to true and sending complete signal to stream.*/
152
+ * Contract: there must be no async operations between setting this field to true and sending complete signal to stream. */
149
153
  private _completed = false;
150
154
 
151
155
  /** Void operation futures are placed into this pool, and corresponding method return immediately.
@@ -163,7 +167,7 @@ export class PlTransaction {
163
167
  public readonly writable: boolean,
164
168
  private readonly _clientRoot: OptionalResourceId,
165
169
  private readonly finalPredicate: FinalResourceDataPredicate,
166
- private readonly sharedResourceDataCache: LRUCache<ResourceId, ResourceDataCacheRecord>
170
+ private readonly sharedResourceDataCache: LRUCache<ResourceId, ResourceDataCacheRecord>,
167
171
  ) {
168
172
  // initiating transaction
169
173
  this.globalTxId = this.sendSingleAndParse(
@@ -173,10 +177,10 @@ export class PlTransaction {
173
177
  name,
174
178
  writable: writable
175
179
  ? TxAPI_Open_Request_WritableTx.WRITABLE
176
- : TxAPI_Open_Request_WritableTx.NOT_WRITABLE
177
- }
180
+ : TxAPI_Open_Request_WritableTx.NOT_WRITABLE,
181
+ },
178
182
  },
179
- (r) => notEmpty(r.txOpen.tx?.id)
183
+ (r) => notEmpty(r.txOpen.tx?.id),
180
184
  );
181
185
 
182
186
  // To avoid floating promise
@@ -202,43 +206,37 @@ export class PlTransaction {
202
206
 
203
207
  private async sendSingleAndParse<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>, T>(
204
208
  r: OneOfKind<ClientMessageRequest, Kind>,
205
- parser: (resp: OneOfKind<ServerMessageResponse, Kind>) => T
209
+ parser: (resp: OneOfKind<ServerMessageResponse, Kind>) => T,
206
210
  ): Promise<T> {
207
211
  // pushing operation packet to server
208
212
  const rawResponsePromise = this.ll.send(r, false);
209
213
 
210
- try {
211
- await this.drainAndAwaitPendingOps();
212
- } finally {
213
- // awaiting our result, and parsing the response
214
- return parser(await rawResponsePromise);
215
- }
214
+ await this.drainAndAwaitPendingOps();
215
+ // awaiting our result, and parsing the response
216
+ return parser(await rawResponsePromise);
216
217
  }
217
218
 
218
219
  private async sendMultiAndParse<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>, T>(
219
220
  r: OneOfKind<ClientMessageRequest, Kind>,
220
- parser: (resp: OneOfKind<ServerMessageResponse, Kind>[]) => T
221
+ parser: (resp: OneOfKind<ServerMessageResponse, Kind>[]) => T,
221
222
  ): Promise<T> {
222
223
  // pushing operation packet to server
223
224
  const rawResponsePromise = this.ll.send(r, true);
224
225
 
225
- try {
226
- await this.drainAndAwaitPendingOps();
227
- } finally {
228
- // awaiting our result, and parsing the response
229
- return parser(await rawResponsePromise);
230
- }
226
+ await this.drainAndAwaitPendingOps();
227
+ // awaiting our result, and parsing the response
228
+ return parser(await rawResponsePromise);
231
229
  }
232
230
 
233
- private async sendVoidSync<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>, T>(
234
- r: OneOfKind<ClientMessageRequest, Kind>
231
+ private async sendVoidSync<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>>(
232
+ r: OneOfKind<ClientMessageRequest, Kind>,
235
233
  ): Promise<void> {
236
234
  await this.ll.send(r, false);
237
235
  }
238
236
 
239
237
  /** Requests sent with this method should never produce recoverable errors */
240
- private sendVoidAsync<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>, T>(
241
- r: OneOfKind<ClientMessageRequest, Kind>
238
+ private sendVoidAsync<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>>(
239
+ r: OneOfKind<ClientMessageRequest, Kind>,
242
240
  ): void {
243
241
  this.pendingVoidOps.push(this.sendVoidSync(r));
244
242
  }
@@ -269,7 +267,7 @@ export class PlTransaction {
269
267
  // @TODO, also floating promises
270
268
  const commitResponse = this.sendSingleAndParse(
271
269
  { oneofKind: 'txCommit', txCommit: {} },
272
- (r) => r.txCommit.success
270
+ (r) => r.txCommit.success,
273
271
  );
274
272
 
275
273
  // send closing frame right after commit to save some time on round-trips
@@ -322,7 +320,7 @@ export class PlTransaction {
322
320
  public createSingleton(
323
321
  name: string,
324
322
  type: ResourceType,
325
- errorIfExists: boolean = false
323
+ errorIfExists: boolean = false,
326
324
  ): ResourceRef {
327
325
  const localId = this.nextLocalResourceId(false);
328
326
 
@@ -333,10 +331,10 @@ export class PlTransaction {
333
331
  type,
334
332
  id: localId,
335
333
  data: Buffer.from(name),
336
- errorIfExists
337
- }
334
+ errorIfExists,
335
+ },
338
336
  },
339
- (r) => r.resourceCreateSingleton.resourceId as ResourceId
337
+ (r) => r.resourceCreateSingleton.resourceId as ResourceId,
340
338
  );
341
339
 
342
340
  return { globalId, localId };
@@ -346,24 +344,24 @@ export class PlTransaction {
346
344
  public async getSingleton(name: string, loadFields: false): Promise<BasicResourceData>;
347
345
  public async getSingleton(
348
346
  name: string,
349
- loadFields: boolean = true
347
+ loadFields: boolean = true,
350
348
  ): Promise<BasicResourceData | ResourceData> {
351
349
  return await this.sendSingleAndParse(
352
350
  {
353
351
  oneofKind: 'resourceGetSingleton',
354
352
  resourceGetSingleton: {
355
353
  data: Buffer.from(name),
356
- loadFields
357
- }
354
+ loadFields,
355
+ },
358
356
  },
359
- (r) => protoToResource(notEmpty(r.resourceGetSingleton.resource))
357
+ (r) => protoToResource(notEmpty(r.resourceGetSingleton.resource)),
360
358
  );
361
359
  }
362
360
 
363
361
  private createResource<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>>(
364
362
  root: boolean,
365
363
  req: (localId: LocalResourceId) => OneOfKind<ClientMessageRequest, Kind>,
366
- parser: (resp: OneOfKind<ServerMessageResponse, Kind>) => bigint
364
+ parser: (resp: OneOfKind<ServerMessageResponse, Kind>) => bigint,
367
365
  ): ResourceRef {
368
366
  const localId = this.nextLocalResourceId(root);
369
367
 
@@ -377,7 +375,7 @@ export class PlTransaction {
377
375
  return this.createResource(
378
376
  true,
379
377
  (localId) => ({ oneofKind: 'resourceCreateRoot', resourceCreateRoot: { type, id: localId } }),
380
- (r) => r.resourceCreateRoot.resourceId
378
+ (r) => r.resourceCreateRoot.resourceId,
381
379
  );
382
380
  }
383
381
 
@@ -391,10 +389,10 @@ export class PlTransaction {
391
389
  resourceCreateStruct: {
392
390
  type,
393
391
  id: localId,
394
- data: data === undefined ? undefined : typeof data === 'string' ? Buffer.from(data) : data
395
- }
392
+ data: data === undefined ? undefined : typeof data === 'string' ? Buffer.from(data) : data,
393
+ },
396
394
  }),
397
- (r) => r.resourceCreateStruct.resourceId
395
+ (r) => r.resourceCreateStruct.resourceId,
398
396
  );
399
397
  }
400
398
 
@@ -408,17 +406,17 @@ export class PlTransaction {
408
406
  resourceCreateEphemeral: {
409
407
  type,
410
408
  id: localId,
411
- data: data === undefined ? undefined : typeof data === 'string' ? Buffer.from(data) : data
412
- }
409
+ data: data === undefined ? undefined : typeof data === 'string' ? Buffer.from(data) : data,
410
+ },
413
411
  }),
414
- (r) => r.resourceCreateEphemeral.resourceId
412
+ (r) => r.resourceCreateEphemeral.resourceId,
415
413
  );
416
414
  }
417
415
 
418
416
  public createValue(
419
417
  type: ResourceType,
420
418
  data: Uint8Array | string,
421
- errorIfExists: boolean = false
419
+ errorIfExists: boolean = false,
422
420
  ): ResourceRef {
423
421
  this.stat.valuesCreated++;
424
422
  this.stat.valuesCreatedDataBytes += data?.length ?? 0;
@@ -430,17 +428,17 @@ export class PlTransaction {
430
428
  type,
431
429
  id: localId,
432
430
  data: typeof data === 'string' ? Buffer.from(data) : data,
433
- errorIfExists
434
- }
431
+ errorIfExists,
432
+ },
435
433
  }),
436
- (r) => r.resourceCreateValue.resourceId
434
+ (r) => r.resourceCreateValue.resourceId,
437
435
  );
438
436
  }
439
437
 
440
438
  public setResourceName(name: string, rId: AnyResourceRef): void {
441
439
  this.sendVoidAsync({
442
440
  oneofKind: 'resourceNameSet',
443
- resourceNameSet: { resourceId: toResourceId(rId), name }
441
+ resourceNameSet: { resourceId: toResourceId(rId), name },
444
442
  });
445
443
  }
446
444
 
@@ -451,14 +449,14 @@ export class PlTransaction {
451
449
  public async getResourceByName(name: string): Promise<ResourceId> {
452
450
  return await this.sendSingleAndParse(
453
451
  { oneofKind: 'resourceNameGet', resourceNameGet: { name } },
454
- (r) => ensureResourceIdNotNull(r.resourceNameGet.resourceId as OptionalResourceId)
452
+ (r) => ensureResourceIdNotNull(r.resourceNameGet.resourceId as OptionalResourceId),
455
453
  );
456
454
  }
457
455
 
458
456
  public async checkResourceNameExists(name: string): Promise<boolean> {
459
457
  return await this.sendSingleAndParse(
460
458
  { oneofKind: 'resourceNameExists', resourceNameExists: { name } },
461
- (r) => r.resourceNameExists.exists
459
+ (r) => r.resourceNameExists.exists,
462
460
  );
463
461
  }
464
462
 
@@ -469,7 +467,7 @@ export class PlTransaction {
469
467
  public async resourceExists(rId: ResourceId): Promise<boolean> {
470
468
  return await this.sendSingleAndParse(
471
469
  { oneofKind: 'resourceExists', resourceExists: { resourceId: rId } },
472
- (r) => r.resourceExists.exists
470
+ (r) => r.resourceExists.exists,
473
471
  );
474
472
  }
475
473
 
@@ -503,7 +501,7 @@ export class PlTransaction {
503
501
  public async getResourceData(
504
502
  rId: AnyResourceRef,
505
503
  loadFields: boolean = true,
506
- ignoreCache: boolean = false
504
+ ignoreCache: boolean = false,
507
505
  ): Promise<BasicResourceData | ResourceData> {
508
506
  if (!ignoreCache && !isResourceRef(rId) && !isLocalResourceId(rId)) {
509
507
  // checking if we can return result from cache
@@ -525,9 +523,9 @@ export class PlTransaction {
525
523
  const result = await this.sendSingleAndParse(
526
524
  {
527
525
  oneofKind: 'resourceGet',
528
- resourceGet: { resourceId: toResourceId(rId), loadFields: loadFields }
526
+ resourceGet: { resourceId: toResourceId(rId), loadFields: loadFields },
529
527
  },
530
- (r) => protoToResource(notEmpty(r.resourceGet.resource))
528
+ (r) => protoToResource(notEmpty(r.resourceGet.resource)),
531
529
  );
532
530
 
533
531
  this.stat.rGetDataNetRequests++;
@@ -549,13 +547,13 @@ export class PlTransaction {
549
547
  this.sharedResourceDataCache.set(rId, {
550
548
  basicData: extractBasicResourceData(result),
551
549
  data: result,
552
- cacheTxOpenTimestamp: this.txOpenTimestamp
550
+ cacheTxOpenTimestamp: this.txOpenTimestamp,
553
551
  });
554
552
  else
555
553
  this.sharedResourceDataCache.set(rId, {
556
554
  basicData: extractBasicResourceData(result),
557
555
  data: undefined,
558
- cacheTxOpenTimestamp: this.txOpenTimestamp
556
+ cacheTxOpenTimestamp: this.txOpenTimestamp,
559
557
  });
560
558
  }
561
559
  }
@@ -577,12 +575,12 @@ export class PlTransaction {
577
575
  ): Promise<BasicResourceData | ResourceData | undefined>;
578
576
  public async getResourceDataIfExists(
579
577
  rId: AnyResourceRef,
580
- loadFields: boolean = true
578
+ loadFields: boolean = true,
581
579
  ): Promise<BasicResourceData | ResourceData | undefined> {
582
580
  // calling this mehtod will ignore cache, because user intention is to detect resource absence
583
581
  // which cache will prevent
584
582
  const result = await notFoundToUndefined(
585
- async () => await this.getResourceData(rId, loadFields, true)
583
+ async () => await this.getResourceData(rId, loadFields, true),
586
584
  );
587
585
 
588
586
  // cleaning cache record if resorce was removed from the db
@@ -603,7 +601,7 @@ export class PlTransaction {
603
601
  this.stat.inputsLocked++;
604
602
  this.sendVoidAsync({
605
603
  oneofKind: 'resourceLockInputs',
606
- resourceLockInputs: { resourceId: toResourceId(rId) }
604
+ resourceLockInputs: { resourceId: toResourceId(rId) },
607
605
  });
608
606
  }
609
607
 
@@ -615,7 +613,7 @@ export class PlTransaction {
615
613
  this.stat.outputsLocked++;
616
614
  this.sendVoidAsync({
617
615
  oneofKind: 'resourceLockOutputs',
618
- resourceLockOutputs: { resourceId: toResourceId(rId) }
616
+ resourceLockOutputs: { resourceId: toResourceId(rId) },
619
617
  });
620
618
  }
621
619
 
@@ -632,7 +630,7 @@ export class PlTransaction {
632
630
  this.stat.fieldsCreated++;
633
631
  this.sendVoidAsync({
634
632
  oneofKind: 'fieldCreate',
635
- fieldCreate: { type: fieldTypeToProto(fieldType), id: toFieldId(fId) }
633
+ fieldCreate: { type: fieldTypeToProto(fieldType), id: toFieldId(fId) },
636
634
  });
637
635
  if (value !== undefined) this.setField(fId, value);
638
636
  }
@@ -641,9 +639,9 @@ export class PlTransaction {
641
639
  return await this.sendSingleAndParse(
642
640
  {
643
641
  oneofKind: 'fieldExists',
644
- fieldExists: { field: toFieldId(fId) }
642
+ fieldExists: { field: toFieldId(fId) },
645
643
  },
646
- (r) => r.fieldExists.exists
644
+ (r) => r.fieldExists.exists,
647
645
  );
648
646
  }
649
647
 
@@ -656,17 +654,17 @@ export class PlTransaction {
656
654
  field: toFieldId(fId),
657
655
  value: {
658
656
  resourceId: toResourceId(ref),
659
- fieldName: '' // default value, read as undefined
660
- }
661
- }
657
+ fieldName: '', // default value, read as undefined
658
+ },
659
+ },
662
660
  });
663
661
  else
664
662
  this.sendVoidAsync({
665
663
  oneofKind: 'fieldSet',
666
664
  fieldSet: {
667
665
  field: toFieldId(fId),
668
- value: toFieldId(ref)
669
- }
666
+ value: toFieldId(ref),
667
+ },
670
668
  });
671
669
  }
672
670
 
@@ -674,7 +672,7 @@ export class PlTransaction {
674
672
  this.stat.fieldsSet++;
675
673
  this.sendVoidAsync({
676
674
  oneofKind: 'fieldSetError',
677
- fieldSetError: { field: toFieldId(fId), errResourceId: toResourceId(ref) }
675
+ fieldSetError: { field: toFieldId(fId), errResourceId: toResourceId(ref) },
678
676
  });
679
677
  }
680
678
 
@@ -682,7 +680,7 @@ export class PlTransaction {
682
680
  this.stat.fieldsGet++;
683
681
  return await this.sendSingleAndParse(
684
682
  { oneofKind: 'fieldGet', fieldGet: { field: toFieldId(fId) } },
685
- (r) => protoToField(notEmpty(r.fieldGet.field))
683
+ (r) => protoToField(notEmpty(r.fieldGet.field)),
686
684
  );
687
685
  }
688
686
 
@@ -706,9 +704,9 @@ export class PlTransaction {
706
704
  const result = await this.sendMultiAndParse(
707
705
  {
708
706
  oneofKind: 'resourceKeyValueList',
709
- resourceKeyValueList: { resourceId: toResourceId(rId), startFrom: '', limit: 0 }
707
+ resourceKeyValueList: { resourceId: toResourceId(rId), startFrom: '', limit: 0 },
710
708
  },
711
- (r) => r.map((e) => e.resourceKeyValueList.record!)
709
+ (r) => r.map((e) => e.resourceKeyValueList.record!),
712
710
  );
713
711
 
714
712
  this.stat.kvListRequests++;
@@ -721,7 +719,7 @@ export class PlTransaction {
721
719
  public async listKeyValuesString(rId: AnyResourceRef): Promise<KeyValueString[]> {
722
720
  return (await this.listKeyValues(rId)).map(({ key, value }) => ({
723
721
  key,
724
- value: Buffer.from(value).toString()
722
+ value: Buffer.from(value).toString(),
725
723
  }));
726
724
  }
727
725
 
@@ -730,7 +728,7 @@ export class PlTransaction {
730
728
  }
731
729
 
732
730
  public async listKeyValuesStringIfResourceExists(
733
- rId: AnyResourceRef
731
+ rId: AnyResourceRef,
734
732
  ): Promise<KeyValueString[] | undefined> {
735
733
  return notFoundToUndefined(async () => await this.listKeyValuesString(rId));
736
734
  }
@@ -743,8 +741,8 @@ export class PlTransaction {
743
741
  resourceKeyValueSet: {
744
742
  resourceId: toResourceId(rId),
745
743
  key,
746
- value: toBytes(value)
747
- }
744
+ value: toBytes(value),
745
+ },
748
746
  });
749
747
  }
750
748
 
@@ -753,8 +751,8 @@ export class PlTransaction {
753
751
  oneofKind: 'resourceKeyValueDelete',
754
752
  resourceKeyValueDelete: {
755
753
  resourceId: toResourceId(rId),
756
- key
757
- }
754
+ key,
755
+ },
758
756
  });
759
757
  }
760
758
 
@@ -762,9 +760,9 @@ export class PlTransaction {
762
760
  const result = await this.sendSingleAndParse(
763
761
  {
764
762
  oneofKind: 'resourceKeyValueGet',
765
- resourceKeyValueGet: { resourceId: toResourceId(rId), key }
763
+ resourceKeyValueGet: { resourceId: toResourceId(rId), key },
766
764
  },
767
- (r) => r.resourceKeyValueGet.value
765
+ (r) => r.resourceKeyValueGet.value,
768
766
  );
769
767
 
770
768
  this.stat.kvGetRequests++;
@@ -783,15 +781,15 @@ export class PlTransaction {
783
781
 
784
782
  public async getKValueIfExists(
785
783
  rId: AnyResourceRef,
786
- key: string
784
+ key: string,
787
785
  ): Promise<Uint8Array | undefined> {
788
786
  const result = await this.sendSingleAndParse(
789
787
  {
790
788
  oneofKind: 'resourceKeyValueGetIfExists',
791
- resourceKeyValueGetIfExists: { resourceId: toResourceId(rId), key }
789
+ resourceKeyValueGetIfExists: { resourceId: toResourceId(rId), key },
792
790
  },
793
791
  (r) =>
794
- r.resourceKeyValueGetIfExists.exists ? r.resourceKeyValueGetIfExists.value : undefined
792
+ r.resourceKeyValueGetIfExists.exists ? r.resourceKeyValueGetIfExists.value : undefined,
795
793
  );
796
794
 
797
795
  this.stat.kvGetRequests++;
@@ -802,7 +800,7 @@ export class PlTransaction {
802
800
 
803
801
  public async getKValueStringIfExists(
804
802
  rId: AnyResourceRef,
805
- key: string
803
+ key: string,
806
804
  ): Promise<string | undefined> {
807
805
  const data = await this.getKValueIfExists(rId, key);
808
806
  return data === undefined ? undefined : Buffer.from(data).toString();
@@ -1,19 +1,22 @@
1
- import {
1
+ import type {
2
2
  Field,
3
+ Resource } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api_types';
4
+ import {
3
5
  Field_ValueStatus,
4
- Resource,
5
- Resource_Kind
6
+ Resource_Kind,
6
7
  } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api_types';
7
8
  import { FieldType as GrpcFieldType } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/base_types';
8
- import {
9
+ import type {
9
10
  FieldData,
10
11
  FieldStatus,
11
- NullResourceId,
12
12
  OptionalResourceId,
13
13
  FieldType,
14
14
  ResourceData,
15
15
  ResourceId,
16
- ResourceKind
16
+ ResourceKind,
17
+ } from './types';
18
+ import {
19
+ NullResourceId,
17
20
  } from './types';
18
21
  import { assertNever, notEmpty } from '@milaboratories/ts-helpers';
19
22
  import { throwPlNotFoundError } from './errors';
@@ -38,7 +41,7 @@ export function protoToResource(proto: Resource): ResourceData {
38
41
  kind: protoToResourceKind(proto.kind),
39
42
  error: protoToError(proto),
40
43
  final: proto.isFinal,
41
- fields: proto.fields?.filter((f) => f.id!.fieldName !== ResourceErrorField).map(protoToField)
44
+ fields: proto.fields?.filter((f) => f.id!.fieldName !== ResourceErrorField).map(protoToField),
42
45
  };
43
46
  }
44
47
 
@@ -65,7 +68,7 @@ export function protoToField(proto: Field): FieldData {
65
68
  status: protoToFieldStatus(proto.valueStatus),
66
69
  value: proto.value as OptionalResourceId,
67
70
  error: proto.error as OptionalResourceId,
68
- valueIsFinal: proto.valueIsFinal
71
+ valueIsFinal: proto.valueIsFinal,
69
72
  };
70
73
  }
71
74
 
package/src/core/types.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { notEmpty } from '@milaboratories/ts-helpers';
2
- import { version } from 'ts-jest/dist/transformers/hoist-jest';
3
2
 
4
3
  // more details here: https://egghead.io/blog/using-branded-types-in-typescript
5
4
  declare const __resource_id_type__: unique symbol;
@@ -101,7 +100,7 @@ export function extractBasicResourceData(rd: ResourceData): BasicResourceData {
101
100
  inputsLocked,
102
101
  outputsLocked,
103
102
  resourceReady,
104
- final
103
+ final,
105
104
  } = rd;
106
105
  return {
107
106
  id,
@@ -113,7 +112,7 @@ export function extractBasicResourceData(rd: ResourceData): BasicResourceData {
113
112
  inputsLocked,
114
113
  outputsLocked,
115
114
  resourceReady,
116
- final
115
+ final,
117
116
  };
118
117
  }
119
118
 
@@ -172,19 +171,19 @@ export function isLocalResourceId(id: bigint): id is LocalResourceId {
172
171
  export function createLocalResourceId(
173
172
  isRoot: boolean,
174
173
  localCounterValue: number,
175
- localTxId: number
174
+ localTxId: number,
176
175
  ): LocalResourceId {
177
176
  if (
178
- localCounterValue > MaxLocalId ||
179
- localTxId > MaxTxId ||
180
- localCounterValue < 0 ||
181
- localTxId <= 0
177
+ localCounterValue > MaxLocalId
178
+ || localTxId > MaxTxId
179
+ || localCounterValue < 0
180
+ || localTxId <= 0
182
181
  )
183
182
  throw Error('wrong local id or tx id');
184
- return ((isRoot ? ResourceIdRootMask : 0n) |
185
- ResourceIdLocalMask |
186
- BigInt(localCounterValue) |
187
- (BigInt(localTxId) << LocalResourceIdTxIdOffset)) as LocalResourceId;
183
+ return ((isRoot ? ResourceIdRootMask : 0n)
184
+ | ResourceIdLocalMask
185
+ | BigInt(localCounterValue)
186
+ | (BigInt(localTxId) << LocalResourceIdTxIdOffset)) as LocalResourceId;
188
187
  }
189
188
 
190
189
  export function createGlobalResourceId(isRoot: boolean, unmaskedId: bigint): ResourceId {
@@ -199,7 +198,7 @@ export function checkLocalityOfResourceId(resourceId: AnyResourceId, expectedTxI
199
198
  if (!isLocalResourceId(resourceId)) return;
200
199
  if (extractTxId(resourceId) !== expectedTxId)
201
200
  throw Error(
202
- 'local id from another transaction, globalize id before leaking it from the transaction'
201
+ 'local id from another transaction, globalize id before leaking it from the transaction',
203
202
  );
204
203
  }
205
204
 
@@ -207,23 +206,23 @@ export function resourceIdToString(resourceId: OptionalAnyResourceId): string {
207
206
  if (isNullResourceId(resourceId)) return 'XX:0x0';
208
207
  if (isLocalResourceId(resourceId))
209
208
  return (
210
- (isRootResourceId(resourceId) ? 'R' : 'N') +
211
- 'L:0x' +
212
- (LocalIdMask & resourceId).toString(16) +
213
- '[0x' +
214
- extractTxId(resourceId).toString(16) +
215
- ']'
209
+ (isRootResourceId(resourceId) ? 'R' : 'N')
210
+ + 'L:0x'
211
+ + (LocalIdMask & resourceId).toString(16)
212
+ + '[0x'
213
+ + extractTxId(resourceId).toString(16)
214
+ + ']'
216
215
  );
217
216
  else
218
217
  return (
219
- (isRootResourceId(resourceId) ? 'R' : 'N') +
220
- 'G:0x' +
221
- (NoFlagsIdMask & resourceId).toString(16)
218
+ (isRootResourceId(resourceId) ? 'R' : 'N')
219
+ + 'G:0x'
220
+ + (NoFlagsIdMask & resourceId).toString(16)
222
221
  );
223
222
  }
224
223
 
225
- const resourceIdRegexp =
226
- /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\[0x(?<txid>[0-9a-fA-F]+)])?$/;
224
+ const resourceIdRegexp
225
+ = /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\[0x(?<txid>[0-9a-fA-F]+)])?$/;
227
226
 
228
227
  export function resourceIdFromString(str: string): OptionalAnyResourceId | undefined {
229
228
  const match = str.match(resourceIdRegexp);
@@ -243,8 +242,8 @@ export function bigintToResourceId(resourceId: bigint): ResourceId {
243
242
  return resourceId as ResourceId;
244
243
  }
245
244
 
246
- export function stringifyWithResourceId(object: unknown | undefined): string {
245
+ export function stringifyWithResourceId(object: unknown): string {
247
246
  return JSON.stringify(object, (key, value) =>
248
- typeof value === 'bigint' ? resourceIdToString(value as OptionalAnyResourceId) : value
247
+ typeof value === 'bigint' ? resourceIdToString(value as OptionalAnyResourceId) : value,
249
248
  );
250
249
  }