@jigs.design/runtime 0.1.0 → 0.1.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 CHANGED
@@ -6,10 +6,10 @@ The layer the server and the browser share: the program format, the types on the
6
6
 
7
7
  ## Entry points
8
8
 
9
- | Entry | What it holds |
10
- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
- | `@jigs.design/runtime` | `Program`, `SessionEvent`, `Message`, `Diagnostic` and the other shared types; the frame protocol; the JSON checks the browser runs; `createTreeStore`; the image and link allowlists |
12
- | `@jigs.design/runtime/frame` | The sandbox frame document, its content security policy, and the worker runtime. The server serves it |
9
+ | Entry | What it holds |
10
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | `@jigs.design/runtime` | `Program`, `SessionEvent`, `Message`, `Diagnostic` and the other shared types; the frame protocol (`HostMessage`, `FrameMessage`, `Op`); the JSON checks the browser runs; `createTreeStore` with its caps `MAX_NODES`, `MAX_OPS` and `MAX_TEXT`; the image and link allowlists |
12
+ | `@jigs.design/runtime/frame` | The sandbox frame document, its content security policy, the worker runtime, and `WATCHDOG_MS` and `HEARTBEAT_MS`. The server serves it |
13
13
 
14
14
  ## How a program runs
15
15
 
@@ -27,4 +27,4 @@ The server serves the frame document from its route. The frame starts a worker a
27
27
 
28
28
  ## Docs
29
29
 
30
- [Sandbox](../../apps/docs/docs/react/sandbox.mdx) and [Packages](../../apps/docs/docs/packages/index.mdx).
30
+ [Sandbox](../../apps/docs/docs/react/sandbox.mdx), [Frame protocol](../../apps/docs/docs/renderers/protocol.mdx) and [Packages](../../apps/docs/docs/packages/index.mdx).
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { frameSecurityPolicy } from "./frame-policy.js";
2
- import { ChatBlock, ChatBlockStatus, ChildrenKind, ComponentSchema, Diagnostic, DiagnosticFix, Invalidation, JsonValue, Message, NumberPropSchema, PROGRAM_FORMAT, PickleErrorCode, PickleErrorData, ProcedureEntry, ProcedureKind, Program, PropSchema, SessionBody, SessionEvent, SessionOptions, Span, pickleErrorCodes } from "./types.js";
2
+ import { ChatBlock, ChatBlockStatus, ChildrenKind, ComponentSchema, Diagnostic, DiagnosticFix, Invalidation, JigsErrorCode, JigsErrorData, JsonValue, Message, NumberPropSchema, PROGRAM_FORMAT, ProcedureEntry, ProcedureKind, Program, PropSchema, SessionBody, SessionEvent, SessionOptions, Span, jigsErrorCodes } from "./types.js";
3
3
  import { FrameMessage, HostMessage, MutationCall, MutationResult, Op, QueryRead, QueryResult, ROOT_ID, Row, RuntimeError, WireArg, WireValue, WorkerMessage } from "./protocol.js";
4
4
  import { parseErrorData, parseInvalidations, parseProgram, parseSessionEvent } from "./parse.js";
5
- import { TreeNode, TreeStore, createTreeStore } from "./tree-store.js";
5
+ import { MAX_NODES, MAX_OPS, MAX_TEXT, TreeNode, TreeStore, createTreeStore } from "./tree-store.js";
6
6
  import { isAllowedImage, isAllowedLink, isImageHostEntry, normalizeImageHost } from "./urls.js";
