db4ai 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/README.md +438 -0
- package/dist/cli/bin.d.ts +50 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +418 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/dashboard/App.d.ts +16 -0
- package/dist/cli/dashboard/App.d.ts.map +1 -0
- package/dist/cli/dashboard/App.js +116 -0
- package/dist/cli/dashboard/App.js.map +1 -0
- package/dist/cli/dashboard/components/index.d.ts +70 -0
- package/dist/cli/dashboard/components/index.d.ts.map +1 -0
- package/dist/cli/dashboard/components/index.js +192 -0
- package/dist/cli/dashboard/components/index.js.map +1 -0
- package/dist/cli/dashboard/hooks/index.d.ts +76 -0
- package/dist/cli/dashboard/hooks/index.d.ts.map +1 -0
- package/dist/cli/dashboard/hooks/index.js +201 -0
- package/dist/cli/dashboard/hooks/index.js.map +1 -0
- package/dist/cli/dashboard/index.d.ts +17 -0
- package/dist/cli/dashboard/index.d.ts.map +1 -0
- package/dist/cli/dashboard/index.js +16 -0
- package/dist/cli/dashboard/index.js.map +1 -0
- package/dist/cli/dashboard/types.d.ts +84 -0
- package/dist/cli/dashboard/types.d.ts.map +1 -0
- package/dist/cli/dashboard/types.js +5 -0
- package/dist/cli/dashboard/types.js.map +1 -0
- package/dist/cli/dashboard/views/index.d.ts +51 -0
- package/dist/cli/dashboard/views/index.d.ts.map +1 -0
- package/dist/cli/dashboard/views/index.js +72 -0
- package/dist/cli/dashboard/views/index.js.map +1 -0
- package/dist/cli/index.d.ts +16 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +48 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/runtime/index.d.ts +236 -0
- package/dist/cli/runtime/index.d.ts.map +1 -0
- package/dist/cli/runtime/index.js +705 -0
- package/dist/cli/runtime/index.js.map +1 -0
- package/dist/cli/scanner/index.d.ts +90 -0
- package/dist/cli/scanner/index.d.ts.map +1 -0
- package/dist/cli/scanner/index.js +640 -0
- package/dist/cli/scanner/index.js.map +1 -0
- package/dist/cli/seed/index.d.ts +160 -0
- package/dist/cli/seed/index.d.ts.map +1 -0
- package/dist/cli/seed/index.js +774 -0
- package/dist/cli/seed/index.js.map +1 -0
- package/dist/cli/sync/index.d.ts +197 -0
- package/dist/cli/sync/index.d.ts.map +1 -0
- package/dist/cli/sync/index.js +706 -0
- package/dist/cli/sync/index.js.map +1 -0
- package/dist/cli/terminal.d.ts +60 -0
- package/dist/cli/terminal.d.ts.map +1 -0
- package/dist/cli/terminal.js +210 -0
- package/dist/cli/terminal.js.map +1 -0
- package/dist/cli/workflow/index.d.ts +152 -0
- package/dist/cli/workflow/index.d.ts.map +1 -0
- package/dist/cli/workflow/index.js +308 -0
- package/dist/cli/workflow/index.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/handlers.d.ts +147 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +39 -0
- package/dist/handlers.js.map +1 -0
- package/dist/index.d.ts +1281 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3164 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +215 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/docs/api-reference.mdx +3 -0
- package/docs/examples.mdx +3 -0
- package/docs/getting-started.mdx +3 -0
- package/docs/index.mdx +3 -0
- package/docs/schema-dsl.mdx +3 -0
- package/package.json +121 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1281 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
export { SerializedFunction, serializeFunction, type EntityHandlerType, type SchemaHandlerType, type LifecycleHandlerType, type StateHandlerType, type HandlerExecutionResult, type HandlerLogEntry, } from './handlers';
|
|
3
|
+
import { type SerializedFunction } from './handlers';
|
|
4
|
+
/**
|
|
5
|
+
* Error codes for schema validation errors.
|
|
6
|
+
*/
|
|
7
|
+
export type SchemaValidationErrorCode = 'MISSING_CONTEXT' | 'MISSING_NAMESPACE' | 'INVALID_FIELD_TYPE';
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when schema validation fails.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* try {
|
|
13
|
+
* DB({ User: { name: 'User name' } }) // Missing $id or $context
|
|
14
|
+
* } catch (error) {
|
|
15
|
+
* if (error instanceof SchemaValidationError) {
|
|
16
|
+
* console.log(error.code) // 'MISSING_CONTEXT'
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
export declare class SchemaValidationError extends Error {
|
|
21
|
+
code: SchemaValidationErrorCode;
|
|
22
|
+
constructor(code: SchemaValidationErrorCode, message: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Error codes for API errors.
|
|
26
|
+
*/
|
|
27
|
+
export type APIErrorCode = 'REGISTRATION_FAILED' | 'GENERATION_FAILED' | 'REFERENCE_RESOLUTION_FAILED';
|
|
28
|
+
/**
|
|
29
|
+
* Error thrown when API operations fail.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* try {
|
|
33
|
+
* await db.User('john-doe')
|
|
34
|
+
* } catch (error) {
|
|
35
|
+
* if (error instanceof APIError) {
|
|
36
|
+
* console.log(error.code) // 'GENERATION_FAILED'
|
|
37
|
+
* console.log(error.statusCode) // 404
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
export declare class APIError extends Error {
|
|
42
|
+
code: APIErrorCode;
|
|
43
|
+
statusCode?: number;
|
|
44
|
+
constructor(code: APIErrorCode, message: string, statusCode?: number);
|
|
45
|
+
}
|
|
46
|
+
export type Components = {
|
|
47
|
+
App: ComponentType;
|
|
48
|
+
List: ComponentType;
|
|
49
|
+
ListItem: ComponentType;
|
|
50
|
+
View: ComponentType;
|
|
51
|
+
Edit: ComponentType;
|
|
52
|
+
Chat: ComponentType;
|
|
53
|
+
};
|
|
54
|
+
export declare function UI(components: Components): Components;
|
|
55
|
+
/**
|
|
56
|
+
* Parse namespace from a $id URL.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* parseNamespaceFromId('https://db.sb/sales') // 'sales' (from path)
|
|
60
|
+
* parseNamespaceFromId('https://db4.ai/startups') // 'startups' (from path)
|
|
61
|
+
* parseNamespaceFromId('https://db.sb/org/team') // 'org/team' (from path)
|
|
62
|
+
* parseNamespaceFromId('https://startup.db.sb') // 'startup' (from subdomain)
|
|
63
|
+
* parseNamespaceFromId('https://startups.db.sb') // 'startups' (from subdomain)
|
|
64
|
+
* parseNamespaceFromId('https://db.sb/') // null
|
|
65
|
+
* parseNamespaceFromId('invalid') // null
|
|
66
|
+
*/
|
|
67
|
+
export declare function parseNamespaceFromId(id: string): string | null;
|
|
68
|
+
export type FieldValue = string | string[] | Record<string, string>;
|
|
69
|
+
export interface SchemaMetadata {
|
|
70
|
+
$id?: string;
|
|
71
|
+
$context?: string;
|
|
72
|
+
$version?: string;
|
|
73
|
+
}
|
|
74
|
+
export type TypeDefinition = Record<string, FieldValue>;
|
|
75
|
+
export type SchemaDefinition = SchemaMetadata & Record<string, TypeDefinition | string>;
|
|
76
|
+
export interface StringField {
|
|
77
|
+
type: 'string';
|
|
78
|
+
description: string;
|
|
79
|
+
optional?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reference operators used in the schema DSL.
|
|
83
|
+
*
|
|
84
|
+
* - `->` (FORWARD_EXACT): Forward exact reference - resolves by ID
|
|
85
|
+
* - `~>` (FORWARD_FUZZY): Forward fuzzy reference - resolves by semantic matching
|
|
86
|
+
* - `<-` (BACKWARD_EXACT): Backward exact reference - reverse lookup by ID
|
|
87
|
+
* - `<~` (BACKWARD_FUZZY): Backward fuzzy reference - reverse lookup by semantic matching
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Forward references (existing)
|
|
91
|
+
* { author: '->User' } // Exact forward ref
|
|
92
|
+
* { avatar: '~>Image' } // Fuzzy forward ref
|
|
93
|
+
*
|
|
94
|
+
* // Backward references (new)
|
|
95
|
+
* { posts: '<-Post' } // Find Posts that reference this entity
|
|
96
|
+
* { related: '<~Article' } // Find semantically related Articles
|
|
97
|
+
*/
|
|
98
|
+
export declare const OPERATORS: {
|
|
99
|
+
/** Forward exact reference: `->Type` - resolves to exact ID match */
|
|
100
|
+
readonly FORWARD_EXACT: "->";
|
|
101
|
+
/** Forward fuzzy reference: `~>Type` - resolves by semantic similarity */
|
|
102
|
+
readonly FORWARD_FUZZY: "~>";
|
|
103
|
+
/** Backward exact reference: `<-Type` - finds entities referencing this one */
|
|
104
|
+
readonly BACKWARD_EXACT: "<-";
|
|
105
|
+
/** Backward fuzzy reference: `<~Type` - finds semantically related entities */
|
|
106
|
+
readonly BACKWARD_FUZZY: "<~";
|
|
107
|
+
};
|
|
108
|
+
/** Type for all valid reference operators */
|
|
109
|
+
export type ReferenceOperator = (typeof OPERATORS)[keyof typeof OPERATORS];
|
|
110
|
+
/** Parsed operator information returned by parseOperator */
|
|
111
|
+
export type ParsedOperator = {
|
|
112
|
+
direction: 'forward';
|
|
113
|
+
fuzzy: boolean;
|
|
114
|
+
} | {
|
|
115
|
+
direction: 'backward';
|
|
116
|
+
mode: 'exact' | 'fuzzy';
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Parse a reference operator prefix into its direction and mode/fuzzy properties.
|
|
120
|
+
*
|
|
121
|
+
* This helper function converts the two-character operator prefix into structured
|
|
122
|
+
* properties for building ReferenceField objects.
|
|
123
|
+
*
|
|
124
|
+
* @param prefix - The operator prefix (`->`, `~>`, `<-`, or `<~`)
|
|
125
|
+
* @returns Parsed operator with direction and either fuzzy (forward) or mode (backward)
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* parseOperator('->') // { direction: 'forward', fuzzy: false }
|
|
129
|
+
* parseOperator('~>') // { direction: 'forward', fuzzy: true }
|
|
130
|
+
* parseOperator('<-') // { direction: 'backward', mode: 'exact' }
|
|
131
|
+
* parseOperator('<~') // { direction: 'backward', mode: 'fuzzy' }
|
|
132
|
+
*/
|
|
133
|
+
export declare function parseOperator(prefix: string): ParsedOperator;
|
|
134
|
+
/**
|
|
135
|
+
* Parsed reference field from the schema DSL.
|
|
136
|
+
*
|
|
137
|
+
* The `direction` and `mode` properties are used for backward references (`<-`, `<~`),
|
|
138
|
+
* while the `fuzzy` property is used for forward references (`->`, `~>`) for
|
|
139
|
+
* backward compatibility.
|
|
140
|
+
*
|
|
141
|
+
* ## Forward References (direction omitted)
|
|
142
|
+
* - `->Type` produces `{ fuzzy: false, ... }` - exact ID lookup
|
|
143
|
+
* - `~>Type` produces `{ fuzzy: true, ... }` - semantic matching
|
|
144
|
+
*
|
|
145
|
+
* ## Backward References
|
|
146
|
+
* - `<-Type` produces `{ direction: 'backward', mode: 'exact', ... }` - find by ID
|
|
147
|
+
* - `<~Type` produces `{ direction: 'backward', mode: 'fuzzy', ... }` - find by semantics
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Forward exact reference
|
|
151
|
+
* parseFieldType('->User')
|
|
152
|
+
* // { type: 'reference', ref: 'User', isArray: false, optional: false, fuzzy: false }
|
|
153
|
+
*
|
|
154
|
+
* // Backward fuzzy array reference
|
|
155
|
+
* parseFieldType('<~Post[]')
|
|
156
|
+
* // { type: 'reference', ref: 'Post', isArray: true, optional: false, direction: 'backward', mode: 'fuzzy' }
|
|
157
|
+
*/
|
|
158
|
+
export interface ReferenceField {
|
|
159
|
+
type: 'reference';
|
|
160
|
+
/** Single reference target type (mutually exclusive with `refs`) */
|
|
161
|
+
ref?: string;
|
|
162
|
+
/** Union type reference targets (mutually exclusive with `ref`) */
|
|
163
|
+
refs?: string[];
|
|
164
|
+
/** Whether this is an array of references (e.g., `->Type[]`) */
|
|
165
|
+
isArray: boolean;
|
|
166
|
+
/** Whether the reference is optional (e.g., `->Type?`) */
|
|
167
|
+
optional?: boolean;
|
|
168
|
+
/** For forward references: true if fuzzy (`~>`), false if exact (`->`) */
|
|
169
|
+
fuzzy?: boolean;
|
|
170
|
+
/** For backward references: always 'backward' when present */
|
|
171
|
+
direction?: 'forward' | 'backward';
|
|
172
|
+
/** For backward references: 'exact' (`<-`) or 'fuzzy' (`<~`) */
|
|
173
|
+
mode?: 'exact' | 'fuzzy';
|
|
174
|
+
}
|
|
175
|
+
export interface ArrayField {
|
|
176
|
+
type: 'array';
|
|
177
|
+
items: {
|
|
178
|
+
type: 'string';
|
|
179
|
+
};
|
|
180
|
+
description: string;
|
|
181
|
+
optional?: boolean;
|
|
182
|
+
refs?: string[];
|
|
183
|
+
backRef?: string;
|
|
184
|
+
count?: number | {
|
|
185
|
+
min: number;
|
|
186
|
+
max: number;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export interface ObjectField {
|
|
190
|
+
type: 'object';
|
|
191
|
+
properties: Record<string, StringField>;
|
|
192
|
+
optional?: boolean;
|
|
193
|
+
}
|
|
194
|
+
export interface EmbeddedField {
|
|
195
|
+
type: 'embedded';
|
|
196
|
+
embeddedType: string;
|
|
197
|
+
isArray?: boolean;
|
|
198
|
+
optional?: boolean;
|
|
199
|
+
}
|
|
200
|
+
export interface JSONPathField {
|
|
201
|
+
type: 'jsonpath';
|
|
202
|
+
path: string;
|
|
203
|
+
transform?: string;
|
|
204
|
+
}
|
|
205
|
+
export interface JSONPathEmbeddedField {
|
|
206
|
+
type: 'jsonpath-embedded';
|
|
207
|
+
path: string;
|
|
208
|
+
embeddedType: string;
|
|
209
|
+
isArray: boolean;
|
|
210
|
+
optional?: boolean;
|
|
211
|
+
}
|
|
212
|
+
export interface ComputedField {
|
|
213
|
+
type: 'computed';
|
|
214
|
+
source: string;
|
|
215
|
+
}
|
|
216
|
+
export interface PromptField {
|
|
217
|
+
type: 'prompt';
|
|
218
|
+
prompt: string;
|
|
219
|
+
}
|
|
220
|
+
export type ParsedField = StringField | ReferenceField | ArrayField | ObjectField | EmbeddedField | JSONPathField | JSONPathEmbeddedField | ComputedField | PromptField;
|
|
221
|
+
export interface TypeReference {
|
|
222
|
+
field: string;
|
|
223
|
+
ref: string;
|
|
224
|
+
refs?: string[];
|
|
225
|
+
isArray: boolean;
|
|
226
|
+
optional?: boolean;
|
|
227
|
+
fuzzy?: boolean;
|
|
228
|
+
backRef?: boolean;
|
|
229
|
+
}
|
|
230
|
+
export interface SeedConfig {
|
|
231
|
+
url: string;
|
|
232
|
+
format?: 'tsv' | 'csv' | 'json';
|
|
233
|
+
idField?: string;
|
|
234
|
+
id?: string;
|
|
235
|
+
idTransform?: string;
|
|
236
|
+
next?: string;
|
|
237
|
+
data?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Parse $id field which can be:
|
|
241
|
+
* - Simple JSONPath: $.slug
|
|
242
|
+
* - Transform with path: PascalCase($.example)
|
|
243
|
+
* - Column name (legacy): slug
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* parseIdConfig('$.slug') // { path: '$.slug' }
|
|
247
|
+
* parseIdConfig('PascalCase($.example)') // { path: '$.example', transform: 'PascalCase' }
|
|
248
|
+
* parseIdConfig('kebab-case($.title)') // { path: '$.title', transform: 'kebab-case' }
|
|
249
|
+
* parseIdConfig('slug') // { path: 'slug' }
|
|
250
|
+
*/
|
|
251
|
+
export declare function parseIdConfig(idField: string): {
|
|
252
|
+
path: string;
|
|
253
|
+
transform?: string;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Validates that a string is a valid JSONPath expression.
|
|
257
|
+
*
|
|
258
|
+
* A valid JSONPath must:
|
|
259
|
+
* - Start with `$.` (root reference)
|
|
260
|
+
* - Contain valid property names, array indices, or bracket notation
|
|
261
|
+
*
|
|
262
|
+
* Supported patterns:
|
|
263
|
+
* - `$.field` - Simple property access
|
|
264
|
+
* - `$.nested.field` - Nested property access
|
|
265
|
+
* - `$.array[0]` - Array index access
|
|
266
|
+
* - `$.array[*]` - Array wildcard
|
|
267
|
+
* - `$.items[?(@.active)]` - Filter expressions
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* isValidJSONPath('$.title') // true
|
|
271
|
+
* isValidJSONPath('$.data.items[0]') // true
|
|
272
|
+
* isValidJSONPath('$.tags[*]') // true
|
|
273
|
+
* isValidJSONPath('title') // false (missing $.)
|
|
274
|
+
* isValidJSONPath('$50 price') // false (not a valid path)
|
|
275
|
+
*/
|
|
276
|
+
export declare function isValidJSONPath(path: string): boolean;
|
|
277
|
+
/**
|
|
278
|
+
* Type guard to check if a ParsedField is a JSONPathField.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* const field = parseFieldType('$.title')
|
|
282
|
+
* if (isJSONPathField(field)) {
|
|
283
|
+
* console.log(field.path) // TypeScript knows field.path exists
|
|
284
|
+
* }
|
|
285
|
+
*/
|
|
286
|
+
export declare function isJSONPathField(field: ParsedField): field is JSONPathField;
|
|
287
|
+
/**
|
|
288
|
+
* Type guard to check if a ParsedField is a JSONPathEmbeddedField.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* const field = parseFieldType('$.author ->Author')
|
|
292
|
+
* if (isJSONPathEmbeddedField(field)) {
|
|
293
|
+
* console.log(field.embeddedType) // TypeScript knows field.embeddedType exists
|
|
294
|
+
* }
|
|
295
|
+
*/
|
|
296
|
+
export declare function isJSONPathEmbeddedField(field: ParsedField): field is JSONPathEmbeddedField;
|
|
297
|
+
/**
|
|
298
|
+
* Type guard to check if a ParsedField is a PromptField.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* const field = parsed.types.Task.fields.description
|
|
302
|
+
* if (isPromptField(field)) {
|
|
303
|
+
* console.log(field.prompt) // TypeScript knows field.prompt exists
|
|
304
|
+
* }
|
|
305
|
+
*/
|
|
306
|
+
export declare function isPromptField(field: ParsedField): field is PromptField;
|
|
307
|
+
/**
|
|
308
|
+
* Type guard to check if a ParsedField is a StringField.
|
|
309
|
+
*/
|
|
310
|
+
export declare function isStringField(field: ParsedField): field is StringField;
|
|
311
|
+
/** Evaluation definition - stub type for schema parsing. */
|
|
312
|
+
export type EvalDefinition = Record<string, unknown>;
|
|
313
|
+
/** Schema experiment definition - stub type for schema parsing. */
|
|
314
|
+
export type SchemaExperiment = Record<string, unknown>;
|
|
315
|
+
/** Schema analytics configuration - stub type for schema parsing. */
|
|
316
|
+
export type SchemaAnalytics = Record<string, unknown>;
|
|
317
|
+
export interface OAuthConfig {
|
|
318
|
+
tokenUrl: string;
|
|
319
|
+
clientId: string;
|
|
320
|
+
clientSecret: string;
|
|
321
|
+
}
|
|
322
|
+
export interface AsyncConfig {
|
|
323
|
+
start: string;
|
|
324
|
+
result: string;
|
|
325
|
+
}
|
|
326
|
+
export interface SourceConfig {
|
|
327
|
+
$api: string;
|
|
328
|
+
$apiKey?: string;
|
|
329
|
+
$bearer?: string;
|
|
330
|
+
$oauth?: OAuthConfig;
|
|
331
|
+
$data?: string;
|
|
332
|
+
$async?: AsyncConfig;
|
|
333
|
+
}
|
|
334
|
+
export type SourceInput = Record<string, 'string' | 'string?'>;
|
|
335
|
+
export interface ImageConfig {
|
|
336
|
+
aspectRatio?: string;
|
|
337
|
+
style?: string;
|
|
338
|
+
}
|
|
339
|
+
export interface SpeechConfig {
|
|
340
|
+
voice?: string;
|
|
341
|
+
speed?: number;
|
|
342
|
+
format?: string;
|
|
343
|
+
}
|
|
344
|
+
export interface DiagramConfig {
|
|
345
|
+
type?: string;
|
|
346
|
+
direction?: string;
|
|
347
|
+
format?: string;
|
|
348
|
+
}
|
|
349
|
+
export interface ConventionsConfig {
|
|
350
|
+
nodes?: string;
|
|
351
|
+
edges?: string;
|
|
352
|
+
events?: string;
|
|
353
|
+
}
|
|
354
|
+
export interface CodeConfig {
|
|
355
|
+
language?: string;
|
|
356
|
+
runtime?: string;
|
|
357
|
+
framework?: string;
|
|
358
|
+
}
|
|
359
|
+
/** Transition configuration - simple string or complex object */
|
|
360
|
+
export interface TransitionConfig {
|
|
361
|
+
to: string | null;
|
|
362
|
+
if?: SerializedFunction;
|
|
363
|
+
do?: SerializedFunction;
|
|
364
|
+
}
|
|
365
|
+
/** State configuration with transitions */
|
|
366
|
+
export interface StateConfig {
|
|
367
|
+
transitions: Record<string, TransitionConfig>;
|
|
368
|
+
$entry?: SerializedFunction;
|
|
369
|
+
$exit?: SerializedFunction;
|
|
370
|
+
}
|
|
371
|
+
/** Parsed state machine configuration */
|
|
372
|
+
export interface ParsedStateConfig {
|
|
373
|
+
$initial: string;
|
|
374
|
+
states: Record<string, StateConfig>;
|
|
375
|
+
}
|
|
376
|
+
/** Raw state config - input format before parsing */
|
|
377
|
+
export type RawStateConfig = {
|
|
378
|
+
$initial: string;
|
|
379
|
+
} & Record<string, unknown>;
|
|
380
|
+
/** State validation error */
|
|
381
|
+
export interface StateValidationError {
|
|
382
|
+
code: string;
|
|
383
|
+
message: string;
|
|
384
|
+
state?: string;
|
|
385
|
+
event?: string;
|
|
386
|
+
transition?: string;
|
|
387
|
+
}
|
|
388
|
+
/** State validation result */
|
|
389
|
+
export interface StateValidationResult {
|
|
390
|
+
valid: boolean;
|
|
391
|
+
errors: StateValidationError[];
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Validate a raw state machine configuration.
|
|
395
|
+
* Checks for: valid $initial, reachable states, no orphan states, valid transitions.
|
|
396
|
+
*/
|
|
397
|
+
export declare function validateStateConfig(config: RawStateConfig): StateValidationResult;
|
|
398
|
+
/**
|
|
399
|
+
* Parse a raw state machine configuration into the normalized format.
|
|
400
|
+
* Converts string functions to SerializedFunction objects.
|
|
401
|
+
*
|
|
402
|
+
* @param config - Raw state machine config from schema
|
|
403
|
+
* @returns Parsed state machine configuration
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* const parsed = parseStateConfig({
|
|
407
|
+
* $initial: 'draft',
|
|
408
|
+
* draft: {
|
|
409
|
+
* submit: 'pending',
|
|
410
|
+
* $entry: (entity) => { console.log('entered draft') }
|
|
411
|
+
* },
|
|
412
|
+
* pending: {
|
|
413
|
+
* approve: { to: 'approved', if: (e) => e.score >= 80 }
|
|
414
|
+
* },
|
|
415
|
+
* approved: null // terminal state
|
|
416
|
+
* })
|
|
417
|
+
*/
|
|
418
|
+
export declare function parseStateConfig(config: RawStateConfig): ParsedStateConfig;
|
|
419
|
+
export interface ParsedType {
|
|
420
|
+
name: string;
|
|
421
|
+
fields: Record<string, ParsedField>;
|
|
422
|
+
references: TypeReference[];
|
|
423
|
+
seed?: SeedConfig;
|
|
424
|
+
icon?: string;
|
|
425
|
+
group?: string;
|
|
426
|
+
$created?: SerializedFunction;
|
|
427
|
+
$updated?: SerializedFunction;
|
|
428
|
+
$deleted?: SerializedFunction;
|
|
429
|
+
handlers?: Record<string, SerializedFunction>;
|
|
430
|
+
$state?: ParsedStateConfig;
|
|
431
|
+
source?: SourceConfig;
|
|
432
|
+
input?: SourceInput;
|
|
433
|
+
from?: string[];
|
|
434
|
+
cache?: string;
|
|
435
|
+
isSourceFunction?: boolean;
|
|
436
|
+
image?: ImageConfig;
|
|
437
|
+
speech?: SpeechConfig;
|
|
438
|
+
diagram?: DiagramConfig;
|
|
439
|
+
conventions?: ConventionsConfig;
|
|
440
|
+
code?: CodeConfig;
|
|
441
|
+
isGenerative?: boolean;
|
|
442
|
+
eval?: Record<string, EvalDefinition>;
|
|
443
|
+
experiment?: SchemaExperiment;
|
|
444
|
+
}
|
|
445
|
+
export interface SchemaSettings {
|
|
446
|
+
iconLibrary?: string;
|
|
447
|
+
}
|
|
448
|
+
export interface ParsedSchema {
|
|
449
|
+
types: Record<string, ParsedType>;
|
|
450
|
+
hash: string;
|
|
451
|
+
settings?: SchemaSettings;
|
|
452
|
+
fn?: Record<string, SerializedFunction>;
|
|
453
|
+
on?: Record<string, SerializedFunction>;
|
|
454
|
+
eval?: Record<string, EvalDefinition>;
|
|
455
|
+
experiment?: Record<string, SchemaExperiment>;
|
|
456
|
+
analytics?: SchemaAnalytics;
|
|
457
|
+
handlers?: Record<string, SerializedFunction>;
|
|
458
|
+
}
|
|
459
|
+
export interface JSONSchemaProperty {
|
|
460
|
+
type: string;
|
|
461
|
+
description?: string;
|
|
462
|
+
items?: {
|
|
463
|
+
type: string;
|
|
464
|
+
properties?: Record<string, JSONSchemaProperty>;
|
|
465
|
+
required?: string[];
|
|
466
|
+
additionalProperties?: boolean;
|
|
467
|
+
};
|
|
468
|
+
properties?: Record<string, JSONSchemaProperty>;
|
|
469
|
+
required?: string[];
|
|
470
|
+
additionalProperties?: boolean;
|
|
471
|
+
minItems?: number;
|
|
472
|
+
maxItems?: number;
|
|
473
|
+
}
|
|
474
|
+
export interface JSONSchema {
|
|
475
|
+
type: 'object';
|
|
476
|
+
properties: Record<string, JSONSchemaProperty>;
|
|
477
|
+
required: string[];
|
|
478
|
+
additionalProperties: boolean;
|
|
479
|
+
}
|
|
480
|
+
export declare function extractCountFromDescription(description: string): number | {
|
|
481
|
+
min: number;
|
|
482
|
+
max: number;
|
|
483
|
+
} | undefined;
|
|
484
|
+
/**
|
|
485
|
+
* Parse a field value into its structured field type representation.
|
|
486
|
+
*
|
|
487
|
+
* Converts the shorthand field notation used in schema definitions into
|
|
488
|
+
* a fully parsed field object with type information, references, and options.
|
|
489
|
+
*
|
|
490
|
+
* ## Reference Operators
|
|
491
|
+
*
|
|
492
|
+
* This function parses all four reference operators defined in {@link OPERATORS}:
|
|
493
|
+
*
|
|
494
|
+
* | Operator | Direction | Mode | Description |
|
|
495
|
+
* |----------|-----------|-------|--------------------------------|
|
|
496
|
+
* | `->` | forward | exact | Resolves to exact ID match |
|
|
497
|
+
* | `~>` | forward | fuzzy | Resolves by semantic similarity|
|
|
498
|
+
* | `<-` | backward | exact | Finds entities referencing this|
|
|
499
|
+
* | `<~` | backward | fuzzy | Finds semantically related |
|
|
500
|
+
*
|
|
501
|
+
* @param value - The field value to parse. Can be:
|
|
502
|
+
* - `string` - A field description or reference pattern (e.g., `'User name'`, `'->User'`, `'~>Image?'`, `'<-Post[]'`)
|
|
503
|
+
* - `string[]` - An array field with description (e.g., `['Tag labels']`, `['<-Post']`)
|
|
504
|
+
* - `Record<string, string>` - A nested object with field descriptions
|
|
505
|
+
* - `Function` - A computed field
|
|
506
|
+
*
|
|
507
|
+
* @returns A ParsedField object representing the field type:
|
|
508
|
+
* - `StringField` - Plain text field with description
|
|
509
|
+
* - `ReferenceField` - Reference to another type (forward or backward)
|
|
510
|
+
* - `ArrayField` - Array of strings or references
|
|
511
|
+
* - `ObjectField` - Nested object with properties
|
|
512
|
+
* - `EmbeddedField` - Embedded type (detected in second pass)
|
|
513
|
+
* - `JSONPathField` - JSONPath expression for data mapping
|
|
514
|
+
* - `ComputedField` - Field computed from a function
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* // String field
|
|
518
|
+
* parseFieldType('User name')
|
|
519
|
+
* // { type: 'string', description: 'User name' }
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* // Forward exact reference
|
|
523
|
+
* parseFieldType('->User')
|
|
524
|
+
* // { type: 'reference', ref: 'User', isArray: false, optional: false, fuzzy: false }
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* // Forward fuzzy reference (optional)
|
|
528
|
+
* parseFieldType('~>Image?')
|
|
529
|
+
* // { type: 'reference', ref: 'Image', isArray: false, optional: true, fuzzy: true }
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* // Forward array reference
|
|
533
|
+
* parseFieldType('->Tag[]')
|
|
534
|
+
* // { type: 'reference', ref: 'Tag', isArray: true, optional: false, fuzzy: false }
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* // Backward exact reference - finds Posts that reference this entity
|
|
538
|
+
* parseFieldType('<-Post')
|
|
539
|
+
* // { type: 'reference', ref: 'Post', isArray: false, optional: false, direction: 'backward', mode: 'exact' }
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* // Backward fuzzy reference array - finds semantically related Articles
|
|
543
|
+
* parseFieldType('<~Article[]')
|
|
544
|
+
* // { type: 'reference', ref: 'Article', isArray: true, optional: false, direction: 'backward', mode: 'fuzzy' }
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* // Union type reference
|
|
548
|
+
* parseFieldType('->User|Organization')
|
|
549
|
+
* // { type: 'reference', refs: ['User', 'Organization'], isArray: false, optional: false, fuzzy: false }
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* // String array with count hint
|
|
553
|
+
* parseFieldType(['List 5 keywords'])
|
|
554
|
+
* // { type: 'array', items: { type: 'string' }, description: 'List 5 keywords', count: 5 }
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* // Nested object
|
|
558
|
+
* parseFieldType({ street: 'Street address', city: 'City name' })
|
|
559
|
+
* // { type: 'object', properties: { street: {...}, city: {...} } }
|
|
560
|
+
*/
|
|
561
|
+
export declare function parseFieldType(value: FieldValue | Function): ParsedField;
|
|
562
|
+
/**
|
|
563
|
+
* Parsed reference field info for generation.
|
|
564
|
+
* Used by the two-phase generation pipeline to understand reference fields.
|
|
565
|
+
*/
|
|
566
|
+
export interface ParsedGenerationReference {
|
|
567
|
+
/** Reference mode: exact (->) or fuzzy (~>) */
|
|
568
|
+
mode: 'exact' | 'fuzzy';
|
|
569
|
+
/** Target type name (or first type for union types) */
|
|
570
|
+
targetType: string;
|
|
571
|
+
/** All target types for union types */
|
|
572
|
+
targetTypes?: string[];
|
|
573
|
+
/** Whether this reference is optional */
|
|
574
|
+
isOptional: boolean;
|
|
575
|
+
/** Whether this is an array reference */
|
|
576
|
+
isArray: boolean;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Parse a reference field definition for generation.
|
|
580
|
+
*
|
|
581
|
+
* Handles patterns like:
|
|
582
|
+
* - `->Person` - exact reference
|
|
583
|
+
* - `~>Industry` - fuzzy reference
|
|
584
|
+
* - `->Type[]` - array of exact references
|
|
585
|
+
* - `~>Type?` - optional fuzzy reference
|
|
586
|
+
* - `->User|Organization` - union type reference
|
|
587
|
+
*
|
|
588
|
+
* @param fieldDef - The field definition string (e.g., '->Person', '~>Industry?')
|
|
589
|
+
* @returns ParsedGenerationReference or null if not a reference field
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* parseGenerationReference('->Person')
|
|
593
|
+
* // { mode: 'exact', targetType: 'Person', isOptional: false, isArray: false }
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* parseGenerationReference('~>Industry?')
|
|
597
|
+
* // { mode: 'fuzzy', targetType: 'Industry', isOptional: true, isArray: false }
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* parseGenerationReference('->User|Organization')
|
|
601
|
+
* // { mode: 'exact', targetType: 'User', targetTypes: ['User', 'Organization'], isOptional: false, isArray: false }
|
|
602
|
+
*/
|
|
603
|
+
export declare function parseGenerationReference(fieldDef: string): ParsedGenerationReference | null;
|
|
604
|
+
/**
|
|
605
|
+
* Parse array field definition for generation.
|
|
606
|
+
*
|
|
607
|
+
* Handles array shorthand like `['~>Investor']` or `['->Person']`.
|
|
608
|
+
*
|
|
609
|
+
* @param fieldDef - The field definition array (e.g., ['~>Investor'])
|
|
610
|
+
* @returns ParsedGenerationReference or null if not a reference array
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* parseGenerationArrayReference(['~>Investor'])
|
|
614
|
+
* // { mode: 'fuzzy', targetType: 'Investor', isOptional: false, isArray: true }
|
|
615
|
+
*/
|
|
616
|
+
export declare function parseGenerationArrayReference(fieldDef: string[]): ParsedGenerationReference | null;
|
|
617
|
+
/**
|
|
618
|
+
* Check if a field definition is a reference field.
|
|
619
|
+
*
|
|
620
|
+
* @param fieldDef - The field definition (string or array)
|
|
621
|
+
* @returns true if this is a reference field
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* isReferenceField('->User') // true
|
|
625
|
+
* isReferenceField('~>Industry?') // true
|
|
626
|
+
* isReferenceField(['~>Investor']) // true
|
|
627
|
+
* isReferenceField('User name') // false
|
|
628
|
+
* isReferenceField(['tags']) // false
|
|
629
|
+
*/
|
|
630
|
+
export declare function isReferenceField(fieldDef: string | string[]): boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Extract reference mode from a field definition.
|
|
633
|
+
*
|
|
634
|
+
* @param fieldDef - The field definition
|
|
635
|
+
* @returns 'exact' | 'fuzzy' | null
|
|
636
|
+
*/
|
|
637
|
+
export declare function getReferenceMode(fieldDef: string | string[]): 'exact' | 'fuzzy' | null;
|
|
638
|
+
/**
|
|
639
|
+
* Extract target type(s) from a reference field.
|
|
640
|
+
*
|
|
641
|
+
* @param fieldDef - The field definition
|
|
642
|
+
* @returns Target type string, array of types for unions, or null if not a reference
|
|
643
|
+
*/
|
|
644
|
+
export declare function getReferenceTargetType(fieldDef: string | string[]): string | string[] | null;
|
|
645
|
+
/**
|
|
646
|
+
* Parse seed configuration from a schema type's `$seed` field.
|
|
647
|
+
*
|
|
648
|
+
* Seed configuration tells the system where to fetch initial data for a type,
|
|
649
|
+
* supporting TSV, CSV, and JSON formats with pagination support.
|
|
650
|
+
*
|
|
651
|
+
* @param value - The seed configuration. Can be:
|
|
652
|
+
* - `string` - A URL (format inferred from extension: `.csv`, `.json`, or default `.tsv`)
|
|
653
|
+
* - `Record<string, string>` - Object with explicit options
|
|
654
|
+
*
|
|
655
|
+
* @returns A SeedConfig object with:
|
|
656
|
+
* - `url` - The data source URL
|
|
657
|
+
* - `format` - Data format ('tsv', 'csv', or 'json')
|
|
658
|
+
* - `idField` - Optional field to use as entity ID
|
|
659
|
+
* - `next` - Optional JSONPath to pagination URL
|
|
660
|
+
* - `data` - Optional JSONPath to data array in response
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* // Simple URL (format inferred)
|
|
664
|
+
* parseSeedConfig('https://example.com/data.csv')
|
|
665
|
+
* // { url: 'https://example.com/data.csv', format: 'csv' }
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* // URL with TSV default
|
|
669
|
+
* parseSeedConfig('https://example.com/data')
|
|
670
|
+
* // { url: 'https://example.com/data', format: 'tsv' }
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* // Object config with pagination
|
|
674
|
+
* parseSeedConfig({
|
|
675
|
+
* url: 'https://api.example.com/items',
|
|
676
|
+
* format: 'json',
|
|
677
|
+
* data: '$.items',
|
|
678
|
+
* next: '$.pagination.next'
|
|
679
|
+
* })
|
|
680
|
+
* // { url: '...', format: 'json', data: '$.items', next: '$.pagination.next' }
|
|
681
|
+
*/
|
|
682
|
+
export declare function parseSeedConfig(value: string | Record<string, string>): SeedConfig;
|
|
683
|
+
/**
|
|
684
|
+
* Converts string fields to prompt fields in a seeded type's field map.
|
|
685
|
+
*
|
|
686
|
+
* In seeded schemas, plain string values represent prompts for AI generation
|
|
687
|
+
* rather than simple field descriptions. This function performs the conversion
|
|
688
|
+
* after initial field parsing, ensuring that JSONPath fields and reference
|
|
689
|
+
* fields remain unchanged while string fields become prompt fields.
|
|
690
|
+
*
|
|
691
|
+
* @param fields - The parsed fields map from parseFieldType calls
|
|
692
|
+
* @returns A new fields map with string fields converted to prompt fields
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* // Input: fields from a seeded type
|
|
696
|
+
* const fields = {
|
|
697
|
+
* title: { type: 'string', description: 'Some title' },
|
|
698
|
+
* jsonField: { type: 'jsonpath', path: '$.name' },
|
|
699
|
+
* ref: { type: 'reference', ref: 'Other', isArray: false },
|
|
700
|
+
* }
|
|
701
|
+
*
|
|
702
|
+
* // Output: string -> prompt, others unchanged
|
|
703
|
+
* const converted = convertStringsToPromptsInSeededType(fields)
|
|
704
|
+
* // converted.title = { type: 'prompt', prompt: 'Some title' }
|
|
705
|
+
* // converted.jsonField = { type: 'jsonpath', path: '$.name' }
|
|
706
|
+
* // converted.ref = { type: 'reference', ref: 'Other', isArray: false }
|
|
707
|
+
*
|
|
708
|
+
* @remarks
|
|
709
|
+
* This function is called during parseSchema when a type has `$seed` defined.
|
|
710
|
+
* Only StringField types are converted; all other field types pass through unchanged.
|
|
711
|
+
*/
|
|
712
|
+
export declare function convertStringsToPromptsInSeededType(fields: Record<string, ParsedField>): Record<string, ParsedField>;
|
|
713
|
+
/**
|
|
714
|
+
* Parse an entire schema definition into a structured ParsedSchema.
|
|
715
|
+
*
|
|
716
|
+
* This is the main parsing function that takes a schema definition object and
|
|
717
|
+
* produces a fully parsed representation with all types, fields, references,
|
|
718
|
+
* and metadata resolved.
|
|
719
|
+
*
|
|
720
|
+
* @param schema - The schema definition object containing type definitions and metadata.
|
|
721
|
+
* Metadata fields are prefixed with `$` (e.g., `$id`, `$context`, `$settings`).
|
|
722
|
+
* All other keys are treated as type definitions.
|
|
723
|
+
*
|
|
724
|
+
* @returns A ParsedSchema object containing:
|
|
725
|
+
* - `types` - Record of parsed type definitions with fields and references
|
|
726
|
+
* - `hash` - Deterministic hash of the schema for versioning
|
|
727
|
+
* - `settings` - Optional schema-level settings (e.g., iconLibrary)
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
* const schema = parseSchema({
|
|
731
|
+
* $id: 'https://db.sb/blog',
|
|
732
|
+
* Post: {
|
|
733
|
+
* title: 'Post title',
|
|
734
|
+
* content: 'Main content',
|
|
735
|
+
* author: '->User',
|
|
736
|
+
* tags: ['Tag labels']
|
|
737
|
+
* },
|
|
738
|
+
* User: {
|
|
739
|
+
* name: 'User name',
|
|
740
|
+
* email: 'Email address',
|
|
741
|
+
* posts: '->Post[]'
|
|
742
|
+
* }
|
|
743
|
+
* })
|
|
744
|
+
*
|
|
745
|
+
* // schema.types.Post.fields.title
|
|
746
|
+
* // { type: 'string', description: 'Post title' }
|
|
747
|
+
*
|
|
748
|
+
* // schema.types.Post.references
|
|
749
|
+
* // [{ field: 'author', ref: 'User', isArray: false }]
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* // Schema with seed configuration and icons
|
|
753
|
+
* const schema = parseSchema({
|
|
754
|
+
* $context: 'startups',
|
|
755
|
+
* $settings: { iconLibrary: 'lucide' },
|
|
756
|
+
* Company: {
|
|
757
|
+
* $icon: 'building',
|
|
758
|
+
* $seed: 'https://api.example.com/companies.json',
|
|
759
|
+
* name: 'Company name',
|
|
760
|
+
* website: 'Website URL'
|
|
761
|
+
* }
|
|
762
|
+
* })
|
|
763
|
+
*
|
|
764
|
+
* // schema.types.Company.icon === 'building'
|
|
765
|
+
* // schema.types.Company.seed.url === 'https://api.example.com/companies.json'
|
|
766
|
+
*/
|
|
767
|
+
export declare function parseSchema(schema: SchemaDefinition): ParsedSchema;
|
|
768
|
+
/**
|
|
769
|
+
* Convert a parsed type definition to a JSON Schema representation.
|
|
770
|
+
*
|
|
771
|
+
* Transforms the internal ParsedType format into a standard JSON Schema object
|
|
772
|
+
* that can be used for validation, documentation, or AI generation prompts.
|
|
773
|
+
*
|
|
774
|
+
* @param parsedType - The parsed type definition to convert
|
|
775
|
+
* @param parsedSchema - Optional full schema for resolving embedded types.
|
|
776
|
+
* When provided, embedded types (e.g., `Address` in `address: 'Address'`) are
|
|
777
|
+
* recursively expanded into their full JSON Schema representation.
|
|
778
|
+
* @param seen - Internal set for tracking visited types to prevent infinite recursion
|
|
779
|
+
* in circular reference scenarios. Do not pass this parameter manually.
|
|
780
|
+
*
|
|
781
|
+
* @returns A JSON Schema object with:
|
|
782
|
+
* - `type: 'object'` - Always an object schema
|
|
783
|
+
* - `properties` - Map of field names to their JSON Schema definitions
|
|
784
|
+
* - `required` - Array of required field names (non-optional fields)
|
|
785
|
+
* - `additionalProperties: false` - Strict schema, no extra fields allowed
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* const parsed = parseSchema({
|
|
789
|
+
* $context: 'blog',
|
|
790
|
+
* Post: {
|
|
791
|
+
* title: 'Post title',
|
|
792
|
+
* author: '->User',
|
|
793
|
+
* tags: ['List 3-5 keywords']
|
|
794
|
+
* }
|
|
795
|
+
* })
|
|
796
|
+
*
|
|
797
|
+
* const jsonSchema = toJSONSchema(parsed.types.Post, parsed)
|
|
798
|
+
* // {
|
|
799
|
+
* // type: 'object',
|
|
800
|
+
* // properties: {
|
|
801
|
+
* // title: { type: 'string', description: 'Post title' },
|
|
802
|
+
* // author: { type: 'string', description: 'Reference to User (ID)' },
|
|
803
|
+
* // tags: { type: 'array', items: { type: 'string' }, minItems: 3, maxItems: 5 }
|
|
804
|
+
* // },
|
|
805
|
+
* // required: ['title', 'author', 'tags'],
|
|
806
|
+
* // additionalProperties: false
|
|
807
|
+
* // }
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* // With embedded types expanded
|
|
811
|
+
* const schema = parseSchema({
|
|
812
|
+
* $context: 'app',
|
|
813
|
+
* User: {
|
|
814
|
+
* name: 'User name',
|
|
815
|
+
* address: 'Address' // Embedded type
|
|
816
|
+
* },
|
|
817
|
+
* Address: {
|
|
818
|
+
* street: 'Street',
|
|
819
|
+
* city: 'City'
|
|
820
|
+
* }
|
|
821
|
+
* })
|
|
822
|
+
*
|
|
823
|
+
* const jsonSchema = toJSONSchema(schema.types.User, schema)
|
|
824
|
+
* // properties.address will contain the full Address schema inline
|
|
825
|
+
*/
|
|
826
|
+
export declare function toJSONSchema(parsedType: ParsedType, parsedSchemaOrIncludeRefs?: ParsedSchema | boolean, seen?: Set<string>): JSONSchema;
|
|
827
|
+
/**
|
|
828
|
+
* Generate a deterministic hash for a schema definition.
|
|
829
|
+
*
|
|
830
|
+
* Creates a consistent 8-character hexadecimal hash that uniquely identifies
|
|
831
|
+
* a schema's structure. The hash is computed using the FNV-1a algorithm on
|
|
832
|
+
* the JSON-serialized schema with sorted keys, ensuring the same schema
|
|
833
|
+
* always produces the same hash regardless of property order.
|
|
834
|
+
*
|
|
835
|
+
* @param schema - The schema definition to hash
|
|
836
|
+
*
|
|
837
|
+
* @returns An 8-character hexadecimal hash string
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* const hash1 = schemaHash({
|
|
841
|
+
* $context: 'blog',
|
|
842
|
+
* Post: { title: 'Title' }
|
|
843
|
+
* })
|
|
844
|
+
* // e.g., 'a1b2c3d4'
|
|
845
|
+
*
|
|
846
|
+
* // Same schema, different property order = same hash
|
|
847
|
+
* const hash2 = schemaHash({
|
|
848
|
+
* Post: { title: 'Title' },
|
|
849
|
+
* $context: 'blog'
|
|
850
|
+
* })
|
|
851
|
+
* // hash1 === hash2
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* // Used for schema versioning
|
|
855
|
+
* const schema = parseSchema({ $context: 'app', User: { name: 'Name' } })
|
|
856
|
+
* console.log(schema.hash)
|
|
857
|
+
* // The hash can be used to detect schema changes and trigger migrations
|
|
858
|
+
*/
|
|
859
|
+
export declare function schemaHash(schema: SchemaDefinition): string;
|
|
860
|
+
export type JobStatus = 'queued' | 'running' | 'completed' | 'failed';
|
|
861
|
+
export interface Job<T = void> {
|
|
862
|
+
id: string;
|
|
863
|
+
status: JobStatus;
|
|
864
|
+
result?: T;
|
|
865
|
+
error?: Error;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* EntityCollection is both a factory function and an iterable collection.
|
|
869
|
+
* - As factory: `await db.Idea('id', { concept: '...' })`
|
|
870
|
+
* - As collection: `for (const idea of db.Idea) { ... }`
|
|
871
|
+
*/
|
|
872
|
+
export interface EntityCollection<T extends Record<string, unknown> = Record<string, unknown>> extends Iterable<T> {
|
|
873
|
+
/** The type name of entities in this collection */
|
|
874
|
+
readonly $type: string;
|
|
875
|
+
/** Current count of entities in the local collection */
|
|
876
|
+
readonly $count: number;
|
|
877
|
+
/** Execute a function for each entity, returns a Job for tracking */
|
|
878
|
+
forEach(fn: (item: T) => void): Job<void>;
|
|
879
|
+
/** Transform each entity, returns a Combinable for chaining */
|
|
880
|
+
map<R>(fn: (item: T) => R): Combinable<R>;
|
|
881
|
+
/** Filter entities by predicate, returns a Combinable for chaining */
|
|
882
|
+
where(predicate: (item: T) => boolean): Combinable<T>;
|
|
883
|
+
/** Fetch all entities from API and populate collection */
|
|
884
|
+
fetchAll(): Promise<T[]>;
|
|
885
|
+
/** Factory function signature - call the collection to generate/fetch an entity */
|
|
886
|
+
(id: string, context?: Record<string, unknown>): Promise<T>;
|
|
887
|
+
}
|
|
888
|
+
export interface DBInstance<T = Record<string, unknown>> {
|
|
889
|
+
id: string;
|
|
890
|
+
type: string;
|
|
891
|
+
data: T;
|
|
892
|
+
}
|
|
893
|
+
export type GeneratedObject = Record<string, unknown>;
|
|
894
|
+
export type TypeFactory = (id: string, context?: Record<string, unknown>) => Promise<GeneratedObject>;
|
|
895
|
+
export interface DBResultBase {
|
|
896
|
+
schema: SchemaDefinition;
|
|
897
|
+
types: Record<string, ParsedType>;
|
|
898
|
+
hash: string;
|
|
899
|
+
id?: string;
|
|
900
|
+
context?: string;
|
|
901
|
+
namespace: string;
|
|
902
|
+
baseUrl: string;
|
|
903
|
+
instances: DBInstance[];
|
|
904
|
+
toJSONSchema: (typeName: string) => JSONSchema;
|
|
905
|
+
registerSchema: () => Promise<void>;
|
|
906
|
+
}
|
|
907
|
+
export type DBResult = DBResultBase & Record<string, EntityCollection>;
|
|
908
|
+
/**
|
|
909
|
+
* Create a database instance from a schema definition.
|
|
910
|
+
*
|
|
911
|
+
* This is the main entry point for defining and working with a db4.ai schema.
|
|
912
|
+
* It parses the schema, registers it with the API, and returns a typed object
|
|
913
|
+
* that provides access to all defined types as EntityCollections.
|
|
914
|
+
*
|
|
915
|
+
* ## API Base URL Configuration
|
|
916
|
+
*
|
|
917
|
+
* The SDK determines the API base URL in the following priority order:
|
|
918
|
+
* 1. Host from `$id` if it's a full URL (e.g., `'https://custom.api.com/myapp'`)
|
|
919
|
+
* 2. `DB4AI_API_BASE` environment variable
|
|
920
|
+
* 3. Default: `'https://db4ai.dev'`
|
|
921
|
+
*
|
|
922
|
+
* @param schema - The schema definition object. Must include either:
|
|
923
|
+
* - `$id` - A URL or namespace identifier (e.g., `'https://db.sb/blog'` or `'blog'`)
|
|
924
|
+
* - `$context` - A namespace string (e.g., `'my-app'`)
|
|
925
|
+
*
|
|
926
|
+
* Type definitions are records where keys are type names and values define fields.
|
|
927
|
+
*
|
|
928
|
+
* @returns A DBResult object providing:
|
|
929
|
+
* - `schema` - The original schema definition
|
|
930
|
+
* - `types` - Parsed type definitions
|
|
931
|
+
* - `hash` - Schema version hash
|
|
932
|
+
* - `namespace` - The resolved namespace
|
|
933
|
+
* - `baseUrl` - API base URL
|
|
934
|
+
* - `toJSONSchema(typeName)` - Convert a type to JSON Schema
|
|
935
|
+
* - `registerSchema()` - Manually register the schema with the API
|
|
936
|
+
* - Dynamic type accessors (e.g., `db.Post`, `db.User`) as EntityCollections
|
|
937
|
+
*
|
|
938
|
+
* @throws Error if neither `$id` nor `$context` is provided
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* // Define a blog schema
|
|
942
|
+
* const db = DB({
|
|
943
|
+
* $context: 'blog',
|
|
944
|
+
* Post: {
|
|
945
|
+
* title: 'Post title',
|
|
946
|
+
* content: 'Main content',
|
|
947
|
+
* author: '->User',
|
|
948
|
+
* tags: ['List 3-5 keywords']
|
|
949
|
+
* },
|
|
950
|
+
* User: {
|
|
951
|
+
* name: 'User name',
|
|
952
|
+
* email: 'Email address'
|
|
953
|
+
* }
|
|
954
|
+
* })
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* // Generate a new post
|
|
958
|
+
* const post = await db.Post('my-first-post', { topic: 'AI' })
|
|
959
|
+
* console.log(post.title, post.content)
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* // Fetch all posts and iterate
|
|
963
|
+
* await db.Post.fetchAll()
|
|
964
|
+
* for (const post of db.Post) {
|
|
965
|
+
* console.log(post.title)
|
|
966
|
+
* }
|
|
967
|
+
*
|
|
968
|
+
* @example
|
|
969
|
+
* // Use with full URL
|
|
970
|
+
* const db = DB({
|
|
971
|
+
* $id: 'https://db.sb/startups',
|
|
972
|
+
* Company: {
|
|
973
|
+
* name: 'Company name',
|
|
974
|
+
* description: 'Company description'
|
|
975
|
+
* }
|
|
976
|
+
* })
|
|
977
|
+
*/
|
|
978
|
+
export declare function DB(schema: SchemaDefinition): DBResult;
|
|
979
|
+
/**
|
|
980
|
+
* A lazy pipeline builder for cartesian products and collection transformations.
|
|
981
|
+
*
|
|
982
|
+
* Combinable provides a fluent API for building transformation pipelines where
|
|
983
|
+
* no computation happens until a terminal operation is invoked. This enables
|
|
984
|
+
* efficient processing of large datasets and cartesian products.
|
|
985
|
+
*
|
|
986
|
+
* Key features:
|
|
987
|
+
* - Lazy evaluation: transformations are only applied when results are consumed
|
|
988
|
+
* - Chainable: all intermediate operations return new Combinable instances
|
|
989
|
+
* - Iterable: works with for...of loops and spread operator
|
|
990
|
+
*
|
|
991
|
+
* Intermediate operations (return Combinable):
|
|
992
|
+
* - `where(predicate)` - Filter items by predicate
|
|
993
|
+
* - `map(fn)` - Transform each item
|
|
994
|
+
* - `take(n)` - Limit to first n items
|
|
995
|
+
* - `skip(n)` - Skip first n items
|
|
996
|
+
*
|
|
997
|
+
* Terminal operations (trigger evaluation):
|
|
998
|
+
* - `all()` - Collect all results into an array
|
|
999
|
+
* - `first()` - Get the first result or undefined
|
|
1000
|
+
* - `count()` - Count total results
|
|
1001
|
+
* - Iteration via for...of or spread
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* // Basic cartesian product
|
|
1005
|
+
* const pairs = combine([1, 2, 3], ['a', 'b']).all()
|
|
1006
|
+
* // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], [3, 'a'], [3, 'b']]
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* // Chained transformations
|
|
1010
|
+
* const result = combine([1, 2, 3], [10, 20, 30])
|
|
1011
|
+
* .where(([a, b]) => a + b > 15)
|
|
1012
|
+
* .map(([a, b]) => a * b)
|
|
1013
|
+
* .take(3)
|
|
1014
|
+
* .all()
|
|
1015
|
+
* // [20, 30, 40]
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* // Lazy evaluation with for...of
|
|
1019
|
+
* for (const [x, y] of combine(range(1000), range(1000)).take(10)) {
|
|
1020
|
+
* console.log(x, y) // Only computes first 10 pairs
|
|
1021
|
+
* }
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* // From EntityCollection
|
|
1025
|
+
* await db.User.fetchAll()
|
|
1026
|
+
* const activeUsers = db.User
|
|
1027
|
+
* .where(user => user.isActive)
|
|
1028
|
+
* .map(user => user.email)
|
|
1029
|
+
* .all()
|
|
1030
|
+
*/
|
|
1031
|
+
export declare class Combinable<T> implements Iterable<T> {
|
|
1032
|
+
private readonly source;
|
|
1033
|
+
constructor(source: () => Generator<T>);
|
|
1034
|
+
/**
|
|
1035
|
+
* Filter combinations by predicate
|
|
1036
|
+
*/
|
|
1037
|
+
where(predicate: (item: T) => boolean): Combinable<T>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Transform each combination
|
|
1040
|
+
*/
|
|
1041
|
+
map<R>(fn: (item: T) => R): Combinable<R>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Limit to first n items
|
|
1044
|
+
*/
|
|
1045
|
+
take(n: number): Combinable<T>;
|
|
1046
|
+
/**
|
|
1047
|
+
* Skip first n items
|
|
1048
|
+
*/
|
|
1049
|
+
skip(n: number): Combinable<T>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Collect all results into an array (terminal operation)
|
|
1052
|
+
*/
|
|
1053
|
+
all(): T[];
|
|
1054
|
+
/**
|
|
1055
|
+
* Get the first result or undefined (terminal operation)
|
|
1056
|
+
*/
|
|
1057
|
+
first(): T | undefined;
|
|
1058
|
+
/**
|
|
1059
|
+
* Count total results (terminal operation)
|
|
1060
|
+
*/
|
|
1061
|
+
count(): number;
|
|
1062
|
+
/**
|
|
1063
|
+
* Make Combinable iterable with for...of and spread operator
|
|
1064
|
+
*/
|
|
1065
|
+
[Symbol.iterator](): Iterator<T>;
|
|
1066
|
+
}
|
|
1067
|
+
export declare function combine<A, B>(a: Iterable<A>, b: Iterable<B>): Combinable<[A, B]>;
|
|
1068
|
+
export declare function combine<A, B, C>(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>): Combinable<[A, B, C]>;
|
|
1069
|
+
export declare function combine<A, B, C, D>(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, d: Iterable<D>): Combinable<[A, B, C, D]>;
|
|
1070
|
+
export declare function combine<A, B, C, D, E>(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, d: Iterable<D>, e: Iterable<E>): Combinable<[A, B, C, D, E]>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Result of parsing MDX frontmatter
|
|
1073
|
+
*/
|
|
1074
|
+
export interface ParseMDXResult {
|
|
1075
|
+
/** Parsed schema definition from YAML frontmatter */
|
|
1076
|
+
schema: SchemaDefinition;
|
|
1077
|
+
/** Remaining MDX body after frontmatter */
|
|
1078
|
+
body: string;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Parse MDX frontmatter and extract schema definition.
|
|
1082
|
+
*
|
|
1083
|
+
* @param mdx - The MDX content with optional YAML frontmatter
|
|
1084
|
+
* @returns Object with parsed schema and remaining body
|
|
1085
|
+
* @throws Error if YAML syntax is invalid
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* const mdx = `---
|
|
1089
|
+
* $context: https://db.sb
|
|
1090
|
+
* Idea:
|
|
1091
|
+
* concept: What is the concept?
|
|
1092
|
+
* ---
|
|
1093
|
+
*
|
|
1094
|
+
* <App>content</App>`
|
|
1095
|
+
*
|
|
1096
|
+
* const { schema, body } = parseMDX(mdx)
|
|
1097
|
+
* // schema = { $context: 'https://db.sb', Idea: { concept: 'What is the concept?' } }
|
|
1098
|
+
* // body = '\n<App>content</App>'
|
|
1099
|
+
*/
|
|
1100
|
+
export declare function parseMDX(mdx: string): ParseMDXResult;
|
|
1101
|
+
/**
|
|
1102
|
+
* Hook context passed to entity hooks
|
|
1103
|
+
*/
|
|
1104
|
+
export interface HookContext {
|
|
1105
|
+
generate: (types: string | string[]) => Promise<void>;
|
|
1106
|
+
changed?: Record<string, boolean>;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Entity lifecycle hooks
|
|
1110
|
+
*/
|
|
1111
|
+
export interface EntityHooks {
|
|
1112
|
+
onCreate?: (entity: unknown, ctx: HookContext) => Promise<void>;
|
|
1113
|
+
onUpdate?: (entity: unknown, ctx: HookContext) => Promise<void>;
|
|
1114
|
+
onDelete?: (entity: unknown) => Promise<void>;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Navigation group in the sidebar
|
|
1118
|
+
*/
|
|
1119
|
+
export interface NavigationGroup {
|
|
1120
|
+
name: string;
|
|
1121
|
+
icon?: string;
|
|
1122
|
+
children: (NavigationGroup | string)[];
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* Field configuration from <Field> elements
|
|
1126
|
+
*/
|
|
1127
|
+
export interface FieldConfig {
|
|
1128
|
+
name: string;
|
|
1129
|
+
lines?: number;
|
|
1130
|
+
placeholder?: string;
|
|
1131
|
+
display?: 'card' | 'link' | 'inline';
|
|
1132
|
+
allowCreate?: boolean;
|
|
1133
|
+
searchable?: boolean;
|
|
1134
|
+
preview?: string[];
|
|
1135
|
+
collapsed?: boolean;
|
|
1136
|
+
readOnly?: boolean;
|
|
1137
|
+
required?: boolean;
|
|
1138
|
+
min?: number;
|
|
1139
|
+
max?: number;
|
|
1140
|
+
span?: number;
|
|
1141
|
+
autoFocus?: boolean;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Section configuration from <Section> elements
|
|
1145
|
+
*/
|
|
1146
|
+
export interface SectionConfig {
|
|
1147
|
+
label: string;
|
|
1148
|
+
collapsed?: boolean;
|
|
1149
|
+
children?: (FieldConfig | SectionConfig)[];
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Search configuration from <Search> elements
|
|
1153
|
+
*/
|
|
1154
|
+
export interface SearchConfig {
|
|
1155
|
+
fields?: string[];
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Filter configuration from <Filter> elements
|
|
1159
|
+
*/
|
|
1160
|
+
export interface FilterConfig {
|
|
1161
|
+
field: string;
|
|
1162
|
+
exists?: boolean;
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Action configuration for generate/built-in actions
|
|
1166
|
+
*/
|
|
1167
|
+
export interface ActionConfig {
|
|
1168
|
+
type: 'generate' | 'delete' | 'duplicate' | 'export' | 'import';
|
|
1169
|
+
entity?: string;
|
|
1170
|
+
context?: string[];
|
|
1171
|
+
confirm?: string;
|
|
1172
|
+
formats?: string[];
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Role-based permission configuration
|
|
1176
|
+
*/
|
|
1177
|
+
export interface RoleConfig {
|
|
1178
|
+
name: string;
|
|
1179
|
+
actions: string[];
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Template configuration for Cards/Detail views
|
|
1183
|
+
*/
|
|
1184
|
+
export interface TemplateConfig {
|
|
1185
|
+
jsx: string;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Form configuration from <Form> elements
|
|
1189
|
+
*/
|
|
1190
|
+
export interface FormConfig {
|
|
1191
|
+
layout?: 'stack' | 'grid';
|
|
1192
|
+
fields?: string[];
|
|
1193
|
+
children?: (FieldConfig | SectionConfig)[];
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Display component configuration
|
|
1197
|
+
*/
|
|
1198
|
+
export interface DisplayConfig {
|
|
1199
|
+
type: 'table' | 'grid' | 'cards';
|
|
1200
|
+
columns?: string[];
|
|
1201
|
+
sortable?: boolean;
|
|
1202
|
+
template?: TemplateConfig;
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* View configuration (List, Detail, Edit, Create)
|
|
1206
|
+
*/
|
|
1207
|
+
export interface ViewConfig {
|
|
1208
|
+
search?: SearchConfig;
|
|
1209
|
+
filters?: FilterConfig[];
|
|
1210
|
+
display?: DisplayConfig;
|
|
1211
|
+
form?: FormConfig;
|
|
1212
|
+
template?: TemplateConfig;
|
|
1213
|
+
editor?: {
|
|
1214
|
+
language: string;
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Collection configuration for a schema type
|
|
1219
|
+
*/
|
|
1220
|
+
export interface CollectionConfig {
|
|
1221
|
+
view?: 'table' | 'cards' | 'grid';
|
|
1222
|
+
columns?: string[];
|
|
1223
|
+
searchable?: boolean;
|
|
1224
|
+
path?: string;
|
|
1225
|
+
slug?: string;
|
|
1226
|
+
list?: ViewConfig;
|
|
1227
|
+
detail?: ViewConfig;
|
|
1228
|
+
edit?: ViewConfig;
|
|
1229
|
+
create?: ViewConfig;
|
|
1230
|
+
actions?: ActionConfig[];
|
|
1231
|
+
permissions?: RoleConfig[];
|
|
1232
|
+
hooks?: EntityHooks;
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Complete UI configuration parsed from JSX
|
|
1236
|
+
*/
|
|
1237
|
+
export interface UIConfig {
|
|
1238
|
+
hooks: Record<string, EntityHooks>;
|
|
1239
|
+
navigation: NavigationGroup[];
|
|
1240
|
+
collections: Record<string, CollectionConfig>;
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Parse JSX UI specification into UIConfig
|
|
1244
|
+
*
|
|
1245
|
+
* @param jsx - The JSX string to parse
|
|
1246
|
+
* @param schema - The parsed schema to determine which elements are collections
|
|
1247
|
+
* @returns Parsed UI configuration
|
|
1248
|
+
* @throws Error if JSX syntax is invalid or no App root element
|
|
1249
|
+
*
|
|
1250
|
+
* @example
|
|
1251
|
+
* const jsx = `
|
|
1252
|
+
* <App hooks={{ Startup: { onCreate: async () => {} } }}>
|
|
1253
|
+
* <Planning icon="lightbulb">
|
|
1254
|
+
* <Idea view="cards" />
|
|
1255
|
+
* </Planning>
|
|
1256
|
+
* </App>
|
|
1257
|
+
* `
|
|
1258
|
+
* const config = parseJSXUI(jsx, schema)
|
|
1259
|
+
* // config.hooks = { Startup: { onCreate: ... } }
|
|
1260
|
+
* // config.navigation = [{ name: 'Planning', icon: 'lightbulb', children: ['Idea'] }]
|
|
1261
|
+
* // config.collections = { Idea: { view: 'cards' } }
|
|
1262
|
+
*/
|
|
1263
|
+
export declare function parseJSXUI(jsx: string, schema: ParsedSchema): UIConfig;
|
|
1264
|
+
/**
|
|
1265
|
+
* Result of processing an MDX file
|
|
1266
|
+
*/
|
|
1267
|
+
export interface ProcessMDXResult {
|
|
1268
|
+
/** Raw YAML schema definition */
|
|
1269
|
+
schema: SchemaDefinition;
|
|
1270
|
+
/** Parsed schema with types, fields, and references */
|
|
1271
|
+
parsedSchema: ParsedSchema;
|
|
1272
|
+
/** Parsed JSX UI configuration */
|
|
1273
|
+
uiConfig: UIConfig;
|
|
1274
|
+
/** Original JSX body (after frontmatter) */
|
|
1275
|
+
rawBody: string;
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Process an MDX file and return all parsed components.
|
|
1279
|
+
*/
|
|
1280
|
+
export declare function processMDX(mdx: string): ProcessMDXResult;
|
|
1281
|
+
//# sourceMappingURL=index.d.ts.map
|