@stonecrop/graphql-middleware 0.8.10 → 0.8.12

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.
@@ -1,7 +1,4 @@
1
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
2
  import { z } from 'zod';
6
3
 
7
4
  /**
@@ -17,45 +14,6 @@ export declare interface ActionContext {
17
14
  [key: string]: unknown;
18
15
  }
19
16
 
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
17
  /**
60
18
  * Action handler function signature
61
19
  * @public
@@ -67,7 +25,7 @@ export declare type ActionHandler = (args: unknown[], context: ActionContext) =>
67
25
  * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
68
26
  * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
69
27
  * Excludes Link and Doctype relation fields from the selection set.
70
- * @internal
28
+ * @public
71
29
  */
72
30
  export declare function buildListQuery(meta: DoctypeMeta, args: {
73
31
  limit?: number;
@@ -78,9 +36,12 @@ export declare function buildListQuery(meta: DoctypeMeta, args: {
78
36
  /**
79
37
  * Build a GraphQL query to fetch a single record by ID.
80
38
  * Excludes Link and Doctype relation fields from the selection set.
81
- * @internal
39
+ * The PK argument name and type are configurable via `StonecropInflectionConfig.recordArgName`
40
+ * and `StonecropInflectionConfig.recordArgType` to match the target schema's conventions
41
+ * (e.g. `rowId: UUID!` for PostGraphile Amber with row_id columns).
42
+ * @public
82
43
  */
83
- export declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string): string;
44
+ export declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string, recordArgName: (t: string) => string, recordArgType: (t: string) => string): string;
84
45
 
85
46
  /**
86
47
  * Built-in handlers available for registration
@@ -88,52 +49,6 @@ export declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t:
88
49
  */
89
50
  export declare const builtinHandlers: Record<string, ActionHandler>;
90
51
 
91
- /**
92
- * Converts camelCase to Title Case label
93
- * @param camelCase - Camel case string
94
- * @returns Title case label
95
- * @public
96
- * @example
97
- * ```typescript
98
- * camelToLabel('userEmail') // 'User Email'
99
- * camelToLabel('firstName') // 'First Name'
100
- * ```
101
- */
102
- export declare function camelToLabel(camelCase: string): string;
103
-
104
- /**
105
- * Converts camelCase to snake_case
106
- * @param camelCase - Camel case string
107
- * @returns Snake case string
108
- * @public
109
- * @example
110
- * ```typescript
111
- * camelToSnake('userEmail') // 'user_email'
112
- * camelToSnake('createdAt') // 'created_at'
113
- * ```
114
- */
115
- export declare function camelToSnake(camelCase: string): string;
116
-
117
- /**
118
- * Classify a single GraphQL field into a Stonecrop field definition.
119
- *
120
- * Classification rules (in order):
121
- * 1. Scalar types → look up in merged scalar map
122
- * 2. Enum types → `Select` with enum values as options
123
- * 3. Object types that are entities → `Link` with slug as options
124
- * 4. Object types that are Connections → `Doctype` with node type slug as options
125
- * 5. List of entity type → `Doctype` with item type slug as options
126
- * 6. Anything else → `Data` with `_unmapped: true`
127
- *
128
- * @param fieldName - The GraphQL field name
129
- * @param field - The GraphQL field definition
130
- * @param entityTypes - Set of type names classified as entities
131
- * @param options - Conversion options (for custom scalars, unmapped meta, etc.)
132
- * @returns The Stonecrop field definition
133
- * @public
134
- */
135
- export declare function classifyFieldType(fieldName: string, field: GraphQLField<unknown, unknown>, entityTypes: Set<string>, options?: GraphQLConversionOptions): GraphQLConversionFieldMeta;
136
-
137
52
  /**
138
53
  * Clear all registered handlers
139
54
  * @public
@@ -146,51 +61,6 @@ export declare function clearHandlers(): void;
146
61
  */
147
62
  export declare function clearRegistry(): void;
148
63
 
149
- /**
150
- * Output of GraphQL schema conversion — one per entity type.
151
- *
152
- * @public
153
- */
154
- export declare interface ConvertedGraphQLDoctype extends Omit<DoctypeMeta, 'fields'> {
155
- /** Field definitions with optional GraphQL conversion metadata */
156
- fields: GraphQLConversionFieldMeta[];
157
- /** Original GraphQL type name (for debugging/reference) */
158
- _graphqlTypeName?: string;
159
- }
160
-
161
- /**
162
- * Convert a GraphQL schema to Stonecrop doctype schemas.
163
- *
164
- * Accepts either an `IntrospectionQuery` result object or an SDL string.
165
- * Entity types are identified using heuristics (or a custom `isEntityType` function)
166
- * and converted to `DoctypeMeta`-compatible JSON objects.
167
- *
168
- * @param source - GraphQL introspection result or SDL string
169
- * @param options - Conversion options for controlling output format and behavior
170
- * @returns Array of converted Stonecrop doctype definitions
171
- *
172
- * @example
173
- * ```typescript
174
- * // From introspection result (fetched from any GraphQL server)
175
- * const introspection = await fetchIntrospection('http://localhost:5000/graphql')
176
- * const doctypes = convertGraphQLSchema(introspection)
177
- *
178
- * // From SDL string
179
- * const sdl = fs.readFileSync('schema.graphql', 'utf-8')
180
- * const doctypes = convertGraphQLSchema(sdl)
181
- *
182
- * // With PostGraphile custom scalars
183
- * const doctypes = convertGraphQLSchema(introspection, {
184
- * customScalars: {
185
- * BigFloat: { component: 'ADecimalInput', fieldtype: 'Decimal' }
186
- * }
187
- * })
188
- * ```
189
- *
190
- * @public
191
- */
192
- export declare function convertGraphQLSchema(source: IntrospectionSource, options?: GraphQLConversionOptions): ConvertedGraphQLDoctype[];
193
-
194
64
  /**
195
65
  * Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality
196
66
  * @param options - Plugin configuration options
@@ -201,42 +71,13 @@ export declare const createStonecropPlugin: (options: StonecropPluginOptions) =>
201
71
 
202
72
  /**
203
73
  * Amber default: sales_orders → allSalesOrders
204
- * @internal
205
- */
206
- export declare function defaultConnectionFieldName(tableName: string): string;
207
-
208
- /**
209
- * Default heuristic to filter fields on entity types.
210
- * Skips internal fields that don't represent meaningful data.
211
- *
212
- * @param fieldName - The GraphQL field name
213
- * @param _field - The GraphQL field definition (unused in default implementation)
214
- * @param _parentType - The parent entity type (unused in default implementation)
215
- * @returns `true` if this field should be included
216
- * @public
217
- */
218
- export declare function defaultIsEntityField(fieldName: string, _field: GraphQLField<unknown, unknown>, _parentType: GraphQLObjectType): boolean;
219
-
220
- /**
221
- * Default heuristic to determine if a GraphQL object type represents an entity.
222
- * An entity type becomes a Stonecrop doctype.
223
- *
224
- * This heuristic excludes:
225
- * - Introspection types (`__*`)
226
- * - Root operation types (`Query`, `Mutation`, `Subscription`)
227
- * - Types with synthetic suffixes (e.g., `*Connection`, `*Edge`, `*Input`)
228
- * - Types starting with `Node` interface marker (exact match only)
229
- *
230
- * @param typeName - The GraphQL type name
231
- * @param type - The GraphQL object type definition
232
- * @returns `true` if this type should become a Stonecrop doctype
233
74
  * @public
234
75
  */
235
- export declare function defaultIsEntityType(typeName: string, type: GraphQLObjectType): boolean;
76
+ export declare function defaultConnectionFieldName(tableName: string): string;
236
77
 
237
78
  /**
238
79
  * Amber default: sales_orders → SalesOrdersOrderBy
239
- * @internal
80
+ * @public
240
81
  */
241
82
  export declare function defaultOrderByTypeName(tableName: string): string;
242
83
 
@@ -244,7 +85,7 @@ export declare function defaultOrderByTypeName(tableName: string): string;
244
85
  * Amber default: sales_orders → salesOrderById
245
86
  * Uses `pluralize` for proper singularization of irregular plurals.
246
87
  * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.
247
- * @internal
88
+ * @public
248
89
  */
249
90
  export declare function defaultRecordFieldName(tableName: string): string;
250
91
 
@@ -477,177 +318,12 @@ export declare class DoctypeValidationError extends Error {
477
318
  errors: ValidationError[]);
478
319
  }
479
320
 
480
- /**
481
- * Unified field metadata - the single source of truth for field definitions.
482
- * Works for both forms (AForm) and tables (ATable).
483
- *
484
- * Core principle: "Text" is "Text" regardless of rendering context.
485
- *
486
- * @public
487
- */
488
- export declare const FieldMeta: z.ZodObject<{
489
- /** Unique identifier for the field within its doctype */
490
- fieldname: z.ZodString;
491
- /** Semantic field type - determines behavior and default component */
492
- fieldtype: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
493
- /** Vue component to render this field. If not specified, derived from TYPE_MAP */
494
- component: z.ZodOptional<z.ZodString>;
495
- /** Human-readable label for the field */
496
- label: z.ZodOptional<z.ZodString>;
497
- /** Width of the field (CSS value, e.g., "40ch", "200px") */
498
- width: z.ZodOptional<z.ZodString>;
499
- /** Text alignment within the field */
500
- align: z.ZodOptional<z.ZodEnum<["left", "center", "right", "start", "end"]>>;
501
- /** Whether the field is required */
502
- required: z.ZodOptional<z.ZodBoolean>;
503
- /** Whether the field is read-only */
504
- readOnly: z.ZodOptional<z.ZodBoolean>;
505
- /** Whether the field is editable (for table cells) */
506
- edit: z.ZodOptional<z.ZodBoolean>;
507
- /** Whether the field is hidden from the UI */
508
- hidden: z.ZodOptional<z.ZodBoolean>;
509
- /** Current value of the field */
510
- value: z.ZodOptional<z.ZodUnknown>;
511
- /** Default value for new records */
512
- default: z.ZodOptional<z.ZodUnknown>;
513
- /**
514
- * Type-specific options:
515
- * - Link: target doctype slug ("customer")
516
- * - Doctype: child doctype slug ("sales-order-item")
517
- * - Select: choices array (["Draft", "Submitted"])
518
- * - Decimal: \{ precision, scale \}
519
- * - Code: \{ language \}
520
- */
521
- options: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
522
- /** Input mask pattern (e.g., "##/##/####" for dates) */
523
- mask: z.ZodOptional<z.ZodString>;
524
- /** Validation configuration */
525
- validation: z.ZodOptional<z.ZodObject<{
526
- /** Error message to display when validation fails */
527
- errorMessage: z.ZodString;
528
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
529
- /** Error message to display when validation fails */
530
- errorMessage: z.ZodString;
531
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
532
- /** Error message to display when validation fails */
533
- errorMessage: z.ZodString;
534
- }, z.ZodTypeAny, "passthrough">>>;
535
- }, "strip", z.ZodTypeAny, {
536
- fieldname: string;
537
- fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
538
- value?: unknown;
539
- options?: string | string[] | Record<string, unknown> | undefined;
540
- validation?: z.objectOutputType<{
541
- /** Error message to display when validation fails */
542
- errorMessage: z.ZodString;
543
- }, z.ZodTypeAny, "passthrough"> | undefined;
544
- component?: string | undefined;
545
- label?: string | undefined;
546
- width?: string | undefined;
547
- align?: "left" | "center" | "right" | "start" | "end" | undefined;
548
- required?: boolean | undefined;
549
- readOnly?: boolean | undefined;
550
- edit?: boolean | undefined;
551
- hidden?: boolean | undefined;
552
- default?: unknown;
553
- mask?: string | undefined;
554
- }, {
555
- fieldname: string;
556
- fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
557
- value?: unknown;
558
- options?: string | string[] | Record<string, unknown> | undefined;
559
- validation?: z.objectInputType<{
560
- /** Error message to display when validation fails */
561
- errorMessage: z.ZodString;
562
- }, z.ZodTypeAny, "passthrough"> | undefined;
563
- component?: string | undefined;
564
- label?: string | undefined;
565
- width?: string | undefined;
566
- align?: "left" | "center" | "right" | "start" | "end" | undefined;
567
- required?: boolean | undefined;
568
- readOnly?: boolean | undefined;
569
- edit?: boolean | undefined;
570
- hidden?: boolean | undefined;
571
- default?: unknown;
572
- mask?: string | undefined;
573
- }>;
574
-
575
- /**
576
- * Field metadata type inferred from Zod schema
577
- * @public
578
- */
579
- export declare type FieldMeta = z.infer<typeof FieldMeta>;
580
-
581
- /**
582
- * Field options - flexible bag for type-specific configuration.
583
- *
584
- * Usage by fieldtype:
585
- * - Link/Doctype: target doctype slug as string ("customer", "sales-order-item")
586
- * - Select: array of choices (["Draft", "Submitted", "Cancelled"])
587
- * - Decimal: config object (\{ precision: 10, scale: 2 \})
588
- * - Code: config object (\{ language: "python" \})
589
- *
590
- * @public
591
- */
592
- export declare const FieldOptions: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
593
-
594
- /**
595
- * Field options type inferred from Zod schema
596
- * @public
597
- */
598
- export declare type FieldOptions = z.infer<typeof FieldOptions>;
599
-
600
- /**
601
- * Field template for TYPE_MAP entries.
602
- * Defines the default component and semantic field type for a field.
603
- * @public
604
- */
605
- declare interface FieldTemplate {
606
- /**
607
- * The Vue component name to render this field (e.g., 'ATextInput', 'ADropdown')
608
- */
609
- component: string;
610
- /**
611
- * The semantic field type (e.g., 'Data', 'Int', 'Select')
612
- */
613
- fieldtype: StonecropFieldType;
614
- }
615
-
616
- /**
617
- * Validation configuration for form fields
618
- * @public
619
- */
620
- export declare const FieldValidation: z.ZodObject<{
621
- /** Error message to display when validation fails */
622
- errorMessage: z.ZodString;
623
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
624
- /** Error message to display when validation fails */
625
- errorMessage: z.ZodString;
626
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
627
- /** Error message to display when validation fails */
628
- errorMessage: z.ZodString;
629
- }, z.ZodTypeAny, "passthrough">>;
630
-
631
- /**
632
- * Field validation type inferred from Zod schema
633
- * @public
634
- */
635
- export declare type FieldValidation = z.infer<typeof FieldValidation>;
636
-
637
321
  /**
638
322
  * Get all loaded doctypes
639
323
  * @public
640
324
  */
641
325
  export declare function getAllMeta(): DoctypeMeta[];
642
326
 
643
- /**
644
- * Get the default component for a field type
645
- * @param fieldtype - The semantic field type
646
- * @returns The default component name
647
- * @public
648
- */
649
- export declare function getDefaultComponent(fieldtype: StonecropFieldType): string;
650
-
651
327
  /**
652
328
  * Get a registered handler by name
653
329
  * @param name - Name of the action handler to retrieve
@@ -662,125 +338,6 @@ export declare function getHandler(name: string): ActionHandler | undefined;
662
338
  */
663
339
  export declare function getMeta(name: string): DoctypeMeta | undefined;
664
340
 
665
- /**
666
- * Mapping from standard GraphQL scalar types to Stonecrop field types.
667
- * These are defined by the GraphQL specification and are always available.
668
- *
669
- * @public
670
- */
671
- export declare const GQL_SCALAR_MAP: Record<string, FieldTemplate>;
672
-
673
- /**
674
- * Extended field metadata with optional GraphQL conversion metadata.
675
- * Only present when `includeUnmappedMeta` is enabled.
676
- *
677
- * @public
678
- */
679
- export declare interface GraphQLConversionFieldMeta extends FieldMeta {
680
- /** Original GraphQL type name (for debugging/reference) */
681
- _graphqlType?: string;
682
- /** Marks fields that couldn't be automatically mapped */
683
- _unmapped?: boolean;
684
- }
685
-
686
- /**
687
- * Options for converting a GraphQL schema to Stonecrop doctype schemas.
688
- * All hooks are optional — sensible defaults are provided for common GraphQL patterns.
689
- *
690
- * @public
691
- */
692
- export declare interface GraphQLConversionOptions {
693
- /**
694
- * GraphQL type names to exclude from conversion.
695
- * Applied after `isEntityType` filtering.
696
- */
697
- exclude?: string[];
698
- /**
699
- * Whitelist of GraphQL type names to convert.
700
- * When provided, only these types are considered (after `isEntityType` filtering).
701
- */
702
- include?: string[];
703
- /**
704
- * Per-type, per-field overrides for the converted field definitions.
705
- * Outer key is the GraphQL type name, inner key is the field name.
706
- *
707
- * @example
708
- * ```typescript
709
- * {
710
- * SalesOrder: {
711
- * totalAmount: { fieldtype: 'Currency', component: 'ACurrencyInput' }
712
- * }
713
- * }
714
- * ```
715
- */
716
- typeOverrides?: Record<string, Record<string, Partial<FieldMeta>>>;
717
- /**
718
- * Map custom or non-standard GraphQL scalar types to Stonecrop field types.
719
- * Merged with the built-in scalar maps (GQL_SCALAR_MAP + WELL_KNOWN_SCALARS).
720
- * User-provided entries take highest precedence.
721
- *
722
- * @example
723
- * ```typescript
724
- * {
725
- * MyCustomMoney: { component: 'ACurrencyInput', fieldtype: 'Currency' },
726
- * PostGISPoint: { component: 'ATextInput', fieldtype: 'Data' }
727
- * }
728
- * ```
729
- */
730
- customScalars?: Record<string, Partial<FieldTemplate>>;
731
- /**
732
- * Custom function to determine if a GraphQL object type represents an entity (→ doctype).
733
- * When provided, replaces the default heuristic entirely.
734
- *
735
- * The default heuristic excludes types matching synthetic patterns:
736
- * `*Connection`, `*Edge`, `*Input`, `*Patch`, `*Payload`, `*Condition`,
737
- * `*Filter`, `*OrderBy`, `*Aggregate`, `Query`, `Mutation`, `Subscription`, `__*`.
738
- *
739
- * @param typeName - The GraphQL type name
740
- * @param type - The full GraphQL object type definition
741
- * @returns `true` if this type should become a Stonecrop doctype
742
- */
743
- isEntityType?: (typeName: string, type: GraphQLObjectType) => boolean;
744
- /**
745
- * Custom function to filter which fields on an entity type are included.
746
- * When provided, replaces the default field filter.
747
- *
748
- * The default filter excludes `nodeId`, `__typename`, and `clientMutationId`.
749
- *
750
- * @param fieldName - The GraphQL field name
751
- * @param field - The full GraphQL field definition
752
- * @param parentType - The parent entity type
753
- * @returns `true` if this field should be included
754
- */
755
- isEntityField?: (fieldName: string, field: GraphQLField<unknown, unknown>, parentType: GraphQLObjectType) => boolean;
756
- /**
757
- * Escape hatch: fully override the classification of a specific field.
758
- * When this returns a non-null value, it is used as the field definition
759
- * (merged with the field name). Return `null` to fall through to default classification.
760
- *
761
- * @param fieldName - The GraphQL field name
762
- * @param field - The full GraphQL field definition
763
- * @param parentType - The parent entity type
764
- * @returns Partial field meta to use, or `null` for default behavior
765
- */
766
- classifyField?: (fieldName: string, field: GraphQLField<unknown, unknown>, parentType: GraphQLObjectType) => Partial<FieldMeta> | null;
767
- /**
768
- * Custom function to derive the database table name from a GraphQL type name.
769
- * The default converts PascalCase to snake_case (e.g., `SalesOrder` → `sales_order`).
770
- *
771
- * Return `undefined` to omit `tableName` from the output.
772
- *
773
- * @param typeName - The GraphQL type name
774
- * @returns The derived table name, or `undefined`
775
- */
776
- deriveTableName?: (typeName: string) => string | undefined;
777
- /**
778
- * Include `_graphqlType` and `_unmapped` metadata on converted fields.
779
- * Useful for debugging conversions. Defaults to `false`.
780
- */
781
- includeUnmappedMeta?: boolean;
782
- }
783
-
784
341
  /**
785
342
  * GraphQL executor interface for running queries/mutations
786
343
  * @public
@@ -806,21 +363,6 @@ export declare function hasHandler(name: string): boolean;
806
363
  */
807
364
  export declare function hasMeta(name: string): boolean;
808
365
 
809
- /**
810
- * Input source for the GraphQL schema converter.
811
- * Accepts either a standard GraphQL introspection result or an SDL string.
812
- *
813
- * - `IntrospectionQuery`: The raw result of a GraphQL introspection query (from any server)
814
- * - `string`: An SDL (Schema Definition Language) string
815
- *
816
- * Note: URL fetching is intentionally not supported in the library API.
817
- * Use the CLI (`stonecrop-schema generate --endpoint <url>`) for endpoint fetching,
818
- * or fetch the introspection result yourself and pass it in.
819
- *
820
- * @public
821
- */
822
- export declare type IntrospectionSource = IntrospectionQuery | string;
823
-
824
366
  /**
825
367
  * Load doctype definitions from a directory of JSON files
826
368
  * @param dir - Directory path containing doctype JSON files
@@ -848,41 +390,10 @@ export declare interface LoadDoctypesOptions {
848
390
  onError?: (file: string, errors: ValidationError[]) => void;
849
391
  }
850
392
 
851
- /**
852
- * Parse and validate a doctype, throwing on failure
853
- * @param data - Data to parse
854
- * @returns Validated DoctypeMeta
855
- * @throws ZodError if validation fails
856
- * @public
857
- */
858
- export declare function parseDoctype(data: unknown): DoctypeMeta;
859
-
860
- /**
861
- * Parse and validate a field, throwing on failure
862
- * @param data - Data to parse
863
- * @returns Validated FieldMeta
864
- * @throws ZodError if validation fails
865
- * @public
866
- */
867
- export declare function parseField(data: unknown): FieldMeta;
868
-
869
- /**
870
- * Convert PascalCase to snake_case (e.g., for deriving table names from type names)
871
- * @param pascal - PascalCase string
872
- * @returns snake_case string
873
- * @public
874
- * @example
875
- * ```typescript
876
- * pascalToSnake('SalesOrder') // 'sales_order'
877
- * pascalToSnake('SalesOrderItem') // 'sales_order_item'
878
- * ```
879
- */
880
- export declare function pascalToSnake(pascal: string): string;
881
-
882
393
  /**
883
394
  * Filter fields to only those directly queryable as scalars, excluding Link and Doctype
884
395
  * relation fields that require GraphQL sub-selections.
885
- * @internal
396
+ * @public
886
397
  */
887
398
  export declare function queryableFieldNames(meta: DoctypeMeta): string;
888
399
 
@@ -903,136 +414,9 @@ export declare function registerHandler(name: string, handler: ActionHandler): v
903
414
  /**
904
415
  * Fieldtypes that map to GraphQL object/connection types and require sub-selections.
905
416
  * These fields are excluded from generated query field selections.
906
- * @internal
907
- */
908
- export declare const RELATION_FIELDTYPES: Set<string>;
909
-
910
- /**
911
- * Route context for identifying what doctype/record we're working with
912
417
  * @public
913
418
  */
914
- export declare interface RouteContext {
915
- /** Doctype name (e.g., 'Task', 'Customer') */
916
- doctype: string;
917
- /** Optional record ID for viewing/editing a specific record */
918
- recordId?: string;
919
- /** Additional context properties */
920
- [key: string]: unknown;
921
- }
922
-
923
- /**
924
- * Converts snake_case to camelCase
925
- * @param snakeCase - Snake case string
926
- * @returns Camel case string
927
- * @public
928
- * @example
929
- * ```typescript
930
- * snakeToCamel('user_email') // 'userEmail'
931
- * snakeToCamel('created_at') // 'createdAt'
932
- * ```
933
- */
934
- export declare function snakeToCamel(snakeCase: string): string;
935
-
936
- /**
937
- * Converts snake_case to Title Case label
938
- * @param snakeCase - Snake case string
939
- * @returns Title case label
940
- * @public
941
- * @example
942
- * ```typescript
943
- * snakeToLabel('user_email') // 'User Email'
944
- * snakeToLabel('first_name') // 'First Name'
945
- * ```
946
- */
947
- export declare function snakeToLabel(snakeCase: string): string;
948
-
949
- /**
950
- * Client for interacting with Stonecrop GraphQL API
951
- * @public
952
- */
953
- export declare class StonecropClient implements GraphQLExecutor {
954
- private endpoint;
955
- private headers;
956
- private metaCache;
957
- constructor(options: StonecropClientOptions);
958
- /**
959
- * Execute a GraphQL query
960
- * @param query - GraphQL query string
961
- * @param variables - Query variables
962
- */
963
- query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
964
- /**
965
- * Execute a GraphQL mutation
966
- * @param mutation - GraphQL mutation string
967
- * @param variables - Mutation variables
968
- */
969
- mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
970
- /**
971
- * Get doctype metadata
972
- * @param context - Route context containing doctype name
973
- */
974
- getMeta(context: RouteContext): Promise<DoctypeMeta | null>;
975
- /**
976
- * Get all doctype metadata
977
- */
978
- getAllMeta(): Promise<DoctypeMeta[]>;
979
- /**
980
- * Get a single record by ID
981
- * @param doctype - Doctype metadata
982
- * @param recordId - Record ID to fetch
983
- */
984
- getRecord(doctype: DoctypeMeta, recordId: string): Promise<Record<string, unknown> | null>;
985
- /**
986
- * Get multiple records with optional filtering and pagination
987
- * @param doctype - Doctype metadata
988
- * @param options - Query options (filters, orderBy, limit, offset)
989
- */
990
- getRecords(doctype: DoctypeMeta, options?: {
991
- filters?: Record<string, unknown>;
992
- orderBy?: string;
993
- limit?: number;
994
- offset?: number;
995
- }): Promise<Record<string, unknown>[]>;
996
- /**
997
- * Execute a doctype action
998
- * @param doctype - Doctype metadata
999
- * @param action - Action name to execute
1000
- * @param args - Action arguments
1001
- */
1002
- runAction(doctype: DoctypeMeta, action: string, args?: unknown[]): Promise<{
1003
- success: boolean;
1004
- data: unknown;
1005
- error: string | null;
1006
- }>;
1007
- /**
1008
- * Clear the cached doctype metadata
1009
- */
1010
- clearMetaCache(): void;
1011
- }
1012
-
1013
- /**
1014
- * Options for creating a Stonecrop client
1015
- * @public
1016
- */
1017
- export declare interface StonecropClientOptions {
1018
- /** GraphQL endpoint URL */
1019
- endpoint: string;
1020
- /** Additional HTTP headers to include in requests */
1021
- headers?: Record<string, string>;
1022
- }
1023
-
1024
- /**
1025
- * Stonecrop field types - the semantic type of the field.
1026
- * These are consistent across forms and tables.
1027
- * @public
1028
- */
1029
- 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"]>;
1030
-
1031
- /**
1032
- * Stonecrop field type enum inferred from Zod schema
1033
- * @public
1034
- */
1035
- export declare type StonecropFieldType = z.infer<typeof StonecropFieldType>;
419
+ export declare const RELATION_FIELDTYPES: Set<string>;
1036
420
 
1037
421
  /**
1038
422
  * Inflection callbacks for mapping table names to GraphQL query field names.
@@ -1059,6 +443,18 @@ export declare interface StonecropInflectionConfig {
1059
443
  * @example Amber default: "sales_orders" → "SalesOrdersOrderBy"
1060
444
  */
1061
445
  orderByTypeName?: (tableName: string) => string;
446
+ /**
447
+ * Given a table name, return the GraphQL argument name used to look up a record by PK.
448
+ * @example Amber default (Relay Global ID): "sales_orders" → "id"
449
+ * @example row_id PK: "sales_orders" → "rowId"
450
+ */
451
+ recordArgName?: (tableName: string) => string;
452
+ /**
453
+ * Given a table name, return the GraphQL variable type for the PK argument.
454
+ * @example Default UUID PK: "sales_orders" → "UUID!"
455
+ * @example Integer PK: "sales_orders" → "Int!"
456
+ */
457
+ recordArgType?: (tableName: string) => string;
1062
458
  }
