@hotrepl/sdk 2.0.0 → 3.0.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ArtifactRef, CommandDescriptor, HandshakeMessage, ServerMessage, SubscribeResultMessage, SubscribeErrorMessage, SessionEvictedMessage, JournalEntry, JobCancelResultMessage, ErrorKind, HotReplErrorEnvelope } from '@hotrepl/protocol';
1
+ import { ArtifactRef, CommandDescriptor, HandshakeMessage, ServerMessage, SubscribeResultMessage, SubscribeErrorMessage, SessionEvictedMessage, JournalEntry, CommandSummary, JobCancelResultMessage, ErrorKind, HotReplErrorEnvelope } from '@hotrepl/protocol';
2
2
 
3
3
  interface ArtifactReader {
4
4
  readArtifact(ref: ArtifactRef): Promise<Uint8Array>;
@@ -120,6 +120,7 @@ declare class Session {
120
120
  readonly handshake: HandshakeMessage;
121
121
  private readonly transport;
122
122
  private readonly descriptors;
123
+ private catalog;
123
124
  private readonly evictionListeners;
124
125
  private sequence;
125
126
  private evicted;
@@ -139,6 +140,8 @@ declare class Session {
139
140
  limit?: number;
140
141
  }): Promise<JournalEntry[]>;
141
142
  artifact(ref: ArtifactRef): Artifact;
143
+ listCommands(): Promise<CommandSummary[]>;
144
+ getCatalogEntry(name: string): Promise<CommandSummary>;
142
145
  describeCommand(name: string): Promise<CommandDescriptor>;
143
146
  pollJob<T>(jobId: string, pollIntervalMs: number): Promise<Result<T>>;
144
147
  nextId(prefix: string): string;
package/dist/index.js CHANGED
@@ -130,6 +130,7 @@ var Session = class {
130
130
  handshake;
131
131
  transport;
132
132
  descriptors = /* @__PURE__ */ new Map();
133
+ catalog;
133
134
  evictionListeners = /* @__PURE__ */ new Set();
134
135
  sequence = 0;
135
136
  evicted;
@@ -148,7 +149,7 @@ var Session = class {
148
149
  }
149
150
  async run(name, args, options = {}) {
150
151
  this.ensureActive();
151
- const descriptor = await this.describeCommand(name);
152
+ const catalogEntry = await this.getCatalogEntry(name);
152
153
  const request = {
153
154
  type: "command_call",
154
155
  id: this.nextId("cmd"),
@@ -157,7 +158,7 @@ var Session = class {
157
158
  };
158
159
  if (options.timeoutMs !== void 0) request.timeoutMs = options.timeoutMs;
159
160
  const response = await this.request(request);
160
- if (descriptor.kind === "sync") {
161
+ if (catalogEntry.kind === "sync") {
161
162
  if (response.type !== MESSAGE_TYPES.commandResult) {
162
163
  throw protocolError("unexpectedResponse", "Expected command_result.");
163
164
  }
@@ -245,6 +246,24 @@ var Session = class {
245
246
  artifact(ref) {
246
247
  return new Artifact(ref, this.transport);
247
248
  }
249
+ async listCommands() {
250
+ this.ensureActive();
251
+ if (this.catalog !== void 0) return this.catalog;
252
+ const response = await this.request({
253
+ type: "commands_list",
254
+ id: this.nextId("list")
255
+ });
256
+ this.catalog = response.commands;
257
+ return this.catalog;
258
+ }
259
+ async getCatalogEntry(name) {
260
+ const commands = await this.listCommands();
261
+ const entry = commands.find((command) => command.name === name);
262
+ if (entry === void 0) {
263
+ throw protocolError("commandNotFound", `Command '${name}' is not registered.`);
264
+ }
265
+ return entry;
266
+ }
248
267
  async describeCommand(name) {
249
268
  const cached = this.descriptors.get(name);
250
269
  if (cached !== void 0) return cached;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotrepl/sdk",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Canonical TypeScript SDK for HotRepl v2 runtimes.",
5
5
  "keywords": [
6
6
  "hotrepl",
@@ -41,7 +41,7 @@
41
41
  "typecheck": "tsc -p tsconfig.json"
42
42
  },
43
43
  "dependencies": {
44
- "@hotrepl/protocol": "2.0.0"
44
+ "@hotrepl/protocol": "3.0.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@hotrepl/testing": "2.0.0"