@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
@@ -1,7 +1,7 @@
1
- import type { ProxySettings } from '@milaboratories/pl-http';
2
- import type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';
1
+ import type { ProxySettings } from "@milaboratories/pl-http";
2
+ import type { ExponentialBackoffRetryOptions } from "@milaboratories/ts-helpers";
3
3
 
4
- export const SUPPORTED_WIRE_PROTOCOLS = ['grpc', 'rest'] as const;
4
+ export const SUPPORTED_WIRE_PROTOCOLS = ["grpc", "rest"] as const;
5
5
  export type wireProtocol = (typeof SUPPORTED_WIRE_PROTOCOLS)[number];
6
6
 
7
7
  /** Base configuration structure for PL client */
@@ -69,7 +69,7 @@ export interface PlClientConfig {
69
69
  * What type of backoff strategy to use in transaction retries
70
70
  * (pl uses optimistic transaction model with regular retries in write transactions)
71
71
  */
72
- retryBackoffAlgorithm: 'exponential' | 'linear';
72
+ retryBackoffAlgorithm: "exponential" | "linear";
73
73
 
74
74
  /** Maximal number of attempts in */
75
75
  retryMaxAttempts: number;
@@ -95,7 +95,7 @@ export const DEFAULT_AUTH_MAX_REFRESH = 12 * 24 * 60 * 60;
95
95
 
96
96
  export const DEFAULT_MAX_CACHE_BYTES = 128_000_000; // 128 Mb
97
97
 
98
- export const DEFAULT_RETRY_BACKOFF_ALGORITHM = 'exponential';
98
+ export const DEFAULT_RETRY_BACKOFF_ALGORITHM = "exponential";
99
99
  export const DEFAULT_RETRY_MAX_ATTEMPTS = 21; // 1st attempt + 20 retries
100
100
  export const DEFAULT_RETRY_INITIAL_DELAY = 20; // 20 ms * <jitter> of sleep after first failure
101
101
  export const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on each round
@@ -103,7 +103,7 @@ export const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms
103
103
  export const DEFAULT_RETRY_JITTER = 0.3; // 30%
104
104
 
105
105
  export const DefaultRetryOptions: ExponentialBackoffRetryOptions = {
106
- type: 'exponentialBackoff',
106
+ type: "exponentialBackoff",
107
107
  maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
108
108
  initialDelay: DEFAULT_RETRY_INITIAL_DELAY,
109
109
  backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
@@ -113,12 +113,12 @@ export const DefaultRetryOptions: ExponentialBackoffRetryOptions = {
113
113
  type PlConfigOverrides = Partial<
114
114
  Pick<
115
115
  PlClientConfig,
116
- | 'ssl'
117
- | 'defaultRequestTimeout'
118
- | 'defaultROTransactionTimeout'
119
- | 'defaultRWTransactionTimeout'
120
- | 'httpProxy'
121
- | 'grpcProxy'
116
+ | "ssl"
117
+ | "defaultRequestTimeout"
118
+ | "defaultROTransactionTimeout"
119
+ | "defaultRWTransactionTimeout"
120
+ | "httpProxy"
121
+ | "grpcProxy"
122
122
  >
123
123
  >;
124
124
 
@@ -135,7 +135,7 @@ export function plAddressToConfig(
135
135
  address: string,
136
136
  overrides: PlConfigOverrides = {},
137
137
  ): PlClientConfig {
138
- if (address.indexOf('://') === -1)
138
+ if (address.indexOf("://") === -1)
139
139
  // non-url address
140
140
  return {
141
141
  hostAndPort: address,
@@ -163,24 +163,24 @@ export function plAddressToConfig(
163
163
  const url = new URL(address);
164
164
 
165
165
  if (
166
- url.protocol !== 'https:'
167
- && url.protocol !== 'http:'
168
- && url.protocol !== 'grpc:'
169
- && url.protocol !== 'tls:'
166
+ url.protocol !== "https:" &&
167
+ url.protocol !== "http:" &&
168
+ url.protocol !== "grpc:" &&
169
+ url.protocol !== "tls:"
170
170
  )
171
171
  throw new Error(`Unexpected URL schema: ${url.protocol}`);
172
172
 
173
- if (url.pathname !== '/' && url.pathname !== '')
173
+ if (url.pathname !== "/" && url.pathname !== "")
174
174
  throw new Error(`Unexpected URL path: ${url.pathname}`);
175
175
 
176
176
  let port = url.port;
177
177
  if (!port) {
178
178
  switch (url.protocol) {
179
- case 'http:':
180
- port = '80';
179
+ case "http:":
180
+ port = "80";
181
181
  break;
182
- case 'https:':
183
- port = '443';
182
+ case "https:":
183
+ port = "443";
184
184
  break;
185
185
  default:
186
186
  throw new Error(`Port must be specified explicitly for ${url.protocol} protocol.`);
@@ -189,45 +189,45 @@ export function plAddressToConfig(
189
189
 
190
190
  return {
191
191
  hostAndPort: `${url.hostname}:${port}`,
192
- alternativeRoot: url.searchParams.get('alternative-root') ?? undefined,
193
- ssl: url.protocol === 'https:' || url.protocol === 'tls:',
192
+ alternativeRoot: url.searchParams.get("alternative-root") ?? undefined,
193
+ ssl: url.protocol === "https:" || url.protocol === "tls:",
194
194
 
195
- wireProtocol: url.searchParams.get('wire-protocol') as wireProtocol ?? undefined,
195
+ wireProtocol: (url.searchParams.get("wire-protocol") as wireProtocol) ?? undefined,
196
196
 
197
197
  defaultRequestTimeout:
198
- parseInt(url.searchParams.get('request-timeout')) ?? DEFAULT_REQUEST_TIMEOUT,
198
+ parseInt(url.searchParams.get("request-timeout")) ?? DEFAULT_REQUEST_TIMEOUT,
199
199
  defaultROTransactionTimeout:
200
- parseInt(url.searchParams.get('ro-tx-timeout'))
201
- ?? parseInt(url.searchParams.get('tx-timeout'))
202
- ?? DEFAULT_RO_TX_TIMEOUT,
200
+ parseInt(url.searchParams.get("ro-tx-timeout")) ??
201
+ parseInt(url.searchParams.get("tx-timeout")) ??
202
+ DEFAULT_RO_TX_TIMEOUT,
203
203
  defaultRWTransactionTimeout:
204
- parseInt(url.searchParams.get('rw-tx-timeout'))
205
- ?? parseInt(url.searchParams.get('tx-timeout'))
206
- ?? DEFAULT_RW_TX_TIMEOUT,
204
+ parseInt(url.searchParams.get("rw-tx-timeout")) ??
205
+ parseInt(url.searchParams.get("tx-timeout")) ??
206
+ DEFAULT_RW_TX_TIMEOUT,
207
207
  authTTLSeconds: DEFAULT_TOKEN_TTL_SECONDS,
208
208
  authMaxRefreshSeconds: DEFAULT_AUTH_MAX_REFRESH,
209
- grpcProxy: url.searchParams.get('grpc-proxy') ?? undefined,
210
- httpProxy: url.searchParams.get('http-proxy') ?? undefined,
211
- user: url.username === '' ? undefined : url.username,
212
- password: url.password === '' ? undefined : url.password,
213
- txDelay: parseInt(url.searchParams.get('tx-delay')) ?? 0,
214
- forceSync: Boolean(url.searchParams.get('force-sync')),
209
+ grpcProxy: url.searchParams.get("grpc-proxy") ?? undefined,
210
+ httpProxy: url.searchParams.get("http-proxy") ?? undefined,
211
+ user: url.username === "" ? undefined : url.username,
212
+ password: url.password === "" ? undefined : url.password,
213
+ txDelay: parseInt(url.searchParams.get("tx-delay")) ?? 0,
214
+ forceSync: Boolean(url.searchParams.get("force-sync")),
215
215
 
216
- maxCacheBytes: parseInt(url.searchParams.get('max-cache-bytes')) ?? DEFAULT_MAX_CACHE_BYTES,
216
+ maxCacheBytes: parseInt(url.searchParams.get("max-cache-bytes")) ?? DEFAULT_MAX_CACHE_BYTES,
217
217
 
218
- retryBackoffAlgorithm: (url.searchParams.get('retry-backoff-algorithm')
219
- ?? DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,
218
+ retryBackoffAlgorithm: (url.searchParams.get("retry-backoff-algorithm") ??
219
+ DEFAULT_RETRY_BACKOFF_ALGORITHM) as any,
220
220
  retryMaxAttempts:
221
- parseInt(url.searchParams.get('retry-max-attempts')) ?? DEFAULT_RETRY_MAX_ATTEMPTS,
221
+ parseInt(url.searchParams.get("retry-max-attempts")) ?? DEFAULT_RETRY_MAX_ATTEMPTS,
222
222
  retryInitialDelay:
223
- parseInt(url.searchParams.get('retry-initial-delay')) ?? DEFAULT_RETRY_INITIAL_DELAY,
223
+ parseInt(url.searchParams.get("retry-initial-delay")) ?? DEFAULT_RETRY_INITIAL_DELAY,
224
224
  retryExponentialBackoffMultiplier:
225
- parseInt(url.searchParams.get('retry-exp-backoff-multiplier'))
226
- ?? DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
225
+ parseInt(url.searchParams.get("retry-exp-backoff-multiplier")) ??
226
+ DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
227
227
  retryLinearBackoffStep:
228
- parseInt(url.searchParams.get('retry-linear-backoff-step'))
229
- ?? DEFAULT_RETRY_LINEAR_BACKOFF_STEP,
230
- retryJitter: parseInt(url.searchParams.get('retry-backoff-jitter')) ?? DEFAULT_RETRY_JITTER,
228
+ parseInt(url.searchParams.get("retry-linear-backoff-step")) ??
229
+ DEFAULT_RETRY_LINEAR_BACKOFF_STEP,
230
+ retryJitter: parseInt(url.searchParams.get("retry-backoff-jitter")) ?? DEFAULT_RETRY_JITTER,
231
231
 
232
232
  ...overrides,
233
233
  };
@@ -257,7 +257,7 @@ export interface AuthOps {
257
257
  }
258
258
 
259
259
  /** Connection status. */
260
- export type PlConnectionStatus = 'OK' | 'Disconnected' | 'Unauthenticated';
260
+ export type PlConnectionStatus = "OK" | "Disconnected" | "Unauthenticated";
261
261
 
262
262
  /** Listener that will be called each time connection status changes. */
263
263
  export type PlConnectionStatusListener = (status: PlConnectionStatus) => void;
@@ -1,70 +1,76 @@
1
- import { withTempRoot } from '../test/test_config';
2
- import { StructTestResource } from '../helpers/pl';
3
- import { toGlobalFieldId } from './transaction';
4
- import { test, expect } from 'vitest';
5
- import { sleep } from '@milaboratories/ts-helpers';
6
- import { DisconnectedError } from './errors';
1
+ import { withTempRoot } from "../test/test_config";
2
+ import { StructTestResource } from "../helpers/pl";
3
+ import { toGlobalFieldId } from "./transaction";
4
+ import { test, expect } from "vitest";
5
+ import { sleep } from "@milaboratories/ts-helpers";
6
+ import { DisconnectedError } from "./errors";
7
7
 
8
- test('connectivity: disconnect during tx', async () => {
9
- await withTempRoot(async (pl, proxy) => {
10
- await expect(async () => {
11
- await pl.withWriteTx('resource1', async (tx) => {
12
- const r0 = tx.createStruct(StructTestResource);
13
- const r1 = tx.createStruct(StructTestResource);
14
- const f0 = { resourceId: tx.clientRoot, fieldName: 'test0' };
15
- const f1 = { resourceId: tx.clientRoot, fieldName: 'test1' };
16
-
17
- tx.createField(f0, 'Dynamic');
18
- tx.createField(f1, 'Dynamic');
19
- tx.setField(f0, r0);
20
- tx.setField(f1, r1);
21
-
22
- await proxy?.disconnectAll();
8
+ test("connectivity: disconnect during tx", async () => {
9
+ await withTempRoot(
10
+ async (pl, proxy) => {
11
+ await expect(async () => {
12
+ await pl.withWriteTx("resource1", async (tx) => {
13
+ const r0 = tx.createStruct(StructTestResource);
14
+ const r1 = tx.createStruct(StructTestResource);
15
+ const f0 = { resourceId: tx.clientRoot, fieldName: "test0" };
16
+ const f1 = { resourceId: tx.clientRoot, fieldName: "test1" };
23
17
 
24
- await sleep(1);
25
-
26
- const theField1 = { resourceId: r1, fieldName: 'theField' };
27
- tx.createField(theField1, 'Input');
28
- tx.lock(r1);
29
- tx.setField(theField1, tx.getFutureFieldValue(r0, 'theField', 'Input'));
30
-
31
- await tx.commit();
32
-
33
- return [await r0.globalId, await toGlobalFieldId(theField1)];
34
- });
35
- }).rejects.toThrow(DisconnectedError);
36
- }, { viaTcpProxy: true });
18
+ tx.createField(f0, "Dynamic");
19
+ tx.createField(f1, "Dynamic");
20
+ tx.setField(f0, r0);
21
+ tx.setField(f1, r1);
22
+
23
+ await proxy?.disconnectAll();
24
+
25
+ await sleep(1);
26
+
27
+ const theField1 = { resourceId: r1, fieldName: "theField" };
28
+ tx.createField(theField1, "Input");
29
+ tx.lock(r1);
30
+ tx.setField(theField1, tx.getFutureFieldValue(r0, "theField", "Input"));
31
+
32
+ await tx.commit();
33
+
34
+ return [await r0.globalId, await toGlobalFieldId(theField1)];
35
+ });
36
+ }).rejects.toThrow(DisconnectedError);
37
+ },
38
+ { viaTcpProxy: true },
39
+ );
37
40
  });
38
41
 
39
- test.skip('connectivity: latency', async () => {
40
- await withTempRoot(async (pl, proxy) => {
41
- proxy?.setLatency(10_000);
42
- await expect(async () => {
43
- const result = await pl.withWriteTx('resource1', async (tx) => {
44
- const r0 = tx.createStruct(StructTestResource);
45
- const r1 = tx.createStruct(StructTestResource);
46
- const f0 = { resourceId: tx.clientRoot, fieldName: 'test0' };
47
- const f1 = { resourceId: tx.clientRoot, fieldName: 'test1' };
48
-
49
- tx.createField(f0, 'Dynamic');
50
- tx.createField(f1, 'Dynamic');
51
- tx.setField(f0, r0);
52
- tx.setField(f1, r1);
53
-
54
- const theField1 = { resourceId: r1, fieldName: 'theField' };
55
- tx.createField(theField1, 'Input');
56
- tx.lock(r1);
57
- tx.setField(theField1, tx.getFutureFieldValue(r0, 'theField', 'Input'));
58
-
59
- await tx.commit().catch((err) => console.log('error committing tx', err));
60
-
61
- return [await r0.globalId, await toGlobalFieldId(theField1)];
62
- });
42
+ test.skip("connectivity: latency", async () => {
43
+ await withTempRoot(
44
+ async (pl, proxy) => {
45
+ proxy?.setLatency(10_000);
46
+ await expect(async () => {
47
+ const result = await pl.withWriteTx("resource1", async (tx) => {
48
+ const r0 = tx.createStruct(StructTestResource);
49
+ const r1 = tx.createStruct(StructTestResource);
50
+ const f0 = { resourceId: tx.clientRoot, fieldName: "test0" };
51
+ const f1 = { resourceId: tx.clientRoot, fieldName: "test1" };
52
+
53
+ tx.createField(f0, "Dynamic");
54
+ tx.createField(f1, "Dynamic");
55
+ tx.setField(f0, r0);
56
+ tx.setField(f1, r1);
57
+
58
+ const theField1 = { resourceId: r1, fieldName: "theField" };
59
+ tx.createField(theField1, "Input");
60
+ tx.lock(r1);
61
+ tx.setField(theField1, tx.getFutureFieldValue(r0, "theField", "Input"));
62
+
63
+ await tx.commit().catch((err) => console.log("error committing tx", err));
64
+
65
+ return [await r0.globalId, await toGlobalFieldId(theField1)];
66
+ });
63
67
 
64
- console.log('result', result);
68
+ console.log("result", result);
65
69
 
66
- return result;
67
- }).rejects.toThrow(Error);
68
- await new Promise(resolve => setTimeout(resolve, 1000));
69
- }, { viaTcpProxy: true });
70
+ return result;
71
+ }).rejects.toThrow(Error);
72
+ await new Promise((resolve) => setTimeout(resolve, 1000));
73
+ },
74
+ { viaTcpProxy: true },
75
+ );
70
76
  }, 60_000);
@@ -1,20 +1,20 @@
1
- import fs from 'node:fs';
2
- import type { AuthInformation, PlClientConfig } from './config';
3
- import { plAddressToConfig } from './config';
4
- import canonicalize from 'canonicalize';
5
- import YAML from 'yaml';
6
- import * as os from 'node:os';
7
- import * as path from 'node:path';
8
- import { notEmpty } from '@milaboratories/ts-helpers';
9
- import { UnauthenticatedPlClient } from './unauth_client';
10
- import { PlClient } from './client';
11
- import { createHash } from 'node:crypto';
12
- import { inferAuthRefreshTime } from './auth';
13
-
14
- const CONFIG_FILE_LOCAL_JSON = 'pl.json';
15
- const CONFIG_FILE_USER_JSON = path.join(os.homedir(), '.pl.json');
16
- const CONFIG_FILE_LOCAL_YAML = 'pl.yaml';
17
- const CONFIG_FILE_USER_YAML = path.join(os.homedir(), '.pl.yaml');
1
+ import fs from "node:fs";
2
+ import type { AuthInformation, PlClientConfig } from "./config";
3
+ import { plAddressToConfig } from "./config";
4
+ import canonicalize from "canonicalize";
5
+ import YAML from "yaml";
6
+ import * as os from "node:os";
7
+ import * as path from "node:path";
8
+ import { notEmpty } from "@milaboratories/ts-helpers";
9
+ import { UnauthenticatedPlClient } from "./unauth_client";
10
+ import { PlClient } from "./client";
11
+ import { createHash } from "node:crypto";
12
+ import { inferAuthRefreshTime } from "./auth";
13
+
14
+ const CONFIG_FILE_LOCAL_JSON = "pl.json";
15
+ const CONFIG_FILE_USER_JSON = path.join(os.homedir(), ".pl.json");
16
+ const CONFIG_FILE_LOCAL_YAML = "pl.yaml";
17
+ const CONFIG_FILE_USER_YAML = path.join(os.homedir(), ".pl.yaml");
18
18
  const CONF_FILE_SEQUENCE = [
19
19
  CONFIG_FILE_LOCAL_JSON,
20
20
  CONFIG_FILE_LOCAL_YAML,
@@ -22,30 +22,30 @@ const CONF_FILE_SEQUENCE = [
22
22
  CONFIG_FILE_USER_YAML,
23
23
  ];
24
24
 
25
- const AUTH_DATA_FILE = '.pl_auth.json';
25
+ const AUTH_DATA_FILE = ".pl_auth.json";
26
26
 
27
27
  type FileConfigOverrideFields =
28
- | 'grpcProxy'
29
- | 'httpProxy'
30
- | 'user'
31
- | 'password'
32
- | 'alternativeRoot'
33
- | 'defaultROTransactionTimeout'
34
- | 'defaultRWTransactionTimeout'
35
- | 'defaultRequestTimeout'
36
- | 'authTTLSeconds'
37
- | 'authMaxRefreshSeconds';
28
+ | "grpcProxy"
29
+ | "httpProxy"
30
+ | "user"
31
+ | "password"
32
+ | "alternativeRoot"
33
+ | "defaultROTransactionTimeout"
34
+ | "defaultRWTransactionTimeout"
35
+ | "defaultRequestTimeout"
36
+ | "authTTLSeconds"
37
+ | "authMaxRefreshSeconds";
38
38
  const FILE_CONFIG_OVERRIDE_FIELDS: FileConfigOverrideFields[] = [
39
- 'grpcProxy',
40
- 'httpProxy',
41
- 'user',
42
- 'password',
43
- 'alternativeRoot',
44
- 'defaultROTransactionTimeout',
45
- 'defaultRWTransactionTimeout',
46
- 'defaultRequestTimeout',
47
- 'authTTLSeconds',
48
- 'authMaxRefreshSeconds',
39
+ "grpcProxy",
40
+ "httpProxy",
41
+ "user",
42
+ "password",
43
+ "alternativeRoot",
44
+ "defaultROTransactionTimeout",
45
+ "defaultRWTransactionTimeout",
46
+ "defaultRequestTimeout",
47
+ "authTTLSeconds",
48
+ "authMaxRefreshSeconds",
49
49
  ];
50
50
 
51
51
  type PlConfigFile = {
@@ -62,8 +62,8 @@ interface AuthCache {
62
62
  export function tryGetFileConfig(): [PlConfigFile, string] | undefined {
63
63
  for (const confPath of CONF_FILE_SEQUENCE)
64
64
  if (fs.existsSync(confPath)) {
65
- const fileContent = fs.readFileSync(confPath, { encoding: 'utf-8' });
66
- if (confPath.endsWith('json')) return [JSON.parse(fileContent) as PlConfigFile, confPath];
65
+ const fileContent = fs.readFileSync(confPath, { encoding: "utf-8" });
66
+ if (confPath.endsWith("json")) return [JSON.parse(fileContent) as PlConfigFile, confPath];
67
67
  else return [YAML.parse(fileContent) as PlConfigFile, confPath];
68
68
  }
69
69
  return undefined;
@@ -83,7 +83,7 @@ function saveAuthInfoCallback(
83
83
  expiration: inferAuthRefreshTime(newAuthInfo, authMaxRefreshSeconds),
84
84
  } as AuthCache),
85
85
  ),
86
- 'utf8',
86
+ "utf8",
87
87
  );
88
88
  };
89
89
  }
@@ -110,21 +110,21 @@ export async function defaultPlClient(): Promise<PlClient> {
110
110
  }
111
111
 
112
112
  if (config === undefined)
113
- throw new Error('Can\'t find configuration to create default platform client.');
113
+ throw new Error("Can't find configuration to create default platform client.");
114
114
 
115
115
  if (process.env.PL_USER !== undefined) config.user = process.env.PL_USER;
116
116
 
117
117
  if (process.env.PL_PASSWORD !== undefined) config.user = process.env.PL_PASSWORD;
118
118
 
119
- const confHash = createHash('sha256')
119
+ const confHash = createHash("sha256")
120
120
  .update(Buffer.from(canonicalize(config)!))
121
- .digest('base64');
121
+ .digest("base64");
122
122
 
123
123
  let authInformation: AuthInformation | undefined = undefined;
124
124
 
125
125
  // try recover auth information from cache
126
126
  if (fs.existsSync(AUTH_DATA_FILE)) {
127
- const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: 'utf-8' }));
127
+ const cache: AuthCache = JSON.parse(fs.readFileSync(AUTH_DATA_FILE, { encoding: "utf-8" }));
128
128
  if (cache.confHash === confHash && cache.expiration > Date.now())
129
129
  authInformation = cache.authInformation;
130
130
  }
@@ -151,7 +151,7 @@ export async function defaultPlClient(): Promise<PlClient> {
151
151
  expiration: inferAuthRefreshTime(authInformation, config.authMaxRefreshSeconds),
152
152
  } as AuthCache),
153
153
  ),
154
- 'utf8',
154
+ "utf8",
155
155
  );
156
156
  }
157
157
 
@@ -1,8 +1,8 @@
1
- import type { PlClient } from './client';
2
- import type { RpcOptions } from '@protobuf-ts/runtime-rpc';
3
- import type { Dispatcher } from 'undici';
4
- import type { ResourceType } from './types';
5
- import type { WireClientProviderFactory } from './wire';
1
+ import type { PlClient } from "./client";
2
+ import type { RpcOptions } from "@protobuf-ts/runtime-rpc";
3
+ import type { Dispatcher } from "undici";
4
+ import type { ResourceType } from "./types";
5
+ import type { WireClientProviderFactory } from "./wire";
6
6
 
7
7
  /** Drivers must implement this interface */
8
8
  export interface PlDriver {
@@ -24,7 +24,7 @@ export interface PlDriverDefinition<Drv extends PlDriver> {
24
24
  export function addRTypeToMetadata(rType: ResourceType, options?: RpcOptions) {
25
25
  options = options ?? {};
26
26
  options.meta = options.meta ?? {};
27
- options.meta['resourceType'] = `${rType.name}:${rType.version}`;
27
+ options.meta["resourceType"] = `${rType.name}:${rType.version}`;
28
28
 
29
29
  return options;
30
30
  }
@@ -1,14 +1,14 @@
1
- import * as tp from 'node:timers/promises';
2
- import { isTimeoutOrCancelError } from './errors';
3
- import { test, expect } from 'vitest';
1
+ import * as tp from "node:timers/promises";
2
+ import { isTimeoutOrCancelError } from "./errors";
3
+ import { test, expect } from "vitest";
4
4
 
5
- test('timeout of sleep error type detection', async () => {
5
+ test("timeout of sleep error type detection", async () => {
6
6
  let noError = false;
7
7
  try {
8
8
  await tp.setTimeout(1000, undefined, { signal: AbortSignal.timeout(10) });
9
9
  noError = true;
10
10
  } catch (err: unknown) {
11
- expect((err as any).code).toStrictEqual('ABORT_ERR');
11
+ expect((err as any).code).toStrictEqual("ABORT_ERR");
12
12
  expect(isTimeoutOrCancelError(err)).toEqual(true);
13
13
  }
14
14
  expect(noError).toBe(false);
@@ -1,10 +1,10 @@
1
- import type { ResourceType } from './types';
1
+ import type { ResourceType } from "./types";
2
2
 
3
3
  export type ErrorResourceData = {
4
4
  message: string;
5
5
  };
6
6
 
7
7
  export const ErrorResourceType: ResourceType = {
8
- name: 'json/resourceError',
9
- version: '1',
8
+ name: "json/resourceError",
9
+ version: "1",
10
10
  };