@localess/schema 4.0.0-dev.20260905071322 → 4.0.0-dev.20260905085556

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/SKILL.md CHANGED
@@ -63,7 +63,7 @@ export type Content = InferContentData<typeof config>;
63
63
  | Export | Purpose |
64
64
  |---|---|
65
65
  | `defineEnum(definition)` | Define an ENUM schema. Identity function; injects `type: 'ENUM'`. |
66
- | `defineSchema(definition)` | Define a ROOT or NODE schema. Normalizes by-value refs (`source`, `schemas`) to id strings. Throws on duplicate field names. |
66
+ | `defineSchema(definition)` | Define a ROOT or NODE schema. Normalizes by-value refs (`source`, `schemas`) to id strings. Throws on duplicate field names. `previewField` is restricted to the names of the schema's own `fields` (falls back to `string` when `fields` is omitted). |
67
67
  | `defineField(field)` | Define a single field, narrowed by `kind`. Optional; catches a stray property from the wrong kind at the call site, unlike a bare field literal. Identity function. |
68
68
  | `defineConfig({ schemas })` | Register the full schema list — the unit the CLI loads and inference resolves against. Throws on duplicate schema ids. |
69
69
  | `validate(config)` | Non-throwing `{ ok, issues }` — ID/name patterns, reserved names, length limits, reference resolution. |
package/dist/define.d.ts CHANGED
@@ -100,8 +100,21 @@ type DefinedComponent<TId extends string, TType extends 'ROOT' | 'NODE', TFields
100
100
  * Define an ENUM schema. Identity function apart from injecting `type: 'ENUM'`;
101
101
  * exists to preserve literal types for inference.
102
102
  *
103
+ * - `id` — unique schema id; also what `OPTION`/`OPTIONS` fields reference via `source`
104
+ * - `values` — the fixed option set; each `{ name, value }` becomes one selectable option, and
105
+ * every `value` across the config becomes part of `InferEnum`'s literal union
106
+ *
103
107
  * @param definition the enum definition (id, values, optional display metadata)
104
108
  * @returns the definition with `type: 'ENUM'`, literal types preserved
109
+ *
110
+ * @example
111
+ * const Status = defineEnum({
112
+ * id: 'Status',
113
+ * values: [
114
+ * { name: 'Draft', value: 'draft' },
115
+ * { name: 'Published', value: 'published' },
116
+ * ],
117
+ * });
105
118
  */
