@wandelbots/nova-js 4.11.1-pr.341.4b83d94 → 4.12.0-pr.342.606c434

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,27 @@ type NatsSubscribeOptions = {
4015
4015
  */
4016
4016
  lastMessage?: boolean;
4017
4017
  };
4018
+ /**
4019
+ * What `subscribe()` returns: a function that unsubscribes when called, with
4020
+ * a method `closed()`, whose promise resolves when the subscription has
4021
+ * ended. After that, the subscription receives no more messages; subscribe
4022
+ * again to receive them.
4023
+ *
4024
+ * The promise resolves with `undefined` when the subscription ended without
4025
+ * an 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
+ * The promise resolves only after the handler has finished with the last
4031
+ * message, so the handler is never called after that. While a handler still
4032
+ * runs, the promise waits for it, as `closed` of a nats.js subscription waits
4033
+ * for the code that iterates its messages. So a handler must not wait for
4034
+ * `closed()` of its own subscription.
4035
+ */
4036
+ type NatsSubscription = (() => void) & {
4037
+ closed(): Promise<Error | undefined>;
4038
+ };
4018
4039
  type NatsMessageHandler<K extends NatsSubscribeSubject> = (payload: NatsSubscribePayloads[K], msg: NatsSubscribeMsg<K>) => void | Promise<void>;
4019
4040
  type SubscribeArgs<K extends NatsSubscribeSubject> = keyof NatsOperationParams[K] extends never ? [handler: NatsMessageHandler<K>, options?: NatsSubscribeOptions] : [params: NatsOperationParams[K], handler: NatsMessageHandler<K>, options?: NatsSubscribeOptions];
4020
4041
  /**
@@ -4058,9 +4079,11 @@ declare class NovaNatsClient {
4058
4079
  * message persisted for each matching subject is replayed to the handler
4059
4080
  * immediately, before live messages (see {@link NatsSubscribeOptions}).
4060
4081
  *
4061
- * Returns a function that unsubscribes when called.
4082
+ * Returns a function that unsubscribes when called. The promise of its
4083
+ * `closed()` resolves when the subscription has ended (see
4084
+ * {@link NatsSubscription}).
4062
4085
  */
4063
- subscribe<K extends NatsSubscribeSubject>(subject: K, ...args: SubscribeArgs<K>): Promise<() => void>;
4086
+ subscribe<K extends NatsSubscribeSubject>(subject: K, ...args: SubscribeArgs<K>): Promise<NatsSubscription>;
4064
4087
  /**
4065
4088
  * Sends a request payload for a NATS subject the server receives, and
4066
4089
  * waits for the JSON-decoded reply.
@@ -4083,5 +4106,5 @@ declare class NovaNatsClient {
4083
4106
  publish<K extends NatsPublishSubject>(subject: K, params: NatsOperationParams[K], payload: NatsPublishPayloads[K]): Promise<void>;
4084
4107
  }
4085
4108
  //#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 };
4109
+ 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
4110
  //# 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;;;;;;;KAO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rC,kCAAkC;;;;;;;;;;EAUlC,uCAAuC;;;;;;;;;;EAUvC,uCAAuC;;;;;;;;;;EAUvC,uCAAuC;;;;;;;;;;EAUvC,kDAAkD;;;;;;;;;;EAUlD,kDAAkD;;;;;;;;;;EAUlD,kDAAkD;;;;;;;;;;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,mB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,QAAQ,oBAAoB,IAC5B,SAAS,oBAAoB,IAC7B;IAAQ;MACP,QAAQ,kBAAkB;;;;;;;;;EAiBvB,QAAQ,UAAU,oBACtB,SAAS,GACT,QAAQ,oBAAoB,IAC5B,SAAS,oBAAoB,KAC5B"}
@@ -117,7 +117,9 @@ 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. The promise of its
121
+ * `closed()` resolves when the subscription has ended (see
122
+ * {@link NatsSubscription}).
121
123
  */
