@stonecrop/graphql-middleware 0.31.0 → 0.32.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.
Files changed (38) hide show
  1. package/dist/index.js +1188 -720
  2. package/dist/index.js.map +1 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/package.json +33 -14
  5. package/dist/graphql_client.tsbuildinfo +0 -1
  6. package/dist/src/debug.d.ts +0 -31
  7. package/dist/src/debug.d.ts.map +0 -1
  8. package/dist/src/debug.js +0 -49
  9. package/dist/src/dispatch/transition.d.ts +0 -107
  10. package/dist/src/dispatch/transition.d.ts.map +0 -1
  11. package/dist/src/dispatch/transition.js +0 -152
  12. package/dist/src/fields.d.ts +0 -23
  13. package/dist/src/fields.d.ts.map +0 -1
  14. package/dist/src/fields.js +0 -28
  15. package/dist/src/index.d.ts +0 -16
  16. package/dist/src/index.d.ts.map +0 -1
  17. package/dist/src/index.js +0 -14
  18. package/dist/src/link-display.d.ts +0 -19
  19. package/dist/src/link-display.d.ts.map +0 -1
  20. package/dist/src/link-display.js +0 -93
  21. package/dist/src/plugin/postgraphile.d.ts +0 -174
  22. package/dist/src/plugin/postgraphile.d.ts.map +0 -1
  23. package/dist/src/plugin/postgraphile.js +0 -882
  24. package/dist/src/preset.d.ts +0 -53
  25. package/dist/src/preset.d.ts.map +0 -1
  26. package/dist/src/preset.js +0 -148
  27. package/dist/src/registry/doctypes.d.ts +0 -95
  28. package/dist/src/registry/doctypes.d.ts.map +0 -1
  29. package/dist/src/registry/doctypes.js +0 -251
  30. package/dist/src/registry/fetchHandlers.d.ts +0 -31
  31. package/dist/src/registry/fetchHandlers.d.ts.map +0 -1
  32. package/dist/src/registry/fetchHandlers.js +0 -24
  33. package/dist/src/tables.d.ts +0 -14
  34. package/dist/src/tables.d.ts.map +0 -1
  35. package/dist/src/tables.js +0 -21
  36. package/dist/src/typeDefs.d.ts +0 -7
  37. package/dist/src/typeDefs.d.ts.map +0 -1
  38. package/dist/src/typeDefs.js +0 -118
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.11"
8
+ "packageVersion": "7.59.0"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,32 +1,50 @@
1
1
  {
2
2
  "name": "@stonecrop/graphql-middleware",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "GraphQL middleware for PostGraphile and Stonecrop schema",
5
+ "keywords": [
6
+ "graphql",
7
+ "middleware",
8
+ "postgraphile",
9
+ "schema",
10
+ "stonecrop"
11
+ ],
12
+ "homepage": "https://github.com/agritheory/stonecrop#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/agritheory/stonecrop/issues"
15
+ },
16
+ "author": {
17
+ "name": "Tyler Matteson",
18
+ "email": "tyler@agritheory.com"
19
+ },
5
20
  "repository": {
6
21
  "type": "git",
7
22
  "url": "https://github.com/agritheory/stonecrop",
8
23
  "directory": "graphql_middleware"
9
24
  },
25
+ "files": [
26
+ "dist",
27
+ "!dist/src"
28
+ ],
10
29
  "type": "module",
30
+ "sideEffects": false,
31
+ "types": "./dist/graphql-middleware.d.ts",
11
32
  "exports": {
12
33
  ".": {
13
34
  "types": "./dist/graphql-middleware.d.ts",
14
35
  "import": "./dist/index.js"
15
- }
36
+ },
37
+ "./package.json": "./package.json"
16
38
  },
17
- "types": "./dist/graphql-middleware.d.ts",
18
- "files": [
19
- "dist"
20
- ],
21
39
  "dependencies": {
22
40
  "@dataplan/pg": "^1.0.3",
23
41
  "graphql": "^16.14.0",
24
42
  "postgraphile": "^5.0.3",
25
- "@stonecrop/schema": "0.31.0"
43
+ "@stonecrop/schema": "0.32.0"
26
44
  },
