@milaboratories/pl-client 2.16.26 → 2.16.28

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 (212) hide show
  1. package/README.md +2 -1
  2. package/dist/core/PromiseTracker.cjs +1 -3
  3. package/dist/core/PromiseTracker.cjs.map +1 -1
  4. package/dist/core/PromiseTracker.d.ts.map +1 -1
  5. package/dist/core/PromiseTracker.js +1 -3
  6. package/dist/core/PromiseTracker.js.map +1 -1
  7. package/dist/core/StatefulPromise.cjs +4 -4
  8. package/dist/core/StatefulPromise.cjs.map +1 -1
  9. package/dist/core/StatefulPromise.d.ts +1 -1
  10. package/dist/core/StatefulPromise.d.ts.map +1 -1
  11. package/dist/core/StatefulPromise.js +4 -4
  12. package/dist/core/StatefulPromise.js.map +1 -1
  13. package/dist/core/advisory_locks.cjs +1 -1
  14. package/dist/core/advisory_locks.cjs.map +1 -1
  15. package/dist/core/advisory_locks.js +1 -1
  16. package/dist/core/advisory_locks.js.map +1 -1
  17. package/dist/core/auth.cjs.map +1 -1
  18. package/dist/core/auth.d.ts +1 -1
  19. package/dist/core/auth.js.map +1 -1
  20. package/dist/core/cache.d.ts +1 -1
  21. package/dist/core/client.cjs +14 -14
  22. package/dist/core/client.cjs.map +1 -1
  23. package/dist/core/client.d.ts +11 -11
  24. package/dist/core/client.d.ts.map +1 -1
  25. package/dist/core/client.js +14 -14
  26. package/dist/core/client.js.map +1 -1
  27. package/dist/core/config.cjs +39 -39
  28. package/dist/core/config.cjs.map +1 -1
  29. package/dist/core/config.d.ts +5 -5
  30. package/dist/core/config.js +39 -39
  31. package/dist/core/config.js.map +1 -1
  32. package/dist/core/default_client.cjs +23 -23
  33. package/dist/core/default_client.cjs.map +1 -1
  34. package/dist/core/default_client.d.ts +3 -3
  35. package/dist/core/default_client.js +23 -23
  36. package/dist/core/default_client.js.map +1 -1
  37. package/dist/core/driver.cjs +1 -1
  38. package/dist/core/driver.cjs.map +1 -1
  39. package/dist/core/driver.d.ts +5 -5
  40. package/dist/core/driver.js +1 -1
  41. package/dist/core/driver.js.map +1 -1
  42. package/dist/core/error_resource.cjs +2 -2
  43. package/dist/core/error_resource.cjs.map +1 -1
  44. package/dist/core/error_resource.d.ts +1 -1
  45. package/dist/core/error_resource.js +2 -2
  46. package/dist/core/error_resource.js.map +1 -1
  47. package/dist/core/errors.cjs +24 -24
  48. package/dist/core/errors.cjs.map +1 -1
  49. package/dist/core/errors.d.ts +1 -1
  50. package/dist/core/errors.d.ts.map +1 -1
  51. package/dist/core/errors.js +24 -24
  52. package/dist/core/errors.js.map +1 -1
  53. package/dist/core/final.cjs +43 -43
  54. package/dist/core/final.cjs.map +1 -1
  55. package/dist/core/final.d.ts +3 -3
  56. package/dist/core/final.d.ts.map +1 -1
  57. package/dist/core/final.js +43 -43
  58. package/dist/core/final.js.map +1 -1
  59. package/dist/core/ll_client.cjs +50 -43
  60. package/dist/core/ll_client.cjs.map +1 -1
  61. package/dist/core/ll_client.d.ts +9 -9
  62. package/dist/core/ll_client.d.ts.map +1 -1
  63. package/dist/core/ll_client.js +50 -43
  64. package/dist/core/ll_client.js.map +1 -1
  65. package/dist/core/ll_transaction.cjs +9 -9
  66. package/dist/core/ll_transaction.cjs.map +1 -1
  67. package/dist/core/ll_transaction.d.ts +7 -7
  68. package/dist/core/ll_transaction.d.ts.map +1 -1
  69. package/dist/core/ll_transaction.js +9 -9
  70. package/dist/core/ll_transaction.js.map +1 -1
  71. package/dist/core/stat.cjs.map +1 -1
  72. package/dist/core/stat.d.ts +1 -1
  73. package/dist/core/stat.js.map +1 -1
  74. package/dist/core/transaction.cjs +46 -46
  75. package/dist/core/transaction.cjs.map +1 -1
  76. package/dist/core/transaction.d.ts +7 -7
  77. package/dist/core/transaction.d.ts.map +1 -1
  78. package/dist/core/transaction.js +46 -46
  79. package/dist/core/transaction.js.map +1 -1
  80. package/dist/core/type_conversion.cjs +22 -22
  81. package/dist/core/type_conversion.cjs.map +1 -1
  82. package/dist/core/type_conversion.d.ts +3 -3
  83. package/dist/core/type_conversion.d.ts.map +1 -1
  84. package/dist/core/type_conversion.js +22 -22
  85. package/dist/core/type_conversion.js.map +1 -1
  86. package/dist/core/types.cjs +25 -25
  87. package/dist/core/types.cjs.map +1 -1
  88. package/dist/core/types.d.ts +7 -7
  89. package/dist/core/types.js +25 -25
  90. package/dist/core/types.js.map +1 -1
  91. package/dist/core/unauth_client.cjs +6 -4
  92. package/dist/core/unauth_client.cjs.map +1 -1
  93. package/dist/core/unauth_client.d.ts +4 -4
  94. package/dist/core/unauth_client.d.ts.map +1 -1
  95. package/dist/core/unauth_client.js +6 -4
  96. package/dist/core/unauth_client.js.map +1 -1
  97. package/dist/core/websocket_stream.cjs +22 -20
  98. package/dist/core/websocket_stream.cjs.map +1 -1
  99. package/dist/core/websocket_stream.d.ts +3 -3
  100. package/dist/core/websocket_stream.d.ts.map +1 -1
  101. package/dist/core/websocket_stream.js +22 -20
  102. package/dist/core/websocket_stream.js.map +1 -1
  103. package/dist/core/wire.d.ts +6 -6
  104. package/dist/core/wire.d.ts.map +1 -1
  105. package/dist/helpers/pl.cjs +19 -19
  106. package/dist/helpers/pl.cjs.map +1 -1
  107. package/dist/helpers/pl.d.ts +2 -2
  108. package/dist/helpers/pl.js +19 -19
  109. package/dist/helpers/pl.js.map +1 -1
  110. package/dist/helpers/poll.cjs +6 -6
  111. package/dist/helpers/poll.cjs.map +1 -1
  112. package/dist/helpers/poll.d.ts +4 -4
  113. package/dist/helpers/poll.d.ts.map +1 -1
  114. package/dist/helpers/poll.js +6 -6
  115. package/dist/helpers/poll.js.map +1 -1
  116. package/dist/helpers/retry_strategy.cjs +1 -1
  117. package/dist/helpers/retry_strategy.cjs.map +1 -1
  118. package/dist/helpers/retry_strategy.d.ts.map +1 -1
  119. package/dist/helpers/retry_strategy.js +1 -1
  120. package/dist/helpers/retry_strategy.js.map +1 -1
  121. package/dist/helpers/state_helpers.d.ts +2 -2
  122. package/dist/helpers/tx_helpers.cjs +2 -2
  123. package/dist/helpers/tx_helpers.cjs.map +1 -1
  124. package/dist/helpers/tx_helpers.d.ts +2 -2
  125. package/dist/helpers/tx_helpers.d.ts.map +1 -1
  126. package/dist/helpers/tx_helpers.js +2 -2
  127. package/dist/helpers/tx_helpers.js.map +1 -1
  128. package/dist/index.d.ts +16 -16
  129. package/dist/proto-grpc/google/protobuf/struct.d.ts +1 -1
  130. package/dist/proto-grpc/google/protobuf/struct.d.ts.map +1 -1
  131. package/dist/proto-rest/index.cjs +4 -5
  132. package/dist/proto-rest/index.cjs.map +1 -1
  133. package/dist/proto-rest/index.d.ts +4 -4
  134. package/dist/proto-rest/index.d.ts.map +1 -1
  135. package/dist/proto-rest/index.js +4 -5
  136. package/dist/proto-rest/index.js.map +1 -1
  137. package/dist/proto-rest/plapi.d.ts.map +1 -1
  138. package/dist/test/tcp-proxy.cjs +11 -10
  139. package/dist/test/tcp-proxy.cjs.map +1 -1
  140. package/dist/test/tcp-proxy.d.ts +1 -1
  141. package/dist/test/tcp-proxy.d.ts.map +1 -1
  142. package/dist/test/tcp-proxy.js +11 -10
  143. package/dist/test/tcp-proxy.js.map +1 -1
  144. package/dist/test/test_config.cjs +21 -17
  145. package/dist/test/test_config.cjs.map +1 -1
  146. package/dist/test/test_config.d.ts +6 -6
  147. package/dist/test/test_config.d.ts.map +1 -1
  148. package/dist/test/test_config.js +21 -17
  149. package/dist/test/test_config.js.map +1 -1
  150. package/dist/util/pl.cjs +1 -1
  151. package/dist/util/pl.cjs.map +1 -1
  152. package/dist/util/pl.js +1 -1
  153. package/dist/util/pl.js.map +1 -1
  154. package/dist/util/util.cjs +1 -1
  155. package/dist/util/util.cjs.map +1 -1
  156. package/dist/util/util.js +1 -1
  157. package/dist/util/util.js.map +1 -1
  158. package/package.json +23 -23
  159. package/src/core/PromiseTracker.ts +3 -4
  160. package/src/core/StatefulPromise.ts +17 -8
  161. package/src/core/abstract_stream.ts +3 -4
  162. package/src/core/advisory_locks.ts +1 -1
  163. package/src/core/auth.ts +2 -2
  164. package/src/core/cache.ts +1 -1
  165. package/src/core/client.test.ts +25 -21
  166. package/src/core/client.ts +54 -45
  167. package/src/core/config.test.ts +44 -44
  168. package/src/core/config.ts +49 -49
  169. package/src/core/connectivity.test.ts +69 -63
  170. package/src/core/default_client.ts +46 -46
  171. package/src/core/driver.ts +6 -6
  172. package/src/core/error.test.ts +5 -5
  173. package/src/core/error_resource.ts +3 -3
  174. package/src/core/errors.ts +39 -31
  175. package/src/core/final.ts +48 -55
  176. package/src/core/ll_client.test.ts +53 -36
  177. package/src/core/ll_client.ts +125 -81
  178. package/src/core/ll_transaction.test.ts +75 -49
  179. package/src/core/ll_transaction.ts +37 -35
  180. package/src/core/stat.ts +1 -1
  181. package/src/core/transaction.test.ts +65 -65
  182. package/src/core/transaction.ts +91 -84
  183. package/src/core/type_conversion.ts +30 -31
  184. package/src/core/types.test.ts +6 -6
  185. package/src/core/types.ts +35 -35
  186. package/src/core/unauth_client.test.ts +18 -14
  187. package/src/core/unauth_client.ts +14 -12
  188. package/src/core/websocket_stream.test.ts +52 -52
  189. package/src/core/websocket_stream.ts +41 -37
  190. package/src/core/wire.ts +10 -8
  191. package/src/helpers/pl.ts +22 -22
  192. package/src/helpers/poll.ts +13 -27
  193. package/src/helpers/retry_strategy.ts +2 -4
  194. package/src/helpers/rich_resource_types.test.ts +2 -2
  195. package/src/helpers/state_helpers.ts +3 -3
  196. package/src/helpers/tx_helpers.ts +9 -7
  197. package/src/index.ts +16 -16
  198. package/src/proto-grpc/google/protobuf/struct.ts +1 -1
  199. package/src/proto-rest/index.ts +17 -18
  200. package/src/proto-rest/plapi.ts +1472 -1472
  201. package/src/test/tcp-proxy.ts +55 -54
  202. package/src/test/test_config.test.ts +3 -3
  203. package/src/test/test_config.ts +51 -46
  204. package/src/util/pl.ts +1 -1
  205. package/src/util/util.test.ts +5 -5
  206. package/src/util/util.ts +1 -1
  207. package/dist/helpers/rich_resource_types.d.ts +0 -2
  208. package/dist/helpers/rich_resource_types.d.ts.map +0 -1
  209. package/dist/helpers/smart_accessors.d.ts +0 -2
  210. package/dist/helpers/smart_accessors.d.ts.map +0 -1
  211. package/src/helpers/rich_resource_types.ts +0 -84
  212. package/src/helpers/smart_accessors.ts +0 -146
