@stonecrop/graphql-middleware 0.12.7 → 0.13.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,53 @@
1
+ /**
2
+ * Controls how PostgreSQL column names are mapped to GraphQL field names in the synthesized preset.
3
+ *
4
+ * - `'camel'` (default): `my_column` → `myColumn`. This matches PostGraphile Amber's built-in behaviour.
5
+ * - `'pascal'`: `my_column` → `MyColumn`. Opt in via `createStonecropPreset({ fieldCasing: 'pascal' })` or
6
+ * `grafserv.fieldCasing: 'pascal'` in `nuxt.config.ts`.
7
+ *
8
+ * Smart tag overrides (`@name` on column comments) are respected regardless of this setting.
9
+ * @public
10
+ */
11
+ export type FieldCasing = 'camel' | 'pascal';
12
+ /**
13
+ * Creates a Stonecrop-flavoured PostGraphile preset.
14
+ *
15
+ * The returned preset extends `PostGraphileAmberPreset` and applies Stonecrop's
16
+ * recommended defaults. Pass it to `extends` in your PostGraphile configuration:
17
+ *
18
+ * ```typescript
19
+ * import { createStonecropPreset, makePgService, createStonecropPlugin } from '@stonecrop/graphql-middleware'
20
+ *
21
+ * export default {
22
+ * extends: [createStonecropPreset()],
23
+ * pgServices: [makePgService({ connectionString: process.env.DATABASE_URL, schemas: ['public'] })],
24
+ * plugins: [createStonecropPlugin()],
25
+ * }
26
+ * ```
27
+ *
28
+ * @param options - Optional configuration. Pass `{ fieldCasing: 'pascal' }` to enable
29
+ * `MyColumn`-style field names instead of the default `myColumn` (camelCase).
30
+ * @public
31
+ */
32
+ export declare const createStonecropPreset: (options?: {
33
+ fieldCasing?: FieldCasing;
34
+ }) => GraphileConfig.Preset;
35
+ /**
36
+ * The default Stonecrop PostGraphile preset with camelCase field names.
37
+ *
38
+ * Equivalent to `createStonecropPreset()` with no options. Use this when you
39
+ * do not need to customise field casing:
40
+ *
41
+ * ```typescript
42
+ * import { StonecropPreset, makePgService, createStonecropPlugin } from '@stonecrop/graphql-middleware'
43
+ *
44
+ * export default {
45
+ * extends: [StonecropPreset],
46
+ * pgServices: [makePgService({ connectionString: process.env.DATABASE_URL })],
47
+ * plugins: [createStonecropPlugin()],
48
+ * }
49
+ * ```
50
+ * @public
51
+ */
52
+ export declare const StonecropPreset: GraphileConfig.Preset;
53
+ //# sourceMappingURL=preset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/preset.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAA;AAc5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU;IAAE,WAAW,CAAC,EAAE,WAAW,CAAA;CAAE,KAAG,cAAc,CAAC,MAG7F,CAAA;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe,EAAE,cAAc,CAAC,MAAgC,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { PostGraphileAmberPreset } from 'postgraphile/presets/amber';
2
+ const StonecropFieldCasingPlugin = {
3
+ name: 'StonecropFieldCasingPlugin',
4
+ version: '0.0.0',
5
+ inflection: {
6
+ replace: {
7
+ attribute(previous, options, details) {
8
+ return this.upperCamelCase(this._attributeName(details));
9
+ },
10
+ },
11
+ },
12
+ };
13
+ /**
14
+ * Creates a Stonecrop-flavoured PostGraphile preset.
15
+ *
16
+ * The returned preset extends `PostGraphileAmberPreset` and applies Stonecrop's
17
+ * recommended defaults. Pass it to `extends` in your PostGraphile configuration:
18
+ *
19
+ * ```typescript
20
+ * import { createStonecropPreset, makePgService, createStonecropPlugin } from '@stonecrop/graphql-middleware'
21
+ *
22
+ * export default {
23
+ * extends: [createStonecropPreset()],
24
+ * pgServices: [makePgService({ connectionString: process.env.DATABASE_URL, schemas: ['public'] })],
25
+ * plugins: [createStonecropPlugin()],
26
+ * }
27
+ * ```
28
+ *
29
+ * @param options - Optional configuration. Pass `{ fieldCasing: 'pascal' }` to enable
30
+ * `MyColumn`-style field names instead of the default `myColumn` (camelCase).
31
+ * @public
32
+ */
33
+ export const createStonecropPreset = (options) => ({
34
+ extends: [PostGraphileAmberPreset],
35
+ plugins: options?.fieldCasing === 'pascal' ? [StonecropFieldCasingPlugin] : [],
36
+ });
37
+ /**
38
+ * The default Stonecrop PostGraphile preset with camelCase field names.
39
+ *
40
+ * Equivalent to `createStonecropPreset()` with no options. Use this when you
41
+ * do not need to customise field casing:
42
+ *
43
+ * ```typescript
44
+ * import { StonecropPreset, makePgService, createStonecropPlugin } from '@stonecrop/graphql-middleware'
45
+ *
46
+ * export default {
47
+ * extends: [StonecropPreset],
48
+ * pgServices: [makePgService({ connectionString: process.env.DATABASE_URL })],
49
+ * plugins: [createStonecropPlugin()],
50
+ * }
51
+ * ```
52
+ * @public
53
+ */
54
+ export const StonecropPreset = createStonecropPreset();
@@ -0,0 +1,31 @@
1
+ import type { PgClient } from '@dataplan/pg';
2
+ import type { LinkDeclaration } from '@stonecrop/schema';
3
+ /**
4
+ * Handler for a custom fetch strategy on a link declaration.
5
+ * Called during `stonecropRecord` resolution when `link.fetch.method === 'custom'`.
6
+ *
7
+ * @param pgClient - Active database client for the current request
8
+ * @param parentRecord - Resolved parent record (scalar fields already populated)
9
+ * @param link - The link declaration, giving access to cardinality and other metadata
10
+ * @returns A single linked record or an array depending on `link.cardinality`
11
+ * @public
12
+ */
13
+ export type FetchHandler = (pgClient: PgClient, parentRecord: Record<string, unknown>, link: LinkDeclaration) => Promise<Record<string, unknown> | Record<string, unknown>[]>;
14
+ /**
15
+ * Register a custom fetch handler by name.
16
+ * The name must match the `handler` field on a `CustomFetch` strategy declaration.
17
+ * @public
18
+ */
19
+ export declare function registerFetchHandler(name: string, handler: FetchHandler): void;
20
+ /**
21
+ * Retrieve a registered fetch handler by name.
22
+ * Returns `undefined` if no handler has been registered under that name.
23
+ * @public
24
+ */
25
+ export declare function getFetchHandler(name: string): FetchHandler | undefined;
26
+ /**
27
+ * Remove all registered fetch handlers. Primarily for test isolation.
28
+ * @public
29
+ */
30
+ export declare function clearFetchHandlers(): void;
31
+ //# sourceMappingURL=fetchHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchHandlers.d.ts","sourceRoot":"","sources":["../../../src/registry/fetchHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,CAC1B,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,eAAe,KACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;AAIjE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEtE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
@@ -0,0 +1,24 @@
1
+ const registry = new Map();
2
+ /**
3
+ * Register a custom fetch handler by name.
4
+ * The name must match the `handler` field on a `CustomFetch` strategy declaration.
5
+ * @public
6
+ */
7
+ export function registerFetchHandler(name, handler) {
8
+ registry.set(name, handler);
9
+ }
10
+ /**
11
+ * Retrieve a registered fetch handler by name.
12
+ * Returns `undefined` if no handler has been registered under that name.
13
+ * @public
14
+ */
15
+ export function getFetchHandler(name) {
16
+ return registry.get(name);
17
+ }
18
+ /**
19
+ * Remove all registered fetch handlers. Primarily for test isolation.
20
+ * @public
21
+ */
22
+ export function clearFetchHandlers() {
23
+ registry.clear();
24
+ }
@@ -0,0 +1,20 @@
1
+ import type { DoctypeMeta } from '@stonecrop/schema';
2
+ import type { WithPgClient } from 'postgraphile/@dataplan/pg';
3
+ /**
4
+ * Context passed to action handlers
5
+ * @public
6
+ */
7
+ export interface ActionContext {
8
+ /** Doctype metadata for the action being executed */
9
+ doctype: DoctypeMeta;
10
+ /** Database access function; available when handler is called from a GraphQL mutation */
11
+ withPgClient?: WithPgClient;
12
+ /** Additional context properties */
13
+ [key: string]: unknown;
14
+ }
15
+ /**
16
+ * Action handler function signature
17
+ * @public
18
+ */
19
+ export type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
20
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/types/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IACpB,yFAAyF;IACzF,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA"}
@@ -1,23 +1,14 @@
1
+ import type { PgClient } from '@dataplan/pg';
1
2
  import type { DoctypeMeta } from '@stonecrop/schema';
