@stonecrop/graphql-middleware 0.8.9 → 0.8.10

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.
@@ -62,6 +62,26 @@ export declare type ActionDefinition = z.infer<typeof ActionDefinition>;
62
62
  */
63
63
  export declare type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
64
64
 
65
+ /**
66
+ * Build a GraphQL connection query to fetch a list of records.
67
+ * Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
68
+ * avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
69
+ * Excludes Link and Doctype relation fields from the selection set.
70
+ * @internal
71
+ */
72
+ export declare function buildListQuery(meta: DoctypeMeta, args: {
73
+ limit?: number;
74
+ offset?: number;
75
+ orderBy?: string;
76
+ }, connectionFieldName: (t: string) => string, orderByTypeName: (t: string) => string): string;
77
+
78
+ /**
79
+ * Build a GraphQL query to fetch a single record by ID.
80
+ * Excludes Link and Doctype relation fields from the selection set.
81
+ * @internal
82
+ */
83
+ export declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string): string;
84
+
65
85
  /**
66
86
  * Built-in handlers available for registration
67
87
  * @public
@@ -179,6 +199,12 @@ export declare function convertGraphQLSchema(source: IntrospectionSource, option
179
199
  */
180
200
  export declare const createStonecropPlugin: (options: StonecropPluginOptions) => GraphileConfig_2.Plugin;
181
201
 
202
+ /**
203
+ * Amber default: sales_orders → allSalesOrders
204
+ * @internal
205
+ */
206
+ export declare function defaultConnectionFieldName(tableName: string): string;
207
+
182
208
  /**
183
209
  * Default heuristic to filter fields on entity types.
184
210
  * Skips internal fields that don't represent meaningful data.
@@ -208,6 +234,20 @@ export declare function defaultIsEntityField(fieldName: string, _field: GraphQLF
208
234
  */
209
235
  export declare function defaultIsEntityType(typeName: string, type: GraphQLObjectType): boolean;
210
236
 
237
+ /**
238
+ * Amber default: sales_orders → SalesOrdersOrderBy
239
+ * @internal
240
+ */
241
+ export declare function defaultOrderByTypeName(tableName: string): string;
242
+
243
+ /**
244
+ * Amber default: sales_orders → salesOrderById
245
+ * Uses `pluralize` for proper singularization of irregular plurals.
246
+ * Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.
247
+ * @internal
248
+ */
249
+ export declare function defaultRecordFieldName(tableName: string): string;
250
+
211
251
  /**
212
252
  * Doctype metadata - complete definition of a doctype
213
253
  * @public
@@ -839,6 +879,13 @@ export declare function parseField(data: unknown): FieldMeta;
839
879
  */
840
880
  export declare function pascalToSnake(pascal: string): string;
841
881
 
882
+ /**
883
+ * Filter fields to only those directly queryable as scalars, excluding Link and Doctype
884
+ * relation fields that require GraphQL sub-selections.
885
+ * @internal
886
+ */
887
+ export declare function queryableFieldNames(meta: DoctypeMeta): string;
888
+
842
889
  /**
843
890
  * Register all built-in handlers
844
891
  * @public
@@ -853,6 +900,13 @@ export declare function registerBuiltinHandlers(): void;
853
900
  */
854
901
  export declare function registerHandler(name: string, handler: ActionHandler): void;
855
902
 
