@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-client",
3
- "version": "2.9.2",
3
+ "version": "2.10.0",
4
4
  "engines": {
5
5
  "node": ">=20.3.0"
6
6
  },
@@ -0,0 +1,10 @@
1
+ import type { ResourceType } from './types';
2
+
3
+ export type ErrorResourceData = {
4
+ message: string;
5
+ };
6
+
7
+ export const ErrorResourceType: ResourceType = {
8
+ name: 'json/resourceError',
9
+ version: '1',
10
+ };
@@ -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
  }
@@ -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
  //
@@ -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 altRoot = `test_${Date.now()}_${randomUUID()}`;
155
+ const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;
156
156
  let altRootId: OptionalResourceId = NullResourceId;
157
157
  try {
158
- const client = await getTestClient(altRoot);
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(altRoot);
162
+ await rawClient.deleteAlternativeRoot(alternativeRoot);
163
163
  return value;
164
164
  } catch (err: any) {
165
- console.log(`ALTERNATIVE ROOT: ${altRoot} (${resourceIdToString(altRootId)})`);
165
+ console.log(`ALTERNATIVE ROOT: ${alternativeRoot} (${resourceIdToString(altRootId)})`);
166
166
  throw new Error(err.message, { cause: err });
167
167
  }
168
168
  }