@@ -10,7 +10,8 @@ import type {
10
10
  ResourceData,
11
11
  ResourceId,
12
12
  ResourceType,
13
- FutureFieldType } from './types';
13
+ FutureFieldType,
14
+ } from "./types";
14
15
  import {
15
16
  createLocalResourceId,
16
17
  ensureResourceIdNotNull,
@@ -18,28 +19,33 @@ import {
18
19
  isLocalResourceId,
19
20
  extractBasicResourceData,
20
21
  isNullResourceId,
21
- } from './types';
22
+ } from "./types";
22
23
  import type {
23
24
  ClientMessageRequest,
24
25
  LLPlTransaction,
25
26
  OneOfKind,
26
27
  ServerMessageResponse,
27
- } from './ll_transaction';
28
- import { TxAPI_Open_Request_WritableTx } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api';
29
- import type { NonUndefined } from 'utility-types';
30
- import { toBytes } from '../util/util';
31
- import { fieldTypeToProto, protoToField, protoToResource } from './type_conversion';
32
- import { canonicalJsonBytes, canonicalJsonGzBytes, deepFreeze, notEmpty } from '@milaboratories/ts-helpers';
33
- import { isNotFoundError } from './errors';
34
- import type { FinalResourceDataPredicate } from './final';
35
- import type { LRUCache } from 'lru-cache';
36
- import type { ResourceDataCacheRecord } from './cache';
37
- import type { TxStat } from './stat';
38
- import { initialTxStatWithoutTime } from './stat';
39
- import type { ErrorResourceData } from './error_resource';
40
- import { ErrorResourceType } from './error_resource';
41
- import { JsonGzObject, JsonObject } from '../helpers/pl';
42
- import { PromiseTracker } from './PromiseTracker';
28
+ } from "./ll_transaction";
29
+ import { TxAPI_Open_Request_WritableTx } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api";
30
+ import type { NonUndefined } from "utility-types";
31
+ import { toBytes } from "../util/util";
32
+ import { fieldTypeToProto, protoToField, protoToResource } from "./type_conversion";
33
+ import {
34
+ canonicalJsonBytes,
35
+ canonicalJsonGzBytes,
36
+ deepFreeze,
37
+ notEmpty,
38
+ } from "@milaboratories/ts-helpers";
39
+ import { isNotFoundError } from "./errors";
40
+ import type { FinalResourceDataPredicate } from "./final";
41
+ import type { LRUCache } from "lru-cache";
42
+ import type { ResourceDataCacheRecord } from "./cache";
43
+ import type { TxStat } from "./stat";
44
+ import { initialTxStatWithoutTime } from "./stat";
45
+ import type { ErrorResourceData } from "./error_resource";
46
+ import { ErrorResourceType } from "./error_resource";
47
+ import { JsonGzObject, JsonObject } from "../helpers/pl";
48
+ import { PromiseTracker } from "./PromiseTracker";
43
49
 
