@opensaas/stack-core 0.37.0 → 0.39.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 (226) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +191 -0
  3. package/CLAUDE.md +42 -3
  4. package/dist/access/access-filter.d.ts +70 -113
  5. package/dist/access/access-filter.d.ts.map +1 -1
  6. package/dist/access/access-filter.js +183 -210
  7. package/dist/access/access-filter.js.map +1 -1
  8. package/dist/access/access-filter.test.js +148 -188
  9. package/dist/access/access-filter.test.js.map +1 -1
  10. package/dist/access/declared-dependencies.d.ts +66 -26
  11. package/dist/access/declared-dependencies.d.ts.map +1 -1
  12. package/dist/access/declared-dependencies.js +62 -17
  13. package/dist/access/declared-dependencies.js.map +1 -1
  14. package/dist/access/declared-dependencies.test.d.ts +2 -0
  15. package/dist/access/declared-dependencies.test.d.ts.map +1 -0
  16. package/dist/access/declared-dependencies.test.js +226 -0
  17. package/dist/access/declared-dependencies.test.js.map +1 -0
  18. package/dist/access/depth-limits.d.ts +8 -7
  19. package/dist/access/depth-limits.d.ts.map +1 -1
  20. package/dist/access/depth-limits.js +8 -7
  21. package/dist/access/depth-limits.js.map +1 -1
  22. package/dist/access/engine.d.ts +0 -20
  23. package/dist/access/engine.d.ts.map +1 -1
  24. package/dist/access/engine.js +0 -25
  25. package/dist/access/engine.js.map +1 -1
  26. package/dist/access/errors.d.ts +61 -8
  27. package/dist/access/errors.d.ts.map +1 -1
  28. package/dist/access/errors.js +91 -12
  29. package/dist/access/errors.js.map +1 -1
  30. package/dist/access/field-access.d.ts +39 -1
  31. package/dist/access/field-access.d.ts.map +1 -1
  32. package/dist/access/field-access.js +108 -42
  33. package/dist/access/field-access.js.map +1 -1
  34. package/dist/access/field-access.test.js +229 -2
  35. package/dist/access/field-access.test.js.map +1 -1
  36. package/dist/access/field-transforms.d.ts +0 -27
  37. package/dist/access/field-transforms.d.ts.map +1 -1
  38. package/dist/access/field-visibility.d.ts +2 -5
  39. package/dist/access/field-visibility.d.ts.map +1 -1
  40. package/dist/access/field-visibility.js +89 -41
  41. package/dist/access/field-visibility.js.map +1 -1
  42. package/dist/access/index.d.ts +6 -3
  43. package/dist/access/index.d.ts.map +1 -1
  44. package/dist/access/index.js +12 -2
  45. package/dist/access/index.js.map +1 -1
  46. package/dist/access/query-validation.d.ts +121 -0
  47. package/dist/access/query-validation.d.ts.map +1 -0
  48. package/dist/access/query-validation.js +292 -0
  49. package/dist/access/query-validation.js.map +1 -0
  50. package/dist/access/relationship-count.d.ts +1 -1
  51. package/dist/access/relationship-count.d.ts.map +1 -1
  52. package/dist/access/relationship-count.js +2 -10
  53. package/dist/access/relationship-count.js.map +1 -1
  54. package/dist/access/relationship-label-filter.d.ts +23 -23
  55. package/dist/access/relationship-label-filter.d.ts.map +1 -1
  56. package/dist/access/relationship-label-filter.js +5 -76
  57. package/dist/access/relationship-label-filter.js.map +1 -1
  58. package/dist/access/relationship-label-filter.test.js +19 -56
  59. package/dist/access/relationship-label-filter.test.js.map +1 -1
  60. package/dist/access/transaction-registry.d.ts +45 -0
  61. package/dist/access/transaction-registry.d.ts.map +1 -0
  62. package/dist/access/transaction-registry.js +37 -0
  63. package/dist/access/transaction-registry.js.map +1 -0
  64. package/dist/access/types.d.ts +55 -59
  65. package/dist/access/types.d.ts.map +1 -1
  66. package/dist/config/index.d.ts +9 -7
  67. package/dist/config/index.d.ts.map +1 -1
  68. package/dist/config/index.js +10 -18
  69. package/dist/config/index.js.map +1 -1
  70. package/dist/config/label.d.ts +6 -13
  71. package/dist/config/label.d.ts.map +1 -1
  72. package/dist/config/label.js +6 -13
  73. package/dist/config/label.js.map +1 -1
  74. package/dist/config/nav-count.d.ts +11 -19
  75. package/dist/config/nav-count.d.ts.map +1 -1
  76. package/dist/config/nav-count.js +11 -19
  77. package/dist/config/nav-count.js.map +1 -1
  78. package/dist/config/plugin-engine.d.ts +0 -10
  79. package/dist/config/plugin-engine.d.ts.map +1 -1
  80. package/dist/config/plugin-engine.js +1 -37
  81. package/dist/config/plugin-engine.js.map +1 -1
  82. package/dist/config/types.d.ts +94 -109
  83. package/dist/config/types.d.ts.map +1 -1
  84. package/dist/context/apply-defaults.d.ts +8 -31
  85. package/dist/context/apply-defaults.d.ts.map +1 -1
  86. package/dist/context/apply-defaults.js +12 -41
  87. package/dist/context/apply-defaults.js.map +1 -1
  88. package/dist/context/hook-pipeline.d.ts +4 -29
  89. package/dist/context/hook-pipeline.d.ts.map +1 -1
  90. package/dist/context/hook-pipeline.js +8 -41
  91. package/dist/context/hook-pipeline.js.map +1 -1
  92. package/dist/context/index.d.ts +4 -15
  93. package/dist/context/index.d.ts.map +1 -1
  94. package/dist/context/index.js +223 -215
  95. package/dist/context/index.js.map +1 -1
  96. package/dist/context/nested-operations.d.ts +7 -26
  97. package/dist/context/nested-operations.d.ts.map +1 -1
  98. package/dist/context/nested-operations.js +73 -171
  99. package/dist/context/nested-operations.js.map +1 -1
  100. package/dist/context/transaction-boundary.d.ts +36 -47
  101. package/dist/context/transaction-boundary.d.ts.map +1 -1
  102. package/dist/context/transaction-boundary.js +92 -79
  103. package/dist/context/transaction-boundary.js.map +1 -1
  104. package/dist/context/write-pipeline.d.ts +25 -64
  105. package/dist/context/write-pipeline.d.ts.map +1 -1
  106. package/dist/context/write-pipeline.js +81 -111
  107. package/dist/context/write-pipeline.js.map +1 -1
  108. package/dist/fields/format-prisma-default.d.ts.map +1 -1
  109. package/dist/fields/format-prisma-default.js +4 -7
  110. package/dist/fields/format-prisma-default.js.map +1 -1
  111. package/dist/fields/index.d.ts +17 -2
  112. package/dist/fields/index.d.ts.map +1 -1
  113. package/dist/fields/index.js +136 -147
  114. package/dist/fields/index.js.map +1 -1
  115. package/dist/filter/collect.d.ts +26 -3
  116. package/dist/filter/collect.d.ts.map +1 -1
  117. package/dist/filter/collect.js +30 -12
  118. package/dist/filter/collect.js.map +1 -1
  119. package/dist/filter/filter.test.js +98 -15
  120. package/dist/filter/filter.test.js.map +1 -1
  121. package/dist/filter/index.d.ts +1 -0
  122. package/dist/filter/index.d.ts.map +1 -1
  123. package/dist/filter/index.js.map +1 -1
  124. package/dist/filter/map.d.ts.map +1 -1
  125. package/dist/filter/map.js +0 -5
  126. package/dist/filter/map.js.map +1 -1
  127. package/dist/filter/parse.d.ts.map +1 -1
  128. package/dist/filter/parse.js +2 -9
  129. package/dist/filter/parse.js.map +1 -1
  130. package/dist/filter/serialize.d.ts.map +1 -1
  131. package/dist/filter/serialize.js +2 -4
  132. package/dist/filter/serialize.js.map +1 -1
  133. package/dist/hooks/index.d.ts +4 -42
  134. package/dist/hooks/index.d.ts.map +1 -1
  135. package/dist/hooks/index.js +5 -59
  136. package/dist/hooks/index.js.map +1 -1
  137. package/dist/index.d.ts +3 -1
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +20 -4
  140. package/dist/index.js.map +1 -1
  141. package/dist/internal.d.ts +1 -0
  142. package/dist/internal.d.ts.map +1 -1
  143. package/dist/internal.js +4 -0
  144. package/dist/internal.js.map +1 -1
  145. package/dist/lib/case-utils.d.ts +0 -32
  146. package/dist/lib/case-utils.d.ts.map +1 -1
  147. package/dist/lib/case-utils.js +0 -32
  148. package/dist/lib/case-utils.js.map +1 -1
  149. package/dist/mcp/handler.d.ts +0 -4
  150. package/dist/mcp/handler.d.ts.map +1 -1
  151. package/dist/mcp/handler.js +12 -69
  152. package/dist/mcp/handler.js.map +1 -1
  153. package/dist/query/index.d.ts +55 -227
  154. package/dist/query/index.d.ts.map +1 -1
  155. package/dist/query/index.js +41 -117
  156. package/dist/query/index.js.map +1 -1
  157. package/dist/query/relationship-options.d.ts +1 -1
  158. package/dist/query/relationship-options.js +1 -1
  159. package/dist/utils/password.d.ts +0 -68
  160. package/dist/utils/password.d.ts.map +1 -1
  161. package/dist/utils/password.js +7 -76
  162. package/dist/utils/password.js.map +1 -1
  163. package/dist/validation/field-config.d.ts.map +1 -1
  164. package/dist/validation/field-config.js +0 -6
  165. package/dist/validation/field-config.js.map +1 -1
  166. package/dist/validation/schema.d.ts +0 -7
  167. package/dist/validation/schema.d.ts.map +1 -1
  168. package/dist/validation/schema.js +0 -10
  169. package/dist/validation/schema.js.map +1 -1
  170. package/package.json +1 -1
  171. package/src/access/access-filter.test.ts +205 -275
  172. package/src/access/access-filter.ts +236 -272
  173. package/src/access/declared-dependencies.test.ts +277 -0
  174. package/src/access/declared-dependencies.ts +117 -37
  175. package/src/access/depth-limits.ts +8 -7
  176. package/src/access/engine.ts +0 -25
  177. package/src/access/errors.ts +97 -12
  178. package/src/access/field-access.test.ts +312 -2
  179. package/src/access/field-access.ts +118 -42
  180. package/src/access/field-transforms.ts +8 -39
  181. package/src/access/field-visibility.ts +99 -45
  182. package/src/access/index.ts +17 -5
  183. package/src/access/query-validation.ts +359 -0
  184. package/src/access/relationship-count.ts +3 -11
  185. package/src/access/relationship-label-filter.test.ts +19 -68
  186. package/src/access/relationship-label-filter.ts +27 -104
  187. package/src/access/transaction-registry.ts +58 -0
  188. package/src/access/types.ts +83 -86
  189. package/src/config/index.ts +10 -22
  190. package/src/config/label.ts +6 -13
  191. package/src/config/nav-count.ts +11 -19
  192. package/src/config/plugin-engine.ts +1 -37
  193. package/src/config/types.ts +95 -110
  194. package/src/context/apply-defaults.ts +12 -44
  195. package/src/context/hook-pipeline.ts +12 -67
  196. package/src/context/index.ts +311 -276
  197. package/src/context/nested-operations.ts +94 -226
  198. package/src/context/transaction-boundary.ts +113 -109
  199. package/src/context/write-pipeline.ts +99 -155
  200. package/src/fields/format-prisma-default.ts +4 -7
  201. package/src/fields/index.ts +155 -147
  202. package/src/filter/collect.ts +48 -12
  203. package/src/filter/filter.test.ts +153 -15
  204. package/src/filter/index.ts +1 -0
  205. package/src/filter/map.ts +0 -5
  206. package/src/filter/parse.ts +2 -9
  207. package/src/filter/serialize.ts +2 -4
  208. package/src/hooks/index.ts +5 -59
  209. package/src/index.ts +23 -4
  210. package/src/internal.ts +5 -0
  211. package/src/lib/case-utils.ts +0 -32
  212. package/src/mcp/handler.ts +13 -71
  213. package/src/query/index.ts +82 -235
  214. package/src/query/relationship-options.ts +1 -1
  215. package/src/utils/password.ts +7 -76
  216. package/src/validation/field-config.ts +0 -6
  217. package/src/validation/schema.ts +0 -10
  218. package/tests/access-relationships.test.ts +18 -16
  219. package/tests/computed-field-selective-evaluation.test.ts +418 -0
  220. package/tests/context.test.ts +727 -1
  221. package/tests/field-types.test.ts +222 -0
  222. package/tests/mcp-handler.test.ts +34 -0
  223. package/tests/needs-declared-dependencies.test.ts +7 -4
  224. package/tests/resolve-chain.test.ts +11 -11
  225. package/tests/transaction-boundary-outermost.test.ts +530 -0
  226. package/tsconfig.tsbuildinfo +1 -1
