@jigs.design/host 0.3.0 → 0.3.1

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/host.js CHANGED
@@ -36,8 +36,8 @@ function defineHost(definition) {
36
36
  for (const [name, procedure] of Object.entries(procedures)) {
37
37
  if (!PROCEDURE_NAME.test(name)) throw new Error(`Procedure name "${name}" must be an identifier: letters, digits and underscores, starting with a letter`);
38
38
  if (procedure.input !== void 0) checkJsonSchema(`The input of "${name}"`, procedure.input);
39
- if (procedure.output !== void 0) checkJsonSchema(`The output of "${name}"`, procedure.output);
40
- if (procedure.kind !== "action" && procedure.projection !== void 0) checkJsonSchema(`The projection of "${name}"`, procedure.projection.schema);
39
+ if (procedure.output !== void 0) checkJsonSchema(procedure.kind === "data" ? `The schema of "${name}"` : `The output of "${name}"`, procedure.output);
40
+ if ((procedure.kind === "query" || procedure.kind === "mutation") && procedure.projection !== void 0) checkJsonSchema(`The projection of "${name}"`, procedure.projection.schema);
41
41
  if (procedure.kind === "mutation") {
42
42
  if (!isCallPolicy(procedure.policy)) throw new Error(`"${name}" has policy ${JSON.stringify(procedure.policy)}: write "allow", "confirm" or "deny"`);
43
43
  if (procedure.policy === "confirm" && procedure.confirm === void 0) throw new Error(`"${name}" asks for confirmation but has no confirm message: give it confirm: (input) => text`);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DesignGuidance, GuidanceInput, SituationDefinition, situation } from "./guidance.js";
2
2
  import { Catalog, CatalogProps, ComponentDefinition, ComponentDesign, ComponentNamed, PropDefinition, PropDefinitions, PropsOf, block, boolean, componentSchema, defineCatalog, defineComponent, handler, image, inline, link, list, none, number, oneOf, string } from "./catalog.js";
3
- import { ActionDefinition, CallPolicy, InputOf, InvalidationScope, InvalidationScopes, MutationDefinition, OutputOf, ProcedureDefinition, Procedures, Projection, QueryDefinition, action, dataSchema, isCallPolicy, mutation, query } from "./procedures.js";
3
+ import { ActionDefinition, CallPolicy, DataDefinition, InputOf, InvalidationScope, InvalidationScopes, MutationDefinition, OutputOf, ProcedureDefinition, Procedures, Projection, QueryDefinition, action, data, dataSchema, isCallPolicy, mutation, query } from "./procedures.js";
4
4
  import { DefineName, JigDefinition, PageName, jig } from "./jigs.js";
5
5
  import { ActionEvent, Host, PagePolicy, PolicyDirectives, contentSecurityPolicy, defineHost } from "./host.js";
6
- export { type ActionDefinition, type ActionEvent, type CallPolicy, type Catalog, type CatalogProps, type ComponentDefinition, type ComponentDesign, type ComponentNamed, type DefineName, type DesignGuidance, type GuidanceInput, type Host, type InputOf, type InvalidationScope, type InvalidationScopes, type JigDefinition, type MutationDefinition, type OutputOf, type PageName, type PagePolicy, type PolicyDirectives, type ProcedureDefinition, type Procedures, type Projection, type PropDefinition, type PropDefinitions, type PropsOf, type QueryDefinition, type SituationDefinition, action, block, boolean, componentSchema, contentSecurityPolicy, dataSchema, defineCatalog, defineComponent, defineHost, handler, image, inline, isCallPolicy, jig, link, list, mutation, none, number, oneOf, query, situation, string };
6
+ export { type ActionDefinition, type ActionEvent, type CallPolicy, type Catalog, type CatalogProps, type ComponentDefinition, type ComponentDesign, type ComponentNamed, type DataDefinition, type DefineName, type DesignGuidance, type GuidanceInput, type Host, type InputOf, type InvalidationScope, type InvalidationScopes, type JigDefinition, type MutationDefinition, type OutputOf, type PageName, type PagePolicy, type PolicyDirectives, type ProcedureDefinition, type Procedures, type Projection, type PropDefinition, type PropDefinitions, type PropsOf, type QueryDefinition, type SituationDefinition, action, block, boolean, componentSchema, contentSecurityPolicy, data, dataSchema, defineCatalog, defineComponent, defineHost, handler, image, inline, isCallPolicy, jig, link, list, mutation, none, number, oneOf, query, situation, string };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { situation } from "./guidance.js";
2
2
  import { block, boolean, componentSchema, defineCatalog, defineComponent, handler, image, inline, link, list, none, number, oneOf, string } from "./catalog.js";
3
- import { action, dataSchema, isCallPolicy, mutation, query } from "./procedures.js";
3
+ import { action, data, dataSchema, isCallPolicy, mutation, query } from "./procedures.js";
4
4
  import { contentSecurityPolicy, defineHost } from "./host.js";
5
5
  import { jig } from "./jigs.js";
6
- export { action, block, boolean, componentSchema, contentSecurityPolicy, dataSchema, defineCatalog, defineComponent, defineHost, handler, image, inline, isCallPolicy, jig, link, list, mutation, none, number, oneOf, query, situation, string };
6
+ export { action, block, boolean, componentSchema, contentSecurityPolicy, data, dataSchema, defineCatalog, defineComponent, defineHost, handler, image, inline, isCallPolicy, jig, link, list, mutation, none, number, oneOf, query, situation, string };
@@ -76,12 +76,25 @@ export interface ActionDefinition<TInput extends z.ZodType | undefined = z.ZodTy
76
76
  kind: "action";
77
77
  output: undefined;
78
78
  }
79
- export type ProcedureDefinition = ActionDefinition | MutationDefinition | QueryDefinition;
79
+ /**
80
+ * Data the embedding page supplies when it shows the view, read with
81
+ * `useQuery` like a query that takes no input. The server never runs it and
82
+ * refuses it on the wire; the page passes the value to `JigsView` as `data`
83
+ * and replaces it there, so nothing refetches it.
84
+ */
85
+ export interface DataDefinition<TOutput extends z.ZodType = z.ZodType> {
86
+ description: string;
87
+ input: undefined;
88
+ kind: "data";
89
+ /** The shape the page provides; the prompt shows it as `Data:`, as a query's output. */
90
+ output: TOutput;
91
+ }
92
+ export type ProcedureDefinition = ActionDefinition | DataDefinition | MutationDefinition | QueryDefinition;
80
93
  export type Procedures = Readonly<Record<string, ProcedureDefinition>>;
81
94
  /**
82
95
  * The schema of what a procedure's views read: its projection's when it has
83
- * one, else its output; `undefined` for an action or a procedure with no
84
- * output. The prompt shows it, and the member check reads against it.
96
+ * one, else its output (a provided slot's schema); `undefined` for an
97
+ * action or a procedure with no output. The prompt shows it, and the member check reads against it.
85
98
  */
86
99
  export declare function dataSchema(procedure: ProcedureDefinition): z.ZodType | undefined;
87
100
  /** What `run` receives for a procedure: the parsed input, or `undefined` when it takes none. */
@@ -144,5 +157,15 @@ export declare function action<TInput extends z.ZodType | undefined = undefined>
144
157
  description: string;
145
158
  input?: TInput;
146
159
  }): ActionDefinition<NoInfer<TInput>>;
