@nubbin/core 0.1.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -1,38 +1,94 @@
1
1
  // src/NubbinIssueCode.ts
2
2
  var NubbinIssueCode = {
3
3
  // Registration — a block, catalog or registry the developer wrote cannot be used as written.
4
+ /** `defineBlock` was given a `version` that is not an integer of 1 or more. */
4
5
  BlockVersion: "block-version",
6
+ /** `defineBlock` was given a slot whose `min` is above its `max`, which no composition satisfies. */
5
7
  SlotBounds: "slot-bounds",
8
+ /** `createRegistry` found a slot's `allow` naming a block no registered block answers to. */
6
9
  SlotAllowUnknown: "slot-allow-unknown",
10
+ /** `createRegistry` was given two blocks claiming one name — the identity every node resolves through. */
7
11
  DuplicateBlockName: "duplicate-block-name",
12
+ /** `defineCatalog` found an entry's `defaults` do not satisfy that entry's own schema. */
8
13
  InvalidDefaults: "invalid-defaults",
14
+ /** `defineCatalog` found `ui.fields` naming a path the schema does not define. Check the spelling against the schema. */
9
15
  HintPathUnresolvable: "hint-path-unresolvable",
16
+ /**
17
+ * `defineCatalog` found a `data` hint with no single target: a path through `[]`, which names
18
+ * every member of an array, or two hints whose paths nest and would write one value twice.
19
+ */
10
20
  HintNotAddressable: "hint-not-addressable",
11
21
  // Schema — what the consumer brought does not answer the one door core reads a schema through.
22
+ /**
23
+ * A schema exposes no `~standard.validate`, or answers with a promise. Validation is
24
+ * synchronous at registration and at compile, so an async validator is refused rather than
25
+ * awaited.
26
+ */
12
27
  NotStandardSchema: "not-standard-schema",
28
+ /**
29
+ * A schema exposes no Standard JSON Schema converter, which field introspection needs — the
30
+ * studio reads a block's fields through it.
31
+ */
13
32
  NoJsonSchema: "no-json-schema",
14
33
  // Structure — the document's graph cannot become a tree.
34
+ /** The document's `roots` is empty, so it names no entry element and there is no tree to build. */
15
35
  NoRoots: "no-roots",
36
+ /**
37
+ * A node names a block neither the registry nor the catalog holds. Register the block, or
38
+ * correct the node's `block`.
39
+ */
16
40
  UnknownBlock: "unknown-block",
41
+ /** A slot or a `roots` entry references an id that `elements` does not hold. */
17
42
  DanglingChild: "dangling-child",
43
+ /** A node reaches back to one of its own ancestors, so the graph cannot flatten into a tree. */
18
44
  Cycle: "cycle",
45
+ /** No slot reaches the node from any root, so it would be dropped silently on compile. */
19
46
  Unreachable: "unreachable",
47
+ /** A slot the block never declared, or a child the slot's `allow` list rejects. */
20
48
  SlotNotAllowed: "slot-not-allowed",
49
+ /** A slot holds fewer children than its `min`. An omitted slot holds zero. */
21
50
  SlotMin: "slot-min",
51
+ /** A slot holds more children than its `max`. */
22
52
  SlotMax: "slot-max",
23
53
  // Props — the values a node carries, judged against the block's schema.
54
+ /**
55
+ * A node's props failed its schema, or parsed to something other than an object. `path` names
56
+ * the offending field.
57
+ */
24
58
  InvalidProps: "invalid-props",
59
+ /**
60
+ * A key the author wrote and the schema did not keep — almost always a typo, `heading` where
61
+ * the schema says `headline`. **Returned in `CompileResult.issues`, never thrown:** the
62
+ * artifact is valid and publishable without that key.
63
+ */
25
64
  UnknownProp: "unknown-prop",
26
65
  // Document operations — the caller named something the document does not hold.
66
+ /** `setNodeProp`, `addNode`, `removeNode` or `moveNode` named a node id no element backs. */
27
67
  NoSuchNode: "no-such-node",
68
+ /**
69
+ * `addNode` was given an id the document already uses. Reusing one would replace a node and
70
+ * redirect every slot that named it.
71
+ */
28
72
  DuplicateNodeId: "duplicate-node-id",
73
+ /**
74
+ * A prop path with no single target: an empty segment, an `[]`, or a descent into an array.
75
+ * Raised by `setAtPath` and by `setNodeProp`.
76
+ */
29
77
  PathNotAddressable: "path-not-addressable",
78
+ /**
79
+ * A route no request could match — no leading slash, a trailing slash, an empty or malformed
80
+ * segment, or a `*` that is not the last one. Raised by `compile` and by `parseMatchKind`.
81
+ */
30
82
  InvalidRoute: "invalid-route",
31
83
  // Render — the artifact and the registry serving it disagree.
84
+ /** `@nubbin/react`: the block registry has no importer for a block the artifact names. */
32
85
  BlockNotLoaded: "block-not-loaded",
86
+ /** `@nubbin/react`: a node declares holes and the render was given no `resolveHole`. */
33
87
  NoHoleResolver: "no-hole-resolver",
88
+ /** `@nubbin/react`: a block returned a Fragment, a composite, or several roots where one host element is required. */
34
89
  NotOneHostElement: "not-one-host-element",
35
90
  // Store — a write the store cannot honour.
91
+ /** A publish names a hash the store does not hold. Write the artifact before pointing a route at it. */
36
92
  ArtifactNotStored: "artifact-not-stored"
37
93
  };
