@stonecrop/graphql-middleware 0.8.7 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/graphql-middleware.d.ts +1168 -0
- package/dist/graphql_client.tsbuildinfo +1 -0
- package/dist/index.cjs +41 -36
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +336 -3331
- package/dist/index.js.map +1 -0
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +191 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +22 -0
- package/dist/src/plugin/postgraphile.d.ts +32 -1
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.js +281 -0
- package/dist/src/registry/actions.d.ts +1 -1
- package/dist/src/registry/actions.js +148 -0
- package/dist/src/registry/doctypes.d.ts +1 -1
- package/dist/src/registry/doctypes.js +167 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.js +2 -0
- package/dist/tests/registry.test.js +4 -0
- package/package.json +5 -6
- package/dist/index.d.ts +0 -2
|
@@ -0,0 +1,1168 @@
|
|
|
1
|
+
import { GraphileConfig as GraphileConfig_2 } from 'postgraphile/graphile-build';
|
|
2
|
+
import { GraphQLField } from 'graphql';
|
|
3
|
+
import { GraphQLObjectType } from 'graphql';
|
|
4
|
+
import type { IntrospectionQuery } from 'graphql';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Context passed to action handlers
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare interface ActionContext {
|
|
12
|
+
/** Doctype metadata for the action being executed */
|
|
13
|
+
doctype: DoctypeMeta;
|
|
14
|
+
/** GraphQL executor for running queries/mutations within the action */
|
|
15
|
+
executor: GraphQLExecutor;
|
|
16
|
+
/** Additional context properties */
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Action definition within a workflow
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare const ActionDefinition: z.ZodObject<{
|
|
25
|
+
/** Display label for the action */
|
|
26
|
+
label: z.ZodString;
|
|
27
|
+
/** Handler function name or path */
|
|
28
|
+
handler: z.ZodString;
|
|
29
|
+
/** Fields that must have values before action can execute */
|
|
30
|
+
requiredFields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
31
|
+
/** Workflow states where this action is available */
|
|
32
|
+
allowedStates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
33
|
+
/** Whether to show a confirmation dialog */
|
|
34
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
/** Additional arguments for the action */
|
|
36
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
label: string;
|
|
39
|
+
handler: string;
|
|
40
|
+
requiredFields?: string[] | undefined;
|
|
41
|
+
allowedStates?: string[] | undefined;
|
|
42
|
+
confirm?: boolean | undefined;
|
|
43
|
+
args?: Record<string, unknown> | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
label: string;
|
|
46
|
+
handler: string;
|
|
47
|
+
requiredFields?: string[] | undefined;
|
|
48
|
+
allowedStates?: string[] | undefined;
|
|
49
|
+
confirm?: boolean | undefined;
|
|
50
|
+
args?: Record<string, unknown> | undefined;
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Action definition type inferred from Zod schema
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export declare type ActionDefinition = z.infer<typeof ActionDefinition>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Action handler function signature
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Built-in handlers available for registration
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export declare const builtinHandlers: Record<string, ActionHandler>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Converts camelCase to Title Case label
|
|
73
|
+
* @param camelCase - Camel case string
|
|
74
|
+
* @returns Title case label
|
|
75
|
+
* @public
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* camelToLabel('userEmail') // 'User Email'
|
|
79
|
+
* camelToLabel('firstName') // 'First Name'
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function camelToLabel(camelCase: string): string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Converts camelCase to snake_case
|
|
86
|
+
* @param camelCase - Camel case string
|
|
87
|
+
* @returns Snake case string
|
|
88
|
+
* @public
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* camelToSnake('userEmail') // 'user_email'
|
|
92
|
+
* camelToSnake('createdAt') // 'created_at'
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function camelToSnake(camelCase: string): string;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Classify a single GraphQL field into a Stonecrop field definition.
|
|
99
|
+
*
|
|
100
|
+
* Classification rules (in order):
|
|
101
|
+
* 1. Scalar types → look up in merged scalar map
|
|
102
|
+
* 2. Enum types → `Select` with enum values as options
|
|
103
|
+
* 3. Object types that are entities → `Link` with slug as options
|
|
104
|
+
* 4. Object types that are Connections → `Doctype` with node type slug as options
|
|
105
|
+
* 5. List of entity type → `Doctype` with item type slug as options
|
|
106
|
+
* 6. Anything else → `Data` with `_unmapped: true`
|
|
107
|
+
*
|
|
108
|
+
* @param fieldName - The GraphQL field name
|
|
109
|
+
* @param field - The GraphQL field definition
|
|
110
|
+
* @param entityTypes - Set of type names classified as entities
|
|
111
|
+
* @param options - Conversion options (for custom scalars, unmapped meta, etc.)
|
|
112
|
+
* @returns The Stonecrop field definition
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
export declare function classifyFieldType(fieldName: string, field: GraphQLField<unknown, unknown>, entityTypes: Set<string>, options?: GraphQLConversionOptions): GraphQLConversionFieldMeta;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Clear all registered handlers
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export declare function clearHandlers(): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Clear all registered doctypes
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export declare function clearRegistry(): void;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Output of GraphQL schema conversion — one per entity type.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
export declare interface ConvertedGraphQLDoctype extends Omit<DoctypeMeta, 'fields'> {
|
|
135
|
+
/** Field definitions with optional GraphQL conversion metadata */
|
|
136
|
+
fields: GraphQLConversionFieldMeta[];
|
|
137
|
+
/** Original GraphQL type name (for debugging/reference) */
|
|
138
|
+
_graphqlTypeName?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Convert a GraphQL schema to Stonecrop doctype schemas.
|
|
143
|
+
*
|
|
144
|
+
* Accepts either an `IntrospectionQuery` result object or an SDL string.
|
|
145
|
+
* Entity types are identified using heuristics (or a custom `isEntityType` function)
|
|
146
|
+
* and converted to `DoctypeMeta`-compatible JSON objects.
|
|
147
|
+
*
|
|
148
|
+
* @param source - GraphQL introspection result or SDL string
|
|
149
|
+
* @param options - Conversion options for controlling output format and behavior
|
|
150
|
+
* @returns Array of converted Stonecrop doctype definitions
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // From introspection result (fetched from any GraphQL server)
|
|
155
|
+
* const introspection = await fetchIntrospection('http://localhost:5000/graphql')
|
|
156
|
+
* const doctypes = convertGraphQLSchema(introspection)
|
|
157
|
+
*
|
|
158
|
+
* // From SDL string
|
|
159
|
+
* const sdl = fs.readFileSync('schema.graphql', 'utf-8')
|
|
160
|
+
* const doctypes = convertGraphQLSchema(sdl)
|
|
161
|
+
*
|
|
162
|
+
* // With PostGraphile custom scalars
|
|
163
|
+
* const doctypes = convertGraphQLSchema(introspection, {
|
|
164
|
+
* customScalars: {
|
|
165
|
+
* BigFloat: { component: 'ADecimalInput', fieldtype: 'Decimal' }
|
|
166
|
+
* }
|
|
167
|
+
* })
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
export declare function convertGraphQLSchema(source: IntrospectionSource, options?: GraphQLConversionOptions): ConvertedGraphQLDoctype[];
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality
|
|
176
|
+
* @param options - Plugin configuration options
|
|
177
|
+
* @returns A PostGraphile plugin
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export declare const createStonecropPlugin: (options: StonecropPluginOptions) => GraphileConfig_2.Plugin;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Default heuristic to filter fields on entity types.
|
|
184
|
+
* Skips internal fields that don't represent meaningful data.
|
|
185
|
+
*
|
|
186
|
+
* @param fieldName - The GraphQL field name
|
|
187
|
+
* @param _field - The GraphQL field definition (unused in default implementation)
|
|
188
|
+
* @param _parentType - The parent entity type (unused in default implementation)
|
|
189
|
+
* @returns `true` if this field should be included
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
export declare function defaultIsEntityField(fieldName: string, _field: GraphQLField<unknown, unknown>, _parentType: GraphQLObjectType): boolean;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Default heuristic to determine if a GraphQL object type represents an entity.
|
|
196
|
+
* An entity type becomes a Stonecrop doctype.
|
|
197
|
+
*
|
|
198
|
+
* This heuristic excludes:
|
|
199
|
+
* - Introspection types (`__*`)
|
|
200
|
+
* - Root operation types (`Query`, `Mutation`, `Subscription`)
|
|
201
|
+
* - Types with synthetic suffixes (e.g., `*Connection`, `*Edge`, `*Input`)
|
|
202
|
+
* - Types starting with `Node` interface marker (exact match only)
|
|
203
|
+
*
|
|
204
|
+
* @param typeName - The GraphQL type name
|
|
205
|
+
* @param type - The GraphQL object type definition
|
|
206
|
+
* @returns `true` if this type should become a Stonecrop doctype
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
export declare function defaultIsEntityType(typeName: string, type: GraphQLObjectType): boolean;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Doctype metadata - complete definition of a doctype
|
|
213
|
+
* @public
|
|
214
|
+
*/
|
|
215
|
+
export declare const DoctypeMeta: z.ZodObject<{
|
|
216
|
+
/** Display name of the doctype */
|
|
217
|
+
name: z.ZodString;
|
|
218
|
+
/** URL-friendly slug (kebab-case) */
|
|
219
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
220
|
+
/** Database table name */
|
|
221
|
+
tableName: z.ZodOptional<z.ZodString>;
|
|
222
|
+
/** Field definitions */
|
|
223
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
224
|
+
fieldname: z.ZodString;
|
|
225
|
+
fieldtype: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
|
|
226
|
+
component: z.ZodOptional<z.ZodString>;
|
|
227
|
+
label: z.ZodOptional<z.ZodString>;
|
|
228
|
+
width: z.ZodOptional<z.ZodString>;
|
|
229
|
+
align: z.ZodOptional<z.ZodEnum<["left", "center", "right", "start", "end"]>>;
|
|
230
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
231
|
+
readOnly: z.ZodOptional<z.ZodBoolean>;
|
|
232
|
+
edit: z.ZodOptional<z.ZodBoolean>;
|
|
233
|
+
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
234
|
+
value: z.ZodOptional<z.ZodUnknown>;
|
|
235
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
236
|
+
options: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
237
|
+
mask: z.ZodOptional<z.ZodString>;
|
|
238
|
+
validation: z.ZodOptional<z.ZodObject<{
|
|
239
|
+
errorMessage: z.ZodString;
|
|
240
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
241
|
+
errorMessage: z.ZodString;
|
|
242
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
243
|
+
errorMessage: z.ZodString;
|
|
244
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
245
|
+
}, "strip", z.ZodTypeAny, {
|
|
246
|
+
fieldname: string;
|
|
247
|
+
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
248
|
+
value?: unknown;
|
|
249
|
+
options?: string | string[] | Record<string, unknown> | undefined;
|
|
250
|
+
validation?: z.objectOutputType<{
|
|
251
|
+
errorMessage: z.ZodString;
|
|
252
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
253
|
+
component?: string | undefined;
|
|
254
|
+
label?: string | undefined;
|
|
255
|
+
width?: string | undefined;
|
|
256
|
+
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
257
|
+
required?: boolean | undefined;
|
|
258
|
+
readOnly?: boolean | undefined;
|
|
259
|
+
edit?: boolean | undefined;
|
|
260
|
+
hidden?: boolean | undefined;
|
|
261
|
+
default?: unknown;
|
|
262
|
+
mask?: string | undefined;
|
|
263
|
+
}, {
|
|
264
|
+
fieldname: string;
|
|
265
|
+
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
266
|
+
value?: unknown;
|
|
267
|
+
options?: string | string[] | Record<string, unknown> | undefined;
|
|
268
|
+
validation?: z.objectInputType<{
|
|
269
|
+
errorMessage: z.ZodString;
|
|
270
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
271
|
+
component?: string | undefined;
|
|
272
|
+
label?: string | undefined;
|
|
273
|
+
width?: string | undefined;
|
|
274
|
+
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
275
|
+
required?: boolean | undefined;
|
|
276
|
+
readOnly?: boolean | undefined;
|
|
277
|
+
edit?: boolean | undefined;
|
|
278
|
+
hidden?: boolean | undefined;
|
|
279
|
+
default?: unknown;
|
|
280
|
+
mask?: string | undefined;
|
|
281
|
+
}>, "many">;
|
|
282
|
+
/** Workflow configuration */
|
|
283
|
+
workflow: z.ZodOptional<z.ZodObject<{
|
|
284
|
+
/** List of workflow states */
|
|
285
|
+
states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
286
|
+
/** Actions available in this workflow */
|
|
287
|
+
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
288
|
+
/** Display label for the action */
|
|
289
|
+
label: z.ZodString;
|
|
290
|
+
/** Handler function name or path */
|
|
291
|
+
handler: z.ZodString;
|
|
292
|
+
/** Fields that must have values before action can execute */
|
|
293
|
+
requiredFields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
294
|
+
/** Workflow states where this action is available */
|
|
295
|
+
allowedStates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
296
|
+
/** Whether to show a confirmation dialog */
|
|
297
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
298
|
+
/** Additional arguments for the action */
|
|
299
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
300
|
+
}, "strip", z.ZodTypeAny, {
|
|
301
|
+
label: string;
|
|
302
|
+
handler: string;
|
|
303
|
+
requiredFields?: string[] | undefined;
|
|
304
|
+
allowedStates?: string[] | undefined;
|
|
305
|
+
confirm?: boolean | undefined;
|
|
306
|
+
args?: Record<string, unknown> | undefined;
|
|
307
|
+
}, {
|
|
308
|
+
label: string;
|
|
309
|
+
handler: string;
|
|
310
|
+
requiredFields?: string[] | undefined;
|
|
311
|
+
allowedStates?: string[] | undefined;
|
|
312
|
+
confirm?: boolean | undefined;
|
|
313
|
+
args?: Record<string, unknown> | undefined;
|
|
314
|
+
}>>>;
|
|
315
|
+
}, "strip", z.ZodTypeAny, {
|
|
316
|
+
states?: string[] | undefined;
|
|
317
|
+
actions?: Record<string, {
|
|
318
|
+
label: string;
|
|
319
|
+
handler: string;
|
|
320
|
+
requiredFields?: string[] | undefined;
|
|
321
|
+
allowedStates?: string[] | undefined;
|
|
322
|
+
confirm?: boolean | undefined;
|
|
323
|
+
args?: Record<string, unknown> | undefined;
|
|
324
|
+
}> | undefined;
|
|
325
|
+
}, {
|
|
326
|
+
states?: string[] | undefined;
|
|
327
|
+
actions?: Record<string, {
|
|
328
|
+
label: string;
|
|
329
|
+
handler: string;
|
|
330
|
+
requiredFields?: string[] | undefined;
|
|
331
|
+
allowedStates?: string[] | undefined;
|
|
332
|
+
confirm?: boolean | undefined;
|
|
333
|
+
args?: Record<string, unknown> | undefined;
|
|
334
|
+
}> | undefined;
|
|
335
|
+
}>>;
|
|
336
|
+
/** Parent doctype for inheritance */
|
|
337
|
+
inherits: z.ZodOptional<z.ZodString>;
|
|
338
|
+
/** Doctype to use for list views */
|
|
339
|
+
listDoctype: z.ZodOptional<z.ZodString>;
|
|
340
|
+
/** Parent doctype for child tables */
|
|
341
|
+
parentDoctype: z.ZodOptional<z.ZodString>;
|
|
342
|
+
}, "strip", z.ZodTypeAny, {
|
|
343
|
+
name: string;
|
|
344
|
+
fields: {
|
|
345
|
+
fieldname: string;
|
|
346
|
+
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
347
|
+
value?: unknown;
|
|
348
|
+
options?: string | string[] | Record<string, unknown> | undefined;
|
|
349
|
+
validation?: z.objectOutputType<{
|
|
350
|
+
errorMessage: z.ZodString;
|
|
351
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
352
|
+
component?: string | undefined;
|
|
353
|
+
label?: string | undefined;
|
|
354
|
+
width?: string | undefined;
|
|
355
|
+
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
356
|
+
required?: boolean | undefined;
|
|
357
|
+
readOnly?: boolean | undefined;
|
|
358
|
+
edit?: boolean | undefined;
|
|
359
|
+
hidden?: boolean | undefined;
|
|
360
|
+
default?: unknown;
|
|
361
|
+
mask?: string | undefined;
|
|
362
|
+
}[];
|
|
363
|
+
slug?: string | undefined;
|
|
364
|
+
tableName?: string | undefined;
|
|
365
|
+
workflow?: {
|
|
366
|
+
states?: string[] | undefined;
|
|
367
|
+
actions?: Record<string, {
|
|
368
|
+
label: string;
|
|
369
|
+
handler: string;
|
|
370
|
+
requiredFields?: string[] | undefined;
|
|
371
|
+
allowedStates?: string[] | undefined;
|
|
372
|
+
confirm?: boolean | undefined;
|
|
373
|
+
args?: Record<string, unknown> | undefined;
|
|
374
|
+
}> | undefined;
|
|
375
|
+
} | undefined;
|
|
376
|
+
inherits?: string | undefined;
|
|
377
|
+
listDoctype?: string | undefined;
|
|
378
|
+
parentDoctype?: string | undefined;
|
|
379
|
+
}, {
|
|
380
|
+
name: string;
|
|
381
|
+
fields: {
|
|
382
|
+
fieldname: string;
|
|
383
|
+
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
384
|
+
value?: unknown;
|
|
385
|
+
options?: string | string[] | Record<string, unknown> | undefined;
|
|
386
|
+
validation?: z.objectInputType<{
|
|
387
|
+
errorMessage: z.ZodString;
|
|
388
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
389
|
+
component?: string | undefined;
|
|
390
|
+
label?: string | undefined;
|
|
391
|
+
width?: string | undefined;
|
|
392
|
+
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
393
|
+
required?: boolean | undefined;
|
|
394
|
+
readOnly?: boolean | undefined;
|
|
395
|
+
edit?: boolean | undefined;
|
|
396
|
+
hidden?: boolean | undefined;
|
|
397
|
+
default?: unknown;
|
|
398
|
+
mask?: string | undefined;
|
|
399
|
+
}[];
|
|
400
|
+
slug?: string | undefined;
|
|
401
|
+
tableName?: string | undefined;
|
|
402
|
+
workflow?: {
|
|
403
|
+
states?: string[] | undefined;
|
|
404
|
+
actions?: Record<string, {
|
|
405
|
+
label: string;
|
|
406
|
+
handler: string;
|
|
407
|
+
requiredFields?: string[] | undefined;
|
|
408
|
+
allowedStates?: string[] | undefined;
|
|
409
|
+
confirm?: boolean | undefined;
|
|
410
|
+
args?: Record<string, unknown> | undefined;
|
|
411
|
+
}> | undefined;
|
|
412
|
+
} | undefined;
|
|
413
|
+
inherits?: string | undefined;
|
|
414
|
+
listDoctype?: string | undefined;
|
|
415
|
+
parentDoctype?: string | undefined;
|
|
416
|
+
}>;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Doctype metadata type inferred from Zod schema
|
|
420
|
+
* @public
|
|
421
|
+
*/
|
|
422
|
+
export declare type DoctypeMeta = z.infer<typeof DoctypeMeta>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Error thrown when a doctype definition fails validation
|
|
426
|
+
* @public
|
|
427
|
+
*/
|
|
428
|
+
export declare class DoctypeValidationError extends Error {
|
|
429
|
+
/** File path or name where the validation error occurred */
|
|
430
|
+
readonly file: string;
|
|
431
|
+
/** List of validation errors found */
|
|
432
|
+
readonly errors: ValidationError[];
|
|
433
|
+
constructor(
|
|
434
|
+
/** File path or name where the validation error occurred */
|
|
435
|
+
file: string,
|
|
436
|
+
/** List of validation errors found */
|
|
437
|
+
errors: ValidationError[]);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Unified field metadata - the single source of truth for field definitions.
|
|
442
|
+
* Works for both forms (AForm) and tables (ATable).
|
|
443
|
+
*
|
|
444
|
+
* Core principle: "Text" is "Text" regardless of rendering context.
|
|
445
|
+
*
|
|
446
|
+
* @public
|
|
447
|
+
*/
|
|
448
|
+
export declare const FieldMeta: z.ZodObject<{
|
|
449
|
+
/** Unique identifier for the field within its doctype */
|
|
450
|
+
fieldname: z.ZodString;
|
|
451
|
+
/** Semantic field type - determines behavior and default component */
|
|
452
|
+
fieldtype: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
|
|
453
|
+
/** Vue component to render this field. If not specified, derived from TYPE_MAP */
|
|
454
|
+
component: z.ZodOptional<z.ZodString>;
|
|
455
|
+
/** Human-readable label for the field */
|
|
456
|
+
label: z.ZodOptional<z.ZodString>;
|
|
457
|
+
/** Width of the field (CSS value, e.g., "40ch", "200px") */
|
|
458
|
+
width: z.ZodOptional<z.ZodString>;
|
|
459
|
+
/** Text alignment within the field */
|
|
460
|
+
align: z.ZodOptional<z.ZodEnum<["left", "center", "right", "start", "end"]>>;
|
|
461
|
+
/** Whether the field is required */
|
|
462
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
463
|
+
/** Whether the field is read-only */
|
|
464
|
+
readOnly: z.ZodOptional<z.ZodBoolean>;
|
|
465
|
+
/** Whether the field is editable (for table cells) */
|
|
466
|
+
edit: z.ZodOptional<z.ZodBoolean>;
|
|
467
|
+
/** Whether the field is hidden from the UI */
|
|
468
|
+
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
469
|
+
/** Current value of the field */
|
|
470
|
+
value: z.ZodOptional<z.ZodUnknown>;
|
|
471
|
+
/** Default value for new records */
|
|
472
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
473
|
+
/**
|
|
474
|
+
* Type-specific options:
|
|
475
|
+
* - Link: target doctype slug ("customer")
|
|
476
|
+
* - Doctype: child doctype slug ("sales-order-item")
|
|
477
|
+
* - Select: choices array (["Draft", "Submitted"])
|
|
478
|
+
* - Decimal: \{ precision, scale \}
|
|
479
|
+
* - Code: \{ language \}
|
|
480
|
+
*/
|
|
481
|
+
options: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
482
|
+
/** Input mask pattern (e.g., "##/##/####" for dates) */
|
|
483
|
+
mask: z.ZodOptional<z.ZodString>;
|
|
484
|
+
/** Validation configuration */
|
|
485
|
+
validation: z.ZodOptional<z.ZodObject<{
|
|
486
|
+
/** Error message to display when validation fails */
|
|
487
|
+
errorMessage: z.ZodString;
|
|
488
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
489
|
+
/** Error message to display when validation fails */
|
|
490
|
+
errorMessage: z.ZodString;
|
|
491
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
492
|
+
/** Error message to display when validation fails */
|
|
493
|
+
errorMessage: z.ZodString;
|
|
494
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
495
|
+
}, "strip", z.ZodTypeAny, {
|
|
496
|
+
fieldname: string;
|
|
497
|
+
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
498
|
+
value?: unknown;
|
|
499
|
+
options?: string | string[] | Record<string, unknown> | undefined;
|
|
500
|
+
validation?: z.objectOutputType<{
|
|
501
|
+
/** Error message to display when validation fails */
|
|
502
|
+
errorMessage: z.ZodString;
|
|
503
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
504
|
+
component?: string | undefined;
|
|
505
|
+
label?: string | undefined;
|
|
506
|
+
width?: string | undefined;
|
|
507
|
+
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
508
|
+
required?: boolean | undefined;
|
|
509
|
+
readOnly?: boolean | undefined;
|
|
510
|
+
edit?: boolean | undefined;
|
|
511
|
+
hidden?: boolean | undefined;
|
|
512
|
+
default?: unknown;
|
|
513
|
+
mask?: string | undefined;
|
|
514
|
+
}, {
|
|
515
|
+
fieldname: string;
|
|
516
|
+
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
517
|
+
value?: unknown;
|
|
518
|
+
options?: string | string[] | Record<string, unknown> | undefined;
|
|
519
|
+
validation?: z.objectInputType<{
|
|
520
|
+
/** Error message to display when validation fails */
|
|
521
|
+
errorMessage: z.ZodString;
|
|
522
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
523
|
+
component?: string | undefined;
|
|
524
|
+
label?: string | undefined;
|
|
525
|
+
width?: string | undefined;
|
|
526
|
+
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
527
|
+
required?: boolean | undefined;
|
|
528
|
+
readOnly?: boolean | undefined;
|
|
529
|
+
edit?: boolean | undefined;
|
|
530
|
+
hidden?: boolean | undefined;
|
|
531
|
+
default?: unknown;
|
|
532
|
+
mask?: string | undefined;
|
|
533
|
+
}>;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Field metadata type inferred from Zod schema
|
|
537
|
+
* @public
|
|
538
|
+
*/
|
|
539
|
+
export declare type FieldMeta = z.infer<typeof FieldMeta>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Field options - flexible bag for type-specific configuration.
|
|
543
|
+
*
|
|
544
|
+
* Usage by fieldtype:
|
|
545
|
+
* - Link/Doctype: target doctype slug as string ("customer", "sales-order-item")
|
|
546
|
+
* - Select: array of choices (["Draft", "Submitted", "Cancelled"])
|
|
547
|
+
* - Decimal: config object (\{ precision: 10, scale: 2 \})
|
|
548
|
+
* - Code: config object (\{ language: "python" \})
|
|
549
|
+
*
|
|
550
|
+
* @public
|
|
551
|
+
*/
|
|
552
|
+
export declare const FieldOptions: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Field options type inferred from Zod schema
|
|
556
|
+
* @public
|
|
557
|
+
*/
|
|
558
|
+
export declare type FieldOptions = z.infer<typeof FieldOptions>;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Field template for TYPE_MAP entries.
|
|
562
|
+
* Defines the default component and semantic field type for a field.
|
|
563
|
+
* @public
|
|
564
|
+
*/
|
|
565
|
+
declare interface FieldTemplate {
|
|
566
|
+
/**
|
|
567
|
+
* The Vue component name to render this field (e.g., 'ATextInput', 'ADropdown')
|
|
568
|
+
*/
|
|
569
|
+
component: string;
|
|
570
|
+
/**
|
|
571
|
+
* The semantic field type (e.g., 'Data', 'Int', 'Select')
|
|
572
|
+
*/
|
|
573
|
+
fieldtype: StonecropFieldType;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Validation configuration for form fields
|
|
578
|
+
* @public
|
|
579
|
+
*/
|
|
580
|
+
export declare const FieldValidation: z.ZodObject<{
|
|
581
|
+
/** Error message to display when validation fails */
|
|
582
|
+
errorMessage: z.ZodString;
|
|
583
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
584
|
+
/** Error message to display when validation fails */
|
|
585
|
+
errorMessage: z.ZodString;
|
|
586
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
587
|
+
/** Error message to display when validation fails */
|
|
588
|
+
errorMessage: z.ZodString;
|
|
589
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Field validation type inferred from Zod schema
|
|
593
|
+
* @public
|
|
594
|
+
*/
|
|
595
|
+
export declare type FieldValidation = z.infer<typeof FieldValidation>;
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Get all loaded doctypes
|
|
599
|
+
* @public
|
|
600
|
+
*/
|
|
601
|
+
export declare function getAllMeta(): DoctypeMeta[];
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Get the default component for a field type
|
|
605
|
+
* @param fieldtype - The semantic field type
|
|
606
|
+
* @returns The default component name
|
|
607
|
+
* @public
|
|
608
|
+
*/
|
|
609
|
+
export declare function getDefaultComponent(fieldtype: StonecropFieldType): string;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Get a registered handler by name
|
|
613
|
+
* @param name - Name of the action handler to retrieve
|
|
614
|
+
* @public
|
|
615
|
+
*/
|
|
616
|
+
export declare function getHandler(name: string): ActionHandler | undefined;
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Get a doctype by name
|
|
620
|
+
* @param name - Name of the doctype to retrieve
|
|
621
|
+
* @public
|
|
622
|
+
*/
|
|
623
|
+
export declare function getMeta(name: string): DoctypeMeta | undefined;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Mapping from standard GraphQL scalar types to Stonecrop field types.
|
|
627
|
+
* These are defined by the GraphQL specification and are always available.
|
|
628
|
+
*
|
|
629
|
+
* @public
|
|
630
|
+
*/
|
|
631
|
+
export declare const GQL_SCALAR_MAP: Record<string, FieldTemplate>;
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Extended field metadata with optional GraphQL conversion metadata.
|
|
635
|
+
* Only present when `includeUnmappedMeta` is enabled.
|
|
636
|
+
*
|
|
637
|
+
* @public
|
|
638
|
+
*/
|
|
639
|
+
export declare interface GraphQLConversionFieldMeta extends FieldMeta {
|
|
640
|
+
/** Original GraphQL type name (for debugging/reference) */
|
|
641
|
+
_graphqlType?: string;
|
|
642
|
+
/** Marks fields that couldn't be automatically mapped */
|
|
643
|
+
_unmapped?: boolean;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Options for converting a GraphQL schema to Stonecrop doctype schemas.
|
|
648
|
+
* All hooks are optional — sensible defaults are provided for common GraphQL patterns.
|
|
649
|
+
*
|
|
650
|
+
* @public
|
|
651
|
+
*/
|
|
652
|
+
export declare interface GraphQLConversionOptions {
|
|
653
|
+
/**
|
|
654
|
+
* GraphQL type names to exclude from conversion.
|
|
655
|
+
* Applied after `isEntityType` filtering.
|
|
656
|
+
*/
|
|
657
|
+
exclude?: string[];
|
|
658
|
+
/**
|
|
659
|
+
* Whitelist of GraphQL type names to convert.
|
|
660
|
+
* When provided, only these types are considered (after `isEntityType` filtering).
|
|
661
|
+
*/
|
|
662
|
+
include?: string[];
|
|
663
|
+
/**
|
|
664
|
+
* Per-type, per-field overrides for the converted field definitions.
|
|
665
|
+
* Outer key is the GraphQL type name, inner key is the field name.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* {
|
|
670
|
+
* SalesOrder: {
|
|
671
|
+
* totalAmount: { fieldtype: 'Currency', component: 'ACurrencyInput' }
|
|
672
|
+
* }
|
|
673
|
+
* }
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
typeOverrides?: Record<string, Record<string, Partial<FieldMeta>>>;
|
|
677
|
+
/**
|
|
678
|
+
* Map custom or non-standard GraphQL scalar types to Stonecrop field types.
|
|
679
|
+
* Merged with the built-in scalar maps (GQL_SCALAR_MAP + WELL_KNOWN_SCALARS).
|
|
680
|
+
* User-provided entries take highest precedence.
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* {
|
|
685
|
+
* MyCustomMoney: { component: 'ACurrencyInput', fieldtype: 'Currency' },
|
|
686
|
+
* PostGISPoint: { component: 'ATextInput', fieldtype: 'Data' }
|
|
687
|
+
* }
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
customScalars?: Record<string, Partial<FieldTemplate>>;
|
|
691
|
+
/**
|
|
692
|
+
* Custom function to determine if a GraphQL object type represents an entity (→ doctype).
|
|
693
|
+
* When provided, replaces the default heuristic entirely.
|
|
694
|
+
*
|
|
695
|
+
* The default heuristic excludes types matching synthetic patterns:
|
|
696
|
+
* `*Connection`, `*Edge`, `*Input`, `*Patch`, `*Payload`, `*Condition`,
|
|
697
|
+
* `*Filter`, `*OrderBy`, `*Aggregate`, `Query`, `Mutation`, `Subscription`, `__*`.
|
|
698
|
+
*
|
|
699
|
+
* @param typeName - The GraphQL type name
|
|
700
|
+
* @param type - The full GraphQL object type definition
|
|
701
|
+
* @returns `true` if this type should become a Stonecrop doctype
|
|
702
|
+
*/
|
|
703
|
+
isEntityType?: (typeName: string, type: GraphQLObjectType) => boolean;
|
|
704
|
+
/**
|
|
705
|
+
* Custom function to filter which fields on an entity type are included.
|
|
706
|
+
* When provided, replaces the default field filter.
|
|
707
|
+
*
|
|
708
|
+
* The default filter excludes `nodeId`, `__typename`, and `clientMutationId`.
|
|
709
|
+
*
|
|
710
|
+
* @param fieldName - The GraphQL field name
|
|
711
|
+
* @param field - The full GraphQL field definition
|
|
712
|
+
* @param parentType - The parent entity type
|
|
713
|
+
* @returns `true` if this field should be included
|
|
714
|
+
*/
|
|
715
|
+
isEntityField?: (fieldName: string, field: GraphQLField<unknown, unknown>, parentType: GraphQLObjectType) => boolean;
|
|
716
|
+
/**
|
|
717
|
+
* Escape hatch: fully override the classification of a specific field.
|
|
718
|
+
* When this returns a non-null value, it is used as the field definition
|
|
719
|
+
* (merged with the field name). Return `null` to fall through to default classification.
|
|
720
|
+
*
|
|
721
|
+
* @param fieldName - The GraphQL field name
|
|
722
|
+
* @param field - The full GraphQL field definition
|
|
723
|
+
* @param parentType - The parent entity type
|
|
724
|
+
* @returns Partial field meta to use, or `null` for default behavior
|
|
725
|
+
*/
|
|
726
|
+
classifyField?: (fieldName: string, field: GraphQLField<unknown, unknown>, parentType: GraphQLObjectType) => Partial<FieldMeta> | null;
|
|
727
|
+
/**
|
|
728
|
+
* Custom function to derive the database table name from a GraphQL type name.
|
|
729
|
+
* The default converts PascalCase to snake_case (e.g., `SalesOrder` → `sales_order`).
|
|
730
|
+
*
|
|
731
|
+
* Return `undefined` to omit `tableName` from the output.
|
|
732
|
+
*
|
|
733
|
+
* @param typeName - The GraphQL type name
|
|
734
|
+
* @returns The derived table name, or `undefined`
|
|
735
|
+
*/
|
|
736
|
+
deriveTableName?: (typeName: string) => string | undefined;
|
|
737
|
+
/**
|
|
738
|
+
* Include `_graphqlType` and `_unmapped` metadata on converted fields.
|
|
739
|
+
* Useful for debugging conversions. Defaults to `false`.
|
|
740
|
+
*/
|
|
741
|
+
includeUnmappedMeta?: boolean;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* GraphQL executor interface for running queries/mutations
|
|
746
|
+
* @public
|
|
747
|
+
*/
|
|
748
|
+
export declare interface GraphQLExecutor {
|
|
749
|
+
/** Execute a GraphQL query */
|
|
750
|
+
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
751
|
+
/** Execute a GraphQL mutation */
|
|
752
|
+
mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Check if a handler is registered
|
|
757
|
+
* @param name - Name of the action handler to check
|
|
758
|
+
* @public
|
|
759
|
+
*/
|
|
760
|
+
export declare function hasHandler(name: string): boolean;
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Check if a doctype is registered
|
|
764
|
+
* @param name - Name of the doctype to check
|
|
765
|
+
* @public
|
|
766
|
+
*/
|
|
767
|
+
export declare function hasMeta(name: string): boolean;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Input source for the GraphQL schema converter.
|
|
771
|
+
* Accepts either a standard GraphQL introspection result or an SDL string.
|
|
772
|
+
*
|
|
773
|
+
* - `IntrospectionQuery`: The raw result of a GraphQL introspection query (from any server)
|
|
774
|
+
* - `string`: An SDL (Schema Definition Language) string
|
|
775
|
+
*
|
|
776
|
+
* Note: URL fetching is intentionally not supported in the library API.
|
|
777
|
+
* Use the CLI (`stonecrop-schema generate --endpoint <url>`) for endpoint fetching,
|
|
778
|
+
* or fetch the introspection result yourself and pass it in.
|
|
779
|
+
*
|
|
780
|
+
* @public
|
|
781
|
+
*/
|
|
782
|
+
export declare type IntrospectionSource = IntrospectionQuery | string;
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Load doctype definitions from a directory of JSON files
|
|
786
|
+
* @param dir - Directory path containing doctype JSON files
|
|
787
|
+
* @param options - Options for loading doctypes (continueOnError, onError callback)
|
|
788
|
+
* @public
|
|
789
|
+
*/
|
|
790
|
+
export declare function loadDoctypes(dir: string, options?: LoadDoctypesOptions): void;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Load doctypes from an object (for programmatic use)
|
|
794
|
+
* @param doctypes - Object mapping doctype names to doctype definitions
|
|
795
|
+
* @param options - Options for loading doctypes (continueOnError, onError callback)
|
|
796
|
+
* @public
|
|
797
|
+
*/
|
|
798
|
+
export declare function loadDoctypesFromObject(doctypes: Record<string, unknown>, options?: LoadDoctypesOptions): void;
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Options for loading doctype definitions
|
|
802
|
+
* @public
|
|
803
|
+
*/
|
|
804
|
+
export declare interface LoadDoctypesOptions {
|
|
805
|
+
/** Continue loading other files if one fails validation */
|
|
806
|
+
continueOnError?: boolean;
|
|
807
|
+
/** Callback for validation errors when continueOnError is true */
|
|
808
|
+
onError?: (file: string, errors: ValidationError[]) => void;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Parse and validate a doctype, throwing on failure
|
|
813
|
+
* @param data - Data to parse
|
|
814
|
+
* @returns Validated DoctypeMeta
|
|
815
|
+
* @throws ZodError if validation fails
|
|
816
|
+
* @public
|
|
817
|
+
*/
|
|
818
|
+
export declare function parseDoctype(data: unknown): DoctypeMeta;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Parse and validate a field, throwing on failure
|
|
822
|
+
* @param data - Data to parse
|
|
823
|
+
* @returns Validated FieldMeta
|
|
824
|
+
* @throws ZodError if validation fails
|
|
825
|
+
* @public
|
|
826
|
+
*/
|
|
827
|
+
export declare function parseField(data: unknown): FieldMeta;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Convert PascalCase to snake_case (e.g., for deriving table names from type names)
|
|
831
|
+
* @param pascal - PascalCase string
|
|
832
|
+
* @returns snake_case string
|
|
833
|
+
* @public
|
|
834
|
+
* @example
|
|
835
|
+
* ```typescript
|
|
836
|
+
* pascalToSnake('SalesOrder') // 'sales_order'
|
|
837
|
+
* pascalToSnake('SalesOrderItem') // 'sales_order_item'
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
export declare function pascalToSnake(pascal: string): string;
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Register all built-in handlers
|
|
844
|
+
* @public
|
|
845
|
+
*/
|
|
846
|
+
export declare function registerBuiltinHandlers(): void;
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Register an action handler
|
|
850
|
+
* @param name - Unique name for the action handler
|
|
851
|
+
* @param handler - Action handler function to register
|
|
852
|
+
* @public
|
|
853
|
+
*/
|
|
854
|
+
export declare function registerHandler(name: string, handler: ActionHandler): void;
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Route context for identifying what doctype/record we're working with
|
|
858
|
+
* @public
|
|
859
|
+
*/
|
|
860
|
+
export declare interface RouteContext {
|
|
861
|
+
/** Doctype name (e.g., 'Task', 'Customer') */
|
|
862
|
+
doctype: string;
|
|
863
|
+
/** Optional record ID for viewing/editing a specific record */
|
|
864
|
+
recordId?: string;
|
|
865
|
+
/** Additional context properties */
|
|
866
|
+
[key: string]: unknown;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Converts snake_case to camelCase
|
|
871
|
+
* @param snakeCase - Snake case string
|
|
872
|
+
* @returns Camel case string
|
|
873
|
+
* @public
|
|
874
|
+
* @example
|
|
875
|
+
* ```typescript
|
|
876
|
+
* snakeToCamel('user_email') // 'userEmail'
|
|
877
|
+
* snakeToCamel('created_at') // 'createdAt'
|
|
878
|
+
* ```
|
|
879
|
+
*/
|
|
880
|
+
export declare function snakeToCamel(snakeCase: string): string;
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Converts snake_case to Title Case label
|
|
884
|
+
* @param snakeCase - Snake case string
|
|
885
|
+
* @returns Title case label
|
|
886
|
+
* @public
|
|
887
|
+
* @example
|
|
888
|
+
* ```typescript
|
|
889
|
+
* snakeToLabel('user_email') // 'User Email'
|
|
890
|
+
* snakeToLabel('first_name') // 'First Name'
|
|
891
|
+
* ```
|
|
892
|
+
*/
|
|
893
|
+
export declare function snakeToLabel(snakeCase: string): string;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Client for interacting with Stonecrop GraphQL API
|
|
897
|
+
* @public
|
|
898
|
+
*/
|
|
899
|
+
export declare class StonecropClient implements GraphQLExecutor {
|
|
900
|
+
private endpoint;
|
|
901
|
+
private headers;
|
|
902
|
+
private metaCache;
|
|
903
|
+
constructor(options: StonecropClientOptions);
|
|
904
|
+
/**
|
|
905
|
+
* Execute a GraphQL query
|
|
906
|
+
* @param query - GraphQL query string
|
|
907
|
+
* @param variables - Query variables
|
|
908
|
+
*/
|
|
909
|
+
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
910
|
+
/**
|
|
911
|
+
* Execute a GraphQL mutation
|
|
912
|
+
* @param mutation - GraphQL mutation string
|
|
913
|
+
* @param variables - Mutation variables
|
|
914
|
+
*/
|
|
915
|
+
mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
|
|
916
|
+
/**
|
|
917
|
+
* Get doctype metadata
|
|
918
|
+
* @param context - Route context containing doctype name
|
|
919
|
+
*/
|
|
920
|
+
getMeta(context: RouteContext): Promise<DoctypeMeta | null>;
|
|
921
|
+
/**
|
|
922
|
+
* Get all doctype metadata
|
|
923
|
+
*/
|
|
924
|
+
getAllMeta(): Promise<DoctypeMeta[]>;
|
|
925
|
+
/**
|
|
926
|
+
* Get a single record by ID
|
|
927
|
+
* @param doctype - Doctype metadata
|
|
928
|
+
* @param recordId - Record ID to fetch
|
|
929
|
+
*/
|
|
930
|
+
getRecord(doctype: DoctypeMeta, recordId: string): Promise<Record<string, unknown> | null>;
|
|
931
|
+
/**
|
|
932
|
+
* Get multiple records with optional filtering and pagination
|
|
933
|
+
* @param doctype - Doctype metadata
|
|
934
|
+
* @param options - Query options (filters, orderBy, limit, offset)
|
|
935
|
+
*/
|
|
936
|
+
getRecords(doctype: DoctypeMeta, options?: {
|
|
937
|
+
filters?: Record<string, unknown>;
|
|
938
|
+
orderBy?: string;
|
|
939
|
+
limit?: number;
|
|
940
|
+
offset?: number;
|
|
941
|
+
}): Promise<Record<string, unknown>[]>;
|
|
942
|
+
/**
|
|
943
|
+
* Execute a doctype action
|
|
944
|
+
* @param doctype - Doctype metadata
|
|
945
|
+
* @param action - Action name to execute
|
|
946
|
+
* @param args - Action arguments
|
|
947
|
+
*/
|
|
948
|
+
runAction(doctype: DoctypeMeta, action: string, args?: unknown[]): Promise<{
|
|
949
|
+
success: boolean;
|
|
950
|
+
data: unknown;
|
|
951
|
+
error: string | null;
|
|
952
|
+
}>;
|
|
953
|
+
/**
|
|
954
|
+
* Clear the cached doctype metadata
|
|
955
|
+
*/
|
|
956
|
+
clearMetaCache(): void;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Options for creating a Stonecrop client
|
|
961
|
+
* @public
|
|
962
|
+
*/
|
|
963
|
+
export declare interface StonecropClientOptions {
|
|
964
|
+
/** GraphQL endpoint URL */
|
|
965
|
+
endpoint: string;
|
|
966
|
+
/** Additional HTTP headers to include in requests */
|
|
967
|
+
headers?: Record<string, string>;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* Stonecrop field types - the semantic type of the field.
|
|
972
|
+
* These are consistent across forms and tables.
|
|
973
|
+
* @public
|
|
974
|
+
*/
|
|
975
|
+
export declare const StonecropFieldType: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Stonecrop field type enum inferred from Zod schema
|
|
979
|
+
* @public
|
|
980
|
+
*/
|
|
981
|
+
export declare type StonecropFieldType = z.infer<typeof StonecropFieldType>;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Inflection callbacks for mapping table names to GraphQL query field names.
|
|
985
|
+
* Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).
|
|
986
|
+
*
|
|
987
|
+
* Defaults match the PostGraphile Amber preset conventions.
|
|
988
|
+
* @public
|
|
989
|
+
*/
|
|
990
|
+
export declare interface StonecropInflectionConfig {
|
|
991
|
+
/**
|
|
992
|
+
* Given a table name, return the GraphQL field name for fetching a single record by ID.
|
|
993
|
+
* @example Amber default: "sales_orders" → "salesOrderById"
|
|
994
|
+
* @example V4 preset: "sales_orders" → "salesOrderByRowId"
|
|
995
|
+
*/
|
|
996
|
+
recordFieldName?: (tableName: string) => string;
|
|
997
|
+
/**
|
|
998
|
+
* Given a table name, return the GraphQL field name for fetching a list/connection.
|
|
999
|
+
* @example Amber default: "sales_orders" → "allSalesOrders"
|
|
1000
|
+
* @example SimplifyInflection: "sales_orders" → "salesOrders"
|
|
1001
|
+
*/
|
|
1002
|
+
connectionFieldName?: (tableName: string) => string;
|
|
1003
|
+
/**
|
|
1004
|
+
* Given a table name, return the GraphQL OrderBy enum type name.
|
|
1005
|
+
* @example Amber default: "sales_orders" → "SalesOrdersOrderBy"
|
|
1006
|
+
*/
|
|
1007
|
+
orderByTypeName?: (tableName: string) => string;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* Options for creating a Stonecrop PostGraphile plugin
|
|
1012
|
+
* @public
|
|
1013
|
+
*/
|
|
1014
|
+
export declare interface StonecropPluginOptions {
|
|
1015
|
+
/** GraphQL executor for running queries/mutations */
|
|
1016
|
+
executor: GraphQLExecutor;
|
|
1017
|
+
/**
|
|
1018
|
+
* Override inflection conventions for mapping table names to GraphQL field names.
|
|
1019
|
+
* Defaults to PostGraphile Amber preset conventions.
|
|
1020
|
+
*/
|
|
1021
|
+
inflection?: StonecropInflectionConfig;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Convert table name to PascalCase doctype name
|
|
1026
|
+
* @param tableName - SQL table name (snake_case)
|
|
1027
|
+
* @returns PascalCase name
|
|
1028
|
+
* @public
|
|
1029
|
+
*/
|
|
1030
|
+
export declare function toPascalCase(tableName: string): string;
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Convert to kebab-case slug
|
|
1034
|
+
* @param name - Name to convert
|
|
1035
|
+
* @returns kebab-case slug
|
|
1036
|
+
* @public
|
|
1037
|
+
*/
|
|
1038
|
+
export declare function toSlug(name: string): string;
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* Mapping from StonecropFieldType to default Vue component.
|
|
1042
|
+
* Components can be overridden in the field definition.
|
|
1043
|
+
* @public
|
|
1044
|
+
*/
|
|
1045
|
+
export declare const TYPE_MAP: Record<StonecropFieldType, FieldTemplate>;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Validate a doctype definition
|
|
1049
|
+
* @param data - Data to validate
|
|
1050
|
+
* @returns Validation result
|
|
1051
|
+
* @public
|
|
1052
|
+
*/
|
|
1053
|
+
export declare function validateDoctype(data: unknown): ValidationResult;
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Validate a field definition
|
|
1057
|
+
* @param data - Data to validate
|
|
1058
|
+
* @returns Validation result
|
|
1059
|
+
* @public
|
|
1060
|
+
*/
|
|
1061
|
+
export declare function validateField(data: unknown): ValidationResult;
|
|
1062
|
+
|
|
1063
|
+
/**
|
|
1064
|
+
* Validate cross-doctype references (Link fields, inherits, etc.)
|
|
1065
|
+
* Call after all doctypes are loaded.
|
|
1066
|
+
* @public
|
|
1067
|
+
*/
|
|
1068
|
+
export declare function validateReferences(): ValidationError[];
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Validation error with path information
|
|
1072
|
+
* @public
|
|
1073
|
+
*/
|
|
1074
|
+
export declare interface ValidationError {
|
|
1075
|
+
/** Path to the invalid property */
|
|
1076
|
+
path: (string | number)[];
|
|
1077
|
+
/** Error message */
|
|
1078
|
+
message: string;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Result of a validation operation
|
|
1083
|
+
* @public
|
|
1084
|
+
*/
|
|
1085
|
+
export declare interface ValidationResult {
|
|
1086
|
+
/** Whether validation passed */
|
|
1087
|
+
success: boolean;
|
|
1088
|
+
/** List of validation errors (empty if success) */
|
|
1089
|
+
errors: ValidationError[];
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Mapping from well-known custom GraphQL scalars to Stonecrop field types.
|
|
1094
|
+
* These cover scalars commonly used across GraphQL servers (PostGraphile, Hasura, etc.)
|
|
1095
|
+
* without baking in knowledge of any specific server.
|
|
1096
|
+
*
|
|
1097
|
+
* Entries here have lower precedence than `customScalars` from options, but higher
|
|
1098
|
+
* precedence than unknown/unmapped scalars.
|
|
1099
|
+
*
|
|
1100
|
+
* @public
|
|
1101
|
+
*/
|
|
1102
|
+
export declare const WELL_KNOWN_SCALARS: Record<string, FieldTemplate>;
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* Workflow metadata - states and actions for a doctype
|
|
1106
|
+
* @public
|
|
1107
|
+
*/
|
|
1108
|
+
export declare const WorkflowMeta: z.ZodObject<{
|
|
1109
|
+
/** List of workflow states */
|
|
1110
|
+
states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1111
|
+
/** Actions available in this workflow */
|
|
1112
|
+
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
1113
|
+
/** Display label for the action */
|
|
1114
|
+
label: z.ZodString;
|
|
1115
|
+
/** Handler function name or path */
|
|
1116
|
+
handler: z.ZodString;
|
|
1117
|
+
/** Fields that must have values before action can execute */
|
|
1118
|
+
requiredFields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1119
|
+
/** Workflow states where this action is available */
|
|
1120
|
+
allowedStates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1121
|
+
/** Whether to show a confirmation dialog */
|
|
1122
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
1123
|
+
/** Additional arguments for the action */
|
|
1124
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1125
|
+
}, "strip", z.ZodTypeAny, {
|
|
1126
|
+
label: string;
|
|
1127
|
+
handler: string;
|
|
1128
|
+
requiredFields?: string[] | undefined;
|
|
1129
|
+
allowedStates?: string[] | undefined;
|
|
1130
|
+
confirm?: boolean | undefined;
|
|
1131
|
+
args?: Record<string, unknown> | undefined;
|
|
1132
|
+
}, {
|
|
1133
|
+
label: string;
|
|
1134
|
+
handler: string;
|
|
1135
|
+
requiredFields?: string[] | undefined;
|
|
1136
|
+
allowedStates?: string[] | undefined;
|
|
1137
|
+
confirm?: boolean | undefined;
|
|
1138
|
+
args?: Record<string, unknown> | undefined;
|
|
1139
|
+
}>>>;
|
|
1140
|
+
}, "strip", z.ZodTypeAny, {
|
|
1141
|
+
states?: string[] | undefined;
|
|
1142
|
+
actions?: Record<string, {
|
|
1143
|
+
label: string;
|
|
1144
|
+
handler: string;
|
|
1145
|
+
requiredFields?: string[] | undefined;
|
|
1146
|
+
allowedStates?: string[] | undefined;
|
|
1147
|
+
confirm?: boolean | undefined;
|
|
1148
|
+
args?: Record<string, unknown> | undefined;
|
|
1149
|
+
}> | undefined;
|
|
1150
|
+
}, {
|
|
1151
|
+
states?: string[] | undefined;
|
|
1152
|
+
actions?: Record<string, {
|
|
1153
|
+
label: string;
|
|
1154
|
+
handler: string;
|
|
1155
|
+
requiredFields?: string[] | undefined;
|
|
1156
|
+
allowedStates?: string[] | undefined;
|
|
1157
|
+
confirm?: boolean | undefined;
|
|
1158
|
+
args?: Record<string, unknown> | undefined;
|
|
1159
|
+
}> | undefined;
|
|
1160
|
+
}>;
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Workflow metadata type inferred from Zod schema
|
|
1164
|
+
* @public
|
|
1165
|
+
*/
|
|
1166
|
+
export declare type WorkflowMeta = z.infer<typeof WorkflowMeta>;
|
|
1167
|
+
|
|
1168
|
+
export { }
|