@flexkit/schema 0.0.0-stage → 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 +21 -0
- package/README.md +34 -2
- package/dist/index.cjs +319 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +304 -0
- package/dist/index.d.ts +304 -0
- package/dist/index.js +281 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ScopeType = 'local' | 'global' | 'relationship';
|
|
4
|
+
type DataType = 'cartesianpoint' | 'bigint' | 'boolean' | 'date' | 'datetime' | 'duration' | 'float' | 'id' | 'int' | 'point' | 'string' | 'time' | 'asset';
|
|
5
|
+
type DefaultValueByDataType = {
|
|
6
|
+
asset: '';
|
|
7
|
+
bigint: string;
|
|
8
|
+
boolean: boolean | '';
|
|
9
|
+
cartesianpoint: string;
|
|
10
|
+
date: string;
|
|
11
|
+
datetime: string;
|
|
12
|
+
duration: string;
|
|
13
|
+
float: number | '';
|
|
14
|
+
id: string;
|
|
15
|
+
int: number | '';
|
|
16
|
+
point: string;
|
|
17
|
+
string: string;
|
|
18
|
+
time: string;
|
|
19
|
+
};
|
|
20
|
+
type DefaultValue<T extends DataType = DataType> = DefaultValueByDataType[T];
|
|
21
|
+
type InputType = 'datetime' | 'editor' | 'asset' | 'number' | 'relationship' | 'select' | 'switch' | 'text' | 'textarea' | (string & NonNullable<unknown>);
|
|
22
|
+
type PreviewType = 'boolean' | 'text' | 'number' | 'date' | 'datetime' | 'editor' | 'select' | 'relationship' | 'switch' | 'textarea'
|
|
23
|
+
/** Filled stars for a numeric value; `options.max` sets the star count (default 5). */
|
|
24
|
+
| 'rating' | (string & NonNullable<unknown>);
|
|
25
|
+
type SelectList = {
|
|
26
|
+
label: string;
|
|
27
|
+
value: string;
|
|
28
|
+
};
|
|
29
|
+
type GroupedSelectList = {
|
|
30
|
+
groupLabel: string;
|
|
31
|
+
items: SelectList[];
|
|
32
|
+
};
|
|
33
|
+
type CommonOptions = {
|
|
34
|
+
comment?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
};
|
|
38
|
+
type SelectOptions = CommonOptions & {
|
|
39
|
+
list: SelectList[] | GroupedSelectList[];
|
|
40
|
+
};
|
|
41
|
+
type AssetOptions = CommonOptions & {
|
|
42
|
+
accept?: string;
|
|
43
|
+
};
|
|
44
|
+
type RelationshipOptions = CommonOptions & {
|
|
45
|
+
accept?: string;
|
|
46
|
+
};
|
|
47
|
+
type DateTimeOptions = CommonOptions & {
|
|
48
|
+
format?: string;
|
|
49
|
+
};
|
|
50
|
+
type NumberOptions = CommonOptions & {
|
|
51
|
+
min?: number;
|
|
52
|
+
/** Upper bound; also the number of stars when `previewType` is `'rating'`. */
|
|
53
|
+
max?: number;
|
|
54
|
+
};
|
|
55
|
+
type AttributeOptions = {
|
|
56
|
+
select: SelectOptions;
|
|
57
|
+
asset: AssetOptions;
|
|
58
|
+
datetime: DateTimeOptions;
|
|
59
|
+
number: NumberOptions;
|
|
60
|
+
relationship: RelationshipOptions;
|
|
61
|
+
text: CommonOptions;
|
|
62
|
+
textarea: CommonOptions;
|
|
63
|
+
switch: CommonOptions;
|
|
64
|
+
[key: string]: CommonOptions;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Authoring form of an attribute's validation: a function that receives the
|
|
68
|
+
* Zod namespace and returns a schema. `flexkit deploy` compiles it to JSON
|
|
69
|
+
* Schema; only what JSON Schema can express survives (no `refine`, no
|
|
70
|
+
* `transform`, no async checks).
|
|
71
|
+
*/
|
|
72
|
+
type ZodValidation = (zod: typeof z) => z.ZodType;
|
|
73
|
+
/** A JSON Schema (draft-07) fragment, as stored by the backend and read by the Studio. */
|
|
74
|
+
type JsonSchemaObject = {
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
77
|
+
type AttributeBaseOf<TValidation> = {
|
|
78
|
+
inputType: InputType;
|
|
79
|
+
previewType?: PreviewType;
|
|
80
|
+
/**
|
|
81
|
+
* Hide the field in the form and the list column. Distinct from
|
|
82
|
+
* `entity.menu.hidden`.
|
|
83
|
+
*/
|
|
84
|
+
hidden?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Make the field read-only in the form. Read-only attributes are omitted
|
|
87
|
+
* from create/update mutations sent by the Studio and skipped during form
|
|
88
|
+
* validation.
|
|
89
|
+
*/
|
|
90
|
+
readOnly?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Marks uniqueness intent. Enforced at deploy for global non-asset attributes.
|
|
93
|
+
*/
|
|
94
|
+
unique?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Require a value at the API level: the generated GraphQL field is non-null.
|
|
97
|
+
* Applies to global scalar attributes.
|
|
98
|
+
*/
|
|
99
|
+
isRequired?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Include this attribute in search indexing and the global search UI.
|
|
102
|
+
*/
|
|
103
|
+
searchable?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Field group name(s) this attribute belongs to. Distinct from
|
|
106
|
+
* `entity.menu.group`, which is the sidebar section.
|
|
107
|
+
*/
|
|
108
|
+
group?: string | string[];
|
|
109
|
+
label: string;
|
|
110
|
+
name: string;
|
|
111
|
+
options?: AttributeOptions[InputType];
|
|
112
|
+
relationship?: {
|
|
113
|
+
entity: string;
|
|
114
|
+
mode: 'single' | 'multiple';
|
|
115
|
+
field: string;
|
|
116
|
+
};
|
|
117
|
+
validation?: TValidation;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Space codes that can read/write this attribute. Members of any listed
|
|
121
|
+
* space have access; users outside all listed spaces cannot see the value.
|
|
122
|
+
*
|
|
123
|
+
* Not allowed on relationship attributes (`scope: 'relationship'`): bind the
|
|
124
|
+
* related entity to the space instead.
|
|
125
|
+
*/
|
|
126
|
+
type AttributeSpaces = {
|
|
127
|
+
spaces?: string[];
|
|
128
|
+
};
|
|
129
|
+
type AttributeScopeAndSpaces = {
|
|
130
|
+
scope: 'relationship';
|
|
131
|
+
spaces?: never;
|
|
132
|
+
} | ({
|
|
133
|
+
scope: 'local' | 'global';
|
|
134
|
+
} & AttributeSpaces);
|
|
135
|
+
type AttributeByDataTypeOf<T extends DataType, TValidation> = AttributeBaseOf<TValidation> & {
|
|
136
|
+
dataType: T;
|
|
137
|
+
defaultValue?: DefaultValueByDataType[T];
|
|
138
|
+
} & (T extends 'asset' ? {
|
|
139
|
+
scope?: 'global';
|
|
140
|
+
} & AttributeSpaces : AttributeScopeAndSpaces);
|
|
141
|
+
type AttributeOf<TValidation> = {
|
|
142
|
+
[T in DataType]: AttributeByDataTypeOf<T, TValidation>;
|
|
143
|
+
}[DataType];
|
|
144
|
+
/** Attribute as written in `flexkit.config.ts`. */
|
|
145
|
+
type Attribute = AttributeOf<ZodValidation>;
|
|
146
|
+
/** Attribute as deployed and served by the backend (validation is JSON Schema). */
|
|
147
|
+
type UiAttribute = AttributeOf<JsonSchemaObject>;
|
|
148
|
+
/**
|
|
149
|
+
* Form-only tab that groups attributes in the edit/add drawer.
|
|
150
|
+
* Distinct from `entity.menu.group` (sidebar section).
|
|
151
|
+
*/
|
|
152
|
+
type FieldGroup = {
|
|
153
|
+
name: string;
|
|
154
|
+
/**
|
|
155
|
+
* Tab label. Required for custom groups. Optional for the reserved
|
|
156
|
+
* `all` tab; Studio uses `All fields` when it is omitted.
|
|
157
|
+
*/
|
|
158
|
+
title?: string;
|
|
159
|
+
/** Lucide icon name in PascalCase, e.g. `'Tag'`. */
|
|
160
|
+
icon?: string;
|
|
161
|
+
default?: boolean;
|
|
162
|
+
hidden?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/** Sidebar placement of an entity in the Studio. */
|
|
165
|
+
type EntityMenu = {
|
|
166
|
+
/** Leave the entity out of the sidebar. */
|
|
167
|
+
hidden?: boolean;
|
|
168
|
+
label?: string;
|
|
169
|
+
/** Name of a `menuGroups` entry of the project. */
|
|
170
|
+
group?: string;
|
|
171
|
+
/** Lucide icon name in PascalCase, e.g. `'Tag'`. */
|
|
172
|
+
icon?: string;
|
|
173
|
+
};
|
|
174
|
+
type EntityOf<TAttribute> = {
|
|
175
|
+
name: string;
|
|
176
|
+
plural: string;
|
|
177
|
+
/**
|
|
178
|
+
* Attribute name used as the human-readable label in relationship previews,
|
|
179
|
+
* search hits, and edit-drawer titles. Must match an attribute `name`.
|
|
180
|
+
* Falls back to the first attribute when omitted. The effective display
|
|
181
|
+
* attribute cannot be space-bound.
|
|
182
|
+
*/
|
|
183
|
+
display?: string;
|
|
184
|
+
menu?: EntityMenu;
|
|
185
|
+
/**
|
|
186
|
+
* Space codes that can access this entity. Members of any listed space have
|
|
187
|
+
* access; users outside all listed spaces cannot see the entity at all.
|
|
188
|
+
*/
|
|
189
|
+
spaces?: string[];
|
|
190
|
+
/**
|
|
191
|
+
* Form field groups rendered as tabs. Does not change storage.
|
|
192
|
+
* Distinct from `menu.group` (sidebar section).
|
|
193
|
+
*/
|
|
194
|
+
groups?: FieldGroup[];
|
|
195
|
+
attributes: TAttribute[];
|
|
196
|
+
};
|
|
197
|
+
/** Entity as written in `flexkit.config.ts`. */
|
|
198
|
+
type Entity = EntityOf<Attribute>;
|
|
199
|
+
/** Entity as deployed and served by the backend. */
|
|
200
|
+
type UiEntity = EntityOf<UiAttribute>;
|
|
201
|
+
type Schema = Entity[];
|
|
202
|
+
type UiSchema = UiEntity[];
|
|
203
|
+
type Scope = {
|
|
204
|
+
name: string;
|
|
205
|
+
label: string;
|
|
206
|
+
isDefault?: boolean;
|
|
207
|
+
sortOrder?: number;
|
|
208
|
+
};
|
|
209
|
+
type Scopes = Scope[];
|
|
210
|
+
type Space = {
|
|
211
|
+
code: string;
|
|
212
|
+
label: string;
|
|
213
|
+
};
|
|
214
|
+
type Spaces = Space[];
|
|
215
|
+
type MenuGroup = {
|
|
216
|
+
name: string;
|
|
217
|
+
title: string;
|
|
218
|
+
};
|
|
219
|
+
/** One project in `flexkit.config.ts`. */
|
|
220
|
+
interface ProjectConfig {
|
|
221
|
+
/** Studio title shown in the navbar. Falls back to the dashboard project name. */
|
|
222
|
+
title?: string;
|
|
223
|
+
projectId: string;
|
|
224
|
+
/** Sidebar sections; entities join one through `menu.group`. */
|
|
225
|
+
menuGroups?: MenuGroup[];
|
|
226
|
+
scopes?: Scopes;
|
|
227
|
+
/**
|
|
228
|
+
* Permission spaces for this project. Spaces scope access to entities,
|
|
229
|
+
* attributes and app resources (automations, skills, agents). Membership is
|
|
230
|
+
* assigned to project members in the Flexkit Dashboard after deploy.
|
|
231
|
+
*/
|
|
232
|
+
spaces?: Spaces;
|
|
233
|
+
schema: Entity[];
|
|
234
|
+
}
|
|
235
|
+
type Config = ProjectConfig | ProjectConfig[];
|
|
236
|
+
/** The deployable form of a project config: what `flexkit deploy` sends. */
|
|
237
|
+
interface UiProjectSchema {
|
|
238
|
+
title?: string;
|
|
239
|
+
projectId: string;
|
|
240
|
+
menuGroups?: MenuGroup[];
|
|
241
|
+
scopes?: Scopes;
|
|
242
|
+
spaces?: Spaces;
|
|
243
|
+
schema: UiEntity[];
|
|
244
|
+
}
|
|
245
|
+
/** Response of `GET /<projectId>/api/schema`: what the Studio renders from. */
|
|
246
|
+
interface ProjectSchemaResponse {
|
|
247
|
+
projectId: string;
|
|
248
|
+
title: string;
|
|
249
|
+
menuGroups: MenuGroup[];
|
|
250
|
+
scopes: Scopes;
|
|
251
|
+
spaces: Spaces;
|
|
252
|
+
schema: UiEntity[];
|
|
253
|
+
schemaHash: string | null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Types and returns a `flexkit.config.ts` export unchanged. */
|
|
257
|
+
declare function defineConfig<T extends Config>(config: T): T;
|
|
258
|
+
/**
|
|
259
|
+
* Types an entity and normalizes it: asset attributes get `scope: 'global'`,
|
|
260
|
+
* and invalid asset scopes or display attributes throw at config load time.
|
|
261
|
+
*/
|
|
262
|
+
declare function defineEntity<T extends Entity>(entity: T): Entity;
|
|
263
|
+
|
|
264
|
+
declare function normalizeEntity(entity: Entity): Entity;
|
|
265
|
+
|
|
266
|
+
/** Removes `$schema` at every level of a JSON Schema document. */
|
|
267
|
+
declare function stripJsonSchemaMeta(value: unknown): unknown;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* JSON Schema keywords the Studio form knows how to validate. Anything else
|
|
271
|
+
* fails the deploy so a rule never silently disappears between the config and
|
|
272
|
+
* the form.
|
|
273
|
+
*/
|
|
274
|
+
declare const SUPPORTED_VALIDATION_KEYWORDS: ReadonlySet<string>;
|
|
275
|
+
declare const SUPPORTED_VALIDATION_FORMATS: ReadonlySet<string>;
|
|
276
|
+
type SerializationLocation = {
|
|
277
|
+
entity?: string;
|
|
278
|
+
attribute?: string;
|
|
279
|
+
};
|
|
280
|
+
/** Raised when a config cannot be turned into a deployable JSON schema. */
|
|
281
|
+
declare class SchemaSerializationError extends Error {
|
|
282
|
+
readonly entity: string | undefined;
|
|
283
|
+
readonly attribute: string | undefined;
|
|
284
|
+
constructor(reason: string, location?: SerializationLocation, options?: {
|
|
285
|
+
cause?: unknown;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Compiles an attribute's Zod validation to a JSON Schema (draft-07) fragment.
|
|
290
|
+
* Throws `SchemaSerializationError` for anything the Studio cannot enforce.
|
|
291
|
+
*/
|
|
292
|
+
declare function serializeValidation(validation: ZodValidation, location?: SerializationLocation): JsonSchemaObject;
|
|
293
|
+
declare function serializeAttribute(attribute: Attribute, entityName: string): UiAttribute;
|
|
294
|
+
declare function serializeEntity(entity: Entity): UiEntity;
|
|
295
|
+
/**
|
|
296
|
+
* Turns one project of a `flexkit.config.ts` into the payload `flexkit deploy`
|
|
297
|
+
* sends. Only data survives: title, projectId, menuGroups, scopes, spaces and
|
|
298
|
+
* the schema with validation compiled to JSON Schema.
|
|
299
|
+
*/
|
|
300
|
+
declare function serializeProjectConfig(project: ProjectConfig): UiProjectSchema;
|
|
301
|
+
/** Serializes a whole `flexkit.config.ts` export (one project or a list). */
|
|
302
|
+
declare function serializeConfig(config: Config): UiProjectSchema[];
|
|
303
|
+
|
|
304
|
+
export { type AssetOptions, type Attribute, type AttributeOf, type AttributeOptions, type CommonOptions, type Config, type DataType, type DateTimeOptions, type DefaultValue, type DefaultValueByDataType, type Entity, type EntityMenu, type EntityOf, type FieldGroup, type GroupedSelectList, type InputType, type JsonSchemaObject, type MenuGroup, type NumberOptions, type PreviewType, type ProjectConfig, type ProjectSchemaResponse, type RelationshipOptions, SUPPORTED_VALIDATION_FORMATS, SUPPORTED_VALIDATION_KEYWORDS, type Schema, SchemaSerializationError, type Scope, type ScopeType, type Scopes, type SelectList, type SelectOptions, type Space, type Spaces, type UiAttribute, type UiEntity, type UiProjectSchema, type UiSchema, type ZodValidation, defineConfig, defineEntity, normalizeEntity, serializeAttribute, serializeConfig, serializeEntity, serializeProjectConfig, serializeValidation, stripJsonSchemaMeta };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ScopeType = 'local' | 'global' | 'relationship';
|
|
4
|
+
type DataType = 'cartesianpoint' | 'bigint' | 'boolean' | 'date' | 'datetime' | 'duration' | 'float' | 'id' | 'int' | 'point' | 'string' | 'time' | 'asset';
|
|
5
|
+
type DefaultValueByDataType = {
|
|
6
|
+
asset: '';
|
|
7
|
+
bigint: string;
|
|
8
|
+
boolean: boolean | '';
|
|
9
|
+
cartesianpoint: string;
|
|
10
|
+
date: string;
|
|
11
|
+
datetime: string;
|
|
12
|
+
duration: string;
|
|
13
|
+
float: number | '';
|
|
14
|
+
id: string;
|
|
15
|
+
int: number | '';
|
|
16
|
+
point: string;
|
|
17
|
+
string: string;
|
|
18
|
+
time: string;
|
|
19
|
+
};
|
|
20
|
+
type DefaultValue<T extends DataType = DataType> = DefaultValueByDataType[T];
|
|
21
|
+
type InputType = 'datetime' | 'editor' | 'asset' | 'number' | 'relationship' | 'select' | 'switch' | 'text' | 'textarea' | (string & NonNullable<unknown>);
|
|
22
|
+
type PreviewType = 'boolean' | 'text' | 'number' | 'date' | 'datetime' | 'editor' | 'select' | 'relationship' | 'switch' | 'textarea'
|
|
23
|
+
/** Filled stars for a numeric value; `options.max` sets the star count (default 5). */
|
|
24
|
+
| 'rating' | (string & NonNullable<unknown>);
|
|
25
|
+
type SelectList = {
|
|
26
|
+
label: string;
|
|
27
|
+
value: string;
|
|
28
|
+
};
|
|
29
|
+
type GroupedSelectList = {
|
|
30
|
+
groupLabel: string;
|
|
31
|
+
items: SelectList[];
|
|
32
|
+
};
|
|
33
|
+
type CommonOptions = {
|
|
34
|
+
comment?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
};
|
|
38
|
+
type SelectOptions = CommonOptions & {
|
|
39
|
+
list: SelectList[] | GroupedSelectList[];
|
|
40
|
+
};
|
|
41
|
+
type AssetOptions = CommonOptions & {
|
|
42
|
+
accept?: string;
|
|
43
|
+
};
|
|
44
|
+
type RelationshipOptions = CommonOptions & {
|
|
45
|
+
accept?: string;
|
|
46
|
+
};
|
|
47
|
+
type DateTimeOptions = CommonOptions & {
|
|
48
|
+
format?: string;
|
|
49
|
+
};
|
|
50
|
+
type NumberOptions = CommonOptions & {
|
|
51
|
+
min?: number;
|
|
52
|
+
/** Upper bound; also the number of stars when `previewType` is `'rating'`. */
|
|
53
|
+
max?: number;
|
|
54
|
+
};
|
|
55
|
+
type AttributeOptions = {
|
|
56
|
+
select: SelectOptions;
|
|
57
|
+
asset: AssetOptions;
|
|
58
|
+
datetime: DateTimeOptions;
|
|
59
|
+
number: NumberOptions;
|
|
60
|
+
relationship: RelationshipOptions;
|
|
61
|
+
text: CommonOptions;
|
|
62
|
+
textarea: CommonOptions;
|
|
63
|
+
switch: CommonOptions;
|
|
64
|
+
[key: string]: CommonOptions;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Authoring form of an attribute's validation: a function that receives the
|
|
68
|
+
* Zod namespace and returns a schema. `flexkit deploy` compiles it to JSON
|
|
69
|
+
* Schema; only what JSON Schema can express survives (no `refine`, no
|
|
70
|
+
* `transform`, no async checks).
|
|
71
|
+
*/
|
|
72
|
+
type ZodValidation = (zod: typeof z) => z.ZodType;
|
|
73
|
+
/** A JSON Schema (draft-07) fragment, as stored by the backend and read by the Studio. */
|
|
74
|
+
type JsonSchemaObject = {
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
77
|
+
type AttributeBaseOf<TValidation> = {
|
|
78
|
+
inputType: InputType;
|
|
79
|
+
previewType?: PreviewType;
|
|
80
|
+
/**
|
|
81
|
+
* Hide the field in the form and the list column. Distinct from
|
|
82
|
+
* `entity.menu.hidden`.
|
|
83
|
+
*/
|
|
84
|
+
hidden?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Make the field read-only in the form. Read-only attributes are omitted
|
|
87
|
+
* from create/update mutations sent by the Studio and skipped during form
|
|
88
|
+
* validation.
|
|
89
|
+
*/
|
|
90
|
+
readOnly?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Marks uniqueness intent. Enforced at deploy for global non-asset attributes.
|
|
93
|
+
*/
|
|
94
|
+
unique?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Require a value at the API level: the generated GraphQL field is non-null.
|
|
97
|
+
* Applies to global scalar attributes.
|
|
98
|
+
*/
|
|
99
|
+
isRequired?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Include this attribute in search indexing and the global search UI.
|
|
102
|
+
*/
|
|
103
|
+
searchable?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Field group name(s) this attribute belongs to. Distinct from
|
|
106
|
+
* `entity.menu.group`, which is the sidebar section.
|
|
107
|
+
*/
|
|
108
|
+
group?: string | string[];
|
|
109
|
+
label: string;
|
|
110
|
+
name: string;
|
|
111
|
+
options?: AttributeOptions[InputType];
|
|
112
|
+
relationship?: {
|
|
113
|
+
entity: string;
|
|
114
|
+
mode: 'single' | 'multiple';
|
|
115
|
+
field: string;
|
|
116
|
+
};
|
|
117
|
+
validation?: TValidation;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Space codes that can read/write this attribute. Members of any listed
|
|
121
|
+
* space have access; users outside all listed spaces cannot see the value.
|
|
122
|
+
*
|
|
123
|
+
* Not allowed on relationship attributes (`scope: 'relationship'`): bind the
|
|
124
|
+
* related entity to the space instead.
|
|
125
|
+
*/
|
|
126
|
+
type AttributeSpaces = {
|
|
127
|
+
spaces?: string[];
|
|
128
|
+
};
|
|
129
|
+
type AttributeScopeAndSpaces = {
|
|
130
|
+
scope: 'relationship';
|
|
131
|
+
spaces?: never;
|
|
132
|
+
} | ({
|
|
133
|
+
scope: 'local' | 'global';
|
|
134
|
+
} & AttributeSpaces);
|
|
135
|
+
type AttributeByDataTypeOf<T extends DataType, TValidation> = AttributeBaseOf<TValidation> & {
|
|
136
|
+
dataType: T;
|
|
137
|
+
defaultValue?: DefaultValueByDataType[T];
|
|
138
|
+
} & (T extends 'asset' ? {
|
|
139
|
+
scope?: 'global';
|
|
140
|
+
} & AttributeSpaces : AttributeScopeAndSpaces);
|
|
141
|
+
type AttributeOf<TValidation> = {
|
|
142
|
+
[T in DataType]: AttributeByDataTypeOf<T, TValidation>;
|
|
143
|
+
}[DataType];
|
|
144
|
+
/** Attribute as written in `flexkit.config.ts`. */
|
|
145
|
+
type Attribute = AttributeOf<ZodValidation>;
|
|
146
|
+
/** Attribute as deployed and served by the backend (validation is JSON Schema). */
|
|
147
|
+
type UiAttribute = AttributeOf<JsonSchemaObject>;
|
|
148
|
+
/**
|
|
149
|
+
* Form-only tab that groups attributes in the edit/add drawer.
|
|
150
|
+
* Distinct from `entity.menu.group` (sidebar section).
|
|
151
|
+
*/
|
|
152
|
+
type FieldGroup = {
|
|
153
|
+
name: string;
|
|
154
|
+
/**
|
|
155
|
+
* Tab label. Required for custom groups. Optional for the reserved
|
|
156
|
+
* `all` tab; Studio uses `All fields` when it is omitted.
|
|
157
|
+
*/
|
|
158
|
+
title?: string;
|
|
159
|
+
/** Lucide icon name in PascalCase, e.g. `'Tag'`. */
|
|
160
|
+
icon?: string;
|
|
161
|
+
default?: boolean;
|
|
162
|
+
hidden?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/** Sidebar placement of an entity in the Studio. */
|
|
165
|
+
type EntityMenu = {
|
|
166
|
+
/** Leave the entity out of the sidebar. */
|
|
167
|
+
hidden?: boolean;
|
|
168
|
+
label?: string;
|
|
169
|
+
/** Name of a `menuGroups` entry of the project. */
|
|
170
|
+
group?: string;
|
|
171
|
+
/** Lucide icon name in PascalCase, e.g. `'Tag'`. */
|
|
172
|
+
icon?: string;
|
|
173
|
+
};
|
|
174
|
+
type EntityOf<TAttribute> = {
|
|
175
|
+
name: string;
|
|
176
|
+
plural: string;
|
|
177
|
+
/**
|
|
178
|
+
* Attribute name used as the human-readable label in relationship previews,
|
|
179
|
+
* search hits, and edit-drawer titles. Must match an attribute `name`.
|
|
180
|
+
* Falls back to the first attribute when omitted. The effective display
|
|
181
|
+
* attribute cannot be space-bound.
|
|
182
|
+
*/
|
|
183
|
+
display?: string;
|
|
184
|
+
menu?: EntityMenu;
|
|
185
|
+
/**
|
|
186
|
+
* Space codes that can access this entity. Members of any listed space have
|
|
187
|
+
* access; users outside all listed spaces cannot see the entity at all.
|
|
188
|
+
*/
|
|
189
|
+
spaces?: string[];
|
|
190
|
+
/**
|
|
191
|
+
* Form field groups rendered as tabs. Does not change storage.
|
|
192
|
+
* Distinct from `menu.group` (sidebar section).
|
|
193
|
+
*/
|
|
194
|
+
groups?: FieldGroup[];
|
|
195
|
+
attributes: TAttribute[];
|
|
196
|
+
};
|
|
197
|
+
/** Entity as written in `flexkit.config.ts`. */
|
|
198
|
+
type Entity = EntityOf<Attribute>;
|
|
199
|
+
/** Entity as deployed and served by the backend. */
|
|
200
|
+
type UiEntity = EntityOf<UiAttribute>;
|
|
201
|
+
type Schema = Entity[];
|
|
202
|
+
type UiSchema = UiEntity[];
|
|
203
|
+
type Scope = {
|
|
204
|
+
name: string;
|
|
205
|
+
label: string;
|
|
206
|
+
isDefault?: boolean;
|
|
207
|
+
sortOrder?: number;
|
|
208
|
+
};
|
|
209
|
+
type Scopes = Scope[];
|
|
210
|
+
type Space = {
|
|
211
|
+
code: string;
|
|
212
|
+
label: string;
|
|
213
|
+
};
|
|
214
|
+
type Spaces = Space[];
|
|
215
|
+
type MenuGroup = {
|
|
216
|
+
name: string;
|
|
217
|
+
title: string;
|
|
218
|
+
};
|
|
219
|
+
/** One project in `flexkit.config.ts`. */
|
|
220
|
+
interface ProjectConfig {
|
|
221
|
+
/** Studio title shown in the navbar. Falls back to the dashboard project name. */
|
|
222
|
+
title?: string;
|
|
223
|
+
projectId: string;
|
|
224
|
+
/** Sidebar sections; entities join one through `menu.group`. */
|
|
225
|
+
menuGroups?: MenuGroup[];
|
|
226
|
+
scopes?: Scopes;
|
|
227
|
+
/**
|
|
228
|
+
* Permission spaces for this project. Spaces scope access to entities,
|
|
229
|
+
* attributes and app resources (automations, skills, agents). Membership is
|
|
230
|
+
* assigned to project members in the Flexkit Dashboard after deploy.
|
|
231
|
+
*/
|
|
232
|
+
spaces?: Spaces;
|
|
233
|
+
schema: Entity[];
|
|
234
|
+
}
|
|
235
|
+
type Config = ProjectConfig | ProjectConfig[];
|
|
236
|
+
/** The deployable form of a project config: what `flexkit deploy` sends. */
|
|
237
|
+
interface UiProjectSchema {
|
|
238
|
+
title?: string;
|
|
239
|
+
projectId: string;
|
|
240
|
+
menuGroups?: MenuGroup[];
|
|
241
|
+
scopes?: Scopes;
|
|
242
|
+
spaces?: Spaces;
|
|
243
|
+
schema: UiEntity[];
|
|
244
|
+
}
|
|
245
|
+
/** Response of `GET /<projectId>/api/schema`: what the Studio renders from. */
|
|
246
|
+
interface ProjectSchemaResponse {
|
|
247
|
+
projectId: string;
|
|
248
|
+
title: string;
|
|
249
|
+
menuGroups: MenuGroup[];
|
|
250
|
+
scopes: Scopes;
|
|
251
|
+
spaces: Spaces;
|
|
252
|
+
schema: UiEntity[];
|
|
253
|
+
schemaHash: string | null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Types and returns a `flexkit.config.ts` export unchanged. */
|
|
257
|
+
declare function defineConfig<T extends Config>(config: T): T;
|
|
258
|
+
/**
|
|
259
|
+
* Types an entity and normalizes it: asset attributes get `scope: 'global'`,
|
|
260
|
+
* and invalid asset scopes or display attributes throw at config load time.
|
|
261
|
+
*/
|
|
262
|
+
declare function defineEntity<T extends Entity>(entity: T): Entity;
|
|
263
|
+
|
|
264
|
+
declare function normalizeEntity(entity: Entity): Entity;
|
|
265
|
+
|
|
266
|
+
/** Removes `$schema` at every level of a JSON Schema document. */
|
|
267
|
+
declare function stripJsonSchemaMeta(value: unknown): unknown;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* JSON Schema keywords the Studio form knows how to validate. Anything else
|
|
271
|
+
* fails the deploy so a rule never silently disappears between the config and
|
|
272
|
+
* the form.
|
|
273
|
+
*/
|
|
274
|
+
declare const SUPPORTED_VALIDATION_KEYWORDS: ReadonlySet<string>;
|
|
275
|
+
declare const SUPPORTED_VALIDATION_FORMATS: ReadonlySet<string>;
|
|
276
|
+
type SerializationLocation = {
|
|
277
|
+
entity?: string;
|
|
278
|
+
attribute?: string;
|
|
279
|
+
};
|
|
280
|
+
/** Raised when a config cannot be turned into a deployable JSON schema. */
|
|
281
|
+
declare class SchemaSerializationError extends Error {
|
|
282
|
+
readonly entity: string | undefined;
|
|
283
|
+
readonly attribute: string | undefined;
|
|
284
|
+
constructor(reason: string, location?: SerializationLocation, options?: {
|
|
285
|
+
cause?: unknown;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Compiles an attribute's Zod validation to a JSON Schema (draft-07) fragment.
|
|
290
|
+
* Throws `SchemaSerializationError` for anything the Studio cannot enforce.
|
|
291
|
+
*/
|
|
292
|
+
declare function serializeValidation(validation: ZodValidation, location?: SerializationLocation): JsonSchemaObject;
|
|
293
|
+
declare function serializeAttribute(attribute: Attribute, entityName: string): UiAttribute;
|
|
294
|
+
declare function serializeEntity(entity: Entity): UiEntity;
|
|
295
|
+
/**
|
|
296
|
+
* Turns one project of a `flexkit.config.ts` into the payload `flexkit deploy`
|
|
297
|
+
* sends. Only data survives: title, projectId, menuGroups, scopes, spaces and
|
|
298
|
+
* the schema with validation compiled to JSON Schema.
|
|
299
|
+
*/
|
|
300
|
+
declare function serializeProjectConfig(project: ProjectConfig): UiProjectSchema;
|
|
301
|
+
/** Serializes a whole `flexkit.config.ts` export (one project or a list). */
|
|
302
|
+
declare function serializeConfig(config: Config): UiProjectSchema[];
|
|
303
|
+
|
|
304
|
+
export { type AssetOptions, type Attribute, type AttributeOf, type AttributeOptions, type CommonOptions, type Config, type DataType, type DateTimeOptions, type DefaultValue, type DefaultValueByDataType, type Entity, type EntityMenu, type EntityOf, type FieldGroup, type GroupedSelectList, type InputType, type JsonSchemaObject, type MenuGroup, type NumberOptions, type PreviewType, type ProjectConfig, type ProjectSchemaResponse, type RelationshipOptions, SUPPORTED_VALIDATION_FORMATS, SUPPORTED_VALIDATION_KEYWORDS, type Schema, SchemaSerializationError, type Scope, type ScopeType, type Scopes, type SelectList, type SelectOptions, type Space, type Spaces, type UiAttribute, type UiEntity, type UiProjectSchema, type UiSchema, type ZodValidation, defineConfig, defineEntity, normalizeEntity, serializeAttribute, serializeConfig, serializeEntity, serializeProjectConfig, serializeValidation, stripJsonSchemaMeta };
|