@jigs.design/client 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CallReply, HeadersOption, HttpTransportOptions, Transport, TransportError, httpTransport } from "./transport.js";
2
2
  import { ClientOptions, ConfirmFunction, JigsClient, PageData, PageResult, createJigsClient } from "./client.js";
3
- import { ActionCall, ActionHandler, ViewController, ViewIssue, ViewStatus, createViewController, missingComponents } from "./view/controller.js";
3
+ import { ActionCall, ActionHandler, MutationEvent, MutationHandler, ViewController, ViewIssue, ViewStatus, createViewController, missingComponents } from "./view/controller.js";
4
4
  import { Diagnostic, Invalidation, JigsErrorCode, JigsErrorData, Message, PageProps, PageReply, Program, PushEvent, SessionBody, SessionEvent, Severity, Span } from "@jigs.design/protocol";
5
- export { type ActionCall, type ActionHandler, type CallReply, type ClientOptions, type ConfirmFunction, type Diagnostic, type HeadersOption, type HttpTransportOptions, type Invalidation, type JigsClient, type JigsErrorCode, type JigsErrorData, type Message, type PageData, type PageProps, type PageReply, type PageResult, type Program, type PushEvent, type SessionBody, type SessionEvent, type Severity, type Span, type Transport, TransportError, type ViewController, type ViewIssue, type ViewStatus, createJigsClient, createViewController, httpTransport, missingComponents };
5
+ export { type ActionCall, type ActionHandler, type CallReply, type ClientOptions, type ConfirmFunction, type Diagnostic, type HeadersOption, type HttpTransportOptions, type Invalidation, type JigsClient, type JigsErrorCode, type JigsErrorData, type Message, type MutationEvent, type MutationHandler, type PageData, type PageProps, type PageReply, type PageResult, type Program, type PushEvent, type SessionBody, type SessionEvent, type Severity, type Span, type Transport, TransportError, type ViewController, type ViewIssue, type ViewStatus, createJigsClient, createViewController, httpTransport, missingComponents };
@@ -1,5 +1,5 @@
1
1
  import { ConfirmFunction, JigsClient } from "../client.js";
2
- import { JsonValue, Program, PropSchema, RuntimeError, WireArg } from "@jigs.design/protocol";
2
+ import { JsonValue, MutationResult, Program, PropSchema, RuntimeError, WireArg } from "@jigs.design/protocol";
3
3
  import { TreeNode, TreeStore } from "@jigs.design/runtime";
4
4
  //#region src/view/controller.d.ts
5
5
  /** What the view shows beside the tree: a snapshot, replaced on each change. */
@@ -40,6 +40,16 @@ export interface ActionCall {
40
40
  * `error`.
41
41
  */
42
42
  export type ActionHandler = (action: ActionCall) => unknown;
43
+ /** A mutation the program ran, once the server answered it. */
44
+ export interface MutationEvent {
45
+ /** What the program passed, which the server checked on a success. */
46
+ input: unknown;
47
+ name: string;
48
+ /** What the program's handle got; a `DECLINED` error when the user said no. */
49
+ result: MutationResult;
50
+ }
51
+ /** Hears each mutation the program ran, after the program got its result. */
52
+ export type MutationHandler = (mutation: MutationEvent) => void;
43
53
  /**
44
54
  * The page side of one view, for any renderer: it owns the sandbox frame and
45
55
  * the tree, and routes the program's queries, mutations and actions. Call
@@ -101,6 +111,13 @@ export interface ViewController {
101
111
  setData: (values: Readonly<Record<string, JsonValue>> | undefined) => void;
102
112
  /** Replaces what each new issue is given to; `undefined` stops reporting. */
103
113
  setIssueHandler: (handler: ((issue: ViewIssue) => void) | undefined) => void;
114
+ /**
115
+ * Replaces what hears each mutation the program ran once it settled, for
116
+ * a page that tells someone, such as the chat model, what the user
117
+ * changed. Actions are not reported: the action handler has them.
118
+ * `undefined` stops reporting.
119
+ */
120
+ setMutationHandler: (handler: MutationHandler | undefined) => void;
104
121
  /**
105
122
  * Components the program uses that the registry lacks, as issues to
106
123
  * report; `missingComponents` lists them.
@@ -115,6 +115,7 @@ function createViewController(client) {
115
115
  let startup = null;
116
116
  let actionHandler;
117
117
  let confirmHandler;
118
+ let mutationHandler;
118
119
  /**
119
120
  * Aborts the confirmations the program on screen asked for, so a question
120
121
  * still showing cannot run a mutation for a program that is gone.
@@ -361,15 +362,19 @@ function createViewController(client) {
361
362
  input: result.data,
362
363
  name: call.name
363
364
  }) : result).then((result) => {
364
- if (started === generation) {
365
- seq++;
366
- post({
367
- id: call.id,
368
- result,
369
- seq,
370
- type: "mutation"
371
- });
372
- }
365
+ if (started !== generation) return;
366
+ seq++;
367
+ post({
368
+ id: call.id,
369
+ result,
370
+ seq,
371
+ type: "mutation"
372
+ });
373
+ if (kind === "mutation") mutationHandler?.({
374
+ input: call.input,
375
+ name: call.name,
376
+ result
377
+ });
373
378
  });
374
379
  }
375
380
  };
@@ -541,6 +546,9 @@ function createViewController(client) {
541
546
  setIssueHandler: (handler) => {
542
547
  issueHandler = handler;
543
548
  },
549
+ setMutationHandler: (handler) => {
550
+ mutationHandler = handler;
551
+ },
544
552
  setUnregistered: (issues) => {
545
553
  unregistered = issues;
546
554
  announce();
@@ -581,6 +589,7 @@ function createViewController(client) {
581
589
  latestDocument = void 0;
582
590
  actionHandler = void 0;
583
591
  confirmHandler = void 0;
592
+ mutationHandler = void 0;
584
593
  provided = /* @__PURE__ */ new Map();
585
594
  withdrawConfirmations();
586
595
  dropObservers();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jigs.design/client",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "createJigsClient: the browser's transport and query cache. No React.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@tanstack/query-core": "5.104.4",
29
- "@jigs.design/protocol": "0.3.4",
30
- "@jigs.design/runtime": "0.3.4"
29
+ "@jigs.design/protocol": "0.3.5",
30
+ "@jigs.design/runtime": "0.3.5"
31
31
  }
32
32
  }