Sign In

@devframes/json-render

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devframes/json-render - npm Package Compare versions

Comparing version
0.9.4
to
0.9.5
+83
dist/types-P1hZJnNo.d.mts
import { Catalog, InferCatalogComponents, InferComponentProps, Spec, UIElement } from "@json-render/core";
//#region src/view-ref.d.ts
/**
* A view backed by **live shared state**: the client subscribes to `stateKey`
* for the spec + state and re-renders on every update. This is what a
* node-authored view ({@link import('./node/create-view').createJsonRenderView})
* produces.
*/
interface JsonRenderViewStateRef {
/** Shared-state key the client subscribes to for the live spec + state. */
stateKey: string;
}
/**
* A view whose spec is embedded **inline** in the reference. It carries no
* shared-state key, so a client can synthesize a view entirely in the browser
* and hand it straight to a renderer — no `sharedState` round-trip. The spec is
* rendered as-is (static: local state and bindings still work, but there is no
* server-driven live update stream).
*/
interface JsonRenderViewInlineRef<SpecType extends DevframeJsonRenderSpec = DevframeJsonRenderSpec> {
/** The full spec, carried in the reference itself. */
spec: SpecType;
}
/**
* The serializable reference to a JSON-render view that crosses process /
* static boundaries — e.g. projected onto a hub dock entry. It carries **no
* functions**: either a {@link JsonRenderViewStateRef.stateKey shared-state key}
* the client subscribes through, or an {@link JsonRenderViewInlineRef.spec
* inline spec} rendered directly.
*/
type JsonRenderViewRef<SpecType extends DevframeJsonRenderSpec = DevframeJsonRenderSpec> = JsonRenderViewStateRef | JsonRenderViewInlineRef<SpecType>;
//#endregion
//#region src/types.d.ts
/**
* A Devframes JSON-render spec **is** an `@json-render/core` `Spec`: a flat
* `root` key, an `elements` map, and optional initial `state`. This alias is
* the Devframes-facing name; it does not add or remove fields.
*/
type DevframeJsonRenderSpec<Element extends UIElement = UIElement> = Omit<Spec, 'elements'> & {
elements: Record<string, Element>;
};
/** Derive a discriminated element union from every component in a catalog. */
type CatalogUIElement<CatalogType extends Catalog> = { [ComponentName in keyof InferCatalogComponents<CatalogType> & string]: UIElement<ComponentName, InferComponentProps<CatalogType, ComponentName>>; }[keyof InferCatalogComponents<CatalogType> & string];
/**
* A single JSON-Pointer patch to a view's `state` model. `path` is an
* RFC 6901 JSON Pointer relative to the state root (e.g. `/count`,
* `/user/name`). Structural spec changes replace the whole spec via
* `update` instead.
*/
interface JsonRenderStatePatch {
op: 'add' | 'remove' | 'replace';
/** JSON Pointer relative to the state root, e.g. `/count`. */
path: string;
value?: unknown;
}
/**
* A JSON-render view handle, returned by `createJsonRenderView`. Owns a
* server-side shared state carrying the live spec + state, and exposes the
* serializable {@link JsonRenderViewStateRef} that a hub dock (or any client
* transport) uses to locate it.
*/
interface JsonRenderView<SpecType extends DevframeJsonRenderSpec = DevframeJsonRenderSpec> {
/** Author-supplied stable id, unique within the view's scope. */
readonly id: string;
/** Human-facing label published in the view index (defaults to `id`). */
readonly title: string;
/** The serializable reference clients subscribe through. */
readonly ref: JsonRenderViewStateRef;
/** Replace the entire spec (a structural change replaces the whole spec). */
update: (spec: SpecType) => void;
/**
* Apply JSON-Pointer patches to the view's `state`. Travels as a
* shared-state patch (not a whole-spec snapshot), so only the changed
* paths cross the wire.
*/
patchState: (patches: JsonRenderStatePatch[]) => void;
/** Read the current spec (immutable). */
value: () => SpecType;
/** Unregister the shared state and its listeners. */
dispose: () => void;
}
//#endregion
export { JsonRenderViewRef as a, JsonRenderViewInlineRef as i, DevframeJsonRenderSpec as n, JsonRenderViewStateRef as o, JsonRenderView as r, CatalogUIElement as t };
+1
-1

