@moltzap/client 2026.506.0 → 2026.507.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/cli/commands/contacts.d.ts.map +1 -1
  2. package/dist/cli/commands/contacts.js +3 -3
  3. package/dist/cli/commands/contacts.js.map +1 -1
  4. package/dist/cli/commands/conversations.d.ts.map +1 -1
  5. package/dist/cli/commands/conversations.js +11 -11
  6. package/dist/cli/commands/conversations.js.map +1 -1
  7. package/dist/cli/commands/messages.d.ts.map +1 -1
  8. package/dist/cli/commands/messages.js +3 -3
  9. package/dist/cli/commands/messages.js.map +1 -1
  10. package/dist/cli/commands/send.d.ts.map +1 -1
  11. package/dist/cli/commands/send.js +3 -3
  12. package/dist/cli/commands/send.js.map +1 -1
  13. package/dist/cli/commands/test-transport.d.ts.map +1 -1
  14. package/dist/cli/commands/test-transport.js +11 -8
  15. package/dist/cli/commands/test-transport.js.map +1 -1
  16. package/dist/cli/http-client.d.ts +2 -2
  17. package/dist/cli/http-client.d.ts.map +1 -1
  18. package/dist/cli/socket-client.d.ts +4 -3
  19. package/dist/cli/socket-client.d.ts.map +1 -1
  20. package/dist/cli/socket-client.js +6 -4
  21. package/dist/cli/socket-client.js.map +1 -1
  22. package/dist/cli/transport.d.ts +3 -3
  23. package/dist/cli/transport.d.ts.map +1 -1
  24. package/dist/cli/transport.js.map +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal/__tests__/app-callback-test-requests.d.ts +2 -2
  29. package/dist/internal/__tests__/app-callback-test-requests.d.ts.map +1 -1
  30. package/dist/internal/__tests__/app-callback-test-requests.js +3 -2
  31. package/dist/internal/__tests__/app-callback-test-requests.js.map +1 -1
  32. package/dist/internal/app-callback-dispatcher-errors.d.ts +3 -3
  33. package/dist/internal/app-callback-dispatcher-errors.d.ts.map +1 -1
  34. package/dist/internal/app-callback-partition-key.d.ts +2 -2
  35. package/dist/internal/app-callback-partition-key.d.ts.map +1 -1
  36. package/dist/runtime/errors.d.ts +2 -12
  37. package/dist/runtime/errors.d.ts.map +1 -1
  38. package/dist/runtime/errors.js +4 -3
  39. package/dist/runtime/errors.js.map +1 -1
  40. package/dist/runtime/frame.d.ts +11 -18
  41. package/dist/runtime/frame.d.ts.map +1 -1
  42. package/dist/runtime/frame.js +23 -53
  43. package/dist/runtime/frame.js.map +1 -1
  44. package/dist/runtime/frame.test.js +28 -34
  45. package/dist/runtime/frame.test.js.map +1 -1
  46. package/dist/runtime/subscribers.d.ts +8 -11
  47. package/dist/runtime/subscribers.d.ts.map +1 -1
  48. package/dist/runtime/subscribers.js.map +1 -1
  49. package/dist/runtime/subscribers.test.js +8 -14
  50. package/dist/runtime/subscribers.test.js.map +1 -1
  51. package/dist/service.d.ts +5 -8
  52. package/dist/service.d.ts.map +1 -1
  53. package/dist/service.js +44 -65
  54. package/dist/service.js.map +1 -1
  55. package/dist/service.test.js +9 -9
  56. package/dist/service.test.js.map +1 -1
  57. package/dist/test/index.d.ts +1 -1
  58. package/dist/test/index.js +1 -1
  59. package/dist/test-utils/conformance-adapter.d.ts +5 -5
  60. package/dist/test-utils/conformance-adapter.d.ts.map +1 -1
  61. package/dist/test-utils/conformance-adapter.js +26 -29
  62. package/dist/test-utils/conformance-adapter.js.map +1 -1
  63. package/dist/test-utils/fake-service.d.ts +4 -4
  64. package/dist/test-utils/fake-service.d.ts.map +1 -1
  65. package/dist/test-utils/fake-service.js +19 -10
  66. package/dist/test-utils/fake-service.js.map +1 -1
  67. package/dist/test-utils/ids.d.ts +2 -6
  68. package/dist/test-utils/ids.d.ts.map +1 -1
  69. package/dist/test-utils/ids.js +1 -2
  70. package/dist/test-utils/ids.js.map +1 -1
  71. package/dist/ws-client.d.ts +11 -89
  72. package/dist/ws-client.d.ts.map +1 -1
  73. package/dist/ws-client.js +56 -153
  74. package/dist/ws-client.js.map +1 -1
  75. package/dist/ws-client.test.js +35 -48
  76. package/dist/ws-client.test.js.map +1 -1
  77. package/package.json +3 -4
  78. package/dist/runtime/index.d.ts +0 -3
  79. package/dist/runtime/index.d.ts.map +0 -1
  80. package/dist/runtime/index.js +0 -3
  81. package/dist/runtime/index.js.map +0 -1
  82. package/dist/runtime/notification-types.types-check.d.ts +0 -2
  83. package/dist/runtime/notification-types.types-check.d.ts.map +0 -1
  84. package/dist/runtime/notification-types.types-check.js +0 -57
  85. package/dist/runtime/notification-types.types-check.js.map +0 -1
  86. package/dist/service.typed-bridge.test.d.ts +0 -2
  87. package/dist/service.typed-bridge.test.d.ts.map +0 -1
  88. package/dist/service.typed-bridge.test.js +0 -93
  89. package/dist/service.typed-bridge.test.js.map +0 -1
  90. package/dist/ws-client.typed-bridge.test.d.ts +0 -2
  91. package/dist/ws-client.typed-bridge.test.d.ts.map +0 -1
  92. package/dist/ws-client.typed-bridge.test.js +0 -105
  93. package/dist/ws-client.typed-bridge.test.js.map +0 -1