1063
459
 
1064
460
  /**
@@ -1075,45 +471,6 @@ export declare interface StonecropPluginOptions {
1075
471
  inflection?: StonecropInflectionConfig;
1076
472
  }
1077
473
 
1078
- /**
1079
- * Convert table name to PascalCase doctype name
1080
- * @param tableName - SQL table name (snake_case)
1081
- * @returns PascalCase name
1082
- * @public
1083
- */
1084
- export declare function toPascalCase(tableName: string): string;
1085
-
1086
- /**
1087
- * Convert to kebab-case slug
1088
- * @param name - Name to convert
1089
- * @returns kebab-case slug
1090
- * @public
1091
- */
1092
- export declare function toSlug(name: string): string;
1093
-
1094
- /**
1095
- * Mapping from StonecropFieldType to default Vue component.
1096
- * Components can be overridden in the field definition.
1097
- * @public
1098
- */
1099
- export declare const TYPE_MAP: Record<StonecropFieldType, FieldTemplate>;
1100
-
1101
- /**
1102
- * Validate a doctype definition
1103
- * @param data - Data to validate
1104
- * @returns Validation result
1105
- * @public
1106
- */
1107
- export declare function validateDoctype(data: unknown): ValidationResult;
1108
-
1109
- /**
1110
- * Validate a field definition
1111
- * @param data - Data to validate
1112
- * @returns Validation result
1113
- * @public
1114
- */
1115
- export declare function validateField(data: unknown): ValidationResult;
1116
-
1117
474
  /**
1118
475
  * Validate cross-doctype references (Link fields, inherits, etc.)
1119
476
  * Call after all doctypes are loaded.
@@ -1132,91 +489,4 @@ export declare interface ValidationError {
1132
489
  message: string;
1133
490
  }
1134
491
 
1135
- /**
1136
- * Result of a validation operation
1137
- * @public
1138
- */
1139
- export declare interface ValidationResult {
1140
- /** Whether validation passed */
1141
- success: boolean;
1142
- /** List of validation errors (empty if success) */
1143
- errors: ValidationError[];
1144
- }
1145
-
1146
- /**
1147
- * Mapping from well-known custom GraphQL scalars to Stonecrop field types.
1148
- * These cover scalars commonly used across GraphQL servers (PostGraphile, Hasura, etc.)
1149
- * without baking in knowledge of any specific server.
1150
- *
1151
- * Entries here have lower precedence than `customScalars` from options, but higher
1152
- * precedence than unknown/unmapped scalars.
1153
- *
1154
- * @public
1155
- */
1156
- export declare const WELL_KNOWN_SCALARS: Record<string, FieldTemplate>;
1157
-
1158
- /**
1159
- * Workflow metadata - states and actions for a doctype
1160
- * @public
1161
- */
1162
- export declare const WorkflowMeta: z.ZodObject<{
1163
- /** List of workflow states */
1164
- states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1165
- /** Actions available in this workflow */
1166
- actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1167
- /** Display label for the action */
1168
- label: z.ZodString;
1169
- /** Handler function name or path */
1170
- handler: z.ZodString;
1171
- /** Fields that must have values before action can execute */
1172
- requiredFields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1173
- /** Workflow states where this action is available */
1174
- allowedStates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1175
- /** Whether to show a confirmation dialog */
1176
- confirm: z.ZodOptional<z.ZodBoolean>;
1177
- /** Additional arguments for the action */
1178
- args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1179
- }, "strip", z.ZodTypeAny, {
1180
- label: string;
1181
- handler: string;
1182
- requiredFields?: string[] | undefined;
1183
- allowedStates?: string[] | undefined;
1184
- confirm?: boolean | undefined;
1185
- args?: Record<string, unknown> | undefined;
1186
- }, {
1187
- label: string;
1188
- handler: string;
1189
- requiredFields?: string[] | undefined;
1190
- allowedStates?: string[] | undefined;
1191
- confirm?: boolean | undefined;
1192
- args?: Record<string, unknown> | undefined;
1193
- }>>>;
1194
- }, "strip", z.ZodTypeAny, {
1195
- states?: string[] | undefined;
1196
- actions?: Record<string, {
1197
- label: string;
1198
- handler: string;
1199
- requiredFields?: string[] | undefined;
1200
- allowedStates?: string[] | undefined;
1201
- confirm?: boolean | undefined;
1202
- args?: Record<string, unknown> | undefined;
1203
- }> | undefined;
1204
- }, {
1205
- states?: string[] | undefined;
1206
- actions?: Record<string, {
1207
- label: string;
1208
- handler: string;
1209
- requiredFields?: string[] | undefined;
1210
- allowedStates?: string[] | undefined;
1211
- confirm?: boolean | undefined;
1212
- args?: Record<string, unknown> | undefined;
1213
- }> | undefined;
1214
- }>;
1215
-
1216
- /**
1217
- * Workflow metadata type inferred from Zod schema
1218
- * @public
1219
- */
1220
- export declare type WorkflowMeta = z.infer<typeof WorkflowMeta>;
1221
-
1222
492
  export { }