@@ -1,2 +0,2 @@

import { i as JsonRenderViewRef, n as JsonRenderView } from "./types-CC2-FD2H.mjs";
import { a as JsonRenderViewRef, r as JsonRenderView } from "./types-P1hZJnNo.mjs";
import { DockRenderer, DockRendererMountOptions } from "@devframes/hub/client";

@@ -3,0 +3,0 @@ import { DevframeDockEntryBase } from "@devframes/hub/types";

import { Catalog, InferComponentProps, Spec, StateModel, StateStore, UIElement } from "./core.mjs";
import { a as JsonRenderViewStateRef, i as JsonRenderViewRef, n as JsonRenderView, r as JsonRenderViewInlineRef, t as DevframeJsonRenderSpec } from "./types-CC2-FD2H.mjs";
import { a as JsonRenderViewRef, i as JsonRenderViewInlineRef, n as DevframeJsonRenderSpec, o as JsonRenderViewStateRef, r as JsonRenderView, t as CatalogUIElement } from "./types-P1hZJnNo.mjs";
import { z } from "zod";

@@ -450,2 +450,2 @@ //#region src/prop-schemas.d.ts

//#endregion
export { BadgePropsSchema, type BaseComponentName, ButtonPropsSchema, CardPropsSchema, type Catalog, CodeBlockPropsSchema, DataTablePropsSchema, type DevframeJsonRenderSpec, DividerPropsSchema, IconPropsSchema, type InferComponentProps, JSON_RENDER_INDEX_KEY, type JsonRenderIndex, type JsonRenderIndexEntry, type JsonRenderView, type JsonRenderViewInlineRef, type JsonRenderViewRef, type JsonRenderViewStateRef, KeyValueTablePropsSchema, LinkPropsSchema, ProgressPropsSchema, SelectPropsSchema, type Spec, StackPropsSchema, type StateModel, type StateStore, SwitchPropsSchema, TabsPropsSchema, TextInputPropsSchema, TextPropsSchema, TreePropsSchema, type UIElement, baseCatalog, baseComponentNames, basePropSchemas, baseSchema };
export { BadgePropsSchema, type BaseComponentName, ButtonPropsSchema, CardPropsSchema, type Catalog, type CatalogUIElement, CodeBlockPropsSchema, DataTablePropsSchema, type DevframeJsonRenderSpec, DividerPropsSchema, IconPropsSchema, type InferComponentProps, JSON_RENDER_INDEX_KEY, type JsonRenderIndex, type JsonRenderIndexEntry, type JsonRenderView, type JsonRenderViewInlineRef, type JsonRenderViewRef, type JsonRenderViewStateRef, KeyValueTablePropsSchema, LinkPropsSchema, ProgressPropsSchema, SelectPropsSchema, type Spec, StackPropsSchema, type StateModel, type StateStore, SwitchPropsSchema, TabsPropsSchema, TextInputPropsSchema, TextPropsSchema, TreePropsSchema, type UIElement, baseCatalog, baseComponentNames, basePropSchemas, baseSchema };

@@ -1,6 +0,7 @@