160
+ /**
161
+ * A provided slot: data the page supplies per view, such as rows an agent
162
+ * already holds, in the shape `schema` describes. It takes no input and has
163
+ * no `run`. A host can later make it a `query()` of the same name and
164
+ * schema without changing a stored program.
165
+ */
166
+ export declare function data<TSchema extends z.ZodType>(definition: {
167
+ description: string;
168
+ schema: TSchema;
169
+ }): DataDefinition<TSchema>;
147
170
  //#endregion
148
171
  export {};
@@ -10,11 +10,15 @@ function isCallPolicy(policy) {
10
10
  }
11
11
  /**
12
12
  * The schema of what a procedure's views read: its projection's when it has
13
- * one, else its output; `undefined` for an action or a procedure with no
14
- * output. The prompt shows it, and the member check reads against it.
13
+ * one, else its output (a provided slot's schema); `undefined` for an
14
+ * action or a procedure with no output. The prompt shows it, and the member check reads against it.
15
15
  */
16
16
  function dataSchema(procedure) {
17
- return procedure.kind === "action" ? void 0 : procedure.projection?.schema ?? procedure.output;
17
+ switch (procedure.kind) {
18
+ case "action": return;
19
+ case "data": return procedure.output;
20
+ default: return procedure.projection?.schema ?? procedure.output;
21
+ }
18
22
  }
19
23
  function query(definition) {
20
24
  const input = definition.input;
@@ -57,5 +61,19 @@ function action(definition) {
57
61
  output: void 0
58
62
  };
59
63
  }
64
+ /**
65
+ * A provided slot: data the page supplies per view, such as rows an agent
66
+ * already holds, in the shape `schema` describes. It takes no input and has
67
+ * no `run`. A host can later make it a `query()` of the same name and
68
+ * schema without changing a stored program.
69
+ */
70
+ function data(definition) {
71
+ return {
72
+ description: definition.description,
73
+ input: void 0,
74
+ kind: "data",
75
+ output: definition.schema
76
+ };
77
+ }
60
78
  //#endregion
61
- export { action, dataSchema, isCallPolicy, mutation, query };
79
+ export { action, data, dataSchema, isCallPolicy, mutation, query };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jigs.design/host",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Define a host: the catalog a spec may draw, the procedures it may call, and the image hosts.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@jigs.design/protocol": "0.3.0"
28
+ "@jigs.design/protocol": "0.3.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "zod": "^4.0.0"