@crvouga/mockingbird-runtime 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -2
- package/dist/adapter-node.d.ts +2521 -0
- package/dist/adapter-node.js +6920 -0
- package/dist/adapter-node.js.map +7 -0
- package/dist/admin-ui.js +25 -0
- package/dist/admin-ui.js.map +7 -0
- package/dist/chunk-2KDYLZXC.js +118 -0
- package/dist/chunk-2KDYLZXC.js.map +7 -0
- package/dist/chunk-2Y25NPCV.js +1289 -0
- package/dist/chunk-2Y25NPCV.js.map +7 -0
- package/dist/chunk-4SAK6MQT.js +246 -0
- package/dist/chunk-4SAK6MQT.js.map +7 -0
- package/dist/chunk-ANCCZFF2.js +778 -0
- package/dist/chunk-ANCCZFF2.js.map +7 -0
- package/dist/chunk-EBGYPQPA.js +198 -0
- package/dist/chunk-EBGYPQPA.js.map +7 -0
- package/dist/chunk-EQLY2YOA.js +274 -0
- package/dist/chunk-EQLY2YOA.js.map +7 -0
- package/dist/chunk-G62YDIIJ.js +7664 -0
- package/dist/chunk-G62YDIIJ.js.map +7 -0
- package/dist/chunk-HU6IOAFC.js +437 -0
- package/dist/chunk-HU6IOAFC.js.map +7 -0
- package/dist/chunk-RNAHPNUJ.js +97 -0
- package/dist/chunk-RNAHPNUJ.js.map +7 -0
- package/dist/chunk-UP4QOSFD.js +87 -0
- package/dist/chunk-UP4QOSFD.js.map +7 -0
- package/dist/chunk-XNS34BPF.js +2489 -0
- package/dist/chunk-XNS34BPF.js.map +7 -0
- package/dist/core.d.ts +356 -0
- package/dist/core.js +51 -0
- package/dist/core.js.map +7 -0
- package/dist/crypto-XS5XCMRJ.js +21 -0
- package/dist/crypto-XS5XCMRJ.js.map +7 -0
- package/dist/helpers-UD7CG4WQ.js +18 -0
- package/dist/helpers-UD7CG4WQ.js.map +7 -0
- package/dist/http-codec.d.ts +72 -0
- package/dist/http-codec.js +25 -0
- package/dist/http-codec.js.map +7 -0
- package/dist/http-provider.d.ts +3243 -0
- package/dist/http-provider.js +37920 -0
- package/dist/http-provider.js.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +7 -0
- package/dist/mqtt-broker/node.d.ts +632 -0
- package/dist/mqtt-broker/node.js +355 -0
- package/dist/mqtt-broker/node.js.map +7 -0
- package/dist/mqtt-broker.d.ts +990 -0
- package/dist/mqtt-broker.js +913 -0
- package/dist/mqtt-broker.js.map +7 -0
- package/dist/openapi-metadata.d.ts +290 -0
- package/dist/openapi-metadata.js +28 -0
- package/dist/openapi-metadata.js.map +7 -0
- package/dist/openapi.d.ts +252 -0
- package/dist/openapi.js +45 -0
- package/dist/openapi.js.map +7 -0
- package/dist/preview/artifacts.d.ts +19 -0
- package/dist/preview/artifacts.js +40 -0
- package/dist/preview/artifacts.js.map +7 -0
- package/dist/preview/bridge.d.ts +21 -0
- package/dist/preview/bridge.js +9 -0
- package/dist/preview/bridge.js.map +7 -0
- package/dist/preview/harness.d.ts +12 -0
- package/dist/preview/harness.js +65 -0
- package/dist/preview/harness.js.map +7 -0
- package/dist/preview/host.d.ts +30 -0
- package/dist/preview/host.js +70 -0
- package/dist/preview/host.js.map +7 -0
- package/dist/service/admin.d.ts +106 -0
- package/dist/service/admin.js +340 -0
- package/dist/service/admin.js.map +7 -0
- package/dist/service.d.ts +2665 -0
- package/dist/service.js +264 -0
- package/dist/service.js.map +7 -0
- package/dist/sqlite.d.ts +69 -0
- package/dist/sqlite.js +19 -0
- package/dist/sqlite.js.map +7 -0
- package/dist/ui.d.ts +37 -0
- package/dist/ui.js +702 -0
- package/dist/ui.js.map +7 -0
- package/package.json +135 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../mqtt/broker/src/topics.ts", "../../mqtt/broker/src/broker.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Topic Names and Topic Filters (MQTT 5.0 section 4.7).\n * https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901241\n */\n\nconst encoder = new TextEncoder()\n\n/** UTF-8 length, which is what every MQTT string limit counts. */\nexport const utf8Length = (value: string): number => encoder.encode(value).length\n\n/** 4.7.3: at least one character, no null character, at most 65,535 UTF-8 bytes. */\nconst wellFormed = (value: string): boolean =>\n value.length > 0 && !value.includes(\"\\u0000\") && utf8Length(value) <= 0xffff\n\n/** A Topic Name a PUBLISH may carry: well formed and free of wildcard characters (4.7.1). */\nexport const isValidTopicName = (topic: string): boolean =>\n wellFormed(topic) && !topic.includes(\"+\") && !topic.includes(\"#\")\n\n/**\n * A Topic Filter a SUBSCRIBE may carry: `#` only as the whole last level, `+` only as a whole\n * level (4.7.1.2, 4.7.1.3).\n */\nexport const isValidTopicFilter = (filter: string): boolean => {\n if (!wellFormed(filter)) return false\n const levels = filter.split(\"/\")\n return levels.every((level, index) => {\n if (level === \"#\") return index === levels.length - 1\n if (level === \"+\") return true\n return !level.includes(\"#\") && !level.includes(\"+\")\n })\n}\n\n/** `$share/{ShareName}/{filter}` (4.8.2). */\nexport const isSharedSubscription = (filter: string): boolean => filter.startsWith(\"$share/\")\n\n/**\n * Whether `filter` matches `topic`. `topic` is compared level by level as literal text, so a\n * caller may also ask whether one filter covers another's exact spelling.\n *\n * 4.7.2: a filter starting with a wildcard does not match a Topic Name starting with `$`.\n * 4.7.1.2: `sport/#` also matches `sport`; a vendor that excludes the parent level passes\n * `parentLevel: false`.\n */\nexport const topicMatches = (\n filter: string,\n topic: string,\n options: { parentLevel?: boolean } = {},\n): boolean => {\n const first = filter[0]\n if (topic.startsWith(\"$\") && (first === \"+\" || first === \"#\")) return false\n const filterLevels = filter.split(\"/\")\n const topicLevels = topic.split(\"/\")\n for (let index = 0; index < filterLevels.length; index++) {\n const level = filterLevels[index]\n if (level === \"#\") return index < topicLevels.length || options.parentLevel !== false\n if (index >= topicLevels.length) return false\n if (level !== \"+\" && level !== topicLevels[index]) return false\n }\n return filterLevels.length === topicLevels.length\n}\n", "/**\n * The MQTT 5 broker engine: sessions, subscriptions, QoS 1 flows, offline queues and expiry.\n *\n * It is transport-free and timer-free. Bytes arrive through {@link Connection.receive} and\n * leave through a {@link Transport}; time is whatever `now()` returns, and everything that\n * depends on it (session expiry, connection expiry) is settled by {@link Broker.sweep}, which\n * every entry point runs first. A suite therefore moves a virtual clock instead of sleeping.\n *\n * Everything durable lives in `Collection`s, so reset and Timeline checkpoints cover it. Only\n * the live connections are held in memory.\n *\n * What a vendor decides differently (who may connect, which topics, limits, reason codes for\n * a refusal) comes in through {@link BrokerPolicy}.\n */\nimport { Collection, fromBase64, IdSequence, toBase64 } from \"@crvouga/mockingbird-service\"\nimport type { SqliteClient } from \"@crvouga/mockingbird-sqlite\"\nimport {\n type ConnectPacket,\n type DisconnectPacket,\n encodePacket,\n LEGACY_UNSUPPORTED_VERSION_CONNACK,\n type Packet,\n PacketReader,\n type Properties,\n type PublishPacket,\n type QoS,\n type SubscribePacket,\n type UnsubscribePacket,\n} from \"./codec.js\"\nimport { ReasonCode } from \"./reason.js\"\nimport {\n isSharedSubscription,\n isValidTopicFilter,\n isValidTopicName,\n topicMatches,\n} from \"./topics.js\"\n\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\n/** The byte pipe to one client. A listener implements it over a socket. */\nexport type Transport = {\n send(bytes: Uint8Array): void\n /** Flush what was sent, then close: the peer sees an orderly end. */\n close(): void\n /** Drop the connection at once, as a network failure does. */\n destroy(): void\n}\n\n/** How a client reached the broker, for a policy that reads it. */\nexport type TransportInfo = {\n kind: \"tcp\" | \"websocket\" | \"memory\"\n /** Request path of a WebSocket upgrade. */\n path?: string\n}\n\n/** What a listener feeds: the other half of a {@link Transport}. */\nexport type Connection = {\n receive(chunk: Uint8Array): void\n /** The transport is gone: the peer closed it or the network failed. */\n closed(): void\n}\n\nexport type ConnectRequest = {\n clientId: string\n /** True when the client sent an empty identifier and `clientId` was assigned. */\n assigned: boolean\n username: string | undefined\n password: Uint8Array | undefined\n cleanStart: boolean\n keepAlive: number\n properties: Properties\n transport: TransportInfo\n}\n\nexport type ConnectDecision =\n | {\n ok: true\n /** Kept with the session and handed back to {@link BrokerPolicy.authorize}. */\n principal?: JsonValue\n /** Epoch ms after which the server drops the connection (a token's expiry). */\n connectionExpiresAt?: number\n }\n | { ok: false; reasonCode: number }\n\nexport type AuthorizeRequest = {\n /** `receive` is asked once per delivery, for vendors that authorize it separately. */\n action: \"publish\" | \"subscribe\" | \"receive\"\n /** The Topic Name, or the Topic Filter for `subscribe`. */\n topic: string\n qos: QoS\n retain: boolean\n clientId: string\n username: string | null\n principal: JsonValue | null\n}\n\n/** Where one vendor's broker differs from another's. Every member is read at use time. */\nexport type BrokerPolicy = {\n authenticate(request: ConnectRequest): ConnectDecision | Promise<ConnectDecision>\n authorize(request: AuthorizeRequest): boolean\n /** What a denied PUBLISH or SUBSCRIBE does: answer `Not authorized`, or also disconnect. */\n denyAction(): \"ignore\" | \"disconnect\"\n /** A reason code refuses a CONNECT for its client identifier. */\n checkClientId?(clientId: string): number | undefined\n /** The identifier assigned to a client that sent none, from a deterministic 16-character token. */\n assignClientId(token: string): string\n /** A reason code rejects a well-formed Topic Name the vendor does not accept. */\n checkTopicName?(topic: string): number | undefined\n /** A reason code rejects a well-formed Topic Filter the vendor does not accept. */\n checkTopicFilter?(filter: string): number | undefined\n /** The Session Expiry Interval (seconds) granted for the one a client asked for. */\n sessionExpiry(requested: number): number\n /** The keep alive the server imposes, when it differs from the client's. */\n serverKeepAlive?(requested: number): number | undefined\n /**\n * Vendor values for the CONNACK: Maximum Packet Size, Topic Alias Maximum, Receive Maximum,\n * Wildcard Subscription Available, Subscription Identifier Available.\n */\n connackProperties(): Properties\n /** Largest PUBLISH payload accepted from a client; larger ones disconnect it. */\n maxPayloadBytes?: number\n /** QoS 1 messages in flight to one client at a time. */\n maxInflight: number\n /** What a session keeps while its client is away. */\n queue: { storeQos0: boolean; maxLength?: number }\n /** PUBACK reason code for a publish no subscription matched. */\n pubackNoMatchingSubscribers: number\n /** A SUBSCRIBE asking for QoS 2: grant QoS 1, or send no SUBACK at all. */\n qos2Subscribe: \"downgrade\" | \"ignore\"\n /** Whether `a/#` matches `a` (MQTT 5.0 4.7.1.2 says it does). */\n multiLevelWildcardMatchesParent: boolean\n /** DISCONNECT reason code when `connectionExpiresAt` passes. */\n connectionExpiredReason: number\n}\n\n/** Never expires (3.1.2.11.2). */\nexport const SESSION_NEVER_EXPIRES = 0xffffffff\n\nexport type SessionRecord = {\n clientId: string\n username: string | null\n principal: JsonValue | null\n /** Seconds the session outlives its connection. */\n sessionExpiryInterval: number\n createdAt: number\n connectedAt: number\n /** `null` while a connection holds the session. */\n disconnectedAt: number | null\n /** Epoch ms the session is discarded at; `null` while connected, or when it never expires. */\n expiresAt: number | null\n connectionExpiresAt: number | null\n /** The live connection holding the session; a stale id marks a connection lost to a restore. */\n connectionId: string | null\n receiveMaximum: number\n maximumPacketSize: number | null\n transport: TransportInfo[\"kind\"]\n}\n\nexport type SubscriptionRecord = {\n clientId: string\n topicFilter: string\n /** Granted QoS. */\n qos: 0 | 1\n noLocal: boolean\n retainAsPublished: boolean\n retainHandling: number\n subscriptionIdentifier: number | null\n}\n\n/** Application message properties a broker forwards unaltered (3.3.2.3). */\ntype ForwardedProperties = {\n payloadFormatIndicator?: number\n messageExpiryInterval?: number\n contentType?: string\n responseTopic?: string\n /** base64. */\n correlationData?: string\n userProperties?: [string, string][]\n}\n\nexport type QueuedMessage = {\n clientId: string\n topic: string\n /** base64. */\n payload: string\n qos: 0 | 1\n properties: ForwardedProperties\n subscriptionIdentifiers: number[]\n /** `inflight` once sent at QoS 1 and not yet acknowledged. */\n state: \"queued\" | \"inflight\"\n packetId: number | null\n enqueuedAt: number\n}\n\n/** Who published. */\nexport type PublishSource = \"mqtt\" | \"http\" | \"admin\"\n\n/** One publish as the log keeps it: metadata only, never the payload. */\nexport type PublishRecord = {\n /** 1 for the first publish since the last reset, counting ones the log has dropped. */\n sequence: number\n topic: string\n qos: QoS\n bytes: number\n source: PublishSource\n /** The publishing client, for `mqtt`. */\n clientId: string | null\n /** Sessions the message was delivered or queued to. */\n matched: number\n at: string\n}\n\nexport type TransportCut = { target: string; since: number }\n\nexport type ClientInfo = {\n clientId: string\n username: string | null\n connected: boolean\n transport: TransportInfo[\"kind\"]\n sessionExpiryInterval: number\n connectedAt: string\n disconnectedAt: string | null\n expiresAt: string | null\n subscriptions: number\n queued: number\n inflight: number\n}\n\nexport type PublishInput = {\n topic: string\n payload: Uint8Array\n qos: QoS\n properties?: Properties\n}\n\nexport type BrokerOptions = {\n sqlite: SqliteClient\n /** Storage namespace; brokers with different namespaces share nothing. */\n namespace: string\n now: () => number\n policy: BrokerPolicy\n}\n\n/** Most publishes the metadata log keeps; older rows are dropped. */\nexport const PUBLISH_LOG_SIZE = 1000\n\nconst EVERY_CLIENT = \"*\"\n\nconst subscriptionKey = (clientId: string, topicFilter: string): string =>\n JSON.stringify([clientId, topicFilter])\n\nconst forwarded = (properties: Properties): ForwardedProperties => ({\n ...(properties.payloadFormatIndicator !== undefined\n ? { payloadFormatIndicator: properties.payloadFormatIndicator }\n : {}),\n ...(properties.messageExpiryInterval !== undefined\n ? { messageExpiryInterval: properties.messageExpiryInterval }\n : {}),\n ...(properties.contentType !== undefined ? { contentType: properties.contentType } : {}),\n ...(properties.responseTopic !== undefined ? { responseTopic: properties.responseTopic } : {}),\n ...(properties.correlationData !== undefined\n ? { correlationData: toBase64(properties.correlationData) }\n : {}),\n ...(properties.userProperties !== undefined && properties.userProperties.length > 0\n ? { userProperties: properties.userProperties }\n : {}),\n})\n\nconst restored = (properties: ForwardedProperties, identifiers: number[]): Properties => {\n const { correlationData, ...rest } = properties\n return {\n ...rest,\n ...(correlationData !== undefined ? { correlationData: fromBase64(correlationData) } : {}),\n ...(identifiers.length > 0 ? { subscriptionIdentifiers: identifiers } : {}),\n }\n}\n\ntype ConnectionState = \"connecting\" | \"authenticating\" | \"open\" | \"closed\"\n\nclass BrokerConnection implements Connection {\n state: ConnectionState = \"connecting\"\n clientId = \"\"\n readonly aliases = new Map<number, string>()\n readonly backlog: Packet[] = []\n private readonly reader: PacketReader\n private lastPacketId = 0\n\n constructor(\n readonly id: string,\n readonly transport: Transport,\n readonly info: TransportInfo,\n private readonly broker: Broker,\n maxPacketSize: number | undefined,\n ) {\n this.reader = new PacketReader(maxPacketSize)\n }\n\n /** Read through a getter so a handler closing the connection mid-loop is seen. */\n private get gone(): boolean {\n return this.state === \"closed\"\n }\n\n receive(chunk: Uint8Array): void {\n if (this.gone) return\n const { packets, error } = this.reader.push(chunk)\n for (const packet of packets) {\n if (this.gone) return\n this.broker.accept(this, packet)\n }\n if (error && !this.gone) this.broker.fail(this, error.reasonCode)\n }\n\n closed(): void {\n this.broker.detach(this)\n }\n\n send(packet: Packet): void {\n if (this.gone) return\n this.transport.send(encodePacket(packet))\n }\n\n /** The next Packet Identifier not in `used` (2.2.1). */\n nextPacketId(used: ReadonlySet<number>): number {\n for (let tries = 0; tries < 0xffff; tries++) {\n this.lastPacketId = this.lastPacketId >= 0xffff ? 1 : this.lastPacketId + 1\n if (!used.has(this.lastPacketId)) return this.lastPacketId\n }\n throw new RangeError(\"no free packet identifier\")\n }\n}\n\nexport class Broker {\n readonly sessions: Collection<SessionRecord>\n readonly subscriptions: Collection<SubscriptionRecord>\n readonly queue: Collection<QueuedMessage>\n readonly publishes: Collection<PublishRecord>\n readonly cuts: Collection<TransportCut>\n readonly counters: Collection<{ value: number }>\n private readonly ids: IdSequence\n private readonly now: () => number\n private readonly policy: BrokerPolicy\n /** Connections holding a session, by client identifier. */\n private readonly live = new Map<string, BrokerConnection>()\n /** Every transport not yet closed, including ones still before their CONNACK. */\n private readonly open = new Set<BrokerConnection>()\n private connectionCount = 0\n private sweeping = false\n\n constructor(options: BrokerOptions) {\n const { sqlite, namespace } = options\n this.sessions = new Collection(sqlite, namespace, \"mqtt_sessions\")\n this.subscriptions = new Collection(sqlite, namespace, \"mqtt_subscriptions\")\n this.queue = new Collection(sqlite, namespace, \"mqtt_queue\")\n this.publishes = new Collection(sqlite, namespace, \"mqtt_publishes\")\n this.cuts = new Collection(sqlite, namespace, \"mqtt_transport_cuts\")\n this.counters = new Collection(sqlite, namespace, \"mqtt_counters\")\n this.ids = new IdSequence(sqlite, namespace, \"mqtt\")\n this.now = options.now\n this.policy = options.policy\n }\n\n // \u2500\u2500 transports \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n /** Attach a new client transport. Feed the returned {@link Connection} what it receives. */\n connect(transport: Transport, info: TransportInfo = { kind: \"memory\" }): Connection {\n this.connectionCount += 1\n const connection = new BrokerConnection(\n `c${this.connectionCount}`,\n transport,\n info,\n this,\n this.policy.connackProperties().maximumPacketSize,\n )\n this.open.add(connection)\n return connection\n }\n\n /** Open transports right now, including ones that have not sent CONNECT. */\n get connections(): number {\n return this.open.size\n }\n\n /**\n * Drop every transport without touching stored sessions: the process is going away, or the\n * stored state is about to be replaced. A session whose connection vanished this way starts\n * its expiry at the next {@link sweep}.\n */\n dropConnections(): void {\n for (const connection of [...this.open]) {\n connection.state = \"closed\"\n connection.transport.destroy()\n }\n this.open.clear()\n this.live.clear()\n }\n\n // \u2500\u2500 time \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n /**\n * Settle everything the clock decides: discard expired sessions, start the expiry of\n * sessions whose connection was lost, and drop connections whose credential expired.\n */\n sweep(): void {\n if (this.sweeping) return\n this.sweeping = true\n try {\n const now = this.now()\n for (const { value: session } of this.sessions.list({ order: \"oldest\" })) {\n const connection = this.live.get(session.clientId)\n if (connection && connection.id === session.connectionId) {\n if (session.connectionExpiresAt !== null && now >= session.connectionExpiresAt) {\n this.shutdown(connection, this.policy.connectionExpiredReason)\n }\n continue\n }\n if (session.disconnectedAt === null) {\n this.endConnection(session, now)\n continue\n }\n if (session.expiresAt !== null && now >= session.expiresAt) {\n this.destroySession(session.clientId)\n }\n }\n } finally {\n this.sweeping = false\n }\n }\n\n // \u2500\u2500 server-side operations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n /**\n * Publish from the server side (an HTTP API, an admin injection). Returns how many sessions\n * the message was delivered or queued to. No client ACL applies; `receive` authorization does.\n */\n publish(input: PublishInput, source: PublishSource = \"http\"): number {\n this.sweep()\n return this.route(input, source, null)\n }\n\n /**\n * End a client's session as an administrator does: disconnect it with `reasonCode` and\n * discard the session, its subscriptions and its queue. False when no such session exists.\n */\n kick(clientId: string, reasonCode: number = ReasonCode.AdministrativeAction): boolean {\n this.sweep()\n if (!this.sessions.has(clientId)) return false\n const connection = this.live.get(clientId)\n if (connection) this.shutdown(connection, reasonCode, true)\n this.destroySession(clientId)\n return true\n }\n\n /**\n * Send a connected client a DISCONNECT and close its connection. The session stays, under\n * its own expiry. False when the client is not connected.\n */\n disconnect(clientId: string, reasonCode: number = ReasonCode.AdministrativeAction): boolean {\n this.sweep()\n const connection = this.live.get(clientId)\n if (!connection) return false\n this.shutdown(connection, reasonCode)\n return true\n }\n\n /**\n * Cut the transport of one client, or of every client: live connections die without a\n * DISCONNECT and new CONNECTs are dropped unanswered until {@link restoreTransport}.\n * Sessions are left to their own expiry. Returns how many connections were dropped.\n */\n cutTransport(clientId?: string): number {\n this.sweep()\n const target = clientId ?? EVERY_CLIENT\n this.cuts.insert(target, { target, since: this.now() })\n let dropped = 0\n for (const connection of [...this.open]) {\n if (clientId !== undefined && connection.clientId !== clientId) continue\n connection.transport.destroy()\n this.detach(connection)\n dropped += 1\n }\n return dropped\n }\n\n /** Let one client, or with no argument every client, connect again. */\n restoreTransport(clientId?: string): void {\n if (clientId !== undefined) {\n this.cuts.delete(clientId)\n return\n }\n for (const row of this.cuts.list()) this.cuts.delete(row.id)\n }\n\n /** Targets currently cut: client identifiers, or `*` for every client. */\n transportCuts(): string[] {\n return this.cuts\n .list({ order: \"oldest\" })\n .map((row) => row.value.target)\n .sort()\n }\n\n clients(): ClientInfo[] {\n this.sweep()\n const subscriptions = this.subscriptions.list()\n const queue = this.queue.list()\n const iso = (value: number | null) => (value === null ? null : new Date(value).toISOString())\n return this.sessions.list({ order: \"oldest\" }).map(({ value: session }) => ({\n clientId: session.clientId,\n username: session.username,\n connected: this.live.has(session.clientId),\n transport: session.transport,\n sessionExpiryInterval: session.sessionExpiryInterval,\n connectedAt: new Date(session.connectedAt).toISOString(),\n disconnectedAt: iso(session.disconnectedAt),\n expiresAt: iso(session.expiresAt),\n subscriptions: subscriptions.filter((row) => row.value.clientId === session.clientId).length,\n queued: queue.filter(\n (row) => row.value.clientId === session.clientId && row.value.state === \"queued\",\n ).length,\n inflight: queue.filter(\n (row) => row.value.clientId === session.clientId && row.value.state === \"inflight\",\n ).length,\n }))\n }\n\n subscriptionList(clientId?: string): SubscriptionRecord[] {\n this.sweep()\n return this.subscriptions\n .list({\n order: \"oldest\",\n ...(clientId !== undefined ? { where: (row) => row.clientId === clientId } : {}),\n })\n .map((row) => row.value)\n }\n\n /** The last {@link PUBLISH_LOG_SIZE} publishes, oldest first. */\n publishLog(): PublishRecord[] {\n return this.publishes.list({ order: \"oldest\" }).map((row) => row.value)\n }\n\n /** Publishes since the last reset, including ones the log no longer holds. */\n publishCount(): number {\n return this.counters.get(\"publishes\")?.value ?? 0\n }\n\n // \u2500\u2500 packets \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n /** @internal Called by a connection for each decoded packet. */\n accept(connection: BrokerConnection, packet: Packet): void {\n if (connection.state === \"authenticating\") {\n connection.backlog.push(packet)\n return\n }\n if (connection.state === \"connecting\") {\n // 3.1: the first packet from a client must be CONNECT.\n if (packet.type !== \"connect\") {\n connection.transport.destroy()\n this.detach(connection)\n return\n }\n this.onConnect(connection, packet)\n return\n }\n if (connection.state !== \"open\") return\n this.sweep()\n if (!this.open.has(connection)) return\n switch (packet.type) {\n case \"publish\":\n this.onPublish(connection, packet)\n return\n case \"puback\":\n this.onPuback(connection, packet.packetId)\n return\n case \"subscribe\":\n this.onSubscribe(connection, packet)\n return\n case \"unsubscribe\":\n this.onUnsubscribe(connection, packet)\n return\n case \"pingreq\":\n connection.send({ type: \"pingresp\" })\n return\n case \"disconnect\":\n this.onDisconnect(connection, packet)\n return\n default:\n // A second CONNECT (3.1), a QoS 2 flow packet this broker never starts, AUTH without\n // extended authentication (3.15), or a packet only a server sends.\n this.fail(connection, ReasonCode.ProtocolError)\n }\n }\n\n /** @internal A protocol violation: answer with `reasonCode` and close. */\n fail(connection: BrokerConnection, reasonCode: number): void {\n if (connection.state === \"open\") {\n this.shutdown(connection, reasonCode)\n return\n }\n connection.transport.destroy()\n this.detach(connection)\n }\n\n /** @internal The transport is gone, or was just closed by the broker. */\n detach(connection: BrokerConnection, keepSession = false): void {\n if (connection.state === \"closed\") return\n const wasOpen = connection.state === \"open\"\n connection.state = \"closed\"\n this.open.delete(connection)\n if (!wasOpen || this.live.get(connection.clientId) !== connection) return\n this.live.delete(connection.clientId)\n if (keepSession) return\n const session = this.sessions.get(connection.clientId)\n if (session) this.endConnection(session, this.now())\n }\n\n /** The session's connection ended at `at`: discard it, or start its expiry (4.1). */\n private endConnection(session: SessionRecord, at: number): void {\n if (session.sessionExpiryInterval === 0) {\n this.destroySession(session.clientId)\n return\n }\n // Messages sent and not acknowledged stay in flight: they are resent on resume (4.4).\n this.sessions.update(session.clientId, {\n ...session,\n connectionId: null,\n connectionExpiresAt: null,\n disconnectedAt: at,\n expiresAt:\n session.sessionExpiryInterval === SESSION_NEVER_EXPIRES\n ? null\n : at + session.sessionExpiryInterval * 1000,\n })\n }\n\n private destroySession(clientId: string): void {\n this.sessions.delete(clientId)\n for (const row of this.subscriptions.list({ where: (each) => each.clientId === clientId })) {\n this.subscriptions.delete(row.id)\n }\n for (const row of this.queue.list({ where: (each) => each.clientId === clientId })) {\n this.queue.delete(row.id)\n }\n }\n\n /** Send DISCONNECT with `reasonCode`, close the transport, and settle the session. */\n private shutdown(connection: BrokerConnection, reasonCode: number, keepSession = false): void {\n connection.send({ type: \"disconnect\", reasonCode, properties: {} })\n connection.transport.close()\n this.detach(connection, keepSession)\n }\n\n private isCut(clientId: string): boolean {\n return this.cuts.has(EVERY_CLIENT) || this.cuts.has(clientId)\n }\n\n private onConnect(connection: BrokerConnection, packet: ConnectPacket): void {\n if (packet.protocolName !== \"MQTT\" || packet.protocolVersion !== 5) {\n // 3.1.2.2: a server that does not accept the protocol level may say so, then must close.\n // MQTT 3.1 / 3.1.1 clients get the CONNACK their own protocol defines for that.\n if (packet.protocolVersion === 3 || packet.protocolVersion === 4) {\n connection.transport.send(LEGACY_UNSUPPORTED_VERSION_CONNACK)\n }\n connection.transport.close()\n this.detach(connection)\n return\n }\n const assigned = packet.clientId === \"\"\n const clientId = assigned ? this.policy.assignClientId(this.ids.next(\"\", 16)) : packet.clientId\n connection.clientId = clientId\n if (this.isCut(clientId)) {\n connection.transport.destroy()\n this.detach(connection)\n return\n }\n const refuse = (reasonCode: number) => {\n if (connection.state === \"closed\") return\n connection.send({ type: \"connack\", sessionPresent: false, reasonCode, properties: {} })\n connection.transport.close()\n this.detach(connection)\n }\n const invalid = this.policy.checkClientId?.(clientId)\n if (invalid !== undefined) {\n refuse(invalid)\n return\n }\n connection.state = \"authenticating\"\n const settle = (decision: ConnectDecision) => {\n if (connection.state !== \"authenticating\") return\n if (!decision.ok) {\n refuse(decision.reasonCode)\n return\n }\n this.openSession(connection, packet, clientId, assigned, decision)\n // Packets that arrived while the policy was deciding. `accept` drops them once closed.\n for (const queued of connection.backlog.splice(0)) this.accept(connection, queued)\n }\n let decision: ConnectDecision | Promise<ConnectDecision>\n try {\n decision = this.policy.authenticate({\n clientId,\n assigned,\n username: packet.username,\n password: packet.password,\n cleanStart: packet.cleanStart,\n keepAlive: packet.keepAlive,\n properties: packet.properties,\n transport: connection.info,\n })\n } catch {\n refuse(ReasonCode.UnspecifiedError)\n return\n }\n if (decision instanceof Promise) {\n decision.then(settle, () => refuse(ReasonCode.UnspecifiedError))\n } else settle(decision)\n }\n\n private openSession(\n connection: BrokerConnection,\n packet: ConnectPacket,\n clientId: string,\n assigned: boolean,\n decision: Extract<ConnectDecision, { ok: true }>,\n ): void {\n this.sweep()\n const now = this.now()\n // 3.1.4: a client identifier already connected is disconnected first. Its session is still\n // the live one, so the new connection resumes it unless it asked for a clean start.\n const previous = this.live.get(clientId)\n if (previous) this.shutdown(previous, ReasonCode.SessionTakenOver, true)\n const existing = this.sessions.get(clientId)\n const sessionPresent = existing !== undefined && !packet.cleanStart\n if (existing && !sessionPresent) this.destroySession(clientId)\n const requested = packet.properties.sessionExpiryInterval ?? 0\n const granted = this.policy.sessionExpiry(requested)\n const record: SessionRecord = {\n clientId,\n username: packet.username ?? null,\n principal: decision.principal ?? null,\n sessionExpiryInterval: granted,\n createdAt: sessionPresent ? existing.createdAt : now,\n connectedAt: now,\n disconnectedAt: null,\n expiresAt: null,\n connectionExpiresAt: decision.connectionExpiresAt ?? null,\n connectionId: connection.id,\n // 3.1.2.11.3: 65,535 when the client names no Receive Maximum.\n receiveMaximum: packet.properties.receiveMaximum ?? 0xffff,\n maximumPacketSize: packet.properties.maximumPacketSize ?? null,\n transport: connection.info.kind,\n }\n if (sessionPresent) this.sessions.update(clientId, record)\n else this.sessions.insert(clientId, record)\n this.live.set(clientId, connection)\n connection.state = \"open\"\n const keepAlive = this.policy.serverKeepAlive?.(packet.keepAlive)\n connection.send({\n type: \"connack\",\n sessionPresent,\n reasonCode: ReasonCode.Success,\n properties: {\n ...this.policy.connackProperties(),\n // What this broker does not do, said the way the protocol provides for (3.2.2.3).\n maximumQoS: 1,\n retainAvailable: 0,\n sharedSubscriptionAvailable: 0,\n ...(assigned ? { assignedClientIdentifier: clientId } : {}),\n ...(granted !== requested ? { sessionExpiryInterval: granted } : {}),\n ...(keepAlive !== undefined && keepAlive !== packet.keepAlive\n ? { serverKeepAlive: keepAlive }\n : {}),\n },\n })\n if (sessionPresent) this.resume(connection, record)\n }\n\n /** 4.4: resend what was sent and never acknowledged, then whatever queued up meanwhile. */\n private resume(connection: BrokerConnection, session: SessionRecord): void {\n const rows = this.queue.list({\n where: (each) => each.clientId === session.clientId && each.state === \"inflight\",\n order: \"oldest\",\n })\n for (const row of rows) {\n this.sendMessage(connection, session, row.id, row.value, row.value.packetId, true)\n }\n this.pump(session.clientId)\n }\n\n private onDisconnect(connection: BrokerConnection, packet: DisconnectPacket): void {\n const interval = packet.properties.sessionExpiryInterval\n const session = this.sessions.get(connection.clientId)\n if (interval !== undefined && session) {\n // 3.14.2.2.2: a session that began with interval 0 cannot be given one on DISCONNECT.\n if (session.sessionExpiryInterval === 0 && interval !== 0) {\n this.fail(connection, ReasonCode.ProtocolError)\n return\n }\n this.sessions.update(connection.clientId, {\n ...session,\n sessionExpiryInterval: this.policy.sessionExpiry(interval),\n })\n }\n connection.transport.close()\n this.detach(connection)\n }\n\n private onPublish(connection: BrokerConnection, packet: PublishPacket): void {\n // 3.3.4: a client must not send a Subscription Identifier.\n if (packet.properties.subscriptionIdentifiers !== undefined) {\n this.fail(connection, ReasonCode.ProtocolError)\n return\n }\n let topic = packet.topic\n const alias = packet.properties.topicAlias\n if (alias !== undefined) {\n // 3.3.2.3.4: 0, or a value above the server's Topic Alias Maximum, is not valid.\n const limit = this.policy.connackProperties().topicAliasMaximum ?? 0\n if (alias === 0 || alias > limit) {\n this.fail(connection, ReasonCode.TopicAliasInvalid)\n return\n }\n if (topic !== \"\") connection.aliases.set(alias, topic)\n else topic = connection.aliases.get(alias) ?? \"\"\n }\n if (topic === \"\") {\n this.fail(connection, ReasonCode.ProtocolError)\n return\n }\n // 3.2.2.3.4 / 3.2.2.3.5: above the advertised Maximum QoS, or RETAIN when Retain Available\n // is 0, is a Protocol Error answered with these reason codes.\n if (packet.qos === 2) {\n this.fail(connection, ReasonCode.QoSNotSupported)\n return\n }\n if (packet.retain) {\n this.fail(connection, ReasonCode.RetainNotSupported)\n return\n }\n if (!isValidTopicName(topic)) {\n this.fail(connection, ReasonCode.TopicNameInvalid)\n return\n }\n const limit = this.policy.maxPayloadBytes\n if (limit !== undefined && packet.payload.length > limit) {\n this.fail(connection, ReasonCode.PacketTooLarge)\n return\n }\n const acknowledge = (reasonCode: number) => {\n if (packet.qos === 1 && packet.packetId !== undefined) {\n connection.send({ type: \"puback\", packetId: packet.packetId, reasonCode, properties: {} })\n }\n }\n const rejected = this.policy.checkTopicName?.(topic)\n if (rejected !== undefined) {\n acknowledge(rejected)\n return\n }\n const session = this.sessions.get(connection.clientId)\n const allowed = this.policy.authorize({\n action: \"publish\",\n topic,\n qos: packet.qos,\n retain: packet.retain,\n clientId: connection.clientId,\n username: session?.username ?? null,\n principal: session?.principal ?? null,\n })\n if (!allowed) {\n if (this.policy.denyAction() === \"disconnect\") {\n this.fail(connection, ReasonCode.NotAuthorized)\n return\n }\n acknowledge(ReasonCode.NotAuthorized)\n return\n }\n const matched = this.route(\n { topic, payload: packet.payload, qos: packet.qos, properties: packet.properties },\n \"mqtt\",\n connection.clientId,\n )\n acknowledge(matched > 0 ? ReasonCode.Success : this.policy.pubackNoMatchingSubscribers)\n }\n\n private onPuback(connection: BrokerConnection, packetId: number): void {\n const row = this.queue\n .list({\n where: (each) =>\n each.clientId === connection.clientId &&\n each.state === \"inflight\" &&\n each.packetId === packetId,\n })\n .at(0)\n if (!row) return\n this.queue.delete(row.id)\n this.pump(connection.clientId)\n }\n\n private onSubscribe(connection: BrokerConnection, packet: SubscribePacket): void {\n const identifier = packet.properties.subscriptionIdentifiers?.[0]\n const identifiers = this.policy.connackProperties().subscriptionIdentifierAvailable ?? 1\n if (identifier !== undefined && identifiers === 0) {\n // 3.2.2.3.12: sent when the server said it does not support them.\n this.fail(connection, ReasonCode.SubscriptionIdentifiersNotSupported)\n return\n }\n if (\n this.policy.qos2Subscribe === \"ignore\" &&\n packet.subscriptions.some((each) => each.qos === 2)\n ) {\n return\n }\n const session = this.sessions.get(connection.clientId)\n const reasonCodes: number[] = []\n for (const each of packet.subscriptions) {\n if (isSharedSubscription(each.topicFilter)) {\n reasonCodes.push(ReasonCode.SharedSubscriptionsNotSupported)\n continue\n }\n if (!isValidTopicFilter(each.topicFilter)) {\n reasonCodes.push(ReasonCode.TopicFilterInvalid)\n continue\n }\n const rejected = this.policy.checkTopicFilter?.(each.topicFilter)\n if (rejected !== undefined) {\n reasonCodes.push(rejected)\n continue\n }\n const allowed = this.policy.authorize({\n action: \"subscribe\",\n topic: each.topicFilter,\n qos: each.qos,\n retain: false,\n clientId: connection.clientId,\n username: session?.username ?? null,\n principal: session?.principal ?? null,\n })\n if (!allowed) {\n if (this.policy.denyAction() === \"disconnect\") {\n this.fail(connection, ReasonCode.NotAuthorized)\n return\n }\n reasonCodes.push(ReasonCode.NotAuthorized)\n continue\n }\n // 3.9.3: the granted QoS may be lower than the one requested.\n const qos = each.qos === 0 ? 0 : 1\n this.subscriptions.insert(subscriptionKey(connection.clientId, each.topicFilter), {\n clientId: connection.clientId,\n topicFilter: each.topicFilter,\n qos,\n noLocal: each.noLocal,\n retainAsPublished: each.retainAsPublished,\n retainHandling: each.retainHandling,\n subscriptionIdentifier: identifier ?? null,\n })\n reasonCodes.push(qos)\n }\n connection.send({ type: \"suback\", packetId: packet.packetId, properties: {}, reasonCodes })\n }\n\n private onUnsubscribe(connection: BrokerConnection, packet: UnsubscribePacket): void {\n const reasonCodes = packet.topicFilters.map((filter) =>\n this.subscriptions.delete(subscriptionKey(connection.clientId, filter))\n ? ReasonCode.Success\n : ReasonCode.NoSubscriptionExisted,\n )\n connection.send({ type: \"unsuback\", packetId: packet.packetId, properties: {}, reasonCodes })\n }\n\n // \u2500\u2500 delivery \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n private route(input: PublishInput, source: PublishSource, publisher: string | null): number {\n const targets = new Map<string, { qos: 0 | 1; identifiers: number[] }>()\n for (const { value: subscription } of this.subscriptions.list({ order: \"oldest\" })) {\n if (subscription.noLocal && subscription.clientId === publisher) continue\n const matches = topicMatches(subscription.topicFilter, input.topic, {\n parentLevel: this.policy.multiLevelWildcardMatchesParent,\n })\n if (!matches) continue\n // 3.3.4: overlapping subscriptions of one client get one copy, at the highest of their\n // granted QoS, carrying every Subscription Identifier.\n const target = targets.get(subscription.clientId) ?? { qos: 0, identifiers: [] }\n if (subscription.qos === 1) target.qos = 1\n if (subscription.subscriptionIdentifier !== null) {\n target.identifiers.push(subscription.subscriptionIdentifier)\n }\n targets.set(subscription.clientId, target)\n }\n let matched = 0\n for (const [clientId, target] of targets) {\n const session = this.sessions.get(clientId)\n if (!session) continue\n const qos = input.qos === 0 ? 0 : target.qos\n const allowed = this.policy.authorize({\n action: \"receive\",\n topic: input.topic,\n qos,\n retain: false,\n clientId,\n username: session.username,\n principal: session.principal,\n })\n if (!allowed) continue\n matched += 1\n this.deliver(session, {\n clientId,\n topic: input.topic,\n payload: toBase64(input.payload),\n qos,\n properties: forwarded(input.properties ?? {}),\n subscriptionIdentifiers: target.identifiers,\n state: \"queued\",\n packetId: null,\n enqueuedAt: this.now(),\n })\n }\n this.record(input, source, publisher, matched)\n return matched\n }\n\n private deliver(session: SessionRecord, message: QueuedMessage): void {\n const connection = this.live.get(session.clientId)\n if (message.qos === 0) {\n if (connection) {\n this.sendMessage(connection, session, undefined, message, null, false)\n return\n }\n if (!this.policy.queue.storeQos0) return\n }\n this.queue.insert(String(this.queue.nextSequence()).padStart(12, \"0\"), message)\n const limit = this.policy.queue.maxLength\n if (limit !== undefined) {\n const waiting = this.queue.list({\n where: (each) => each.clientId === session.clientId && each.state === \"queued\",\n order: \"oldest\",\n })\n for (const row of waiting.slice(0, Math.max(0, waiting.length - limit))) {\n this.queue.delete(row.id)\n }\n }\n if (connection) this.pump(session.clientId)\n }\n\n /** Send as much of a client's queue as its Receive Maximum allows (4.9). */\n private pump(clientId: string): void {\n const connection = this.live.get(clientId)\n const session = this.sessions.get(clientId)\n if (!connection || !session) return\n const rows = this.queue.list({ where: (each) => each.clientId === clientId, order: \"oldest\" })\n const used = new Set<number>()\n for (const row of rows) {\n if (row.value.state === \"inflight\" && row.value.packetId !== null) {\n used.add(row.value.packetId)\n }\n }\n const window = Math.min(session.receiveMaximum, this.policy.maxInflight)\n for (const row of rows) {\n if (row.value.state !== \"queued\") continue\n if (row.value.qos === 0) {\n this.queue.delete(row.id)\n this.sendMessage(connection, session, undefined, row.value, null, false)\n continue\n }\n if (used.size >= window) break\n const packetId = connection.nextPacketId(used)\n used.add(packetId)\n const sending: QueuedMessage = { ...row.value, state: \"inflight\", packetId }\n this.queue.update(row.id, sending)\n this.sendMessage(connection, session, row.id, sending, packetId, false)\n }\n }\n\n private sendMessage(\n connection: BrokerConnection,\n session: SessionRecord,\n queueId: string | undefined,\n message: QueuedMessage,\n packetId: number | null,\n dup: boolean,\n ): void {\n const bytes = encodePacket({\n type: \"publish\",\n topic: message.topic,\n payload: fromBase64(message.payload),\n qos: message.qos,\n // 3.3.1.3: a message forwarded to an established subscription has RETAIN 0.\n retain: false,\n dup,\n ...(packetId !== null ? { packetId } : {}),\n properties: restored(message.properties, message.subscriptionIdentifiers),\n })\n // 3.1.2.11.4: a packet above the client's Maximum Packet Size is discarded unsent, and\n // treated as if the application message had been delivered.\n if (session.maximumPacketSize !== null && bytes.length > session.maximumPacketSize) {\n if (queueId !== undefined) this.queue.delete(queueId)\n return\n }\n if (connection.state === \"open\") connection.transport.send(bytes)\n }\n\n private record(\n input: PublishInput,\n source: PublishSource,\n publisher: string | null,\n matched: number,\n ): void {\n const sequence = this.publishCount() + 1\n this.counters.insert(\"publishes\", { value: sequence })\n this.publishes.insert(String(sequence).padStart(12, \"0\"), {\n sequence,\n topic: input.topic,\n qos: input.qos,\n bytes: input.payload.length,\n source,\n clientId: publisher,\n matched,\n at: new Date(this.now()).toISOString(),\n })\n this.publishes.delete(String(sequence - PUBLISH_LOG_SIZE).padStart(12, \"0\"))\n }\n}\n\n/**\n * Largest first packet {@link routeConnection} holds while it waits for a CONNECT. Every\n * length-prefixed CONNECT field at its 65,535-byte maximum fits with room to spare; a client\n * declaring more is dropped from its fixed header, before any of the body is buffered.\n */\nconst MAX_ROUTED_CONNECT_BYTES = 1024 * 1024\n\n/**\n * Hold a new transport until its CONNECT arrives, ask `select` which broker it belongs to\n * (a tenant chosen by username or client identifier), and attach it there. A transport whose\n * first packet is not a CONNECT, is larger than {@link MAX_ROUTED_CONNECT_BYTES}, or that\n * `select` turns away, is dropped.\n */\nexport const routeConnection = (\n transport: Transport,\n select: (connect: ConnectPacket) => Broker | undefined,\n info: TransportInfo = { kind: \"memory\" },\n): Connection => {\n // Bounds what is held before CONNECT: at most one packet of this size.\n const reader = new PacketReader(MAX_ROUTED_CONNECT_BYTES)\n const held: Uint8Array[] = []\n let attached: Connection | undefined\n let done = false\n return {\n receive(chunk) {\n if (attached) {\n attached.receive(chunk)\n return\n }\n if (done) return\n held.push(chunk)\n const { packets, error } = reader.push(chunk)\n const first = packets[0]\n if (!first && !error) return\n const broker = first?.type === \"connect\" ? select(first) : undefined\n if (!broker) {\n done = true\n transport.destroy()\n return\n }\n attached = broker.connect(transport, info)\n for (const each of held.splice(0)) attached.receive(each)\n },\n closed() {\n done = true\n attached?.closed()\n },\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,UAAU,IAAI,YAAW;AAGxB,IAAM,aAAa,CAAC,UAA0B,QAAQ,OAAO,KAAK,EAAE;AAG3E,IAAM,aAAa,CAAC,UAClB,MAAM,SAAS,KAAK,CAAC,MAAM,SAAS,IAAQ,KAAK,WAAW,KAAK,KAAK;AAGjE,IAAM,mBAAmB,CAAC,UAC/B,WAAW,KAAK,KAAK,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG;AAM3D,IAAM,qBAAqB,CAAC,WAA2B;AAC5D,MAAI,CAAC,WAAW,MAAM;AAAG,WAAO;AAChC,QAAM,SAAS,OAAO,MAAM,GAAG;AAC/B,SAAO,OAAO,MAAM,CAAC,OAAO,UAAS;AACnC,QAA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OAAO,KAAK,KAAK;AAC5C,YAAM,QAAQ,QAAQ,CAAC;AACvB,UAAI,CAAC,SAAS,CAAC;AAAO;AACtB,YAAM,SAAS,OAAO,SAAS,YAAY,OAAO,KAAK,IAAI;AAC3D,UAAI,CAAC,QAAQ;AACX,eAAO;AACP,kBAAU,QAAO;AACjB;MACF;AACA,iBAAW,OAAO,QAAQ,WAAW,IAAI;AACzC,iBAAW,QAAQ,KAAK,OAAO,CAAC;AAAG,iBAAS,QAAQ,IAAI;IAC1D;IACA,SAAM;AACJ,aAAO;AACP,gBAAU,OAAM;IAClB;;AAEJ;",
|
|
6
|
+
"names": ["decision", "limit"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Mockingbird understands.
|
|
3
|
+
* Unknown keys (including `x-*` extensions) are preserved on every object.
|
|
4
|
+
*/
|
|
5
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
6
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
};
|
|
9
|
+
type ReferenceObject = {
|
|
10
|
+
$ref: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
summary?: string;
|
|
13
|
+
};
|
|
14
|
+
type SchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
15
|
+
type SchemaObject = {
|
|
16
|
+
$ref?: string;
|
|
17
|
+
type?: SchemaType | SchemaType[];
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
format?: string;
|
|
21
|
+
enum?: JsonValue[];
|
|
22
|
+
const?: JsonValue;
|
|
23
|
+
default?: JsonValue;
|
|
24
|
+
example?: JsonValue;
|
|
25
|
+
examples?: JsonValue[];
|
|
26
|
+
nullable?: boolean;
|
|
27
|
+
deprecated?: boolean;
|
|
28
|
+
readOnly?: boolean;
|
|
29
|
+
writeOnly?: boolean;
|
|
30
|
+
minimum?: number;
|
|
31
|
+
maximum?: number;
|
|
32
|
+
exclusiveMinimum?: number;
|
|
33
|
+
exclusiveMaximum?: number;
|
|
34
|
+
multipleOf?: number;
|
|
35
|
+
minLength?: number;
|
|
36
|
+
maxLength?: number;
|
|
37
|
+
pattern?: string;
|
|
38
|
+
minItems?: number;
|
|
39
|
+
maxItems?: number;
|
|
40
|
+
uniqueItems?: boolean;
|
|
41
|
+
items?: SchemaObject;
|
|
42
|
+
prefixItems?: SchemaObject[];
|
|
43
|
+
minProperties?: number;
|
|
44
|
+
maxProperties?: number;
|
|
45
|
+
required?: string[];
|
|
46
|
+
properties?: Record<string, SchemaObject>;
|
|
47
|
+
additionalProperties?: boolean | SchemaObject;
|
|
48
|
+
propertyNames?: SchemaObject;
|
|
49
|
+
oneOf?: SchemaObject[];
|
|
50
|
+
anyOf?: SchemaObject[];
|
|
51
|
+
allOf?: SchemaObject[];
|
|
52
|
+
not?: SchemaObject;
|
|
53
|
+
discriminator?: {
|
|
54
|
+
propertyName: string;
|
|
55
|
+
mapping?: Record<string, string>;
|
|
56
|
+
};
|
|
57
|
+
[extension: `x-${string}`]: unknown;
|
|
58
|
+
};
|
|
59
|
+
type ParameterLocation = "path" | "query" | "header" | "cookie";
|
|
60
|
+
type ParameterObject = {
|
|
61
|
+
name: string;
|
|
62
|
+
in: ParameterLocation;
|
|
63
|
+
description?: string;
|
|
64
|
+
required?: boolean;
|
|
65
|
+
deprecated?: boolean;
|
|
66
|
+
style?: string;
|
|
67
|
+
explode?: boolean;
|
|
68
|
+
schema?: SchemaObject;
|
|
69
|
+
content?: Record<string, MediaTypeObject>;
|
|
70
|
+
example?: JsonValue;
|
|
71
|
+
[extension: `x-${string}`]: unknown;
|
|
72
|
+
};
|
|
73
|
+
type MediaTypeObject = {
|
|
74
|
+
schema?: SchemaObject;
|
|
75
|
+
example?: JsonValue;
|
|
76
|
+
examples?: Record<string, unknown>;
|
|
77
|
+
encoding?: Record<string, unknown>;
|
|
78
|
+
[extension: `x-${string}`]: unknown;
|
|
79
|
+
};
|
|
80
|
+
type RequestBodyObject = {
|
|
81
|
+
description?: string;
|
|
82
|
+
required?: boolean;
|
|
83
|
+
content: Record<string, MediaTypeObject>;
|
|
84
|
+
[extension: `x-${string}`]: unknown;
|
|
85
|
+
};
|
|
86
|
+
type HeaderObject = {
|
|
87
|
+
description?: string;
|
|
88
|
+
required?: boolean;
|
|
89
|
+
schema?: SchemaObject;
|
|
90
|
+
[extension: `x-${string}`]: unknown;
|
|
91
|
+
};
|
|
92
|
+
type ResponseObject = {
|
|
93
|
+
description: string;
|
|
94
|
+
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
95
|
+
content?: Record<string, MediaTypeObject>;
|
|
96
|
+
[extension: `x-${string}`]: unknown;
|
|
97
|
+
};
|
|
98
|
+
type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
|
|
99
|
+
type SecurityRequirementObject = Record<string, string[]>;
|
|
100
|
+
type OperationObject = {
|
|
101
|
+
operationId?: string;
|
|
102
|
+
summary?: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
tags?: string[];
|
|
105
|
+
deprecated?: boolean;
|
|
106
|
+
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
107
|
+
requestBody?: RequestBodyObject | ReferenceObject;
|
|
108
|
+
responses: ResponsesObject;
|
|
109
|
+
security?: SecurityRequirementObject[];
|
|
110
|
+
[extension: `x-${string}`]: unknown;
|
|
111
|
+
};
|
|
112
|
+
declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
113
|
+
type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
114
|
+
type PathItemObject = {
|
|
115
|
+
summary?: string;
|
|
116
|
+
description?: string;
|
|
117
|
+
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
118
|
+
[extension: `x-${string}`]: unknown;
|
|
119
|
+
} & Partial<Record<HttpMethod, OperationObject>>;
|
|
120
|
+
type SecuritySchemeObject = {
|
|
121
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
122
|
+
description?: string;
|
|
123
|
+
name?: string;
|
|
124
|
+
in?: ParameterLocation;
|
|
125
|
+
scheme?: string;
|
|
126
|
+
bearerFormat?: string;
|
|
127
|
+
flows?: Record<string, unknown>;
|
|
128
|
+
openIdConnectUrl?: string;
|
|
129
|
+
[extension: `x-${string}`]: unknown;
|
|
130
|
+
};
|
|
131
|
+
type ComponentsObject = {
|
|
132
|
+
schemas?: Record<string, SchemaObject>;
|
|
133
|
+
responses?: Record<string, ResponseObject>;
|
|
134
|
+
parameters?: Record<string, ParameterObject>;
|
|
135
|
+
requestBodies?: Record<string, RequestBodyObject>;
|
|
136
|
+
headers?: Record<string, HeaderObject>;
|
|
137
|
+
securitySchemes?: Record<string, SecuritySchemeObject>;
|
|
138
|
+
[extension: `x-${string}`]: unknown;
|
|
139
|
+
};
|
|
140
|
+
type ServerObject = {
|
|
141
|
+
url: string;
|
|
142
|
+
description?: string;
|
|
143
|
+
variables?: Record<string, unknown>;
|
|
144
|
+
[extension: `x-${string}`]: unknown;
|
|
145
|
+
};
|
|
146
|
+
type InfoObject = {
|
|
147
|
+
title: string;
|
|
148
|
+
version: string;
|
|
149
|
+
description?: string;
|
|
150
|
+
[extension: `x-${string}`]: unknown;
|
|
151
|
+
};
|
|
152
|
+
type OpenAPIDocument = {
|
|
153
|
+
openapi: string;
|
|
154
|
+
info: InfoObject;
|
|
155
|
+
servers?: ServerObject[];
|
|
156
|
+
paths: Record<string, PathItemObject>;
|
|
157
|
+
components?: ComponentsObject;
|
|
158
|
+
security?: SecurityRequirementObject[];
|
|
159
|
+
tags?: Array<{
|
|
160
|
+
name: string;
|
|
161
|
+
description?: string;
|
|
162
|
+
}>;
|
|
163
|
+
[extension: `x-${string}`]: unknown;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Mockingbird's OpenAPI extensions. They are deliberately generic: nothing here knows about any
|
|
168
|
+
* particular provider. Provider specifics live in each provider's `openapi.yaml`.
|
|
169
|
+
*/
|
|
170
|
+
/** `x-mockingbird` on an operation. */
|
|
171
|
+
type OperationExtension = {
|
|
172
|
+
/** Opt in to a terminal path parameter spanning slash-separated segments. */
|
|
173
|
+
path?: {
|
|
174
|
+
parameter: string;
|
|
175
|
+
allowEmpty?: boolean;
|
|
176
|
+
};
|
|
177
|
+
/** `false` marks an operation the mock explicitly does not implement. Default `true`. */
|
|
178
|
+
supported?: boolean;
|
|
179
|
+
/** Human explanation, required when `supported: false` or `parity.enabled: false`. */
|
|
180
|
+
reason?: string;
|
|
181
|
+
parity?: {
|
|
182
|
+
/** Whether the differential runner generates this operation. Defaults to `supported`. */
|
|
183
|
+
enabled?: boolean;
|
|
184
|
+
/** `false` for operations that must never hit a real account (destructive, billing…). Default `true`. */
|
|
185
|
+
safe?: boolean;
|
|
186
|
+
reason?: string;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
type OperationMetadata = {
|
|
190
|
+
path?: {
|
|
191
|
+
parameter: string;
|
|
192
|
+
allowEmpty?: boolean;
|
|
193
|
+
};
|
|
194
|
+
supported: boolean;
|
|
195
|
+
reason: string | undefined;
|
|
196
|
+
parity: {
|
|
197
|
+
enabled: boolean;
|
|
198
|
+
safe: boolean;
|
|
199
|
+
reason: string | undefined;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
/** `x-mockingbird-resource`: this string value is the identity of a resource. */
|
|
203
|
+
type ResourceIdentityExtension = {
|
|
204
|
+
type: string;
|
|
205
|
+
identity: true;
|
|
206
|
+
};
|
|
207
|
+
/** `x-mockingbird-resource-ref`: this value must reference an existing resource of `type`. */
|
|
208
|
+
type ResourceRefExtension = {
|
|
209
|
+
type: string;
|
|
210
|
+
/** A well-formed id that does not exist, used to exercise not-found behaviour. */
|
|
211
|
+
missing?: string;
|
|
212
|
+
};
|
|
213
|
+
declare const VOLATILE_KINDS: readonly ["id", "timestamp", "token", "url", "account", "opaque"];
|
|
214
|
+
type VolatileKind = (typeof VOLATILE_KINDS)[number];
|
|
215
|
+
/** `x-mockingbird-volatile`: nondeterministic on the real side; compared by shape only. */
|
|
216
|
+
type VolatileExtension = {
|
|
217
|
+
kind: VolatileKind;
|
|
218
|
+
};
|
|
219
|
+
declare const SCOPE_VALUES: readonly ["run-id", "walk-start-unix", "walk-start-iso"];
|
|
220
|
+
type ScopeValue = (typeof SCOPE_VALUES)[number];
|
|
221
|
+
/** `x-mockingbird-scope`: always generate this run-scoped value instead of a random one. */
|
|
222
|
+
type ScopeExtension = {
|
|
223
|
+
value: ScopeValue;
|
|
224
|
+
};
|
|
225
|
+
/** `x-mockingbird-unsupported`: the mock does not implement this parameter/property. */
|
|
226
|
+
type UnsupportedExtension = true | {
|
|
227
|
+
reason?: string;
|
|
228
|
+
};
|
|
229
|
+
type SchemaMetadata = {
|
|
230
|
+
resource: ResourceIdentityExtension | undefined;
|
|
231
|
+
resourceRef: ResourceRefExtension | undefined;
|
|
232
|
+
volatile: VolatileExtension | undefined;
|
|
233
|
+
scope: ScopeExtension | undefined;
|
|
234
|
+
unsupported: {
|
|
235
|
+
reason: string | undefined;
|
|
236
|
+
} | undefined;
|
|
237
|
+
};
|
|
238
|
+
declare const EXTENSION_KEYS: {
|
|
239
|
+
readonly operation: "x-mockingbird";
|
|
240
|
+
readonly resource: "x-mockingbird-resource";
|
|
241
|
+
readonly resourceRef: "x-mockingbird-resource-ref";
|
|
242
|
+
readonly volatile: "x-mockingbird-volatile";
|
|
243
|
+
readonly scope: "x-mockingbird-scope";
|
|
244
|
+
readonly unsupported: "x-mockingbird-unsupported";
|
|
245
|
+
readonly parityHeader: "x-mockingbird-parity-header";
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
type JsonPath = Array<string | number>;
|
|
249
|
+
type Annotation = {
|
|
250
|
+
kind: "identity";
|
|
251
|
+
path: JsonPath;
|
|
252
|
+
type: string;
|
|
253
|
+
} | {
|
|
254
|
+
kind: "volatile";
|
|
255
|
+
path: JsonPath;
|
|
256
|
+
volatile: VolatileKind;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Walk `value` guided by `schema` and report every identity / volatile location.
|
|
260
|
+
* Values with no schema coverage (unknown properties, unmatched union branches) yield nothing,
|
|
261
|
+
* which means they are compared strictly by the canonicalizer.
|
|
262
|
+
*/
|
|
263
|
+
declare const annotateValue: (document: OpenAPIDocument, schema: SchemaObject, value: unknown, path?: JsonPath) => Annotation[];
|
|
264
|
+
declare const pathKey: (path: JsonPath) => string;
|
|
265
|
+
|
|
266
|
+
/** Read `x-mockingbird` from an operation, applying defaults. */
|
|
267
|
+
declare const operationMetadata: (operation: OperationObject) => OperationMetadata;
|
|
268
|
+
/**
|
|
269
|
+
* Read Mockingbird's schema-level extensions from a (resolved) schema or parameter.
|
|
270
|
+
* Extensions on a `$ref` wrapper win over the target's, matching {@link resolveSchema}.
|
|
271
|
+
*/
|
|
272
|
+
declare const schemaMetadata: (holder: SchemaObject | ParameterObject) => SchemaMetadata;
|
|
273
|
+
/** Metadata of a parameter: extensions on the parameter itself win over its schema's. */
|
|
274
|
+
declare const parameterMetadata: (document: OpenAPIDocument, parameter: ParameterObject) => SchemaMetadata;
|
|
275
|
+
/** Lower-cased names of response headers flagged with `x-mockingbird-parity-header: true`. */
|
|
276
|
+
declare const parityHeaders: (document: OpenAPIDocument, response: ResponseObject) => string[];
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Semantic checks for Mockingbird extensions:
|
|
280
|
+
* - malformed extension objects
|
|
281
|
+
* - identities and references must be strings
|
|
282
|
+
* - `supported: false` / `parity.enabled: false` need a reason
|
|
283
|
+
* - every referenced resource type is produced by some identity in the document
|
|
284
|
+
*/
|
|
285
|
+
declare const validateMetadata: (document: OpenAPIDocument) => string[];
|
|
286
|
+
/** Every resource type produced by an identity somewhere in the document. */
|
|
287
|
+
declare const resourceTypes: (document: OpenAPIDocument) => string[];
|
|
288
|
+
|
|
289
|
+
export { EXTENSION_KEYS, SCOPE_VALUES, VOLATILE_KINDS, annotateValue, operationMetadata, parameterMetadata, parityHeaders, pathKey, resourceTypes, schemaMetadata, validateMetadata };
|
|
290
|
+
export type { Annotation, JsonPath, OperationExtension, OperationMetadata, ResourceIdentityExtension, ResourceRefExtension, SchemaMetadata, ScopeExtension, ScopeValue, UnsupportedExtension, VolatileExtension, VolatileKind };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EXTENSION_KEYS,
|
|
3
|
+
SCOPE_VALUES,
|
|
4
|
+
VOLATILE_KINDS,
|
|
5
|
+
annotateValue,
|
|
6
|
+
operationMetadata,
|
|
7
|
+
parameterMetadata,
|
|
8
|
+
parityHeaders,
|
|
9
|
+
pathKey,
|
|
10
|
+
resourceTypes,
|
|
11
|
+
schemaMetadata,
|
|
12
|
+
validateMetadata
|
|
13
|
+
} from "./chunk-EQLY2YOA.js";
|
|
14
|
+
import "./chunk-HU6IOAFC.js";
|
|
15
|
+
export {
|
|
16
|
+
EXTENSION_KEYS,
|
|
17
|
+
SCOPE_VALUES,
|
|
18
|
+
VOLATILE_KINDS,
|
|
19
|
+
annotateValue,
|
|
20
|
+
operationMetadata,
|
|
21
|
+
parameterMetadata,
|
|
22
|
+
parityHeaders,
|
|
23
|
+
pathKey,
|
|
24
|
+
resourceTypes,
|
|
25
|
+
schemaMetadata,
|
|
26
|
+
validateMetadata
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=openapi-metadata.js.map
|