import { n as JsonRenderView, t as DevframeJsonRenderSpec } from "../types-CC2-FD2H.mjs";
import { n as DevframeJsonRenderSpec, r as JsonRenderView } from "../types-P1hZJnNo.mjs";
import { StandardSchemaV1 } from "@standard-schema/spec";
import { DevframeNodeContext, DevframeScopedNodeContext } from "devframe";
//#region src/node/create-view.d.ts
/** Options for {@link createJsonRenderView}. */
interface CreateJsonRenderViewOptions {
interface CreateJsonRenderViewOptions<SpecType extends DevframeJsonRenderSpec = DevframeJsonRenderSpec> {
/**

@@ -13,3 +14,5 @@ * Stable, author-supplied id, unique within the view's scope. Forms the

/** The initial spec. */
spec: DevframeJsonRenderSpec;
spec: SpecType;
/** A replacement Standard Schema validator, or `false` to disable validation. */
schema?: StandardSchemaV1 | false;
/**

@@ -44,3 +47,3 @@ * Override the scope segment of the view's stable id. Defaults to the

*/
declare function createJsonRenderView(ctx: AnyContext, options: CreateJsonRenderViewOptions): JsonRenderView;
declare function createJsonRenderView<SpecType extends DevframeJsonRenderSpec = DevframeJsonRenderSpec>(ctx: AnyContext, options: CreateJsonRenderViewOptions<SpecType>): JsonRenderView<SpecType>;
//#endregion

@@ -305,2 +308,15 @@ //#region ../../node_modules/.pnpm/nostics@1.2.0/node_modules/nostics/dist/diagnostic-wduO7saY.d.mts

};
readonly DF0073: {
readonly why: (p: {
id: string;
issues: string;
}) => string;
readonly fix: "Match the authored spec to the Standard Schema passed to `createJsonRenderView`.";
};
readonly DF0074: {
readonly why: (p: {
id: string;
}) => string;
readonly fix: "Use a synchronous Standard Schema so initial creation and updates remain synchronous.";
};
}, readonly [(d: Diagnostic, { method }?: {

@@ -307,0 +323,0 @@ method?: "log" | "warn" | "error";

@@ -23,2 +23,10 @@ import { b as basePropSchemas, t as JSON_RENDER_INDEX_KEY } from "../view-index-CJ8aJJLZ.mjs";

fix: "Specs and state travel as strict JSON — remove functions, symbols, class instances, Map/Set, or circular references."
},
DF0073: {
why: (p) => `JSON-render view "${p.id}" does not match its configured schema: ${p.issues}`,
fix: "Match the authored spec to the Standard Schema passed to `createJsonRenderView`."
},
DF0074: {
why: (p) => `JSON-render view "${p.id}" uses an asynchronous Standard Schema.`,
fix: "Use a synchronous Standard Schema so initial creation and updates remain synchronous."
}

@@ -81,2 +89,23 @@ }

}
function formatStandardSchemaIssues(issues) {
return issues.map((issue) => {
return `${issue.path?.map((segment) => typeof segment === "object" ? String(segment.key) : String(segment)).join(".") || "(root)"}: ${issue.message}`;
}).join("; ");
}
function isPromise(value) {
return typeof value.then === "function";
}
function validateSpec(id, spec, schema) {
if (schema === false) return;
if (!schema) {
validateElementProps(id, spec);
return;
}
const result = schema["~standard"].validate(spec);
if (isPromise(result)) throw diagnostics.DF0074({ id });
if (result.issues) throw diagnostics.DF0073({
id,
issues: formatStandardSchemaIssues(result.issues)
});
}
function normalizeSpec(spec) {

@@ -116,3 +145,3 @@ return spec.state ? spec : {

const initial = normalizeSpec(options.spec);
validateElementProps(id, initial);
validateSpec(id, initial, options.schema);
assertJsonSerializable(id, initial);

@@ -146,3 +175,3 @@ const state = createSharedState({

const next = normalizeSpec(spec);
validateElementProps(id, next);
validateSpec(id, next, options.schema);
assertJsonSerializable(id, next);

@@ -149,0 +178,0 @@ state.mutate(() => next);

{
"name": "@devframes/json-render",
"type": "module",
"version": "0.9.4",
"version": "0.9.5",
"description": "Protocol layer for describing devframe views as JSON that any renderer can display.",

@@ -33,4 +33,4 @@ "author": "Anthony Fu <anthonyfu117@hotmail.com>",

"peerDependencies": {
"@devframes/hub": "0.9.4",
"devframe": "0.9.4"
"@devframes/hub": "0.9.5",
"devframe": "0.9.5"
},

@@ -44,2 +44,3 @@ "peerDependenciesMeta": {

"@json-render/core": "^0.19.0",
"@standard-schema/spec": "^1.1.0",
"zod": "^4.4.3"

@@ -50,4 +51,4 @@ },

"tsdown": "^0.22.14",
"devframe": "0.9.4",
"@devframes/hub": "0.9.4"
"@devframes/hub": "0.9.5",
"devframe": "0.9.5"
},

@@ -54,0 +55,0 @@ "scripts": {

import { Spec } from "@json-render/core";
//#region src/view-ref.d.ts
/**
* A view backed by **live shared state**: the client subscribes to `stateKey`
* for the spec + state and re-renders on every update. This is what a
* node-authored view ({@link import('./node/create-view').createJsonRenderView})
* produces.
*/
interface JsonRenderViewStateRef {
/** Shared-state key the client subscribes to for the live spec + state. */
stateKey: string;
}
/**
* A view whose spec is embedded **inline** in the reference. It carries no
* shared-state key, so a client can synthesize a view entirely in the browser
* and hand it straight to a renderer — no `sharedState` round-trip. The spec is
* rendered as-is (static: local state and bindings still work, but there is no
* server-driven live update stream).
*/
interface JsonRenderViewInlineRef {
/** The full spec, carried in the reference itself. */
spec: DevframeJsonRenderSpec;
}
/**
* The serializable reference to a JSON-render view that crosses process /
* static boundaries — e.g. projected onto a hub dock entry. It carries **no
* functions**: either a {@link JsonRenderViewStateRef.stateKey shared-state key}
* the client subscribes through, or an {@link JsonRenderViewInlineRef.spec
* inline spec} rendered directly.
*/
type JsonRenderViewRef = JsonRenderViewStateRef | JsonRenderViewInlineRef;
//#endregion
//#region src/types.d.ts
/**
* A Devframes JSON-render spec **is** an `@json-render/core` `Spec`: a flat
* `root` key, an `elements` map, and optional initial `state`. This alias is
* the Devframes-facing name; it does not add or remove fields.
*/
type DevframeJsonRenderSpec = Spec;
/**
* A single JSON-Pointer patch to a view's `state` model. `path` is an
* RFC 6901 JSON Pointer relative to the state root (e.g. `/count`,
* `/user/name`). Structural spec changes replace the whole spec via
* `update` instead.
*/
interface JsonRenderStatePatch {
op: 'add' | 'remove' | 'replace';
/** JSON Pointer relative to the state root, e.g. `/count`. */
path: string;
value?: unknown;
}
/**
* A JSON-render view handle, returned by `createJsonRenderView`. Owns a
* server-side shared state carrying the live spec + state, and exposes the
* serializable {@link JsonRenderViewStateRef} that a hub dock (or any client
* transport) uses to locate it.
*/
interface JsonRenderView {
/** Author-supplied stable id, unique within the view's scope. */
readonly id: string;
/** Human-facing label published in the view index (defaults to `id`). */
readonly title: string;
/** The serializable reference clients subscribe through. */
readonly ref: JsonRenderViewStateRef;
/** Replace the entire spec (a structural change replaces the whole spec). */
update: (spec: DevframeJsonRenderSpec) => void;
/**
* Apply JSON-Pointer patches to the view's `state`. Travels as a
* shared-state patch (not a whole-spec snapshot), so only the changed
* paths cross the wire.
*/
patchState: (patches: JsonRenderStatePatch[]) => void;
/** Read the current spec (immutable). */
value: () => DevframeJsonRenderSpec;
/** Unregister the shared state and its listeners. */
dispose: () => void;
}
//#endregion
export { JsonRenderViewStateRef as a, JsonRenderViewRef as i, JsonRenderView as n, JsonRenderViewInlineRef as r, DevframeJsonRenderSpec as t };