@@ -1,57 +0,0 @@
1
- /**
2
- * Negative type-test canary for Phase 7.5c (#455).
3
- *
4
- * Locks the compiler-enforced lift contract that splits unvalidated
5
- * wire-decoder output (`RawDecodedNotification<D>`,
6
- * `DecodedNotificationFrame`) from validated typed-bridge surface
7
- * (`DecodedNotification<D>`).
8
- *
9
- * What we assert:
10
- *
11
- * 1. `subscribers.dispatch` accepts the raw / unknown-method union
12
- * `DecodedNotificationFrame`. Validated `DecodedNotification<D>`
13
- * values are still acceptable (subtype of `RawDecodedNotification<D>`),
14
- * but a raw frame cannot reach the typed handler bucket without
15
- * passing through `validateNotificationParams`.
16
- *
17
- * 2. `defineEffectNotificationHandlers(...).dispatch` (the typed
18
- * handler dispatcher used by `MoltZapService`) refuses
19
- * `RawDecodedNotification<D>` and the broader
20
- * `DecodedNotificationFrame` union — only validated
21
- * `DecodedNotification<D>` may flow in. This is the load-bearing
22
- * negative: a regression that re-aliases the two types would
23
- * surface here as a missing `@ts-expect-error`.
24
- *
25
- * Compile-only — no runtime test runner picks this file up. The
26
- * `@ts-expect-error` markers fail the build if they ever start
27
- * compiling cleanly.
28
- */
29
- import { Effect } from "effect";
30
- import { ConversationArchivedNotificationDefinition, bindNotificationHandler, defineEffectNotificationHandlers, defineNotificationGroup, } from "@moltzap/protocol";
31
- import { makeSubscriberRegistry } from "./subscribers.js";
32
- const noopLogger = { warn: () => { } };
33
- const registry = Effect.runSync(makeSubscriberRegistry(noopLogger));
34
- const canaryGroup = defineNotificationGroup("phase7.5c-canary", [
35
- ConversationArchivedNotificationDefinition,
36
- ]);
37
- const typedHandlers = defineEffectNotificationHandlers(canaryGroup, [
38
- bindNotificationHandler(ConversationArchivedNotificationDefinition, () => Effect.void),
39
- ]);
40
- // --- Subscribers (raw|unknown) accept the wire-decoder union ---
41
- void registry.dispatch(rawFrame); // OK: raw subtype of the union
42
- void registry.dispatch(wireUnion); // OK: union dispatch
43
- // Validated values are also accepted because `DecodedNotification<D>`
44
- // is a subtype of `RawDecodedNotification<D>` (params narrower).
45
- void registry.dispatch(validatedFrame);
46
- // --- Typed dispatcher refuses pre-validation shapes ---
47
- // @ts-expect-error - typed dispatcher rejects unvalidated raw frames; lift via `validateNotificationParams` first
48
- void typedHandlers.dispatch(rawFrame);
49
- // @ts-expect-error - typed dispatcher rejects the wire-decoder union (includes the unknown-method branch)
50
- void typedHandlers.dispatch(wireUnion);
51
- // Validated frame is accepted — proves the negative is not vacuous
52
- // (a regression that aliases Decoded≡Raw would still pass this line
53
- // but flip the `@ts-expect-error`s above).
54
- void typedHandlers.dispatch(validatedFrame);
55
- // @ts-expect-error - unknown-method branch has no descriptor; typed dispatcher requires `definition`
56
- void typedHandlers.dispatch(unknownMethodFrame);
57
- //# sourceMappingURL=notification-types.types-check.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"notification-types.types-check.js","sourceRoot":"","sources":["../../src/runtime/notification-types.types-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,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d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.typed-bridge.test.d.ts","sourceRoot":"","sources":["../src/service.typed-bridge.test.ts"],"names":[],"mappings":""}
@@ -1,93 +0,0 @@
1
- /**
2
- * Drives a stale-shape notification through the real subscriber →
3
- * service → typed-handler dispatch path (`handleNotification` →
4
- * `notificationHandlers.dispatch`). The helper test in
5
- * `ws-client.typed-bridge.test.ts` exercises `validateNotificationParams`
6
- * in isolation; this file proves the subscriber-fanout bridge actually
7
- * invokes it and skips dispatch on drift, so the stale frame never
8
- * reaches the typed handler bound inside `createNotificationHandlers`.
9
- *
10
- * Discriminating choice: `ConversationArchivedNotificationDefinition`
11
- * is one of the five notifications in `serviceNotificationGroup`, so a
12
- * payload missing the required `archivedAt` field hits the typed-handler
13
- * dispatch path (which would call `markConversationArchived` +
14
- * `fanout(handlers.conversationArchived, ...)`). The regression asserts:
15
- * 1. The typed `conversationArchived` user handler is NOT invoked.
16
- * 2. The internal `archivedConversationIds` set is NOT updated.
17
- * 3. The raw-notification handler IS invoked (proves the
18
- * pre-validation surface still fires; only the typed dispatch is
19
- * gated).
20
- * 4. A drift warning is logged with the notification name.
21
- */
22
- import { describe, expect, it, vi } from "vitest";
23
- import { ConversationArchivedNotificationDefinition, agentId, conversationId, notificationFrame, } from "@moltzap/protocol";
24
- import { MoltZapService } from "./service.js";
25
- class TestMoltZapService extends MoltZapService {
26
- driveNotification(notification) {
27
- this.handleNotification(notification);
28
- }
29
- }
30
- const CONV_ID = conversationId("00000000-0000-4000-8000-000000c0a4ed");
31
- const BY_AGENT = agentId("00000000-0000-4000-8000-0000000a9e47");
32
- // Constructing the stale-shape fixture as `RawDecodedNotification`
33
- // (params: unknown) lets TypeScript accept the unvalidated payload
34
- // without a type lie: the wire decoder is payload-opaque, so a frame
35
- // missing the required `archivedAt` field is structurally a Raw
36
- // notification — the typed-bridge lift in `validateNotificationParams`
37
- // is what rejects it at dispatch time.
38
- const STALE_ARCHIVED = {
39
- jsonrpc: "2.0",
40
- method: ConversationArchivedNotificationDefinition.name,
41
- params: { conversationId: CONV_ID, by: BY_AGENT },
42
- _tag: "Notification",
43
- definition: ConversationArchivedNotificationDefinition,
44
- };
45
- const LIVE_ARCHIVED = {
46
- ...notificationFrame(ConversationArchivedNotificationDefinition, {
47
- conversationId: CONV_ID,
48
- archivedAt: "2026-05-05T00:00:00.000Z",
49
- by: BY_AGENT,
50
- }),
51
- _tag: "Notification",
52
- definition: ConversationArchivedNotificationDefinition,
53
- };
54
- describe("MoltZapService.handleNotification subscriber-fanout bridge", () => {
55
- it("skips typed dispatch on a stale shape, fans out raw, and logs drift", () => {
56
- const warn = vi.fn();
57
- const service = new TestMoltZapService({
58
- serverUrl: "ws://test",
59
- agentKey: "test-key",
60
- logger: { info: vi.fn(), warn, error: vi.fn() },
61
- });
62
- const onArchived = vi.fn();
63
- const onRaw = vi.fn();
64
- service.on("conversationArchived", onArchived);
65
- service.on("rawNotification", onRaw);
66
- service.driveNotification(STALE_ARCHIVED);
67
- // Typed handler MUST NOT see the malformed payload.
68
- expect(onArchived).not.toHaveBeenCalled();
69
- expect(service.isConversationArchived(CONV_ID)).toBe(false);
70
- // Raw-notification handler still fires — fanout runs before the
71
- // typed-bridge gate, so subscribers using the opaque surface are
72
- // unaffected.
73
- expect(onRaw).toHaveBeenCalledTimes(1);
74
- // Drift warning surfaced via the WsClientLogger.
75
- expect(warn).toHaveBeenCalledTimes(1);
76
- expect(String(warn.mock.calls[0]?.[0])).toMatch(/conversations\/archived.*drift signal/);
77
- });
78
- it("dispatches a live shape to the typed handler and updates internal state", () => {
79
- const warn = vi.fn();
80
- const service = new TestMoltZapService({
81
- serverUrl: "ws://test",
82
- agentKey: "test-key",
83
- logger: { info: vi.fn(), warn, error: vi.fn() },
84
- });
85
- const onArchived = vi.fn();
86
- service.on("conversationArchived", onArchived);
87
- service.driveNotification(LIVE_ARCHIVED);
88
- expect(onArchived).toHaveBeenCalledTimes(1);
89
- expect(service.isConversationArchived(CONV_ID)).toBe(true);
90
- expect(warn).not.toHaveBeenCalled();
91
- });
92
- });
93
- //# sourceMappingURL=service.typed-bridge.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.typed-bridge.test.js","sourceRoot":"","sources":["../src/service.typed-bridge.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EACL,0CAA0C,EAC1C,OAAO,EACP,cAAc,EACd,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAM9C,MAAM,kBAAmB,SAAQ,cAAc;IACtC,iBAAiB,CAAC,YAAsC;QAC7D,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;CACF;AAED,MAAM,OAAO,GAAG,cAAc,CAAC,sCAAsC,CAAC,CAAC;AACvE,MAAM,QAAQ,GAAG,OAAO,CAAC,sCAAsC,CAAC,CAAC;AAMjE,mEAAmE;AACnE,mEAAmE;AACnE,qEAAqE;AACrE,gEAAgE;AAChE,uEAAuE;AACvE,uCAAuC;AACvC,MAAM,cAAc,GAA4B;IAC9C,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,0CAA0C,CAAC,IAAI;IACvD,MAAM,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE;IACjD,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,0CAA0C;CAC5B,CAAC;AAE7B,MAAM,aAAa,GAA4B;IAC7C,GAAG,iBAAiB,CAAC,0CAA0C,EAAE;QAC/D,cAAc,EAAE,OAAO;QACvB,UAAU,EAAE,0BAA0B;QACtC,EAAE,EAAE,QAAQ;KACb,CAAC;IACF,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,0CAA0C;CACvD,CAAC;AAEF,QAAQ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E,EAAE,GAAG,EAAE;QACjF,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC;YACrC,SAAS,EAAE,WAAW;YACtB,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;SAChD,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,sBAAsB,EAAE,UAAU,CAAC,CAAC;QAE/C,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAEzC,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ws-client.typed-bridge.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ws-client.typed-bridge.test.d.ts","sourceRoot":"","sources":["../src/ws-client.typed-bridge.test.ts"],"names":[],"mappings":""}
@@ -1,105 +0,0 @@
1
- /**
2
- * Typed-bridge regression: the wire decoder is payload-opaque (so
3
- * `delivery/payload-opacity-client` conformance holds). Inbound typed
4
- * consumers MUST validate `params` before exposing them to a typed
5
- * handler. A stale Phase-6 `task/closed` shape (carrying `sessionId` +
6
- * scalar `closedBy`) is a known-method notification whose method
7
- * matches `TaskClosedNotificationDefinition`, so a definition-only
8
- * match would silently bridge a malformed payload into a typed
9
- * consumer. Both bridges (`acceptTypedNotification` for
10
- * `waitForNotification` and the shared `validateNotificationParams`
11
- * helper used by `service.handleNotification`) log and skip instead.
12
- */
13
- import { describe, expect, it, vi } from "vitest";
14
- import { PresenceChangedNotificationDefinition, TaskClosedNotificationDefinition, agentId, conversationId, notificationFrame, taskId, } from "@moltzap/protocol";
15
- import { acceptTypedNotification, validateNotificationParams, } from "./ws-client.js";
16
- // Stale wire-shape fixture as `RawDecodedNotification` (params: unknown):
17
- // the wire decoder is payload-opaque, so the pre-Phase-7 `sessionId` /
18
- // scalar `closedBy` shape is structurally a valid Raw notification.
19
- // `validateNotificationParams` is what rejects it at the typed-bridge
20
- // boundary; the type system distinguishes "decoded from the wire" from
21
- // "validated against the schema."
22
- const STALE_TASK_CLOSED = {
23
- jsonrpc: "2.0",
24
- method: TaskClosedNotificationDefinition.name,
25
- params: {
26
- sessionId: "11111111-1111-4111-8111-111111111111",
27
- closedBy: "33333333-3333-4333-8333-333333333333",
28
- },
29
- _tag: "Notification",
30
- definition: TaskClosedNotificationDefinition,
31
- };
32
- const LIVE_TASK_CLOSED = {
33
- ...notificationFrame(TaskClosedNotificationDefinition, {
34
- taskId: taskId("11111111-1111-4111-8111-111111111111"),
35
- conversations: {
36
- main: conversationId("22222222-2222-4222-8222-222222222222"),
37
- },
38
- closedBy: {
39
- agentId: agentId("33333333-3333-4333-8333-333333333333"),
40
- ownerId: "owner-1",
41
- },
42
- }),
43
- _tag: "Notification",
44
- definition: TaskClosedNotificationDefinition,
45
- };
46
- function makeLogger() {
47
- return {
48
- info: vi.fn(),
49
- warn: vi.fn(),
50
- error: vi.fn(),
51
- };
52
- }
53
- describe("acceptTypedNotification", () => {
54
- it("rejects a stale `task/closed` payload, logs the drift signal", () => {
55
- const logger = makeLogger();
56
- const accepted = acceptTypedNotification(TaskClosedNotificationDefinition, STALE_TASK_CLOSED, logger);
57
- expect(accepted).toBe(false);
58
- expect(logger.warn).toHaveBeenCalledTimes(1);
59
- expect(String(logger.warn.mock.calls[0]?.[0])).toMatch(/task\/closed.*drift signal/);
60
- });
61
- it("accepts a live `task/closed` payload — proves the validator is not vacuously false", () => {
62
- const logger = makeLogger();
63
- const accepted = acceptTypedNotification(TaskClosedNotificationDefinition, LIVE_TASK_CLOSED, logger);
64
- expect(accepted).toBe(true);
65
- expect(logger.warn).not.toHaveBeenCalled();
66
- });
67
- it("returns false for a non-matching definition without invoking validateParams", () => {
68
- const logger = makeLogger();
69
- const validateSpy = vi.spyOn(TaskClosedNotificationDefinition, "validateParams");
70
- const wrongMethod = {
71
- jsonrpc: "2.0",
72
- method: PresenceChangedNotificationDefinition.name,
73
- params: {},
74
- _tag: "Notification",
75
- definition: PresenceChangedNotificationDefinition,
76
- };
77
- const accepted = acceptTypedNotification(TaskClosedNotificationDefinition, wrongMethod, logger);
78
- expect(accepted).toBe(false);
79
- expect(validateSpy).not.toHaveBeenCalled();
80
- expect(logger.warn).not.toHaveBeenCalled();
81
- validateSpy.mockRestore();
82
- });
83
- it("works without a logger (logger is optional)", () => {
84
- const accepted = acceptTypedNotification(TaskClosedNotificationDefinition, STALE_TASK_CLOSED, undefined);
85
- expect(accepted).toBe(false);
86
- });
87
- });
88
- // Tests the shared validation core used by both inbound typed bridges
89
- // (`acceptTypedNotification` and `service.handleNotification`). A
90
- // refactor that breaks the shared core surfaces here, not via downstream
91
- // integration regressions.
92
- describe("validateNotificationParams", () => {
93
- it("returns false + logs when params fail the attached schema", () => {
94
- const logger = makeLogger();
95
- expect(validateNotificationParams(STALE_TASK_CLOSED, logger)).toBe(false);
96
- expect(logger.warn).toHaveBeenCalledTimes(1);
97
- expect(String(logger.warn.mock.calls[0]?.[0])).toMatch(/task\/closed.*drift signal/);
98
- });
99
- it("returns true + no log when params conform", () => {
100
- const logger = makeLogger();
101
- expect(validateNotificationParams(LIVE_TASK_CLOSED, logger)).toBe(true);
102
- expect(logger.warn).not.toHaveBeenCalled();
103
- });
104
- });
105
- //# sourceMappingURL=ws-client.typed-bridge.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ws-client.typed-bridge.test.js","sourceRoot":"","sources":["../src/ws-client.typed-bridge.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EACL,qCAAqC,EACrC,gCAAgC,EAChC,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,MAAM,GACP,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAUxB,0EAA0E;AAC1E,uEAAuE;AACvE,oEAAoE;AACpE,sEAAsE;AACtE,uEAAuE;AACvE,kCAAkC;AAClC,MAAM,iBAAiB,GAAkB;IACvC,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,gCAAgC,CAAC,IAAI;IAC7C,MAAM,EAAE;QACN,SAAS,EAAE,sCAAsC;QACjD,QAAQ,EAAE,sCAAsC;KACjD;IACD,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,gCAAgC;CAC5B,CAAC;AAEnB,MAAM,gBAAgB,GAAkB;IACtC,GAAG,iBAAiB,CAAC,gCAAgC,EAAE;QACrD,MAAM,EAAE,MAAM,CAAC,sCAAsC,CAAC;QACtD,aAAa,EAAE;YACb,IAAI,EAAE,cAAc,CAAC,sCAAsC,CAAC;SAC7D;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,OAAO,CAAC,sCAAsC,CAAC;YACxD,OAAO,EAAE,SAAS;SACnB;KACF,CAAC;IACF,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,gCAAgC;CAC7C,CAAC;AAEF,SAAS,UAAU;IAKjB,OAAO;QACL,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;QACb,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;QACb,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;KACf,CAAC;AACJ,CAAC;AAED,QA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