@stonecrop/graphql-middleware 0.8.13 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -80
- package/dist/graphql-middleware.d.ts +17 -220
- package/dist/index.js +38 -36
- package/dist/index.js.map +1 -1
- package/dist/plugin/postgraphile.js +7 -6
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.d.ts +3 -3
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/package.json +7 -9
- package/dist/index.cjs +0 -86
- package/dist/index.cjs.map +0 -1
- /package/dist/{src/tsdoc-metadata.json → tsdoc-metadata.json} +0 -0
package/README.md
CHANGED
|
@@ -12,10 +12,10 @@ import { grafserv } from 'postgraphile/grafserv'
|
|
|
12
12
|
import { PostGraphileAmberPreset } from 'postgraphile/presets/amber'
|
|
13
13
|
import { makePgService } from 'postgraphile/adaptors/pg'
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
createStonecropPlugin,
|
|
16
|
+
loadDoctypes,
|
|
17
|
+
registerBuiltinHandlers,
|
|
18
|
+
registerHandler,
|
|
19
19
|
} from '@stonecrop/graphql-middleware'
|
|
20
20
|
|
|
21
21
|
// Load doctype definitions from JSON files
|
|
@@ -24,30 +24,30 @@ loadDoctypes('./doctypes')
|
|
|
24
24
|
// Register action handlers
|
|
25
25
|
registerBuiltinHandlers()
|
|
26
26
|
registerHandler('submitOrder', async (args, ctx) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const [orderId] = args as [string]
|
|
28
|
+
// Custom business logic
|
|
29
|
+
return { submitted: true }
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
// Create executor for the plugin to use
|
|
33
33
|
const executor = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
async query(query: string, variables?: Record<string, unknown>) {
|
|
35
|
+
// Execute against PostGraphile's internal schema
|
|
36
|
+
return graphqlExecute(schema, query, variables)
|
|
37
|
+
},
|
|
38
|
+
async mutate(mutation: string, variables?: Record<string, unknown>) {
|
|
39
|
+
return this.query(mutation, variables)
|
|
40
|
+
},
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const preset: GraphileConfig.Preset = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
extends: [PostGraphileAmberPreset],
|
|
45
|
+
plugins: [createStonecropPlugin({ executor })],
|
|
46
|
+
pgServices: [
|
|
47
|
+
makePgService({
|
|
48
|
+
connectionString: process.env.DATABASE_URL,
|
|
49
|
+
}),
|
|
50
|
+
],
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -57,7 +57,7 @@ const preset: GraphileConfig.Preset = {
|
|
|
57
57
|
import { StonecropClient } from '@stonecrop/graphql-middleware'
|
|
58
58
|
|
|
59
59
|
const client = new StonecropClient({
|
|
60
|
-
|
|
60
|
+
endpoint: 'http://localhost:4000/graphql',
|
|
61
61
|
})
|
|
62
62
|
|
|
63
63
|
// Get doctype metadata
|
|
@@ -65,8 +65,8 @@ const meta = await client.getMeta({ doctype: 'SalesOrder' })
|
|
|
65
65
|
|
|
66
66
|
// Fetch records
|
|
67
67
|
const orders = await client.getRecords(meta, {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
limit: 10,
|
|
69
|
+
orderBy: 'createdAt',
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
// Fetch single record
|
|
@@ -80,63 +80,28 @@ const result = await client.runAction(meta, 'submit', [order.id])
|
|
|
80
80
|
|
|
81
81
|
```json
|
|
82
82
|
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
"name": "SalesOrder",
|
|
84
|
+
"tableName": "sales_orders",
|
|
85
|
+
"fields": [
|
|
86
|
+
{ "fieldname": "id", "fieldtype": "UUID" },
|
|
87
|
+
{ "fieldname": "customer", "fieldtype": "Link", "required": true },
|
|
88
|
+
{ "fieldname": "status", "fieldtype": "Select" },
|
|
89
|
+
{ "fieldname": "total", "fieldtype": "Currency" }
|
|
90
|
+
],
|
|
91
|
+
"workflow": {
|
|
92
|
+
"states": ["Draft", "Submitted", "Cancelled"],
|
|
93
|
+
"actions": {
|
|
94
|
+
"submit": {
|
|
95
|
+
"label": "Submit",
|
|
96
|
+
"handler": "submitOrder",
|
|
97
|
+
"requiredFields": ["customer"],
|
|
98
|
+
"allowedStates": ["Draft"]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
102
|
}
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
##
|
|
105
|
+
## References
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
- `loadDoctypes(dir: string)` - Load doctype JSON files from directory
|
|
110
|
-
- `loadDoctypesFromObject(doctypes)` - Load doctypes from an object
|
|
111
|
-
- `getMeta(name: string)` - Get a single doctype definition
|
|
112
|
-
- `getAllMeta()` - Get all loaded doctypes
|
|
113
|
-
- `registerHandler(name, handler)` - Register an action handler
|
|
114
|
-
- `registerBuiltinHandlers()` - Register built-in handlers
|
|
115
|
-
|
|
116
|
-
### Built-in Handlers
|
|
117
|
-
|
|
118
|
-
- `validateRequiredFields` - Validates that required fields are present
|
|
119
|
-
- `noop` - Does nothing, returns `{ ok: true }`
|
|
120
|
-
|
|
121
|
-
### GraphQL Schema
|
|
122
|
-
|
|
123
|
-
The plugin adds these operations:
|
|
124
|
-
|
|
125
|
-
```graphql
|
|
126
|
-
type Query {
|
|
127
|
-
stonecropMeta(doctype: String!): DoctypeMeta
|
|
128
|
-
stonecropAllMeta: [DoctypeMeta!]!
|
|
129
|
-
stonecropRecord(doctype: String!, id: String!): RecordResult
|
|
130
|
-
stonecropRecords(
|
|
131
|
-
doctype: String!
|
|
132
|
-
filters: JSON
|
|
133
|
-
orderBy: String
|
|
134
|
-
limit: Int
|
|
135
|
-
offset: Int
|
|
136
|
-
): RecordsResult
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
type Mutation {
|
|
140
|
-
stonecropAction(doctype: String!, action: String!, args: JSON): ActionResult!
|
|
141
|
-
}
|
|
142
|
-
```
|
|
107
|
+
For full method signatures and parameter details, see [API Reference](./api.md).
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DoctypeMeta } from '@stonecrop/schema';
|
|
1
2
|
import { GraphileConfig as GraphileConfig_2 } from 'postgraphile/graphile-build';
|
|
2
|
-
import {
|
|
3
|
+
import { ValidationError } from '@stonecrop/schema';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Context passed to action handlers
|
|
@@ -82,225 +83,30 @@ export declare function defaultConnectionFieldName(tableName: string): string;
|
|
|
82
83
|
export declare function defaultOrderByTypeName(tableName: string): string;
|
|
83
84
|
|
|
84
85
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
86
|
+
* Default PK argument name: 'id' (standard Relay Global ID pattern).
|
|
87
|
+
* Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;
|
|
88
|
+
* PostGraphile Amber generates `rowId: UUID!` for those fields.
|
|
88
89
|
* @public
|
|
89
90
|
*/
|
|
90
|
-
export declare function
|
|
91
|
+
export declare function defaultRecordArgName(_tableName: string): string;
|
|
91
92
|
|
|
92
93
|
/**
|
|
93
|
-
*
|
|
94
|
+
* Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).
|
|
95
|
+
* Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs
|
|
96
|
+
* such as integer serials or Relay Global IDs ('ID!').
|
|
94
97
|
* @public
|
|
95
98
|
*/
|
|
96
|
-
export declare
|
|
97
|
-
/** Display name of the doctype */
|
|
98
|
-
name: z.ZodString;
|
|
99
|
-
/** URL-friendly slug (kebab-case) */
|
|
100
|
-
slug: z.ZodOptional<z.ZodString>;
|
|
101
|
-
/** Database table name */
|
|
102
|
-
tableName: z.ZodOptional<z.ZodString>;
|
|
103
|
-
/** Field definitions */
|
|
104
|
-
fields: z.ZodArray<z.ZodObject<{
|
|
105
|
-
fieldname: z.ZodString;
|
|
106
|
-
fieldtype: z.ZodEnum<["Data", "Text", "Int", "Float", "Decimal", "Check", "Date", "Time", "Datetime", "Duration", "DateRange", "JSON", "Code", "Link", "Doctype", "Attach", "Currency", "Quantity", "Select"]>;
|
|
107
|
-
component: z.ZodOptional<z.ZodString>;
|
|
108
|
-
label: z.ZodOptional<z.ZodString>;
|
|
109
|
-
width: z.ZodOptional<z.ZodString>;
|
|
110
|
-
align: z.ZodOptional<z.ZodEnum<["left", "center", "right", "start", "end"]>>;
|
|
111
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
112
|
-
readOnly: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
-
edit: z.ZodOptional<z.ZodBoolean>;
|
|
114
|
-
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
-
value: z.ZodOptional<z.ZodUnknown>;
|
|
116
|
-
default: z.ZodOptional<z.ZodUnknown>;
|
|
117
|
-
options: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
|
|
118
|
-
mask: z.ZodOptional<z.ZodString>;
|
|
119
|
-
validation: z.ZodOptional<z.ZodObject<{
|
|
120
|
-
errorMessage: z.ZodString;
|
|
121
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
122
|
-
errorMessage: z.ZodString;
|
|
123
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
124
|
-
errorMessage: z.ZodString;
|
|
125
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
|
126
|
-
}, "strip", z.ZodTypeAny, {
|
|
127
|
-
fieldname: string;
|
|
128
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
129
|
-
value?: unknown;
|
|
130
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
131
|
-
validation?: z.objectOutputType<{
|
|
132
|
-
errorMessage: z.ZodString;
|
|
133
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
134
|
-
component?: string | undefined;
|
|
135
|
-
label?: string | undefined;
|
|
136
|
-
width?: string | undefined;
|
|
137
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
138
|
-
required?: boolean | undefined;
|
|
139
|
-
readOnly?: boolean | undefined;
|
|
140
|
-
edit?: boolean | undefined;
|
|
141
|
-
hidden?: boolean | undefined;
|
|
142
|
-
default?: unknown;
|
|
143
|
-
mask?: string | undefined;
|
|
144
|
-
}, {
|
|
145
|
-
fieldname: string;
|
|
146
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
147
|
-
value?: unknown;
|
|
148
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
149
|
-
validation?: z.objectInputType<{
|
|
150
|
-
errorMessage: z.ZodString;
|
|
151
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
152
|
-
component?: string | undefined;
|
|
153
|
-
label?: string | undefined;
|
|
154
|
-
width?: string | undefined;
|
|
155
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
156
|
-
required?: boolean | undefined;
|
|
157
|
-
readOnly?: boolean | undefined;
|
|
158
|
-
edit?: boolean | undefined;
|
|
159
|
-
hidden?: boolean | undefined;
|
|
160
|
-
default?: unknown;
|
|
161
|
-
mask?: string | undefined;
|
|
162
|
-
}>, "many">;
|
|
163
|
-
/** Workflow configuration */
|
|
164
|
-
workflow: z.ZodOptional<z.ZodObject<{
|
|
165
|
-
/** List of workflow states */
|
|
166
|
-
states: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
167
|
-
/** Actions available in this workflow */
|
|
168
|
-
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
169
|
-
/** Display label for the action */
|
|
170
|
-
label: z.ZodString;
|
|
171
|
-
/** Handler function name or path */
|
|
172
|
-
handler: z.ZodString;
|
|
173
|
-
/** Fields that must have values before action can execute */
|
|
174
|
-
requiredFields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
175
|
-
/** Workflow states where this action is available */
|
|
176
|
-
allowedStates: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
177
|
-
/** Whether to show a confirmation dialog */
|
|
178
|
-
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
179
|
-
/** Additional arguments for the action */
|
|
180
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
181
|
-
}, "strip", z.ZodTypeAny, {
|
|
182
|
-
label: string;
|
|
183
|
-
handler: string;
|
|
184
|
-
requiredFields?: string[] | undefined;
|
|
185
|
-
allowedStates?: string[] | undefined;
|
|
186
|
-
confirm?: boolean | undefined;
|
|
187
|
-
args?: Record<string, unknown> | undefined;
|
|
188
|
-
}, {
|
|
189
|
-
label: string;
|
|
190
|
-
handler: string;
|
|
191
|
-
requiredFields?: string[] | undefined;
|
|
192
|
-
allowedStates?: string[] | undefined;
|
|
193
|
-
confirm?: boolean | undefined;
|
|
194
|
-
args?: Record<string, unknown> | undefined;
|
|
195
|
-
}>>>;
|
|
196
|
-
}, "strip", z.ZodTypeAny, {
|
|
197
|
-
states?: string[] | undefined;
|
|
198
|
-
actions?: Record<string, {
|
|
199
|
-
label: string;
|
|
200
|
-
handler: string;
|
|
201
|
-
requiredFields?: string[] | undefined;
|
|
202
|
-
allowedStates?: string[] | undefined;
|
|
203
|
-
confirm?: boolean | undefined;
|
|
204
|
-
args?: Record<string, unknown> | undefined;
|
|
205
|
-
}> | undefined;
|
|
206
|
-
}, {
|
|
207
|
-
states?: string[] | undefined;
|
|
208
|
-
actions?: Record<string, {
|
|
209
|
-
label: string;
|
|
210
|
-
handler: string;
|
|
211
|
-
requiredFields?: string[] | undefined;
|
|
212
|
-
allowedStates?: string[] | undefined;
|
|
213
|
-
confirm?: boolean | undefined;
|
|
214
|
-
args?: Record<string, unknown> | undefined;
|
|
215
|
-
}> | undefined;
|
|
216
|
-
}>>;
|
|
217
|
-
/** Parent doctype for inheritance */
|
|
218
|
-
inherits: z.ZodOptional<z.ZodString>;
|
|
219
|
-
/** Doctype to use for list views */
|
|
220
|
-
listDoctype: z.ZodOptional<z.ZodString>;
|
|
221
|
-
/** Parent doctype for child tables */
|
|
222
|
-
parentDoctype: z.ZodOptional<z.ZodString>;
|
|
223
|
-
}, "strip", z.ZodTypeAny, {
|
|
224
|
-
name: string;
|
|
225
|
-
fields: {
|
|
226
|
-
fieldname: string;
|
|
227
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
228
|
-
value?: unknown;
|
|
229
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
230
|
-
validation?: z.objectOutputType<{
|
|
231
|
-
errorMessage: z.ZodString;
|
|
232
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
233
|
-
component?: string | undefined;
|
|
234
|
-
label?: string | undefined;
|
|
235
|
-
width?: string | undefined;
|
|
236
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
237
|
-
required?: boolean | undefined;
|
|
238
|
-
readOnly?: boolean | undefined;
|
|
239
|
-
edit?: boolean | undefined;
|
|
240
|
-
hidden?: boolean | undefined;
|
|
241
|
-
default?: unknown;
|
|
242
|
-
mask?: string | undefined;
|
|
243
|
-
}[];
|
|
244
|
-
slug?: string | undefined;
|
|
245
|
-
tableName?: string | undefined;
|
|
246
|
-
workflow?: {
|
|
247
|
-
states?: string[] | undefined;
|
|
248
|
-
actions?: Record<string, {
|
|
249
|
-
label: string;
|
|
250
|
-
handler: string;
|
|
251
|
-
requiredFields?: string[] | undefined;
|
|
252
|
-
allowedStates?: string[] | undefined;
|
|
253
|
-
confirm?: boolean | undefined;
|
|
254
|
-
args?: Record<string, unknown> | undefined;
|
|
255
|
-
}> | undefined;
|
|
256
|
-
} | undefined;
|
|
257
|
-
inherits?: string | undefined;
|
|
258
|
-
listDoctype?: string | undefined;
|
|
259
|
-
parentDoctype?: string | undefined;
|
|
260
|
-
}, {
|
|
261
|
-
name: string;
|
|
262
|
-
fields: {
|
|
263
|
-
fieldname: string;
|
|
264
|
-
fieldtype: "Data" | "Text" | "Int" | "Float" | "Decimal" | "Check" | "Date" | "Time" | "Datetime" | "Duration" | "DateRange" | "JSON" | "Code" | "Link" | "Doctype" | "Attach" | "Currency" | "Quantity" | "Select";
|
|
265
|
-
value?: unknown;
|
|
266
|
-
options?: string | string[] | Record<string, unknown> | undefined;
|
|
267
|
-
validation?: z.objectInputType<{
|
|
268
|
-
errorMessage: z.ZodString;
|
|
269
|
-
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
270
|
-
component?: string | undefined;
|
|
271
|
-
label?: string | undefined;
|
|
272
|
-
width?: string | undefined;
|
|
273
|
-
align?: "left" | "center" | "right" | "start" | "end" | undefined;
|
|
274
|
-
required?: boolean | undefined;
|
|
275
|
-
readOnly?: boolean | undefined;
|
|
276
|
-
edit?: boolean | undefined;
|
|
277
|
-
hidden?: boolean | undefined;
|
|
278
|
-
default?: unknown;
|
|
279
|
-
mask?: string | undefined;
|
|
280
|
-
}[];
|
|
281
|
-
slug?: string | undefined;
|
|
282
|
-
tableName?: string | undefined;
|
|
283
|
-
workflow?: {
|
|
284
|
-
states?: string[] | undefined;
|
|
285
|
-
actions?: Record<string, {
|
|
286
|
-
label: string;
|
|
287
|
-
handler: string;
|
|
288
|
-
requiredFields?: string[] | undefined;
|
|
289
|
-
allowedStates?: string[] | undefined;
|
|
290
|
-
confirm?: boolean | undefined;
|
|
291
|
-
args?: Record<string, unknown> | undefined;
|
|
292
|
-
}> | undefined;
|
|
293
|
-
} | undefined;
|
|
294
|
-
inherits?: string | undefined;
|
|
295
|
-
listDoctype?: string | undefined;
|
|
296
|
-
parentDoctype?: string | undefined;
|
|
297
|
-
}>;
|
|
99
|
+
export declare function defaultRecordArgType(_tableName: string): string;
|
|
298
100
|
|
|
299
101
|
/**
|
|
300
|
-
*
|
|
102
|
+
* Amber default: sales_orders → salesOrderById
|
|
103
|
+
* Uses `pluralize` for proper singularization of irregular plurals.
|
|
104
|
+
* Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.
|
|
301
105
|
* @public
|
|
302
106
|
*/
|
|
303
|
-
export declare
|
|
107
|
+
export declare function defaultRecordFieldName(tableName: string): string;
|
|
108
|
+
|
|
109
|
+
export { DoctypeMeta }
|
|
304
110
|
|
|
305
111
|
/**
|
|
306
112
|
* Error thrown when a doctype definition fails validation
|
|
@@ -478,15 +284,6 @@ export declare interface StonecropPluginOptions {
|
|
|
478
284
|
*/
|
|
479
285
|
export declare function validateReferences(): ValidationError[];
|
|
480
286
|
|
|
481
|
-
|
|
482
|
-
* Validation error with path information
|
|
483
|
-
* @public
|
|
484
|
-
*/
|
|
485
|
-
export declare interface ValidationError {
|
|
486
|
-
/** Path to the invalid property */
|
|
487
|
-
path: (string | number)[];
|
|
488
|
-
/** Error message */
|
|
489
|
-
message: string;
|
|
490
|
-
}
|
|
287
|
+
export { ValidationError }
|
|
491
288
|
|
|
492
289
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { readdirSync as O, statSync as x, readFileSync as B } from "node:fs";
|
|
2
2
|
import { join as M } from "node:path";
|
|
3
3
|
import { validateDoctype as R, parseDoctype as k, toPascalCase as A, snakeToCamel as F } from "@stonecrop/schema";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { loadOne as b, object as w, constant as j, lambda as q } from "postgraphile/grafast";
|
|
5
|
+
import { extendSchema as T, gql as I } from "postgraphile/utils";
|
|
6
6
|
import J from "pluralize";
|
|
7
7
|
const u = /* @__PURE__ */ new Map();
|
|
8
|
-
class
|
|
8
|
+
class D extends Error {
|
|
9
9
|
constructor(t, r) {
|
|
10
10
|
const o = r.map((n) => ` ${n.path.join(".")}: ${n.message}`).join(`
|
|
11
11
|
`);
|
|
@@ -34,7 +34,7 @@ function C(e, t) {
|
|
|
34
34
|
t.onError?.(e, [a]);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
throw new
|
|
37
|
+
throw new D(e, [a]);
|
|
38
38
|
}
|
|
39
39
|
const n = R(o);
|
|
40
40
|
if (!n.success) {
|
|
@@ -42,7 +42,7 @@ function C(e, t) {
|
|
|
42
42
|
t.onError?.(e, n.errors);
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
throw new
|
|
45
|
+
throw new D(e, n.errors);
|
|
46
46
|
}
|
|
47
47
|
const c = k(o);
|
|
48
48
|
u.set(c.name, c);
|
|
@@ -55,13 +55,13 @@ function de(e, t = {}) {
|
|
|
55
55
|
t.onError?.(r, c.errors);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
throw new
|
|
58
|
+
throw new D(r, c.errors);
|
|
59
59
|
}
|
|
60
60
|
const i = k(n);
|
|
61
61
|
u.set(i.name, i);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function S(e) {
|
|
65
65
|
return u.get(e);
|
|
66
66
|
}
|
|
67
67
|
function H() {
|
|
@@ -94,18 +94,18 @@ function pe() {
|
|
|
94
94
|
}
|
|
95
95
|
return e;
|
|
96
96
|
}
|
|
97
|
-
const
|
|
97
|
+
const $ = /* @__PURE__ */ new Map();
|
|
98
98
|
function _(e, t) {
|
|
99
|
-
|
|
99
|
+
$.set(e, t);
|
|
100
100
|
}
|
|
101
101
|
function U(e) {
|
|
102
|
-
return
|
|
102
|
+
return $.get(e);
|
|
103
103
|
}
|
|
104
104
|
function ye(e) {
|
|
105
|
-
return
|
|
105
|
+
return $.has(e);
|
|
106
106
|
}
|
|
107
107
|
function me() {
|
|
108
|
-
|
|
108
|
+
$.clear();
|
|
109
109
|
}
|
|
110
110
|
const Q = async (e, t) => {
|
|
111
111
|
const [r] = e, { doctype: o } = t, n = [];
|
|
@@ -180,8 +180,8 @@ function ge() {
|
|
|
180
180
|
}
|
|
181
181
|
const he = (e) => {
|
|
182
182
|
const t = e.inflection?.recordFieldName ?? v, r = e.inflection?.connectionFieldName ?? z, o = e.inflection?.orderByTypeName ?? Y, n = e.inflection?.recordArgName ?? K, c = e.inflection?.recordArgType ?? X;
|
|
183
|
-
return
|
|
184
|
-
typeDefs:
|
|
183
|
+
return T(() => ({
|
|
184
|
+
typeDefs: I`
|
|
185
185
|
type StonecropFieldMeta {
|
|
186
186
|
fieldname: String!
|
|
187
187
|
fieldtype: String!
|
|
@@ -251,15 +251,15 @@ const he = (e) => {
|
|
|
251
251
|
Query: {
|
|
252
252
|
plans: {
|
|
253
253
|
stonecropMeta(i, { $doctype: a }) {
|
|
254
|
-
return
|
|
254
|
+
return q(a, (d) => S(d) ?? null);
|
|
255
255
|
},
|
|
256
256
|
stonecropAllMeta() {
|
|
257
|
-
return
|
|
257
|
+
return j(H());
|
|
258
258
|
},
|
|
259
259
|
stonecropRecord(i, { $doctype: a, $id: d }) {
|
|
260
|
-
return
|
|
260
|
+
return b(w({ doctype: a, id: d }), async (p) => await Promise.all(
|
|
261
261
|
p.map(async (f) => {
|
|
262
|
-
const l =
|
|
262
|
+
const l = S(f.doctype);
|
|
263
263
|
if (!l)
|
|
264
264
|
throw new Error(`Unknown doctype: ${f.doctype}`);
|
|
265
265
|
if (!l.tableName)
|
|
@@ -275,8 +275,8 @@ const he = (e) => {
|
|
|
275
275
|
));
|
|
276
276
|
},
|
|
277
277
|
stonecropRecords(i, { $doctype: a, $filters: d, $orderBy: p, $limit: f, $offset: l }) {
|
|
278
|
-
return
|
|
279
|
-
|
|
278
|
+
return b(
|
|
279
|
+
w({
|
|
280
280
|
doctype: a,
|
|
281
281
|
filters: d,
|
|
282
282
|
orderBy: p,
|
|
@@ -285,12 +285,12 @@ const he = (e) => {
|
|
|
285
285
|
}),
|
|
286
286
|
async (y) => await Promise.all(
|
|
287
287
|
y.map(async (s) => {
|
|
288
|
-
const m =
|
|
288
|
+
const m = S(s.doctype);
|
|
289
289
|
if (!m)
|
|
290
290
|
throw new Error(`Unknown doctype: ${s.doctype}`);
|
|
291
291
|
if (!m.tableName)
|
|
292
292
|
throw new Error(`Doctype ${s.doctype} has no table mapping`);
|
|
293
|
-
const
|
|
293
|
+
const h = te(
|
|
294
294
|
m,
|
|
295
295
|
{
|
|
296
296
|
limit: s.limit,
|
|
@@ -299,15 +299,15 @@ const he = (e) => {
|
|
|
299
299
|
},
|
|
300
300
|
r,
|
|
301
301
|
o
|
|
302
|
-
),
|
|
302
|
+
), N = await e.executor.query(h, {
|
|
303
303
|
limit: s.limit,
|
|
304
304
|
offset: s.offset,
|
|
305
305
|
orderBy: s.orderBy
|
|
306
|
-
}),
|
|
306
|
+
}), g = ne(N, m, r);
|
|
307
307
|
return {
|
|
308
|
-
data:
|
|
308
|
+
data: g,
|
|
309
309
|
doctype: s.doctype,
|
|
310
|
-
count:
|
|
310
|
+
count: g.length
|
|
311
311
|
};
|
|
312
312
|
})
|
|
313
313
|
)
|
|
@@ -318,15 +318,15 @@ const he = (e) => {
|
|
|
318
318
|
Mutation: {
|
|
319
319
|
plans: {
|
|
320
320
|
stonecropAction(i, { $doctype: a, $action: d, $args: p }) {
|
|
321
|
-
return
|
|
322
|
-
|
|
321
|
+
return b(
|
|
322
|
+
w({
|
|
323
323
|
doctype: a,
|
|
324
324
|
action: d,
|
|
325
325
|
actionArgs: p
|
|
326
326
|
}),
|
|
327
327
|
async (f) => await Promise.all(
|
|
328
328
|
f.map(async (l) => {
|
|
329
|
-
const y =
|
|
329
|
+
const y = S(l.doctype);
|
|
330
330
|
if (!y)
|
|
331
331
|
return {
|
|
332
332
|
success: !1,
|
|
@@ -340,21 +340,21 @@ const he = (e) => {
|
|
|
340
340
|
data: null,
|
|
341
341
|
error: `Unknown action: ${l.action} on ${l.doctype}`
|
|
342
342
|
};
|
|
343
|
-
const m =
|
|
344
|
-
if (!
|
|
343
|
+
const m = s.handler, h = U(m);
|
|
344
|
+
if (!h)
|
|
345
345
|
return {
|
|
346
346
|
success: !1,
|
|
347
347
|
data: null,
|
|
348
|
-
error: `Handler not registered: ${
|
|
348
|
+
error: `Handler not registered: ${m}`
|
|
349
349
|
};
|
|
350
|
-
const
|
|
350
|
+
const N = {
|
|
351
351
|
doctype: y,
|
|
352
352
|
executor: e.executor
|
|
353
353
|
};
|
|
354
354
|
try {
|
|
355
355
|
return {
|
|
356
356
|
success: !0,
|
|
357
|
-
data: await
|
|
357
|
+
data: await h(l.actionArgs ?? [], N),
|
|
358
358
|
error: null
|
|
359
359
|
};
|
|
360
360
|
} catch (g) {
|
|
@@ -427,7 +427,7 @@ function ne(e, t, r) {
|
|
|
427
427
|
return e[o]?.nodes ?? [];
|
|
428
428
|
}
|
|
429
429
|
export {
|
|
430
|
-
|
|
430
|
+
D as DoctypeValidationError,
|
|
431
431
|
Z as RELATION_FIELDTYPES,
|
|
432
432
|
te as buildListQuery,
|
|
433
433
|
ee as buildRecordQuery,
|
|
@@ -437,10 +437,12 @@ export {
|
|
|
437
437
|
he as createStonecropPlugin,
|
|
438
438
|
z as defaultConnectionFieldName,
|
|
439
439
|
Y as defaultOrderByTypeName,
|
|
440
|
+
K as defaultRecordArgName,
|
|
441
|
+
X as defaultRecordArgType,
|
|
440
442
|
v as defaultRecordFieldName,
|
|
441
443
|
H as getAllMeta,
|
|
442
444
|
U as getHandler,
|
|
443
|
-
|
|
445
|
+
S as getMeta,
|
|
444
446
|
ye as hasHandler,
|
|
445
447
|
fe as hasMeta,
|
|
446
448
|
L as loadDoctypes,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/registry/doctypes.ts","../src/registry/actions.ts","../src/plugin/postgraphile.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '@stonecrop/schema'\nimport type { DoctypeMeta, ValidationError } from '@stonecrop/schema'\n\nconst doctypeRegistry: Map<string, DoctypeMeta> = new Map()\n\n/**\n * Error thrown when a doctype definition fails validation\n * @public\n */\nexport class DoctypeValidationError extends Error {\n\tconstructor(\n\t\t/** File path or name where the validation error occurred */\n\t\tpublic readonly file: string,\n\t\t/** List of validation errors found */\n\t\tpublic readonly errors: ValidationError[]\n\t) {\n\t\tconst errorMessages = errors.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\\n')\n\t\tsuper(`Invalid doctype definition in ${file}:\\n${errorMessages}`)\n\t\tthis.name = 'DoctypeValidationError'\n\t}\n}\n\n/**\n * Options for loading doctype definitions\n * @public\n */\nexport interface LoadDoctypesOptions {\n\t/** Continue loading other files if one fails validation */\n\tcontinueOnError?: boolean\n\t/** Callback for validation errors when continueOnError is true */\n\tonError?: (file: string, errors: ValidationError[]) => void\n}\n\n/**\n * Load doctype definitions from a directory of JSON files\n * @param dir - Directory path containing doctype JSON files\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypes(dir: string, options: LoadDoctypesOptions = {}): void {\n\tconst entries = readdirSync(dir)\n\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry)\n\t\tconst stat = statSync(fullPath)\n\n\t\tif (stat.isDirectory()) {\n\t\t\tloadDoctypes(fullPath, options)\n\t\t} else if (entry.endsWith('.json')) {\n\t\t\tloadDoctypeFile(fullPath, options)\n\t\t}\n\t}\n}\n\n/**\n * Load and validate a single doctype file\n */\nfunction loadDoctypeFile(filePath: string, options: LoadDoctypesOptions): void {\n\tconst content = readFileSync(filePath, 'utf-8')\n\tlet data: unknown\n\n\ttry {\n\t\tdata = JSON.parse(content)\n\t} catch (err) {\n\t\tconst parseError: ValidationError = {\n\t\t\tpath: [],\n\t\t\tmessage: `Invalid JSON: ${err instanceof Error ? err.message : String(err)}`,\n\t\t}\n\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, [parseError])\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, [parseError])\n\t}\n\n\tconst result = validateDoctype(data)\n\n\tif (!result.success) {\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, result.errors)\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, result.errors)\n\t}\n\n\tconst doctype = parseDoctype(data)\n\tdoctypeRegistry.set(doctype.name, doctype)\n}\n\n/**\n * Load doctypes from an object (for programmatic use)\n * @param doctypes - Object mapping doctype names to doctype definitions\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypesFromObject(doctypes: Record<string, unknown>, options: LoadDoctypesOptions = {}): void {\n\tfor (const [name, data] of Object.entries(doctypes)) {\n\t\tconst withName = { ...(data as object), name }\n\t\tconst result = validateDoctype(withName)\n\n\t\tif (!result.success) {\n\t\t\tif (options.continueOnError) {\n\t\t\t\toptions.onError?.(name, result.errors)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthrow new DoctypeValidationError(name, result.errors)\n\t\t}\n\n\t\tconst doctype = parseDoctype(withName)\n\t\tdoctypeRegistry.set(doctype.name, doctype)\n\t}\n}\n\n/**\n * Get a doctype by name\n * @param name - Name of the doctype to retrieve\n * @public\n */\nexport function getMeta(name: string): DoctypeMeta | undefined {\n\treturn doctypeRegistry.get(name)\n}\n\n/**\n * Get all loaded doctypes\n * @public\n */\nexport function getAllMeta(): DoctypeMeta[] {\n\treturn Array.from(doctypeRegistry.values())\n}\n\n/**\n * Check if a doctype is registered\n * @param name - Name of the doctype to check\n * @public\n */\nexport function hasMeta(name: string): boolean {\n\treturn doctypeRegistry.has(name)\n}\n\n/**\n * Clear all registered doctypes\n * @public\n */\nexport function clearRegistry(): void {\n\tdoctypeRegistry.clear()\n}\n\n/**\n * Validate cross-doctype references (Link fields, inherits, etc.)\n * Call after all doctypes are loaded.\n * @public\n */\nexport function validateReferences(): ValidationError[] {\n\tconst errors: ValidationError[] = []\n\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\t// Check inherits reference\n\t\tif (doctype.inherits && !doctypeRegistry.has(doctype.inherits)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'inherits'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.inherits}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check listDoctype reference\n\t\tif (doctype.listDoctype && !doctypeRegistry.has(doctype.listDoctype)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'listDoctype'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.listDoctype}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check parentDoctype reference\n\t\tif (doctype.parentDoctype && !doctypeRegistry.has(doctype.parentDoctype)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'parentDoctype'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.parentDoctype}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check Link field targets\n\t\tfor (const field of doctype.fields) {\n\t\t\tif (field.fieldtype === 'Link' && typeof field.options === 'string') {\n\t\t\t\tif (!doctypeRegistry.has(field.options)) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tpath: [doctype.name, 'fields', field.fieldname, 'options'],\n\t\t\t\t\t\tmessage: `Link references unknown doctype: ${field.options}`,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn errors\n}\n","import type { DoctypeMeta } from '@stonecrop/schema'\nimport type { ActionHandler, ActionContext } from '../types'\n\nconst handlerRegistry: Map<string, ActionHandler> = new Map()\n\n/**\n * Register an action handler\n * @param name - Unique name for the action handler\n * @param handler - Action handler function to register\n * @public\n */\nexport function registerHandler(name: string, handler: ActionHandler): void {\n\thandlerRegistry.set(name, handler)\n}\n\n/**\n * Get a registered handler by name\n * @param name - Name of the action handler to retrieve\n * @public\n */\nexport function getHandler(name: string): ActionHandler | undefined {\n\treturn handlerRegistry.get(name)\n}\n\n/**\n * Check if a handler is registered\n * @param name - Name of the action handler to check\n * @public\n */\nexport function hasHandler(name: string): boolean {\n\treturn handlerRegistry.has(name)\n}\n\n/**\n * Clear all registered handlers\n * @public\n */\nexport function clearHandlers(): void {\n\thandlerRegistry.clear()\n}\n\n// =============================================================================\n// Built-in Handlers\n// =============================================================================\n\n/**\n * Validate that all required fields are present in a record\n */\nconst validateRequiredFields: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst missing: string[] = []\n\tfor (const field of doctype.fields) {\n\t\tif (field.required && (record[field.fieldname] === undefined || record[field.fieldname] === null)) {\n\t\t\tmissing.push(field.label ?? field.fieldname)\n\t\t}\n\t}\n\n\tif (missing.length > 0) {\n\t\tthrow new Error(`Missing required fields: ${missing.join(', ')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate field types match expected types\n */\nconst validateFieldTypes: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst errors: string[] = []\n\n\tfor (const field of doctype.fields) {\n\t\tconst value = record[field.fieldname]\n\t\tif (value === undefined || value === null) continue\n\n\t\tconst error = validateFieldValue(field.fieldname, value, field.fieldtype)\n\t\tif (error) errors.push(error)\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`Field type validation failed:\\n${errors.join('\\n')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate a single field value against its expected type\n */\nfunction validateFieldValue(fieldname: string, value: unknown, fieldtype: string): string | null {\n\tswitch (fieldtype) {\n\t\tcase 'Int':\n\t\t\tif (typeof value !== 'number' || !Number.isInteger(value)) {\n\t\t\t\treturn `${fieldname}: expected integer, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Float':\n\t\tcase 'Decimal':\n\t\tcase 'Currency':\n\t\tcase 'Quantity':\n\t\t\tif (typeof value !== 'number' && typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected number, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Check':\n\t\t\tif (typeof value !== 'boolean') {\n\t\t\t\treturn `${fieldname}: expected boolean, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Data':\n\t\tcase 'Text':\n\t\tcase 'Code':\n\t\tcase 'Link':\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected string, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Date':\n\t\tcase 'Time':\n\t\tcase 'Datetime':\n\t\t\tif (typeof value !== 'string' && !(value instanceof Date)) {\n\t\t\t\treturn `${fieldname}: expected date string or Date, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'JSON':\n\t\t\tif (typeof value !== 'object') {\n\t\t\t\treturn `${fieldname}: expected object, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Table':\n\t\t\tif (!Array.isArray(value)) {\n\t\t\t\treturn `${fieldname}: expected array, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn null\n}\n\n/**\n * No-op handler for testing or placeholder actions\n */\nconst noop: ActionHandler = async () => {\n\treturn { ok: true }\n}\n\n/**\n * Built-in handlers available for registration\n * @public\n */\nexport const builtinHandlers: Record<string, ActionHandler> = {\n\tvalidateRequiredFields,\n\tvalidateFieldTypes,\n\tnoop,\n}\n\n/**\n * Register all built-in handlers\n * @public\n */\nexport function registerBuiltinHandlers(): void {\n\tfor (const [name, handler] of Object.entries(builtinHandlers)) {\n\t\tregisterHandler(name, handler)\n\t}\n}\n","import { extendSchema, gql } from 'postgraphile/utils'\nimport { constant, lambda, object, loadOne } from 'postgraphile/grafast'\nimport { GraphileConfig } from 'postgraphile/graphile-build'\n\nimport pluralize from 'pluralize'\n\nimport { snakeToCamel, toPascalCase } from '@stonecrop/schema'\nimport { getHandler } from '../registry/actions'\nimport { getMeta, getAllMeta } from '../registry/doctypes'\nimport type { DoctypeMeta } from '@stonecrop/schema'\nimport type { ActionContext, GraphQLExecutor } from '../types'\n\n/**\n * Inflection callbacks for mapping table names to GraphQL query field names.\n * Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).\n *\n * Defaults match the PostGraphile Amber preset conventions.\n * @public\n */\nexport interface StonecropInflectionConfig {\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a single record by ID.\n\t * @example Amber default: \"sales_orders\" → \"salesOrderById\"\n\t * @example V4 preset: \"sales_orders\" → \"salesOrderByRowId\"\n\t */\n\trecordFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a list/connection.\n\t * @example Amber default: \"sales_orders\" → \"allSalesOrders\"\n\t * @example SimplifyInflection: \"sales_orders\" → \"salesOrders\"\n\t */\n\tconnectionFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL OrderBy enum type name.\n\t * @example Amber default: \"sales_orders\" → \"SalesOrdersOrderBy\"\n\t */\n\torderByTypeName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL argument name used to look up a record by PK.\n\t * @example Amber default (Relay Global ID): \"sales_orders\" → \"id\"\n\t * @example row_id PK: \"sales_orders\" → \"rowId\"\n\t */\n\trecordArgName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL variable type for the PK argument.\n\t * @example Default UUID PK: \"sales_orders\" → \"UUID!\"\n\t * @example Integer PK: \"sales_orders\" → \"Int!\"\n\t */\n\trecordArgType?: (tableName: string) => string\n}\n\n/**\n * Options for creating a Stonecrop PostGraphile plugin\n * @public\n */\nexport interface StonecropPluginOptions {\n\t/** GraphQL executor for running queries/mutations */\n\texecutor: GraphQLExecutor\n\n\t/**\n\t * Override inflection conventions for mapping table names to GraphQL field names.\n\t * Defaults to PostGraphile Amber preset conventions.\n\t */\n\tinflection?: StonecropInflectionConfig\n}\n\n/**\n * Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality\n * @param options - Plugin configuration options\n * @returns A PostGraphile plugin\n * @public\n */\nexport const createStonecropPlugin = (options: StonecropPluginOptions): GraphileConfig.Plugin => {\n\t// Resolve inflection callbacks with Amber defaults\n\tconst recordFieldName = options.inflection?.recordFieldName ?? defaultRecordFieldName\n\tconst connectionFieldName = options.inflection?.connectionFieldName ?? defaultConnectionFieldName\n\tconst orderByTypeName = options.inflection?.orderByTypeName ?? defaultOrderByTypeName\n\tconst recordArgName = options.inflection?.recordArgName ?? defaultRecordArgName\n\tconst recordArgType = options.inflection?.recordArgType ?? defaultRecordArgType\n\n\treturn extendSchema(() => {\n\t\treturn {\n\t\t\ttypeDefs: gql`\n\t\t\t\ttype StonecropFieldMeta {\n\t\t\t\t\tfieldname: String!\n\t\t\t\t\tfieldtype: String!\n\t\t\t\t\tlabel: String\n\t\t\t\t\trequired: Boolean\n\t\t\t\t\toptions: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionDefinition {\n\t\t\t\t\tlabel: String!\n\t\t\t\t\thandler: String!\n\t\t\t\t\trequiredFields: [String!]\n\t\t\t\t\tallowedStates: [String!]\n\t\t\t\t\tconfirm: Boolean\n\t\t\t\t\targs: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowMeta {\n\t\t\t\t\tstates: [String!]\n\t\t\t\t\tactions: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropDoctypeMeta {\n\t\t\t\t\tname: String!\n\t\t\t\t\ttableName: String\n\t\t\t\t\tfields: [StonecropFieldMeta!]!\n\t\t\t\t\tworkflow: StonecropWorkflowMeta\n\t\t\t\t\tlistDoctype: String\n\t\t\t\t\tparentDoctype: String\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordResult {\n\t\t\t\t\tdata: JSON\n\t\t\t\t\tdoctype: String!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordsResult {\n\t\t\t\t\tdata: [JSON!]!\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tcount: Int!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionResult {\n\t\t\t\t\tsuccess: Boolean!\n\t\t\t\t\tdata: JSON\n\t\t\t\t\terror: String\n\t\t\t\t}\n\n\t\t\t\textend type Query {\n\t\t\t\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\t\t\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\t\t\t\tstonecropRecord(doctype: String!, id: String!): StonecropRecordResult\n\t\t\t\t\tstonecropRecords(\n\t\t\t\t\t\tdoctype: String!\n\t\t\t\t\t\tfilters: JSON\n\t\t\t\t\t\torderBy: String\n\t\t\t\t\t\tlimit: Int\n\t\t\t\t\t\toffset: Int\n\t\t\t\t\t): StonecropRecordsResult\n\t\t\t\t}\n\n\t\t\t\textend type Mutation {\n\t\t\t\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t\t\t\t}\n\t\t\t`,\n\n\t\t\tobjects: {\n\t\t\t\tQuery: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropMeta(_: any, { $doctype }: any) {\n\t\t\t\t\t\t\treturn lambda($doctype, (doctype: unknown) => {\n\t\t\t\t\t\t\t\tconst meta = getMeta(doctype as string)\n\t\t\t\t\t\t\t\treturn meta ?? null\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropAllMeta() {\n\t\t\t\t\t\t\treturn constant(getAllMeta())\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecord(_: any, { $doctype, $id }: any) {\n\t\t\t\t\t\t\treturn loadOne(object({ doctype: $doctype, id: $id }), async (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tconst query = buildRecordQuery(meta, recordFieldName, recordArgName, recordArgType)\n\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t[recordArgName(meta.tableName!)]: spec.id,\n\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\tdata: extractSingleResult(result, meta, recordFieldName),\n\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecords(_: any, { $doctype, $filters, $orderBy, $limit, $offset }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\tfilters: $filters,\n\t\t\t\t\t\t\t\t\torderBy: $orderBy,\n\t\t\t\t\t\t\t\t\tlimit: $limit,\n\t\t\t\t\t\t\t\t\toffset: $offset,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildListQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tconnectionFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\torderByTypeName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\tconst data = extractListResult(result, meta, connectionFieldName)\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\tcount: data.length,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\n\t\t\t\tMutation: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropAction(_: any, { $doctype, $action, $args: $actionArgs }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\taction: $action,\n\t\t\t\t\t\t\t\t\tactionArgs: $actionArgs,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown doctype: ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionDef = meta.workflow?.actions?.[spec.action]\n\t\t\t\t\t\t\t\t\t\t\tif (!actionDef) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown action: ${spec.action} on ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst handler = getHandler(actionDef.handler)\n\t\t\t\t\t\t\t\t\t\t\tif (!handler) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Handler not registered: ${actionDef.handler}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionContext: ActionContext = {\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: meta,\n\t\t\t\t\t\t\t\t\t\t\t\texecutor: options.executor,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\tconst result = await handler(spec.actionArgs ?? [], actionContext)\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: result,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t})\n}\n\n// =============================================================================\n// Inflection helpers — default to PostGraphile Amber preset conventions\n// Uses `pluralize` for proper English singularization (handles irregular\n// plurals like statuses→status, categories→category, addresses→address).\n// snakeToCamel / toPascalCase are imported from @stonecrop/schema.\n// =============================================================================\n\n/**\n * Amber default: sales_orders → salesOrderById\n * Uses `pluralize` for proper singularization of irregular plurals.\n * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.\n * @public\n */\nfunction defaultRecordFieldName(tableName: string): string {\n\tconst singular = pluralize.singular(tableName)\n\treturn `${snakeToCamel(singular)}ById`\n}\n\n/**\n * Amber default: sales_orders → allSalesOrders\n * @public\n */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/**\n * Amber default: sales_orders → SalesOrdersOrderBy\n * @public\n */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\n}\n\n/**\n * Default PK argument name: 'id' (standard Relay Global ID pattern).\n * Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;\n * PostGraphile Amber generates `rowId: UUID!` for those fields.\n * @internal\n */\nfunction defaultRecordArgName(_tableName: string): string {\n\treturn 'id'\n}\n\n/**\n * Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).\n * Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs\n * such as integer serials or Relay Global IDs ('ID!').\n * @internal\n */\nfunction defaultRecordArgType(_tableName: string): string {\n\treturn 'UUID!'\n}\n\n// =============================================================================\n// Query builders — generate GraphQL queries to send to the underlying schema\n// =============================================================================\n\n/**\n * Fieldtypes that map to GraphQL object/connection types and require sub-selections.\n * These fields are excluded from generated query field selections.\n * @public\n */\nconst RELATION_FIELDTYPES = new Set(['Link', 'Doctype'])\n\n/**\n * Filter fields to only those directly queryable as scalars, excluding Link and Doctype\n * relation fields that require GraphQL sub-selections.\n * @public\n */\nfunction queryableFieldNames(meta: DoctypeMeta): string {\n\treturn meta.fields\n\t\t.filter(f => !RELATION_FIELDTYPES.has(f.fieldtype))\n\t\t.map(f => f.fieldname)\n\t\t.join('\\n ')\n}\n\n/**\n * Build a GraphQL query to fetch a single record by ID.\n * Excludes Link and Doctype relation fields from the selection set.\n * The PK argument name and type are configurable via `StonecropInflectionConfig.recordArgName`\n * and `StonecropInflectionConfig.recordArgType` to match the target schema's conventions\n * (e.g. `rowId: UUID!` for PostGraphile Amber with row_id columns).\n * @public\n */\nfunction buildRecordQuery(\n\tmeta: DoctypeMeta,\n\trecordFieldName: (t: string) => string,\n\trecordArgName: (t: string) => string,\n\trecordArgType: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst queryName = recordFieldName(meta.tableName!)\n\tconst argName = recordArgName(meta.tableName!)\n\tconst argType = recordArgType(meta.tableName!)\n\n\treturn `\n\t\tquery GetRecord($${argName}: ${argType}) {\n\t\t\t${queryName}(${argName}: $${argName}) {\n\t\t\t\t${fieldNames}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Build a GraphQL connection query to fetch a list of records.\n * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,\n * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.\n * Excludes Link and Doctype relation fields from the selection set.\n * @public\n */\nfunction buildListQuery(\n\tmeta: DoctypeMeta,\n\targs: { limit?: number; offset?: number; orderBy?: string },\n\tconnectionFieldName: (t: string) => string,\n\torderByTypeName: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst orderByType = orderByTypeName(meta.tableName!)\n\n\tconst varDecls: string[] = []\n\tconst queryArgs: string[] = []\n\tif (args.limit) {\n\t\tvarDecls.push('$limit: Int')\n\t\tqueryArgs.push(`first: $limit`)\n\t}\n\tif (args.offset) {\n\t\tvarDecls.push('$offset: Int')\n\t\tqueryArgs.push(`offset: $offset`)\n\t}\n\tif (args.orderBy) {\n\t\tvarDecls.push(`$orderBy: [${orderByType}!]`)\n\t\tqueryArgs.push(`orderBy: $orderBy`)\n\t}\n\n\tconst varStr = varDecls.length > 0 ? `(${varDecls.join(', ')})` : ''\n\tconst argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : ''\n\n\treturn `\n\t\tquery GetRecords${varStr} {\n\t\t\t${connectionName}${argsStr} {\n\t\t\t\tnodes {\n\t\t\t\t${fieldNames}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Extract a single record from a PostGraphile query result using the record field name.\n * @internal\n */\nfunction extractSingleResult(result: unknown, meta: DoctypeMeta, recordFieldName: (t: string) => string): unknown {\n\tconst queryName = recordFieldName(meta.tableName!)\n\treturn (result as Record<string, unknown>)[queryName]\n}\n\n/**\n * Extract the list of nodes from a PostGraphile connection query result.\n * Returns an empty array if the connection field is absent.\n * @internal\n */\nfunction extractListResult(result: unknown, meta: DoctypeMeta, connectionFieldName: (t: string) => string): unknown[] {\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst connection = (result as Record<string, unknown>)[connectionName] as {\n\t\tnodes: unknown[]\n\t}\n\treturn connection?.nodes ?? []\n}\n\n// =============================================================================\n// Exported for testing and advanced usage\n// =============================================================================\n\nexport {\n\tdefaultRecordFieldName,\n\tdefaultConnectionFieldName,\n\tdefaultOrderByTypeName,\n\tdefaultRecordArgName,\n\tdefaultRecordArgType,\n\tbuildRecordQuery,\n\tbuildListQuery,\n\tqueryableFieldNames,\n\tRELATION_FIELDTYPES,\n\textractSingleResult,\n\textractListResult,\n}\n"],"names":["doctypeRegistry","DoctypeValidationError","file","errors","errorMessages","e","loadDoctypes","dir","options","entries","readdirSync","entry","fullPath","join","statSync","loadDoctypeFile","filePath","content","readFileSync","data","err","parseError","result","validateDoctype","doctype","parseDoctype","loadDoctypesFromObject","doctypes","name","withName","getMeta","getAllMeta","hasMeta","clearRegistry","validateReferences","field","handlerRegistry","registerHandler","handler","getHandler","hasHandler","clearHandlers","validateRequiredFields","args","context","record","missing","validateFieldTypes","value","error","validateFieldValue","fieldname","fieldtype","noop","builtinHandlers","registerBuiltinHandlers","createStonecropPlugin","recordFieldName","defaultRecordFieldName","connectionFieldName","defaultConnectionFieldName","orderByTypeName","defaultOrderByTypeName","recordArgName","defaultRecordArgName","recordArgType","defaultRecordArgType","extendSchema","gql","_","$doctype","lambda","constant","$id","loadOne","object","specs","spec","meta","query","buildRecordQuery","extractSingleResult","$filters","$orderBy","$limit","$offset","buildListQuery","extractListResult","$action","$actionArgs","actionDef","actionContext","tableName","singular","pluralize","snakeToCamel","toPascalCase","_tableName","RELATION_FIELDTYPES","queryableFieldNames","f","fieldNames","queryName","argName","argType","connectionName","orderByType","varDecls","queryArgs","varStr","argsStr"],"mappings":";;;;;;AAMA,MAAMA,wBAAgD,IAAA;AAM/C,MAAMC,UAA+B,MAAM;AAAA,EACjD,YAEiBC,GAEAC,GACf;AACD,UAAMC,IAAgBD,EAAO,IAAI,CAAAE,MAAK,KAAKA,EAAE,KAAK,KAAK,GAAG,CAAC,KAAKA,EAAE,OAAO,EAAE,EAAE,KAAK;AAAA,CAAI;AACtF,UAAM,iCAAiCH,CAAI;AAAA,EAAME,CAAa,EAAE,GALhD,KAAA,OAAAF,GAEA,KAAA,SAAAC,GAIhB,KAAK,OAAO;AAAA,EACb;AACD;AAmBO,SAASG,EAAaC,GAAaC,IAA+B,IAAU;AAClF,QAAMC,IAAUC,EAAYH,CAAG;AAE/B,aAAWI,KAASF,GAAS;AAC5B,UAAMG,IAAWC,EAAKN,GAAKI,CAAK;AAGhC,IAFaG,EAASF,CAAQ,EAErB,gBACRN,EAAaM,G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AAS,IAAIC,CAAO,MAAMA,CAAO;AAAA,MAChCF,CAAU;AAAA;AAAA;AAAA;AAIhB;AASA,SAASf,GACRR,GACAnC,GACAgB,GACAE,GACS;AACT,QAAMwC,IAAaF,EAAoBrB,CAAI,GACrC2B,IAAiB9C,EAAoBmB,EAAK,SAAU,GACpD4B,IAAc7C,EAAgBiB,EAAK,SAAU,GAE7C6B,IAAqB,CAAA,GACrBC,IAAsB,CAAA;AAC5B,EAAIjE,EAAK,UACRgE,EAAS,KAAK,aAAa,GAC3BC,EAAU,KAAK,eAAe,IAE3BjE,EAAK,WACRgE,EAAS,KAAK,cAAc,GAC5BC,EAAU,KAAK,iBAAiB,IAE7BjE,EAAK,YACRgE,EAAS,KAAK,cAAcD,CAAW,IAAI,GAC3CE,EAAU,KAAK,mBAAmB;AAGnC,QAAMC,IAASF,EAAS,SAAS,IAAI,IAAIA,EAAS,KAAK,IAAI,CAAC,MAAM,IAC5DG,IAAUF,EAAU,SAAS,IAAI,IAAIA,EAAU,KAAK,IAAI,CAAC,MAAM;AAErE,SAAO;AAAA,oBACYC,CAAM;AAAA,KACrBJ,CAAc,GAAGK,CAAO;AAAA;AAAA,MAEvBT,CAAU;AAAA;AAAA;AAAA;AAAA;AAKhB;AAMA,SAASpB,GAAoB3D,GAAiBwD,GAAmBrB,GAAiD;AACjH,QAAM6C,IAAY7C,EAAgBqB,EAAK,SAAU;AACjD,SAAQxD,EAAmCgF,CAAS;AACrD;AAOA,SAASf,GAAkBjE,GAAiBwD,GAAmBnB,GAAuD;AACrH,QAAM8C,IAAiB9C,EAAoBmB,EAAK,SAAU;AAI1D,SAHoBxD,EAAmCmF,CAAc,GAGlD,SAAS,CAAA;AAC7B;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/registry/doctypes.ts","../src/registry/actions.ts","../src/plugin/postgraphile.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '@stonecrop/schema'\nimport type { DoctypeMeta, ValidationError } from '@stonecrop/schema'\n\nconst doctypeRegistry: Map<string, DoctypeMeta> = new Map()\n\n/**\n * Error thrown when a doctype definition fails validation\n * @public\n */\nexport class DoctypeValidationError extends Error {\n\tconstructor(\n\t\t/** File path or name where the validation error occurred */\n\t\tpublic readonly file: string,\n\t\t/** List of validation errors found */\n\t\tpublic readonly errors: ValidationError[]\n\t) {\n\t\tconst errorMessages = errors.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\\n')\n\t\tsuper(`Invalid doctype definition in ${file}:\\n${errorMessages}`)\n\t\tthis.name = 'DoctypeValidationError'\n\t}\n}\n\n/**\n * Options for loading doctype definitions\n * @public\n */\nexport interface LoadDoctypesOptions {\n\t/** Continue loading other files if one fails validation */\n\tcontinueOnError?: boolean\n\t/** Callback for validation errors when continueOnError is true */\n\tonError?: (file: string, errors: ValidationError[]) => void\n}\n\n/**\n * Load doctype definitions from a directory of JSON files\n * @param dir - Directory path containing doctype JSON files\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypes(dir: string, options: LoadDoctypesOptions = {}): void {\n\tconst entries = readdirSync(dir)\n\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry)\n\t\tconst stat = statSync(fullPath)\n\n\t\tif (stat.isDirectory()) {\n\t\t\tloadDoctypes(fullPath, options)\n\t\t} else if (entry.endsWith('.json')) {\n\t\t\tloadDoctypeFile(fullPath, options)\n\t\t}\n\t}\n}\n\n/**\n * Load and validate a single doctype file\n */\nfunction loadDoctypeFile(filePath: string, options: LoadDoctypesOptions): void {\n\tconst content = readFileSync(filePath, 'utf-8')\n\tlet data: unknown\n\n\ttry {\n\t\tdata = JSON.parse(content)\n\t} catch (err) {\n\t\tconst parseError: ValidationError = {\n\t\t\tpath: [],\n\t\t\tmessage: `Invalid JSON: ${err instanceof Error ? err.message : String(err)}`,\n\t\t}\n\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, [parseError])\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, [parseError])\n\t}\n\n\tconst result = validateDoctype(data)\n\n\tif (!result.success) {\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, result.errors)\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, result.errors)\n\t}\n\n\tconst doctype = parseDoctype(data)\n\tdoctypeRegistry.set(doctype.name, doctype)\n}\n\n/**\n * Load doctypes from an object (for programmatic use)\n * @param doctypes - Object mapping doctype names to doctype definitions\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypesFromObject(doctypes: Record<string, unknown>, options: LoadDoctypesOptions = {}): void {\n\tfor (const [name, data] of Object.entries(doctypes)) {\n\t\tconst withName = { ...(data as object), name }\n\t\tconst result = validateDoctype(withName)\n\n\t\tif (!result.success) {\n\t\t\tif (options.continueOnError) {\n\t\t\t\toptions.onError?.(name, result.errors)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthrow new DoctypeValidationError(name, result.errors)\n\t\t}\n\n\t\tconst doctype = parseDoctype(withName)\n\t\tdoctypeRegistry.set(doctype.name, doctype)\n\t}\n}\n\n/**\n * Get a doctype by name\n * @param name - Name of the doctype to retrieve\n * @public\n */\nexport function getMeta(name: string): DoctypeMeta | undefined {\n\treturn doctypeRegistry.get(name)\n}\n\n/**\n * Get all loaded doctypes\n * @public\n */\nexport function getAllMeta(): DoctypeMeta[] {\n\treturn Array.from(doctypeRegistry.values())\n}\n\n/**\n * Check if a doctype is registered\n * @param name - Name of the doctype to check\n * @public\n */\nexport function hasMeta(name: string): boolean {\n\treturn doctypeRegistry.has(name)\n}\n\n/**\n * Clear all registered doctypes\n * @public\n */\nexport function clearRegistry(): void {\n\tdoctypeRegistry.clear()\n}\n\n/**\n * Validate cross-doctype references (Link fields, inherits, etc.)\n * Call after all doctypes are loaded.\n * @public\n */\nexport function validateReferences(): ValidationError[] {\n\tconst errors: ValidationError[] = []\n\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\t// Check inherits reference\n\t\tif (doctype.inherits && !doctypeRegistry.has(doctype.inherits)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'inherits'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.inherits}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check listDoctype reference\n\t\tif (doctype.listDoctype && !doctypeRegistry.has(doctype.listDoctype)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'listDoctype'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.listDoctype}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check parentDoctype reference\n\t\tif (doctype.parentDoctype && !doctypeRegistry.has(doctype.parentDoctype)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'parentDoctype'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.parentDoctype}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check Link field targets\n\t\tfor (const field of doctype.fields) {\n\t\t\tif (field.fieldtype === 'Link' && typeof field.options === 'string') {\n\t\t\t\tif (!doctypeRegistry.has(field.options)) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tpath: [doctype.name, 'fields', field.fieldname, 'options'],\n\t\t\t\t\t\tmessage: `Link references unknown doctype: ${field.options}`,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn errors\n}\n","import type { DoctypeMeta } from '@stonecrop/schema'\nimport type { ActionHandler, ActionContext } from '../types'\n\nconst handlerRegistry: Map<string, ActionHandler> = new Map()\n\n/**\n * Register an action handler\n * @param name - Unique name for the action handler\n * @param handler - Action handler function to register\n * @public\n */\nexport function registerHandler(name: string, handler: ActionHandler): void {\n\thandlerRegistry.set(name, handler)\n}\n\n/**\n * Get a registered handler by name\n * @param name - Name of the action handler to retrieve\n * @public\n */\nexport function getHandler(name: string): ActionHandler | undefined {\n\treturn handlerRegistry.get(name)\n}\n\n/**\n * Check if a handler is registered\n * @param name - Name of the action handler to check\n * @public\n */\nexport function hasHandler(name: string): boolean {\n\treturn handlerRegistry.has(name)\n}\n\n/**\n * Clear all registered handlers\n * @public\n */\nexport function clearHandlers(): void {\n\thandlerRegistry.clear()\n}\n\n// =============================================================================\n// Built-in Handlers\n// =============================================================================\n\n/**\n * Validate that all required fields are present in a record\n */\nconst validateRequiredFields: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst missing: string[] = []\n\tfor (const field of doctype.fields) {\n\t\tif (field.required && (record[field.fieldname] === undefined || record[field.fieldname] === null)) {\n\t\t\tmissing.push(field.label ?? field.fieldname)\n\t\t}\n\t}\n\n\tif (missing.length > 0) {\n\t\tthrow new Error(`Missing required fields: ${missing.join(', ')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate field types match expected types\n */\nconst validateFieldTypes: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst errors: string[] = []\n\n\tfor (const field of doctype.fields) {\n\t\tconst value = record[field.fieldname]\n\t\tif (value === undefined || value === null) continue\n\n\t\tconst error = validateFieldValue(field.fieldname, value, field.fieldtype)\n\t\tif (error) errors.push(error)\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`Field type validation failed:\\n${errors.join('\\n')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate a single field value against its expected type\n */\nfunction validateFieldValue(fieldname: string, value: unknown, fieldtype: string): string | null {\n\tswitch (fieldtype) {\n\t\tcase 'Int':\n\t\t\tif (typeof value !== 'number' || !Number.isInteger(value)) {\n\t\t\t\treturn `${fieldname}: expected integer, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Float':\n\t\tcase 'Decimal':\n\t\tcase 'Currency':\n\t\tcase 'Quantity':\n\t\t\tif (typeof value !== 'number' && typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected number, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Check':\n\t\t\tif (typeof value !== 'boolean') {\n\t\t\t\treturn `${fieldname}: expected boolean, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Data':\n\t\tcase 'Text':\n\t\tcase 'Code':\n\t\tcase 'Link':\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected string, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Date':\n\t\tcase 'Time':\n\t\tcase 'Datetime':\n\t\t\tif (typeof value !== 'string' && !(value instanceof Date)) {\n\t\t\t\treturn `${fieldname}: expected date string or Date, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'JSON':\n\t\t\tif (typeof value !== 'object') {\n\t\t\t\treturn `${fieldname}: expected object, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Table':\n\t\t\tif (!Array.isArray(value)) {\n\t\t\t\treturn `${fieldname}: expected array, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn null\n}\n\n/**\n * No-op handler for testing or placeholder actions\n */\nconst noop: ActionHandler = async () => {\n\treturn { ok: true }\n}\n\n/**\n * Built-in handlers available for registration\n * @public\n */\nexport const builtinHandlers: Record<string, ActionHandler> = {\n\tvalidateRequiredFields,\n\tvalidateFieldTypes,\n\tnoop,\n}\n\n/**\n * Register all built-in handlers\n * @public\n */\nexport function registerBuiltinHandlers(): void {\n\tfor (const [name, handler] of Object.entries(builtinHandlers)) {\n\t\tregisterHandler(name, handler)\n\t}\n}\n","import type { DoctypeMeta } from '@stonecrop/schema'\nimport { snakeToCamel, toPascalCase } from '@stonecrop/schema'\nimport { constant, lambda, object, loadOne } from 'postgraphile/grafast'\nimport { GraphileConfig } from 'postgraphile/graphile-build'\nimport { extendSchema, gql } from 'postgraphile/utils'\nimport pluralize from 'pluralize'\n\nimport { getHandler, registerHandler } from '../registry/actions'\nimport { getMeta, getAllMeta } from '../registry/doctypes'\nimport type { ActionContext, GraphQLExecutor } from '../types'\n\n/**\n * Inflection callbacks for mapping table names to GraphQL query field names.\n * Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).\n *\n * Defaults match the PostGraphile Amber preset conventions.\n * @public\n */\nexport interface StonecropInflectionConfig {\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a single record by ID.\n\t * @example Amber default: \"sales_orders\" → \"salesOrderById\"\n\t * @example V4 preset: \"sales_orders\" → \"salesOrderByRowId\"\n\t */\n\trecordFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a list/connection.\n\t * @example Amber default: \"sales_orders\" → \"allSalesOrders\"\n\t * @example SimplifyInflection: \"sales_orders\" → \"salesOrders\"\n\t */\n\tconnectionFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL OrderBy enum type name.\n\t * @example Amber default: \"sales_orders\" → \"SalesOrdersOrderBy\"\n\t */\n\torderByTypeName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL argument name used to look up a record by PK.\n\t * @example Amber default (Relay Global ID): \"sales_orders\" → \"id\"\n\t * @example row_id PK: \"sales_orders\" → \"rowId\"\n\t */\n\trecordArgName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL variable type for the PK argument.\n\t * @example Default UUID PK: \"sales_orders\" → \"UUID!\"\n\t * @example Integer PK: \"sales_orders\" → \"Int!\"\n\t */\n\trecordArgType?: (tableName: string) => string\n}\n\n/**\n * Options for creating a Stonecrop PostGraphile plugin\n * @public\n */\nexport interface StonecropPluginOptions {\n\t/** GraphQL executor for running queries/mutations */\n\texecutor: GraphQLExecutor\n\n\t/**\n\t * Override inflection conventions for mapping table names to GraphQL field names.\n\t * Defaults to PostGraphile Amber preset conventions.\n\t */\n\tinflection?: StonecropInflectionConfig\n}\n\n/**\n * Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality\n * @param options - Plugin configuration options\n * @returns A PostGraphile plugin\n * @public\n */\nexport const createStonecropPlugin = (options: StonecropPluginOptions): GraphileConfig.Plugin => {\n\t// Resolve inflection callbacks with Amber defaults\n\tconst recordFieldName = options.inflection?.recordFieldName ?? defaultRecordFieldName\n\tconst connectionFieldName = options.inflection?.connectionFieldName ?? defaultConnectionFieldName\n\tconst orderByTypeName = options.inflection?.orderByTypeName ?? defaultOrderByTypeName\n\tconst recordArgName = options.inflection?.recordArgName ?? defaultRecordArgName\n\tconst recordArgType = options.inflection?.recordArgType ?? defaultRecordArgType\n\n\treturn extendSchema(() => {\n\t\treturn {\n\t\t\ttypeDefs: gql`\n\t\t\t\ttype StonecropFieldMeta {\n\t\t\t\t\tfieldname: String!\n\t\t\t\t\tfieldtype: String!\n\t\t\t\t\tlabel: String\n\t\t\t\t\trequired: Boolean\n\t\t\t\t\toptions: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionDefinition {\n\t\t\t\t\tlabel: String!\n\t\t\t\t\thandler: String!\n\t\t\t\t\trequiredFields: [String!]\n\t\t\t\t\tallowedStates: [String!]\n\t\t\t\t\tconfirm: Boolean\n\t\t\t\t\targs: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowMeta {\n\t\t\t\t\tstates: [String!]\n\t\t\t\t\tactions: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropDoctypeMeta {\n\t\t\t\t\tname: String!\n\t\t\t\t\ttableName: String\n\t\t\t\t\tfields: [StonecropFieldMeta!]!\n\t\t\t\t\tworkflow: StonecropWorkflowMeta\n\t\t\t\t\tlistDoctype: String\n\t\t\t\t\tparentDoctype: String\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordResult {\n\t\t\t\t\tdata: JSON\n\t\t\t\t\tdoctype: String!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordsResult {\n\t\t\t\t\tdata: [JSON!]!\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tcount: Int!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionResult {\n\t\t\t\t\tsuccess: Boolean!\n\t\t\t\t\tdata: JSON\n\t\t\t\t\terror: String\n\t\t\t\t}\n\n\t\t\t\textend type Query {\n\t\t\t\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\t\t\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\t\t\t\tstonecropRecord(doctype: String!, id: String!): StonecropRecordResult\n\t\t\t\t\tstonecropRecords(\n\t\t\t\t\t\tdoctype: String!\n\t\t\t\t\t\tfilters: JSON\n\t\t\t\t\t\torderBy: String\n\t\t\t\t\t\tlimit: Int\n\t\t\t\t\t\toffset: Int\n\t\t\t\t\t): StonecropRecordsResult\n\t\t\t\t}\n\n\t\t\t\textend type Mutation {\n\t\t\t\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t\t\t\t}\n\t\t\t`,\n\n\t\t\tobjects: {\n\t\t\t\tQuery: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropMeta(_: any, { $doctype }: any) {\n\t\t\t\t\t\t\treturn lambda($doctype, (doctype: unknown) => {\n\t\t\t\t\t\t\t\tconst meta = getMeta(doctype as string)\n\t\t\t\t\t\t\t\treturn meta ?? null\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropAllMeta() {\n\t\t\t\t\t\t\treturn constant(getAllMeta())\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecord(_: any, { $doctype, $id }: any) {\n\t\t\t\t\t\t\treturn loadOne(object({ doctype: $doctype, id: $id }), async (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tconst query = buildRecordQuery(meta, recordFieldName, recordArgName, recordArgType)\n\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t[recordArgName(meta.tableName!)]: spec.id,\n\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\tdata: extractSingleResult(result, meta, recordFieldName),\n\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecords(_: any, { $doctype, $filters, $orderBy, $limit, $offset }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\tfilters: $filters,\n\t\t\t\t\t\t\t\t\torderBy: $orderBy,\n\t\t\t\t\t\t\t\t\tlimit: $limit,\n\t\t\t\t\t\t\t\t\toffset: $offset,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildListQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tconnectionFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\torderByTypeName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\tconst data = extractListResult(result, meta, connectionFieldName)\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\tcount: data.length,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\n\t\t\t\tMutation: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropAction(_: any, { $doctype, $action, $args: $actionArgs }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\taction: $action,\n\t\t\t\t\t\t\t\t\tactionArgs: $actionArgs,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown doctype: ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionDef = meta.workflow?.actions?.[spec.action]\n\t\t\t\t\t\t\t\t\t\t\tif (!actionDef) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown action: ${spec.action} on ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tconst handlerName = actionDef.handler\n\t\t\t\t\t\t\t\t\t\t\tconst handler = getHandler(handlerName)\n\t\t\t\t\t\t\t\t\t\t\tif (!handler) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Handler not registered: ${handlerName}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionContext: ActionContext = {\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: meta,\n\t\t\t\t\t\t\t\t\t\t\t\texecutor: options.executor,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\tconst result = await handler(spec.actionArgs ?? [], actionContext)\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: result,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t})\n}\n\n// =============================================================================\n// Inflection helpers — default to PostGraphile Amber preset conventions\n// Uses `pluralize` for proper English singularization (handles irregular\n// plurals like statuses→status, categories→category, addresses→address).\n// snakeToCamel / toPascalCase are imported from @stonecrop/schema.\n// =============================================================================\n\n/**\n * Amber default: sales_orders → salesOrderById\n * Uses `pluralize` for proper singularization of irregular plurals.\n * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.\n * @public\n */\nfunction defaultRecordFieldName(tableName: string): string {\n\tconst singular = pluralize.singular(tableName)\n\treturn `${snakeToCamel(singular)}ById`\n}\n\n/**\n * Amber default: sales_orders → allSalesOrders\n * @public\n */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/**\n * Amber default: sales_orders → SalesOrdersOrderBy\n * @public\n */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\n}\n\n/**\n * Default PK argument name: 'id' (standard Relay Global ID pattern).\n * Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;\n * PostGraphile Amber generates `rowId: UUID!` for those fields.\n * @public\n */\nfunction defaultRecordArgName(_tableName: string): string {\n\treturn 'id'\n}\n\n/**\n * Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).\n * Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs\n * such as integer serials or Relay Global IDs ('ID!').\n * @public\n */\nfunction defaultRecordArgType(_tableName: string): string {\n\treturn 'UUID!'\n}\n\n// =============================================================================\n// Query builders — generate GraphQL queries to send to the underlying schema\n// =============================================================================\n\n/**\n * Fieldtypes that map to GraphQL object/connection types and require sub-selections.\n * These fields are excluded from generated query field selections.\n * @public\n */\nconst RELATION_FIELDTYPES = new Set(['Link', 'Doctype'])\n\n/**\n * Filter fields to only those directly queryable as scalars, excluding Link and Doctype\n * relation fields that require GraphQL sub-selections.\n * @public\n */\nfunction queryableFieldNames(meta: DoctypeMeta): string {\n\treturn meta.fields\n\t\t.filter(f => !RELATION_FIELDTYPES.has(f.fieldtype))\n\t\t.map(f => f.fieldname)\n\t\t.join('\\n ')\n}\n\n/**\n * Build a GraphQL query to fetch a single record by ID.\n * Excludes Link and Doctype relation fields from the selection set.\n * The PK argument name and type are configurable via `StonecropInflectionConfig.recordArgName`\n * and `StonecropInflectionConfig.recordArgType` to match the target schema's conventions\n * (e.g. `rowId: UUID!` for PostGraphile Amber with row_id columns).\n * @public\n */\nfunction buildRecordQuery(\n\tmeta: DoctypeMeta,\n\trecordFieldName: (t: string) => string,\n\trecordArgName: (t: string) => string,\n\trecordArgType: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst queryName = recordFieldName(meta.tableName!)\n\tconst argName = recordArgName(meta.tableName!)\n\tconst argType = recordArgType(meta.tableName!)\n\n\treturn `\n\t\tquery GetRecord($${argName}: ${argType}) {\n\t\t\t${queryName}(${argName}: $${argName}) {\n\t\t\t\t${fieldNames}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Build a GraphQL connection query to fetch a list of records.\n * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,\n * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.\n * Excludes Link and Doctype relation fields from the selection set.\n * @public\n */\nfunction buildListQuery(\n\tmeta: DoctypeMeta,\n\targs: { limit?: number; offset?: number; orderBy?: string },\n\tconnectionFieldName: (t: string) => string,\n\torderByTypeName: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst orderByType = orderByTypeName(meta.tableName!)\n\n\tconst varDecls: string[] = []\n\tconst queryArgs: string[] = []\n\tif (args.limit) {\n\t\tvarDecls.push('$limit: Int')\n\t\tqueryArgs.push(`first: $limit`)\n\t}\n\tif (args.offset) {\n\t\tvarDecls.push('$offset: Int')\n\t\tqueryArgs.push(`offset: $offset`)\n\t}\n\tif (args.orderBy) {\n\t\tvarDecls.push(`$orderBy: [${orderByType}!]`)\n\t\tqueryArgs.push(`orderBy: $orderBy`)\n\t}\n\n\tconst varStr = varDecls.length > 0 ? `(${varDecls.join(', ')})` : ''\n\tconst argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : ''\n\n\treturn `\n\t\tquery GetRecords${varStr} {\n\t\t\t${connectionName}${argsStr} {\n\t\t\t\tnodes {\n\t\t\t\t${fieldNames}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Extract a single record from a PostGraphile query result using the record field name.\n * @internal\n */\nfunction extractSingleResult(result: unknown, meta: DoctypeMeta, recordFieldName: (t: string) => string): unknown {\n\tconst queryName = recordFieldName(meta.tableName!)\n\treturn (result as Record<string, unknown>)[queryName]\n}\n\n/**\n * Extract the list of nodes from a PostGraphile connection query result.\n * Returns an empty array if the connection field is absent.\n * @internal\n */\nfunction extractListResult(result: unknown, meta: DoctypeMeta, connectionFieldName: (t: string) => string): unknown[] {\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst connection = (result as Record<string, unknown>)[connectionName] as {\n\t\tnodes: unknown[]\n\t}\n\treturn connection?.nodes ?? []\n}\n\n// =============================================================================\n// Exported for testing and advanced usage\n// =============================================================================\n\nexport {\n\tdefaultRecordFieldName,\n\tdefaultConnectionFieldName,\n\tdefaultOrderByTypeName,\n\tdefaultRecordArgName,\n\tdefaultRecordArgType,\n\tbuildRecordQuery,\n\tbuildListQuery,\n\tqueryableFieldNames,\n\tRELATION_FIELDTYPES,\n\textractSingleResult,\n\textractListResult,\n}\n"],"names":["doctypeRegistry","DoctypeValidationError","file","errors","errorMessages","e","loadDoctypes","dir","options","entries","readdirSync","entry","fullPath","join","statSync","loadDoctypeFile","filePath","content","readFileSync","data","err","parseError","result","validateDoctype","doctype","parseDoctype","loadDoctypesFromObject","doctypes","name","withName","getMeta","getAllMeta","hasMeta","clearRegistry","validateReferences","field","handlerRegistry","registerHandler","handler","getHandler","hasHandler","clearHandlers","validateRequiredFields","args","context","record","missing","validateFieldTypes","value","error","validateFieldValue","fieldname","fieldtype","noop","builtinHandlers","registerBuiltinHandlers","createStonecropPlugin","recordFieldName","defaultRecordFieldName","connectionFieldName","defaultConnectionFieldName","orderByTypeName","defaultOrderByTypeName","recordArgName","defaultRecordArgName","recordArgType","defaultRecordArgType","extendSchema","gql","_","$doctype","lambda","constant","$id","loadOne","object","specs","spec","meta","query","buildRecordQuery","extractSingleResult","$filters","$orderBy","$limit","$offset","buildListQuery","extractListResult","$action","$actionArgs","actionDef","handlerName","actionContext","tableName","singular","pluralize","snakeToCamel","toPascalCase","_tableName","RELATION_FIELDTYPES","queryableFieldNames","f","fieldNames","queryName","argName","argType","connectionName","orderByType","varDecls","queryArgs","varStr","argsStr"],"mappings":";;;;;;AAMA,MAAMA,wBAAgD,IAAA;AAM/C,MAAMC,UAA+B,MAAM;AAAA,EACjD,YAEiBC,GAEAC,GACf;AACD,UAAMC,IAAgBD,EAAO,IAAI,CAAAE,MAAK,KAAKA,EAAE,KAAK,KAAK,GAAG,CAAC,KAAKA,EAAE,OAAO,EAAE,EAAE,KAAK;AAAA,CAAI;AACtF,UAAM,iCAAiCH,CAAI;AAAA,EAAME,CAAa,EAAE,GALhD,KAAA,OAAAF,GAEA,KAAA,SAAAC,GAIhB,KAAK,OAAO;AAAA,EACb;AACD;AAmBO,SAASG,EAAaC,GAAaC,IAA+B,IAAU;AAClF,QAAMC,IAAUC,EAAYH,CAAG;AAE/B,aAAWI,KAASF,GAAS;AAC5B,UAAMG,IAAWC,EAAKN,GAAKI,CAAK;AAGhC,IAFaG,EAASF,CAAQ,EAErB,gBACRN,EAAaM,GAAUJ,CAAO,IACpBG,EAAM,SAAS,OAAO,KAChCI,EAAgBH,GAAUJ,CAAO;AAAA,EAEnC;AACD;AAKA,SAASO,EAAgBC,GAAkBR,GAAoC;AAC9E,QAAMS,IAAUC,EAAaF,GAAU,OAAO;AAC9C,MAAIG;AAEJ,MAAI;AACH,IAAAA,IAAO,KAAK,MAAMF,CAAO;AAAA,EAC1B,SAASG,GAAK;AACb,UAAMC,IAA8B;AAAA,MACnC,MAAM,CAAA;AAAA,MACN,SAAS,iBAAiBD,aAAe,QAAQA,EAAI,UAAU,OAAOA,CAAG,CAAC;AAAA,IAAA;AAG3E,QAAIZ,EAAQ,iBAAiB;AAC5B,MAAAA,EAAQ,UAAUQ,GAAU,CAACK,CAAU,CAAC;AACxC;AA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W,IAAI,GAC3CE,EAAU,KAAK,mBAAmB;AAGnC,QAAMC,IAASF,EAAS,SAAS,IAAI,IAAIA,EAAS,KAAK,IAAI,CAAC,MAAM,IAC5DG,IAAUF,EAAU,SAAS,IAAI,IAAIA,EAAU,KAAK,IAAI,CAAC,MAAM;AAErE,SAAO;AAAA,oBACYC,CAAM;AAAA,KACrBJ,CAAc,GAAGK,CAAO;AAAA;AAAA,MAEvBT,CAAU;AAAA;AAAA;AAAA;AAAA;AAKhB;AAMA,SAASrB,GAAoB3D,GAAiBwD,GAAmBrB,GAAiD;AACjH,QAAM8C,IAAY9C,EAAgBqB,EAAK,SAAU;AACjD,SAAQxD,EAAmCiF,CAAS;AACrD;AAOA,SAAShB,GAAkBjE,GAAiBwD,GAAmBnB,GAAuD;AACrH,QAAM+C,IAAiB/C,EAAoBmB,EAAK,SAAU;AAI1D,SAHoBxD,EAAmCoF,CAAc,GAGlD,SAAS,CAAA;AAC7B;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { snakeToCamel, toPascalCase } from '@stonecrop/schema';
|
|
2
2
|
import { constant, lambda, object, loadOne } from 'postgraphile/grafast';
|
|
3
|
+
import { extendSchema, gql } from 'postgraphile/utils';
|
|
3
4
|
import pluralize from 'pluralize';
|
|
4
|
-
import { snakeToCamel, toPascalCase } from '@stonecrop/schema';
|
|
5
5
|
import { getHandler } from '../registry/actions';
|
|
6
6
|
import { getMeta, getAllMeta } from '../registry/doctypes';
|
|
7
7
|
/**
|
|
@@ -180,12 +180,13 @@ export const createStonecropPlugin = (options) => {
|
|
|
180
180
|
error: `Unknown action: ${spec.action} on ${spec.doctype}`,
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
const
|
|
183
|
+
const handlerName = actionDef.handler;
|
|
184
|
+
const handler = getHandler(handlerName);
|
|
184
185
|
if (!handler) {
|
|
185
186
|
return {
|
|
186
187
|
success: false,
|
|
187
188
|
data: null,
|
|
188
|
-
error: `Handler not registered: ${
|
|
189
|
+
error: `Handler not registered: ${handlerName}`,
|
|
189
190
|
};
|
|
190
191
|
}
|
|
191
192
|
const actionContext = {
|
|
@@ -250,7 +251,7 @@ function defaultOrderByTypeName(tableName) {
|
|
|
250
251
|
* Default PK argument name: 'id' (standard Relay Global ID pattern).
|
|
251
252
|
* Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;
|
|
252
253
|
* PostGraphile Amber generates `rowId: UUID!` for those fields.
|
|
253
|
-
* @
|
|
254
|
+
* @public
|
|
254
255
|
*/
|
|
255
256
|
function defaultRecordArgName(_tableName) {
|
|
256
257
|
return 'id';
|
|
@@ -259,7 +260,7 @@ function defaultRecordArgName(_tableName) {
|
|
|
259
260
|
* Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).
|
|
260
261
|
* Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs
|
|
261
262
|
* such as integer serials or Relay Global IDs ('ID!').
|
|
262
|
-
* @
|
|
263
|
+
* @public
|
|
263
264
|
*/
|
|
264
265
|
function defaultRecordArgType(_tableName) {
|
|
265
266
|
return 'UUID!';
|
package/dist/src/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export type { LoadDoctypesOptions } from './registry/doctypes';
|
|
|
5
5
|
export { registerHandler, getHandler, hasHandler, clearHandlers, registerBuiltinHandlers, builtinHandlers, } from './registry/actions';
|
|
6
6
|
export { createStonecropPlugin } from './plugin/postgraphile';
|
|
7
7
|
export type { StonecropPluginOptions, StonecropInflectionConfig } from './plugin/postgraphile';
|
|
8
|
-
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from './plugin/postgraphile';
|
|
8
|
+
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, defaultRecordArgName, defaultRecordArgType, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from './plugin/postgraphile';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGrE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAG5E,OAAO,EACN,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,UAAU,EACV,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,qBAAqB,CAAA;AAE5B,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAG9D,OAAO,EACN,eAAe,EACf,UAAU,EACV,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,eAAe,GACf,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,YAAY,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAG9F,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGrE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAG5E,OAAO,EACN,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,UAAU,EACV,OAAO,EACP,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACtB,MAAM,qBAAqB,CAAA;AAE5B,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAG9D,OAAO,EACN,eAAe,EACf,UAAU,EACV,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,eAAe,GACf,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,YAAY,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAG9F,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,uBAAuB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GraphileConfig } from 'postgraphile/graphile-build';
|
|
2
1
|
import type { DoctypeMeta } from '@stonecrop/schema';
|
|
2
|
+
import { GraphileConfig } from 'postgraphile/graphile-build';
|
|
3
3
|
import type { GraphQLExecutor } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Inflection callbacks for mapping table names to GraphQL query field names.
|
|
@@ -80,14 +80,14 @@ declare function defaultOrderByTypeName(tableName: string): string;
|
|
|
80
80
|
* Default PK argument name: 'id' (standard Relay Global ID pattern).
|
|
81
81
|
* Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;
|
|
82
82
|
* PostGraphile Amber generates `rowId: UUID!` for those fields.
|
|
83
|
-
* @
|
|
83
|
+
* @public
|
|
84
84
|
*/
|
|
85
85
|
declare function defaultRecordArgName(_tableName: string): string;
|
|
86
86
|
/**
|
|
87
87
|
* Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).
|
|
88
88
|
* Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs
|
|
89
89
|
* such as integer serials or Relay Global IDs ('ID!').
|
|
90
|
-
* @
|
|
90
|
+
* @public
|
|
91
91
|
*/
|
|
92
92
|
declare function defaultRecordArgType(_tableName: string): string;
|
|
93
93
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAM5D,OAAO,KAAK,EAAiB,eAAe,EAAE,MAAM,UAAU,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE/C;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAEnD;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE/C;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;IAE7C;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAA;CAC7C;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC,qDAAqD;IACrD,QAAQ,EAAE,eAAe,CAAA;IAEzB;;;OAGG;IACH,UAAU,CAAC,EAAE,yBAAyB,CAAA;CACtC;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,sBAAsB,KAAG,cAAc,CAAC,MA6OtF,CAAA;AASD;;;;;GAKG;AACH,iBAAS,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;GAGG;AACH,iBAAS,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;GAGG;AACH,iBAAS,sBAAsB,CAA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,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GACjB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/graphql-middleware",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
"module": "./dist/index.js",
|
|
7
|
-
"types": "./dist/src/index.d.ts",
|
|
5
|
+
"types": "./dist/graphql-middleware.d.ts",
|
|
8
6
|
"exports": {
|
|
9
7
|
".": {
|
|
10
|
-
"types": "./dist/
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
8
|
+
"types": "./dist/graphql-middleware.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
13
10
|
}
|
|
14
11
|
},
|
|
15
12
|
"files": [
|
|
16
13
|
"dist"
|
|
17
14
|
],
|
|
15
|
+
"description": "GraphQL middleware for PostGraphile and Stonecrop schema",
|
|
16
|
+
"sideEffects": false,
|
|
18
17
|
"dependencies": {
|
|
19
18
|
"graphql": "^16.12.0",
|
|
20
19
|
"pluralize": "^8.0.0",
|
|
21
20
|
"postgraphile": "^5.0.0-rc.7",
|
|
22
|
-
"@stonecrop/schema": "0.
|
|
21
|
+
"@stonecrop/schema": "0.9.1"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"@rushstack/heft": "^1.2.0",
|
|
@@ -34,7 +33,6 @@
|
|
|
34
33
|
},
|
|
35
34
|
"scripts": {
|
|
36
35
|
"_phase:build": "heft build && vite build && rushx docs",
|
|
37
|
-
"prepublish": "heft build && vite build && rushx docs",
|
|
38
36
|
"build": "heft build && vite build && rushx docs",
|
|
39
37
|
"docs": "bash ../common/scripts/run-docs.sh graphql_middleware",
|
|
40
38
|
"test": "vitest run --coverage.enabled false",
|
package/dist/index.cjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("node:fs"),J=require("node:path"),h=require("@stonecrop/schema"),k=require("postgraphile/utils"),p=require("postgraphile/grafast"),L=require("pluralize"),f=new Map;class b extends Error{constructor(t,r){const o=r.map(n=>` ${n.path.join(".")}: ${n.message}`).join(`
|
|
2
|
-
`);super(`Invalid doctype definition in ${t}:
|
|
3
|
-
${o}`),this.file=t,this.errors=r,this.name="DoctypeValidationError"}}function E(e,t={}){const r=D.readdirSync(e);for(const o of r){const n=J.join(e,o);D.statSync(n).isDirectory()?E(n,t):o.endsWith(".json")&&_(n,t)}}function _(e,t){const r=D.readFileSync(e,"utf-8");let o;try{o=JSON.parse(r)}catch(s){const c={path:[],message:`Invalid JSON: ${s instanceof Error?s.message:String(s)}`};if(t.continueOnError){t.onError?.(e,[c]);return}throw new b(e,[c])}const n=h.validateDoctype(o);if(!n.success){if(t.continueOnError){t.onError?.(e,n.errors);return}throw new b(e,n.errors)}const a=h.parseDoctype(o);f.set(a.name,a)}function C(e,t={}){for(const[r,o]of Object.entries(e)){const n={...o,name:r},a=h.validateDoctype(n);if(!a.success){if(t.continueOnError){t.onError?.(r,a.errors);continue}throw new b(r,a.errors)}const s=h.parseDoctype(n);f.set(s.name,s)}}function $(e){return f.get(e)}function F(){return Array.from(f.values())}function P(e){return f.has(e)}function Q(){f.clear()}function U(){const e=[];for(const t of f.values()){t.inherits&&!f.has(t.inherits)&&e.push({path:[t.name,"inherits"],message:`References unknown doctype: ${t.inherits}`}),t.listDoctype&&!f.has(t.listDoctype)&&e.push({path:[t.name,"listDoctype"],message:`References unknown doctype: ${t.listDoctype}`}),t.parentDoctype&&!f.has(t.parentDoctype)&&e.push({path:[t.name,"parentDoctype"],message:`References unknown doctype: ${t.parentDoctype}`});for(const r of t.fields)r.fieldtype==="Link"&&typeof r.options=="string"&&(f.has(r.options)||e.push({path:[t.name,"fields",r.fieldname,"options"],message:`Link references unknown doctype: ${r.options}`}))}return e}const N=new Map;function M(e,t){N.set(e,t)}function q(e){return N.get(e)}function v(e){return N.has(e)}function V(){N.clear()}const W=async(e,t)=>{const[r]=e,{doctype:o}=t,n=[];for(const a of o.fields)a.required&&(r[a.fieldname]===void 0||r[a.fieldname]===null)&&n.push(a.label??a.fieldname);if(n.length>0)throw new Error(`Missing required fields: ${n.join(", ")}`);return{valid:!0}},G=async(e,t)=>{const[r]=e,{doctype:o}=t,n=[];for(const a of o.fields){const s=r[a.fieldname];if(s==null)continue;const c=Y(a.fieldname,s,a.fieldtype);c&&n.push(c)}if(n.length>0)throw new Error(`Field type validation failed:
|
|
4
|
-
${n.join(`
|
|
5
|
-
`)}`);return{valid:!0}};function Y(e,t,r){switch(r){case"Int":if(typeof t!="number"||!Number.isInteger(t))return`${e}: expected integer, got ${typeof t}`;break;case"Float":case"Decimal":case"Currency":case"Quantity":if(typeof t!="number"&&typeof t!="string")return`${e}: expected number, got ${typeof t}`;break;case"Check":if(typeof t!="boolean")return`${e}: expected boolean, got ${typeof t}`;break;case"Data":case"Text":case"Code":case"Link":if(typeof t!="string")return`${e}: expected string, got ${typeof t}`;break;case"Date":case"Time":case"Datetime":if(typeof t!="string"&&!(t instanceof Date))return`${e}: expected date string or Date, got ${typeof t}`;break;case"JSON":if(typeof t!="object")return`${e}: expected object, got ${typeof t}`;break;case"Table":if(!Array.isArray(t))return`${e}: expected array, got ${typeof t}`;break}return null}const z=async()=>({ok:!0}),A={validateRequiredFields:W,validateFieldTypes:G,noop:z};function K(){for(const[e,t]of Object.entries(A))M(e,t)}const X=e=>{const t=e.inflection?.recordFieldName??B,r=e.inflection?.connectionFieldName??j,o=e.inflection?.orderByTypeName??x,n=e.inflection?.recordArgName??Z,a=e.inflection?.recordArgType??ee;return k.extendSchema(()=>({typeDefs:k.gql`
|
|
6
|
-
type StonecropFieldMeta {
|
|
7
|
-
fieldname: String!
|
|
8
|
-
fieldtype: String!
|
|
9
|
-
label: String
|
|
10
|
-
required: Boolean
|
|
11
|
-
options: JSON
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type StonecropActionDefinition {
|
|
15
|
-
label: String!
|
|
16
|
-
handler: String!
|
|
17
|
-
requiredFields: [String!]
|
|
18
|
-
allowedStates: [String!]
|
|
19
|
-
confirm: Boolean
|
|
20
|
-
args: JSON
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type StonecropWorkflowMeta {
|
|
24
|
-
states: [String!]
|
|
25
|
-
actions: JSON
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type StonecropDoctypeMeta {
|
|
29
|
-
name: String!
|
|
30
|
-
tableName: String
|
|
31
|
-
fields: [StonecropFieldMeta!]!
|
|
32
|
-
workflow: StonecropWorkflowMeta
|
|
33
|
-
listDoctype: String
|
|
34
|
-
parentDoctype: String
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type StonecropRecordResult {
|
|
38
|
-
data: JSON
|
|
39
|
-
doctype: String!
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type StonecropRecordsResult {
|
|
43
|
-
data: [JSON!]!
|
|
44
|
-
doctype: String!
|
|
45
|
-
count: Int!
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type StonecropActionResult {
|
|
49
|
-
success: Boolean!
|
|
50
|
-
data: JSON
|
|
51
|
-
error: String
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
extend type Query {
|
|
55
|
-
stonecropMeta(doctype: String!): StonecropDoctypeMeta
|
|
56
|
-
stonecropAllMeta: [StonecropDoctypeMeta!]!
|
|
57
|
-
stonecropRecord(doctype: String!, id: String!): StonecropRecordResult
|
|
58
|
-
stonecropRecords(
|
|
59
|
-
doctype: String!
|
|
60
|
-
filters: JSON
|
|
61
|
-
orderBy: String
|
|
62
|
-
limit: Int
|
|
63
|
-
offset: Int
|
|
64
|
-
): StonecropRecordsResult
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
extend type Mutation {
|
|
68
|
-
stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
|
|
69
|
-
}
|
|
70
|
-
`,objects:{Query:{plans:{stonecropMeta(s,{$doctype:c}){return p.lambda(c,d=>$(d)??null)},stonecropAllMeta(){return p.constant(F())},stonecropRecord(s,{$doctype:c,$id:d}){return p.loadOne(p.object({doctype:c,id:d}),async y=>await Promise.all(y.map(async u=>{const l=$(u.doctype);if(!l)throw new Error(`Unknown doctype: ${u.doctype}`);if(!l.tableName)throw new Error(`Doctype ${u.doctype} has no table mapping`);const g=I(l,t,n,a),i=await e.executor.query(g,{[n(l.tableName)]:u.id});return{data:te(i,l,t),doctype:u.doctype}})))},stonecropRecords(s,{$doctype:c,$filters:d,$orderBy:y,$limit:u,$offset:l}){return p.loadOne(p.object({doctype:c,filters:d,orderBy:y,limit:u,offset:l}),async g=>await Promise.all(g.map(async i=>{const m=$(i.doctype);if(!m)throw new Error(`Unknown doctype: ${i.doctype}`);if(!m.tableName)throw new Error(`Doctype ${i.doctype} has no table mapping`);const w=H(m,{limit:i.limit,offset:i.offset,orderBy:i.orderBy},r,o),S=await e.executor.query(w,{limit:i.limit,offset:i.offset,orderBy:i.orderBy}),O=re(S,m,r);return{data:O,doctype:i.doctype,count:O.length}})))}}},Mutation:{plans:{stonecropAction(s,{$doctype:c,$action:d,$args:y}){return p.loadOne(p.object({doctype:c,action:d,actionArgs:y}),async u=>await Promise.all(u.map(async l=>{const g=$(l.doctype);if(!g)return{success:!1,data:null,error:`Unknown doctype: ${l.doctype}`};const i=g.workflow?.actions?.[l.action];if(!i)return{success:!1,data:null,error:`Unknown action: ${l.action} on ${l.doctype}`};const m=q(i.handler);if(!m)return{success:!1,data:null,error:`Handler not registered: ${i.handler}`};const w={doctype:g,executor:e.executor};try{return{success:!0,data:await m(l.actionArgs??[],w),error:null}}catch(S){return{success:!1,data:null,error:S instanceof Error?S.message:String(S)}}})))}}}}}))};function B(e){const t=L.singular(e);return`${h.snakeToCamel(t)}ById`}function j(e){return`all${h.toPascalCase(e)}`}function x(e){return`${h.toPascalCase(e)}OrderBy`}function Z(e){return"id"}function ee(e){return"UUID!"}const T=new Set(["Link","Doctype"]);function R(e){return e.fields.filter(t=>!T.has(t.fieldtype)).map(t=>t.fieldname).join(`
|
|
71
|
-
`)}function I(e,t,r,o){const n=R(e),a=t(e.tableName),s=r(e.tableName),c=o(e.tableName);return`
|
|
72
|
-
query GetRecord($${s}: ${c}) {
|
|
73
|
-
${a}(${s}: $${s}) {
|
|
74
|
-
${n}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
`}function H(e,t,r,o){const n=R(e),a=r(e.tableName),s=o(e.tableName),c=[],d=[];t.limit&&(c.push("$limit: Int"),d.push("first: $limit")),t.offset&&(c.push("$offset: Int"),d.push("offset: $offset")),t.orderBy&&(c.push(`$orderBy: [${s}!]`),d.push("orderBy: $orderBy"));const y=c.length>0?`(${c.join(", ")})`:"",u=d.length>0?`(${d.join(", ")})`:"";return`
|
|
78
|
-
query GetRecords${y} {
|
|
79
|
-
${a}${u} {
|
|
80
|
-
nodes {
|
|
81
|
-
${n}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
`}function te(e,t,r){const o=r(t.tableName);return e[o]}function re(e,t,r){const o=r(t.tableName);return e[o]?.nodes??[]}exports.DoctypeValidationError=b;exports.RELATION_FIELDTYPES=T;exports.buildListQuery=H;exports.buildRecordQuery=I;exports.builtinHandlers=A;exports.clearHandlers=V;exports.clearRegistry=Q;exports.createStonecropPlugin=X;exports.defaultConnectionFieldName=j;exports.defaultOrderByTypeName=x;exports.defaultRecordFieldName=B;exports.getAllMeta=F;exports.getHandler=q;exports.getMeta=$;exports.hasHandler=v;exports.hasMeta=P;exports.loadDoctypes=E;exports.loadDoctypesFromObject=C;exports.queryableFieldNames=R;exports.registerBuiltinHandlers=K;exports.registerHandler=M;exports.validateReferences=U;
|
|
86
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/registry/doctypes.ts","../src/registry/actions.ts","../src/plugin/postgraphile.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '@stonecrop/schema'\nimport type { DoctypeMeta, ValidationError } from '@stonecrop/schema'\n\nconst doctypeRegistry: Map<string, DoctypeMeta> = new Map()\n\n/**\n * Error thrown when a doctype definition fails validation\n * @public\n */\nexport class DoctypeValidationError extends Error {\n\tconstructor(\n\t\t/** File path or name where the validation error occurred */\n\t\tpublic readonly file: string,\n\t\t/** List of validation errors found */\n\t\tpublic readonly errors: ValidationError[]\n\t) {\n\t\tconst errorMessages = errors.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\\n')\n\t\tsuper(`Invalid doctype definition in ${file}:\\n${errorMessages}`)\n\t\tthis.name = 'DoctypeValidationError'\n\t}\n}\n\n/**\n * Options for loading doctype definitions\n * @public\n */\nexport interface LoadDoctypesOptions {\n\t/** Continue loading other files if one fails validation */\n\tcontinueOnError?: boolean\n\t/** Callback for validation errors when continueOnError is true */\n\tonError?: (file: string, errors: ValidationError[]) => void\n}\n\n/**\n * Load doctype definitions from a directory of JSON files\n * @param dir - Directory path containing doctype JSON files\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypes(dir: string, options: LoadDoctypesOptions = {}): void {\n\tconst entries = readdirSync(dir)\n\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry)\n\t\tconst stat = statSync(fullPath)\n\n\t\tif (stat.isDirectory()) {\n\t\t\tloadDoctypes(fullPath, options)\n\t\t} else if (entry.endsWith('.json')) {\n\t\t\tloadDoctypeFile(fullPath, options)\n\t\t}\n\t}\n}\n\n/**\n * Load and validate a single doctype file\n */\nfunction loadDoctypeFile(filePath: string, options: LoadDoctypesOptions): void {\n\tconst content = readFileSync(filePath, 'utf-8')\n\tlet data: unknown\n\n\ttry {\n\t\tdata = JSON.parse(content)\n\t} catch (err) {\n\t\tconst parseError: ValidationError = {\n\t\t\tpath: [],\n\t\t\tmessage: `Invalid JSON: ${err instanceof Error ? err.message : String(err)}`,\n\t\t}\n\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, [parseError])\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, [parseError])\n\t}\n\n\tconst result = validateDoctype(data)\n\n\tif (!result.success) {\n\t\tif (options.continueOnError) {\n\t\t\toptions.onError?.(filePath, result.errors)\n\t\t\treturn\n\t\t}\n\t\tthrow new DoctypeValidationError(filePath, result.errors)\n\t}\n\n\tconst doctype = parseDoctype(data)\n\tdoctypeRegistry.set(doctype.name, doctype)\n}\n\n/**\n * Load doctypes from an object (for programmatic use)\n * @param doctypes - Object mapping doctype names to doctype definitions\n * @param options - Options for loading doctypes (continueOnError, onError callback)\n * @public\n */\nexport function loadDoctypesFromObject(doctypes: Record<string, unknown>, options: LoadDoctypesOptions = {}): void {\n\tfor (const [name, data] of Object.entries(doctypes)) {\n\t\tconst withName = { ...(data as object), name }\n\t\tconst result = validateDoctype(withName)\n\n\t\tif (!result.success) {\n\t\t\tif (options.continueOnError) {\n\t\t\t\toptions.onError?.(name, result.errors)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthrow new DoctypeValidationError(name, result.errors)\n\t\t}\n\n\t\tconst doctype = parseDoctype(withName)\n\t\tdoctypeRegistry.set(doctype.name, doctype)\n\t}\n}\n\n/**\n * Get a doctype by name\n * @param name - Name of the doctype to retrieve\n * @public\n */\nexport function getMeta(name: string): DoctypeMeta | undefined {\n\treturn doctypeRegistry.get(name)\n}\n\n/**\n * Get all loaded doctypes\n * @public\n */\nexport function getAllMeta(): DoctypeMeta[] {\n\treturn Array.from(doctypeRegistry.values())\n}\n\n/**\n * Check if a doctype is registered\n * @param name - Name of the doctype to check\n * @public\n */\nexport function hasMeta(name: string): boolean {\n\treturn doctypeRegistry.has(name)\n}\n\n/**\n * Clear all registered doctypes\n * @public\n */\nexport function clearRegistry(): void {\n\tdoctypeRegistry.clear()\n}\n\n/**\n * Validate cross-doctype references (Link fields, inherits, etc.)\n * Call after all doctypes are loaded.\n * @public\n */\nexport function validateReferences(): ValidationError[] {\n\tconst errors: ValidationError[] = []\n\n\tfor (const doctype of doctypeRegistry.values()) {\n\t\t// Check inherits reference\n\t\tif (doctype.inherits && !doctypeRegistry.has(doctype.inherits)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'inherits'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.inherits}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check listDoctype reference\n\t\tif (doctype.listDoctype && !doctypeRegistry.has(doctype.listDoctype)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'listDoctype'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.listDoctype}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check parentDoctype reference\n\t\tif (doctype.parentDoctype && !doctypeRegistry.has(doctype.parentDoctype)) {\n\t\t\terrors.push({\n\t\t\t\tpath: [doctype.name, 'parentDoctype'],\n\t\t\t\tmessage: `References unknown doctype: ${doctype.parentDoctype}`,\n\t\t\t})\n\t\t}\n\n\t\t// Check Link field targets\n\t\tfor (const field of doctype.fields) {\n\t\t\tif (field.fieldtype === 'Link' && typeof field.options === 'string') {\n\t\t\t\tif (!doctypeRegistry.has(field.options)) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tpath: [doctype.name, 'fields', field.fieldname, 'options'],\n\t\t\t\t\t\tmessage: `Link references unknown doctype: ${field.options}`,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn errors\n}\n","import type { DoctypeMeta } from '@stonecrop/schema'\nimport type { ActionHandler, ActionContext } from '../types'\n\nconst handlerRegistry: Map<string, ActionHandler> = new Map()\n\n/**\n * Register an action handler\n * @param name - Unique name for the action handler\n * @param handler - Action handler function to register\n * @public\n */\nexport function registerHandler(name: string, handler: ActionHandler): void {\n\thandlerRegistry.set(name, handler)\n}\n\n/**\n * Get a registered handler by name\n * @param name - Name of the action handler to retrieve\n * @public\n */\nexport function getHandler(name: string): ActionHandler | undefined {\n\treturn handlerRegistry.get(name)\n}\n\n/**\n * Check if a handler is registered\n * @param name - Name of the action handler to check\n * @public\n */\nexport function hasHandler(name: string): boolean {\n\treturn handlerRegistry.has(name)\n}\n\n/**\n * Clear all registered handlers\n * @public\n */\nexport function clearHandlers(): void {\n\thandlerRegistry.clear()\n}\n\n// =============================================================================\n// Built-in Handlers\n// =============================================================================\n\n/**\n * Validate that all required fields are present in a record\n */\nconst validateRequiredFields: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst missing: string[] = []\n\tfor (const field of doctype.fields) {\n\t\tif (field.required && (record[field.fieldname] === undefined || record[field.fieldname] === null)) {\n\t\t\tmissing.push(field.label ?? field.fieldname)\n\t\t}\n\t}\n\n\tif (missing.length > 0) {\n\t\tthrow new Error(`Missing required fields: ${missing.join(', ')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate field types match expected types\n */\nconst validateFieldTypes: ActionHandler = async (args, context) => {\n\tconst [record] = args as [Record<string, unknown>]\n\tconst { doctype } = context\n\n\tconst errors: string[] = []\n\n\tfor (const field of doctype.fields) {\n\t\tconst value = record[field.fieldname]\n\t\tif (value === undefined || value === null) continue\n\n\t\tconst error = validateFieldValue(field.fieldname, value, field.fieldtype)\n\t\tif (error) errors.push(error)\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`Field type validation failed:\\n${errors.join('\\n')}`)\n\t}\n\n\treturn { valid: true }\n}\n\n/**\n * Validate a single field value against its expected type\n */\nfunction validateFieldValue(fieldname: string, value: unknown, fieldtype: string): string | null {\n\tswitch (fieldtype) {\n\t\tcase 'Int':\n\t\t\tif (typeof value !== 'number' || !Number.isInteger(value)) {\n\t\t\t\treturn `${fieldname}: expected integer, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Float':\n\t\tcase 'Decimal':\n\t\tcase 'Currency':\n\t\tcase 'Quantity':\n\t\t\tif (typeof value !== 'number' && typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected number, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Check':\n\t\t\tif (typeof value !== 'boolean') {\n\t\t\t\treturn `${fieldname}: expected boolean, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Data':\n\t\tcase 'Text':\n\t\tcase 'Code':\n\t\tcase 'Link':\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\treturn `${fieldname}: expected string, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Date':\n\t\tcase 'Time':\n\t\tcase 'Datetime':\n\t\t\tif (typeof value !== 'string' && !(value instanceof Date)) {\n\t\t\t\treturn `${fieldname}: expected date string or Date, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'JSON':\n\t\t\tif (typeof value !== 'object') {\n\t\t\t\treturn `${fieldname}: expected object, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\n\t\tcase 'Table':\n\t\t\tif (!Array.isArray(value)) {\n\t\t\t\treturn `${fieldname}: expected array, got ${typeof value}`\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn null\n}\n\n/**\n * No-op handler for testing or placeholder actions\n */\nconst noop: ActionHandler = async () => {\n\treturn { ok: true }\n}\n\n/**\n * Built-in handlers available for registration\n * @public\n */\nexport const builtinHandlers: Record<string, ActionHandler> = {\n\tvalidateRequiredFields,\n\tvalidateFieldTypes,\n\tnoop,\n}\n\n/**\n * Register all built-in handlers\n * @public\n */\nexport function registerBuiltinHandlers(): void {\n\tfor (const [name, handler] of Object.entries(builtinHandlers)) {\n\t\tregisterHandler(name, handler)\n\t}\n}\n","import { extendSchema, gql } from 'postgraphile/utils'\nimport { constant, lambda, object, loadOne } from 'postgraphile/grafast'\nimport { GraphileConfig } from 'postgraphile/graphile-build'\n\nimport pluralize from 'pluralize'\n\nimport { snakeToCamel, toPascalCase } from '@stonecrop/schema'\nimport { getHandler } from '../registry/actions'\nimport { getMeta, getAllMeta } from '../registry/doctypes'\nimport type { DoctypeMeta } from '@stonecrop/schema'\nimport type { ActionContext, GraphQLExecutor } from '../types'\n\n/**\n * Inflection callbacks for mapping table names to GraphQL query field names.\n * Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).\n *\n * Defaults match the PostGraphile Amber preset conventions.\n * @public\n */\nexport interface StonecropInflectionConfig {\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a single record by ID.\n\t * @example Amber default: \"sales_orders\" → \"salesOrderById\"\n\t * @example V4 preset: \"sales_orders\" → \"salesOrderByRowId\"\n\t */\n\trecordFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL field name for fetching a list/connection.\n\t * @example Amber default: \"sales_orders\" → \"allSalesOrders\"\n\t * @example SimplifyInflection: \"sales_orders\" → \"salesOrders\"\n\t */\n\tconnectionFieldName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL OrderBy enum type name.\n\t * @example Amber default: \"sales_orders\" → \"SalesOrdersOrderBy\"\n\t */\n\torderByTypeName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL argument name used to look up a record by PK.\n\t * @example Amber default (Relay Global ID): \"sales_orders\" → \"id\"\n\t * @example row_id PK: \"sales_orders\" → \"rowId\"\n\t */\n\trecordArgName?: (tableName: string) => string\n\n\t/**\n\t * Given a table name, return the GraphQL variable type for the PK argument.\n\t * @example Default UUID PK: \"sales_orders\" → \"UUID!\"\n\t * @example Integer PK: \"sales_orders\" → \"Int!\"\n\t */\n\trecordArgType?: (tableName: string) => string\n}\n\n/**\n * Options for creating a Stonecrop PostGraphile plugin\n * @public\n */\nexport interface StonecropPluginOptions {\n\t/** GraphQL executor for running queries/mutations */\n\texecutor: GraphQLExecutor\n\n\t/**\n\t * Override inflection conventions for mapping table names to GraphQL field names.\n\t * Defaults to PostGraphile Amber preset conventions.\n\t */\n\tinflection?: StonecropInflectionConfig\n}\n\n/**\n * Create a PostGraphile plugin that extends the GraphQL schema with Stonecrop functionality\n * @param options - Plugin configuration options\n * @returns A PostGraphile plugin\n * @public\n */\nexport const createStonecropPlugin = (options: StonecropPluginOptions): GraphileConfig.Plugin => {\n\t// Resolve inflection callbacks with Amber defaults\n\tconst recordFieldName = options.inflection?.recordFieldName ?? defaultRecordFieldName\n\tconst connectionFieldName = options.inflection?.connectionFieldName ?? defaultConnectionFieldName\n\tconst orderByTypeName = options.inflection?.orderByTypeName ?? defaultOrderByTypeName\n\tconst recordArgName = options.inflection?.recordArgName ?? defaultRecordArgName\n\tconst recordArgType = options.inflection?.recordArgType ?? defaultRecordArgType\n\n\treturn extendSchema(() => {\n\t\treturn {\n\t\t\ttypeDefs: gql`\n\t\t\t\ttype StonecropFieldMeta {\n\t\t\t\t\tfieldname: String!\n\t\t\t\t\tfieldtype: String!\n\t\t\t\t\tlabel: String\n\t\t\t\t\trequired: Boolean\n\t\t\t\t\toptions: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionDefinition {\n\t\t\t\t\tlabel: String!\n\t\t\t\t\thandler: String!\n\t\t\t\t\trequiredFields: [String!]\n\t\t\t\t\tallowedStates: [String!]\n\t\t\t\t\tconfirm: Boolean\n\t\t\t\t\targs: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropWorkflowMeta {\n\t\t\t\t\tstates: [String!]\n\t\t\t\t\tactions: JSON\n\t\t\t\t}\n\n\t\t\t\ttype StonecropDoctypeMeta {\n\t\t\t\t\tname: String!\n\t\t\t\t\ttableName: String\n\t\t\t\t\tfields: [StonecropFieldMeta!]!\n\t\t\t\t\tworkflow: StonecropWorkflowMeta\n\t\t\t\t\tlistDoctype: String\n\t\t\t\t\tparentDoctype: String\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordResult {\n\t\t\t\t\tdata: JSON\n\t\t\t\t\tdoctype: String!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropRecordsResult {\n\t\t\t\t\tdata: [JSON!]!\n\t\t\t\t\tdoctype: String!\n\t\t\t\t\tcount: Int!\n\t\t\t\t}\n\n\t\t\t\ttype StonecropActionResult {\n\t\t\t\t\tsuccess: Boolean!\n\t\t\t\t\tdata: JSON\n\t\t\t\t\terror: String\n\t\t\t\t}\n\n\t\t\t\textend type Query {\n\t\t\t\t\tstonecropMeta(doctype: String!): StonecropDoctypeMeta\n\t\t\t\t\tstonecropAllMeta: [StonecropDoctypeMeta!]!\n\t\t\t\t\tstonecropRecord(doctype: String!, id: String!): StonecropRecordResult\n\t\t\t\t\tstonecropRecords(\n\t\t\t\t\t\tdoctype: String!\n\t\t\t\t\t\tfilters: JSON\n\t\t\t\t\t\torderBy: String\n\t\t\t\t\t\tlimit: Int\n\t\t\t\t\t\toffset: Int\n\t\t\t\t\t): StonecropRecordsResult\n\t\t\t\t}\n\n\t\t\t\textend type Mutation {\n\t\t\t\t\tstonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!\n\t\t\t\t}\n\t\t\t`,\n\n\t\t\tobjects: {\n\t\t\t\tQuery: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropMeta(_: any, { $doctype }: any) {\n\t\t\t\t\t\t\treturn lambda($doctype, (doctype: unknown) => {\n\t\t\t\t\t\t\t\tconst meta = getMeta(doctype as string)\n\t\t\t\t\t\t\t\treturn meta ?? null\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropAllMeta() {\n\t\t\t\t\t\t\treturn constant(getAllMeta())\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecord(_: any, { $doctype, $id }: any) {\n\t\t\t\t\t\t\treturn loadOne(object({ doctype: $doctype, id: $id }), async (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tconst query = buildRecordQuery(meta, recordFieldName, recordArgName, recordArgType)\n\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t[recordArgName(meta.tableName!)]: spec.id,\n\t\t\t\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\tdata: extractSingleResult(result, meta, recordFieldName),\n\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\tstonecropRecords(_: any, { $doctype, $filters, $orderBy, $limit, $offset }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\tfilters: $filters,\n\t\t\t\t\t\t\t\t\torderBy: $orderBy,\n\t\t\t\t\t\t\t\t\tlimit: $limit,\n\t\t\t\t\t\t\t\t\toffset: $offset,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Unknown doctype: ${spec.doctype}`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif (!meta.tableName) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error(`Doctype ${spec.doctype} has no table mapping`)\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst query = buildListQuery(\n\t\t\t\t\t\t\t\t\t\t\t\tmeta,\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\tconnectionFieldName,\n\t\t\t\t\t\t\t\t\t\t\t\torderByTypeName\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, {\n\t\t\t\t\t\t\t\t\t\t\t\tlimit: spec.limit,\n\t\t\t\t\t\t\t\t\t\t\t\toffset: spec.offset,\n\t\t\t\t\t\t\t\t\t\t\t\torderBy: spec.orderBy,\n\t\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t\t\tconst data = extractListResult(result, meta, connectionFieldName)\n\n\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\tdata,\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: spec.doctype,\n\t\t\t\t\t\t\t\t\t\t\t\tcount: data.length,\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\n\t\t\t\tMutation: {\n\t\t\t\t\tplans: {\n\t\t\t\t\t\tstonecropAction(_: any, { $doctype, $action, $args: $actionArgs }: any) {\n\t\t\t\t\t\t\treturn loadOne(\n\t\t\t\t\t\t\t\tobject({\n\t\t\t\t\t\t\t\t\tdoctype: $doctype,\n\t\t\t\t\t\t\t\t\taction: $action,\n\t\t\t\t\t\t\t\t\tactionArgs: $actionArgs,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tasync (specs: readonly any[]) => {\n\t\t\t\t\t\t\t\t\treturn await Promise.all(\n\t\t\t\t\t\t\t\t\t\tspecs.map(async spec => {\n\t\t\t\t\t\t\t\t\t\t\tconst meta = getMeta(spec.doctype)\n\t\t\t\t\t\t\t\t\t\t\tif (!meta) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown doctype: ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionDef = meta.workflow?.actions?.[spec.action]\n\t\t\t\t\t\t\t\t\t\t\tif (!actionDef) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Unknown action: ${spec.action} on ${spec.doctype}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst handler = getHandler(actionDef.handler)\n\t\t\t\t\t\t\t\t\t\t\tif (!handler) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: `Handler not registered: ${actionDef.handler}`,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst actionContext: ActionContext = {\n\t\t\t\t\t\t\t\t\t\t\t\tdoctype: meta,\n\t\t\t\t\t\t\t\t\t\t\t\texecutor: options.executor,\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\tconst result = await handler(spec.actionArgs ?? [], actionContext)\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: true,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: result,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: null,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\t\t\t\t\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t})\n}\n\n// =============================================================================\n// Inflection helpers — default to PostGraphile Amber preset conventions\n// Uses `pluralize` for proper English singularization (handles irregular\n// plurals like statuses→status, categories→category, addresses→address).\n// snakeToCamel / toPascalCase are imported from @stonecrop/schema.\n// =============================================================================\n\n/**\n * Amber default: sales_orders → salesOrderById\n * Uses `pluralize` for proper singularization of irregular plurals.\n * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.\n * @public\n */\nfunction defaultRecordFieldName(tableName: string): string {\n\tconst singular = pluralize.singular(tableName)\n\treturn `${snakeToCamel(singular)}ById`\n}\n\n/**\n * Amber default: sales_orders → allSalesOrders\n * @public\n */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/**\n * Amber default: sales_orders → SalesOrdersOrderBy\n * @public\n */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\n}\n\n/**\n * Default PK argument name: 'id' (standard Relay Global ID pattern).\n * Override via `StonecropInflectionConfig.recordArgName` when using row_id columns;\n * PostGraphile Amber generates `rowId: UUID!` for those fields.\n * @internal\n */\nfunction defaultRecordArgName(_tableName: string): string {\n\treturn 'id'\n}\n\n/**\n * Default PK argument type: 'UUID!' (PostGraphile Amber default for UUID PKs).\n * Override via `StonecropInflectionConfig.recordArgType` when using non-UUID PKs\n * such as integer serials or Relay Global IDs ('ID!').\n * @internal\n */\nfunction defaultRecordArgType(_tableName: string): string {\n\treturn 'UUID!'\n}\n\n// =============================================================================\n// Query builders — generate GraphQL queries to send to the underlying schema\n// =============================================================================\n\n/**\n * Fieldtypes that map to GraphQL object/connection types and require sub-selections.\n * These fields are excluded from generated query field selections.\n * @public\n */\nconst RELATION_FIELDTYPES = new Set(['Link', 'Doctype'])\n\n/**\n * Filter fields to only those directly queryable as scalars, excluding Link and Doctype\n * relation fields that require GraphQL sub-selections.\n * @public\n */\nfunction queryableFieldNames(meta: DoctypeMeta): string {\n\treturn meta.fields\n\t\t.filter(f => !RELATION_FIELDTYPES.has(f.fieldtype))\n\t\t.map(f => f.fieldname)\n\t\t.join('\\n ')\n}\n\n/**\n * Build a GraphQL query to fetch a single record by ID.\n * Excludes Link and Doctype relation fields from the selection set.\n * The PK argument name and type are configurable via `StonecropInflectionConfig.recordArgName`\n * and `StonecropInflectionConfig.recordArgType` to match the target schema's conventions\n * (e.g. `rowId: UUID!` for PostGraphile Amber with row_id columns).\n * @public\n */\nfunction buildRecordQuery(\n\tmeta: DoctypeMeta,\n\trecordFieldName: (t: string) => string,\n\trecordArgName: (t: string) => string,\n\trecordArgType: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst queryName = recordFieldName(meta.tableName!)\n\tconst argName = recordArgName(meta.tableName!)\n\tconst argType = recordArgType(meta.tableName!)\n\n\treturn `\n\t\tquery GetRecord($${argName}: ${argType}) {\n\t\t\t${queryName}(${argName}: $${argName}) {\n\t\t\t\t${fieldNames}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Build a GraphQL connection query to fetch a list of records.\n * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,\n * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.\n * Excludes Link and Doctype relation fields from the selection set.\n * @public\n */\nfunction buildListQuery(\n\tmeta: DoctypeMeta,\n\targs: { limit?: number; offset?: number; orderBy?: string },\n\tconnectionFieldName: (t: string) => string,\n\torderByTypeName: (t: string) => string\n): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst orderByType = orderByTypeName(meta.tableName!)\n\n\tconst varDecls: string[] = []\n\tconst queryArgs: string[] = []\n\tif (args.limit) {\n\t\tvarDecls.push('$limit: Int')\n\t\tqueryArgs.push(`first: $limit`)\n\t}\n\tif (args.offset) {\n\t\tvarDecls.push('$offset: Int')\n\t\tqueryArgs.push(`offset: $offset`)\n\t}\n\tif (args.orderBy) {\n\t\tvarDecls.push(`$orderBy: [${orderByType}!]`)\n\t\tqueryArgs.push(`orderBy: $orderBy`)\n\t}\n\n\tconst varStr = varDecls.length > 0 ? `(${varDecls.join(', ')})` : ''\n\tconst argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : ''\n\n\treturn `\n\t\tquery GetRecords${varStr} {\n\t\t\t${connectionName}${argsStr} {\n\t\t\t\tnodes {\n\t\t\t\t${fieldNames}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t`\n}\n\n/**\n * Extract a single record from a PostGraphile query result using the record field name.\n * @internal\n */\nfunction extractSingleResult(result: unknown, meta: DoctypeMeta, recordFieldName: (t: string) => string): unknown {\n\tconst queryName = recordFieldName(meta.tableName!)\n\treturn (result as Record<string, unknown>)[queryName]\n}\n\n/**\n * Extract the list of nodes from a PostGraphile connection query result.\n * Returns an empty array if the connection field is absent.\n * @internal\n */\nfunction extractListResult(result: unknown, meta: DoctypeMeta, connectionFieldName: (t: string) => string): unknown[] {\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst connection = (result as Record<string, unknown>)[connectionName] as {\n\t\tnodes: unknown[]\n\t}\n\treturn connection?.nodes ?? []\n}\n\n// =============================================================================\n// Exported for testing and advanced usage\n// =============================================================================\n\nexport {\n\tdefaultRecordFieldName,\n\tdefaultConnectionFieldName,\n\tdefaultOrderByTypeName,\n\tdefaultRecordArgName,\n\tdefaultRecordArgType,\n\tbuildRecordQuery,\n\tbuildListQuery,\n\tqueryableFieldNames,\n\tRELATION_FIELDTYPES,\n\textractSingleResult,\n\textractListResult,\n}\n"],"names":["doctypeRegistry","DoctypeValidationError","file","errors","errorMessages","e","loadDoctypes","dir","options","entries","readdirSync","entry","fullPath","join","statSync","loadDoctypeFile","filePath","content","readFileSync","data","err","parseError","result","validateDoctype","doctype","parseDoctype","loadDoctypesFromObject","doctypes","name","withName","getMeta","getAllMeta","hasMeta","clearRegistry","validateReferences","field","handlerRegistry","registerHandler","handler","getHandler","hasHandler","clearHandlers","validateRequiredFields","args","context","record","missing","validateFieldTypes","value","error","validateFieldValue","fieldname","fieldtype","noop","builtinHandlers","registerBuiltinHandlers","createStonecropPlugin","recordFieldName","defaultRecordFieldName","connectionFieldName","defaultConnectionFieldName","orderByTypeName","defaultOrderByTypeName","recordArgName","defaultRecordArgName","recordArgType","defaultRecordArgType","extendSchema","gql","_","$doctype","lambda","constant","$id","loadOne","object","specs","spec","meta","query","buildRecordQuery","extractSingleResult","$filters","$orderBy","$limit","$offset","buildListQuery","extractListResult","$action","$actionArgs","actionDef","actionContext","tableName","singular","pluralize","snakeToCamel","toPascalCase","_tableName","RELATION_FIELDTYPES","queryableFieldNames","f","fieldNames","queryName","argName","argType","connectionName","orderByType","varDecls","queryArgs","varStr","argsStr"],"mappings":"0PAMMA,MAAgD,IAM/C,MAAMC,UAA+B,KAAM,CACjD,YAEiBC,EAEAC,EACf,CACD,MAAMC,EAAgBD,EAAO,IAAIE,GAAK,KAAKA,EAAE,KAAK,KAAK,GAAG,CAAC,KAAKA,EAAE,OAAO,EAAE,EAAE,KAAK;AAAA,CAAI,EACtF,MAAM,iCAAiCH,CAAI;AAAA,EAAME,CAAa,EAAE,EALhD,KAAA,KAAAF,EAEA,KAAA,OAAAC,EAIhB,KAAK,KAAO,wBACb,CACD,CAmBO,SAASG,EAAaC,EAAaC,EAA+B,GAAU,CAClF,MAAMC,EAAUC,EAAAA,YAAYH,CAAG,EAE/B,UAAWI,KAASF,EAAS,CAC5B,MAAMG,EAAWC,EAAAA,KAAKN,EAAKI,CAAK,EACnBG,EAAAA,SAASF,CAAQ,EAErB,cACRN,EAAaM,EAAUJ,CAAO,EACpBG,EAAM,SAAS,OAAO,GAChCI,EAAgBH,EAAUJ,CAAO,CAEnC,CACD,CAKA,SAASO,EAAgBC,EAAkBR,EAAoC,CAC9E,MAAMS,EAAUC,EAAAA,aAAaF,EAAU,OAAO,EAC9C,IAAIG,EAEJ,GAAI,CACHA,EAAO,KAAK,MAAMF,CAAO,CAC1B,OAASG,EAAK,CACb,MAAMC,EAA8B,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