903
+ /**
904
+ * Fieldtypes that map to GraphQL object/connection types and require sub-selections.
905
+ * These fields are excluded from generated query field selections.
906
+ * @internal
907
+ */
908
+ export declare const RELATION_FIELDTYPES: Set<string>;
909
+
856
910
  /**
857
911
  * Route context for identifying what doctype/record we're working with
858
912
  * @public
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@stonecrop/schema"),O=require("node:fs"),q=require("node:path"),D=require("postgraphile/utils"),y=require("postgraphile/grafast"),p=new Map;class h extends Error{constructor(e,r){const o=r.map(n=>` ${n.path.join(".")}: ${n.message}`).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@stonecrop/schema"),O=require("node:fs"),L=require("node:path"),N=require("postgraphile/utils"),f=require("postgraphile/grafast"),B=require("pluralize"),p=new Map;class h extends Error{constructor(e,r){const a=r.map(n=>` ${n.path.join(".")}: ${n.message}`).join(`
2
2
  `);super(`Invalid doctype definition in ${e}:
3
- ${o}`),this.file=e,this.errors=r,this.name="DoctypeValidationError"}}function j(t,e={}){const r=O.readdirSync(t);for(const o of r){const n=q.join(t,o);O.statSync(n).isDirectory()?j(n,e):o.endsWith(".json")&&F(n,e)}}function F(t,e){const r=O.readFileSync(t,"utf-8");let o;try{o=JSON.parse(r)}catch(i){const s={path:[],message:`Invalid JSON: ${i instanceof Error?i.message:String(i)}`};if(e.continueOnError){e.onError?.(t,[s]);return}throw new h(t,[s])}const n=a.validateDoctype(o);if(!n.success){if(e.continueOnError){e.onError?.(t,n.errors);return}throw new h(t,n.errors)}const c=a.parseDoctype(o);p.set(c.name,c)}function C(t,e={}){for(const[r,o]of Object.entries(t)){const n={...o,name:r},c=a.validateDoctype(n);if(!c.success){if(e.continueOnError){e.onError?.(r,c.errors);continue}throw new h(r,c.errors)}const i=a.parseDoctype(n);p.set(i.name,i)}}function b(t){return p.get(t)}function M(){return Array.from(p.values())}function T(t){return p.has(t)}function E(){p.clear()}function B(){const t=[];for(const e of p.values()){e.inherits&&!p.has(e.inherits)&&t.push({path:[e.name,"inherits"],message:`References unknown doctype: ${e.inherits}`}),e.listDoctype&&!p.has(e.listDoctype)&&t.push({path:[e.name,"listDoctype"],message:`References unknown doctype: ${e.listDoctype}`}),e.parentDoctype&&!p.has(e.parentDoctype)&&t.push({path:[e.name,"parentDoctype"],message:`References unknown doctype: ${e.parentDoctype}`});for(const r of e.fields)r.fieldtype==="Link"&&typeof r.options=="string"&&(p.has(r.options)||t.push({path:[e.name,"fields",r.fieldname,"options"],message:`Link references unknown doctype: ${r.options}`}))}return t}const S=new Map;function N(t,e){S.set(t,e)}function R(t){return S.get(t)}function L(t){return S.has(t)}function _(){S.clear()}const x=async(t,e)=>{const[r]=t,{doctype:o}=e,n=[];for(const c of o.fields)c.required&&(r[c.fieldname]===void 0||r[c.fieldname]===null)&&n.push(c.label??c.fieldname);if(n.length>0)throw new Error(`Missing required fields: ${n.join(", ")}`);return{valid:!0}},I=async(t,e)=>{const[r]=t,{doctype:o}=e,n=[];for(const c of o.fields){const i=r[c.fieldname];if(i==null)continue;const s=J(c.fieldname,i,c.fieldtype);s&&n.push(s)}if(n.length>0)throw new Error(`Field type validation failed:
3
+ ${a}`),this.file=e,this.errors=r,this.name="DoctypeValidationError"}}function j(t,e={}){const r=O.readdirSync(t);for(const a of r){const n=L.join(t,a);O.statSync(n).isDirectory()?j(n,e):a.endsWith(".json")&&I(n,e)}}function I(t,e){const r=O.readFileSync(t,"utf-8");let a;try{a=JSON.parse(r)}catch(i){const s={path:[],message:`Invalid JSON: ${i instanceof Error?i.message:String(i)}`};if(e.continueOnError){e.onError?.(t,[s]);return}throw new h(t,[s])}const n=o.validateDoctype(a);if(!n.success){if(e.continueOnError){e.onError?.(t,n.errors);return}throw new h(t,n.errors)}const c=o.parseDoctype(a);p.set(c.name,c)}function _(t,e={}){for(const[r,a]of Object.entries(t)){const n={...a,name:r},c=o.validateDoctype(n);if(!c.success){if(e.continueOnError){e.onError?.(r,c.errors);continue}throw new h(r,c.errors)}const i=o.parseDoctype(n);p.set(i.name,i)}}function b(t){return p.get(t)}function M(){return Array.from(p.values())}function x(t){return p.has(t)}function J(){p.clear()}function H(){const t=[];for(const e of p.values()){e.inherits&&!p.has(e.inherits)&&t.push({path:[e.name,"inherits"],message:`References unknown doctype: ${e.inherits}`}),e.listDoctype&&!p.has(e.listDoctype)&&t.push({path:[e.name,"listDoctype"],message:`References unknown doctype: ${e.listDoctype}`}),e.parentDoctype&&!p.has(e.parentDoctype)&&t.push({path:[e.name,"parentDoctype"],message:`References unknown doctype: ${e.parentDoctype}`});for(const r of e.fields)r.fieldtype==="Link"&&typeof r.options=="string"&&(p.has(r.options)||t.push({path:[e.name,"fields",r.fieldname,"options"],message:`Link references unknown doctype: ${r.options}`}))}return t}const S=new Map;function R(t,e){S.set(t,e)}function P(t){return S.get(t)}function Q(t){return S.has(t)}function v(){S.clear()}const G=async(t,e)=>{const[r]=t,{doctype:a}=e,n=[];for(const c of a.fields)c.required&&(r[c.fieldname]===void 0||r[c.fieldname]===null)&&n.push(c.label??c.fieldname);if(n.length>0)throw new Error(`Missing required fields: ${n.join(", ")}`);return{valid:!0}},W=async(t,e)=>{const[r]=t,{doctype:a}=e,n=[];for(const c of a.fields){const i=r[c.fieldname];if(i==null)continue;const s=U(c.fieldname,i,c.fieldtype);s&&n.push(s)}if(n.length>0)throw new Error(`Field type validation failed:
4
4
  ${n.join(`
5
- `)}`);return{valid:!0}};function J(t,e,r){switch(r){case"Int":if(typeof e!="number"||!Number.isInteger(e))return`${t}: expected integer, got ${typeof e}`;break;case"Float":case"Decimal":case"Currency":case"Quantity":if(typeof e!="number"&&typeof e!="string")return`${t}: expected number, got ${typeof e}`;break;case"Check":if(typeof e!="boolean")return`${t}: expected boolean, got ${typeof e}`;break;case"Data":case"Text":case"Code":case"Link":if(typeof e!="string")return`${t}: expected string, got ${typeof e}`;break;case"Date":case"Time":case"Datetime":if(typeof e!="string"&&!(e instanceof Date))return`${t}: expected date string or Date, got ${typeof e}`;break;case"JSON":if(typeof e!="object")return`${t}: expected object, got ${typeof e}`;break;case"Table":if(!Array.isArray(e))return`${t}: expected array, got ${typeof e}`;break}return null}const H=async()=>({ok:!0}),A={validateRequiredFields:x,validateFieldTypes:I,noop:H};function G(){for(const[t,e]of Object.entries(A))N(t,e)}const Q=t=>{const e=t.inflection?.recordFieldName??W,r=t.inflection?.connectionFieldName??v,o=t.inflection?.orderByTypeName??U;return D.extendSchema(()=>({typeDefs:D.gql`
5
+ `)}`);return{valid:!0}};function U(t,e,r){switch(r){case"Int":if(typeof e!="number"||!Number.isInteger(e))return`${t}: expected integer, got ${typeof e}`;break;case"Float":case"Decimal":case"Currency":case"Quantity":if(typeof e!="number"&&typeof e!="string")return`${t}: expected number, got ${typeof e}`;break;case"Check":if(typeof e!="boolean")return`${t}: expected boolean, got ${typeof e}`;break;case"Data":case"Text":case"Code":case"Link":if(typeof e!="string")return`${t}: expected string, got ${typeof e}`;break;case"Date":case"Time":case"Datetime":if(typeof e!="string"&&!(e instanceof Date))return`${t}: expected date string or Date, got ${typeof e}`;break;case"JSON":if(typeof e!="object")return`${t}: expected object, got ${typeof e}`;break;case"Table":if(!Array.isArray(e))return`${t}: expected array, got ${typeof e}`;break}return null}const V=async()=>({ok:!0}),A={validateRequiredFields:G,validateFieldTypes:W,noop:V};function Y(){for(const[t,e]of Object.entries(A))R(t,e)}const K=t=>{const e=t.inflection?.recordFieldName??F,r=t.inflection?.connectionFieldName??k,a=t.inflection?.orderByTypeName??q;return N.extendSchema(()=>({typeDefs:N.gql`
6
6
  type StonecropFieldMeta {
7
7
  fieldname: String!
8
8
  fieldtype: String!
@@ -67,23 +67,22 @@ ${n.join(`
67
67
  extend type Mutation {
68
68
  stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
69
69
  }
70
- `,objects:{Query:{plans:{stonecropMeta(n,{$doctype:c}){return y.lambda(c,i=>b(i)??null)},stonecropAllMeta(){return y.constant(M())},stonecropRecord(n,{$doctype:c,$id:i}){return y.loadOne(y.object({doctype:c,id:i}),async s=>await Promise.all(s.map(async u=>{const d=b(u.doctype);if(!d)throw new Error(`Unknown doctype: ${u.doctype}`);if(!d.tableName)throw new Error(`Doctype ${u.doctype} has no table mapping`);const f=V(d,e),l=await t.executor.query(f,{id:u.id});return{data:Y(l,d,e),doctype:u.doctype}})))},stonecropRecords(n,{$doctype:c,$filters:i,$orderBy:s,$limit:u,$offset:d}){return y.loadOne(y.object({doctype:c,filters:i,orderBy:s,limit:u,offset:d}),async f=>await Promise.all(f.map(async l=>{const m=b(l.doctype);if(!m)throw new Error(`Unknown doctype: ${l.doctype}`);if(!m.tableName)throw new Error(`Doctype ${l.doctype} has no table mapping`);const $=K(m,{limit:l.limit,offset:l.offset,orderBy:l.orderBy},r,o),g=await t.executor.query($,{limit:l.limit,offset:l.offset,orderBy:l.orderBy}),w=z(g,m,r);return{data:w,doctype:l.doctype,count:w.length}})))}}},Mutation:{plans:{stonecropAction(n,{$doctype:c,$action:i,$args:s}){return y.loadOne(y.object({doctype:c,action:i,actionArgs:s}),async u=>await Promise.all(u.map(async d=>{const f=b(d.doctype);if(!f)return{success:!1,data:null,error:`Unknown doctype: ${d.doctype}`};const l=f.workflow?.actions?.[d.action];if(!l)return{success:!1,data:null,error:`Unknown action: ${d.action} on ${d.doctype}`};const m=R(l.handler);if(!m)return{success:!1,data:null,error:`Handler not registered: ${l.handler}`};const $={doctype:f,executor:t.executor};try{return{success:!0,data:await m(d.actionArgs??[],$),error:null}}catch(g){return{success:!1,data:null,error:g instanceof Error?g.message:String(g)}}})))}}}}}))};function P(t){return t.replace(/_([a-z])/g,(e,r)=>r.toUpperCase())}function k(t){const e=P(t);return e.charAt(0).toUpperCase()+e.slice(1)}function W(t){const e=t.replace(/s$/,"");return`${P(e)}ById`}function v(t){return`all${k(t)}`}function U(t){return`${k(t)}OrderBy`}function V(t,e){const r=t.fields.map(n=>n.fieldname).join(`
71
- `);return`
70
+ `,objects:{Query:{plans:{stonecropMeta(n,{$doctype:c}){return f.lambda(c,i=>b(i)??null)},stonecropAllMeta(){return f.constant(M())},stonecropRecord(n,{$doctype:c,$id:i}){return f.loadOne(f.object({doctype:c,id:i}),async s=>await Promise.all(s.map(async d=>{const u=b(d.doctype);if(!u)throw new Error(`Unknown doctype: ${d.doctype}`);if(!u.tableName)throw new Error(`Doctype ${d.doctype} has no table mapping`);const y=E(u,e),l=await t.executor.query(y,{id:d.id});return{data:z(l,u,e),doctype:d.doctype}})))},stonecropRecords(n,{$doctype:c,$filters:i,$orderBy:s,$limit:d,$offset:u}){return f.loadOne(f.object({doctype:c,filters:i,orderBy:s,limit:d,offset:u}),async y=>await Promise.all(y.map(async l=>{const m=b(l.doctype);if(!m)throw new Error(`Unknown doctype: ${l.doctype}`);if(!m.tableName)throw new Error(`Doctype ${l.doctype} has no table mapping`);const $=C(m,{limit:l.limit,offset:l.offset,orderBy:l.orderBy},r,a),g=await t.executor.query($,{limit:l.limit,offset:l.offset,orderBy:l.orderBy}),D=X(g,m,r);return{data:D,doctype:l.doctype,count:D.length}})))}}},Mutation:{plans:{stonecropAction(n,{$doctype:c,$action:i,$args:s}){return f.loadOne(f.object({doctype:c,action:i,actionArgs:s}),async d=>await Promise.all(d.map(async u=>{const y=b(u.doctype);if(!y)return{success:!1,data:null,error:`Unknown doctype: ${u.doctype}`};const l=y.workflow?.actions?.[u.action];if(!l)return{success:!1,data:null,error:`Unknown action: ${u.action} on ${u.doctype}`};const m=P(l.handler);if(!m)return{success:!1,data:null,error:`Handler not registered: ${l.handler}`};const $={doctype:y,executor:t.executor};try{return{success:!0,data:await m(u.actionArgs??[],$),error:null}}catch(g){return{success:!1,data:null,error:g instanceof Error?g.message:String(g)}}})))}}}}}))};function F(t){const e=B.singular(t);return`${o.snakeToCamel(e)}ById`}function k(t){return`all${o.toPascalCase(t)}`}function q(t){return`${o.toPascalCase(t)}OrderBy`}const T=new Set(["Link","Doctype"]);function w(t){return t.fields.filter(e=>!T.has(e.fieldtype)).map(e=>e.fieldname).join(`
71
+ `)}function E(t,e){const r=w(t);return`
72
72
  query GetRecord($id: UUID!) {
73
73
  ${e(t.tableName)}(id: $id) {
74
74
  ${r}
75
75
  }
76
76
  }
77
- `}function K(t,e,r,o){const n=t.fields.map(d=>d.fieldname).join(`
78
- `),c=r(t.tableName),i=o(t.tableName),s=[];e.limit&&s.push("first: $limit"),e.offset&&s.push("offset: $offset"),e.orderBy&&s.push("orderBy: $orderBy");const u=s.length>0?`(${s.join(", ")})`:"";return`
79
- query GetRecords($limit: Int, $offset: Int, $orderBy: [${i}!]) {
80
- ${c}${u} {
77
+ `}function C(t,e,r,a){const n=w(t),c=r(t.tableName),i=a(t.tableName),s=[],d=[];e.limit&&(s.push("$limit: Int"),d.push("first: $limit")),e.offset&&(s.push("$offset: Int"),d.push("offset: $offset")),e.orderBy&&(s.push(`$orderBy: [${i}!]`),d.push("orderBy: $orderBy"));const u=s.length>0?`(${s.join(", ")})`:"",y=d.length>0?`(${d.join(", ")})`:"";return`
78
+ query GetRecords${u} {
79
+ ${c}${y} {
81
80
  nodes {
82
81
  ${n}
83
82
  }
84
83
  }
85
84
  }
86
- `}function Y(t,e,r){const o=r(e.tableName);return t[o]}function z(t,e,r){const o=r(e.tableName);return t[o]?.nodes??[]}class X{endpoint;headers;metaCache=new Map;constructor(e){this.endpoint=e.endpoint,this.headers={"Content-Type":"application/json",...e.headers}}async query(e,r){const n=await(await fetch(this.endpoint,{method:"POST",headers:this.headers,body:JSON.stringify({query:e,variables:r})})).json();if(n.errors?.length)throw new Error(n.errors[0].message);return n.data}async mutate(e,r){return this.query(e,r)}async getMeta(e){const r=this.metaCache.get(e.doctype);if(r)return r;const o=await this.query(`
85
+ `}function z(t,e,r){const a=r(e.tableName);return t[a]}function X(t,e,r){const a=r(e.tableName);return t[a]?.nodes??[]}class Z{endpoint;headers;metaCache=new Map;constructor(e){this.endpoint=e.endpoint,this.headers={"Content-Type":"application/json",...e.headers}}async query(e,r){const n=await(await fetch(this.endpoint,{method:"POST",headers:this.headers,body:JSON.stringify({query:e,variables:r})})).json();if(n.errors?.length)throw new Error(n.errors[0].message);return n.data}async mutate(e,r){return this.query(e,r)}async getMeta(e){const r=this.metaCache.get(e.doctype);if(r)return r;const a=await this.query(`
87
86
  query GetMeta($doctype: String!) {
88
87
  stonecropMeta(doctype: $doctype) {
89
88
  name
@@ -109,7 +108,7 @@ ${n.join(`
109
108
  parentDoctype
110
109
  }
111
110
  }
112
- `,{doctype:e.doctype});return o.stonecropMeta&&this.metaCache.set(e.doctype,o.stonecropMeta),o.stonecropMeta}async getAllMeta(){const e=await this.query(`
111
+ `,{doctype:e.doctype});return a.stonecropMeta&&this.metaCache.set(e.doctype,a.stonecropMeta),a.stonecropMeta}async getAllMeta(){const e=await this.query(`
113
112
  query GetAllMeta {
114
113
  stonecropAllMeta {
115
114
  name
@@ -160,7 +159,7 @@ ${n.join(`
160
159
  count
161
160
  }
162
161
  }
163
- `,{doctype:e.name,...r})).stonecropRecords.data}async runAction(e,r,o){return(await this.query(`
162
+ `,{doctype:e.name,...r})).stonecropRecords.data}async runAction(e,r,a){return(await this.query(`
164
163
  mutation RunAction($doctype: String!, $action: String!, $args: JSON) {
165
164
  stonecropAction(doctype: $doctype, action: $action, args: $args) {
166
165
  success
@@ -168,5 +167,5 @@ ${n.join(`
168
167
  error
169
168
  }
170
169
  }
171
- `,{doctype:e.name,action:r,args:o})).stonecropAction}clearMetaCache(){this.metaCache.clear()}}Object.defineProperty(exports,"ActionDefinition",{enumerable:!0,get:()=>a.ActionDefinition});Object.defineProperty(exports,"DoctypeMeta",{enumerable:!0,get:()=>a.DoctypeMeta});Object.defineProperty(exports,"FieldMeta",{enumerable:!0,get:()=>a.FieldMeta});Object.defineProperty(exports,"FieldOptions",{enumerable:!0,get:()=>a.FieldOptions});Object.defineProperty(exports,"FieldValidation",{enumerable:!0,get:()=>a.FieldValidation});Object.defineProperty(exports,"GQL_SCALAR_MAP",{enumerable:!0,get:()=>a.GQL_SCALAR_MAP});Object.defineProperty(exports,"StonecropFieldType",{enumerable:!0,get:()=>a.StonecropFieldType});Object.defineProperty(exports,"TYPE_MAP",{enumerable:!0,get:()=>a.TYPE_MAP});Object.defineProperty(exports,"WELL_KNOWN_SCALARS",{enumerable:!0,get:()=>a.WELL_KNOWN_SCALARS});Object.defineProperty(exports,"WorkflowMeta",{enumerable:!0,get:()=>a.WorkflowMeta});Object.defineProperty(exports,"camelToLabel",{enumerable:!0,get:()=>a.camelToLabel});Object.defineProperty(exports,"camelToSnake",{enumerable:!0,get:()=>a.camelToSnake});Object.defineProperty(exports,"classifyFieldType",{enumerable:!0,get:()=>a.classifyFieldType});Object.defineProperty(exports,"convertGraphQLSchema",{enumerable:!0,get:()=>a.convertGraphQLSchema});Object.defineProperty(exports,"defaultIsEntityField",{enumerable:!0,get:()=>a.defaultIsEntityField});Object.defineProperty(exports,"defaultIsEntityType",{enumerable:!0,get:()=>a.defaultIsEntityType});Object.defineProperty(exports,"getDefaultComponent",{enumerable:!0,get:()=>a.getDefaultComponent});Object.defineProperty(exports,"parseDoctype",{enumerable:!0,get:()=>a.parseDoctype});Object.defineProperty(exports,"parseField",{enumerable:!0,get:()=>a.parseField});Object.defineProperty(exports,"pascalToSnake",{enumerable:!0,get:()=>a.pascalToSnake});Object.defineProperty(exports,"snakeToCamel",{enumerable:!0,get:()=>a.snakeToCamel});Object.defineProperty(exports,"snakeToLabel",{enumerable:!0,get:()=>a.snakeToLabel});Object.defineProperty(exports,"toPascalCase",{enumerable:!0,get:()=>a.toPascalCase});Object.defineProperty(exports,"toSlug",{enumerable:!0,get:()=>a.toSlug});Object.defineProperty(exports,"validateDoctype",{enumerable:!0,get:()=>a.validateDoctype});Object.defineProperty(exports,"validateField",{enumerable:!0,get:()=>a.validateField});exports.DoctypeValidationError=h;exports.StonecropClient=X;exports.builtinHandlers=A;exports.clearHandlers=_;exports.clearRegistry=E;exports.createStonecropPlugin=Q;exports.getAllMeta=M;exports.getHandler=R;exports.getMeta=b;exports.hasHandler=L;exports.hasMeta=T;exports.loadDoctypes=j;exports.loadDoctypesFromObject=C;exports.registerBuiltinHandlers=G;exports.registerHandler=N;exports.validateReferences=B;
170
+ `,{doctype:e.name,action:r,args:a})).stonecropAction}clearMetaCache(){this.metaCache.clear()}}Object.defineProperty(exports,"ActionDefinition",{enumerable:!0,get:()=>o.ActionDefinition});Object.defineProperty(exports,"DoctypeMeta",{enumerable:!0,get:()=>o.DoctypeMeta});Object.defineProperty(exports,"FieldMeta",{enumerable:!0,get:()=>o.FieldMeta});Object.defineProperty(exports,"FieldOptions",{enumerable:!0,get:()=>o.FieldOptions});Object.defineProperty(exports,"FieldValidation",{enumerable:!0,get:()=>o.FieldValidation});Object.defineProperty(exports,"GQL_SCALAR_MAP",{enumerable:!0,get:()=>o.GQL_SCALAR_MAP});Object.defineProperty(exports,"StonecropFieldType",{enumerable:!0,get:()=>o.StonecropFieldType});Object.defineProperty(exports,"TYPE_MAP",{enumerable:!0,get:()=>o.TYPE_MAP});Object.defineProperty(exports,"WELL_KNOWN_SCALARS",{enumerable:!0,get:()=>o.WELL_KNOWN_SCALARS});Object.defineProperty(exports,"WorkflowMeta",{enumerable:!0,get:()=>o.WorkflowMeta});Object.defineProperty(exports,"camelToLabel",{enumerable:!0,get:()=>o.camelToLabel});Object.defineProperty(exports,"camelToSnake",{enumerable:!0,get:()=>o.camelToSnake});Object.defineProperty(exports,"classifyFieldType",{enumerable:!0,get:()=>o.classifyFieldType});Object.defineProperty(exports,"convertGraphQLSchema",{enumerable:!0,get:()=>o.convertGraphQLSchema});Object.defineProperty(exports,"defaultIsEntityField",{enumerable:!0,get:()=>o.defaultIsEntityField});Object.defineProperty(exports,"defaultIsEntityType",{enumerable:!0,get:()=>o.defaultIsEntityType});Object.defineProperty(exports,"getDefaultComponent",{enumerable:!0,get:()=>o.getDefaultComponent});Object.defineProperty(exports,"parseDoctype",{enumerable:!0,get:()=>o.parseDoctype});Object.defineProperty(exports,"parseField",{enumerable:!0,get:()=>o.parseField});Object.defineProperty(exports,"pascalToSnake",{enumerable:!0,get:()=>o.pascalToSnake});Object.defineProperty(exports,"snakeToCamel",{enumerable:!0,get:()=>o.snakeToCamel});Object.defineProperty(exports,"snakeToLabel",{enumerable:!0,get:()=>o.snakeToLabel});Object.defineProperty(exports,"toPascalCase",{enumerable:!0,get:()=>o.toPascalCase});Object.defineProperty(exports,"toSlug",{enumerable:!0,get:()=>o.toSlug});Object.defineProperty(exports,"validateDoctype",{enumerable:!0,get:()=>o.validateDoctype});Object.defineProperty(exports,"validateField",{enumerable:!0,get:()=>o.validateField});exports.DoctypeValidationError=h;exports.RELATION_FIELDTYPES=T;exports.StonecropClient=Z;exports.buildListQuery=C;exports.buildRecordQuery=E;exports.builtinHandlers=A;exports.clearHandlers=v;exports.clearRegistry=J;exports.createStonecropPlugin=K;exports.defaultConnectionFieldName=k;exports.defaultOrderByTypeName=q;exports.defaultRecordFieldName=F;exports.getAllMeta=M;exports.getHandler=P;exports.getMeta=b;exports.hasHandler=Q;exports.hasMeta=x;exports.loadDoctypes=j;exports.loadDoctypesFromObject=_;exports.queryableFieldNames=w;exports.registerBuiltinHandlers=Y;exports.registerHandler=R;exports.validateReferences=H;
172
171
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/registry/doctypes.ts","../src/registry/actions.ts","../src/plugin/postgraphile.ts","../src/client/index.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '../types'\nimport type { DoctypeMeta, ValidationError } from '../types'\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 { ActionHandler, ActionContext, DoctypeMeta } 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 { getHandler } from '../registry/actions'\nimport { getMeta, getAllMeta } from '../registry/doctypes'\nimport type { ActionContext, DoctypeMeta, 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\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\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)\n\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, { id: spec.id })\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// =============================================================================\n\nfunction toCamelCase(str: string): string {\n\treturn str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())\n}\n\nfunction toPascalCase(str: string): string {\n\tconst camel = toCamelCase(str)\n\treturn camel.charAt(0).toUpperCase() + camel.slice(1)\n}\n\n/** Amber default: sales_orders → salesOrderById */\nfunction defaultRecordFieldName(tableName: string): string {\n\t// sales_orders -> salesOrder (remove trailing 's' and camelCase) + ById\n\tconst singular = tableName.replace(/s$/, '')\n\treturn `${toCamelCase(singular)}ById`\n}\n\n/** Amber default: sales_orders → allSalesOrders */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/** Amber default: sales_orders → SalesOrdersOrderBy */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\n}\n\n// =============================================================================\n// Query builders — generate GraphQL queries to send to the underlying schema\n// =============================================================================\n\nfunction buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string): string {\n\tconst fieldNames = meta.fields.map(f => f.fieldname).join('\\n ')\n\tconst queryName = recordFieldName(meta.tableName!)\n\n\treturn `\n\t\tquery GetRecord($id: UUID!) {\n\t\t\t${queryName}(id: $id) {\n\t\t\t\t${fieldNames}\n\t\t\t}\n\t\t}\n\t`\n}\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 = meta.fields.map(f => f.fieldname).join('\\n ')\n\tconst connectionName = connectionFieldName(meta.tableName!)\n\tconst orderByType = orderByTypeName(meta.tableName!)\n\n\tconst queryArgs: string[] = []\n\tif (args.limit) queryArgs.push(`first: $limit`)\n\tif (args.offset) queryArgs.push(`offset: $offset`)\n\tif (args.orderBy) queryArgs.push(`orderBy: $orderBy`)\n\n\tconst argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : ''\n\n\treturn `\n\t\tquery GetRecords($limit: Int, $offset: Int, $orderBy: [${orderByType}!]) {\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\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\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","import type { DoctypeMeta, RouteContext, GraphQLExecutor } from '../types'\n\n/**\n * Options for creating a Stonecrop client\n * @public\n */\nexport interface StonecropClientOptions {\n\t/** GraphQL endpoint URL */\n\tendpoint: string\n\t/** Additional HTTP headers to include in requests */\n\theaders?: Record<string, string>\n}\n\n/**\n * Client for interacting with Stonecrop GraphQL API\n * @public\n */\nexport class StonecropClient implements GraphQLExecutor {\n\tprivate endpoint: string\n\tprivate headers: Record<string, string>\n\tprivate metaCache: Map<string, DoctypeMeta> = new Map()\n\n\tconstructor(options: StonecropClientOptions) {\n\t\tthis.endpoint = options.endpoint\n\t\tthis.headers = {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...options.headers,\n\t\t}\n\t}\n\n\t/**\n\t * Execute a GraphQL query\n\t * @param query - GraphQL query string\n\t * @param variables - Query variables\n\t */\n\tasync query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T> {\n\t\tconst response = await fetch(this.endpoint, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: this.headers,\n\t\t\tbody: JSON.stringify({ query, variables }),\n\t\t})\n\n\t\tconst json = (await response.json()) as {\n\t\t\tdata?: T\n\t\t\terrors?: Array<{ message: string }>\n\t\t}\n\n\t\tif (json.errors?.length) {\n\t\t\tthrow new Error(json.errors[0].message)\n\t\t}\n\n\t\treturn json.data as T\n\t}\n\n\t/**\n\t * Execute a GraphQL mutation\n\t * @param mutation - GraphQL mutation string\n\t * @param variables - Mutation variables\n\t */\n\tasync mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T> {\n\t\treturn this.query<T>(mutation, variables)\n\t}\n\n\t/**\n\t * Get doctype metadata\n\t * @param context - Route context containing doctype name\n\t */\n\tasync getMeta(context: RouteContext): Promise<DoctypeMeta | null> {\n\t\tconst cached = this.metaCache.get(context.doctype)\n\t\tif (cached) return cached\n\n\t\tconst result = await this.query<{ stonecropMeta: DoctypeMeta | null }>(\n\t\t\t`\n\t\t\tquery GetMeta($doctype: String!) {\n\t\t\t\tstonecropMeta(doctype: $doctype) {\n\t\t\t\t\tname\n\t\t\t\t\tslug\n\t\t\t\t\ttableName\n\t\t\t\t\tfields {\n\t\t\t\t\t\tfieldname\n\t\t\t\t\t\tfieldtype\n\t\t\t\t\t\tcomponent\n\t\t\t\t\t\tlabel\n\t\t\t\t\t\trequired\n\t\t\t\t\t\treadOnly\n\t\t\t\t\t\toptions\n\t\t\t\t\t\tprecision\n\t\t\t\t\t\tscale\n\t\t\t\t\t}\n\t\t\t\t\tworkflow {\n\t\t\t\t\t\tstates\n\t\t\t\t\t\tactions\n\t\t\t\t\t}\n\t\t\t\t\tinherits\n\t\t\t\t\tlistDoctype\n\t\t\t\t\tparentDoctype\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{ doctype: context.doctype }\n\t\t)\n\n\t\tif (result.stonecropMeta) {\n\t\t\tthis.metaCache.set(context.doctype, result.stonecropMeta)\n\t\t}\n\n\t\treturn result.stonecropMeta\n\t}\n\n\t/**\n\t * Get all doctype metadata\n\t */\n\tasync getAllMeta(): Promise<DoctypeMeta[]> {\n\t\tconst result = await this.query<{ stonecropAllMeta: DoctypeMeta[] }>(\n\t\t\t`\n\t\t\tquery GetAllMeta {\n\t\t\t\tstonecropAllMeta {\n\t\t\t\t\tname\n\t\t\t\t\tslug\n\t\t\t\t\ttableName\n\t\t\t\t\tfields {\n\t\t\t\t\t\tfieldname\n\t\t\t\t\t\tfieldtype\n\t\t\t\t\t\tcomponent\n\t\t\t\t\t\tlabel\n\t\t\t\t\t\trequired\n\t\t\t\t\t\treadOnly\n\t\t\t\t\t\toptions\n\t\t\t\t\t\tprecision\n\t\t\t\t\t\tscale\n\t\t\t\t\t}\n\t\t\t\t\tworkflow {\n\t\t\t\t\t\tstates\n\t\t\t\t\t\tactions\n\t\t\t\t\t}\n\t\t\t\t\tinherits\n\t\t\t\t\tlistDoctype\n\t\t\t\t\tparentDoctype\n\t\t\t\t}\n\t\t\t}\n\t\t\t`\n\t\t)\n\n\t\tfor (const meta of result.stonecropAllMeta) {\n\t\t\tthis.metaCache.set(meta.name, meta)\n\t\t}\n\n\t\treturn result.stonecropAllMeta\n\t}\n\n\t/**\n\t * Get a single record by ID\n\t * @param doctype - Doctype metadata\n\t * @param recordId - Record ID to fetch\n\t */\n\tasync getRecord(doctype: DoctypeMeta, recordId: string): Promise<Record<string, unknown> | null> {\n\t\tconst result = await this.query<{\n\t\t\tstonecropRecord: { data: Record<string, unknown> | null }\n\t\t}>(\n\t\t\t`\n\t\t\tquery GetRecord($doctype: String!, $id: String!) {\n\t\t\t\tstonecropRecord(doctype: $doctype, id: $id) {\n\t\t\t\t\tdata\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{ doctype: doctype.name, id: recordId }\n\t\t)\n\n\t\treturn result.stonecropRecord.data\n\t}\n\n\t/**\n\t * Get multiple records with optional filtering and pagination\n\t * @param doctype - Doctype metadata\n\t * @param options - Query options (filters, orderBy, limit, offset)\n\t */\n\tasync getRecords(\n\t\tdoctype: DoctypeMeta,\n\t\toptions?: {\n\t\t\tfilters?: Record<string, unknown>\n\t\t\torderBy?: string\n\t\t\tlimit?: number\n\t\t\toffset?: number\n\t\t}\n\t): Promise<Record<string, unknown>[]> {\n\t\tconst result = await this.query<{\n\t\t\tstonecropRecords: { data: Record<string, unknown>[] }\n\t\t}>(\n\t\t\t`\n\t\t\tquery GetRecords(\n\t\t\t\t$doctype: String!\n\t\t\t\t$filters: JSON\n\t\t\t\t$orderBy: String\n\t\t\t\t$limit: Int\n\t\t\t\t$offset: Int\n\t\t\t) {\n\t\t\t\tstonecropRecords(\n\t\t\t\t\tdoctype: $doctype\n\t\t\t\t\tfilters: $filters\n\t\t\t\t\torderBy: $orderBy\n\t\t\t\t\tlimit: $limit\n\t\t\t\t\toffset: $offset\n\t\t\t\t) {\n\t\t\t\t\tdata\n\t\t\t\t\tcount\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{\n\t\t\t\tdoctype: doctype.name,\n\t\t\t\t...options,\n\t\t\t}\n\t\t)\n\n\t\treturn result.stonecropRecords.data\n\t}\n\n\t/**\n\t * Execute a doctype action\n\t * @param doctype - Doctype metadata\n\t * @param action - Action name to execute\n\t * @param args - Action arguments\n\t */\n\tasync runAction(\n\t\tdoctype: DoctypeMeta,\n\t\taction: string,\n\t\targs?: unknown[]\n\t): Promise<{ success: boolean; data: unknown; error: string | null }> {\n\t\tconst result = await this.query<{\n\t\t\tstonecropAction: { success: boolean; data: unknown; error: string | null }\n\t\t}>(\n\t\t\t`\n\t\t\tmutation RunAction($doctype: String!, $action: String!, $args: JSON) {\n\t\t\t\tstonecropAction(doctype: $doctype, action: $action, args: $args) {\n\t\t\t\t\tsuccess\n\t\t\t\t\tdata\n\t\t\t\t\terror\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{\n\t\t\t\tdoctype: doctype.name,\n\t\t\t\taction,\n\t\t\t\targs,\n\t\t\t}\n\t\t)\n\n\t\treturn result.stonecropAction\n\t}\n\n\t/**\n\t * Clear the cached doctype metadata\n\t */\n\tclearMetaCache(): void {\n\t\tthis.metaCache.clear()\n\t}\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","extendSchema","gql","_","$doctype","lambda","constant","$id","loadOne","object","specs","spec","meta","query","buildRecordQuery","extractSingleResult","$filters","$orderBy","$limit","$offset","buildListQuery","extractListResult","$action","$actionArgs","actionDef","actionContext","toCamelCase","str","letter","toPascalCase","camel","tableName","singular","fieldNames","f","connectionName","orderByType","queryArgs","argsStr","queryName","StonecropClient","variables","json","mutation","cached","recordId","action"],"mappings":"mOAMMA,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,CACnC,KAAM,CAAA,EACN,QAAS,iBAAiBD,aAAe,MAAQA,EAAI,QAAU,OAAOA,CAAG,CAAC,EAAA,EAG3E,GAAIZ,EAAQ,gBAAiB,CAC5BA,EAAQ,UAAUQ,EAAU,CAACK,CAAU,CAAC,EACxC,MACD,CACA,MAAM,IAAIpB,EAAuBe,EAAU,CAACK,CAAU,CAAC,CACxD,CAEA,MAAMC,E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plugin/postgraphile.ts","../src/client/index.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\nimport { parseDoctype, validateDoctype } from '../types'\nimport type { DoctypeMeta, ValidationError } from '../types'\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 { ActionHandler, ActionContext, DoctypeMeta } 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 { ActionContext, DoctypeMeta, 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\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\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)\n\t\t\t\t\t\t\t\t\t\tconst result = await options.executor.query(query, { id: spec.id })\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 * @internal\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 * @internal\n */\nfunction defaultConnectionFieldName(tableName: string): string {\n\treturn `all${toPascalCase(tableName)}`\n}\n\n/**\n * Amber default: sales_orders → SalesOrdersOrderBy\n * @internal\n */\nfunction defaultOrderByTypeName(tableName: string): string {\n\treturn `${toPascalCase(tableName)}OrderBy`\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 * @internal\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 * @internal\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 * @internal\n */\nfunction buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string): string {\n\tconst fieldNames = queryableFieldNames(meta)\n\tconst queryName = recordFieldName(meta.tableName!)\n\n\treturn `\n\t\tquery GetRecord($id: UUID!) {\n\t\t\t${queryName}(id: $id) {\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 * @internal\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\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\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\tbuildRecordQuery,\n\tbuildListQuery,\n\tqueryableFieldNames,\n\tRELATION_FIELDTYPES,\n}\n","import type { DoctypeMeta, RouteContext, GraphQLExecutor } from '../types'\n\n/**\n * Options for creating a Stonecrop client\n * @public\n */\nexport interface StonecropClientOptions {\n\t/** GraphQL endpoint URL */\n\tendpoint: string\n\t/** Additional HTTP headers to include in requests */\n\theaders?: Record<string, string>\n}\n\n/**\n * Client for interacting with Stonecrop GraphQL API\n * @public\n */\nexport class StonecropClient implements GraphQLExecutor {\n\tprivate endpoint: string\n\tprivate headers: Record<string, string>\n\tprivate metaCache: Map<string, DoctypeMeta> = new Map()\n\n\tconstructor(options: StonecropClientOptions) {\n\t\tthis.endpoint = options.endpoint\n\t\tthis.headers = {\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...options.headers,\n\t\t}\n\t}\n\n\t/**\n\t * Execute a GraphQL query\n\t * @param query - GraphQL query string\n\t * @param variables - Query variables\n\t */\n\tasync query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T> {\n\t\tconst response = await fetch(this.endpoint, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: this.headers,\n\t\t\tbody: JSON.stringify({ query, variables }),\n\t\t})\n\n\t\tconst json = (await response.json()) as {\n\t\t\tdata?: T\n\t\t\terrors?: Array<{ message: string }>\n\t\t}\n\n\t\tif (json.errors?.length) {\n\t\t\tthrow new Error(json.errors[0].message)\n\t\t}\n\n\t\treturn json.data as T\n\t}\n\n\t/**\n\t * Execute a GraphQL mutation\n\t * @param mutation - GraphQL mutation string\n\t * @param variables - Mutation variables\n\t */\n\tasync mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T> {\n\t\treturn this.query<T>(mutation, variables)\n\t}\n\n\t/**\n\t * Get doctype metadata\n\t * @param context - Route context containing doctype name\n\t */\n\tasync getMeta(context: RouteContext): Promise<DoctypeMeta | null> {\n\t\tconst cached = this.metaCache.get(context.doctype)\n\t\tif (cached) return cached\n\n\t\tconst result = await this.query<{ stonecropMeta: DoctypeMeta | null }>(\n\t\t\t`\n\t\t\tquery GetMeta($doctype: String!) {\n\t\t\t\tstonecropMeta(doctype: $doctype) {\n\t\t\t\t\tname\n\t\t\t\t\tslug\n\t\t\t\t\ttableName\n\t\t\t\t\tfields {\n\t\t\t\t\t\tfieldname\n\t\t\t\t\t\tfieldtype\n\t\t\t\t\t\tcomponent\n\t\t\t\t\t\tlabel\n\t\t\t\t\t\trequired\n\t\t\t\t\t\treadOnly\n\t\t\t\t\t\toptions\n\t\t\t\t\t\tprecision\n\t\t\t\t\t\tscale\n\t\t\t\t\t}\n\t\t\t\t\tworkflow {\n\t\t\t\t\t\tstates\n\t\t\t\t\t\tactions\n\t\t\t\t\t}\n\t\t\t\t\tinherits\n\t\t\t\t\tlistDoctype\n\t\t\t\t\tparentDoctype\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{ doctype: context.doctype }\n\t\t)\n\n\t\tif (result.stonecropMeta) {\n\t\t\tthis.metaCache.set(context.doctype, result.stonecropMeta)\n\t\t}\n\n\t\treturn result.stonecropMeta\n\t}\n\n\t/**\n\t * Get all doctype metadata\n\t */\n\tasync getAllMeta(): Promise<DoctypeMeta[]> {\n\t\tconst result = await this.query<{ stonecropAllMeta: DoctypeMeta[] }>(\n\t\t\t`\n\t\t\tquery GetAllMeta {\n\t\t\t\tstonecropAllMeta {\n\t\t\t\t\tname\n\t\t\t\t\tslug\n\t\t\t\t\ttableName\n\t\t\t\t\tfields {\n\t\t\t\t\t\tfieldname\n\t\t\t\t\t\tfieldtype\n\t\t\t\t\t\tcomponent\n\t\t\t\t\t\tlabel\n\t\t\t\t\t\trequired\n\t\t\t\t\t\treadOnly\n\t\t\t\t\t\toptions\n\t\t\t\t\t\tprecision\n\t\t\t\t\t\tscale\n\t\t\t\t\t}\n\t\t\t\t\tworkflow {\n\t\t\t\t\t\tstates\n\t\t\t\t\t\tactions\n\t\t\t\t\t}\n\t\t\t\t\tinherits\n\t\t\t\t\tlistDoctype\n\t\t\t\t\tparentDoctype\n\t\t\t\t}\n\t\t\t}\n\t\t\t`\n\t\t)\n\n\t\tfor (const meta of result.stonecropAllMeta) {\n\t\t\tthis.metaCache.set(meta.name, meta)\n\t\t}\n\n\t\treturn result.stonecropAllMeta\n\t}\n\n\t/**\n\t * Get a single record by ID\n\t * @param doctype - Doctype metadata\n\t * @param recordId - Record ID to fetch\n\t */\n\tasync getRecord(doctype: DoctypeMeta, recordId: string): Promise<Record<string, unknown> | null> {\n\t\tconst result = await this.query<{\n\t\t\tstonecropRecord: { data: Record<string, unknown> | null }\n\t\t}>(\n\t\t\t`\n\t\t\tquery GetRecord($doctype: String!, $id: String!) {\n\t\t\t\tstonecropRecord(doctype: $doctype, id: $id) {\n\t\t\t\t\tdata\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{ doctype: doctype.name, id: recordId }\n\t\t)\n\n\t\treturn result.stonecropRecord.data\n\t}\n\n\t/**\n\t * Get multiple records with optional filtering and pagination\n\t * @param doctype - Doctype metadata\n\t * @param options - Query options (filters, orderBy, limit, offset)\n\t */\n\tasync getRecords(\n\t\tdoctype: DoctypeMeta,\n\t\toptions?: {\n\t\t\tfilters?: Record<string, unknown>\n\t\t\torderBy?: string\n\t\t\tlimit?: number\n\t\t\toffset?: number\n\t\t}\n\t): Promise<Record<string, unknown>[]> {\n\t\tconst result = await this.query<{\n\t\t\tstonecropRecords: { data: Record<string, unknown>[] }\n\t\t}>(\n\t\t\t`\n\t\t\tquery GetRecords(\n\t\t\t\t$doctype: String!\n\t\t\t\t$filters: JSON\n\t\t\t\t$orderBy: String\n\t\t\t\t$limit: Int\n\t\t\t\t$offset: Int\n\t\t\t) {\n\t\t\t\tstonecropRecords(\n\t\t\t\t\tdoctype: $doctype\n\t\t\t\t\tfilters: $filters\n\t\t\t\t\torderBy: $orderBy\n\t\t\t\t\tlimit: $limit\n\t\t\t\t\toffset: $offset\n\t\t\t\t) {\n\t\t\t\t\tdata\n\t\t\t\t\tcount\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{\n\t\t\t\tdoctype: doctype.name,\n\t\t\t\t...options,\n\t\t\t}\n\t\t)\n\n\t\treturn result.stonecropRecords.data\n\t}\n\n\t/**\n\t * Execute a doctype action\n\t * @param doctype - Doctype metadata\n\t * @param action - Action name to execute\n\t * @param args - Action arguments\n\t */\n\tasync runAction(\n\t\tdoctype: DoctypeMeta,\n\t\taction: string,\n\t\targs?: unknown[]\n\t): Promise<{ success: boolean; data: unknown; error: string | null }> {\n\t\tconst result = await this.query<{\n\t\t\tstonecropAction: { success: boolean; data: unknown; error: string | null }\n\t\t}>(\n\t\t\t`\n\t\t\tmutation RunAction($doctype: String!, $action: String!, $args: JSON) {\n\t\t\t\tstonecropAction(doctype: $doctype, action: $action, args: $args) {\n\t\t\t\t\tsuccess\n\t\t\t\t\tdata\n\t\t\t\t\terror\n\t\t\t\t}\n\t\t\t}\n\t\t\t`,\n\t\t\t{\n\t\t\t\tdoctype: doctype.name,\n\t\t\t\taction,\n\t\t\t\targs,\n\t\t\t}\n\t\t)\n\n\t\treturn result.stonecropAction\n\t}\n\n\t/**\n\t * Clear the cached doctype metadata\n\t */\n\tclearMetaCache(): void {\n\t\tthis.metaCache.clear()\n\t}\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","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","RELATION_FIELDTYPES","queryableFieldNames","f","fieldNames","connectionName","orderByType","varDecls","queryArgs","varStr","argsStr","queryName","StonecropClient","variables","json","mutation","cached","recordId","action"],"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,CAmB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