@stonecrop/graphql-middleware 0.7.0

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.
@@ -0,0 +1,29 @@
1
+ import { DoctypeMeta, RouteContext, GraphQLExecutor } from '../types';
2
+ export interface StonecropClientOptions {
3
+ endpoint: string;
4
+ headers?: Record<string, string>;
5
+ }
6
+ export declare class StonecropClient implements GraphQLExecutor {
7
+ private endpoint;
8
+ private headers;
9
+ private metaCache;
10
+ constructor(options: StonecropClientOptions);
11
+ query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
12
+ mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
13
+ getMeta(context: RouteContext): Promise<DoctypeMeta | null>;
14
+ getAllMeta(): Promise<DoctypeMeta[]>;
15
+ getRecord(doctype: DoctypeMeta, recordId: string): Promise<Record<string, unknown> | null>;
16
+ getRecords(doctype: DoctypeMeta, options?: {
17
+ filters?: Record<string, unknown>;
18
+ orderBy?: string;
19
+ limit?: number;
20
+ offset?: number;
21
+ }): Promise<Record<string, unknown>[]>;
22
+ runAction(doctype: DoctypeMeta, action: string, args?: unknown[]): Promise<{
23
+ success: boolean;
24
+ data: unknown;
25
+ error: string | null;
26
+ }>;
27
+ clearMetaCache(): void;
28
+ }
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1E,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED,qBAAa,eAAgB,YAAW,eAAe;IACtD,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,OAAO,CAAwB;I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DDL, normalizeType, mapColumnToField, PG_TYPE_MAP, TYPE_ALIASES } from '@stonecrop/schema';
2
+ export type { ConvertedDoctype, ConversionFieldMeta, ParsedColumn, ParsedTable, ConversionOptions, PostgresType, } from '@stonecrop/schema';
3
+ export { PG_TYPE_MAP as TYPE_MAP } from '@stonecrop/schema';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/converter/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEvH,YAAY,EACX,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,YAAY,GACZ,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,WAAW,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,11 @@
1
+ export { StonecropFieldType, TYPE_MAP, getDefaultComponent, FieldMeta, FieldOptions, FieldValidation, DoctypeMeta, WorkflowMeta, ActionDefinition, validateField, validateDoctype, parseField, parseDoctype, convertSchema, parseDDL, normalizeType, mapColumnToField, PG_TYPE_MAP, TYPE_ALIASES, } from '@stonecrop/schema';
2
+ export type { ValidationResult, ValidationError, ConvertedDoctype, ConversionFieldMeta, ParsedColumn, ParsedTable, ConversionOptions, PostgresType, } from '@stonecrop/schema';
3
+ export type { RouteContext, ActionContext, ActionHandler, GraphQLExecutor } from './types';
4
+ export { loadDoctypes, loadDoctypesFromObject, getMeta, getAllMeta, hasMeta, clearRegistry, validateReferences, DoctypeValidationError, } from './registry/doctypes';
5
+ export type { LoadDoctypesOptions } from './registry/doctypes';
6
+ export { registerHandler, getHandler, hasHandler, clearHandlers, registerBuiltinHandlers, builtinHandlers, } from './registry/actions';
7
+ export { createStonecropPlugin } from './plugin/postgraphile';
8
+ export type { StonecropPluginOptions } from './plugin/postgraphile';
9
+ export { StonecropClient } from './client';
10
+ export type { StonecropClientOptions } from './client';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,aAAa,EACb,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,YAAY,GACZ,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EACX,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,YAAY,GACZ,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,MAAM,uBAAuB,CAAA;AAGnE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { GraphQLExecutor } from '../types';
2
+ export interface StonecropPluginOptions {
3
+ executor: GraphQLExecutor;
4
+ }
5
+ export declare const createStonecropPlugin: (options: StonecropPluginOptions) => GraphileConfig.Plugin;
6
+ //# sourceMappingURL=postgraphile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgraphile.d.ts","sourceRoot":"","sources":["../../../src/plugin/postgraphile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA8B,eAAe,EAAE,MAAM,UAAU,CAAA;AAE3E,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,eAAe,CAAA;CACzB;AAED,eAAO,MAAM,qBAAqB,GAAI,SAAS,sBAAsB,0BAmLpE,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { ActionHandler } from '../types';
2
+ /**
3
+ * Register an action handler
4
+ */
5
+ export declare function registerHandler(name: string, handler: ActionHandler): void;
6
+ /**
7
+ * Get a registered handler by name
8
+ */
9
+ export declare function getHandler(name: string): ActionHandler | undefined;
10
+ /**
11
+ * Check if a handler is registered
12
+ */
13
+ export declare function hasHandler(name: string): boolean;
14
+ /**
15
+ * Clear all registered handlers
16
+ */
17
+ export declare function clearHandlers(): void;
18
+ /**
19
+ * Built-in handlers available for registration
20
+ */
21
+ export declare const builtinHandlers: Record<string, ActionHandler>;
22
+ /**
23
+ * Register all built-in handlers
24
+ */
25
+ export declare function registerBuiltinHandlers(): void;
26
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/registry/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,UAAU,CAAA;AAIzE;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAE1E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAElE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAqHD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAIzD,CAAA;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAI9C"}
@@ -0,0 +1,42 @@
1
+ import { DoctypeMeta, ValidationError } from '../types';
2
+ export declare class DoctypeValidationError extends Error {
3
+ readonly file: string;
4
+ readonly errors: ValidationError[];
5
+ constructor(file: string, errors: ValidationError[]);
6
+ }
7
+ export interface LoadDoctypesOptions {
8
+ /** Continue loading other files if one fails validation */
9
+ continueOnError?: boolean;
10
+ /** Callback for validation errors when continueOnError is true */
11
+ onError?: (file: string, errors: ValidationError[]) => void;
12
+ }
13
+ /**
14
+ * Load doctype definitions from a directory of JSON files
15
+ */
16
+ export declare function loadDoctypes(dir: string, options?: LoadDoctypesOptions): void;
17
+ /**
18
+ * Load doctypes from an object (for programmatic use)
19
+ */
20
+ export declare function loadDoctypesFromObject(doctypes: Record<string, unknown>, options?: LoadDoctypesOptions): void;
21
+ /**
22
+ * Get a doctype by name
23
+ */
24
+ export declare function getMeta(name: string): DoctypeMeta | undefined;
25
+ /**
26
+ * Get all loaded doctypes
27
+ */
28
+ export declare function getAllMeta(): DoctypeMeta[];
29
+ /**
30
+ * Check if a doctype is registered
31
+ */
32
+ export declare function hasMeta(name: string): boolean;
33
+ /**
34
+ * Clear all registered doctypes
35
+ */
36
+ export declare function clearRegistry(): void;
37
+ /**
38
+ * Validate cross-doctype references (Link fields, inherits, etc.)
39
+ * Call after all doctypes are loaded.
40
+ */
41
+ export declare function validateReferences(): ValidationError[];
42
+ //# sourceMappingURL=doctypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctypes.d.ts","sourceRoot":"","sources":["../../../src/registry/doctypes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAI5D,qBAAa,sBAAuB,SAAQ,KAAK;aACpB,IAAI,EAAE,MAAM;aAAkB,MAAM,EAAE,eAAe,EAAE;gBAAvD,IAAI,EAAE,MAAM,EAAkB,MAAM,EAAE,eAAe,EAAE;CAKnF;AAED,MAAM,WAAW,mBAAmB;IACnC,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,kEAAkE;IAClE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,IAAI,CAAA;CAC3D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAajF;AAsCD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAgBjH;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAE7D;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,WAAW,EAAE,CAE1C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,EAAE,CA0CtD"}
@@ -0,0 +1,31 @@
1
+ import { DoctypeMeta } from '@stonecrop/schema';
2
+ export { StonecropFieldType, FieldOptions, FieldMeta, ActionDefinition, WorkflowMeta, DoctypeMeta, validateDoctype, validateField, parseDoctype, parseField, } from '@stonecrop/schema';
3
+ export type { ValidationResult, ValidationError, ConversionFieldMeta, ParsedColumn, ParsedTable, ConversionOptions, PostgresType, } from '@stonecrop/schema';
4
+ /**
5
+ * Route context for identifying what doctype/record we're working with
6
+ */
7
+ export interface RouteContext {
8
+ doctype: string;
9
+ recordId?: string;
10
+ [key: string]: unknown;
11
+ }
12
+ /**
13
+ * GraphQL executor interface for running queries/mutations
14
+ */
15
+ export interface GraphQLExecutor {
16
+ query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
17
+ mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
18
+ }
19
+ /**
20
+ * Context passed to action handlers
21
+ */
22
+ export interface ActionContext {
23
+ doctype: DoctypeMeta;
24
+ executor: GraphQLExecutor;
25
+ [key: string]: unknown;
26
+ }
27
+ /**
28
+ * Action handler function signature
29
+ */
30
+ export type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,eAAe,EACf,aAAa,EACb,YAAY,EACZ,UAAU,GACV,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EACX,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,YAAY,GACZ,MAAM,mBAAmB,CAAA;AAM1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAClF,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACtF;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,WAAW,CAAA;IACpB,QAAQ,EAAE,eAAe,CAAA;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=registry.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../tests/registry.test.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@stonecrop/graphql-middleware",
3
+ "version": "0.7.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "graphql": "^16.12.0",
20
+ "postgraphile": "^5.0.0-rc.3",
21
+ "zod": "^3.25.76",
22
+ "@stonecrop/schema": "0.7.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^22.19.5",
26
+ "typescript": "^5.9.3",
27
+ "vite": "^7.3.1",
28
+ "vite-plugin-dts": "^4.5.4",
29
+ "vitest": "^4.0.17"
30
+ },
31
+ "scripts": {
32
+ "_phase:build": "vite build",
33
+ "prepublish": "vite build",
34
+ "build": "vite build",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest"
37
+ }
38
+ }