@wandelbots/nova-js 4.11.1-pr.341.4b83d94 → 4.12.0-pr.342.98a4769

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.
@@ -4015,6 +4015,21 @@ type NatsSubscribeOptions = {
4015
4015
  */
4016
4016
  lastMessage?: boolean;
4017
4017
  };
4018
+ /**
4019
+ * What `subscribe()` returns: a function that unsubscribes when called, with
4020
+ * a `closed` promise that resolves when the subscription has ended. After
4021
+ * that, the subscription receives no more messages; subscribe again to
4022
+ * receive them.
4023
+ *
4024
+ * `closed` resolves with `undefined` when the subscription ended without an
4025
+ * error: after an unsubscribe, or because the connection was closed. It
4026
+ * resolves with the error when the server or the NATS library ended it, for
4027
+ * example when the server refused the subject, or when JetStream could not
4028
+ * create a lost consumer again.
4029
+ */
4030
+ type NatsSubscription = (() => void) & {
4031
+ closed: Promise<Error | undefined>;
4032
+ };
4018
4033
  type NatsMessageHandler<K extends NatsSubscribeSubject> = (payload: NatsSubscribePayloads[K], msg: NatsSubscribeMsg<K>) => void | Promise<void>;
4019
4034
  type SubscribeArgs<K extends NatsSubscribeSubject> = keyof NatsOperationParams[K] extends never ? [handler: NatsMessageHandler<K>, options?: NatsSubscribeOptions] : [params: NatsOperationParams[K], handler: NatsMessageHandler<K>, options?: NatsSubscribeOptions];
4020
4035
  /**
@@ -4058,9 +4073,10 @@ declare class NovaNatsClient {
4058
4073
  * message persisted for each matching subject is replayed to the handler
4059
4074
  * immediately, before live messages (see {@link NatsSubscribeOptions}).
4060
4075
  *
4061
- * Returns a function that unsubscribes when called.
4076
+ * Returns a function that unsubscribes when called. Its `closed` promise
4077
+ * resolves when the subscription has ended (see {@link NatsSubscription}).
4062
4078
  */