7
- export { type ChatBlock, type ChatBlockStatus, type ChildrenKind, type ComponentSchema, type Diagnostic, type DiagnosticFix, type FrameMessage, type HostMessage, type Invalidation, type JsonValue, type Message, type MutationCall, type MutationResult, type NumberPropSchema, type Op, PROGRAM_FORMAT, type PickleErrorCode, type PickleErrorData, type ProcedureEntry, type ProcedureKind, type Program, type PropSchema, type QueryRead, type QueryResult, ROOT_ID, type Row, type RuntimeError, type SessionBody, type SessionEvent, type SessionOptions, type Span, type TreeNode, type TreeStore, type WireArg, type WireValue, type WorkerMessage, createTreeStore, frameSecurityPolicy, isAllowedImage, isAllowedLink, isImageHostEntry, normalizeImageHost, parseErrorData, parseInvalidations, parseProgram, parseSessionEvent, pickleErrorCodes };
7
+ export { type ChatBlock, type ChatBlockStatus, type ChildrenKind, type ComponentSchema, type Diagnostic, type DiagnosticFix, type FrameMessage, type HostMessage, type Invalidation, type JigsErrorCode, type JigsErrorData, type JsonValue, MAX_NODES, MAX_OPS, MAX_TEXT, type Message, type MutationCall, type MutationResult, type NumberPropSchema, type Op, PROGRAM_FORMAT, type ProcedureEntry, type ProcedureKind, type Program, type PropSchema, type QueryRead, type QueryResult, ROOT_ID, type Row, type RuntimeError, type SessionBody, type SessionEvent, type SessionOptions, type Span, type TreeNode, type TreeStore, type WireArg, type WireValue, type WorkerMessage, createTreeStore, frameSecurityPolicy, isAllowedImage, isAllowedLink, isImageHostEntry, jigsErrorCodes, normalizeImageHost, parseErrorData, parseInvalidations, parseProgram, parseSessionEvent };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { PROGRAM_FORMAT, pickleErrorCodes } from "./types.js";
1
+ import { PROGRAM_FORMAT, jigsErrorCodes } from "./types.js";
2
2
  import { ROOT_ID } from "./protocol.js";
3
3
  import { frameSecurityPolicy } from "./frame-policy.js";
4
4
  import { parseErrorData, parseInvalidations, parseProgram, parseSessionEvent } from "./parse.js";
5
5
  import { isAllowedImage, isAllowedLink, isImageHostEntry, normalizeImageHost } from "./urls.js";
6
- import { createTreeStore } from "./tree-store.js";
7
- export { PROGRAM_FORMAT, ROOT_ID, createTreeStore, frameSecurityPolicy, isAllowedImage, isAllowedLink, isImageHostEntry, normalizeImageHost, parseErrorData, parseInvalidations, parseProgram, parseSessionEvent, pickleErrorCodes };
6
+ import { MAX_NODES, MAX_OPS, MAX_TEXT, createTreeStore } from "./tree-store.js";
7
+ export { MAX_NODES, MAX_OPS, MAX_TEXT, PROGRAM_FORMAT, ROOT_ID, createTreeStore, frameSecurityPolicy, isAllowedImage, isAllowedLink, isImageHostEntry, jigsErrorCodes, normalizeImageHost, parseErrorData, parseInvalidations, parseProgram, parseSessionEvent };
package/dist/parse.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Invalidation, PickleErrorData, Program, SessionEvent } from "./types.js";
1
+ import { Invalidation, JigsErrorData, Program, SessionEvent } from "./types.js";
2
2
  //#region src/parse.d.ts
3
- export declare function parseErrorData(value: unknown): PickleErrorData | null;
3
+ export declare function parseErrorData(value: unknown): JigsErrorData | null;
4
4
  /** The `invalidate` list of a mutation's reply. */
5
5
  export declare function parseInvalidations(value: unknown): ReadonlyArray<Invalidation> | null;
6
6
  export declare function parseProgram(value: unknown): Program | null;
package/dist/parse.js CHANGED
@@ -1,4 +1,4 @@
1
- import { pickleErrorCodes } from "./types.js";
1
+ import { jigsErrorCodes } from "./types.js";
2
2
  //#region src/parse.ts
3
3
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
4
  const isString = (value) => typeof value === "string";
@@ -13,7 +13,7 @@ function recordOf(value, item) {
13
13
  }
14
14
  return out;
15
15
  }
