@milaboratories/pl-client 2.9.2 → 2.10.0
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/dist/core/error_resource.d.ts +6 -0
- package/dist/core/error_resource.d.ts.map +1 -0
- package/dist/core/errors.d.ts +5 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/transaction.d.ts +2 -0
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +208 -189
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/error_resource.ts +10 -0
- package/src/core/errors.ts +5 -0
- package/src/core/transaction.ts +13 -0
- package/src/test/test_config.ts +4 -4
package/package.json
CHANGED
package/src/core/errors.ts
CHANGED
|
@@ -36,6 +36,7 @@ export function isTimeoutOrCancelError(err: unknown, nested: boolean = false): b
|
|
|
36
36
|
export const PlErrorCodeNotFound = 5;
|
|
37
37
|
|
|
38
38
|
export class PlError extends Error {
|
|
39
|
+
name = 'PlError';
|
|
39
40
|
constructor(public readonly status: Status) {
|
|
40
41
|
super(`code=${status.code} ${status.message}`);
|
|
41
42
|
}
|
|
@@ -46,12 +47,14 @@ export function throwPlNotFoundError(message: string): never {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export class RecoverablePlError extends PlError {
|
|
50
|
+
name = 'RecoverablePlError';
|
|
49
51
|
constructor(status: Status) {
|
|
50
52
|
super(status);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
export class UnrecoverablePlError extends PlError {
|
|
57
|
+
name = 'UnrecoverablePlError';
|
|
55
58
|
constructor(status: Status) {
|
|
56
59
|
super(status);
|
|
57
60
|
}
|
|
@@ -64,12 +67,14 @@ export function isNotFoundError(err: unknown, nested: boolean = false): boolean
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
export class UnauthenticatedError extends Error {
|
|
70
|
+
name = 'UnauthenticatedError';
|
|
67
71
|
constructor(message: string) {
|
|
68
72
|
super('LoginFailed: ' + message);
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
export class DisconnectedError extends Error {
|
|
77
|
+
name = 'DisconnectedError';
|
|
73
78
|
constructor(message: string) {
|
|
74
79
|
super('Disconnected: ' + message);
|
|
75
80
|
}
|
package/src/core/transaction.ts
CHANGED
|
@@ -36,6 +36,8 @@ import type { LRUCache } from 'lru-cache';
|
|
|
36
36
|
import type { ResourceDataCacheRecord } from './cache';
|
|
37
37
|
import type { TxStat } from './stat';
|
|
38
38
|
import { initialTxStat } from './stat';
|
|
39
|
+
import type { ErrorResourceData } from './error_resource';
|
|
40
|
+
import { ErrorResourceType } from './error_resource';
|
|
39
41
|
|
|
40
42
|
/** Reference to resource, used only within transaction */
|
|
41
43
|
export interface ResourceRef {
|
|
@@ -440,6 +442,10 @@ export class PlTransaction {
|
|
|
440
442
|
);
|
|
441
443
|
}
|
|
442
444
|
|
|
445
|
+
public createError(message: string): ResourceRef {
|
|
446
|
+
return this.createValue(ErrorResourceType, JSON.stringify({ message } satisfies ErrorResourceData));
|
|
447
|
+
}
|
|
448
|
+
|
|
443
449
|
public setResourceName(name: string, rId: AnyResourceRef): void {
|
|
444
450
|
this.sendVoidAsync({
|
|
445
451
|
oneofKind: 'resourceNameSet',
|
|
@@ -630,6 +636,13 @@ export class PlTransaction {
|
|
|
630
636
|
this.lockOutputs(rID);
|
|
631
637
|
}
|
|
632
638
|
|
|
639
|
+
public setResourceError(rId: AnyResourceRef, ref: AnyResourceRef): void {
|
|
640
|
+
this.sendVoidAsync({
|
|
641
|
+
oneofKind: 'resourceSetError',
|
|
642
|
+
resourceSetError: { resourceId: toResourceId(rId), errorResourceId: toResourceId(ref) },
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
|
|
633
646
|
//
|
|
634
647
|
// Fields
|
|
635
648
|
//
|
package/src/test/test_config.ts
CHANGED
|
@@ -152,17 +152,17 @@ export async function getTestClient(alternativeRoot?: string) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
export async function withTempRoot<T>(body: (pl: PlClient) => Promise<T>): Promise<T> {
|
|
155
|
-
const
|
|
155
|
+
const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;
|
|
156
156
|
let altRootId: OptionalResourceId = NullResourceId;
|
|
157
157
|
try {
|
|
158
|
-
const client = await getTestClient(
|
|
158
|
+
const client = await getTestClient(alternativeRoot);
|
|
159
159
|
altRootId = client.clientRoot;
|
|
160
160
|
const value = await body(client);
|
|
161
161
|
const rawClient = await getTestClient();
|
|
162
|
-
await rawClient.deleteAlternativeRoot(
|
|
162
|
+
await rawClient.deleteAlternativeRoot(alternativeRoot);
|
|
163
163
|
return value;
|
|
164
164
|
} catch (err: any) {
|
|
165
|
-
console.log(`ALTERNATIVE ROOT: ${
|
|
165
|
+
console.log(`ALTERNATIVE ROOT: ${alternativeRoot} (${resourceIdToString(altRootId)})`);
|
|
166
166
|
throw new Error(err.message, { cause: err });
|
|
167
167
|
}
|
|
168
168
|
}
|