@@ -1,28 +1,16 @@
1
1
  import type { OpenSaasConfig, ListConfig } from '../config/types.js';
2
2
  import type { AccessContext, PrismaClientLike } from '../access/types.js';
3
3
  /**
4
- * Write Pipeline — the single module that runs the canonical, secured write
5
- * sequence for one create/update/delete. It owns the phase order in one place;
6
- * the per-operation differences (target resolution + access, which input phases
7
- * run, the DB verb and returned row) are supplied by a {@link WriteStrategy}.
8
- *
9
- * The phase order is the framework's single most important invariant. See the
10
- * "Write Pipeline" glossary term in CONTEXT.md and the hooks ordering in
11
- * CLAUDE.md. Reads (findUnique/findMany) and the two-phase read model
12
- * (ADR-0001) are intentionally out of scope here.
13
- */
14
- /**
15
- * The write operations the pipeline can run.
4
+ * Write Pipeline — runs the canonical, secured write sequence for one
5
+ * create/update/delete; see the "Write Pipeline" glossary entry in CONTEXT.md
6
+ * for the phase order and the hooks ordering in CLAUDE.md. Reads are out of
7
+ * scope (ADR-0001).
16
8
  */
17
9
  export type WriteOperation = 'create' | 'update' | 'delete';
18
10
  /**
19
- * Result of resolving a write target (axis 1).
20
- *
21
- * - `{ status: 'ok', originalItem }` — proceed. `originalItem` is the existing
22
- * row for update/delete, or `undefined` for create.
23
- * - `{ status: 'denied' }` — access denied, missing target, or filter
24
- * non-match. The pipeline short-circuits to `null` (silent failure) BEFORE
25
- * any input phases, before-hooks, or the DB call.
11
+ * Result of resolving a write target (axis 1). `denied` covers access denial,
12
+ * a missing target, or a filter non-match alike, and short-circuits to `null`
13
+ * before any hooks or the DB call.
26
14
  */
