@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.
- package/dist/graphql-middleware.d.ts +54 -0
- package/dist/index.cjs +12 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +146 -142
- package/dist/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/plugin/postgraphile.d.ts +49 -1
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.js +68 -19
- package/dist/tests/query-builders.test.d.ts +2 -0
- package/dist/tests/query-builders.test.d.ts.map +1 -0
- package/dist/tests/query-builders.test.js +178 -0
- package/package.json +4 -2
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","../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":";;;;;;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,EAA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A;AAAA,MAoBA;AAAA,QACC,SAASgB,EAAQ;AAAA,QACjB,GAAGhB;AAAA,MAAA;AAAA,IACJ,GAGa,iBAAiB;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,UACLgB,GACAoF,GACAjE,GACqE;AAoBrE,YAnBe,MAAM,KAAK;AAAA,MAGzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASA;AAAA,QACC,SAASnB,EAAQ;AAAA,QACjB,QAAAoF;AAAA,QACA,MAAAjE;AAAA,MAAA;AAAA,IACD,GAGa;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKA,iBAAuB;AACtB,SAAK,UAAU,MAAA;AAAA,EAChB;AACD;"}
|
|
1
|
+
{"version":3,"file":"index.js","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 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":";;;;;;;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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;AAAA,MAGzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASA;AAAA,QACC,SAASnB,EAAQ;AAAA,QACjB,QAAAsF;AAAA,QACA,MAAAnE;AAAA,MAAA;AAAA,IACD,GAGa;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKA,iBAAuB;AACtB,SAAK,UAAU,MAAA;AAAA,EAChB;AACD;"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type { LoadDoctypesOptions } from './registry/doctypes';
|
|
|
6
6
|
export { registerHandler, getHandler, hasHandler, clearHandlers, registerBuiltinHandlers, builtinHandlers, } from './registry/actions';
|
|
7
7
|
export { createStonecropPlugin } from './plugin/postgraphile';
|
|
8
8
|
export type { StonecropPluginOptions, StonecropInflectionConfig } from './plugin/postgraphile';
|
|
9
|
+
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from './plugin/postgraphile';
|
|
9
10
|
export { StonecropClient } from './client';
|
|
10
11
|
export type { StonecropClientOptions } from './client';
|
|
11
12
|
//# 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":"AACA,OAAO,EAEN,kBAAkB,EAClB,QAAQ,EACR,mBAAmB,EAGnB,SAAS,EACT,YAAY,EACZ,eAAe,EAGf,WAAW,EACX,YAAY,EACZ,gBAAgB,EAGhB,aAAa,EACb,eAAe,EACf,UAAU,EACV,YAAY,EAGZ,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EAGjB,MAAM,EACN,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,mBAAmB,CAAA;AAE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,EACxB,0BAA0B,EAC1B,uBAAuB,GACvB,MAAM,mBAAmB,CAAA;AAG1B,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAG1F,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;AAG9B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -18,5 +18,7 @@ export { loadDoctypes, loadDoctypesFromObject, getMeta, getAllMeta, hasMeta, cle
|
|
|
18
18
|
export { registerHandler, getHandler, hasHandler, clearHandlers, registerBuiltinHandlers, builtinHandlers, } from './registry/actions';
|
|
19
19
|
// PostGraphile plugin
|
|
20
20
|
export { createStonecropPlugin } from './plugin/postgraphile';
|
|
21
|
+
// Query builders and inflection helpers (exported for testing and advanced usage)
|
|
22
|
+
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from './plugin/postgraphile';
|
|
21
23
|
// Client
|
|
22
24
|
export { StonecropClient } from './client';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphileConfig } from 'postgraphile/graphile-build';
|
|
2
|
-
import type { GraphQLExecutor } from '../types';
|
|
2
|
+
import type { DoctypeMeta, GraphQLExecutor } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Inflection callbacks for mapping table names to GraphQL query field names.
|
|
5
5
|
* Override these when using a non-Amber inflection preset (e.g., V4, SimplifyInflection).
|
|
@@ -46,4 +46,52 @@ export interface StonecropPluginOptions {
|
|
|
46
46
|
* @public
|
|
47
47
|
*/
|
|
48
48
|
export declare const createStonecropPlugin: (options: StonecropPluginOptions) => GraphileConfig.Plugin;
|
|
49
|
+
/**
|
|
50
|
+
* Amber default: sales_orders → salesOrderById
|
|
51
|
+
* Uses `pluralize` for proper singularization of irregular plurals.
|
|
52
|
+
* Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
declare function defaultRecordFieldName(tableName: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Amber default: sales_orders → allSalesOrders
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
declare function defaultConnectionFieldName(tableName: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Amber default: sales_orders → SalesOrdersOrderBy
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
declare function defaultOrderByTypeName(tableName: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Fieldtypes that map to GraphQL object/connection types and require sub-selections.
|
|
68
|
+
* These fields are excluded from generated query field selections.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
declare const RELATION_FIELDTYPES: Set<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Filter fields to only those directly queryable as scalars, excluding Link and Doctype
|
|
74
|
+
* relation fields that require GraphQL sub-selections.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
declare function queryableFieldNames(meta: DoctypeMeta): string;
|
|
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
|
+
declare function buildRecordQuery(meta: DoctypeMeta, recordFieldName: (t: string) => string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Build a GraphQL connection query to fetch a list of records.
|
|
86
|
+
* Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
|
|
87
|
+
* avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
|
|
88
|
+
* Excludes Link and Doctype relation fields from the selection set.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
declare function buildListQuery(meta: DoctypeMeta, args: {
|
|
92
|
+
limit?: number;
|
|
93
|
+
offset?: number;
|
|
94
|
+
orderBy?: string;
|
|
95
|
+
}, connectionFieldName: (t: string) => string, orderByTypeName: (t: string) => string): string;
|
|
96
|
+
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, };
|
|
49
97
|
//# sourceMappingURL=postgraphile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAO5D,OAAO,KAAK,EAAiB,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE3E;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,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ACpC,MAAM,CAgCR;AAmBD,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,GACnB,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { extendSchema, gql } from 'postgraphile/utils';
|
|
2
2
|
import { constant, lambda, object, loadOne } from 'postgraphile/grafast';
|
|
3
|
+
import pluralize from 'pluralize';
|
|
4
|
+
import { snakeToCamel, toPascalCase } from '@stonecrop/schema';
|
|
3
5
|
import { getHandler } from '../registry/actions';
|
|
4
6
|
import { getMeta, getAllMeta } from '../registry/doctypes';
|
|
5
7
|
/**
|
|
@@ -212,33 +214,61 @@ export const createStonecropPlugin = (options) => {
|
|
|
212
214
|
};
|
|
213
215
|
// =============================================================================
|
|
214
216
|
// Inflection helpers — default to PostGraphile Amber preset conventions
|
|
217
|
+
// Uses `pluralize` for proper English singularization (handles irregular
|
|
218
|
+
// plurals like statuses→status, categories→category, addresses→address).
|
|
219
|
+
// snakeToCamel / toPascalCase are imported from @stonecrop/schema.
|
|
215
220
|
// =============================================================================
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
/** Amber default: sales_orders → salesOrderById */
|
|
221
|
+
/**
|
|
222
|
+
* Amber default: sales_orders → salesOrderById
|
|
223
|
+
* Uses `pluralize` for proper singularization of irregular plurals.
|
|
224
|
+
* Override via `StonecropInflectionConfig.recordFieldName` for non-standard PK columns.
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
224
227
|
function defaultRecordFieldName(tableName) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return `${toCamelCase(singular)}ById`;
|
|
228
|
+
const singular = pluralize.singular(tableName);
|
|
229
|
+
return `${snakeToCamel(singular)}ById`;
|
|
228
230
|
}
|
|
229
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* Amber default: sales_orders → allSalesOrders
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
230
235
|
function defaultConnectionFieldName(tableName) {
|
|
231
236
|
return `all${toPascalCase(tableName)}`;
|
|
232
237
|
}
|
|
233
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* Amber default: sales_orders → SalesOrdersOrderBy
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
234
242
|
function defaultOrderByTypeName(tableName) {
|
|
235
243
|
return `${toPascalCase(tableName)}OrderBy`;
|
|
236
244
|
}
|
|
237
245
|
// =============================================================================
|
|
238
246
|
// Query builders — generate GraphQL queries to send to the underlying schema
|
|
239
247
|
// =============================================================================
|
|
248
|
+
/**
|
|
249
|
+
* Fieldtypes that map to GraphQL object/connection types and require sub-selections.
|
|
250
|
+
* These fields are excluded from generated query field selections.
|
|
251
|
+
* @internal
|
|
252
|
+
*/
|
|
253
|
+
const RELATION_FIELDTYPES = new Set(['Link', 'Doctype']);
|
|
254
|
+
/**
|
|
255
|
+
* Filter fields to only those directly queryable as scalars, excluding Link and Doctype
|
|
256
|
+
* relation fields that require GraphQL sub-selections.
|
|
257
|
+
* @internal
|
|
258
|
+
*/
|
|
259
|
+
function queryableFieldNames(meta) {
|
|
260
|
+
return meta.fields
|
|
261
|
+
.filter(f => !RELATION_FIELDTYPES.has(f.fieldtype))
|
|
262
|
+
.map(f => f.fieldname)
|
|
263
|
+
.join('\n ');
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Build a GraphQL query to fetch a single record by ID.
|
|
267
|
+
* Excludes Link and Doctype relation fields from the selection set.
|
|
268
|
+
* @internal
|
|
269
|
+
*/
|
|
240
270
|
function buildRecordQuery(meta, recordFieldName) {
|
|
241
|
-
const fieldNames = meta
|
|
271
|
+
const fieldNames = queryableFieldNames(meta);
|
|
242
272
|
const queryName = recordFieldName(meta.tableName);
|
|
243
273
|
return `
|
|
244
274
|
query GetRecord($id: UUID!) {
|
|
@@ -248,20 +278,35 @@ function buildRecordQuery(meta, recordFieldName) {
|
|
|
248
278
|
}
|
|
249
279
|
`;
|
|
250
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Build a GraphQL connection query to fetch a list of records.
|
|
283
|
+
* Only declares variables ($limit, $offset, $orderBy) that are actually used in the query,
|
|
284
|
+
* avoiding GraphQL spec §5.8.3 violations from unused variable declarations.
|
|
285
|
+
* Excludes Link and Doctype relation fields from the selection set.
|
|
286
|
+
* @internal
|
|
287
|
+
*/
|
|
251
288
|
function buildListQuery(meta, args, connectionFieldName, orderByTypeName) {
|
|
252
|
-
const fieldNames = meta
|
|
289
|
+
const fieldNames = queryableFieldNames(meta);
|
|
253
290
|
const connectionName = connectionFieldName(meta.tableName);
|
|
254
291
|
const orderByType = orderByTypeName(meta.tableName);
|
|
292
|
+
const varDecls = [];
|
|
255
293
|
const queryArgs = [];
|
|
256
|
-
if (args.limit)
|
|
294
|
+
if (args.limit) {
|
|
295
|
+
varDecls.push('$limit: Int');
|
|
257
296
|
queryArgs.push(`first: $limit`);
|
|
258
|
-
|
|
297
|
+
}
|
|
298
|
+
if (args.offset) {
|
|
299
|
+
varDecls.push('$offset: Int');
|
|
259
300
|
queryArgs.push(`offset: $offset`);
|
|
260
|
-
|
|
301
|
+
}
|
|
302
|
+
if (args.orderBy) {
|
|
303
|
+
varDecls.push(`$orderBy: [${orderByType}!]`);
|
|
261
304
|
queryArgs.push(`orderBy: $orderBy`);
|
|
305
|
+
}
|
|
306
|
+
const varStr = varDecls.length > 0 ? `(${varDecls.join(', ')})` : '';
|
|
262
307
|
const argsStr = queryArgs.length > 0 ? `(${queryArgs.join(', ')})` : '';
|
|
263
308
|
return `
|
|
264
|
-
query GetRecords
|
|
309
|
+
query GetRecords${varStr} {
|
|
265
310
|
${connectionName}${argsStr} {
|
|
266
311
|
nodes {
|
|
267
312
|
${fieldNames}
|
|
@@ -279,3 +324,7 @@ function extractListResult(result, meta, connectionFieldName) {
|
|
|
279
324
|
const connection = result[connectionName];
|
|
280
325
|
return connection?.nodes ?? [];
|
|
281
326
|
}
|
|
327
|
+
// =============================================================================
|
|
328
|
+
// Exported for testing and advanced usage
|
|
329
|
+
// =============================================================================
|
|
330
|
+
export { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-builders.test.d.ts","sourceRoot":"","sources":["../../tests/query-builders.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { defaultRecordFieldName, defaultConnectionFieldName, defaultOrderByTypeName, buildRecordQuery, buildListQuery, queryableFieldNames, RELATION_FIELDTYPES, } from '../src/plugin/postgraphile';
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Test fixtures
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
/** A simple doctype with only scalar fields */
|
|
7
|
+
const scalarOnlyMeta = {
|
|
8
|
+
name: 'Resource',
|
|
9
|
+
tableName: 'resources',
|
|
10
|
+
fields: [
|
|
11
|
+
{ fieldname: 'id', fieldtype: 'Data', label: 'ID' },
|
|
12
|
+
{ fieldname: 'name', fieldtype: 'Data', label: 'Name' },
|
|
13
|
+
{ fieldname: 'quantity', fieldtype: 'Int', label: 'Quantity' },
|
|
14
|
+
{ fieldname: 'is_active', fieldtype: 'Check', label: 'Active' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
/** A doctype that includes Link and Doctype (relation) fields alongside scalars */
|
|
18
|
+
const mixedFieldsMeta = {
|
|
19
|
+
name: 'Recipe',
|
|
20
|
+
tableName: 'recipes',
|
|
21
|
+
fields: [
|
|
22
|
+
{ fieldname: 'id', fieldtype: 'Data', label: 'ID' },
|
|
23
|
+
{ fieldname: 'title', fieldtype: 'Data', label: 'Title' },
|
|
24
|
+
{ fieldname: 'created_at', fieldtype: 'Datetime', label: 'Created' },
|
|
25
|
+
// FK object reference — requires sub-selection, should be skipped
|
|
26
|
+
{ fieldname: 'userByCreatedBy', fieldtype: 'Link', label: 'Creator', options: 'user' },
|
|
27
|
+
// Reverse relation connection — requires sub-selection, should be skipped
|
|
28
|
+
{
|
|
29
|
+
fieldname: 'recipeIngredientsByRecipeId',
|
|
30
|
+
fieldtype: 'Doctype',
|
|
31
|
+
label: 'Ingredients',
|
|
32
|
+
options: 'recipe-ingredient',
|
|
33
|
+
},
|
|
34
|
+
{ fieldname: 'rating', fieldtype: 'Float', label: 'Rating' },
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
// ===========================================================================
|
|
38
|
+
// Inflection helpers
|
|
39
|
+
// ===========================================================================
|
|
40
|
+
describe('defaultRecordFieldName', () => {
|
|
41
|
+
it('singularizes regular plurals and appends ById', () => {
|
|
42
|
+
expect(defaultRecordFieldName('resources')).toBe('resourceById');
|
|
43
|
+
});
|
|
44
|
+
it('handles irregular plurals (statuses → status)', () => {
|
|
45
|
+
expect(defaultRecordFieldName('statuses')).toBe('statusById');
|
|
46
|
+
});
|
|
47
|
+
it('handles irregular plurals (categories → category)', () => {
|
|
48
|
+
expect(defaultRecordFieldName('categories')).toBe('categoryById');
|
|
49
|
+
});
|
|
50
|
+
it('handles irregular plurals (addresses → address)', () => {
|
|
51
|
+
expect(defaultRecordFieldName('addresses')).toBe('addressById');
|
|
52
|
+
});
|
|
53
|
+
it('handles snake_case table names', () => {
|
|
54
|
+
expect(defaultRecordFieldName('sales_orders')).toBe('salesOrderById');
|
|
55
|
+
});
|
|
56
|
+
it('handles already-singular names', () => {
|
|
57
|
+
expect(defaultRecordFieldName('resource')).toBe('resourceById');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('defaultConnectionFieldName', () => {
|
|
61
|
+
it('prefixes with "all" and PascalCases', () => {
|
|
62
|
+
expect(defaultConnectionFieldName('resources')).toBe('allResources');
|
|
63
|
+
});
|
|
64
|
+
it('handles snake_case', () => {
|
|
65
|
+
expect(defaultConnectionFieldName('sales_orders')).toBe('allSalesOrders');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('defaultOrderByTypeName', () => {
|
|
69
|
+
it('PascalCases and appends OrderBy', () => {
|
|
70
|
+
expect(defaultOrderByTypeName('resources')).toBe('ResourcesOrderBy');
|
|
71
|
+
});
|
|
72
|
+
it('handles snake_case', () => {
|
|
73
|
+
expect(defaultOrderByTypeName('sales_orders')).toBe('SalesOrdersOrderBy');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// ===========================================================================
|
|
77
|
+
// Query builders — relation field filtering (Issue 5)
|
|
78
|
+
// ===========================================================================
|
|
79
|
+
describe('queryableFieldNames', () => {
|
|
80
|
+
it('returns all fields when none are relational', () => {
|
|
81
|
+
const names = queryableFieldNames(scalarOnlyMeta);
|
|
82
|
+
expect(names).toContain('id');
|
|
83
|
+
expect(names).toContain('name');
|
|
84
|
+
expect(names).toContain('quantity');
|
|
85
|
+
expect(names).toContain('is_active');
|
|
86
|
+
});
|
|
87
|
+
it('excludes Link and Doctype fields', () => {
|
|
88
|
+
const names = queryableFieldNames(mixedFieldsMeta);
|
|
89
|
+
expect(names).toContain('id');
|
|
90
|
+
expect(names).toContain('title');
|
|
91
|
+
expect(names).toContain('created_at');
|
|
92
|
+
expect(names).toContain('rating');
|
|
93
|
+
expect(names).not.toContain('userByCreatedBy');
|
|
94
|
+
expect(names).not.toContain('recipeIngredientsByRecipeId');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('RELATION_FIELDTYPES', () => {
|
|
98
|
+
it('contains Link and Doctype', () => {
|
|
99
|
+
expect(RELATION_FIELDTYPES.has('Link')).toBe(true);
|
|
100
|
+
expect(RELATION_FIELDTYPES.has('Doctype')).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
it('does not contain scalar types', () => {
|
|
103
|
+
expect(RELATION_FIELDTYPES.has('Data')).toBe(false);
|
|
104
|
+
expect(RELATION_FIELDTYPES.has('Int')).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
// ===========================================================================
|
|
108
|
+
// buildRecordQuery
|
|
109
|
+
// ===========================================================================
|
|
110
|
+
describe('buildRecordQuery', () => {
|
|
111
|
+
it('generates valid query with only scalar fields', () => {
|
|
112
|
+
const query = buildRecordQuery(scalarOnlyMeta, defaultRecordFieldName);
|
|
113
|
+
expect(query).toContain('query GetRecord($id: UUID!)');
|
|
114
|
+
expect(query).toContain('resourceById(id: $id)');
|
|
115
|
+
expect(query).toContain('id');
|
|
116
|
+
expect(query).toContain('name');
|
|
117
|
+
expect(query).toContain('quantity');
|
|
118
|
+
});
|
|
119
|
+
it('excludes relation fields from selection', () => {
|
|
120
|
+
const query = buildRecordQuery(mixedFieldsMeta, defaultRecordFieldName);
|
|
121
|
+
expect(query).toContain('title');
|
|
122
|
+
expect(query).toContain('rating');
|
|
123
|
+
expect(query).not.toContain('userByCreatedBy');
|
|
124
|
+
expect(query).not.toContain('recipeIngredientsByRecipeId');
|
|
125
|
+
});
|
|
126
|
+
it('uses custom recordFieldName inflection', () => {
|
|
127
|
+
const customInflection = (t) => `${t}ByRowId`;
|
|
128
|
+
const query = buildRecordQuery(scalarOnlyMeta, customInflection);
|
|
129
|
+
expect(query).toContain('resourcesByRowId(id: $id)');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
// ===========================================================================
|
|
133
|
+
// buildListQuery — variable declarations (Issue 3)
|
|
134
|
+
// ===========================================================================
|
|
135
|
+
describe('buildListQuery', () => {
|
|
136
|
+
const identity = (t) => t;
|
|
137
|
+
it('declares no variables when no args are provided', () => {
|
|
138
|
+
const query = buildListQuery(scalarOnlyMeta, {}, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
139
|
+
// Should be just "query GetRecords {" with no parenthesized variable declarations
|
|
140
|
+
expect(query).toMatch(/query GetRecords\s*\{/);
|
|
141
|
+
expect(query).not.toContain('$limit');
|
|
142
|
+
expect(query).not.toContain('$offset');
|
|
143
|
+
expect(query).not.toContain('$orderBy');
|
|
144
|
+
});
|
|
145
|
+
it('declares only $limit when only limit is provided', () => {
|
|
146
|
+
const query = buildListQuery(scalarOnlyMeta, { limit: 10 }, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
147
|
+
expect(query).toContain('$limit: Int');
|
|
148
|
+
expect(query).toContain('first: $limit');
|
|
149
|
+
expect(query).not.toContain('$offset');
|
|
150
|
+
expect(query).not.toContain('$orderBy');
|
|
151
|
+
});
|
|
152
|
+
it('declares only $limit and $offset when both are provided', () => {
|
|
153
|
+
const query = buildListQuery(scalarOnlyMeta, { limit: 10, offset: 20 }, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
154
|
+
expect(query).toContain('$limit: Int');
|
|
155
|
+
expect(query).toContain('$offset: Int');
|
|
156
|
+
expect(query).not.toContain('$orderBy');
|
|
157
|
+
});
|
|
158
|
+
it('declares all three variables when all args are provided', () => {
|
|
159
|
+
const query = buildListQuery(scalarOnlyMeta, { limit: 10, offset: 20, orderBy: 'NAME_ASC' }, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
160
|
+
expect(query).toContain('$limit: Int');
|
|
161
|
+
expect(query).toContain('$offset: Int');
|
|
162
|
+
expect(query).toContain('$orderBy: [ResourcesOrderBy!]');
|
|
163
|
+
expect(query).toContain('first: $limit');
|
|
164
|
+
expect(query).toContain('offset: $offset');
|
|
165
|
+
expect(query).toContain('orderBy: $orderBy');
|
|
166
|
+
});
|
|
167
|
+
it('uses correct connection field name', () => {
|
|
168
|
+
const query = buildListQuery(scalarOnlyMeta, {}, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
169
|
+
expect(query).toContain('allResources');
|
|
170
|
+
});
|
|
171
|
+
it('excludes relation fields from selection', () => {
|
|
172
|
+
const query = buildListQuery(mixedFieldsMeta, {}, defaultConnectionFieldName, defaultOrderByTypeName);
|
|
173
|
+
expect(query).toContain('title');
|
|
174
|
+
expect(query).toContain('rating');
|
|
175
|
+
expect(query).not.toContain('userByCreatedBy');
|
|
176
|
+
expect(query).not.toContain('recipeIngredientsByRecipeId');
|
|
177
|
+
});
|
|
178
|
+
});
|