@milaboratories/pl-client 2.11.8 → 2.11.10

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 (184) hide show
  1. package/dist/core/auth.cjs +24 -0
  2. package/dist/core/auth.cjs.map +1 -0
  3. package/dist/core/auth.d.ts +1 -1
  4. package/dist/core/auth.js +21 -0
  5. package/dist/core/auth.js.map +1 -0
  6. package/dist/core/cache.d.ts +1 -1
  7. package/dist/core/client.cjs +288 -0
  8. package/dist/core/client.cjs.map +1 -0
  9. package/dist/core/client.d.ts +10 -10
  10. package/dist/core/client.js +267 -0
  11. package/dist/core/client.js.map +1 -0
  12. package/dist/core/config.cjs +111 -0
  13. package/dist/core/config.cjs.map +1 -0
  14. package/dist/core/config.d.ts +1 -1
  15. package/dist/core/config.js +95 -0
  16. package/dist/core/config.js.map +1 -0
  17. package/dist/core/default_client.cjs +143 -0
  18. package/dist/core/default_client.cjs.map +1 -0
  19. package/dist/core/default_client.d.ts +1 -1
  20. package/dist/core/default_client.js +120 -0
  21. package/dist/core/default_client.js.map +1 -0
  22. package/dist/core/driver.cjs +14 -0
  23. package/dist/core/driver.cjs.map +1 -0
  24. package/dist/core/driver.d.ts +5 -5
  25. package/dist/core/driver.js +12 -0
  26. package/dist/core/driver.js.map +1 -0
  27. package/dist/core/error_resource.cjs +9 -0
  28. package/dist/core/error_resource.cjs.map +1 -0
  29. package/dist/core/error_resource.d.ts +1 -1
  30. package/dist/core/error_resource.js +7 -0
  31. package/dist/core/error_resource.js.map +1 -0
  32. package/dist/core/errors.cjs +106 -0
  33. package/dist/core/errors.cjs.map +1 -0
  34. package/dist/core/errors.d.ts +1 -1
  35. package/dist/core/errors.js +93 -0
  36. package/dist/core/errors.js.map +1 -0
  37. package/dist/core/final.cjs +98 -0
  38. package/dist/core/final.cjs.map +1 -0
  39. package/dist/core/final.d.ts +2 -2
  40. package/dist/core/final.js +96 -0
  41. package/dist/core/final.js.map +1 -0
  42. package/dist/core/grpc.d.ts +1 -1
  43. package/dist/core/http.d.ts +1 -0
  44. package/dist/core/ll_client.cjs +266 -0
  45. package/dist/core/ll_client.cjs.map +1 -0
  46. package/dist/core/ll_client.d.ts +3 -3
  47. package/dist/core/ll_client.js +264 -0
  48. package/dist/core/ll_client.js.map +1 -0
  49. package/dist/core/ll_transaction.cjs +236 -0
  50. package/dist/core/ll_transaction.cjs.map +1 -0
  51. package/dist/core/ll_transaction.d.ts +2 -2
  52. package/dist/core/ll_transaction.js +233 -0
  53. package/dist/core/ll_transaction.js.map +1 -0
  54. package/dist/core/stat.cjs +74 -0
  55. package/dist/core/stat.cjs.map +1 -0
  56. package/dist/core/stat.js +70 -0
  57. package/dist/core/stat.js.map +1 -0
  58. package/dist/core/transaction.cjs +626 -0
  59. package/dist/core/transaction.cjs.map +1 -0
  60. package/dist/core/transaction.d.ts +6 -6
  61. package/dist/core/transaction.js +613 -0
  62. package/dist/core/transaction.js.map +1 -0
  63. package/dist/core/type_conversion.cjs +106 -0
  64. package/dist/core/type_conversion.cjs.map +1 -0
  65. package/dist/core/type_conversion.d.ts +2 -2
  66. package/dist/core/type_conversion.js +102 -0
  67. package/dist/core/type_conversion.js.map +1 -0
  68. package/dist/core/types.cjs +159 -0
  69. package/dist/core/types.cjs.map +1 -0
  70. package/dist/core/types.js +134 -0
  71. package/dist/core/types.js.map +1 -0
  72. package/dist/core/unauth_client.cjs +43 -0
  73. package/dist/core/unauth_client.cjs.map +1 -0
  74. package/dist/core/unauth_client.d.ts +2 -2
  75. package/dist/core/unauth_client.js +41 -0
  76. package/dist/core/unauth_client.js.map +1 -0
  77. package/dist/helpers/pl.cjs +124 -0
  78. package/dist/helpers/pl.cjs.map +1 -0
  79. package/dist/helpers/pl.d.ts +10 -2
  80. package/dist/helpers/pl.js +94 -0
  81. package/dist/helpers/pl.js.map +1 -0
  82. package/dist/helpers/poll.cjs +148 -0
  83. package/dist/helpers/poll.cjs.map +1 -0
  84. package/dist/helpers/poll.d.ts +4 -4
  85. package/dist/helpers/poll.js +123 -0
  86. package/dist/helpers/poll.js.map +1 -0
  87. package/dist/helpers/rich_resource_types.d.ts +1 -0
  88. package/dist/helpers/smart_accessors.d.ts +1 -0
  89. package/dist/helpers/state_helpers.d.ts +1 -1
  90. package/dist/helpers/tx_helpers.cjs +25 -0
  91. package/dist/helpers/tx_helpers.cjs.map +1 -0
  92. package/dist/helpers/tx_helpers.d.ts +2 -2
  93. package/dist/helpers/tx_helpers.js +23 -0
  94. package/dist/helpers/tx_helpers.js.map +1 -0
  95. package/dist/index.cjs +99 -0
  96. package/dist/index.cjs.map +1 -0
  97. package/dist/index.js +16 -1
  98. package/dist/index.js.map +1 -1
  99. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.cjs +71 -0
  100. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -0
  101. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +7 -2
  102. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.js +69 -0
  103. package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -0
  104. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +8 -5
  105. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +7 -2
  106. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +8 -5
  107. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +8 -3
  108. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +11 -5
  109. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +8 -3
  110. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +13 -5
  111. package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +7 -2
  112. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12238 -0
  113. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -0
  114. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +223 -0
  115. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -0
  116. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +57 -5
  117. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +221 -0
  118. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -0
  119. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +21 -7
  120. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.js +12086 -0
  121. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -0
  122. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1127 -0
  123. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -0
  124. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +11 -4
  125. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1113 -0
  126. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -0
  127. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +152 -0
  128. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -0
  129. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +6 -1
  130. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +149 -0
  131. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -0
  132. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +22 -7
  133. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +500 -0
  134. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -0
  135. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +7 -2
  136. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +496 -0
  137. package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -0
  138. package/dist/proto/google/api/http.d.ts +6 -1
  139. package/dist/proto/google/protobuf/any.cjs +151 -0
  140. package/dist/proto/google/protobuf/any.cjs.map +1 -0
  141. package/dist/proto/google/protobuf/any.d.ts +10 -1
  142. package/dist/proto/google/protobuf/any.js +149 -0
  143. package/dist/proto/google/protobuf/any.js.map +1 -0
  144. package/dist/proto/google/protobuf/descriptor.d.ts +6 -1
  145. package/dist/proto/google/protobuf/duration.cjs +105 -0
  146. package/dist/proto/google/protobuf/duration.cjs.map +1 -0
  147. package/dist/proto/google/protobuf/duration.d.ts +9 -1
  148. package/dist/proto/google/protobuf/duration.js +103 -0
  149. package/dist/proto/google/protobuf/duration.js.map +1 -0
  150. package/dist/proto/google/protobuf/empty.d.ts +6 -1
  151. package/dist/proto/google/protobuf/struct.d.ts +9 -1
  152. package/dist/proto/google/protobuf/timestamp.cjs +133 -0
  153. package/dist/proto/google/protobuf/timestamp.cjs.map +1 -0
  154. package/dist/proto/google/protobuf/timestamp.d.ts +9 -1
  155. package/dist/proto/google/protobuf/timestamp.js +131 -0
  156. package/dist/proto/google/protobuf/timestamp.js.map +1 -0
  157. package/dist/proto/google/protobuf/wrappers.d.ts +9 -1
  158. package/dist/test/test_config.cjs +149 -0
  159. package/dist/test/test_config.cjs.map +1 -0
  160. package/dist/test/test_config.d.ts +1 -1
  161. package/dist/test/test_config.js +123 -0
  162. package/dist/test/test_config.js.map +1 -0
  163. package/dist/util/pl.cjs +8 -0
  164. package/dist/util/pl.cjs.map +1 -0
  165. package/dist/util/pl.js +6 -0
  166. package/dist/util/pl.js.map +1 -0
  167. package/dist/util/util.cjs +17 -0
  168. package/dist/util/util.cjs.map +1 -0
  169. package/dist/util/util.js +15 -0
  170. package/dist/util/util.js.map +1 -0
  171. package/package.json +14 -11
  172. package/src/core/client.test.ts +1 -0
  173. package/src/core/config.test.ts +1 -0
  174. package/src/core/error.test.ts +1 -0
  175. package/src/core/ll_client.test.ts +1 -0
  176. package/src/core/ll_transaction.test.ts +1 -0
  177. package/src/core/transaction.test.ts +1 -0
  178. package/src/core/types.test.ts +1 -0
  179. package/src/core/unauth_client.test.ts +1 -0
  180. package/src/helpers/rich_resource_types.test.ts +2 -0
  181. package/src/test/test_config.test.ts +1 -0
  182. package/src/util/util.test.ts +1 -0
  183. package/dist/index.mjs +0 -14537
  184. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,264 @@
