@abelxiaoxing/cadence 2.0.13 → 2.0.14

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.
@@ -1,3 +1,11 @@
1
+ import {
2
+ decodeWorkbenchCommand,
3
+ decodeWorkbenchRead,
4
+ decodeWorkbenchResult,
5
+ type WorkbenchCommand,
6
+ type WorkbenchRead,
7
+ type WorkbenchResult,
8
+ } from "./service/contracts/workbench.ts";
1
9
  import {
2
10
  type Action,
3
11
  type ActiveRuns,
@@ -82,6 +90,11 @@ import {
82
90
  * Text transports use parseWireJson BEFORE handing unknown values to this client.
83
91
  */
84
92
  export interface ServiceTransport {
93
+ workbenchRead?(
94
+ request: WorkbenchRead,
95
+ signal?: AbortSignal,
96
+ ): Promise<unknown>;
97
+ workbenchCommand?(request: WorkbenchCommand): Promise<unknown>;
85
98
  current?(request: CurrentRequest, signal?: AbortSignal): Promise<unknown>;
86
99
  currentChanges?(
87
100
  request: CurrentRequest,
@@ -123,6 +136,42 @@ const unavailable = <T>(mutation: boolean): Reply<T> => ({
123
136
 
124
137
  export class ServiceClient {
125
138
  constructor(private readonly transport: ServiceTransport) {}
139
+ async workbenchRead(
140
+ input: WorkbenchRead,
141
+ signal?: AbortSignal,
142
+ ): Promise<Reply<WorkbenchResult>> {
143
+ const request = decodeWorkbenchRead(input);
144
+ try {
145
+ if (!this.transport.workbenchRead) return unavailable(false);
146
+ return decodeReply(
147
+ await this.transport.workbenchRead(request, signal),
148
+ decodeWorkbenchResult,
149
+ );
150
+ } catch {
151
+ return unavailable(false);
152
+ }
153
+ }
154
+ async workbenchCommand(
155
+ input: WorkbenchCommand,
156
+ ): Promise<Reply<WorkbenchResult>> {
157
+ const request = decodeWorkbenchCommand(input);
158
+ try {
159
+ if (!this.transport.workbenchCommand) return unavailable(true);
160
+ const reply = decodeReply(
161
+ await this.transport.workbenchCommand(request),
162
+ decodeWorkbenchResult,
163
+ );
164
+ if (
165
+ reply.kind === "ok" &&
166
+ (!("commandId" in reply.value) ||
167
+ reply.value.commandId !== request.commandId)
168
+ )
169
+ return unavailable(true);
170
+ return reply;
171
+ } catch {
172
+ return unavailable(true);
173
+ }
174
+ }
126
175
  async current(
127
176
  input: CurrentRequest,
128
177
  signal?: AbortSignal,