16
- const isErrorCode = (value) => pickleErrorCodes.some((code) => code === value);
16
+ const isErrorCode = (value) => jigsErrorCodes.some((code) => code === value);
17
17
  function parseErrorData(value) {
18
18
  if (!isRecord(value) || !isErrorCode(value.code) || !isString(value.message)) return null;
19
19
  return {
@@ -1,4 +1,4 @@
1
- import { PickleErrorData, ProcedureEntry } from "./types.js";
1
+ import { JigsErrorData, ProcedureEntry } from "./types.js";
2
2
  //#region src/protocol.d.ts
3
3
  /**
4
4
  * Prop value on the wire. Functions never leave the worker; they travel as
@@ -56,7 +56,7 @@ export type QueryResult = {
56
56
  status: "success";
57
57
  } | {
58
58
  data: null;
59
- error: PickleErrorData;
59
+ error: JigsErrorData;
60
60
  status: "error";
61
61
  };
62
62
  /** How a mutation settled. */
@@ -64,7 +64,7 @@ export type MutationResult = {
64
64
  data: unknown;
65
65
  status: "success";
66
66
  } | {
67
- error: PickleErrorData;
67
+ error: JigsErrorData;
68
68
  status: "error";
69
69
  };
70
70
  /** A query the program read during a render. `key` is stable for a name and input. */
@@ -11,7 +11,7 @@ export interface Runtime {
11
11
  * and fine). `FunctionCtor` is passed in because the worker removes dynamic
12
12
  * code evaluation from its globals before any program runs.
13
13
  *
14
- * A small React-style reconciler: programs build a tree with `__pickle.jsx`,
14
+ * A small React-style reconciler: programs build a tree with `__jigs.jsx`,
15
15
  * the runtime diffs it against the previous render by position and type, and
16
16
  * posts the differences as `Op`s. Each render also reports the queries it read
17
17
  * and the mutations its handlers called; the page runs those through the
@@ -7,7 +7,7 @@
7
7
  * and fine). `FunctionCtor` is passed in because the worker removes dynamic
8
8
  * code evaluation from its globals before any program runs.
9
9
  *
10
- * A small React-style reconciler: programs build a tree with `__pickle.jsx`,
10
+ * A small React-style reconciler: programs build a tree with `__jigs.jsx`,
11
11
  * the runtime diffs it against the previous render by position and type, and
12
12
  * posts the differences as `Op`s. Each render also reports the queries it read
13
13
  * and the mutations its handlers called; the page runs those through the
@@ -244,7 +244,7 @@ function createRuntime(post, FunctionCtor) {
244
244
  status: state.status
245
245
  });
246
246
  };
