@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.
- package/README.md +2 -1
- package/dist/core/PromiseTracker.cjs +1 -3
- package/dist/core/PromiseTracker.cjs.map +1 -1
- package/dist/core/PromiseTracker.d.ts.map +1 -1
- package/dist/core/PromiseTracker.js +1 -3
- package/dist/core/PromiseTracker.js.map +1 -1
- package/dist/core/StatefulPromise.cjs +4 -4
- package/dist/core/StatefulPromise.cjs.map +1 -1
- package/dist/core/StatefulPromise.d.ts +1 -1
- package/dist/core/StatefulPromise.d.ts.map +1 -1
- package/dist/core/StatefulPromise.js +4 -4
- package/dist/core/StatefulPromise.js.map +1 -1
- package/dist/core/advisory_locks.cjs +1 -1
- package/dist/core/advisory_locks.cjs.map +1 -1
- package/dist/core/advisory_locks.js +1 -1
- package/dist/core/advisory_locks.js.map +1 -1
- package/dist/core/auth.cjs.map +1 -1
- package/dist/core/auth.d.ts +1 -1
- package/dist/core/auth.js.map +1 -1
- package/dist/core/cache.d.ts +1 -1
- package/dist/core/client.cjs +14 -14
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +11 -11
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +14 -14
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.cjs +39 -39
- package/dist/core/config.cjs.map +1 -1
- package/dist/core/config.d.ts +5 -5
- package/dist/core/config.js +39 -39
- package/dist/core/config.js.map +1 -1
- package/dist/core/default_client.cjs +23 -23
- package/dist/core/default_client.cjs.map +1 -1
- package/dist/core/default_client.d.ts +3 -3
- package/dist/core/default_client.js +23 -23
- package/dist/core/default_client.js.map +1 -1
- package/dist/core/driver.cjs +1 -1
- package/dist/core/driver.cjs.map +1 -1
- package/dist/core/driver.d.ts +5 -5
- package/dist/core/driver.js +1 -1
- package/dist/core/driver.js.map +1 -1
- package/dist/core/error_resource.cjs +2 -2
- package/dist/core/error_resource.cjs.map +1 -1
- package/dist/core/error_resource.d.ts +1 -1
- package/dist/core/error_resource.js +2 -2
- package/dist/core/error_resource.js.map +1 -1
- package/dist/core/errors.cjs +24 -24
- package/dist/core/errors.cjs.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +24 -24
- package/dist/core/errors.js.map +1 -1
- package/dist/core/final.cjs +43 -43
- package/dist/core/final.cjs.map +1 -1
- package/dist/core/final.d.ts +3 -3
- package/dist/core/final.d.ts.map +1 -1
- package/dist/core/final.js +43 -43
- package/dist/core/final.js.map +1 -1
- package/dist/core/ll_client.cjs +50 -43
- package/dist/core/ll_client.cjs.map +1 -1
- package/dist/core/ll_client.d.ts +9 -9
- package/dist/core/ll_client.d.ts.map +1 -1
- package/dist/core/ll_client.js +50 -43
- package/dist/core/ll_client.js.map +1 -1
- package/dist/core/ll_transaction.cjs +9 -9
- package/dist/core/ll_transaction.cjs.map +1 -1
- package/dist/core/ll_transaction.d.ts +7 -7
- package/dist/core/ll_transaction.d.ts.map +1 -1
- package/dist/core/ll_transaction.js +9 -9
- package/dist/core/ll_transaction.js.map +1 -1
- package/dist/core/stat.cjs.map +1 -1
- package/dist/core/stat.d.ts +1 -1
- package/dist/core/stat.js.map +1 -1
- package/dist/core/transaction.cjs +46 -46
- package/dist/core/transaction.cjs.map +1 -1
- package/dist/core/transaction.d.ts +7 -7
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/core/transaction.js +46 -46
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/type_conversion.cjs +22 -22
- package/dist/core/type_conversion.cjs.map +1 -1
- package/dist/core/type_conversion.d.ts +3 -3
- package/dist/core/type_conversion.d.ts.map +1 -1
- package/dist/core/type_conversion.js +22 -22
- package/dist/core/type_conversion.js.map +1 -1
- package/dist/core/types.cjs +25 -25
- package/dist/core/types.cjs.map +1 -1
- package/dist/core/types.d.ts +7 -7
- package/dist/core/types.js +25 -25
- package/dist/core/types.js.map +1 -1
- package/dist/core/unauth_client.cjs +6 -4
- package/dist/core/unauth_client.cjs.map +1 -1
- package/dist/core/unauth_client.d.ts +4 -4
- package/dist/core/unauth_client.d.ts.map +1 -1
- package/dist/core/unauth_client.js +6 -4
- package/dist/core/unauth_client.js.map +1 -1
- package/dist/core/websocket_stream.cjs +22 -20
- package/dist/core/websocket_stream.cjs.map +1 -1
- package/dist/core/websocket_stream.d.ts +3 -3
- package/dist/core/websocket_stream.d.ts.map +1 -1
- package/dist/core/websocket_stream.js +22 -20
- package/dist/core/websocket_stream.js.map +1 -1
- package/dist/core/wire.d.ts +6 -6
- package/dist/core/wire.d.ts.map +1 -1
- package/dist/helpers/pl.cjs +19 -19
- package/dist/helpers/pl.cjs.map +1 -1
- package/dist/helpers/pl.d.ts +2 -2
- package/dist/helpers/pl.js +19 -19
- package/dist/helpers/pl.js.map +1 -1
- package/dist/helpers/poll.cjs +6 -6
- package/dist/helpers/poll.cjs.map +1 -1
- package/dist/helpers/poll.d.ts +4 -4
- package/dist/helpers/poll.d.ts.map +1 -1
- package/dist/helpers/poll.js +6 -6
- package/dist/helpers/poll.js.map +1 -1
- package/dist/helpers/retry_strategy.cjs +1 -1
- package/dist/helpers/retry_strategy.cjs.map +1 -1
- package/dist/helpers/retry_strategy.d.ts.map +1 -1
- package/dist/helpers/retry_strategy.js +1 -1
- package/dist/helpers/retry_strategy.js.map +1 -1
- package/dist/helpers/state_helpers.d.ts +2 -2
- package/dist/helpers/tx_helpers.cjs +2 -2
- package/dist/helpers/tx_helpers.cjs.map +1 -1
- package/dist/helpers/tx_helpers.d.ts +2 -2
- package/dist/helpers/tx_helpers.d.ts.map +1 -1
- package/dist/helpers/tx_helpers.js +2 -2
- package/dist/helpers/tx_helpers.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/proto-grpc/google/protobuf/struct.d.ts +1 -1
- package/dist/proto-grpc/google/protobuf/struct.d.ts.map +1 -1
- package/dist/proto-rest/index.cjs +4 -5
- package/dist/proto-rest/index.cjs.map +1 -1
- package/dist/proto-rest/index.d.ts +4 -4
- package/dist/proto-rest/index.d.ts.map +1 -1
- package/dist/proto-rest/index.js +4 -5
- package/dist/proto-rest/index.js.map +1 -1
- package/dist/proto-rest/plapi.d.ts.map +1 -1
- package/dist/test/tcp-proxy.cjs +11 -10
- package/dist/test/tcp-proxy.cjs.map +1 -1
- package/dist/test/tcp-proxy.d.ts +1 -1
- package/dist/test/tcp-proxy.d.ts.map +1 -1
- package/dist/test/tcp-proxy.js +11 -10
- package/dist/test/tcp-proxy.js.map +1 -1
- package/dist/test/test_config.cjs +21 -17
- package/dist/test/test_config.cjs.map +1 -1
- package/dist/test/test_config.d.ts +6 -6
- package/dist/test/test_config.d.ts.map +1 -1
- package/dist/test/test_config.js +21 -17
- package/dist/test/test_config.js.map +1 -1
- package/dist/util/pl.cjs +1 -1
- package/dist/util/pl.cjs.map +1 -1
- package/dist/util/pl.js +1 -1
- package/dist/util/pl.js.map +1 -1
- package/dist/util/util.cjs +1 -1
- package/dist/util/util.cjs.map +1 -1
- package/dist/util/util.js +1 -1
- package/dist/util/util.js.map +1 -1
- package/package.json +23 -23
- package/src/core/PromiseTracker.ts +3 -4
- package/src/core/StatefulPromise.ts +17 -8
- package/src/core/abstract_stream.ts +3 -4
- package/src/core/advisory_locks.ts +1 -1
- package/src/core/auth.ts +2 -2
- package/src/core/cache.ts +1 -1
- package/src/core/client.test.ts +25 -21
- package/src/core/client.ts +54 -45
- package/src/core/config.test.ts +44 -44
- package/src/core/config.ts +49 -49
- package/src/core/connectivity.test.ts +69 -63
- package/src/core/default_client.ts +46 -46
- package/src/core/driver.ts +6 -6
- package/src/core/error.test.ts +5 -5
- package/src/core/error_resource.ts +3 -3
- package/src/core/errors.ts +39 -31
- package/src/core/final.ts +48 -55
- package/src/core/ll_client.test.ts +53 -36
- package/src/core/ll_client.ts +125 -81
- package/src/core/ll_transaction.test.ts +75 -49
- package/src/core/ll_transaction.ts +37 -35
- package/src/core/stat.ts +1 -1
- package/src/core/transaction.test.ts +65 -65
- package/src/core/transaction.ts +91 -84
- package/src/core/type_conversion.ts +30 -31
- package/src/core/types.test.ts +6 -6
- package/src/core/types.ts +35 -35
- package/src/core/unauth_client.test.ts +18 -14
- package/src/core/unauth_client.ts +14 -12
- package/src/core/websocket_stream.test.ts +52 -52
- package/src/core/websocket_stream.ts +41 -37
- package/src/core/wire.ts +10 -8
- package/src/helpers/pl.ts +22 -22
- package/src/helpers/poll.ts +13 -27
- package/src/helpers/retry_strategy.ts +2 -4
- package/src/helpers/rich_resource_types.test.ts +2 -2
- package/src/helpers/state_helpers.ts +3 -3
- package/src/helpers/tx_helpers.ts +9 -7
- package/src/index.ts +16 -16
- package/src/proto-grpc/google/protobuf/struct.ts +1 -1
- package/src/proto-rest/index.ts +17 -18
- package/src/proto-rest/plapi.ts +1472 -1472
- package/src/test/tcp-proxy.ts +55 -54
- package/src/test/test_config.test.ts +3 -3
- package/src/test/test_config.ts +51 -46
- package/src/util/pl.ts +1 -1
- package/src/util/util.test.ts +5 -5
- package/src/util/util.ts +1 -1
- package/dist/helpers/rich_resource_types.d.ts +0 -2
- package/dist/helpers/rich_resource_types.d.ts.map +0 -1
- package/dist/helpers/smart_accessors.d.ts +0 -2
- package/dist/helpers/smart_accessors.d.ts.map +0 -1
- package/src/helpers/rich_resource_types.ts +0 -84
- package/src/helpers/smart_accessors.ts +0 -146
package/src/core/transaction.ts
CHANGED
|
@@ -10,7 +10,8 @@ import type {
|
|
|
10
10
|
ResourceData,
|
|
11
11
|
ResourceId,
|
|
12
12
|
ResourceType,
|
|
13
|
-
FutureFieldType
|
|
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
|
|
22
|
+
} from "./types";
|
|
22
23
|
import type {
|
|
23
24
|
ClientMessageRequest,
|
|
24
25
|
LLPlTransaction,
|
|
25
26
|
OneOfKind,
|
|
26
27
|
ServerMessageResponse,
|
|
27
|
-
} from
|
|
28
|
-
import { TxAPI_Open_Request_WritableTx } from
|
|
29
|
-
import type { NonUndefined } from
|
|
30
|
-
import { toBytes } from
|
|
31
|
-
import { fieldTypeToProto, protoToField, protoToResource } from
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
import {
|
|
39
|
-
import type {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
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(
|
|
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 ===
|
|
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 ===
|
|
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(
|
|
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 =
|
|
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:
|
|
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[
|
|
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[
|
|
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[
|
|
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[
|
|
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(
|
|
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(
|
|
313
|
-
{ oneofKind:
|
|
314
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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[
|
|
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:
|
|
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:
|
|
439
|
+
oneofKind: "resourceCreateStruct",
|
|
438
440
|
resourceCreateStruct: {
|
|
439
441
|
type,
|
|
440
442
|
id: localId,
|
|
441
|
-
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:
|
|
457
|
+
oneofKind: "resourceCreateEphemeral",
|
|
455
458
|
resourceCreateEphemeral: {
|
|
456
459
|
type,
|
|
457
460
|
id: localId,
|
|
458
|
-
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:
|
|
479
|
+
oneofKind: "resourceCreateValue",
|
|
476
480
|
resourceCreateValue: {
|
|
477
481
|
type,
|
|
478
482
|
id: localId,
|
|
479
|
-
data: typeof 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(
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
734
|
+
oneofKind: "fieldSet",
|
|
728
735
|
fieldSet: {
|
|
729
736
|
field: toFieldId(fId),
|
|
730
737
|
value: {
|
|
731
738
|
resourceId: toResourceId(ref),
|
|
732
|
-
fieldName:
|
|
739
|
+
fieldName: "", // default value, read as undefined
|
|
733
740
|
},
|
|
734
741
|
},
|
|
735
742
|
});
|
|
736
743
|
else
|
|
737
744
|
this.sendVoidAsync({
|
|
738
|
-
oneofKind:
|
|
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:
|
|
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:
|
|
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:
|
|
775
|
+
this.sendVoidAsync({ oneofKind: "fieldReset", fieldReset: { field: toFieldId(fId) } });
|
|
769
776
|
}
|
|
770
777
|
|
|
771
778
|
public removeField(fId: AnyFieldRef): void {
|
|
772
|
-
this.sendVoidAsync({ oneofKind:
|
|
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:
|
|
784
|
-
resourceKeyValueList: { resourceId: toResourceId(rId), startFrom:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
914
|
-
this.setField({ resourceId: getFieldResource, fieldName:
|
|
915
|
-
return { resourceId: getFieldResource, fieldName:
|
|
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
|
|
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
|
|
8
|
-
import { FieldType as GrpcFieldType } from
|
|
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
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
} from
|
|
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 =
|
|
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(
|
|
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
|
|
50
|
+
return "Structural";
|
|
52
51
|
case Resource_Kind.VALUE:
|
|
53
|
-
return
|
|
52
|
+
return "Value";
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
throw new Error(
|
|
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
|
|
77
|
+
return "Input";
|
|
79
78
|
case GrpcFieldType.OUTPUT:
|
|
80
|
-
return
|
|
79
|
+
return "Output";
|
|
81
80
|
case GrpcFieldType.SERVICE:
|
|
82
|
-
return
|
|
81
|
+
return "Service";
|
|
83
82
|
case GrpcFieldType.ONE_TIME_WRITABLE:
|
|
84
|
-
return
|
|
83
|
+
return "OTW";
|
|
85
84
|
case GrpcFieldType.DYNAMIC:
|
|
86
|
-
return
|
|
85
|
+
return "Dynamic";
|
|
87
86
|
case GrpcFieldType.MULTIPLE_TIMES_WRITABLE:
|
|
88
|
-
return
|
|
87
|
+
return "MTW";
|
|
89
88
|
default:
|
|
90
|
-
throw new Error(
|
|
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
|
|
96
|
+
return "Empty";
|
|
98
97
|
case Field_ValueStatus.ASSIGNED:
|
|
99
|
-
return
|
|
98
|
+
return "Assigned";
|
|
100
99
|
case Field_ValueStatus.RESOLVED:
|
|
101
|
-
return
|
|
100
|
+
return "Resolved";
|
|
102
101
|
default:
|
|
103
|
-
throw new Error(
|
|
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
|
|
108
|
+
case "Input":
|
|
110
109
|
return GrpcFieldType.INPUT;
|
|
111
|
-
case
|
|
110
|
+
case "Output":
|
|
112
111
|
return GrpcFieldType.OUTPUT;
|
|
113
|
-
case
|
|
112
|
+
case "Dynamic":
|
|
114
113
|
return GrpcFieldType.DYNAMIC;
|
|
115
|
-
case
|
|
114
|
+
case "Service":
|
|
116
115
|
return GrpcFieldType.SERVICE;
|
|
117
|
-
case
|
|
116
|
+
case "MTW":
|
|
118
117
|
return GrpcFieldType.MULTIPLE_TIMES_WRITABLE;
|
|
119
|
-
case
|
|
118
|
+
case "OTW":
|
|
120
119
|
return GrpcFieldType.ONE_TIME_WRITABLE;
|
|
121
120
|
default:
|
|
122
121
|
return assertNever(type);
|