@estokad/schema 0.1.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/LICENSE +17 -0
- package/README.md +111 -0
- package/dist/compile.d.ts +9 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +357 -0
- package/dist/compile.js.map +1 -0
- package/dist/define.d.ts +20 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +13 -0
- package/dist/define.js.map +1 -0
- package/dist/generate.d.ts +8 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +268 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/modules.d.ts +5 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +34 -0
- package/dist/modules.js.map +1 -0
- package/dist/types.d.ts +240 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/zod.d.ts +14 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +140 -0
- package/dist/zod.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Copyright © 2026 Samarkand Industries OÜ. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Estokad is proprietary software. Source code in this repository is the
|
|
4
|
+
confidential intellectual property of Samarkand Industries OÜ
|
|
5
|
+
(registered Tallinn, Estonia).
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, or distribute this software is granted
|
|
8
|
+
only under a separate written agreement signed by Samarkand Industries
|
|
9
|
+
OÜ. Without such agreement, no license is granted, expressed or implied.
|
|
10
|
+
|
|
11
|
+
Public-facing components — the SDK packages published to npm under the
|
|
12
|
+
`@estokad/*` scope, and the SDKs' published documentation — are licensed
|
|
13
|
+
separately. See the LICENSE file inside each `packages/*` directory or
|
|
14
|
+
the package's npm registry page for the terms that apply to that
|
|
15
|
+
specific package.
|
|
16
|
+
|
|
17
|
+
Contact: legal@samarkandindustries.com
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
## @estokad/schema
|
|
2
|
+
|
|
3
|
+
`defineType()`, `defineEmbedded()`, all 16 field types from `docs/schema-system.md` § 3, and the JSON IR compiler.
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
7
|
+
M1.1: package complete. 15 tests passing. Pure TypeScript, no I/O. The CLI (M1.2) wraps this with file loading; the API (M1.3) consumes the IR for content type registration and Zod-based validation.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineType, defineEmbedded, compile } from '@estokad/schema'
|
|
13
|
+
|
|
14
|
+
const seo = defineEmbedded({
|
|
15
|
+
name: 'seo',
|
|
16
|
+
title: 'SEO',
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: 'title', type: 'text', max: 60 },
|
|
19
|
+
{ name: 'description', type: 'text', max: 160 },
|
|
20
|
+
{ name: 'ogImage', type: 'asset' },
|
|
21
|
+
],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const author = defineType({
|
|
25
|
+
name: 'author',
|
|
26
|
+
title: 'Author',
|
|
27
|
+
fields: [
|
|
28
|
+
{ name: 'name', type: 'text', required: true },
|
|
29
|
+
{ name: 'role', type: 'text' },
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const pressRelease = defineType({
|
|
34
|
+
name: 'pressRelease',
|
|
35
|
+
title: 'Press release',
|
|
36
|
+
displayField: 'title',
|
|
37
|
+
previewUrl: '/press/{slug}',
|
|
38
|
+
fields: [
|
|
39
|
+
{ name: 'title', type: 'text', max: 140, required: true, localized: true },
|
|
40
|
+
{ name: 'slug', type: 'slug', source: 'title', required: true },
|
|
41
|
+
{ name: 'body', type: 'richText', required: true },
|
|
42
|
+
{ name: 'category', type: 'enum', options: ['announcement', 'results', 'leadership'] },
|
|
43
|
+
{ name: 'author', type: 'reference', to: 'author' },
|
|
44
|
+
{ name: 'publishedAt', type: 'datetime' },
|
|
45
|
+
{ name: 'seo', type: 'embedded', of: seo },
|
|
46
|
+
],
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const ir = compile([author, pressRelease])
|
|
50
|
+
// ir is an array of TypeIR — one per top-level type plus any embedded types
|
|
51
|
+
// hoisted from { type: 'embedded', of: ... } references.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Pass a `state` map to preserve UUIDs across runs (rename detection):
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import type { SchemaState } from '@estokad/schema'
|
|
58
|
+
|
|
59
|
+
const state: SchemaState = {
|
|
60
|
+
types: {
|
|
61
|
+
pressRelease: {
|
|
62
|
+
id: '<uuid from previous compile>',
|
|
63
|
+
fields: { title: '<uuid>', slug: '<uuid>' /* ... */ },
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const ir = compile([pressRelease], { state })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The CLI persists this map to `.estokad/schema-state.json`; that lands in M1.2.
|
|
72
|
+
|
|
73
|
+
## Field types
|
|
74
|
+
|
|
75
|
+
All 16 from `docs/schema-system.md` § 3:
|
|
76
|
+
|
|
77
|
+
| `type` value | Notes |
|
|
78
|
+
| --------------- | ----------------------------------------------------------------- |
|
|
79
|
+
| `text` | `max`, `min`, `multiline`, `pattern` (RegExp or string) |
|
|
80
|
+
| `richText` | `features` whitelist |
|
|
81
|
+
| `number` | `min`, `max`, `integer` |
|
|
82
|
+
| `boolean` | — |
|
|
83
|
+
| `datetime` | `min`, `max` (ISO 8601) |
|
|
84
|
+
| `date` | `min`, `max` |
|
|
85
|
+
| `slug` | `source` (must point at a text field on the same type), `pattern` |
|
|
86
|
+
| `asset` | `accept` (MIME glob list), `maxSize` (bytes) |
|
|
87
|
+
| `assetList` | `asset` options + `min`, `max` count |
|
|
88
|
+
| `reference` | `to` (target type name), `crossSpace` |
|
|
89
|
+
| `referenceList` | `reference` options + `min`, `max` count |
|
|
90
|
+
| `enum` | `options` (non-empty unique strings) |
|
|
91
|
+
| `geoPoint` | `{ lat, lng }` |
|
|
92
|
+
| `embedded` | `of` (an `EmbeddedDefinition` from `defineEmbedded()`) |
|
|
93
|
+
| `json` | escape hatch; discouraged |
|
|
94
|
+
| `markdown` | simpler than `richText` for migrated content |
|
|
95
|
+
|
|
96
|
+
Common options on every field: `required`, `default`, `hint`, `localized`, `readOnly`, `condition`, `validate`.
|
|
97
|
+
|
|
98
|
+
## What this package does not do
|
|
99
|
+
|
|
100
|
+
- File I/O (the CLI handles `.estokad/schema-state.json` and `schemas/*.ts` loading) — M1.2
|
|
101
|
+
- Zod schema generation for runtime data validation — M1.3
|
|
102
|
+
- GraphQL/REST handler registration — M2.x
|
|
103
|
+
- The Studio's visual schema builder UI — M1.5
|
|
104
|
+
|
|
105
|
+
## Documentation
|
|
106
|
+
|
|
107
|
+
Full reference at [`docs.estokad.com/schema`](https://docs.estokad.com/docs/schema) and [`docs.estokad.com/schema/define-type`](https://docs.estokad.com/docs/schema/define-type).
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
Apache-2.0. Estokad is a Samarkand Industries OÜ product.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyDefinition, SchemaState, TypeIR } from './types.js';
|
|
2
|
+
export interface CompileOptions {
|
|
3
|
+
readonly state?: SchemaState;
|
|
4
|
+
}
|
|
5
|
+
export declare function compile(definitions: ReadonlyArray<AnyDefinition>, options?: CompileOptions): TypeIR[];
|
|
6
|
+
export declare class SchemaError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,aAAa,EAGb,WAAW,EAEX,MAAM,EAEP,MAAM,YAAY,CAAA;AAGnB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAA;CAC7B;AAED,wBAAgB,OAAO,CACrB,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,EACzC,OAAO,GAAE,cAAmB,GAC3B,MAAM,EAAE,CAIV;AAgYD,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
// compile() — the single entry point that turns user-facing TypeDefinitions
|
|
2
|
+
// and EmbeddedDefinitions into the JSON IR documented in
|
|
3
|
+
// docs/schema-system.md § 5.
|
|
4
|
+
//
|
|
5
|
+
// What it does, in order:
|
|
6
|
+
// 1. Collect all defined embedded types (referenced via { type: 'embedded',
|
|
7
|
+
// of: <embeddedDef> }) so they end up in the IR alongside top-level types.
|
|
8
|
+
// 2. Validate the schema set: name uniqueness, reference targets exist, no
|
|
9
|
+
// circular embedding, internal consistency.
|
|
10
|
+
// 3. Allocate stable UUIDs from the optional state map (so renames in code
|
|
11
|
+
// don't lose identity); generate v4 UUIDs for anything new.
|
|
12
|
+
// 4. Emit the IR — one TypeIR per top-level type or embedded type, in the
|
|
13
|
+
// order they were declared.
|
|
14
|
+
//
|
|
15
|
+
// The compiler does not produce Zod schemas (that lands alongside the API in
|
|
16
|
+
// M1.3) and does not load files (the CLI handles I/O in M1.2). compile() is
|
|
17
|
+
// pure: same input + same state -> same output.
|
|
18
|
+
import { randomUUID } from 'node:crypto';
|
|
19
|
+
import { IR_SCHEMA_URL } from './types.js';
|
|
20
|
+
export function compile(definitions, options = {}) {
|
|
21
|
+
const collected = collect(definitions);
|
|
22
|
+
validate(collected);
|
|
23
|
+
return collected.map((def) => emit(def, options.state));
|
|
24
|
+
}
|
|
25
|
+
// --- collection: walk fields, hoist embedded references ------------------
|
|
26
|
+
function collect(definitions) {
|
|
27
|
+
const seen = new Map();
|
|
28
|
+
for (const def of definitions) {
|
|
29
|
+
if (seen.has(def.name)) {
|
|
30
|
+
throw new SchemaError(`Duplicate definition '${def.name}'. Each type and embedded must have a unique name.`);
|
|
31
|
+
}
|
|
32
|
+
seen.set(def.name, def);
|
|
33
|
+
}
|
|
34
|
+
// Hoist embedded types referenced via { type: 'embedded', of: ... } so
|
|
35
|
+
// callers don't have to remember to pass them. If they pass both an
|
|
36
|
+
// explicit and an inline reference, the explicit one wins.
|
|
37
|
+
for (const def of definitions) {
|
|
38
|
+
for (const field of def.fields) {
|
|
39
|
+
if (field.type === 'embedded') {
|
|
40
|
+
const existing = seen.get(field.of.name);
|
|
41
|
+
if (existing && existing !== field.of) {
|
|
42
|
+
throw new SchemaError(`Embedded '${field.of.name}' is referenced by '${def.name}.${field.name}' but ` +
|
|
43
|
+
`a different definition with the same name was passed to compile(). Pass the ` +
|
|
44
|
+
`same object both times, or remove the explicit pass.`);
|
|
45
|
+
}
|
|
46
|
+
if (!existing) {
|
|
47
|
+
seen.set(field.of.name, field.of);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return Array.from(seen.values());
|
|
53
|
+
}
|
|
54
|
+
// --- validation ----------------------------------------------------------
|
|
55
|
+
function validate(definitions) {
|
|
56
|
+
const byName = new Map(definitions.map((d) => [d.name, d]));
|
|
57
|
+
for (const def of definitions) {
|
|
58
|
+
assertCamelCase(def.name, `definition name`);
|
|
59
|
+
assertNonEmpty(def.title, `${def.name} must have a non-empty title`);
|
|
60
|
+
const fieldNames = new Set();
|
|
61
|
+
for (const field of def.fields) {
|
|
62
|
+
assertCamelCase(field.name, `${def.name}.${field.name} field name`);
|
|
63
|
+
if (fieldNames.has(field.name)) {
|
|
64
|
+
throw new SchemaError(`Duplicate field '${def.name}.${field.name}'.`);
|
|
65
|
+
}
|
|
66
|
+
fieldNames.add(field.name);
|
|
67
|
+
validateField(def, field, byName);
|
|
68
|
+
}
|
|
69
|
+
if (def.__kind === 'type' && def.displayField) {
|
|
70
|
+
if (!fieldNames.has(def.displayField)) {
|
|
71
|
+
throw new SchemaError(`${def.name}.displayField references missing field '${def.displayField}'.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Cycle check on embedded references — an embedded type can't transitively
|
|
76
|
+
// contain itself. Top-level types can reference each other freely (entry
|
|
77
|
+
// references are resolved via UUIDs at query time, not statically).
|
|
78
|
+
detectEmbeddedCycles(definitions);
|
|
79
|
+
}
|
|
80
|
+
function validateField(parent, field, byName) {
|
|
81
|
+
const path = `${parent.name}.${field.name}`;
|
|
82
|
+
switch (field.type) {
|
|
83
|
+
case 'text':
|
|
84
|
+
case 'markdown': {
|
|
85
|
+
if (field.type === 'text' &&
|
|
86
|
+
field.min != null &&
|
|
87
|
+
field.max != null &&
|
|
88
|
+
field.min > field.max) {
|
|
89
|
+
throw new SchemaError(`${path}: min (${field.min}) must be <= max (${field.max}).`);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
case 'number': {
|
|
94
|
+
if (field.min != null && field.max != null && field.min > field.max) {
|
|
95
|
+
throw new SchemaError(`${path}: min (${field.min}) must be <= max (${field.max}).`);
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
case 'slug': {
|
|
100
|
+
const sourceField = parent.fields.find((f) => f.name === field.source);
|
|
101
|
+
if (!sourceField) {
|
|
102
|
+
throw new SchemaError(`${path}: source '${field.source}' must reference a field on the same type.`);
|
|
103
|
+
}
|
|
104
|
+
if (sourceField.type !== 'text') {
|
|
105
|
+
throw new SchemaError(`${path}: source '${field.source}' must be a text field, got ${sourceField.type}.`);
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
case 'reference':
|
|
110
|
+
case 'referenceList': {
|
|
111
|
+
// Polymorphic referenceList accepts an array of target type names
|
|
112
|
+
// (M1.4b). Single-target reference still requires a string. Both
|
|
113
|
+
// are validated against the same byName index.
|
|
114
|
+
const targets = field.type === 'referenceList' && Array.isArray(field.to)
|
|
115
|
+
? field.to
|
|
116
|
+
: [field.to];
|
|
117
|
+
if (targets.length === 0) {
|
|
118
|
+
throw new SchemaError(`${path}: at least one reference target is required.`);
|
|
119
|
+
}
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
for (const targetName of targets) {
|
|
122
|
+
if (seen.has(targetName)) {
|
|
123
|
+
throw new SchemaError(`${path}: duplicate reference target '${targetName}'.`);
|
|
124
|
+
}
|
|
125
|
+
seen.add(targetName);
|
|
126
|
+
const target = byName.get(targetName);
|
|
127
|
+
if (!target) {
|
|
128
|
+
throw new SchemaError(`${path}: reference target '${targetName}' is not defined in this schema set.`);
|
|
129
|
+
}
|
|
130
|
+
if (target.__kind === 'embedded') {
|
|
131
|
+
throw new SchemaError(`${path}: reference target '${targetName}' is an embedded type. ` +
|
|
132
|
+
`Embedded types are referenced via { type: 'embedded', of: ... }, not { type: 'reference', to: ... }.`);
|
|
133
|
+
}
|
|
134
|
+
if (target.isSingleton && field.type === 'referenceList') {
|
|
135
|
+
throw new SchemaError(`${path}: cannot list-reference singleton '${targetName}'. Use { type: 'reference', to } instead.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
case 'enum': {
|
|
141
|
+
if (field.options.length === 0) {
|
|
142
|
+
throw new SchemaError(`${path}: enum must have at least one option.`);
|
|
143
|
+
}
|
|
144
|
+
const optionSet = new Set(field.options);
|
|
145
|
+
if (optionSet.size !== field.options.length) {
|
|
146
|
+
throw new SchemaError(`${path}: enum options must be unique.`);
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
case 'embedded': {
|
|
151
|
+
// The collector should have ensured of.name is registered.
|
|
152
|
+
if (!byName.has(field.of.name)) {
|
|
153
|
+
throw new SchemaError(`${path}: embedded target '${field.of.name}' was not collected.`);
|
|
154
|
+
}
|
|
155
|
+
if (byName.get(field.of.name)?.__kind !== 'embedded') {
|
|
156
|
+
throw new SchemaError(`${path}: embedded target '${field.of.name}' must be created with defineEmbedded().`);
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
case 'assetList':
|
|
161
|
+
case 'asset':
|
|
162
|
+
case 'richText':
|
|
163
|
+
case 'boolean':
|
|
164
|
+
case 'datetime':
|
|
165
|
+
case 'date':
|
|
166
|
+
case 'geoPoint':
|
|
167
|
+
case 'json':
|
|
168
|
+
return;
|
|
169
|
+
default: {
|
|
170
|
+
// Exhaustiveness: TypeScript narrows `field` to never if we've handled
|
|
171
|
+
// every variant. If a new field type is added without a case, this fails
|
|
172
|
+
// at compile time.
|
|
173
|
+
const _exhaustive = field;
|
|
174
|
+
throw new SchemaError(`Unhandled field type: ${JSON.stringify(_exhaustive)}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function detectEmbeddedCycles(definitions) {
|
|
179
|
+
const byName = new Map(definitions.map((d) => [d.name, d]));
|
|
180
|
+
function walk(def, stack) {
|
|
181
|
+
if (stack.includes(def.name)) {
|
|
182
|
+
throw new SchemaError(`Circular embedding: ${stack.join(' -> ')} -> ${def.name}. ` +
|
|
183
|
+
`Embedded types cannot contain themselves transitively.`);
|
|
184
|
+
}
|
|
185
|
+
const next = [...stack, def.name];
|
|
186
|
+
for (const field of def.fields) {
|
|
187
|
+
if (field.type === 'embedded') {
|
|
188
|
+
const target = byName.get(field.of.name);
|
|
189
|
+
if (target?.__kind === 'embedded') {
|
|
190
|
+
walk(target, next);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
for (const def of definitions) {
|
|
196
|
+
if (def.__kind === 'embedded') {
|
|
197
|
+
walk(def, []);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// --- emission: produce the IR --------------------------------------------
|
|
202
|
+
function emit(def, state) {
|
|
203
|
+
const stateEntry = state?.types[def.name];
|
|
204
|
+
const id = stateEntry?.id ?? randomUUID();
|
|
205
|
+
return {
|
|
206
|
+
$schema: IR_SCHEMA_URL,
|
|
207
|
+
id,
|
|
208
|
+
name: def.name,
|
|
209
|
+
title: def.title,
|
|
210
|
+
...(def.description !== undefined && { description: def.description }),
|
|
211
|
+
...(def.__kind === 'type' &&
|
|
212
|
+
def.icon !== undefined && {
|
|
213
|
+
icon: def.icon,
|
|
214
|
+
}),
|
|
215
|
+
isSingleton: def.__kind === 'type' && def.isSingleton === true,
|
|
216
|
+
isEmbedded: def.__kind === 'embedded',
|
|
217
|
+
...(def.__kind === 'type' &&
|
|
218
|
+
def.displayField !== undefined && {
|
|
219
|
+
displayField: def.displayField,
|
|
220
|
+
}),
|
|
221
|
+
...(def.__kind === 'type' &&
|
|
222
|
+
def.previewUrl !== undefined && {
|
|
223
|
+
previewUrl: def.previewUrl,
|
|
224
|
+
}),
|
|
225
|
+
fields: def.fields.map((field) => emitField(field, stateEntry)),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function emitField(field, stateEntry) {
|
|
229
|
+
const id = stateEntry?.fields[field.name] ?? randomUUID();
|
|
230
|
+
const base = {
|
|
231
|
+
id,
|
|
232
|
+
name: field.name,
|
|
233
|
+
...(field.required !== undefined && { required: field.required }),
|
|
234
|
+
...(field.default !== undefined && { default: field.default }),
|
|
235
|
+
...(field.hint !== undefined && { hint: field.hint }),
|
|
236
|
+
...(field.localized !== undefined && { localized: field.localized }),
|
|
237
|
+
...(field.readOnly !== undefined && { readOnly: field.readOnly }),
|
|
238
|
+
};
|
|
239
|
+
switch (field.type) {
|
|
240
|
+
case 'text':
|
|
241
|
+
return {
|
|
242
|
+
...base,
|
|
243
|
+
type: 'text',
|
|
244
|
+
...(field.max !== undefined && { max: field.max }),
|
|
245
|
+
...(field.min !== undefined && { min: field.min }),
|
|
246
|
+
...(field.multiline !== undefined && { multiline: field.multiline }),
|
|
247
|
+
...(field.pattern !== undefined && { pattern: serializePattern(field.pattern) }),
|
|
248
|
+
};
|
|
249
|
+
case 'richText':
|
|
250
|
+
return {
|
|
251
|
+
...base,
|
|
252
|
+
type: 'richText',
|
|
253
|
+
...(field.features !== undefined && { features: field.features }),
|
|
254
|
+
};
|
|
255
|
+
case 'number':
|
|
256
|
+
return {
|
|
257
|
+
...base,
|
|
258
|
+
type: 'number',
|
|
259
|
+
...(field.min !== undefined && { min: field.min }),
|
|
260
|
+
...(field.max !== undefined && { max: field.max }),
|
|
261
|
+
...(field.integer !== undefined && { integer: field.integer }),
|
|
262
|
+
};
|
|
263
|
+
case 'boolean':
|
|
264
|
+
return { ...base, type: 'boolean' };
|
|
265
|
+
case 'datetime':
|
|
266
|
+
return {
|
|
267
|
+
...base,
|
|
268
|
+
type: 'datetime',
|
|
269
|
+
...(field.min !== undefined && { min: field.min }),
|
|
270
|
+
...(field.max !== undefined && { max: field.max }),
|
|
271
|
+
};
|
|
272
|
+
case 'date':
|
|
273
|
+
return {
|
|
274
|
+
...base,
|
|
275
|
+
type: 'date',
|
|
276
|
+
...(field.min !== undefined && { min: field.min }),
|
|
277
|
+
...(field.max !== undefined && { max: field.max }),
|
|
278
|
+
};
|
|
279
|
+
case 'slug':
|
|
280
|
+
return {
|
|
281
|
+
...base,
|
|
282
|
+
type: 'slug',
|
|
283
|
+
source: field.source,
|
|
284
|
+
...(field.pattern !== undefined && { pattern: serializePattern(field.pattern) }),
|
|
285
|
+
};
|
|
286
|
+
case 'asset':
|
|
287
|
+
return {
|
|
288
|
+
...base,
|
|
289
|
+
type: 'asset',
|
|
290
|
+
...(field.accept !== undefined && { accept: field.accept }),
|
|
291
|
+
...(field.maxSize !== undefined && { maxSize: field.maxSize }),
|
|
292
|
+
};
|
|
293
|
+
case 'assetList':
|
|
294
|
+
return {
|
|
295
|
+
...base,
|
|
296
|
+
type: 'assetList',
|
|
297
|
+
...(field.accept !== undefined && { accept: field.accept }),
|
|
298
|
+
...(field.maxSize !== undefined && { maxSize: field.maxSize }),
|
|
299
|
+
...(field.max !== undefined && { max: field.max }),
|
|
300
|
+
...(field.min !== undefined && { min: field.min }),
|
|
301
|
+
};
|
|
302
|
+
case 'reference':
|
|
303
|
+
return {
|
|
304
|
+
...base,
|
|
305
|
+
type: 'reference',
|
|
306
|
+
to: field.to,
|
|
307
|
+
...(field.crossSpace !== undefined && { crossSpace: field.crossSpace }),
|
|
308
|
+
};
|
|
309
|
+
case 'referenceList':
|
|
310
|
+
return {
|
|
311
|
+
...base,
|
|
312
|
+
type: 'referenceList',
|
|
313
|
+
// Pass both shapes through unchanged (M1.4b). Authoring code
|
|
314
|
+
// can write `to: 'image'` for a single-target list or
|
|
315
|
+
// `to: ['image', 'quote', 'title']` for a polymorphic blocks
|
|
316
|
+
// container; readers should normalise via toArray() in
|
|
317
|
+
// resolve.ts when they need an iterable form.
|
|
318
|
+
to: field.to,
|
|
319
|
+
...(field.crossSpace !== undefined && { crossSpace: field.crossSpace }),
|
|
320
|
+
...(field.max !== undefined && { max: field.max }),
|
|
321
|
+
...(field.min !== undefined && { min: field.min }),
|
|
322
|
+
};
|
|
323
|
+
case 'enum':
|
|
324
|
+
return { ...base, type: 'enum', options: field.options };
|
|
325
|
+
case 'geoPoint':
|
|
326
|
+
return { ...base, type: 'geoPoint' };
|
|
327
|
+
case 'embedded':
|
|
328
|
+
return { ...base, type: 'embedded', of: field.of.name };
|
|
329
|
+
case 'json':
|
|
330
|
+
return { ...base, type: 'json' };
|
|
331
|
+
case 'markdown':
|
|
332
|
+
return { ...base, type: 'markdown' };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function serializePattern(p) {
|
|
336
|
+
return p instanceof RegExp ? p.source : p;
|
|
337
|
+
}
|
|
338
|
+
// --- helpers -------------------------------------------------------------
|
|
339
|
+
const CAMEL_CASE = /^[a-z][a-zA-Z0-9]*$/;
|
|
340
|
+
function assertCamelCase(name, label) {
|
|
341
|
+
if (!CAMEL_CASE.test(name)) {
|
|
342
|
+
throw new SchemaError(`${label} '${name}' must be camelCase ([a-z][a-zA-Z0-9]*). The IR uses this name as ` +
|
|
343
|
+
`the JSON property and SDK accessor.`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function assertNonEmpty(value, message) {
|
|
347
|
+
if (!value || value.trim() === '') {
|
|
348
|
+
throw new SchemaError(message);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
export class SchemaError extends Error {
|
|
352
|
+
constructor(message) {
|
|
353
|
+
super(message);
|
|
354
|
+
this.name = 'SchemaError';
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yDAAyD;AACzD,6BAA6B;AAC7B,EAAE;AACF,0BAA0B;AAC1B,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,iDAAiD;AACjD,6EAA6E;AAC7E,iEAAiE;AACjE,4EAA4E;AAC5E,iCAAiC;AACjC,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,gDAAgD;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAWxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAM1C,MAAM,UAAU,OAAO,CACrB,WAAyC,EACzC,UAA0B,EAAE;IAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IACtC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACnB,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;AACzD,CAAC;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IAAI,EAAE,UAAU,EAAE,CAAA;IACxC,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAkB;IAC1C,OAAO,CAAC,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,4EAA4E;AAE5E,MAAM,UAAU,GAAG,qBAAqB,CAAA;AAExC,SAAS,eAAe,CAAC,IAAY,EAAE,KAAa;IAClD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,WAAW,CACnB,GAAG,KAAK,KAAK,IAAI,oEAAoE;YACnF,qCAAqC,CACxC,CAAA;IACH,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,OAAe;IACpD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;AACH,CAAC;AAED,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF"}
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EmbeddedDefinition, Field, TypeDefinition } from './types.js';
|
|
2
|
+
export interface DefineTypeInput {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly description?: string;
|
|
6
|
+
readonly icon?: string;
|
|
7
|
+
readonly isSingleton?: boolean;
|
|
8
|
+
readonly displayField?: string;
|
|
9
|
+
readonly previewUrl?: string;
|
|
10
|
+
readonly fields: ReadonlyArray<Field>;
|
|
11
|
+
}
|
|
12
|
+
export interface DefineEmbeddedInput {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly title: string;
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
readonly fields: ReadonlyArray<Field>;
|
|
17
|
+
}
|
|
18
|
+
export declare function defineType(input: DefineTypeInput): TypeDefinition;
|
|
19
|
+
export declare function defineEmbedded(input: DefineEmbeddedInput): EmbeddedDefinition;
|
|
20
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;CACtC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,cAAc,CAEjE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,kBAAkB,CAE7E"}
|
package/dist/define.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// defineType() and defineEmbedded() are declarative collectors.
|
|
2
|
+
//
|
|
3
|
+
// They tag the user's input with __kind so the compiler can distinguish them
|
|
4
|
+
// at runtime, but they don't validate or normalize — that's compile()'s job.
|
|
5
|
+
// This keeps the developer's stack trace clean when things go wrong: errors
|
|
6
|
+
// surface at compile, where context is richest, not at module load.
|
|
7
|
+
export function defineType(input) {
|
|
8
|
+
return { ...input, __kind: 'type' };
|
|
9
|
+
}
|
|
10
|
+
export function defineEmbedded(input) {
|
|
11
|
+
return { ...input, __kind: 'embedded' };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,oEAAoE;AAsBpE,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,OAAO,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,OAAO,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAA;AACzC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TypeIR } from './types.js';
|
|
2
|
+
/** Emit a `@estokad/sdk` declaration-merge augmentation that maps each
|
|
3
|
+
* content-type name to a generated TypeScript interface. Customers
|
|
4
|
+
* import this once and `client.pressRelease.get(...)` becomes fully
|
|
5
|
+
* typed without hand-writing the ContentTypes block. (M2.2d) */
|
|
6
|
+
export declare function generateContentTypesAugmentation(ir: ReadonlyArray<TypeIR>): string;
|
|
7
|
+
export declare function generateTypeScript(ir: ReadonlyArray<TypeIR>): string;
|
|
8
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAMV,MAAM,EACP,MAAM,YAAY,CAAA;AAInB;;;iEAGiE;AACjE,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CA0BlF;AAuDD,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAoBpE"}
|