247
- const Pickle = Object.freeze({
247
+ const Jigs = Object.freeze({
248
248
  render: (element) => {
249
249
  rootElement = element;
250
250
  },
@@ -325,7 +325,7 @@ function createRuntime(post, FunctionCtor) {
325
325
  componentDepth--;
326
326
  }
327
327
  };
328
- const pickle = Object.freeze({
328
+ const jigs = Object.freeze({
329
329
  call: callComponent,
330
330
  each,
331
331
  Fragment: FRAGMENT,
@@ -335,7 +335,7 @@ function createRuntime(post, FunctionCtor) {
335
335
  type
336
336
  })
337
337
  });
338
- const pickleSafe = (evaluate, fallback, line) => {
338
+ const jigsSafe = (evaluate, fallback, line) => {
339
339
  try {
340
340
  return evaluate();
341
341
  } catch (error) {
@@ -591,7 +591,7 @@ function createRuntime(post, FunctionCtor) {
591
591
  reads = /* @__PURE__ */ new Map();
592
592
  const next = [];
593
593
  try {
594
- run(Pickle, pickle, pickleSafe);
594
+ run(Jigs, jigs, jigsSafe);
595
595
  expand(rootElement, next);
596
596
  } catch (error) {
597
597
  reads = previousReads;
@@ -682,7 +682,7 @@ function createRuntime(post, FunctionCtor) {
682
682
  unstableSites.clear();
683
683
  querySites = /* @__PURE__ */ new Map();
684
684
  try {
685
- candidate = new FunctionCtor("Pickle", "__pickle", "__pickleSafe", message.code);
685
+ candidate = new FunctionCtor("Jigs", "__jigs", "__jigsSafe", message.code);
686
686
  } catch (error) {
687
687
  prose = previousProse;
688
688
  procedures = previousProcedures;
@@ -22,6 +22,23 @@ export interface TreeStore {
22
22
  setSchemas: (schemas: TreeSchemas) => void;
23
23
  subscribe: (listener: () => void) => () => void;
24
24
  }
25
+ /**
26
+ * Most nodes a tree may hold, the root aside. The runtime refuses to render
27
+ * more (it keeps its own copy of the number), so only a worker that broke out
28
+ * of the runtime gets past it here, and the store drops the creates over it.
29
+ * The count is what a whole message leaves: the runtime may create a row's
30
+ * new nodes before it removes the old ones further on, so mid-message the
31
+ * store may hold up to twice this (`MAX_DRAFT_NODES`).
32
+ */
33
+ export declare const MAX_NODES = 10000;
34
+ /**
35
+ * Most ops one message may carry. A render of `MAX_NODES` nodes needs at most
36
+ * three per node (remove the old one, create and place the new one), so the
37
+ * runtime stays under it; a message over it is dropped whole.
38
+ */
39
+ export declare const MAX_OPS: number;
40
+ /** Longest text a text node may hold, in UTF-16 code units, as for a string prop. */
41
+ export declare const MAX_TEXT = 10000;
25
42
  /**
26
43
  * The page's copy of the sandboxed UI, built from worker ops. Ops are
27
44
  * untrusted: components the program did not declare and props that fail
package/dist/types.d.ts CHANGED
@@ -5,11 +5,11 @@
5
5
  */
6
6
  /** The version of the program format. The runtime refuses any other. */
7
7
  export declare const PROGRAM_FORMAT = 1;
8
- export declare const pickleErrorCodes: readonly ["BAD_INPUT", "UNAUTHORIZED", "FORBIDDEN", "NOT_FOUND", "CONFLICT", "RATE_LIMITED", "INTERNAL", "UNKNOWN_PROCEDURE", "UNAVAILABLE", "NETWORK", "DECLINED"];
9
- export type PickleErrorCode = (typeof pickleErrorCodes)[number];
8
+ export declare const jigsErrorCodes: readonly ["BAD_INPUT", "UNAUTHORIZED", "FORBIDDEN", "NOT_FOUND", "CONFLICT", "RATE_LIMITED", "INTERNAL", "UNKNOWN_PROCEDURE", "UNAVAILABLE", "NETWORK", "DECLINED"];
9
+ export type JigsErrorCode = (typeof jigsErrorCodes)[number];
10
10
  /** A failure as the spec and the browser see it. */
11
- export interface PickleErrorData {
12
- code: PickleErrorCode;
11
+ export interface JigsErrorData {
12
+ code: JigsErrorCode;
13
13
  message: string;
14
14
  }
15
15
  /**
@@ -125,7 +125,7 @@ export type SessionEvent = {
125
125
  source: string;
126
126
  type: "done";
127
127
  } | {
128
- error: PickleErrorData;
128
+ error: JigsErrorData;
129
129
  type: "error";
130
130
  };
131
131
  /**
@@ -134,7 +134,7 @@ export type SessionEvent = {
134
134
  */
135
135
  export type ChatBlockStatus = "done" | "repairing" | "streaming";
136
136
  /**
137
- * A pickle in a chat reply: one fenced `pickle` block, compiled on its own.
137
+ * A jig in a chat reply: one fenced `jigs` block, compiled on its own.
138
138
  * The server sends it again whenever its program changes, under the same
139
139
  * `key`.
140
140
  */
@@ -142,7 +142,7 @@ export interface ChatBlock {
142
142
  /** Lines refer to `source`, which starts with its pragma line. */
143
143
  diagnostics: ReadonlyArray<Diagnostic>;
144
144
  /** Set when the block could not be built, e.g. an edit to a missing UI. */
145
- error?: PickleErrorData;
145
+ error?: JigsErrorData;
146
146
  /** The id the model gave the block, e.g. "monthly-spending". */
147
147
  id: string;
148
148
  /** `${id}@${version}`: unique in a conversation. */
package/dist/types.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /** The version of the program format. The runtime refuses any other. */
7
7
  const PROGRAM_FORMAT = 1;
8
- const pickleErrorCodes = [
8
+ const jigsErrorCodes = [
9
9
  "BAD_INPUT",
10
10
  "UNAUTHORIZED",
11
11
  "FORBIDDEN",
@@ -19,4 +19,4 @@ const pickleErrorCodes = [
19
19
  "DECLINED"
20
20
  ];
21
21
  //#endregion
22
- export { PROGRAM_FORMAT, pickleErrorCodes };
22
+ export { PROGRAM_FORMAT, jigsErrorCodes };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@jigs.design/runtime",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The program format, the types the server and the browser share, the sandboxed runtime, and the tree store.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/yoamomonstruos/pickle.git",
8
+ "url": "git+https://github.com/yoamomonstruos/jigs.git",
9
9
  "directory": "packages/runtime"
10
10
  },
11
11
  "type": "module",