1
+ import { PlatformClient } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.js';
2
+ import { compressionAlgorithms, ChannelCredentials, InterceptingCall, status } from '@grpc/grpc-js';
3
+ import { plAddressToConfig } from './config.js';
4
+ import { GrpcTransport } from '@protobuf-ts/grpc-transport';
5
+ import { LLPlTransaction } from './ll_transaction.js';
6
+ import { parsePlJwt } from '../util/pl.js';
7
+ import { inferAuthRefreshTime } from './auth.js';
8
+ import { defaultHttpDispatcher } from '@milaboratories/pl-http';
9
+
10
+ class GrpcClientProviderImpl {
11
+ grpcTransport;
12
+ clientConstructor;
13
+ client = undefined;
14
+ constructor(grpcTransport, clientConstructor) {
15
+ this.grpcTransport = grpcTransport;
16
+ this.clientConstructor = clientConstructor;
17
+ }
18
+ reset() {
19
+ this.client = undefined;
20
+ }
21
+ get() {
22
+ if (this.client === undefined)
23
+ this.client = this.clientConstructor(this.grpcTransport());
24
+ return this.client;
25
+ }
26
+ }
27
+ /** Abstract out low level networking and authorization details */
28
+ class LLPlClient {
29
+ ops;
30
+ conf;
31
+ /** Initial authorization information */
32
+ authInformation;
33
+ /** Will be executed by the client when it is required */
34
+ onAuthUpdate;
35
+ /** Will be executed if auth-related error happens during normal client operation */
36
+ onAuthError;
37
+ /** Will be executed by the client when it is required */
38
+ onAuthRefreshProblem;
39
+ /** Threshold after which auth info refresh is required */
40
+ refreshTimestamp;
41
+ _status = 'OK';
42
+ statusListener;
43
+ grpcInterceptors;
44
+ _grpcTransport;
45
+ providers = [];
46
+ grpcPl;
47
+ httpDispatcher;
48
+ constructor(configOrAddress, ops = {}) {
49
+ this.ops = ops;
50
+ this.conf
51
+ = typeof configOrAddress === 'string' ? plAddressToConfig(configOrAddress) : configOrAddress;
52
+ this.grpcInterceptors = [];
53
+ const { auth, statusListener, shouldUseGzip } = ops;
54
+ if (auth !== undefined) {
55
+ this.refreshTimestamp = inferAuthRefreshTime(auth.authInformation, this.conf.authMaxRefreshSeconds);
56
+ this.grpcInterceptors.push(this.createAuthInterceptor());
57
+ this.authInformation = auth.authInformation;
58
+ this.onAuthUpdate = auth.onUpdate;
59
+ this.onAuthRefreshProblem = auth.onUpdateError;
60
+ this.onAuthError = auth.onAuthError;
61
+ }
62
+ this.grpcInterceptors.push(this.createErrorInterceptor());
63
+ // initialize _grpcTransport and _grpcPl
64
+ this.initGrpc(shouldUseGzip ?? false);
65
+ this.httpDispatcher = defaultHttpDispatcher(this.conf.httpProxy);
66
+ if (statusListener !== undefined) {
67
+ this.statusListener = statusListener;
68
+ statusListener(this._status);
69
+ }
70
+ this.grpcPl = this.createGrpcClientProvider((transport) => new PlatformClient(transport));
71
+ }
72
+ /**
73
+ * Initializes (or reinitializes) _grpcTransport and _grpcPl
74
+ * @param gzip - whether to enable gzip compression
75
+ */
76
+ initGrpc(gzip) {
77
+ const clientOptions = {
78
+ 'grpc.keepalive_time_ms': 30_000, // 30 seconds
79
+ 'interceptors': this.grpcInterceptors,
80
+ };
81
+ if (gzip)
82
+ clientOptions['grpc.default_compression_algorithm'] = compressionAlgorithms.gzip;
83
+ //
84
+ // Leaving it here for now
85
+ // https://github.com/grpc/grpc-node/issues/2788
86
+ //
87
+ // We should implement message pooling algorithm to overcome hardcoded NO_DELAY behaviour
88
+ // of HTTP/2 and allow our small messages to batch together.
89
+ //
90
+ const grpcOptions = {
91
+ host: this.conf.hostAndPort,
92
+ timeout: this.conf.defaultRequestTimeout,
93
+ channelCredentials: this.conf.ssl
94
+ ? ChannelCredentials.createSsl()
95
+ : ChannelCredentials.createInsecure(),
96
+ clientOptions,
97
+ };
98
+ if (this.conf.grpcProxy)
99
+ process.env.grpc_proxy = this.conf.grpcProxy;
100
+ else
101
+ delete process.env.grpc_proxy;
102
+ const oldTransport = this._grpcTransport;
103
+ this._grpcTransport = new GrpcTransport(grpcOptions);
104
+ // Reset all providers to let them reinitialize their clients
105
+ for (let i = 0; i < this.providers.length; i++) {
106
+ const provider = this.providers[i].deref();
107
+ if (provider === undefined) {
108
+ // at the same time we need to remove providers that are no longer valid
109
+ this.providers.splice(i, 1);
110
+ i--;
111
+ }
112
+ else {
113
+ provider.reset();
114
+ }
115
+ }
116
+ if (oldTransport !== undefined)
117
+ oldTransport.close();
118
+ }
119
+ providerCleanupCounter = 0;
120
+ /**
121
+ * Creates a provider for a grpc client. Returned provider will create fresh client whenever the underlying transport is reset.
122
+ *
123
+ * @param clientConstructor - a factory function that creates a grpc client
124
+ */
125
+ createGrpcClientProvider(clientConstructor) {
126
+ // We need to cleanup providers periodically to avoid memory leaks.
127
+ // This is a simple heuristic to avoid memory leaks.
128
+ // We could use a more sophisticated algorithm, but this is good enough for now.
129
+ this.providerCleanupCounter++;
130
+ if (this.providerCleanupCounter >= 16) {
131
+ for (let i = 0; i < this.providers.length; i++) {
132
+ const provider = this.providers[i].deref();
133
+ if (provider === undefined) {
134
+ this.providers.splice(i, 1);
135
+ i--;
136
+ }
137
+ }
138
+ this.providerCleanupCounter = 0;
139
+ }
140
+ const provider = new GrpcClientProviderImpl(() => this._grpcTransport, clientConstructor);
141
+ this.providers.push(new WeakRef(provider));
142
+ return provider;
143
+ }
144
+ get grpcTransport() {
145
+ return this._grpcTransport;
146
+ }
147
+ /** Returns true if client is authenticated. Even with anonymous auth information
148
+ * connection is considered authenticated. Unauthenticated clients are used for
149
+ * login and similar tasks, see {@link UnauthenticatedPlClient}. */
150
+ get authenticated() {
151
+ return this.authInformation !== undefined;
152
+ }
153
+ /** null means anonymous connection */
154
+ get authUser() {
155
+ if (!this.authenticated)
156
+ throw new Error('Client is not authenticated');
157
+ if (this.authInformation?.jwtToken)
158
+ return parsePlJwt(this.authInformation?.jwtToken).user.login;
159
+ else
160
+ return null;
161
+ }
162
+ updateStatus(newStatus) {
163
+ process.nextTick(() => {
164
+ if (this._status !== newStatus) {
165
+ this._status = newStatus;
166
+ if (this.statusListener !== undefined)
167
+ this.statusListener(this._status);
168
+ if (this.onAuthError !== undefined)
169
+ this.onAuthError();
170
+ }
171
+ });
172
+ }
173
+ get status() {
174
+ return this._status;
175
+ }
176
+ authRefreshInProgress = false;
177
+ refreshAuthInformationIfNeeded() {
178
+ if (this.refreshTimestamp === undefined
179
+ || Date.now() < this.refreshTimestamp
180
+ || this.authRefreshInProgress
181
+ || this._status === 'Unauthenticated')
182
+ return;
183
+ // Running refresh in background`
184
+ this.authRefreshInProgress = true;
185
+ void (async () => {
186
+ try {
187
+ const response = await this.grpcPl.get().getJWTToken({
188
+ expiration: {
189
+ seconds: BigInt(this.conf.authTTLSeconds),
190
+ nanos: 0,
191
+ },
192
+ }).response;
193
+ this.authInformation = { jwtToken: response.token };
194
+ this.refreshTimestamp = inferAuthRefreshTime(this.authInformation, this.conf.authMaxRefreshSeconds);
195
+ if (this.onAuthUpdate)
196
+ this.onAuthUpdate(this.authInformation);
197
+ }
198
+ catch (e) {
199
+ if (this.onAuthRefreshProblem)
200
+ this.onAuthRefreshProblem(e);
201
+ }
202
+ finally {
203
+ this.authRefreshInProgress = false;
204
+ }
205
+ })();
206
+ }
207
+ /** Detects certain errors and update client status accordingly */
208
+ createErrorInterceptor() {
209
+ return (options, nextCall) => {
210
+ return new InterceptingCall(nextCall(options), {
211
+ start: (metadata, listener, next) => {
212
+ next(metadata, {
213
+ onReceiveStatus: (status$1, next) => {
214
+ if (status$1.code == status.UNAUTHENTICATED)
215
+ // (!!!) don't change to "==="
216
+ this.updateStatus('Unauthenticated');
217
+ if (status$1.code == status.UNAVAILABLE)
218
+ // (!!!) don't change to "==="
219
+ this.updateStatus('Disconnected');
220
+ next(status$1);
221
+ },
222
+ });
223
+ },
224
+ });
225
+ };
226
+ }
227
+ /** Injects authentication information if needed */
228
+ createAuthInterceptor() {
229
+ return (options, nextCall) => {
230
+ return new InterceptingCall(nextCall(options), {
231
+ start: (metadata, listener, next) => {
232
+ if (this.authInformation?.jwtToken !== undefined) {
233
+ metadata.set('authorization', 'Bearer ' + this.authInformation.jwtToken);
234
+ this.refreshAuthInformationIfNeeded();
235
+ next(metadata, listener);
236
+ }
237
+ else {
238
+ next(metadata, listener);
239
+ }
240
+ },
241
+ });
242
+ };
243
+ }
244
+ createTx(rw, ops = {}) {
245
+ return new LLPlTransaction((abortSignal) => {
246
+ let totalAbortSignal = abortSignal;
247
+ if (ops.abortSignal)
248
+ totalAbortSignal = AbortSignal.any([totalAbortSignal, ops.abortSignal]);
249
+ return this.grpcPl.get().tx({
250
+ abort: totalAbortSignal,
251
+ timeout: ops.timeout
252
+ ?? (rw ? this.conf.defaultRWTransactionTimeout : this.conf.defaultROTransactionTimeout),
253
+ });
254
+ });
255
+ }
256
+ /** Closes underlying transport */
257
+ async close() {
258
+ this.grpcTransport.close();
259
+ await this.httpDispatcher.destroy();
260
+ }
261
+ }
262
+
263
+ export { LLPlClient };
264
+ //# sourceMappingURL=ll_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ll_client.js","sources":["../../src/core/ll_client.ts"],"sourcesContent":["import { PlatformClient } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api.client';\nimport type { ClientOptions, Interceptor } from '@grpc/grpc-js';\nimport {\n ChannelCredentials,\n InterceptingCall,\n status as GrpcStatus,\n compressionAlgorithms,\n} from '@grpc/grpc-js';\nimport type {\n AuthInformation,\n AuthOps,\n PlClientConfig,\n PlConnectionStatus,\n PlConnectionStatusListener,\n} from './config';\nimport { plAddressToConfig } from './config';\nimport type { GrpcOptions } from '@protobuf-ts/grpc-transport';\nimport { GrpcTransport } from '@protobuf-ts/grpc-transport';\nimport { LLPlTransaction } from './ll_transaction';\nimport { parsePlJwt } from '../util/pl';\nimport type { Dispatcher } from 'undici';\nimport { inferAuthRefreshTime } from './auth';\nimport { defaultHttpDispatcher } from '@milaboratories/pl-http';\nimport type { GrpcClientProvider, GrpcClientProviderFactory } from './grpc';\n\nexport interface PlCallOps {\n timeout?: number;\n abortSignal?: AbortSignal;\n}\n\nclass GrpcClientProviderImpl<Client> implements GrpcClientProvider<Client> {\n private client: Client | undefined = undefined;\n\n constructor(private readonly grpcTransport: () => GrpcTransport, private readonly clientConstructor: (transport: GrpcTransport) => Client) {}\n\n public reset(): void {\n this.client = undefined;\n }\n\n public get(): Client {\n if (this.client === undefined)\n this.client = this.clientConstructor(this.grpcTransport());\n return this.client;\n }\n}\n\n/** Abstract out low level networking and authorization details */\nexport class LLPlClient implements GrpcClientProviderFactory {\n public readonly conf: PlClientConfig;\n\n /** Initial authorization information */\n private authInformation?: AuthInformation;\n /** Will be executed by the client when it is required */\n private readonly onAuthUpdate?: (newInfo: AuthInformation) => void;\n /** Will be executed if auth-related error happens during normal client operation */\n private readonly onAuthError?: () => void;\n /** Will be executed by the client when it is required */\n private readonly onAuthRefreshProblem?: (error: unknown) => void;\n /** Threshold after which auth info refresh is required */\n private refreshTimestamp?: number;\n\n private _status: PlConnectionStatus = 'OK';\n private readonly statusListener?: PlConnectionStatusListener;\n\n private readonly grpcInterceptors: Interceptor[];\n private _grpcTransport!: GrpcTransport;\n private readonly providers: WeakRef<GrpcClientProviderImpl<any>>[] = [];\n\n public readonly grpcPl: GrpcClientProvider<PlatformClient>;\n\n public readonly httpDispatcher: Dispatcher;\n\n constructor(\n configOrAddress: PlClientConfig | string,\n private readonly ops: {\n auth?: AuthOps;\n statusListener?: PlConnectionStatusListener;\n shouldUseGzip?: boolean;\n } = {},\n ) {\n this.conf\n = typeof configOrAddress === 'string' ? plAddressToConfig(configOrAddress) : configOrAddress;\n\n this.grpcInterceptors = [];\n\n const { auth, statusListener, shouldUseGzip } = ops;\n\n if (auth !== undefined) {\n this.refreshTimestamp = inferAuthRefreshTime(\n auth.authInformation,\n this.conf.authMaxRefreshSeconds,\n );\n this.grpcInterceptors.push(this.createAuthInterceptor());\n this.authInformation = auth.authInformation;\n this.onAuthUpdate = auth.onUpdate;\n this.onAuthRefreshProblem = auth.onUpdateError;\n this.onAuthError = auth.onAuthError;\n }\n\n this.grpcInterceptors.push(this.createErrorInterceptor());\n\n // initialize _grpcTransport and _grpcPl\n this.initGrpc(shouldUseGzip ?? false);\n\n this.httpDispatcher = defaultHttpDispatcher(this.conf.httpProxy);\n\n if (statusListener !== undefined) {\n this.statusListener = statusListener;\n statusListener(this._status);\n }\n\n this.grpcPl = this.createGrpcClientProvider((transport) => new PlatformClient(transport));\n }\n\n /**\n * Initializes (or reinitializes) _grpcTransport and _grpcPl\n * @param gzip - whether to enable gzip compression\n */\n private initGrpc(gzip: boolean) {\n const clientOptions: ClientOptions = {\n 'grpc.keepalive_time_ms': 30_000, // 30 seconds\n 'interceptors': this.grpcInterceptors,\n };\n\n if (gzip) clientOptions['grpc.default_compression_algorithm'] = compressionAlgorithms.gzip;\n\n //\n // Leaving it here for now\n // https://github.com/grpc/grpc-node/issues/2788\n //\n // We should implement message pooling algorithm to overcome hardcoded NO_DELAY behaviour\n // of HTTP/2 and allow our small messages to batch together.\n //\n const grpcOptions: GrpcOptions = {\n host: this.conf.hostAndPort,\n timeout: this.conf.defaultRequestTimeout,\n channelCredentials: this.conf.ssl\n ? ChannelCredentials.createSsl()\n : ChannelCredentials.createInsecure(),\n clientOptions,\n };\n\n if (this.conf.grpcProxy) process.env.grpc_proxy = this.conf.grpcProxy;\n else delete process.env.grpc_proxy;\n\n const oldTransport = this._grpcTransport;\n\n this._grpcTransport = new GrpcTransport(grpcOptions);\n\n // Reset all providers to let them reinitialize their clients\n for (let i = 0; i < this.providers.length; i++) {\n const provider = this.providers[i].deref();\n if (provider === undefined) {\n // at the same time we need to remove providers that are no longer valid\n this.providers.splice(i, 1);\n i--;\n } else {\n provider.reset();\n }\n }\n\n if (oldTransport !== undefined) oldTransport.close();\n }\n\n private providerCleanupCounter = 0;\n\n /**\n * Creates a provider for a grpc client. Returned provider will create fresh client whenever the underlying transport is reset.\n *\n * @param clientConstructor - a factory function that creates a grpc client\n */\n public createGrpcClientProvider<Client>(clientConstructor: (transport: GrpcTransport) => Client): GrpcClientProvider<Client> {\n // We need to cleanup providers periodically to avoid memory leaks.\n // This is a simple heuristic to avoid memory leaks.\n // We could use a more sophisticated algorithm, but this is good enough for now.\n this.providerCleanupCounter++;\n if (this.providerCleanupCounter >= 16) {\n for (let i = 0; i < this.providers.length; i++) {\n const provider = this.providers[i].deref();\n if (provider === undefined) {\n this.providers.splice(i, 1);\n i--;\n }\n }\n this.providerCleanupCounter = 0;\n }\n\n const provider = new GrpcClientProviderImpl<Client>(() => this._grpcTransport, clientConstructor);\n this.providers.push(new WeakRef(provider));\n return provider;\n }\n\n public get grpcTransport(): GrpcTransport {\n return this._grpcTransport;\n }\n\n /** Returns true if client is authenticated. Even with anonymous auth information\n * connection is considered authenticated. Unauthenticated clients are used for\n * login and similar tasks, see {@link UnauthenticatedPlClient}. */\n public get authenticated(): boolean {\n return this.authInformation !== undefined;\n }\n\n /** null means anonymous connection */\n public get authUser(): string | null {\n if (!this.authenticated) throw new Error('Client is not authenticated');\n if (this.authInformation?.jwtToken)\n return parsePlJwt(this.authInformation?.jwtToken).user.login;\n else return null;\n }\n\n private updateStatus(newStatus: PlConnectionStatus) {\n process.nextTick(() => {\n if (this._status !== newStatus) {\n this._status = newStatus;\n if (this.statusListener !== undefined) this.statusListener(this._status);\n if (this.onAuthError !== undefined) this.onAuthError();\n }\n });\n }\n\n public get status(): PlConnectionStatus {\n return this._status;\n }\n\n private authRefreshInProgress: boolean = false;\n\n private refreshAuthInformationIfNeeded(): void {\n if (\n this.refreshTimestamp === undefined\n || Date.now() < this.refreshTimestamp\n || this.authRefreshInProgress\n || this._status === 'Unauthenticated'\n )\n return;\n\n // Running refresh in background`\n this.authRefreshInProgress = true;\n void (async () => {\n try {\n const response = await this.grpcPl.get().getJWTToken({\n expiration: {\n seconds: BigInt(this.conf.authTTLSeconds),\n nanos: 0,\n },\n }).response;\n this.authInformation = { jwtToken: response.token };\n this.refreshTimestamp = inferAuthRefreshTime(\n this.authInformation,\n this.conf.authMaxRefreshSeconds,\n );\n if (this.onAuthUpdate) this.onAuthUpdate(this.authInformation);\n } catch (e: unknown) {\n if (this.onAuthRefreshProblem) this.onAuthRefreshProblem(e);\n } finally {\n this.authRefreshInProgress = false;\n }\n })();\n }\n\n /** Detects certain errors and update client status accordingly */\n private createErrorInterceptor(): Interceptor {\n return (options, nextCall) => {\n return new InterceptingCall(nextCall(options), {\n start: (metadata, listener, next) => {\n next(metadata, {\n onReceiveStatus: (status, next) => {\n if (status.code == GrpcStatus.UNAUTHENTICATED)\n // (!!!) don't change to \"===\"\n this.updateStatus('Unauthenticated');\n if (status.code == GrpcStatus.UNAVAILABLE)\n // (!!!) don't change to \"===\"\n this.updateStatus('Disconnected');\n next(status);\n },\n });\n },\n });\n };\n }\n\n /** Injects authentication information if needed */\n private createAuthInterceptor(): Interceptor {\n return (options, nextCall) => {\n return new InterceptingCall(nextCall(options), {\n start: (metadata, listener, next) => {\n if (this.authInformation?.jwtToken !== undefined) {\n metadata.set('authorization', 'Bearer ' + this.authInformation.jwtToken);\n this.refreshAuthInformationIfNeeded();\n next(metadata, listener);\n } else {\n next(metadata, listener);\n }\n },\n });\n };\n }\n\n createTx(rw: boolean, ops: PlCallOps = {}): LLPlTransaction {\n return new LLPlTransaction((abortSignal) => {\n let totalAbortSignal = abortSignal;\n if (ops.abortSignal) totalAbortSignal = AbortSignal.any([totalAbortSignal, ops.abortSignal]);\n return this.grpcPl.get().tx({\n abort: totalAbortSignal,\n timeout:\n ops.timeout\n ?? (rw ? this.conf.defaultRWTransactionTimeout : this.conf.defaultROTransactionTimeout),\n });\n });\n }\n\n /** Closes underlying transport */\n public async close() {\n this.grpcTransport.close();\n await this.httpDispatcher.destroy();\n }\n}\n"],"names":["status","GrpcStatus"],"mappings":";;;;;;;;;AA8BA,MAAM,sBAAsB,CAAA;AAGG,IAAA,aAAA;AAAqD,IAAA,iBAAA;IAF1E,MAAM,GAAuB,SAAS;IAE9C,WAAA,CAA6B,aAAkC,EAAmB,iBAAuD,EAAA;QAA5G,IAAA,CAAA,aAAa,GAAb,aAAa;QAAwC,IAAA,CAAA,iBAAiB,GAAjB,iBAAiB;IAAyC;IAErI,KAAK,GAAA;AACV,QAAA,IAAI,CAAC,MAAM,GAAG,SAAS;IACzB;IAEO,GAAG,GAAA;AACR,QAAA,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;AAC3B,YAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC,MAAM;IACpB;AACD;AAED;MACa,UAAU,CAAA;AA2BF,IAAA,GAAA;AA1BH,IAAA,IAAI;;AAGZ,IAAA,eAAe;;AAEN,IAAA,YAAY;;AAEZ,IAAA,WAAW;;AAEX,IAAA,oBAAoB;;AAE7B,IAAA,gBAAgB;IAEhB,OAAO,GAAuB,IAAI;AACzB,IAAA,cAAc;AAEd,IAAA,gBAAgB;AACzB,IAAA,cAAc;IACL,SAAS,GAA2C,EAAE;AAEvD,IAAA,MAAM;AAEN,IAAA,cAAc;IAE9B,WAAA,CACE,eAAwC,EACvB,GAAA,GAIb,EAAE,EAAA;QAJW,IAAA,CAAA,GAAG,GAAH,GAAG;AAMpB,QAAA,IAAI,CAAC;AACD,cAAA,OAAO,eAAe,KAAK,QAAQ,GAAG,iBAAiB,CAAC,eAAe,CAAC,GAAG,eAAe;AAE9F,QAAA,IAAI,CA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;oBAC1B;yBAAO;AACL,wBAAA,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC;oBAC1B;gBACF,CAAC;AACF,aAAA,CAAC;AACJ,QAAA,CAAC;IACH;AAEA,IAAA,QAAQ,CAAC,EAAW,EAAE,GAAA,GAAiB,EAAE,EAAA;AACvC,QAAA,OAAO,IAAI,eAAe,CAAC,CAAC,WAAW,KAAI;YACzC,IAAI,gBAAgB,GAAG,WAAW;YAClC,IAAI,GAAG,CAAC,WAAW;AAAE,gBAAA,gBAAgB,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;YAC5F,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;AAC1B,gBAAA,KAAK,EAAE,gBAAgB;gBACvB,OAAO,EACL,GAAG,CAAC;AACD,wBAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC;AAC1F,aAAA,CAAC;AACJ,QAAA,CAAC,CAAC;IACJ;;AAGO,IAAA,MAAM,KAAK,GAAA;AAChB,QAAA,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE;AAC1B,QAAA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;IACrC;AACD;;;;"}
@@ -0,0 +1,236 @@
1
+ 'use strict';
2
+
3
+ var Denque = require('denque');
4
+ var errors = require('./errors.cjs');
5
+
6
+ function createResponseHandler(kind, expectMultiResponse, resolve, reject) {
7
+ return { kind, expectMultiResponse, resolve, reject };
8
+ }
9
+ function isRecoverable(status) {
10
+ return status.code === errors.PlErrorCodeNotFound;
11
+ }
12
+ class RethrowError extends Error {
13
+ rethrowLambda;
14
+ name = 'RethrowError';
15
+ constructor(rethrowLambda) {
16
+ super('Rethrow error, you should never see this one.');
17
+ this.rethrowLambda = rethrowLambda;
18
+ }
19
+ }
20
+ class LLPlTransaction {
21
+ /** Bidirectional channel through which transaction communicates with the server */
22
+ stream;
23
+ /** Used to abort ongoing transaction stream */
24
+ abortController = new AbortController();
25
+ /** Counter of sent requests, used to calculate which future response will correspond to this request.
26
+ * Incremented on each sent request. */
27
+ requestIdxCounter = 0;
28
+ /** Queue from which incoming message processor takes handlers to which pass incoming messages */
29
+ responseHandlerQueue = new Denque();
30
+ /** Each new resource, created by the transaction, is assigned with virtual (local) resource id, to make it possible
31
+ * to populate its fields without awaiting actual resource id. This counter tracks those ids on client side, the
32
+ * same way it is tracked on the server, so client can synchronously return such ids to the user. */
33
+ localResourceIdCounter = 0n;
34
+ /** Switches to true, when this transaction closes due to normal or exceptional conditions. Prevents any new messages
35
+ * to be sent to the stream. */
36
+ closed = false;
37
+ /** Whether the outgoing stream was already closed. */
38
+ completed = false;
39
+ /** If this transaction was terminated due to error, this is a generator to create new errors if corresponding response is required. */
40
+ errorFactory;
41
+ /** Timestamp when transaction was opened */
42
+ openTimestamp = Date.now();
43
+ incomingProcessorResult;
44
+ constructor(streamFactory) {
45
+ this.stream = streamFactory(this.abortController.signal);
46
+ // Starting incoming event processor
47
+ this.incomingProcessorResult = this.incomingEventProcessor();
48
+ }
49
+ assignErrorFactoryIfNotSet(errorFactory, reject) {
50
+ if (reject !== undefined)
51
+ reject(new RethrowError(errorFactory));
52
+ if (this.errorFactory)
53
+ return errorFactory;
54
+ this.errorFactory = errorFactory;
55
+ return errorFactory;
56
+ }
57
+ async incomingEventProcessor() {
58
+ /** Counter of received responses, used to check consistency of responses.
59
+ * Increments on each received message. */
60
+ let expectedId = -1;
61
+ // defined externally to make possible to communicate any processing errors
62
+ // to the specific request on which it happened
63
+ let currentHandler = undefined;
64
+ let responseAggregator = undefined;
65
+ try {
66
+ for await (const message of this.stream.responses) {
67
+ if (currentHandler === undefined) {
68
+ currentHandler = this.responseHandlerQueue.shift();
69
+ if (currentHandler === undefined) {
70
+ this.assignErrorFactoryIfNotSet(() => {
71
+ throw new Error(`orphan incoming message`);
72
+ });
73
+ break;
74
+ }
75
+ // allocating response aggregator array
76
+ if (currentHandler.expectMultiResponse)
77
+ responseAggregator = [];
78
+ expectedId++;
79
+ }
80
+ if (message.requestId !== expectedId) {
81
+ const errorMessage = `out of order messages, ${message.requestId} !== ${expectedId}`;
82
+ this.assignErrorFactoryIfNotSet(() => {
83
+ throw new Error(errorMessage);
84
+ });
85
+ break;
86
+ }
87
+ if (message.error !== undefined) {
88
+ const status = message.error;
89
+ if (isRecoverable(status)) {
90
+ currentHandler.reject(new RethrowError(() => {
91
+ throw new errors.RecoverablePlError(status);
92
+ }));
93
+ currentHandler = undefined;
94
+ if (message.multiMessage !== undefined && !message.multiMessage.isLast) {
95
+ this.assignErrorFactoryIfNotSet(() => {
96
+ throw new Error('Unexpected message sequence.');
97
+ });
98
+ break;
99
+ }
100
+ // We can continue to work after recoverable errors
101
+ continue;
102
+ }
103
+ else {
104
+ this.assignErrorFactoryIfNotSet(() => {
105
+ throw new errors.UnrecoverablePlError(status);
106
+ }, currentHandler.reject);
107
+ currentHandler = undefined;
108
+ // In case of unrecoverable errors we close the transaction
109
+ break;
110
+ }
111
+ }
112
+ if (currentHandler.kind !== message.response.oneofKind
113
+ && message?.multiMessage?.isEmpty !== true) {
114
+ const errorMessage = `inconsistent request response types: ${currentHandler.kind} !== ${message.response.oneofKind}`;
115
+ this.assignErrorFactoryIfNotSet(() => {
116
+ throw new Error(errorMessage);
117
+ }, currentHandler.reject);
118
+ currentHandler = undefined;
119
+ break;
120
+ }
121
+ if (currentHandler.expectMultiResponse !== (message.multiMessage !== undefined)) {
122
+ const errorMessage = `inconsistent multi state: ${currentHandler.expectMultiResponse} !== ${message.multiMessage !== undefined}`;
123
+ this.assignErrorFactoryIfNotSet(() => {
124
+ throw new Error(errorMessage);
125
+ }, currentHandler.reject);
126
+ currentHandler = undefined;
127
+ break;
128
+ }
129
+ // <- at this point we validated everything we can at this level
130
+ if (message.multiMessage !== undefined) {
131
+ if (!message.multiMessage.isEmpty) {
132
+ if (message.multiMessage.id !== responseAggregator.length + 1) {
133
+ const errorMessage = `inconsistent multi id: ${message.multiMessage.id} !== ${responseAggregator.length + 1}`;
134
+ this.assignErrorFactoryIfNotSet(() => {
135
+ throw new Error(errorMessage);
136
+ }, currentHandler.reject);
137
+ currentHandler = undefined;
138
+ break;
139
+ }
140
+ responseAggregator.push(message.response);
141
+ }
142
+ if (message.multiMessage.isLast) {
143
+ currentHandler.resolve(responseAggregator);
144
+ responseAggregator = undefined;
145
+ currentHandler = undefined;
146
+ }
147
+ }
148
+ else {
149
+ currentHandler.resolve(message.response);
150
+ currentHandler = undefined;
151
+ }
152
+ }
153
+ }
154
+ catch (e) {
155
+ return this.assignErrorFactoryIfNotSet(() => {
156
+ errors.rethrowMeaningfulError(e, true);
157
+ }, currentHandler?.reject);
158
+ }
159
+ finally {
160
+ await this.close();
161
+ }
162
+ return null;
163
+ }
164
+ /** Executed after termination of incoming message processor */
165
+ async close() {
166
+ if (this.closed)
167
+ return;
168
+ this.closed = true;
169
+ // Rejecting all messages
170
+ while (true) {
171
+ const handler = this.responseHandlerQueue.shift();
172
+ if (!handler)
173
+ break;
174
+ if (this.errorFactory)
175
+ handler.reject(new RethrowError(this.errorFactory));
176
+ else
177
+ handler.reject(new Error('no reply'));
178
+ }
179
+ // closing outgoing stream
180
+ await this.stream.requests.complete();
181
+ }
182
+ /** Forcefully close the transaction, terminate all connections and reject all pending requests */
183
+ abort(cause) {
184
+ this.assignErrorFactoryIfNotSet(() => {
185
+ throw new Error(`transaction aborted`, { cause });
186
+ });
187
+ this.abortController.abort(cause);
188
+ }
189
+ /** Await incoming message loop termination and throw any leftover errors if it was unsuccessful */
190
+ async await() {
191
+ // for those who want to understand "why?":
192
+ // this way there is no hanging promise that will complete with rejection
193
+ // until await is implicitly requested, the this.incomingProcessorResult
194
+ // always resolves with success
195
+ const processingResult = await this.incomingProcessorResult;
196
+ if (processingResult !== null)
197
+ processingResult();
198
+ }
199
+ /** Generate proper client message and send it to the server, and returns a promise of future response. */
200
+ async send(r, expectMultiResponse) {
201
+ if (this.errorFactory)
202
+ return Promise.reject(new RethrowError(this.errorFactory));
203
+ if (this.closed)
204
+ return Promise.reject(new Error('Transaction already closed'));
205
+ // Note: Promise synchronously executes a callback passed to a constructor
206
+ const result = new Promise((resolve, reject) => {
207
+ this.responseHandlerQueue.push(createResponseHandler(r.oneofKind, expectMultiResponse, resolve, reject));
208
+ });
209
+ // Awaiting message dispatch to catch any associated errors.
210
+ // There is no hurry, we are not going to receive a response until message is sent.
211
+ await this.stream.requests.send({
212
+ requestId: this.requestIdxCounter++,
213
+ request: r,
214
+ });
215
+ try {
216
+ return await result;
217
+ }
218
+ catch (e) {
219
+ if (e instanceof RethrowError)
220
+ e.rethrowLambda();
221
+ throw new Error('Error while waiting for response', { cause: e });
222
+ }
223
+ }
224
+ _completed = false;
225
+ /** Safe to call multiple times */
226
+ async complete() {
227
+ if (this._completed)
228
+ return;
229
+ this._completed = true;
230
+ await this.stream.requests.complete();
231
+ }
232
+ }
233
+
234
+ exports.LLPlTransaction = LLPlTransaction;
235
+ exports.RethrowError = RethrowError;
236
+ //# sourceMappingURL=ll_transaction.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ll_transaction.cjs","sources":["../../src/core/ll_transaction.ts"],"sourcesContent":["import type {\n TxAPI_ClientMessage,\n TxAPI_ServerMessage,\n} from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';\nimport type { DuplexStreamingCall } from '@protobuf-ts/runtime-rpc';\nimport Denque from 'denque';\nimport type { Status } from '../proto/github.com/googleapis/googleapis/google/rpc/status';\nimport {\n PlErrorCodeNotFound,\n RecoverablePlError,\n rethrowMeaningfulError,\n UnrecoverablePlError,\n} from './errors';\n\nexport type ClientMessageRequest = TxAPI_ClientMessage['request'];\n\nexport type ServerMessageResponse = TxAPI_ServerMessage['response'];\n\ntype TxStream = DuplexStreamingCall<TxAPI_ClientMessage, TxAPI_ServerMessage>;\n\nexport type OneOfKind<T extends { oneofKind: unknown }, Kind extends T['oneofKind']> = Extract<\n T,\n { oneofKind: Kind }\n>;\n\ninterface SingleResponseHandler<Kind extends ServerMessageResponse['oneofKind']> {\n kind: Kind;\n expectMultiResponse: false;\n resolve: (v: OneOfKind<ServerMessageResponse, Kind>) => void;\n reject: (e: Error) => void;\n}\n\ninterface MultiResponseHandler<Kind extends ServerMessageResponse['oneofKind']> {\n kind: Kind;\n expectMultiResponse: true;\n resolve: (v: OneOfKind<ServerMessageResponse, Kind>[]) => void;\n reject: (e: Error) => void;\n}\n\ntype AnySingleResponseHandler = SingleResponseHandler<ServerMessageResponse['oneofKind']>;\n\ntype AnyMultiResponseHandler = MultiResponseHandler<ServerMessageResponse['oneofKind']>;\n\ntype AnyResponseHandler =\n | SingleResponseHandler<ServerMessageResponse['oneofKind']>\n | MultiResponseHandler<ServerMessageResponse['oneofKind']>;\n\nfunction createResponseHandler<Kind extends ServerMessageResponse['oneofKind']>(\n kind: Kind,\n expectMultiResponse: boolean,\n resolve:\n | ((v: OneOfKind<ServerMessageResponse, Kind>) => void)\n | ((v: OneOfKind<ServerMessageResponse, Kind>[]) => void),\n reject: (e: Error) => void,\n): AnyResponseHandler {\n return { kind, expectMultiResponse, resolve, reject } as AnyResponseHandler;\n}\n\nfunction isRecoverable(status: Status): boolean {\n return status.code === PlErrorCodeNotFound;\n}\n\nexport class RethrowError extends Error {\n name = 'RethrowError';\n constructor(public readonly rethrowLambda: () => never) {\n super('Rethrow error, you should never see this one.');\n }\n}\n\nexport class LLPlTransaction {\n /** Bidirectional channel through which transaction communicates with the server */\n private readonly stream: TxStream;\n\n /** Used to abort ongoing transaction stream */\n private readonly abortController = new AbortController();\n\n /** Counter of sent requests, used to calculate which future response will correspond to this request.\n * Incremented on each sent request. */\n private requestIdxCounter = 0;\n\n /** Queue from which incoming message processor takes handlers to which pass incoming messages */\n private readonly responseHandlerQueue = new Denque<AnyResponseHandler>();\n\n /** Each new resource, created by the transaction, is assigned with virtual (local) resource id, to make it possible\n * to populate its fields without awaiting actual resource id. This counter tracks those ids on client side, the\n * same way it is tracked on the server, so client can synchronously return such ids to the user. */\n private localResourceIdCounter = 0n;\n\n /** Switches to true, when this transaction closes due to normal or exceptional conditions. Prevents any new messages\n * to be sent to the stream. */\n private closed = false;\n /** Whether the outgoing stream was already closed. */\n private completed = false;\n\n /** If this transaction was terminated due to error, this is a generator to create new errors if corresponding response is required. */\n private errorFactory?: () => never;\n\n /** Timestamp when transaction was opened */\n private readonly openTimestamp = Date.now();\n\n private readonly incomingProcessorResult: Promise<(() => never) | null>;\n\n constructor(streamFactory: (abortSignal: AbortSignal) => TxStream) {\n this.stream = streamFactory(this.abortController.signal);\n\n // Starting incoming event processor\n this.incomingProcessorResult = this.incomingEventProcessor();\n }\n\n private assignErrorFactoryIfNotSet(\n errorFactory: () => never,\n reject?: (e: Error) => void,\n ): () => never {\n if (reject !== undefined) reject(new RethrowError(errorFactory));\n if (this.errorFactory) return errorFactory;\n this.errorFactory = errorFactory;\n return errorFactory;\n }\n\n private async incomingEventProcessor(): Promise<(() => never) | null> {\n /** Counter of received responses, used to check consistency of responses.\n * Increments on each received message. */\n let expectedId = -1;\n\n // defined externally to make possible to communicate any processing errors\n // to the specific request on which it happened\n let currentHandler: AnyResponseHandler | undefined = undefined;\n let responseAggregator: ServerMessageResponse[] | undefined = undefined;\n try {\n for await (const message of this.stream.responses) {\n if (currentHandler === undefined) {\n currentHandler = this.responseHandlerQueue.shift();\n\n if (currentHandler === undefined) {\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error(`orphan incoming message`);\n });\n break;\n }\n\n // allocating response aggregator array\n if (currentHandler.expectMultiResponse) responseAggregator = [];\n\n expectedId++;\n }\n\n if (message.requestId !== expectedId) {\n const errorMessage = `out of order messages, ${message.requestId} !== ${expectedId}`;\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error(errorMessage);\n });\n break;\n }\n\n if (message.error !== undefined) {\n const status = message.error;\n\n if (isRecoverable(status)) {\n currentHandler.reject(\n new RethrowError(() => {\n throw new RecoverablePlError(status);\n }),\n );\n currentHandler = undefined;\n\n if (message.multiMessage !== undefined && !message.multiMessage.isLast) {\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error('Unexpected message sequence.');\n });\n break;\n }\n\n // We can continue to work after recoverable errors\n continue;\n } else {\n this.assignErrorFactoryIfNotSet(() => {\n throw new UnrecoverablePlError(status);\n }, currentHandler.reject);\n currentHandler = undefined;\n\n // In case of unrecoverable errors we close the transaction\n break;\n }\n }\n\n if (\n currentHandler.kind !== message.response.oneofKind\n && message?.multiMessage?.isEmpty !== true\n ) {\n const errorMessage = `inconsistent request response types: ${currentHandler.kind} !== ${message.response.oneofKind}`;\n\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error(errorMessage);\n }, currentHandler.reject);\n currentHandler = undefined;\n\n break;\n }\n\n if (currentHandler.expectMultiResponse !== (message.multiMessage !== undefined)) {\n const errorMessage = `inconsistent multi state: ${currentHandler.expectMultiResponse} !== ${message.multiMessage !== undefined}`;\n\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error(errorMessage);\n }, currentHandler.reject);\n currentHandler = undefined;\n\n break;\n }\n\n // <- at this point we validated everything we can at this level\n\n if (message.multiMessage !== undefined) {\n if (!message.multiMessage.isEmpty) {\n if (message.multiMessage.id !== responseAggregator!.length + 1) {\n const errorMessage = `inconsistent multi id: ${message.multiMessage.id} !== ${responseAggregator!.length + 1}`;\n\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error(errorMessage);\n }, currentHandler.reject);\n currentHandler = undefined;\n\n break;\n }\n\n responseAggregator!.push(message.response);\n }\n\n if (message.multiMessage.isLast) {\n (currentHandler as AnyMultiResponseHandler).resolve(responseAggregator!);\n responseAggregator = undefined;\n currentHandler = undefined;\n }\n } else {\n (currentHandler as AnySingleResponseHandler).resolve(message.response);\n currentHandler = undefined;\n }\n }\n } catch (e: any) {\n return this.assignErrorFactoryIfNotSet(() => {\n rethrowMeaningfulError(e, true);\n }, currentHandler?.reject);\n } finally {\n await this.close();\n }\n return null;\n }\n\n /** Executed after termination of incoming message processor */\n private async close(): Promise<void> {\n if (this.closed) return;\n\n this.closed = true;\n\n // Rejecting all messages\n\n while (true) {\n const handler = this.responseHandlerQueue.shift();\n if (!handler) break;\n if (this.errorFactory) handler.reject(new RethrowError(this.errorFactory));\n else handler.reject(new Error('no reply'));\n }\n\n // closing outgoing stream\n await this.stream.requests.complete();\n }\n\n /** Forcefully close the transaction, terminate all connections and reject all pending requests */\n public abort(cause?: Error) {\n this.assignErrorFactoryIfNotSet(() => {\n throw new Error(`transaction aborted`, { cause });\n });\n this.abortController.abort(cause);\n }\n\n /** Await incoming message loop termination and throw any leftover errors if it was unsuccessful */\n public async await(): Promise<void> {\n // for those who want to understand \"why?\":\n // this way there is no hanging promise that will complete with rejection\n // until await is implicitly requested, the this.incomingProcessorResult\n // always resolves with success\n\n const processingResult = await this.incomingProcessorResult;\n if (processingResult !== null) processingResult();\n }\n\n public async send<Kind extends ClientMessageRequest['oneofKind']>(\n r: OneOfKind<ClientMessageRequest, Kind>,\n expectMultiResponse: false\n ): Promise<OneOfKind<ServerMessageResponse, Kind>>;\n public async send<Kind extends ClientMessageRequest['oneofKind']>(\n r: OneOfKind<ClientMessageRequest, Kind>,\n expectMultiResponse: true\n ): Promise<OneOfKind<ServerMessageResponse, Kind>[]>;\n /** Generate proper client message and send it to the server, and returns a promise of future response. */\n public async send<Kind extends ClientMessageRequest['oneofKind']>(\n r: OneOfKind<ClientMessageRequest, Kind>,\n expectMultiResponse: boolean,\n ): Promise<OneOfKind<ServerMessageResponse, Kind> | OneOfKind<ServerMessageResponse, Kind>[]> {\n if (this.errorFactory) return Promise.reject(new RethrowError(this.errorFactory));\n\n if (this.closed) return Promise.reject(new Error('Transaction already closed'));\n\n // Note: Promise synchronously executes a callback passed to a constructor\n const result = new Promise<OneOfKind<ServerMessageResponse, Kind>>((resolve, reject) => {\n this.responseHandlerQueue.push(\n createResponseHandler(r.oneofKind, expectMultiResponse, resolve, reject),\n );\n });\n\n // Awaiting message dispatch to catch any associated errors.\n // There is no hurry, we are not going to receive a response until message is sent.\n await this.stream.requests.send({\n requestId: this.requestIdxCounter++,\n request: r,\n });\n\n try {\n return await result;\n } catch (e: any) {\n if (e instanceof RethrowError) e.rethrowLambda();\n throw new Error('Error while waiting for response', { cause: e });\n }\n }\n\n private _completed = false;\n\n /** Safe to call multiple times */\n public async complete() {\n if (this._completed) return;\n this._completed = true;\n await this.stream.requests.complete();\n }\n}\n"],"names":["PlErrorCodeNotFound","RecoverablePlError","UnrecoverablePlError","rethrowMeaningfulError"],"mappings":";;;;;AA+CA,SAAS,qBAAqB,CAC5B,IAAU,EACV,mBAA4B,EAC5B,OAE2D,EAC3D,MAA0B,EAAA;IAE1B,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAwB;AAC7E;AAEA,SAAS,aAAa,CAAC,MAAc,EAAA;AACnC,IAAA,OAAO,MAAM,CAAC,IAAI,KAAKA,0BAAmB;AAC5C;AAEM,MAAO,YAAa,SAAQ,KAAK,CAAA;AAET,IAAA,aAAA;IAD5B,IAAI,GAAG,cAAc;AACrB,IAAA,WAAA,CAA4B,aAA0B,EAAA;QACpD,KAAK,CAAC,+CAA+C,CAAC;QAD5B,IAAA,CAAA,aAAa,GAAb,aAAa;IAEzC;AACD;MAEY,eAAe,CAAA;;AAET,IAAA,MAAM;;AAGN,IAAA,eAAe,GAAG,IAAI,eAAe,EAAE;AAExD;AACuC;IAC/B,iBAAiB,GAAG,CAAC;;AAGZ,IAAA,oBAAoB,GAAG,IAAI,MAAM,EAAsB;AAExE;;AAEoG;IAC5F,sBAAsB,GAAG,EAAE;AAEnC;AAC+B;IACvB,MAAM,GAAG,KAAK;;IAEd,SAAS,GAAG,KAAK;;AAGjB,IAAA,YAAY;;AAGH,IAAA,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE;AAE1B,IAAA,uBAAuB;AAExC,IAAA,WAAA,CAAY,aAAq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 -1,5 +1,5 @@
1
- import { TxAPI_ClientMessage, TxAPI_ServerMessage } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
2
- import { DuplexStreamingCall } from '@protobuf-ts/runtime-rpc';
1
+ import type { TxAPI_ClientMessage, TxAPI_ServerMessage } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
2
+ import type { DuplexStreamingCall } from '@protobuf-ts/runtime-rpc';
3
3
  export type ClientMessageRequest = TxAPI_ClientMessage['request'];
4
4
  export type ServerMessageResponse = TxAPI_ServerMessage['response'];
5
5
  type TxStream = DuplexStreamingCall<TxAPI_ClientMessage, TxAPI_ServerMessage>;