27
15
  export type TargetResolution = {
28
16
  status: 'ok';
@@ -57,20 +45,13 @@ export interface PrismaModel {
57
45
  }
58
46
  /**
59
47
  * Per-operation strategy. Supplies the three axes on which create/update/delete
60
- * genuinely differ; the pipeline owns the shared phase order around them.
61
- *
62
- * 1. `resolveTarget` — fetch the target row (if any) + operation-level access.
63
- * 2. `runInputPhases` — whether the resolveInput → validate-hooks → field
64
- * rules → filter-writable → nested-ops span runs (create & update: yes;
65
- * delete: no).
66
- * 3. `persist` — the DB verb; returns the row passed through Field Visibility.
48
+ * differ; the pipeline owns the shared phase order around them.
67
49
  */
68
50
  export interface WriteStrategy {
69
51
  operation: WriteOperation;
70
52
  /**
71
- * Axis 1: resolve the target row and check operation-level access. Receives
72
- * the dynamically-resolved Prisma model so it can fetch rows and perform
73
- * filter re-checks. Implementations must honour `context._isSudo`.
53
+ * Axis 1: resolve the target row and check operation-level access.
54
+ * Implementations must honour `context._isSudo`.
74
55
  */
75
56
  resolveTarget(model: PrismaModel): Promise<TargetResolution>;
76
57
  /**
@@ -87,9 +68,6 @@ export interface WriteStrategy {
87
68
  */
88
69
  persist(model: PrismaModel, data: Record<string, unknown>, include?: Record<string, unknown>): Promise<Record<string, unknown>>;
89
70
  }
90
- /**
91
- * Arguments shared by every write pipeline run.
92
- */
93
71
  export interface WritePipelineArgs<TPrisma extends PrismaClientLike> {
94
72
  listName: string;
95
73
  listConfig: ListConfig<any>;
@@ -98,58 +76,41 @@ export interface WritePipelineArgs<TPrisma extends PrismaClientLike> {
98
76
  config: OpenSaasConfig;
99
77
  /** The original input data for the write (create/update). `undefined` for delete. */
100
78
  inputData: Record<string, unknown> | undefined;
101
- /** The per-operation strategy supplying the three variation axes. */
79
+ /** The per-operation strategy (see {@link WriteStrategy}). */
102
80
  strategy: WriteStrategy;
103
81
  /**
104
- * The target resolution computed ONCE before the transaction opened (#590).
105
- *
106
- * The transaction-boundary bracket resolves the top-level target + access
107
- * before opening the transaction (both to gate silent-failures without firing
108
- * boundary hooks, and to supply `originalItem` to `beforeTransaction`). To
109
- * avoid a second resolution inside the transaction, the in-transaction body
110
- * reuses this result instead of calling `strategy.resolveTarget` again.
82
+ * The target resolution computed once before the transaction opens, and
83
+ * reused inside it rather than resolved a second time — see the
84
+ * pre-transaction gate in {@link runWritePipeline}.
111
85
  */
112
86
  preResolvedTarget?: TargetResolution;
113
87
  }
114
88
  /**
115
- * Run the canonical secured write sequence once.
116
- *
117
- * Phase order (owned here, in one place):
118
- * resolve target + operation-level access
119
- * → list/field `resolveInput`
120
- * → list/field `validate`
121
- * → built-in field rules (`validateFieldRules`)
122
- * → filter writable fields
123
- * → nested operations
124
- * → list/field `beforeOperation`
125
- * → DB
126
- * → list/field `afterOperation`
127
- * → `filterReadableFields` (Field Visibility)
89
+ * Run the canonical secured write sequence once. Phase order matches the
90
+ * "Write Pipeline" glossary entry in CONTEXT.md.
128
91
  *
129
92
  * Contract preserved exactly:
130
93
  * - missing target / access denied / filter non-match → `null` (silent),
131
94
  * BEFORE the DB call and BEFORE `beforeOperation`.
132
95
  * - validation failure → THROW `ValidationError` (never silent).
133
- * - sudo mode skips access checks and writable-field filtering (the strategy
134
- * and `filterWritableFields` both honour `context._isSudo`).
96
+ * - sudo mode skips access checks and writable-field filtering.
135
97
  * - `afterOperation` receives `originalItem` for update/delete (undefined for
136
98
  * create).
137
- * - delete returns the deleted row as-is (no Field Visibility pass), matching
138
- * current behaviour.
99
+ * - delete returns the deleted row as-is (no Field Visibility pass).
139
100
  */
140
101
  export declare function runWritePipeline<TPrisma extends PrismaClientLike>(args: WritePipelineArgs<TPrisma>): Promise<Record<string, unknown> | null>;
141
102
  /**
142
- * Create strategy.
103
+ * Create strategy for {@link WriteStrategy}.
143
104
  *
144
- * Axis 1: checks `create` access with NO existing row. Enforces the
145
- * singleton-create constraint even under sudo. On create, an access result of
146
- * `true` OR a filter object both proceed — there is no filter re-check.
105
+ * Axis 1: checks `create` access with no existing row; a filter result
106
+ * proceeds with no re-check (unlike update/delete). Enforces the
107
+ * singleton-create constraint even under sudo.
147
108
  * Axis 2: runs all input phases.
148
109
  * Axis 3: `model.create({ data })`, prepending `id: 1` for singleton lists.
149
110
  */
150
111
  export declare function createWriteStrategy(listName: string, listConfig: ListConfig<any>, context: AccessContext): WriteStrategy;
151
112
  /**
152
- * Update strategy.
113
+ * Update strategy for {@link WriteStrategy}.
153
114
  *
154
115
  * Axis 1: fetch row, check `update` access, re-check filter results.
155
116
  * Axis 2: runs all input phases.
@@ -159,11 +120,11 @@ export declare function updateWriteStrategy(listConfig: ListConfig<any>, context
159
120
  id: string;
160
121
  }): WriteStrategy;
161
122
  /**
162
- * Delete strategy.
123
+ * Delete strategy for {@link WriteStrategy}.
163
124
  *
164
125
  * Axis 1: enforce singleton constraint (even under sudo), fetch row, check
165
126
  * `delete` access, re-check filter results.
166
- * Axis 2: SKIPS input phases (runs only validate/field-validate).
127
+ * Axis 2: skips input phases (runs only validate/field-validate).
167
128
  * Axis 3: `model.delete({ where })`; afterOperation gets `originalItem`.
168
129
  */
169
130
  export declare function deleteWriteStrategy(listName: string, listConfig: ListConfig<any>, context: AccessContext, where: {
@@ -1 +1 @@
1
- {"version":3,"file":"write-pipeline.d.ts","sourceRoot":"","sources":["../../src/context/write-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AA2BzE;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE3D;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAA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B,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAC3B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GACpB,aAAa,CAgBf"}
@@ -3,6 +3,7 @@ import { executeValidate, executeBeforeOperation, executeAfterOperation, execute
3
3
  import { hookPipeline } from './hook-pipeline.js';
4
4
  import { processNestedOperations, runAfterTasks } from './nested-operations.js';
5
5
  import { enumerateInvolvedLists, runWithTransactionBoundary } from './transaction-boundary.js';
6
+ import { TransactionRegistry } from '../access/transaction-registry.js';
6
7
  import { getDbKey } from '../lib/case-utils.js';
7
8
  // NOTE: `index.ts` imports from this module too — this is an intentional cyclic
8
9
  // dependency. It is safe because `buildDbDelegate` is only INVOKED at write
@@ -11,23 +12,20 @@ import { getDbKey } from '../lib/case-utils.js';
11
12
  import { buildDbDelegate } from './index.js';
12
13
  /**
13
14
  * Resolve the dynamic Prisma model for a list. Model names are generated at
14
- * runtime from list keys, which is the one place a cast is unavoidable — it is
15
- * kept localized here (mirroring the existing pattern in `context/index.ts`).
15
+ * runtime, so the cast is unavoidable — kept localized here (mirrors
16
+ * `context/index.ts`).
16
17
  */
17
18
  function getModel(prisma, listName) {
18
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- model names are generated at runtime
19
20
  return prisma[getDbKey(listName)];
20
21
  }
21
22
  /**
22
- * Run `fn` inside ONE interactive transaction (ADR-0010: every write is
23
- * transactional, so the hook contract does not depend on whether a write
24
- * happened to be nested). The transaction client `tx` is passed to `fn` and
25
- * used as the persistence target for the parent + all nested writes, so they
26
- * are atomic and a throwing hook rolls the whole write back.
23
+ * Run `fn` inside ONE interactive transaction, used as the persistence target
24
+ * for the parent and all nested writes (ADR-0010).
27
25
  *
28
- * If the client does not expose `$transaction` (e.g. a test mock), `fn` runs
29
- * directly against the client — the hook ordering and arguments are identical;
30
- * only the rollback guarantee is provided by the real transaction.
26
+ * Without `$transaction` (e.g. a test mock), `fn` runs directly against the
27
+ * client — hook ordering and arguments are identical, but only a real
28
+ * transaction provides the rollback guarantee.
31
29
  */
32
30
  async function runInTransaction(prisma, fn) {
33
31
  const client = prisma;
@@ -36,52 +34,32 @@ async function runInTransaction(prisma, fn) {
36
34
  }
37
35
  return fn(prisma);
38
36
  }
39
- /**
40
- * Check if a list is configured as a singleton.
41
- */
42
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
43
38
  function isSingletonList(listConfig) {
44
39
  return !!listConfig.isSingleton;
45
40
  }
46
41
  /**
47
- * Run the canonical secured write sequence once.
48
- *
49
- * Phase order (owned here, in one place):
50
- * resolve target + operation-level access
51
- * → list/field `resolveInput`
52
- * → list/field `validate`
53
- * → built-in field rules (`validateFieldRules`)
54
- * → filter writable fields
55
- * → nested operations
56
- * → list/field `beforeOperation`
57
- * → DB
58
- * → list/field `afterOperation`
59
- * → `filterReadableFields` (Field Visibility)
42
+ * Run the canonical secured write sequence once. Phase order matches the
43
+ * "Write Pipeline" glossary entry in CONTEXT.md.
60
44
  *
61
45
  * Contract preserved exactly:
62
46
  * - missing target / access denied / filter non-match → `null` (silent),
63
47
  * BEFORE the DB call and BEFORE `beforeOperation`.
64
48
  * - validation failure → THROW `ValidationError` (never silent).
65
- * - sudo mode skips access checks and writable-field filtering (the strategy
66
- * and `filterWritableFields` both honour `context._isSudo`).
49
+ * - sudo mode skips access checks and writable-field filtering.
67
50
  * - `afterOperation` receives `originalItem` for update/delete (undefined for
68
51
  * create).
69
- * - delete returns the deleted row as-is (no Field Visibility pass), matching
70
- * current behaviour.
52
+ * - delete returns the deleted row as-is (no Field Visibility pass).
71
53
  */
72
54
  export async function runWritePipeline(args) {
73
55
  const { prisma, listName, listConfig, context, config, inputData, strategy } = args;
74
56
  // ── Pre-transaction access gate (#590) ──────────────────────────────────────
75
- // Resolve the TOP-LEVEL target + operation-level access OUTSIDE the
76
- // transaction first, using the NON-transactional client. A
77
- // denied/missing/filter-non-match target short-circuits to `null` (silent
78
- // failure) WITHOUT firing any transaction-boundary hooks a denied write
79
- // opens no transaction and takes no external action, so it must not run
80
- // beforeTransaction/afterTransaction. This resolution also yields the
81
- // top-level `originalItem` the boundary hooks receive for update/delete.
82
- // The result is passed into the transaction as `preResolvedTarget` and REUSED
83
- // there (the in-transaction resolveTarget does NOT re-run), so the target is
84
- // read exactly once — #569's resolveTarget call-count semantics are preserved.
57
+ // Resolves the top-level target + access OUTSIDE the transaction so a denied
58
+ // write short-circuits to `null` WITHOUT firing beforeTransaction/
59
+ // afterTransaction — a denied write takes no external action, so the
60
+ // boundary hooks must not run. The result feeds `preResolvedTarget` and is
61
+ // REUSED inside the transaction rather than re-resolved, keeping the target
62
+ // read exactly once (#569).
85
63
  const gate = await strategy.resolveTarget(getModel(prisma, listName));
86
64
  if (gate.status === 'denied') {
87
65
  return null;
@@ -95,50 +73,53 @@ export async function runWritePipeline(args) {
95
73
  topLevelOriginalItem: gate.originalItem,
96
74
  config,
97
75
  });
76
+ // ── Transaction ownership for the transaction-boundary hooks (ADR-0028) ────
77
+ // A context carrying `_transactionOwner` is JOINING an enclosing transaction
78
+ // it did not open — defer to that owner even if `prisma` here still exposes
79
+ // `$transaction`. Otherwise this write becomes the owner: the registry every
80
+ // joined write below it enqueues into.
81
+ const existingOwner = context._transactionOwner;
82
+ const opensOwnTransaction = !existingOwner && typeof prisma.$transaction === 'function';
83
+ const ownedRegistry = opensOwnTransaction ? new TransactionRegistry() : undefined;
84
+ const transactionOwnerForBody = existingOwner ?? ownedRegistry;
98
85
  // ── Bracket the transaction with beforeTransaction/afterTransaction (#590) ──
99
- // beforeTransaction runs before the transaction opens; afterTransaction runs
100
- // after it settles (commit or rollback), per the symmetric-bracket rule.
86
+ // afterTransaction fires when the transaction settles, deferred to the owner
87
+ // for a joined write (ADR-0028, symmetric-bracket rule).
101
88
  return runWithTransactionBoundary({
102
89
  involvedLists,
103
90
  context,
91
+ joinedOwner: existingOwner,
92
+ ownedRegistry,
104
93
  runTransaction: () =>
105
- // ADR-0010: every write runs inside ONE interactive transaction. The
106
- // parent and ALL nested writes share this transaction's client `tx` as
107
- // their persistence target, so they are atomic and a throwing
108
- // `beforeOperation`/`afterOperation` (or validation) rolls the whole write
109
- // back. `runWriteInTransaction` resolves the target row, runs the full
110
- // hook pipeline, persists, and runs nested + own `afterOperation` — all
111
- // against `tx`.
94
+ // ADR-0010: parent + nested writes share `tx` as their persistence target.
112
95
  runInTransaction(prisma, (tx) => runWriteInTransaction({
113
96
  ...args,
114
97
  prisma: tx,
115
- // Reuse the pre-transaction target resolution (computed above) so the
116
- // target is read exactly once (#569 call-count semantics preserved).
98
+ // Reuse the pre-transaction target resolution (#569 call-count semantics).
117
99
  preResolvedTarget: gate,
118
- // ADR-0010 atomicity: hooks that write via `context.db` must hit the
119
- // SAME transaction, or those writes would commit independently and
120
- // survive a rollback. Rebind the context's `db` (and `prisma`) to the
121
- // transaction client `tx` so before/afterOperation `context.db` writes
122
- // participate in — and roll back with — this write's transaction.
123
- context: bindContextToTransaction(args, tx),
100
+ // Rebind context.db/prisma to `tx` (ADR-0010 atomicity) and carry the
101
+ // transaction owner (ADR-0028) see bindContextToTransaction below.
102
+ context: bindContextToTransaction(args, tx, transactionOwnerForBody),
124
103
  })),
125
104
  });
126
105
  }
127
106
  /**
128
107
  * Build an {@link AccessContext} whose `db`/`prisma` target the transaction
129
- * client `tx`, so any `context.db` write a hook performs runs inside this
130
- * write's transaction and rolls back with it (ADR-0010).
108
+ * client `tx`, so a `context.db` write a hook performs runs inside — and rolls
109
+ * back with — this write's transaction (ADR-0010).
131
110
  *
132
111
  * The access-controlled `db` delegates capture their Prisma client at
133
- * construction, so the request-time `context.db` is bound to the ORIGINAL
134
- * client. We rebuild the delegates against `tx` via {@link buildDbDelegate},
135
- * reusing the request context's `session`, `storage`, `plugins`, `_isSudo`, and
136
- * the current `_resolveOutputChain` value (carried through unchanged, so a
137
- * write issued from inside a `resolveOutput` hook keeps that hook's chain).
138
- * Plugin runtimes are NOT re-executed; the existing `plugins` object is
139
- * reused as-is.
112
+ * construction, so swapping `context.prisma` alone would not rebind `db` — we
113
+ * rebuild the delegates against `tx` via {@link buildDbDelegate}, reusing the
114
+ * request context's `session`, `storage`, `plugins`, `_isSudo`, and
115
+ * `_resolveOutputChain` as-is (so a write from inside a `resolveOutput` hook
116
+ * keeps that hook's chain). Plugin runtimes are NOT re-executed.
117
+ *
118
+ * `transactionOwner` (ADR-0028) is carried onto the rebuilt context so a hook's
119
+ * own `context.db` write defers its transaction-boundary bracket to that owner
120
+ * instead of firing eagerly.
140
121
  */
141
- function bindContextToTransaction(args, tx) {
122
+ function bindContextToTransaction(args, tx, transactionOwner) {
142
123
  const { context, config } = args;
143
124
  const txContext = {
144
125
  session: context.session,
@@ -148,9 +129,10 @@ function bindContextToTransaction(args, tx) {
148
129
  plugins: context.plugins,
149
130
  _isSudo: context._isSudo,
150
131
  _resolveOutputChain: context._resolveOutputChain,
132
+ _transactionOwner: transactionOwner,
151
133
  };
152
- // Rebuild the db delegate against `tx`, pointing back at `txContext` so hooks
153
- // reached through it also see the transactional context.
134
+ // Rebuild `db` against `tx`, referencing `txContext` itself so hooks reached
135
+ // through it see the transactional context.
154
136
  txContext.db = buildDbDelegate(config, tx, txContext);
155
137
  return txContext;
156
138
  }
@@ -165,31 +147,24 @@ async function runWriteInTransaction(args) {
165
147
  const { operation } = strategy;
166
148
  const model = getModel(tx, listName);
167
149
  // ── Phase 1: resolve target + operation-level access ──────────────────────
168
- // Short-circuits to `null` (silent failure) for missing target, denied
169
- // access, or filter non-match before any hook side effects or the DB call.
170
- // The transaction-boundary bracket (#590) already resolved this once before
171
- // opening the transaction; reuse that result rather than reading the target
172
- // twice. (When invoked without the bracket — e.g. a direct unit test — fall
173
- // back to resolving here against the tx model.)
150
+ // Reuses `preResolvedTarget` from the pre-transaction gate rather than
151
+ // reading the target twice; falls back to resolving here when invoked
152
+ // directly (e.g. a unit test) without that bracket.
174
153
  const resolution = args.preResolvedTarget ?? (await strategy.resolveTarget(model));
175
154
  if (resolution.status === 'denied') {
176
155
  return null;
177
156
  }
178
157
  const originalItem = resolution.originalItem;
179
158
  // ── Delete path: skip input phases, run only validate/field-validate ────────
180
- // (matches current delete behaviour exactly).
181
159
  if (!strategy.runInputPhases) {
182
160
  return runDeletePath({ listName, listConfig, context, originalItem, model, strategy });
183
161
  }
184
- // Only create/update reach here (delete short-circuited above). Narrow the
185
- // operation so the field-hook helpers receive a 'create' | 'update' value.
162
+ // Only create/update reach here (delete short-circuited above); narrow so
163
+ // field-hook helpers receive a 'create' | 'update' value.
186
164
  const writeOp = operation === 'create' ? 'create' : 'update';
187
- // `inputData` is always present for create/update (the operations that run
188
- // input phases). Default to {} only as a defensive measure.
165
+ // `inputData` is always present here; `?? {}` is only a defensive fallback.
189
166
  const input = inputData ?? {};
190
- // ── Phases 2–4: transform + validate span (Hook Pipeline) ──────────────────
191
- // The Hook Pipeline owns the list/field `resolveInput` → list/field `validate`
192
- // → built-in field rules span and the `resolvedData` threading through it. It
167
+ // ── Phases 2–4: transform + validate span (Hook Pipeline glossary, CONTEXT.md) ──
193
168
  // THROWS `ValidationError` on any validation failure (never silent).
194
169
  const { resolvedData } = await hookPipeline.run({
195
170
  operation: writeOp,
@@ -207,16 +182,14 @@ async function runWriteInTransaction(args) {
207
182
  inputData: input,
208
183
  });
209
184
  // ── Phase 5.5: process nested relationship operations ───────────────────────
210
- // This runs each nested record's resolveInput/validate/field-rules AND its
211
- // `beforeOperation` (inside this transaction), returning the transformed
212
- // payload plus deferred `afterOperation` tasks and the relation fields to
213
- // `include` so those tasks can recover their persisted `item`. All nested DB
214
- // reads/persistence go through `tx`.
185
+ // Runs each nested record's resolveInput/validate/field-rules AND its
186
+ // `beforeOperation` inside this transaction, returning deferred
187
+ // `afterOperation` tasks plus the relation fields to `include` so those tasks
188
+ // can recover their persisted `item`.
215
189
  const { data, afterTasks, includeFields } = await processNestedOperations(filteredData, listConfig.fields, config, { ...context, prisma: tx }, writeOp, listName, originalItem,
216
- // Pass the enclosing write's `inputData` (the SAME value the Phase-5
217
- // `filterWritableFields` call above uses) so the connect-site owning-field
218
- // gate evaluates item-/inputData-dependent field rules identically to Phase 5
219
- // and the two cannot diverge into a spurious connect denial (#588 finding).
190
+ // Same `inputData` Phase 5's filterWritableFields used, so the connect-site
191
+ // owning-field gate evaluates identically and can't diverge into a
192
+ // spurious connect denial (#588).
220
193
  input);
221
194
  // ── Phase 6: field-level beforeOperation (side effects only) ────────────────
222
195
  await executeFieldBeforeOperationHooks(input, resolvedData, listConfig.fields, writeOp, context, listName, originalItem);
@@ -238,8 +211,8 @@ async function runWriteInTransaction(args) {
238
211
  context,
239
212
  });
240
213
  // ── Phase 8: DB write ───────────────────────────────────────────────────────
241
- // Ask the DB to return the nested relations that have deferred
242
- // `afterOperation` tasks so they can recover their persisted `item`.
214
+ // `include` returns the nested relations with deferred `afterOperation`
215
+ // tasks so they can recover their persisted `item`.
243
216
  const include = buildIncludeFromFields(includeFields);
244
217
  const item = await strategy.persist(model, data, include);
245
218
  // ── Phase 9: list-level afterOperation ──────────────────────────────────────
@@ -256,7 +229,7 @@ async function runWriteInTransaction(args) {
256
229
  listKey: listName,
257
230
  operation: 'update',
258
231
  inputData: input,
259
- // originalItem is the row before the update
232
+ // Non-null for update (fetched in Phase 1); cast narrows the type.
260
233
  originalItem: originalItem,
261
234
  item,
262
235
  resolvedData,
@@ -291,11 +264,9 @@ function buildIncludeFromFields(includeFields) {
291
264
  }
292
265
  /**
293
266
  * Run the deferred nested `afterOperation` tasks against the persisted parent
294
- * row. The persisted parent is always a record here; the `?? {}` is only a
295
- * type-narrowing guard. Each task recovers its OWN nested row from `item` by
296
- * id-diff (create) or known id (update); if a created row cannot be recovered
297
- * the task THROWS rather than firing `afterOperation` with a fabricated item
298
- * (see `recoverCreatedRows`/the create task in `nested-operations.ts`).
267
+ * row (`?? {}` is only a type-narrowing guard parent is always a record
268
+ * here). Each task recovers its own nested row by id-diff/known id and THROWS
269
+ * if it can't, rather than firing with a fabricated item (ADR-0010).
299
270
  */
300
271
  async function runNestedAfterTasks(afterTasks, item) {
301
272
  if (afterTasks.length === 0)
@@ -303,10 +274,9 @@ async function runNestedAfterTasks(afterTasks, item) {
303
274
  await runAfterTasks(afterTasks, item ?? {});
304
275
  }
305
276
  /**
306
- * The delete tail of the pipeline: skips the input-shaping phases and runs only
307
- * validate/field-validate before the DB delete, then the after-hooks. Returns
308
- * the deleted row as-is (no Field Visibility pass) — matching current delete
309
- * behaviour exactly.
277
+ * The delete tail of the pipeline: skips the input-shaping phases and runs
278
+ * only validate/field-validate before the DB delete, then the after-hooks.
279
+ * Returns the deleted row as-is (no Field Visibility pass).
310
280
  */
311
281
  async function runDeletePath(args) {
312
282
  const { listName, listConfig, context, originalItem, model, strategy } = args;
@@ -344,11 +314,11 @@ async function runDeletePath(args) {
344
314
  }
345
315
  // ── Per-operation strategies ──────────────────────────────────────────────────
346
316
  /**
347
- * Create strategy.
317
+ * Create strategy for {@link WriteStrategy}.
348
318
  *
349
- * Axis 1: checks `create` access with NO existing row. Enforces the
350
- * singleton-create constraint even under sudo. On create, an access result of
351
- * `true` OR a filter object both proceed — there is no filter re-check.
319
+ * Axis 1: checks `create` access with no existing row; a filter result
320
+ * proceeds with no re-check (unlike update/delete). Enforces the
321
+ * singleton-create constraint even under sudo.
352
322
  * Axis 2: runs all input phases.
353
323
  * Axis 3: `model.create({ data })`, prepending `id: 1` for singleton lists.
354
324
  */
@@ -422,7 +392,7 @@ listConfig, context, where, access) {
422
392
  };
423
393
  }
424
394
  /**
425
- * Update strategy.
395
+ * Update strategy for {@link WriteStrategy}.
426
396
  *
427
397
  * Axis 1: fetch row, check `update` access, re-check filter results.
428
398
  * Axis 2: runs all input phases.
@@ -441,11 +411,11 @@ listConfig, context, where) {
441
411
  };
442
412
  }
443
413
  /**
444
- * Delete strategy.
414
+ * Delete strategy for {@link WriteStrategy}.
445
415
  *
446
416
  * Axis 1: enforce singleton constraint (even under sudo), fetch row, check
447
417
  * `delete` access, re-check filter results.
448
- * Axis 2: SKIPS input phases (runs only validate/field-validate).
418
+ * Axis 2: skips input phases (runs only validate/field-validate).
449
419
  * Axis 3: `model.delete({ where })`; afterOperation gets `originalItem`.
450
420
  */
451
421
  export function deleteWriteStrategy(listName,
@@ -1 +1 @@
1
- {"version":3,"file":"write-pipeline.js","sourceRoot":"","sources":["../../src/context/write-pipeline.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,gCAAgC,EAChC,+BAA+B,EAC/B,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE/E,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAC9E,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA2F5C;;;;GAIG;AACH,SAAS,QAAQ,CACf,MAAe,EACf,QAAgB;IAEhB,sGAAsG;IACtG,OAAQ,MAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAgB,CAAA;AAC3D,CAAC;AAcD;;;;;;;;;;GAUG;AACH,KAAK,UAAU,gBAAgB,CAC7B,MAAe,EACf,EAA4D;IAE5D,MAAM,MAAM,GAAG,MAAuC,CAAA;IACtD,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QAC9C,OAAO,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,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C,CAAA;QAChC,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"format-prisma-default.d.ts","sourceRoot":"","sources":["../../src/fields/format-prisma-default.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,sBAAsB,GAChC,MAAM,GAAG,SAAS,CA6BpB"}
1
+ {"version":3,"file":"format-prisma-default.d.ts","sourceRoot":"","sources":["../../src/fields/format-prisma-default.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,sBAAsB,GAChC,MAAM,GAAG,SAAS,CA0BpB"}
@@ -28,17 +28,14 @@ export function formatPrismaDefault(value, fieldType) {
28
28
  }
29
29
  switch (fieldType) {
30
30
  case 'integer':
31
- // Bare numeric literal — Prisma expects no quotes for Int defaults.
32
31
  return String(value);
33
32
  case 'text':
34
- // Double-quoted string literal. The value is escaped via JSON.stringify so
35
- // embedded quotes/backslashes are handled correctly.
33
+ // JSON.stringify (not a template literal) so embedded quotes/backslashes
34
+ // in the value are escaped correctly.
36
35
  return JSON.stringify(String(value));
37
36
  case 'json': {
38
- // Keystone's JSON-literal form: canonical, space-free JSON.stringify of the
39
- // value, then wrap the whole serialised string in escaped double quotes so
40
- // Prisma stores the JSON text as the column default. The outer
41
- // JSON.stringify produces the escaped, double-quoted wrapper.
37
+ // Double JSON.stringify: once to canonicalize the value as JSON text,
38
+ // again to wrap that text in an escaped, double-quoted Prisma literal.
42
39
  const serialised = JSON.stringify(value);
43
40
  // JSON.stringify can return undefined for unserialisable values (e.g. a
44
41
  // function). Treat that as "no default" rather than emitting `@default()`.
@@ -1 +1 @@
1
- {"version":3,"file":"format-prisma-default.js","sourceRoot":"","sources":["../../src/fields/format-prisma-default.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,SAAiC;IAEjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,SAAS;YACZ,oEAAoE;YACpE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;QAEtB,KAAK,MAAM;YACT,2EAA2E;YAC3E,qDAAqD;YACrD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAEtC,KAAK,MAAM,EAAE,CAAC;YACZ,4EAA4E;YAC5E,2EAA2E;YAC3E,+DAA+D;YAC/D,8DAA8D;YAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACxC,wEAAwE;YACxE,2EAA2E;YAC3E,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"format-prisma-default.js","sourceRoot":"","sources":["../../src/fields/format-prisma-default.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,SAAiC;IAEjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;QAEtB,KAAK,MAAM;YACT,yEAAyE;YACzE,sCAAsC;YACtC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAEtC,KAAK,MAAM,EAAE,CAAC;YACZ,sEAAsE;YACtE,uEAAuE;YACvE,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACxC,wEAAwE;YACxE,2EAA2E;YAC3E,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;AACH,CAAC"}