122
124
  async subscribe(subject, ...args) {
123
125
  const [params, handler, options] = typeof args[0] === "function" ? [
@@ -133,31 +135,30 @@ var NovaNatsClient = class {
133
135
  const resolvedSubject = buildSubject(subject, params);
134
136
  const paramPositions = [];
135
137
  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
- };
138
+ const dispatch = (messages) => (async () => {
139
+ for await (const msg of messages) try {
140
+ const subjectTokens = msg.subject.split(".");
141
+ const subjectParams = Object.fromEntries(paramPositions.map(([name, index]) => [name, subjectTokens[index] ?? ""]));
142
+ await handler(msg.json(), Object.assign(msg, { subjectParams }));
143
+ } catch (err) {
144
+ console.error(`Error handling NATS message on subject "${resolvedSubject}"`, err);
145
+ }
146
+ })().catch((err) => {
147
+ console.error(`NATS subscription iterator failed for "${resolvedSubject}"`, err);
148
+ return err instanceof Error ? err : new Error(String(err));
149
+ });
149
150
  if (options?.lastMessage) {
150
151
  const streamName = await (await jetstreamManager(nc)).streams.find(resolvedSubject);
151
152
  const messages = await (await jetstream(nc).consumers.get(streamName, {
152
153
  filter_subjects: resolvedSubject,
153
154
  deliver_policy: DeliverPolicy.LastPerSubject
154
155
  })).consume();
155
- dispatch(messages);
156
- return () => void messages.close();
156
+ const closed = dispatch(messages);
157
+ return Object.assign(() => void messages.close(), { closed: () => closed });
157
158
  }
158
159
  const sub = nc.subscribe(resolvedSubject);
159
- dispatch(sub);
160
- return () => sub.unsubscribe();
160
+ const closed = dispatch(sub);
161
+ return Object.assign(() => sub.unsubscribe(), { closed: () => closed });
161
162
  }
162
163
  /**
163
164
  * 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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3B,QAAQ,MACN,0CAA0C,gBAAgB,IAC1D,GACF;GACF,CAAC;EACH;EAEA,IAAI,SAAS,aAAa;GAQxB,MAAM,aAAa,OAAM,MAHP,iBAAiB,EAAE,EAAA,CAGR,QAAQ,KAAK,eAAe;GASzD,MAAM,WAAW,OAAM,MARA,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,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 method `closed()`, whose promise resolves when the subscription has\n * ended. After that, the subscription receives no more messages; subscribe\n * again to receive them.\n *\n * The promise resolves with `undefined` when the subscription ended without\n * an 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 *\n * The promise resolves only after the handler has finished with the last\n * message, so the handler is never called after that. While a handler still\n * runs, the promise waits for it, as `closed` of a nats.js subscription waits\n * for the code that iterates its messages. So a handler must not wait for\n * `closed()` of its own subscription.\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. The promise of its\n * `closed()` resolves when the subscription has ended (see\n * {@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 const closed = dispatch(messages)\n return Object.assign(() => void messages.close(), {\n closed: () => closed,\n })\n }\n\n const sub = nc.subscribe(resolvedSubject)\n const closed = dispatch(sub)\n return Object.assign(() => sub.unsubscribe(), { closed: () => closed })\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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A,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,YAAY;IAK7D,iBAAiB;IACjB,gBAAgB,cAAc;GAChC,CAAC,EAAA,CAC+B,QAAQ;GACxC,MAAM,SAAS,SAAS,QAAQ;GAChC,OAAO,OAAO,aAAa,KAAK,SAAS,MAAM,GAAG,EAChD,cAAc,OAChB,CAAC;EACH;EAEA,MAAM,MAAM,GAAG,UAAU,eAAe;EACxC,MAAM,SAAS,SAAS,GAAG;EAC3B,OAAO,OAAO,aAAa,IAAI,YAAY,GAAG,EAAE,cAAc,OAAO,CAAC;CACxE;;;;;;;;;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"}
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.606c434",
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,28 @@ 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 method `closed()`, whose promise resolves when the subscription has
69
+ * ended. After that, the subscription receives no more messages; subscribe
70
+ * again to receive them.
71
+ *
72
+ * The promise resolves with `undefined` when the subscription ended without
73
+ * an 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
+ * The promise resolves only after the handler has finished with the last
79
+ * message, so the handler is never called after that. While a handler still
80
+ * runs, the promise waits for it, as `closed` of a nats.js subscription waits
81
+ * for the code that iterates its messages. So a handler must not wait for
82
+ * `closed()` of its own subscription.
83
+ */
84
+ export type NatsSubscription = (() => void) & {
85
+ closed(): Promise<Error | undefined>
86
+ }
87
+
66
88
  type NatsMessageHandler<K extends NatsSubscribeSubject> = (
67
89
  payload: NatsSubscribePayloads[K],
68
90
  msg: NatsSubscribeMsg<K>,
@@ -150,12 +172,14 @@ export class NovaNatsClient {
150
172
  * message persisted for each matching subject is replayed to the handler
151
173
  * immediately, before live messages (see {@link NatsSubscribeOptions}).
152
174
  *
153
- * Returns a function that unsubscribes when called.
175
+ * Returns a function that unsubscribes when called. The promise of its
176
+ * `closed()` resolves when the subscription has ended (see
177
+ * {@link NatsSubscription}).
154
178
  */
155
179
  async subscribe<K extends NatsSubscribeSubject>(
156
180
  subject: K,
157
181
  ...args: SubscribeArgs<K>
158
- ): Promise<() => void> {
182
+ ): Promise<NatsSubscription> {
159
183
  const [params, handler, options] =
160
184
  typeof args[0] === "function"
161
185
  ? ([{}, args[0], args[1] as NatsSubscribeOptions | undefined] as const)
@@ -175,8 +199,12 @@ export class NovaNatsClient {
175
199
  }
176
200
  }
177
201
 
178
- const dispatch = (messages: AsyncIterable<NatsReceivedMsg>) => {
179
- ;(async () => {
202
+ // Resolves when the messages end: with `undefined` when they end without
203
+ // an error, else with the error
204
+ const dispatch = (
205
+ messages: AsyncIterable<NatsReceivedMsg>,
206
+ ): Promise<Error | undefined> =>
207
+ (async () => {
180
208
  for await (const msg of messages) {
181
209
  // Handled per-message: a bad payload or a throwing/rejecting
182
210
  // handler should not stop the subscription from processing later
@@ -200,13 +228,14 @@ export class NovaNatsClient {
200
228
  )
201
229
  }
202
230
  }
231
+ return undefined
203
232
  })().catch((err: unknown) => {
204
233
  console.error(
205
234
  `NATS subscription iterator failed for "${resolvedSubject}"`,
206
235
  err,
207
236
  )
237
+ return err instanceof Error ? err : new Error(String(err))
208
238
  })
209
- }
210
239
 
211
240
  if (options?.lastMessage) {
212
241
  // Delivered through JetStream instead of a core subscription: an
@@ -226,13 +255,15 @@ export class NovaNatsClient {
226
255
  deliver_policy: DeliverPolicy.LastPerSubject,
227
256
  })
228
257
  const messages = await consumer.consume()
229
- dispatch(messages)
230
- return () => void messages.close()
258
+ const closed = dispatch(messages)
259
+ return Object.assign(() => void messages.close(), {
260
+ closed: () => closed,
261
+ })
231
262
  }
232
263
 
233
264
  const sub = nc.subscribe(resolvedSubject)
234
- dispatch(sub)
235
- return () => sub.unsubscribe()
265
+ const closed = dispatch(sub)
266
+ return Object.assign(() => sub.unsubscribe(), { closed: () => closed })
236
267
  }
237
268
 
238
269
  /**