44
50
  /** Reference to resource, used only within transaction */
45
51
  export interface ResourceRef {
@@ -81,17 +87,17 @@ export type AnyFieldRef = _FieldId<AnyResourceRef>; // FieldRef | FieldId
81
87
  export type AnyRef = AnyResourceRef | AnyFieldRef;
82
88
 
83
89
  export function isField(ref: AnyRef): ref is AnyFieldRef {
84
- return ref.hasOwnProperty('resourceId') && ref.hasOwnProperty('fieldName');
90
+ return ref.hasOwnProperty("resourceId") && ref.hasOwnProperty("fieldName");
85
91
  }
86
92
 
87
93
  export function isResource(ref: AnyRef): ref is AnyResourceRef {
88
94
  return (
89
- typeof ref === 'bigint' || (ref.hasOwnProperty('globalId') && ref.hasOwnProperty('localId'))
95
+ typeof ref === "bigint" || (ref.hasOwnProperty("globalId") && ref.hasOwnProperty("localId"))
90
96
  );
91
97
  }
92
98
 
93
99
  export function isResourceId(ref: AnyRef): ref is ResourceId {
94
- return typeof ref === 'bigint' && !isLocalResourceId(ref) && !isNullResourceId(ref);
100
+ return typeof ref === "bigint" && !isLocalResourceId(ref) && !isNullResourceId(ref);
95
101
  }
96
102
 
97
103
  export function isFieldRef(ref: AnyFieldRef): ref is FieldRef {
@@ -99,7 +105,7 @@ export function isFieldRef(ref: AnyFieldRef): ref is FieldRef {
99
105
  }
100
106
 
101
107
  export function isResourceRef(ref: AnyResourceRef): ref is ResourceRef {
102
- return ref.hasOwnProperty('globalId') && ref.hasOwnProperty('localId');
108
+ return ref.hasOwnProperty("globalId") && ref.hasOwnProperty("localId");
103
109
  }
104
110
 
105
111
  export function toFieldId(ref: AnyFieldRef): AnyFieldId {
@@ -129,7 +135,7 @@ export function field(resourceId: AnyResourceRef, fieldName: string): AnyFieldRe
129
135
 
130
136
  /** If transaction commit failed due to write conflicts */
131
137
  export class TxCommitConflict extends Error {
132
- name = 'TxCommitConflict';
138
+ name = "TxCommitConflict";
133
139
  }
134
140
 
135
141
  async function notFoundToUndefined<T>(cb: () => Promise<T>): Promise<T | undefined> {
@@ -149,10 +155,7 @@ function tracked<T extends (this: PlTransaction, ...a: any[]) => Promise<any>>(
149
155
  value: T,
150
156
  _context: ClassMethodDecoratorContext,
151
157
  ) {
152
- return function (
153
- this: PlTransaction,
154
- ...args: Parameters<T>
155
- ): ReturnType<T> {
158
+ return function (this: PlTransaction, ...args: Parameters<T>): ReturnType<T> {
156
159
  return this.track(value.apply(this, args)) as ReturnType<T>;
157
160
  } as unknown as T;
158
161
  }
@@ -204,7 +207,7 @@ export class PlTransaction {
204
207
  // initiating transaction
205
208
  this.globalTxId = this.sendSingleAndParse(
206
209
  {
207
- oneofKind: 'txOpen',
210
+ oneofKind: "txOpen",
208
211
  txOpen: {
209
212
  name,
210
213
  enableFormattedErrors,
@@ -241,7 +244,7 @@ export class PlTransaction {
241
244
  await this.pending.awaitAll();
242
245
  }
243
246
 
244
- private sendSingleAndParse<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>, T>(
247
+ private sendSingleAndParse<Kind extends NonUndefined<ClientMessageRequest["oneofKind"]>, T>(
245
248
  r: OneOfKind<ClientMessageRequest, Kind>,
246
249
  parser: (resp: OneOfKind<ServerMessageResponse, Kind>) => T,
247
250
  ): Promise<T> {
@@ -257,7 +260,7 @@ export class PlTransaction {
257
260
  });
258
261
  }
259
262
 
260
- private sendMultiAndParse<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>, T>(
263
+ private sendMultiAndParse<Kind extends NonUndefined<ClientMessageRequest["oneofKind"]>, T>(
261
264
  r: OneOfKind<ClientMessageRequest, Kind>,
262
265
  parser: (resp: OneOfKind<ServerMessageResponse, Kind>[]) => T,
263
266
  ): Promise<T> {
@@ -273,21 +276,21 @@ export class PlTransaction {
273
276
  });
274
277
  }
275
278
 
276
- private async sendVoidSync<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>>(
279
+ private async sendVoidSync<Kind extends NonUndefined<ClientMessageRequest["oneofKind"]>>(
277
280
  r: OneOfKind<ClientMessageRequest, Kind>,
278
281
  ): Promise<void> {
279
282
  await this.ll.send(r, false);
280
283
  }
281
284
 
282
285
  /** Requests sent with this method should never produce recoverable errors */
283
- private sendVoidAsync<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>>(
286
+ private sendVoidAsync<Kind extends NonUndefined<ClientMessageRequest["oneofKind"]>>(
284
287
  r: OneOfKind<ClientMessageRequest, Kind>,
285
288
  ): void {
286
289
  void this.track(this.sendVoidSync(r));
287
290
  }
288
291
 
289
292
  private checkTxOpen() {
290
- if (this._completed) throw new Error('Transaction already closed');
293
+ if (this._completed) throw new Error("Transaction already closed");
291
294
  }
292
295
 
293
296
  public get completed() {
@@ -309,10 +312,9 @@ export class PlTransaction {
309
312
  await completeResult;
310
313
  await this.ll.await();
311
314
  } else {
312
- const commitResponse = this.track(this.sendSingleAndParse(
313
- { oneofKind: 'txCommit', txCommit: {} },
314
- (r) => r.txCommit.success,
315
- ));
315
+ const commitResponse = this.track(
316
+ this.sendSingleAndParse({ oneofKind: "txCommit", txCommit: {} }, (r) => r.txCommit.success),
317
+ );
316
318
 
317
319
  // send closing frame right after commit to save some time on round-trips
318
320
  const completeResult = this.track(this.ll.complete());
@@ -336,7 +338,7 @@ export class PlTransaction {
336
338
  // tx will accept no requests after this one
337
339
  this._completed = true;
338
340
 
339
- const discardResponse = this.sendVoidSync({ oneofKind: 'txDiscard', txDiscard: {} });
341
+ const discardResponse = this.sendVoidSync({ oneofKind: "txDiscard", txDiscard: {} });
340
342
  void this.track(discardResponse);
341
343
  // send closing frame right after commit to save some time on round-trips
342
344
  const completeResult = this.track(this.ll.complete());
@@ -371,7 +373,7 @@ export class PlTransaction {
371
373
 
372
374
  const globalId = this.sendSingleAndParse(
373
375
  {
374
- oneofKind: 'resourceCreateSingleton',
376
+ oneofKind: "resourceCreateSingleton",
375
377
  resourceCreateSingleton: {
376
378
  type,
377
379
  id: localId,
@@ -395,7 +397,7 @@ export class PlTransaction {
395
397
  ): Promise<BasicResourceData | ResourceData> {
396
398
  return this.sendSingleAndParse(
397
399
  {
398
- oneofKind: 'resourceGetSingleton',
400
+ oneofKind: "resourceGetSingleton",
399
401
  resourceGetSingleton: {
400
402
  data: Buffer.from(name),
401
403
  loadFields,
@@ -405,7 +407,7 @@ export class PlTransaction {
405
407
  );
406
408
  }
407
409
 
408
- private createResource<Kind extends NonUndefined<ClientMessageRequest['oneofKind']>>(
410
+ private createResource<Kind extends NonUndefined<ClientMessageRequest["oneofKind"]>>(
409
411
  root: boolean,
410
412
  req: (localId: LocalResourceId) => OneOfKind<ClientMessageRequest, Kind>,
411
413
  parser: (resp: OneOfKind<ServerMessageResponse, Kind>) => bigint,
@@ -423,7 +425,7 @@ export class PlTransaction {
423
425
  this._stat.rootsCreated++;
424
426
  return this.createResource(
425
427
  true,
426
- (localId) => ({ oneofKind: 'resourceCreateRoot', resourceCreateRoot: { type, id: localId } }),
428
+ (localId) => ({ oneofKind: "resourceCreateRoot", resourceCreateRoot: { type, id: localId } }),
427
429
  (r) => r.resourceCreateRoot.resourceId,
428
430
  );
429
431
  }
@@ -434,11 +436,12 @@ export class PlTransaction {
434
436
  return this.createResource(
435
437
  false,
436
438
  (localId) => ({
437
- oneofKind: 'resourceCreateStruct',
439
+ oneofKind: "resourceCreateStruct",
438
440
  resourceCreateStruct: {
439
441
  type,
440
442
  id: localId,
441
- data: data === undefined ? undefined : typeof data === 'string' ? Buffer.from(data) : data,
443
+ data:
444
+ data === undefined ? undefined : typeof data === "string" ? Buffer.from(data) : data,
442
445
  },
443
446
  }),
444
447
  (r) => r.resourceCreateStruct.resourceId,
@@ -451,11 +454,12 @@ export class PlTransaction {
451
454
  return this.createResource(
452
455
  false,
453
456
  (localId) => ({
454
- oneofKind: 'resourceCreateEphemeral',
457
+ oneofKind: "resourceCreateEphemeral",
455
458
  resourceCreateEphemeral: {
456
459
  type,
457
460
  id: localId,
458
- data: data === undefined ? undefined : typeof data === 'string' ? Buffer.from(data) : data,
461
+ data:
462
+ data === undefined ? undefined : typeof data === "string" ? Buffer.from(data) : data,
459
463
  },
460
464
  }),
461
465
  (r) => r.resourceCreateEphemeral.resourceId,
@@ -472,11 +476,11 @@ export class PlTransaction {
472
476
  return this.createResource(
473
477
  false,
474
478
  (localId) => ({
475
- oneofKind: 'resourceCreateValue',
479
+ oneofKind: "resourceCreateValue",
476
480
  resourceCreateValue: {
477
481
  type,
478
482
  id: localId,
479
- data: typeof data === 'string' ? Buffer.from(data) : data,
483
+ data: typeof data === "string" ? Buffer.from(data) : data,
480
484
  errorIfExists,
481
485
  },
482
486
  }),
@@ -495,41 +499,44 @@ export class PlTransaction {
495
499
  }
496
500
 
497
501
  public createError(message: string): ResourceRef {
498
- return this.createValue(ErrorResourceType, JSON.stringify({ message } satisfies ErrorResourceData));
502
+ return this.createValue(
503
+ ErrorResourceType,
504
+ JSON.stringify({ message } satisfies ErrorResourceData),
505
+ );
499
506
  }
500
507
 
501
508
  public setResourceName(name: string, rId: AnyResourceRef): void {
502
509
  this.sendVoidAsync({
503
- oneofKind: 'resourceNameSet',
510
+ oneofKind: "resourceNameSet",
504
511
  resourceNameSet: { resourceId: toResourceId(rId), name },
505
512
  });
506
513
  }
507
514
 
508
515
  public deleteResourceName(name: string): void {
509
- this.sendVoidAsync({ oneofKind: 'resourceNameDelete', resourceNameDelete: { name } });
516
+ this.sendVoidAsync({ oneofKind: "resourceNameDelete", resourceNameDelete: { name } });
510
517
  }
511
518
 
512
519
  public getResourceByName(name: string): Promise<ResourceId> {
513
520
  return this.sendSingleAndParse(
514
- { oneofKind: 'resourceNameGet', resourceNameGet: { name } },
521
+ { oneofKind: "resourceNameGet", resourceNameGet: { name } },
515
522
  (r) => ensureResourceIdNotNull(r.resourceNameGet.resourceId as OptionalResourceId),
516
523
  );
517
524
  }
518
525
 
519
526
  public checkResourceNameExists(name: string): Promise<boolean> {
520
527
  return this.sendSingleAndParse(
521
- { oneofKind: 'resourceNameExists', resourceNameExists: { name } },
528
+ { oneofKind: "resourceNameExists", resourceNameExists: { name } },
522
529
  (r) => r.resourceNameExists.exists,
523
530
  );
524
531
  }
525
532
 
526
533
  public removeResource(rId: ResourceId): void {
527
- this.sendVoidAsync({ oneofKind: 'resourceRemove', resourceRemove: { id: rId } });
534
+ this.sendVoidAsync({ oneofKind: "resourceRemove", resourceRemove: { id: rId } });
528
535
  }
529
536
 
530
537
  public resourceExists(rId: ResourceId): Promise<boolean> {
531
538
  return this.sendSingleAndParse(
532
- { oneofKind: 'resourceExists', resourceExists: { resourceId: rId } },
539
+ { oneofKind: "resourceExists", resourceExists: { resourceId: rId } },
533
540
  (r) => r.resourceExists.exists,
534
541
  );
535
542
  }
@@ -541,25 +548,25 @@ export class PlTransaction {
541
548
  /** This method may return stale resource state from cache if resource was removed */
542
549
  public async getResourceData(
543
550
  rId: AnyResourceRef,
544
- loadFields: boolean
551
+ loadFields: boolean,
545
552
  ): Promise<BasicResourceData | ResourceData>;
546
553
  /** This method may return stale resource state from cache if ignoreCache == false if resource was removed */
547
554
  public async getResourceData(
548
555
  rId: AnyResourceRef,
549
556
  loadFields: true,
550
- ignoreCache: boolean
557
+ ignoreCache: boolean,
551
558
  ): Promise<ResourceData>;
552
559
  /** This method may return stale resource state from cache if ignoreCache == false if resource was removed */
553
560
  public async getResourceData(
554
561
  rId: AnyResourceRef,
555
562
  loadFields: false,
556
- ignoreCache: boolean
563
+ ignoreCache: boolean,
557
564
  ): Promise<BasicResourceData>;
558
565
  /** This method may return stale resource state from cache if ignoreCache == false if resource was removed */
559
566
  public async getResourceData(
560
567
  rId: AnyResourceRef,
561
568
  loadFields: boolean,
562
- ignoreCache: boolean
569
+ ignoreCache: boolean,
563
570
  ): Promise<BasicResourceData | ResourceData>;
564
571
  @tracked
565
572
  public async getResourceData(
@@ -586,7 +593,7 @@ export class PlTransaction {
586
593
 
587
594
  const result = await this.sendSingleAndParse(
588
595
  {
589
- oneofKind: 'resourceGet',
596
+ oneofKind: "resourceGet",
590
597
  resourceGet: { resourceId: toResourceId(rId), loadFields: loadFields },
591
598
  },
592
599
  (r) => protoToResource(notEmpty(r.resourceGet.resource)),
@@ -630,15 +637,15 @@ export class PlTransaction {
630
637
 
631
638
  public async getResourceDataIfExists(
632
639
  rId: AnyResourceRef,
633
- loadFields: true
640
+ loadFields: true,
634
641
  ): Promise<ResourceData | undefined>;
635
642
  public async getResourceDataIfExists(
636
643
  rId: AnyResourceRef,
637
- loadFields: false
644
+ loadFields: false,
638
645
  ): Promise<BasicResourceData | undefined>;
639
646
  public async getResourceDataIfExists(
640
647
  rId: AnyResourceRef,
641
- loadFields: boolean
648
+ loadFields: boolean,
642
649
  ): Promise<BasicResourceData | ResourceData | undefined>;
643
650
  @tracked
644
651
  public async getResourceDataIfExists(
@@ -668,7 +675,7 @@ export class PlTransaction {
668
675
  public lockInputs(rId: AnyResourceRef): void {
669
676
  this._stat.inputsLocked++;
670
677
  this.sendVoidAsync({
671
- oneofKind: 'resourceLockInputs',
678
+ oneofKind: "resourceLockInputs",
672
679
  resourceLockInputs: { resourceId: toResourceId(rId) },
673
680
  });
674
681
  }
@@ -680,7 +687,7 @@ export class PlTransaction {
680
687
  public lockOutputs(rId: AnyResourceRef): void {
681
688
  this._stat.outputsLocked++;
682
689
  this.sendVoidAsync({
683
- oneofKind: 'resourceLockOutputs',
690
+ oneofKind: "resourceLockOutputs",
684
691
  resourceLockOutputs: { resourceId: toResourceId(rId) },
685
692
  });
686
693
  }
@@ -692,7 +699,7 @@ export class PlTransaction {
692
699
 
693
700
  public setResourceError(rId: AnyResourceRef, ref: AnyResourceRef): void {
694
701
  this.sendVoidAsync({
695
- oneofKind: 'resourceSetError',
702
+ oneofKind: "resourceSetError",
696
703
  resourceSetError: { resourceId: toResourceId(rId), errorResourceId: toResourceId(ref) },
697
704
  });
698
705
  }
@@ -704,7 +711,7 @@ export class PlTransaction {
704
711
  public createField(fId: AnyFieldRef, fieldType: FieldType, value?: AnyRef): void {
705
712
  this._stat.fieldsCreated++;
706
713
  this.sendVoidAsync({
707
- oneofKind: 'fieldCreate',
714
+ oneofKind: "fieldCreate",
708
715
  fieldCreate: { type: fieldTypeToProto(fieldType), id: toFieldId(fId) },
709
716
  });
710
717
  if (value !== undefined) this.setField(fId, value);
@@ -713,7 +720,7 @@ export class PlTransaction {
713
720
  public fieldExists(fId: AnyFieldRef): Promise<boolean> {
714
721
  return this.sendSingleAndParse(
715
722
  {
716
- oneofKind: 'fieldExists',
723
+ oneofKind: "fieldExists",
717
724
  fieldExists: { field: toFieldId(fId) },
718
725
  },
719
726
  (r) => r.fieldExists.exists,
@@ -724,18 +731,18 @@ export class PlTransaction {
724
731
  this._stat.fieldsSet++;
725
732
  if (isResource(ref))
726
733
  this.sendVoidAsync({
727
- oneofKind: 'fieldSet',
734
+ oneofKind: "fieldSet",
728
735
  fieldSet: {
729
736
  field: toFieldId(fId),
730
737
  value: {
731
738
  resourceId: toResourceId(ref),
732
- fieldName: '', // default value, read as undefined
739
+ fieldName: "", // default value, read as undefined
733
740
  },
734
741
  },
735
742
  });
736
743
  else
737
744
  this.sendVoidAsync({
738
- oneofKind: 'fieldSet',
745
+ oneofKind: "fieldSet",
739
746
  fieldSet: {
740
747
  field: toFieldId(fId),
741
748
  value: toFieldId(ref),
@@ -746,7 +753,7 @@ export class PlTransaction {
746
753
  public setFieldError(fId: AnyFieldRef, ref: AnyResourceRef): void {
747
754
  this._stat.fieldsSet++;
748
755
  this.sendVoidAsync({
749
- oneofKind: 'fieldSetError',
756
+ oneofKind: "fieldSetError",
750
757
  fieldSetError: { field: toFieldId(fId), errResourceId: toResourceId(ref) },
751
758
  });
752
759
  }
@@ -754,7 +761,7 @@ export class PlTransaction {
754
761
  public getField(fId: AnyFieldRef): Promise<FieldData> {
755
762
  this._stat.fieldsGet++;
756
763
  return this.sendSingleAndParse(
757
- { oneofKind: 'fieldGet', fieldGet: { field: toFieldId(fId) } },
764
+ { oneofKind: "fieldGet", fieldGet: { field: toFieldId(fId) } },
758
765
  (r) => protoToField(notEmpty(r.fieldGet.field)),
759
766
  );
760
767
  }
@@ -765,11 +772,11 @@ export class PlTransaction {
765
772
  }
766
773
 
767
774
  public resetField(fId: AnyFieldRef): void {
768
- this.sendVoidAsync({ oneofKind: 'fieldReset', fieldReset: { field: toFieldId(fId) } });
775
+ this.sendVoidAsync({ oneofKind: "fieldReset", fieldReset: { field: toFieldId(fId) } });
769
776
  }
770
777
 
771
778
  public removeField(fId: AnyFieldRef): void {
772
- this.sendVoidAsync({ oneofKind: 'fieldRemove', fieldRemove: { field: toFieldId(fId) } });
779
+ this.sendVoidAsync({ oneofKind: "fieldRemove", fieldRemove: { field: toFieldId(fId) } });
773
780
  }
774
781
 
775
782
  //
@@ -780,8 +787,8 @@ export class PlTransaction {
780
787
  public async listKeyValues(rId: AnyResourceRef): Promise<KeyValue[]> {
781
788
  const result = await this.sendMultiAndParse(
782
789
  {
783
- oneofKind: 'resourceKeyValueList',
784
- resourceKeyValueList: { resourceId: toResourceId(rId), startFrom: '', limit: 0 },
790
+ oneofKind: "resourceKeyValueList",
791
+ resourceKeyValueList: { resourceId: toResourceId(rId), startFrom: "", limit: 0 },
785
792
  },
786
793
  (r) => r.map((e) => e.resourceKeyValueList.record!),
787
794
  );
@@ -817,7 +824,7 @@ export class PlTransaction {
817
824
  this._stat.kvSetRequests++;
818
825
  this._stat.kvSetBytes++;
819
826
  this.sendVoidAsync({
820
- oneofKind: 'resourceKeyValueSet',
827
+ oneofKind: "resourceKeyValueSet",
821
828
  resourceKeyValueSet: {
822
829
  resourceId: toResourceId(rId),
823
830
  key,
@@ -828,7 +835,7 @@ export class PlTransaction {
828
835
 
829
836
  public deleteKValue(rId: AnyResourceRef, key: string): void {
830
837
  this.sendVoidAsync({
831
- oneofKind: 'resourceKeyValueDelete',
838
+ oneofKind: "resourceKeyValueDelete",
832
839
  resourceKeyValueDelete: {
833
840
  resourceId: toResourceId(rId),
834
841
  key,
@@ -840,7 +847,7 @@ export class PlTransaction {
840
847
  public async getKValue(rId: AnyResourceRef, key: string): Promise<Uint8Array> {
841
848
  const result = await this.sendSingleAndParse(
842
849
  {
843
- oneofKind: 'resourceKeyValueGet',
850
+ oneofKind: "resourceKeyValueGet",
844
851
  resourceKeyValueGet: { resourceId: toResourceId(rId), key },
845
852
  },
846
853
  (r) => r.resourceKeyValueGet.value,
@@ -869,7 +876,7 @@ export class PlTransaction {
869
876
  ): Promise<Uint8Array | undefined> {
870
877
  const result = await this.sendSingleAndParse(
871
878
  {
872
- oneofKind: 'resourceKeyValueGetIfExists',
879
+ oneofKind: "resourceKeyValueGetIfExists",
873
880
  resourceKeyValueGetIfExists: { resourceId: toResourceId(rId), key },
874
881
  },
875
882
  (r) =>
@@ -910,9 +917,9 @@ export class PlTransaction {
910
917
  /** Resolves existing or create first level resource from */
911
918
  public getFutureFieldValue(rId: AnyRef, fieldName: string, fieldType: FutureFieldType): FieldRef {
912
919
  const data = Buffer.from(JSON.stringify({ fieldName, fieldType }));
913
- const getFieldResource = this.createEphemeral({ name: 'json/getField', version: '1' }, data);
914
- this.setField({ resourceId: getFieldResource, fieldName: 'resource' }, rId);
915
- return { resourceId: getFieldResource, fieldName: 'result' };
920
+ const getFieldResource = this.createEphemeral({ name: "json/getField", version: "1" }, data);
921
+ this.setField({ resourceId: getFieldResource, fieldName: "resource" }, rId);
922
+ return { resourceId: getFieldResource, fieldName: "result" };
916
923
  }
917
924
 
918
925
  //
@@ -1,11 +1,12 @@
1
1
  import type {
2
2
  Field,
3
- Resource } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types';
3
+ Resource,
4
+ } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types";
4
5
  import {
5
6
  Field_ValueStatus,
6
7
  Resource_Kind,
7
- } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types';
8
- import { FieldType as GrpcFieldType } from '../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types';
8
+ } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types";
9
+ import { FieldType as GrpcFieldType } from "../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types";
9
10
  import type {
10
11
  FieldData,
11
12
  FieldStatus,
@@ -14,14 +15,12 @@ import type {
14
15
  ResourceData,
15
16
  ResourceId,
16
17
  ResourceKind,
17
- } from './types';
18
- import {
19
- NullResourceId,
20
- } from './types';
21
- import { assertNever, notEmpty } from '@milaboratories/ts-helpers';
22
- import { throwPlNotFoundError } from './errors';
18
+ } from "./types";
19
+ import { NullResourceId } from "./types";
20
+ import { assertNever, notEmpty } from "@milaboratories/ts-helpers";
21
+ import { throwPlNotFoundError } from "./errors";
23
22
 
24
- const ResourceErrorField = 'resourceError';
23
+ const ResourceErrorField = "resourceError";
25
24
 
26
25
  function resourceIsDeleted(proto: Resource): boolean {
27
26
  return proto.deletedTime !== undefined && proto.deletedTime.seconds !== 0n;
@@ -29,7 +28,7 @@ function resourceIsDeleted(proto: Resource): boolean {
29
28
 
30
29
  /** Throws "native" pl not found error, if resource is marked as deleted. */
31
30
  export function protoToResource(proto: Resource): ResourceData {
32
- if (resourceIsDeleted(proto)) throwPlNotFoundError('resource deleted');
31
+ if (resourceIsDeleted(proto)) throwPlNotFoundError("resource deleted");
33
32
  return {
34
33
  id: proto.id as ResourceId,
35
34
  originalResourceId: proto.originalResourceId as OptionalResourceId,
@@ -48,12 +47,12 @@ export function protoToResource(proto: Resource): ResourceData {
48
47
  function protoToResourceKind(proto: Resource_Kind): ResourceKind {
49
48
  switch (proto) {
50
49
  case Resource_Kind.STRUCTURAL:
51
- return 'Structural';
50
+ return "Structural";
52
51
  case Resource_Kind.VALUE:
53
- return 'Value';
52
+ return "Value";
54
53
  }
55
54
 
56
- throw new Error('invalid ResourceKind: ' + proto);
55
+ throw new Error("invalid ResourceKind: " + proto);
57
56
  }
58
57
 
59
58
  function protoToError(proto: Resource): OptionalResourceId {
@@ -75,48 +74,48 @@ export function protoToField(proto: Field): FieldData {
75
74
  function protoToFieldType(proto: GrpcFieldType): FieldType {
76
75
  switch (proto) {
77
76
  case GrpcFieldType.INPUT:
78
- return 'Input';
77
+ return "Input";
79
78
  case GrpcFieldType.OUTPUT:
80
- return 'Output';
79
+ return "Output";
81
80
  case GrpcFieldType.SERVICE:
82
- return 'Service';
81
+ return "Service";
83
82
  case GrpcFieldType.ONE_TIME_WRITABLE:
84
- return 'OTW';
83
+ return "OTW";
85
84
  case GrpcFieldType.DYNAMIC:
86
- return 'Dynamic';
85
+ return "Dynamic";
87
86
  case GrpcFieldType.MULTIPLE_TIMES_WRITABLE:
88
- return 'MTW';
87
+ return "MTW";
89
88
  default:
90
- throw new Error('invalid FieldType: ' + proto);
89
+ throw new Error("invalid FieldType: " + proto);
91
90
  }
92
91
  }
93
92
 
94
93
  function protoToFieldStatus(proto: Field_ValueStatus): FieldStatus {
95
94
  switch (proto) {
96
95
  case Field_ValueStatus.EMPTY:
97
- return 'Empty';
96
+ return "Empty";
98
97
  case Field_ValueStatus.ASSIGNED:
99
- return 'Assigned';
98
+ return "Assigned";
100
99
  case Field_ValueStatus.RESOLVED:
101
- return 'Resolved';
100
+ return "Resolved";
102
101
  default:
103
- throw new Error('invalid FieldStatus: ' + proto);
102
+ throw new Error("invalid FieldStatus: " + proto);
104
103
  }
105
104
  }
106
105
 
107
106
  export function fieldTypeToProto(type: FieldType): GrpcFieldType {
108
107
  switch (type) {
109
- case 'Input':
108
+ case "Input":
110
109
  return GrpcFieldType.INPUT;
111
- case 'Output':
110
+ case "Output":
112
111
  return GrpcFieldType.OUTPUT;
113
- case 'Dynamic':
112
+ case "Dynamic":
114
113
  return GrpcFieldType.DYNAMIC;
115
- case 'Service':
114
+ case "Service":
116
115
  return GrpcFieldType.SERVICE;
117
- case 'MTW':
116
+ case "MTW":
118
117
  return GrpcFieldType.MULTIPLE_TIMES_WRITABLE;
119
- case 'OTW':
118
+ case "OTW":
120
119
  return GrpcFieldType.ONE_TIME_WRITABLE;
121
120
  default:
122
121
  return assertNever(type);