4063
- subscribe<K extends NatsSubscribeSubject>(subject: K, ...args: SubscribeArgs<K>): Promise<() => void>;
4079
+ subscribe<K extends NatsSubscribeSubject>(subject: K, ...args: SubscribeArgs<K>): Promise<NatsSubscription>;
4064
4080
  /**
4065
4081
  * Sends a request payload for a NATS subject the server receives, and
4066
4082
  * waits for the JSON-decoded reply.
@@ -4083,5 +4099,5 @@ declare class NovaNatsClient {
4083
4099
  publish<K extends NatsPublishSubject>(subject: K, params: NatsOperationParams[K], payload: NatsPublishPayloads[K]): Promise<void>;
4084
4100
  }
4085
4101
  //#endregion
4086
- export { type AbbController, type AddVirtualControllerMotionGroupRequest, type App, type AppCreatedEvent, type AppDeletedEvent, type AppEventData, type AppUpdatedEvent, type ArpScanReply, type ArpScanRequest, type AsyncReplyHeaders, type AsyncRequestHeaders, type BostondynamicsController, type Box, type BusIOsState, type BusIOsStateEnum, type CancelIOSubscription, type Capacity, type Capsule, type CartesianLimits, type CartesianVelocity, type CartesianVelocity1, type CartesianVelocity2, type Cell, type CellCreatedEvent, type CellCycleEvent, type CellDeletedEvent, type CellDescription, type CellEventData, type CellName, type CellUpdatedEvent, type CloudEvent, type Collider, type ColliderDictionary, type ColliderDictionary1, type ColliderDictionary2, type CollisionMotionGroupLink, type CollisionMotionGroupTool, type CollisionMotionGroupTool1, type CollisionSetup, type ContainerEnvironment, type ContainerImage, type ContainerResources, type ContainerStorage, type ControllerNetworkInterface, type ControllerNetworkInterface1, type ConvexHull, type Cylinder, type DHParameter, type Device, type Execute, type Execute1, type FanucController, type IOBooleanValue, type IOFloatValue, type IOIntegerValue, type IOSubscriptionCreated, type IOSubscriptionLease, type IOUpdateType, type IOValue, type ImageCredentials, type JoggingDetails, type JoggingPausedByUser, type JoggingPausedNearCollision, type JoggingPausedNearJointLimit, type JoggingPausedNearSingularity, type JoggingPausedOnIO, type JoggingRunning, type JointLimits, type JointTypeEnum, type Joints, type Joints1, type Joints2, type Joints3, type KukaController, type LimitRange, type LimitRange1, type LimitSet, type LinkChain, type LinkChain1, type ListIOValuesResponse, type Location, type Manufacturer, type MotionGroupDescription, type MotionGroupFromJSON, type MotionGroupFromModel, type MotionGroupModel, type MotionGroupState, type MotionGroupState1, type MotionGroupState_JointLimitReached, type MotionGroupState_JointLimitReached1, type NatsErrorPayload, type NatsOperationParams, type NatsPublishPayloads, type NatsPublishSubject, type NatsReceivedMsg, type NatsReplyPayloads, type NatsRequestPayloads, type NatsRequestSubject, type NatsSubscribeMsg, type NatsSubscribeOptions, type NatsSubscribePayloads, type NatsSubscribeSubject, type NetworkBackend, type NetworkInterface, type NetworkInterfacesReply, type NetworkInterfacesRequest, type NetworkLinkState, type NetworkState, type NetworkStatusChangedEvent, NovaNatsClient, type NovaNatsClientConfig, type OperatingState, type OperationLimits, type OperationMode, type Payload, type PayloadDictionary, type Plane, type Pose, type Pose1, type Pose2, type Pose3, type Pose4, type Pose5, type ProgramRunState, type ProgramRunState1, type ProgramStatus, type Rectangle, type RectangularCapsule, type RenewIOSubscription, type RobotController, type RobotControllerCreatedEvent, type RobotControllerDeletedEvent, type RobotControllerEventData, type RobotControllerState, type RobotControllerUpdatedEvent, type RobotSystemMode, type RotationVector, type SafetyStateType, type SafetyToolColliders, type SelectIOs, type ServiceGroup, type ServiceStatus, type ServiceStatusList, type ServiceStatusPhase, type ServiceStatusSeverity, type Sphere, type StaubliController, type StreamIOValuesResponse, type SubscribeIOs, type SystemUpdateCompletedEvent, type SystemUpdateStartedEvent, type TcpOffset, type TcpOffsetDictionary, type TechmanController, type TrajectoryDetails, type TrajectoryEnded, type TrajectoryPausedByUser, type TrajectoryPausedOnIO, type TrajectoryRunning, type TrajectoryWaitForIO, type UnitreeController, type UniversalrobotsController, type UpdateIOSubscription, type Vector3D, type Vector3D1, type Vector3D2, type VirtualController, type YaskawaController, buildNatsServerUrl };
4102
+ export { type AbbController, type AddVirtualControllerMotionGroupRequest, type App, type AppCreatedEvent, type AppDeletedEvent, type AppEventData, type AppUpdatedEvent, type ArpScanReply, type ArpScanRequest, type AsyncReplyHeaders, type AsyncRequestHeaders, type BostondynamicsController, type Box, type BusIOsState, type BusIOsStateEnum, type CancelIOSubscription, type Capacity, type Capsule, type CartesianLimits, type CartesianVelocity, type CartesianVelocity1, type CartesianVelocity2, type Cell, type CellCreatedEvent, type CellCycleEvent, type CellDeletedEvent, type CellDescription, type CellEventData, type CellName, type CellUpdatedEvent, type CloudEvent, type Collider, type ColliderDictionary, type ColliderDictionary1, type ColliderDictionary2, type CollisionMotionGroupLink, type CollisionMotionGroupTool, type CollisionMotionGroupTool1, type CollisionSetup, type ContainerEnvironment, type ContainerImage, type ContainerResources, type ContainerStorage, type ControllerNetworkInterface, type ControllerNetworkInterface1, type ConvexHull, type Cylinder, type DHParameter, type Device, type Execute, type Execute1, type FanucController, type IOBooleanValue, type IOFloatValue, type IOIntegerValue, type IOSubscriptionCreated, type IOSubscriptionLease, type IOUpdateType, type IOValue, type ImageCredentials, type JoggingDetails, type JoggingPausedByUser, type JoggingPausedNearCollision, type JoggingPausedNearJointLimit, type JoggingPausedNearSingularity, type JoggingPausedOnIO, type JoggingRunning, type JointLimits, type JointTypeEnum, type Joints, type Joints1, type Joints2, type Joints3, type KukaController, type LimitRange, type LimitRange1, type LimitSet, type LinkChain, type LinkChain1, type ListIOValuesResponse, type Location, type Manufacturer, type MotionGroupDescription, type MotionGroupFromJSON, type MotionGroupFromModel, type MotionGroupModel, type MotionGroupState, type MotionGroupState1, type MotionGroupState_JointLimitReached, type MotionGroupState_JointLimitReached1, type NatsErrorPayload, type NatsOperationParams, type NatsPublishPayloads, type NatsPublishSubject, type NatsReceivedMsg, type NatsReplyPayloads, type NatsRequestPayloads, type NatsRequestSubject, type NatsSubscribeMsg, type NatsSubscribeOptions, type NatsSubscribePayloads, type NatsSubscribeSubject, type NatsSubscription, type NetworkBackend, type NetworkInterface, type NetworkInterfacesReply, type NetworkInterfacesRequest, type NetworkLinkState, type NetworkState, type NetworkStatusChangedEvent, NovaNatsClient, type NovaNatsClientConfig, type OperatingState, type OperationLimits, type OperationMode, type Payload, type PayloadDictionary, type Plane, type Pose, type Pose1, type Pose2, type Pose3, type Pose4, type Pose5, type ProgramRunState, type ProgramRunState1, type ProgramStatus, type Rectangle, type RectangularCapsule, type RenewIOSubscription, type RobotController, type RobotControllerCreatedEvent, type RobotControllerDeletedEvent, type RobotControllerEventData, type RobotControllerState, type RobotControllerUpdatedEvent, type RobotSystemMode, type RotationVector, type SafetyStateType, type SafetyToolColliders, type SelectIOs, type ServiceGroup, type ServiceStatus, type ServiceStatusList, type ServiceStatusPhase, type ServiceStatusSeverity, type Sphere, type StaubliController, type StreamIOValuesResponse, type SubscribeIOs, type SystemUpdateCompletedEvent, type SystemUpdateStartedEvent, type TcpOffset, type TcpOffsetDictionary, type TechmanController, type TrajectoryDetails, type TrajectoryEnded, type TrajectoryPausedByUser, type TrajectoryPausedOnIO, type TrajectoryRunning, type TrajectoryWaitForIO, type UnitreeController, type UniversalrobotsController, type UpdateIOSubscription, type Vector3D, type Vector3D1, type Vector3D2, type VirtualController, type YaskawaController, buildNatsServerUrl };
4087
4103
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/lib/experimental/nats/buildNatsServerUrl.ts","../../../src/lib/experimental/nats/generated/types.ts","../../../src/lib/experimental/nats/generated/operations.ts","../../../src/lib/experimental/nats/NovaNatsClient.ts"],"mappings":";;;;;;;;;;;iBAUgB,mBAAmB;;;;;;;;;;;;;;;;KCIvB;;;;;;;;KAQA;;;;;KAKA;;;;;;;;;KAkBA;;;;;;;;;;;KAWA,yCACR,uBACA;;;;;;;;;KASQ;EACV;EACA;;;;;;;;KAQU;;;;;;;KAOA;;;;KASA;;;;;KAUA;;;;;KASA;;;;;KAKA;;;;;KAmBA,oBAAoB;;;;;;;;;;;KAWpB;;;;;;;;;;;;;;KAcA;;;;;;;;;;;;;;;;;;;KAmBA,YAAY;;;;;;;KAOZ,aAAa;;;;;;;;KAQb;;;;;KASA,UAAU,iBAAiB,iBAAiB;;;;;;;KAO5C,uBAAuB;;;;;;;;;;KAUvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4CA;;;;;;;;;;;;;;KAmB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;;;;EAUlD,gEAAgE;;;;;;;;;;EAUhE,gEAAgE;;;;;;;;;;EAUhE,gEAAgE;;KAGtD,2BAA2B;;;KC92C3B,uBAAuB;;;;;;;UAQlB;;EAEf;;EAEA,MAAM;;EAEN,UAAU;;EAEV,KAAK,MAAM;;EAEX;;;;;;;;;KAUU,iBAAiB,UAAU,wBACrC;EACE,eAAe,oBAAoB;;KAG3B;;;;;;;;EAQV;;KAGG,mBAAmB,UAAU,yBAChC,SAAS,sBAAsB,IAC/B,KAAK,iBAAiB,cACZ;KAEP,cAAc,UAAU,8BACrB,oBAAoB,oBACrB,SAAS,mBAAmB,IAAI,UAAU,yBAEzC,QAAQ,oBAAoB,IAC5B,SAAS,mBAAmB,IAC5B,UAAU;;;;;;;cASL;WACF,QAAQ;UACT;EAEI,YAAA,MAAM,MAAM,SAAQ;;;;;;EAgBhC,WAAW,QAAQ;;EAYb,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCT,UAAU,UAAU,sBACxB,SAAS,MACN,MAAM,cAAc,KACtB;;;;;;;;;EAwFG,QAAQ,UAAU,oBACtB,SAAS,GACT,QAAQ,oBAAoB,IAC5B,SAAS,oBAAoB,IAC7B;IAAQ;MACP,QAAQ,kBAAkB;;;;;;;;;EAiBvB,QAAQ,UAAU,oBACtB,SAAS,GACT,QAAQ,oBAAoB,IAC5B,SAAS,oBAAoB,KAC5B"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/lib/experimental/nats/buildNatsServerUrl.ts","../../../src/lib/experimental/nats/generated/types.ts","../../../src/lib/experimental/nats/generated/operations.ts","../../../src/lib/experimental/nats/NovaNatsClient.ts"],"mappings":";;;;;;;;;;;iBAUgB,mBAAmB;;;;;;;;;;;;;;;;KCIvB;;;;;;;;KAQA;;;;;KAKA;;;;;;;;;KAkBA;;;;;;;;;;;KAWA,yCACR,uBACA;;;;;;;;;KASQ;EACV;EACA;;;;;;;;KAQU;;;;;;;KAOA;;;;KASA;;;;;KAUA;;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@@ var NovaNatsClient = class {
117
117
  * message persisted for each matching subject is replayed to the handler
118
118
  * immediately, before live messages (see {@link NatsSubscribeOptions}).
119
119
  *
120
- * Returns a function that unsubscribes when called.
120
+ * Returns a function that unsubscribes when called. Its `closed` promise
121
+ * resolves when the subscription has ended (see {@link NatsSubscription}).
121
122
  */