2
3
  /**
3
- * GraphQL executor interface for running queries/mutations
4
- * @public
5
- */
6
- export interface GraphQLExecutor {
7
- /** Execute a GraphQL query */
8
- query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
9
- /** Execute a GraphQL mutation */
10
- mutate<T = unknown>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
11
- }
12
- /**
13
- * Context passed to action handlers
4
+ * Context passed to action handlers.
14
5
  * @public
15
6
  */
16
7
  export interface ActionContext {
17
8
  /** Doctype metadata for the action being executed */
18
9
  doctype: DoctypeMeta;
19
- /** GraphQL executor for running queries/mutations within the action */
20
- executor: GraphQLExecutor;
10
+ /** Active database client — available when the action is dispatched via stonecropAction */
11
+ pgClient?: PgClient;
21
12
  /** Additional context properties */
22
13
  [key: string]: unknown;
23
14
  }
@@ -26,5 +17,4 @@ export interface ActionContext {
26
17
  * @public
27
18
  */
28
19
  export type ActionHandler = (args: unknown[], context: ActionContext) => Promise<unknown>;
29
- export type { ReverseConnectionParams, BuildRecordQueryOptions, BuildRecordQueryParams, BuildNestedSelectionsParams, BuildListQueryArgs, BuildListQueryParams, MergeNestedResultsParams, ExtractSingleResultParams, ExtractListResultParams, } from './query';
30
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,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,iCAAiC;IACjC,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;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IACpB,uEAAuE;IACvE,QAAQ,EAAE,eAAe,CAAA;IACzB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAGzF,YAAY,EACX,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,GACvB,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,qDAAqD;IACrD,OAAO,EAAE,WAAW,CAAA;IACpB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,oCAAoC;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Field name casing convention for generated GraphQL field names.
3
+ * @public
4
+ */
5
+ export type FieldCasing = 'camel' | 'pascal';
6
+ /**
7
+ * Options for configuring a StonecropPreset.
8
+ * @public
9
+ */
10
+ export interface StonecropPresetOptions {
11
+ /**
12
+ * Field name casing convention for generated GraphQL field names.
13
+ * `'camel'` (default) produces names like `createdAt`, `taskTitle`.
14
+ * `'pascal'` produces names like `CreatedAt`, `TaskTitle`.
15
+ */
16
+ fieldCasing?: FieldCasing;
17
+ }
18
+ //# sourceMappingURL=preset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../../src/types/preset.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAA;AAE5C;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;CACzB"}
@@ -0,0 +1,79 @@
1
+ import { gql } from 'postgraphile/utils';
2
+ /**
3
+ * GraphQL type definitions for Stonecrop's middleware API.
4
+ * Includes stonecropMeta, stonecropRecord, stonecropRecords, stonecropAction, and related types.
5
+ * @public
6
+ */
7
+ export const typeDefs = gql `
8
+ type StonecropFieldMeta {
9
+ fieldname: String!
10
+ fieldtype: String!
11
+ component: String
12
+ label: String
13
+ width: String
14
+ align: String
15
+ required: Boolean
16
+ readOnly: Boolean
17
+ edit: Boolean
18
+ hidden: Boolean
19
+ default: JSON
20
+ options: JSON
21
+ mask: String
22
+ precision: Int
23
+ scale: Int
24
+ mode: String
25
+ validation: JSON
26
+ }
27
+
28
+ type StonecropWorkflowAction {
29
+ label: String!
30
+ handler: String!
31
+ requiredFields: [String!]
32
+ allowedStates: [String!]
33
+ confirm: Boolean
34
+ args: JSON
35
+ }
36
+
37
+ type StonecropWorkflowMeta {
38
+ states: [String!]
39
+ actions: [StonecropWorkflowAction!]
40
+ }
41
+
42
+ type StonecropDoctypeMeta {
43
+ name: String!
44
+ slug: String
45
+ tableName: String
46
+ fields: [StonecropFieldMeta!]!
47
+ workflow: StonecropWorkflowMeta
48
+ inherits: String
49
+ }
50
+
51
+ type StonecropRecordResult {
52
+ data: JSON
53
+ doctype: String!
54
+ unknownLinks: [String!]
55
+ }
56
+
57
+ type StonecropRecordsResult {
58
+ data: [JSON!]!
59
+ doctype: String!
60
+ count: Int!
61
+ }
62
+
63
+ type StonecropActionResult {
64
+ success: Boolean!
65
+ data: JSON
66
+ error: String
67
+ }
68
+
69
+ extend type Query {
70
+ stonecropMeta(doctype: String!): StonecropDoctypeMeta
71
+ stonecropAllMeta: [StonecropDoctypeMeta!]!
72
+ stonecropRecord(doctype: String!, id: String!, options: JSON): StonecropRecordResult
73
+ stonecropRecords(doctype: String!, filters: JSON, orderBy: String, limit: Int, offset: Int): StonecropRecordsResult
74
+ }
75
+
76
+ extend type Mutation {
77
+ stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
78
+ }
79
+ `;
File without changes
@@ -0,0 +1,3 @@
1
+ // =============================================================================
2
+ // Runtime Context Types (unique to graphql_middleware)
3
+ // =============================================================================
File without changes
@@ -0,0 +1,3 @@
1
+ // =============================================================================
2
+ // Query Builder Types
3
+ // =============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/graphql-middleware",
3
- "version": "0.12.7",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "types": "./dist/graphql-middleware.d.ts",
6
6
  "exports": {
@@ -14,13 +14,16 @@
14
14
  ],
15
15
  "description": "GraphQL middleware for PostGraphile and Stonecrop schema",
16
16
  "dependencies": {
17
+ "@dataplan/pg": "^1.0.3",
17
18
  "graphql": "^16.14.0",
18
19
  "pluralize": "^8.0.0",
19
20
  "postgraphile": "^5.0.3",
20
- "@stonecrop/schema": "0.12.7"
21
+ "@stonecrop/schema": "0.13.0"
21
22
  },
22
23
  "devDependencies": {
24
+ "@electric-sql/pglite": "^0.4.5",
23
25
  "@eslint/js": "^10.0.1",
26
+ "@types/pg": "^8.11.0",
24
27
  "@rushstack/heft": "^1.2.17",
25
28
  "@types/node": "^24.12.4",
26
29
  "@types/pluralize": "^0.0.33",
@@ -29,6 +32,8 @@
29
32
  "eslint": "^10.3.0",
30
33
  "eslint-config-prettier": "^10.1.8",
31
34
  "globals": "^17.6.0",
35
+ "pg": "^8.20.0",
36
+ "pglite-server": "^0.1.5",
32
37
  "typescript": "^6.0.3",
33
38
  "typescript-eslint": "^8.59.1",
34
39
  "vite": "^7.3.2",