106
119
  export declare function defineEnum<const TId extends string, const TValues extends readonly SchemaEnumValue[] | undefined = undefined>(definition: {
107
120
  id: TId;
@@ -119,8 +132,29 @@ export declare function defineEnum<const TId extends string, const TValues exten
119
132
  * (`source`, `schemas`) still happens exclusively in `defineSchema`, applied uniformly regardless
120
133
  * of a field's origin. See `docs/decisions/008-schema-package.md`.
121
134
  *
135
+ * Every `kind` accepts `name` (required), plus `displayName?`, `required?`, `description?`,
136
+ * `defaultValue?`, `translatable?`. Kind-specific extras:
137
+ * - `TEXT` / `TEXTAREA` / `RICH_TEXT` / `MARKDOWN` — `minLength?`, `maxLength?`
138
+ * - `NUMBER` — `minValue?`, `maxValue?`
139
+ * - `COLOR` / `DATE` / `DATETIME` / `BOOLEAN` / `LINK` — no extras
140
+ * - `OPTION` — `source` (required: an ENUM definition from `defineEnum`, or its id)
141
+ * - `OPTIONS` — `source` (required, same as `OPTION`), `minValues?`, `maxValues?`
142
+ * - `REFERENCE` / `REFERENCES` — `path?`
143
+ * - `ASSET` / `ASSETS` — `fileTypes?`, `fileType?`
144
+ * - `SCHEMA` / `SCHEMAS` — `schemas?` (allowed definitions from `defineSchema`, or their ids;
145
+ * every `NODE` schema in the config is allowed when omitted)
146
+ *
147
+ * Full field-kind reference, including the type each kind infers to: `docs/schema.md`.
148
+ *
122
149
  * @param field the field definition; `kind` selects which extra properties are allowed
123
150
  * @returns the field unchanged, with `name`/`kind`/extras narrowed to their literal types
151
+ *
152
+ * @example
153
+ * defineField({ name: 'title', kind: 'TEXT', required: true, maxLength: 100 });
154
+ * @example
155
+ * defineField({ name: 'status', kind: 'OPTION', source: Status }); // Status = defineEnum(...)
156
+ * @example
157
+ * defineField({ name: 'blocks', kind: 'SCHEMAS', schemas: [Button] }); // Button = defineSchema(...)
124
158
  */
125
159
  export declare function defineField<const TKind extends SchemaFieldKind, const TName extends string, const TField extends Omit<Extract<SchemaFieldInput, {
126
160
  kind: TKind;
@@ -133,14 +167,36 @@ export declare function defineField<const TKind extends SchemaFieldKind, const T
133
167
  name: TName;
134
168
  kind: TKind;
135
169
  } & TField>;
170
+ /** Union of a schema's own field names; falls back to plain `string` when `fields` is omitted. */
171
+ type FieldNameOf<TFields> = TFields extends readonly {
172
+ name: infer N extends string;
173
+ }[] ? N : string;
136
174
  /**
137
175
  * Define a ROOT (content type) or NODE (nested component) schema.
138
176
  * Normalizes by-value references (enum in `source`, components in `schemas`) to their id strings;
139
177
  * the returned type keeps those ids as literals for inference.
140
178
  *
179
+ * - `id` — unique schema id; also the `_schema` value on its inferred content type, and what
180
+ * `SCHEMA`/`SCHEMAS` fields reference via `schemas`
181
+ * - `type` — `'ROOT'` for a fetchable content type, `'NODE'` for a nested component only reachable
182
+ * through another schema's `SCHEMA`/`SCHEMAS` field
183
+ * - `previewField` — name of one of this schema's own fields, shown as its preview label in the
184
+ * Localess editor; restricted to the field names in `fields` (falls back to plain `string`
185
+ * when `fields` is omitted)
186
+ * - `fields` — ordered list of `defineField(...)` results and/or raw field literals; see
187
+ * `defineField` for the per-kind property reference
188
+ *
141
189
  * @param definition the schema definition; `type` selects ROOT or NODE
142
190
  * @returns the definition with references normalized to id strings, literal types preserved
143
191
  * @throws Error on duplicate field names — a programming error, not a validation concern
192
+ *
193
+ * @example
194
+ * const Button = defineSchema({
195
+ * id: 'Button',
196
+ * type: 'NODE',
197
+ * previewField: 'label',
198
+ * fields: [defineField({ name: 'label', kind: 'TEXT', required: true })],
199
+ * });
144
200
  */
145
201
  export declare function defineSchema<const TId extends string, const TType extends 'ROOT' | 'NODE', const TFields extends readonly SchemaFieldInput[] | undefined = undefined>(definition: {
146
202
  id: TId;
@@ -148,7 +204,7 @@ export declare function defineSchema<const TId extends string, const TType exten
148
204
  displayName?: string;
149
205
  description?: string;
150
206
  labels?: readonly string[];
151
- previewField?: string;
207
+ previewField?: FieldNameOf<TFields>;
152
208
  fields?: TFields;
153
209
  }): DefinedComponent<TId, TType, TFields>;
154
210
  /**
package/dist/index.js CHANGED
@@ -4,8 +4,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
4
  * Define an ENUM schema. Identity function apart from injecting `type: 'ENUM'`;
5
5
  * exists to preserve literal types for inference.
6
6
  *
7
+ * - `id` — unique schema id; also what `OPTION`/`OPTIONS` fields reference via `source`
8
+ * - `values` — the fixed option set; each `{ name, value }` becomes one selectable option, and
9
+ * every `value` across the config becomes part of `InferEnum`'s literal union
10
+ *
7
11
  * @param definition the enum definition (id, values, optional display metadata)
8
12
  * @returns the definition with `type: 'ENUM'`, literal types preserved
13
+ *
14
+ * @example
15
+ * const Status = defineEnum({
16
+ * id: 'Status',
17
+ * values: [
18
+ * { name: 'Draft', value: 'draft' },
19
+ * { name: 'Published', value: 'published' },
20
+ * ],
21
+ * });
9
22
  */
10
23
  function defineEnum(definition) {
11
24
  return {
@@ -22,8 +35,29 @@ function defineEnum(definition) {
22
35
  * (`source`, `schemas`) still happens exclusively in `defineSchema`, applied uniformly regardless
23
36
  * of a field's origin. See `docs/decisions/008-schema-package.md`.
24
37
  *
38
+ * Every `kind` accepts `name` (required), plus `displayName?`, `required?`, `description?`,
39
+ * `defaultValue?`, `translatable?`. Kind-specific extras:
40
+ * - `TEXT` / `TEXTAREA` / `RICH_TEXT` / `MARKDOWN` — `minLength?`, `maxLength?`
41
+ * - `NUMBER` — `minValue?`, `maxValue?`
42
+ * - `COLOR` / `DATE` / `DATETIME` / `BOOLEAN` / `LINK` — no extras
43
+ * - `OPTION` — `source` (required: an ENUM definition from `defineEnum`, or its id)
44
+ * - `OPTIONS` — `source` (required, same as `OPTION`), `minValues?`, `maxValues?`
45
+ * - `REFERENCE` / `REFERENCES` — `path?`
46
+ * - `ASSET` / `ASSETS` — `fileTypes?`, `fileType?`
47
+ * - `SCHEMA` / `SCHEMAS` — `schemas?` (allowed definitions from `defineSchema`, or their ids;
48
+ * every `NODE` schema in the config is allowed when omitted)
49
+ *
50
+ * Full field-kind reference, including the type each kind infers to: `docs/schema.md`.
51
+ *
25
52
  * @param field the field definition; `kind` selects which extra properties are allowed
26
53
  * @returns the field unchanged, with `name`/`kind`/extras narrowed to their literal types
54
+ *
55
+ * @example
56
+ * defineField({ name: 'title', kind: 'TEXT', required: true, maxLength: 100 });
57
+ * @example
58
+ * defineField({ name: 'status', kind: 'OPTION', source: Status }); // Status = defineEnum(...)
59
+ * @example
60
+ * defineField({ name: 'blocks', kind: 'SCHEMAS', schemas: [Button] }); // Button = defineSchema(...)
27
61
  */
28
62
  function defineField(field) {
29
63
  return field;
@@ -33,9 +67,27 @@ function defineField(field) {
33
67
  * Normalizes by-value references (enum in `source`, components in `schemas`) to their id strings;
34
68
  * the returned type keeps those ids as literals for inference.
35
69
  *
70
+ * - `id` — unique schema id; also the `_schema` value on its inferred content type, and what
71
+ * `SCHEMA`/`SCHEMAS` fields reference via `schemas`
72
+ * - `type` — `'ROOT'` for a fetchable content type, `'NODE'` for a nested component only reachable
73
+ * through another schema's `SCHEMA`/`SCHEMAS` field
74
+ * - `previewField` — name of one of this schema's own fields, shown as its preview label in the
75
+ * Localess editor; restricted to the field names in `fields` (falls back to plain `string`
76
+ * when `fields` is omitted)
77
+ * - `fields` — ordered list of `defineField(...)` results and/or raw field literals; see
78
+ * `defineField` for the per-kind property reference
79
+ *
36
80
  * @param definition the schema definition; `type` selects ROOT or NODE
37
81
  * @returns the definition with references normalized to id strings, literal types preserved
38
82
  * @throws Error on duplicate field names — a programming error, not a validation concern
83
+ *
84
+ * @example
85
+ * const Button = defineSchema({
86
+ * id: 'Button',
87
+ * type: 'NODE',
88
+ * previewField: 'label',
89
+ * fields: [defineField({ name: 'label', kind: 'TEXT', required: true })],
90
+ * });
39
91
  */
40
92
  function defineSchema(definition) {
41
93
  const seen = /* @__PURE__ */ new Set();
package/dist/index.mjs CHANGED
@@ -3,8 +3,21 @@
3
3
  * Define an ENUM schema. Identity function apart from injecting `type: 'ENUM'`;
4
4
  * exists to preserve literal types for inference.
5
5
  *
6
+ * - `id` — unique schema id; also what `OPTION`/`OPTIONS` fields reference via `source`
7
+ * - `values` — the fixed option set; each `{ name, value }` becomes one selectable option, and
8
+ * every `value` across the config becomes part of `InferEnum`'s literal union
9
+ *
6
10
  * @param definition the enum definition (id, values, optional display metadata)
7
11
  * @returns the definition with `type: 'ENUM'`, literal types preserved
12
+ *
13
+ * @example
14
+ * const Status = defineEnum({
15
+ * id: 'Status',
16
+ * values: [
17
+ * { name: 'Draft', value: 'draft' },
18
+ * { name: 'Published', value: 'published' },
19
+ * ],
20
+ * });
8
21
  */
9
22
  function defineEnum(definition) {
10
23
  return {
@@ -21,8 +34,29 @@ function defineEnum(definition) {
21
34
  * (`source`, `schemas`) still happens exclusively in `defineSchema`, applied uniformly regardless
22
35
  * of a field's origin. See `docs/decisions/008-schema-package.md`.
23
36
  *
37
+ * Every `kind` accepts `name` (required), plus `displayName?`, `required?`, `description?`,
38
+ * `defaultValue?`, `translatable?`. Kind-specific extras:
39
+ * - `TEXT` / `TEXTAREA` / `RICH_TEXT` / `MARKDOWN` — `minLength?`, `maxLength?`
40
+ * - `NUMBER` — `minValue?`, `maxValue?`
41
+ * - `COLOR` / `DATE` / `DATETIME` / `BOOLEAN` / `LINK` — no extras
42
+ * - `OPTION` — `source` (required: an ENUM definition from `defineEnum`, or its id)
43
+ * - `OPTIONS` — `source` (required, same as `OPTION`), `minValues?`, `maxValues?`
44
+ * - `REFERENCE` / `REFERENCES` — `path?`
45
+ * - `ASSET` / `ASSETS` — `fileTypes?`, `fileType?`
46
+ * - `SCHEMA` / `SCHEMAS` — `schemas?` (allowed definitions from `defineSchema`, or their ids;
47
+ * every `NODE` schema in the config is allowed when omitted)
48
+ *
49
+ * Full field-kind reference, including the type each kind infers to: `docs/schema.md`.
50
+ *
24
51
  * @param field the field definition; `kind` selects which extra properties are allowed
25
52
  * @returns the field unchanged, with `name`/`kind`/extras narrowed to their literal types
53
+ *
54
+ * @example
55
+ * defineField({ name: 'title', kind: 'TEXT', required: true, maxLength: 100 });
56
+ * @example
57
+ * defineField({ name: 'status', kind: 'OPTION', source: Status }); // Status = defineEnum(...)
58
+ * @example
59
+ * defineField({ name: 'blocks', kind: 'SCHEMAS', schemas: [Button] }); // Button = defineSchema(...)
26
60
  */
27
61
  function defineField(field) {
28
62
  return field;
@@ -32,9 +66,27 @@ function defineField(field) {
32
66
  * Normalizes by-value references (enum in `source`, components in `schemas`) to their id strings;
33
67
  * the returned type keeps those ids as literals for inference.
34
68
  *
69
+ * - `id` — unique schema id; also the `_schema` value on its inferred content type, and what
70
+ * `SCHEMA`/`SCHEMAS` fields reference via `schemas`
71
+ * - `type` — `'ROOT'` for a fetchable content type, `'NODE'` for a nested component only reachable
72
+ * through another schema's `SCHEMA`/`SCHEMAS` field
73
+ * - `previewField` — name of one of this schema's own fields, shown as its preview label in the
74
+ * Localess editor; restricted to the field names in `fields` (falls back to plain `string`
75
+ * when `fields` is omitted)
76
+ * - `fields` — ordered list of `defineField(...)` results and/or raw field literals; see
77
+ * `defineField` for the per-kind property reference
78
+ *
35
79
  * @param definition the schema definition; `type` selects ROOT or NODE
36
80
  * @returns the definition with references normalized to id strings, literal types preserved
37
81
  * @throws Error on duplicate field names — a programming error, not a validation concern
82
+ *
83
+ * @example
84
+ * const Button = defineSchema({
85
+ * id: 'Button',
86
+ * type: 'NODE',
87
+ * previewField: 'label',
88
+ * fields: [defineField({ name: 'label', kind: 'TEXT', required: true })],
89
+ * });
38
90
  */
39
91
  function defineSchema(definition) {
40
92
  const seen = /* @__PURE__ */ new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/schema",
3
- "version": "4.0.0-dev.20260905071322",
3
+ "version": "4.0.0-dev.20260905085556",
4
4
  "description": "Programmatic schema definitions for Localess with TypeScript content type inference.",
5
5
  "keywords": [
6
6
  "localess",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "license": "MIT",
45
45
  "dependencies": {
46
- "@localess/model": "4.0.0-dev.20260905071322"
46
+ "@localess/model": "4.0.0-dev.20260905085556"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^24",