38
94
 
@@ -57,7 +113,17 @@ var NubbinError = class extends Error {
57
113
  * Every refusal but `compile`'s carries exactly one issue; read `issues` for the rest.
58
114
  */
59
115
  code;
116
+ /**
117
+ * Every cause, in the order they were found, and never empty. This is what a log, a tracker or
118
+ * an editing surface serializes — each issue carries its own `code`, `at` and `path`.
119
+ */
60
120
  issues;
121
+ /**
122
+ * @param issues - The causes, first one first. `code` is taken from `issues[0]` and `message`
123
+ * is a summary of all of them.
124
+ * @throws {Error} A plain `Error`, not a `NubbinError`, when `issues` is empty — a refusal
125
+ * with no cause names nothing.
126
+ */
61
127
  constructor(issues) {
62
128
  const first = issues[0];
63
129
  if (first === void 0) {
@@ -175,6 +241,19 @@ function walkJsonSchema(node, basePath) {
175
241
 
176
242
  // src/adapters/zodAdapter.ts
177
243
  var zodAdapter = {
244
+ /**
245
+ * Every addressable path in a schema, as the field tree an editing surface renders.
246
+ *
247
+ * @param schema - The schema to read. It must expose the Standard JSON Schema converter —
248
+ * `~standard.jsonSchema` — which the spec has carried since 1.1.
249
+ * @returns One `FieldNode` per path, parent before child: dotted for object properties, `path[]`
250
+ * for an array's row shape, and a union's branch fields under the union's own path. The root
251
+ * has no entry. A path two union branches share is reported once, keeping the first kind seen.
252
+ * @throws {NubbinError} `no-json-schema` when the schema exposes no converter.
253
+ * @throws The converter's own error when the schema holds a type JSON Schema cannot represent —
254
+ * `z.date()`, for one. It is asked to throw rather than degrade, so an unrepresentable field
255
+ * fails at registration instead of arriving in the studio as a string field.
256
+ */
178
257
  describe(schema) {
179
258
  const fields = walkJsonSchema(projectJsonSchema(schema), "");
180
259
  const seen = /* @__PURE__ */ new Set();
@@ -795,7 +874,7 @@ function validateStructure(version, registry) {
795
874
  }
796
875
 
797
876
  // src/version.constants.ts
798
- var NUBBIN_VERSION = "0.1.0";
877
+ var NUBBIN_VERSION = "0.2.0";
799
878
 
800
879
  // src/compile.ts
801
880
  function compile(version, catalog, registry, route) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubbin/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "The Nubbin contract: define blocks, split catalog from registry, and compile a page document into an immutable artifact.",
5
5
  "keywords": [
6
6
  "nubbin",