122
123
  async subscribe(subject, ...args) {
123
124
  const [params, handler, options] = typeof args[0] === "function" ? [
@@ -133,31 +134,28 @@ var NovaNatsClient = class {
133
134
  const resolvedSubject = buildSubject(subject, params);
134
135
  const paramPositions = [];
135
136
  for (const [index, token] of subject.split(".").entries()) if (token.startsWith("{") && token.endsWith("}")) paramPositions.push([token.slice(1, -1), index]);
136
- const dispatch = (messages) => {
137
- (async () => {
138
- for await (const msg of messages) try {
139
- const subjectTokens = msg.subject.split(".");
140
- const subjectParams = Object.fromEntries(paramPositions.map(([name, index]) => [name, subjectTokens[index] ?? ""]));
141
- await handler(msg.json(), Object.assign(msg, { subjectParams }));
142
- } catch (err) {
143
- console.error(`Error handling NATS message on subject "${resolvedSubject}"`, err);
144
- }
145
- })().catch((err) => {
146
- console.error(`NATS subscription iterator failed for "${resolvedSubject}"`, err);
147
- });
148
- };
137
+ const dispatch = (messages) => (async () => {
138
+ for await (const msg of messages) try {
139
+ const subjectTokens = msg.subject.split(".");
140
+ const subjectParams = Object.fromEntries(paramPositions.map(([name, index]) => [name, subjectTokens[index] ?? ""]));
141
+ await handler(msg.json(), Object.assign(msg, { subjectParams }));
142
+ } catch (err) {
143
+ console.error(`Error handling NATS message on subject "${resolvedSubject}"`, err);
144
+ }
145
+ })().catch((err) => {
146
+ console.error(`NATS subscription iterator failed for "${resolvedSubject}"`, err);
147
+ return err instanceof Error ? err : new Error(String(err));
148
+ });
149
149
  if (options?.lastMessage) {
150
150
  const streamName = await (await jetstreamManager(nc)).streams.find(resolvedSubject);
151
151
  const messages = await (await jetstream(nc).consumers.get(streamName, {
152
152
  filter_subjects: resolvedSubject,
153
153
  deliver_policy: DeliverPolicy.LastPerSubject
154
154
  })).consume();
155
- dispatch(messages);
156
- return () => void messages.close();
155
+ return Object.assign(() => void messages.close(), { closed: dispatch(messages) });
157
156
  }
158
157
  const sub = nc.subscribe(resolvedSubject);
159
- dispatch(sub);
160
- return () => sub.unsubscribe();
158
+ return Object.assign(() => sub.unsubscribe(), { closed: dispatch(sub) });
161
159
  }
162
160
  /**
163
161
  * Sends a request payload for a NATS subject the server receives, and
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/lib/experimental/nats/buildNatsServerUrl.ts","../../../src/lib/experimental/nats/buildSubject.ts","../../../src/lib/experimental/nats/NovaNatsClient.ts"],"sourcesContent":["import { parseNovaInstanceUrl } from \"../../converters.ts\"\n\n/**\n * Builds the WebSocket URL for a NOVA instance's NATS gateway from its\n * instance URL, e.g. `https://foo.instance.wandelbots.io` becomes\n * `wss://foo.instance.wandelbots.io/api/nats`.\n *\n * Pass the result as `servers` in the `NovaNatsClientConfig` passed to\n * `NovaNatsClient`.\n */\nexport function buildNatsServerUrl(instanceUrl: string): string {\n const url = parseNovaInstanceUrl(instanceUrl)\n const protocol = url.protocol === \"https:\" ? \"wss:\" : \"ws:\"\n return `${protocol}//${url.host}/api/nats`\n}\n","/**\n * Builds a NATS subject from an AsyncAPI-style channel address template\n * (e.g. `\"{instance}.v2.cells.{cell}\"`) by substituting each `{param}`\n * placeholder with the corresponding value from `params`.\n */\n\nfunction isValidSubjectChar(char: string): boolean {\n const code = char.charCodeAt(0)\n return (\n (code >= 48 && code <= 57) || // 0-9\n (code >= 65 && code <= 90) || // A-Z\n (code >= 97 && code <= 122) || // a-z\n char === \"-\" ||\n char === \"_\"\n )\n}\n\nfunction isValidSubjectValue(value: string): boolean {\n // A bare \"*\" is the NATS single-token wildcard, allowed on its own (e.g.\n // subscribing to all cells with `{ cell: \"*\" }\") but not as part of a\n // larger value, since it wouldn't act as a wildcard there anyway.\n if (value === \"*\") return true\n if (value.length === 0) return false\n for (const char of value) {\n if (!isValidSubjectChar(char)) return false\n }\n return true\n}\n\nexport function buildSubject(\n template: string,\n params: Record<string, string>,\n): string {\n // Scanned manually (rather than with a regex like /\\{([^}]+)\\}/g) to avoid\n // a polynomial-time backtracking blowup on pathological input, e.g. a\n // template consisting of many \"{\" characters with no closing \"}\".\n let result = \"\"\n let cursor = 0\n\n while (cursor < template.length) {\n const openIndex = template.indexOf(\"{\", cursor)\n if (openIndex === -1) {\n result += template.slice(cursor)\n break\n }\n\n const closeIndex = template.indexOf(\"}\", openIndex + 1)\n if (closeIndex === -1) {\n result += template.slice(cursor)\n break\n }\n\n result += template.slice(cursor, openIndex)\n const paramName = template.slice(openIndex + 1, closeIndex)\n const value = params[paramName]\n if (value === undefined) {\n throw new Error(\n `Missing value for subject parameter \"${paramName}\" in template \"${template}\"`,\n )\n }\n if (!isValidSubjectValue(value)) {\n throw new Error(\n `Invalid value for subject parameter \"${paramName}\": \"${value}\" (must be non-empty and contain only letters, digits, \"-\", and \"_\")`,\n )\n }\n result += value\n\n cursor = closeIndex + 1\n }\n\n return result\n}\n","import { DeliverPolicy, jetstream, jetstreamManager } from \"@nats-io/jetstream\"\nimport {\n type ConnectionOptions,\n type MsgHdrs,\n type NatsConnection,\n wsconnect,\n} from \"@nats-io/nats-core\"\nimport type { Nova } from \"../../Nova.ts\"\nimport { buildNatsServerUrl } from \"./buildNatsServerUrl.ts\"\nimport { buildSubject } from \"./buildSubject.ts\"\nimport type {\n NatsOperationParams,\n NatsPublishPayloads,\n NatsPublishSubject,\n NatsReplyPayloads,\n NatsRequestPayloads,\n NatsRequestSubject,\n NatsSubscribePayloads,\n NatsSubscribeSubject,\n} from \"./generated/operations.ts\"\n\nexport type NovaNatsClientConfig = ConnectionOptions\n\n/**\n * The fields of a received message that exist on both a core NATS `Msg` and\n * a JetStream `JsMsg` — a subscription delivers the former by default and\n * the latter with `lastMessage: true` (see {@link NatsSubscribeOptions}),\n * so handlers see only what both have in common.\n */\nexport interface NatsReceivedMsg {\n /** The concrete subject the message was published to. */\n subject: string\n /** The message's raw payload bytes. */\n data: Uint8Array\n /** Headers set by the server or the publisher, if any. */\n headers?: MsgHdrs\n /** The payload decoded as JSON. */\n json<T>(): T\n /** The payload decoded as a string. */\n string(): string\n}\n\n/**\n * A received message, annotated with the values of the subject template's\n * `{param}` placeholders as extracted from the message's concrete subject.\n * With a wildcard subscription (e.g. `{ cell: \"*\" }`), `subjectParams` is how\n * a handler knows which entity a message belongs to. Typed per subject via\n * the generated `NatsOperationParams`.\n */\nexport type NatsSubscribeMsg<K extends NatsSubscribeSubject> =\n NatsReceivedMsg & {\n subjectParams: NatsOperationParams[K]\n }\n\nexport type NatsSubscribeOptions = {\n /**\n * When true, the subscription immediately replays the last JetStream\n * message persisted for each subject matching the subscription (one per\n * concrete subject when subscribing with wildcards), then continues with\n * live messages. Requires the server to have a JetStream stream capturing\n * the subscribed subject; subscribing fails with an error if none exists.\n */\n lastMessage?: boolean\n}\n\ntype NatsMessageHandler<K extends NatsSubscribeSubject> = (\n payload: NatsSubscribePayloads[K],\n msg: NatsSubscribeMsg<K>,\n) => void | Promise<void>\n\ntype SubscribeArgs<K extends NatsSubscribeSubject> =\n keyof NatsOperationParams[K] extends never\n ? [handler: NatsMessageHandler<K>, options?: NatsSubscribeOptions]\n : [\n params: NatsOperationParams[K],\n handler: NatsMessageHandler<K>,\n options?: NatsSubscribeOptions,\n ]\n\n/**\n * Typed NATS client for the Wandelbots NOVA messaging API, generated from\n * src/asyncapi.yaml (see scripts/generate-nats-client.ts).\n *\n * Connects over WebSocket via `@nats-io/nats-core`'s `wsconnect`.\n */\nexport class NovaNatsClient {\n readonly config: NovaNatsClientConfig\n private connectionPromise: Promise<NatsConnection> | null = null\n\n constructor(nova: Nova, config: NovaNatsClientConfig = {}) {\n this.config = {\n servers: buildNatsServerUrl(nova.instanceUrl.href),\n // Reuse the Nova instance's access token for NATS auth, if it has one\n // (e.g. from login or a passed-in config.accessToken). Explicit auth\n // options in `config` (token/user/pass/authenticator) still win.\n ...(nova.accessToken ? { token: nova.accessToken } : {}),\n ...config,\n }\n }\n\n /**\n * Connects to NATS if not already connected or connecting, and returns the\n * connection. Safe to call concurrently: all callers share the same\n * in-flight connection attempt instead of each starting their own.\n */\n connect(): Promise<NatsConnection> {\n if (!this.connectionPromise) {\n this.connectionPromise = wsconnect(this.config).catch((err: unknown) => {\n // Allow a subsequent connect() call to retry after a failed attempt.\n this.connectionPromise = null\n throw err\n })\n }\n return this.connectionPromise\n }\n\n /** Closes the underlying NATS connection, if open or connecting. */\n async close(): Promise<void> {\n const connectionPromise = this.connectionPromise\n this.connectionPromise = null\n if (!connectionPromise) return\n try {\n const nc = await connectionPromise\n await nc.close()\n } catch {\n // Connection never succeeded; nothing to close.\n }\n }\n\n /**\n * Subscribes to a NATS subject published by the server, invoking `handler`\n * with the JSON-decoded payload of every message received.\n *\n * `subject` is the subject template as it appears on the wire, e.g.\n * `\"nova.v2.cells.{cell}\"`, with `{param}` placeholders filled in from\n * `params`.\n *\n * Errors decoding a message or thrown/rejected by `handler` are caught and\n * logged per-message, so one bad message doesn't stop later messages on\n * the same subscription from being handled.\n *\n * Each message is annotated with `msg.subjectParams` — the template's\n * `{param}` values extracted from the message's concrete subject — so a\n * wildcard subscriber knows which entity a message belongs to:\n *\n * nats.subscribe(\"nova.v2.cells.{cell}.status\", { cell: \"*\" },\n * (services, msg) => console.log(msg.subjectParams.cell, services))\n *\n * With `{ lastMessage: true }` as the final argument, the last JetStream\n * message persisted for each matching subject is replayed to the handler\n * immediately, before live messages (see {@link NatsSubscribeOptions}).\n *\n * Returns a function that unsubscribes when called.\n */\n async subscribe<K extends NatsSubscribeSubject>(\n subject: K,\n ...args: SubscribeArgs<K>\n ): Promise<() => void> {\n const [params, handler, options] =\n typeof args[0] === \"function\"\n ? ([{}, args[0], args[1] as NatsSubscribeOptions | undefined] as const)\n : ([args[0], args[1] as NatsMessageHandler<K>, args[2]] as const)\n\n const nc = await this.connect()\n const resolvedSubject = buildSubject(subject, params)\n\n // The token positions of the template's {param} placeholders, computed\n // once here so each message's subjectParams is a plain index pick: a\n // delivered message always matches the subscribed pattern token for\n // token, so its params sit at the same positions as in the template.\n const paramPositions: [name: string, index: number][] = []\n for (const [index, token] of subject.split(\".\").entries()) {\n if (token.startsWith(\"{\") && token.endsWith(\"}\")) {\n paramPositions.push([token.slice(1, -1), index])\n }\n }\n\n const dispatch = (messages: AsyncIterable<NatsReceivedMsg>) => {\n ;(async () => {\n for await (const msg of messages) {\n // Handled per-message: a bad payload or a throwing/rejecting\n // handler should not stop the subscription from processing later\n // messages.\n try {\n const subjectTokens = msg.subject.split(\".\")\n const subjectParams = Object.fromEntries(\n paramPositions.map(([name, index]) => [\n name,\n subjectTokens[index] ?? \"\",\n ]),\n ) as NatsOperationParams[K]\n await handler(\n msg.json<NatsSubscribePayloads[K]>(),\n Object.assign(msg, { subjectParams }),\n )\n } catch (err) {\n console.error(\n `Error handling NATS message on subject \"${resolvedSubject}\"`,\n err,\n )\n }\n }\n })().catch((err: unknown) => {\n console.error(\n `NATS subscription iterator failed for \"${resolvedSubject}\"`,\n err,\n )\n })\n }\n\n if (options?.lastMessage) {\n // Delivered through JetStream instead of a core subscription: an\n // ordered (ephemeral, auto-acked, auto-cleaned-up) consumer with\n // \"last per subject\" delivery replays the last persisted message of\n // each matching subject, then seamlessly continues with live messages.\n const jsm = await jetstreamManager(nc)\n // Throws if no stream captures the subject, rather than silently\n // never delivering anything.\n const streamName = await jsm.streams.find(resolvedSubject)\n const consumer = await jetstream(nc).consumers.get(streamName, {\n // A single string, not an array: only then does @nats-io/jetstream\n // put the filter into the consumer-create subject\n // ($JS.API.CONSUMER.CREATE.<stream>.<consumer>.<filter>), which NOVA's\n // per-cell NATS authorization requires (IC-908).\n filter_subjects: resolvedSubject,\n deliver_policy: DeliverPolicy.LastPerSubject,\n })\n const messages = await consumer.consume()\n dispatch(messages)\n return () => void messages.close()\n }\n\n const sub = nc.subscribe(resolvedSubject)\n dispatch(sub)\n return () => sub.unsubscribe()\n }\n\n /**\n * Sends a request payload for a NATS subject the server receives, and\n * waits for the JSON-decoded reply.\n *\n * `subject` is the subject template as it appears on the wire, e.g.\n * `\"nova.v2.cells.{cell}.bus-ios.ios.set\"`, with `{param}` placeholders\n * filled in from `params`.\n */\n async request<K extends NatsRequestSubject>(\n subject: K,\n params: NatsOperationParams[K],\n payload: NatsRequestPayloads[K],\n opts: { timeout?: number } = {},\n ): Promise<NatsReplyPayloads[K]> {\n const nc = await this.connect()\n const resolvedSubject = buildSubject(subject, params)\n const msg = await nc.request(resolvedSubject, JSON.stringify(payload), {\n timeout: opts.timeout ?? 5000,\n })\n return msg.json<NatsReplyPayloads[K]>()\n }\n\n /**\n * Publishes a JSON payload to any NATS subject defined in the spec,\n * without waiting for a reply.\n *\n * `subject` is the subject template as it appears on the wire, e.g.\n * `\"nova.v2.cells.{cell}.bus-ios.ios.set\"`, with `{param}` placeholders\n * filled in from `params`.\n */\n async publish<K extends NatsPublishSubject>(\n subject: K,\n params: NatsOperationParams[K],\n payload: NatsPublishPayloads[K],\n ): Promise<void> {\n const nc = await this.connect()\n const resolvedSubject = buildSubject(subject, params)\n nc.publish(resolvedSubject, JSON.stringify(payload))\n }\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAgB,mBAAmB,aAA6B;CAC9D,MAAM,MAAM,qBAAqB,WAAW;CAE5C,OAAO,GADU,IAAI,aAAa,WAAW,SAAS,MACnC,IAAI,IAAI,KAAK;AAClC;;;;;;;;ACRA,SAAS,mBAAmB,MAAuB;CACjD,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,OACG,QAAQ,MAAM,QAAQ,MACtB,QAAQ,MAAM,QAAQ,MACtB,QAAQ,MAAM,QAAQ,OACvB,SAAS,OACT,SAAS;AAEb;AAEA,SAAS,oBAAoB,OAAwB;CAInD,IAAI,UAAU,KAAK,OAAO;CAC1B,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,KAAK,MAAM,QAAQ,OACjB,I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YAAY;IAK7D,iBAAiB;IACjB,gBAAgB,cAAc;GAChC,CAAC,EAAA,CAC+B,QAAQ;GACxC,SAAS,QAAQ;GACjB,aAAa,KAAK,SAAS,MAAM;EACnC;EAEA,MAAM,MAAM,GAAG,UAAU,eAAe;EACxC,SAAS,GAAG;EACZ,aAAa,IAAI,YAAY;CAC/B;;;;;;;;;CAUA,MAAM,QACJ,SACA,QACA,SACA,OAA6B,CAAC,GACC;EAC/B,MAAM,KAAK,MAAM,KAAK,QAAQ;EAC9B,MAAM,kBAAkB,aAAa,SAAS,MAAM;EAIpD,QAAO,MAHW,GAAG,QAAQ,iBAAiB,KAAK,UAAU,OAAO,GAAG,EACrE,SAAS,KAAK,WAAW,IAC3B,CAAC,EAAA,CACU,KAA2B;CACxC;;;;;;;;;CAUA,MAAM,QACJ,SACA,QACA,SACe;EACf,MAAM,KAAK,MAAM,KAAK,QAAQ;EAC9B,MAAM,kBAAkB,aAAa,SAAS,MAAM;EACpD,GAAG,QAAQ,iBAAiB,KAAK,UAAU,OAAO,CAAC;CACrD;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/lib/experimental/nats/buildNatsServerUrl.ts","../../../src/lib/experimental/nats/buildSubject.ts","../../../src/lib/experimental/nats/NovaNatsClient.ts"],"sourcesContent":["import { parseNovaInstanceUrl } from \"../../converters.ts\"\n\n/**\n * Builds the WebSocket URL for a NOVA instance's NATS gateway from its\n * instance URL, e.g. `https://foo.instance.wandelbots.io` becomes\n * `wss://foo.instance.wandelbots.io/api/nats`.\n *\n * Pass the result as `servers` in the `NovaNatsClientConfig` passed to\n * `NovaNatsClient`.\n */\nexport function buildNatsServerUrl(instanceUrl: string): string {\n const url = parseNovaInstanceUrl(instanceUrl)\n const protocol = url.protocol === \"https:\" ? \"wss:\" : \"ws:\"\n return `${protocol}//${url.host}/api/nats`\n}\n","/**\n * Builds a NATS subject from an AsyncAPI-style channel address template\n * (e.g. `\"{instance}.v2.cells.{cell}\"`) by substituting each `{param}`\n * placeholder with the corresponding value from `params`.\n */\n\nfunction isValidSubjectChar(char: string): boolean {\n const code = char.charCodeAt(0)\n return (\n (code >= 48 && code <= 57) || // 0-9\n (code >= 65 && code <= 90) || // A-Z\n (code >= 97 && code <= 122) || // a-z\n char === \"-\" ||\n char === \"_\"\n )\n}\n\nfunction isValidSubjectValue(value: string): boolean {\n // A bare \"*\" is the NATS single-token wildcard, allowed on its own (e.g.\n // subscribing to all cells with `{ cell: \"*\" }\") but not as part of a\n // larger value, since it wouldn't act as a wildcard there anyway.\n if (value === \"*\") return true\n if (value.length === 0) return false\n for (const char of value) {\n if (!isValidSubjectChar(char)) return false\n }\n return true\n}\n\nexport function buildSubject(\n template: string,\n params: Record<string, string>,\n): string {\n // Scanned manually (rather than with a regex like /\\{([^}]+)\\}/g) to avoid\n // a polynomial-time backtracking blowup on pathological input, e.g. a\n // template consisting of many \"{\" characters with no closing \"}\".\n let result = \"\"\n let cursor = 0\n\n while (cursor < template.length) {\n const openIndex = template.indexOf(\"{\", cursor)\n if (openIndex === -1) {\n result += template.slice(cursor)\n break\n }\n\n const closeIndex = template.indexOf(\"}\", openIndex + 1)\n if (closeIndex === -1) {\n result += template.slice(cursor)\n break\n }\n\n result += template.slice(cursor, openIndex)\n const paramName = template.slice(openIndex + 1, closeIndex)\n const value = params[paramName]\n if (value === undefined) {\n throw new Error(\n `Missing value for subject parameter \"${paramName}\" in template \"${template}\"`,\n )\n }\n if (!isValidSubjectValue(value)) {\n throw new Error(\n `Invalid value for subject parameter \"${paramName}\": \"${value}\" (must be non-empty and contain only letters, digits, \"-\", and \"_\")`,\n )\n }\n result += value\n\n cursor = closeIndex + 1\n }\n\n return result\n}\n","import { DeliverPolicy, jetstream, jetstreamManager } from \"@nats-io/jetstream\"\nimport {\n type ConnectionOptions,\n type MsgHdrs,\n type NatsConnection,\n wsconnect,\n} from \"@nats-io/nats-core\"\nimport type { Nova } from \"../../Nova.ts\"\nimport { buildNatsServerUrl } from \"./buildNatsServerUrl.ts\"\nimport { buildSubject } from \"./buildSubject.ts\"\nimport type {\n NatsOperationParams,\n NatsPublishPayloads,\n NatsPublishSubject,\n NatsReplyPayloads,\n NatsRequestPayloads,\n NatsRequestSubject,\n NatsSubscribePayloads,\n NatsSubscribeSubject,\n} from \"./generated/operations.ts\"\n\nexport type NovaNatsClientConfig = ConnectionOptions\n\n/**\n * The fields of a received message that exist on both a core NATS `Msg` and\n * a JetStream `JsMsg` — a subscription delivers the former by default and\n * the latter with `lastMessage: true` (see {@link NatsSubscribeOptions}),\n * so handlers see only what both have in common.\n */\nexport interface NatsReceivedMsg {\n /** The concrete subject the message was published to. */\n subject: string\n /** The message's raw payload bytes. */\n data: Uint8Array\n /** Headers set by the server or the publisher, if any. */\n headers?: MsgHdrs\n /** The payload decoded as JSON. */\n json<T>(): T\n /** The payload decoded as a string. */\n string(): string\n}\n\n/**\n * A received message, annotated with the values of the subject template's\n * `{param}` placeholders as extracted from the message's concrete subject.\n * With a wildcard subscription (e.g. `{ cell: \"*\" }`), `subjectParams` is how\n * a handler knows which entity a message belongs to. Typed per subject via\n * the generated `NatsOperationParams`.\n */\nexport type NatsSubscribeMsg<K extends NatsSubscribeSubject> =\n NatsReceivedMsg & {\n subjectParams: NatsOperationParams[K]\n }\n\nexport type NatsSubscribeOptions = {\n /**\n * When true, the subscription immediately replays the last JetStream\n * message persisted for each subject matching the subscription (one per\n * concrete subject when subscribing with wildcards), then continues with\n * live messages. Requires the server to have a JetStream stream capturing\n * the subscribed subject; subscribing fails with an error if none exists.\n */\n lastMessage?: boolean\n}\n\n/**\n * What `subscribe()` returns: a function that unsubscribes when called, with\n * a `closed` promise that resolves when the subscription has ended. After\n * that, the subscription receives no more messages; subscribe again to\n * receive them.\n *\n * `closed` resolves with `undefined` when the subscription ended without an\n * error: after an unsubscribe, or because the connection was closed. It\n * resolves with the error when the server or the NATS library ended it, for\n * example when the server refused the subject, or when JetStream could not\n * create a lost consumer again.\n */\nexport type NatsSubscription = (() => void) & {\n closed: Promise<Error | undefined>\n}\n\ntype NatsMessageHandler<K extends NatsSubscribeSubject> = (\n payload: NatsSubscribePayloads[K],\n msg: NatsSubscribeMsg<K>,\n) => void | Promise<void>\n\ntype SubscribeArgs<K extends NatsSubscribeSubject> =\n keyof NatsOperationParams[K] extends never\n ? [handler: NatsMessageHandler<K>, options?: NatsSubscribeOptions]\n : [\n params: NatsOperationParams[K],\n handler: NatsMessageHandler<K>,\n options?: NatsSubscribeOptions,\n ]\n\n/**\n * Typed NATS client for the Wandelbots NOVA messaging API, generated from\n * src/asyncapi.yaml (see scripts/generate-nats-client.ts).\n *\n * Connects over WebSocket via `@nats-io/nats-core`'s `wsconnect`.\n */\nexport class NovaNatsClient {\n readonly config: NovaNatsClientConfig\n private connectionPromise: Promise<NatsConnection> | null = null\n\n constructor(nova: Nova, config: NovaNatsClientConfig = {}) {\n this.config = {\n servers: buildNatsServerUrl(nova.instanceUrl.href),\n // Reuse the Nova instance's access token for NATS auth, if it has one\n // (e.g. from login or a passed-in config.accessToken). Explicit auth\n // options in `config` (token/user/pass/authenticator) still win.\n ...(nova.accessToken ? { token: nova.accessToken } : {}),\n ...config,\n }\n }\n\n /**\n * Connects to NATS if not already connected or connecting, and returns the\n * connection. Safe to call concurrently: all callers share the same\n * in-flight connection attempt instead of each starting their own.\n */\n connect(): Promise<NatsConnection> {\n if (!this.connectionPromise) {\n this.connectionPromise = wsconnect(this.config).catch((err: unknown) => {\n // Allow a subsequent connect() call to retry after a failed attempt.\n this.connectionPromise = null\n throw err\n })\n }\n return this.connectionPromise\n }\n\n /** Closes the underlying NATS connection, if open or connecting. */\n async close(): Promise<void> {\n const connectionPromise = this.connectionPromise\n this.connectionPromise = null\n if (!connectionPromise) return\n try {\n const nc = await connectionPromise\n await nc.close()\n } catch {\n // Connection never succeeded; nothing to close.\n }\n }\n\n /**\n * Subscribes to a NATS subject published by the server, invoking `handler`\n * with the JSON-decoded payload of every message received.\n *\n * `subject` is the subject template as it appears on the wire, e.g.\n * `\"nova.v2.cells.{cell}\"`, with `{param}` placeholders filled in from\n * `params`.\n *\n * Errors decoding a message or thrown/rejected by `handler` are caught and\n * logged per-message, so one bad message doesn't stop later messages on\n * the same subscription from being handled.\n *\n * Each message is annotated with `msg.subjectParams` — the template's\n * `{param}` values extracted from the message's concrete subject — so a\n * wildcard subscriber knows which entity a message belongs to:\n *\n * nats.subscribe(\"nova.v2.cells.{cell}.status\", { cell: \"*\" },\n * (services, msg) => console.log(msg.subjectParams.cell, services))\n *\n * With `{ lastMessage: true }` as the final argument, the last JetStream\n * message persisted for each matching subject is replayed to the handler\n * immediately, before live messages (see {@link NatsSubscribeOptions}).\n *\n * Returns a function that unsubscribes when called. Its `closed` promise\n * resolves when the subscription has ended (see {@link NatsSubscription}).\n */\n async subscribe<K extends NatsSubscribeSubject>(\n subject: K,\n ...args: SubscribeArgs<K>\n ): Promise<NatsSubscription> {\n const [params, handler, options] =\n typeof args[0] === \"function\"\n ? ([{}, args[0], args[1] as NatsSubscribeOptions | undefined] as const)\n : ([args[0], args[1] as NatsMessageHandler<K>, args[2]] as const)\n\n const nc = await this.connect()\n const resolvedSubject = buildSubject(subject, params)\n\n // The token positions of the template's {param} placeholders, computed\n // once here so each message's subjectParams is a plain index pick: a\n // delivered message always matches the subscribed pattern token for\n // token, so its params sit at the same positions as in the template.\n const paramPositions: [name: string, index: number][] = []\n for (const [index, token] of subject.split(\".\").entries()) {\n if (token.startsWith(\"{\") && token.endsWith(\"}\")) {\n paramPositions.push([token.slice(1, -1), index])\n }\n }\n\n // Resolves when the messages end: with `undefined` when they end without\n // an error, else with the error\n const dispatch = (\n messages: AsyncIterable<NatsReceivedMsg>,\n ): Promise<Error | undefined> =>\n (async () => {\n for await (const msg of messages) {\n // Handled per-message: a bad payload or a throwing/rejecting\n // handler should not stop the subscription from processing later\n // messages.\n try {\n const subjectTokens = msg.subject.split(\".\")\n const subjectParams = Object.fromEntries(\n paramPositions.map(([name, index]) => [\n name,\n subjectTokens[index] ?? \"\",\n ]),\n ) as NatsOperationParams[K]\n await handler(\n msg.json<NatsSubscribePayloads[K]>(),\n Object.assign(msg, { subjectParams }),\n )\n } catch (err) {\n console.error(\n `Error handling NATS message on subject \"${resolvedSubject}\"`,\n err,\n )\n }\n }\n return undefined\n })().catch((err: unknown) => {\n console.error(\n `NATS subscription iterator failed for \"${resolvedSubject}\"`,\n err,\n )\n return err instanceof Error ? err : new Error(String(err))\n })\n\n if (options?.lastMessage) {\n // Delivered through JetStream instead of a core subscription: an\n // ordered (ephemeral, auto-acked, auto-cleaned-up) consumer with\n // \"last per subject\" delivery replays the last persisted message of\n // each matching subject, then seamlessly continues with live messages.\n const jsm = await jetstreamManager(nc)\n // Throws if no stream captures the subject, rather than silently\n // never delivering anything.\n const streamName = await jsm.streams.find(resolvedSubject)\n const consumer = await jetstream(nc).consumers.get(streamName, {\n // A single string, not an array: only then does @nats-io/jetstream\n // put the filter into the consumer-create subject\n // ($JS.API.CONSUMER.CREATE.<stream>.<consumer>.<filter>), which NOVA's\n // per-cell NATS authorization requires (IC-908).\n filter_subjects: resolvedSubject,\n deliver_policy: DeliverPolicy.LastPerSubject,\n })\n const messages = await consumer.consume()\n return Object.assign(() => void messages.close(), {\n closed: dispatch(messages),\n })\n }\n\n const sub = nc.subscribe(resolvedSubject)\n return Object.assign(() => sub.unsubscribe(), { closed: dispatch(sub) })\n }\n\n /**\n * Sends a request payload for a NATS subject the server receives, and\n * waits for the JSON-decoded reply.\n *\n * `subject` is the subject template as it appears on the wire, e.g.\n * `\"nova.v2.cells.{cell}.bus-ios.ios.set\"`, with `{param}` placeholders\n * filled in from `params`.\n */\n async request<K extends NatsRequestSubject>(\n subject: K,\n params: NatsOperationParams[K],\n payload: NatsRequestPayloads[K],\n opts: { timeout?: number } = {},\n ): Promise<NatsReplyPayloads[K]> {\n const nc = await this.connect()\n const resolvedSubject = buildSubject(subject, params)\n const msg = await nc.request(resolvedSubject, JSON.stringify(payload), {\n timeout: opts.timeout ?? 5000,\n })\n return msg.json<NatsReplyPayloads[K]>()\n }\n\n /**\n * Publishes a JSON payload to any NATS subject defined in the spec,\n * without waiting for a reply.\n *\n * `subject` is the subject template as it appears on the wire, e.g.\n * `\"nova.v2.cells.{cell}.bus-ios.ios.set\"`, with `{param}` placeholders\n * filled in from `params`.\n */\n async publish<K extends NatsPublishSubject>(\n subject: K,\n params: NatsOperationParams[K],\n payload: NatsPublishPayloads[K],\n ): Promise<void> {\n const nc = await this.connect()\n const resolvedSubject = buildSubject(subject, params)\n nc.publish(resolvedSubject, JSON.stringify(payload))\n }\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAgB,mBAAmB,aAA6B;CAC9D,MAAM,MAAM,qBAAqB,WAAW;CAE5C,OAAO,GADU,IAAI,aAAa,WAAW,SAAS,MACnC,IAAI,IAAI,KAAK;AAClC;;;;;;;;ACRA,SAAS,mBAAmB,MAAuB;CACjD,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,OACG,QAAQ,MAAM,QAAQ,MACtB,QAAQ,MAAM,QAAQ,MACtB,QAAQ,MAAM,QAAQ,OACvB,SAAS,OACT,SAAS;AAEb;AAEA,SAAS,oBAAoB,OAAwB;CAInD,IAAI,UAAU,KAAK,OAAO;CAC1B,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,KAAK,MAAM,QAAQ,OACjB,IAAI,CAAC,mBAAmB,IAAI,GAAG,OAAO;CAExC,OAAO;AACT;AAEA,SAAgB,aACd,UACA,QACQ;CAIR,IAAI,SAAS;CACb,IAAI,SAAS;CAEb,OAAO,SAAS,SAAS,QAAQ;EAC/B,MAAM,YAAY,SAAS,QAAQ,KAAK,MAAM;EAC9C,IAAI,cAAc,IAAI;GACpB,UAAU,SAAS,MAAM,MAAM;GAC/B;EACF;EAEA,MAAM,aAAa,SAAS,QAAQ,KAAK,YAAY,CAAC;EACtD,IAAI,eAAe,IAAI;GACrB,UAAU,SAAS,MAAM,MAAM;GAC/B;EACF;EAEA,UAAU,SAAS,MAAM,QAAQ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AM,KAAK,MAAM,KAAK,QAAQ;EAC9B,MAAM,kBAAkB,aAAa,SAAS,MAAM;EAIpD,QAAO,MAHW,GAAG,QAAQ,iBAAiB,KAAK,UAAU,OAAO,GAAG,EACrE,SAAS,KAAK,WAAW,IAC3B,CAAC,EAAA,CACU,KAA2B;CACxC;;;;;;;;;CAUA,MAAM,QACJ,SACA,QACA,SACe;EACf,MAAM,KAAK,MAAM,KAAK,QAAQ;EAC9B,MAAM,kBAAkB,aAAa,SAAS,MAAM;EACpD,GAAG,QAAQ,iBAAiB,KAAK,UAAU,OAAO,CAAC;CACrD;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wandelbots/nova-js",
3
3
  "type": "module",
4
- "version": "4.11.1-pr.341.4b83d94",
4
+ "version": "4.12.0-pr.342.98a4769",
5
5
  "description": "Official JS client for the Wandelbots API",
6
6
  "sideEffects": false,
7
7
  "packageManager": "pnpm@11.9.0+sha512.bd682d5d03fe525ef7c9fd6780c6884d1e756ac4c9c9fe00c538782824310dcf90e3ddc4f53835f06dfaebd5085e41855e0bcbb3b60de2ac5bbab89e5036f03b",
@@ -24,5 +24,6 @@ export type {
24
24
  NatsReceivedMsg,
25
25
  NatsSubscribeMsg,
26
26
  NatsSubscribeOptions,
27
+ NatsSubscription,
27
28
  NovaNatsClientConfig,
28
29
  } from "../../lib/experimental/nats/NovaNatsClient.ts"
@@ -63,6 +63,22 @@ export type NatsSubscribeOptions = {
63
63
  lastMessage?: boolean
64
64
  }
65
65
 
66
+ /**
67
+ * What `subscribe()` returns: a function that unsubscribes when called, with
68
+ * a `closed` promise that resolves when the subscription has ended. After
69
+ * that, the subscription receives no more messages; subscribe again to
70
+ * receive them.
71
+ *
72
+ * `closed` resolves with `undefined` when the subscription ended without an
73
+ * error: after an unsubscribe, or because the connection was closed. It
74
+ * resolves with the error when the server or the NATS library ended it, for
75
+ * example when the server refused the subject, or when JetStream could not
76
+ * create a lost consumer again.
77
+ */
78
+ export type NatsSubscription = (() => void) & {
79
+ closed: Promise<Error | undefined>
80
+ }
81
+
66
82
  type NatsMessageHandler<K extends NatsSubscribeSubject> = (
67
83
  payload: NatsSubscribePayloads[K],
68
84
  msg: NatsSubscribeMsg<K>,
@@ -150,12 +166,13 @@ export class NovaNatsClient {
150
166
  * message persisted for each matching subject is replayed to the handler
151
167
  * immediately, before live messages (see {@link NatsSubscribeOptions}).
152
168
  *
153
- * Returns a function that unsubscribes when called.
169
+ * Returns a function that unsubscribes when called. Its `closed` promise
170
+ * resolves when the subscription has ended (see {@link NatsSubscription}).
154
171
  */
155
172
  async subscribe<K extends NatsSubscribeSubject>(
156
173
  subject: K,
157
174
  ...args: SubscribeArgs<K>
158
- ): Promise<() => void> {
175
+ ): Promise<NatsSubscription> {
159
176
  const [params, handler, options] =
160
177
  typeof args[0] === "function"
161
178
  ? ([{}, args[0], args[1] as NatsSubscribeOptions | undefined] as const)
@@ -175,8 +192,12 @@ export class NovaNatsClient {
175
192
  }
176
193
  }
177
194
 
178
- const dispatch = (messages: AsyncIterable<NatsReceivedMsg>) => {
179
- ;(async () => {
195
+ // Resolves when the messages end: with `undefined` when they end without
196
+ // an error, else with the error
197
+ const dispatch = (
198
+ messages: AsyncIterable<NatsReceivedMsg>,
199
+ ): Promise<Error | undefined> =>
200
+ (async () => {
180
201
  for await (const msg of messages) {
181
202
  // Handled per-message: a bad payload or a throwing/rejecting
182
203
  // handler should not stop the subscription from processing later
@@ -200,13 +221,14 @@ export class NovaNatsClient {
200
221
  )
201
222
  }
202
223
  }
224
+ return undefined
203
225
  })().catch((err: unknown) => {
204
226
  console.error(
205
227
  `NATS subscription iterator failed for "${resolvedSubject}"`,
206
228
  err,
207
229
  )
230
+ return err instanceof Error ? err : new Error(String(err))
208
231
  })
209
- }
210
232
 
211
233
  if (options?.lastMessage) {
212
234
  // Delivered through JetStream instead of a core subscription: an
@@ -226,13 +248,13 @@ export class NovaNatsClient {
226
248
  deliver_policy: DeliverPolicy.LastPerSubject,
227
249
  })
228
250
  const messages = await consumer.consume()
229
- dispatch(messages)
230
- return () => void messages.close()
251
+ return Object.assign(() => void messages.close(), {
252
+ closed: dispatch(messages),
253
+ })
231
254
  }
232
255
 
233
256
  const sub = nc.subscribe(resolvedSubject)
234
- dispatch(sub)
235
- return () => sub.unsubscribe()
257
+ return Object.assign(() => sub.unsubscribe(), { closed: dispatch(sub) })
236
258
  }
237
259
 
238
260
  /**