27
45
  "devDependencies": {
28
46
  "@electric-sql/pglite": "^0.4.5",
29
- "@rushstack/heft": "^1.2.17",
47
+ "@microsoft/api-extractor": "^7.58.7",
30
48
  "@types/node": "^24.12.4",
31
49
  "@types/pg": "^8.11.0",
32
50
  "@vitest/coverage-istanbul": "^4.1.5",
@@ -36,14 +54,15 @@
36
54
  "pg": "^8.20.0",
37
55
  "pglite-server": "^0.1.5",
38
56
  "typescript": "^6.0.3",
39
- "vite": "^7.3.2",
40
- "vitest": "^4.1.5",
41
- "stonecrop-rig": "0.7.0"
57
+ "vite": "^8.2.2",
58
+ "vitest": "^4.1.5"
59
+ },
60
+ "engines": {
61
+ "node": ">=24.0.0"
42
62
  },
43
63
  "scripts": {
44
- "_phase:build": "heft build --clean && vite build && rushx docs",
45
- "build": "heft build --clean && vite build && rushx docs",
46
- "docs": "bash ../common/scripts/run-docs.sh graphql_middleware",
64
+ "dev": "vite build --watch",
65
+ "docs": "bash ../tools/scripts/run-docs.sh graphql_middleware",
47
66
  "lint": "oxlint",
48
67
  "lint:fix": "oxlint --fix",
49
68
  "test": "vitest run --coverage.enabled false",
@@ -1 +0,0 @@
1
- {"version":"6.0.3"}
@@ -1,31 +0,0 @@
1
- /**
2
- * Options for the Stonecrop debug plugin.
3
- * @public
4
- */
5
- export interface DebugPluginOptions {
6
- /** Log a message when a plan is built for a Stonecrop field. Default: `true` */
7
- logPlans?: boolean;
8
- /** Log timing for plan construction. Default: `false` */
9
- logTiming?: boolean;
10
- }
11
- /**
12
- * Creates a PostGraphile plugin that wraps Stonecrop resolver plans with
13
- * debug logging. Use it in your preset file:
14
- *
15
- * ```typescript
16
- * import { createStonecropPlugin, createDebugPlugin } from '@stonecrop/graphql-middleware'
17
- *
18
- * export default {
19
- * plugins: [createStonecropPlugin(), createDebugPlugin()],
20
- * }
21
- * ```
22
- *
23
- * Place `createDebugPlugin()` **after** `createStonecropPlugin()` in the
24
- * plugins array so the wrapper sees the Stonecrop fields.
25
- *
26
- * @param options - Optional logging configuration
27
- * @returns A PostGraphile plugin
28
- * @public
29
- */
30
- export declare const createDebugPlugin: (options?: DebugPluginOptions) => GraphileConfig.Plugin;
31
- //# sourceMappingURL=debug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAS,kBAAuB,KAAG,cAAc,CAAC,MAmCnF,CAAA"}
package/dist/src/debug.js DELETED
@@ -1,49 +0,0 @@
1
- import { wrapPlans } from 'postgraphile/utils';
2
- /**
3
- * Creates a PostGraphile plugin that wraps Stonecrop resolver plans with
4
- * debug logging. Use it in your preset file:
5
- *
6
- * ```typescript
7
- * import { createStonecropPlugin, createDebugPlugin } from '@stonecrop/graphql-middleware'
8
- *
9
- * export default {
10
- * plugins: [createStonecropPlugin(), createDebugPlugin()],
11
- * }
12
- * ```
13
- *
14
- * Place `createDebugPlugin()` **after** `createStonecropPlugin()` in the
15
- * plugins array so the wrapper sees the Stonecrop fields.
16
- *
17
- * @param options - Optional logging configuration
18
- * @returns A PostGraphile plugin
19
- * @public
20
- */
21
- export const createDebugPlugin = (options = {}) => {
22
- const { logPlans = true, logTiming = false } = options;
23
- const wrapField = (typeName, fieldName) => ({
24
- plan: (plan) => {
25
- if (logPlans) {
26
- // oxlint-disable-next-line no-console
27
- console.log(`[@stonecrop/graphql-middleware] Building plan for ${typeName}.${fieldName}`);
28
- }
29
- const start = logTiming ? Date.now() : 0;
30
- const $result = plan();
31
- if (logTiming) {
32
- // oxlint-disable-next-line no-console
33
- console.log(`[@stonecrop/graphql-middleware] Plan built for ${typeName}.${fieldName} in ${Date.now() - start}ms`);
34
- }
35
- return $result;
36
- },
37
- });
38
- return wrapPlans({
39
- Query: {
40
- stonecropRecord: wrapField('Query', 'stonecropRecord'),
41
- stonecropRecords: wrapField('Query', 'stonecropRecords'),
42
- stonecropMeta: wrapField('Query', 'stonecropMeta'),
43
- stonecropAllMeta: wrapField('Query', 'stonecropAllMeta'),
44
- },
45
- Mutation: {
46
- stonecropAction: wrapField('Mutation', 'stonecropAction'),
47
- },
48
- });
49
- };
@@ -1,107 +0,0 @@
1
- /**
2
- * Backend IO the dispatch layer injects so the transition logic stays storage-agnostic.
3
- * The same guard runs whether the record lives in Postgres, a mock executor, or an
4
- * in-memory Map — only these closures change per backend.
5
- * @public
6
- */
7
- export interface GuardedTransitionIO {
8
- /**
9
- * Read the record's current workflow state — the value of its `status` field.
10
- *
11
- * Three answers, and the difference between the last two matters:
12
- * - a string — the record's current state
13
- * - `undefined` — the record exists but carries no workflow state
14
- * - `null` — **there is no such record**
15
- *
16
- * Collapsing those two into `undefined` is what let an action against a missing record report
17
- * success: the state read as `''`, an action declaring no `allowedStates` passed the guard, and
18
- * the write then found nothing to write. Backends must return `null` when the lookup misses.
19
- */
20
- readState: () => Promise<string | null | undefined>;
21
- /** Persist the record's new workflow state, written verbatim. */
22
- writeState: (nextState: string) => Promise<void>;
23
- /**
24
- * Persist a record's field data for a self-transition, returning the full record as it now
25
- * stands (so the client writeback reflects it).
26
- *
27
- * **This is an upsert, and it is the create path.** Saving a record is one request whether or
28
- * not the row is there yet, so there is no create action and no create mutation — `exists` says
29
- * which case you are in, and the second argument exists only because the dispatcher already
30
- * knows: it read the record's state to run the guard. When `exists` is false, mint or derive the
31
- * identity here and return the created record; identity is the backend's business, not the
32
- * dispatcher's. Read the declared `primaryKey` out of `data` for a natural-keyed doctype — that
33
- * value is a field the user filled in — and mint one only when the doctype is surrogate-keyed.
34
- *
35
- * Never return an empty object for a creation: the dispatcher treats that as a backend that
36
- * only knows how to patch, and fails loudly rather than reporting a save that stored nothing.
37
- *
38
- * Optional. A backend with no data-write path omits it, which is how it declines both saving
39
- * and creating; a self-transition is then rejected loudly rather than silently dropped — unless
40
- * `runEffect` is supplied, in which case the handler is the persistence path.
41
- */
42
- writeData?: (patch: Record<string, unknown>, exists: boolean) => Promise<Record<string, unknown>>;
43
- /**
44
- * Run the adapter's side effect for this action, after the guard has passed and before any
45
- * state is written. This is the seam a **database author** wires — see
46
- * `StonecropPluginOptions.actionHandlers` for the Postgres adapter's registration surface.
47
- *
48
- * It is what makes a stateless Command (no `nextState`, no `selfTransition`) executable at
49
- * all: without one, such an action has nothing to apply and fails loudly.
50
- *
51
- * Throwing rejects the action, so the dispatcher writes neither data nor state. It does **not**
52
- * undo writes the handler already made: this guard is storage-agnostic and owns no transaction,
53
- * and the Postgres adapter in particular dispatches outside one. A handler whose own statements
54
- * must be all-or-nothing has to wrap them itself.
55
- *
56
- * Returning a full record makes it the client writeback payload; returning `undefined` leaves
57
- * the doctype's own outcome to decide what comes back.
58
- *
59
- * @param currentState - The state the guard read, or `undefined` when nothing required reading it
60
- * @returns The updated record, or `undefined` to leave the result payload to the state outcome
61
- */
62
- runEffect?: (currentState: string | undefined) => Promise<unknown>;
63
- }
64
- /**
65
- * Apply a workflow action on the server, enforcing `allowedStates`.
66
- *
67
- * The server owns the transition: it reads the record's authoritative current state,
68
- * rejects the action when `isActionAllowedInState` denies it, then applies the outcome.
69
- * Storage access is injected via `io` so this one guard serves every backend and can never
70
- * disagree with the frontend's `getAvailableTransitions`, which shares the same predicate.
71
- *
72
- * **The doctype decides whether an action may run and what state results; the adapter decides
73
- * what actually happens.** `allowedStates`, `nextState` and `selfTransition` are authored in the
74
- * doctype (in DocBuilder, by whoever models the workflow); the effect is registered by whoever
75
- * owns the database. Neither names the other: an action never carries a handler name, and a
76
- * handler never overrides the guard.
77
- *
78
- * There are four action shapes this distinguishes:
79
- * - A cross-state **transition** (has `nextState`): writes the new `status`, guarded by `allowedStates`.
80
- * - A **self-transition** (`selfTransition: true`, no `nextState`, e.g. `Save`): stays in the current
81
- * state and persists record field `data` in place via `io.writeData`, guarded by `allowedStates`.
82
- * When the target record does not exist the same write creates it — saving a record is one
83
- * request whether or not the row is there yet, so there is no separate create action, no create
84
- * mutation, and no second write path for it.
85
- * - A **stateless command** (neither of the above) with an `io.runEffect`: the handler is the whole
86
- * outcome. Still guarded by `allowedStates`, and still forbidden from moving the record.
87
- * - Anything else — no `nextState`, no `selfTransition`, no registered effect — is either a genuine
88
- * authoring mistake or a command whose handler was never wired. It fails loudly before touching
89
- * the backend rather than reporting a false success.
90
- *
91
- * @param actionDef - The action's `label`, `allowedStates`, and either `nextState` (transition) or `selfTransition`
92
- * @param io - Backend read/write closures, plus the optional adapter-owned effect
93
- * @param data - Record field data for a self-transition's mutate-in-place write (ignored by transitions)
94
- * @returns Action result envelope — the freshest record the backend produced, or the resulting state
95
- * @public
96
- */
97
- export declare function applyGuardedTransition(actionDef: {
98
- label?: string;
99
- allowedStates?: string[];
100
- nextState?: string;
101
- selfTransition?: boolean;
102
- }, io: GuardedTransitionIO, data?: Record<string, unknown>): Promise<{
103
- success: boolean;
104
- data: unknown;
105
- error: string | null;
106
- }>;
107
- //# sourceMappingURL=transition.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transition.d.ts","sourceRoot":"","sources":["../../../src/dispatch/transition.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;;;;;;;;;OAWG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;IACnD,iEAAiE;IACjE,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAChD;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACjG;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAClE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,sBAAsB,CAC3C,SAAS,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,EACrG,EAAE,EAAE,mBAAmB,EACvB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CA4HpE"}
@@ -1,152 +0,0 @@
1
- import { isActionAllowedInState } from '@stonecrop/schema';
2
- /**
3
- * Apply a workflow action on the server, enforcing `allowedStates`.
4
- *
5
- * The server owns the transition: it reads the record's authoritative current state,
6
- * rejects the action when `isActionAllowedInState` denies it, then applies the outcome.
7
- * Storage access is injected via `io` so this one guard serves every backend and can never
8
- * disagree with the frontend's `getAvailableTransitions`, which shares the same predicate.
9
- *
10
- * **The doctype decides whether an action may run and what state results; the adapter decides
11
- * what actually happens.** `allowedStates`, `nextState` and `selfTransition` are authored in the
12
- * doctype (in DocBuilder, by whoever models the workflow); the effect is registered by whoever
13
- * owns the database. Neither names the other: an action never carries a handler name, and a
14
- * handler never overrides the guard.
15
- *
16
- * There are four action shapes this distinguishes:
17
- * - A cross-state **transition** (has `nextState`): writes the new `status`, guarded by `allowedStates`.
18
- * - A **self-transition** (`selfTransition: true`, no `nextState`, e.g. `Save`): stays in the current
19
- * state and persists record field `data` in place via `io.writeData`, guarded by `allowedStates`.
20
- * When the target record does not exist the same write creates it — saving a record is one
21
- * request whether or not the row is there yet, so there is no separate create action, no create
22
- * mutation, and no second write path for it.
23
- * - A **stateless command** (neither of the above) with an `io.runEffect`: the handler is the whole
24
- * outcome. Still guarded by `allowedStates`, and still forbidden from moving the record.
25
- * - Anything else — no `nextState`, no `selfTransition`, no registered effect — is either a genuine
26
- * authoring mistake or a command whose handler was never wired. It fails loudly before touching
27
- * the backend rather than reporting a false success.
28
- *
29
- * @param actionDef - The action's `label`, `allowedStates`, and either `nextState` (transition) or `selfTransition`
30
- * @param io - Backend read/write closures, plus the optional adapter-owned effect
31
- * @param data - Record field data for a self-transition's mutate-in-place write (ignored by transitions)
32
- * @returns Action result envelope — the freshest record the backend produced, or the resulting state
33
- * @public
34
- */
35
- export async function applyGuardedTransition(actionDef, io, data) {
36
- const label = actionDef.label ?? 'unknown';
37
- const isSelfTransition = actionDef.selfTransition === true;
38
- const hasStateOutcome = isSelfTransition || actionDef.nextState != null;
39
- // Nothing to apply and no effect registered — fail loudly WITHOUT touching the backend.
40
- // This is the honest report for both causes: an action authored with no outcome, and a
41
- // command whose server handler the adapter never registered.
42
- if (!hasStateOutcome && !io.runEffect) {
43
- return {
44
- success: false,
45
- data: null,
46
- error: `Action "${label}" has no workflow transition and no server-side effect is wired — nothing was executed. Give it a nextState or selfTransition in the doctype, or register a server-side handler for it on the adapter.`,
47
- };
48
- }
49
- // A self-transition exists to persist data; with no way at all to do that — no data write, no
50
- // create, no effect — reject before running anything rather than half-applying.
51
- if (isSelfTransition && !io.writeData && !io.runEffect) {
52
- return {
53
- success: false,
54
- data: null,
55
- error: `Action "${label}" persists record data in place, which this backend does not support.`,
56
- };
57
- }
58
- // Read the authoritative state only when something actually consumes it: the guard, or a
59
- // state outcome that the caller's readState is paired with. A handler-only command on a
60
- // doctype with no `status` column must not be forced through a read it never uses.
61
- const isGuarded = (actionDef.allowedStates?.length ?? 0) > 0;
62
- let currentState;
63
- if (isGuarded || hasStateOutcome) {
64
- const state = await io.readState();
65
- // A missing record is reported, never guarded around. Reaching the guard with a state of
66
- // `''` produced two wrong answers depending only on whether the action declared
67
- // `allowedStates`: a misleading "not allowed from state: (unknown)" when it did, and a
68
- // silent `{ success: true }` writing nothing when it did not.
69
- if (state === null) {
70
- // A self-transition against a record that is not there is a create — the same write,
71
- // against a row that does not exist yet. The guard is deliberately skipped:
72
- // `allowedStates` constrains movement between states, and a record being created is not
73
- // in one; its initial state is the backend's to set.
74
- //
75
- // A registered effect does NOT run here. An effect is written against an existing row,
76
- // and firing it against a just-created one is a different contract than the one it was
77
- // registered under; making creation observable to effects is deferred rather than
78
- // guessed at.
79
- if (isSelfTransition && io.writeData) {
80
- const created = await io.writeData(data ?? {}, false);
81
- // A backend that only knows how to patch returns nothing here, having matched no
82
- // row. Reporting that as success is the exact bug the `null` answer above exists to
83
- // kill, so it must not come back through the create path.
84
- if (!created || Object.keys(created).length === 0) {
85
- return {
86
- success: false,
87
- data: null,
88
- error: `Action "${label}" targets a record that does not exist, and the backend did not create it.`,
89
- };
90
- }
91
- return { success: true, data: created, error: null };
92
- }
93
- return {
94
- success: false,
95
- data: null,
96
- error: `Action "${label}" targets a record that does not exist — nothing was executed.`,
97
- };
98
- }
99
- currentState = state ?? '';
100
- }
101
- if (!isActionAllowedInState(actionDef, currentState ?? '')) {
102
- return {
103
- success: false,
104
- data: null,
105
- error: `Action not allowed from state: ${currentState || '(unknown)'}`,
106
- };
107
- }
108
- // The effect runs after the guard and before any write, so a handler that rejects cannot
109
- // leave the record in the target state. Its throw is attributed to the action by name —
110
- // the adapter's handler is code the doctype author cannot see, so an anonymous failure
111
- // would be undebuggable from either side.
112
- let effectResult;
113
- if (io.runEffect) {
114
- try {
115
- effectResult = await io.runEffect(currentState);
116
- }
117
- catch (err) {
118
- return {
119
- success: false,
120
- data: null,
121
- error: `Action "${label}" failed: ${err instanceof Error ? err.message : String(err)}`,
122
- };
123
- }
124
- }
125
- // Self-transition: mutate record data in place, keep the current state. The full updated
126
- // record is returned so the client writeback reflects the new data. When the backend has no
127
- // data-write path the effect above already did the persisting (guarded at the top).
128
- if (isSelfTransition) {
129
- const record = io.writeData ? await io.writeData(data ?? {}, true) : effectResult;
130
- return { success: true, data: record ?? null, error: null };
131
- }
132
- // NON-ATOMIC: the current state is read above and nextState written here as two
133
- // separate statements — and a registered effect runs between them. Two concurrent
134
- // transitions on the same record can both pass the guard before either writes, so both
135
- // "succeed" even when the workflow intended them to be mutually exclusive. Closing this
136
- // requires guarding and writing in one statement — an atomic
137
- // `UPDATE ... SET status = nextState WHERE status = ANY(allowedStates)` — and reporting
138
- // "no rows updated" as a rejected transition. Deferred for now.
139
- if (actionDef.nextState == null) {
140
- // A stateless command: the effect (guaranteed present by the top guard) is the whole
141
- // outcome. It must not move the record — that is the doctype's call, not the handler's.
142
- return { success: true, data: effectResult ?? null, error: null };
143
- }
144
- await io.writeState(actionDef.nextState);
145
- // The freshest thing the backend produced wins: a handler that returned a record describes
146
- // the row better than the state alone, which is all a bare transition knows.
147
- return {
148
- success: true,
149
- data: effectResult ?? { state: actionDef.nextState },
150
- error: null,
151
- };
152
- }
@@ -1,23 +0,0 @@
1
- import type { DoctypeField, ValueField } from '@stonecrop/schema';
2
- import { flattenFields } from '@stonecrop/schema';
3
- export { flattenFields };
4
- /**
5
- * The fields that have a database column of their own — the one definition of that question.
6
- *
7
- * Two properties disqualify a field, and both are the field saying so itself: a `computed` field is
8
- * declared precisely to state it has no column, and a container (a table field) is a relation
9
- * rather than a value. Everything else names a column.
10
- *
11
- * This is deliberately **not** the same question as "does this column belong in a record payload".
12
- * An *expanding* link's foreign key has a real column that this returns, while `collectColumns`
13
- * omits it from the SELECT on purpose because the relation is fetched separately. Conflating the
14
- * two is how the read path came to drop the very column its expansion needed. Callers wanting the
15
- * payload projection filter this further by render mode; callers asking whether a column exists —
16
- * link validation, and the write path deciding what it may set — want it unfiltered.
17
- *
18
- * Extracted because the rule had grown three statements across two modules, one of them a comment
19
- * reading "mirrors `collectColumns`". A rule that has to be mirrored by hand is one edit away from
20
- * the read path and the validator disagreeing about what a doctype declares.
21
- */
22
- export declare function columnBackedFields(fields: readonly DoctypeField[]): ValueField[];
23
- //# sourceMappingURL=fields.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAOjD,OAAO,EAAE,aAAa,EAAE,CAAA;AAExB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAEhF"}
@@ -1,28 +0,0 @@
1
- import { flattenFields } from '@stonecrop/schema';
2
- // Re-exported so this module stays the one place the adapter asks about a doctype's fields, while
3
- // the definition itself lives in `@stonecrop/schema`. It moved there because `DoctypeMeta`'s own
4
- // validation needs the same descent, and the copy it had written instead scanned top level only —
5
- // so the load gate and the read path disagreed about what a doctype declares, which is exactly
6
- // what keeping one definition is for.
7
- export { flattenFields };
8
- /**
9
- * The fields that have a database column of their own — the one definition of that question.
10
- *
11
- * Two properties disqualify a field, and both are the field saying so itself: a `computed` field is
12
- * declared precisely to state it has no column, and a container (a table field) is a relation
13
- * rather than a value. Everything else names a column.
14
- *
15
- * This is deliberately **not** the same question as "does this column belong in a record payload".
16
- * An *expanding* link's foreign key has a real column that this returns, while `collectColumns`
17
- * omits it from the SELECT on purpose because the relation is fetched separately. Conflating the
18
- * two is how the read path came to drop the very column its expansion needed. Callers wanting the
19
- * payload projection filter this further by render mode; callers asking whether a column exists —
20
- * link validation, and the write path deciding what it may set — want it unfiltered.
21
- *
22
- * Extracted because the rule had grown three statements across two modules, one of them a comment
23
- * reading "mirrors `collectColumns`". A rule that has to be mirrored by hand is one edit away from
24
- * the read path and the validator disagreeing about what a doctype declares.
25
- */
26
- export function columnBackedFields(fields) {
27
- return flattenFields(fields).filter((f) => f.kind === 'field' && !f.computed);
28
- }
@@ -1,16 +0,0 @@
1
- export type { DoctypeMeta, ValidationError } from '@stonecrop/schema';
2
- export { loadDoctypes, loadDoctypesFromObject, getMeta, getAllMeta, hasMeta, clearRegistry, DoctypeValidationError, } from './registry/doctypes';
3
- export type { LoadDoctypesOptions } from './registry/doctypes';
4
- export { registerFetchHandler, getFetchHandler, clearFetchHandlers } from './registry/fetchHandlers';
5
- export type { FetchHandler } from './registry/fetchHandlers';
6
- export { applyGuardedTransition } from './dispatch/transition';
7
- export type { GuardedTransitionIO } from './dispatch/transition';
8
- export { createStonecropPlugin } from './plugin/postgraphile';
9
- export type { StonecropPluginOptions, ActionHandler, ActionHandlerContext } from './plugin/postgraphile';
10
- export { createDebugPlugin } from './debug';
11
- export type { DebugPluginOptions } from './debug';
12
- export { typeDefs } from './typeDefs';
13
- export { createStonecropPreset, StonecropPreset } from './preset';
14
- export type { FieldCasing } from './preset';
15
- export { makePgService } from 'postgraphile/adaptors/pg';
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,EACN,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,UAAU,EACV,OAAO,EACP,aAAa,EACb,sBAAsB,GACtB,MAAM,qBAAqB,CAAA;AAE5B,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAG9D,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AACpG,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAGhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,YAAY,EAAE,sBAAsB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAGxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACjE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA"}
package/dist/src/index.js DELETED
@@ -1,14 +0,0 @@
1
- // Doctype registry
2
- export { loadDoctypes, loadDoctypesFromObject, getMeta, getAllMeta, hasMeta, clearRegistry, DoctypeValidationError, } from './registry/doctypes';
3
- // Fetch handlers
4
- export { registerFetchHandler, getFetchHandler, clearFetchHandlers } from './registry/fetchHandlers';
5
- // Server-owned workflow transition (guarded by allowedStates)
6
- export { applyGuardedTransition } from './dispatch/transition';
7
- // PostGraphile plugin
8
- export { createStonecropPlugin } from './plugin/postgraphile';
9
- // Debug plugin
10
- export { createDebugPlugin } from './debug';
11
- export { typeDefs } from './typeDefs';
12
- // Preset
13
- export { createStonecropPreset, StonecropPreset } from './preset';
14
- export { makePgService } from 'postgraphile/adaptors/pg';
@@ -1,19 +0,0 @@
1
- import type { DoctypeMeta } from '@stonecrop/schema';
2
- import type { PgClient } from '@dataplan/pg';
3
- type SqlQueryFn = (pgClient: PgClient, query: {
4
- text: string;
5
- values?: unknown[];
6
- }) => Promise<{
7
- rows: readonly Record<string, unknown>[];
8
- }>;
9
- /**
10
- * Replace inline link FK scalars with `{ id, displayText }` when the target doctype declares a
11
- * `displayField`. Expanded relations (object values) are skipped.
12
- *
13
- * Takes every row at once and issues one lookup per FK field, not per row. Callers holding a batch
14
- * must pass the whole batch: called per row inside a loader's own loop it reinstates the N+1 the
15
- * loader exists to prevent, and does so invisibly, since the result is identical either way.
16
- */
17
- export declare function enrichLinkDisplayFields(pgClient: PgClient, meta: DoctypeMeta, rows: Record<string, unknown>[], tables: Record<string, string> | undefined, debugSql: SqlQueryFn): Promise<void>;
18
- export {};
19
- //# sourceMappingURL=link-display.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"link-display.d.ts","sourceRoot":"","sources":["../../src/link-display.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAK5C,KAAK,UAAU,GAAG,CACjB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;CAAE,KACvC,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAAE,CAAC,CAAA;AAqD1D;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC5C,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC1C,QAAQ,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CAyCf"}