@opensaas/stack-core 0.42.0 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +9 -0
- package/dist/access/types.d.ts +2 -2
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/types.d.ts +69 -58
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/index.d.ts +5 -5
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/access/types.ts +6 -2
- package/src/config/types.ts +77 -50
- package/src/context/index.ts +17 -5
- package/src/internal.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/src/config/types.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AccessControl,
|
|
3
|
+
AccessControlledDB,
|
|
4
|
+
FieldAccess,
|
|
5
|
+
PrismaClientLike,
|
|
6
|
+
} from '../access/types.js'
|
|
2
7
|
import type { FilterSpec } from '../filter/types.js'
|
|
3
8
|
import type { z } from 'zod'
|
|
4
9
|
|
|
@@ -21,7 +26,7 @@ export type FieldResolveInputHookArgs<
|
|
|
21
26
|
inputData: TTypeInfo['inputs']['create']
|
|
22
27
|
item: undefined
|
|
23
28
|
resolvedData: TTypeInfo['inputs']['create']
|
|
24
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
29
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
25
30
|
}
|
|
26
31
|
| {
|
|
27
32
|
listKey: string
|
|
@@ -30,7 +35,7 @@ export type FieldResolveInputHookArgs<
|
|
|
30
35
|
inputData: TTypeInfo['inputs']['update']
|
|
31
36
|
item: TTypeInfo['item']
|
|
32
37
|
resolvedData: TTypeInfo['inputs']['update']
|
|
33
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
38
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
/** Arguments for {@link FieldHooks.validate} (and its deprecated `validateInput` alias). */
|
|
@@ -45,7 +50,7 @@ export type FieldValidateHookArgs<
|
|
|
45
50
|
inputData: TTypeInfo['inputs']['create']
|
|
46
51
|
item: undefined
|
|
47
52
|
resolvedData: TTypeInfo['inputs']['create']
|
|
48
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
53
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
49
54
|
addValidationError: (msg: string) => void
|
|
50
55
|
}
|
|
51
56
|
| {
|
|
@@ -55,7 +60,7 @@ export type FieldValidateHookArgs<
|
|
|
55
60
|
inputData: TTypeInfo['inputs']['update']
|
|
56
61
|
item: TTypeInfo['item']
|
|
57
62
|
resolvedData: TTypeInfo['inputs']['update']
|
|
58
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
63
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
59
64
|
addValidationError: (msg: string) => void
|
|
60
65
|
}
|
|
61
66
|
| {
|
|
@@ -63,7 +68,7 @@ export type FieldValidateHookArgs<
|
|
|
63
68
|
fieldKey: TFieldKey
|
|
64
69
|
operation: 'delete'
|
|
65
70
|
item: TTypeInfo['item']
|
|
66
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
71
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
67
72
|
addValidationError: (msg: string) => void
|
|
68
73
|
}
|
|
69
74
|
|
|
@@ -78,7 +83,7 @@ export type FieldBeforeOperationHookArgs<
|
|
|
78
83
|
operation: 'create'
|
|
79
84
|
inputData: TTypeInfo['inputs']['create']
|
|
80
85
|
resolvedData: TTypeInfo['inputs']['create']
|
|
81
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
86
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
82
87
|
}
|
|
83
88
|
| {
|
|
84
89
|
listKey: string
|
|
@@ -87,14 +92,14 @@ export type FieldBeforeOperationHookArgs<
|
|
|
87
92
|
inputData: TTypeInfo['inputs']['update']
|
|
88
93
|
item: TTypeInfo['item']
|
|
89
94
|
resolvedData: TTypeInfo['inputs']['update']
|
|
90
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
95
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
91
96
|
}
|
|
92
97
|
| {
|
|
93
98
|
listKey: string
|
|
94
99
|
fieldKey: TFieldKey
|
|
95
100
|
operation: 'delete'
|
|
96
101
|
item: TTypeInfo['item']
|
|
97
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
102
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
/** Arguments for {@link FieldHooks.afterOperation}. */
|
|
@@ -109,7 +114,7 @@ export type FieldAfterOperationHookArgs<
|
|
|
109
114
|
inputData: TTypeInfo['inputs']['create']
|
|
110
115
|
item: TTypeInfo['item']
|
|
111
116
|
resolvedData: TTypeInfo['inputs']['create']
|
|
112
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
117
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
113
118
|
}
|
|
114
119
|
| {
|
|
115
120
|
listKey: string
|
|
@@ -119,14 +124,14 @@ export type FieldAfterOperationHookArgs<
|
|
|
119
124
|
originalItem: TTypeInfo['item']
|
|
120
125
|
item: TTypeInfo['item']
|
|
121
126
|
resolvedData: TTypeInfo['inputs']['update']
|
|
122
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
127
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
123
128
|
}
|
|
124
129
|
| {
|
|
125
130
|
listKey: string
|
|
126
131
|
fieldKey: TFieldKey
|
|
127
132
|
operation: 'delete'
|
|
128
133
|
originalItem: TTypeInfo['item']
|
|
129
|
-
context: import('../context/index.js').StackContext<TTypeInfo['prisma']>
|
|
134
|
+
context: import('../context/index.js').StackContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
/**
|
|
@@ -150,7 +155,7 @@ export type FieldBeforeTransactionHookArgs<
|
|
|
150
155
|
fieldKey: TFieldKey
|
|
151
156
|
operation: 'create'
|
|
152
157
|
inputData: TTypeInfo['inputs']['create']
|
|
153
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
158
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
154
159
|
}
|
|
155
160
|
| {
|
|
156
161
|
listKey: string
|
|
@@ -158,14 +163,14 @@ export type FieldBeforeTransactionHookArgs<
|
|
|
158
163
|
operation: 'update'
|
|
159
164
|
inputData: TTypeInfo['inputs']['update']
|
|
160
165
|
item: TTypeInfo['item'] | undefined
|
|
161
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
166
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
162
167
|
}
|
|
163
168
|
| {
|
|
164
169
|
listKey: string
|
|
165
170
|
fieldKey: TFieldKey
|
|
166
171
|
operation: 'delete'
|
|
167
172
|
item: TTypeInfo['item'] | undefined
|
|
168
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
173
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
169
174
|
}
|
|
170
175
|
|
|
171
176
|
/**
|
|
@@ -196,7 +201,7 @@ export type FieldAfterTransactionHookArgs<
|
|
|
196
201
|
inputData: TTypeInfo['inputs']['create']
|
|
197
202
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
198
203
|
item: TTypeInfo['item'] | undefined
|
|
199
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
204
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
200
205
|
}
|
|
201
206
|
| {
|
|
202
207
|
listKey: string
|
|
@@ -205,7 +210,7 @@ export type FieldAfterTransactionHookArgs<
|
|
|
205
210
|
status: 'rolled-back'
|
|
206
211
|
inputData: TTypeInfo['inputs']['create']
|
|
207
212
|
error: unknown
|
|
208
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
213
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
209
214
|
}
|
|
210
215
|
| {
|
|
211
216
|
listKey: string
|
|
@@ -217,7 +222,7 @@ export type FieldAfterTransactionHookArgs<
|
|
|
217
222
|
originalItem: TTypeInfo['item'] | undefined
|
|
218
223
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
219
224
|
item: TTypeInfo['item'] | undefined
|
|
220
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
225
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
221
226
|
}
|
|
222
227
|
| {
|
|
223
228
|
listKey: string
|
|
@@ -227,7 +232,7 @@ export type FieldAfterTransactionHookArgs<
|
|
|
227
232
|
inputData: TTypeInfo['inputs']['update']
|
|
228
233
|
originalItem: TTypeInfo['item'] | undefined
|
|
229
234
|
error: unknown
|
|
230
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
235
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
231
236
|
}
|
|
232
237
|
| {
|
|
233
238
|
listKey: string
|
|
@@ -236,7 +241,7 @@ export type FieldAfterTransactionHookArgs<
|
|
|
236
241
|
status: 'committed'
|
|
237
242
|
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
238
243
|
originalItem: TTypeInfo['item'] | undefined
|
|
239
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
244
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
240
245
|
}
|
|
241
246
|
| {
|
|
242
247
|
listKey: string
|
|
@@ -245,7 +250,7 @@ export type FieldAfterTransactionHookArgs<
|
|
|
245
250
|
status: 'rolled-back'
|
|
246
251
|
originalItem: TTypeInfo['item'] | undefined
|
|
247
252
|
error: unknown
|
|
248
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
253
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
249
254
|
}
|
|
250
255
|
|
|
251
256
|
/** Arguments for {@link FieldHooks.resolveOutput}. */
|
|
@@ -258,7 +263,7 @@ export type FieldResolveOutputHookArgs<
|
|
|
258
263
|
item: TTypeInfo['item']
|
|
259
264
|
listKey: string
|
|
260
265
|
fieldName: TFieldKey
|
|
261
|
-
context: import('../access/types.js').AccessContext<TTypeInfo['prisma']>
|
|
266
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
262
267
|
}
|
|
263
268
|
|
|
264
269
|
/**
|
|
@@ -1506,6 +1511,10 @@ export type GetFieldValueType<
|
|
|
1506
1511
|
* @template TItem - The output type (Prisma model type)
|
|
1507
1512
|
* @template TCreateInput - The Prisma create input type
|
|
1508
1513
|
* @template TUpdateInput - The Prisma update input type
|
|
1514
|
+
* @template TDb - The app's own generated `db` surface (the CLI's `CustomDB`),
|
|
1515
|
+
* with virtual and transformed fields folded into every list's payload.
|
|
1516
|
+
* Defaults to `AccessControlledDB<TPrisma>` — the plain Prisma-shaped view —
|
|
1517
|
+
* so a `TypeInfo` written (or defaulted) without it keeps today's behaviour.
|
|
1509
1518
|
*
|
|
1510
1519
|
* @example
|
|
1511
1520
|
* ```typescript
|
|
@@ -1518,6 +1527,7 @@ export type GetFieldValueType<
|
|
|
1518
1527
|
* update: Prisma.PostUpdateInput
|
|
1519
1528
|
* }
|
|
1520
1529
|
* prisma: PrismaClient
|
|
1530
|
+
* db: CustomDB
|
|
1521
1531
|
* }
|
|
1522
1532
|
* ```
|
|
1523
1533
|
*/
|
|
@@ -1525,6 +1535,7 @@ export interface TypeInfo<
|
|
|
1525
1535
|
TKey extends string = string,
|
|
1526
1536
|
TFields extends Record<string, any> = Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- TypeInfo must accept any field record
|
|
1527
1537
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1538
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1528
1539
|
> {
|
|
1529
1540
|
key: TKey
|
|
1530
1541
|
fields: TFields
|
|
@@ -1539,6 +1550,12 @@ export interface TypeInfo<
|
|
|
1539
1550
|
* resolving through the unparameterised {@link PrismaClientLike} default.
|
|
1540
1551
|
*/
|
|
1541
1552
|
prisma: TPrisma
|
|
1553
|
+
/**
|
|
1554
|
+
* The app's own generated `db` surface (see {@link TDb}), so a hook's
|
|
1555
|
+
* `context.db` describes the same virtual/transformed-field-augmented rows
|
|
1556
|
+
* the app's own generated `db` surface produces for the same read (#1232).
|
|
1557
|
+
*/
|
|
1558
|
+
db: TDb
|
|
1542
1559
|
}
|
|
1543
1560
|
|
|
1544
1561
|
// Generic `any` default allows OperationAccess to work with any list item type
|
|
@@ -1615,6 +1632,7 @@ export type ResolveInputHookArgs<
|
|
|
1615
1632
|
TCreateInput = Record<string, unknown>,
|
|
1616
1633
|
TUpdateInput = Record<string, unknown>,
|
|
1617
1634
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1635
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1618
1636
|
> =
|
|
1619
1637
|
| {
|
|
1620
1638
|
listKey: string
|
|
@@ -1622,7 +1640,7 @@ export type ResolveInputHookArgs<
|
|
|
1622
1640
|
inputData: TCreateInput
|
|
1623
1641
|
resolvedData: TCreateInput
|
|
1624
1642
|
item: undefined
|
|
1625
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1643
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1626
1644
|
}
|
|
1627
1645
|
| {
|
|
1628
1646
|
listKey: string
|
|
@@ -1630,7 +1648,7 @@ export type ResolveInputHookArgs<
|
|
|
1630
1648
|
inputData: TUpdateInput
|
|
1631
1649
|
resolvedData: TUpdateInput
|
|
1632
1650
|
item: TOutput
|
|
1633
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1651
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1634
1652
|
}
|
|
1635
1653
|
|
|
1636
1654
|
/**
|
|
@@ -1644,6 +1662,7 @@ export type ValidateHookArgs<
|
|
|
1644
1662
|
TCreateInput = Record<string, unknown>,
|
|
1645
1663
|
TUpdateInput = Record<string, unknown>,
|
|
1646
1664
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1665
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1647
1666
|
> =
|
|
1648
1667
|
| {
|
|
1649
1668
|
listKey: string
|
|
@@ -1651,7 +1670,7 @@ export type ValidateHookArgs<
|
|
|
1651
1670
|
inputData: TCreateInput
|
|
1652
1671
|
resolvedData: TCreateInput
|
|
1653
1672
|
item: undefined
|
|
1654
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1673
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1655
1674
|
addValidationError: (msg: string) => void
|
|
1656
1675
|
}
|
|
1657
1676
|
| {
|
|
@@ -1660,14 +1679,14 @@ export type ValidateHookArgs<
|
|
|
1660
1679
|
inputData: TUpdateInput
|
|
1661
1680
|
resolvedData: TUpdateInput
|
|
1662
1681
|
item: TOutput
|
|
1663
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1682
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1664
1683
|
addValidationError: (msg: string) => void
|
|
1665
1684
|
}
|
|
1666
1685
|
| {
|
|
1667
1686
|
listKey: string
|
|
1668
1687
|
operation: 'delete'
|
|
1669
1688
|
item: TOutput
|
|
1670
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1689
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1671
1690
|
addValidationError: (msg: string) => void
|
|
1672
1691
|
}
|
|
1673
1692
|
|
|
@@ -1682,13 +1701,14 @@ export type BeforeOperationHookArgs<
|
|
|
1682
1701
|
TCreateInput = Record<string, unknown>,
|
|
1683
1702
|
TUpdateInput = Record<string, unknown>,
|
|
1684
1703
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1704
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1685
1705
|
> =
|
|
1686
1706
|
| {
|
|
1687
1707
|
listKey: string
|
|
1688
1708
|
operation: 'create'
|
|
1689
1709
|
inputData: TCreateInput
|
|
1690
1710
|
resolvedData: TCreateInput
|
|
1691
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1711
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1692
1712
|
}
|
|
1693
1713
|
| {
|
|
1694
1714
|
listKey: string
|
|
@@ -1696,13 +1716,13 @@ export type BeforeOperationHookArgs<
|
|
|
1696
1716
|
inputData: TUpdateInput
|
|
1697
1717
|
item: TOutput
|
|
1698
1718
|
resolvedData: TUpdateInput
|
|
1699
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1719
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1700
1720
|
}
|
|
1701
1721
|
| {
|
|
1702
1722
|
listKey: string
|
|
1703
1723
|
operation: 'delete'
|
|
1704
1724
|
item: TOutput
|
|
1705
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1725
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1706
1726
|
}
|
|
1707
1727
|
|
|
1708
1728
|
/**
|
|
@@ -1716,6 +1736,7 @@ export type AfterOperationHookArgs<
|
|
|
1716
1736
|
TCreateInput = Record<string, unknown>,
|
|
1717
1737
|
TUpdateInput = Record<string, unknown>,
|
|
1718
1738
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1739
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1719
1740
|
> =
|
|
1720
1741
|
| {
|
|
1721
1742
|
listKey: string
|
|
@@ -1723,7 +1744,7 @@ export type AfterOperationHookArgs<
|
|
|
1723
1744
|
inputData: TCreateInput
|
|
1724
1745
|
item: TOutput
|
|
1725
1746
|
resolvedData: TCreateInput
|
|
1726
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1747
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1727
1748
|
}
|
|
1728
1749
|
| {
|
|
1729
1750
|
listKey: string
|
|
@@ -1732,13 +1753,13 @@ export type AfterOperationHookArgs<
|
|
|
1732
1753
|
originalItem: TOutput
|
|
1733
1754
|
item: TOutput
|
|
1734
1755
|
resolvedData: TUpdateInput
|
|
1735
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1756
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1736
1757
|
}
|
|
1737
1758
|
| {
|
|
1738
1759
|
listKey: string
|
|
1739
1760
|
operation: 'delete'
|
|
1740
1761
|
originalItem: TOutput
|
|
1741
|
-
context: import('../context/index.js').StackContext<TPrisma>
|
|
1762
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1742
1763
|
}
|
|
1743
1764
|
|
|
1744
1765
|
/**
|
|
@@ -1755,25 +1776,26 @@ export type BeforeTransactionHookArgs<
|
|
|
1755
1776
|
TCreateInput = Record<string, unknown>,
|
|
1756
1777
|
TUpdateInput = Record<string, unknown>,
|
|
1757
1778
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1779
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1758
1780
|
> =
|
|
1759
1781
|
| {
|
|
1760
1782
|
listKey: string
|
|
1761
1783
|
operation: 'create'
|
|
1762
1784
|
inputData: TCreateInput
|
|
1763
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1785
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1764
1786
|
}
|
|
1765
1787
|
| {
|
|
1766
1788
|
listKey: string
|
|
1767
1789
|
operation: 'update'
|
|
1768
1790
|
inputData: TUpdateInput
|
|
1769
1791
|
item: TOutput | undefined
|
|
1770
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1792
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1771
1793
|
}
|
|
1772
1794
|
| {
|
|
1773
1795
|
listKey: string
|
|
1774
1796
|
operation: 'delete'
|
|
1775
1797
|
item: TOutput | undefined
|
|
1776
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1798
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1777
1799
|
}
|
|
1778
1800
|
|
|
1779
1801
|
/**
|
|
@@ -1799,6 +1821,7 @@ export type AfterTransactionHookArgs<
|
|
|
1799
1821
|
TCreateInput = Record<string, unknown>,
|
|
1800
1822
|
TUpdateInput = Record<string, unknown>,
|
|
1801
1823
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1824
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1802
1825
|
> =
|
|
1803
1826
|
| {
|
|
1804
1827
|
listKey: string
|
|
@@ -1807,7 +1830,7 @@ export type AfterTransactionHookArgs<
|
|
|
1807
1830
|
inputData: TCreateInput
|
|
1808
1831
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1809
1832
|
item: TOutput | undefined
|
|
1810
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1833
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1811
1834
|
}
|
|
1812
1835
|
| {
|
|
1813
1836
|
listKey: string
|
|
@@ -1815,7 +1838,7 @@ export type AfterTransactionHookArgs<
|
|
|
1815
1838
|
status: 'rolled-back'
|
|
1816
1839
|
inputData: TCreateInput
|
|
1817
1840
|
error: unknown
|
|
1818
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1841
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1819
1842
|
}
|
|
1820
1843
|
| {
|
|
1821
1844
|
listKey: string
|
|
@@ -1826,7 +1849,7 @@ export type AfterTransactionHookArgs<
|
|
|
1826
1849
|
originalItem: TOutput | undefined
|
|
1827
1850
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1828
1851
|
item: TOutput | undefined
|
|
1829
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1852
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1830
1853
|
}
|
|
1831
1854
|
| {
|
|
1832
1855
|
listKey: string
|
|
@@ -1835,7 +1858,7 @@ export type AfterTransactionHookArgs<
|
|
|
1835
1858
|
inputData: TUpdateInput
|
|
1836
1859
|
originalItem: TOutput | undefined
|
|
1837
1860
|
error: unknown
|
|
1838
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1861
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1839
1862
|
}
|
|
1840
1863
|
| {
|
|
1841
1864
|
listKey: string
|
|
@@ -1843,7 +1866,7 @@ export type AfterTransactionHookArgs<
|
|
|
1843
1866
|
status: 'committed'
|
|
1844
1867
|
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1845
1868
|
originalItem: TOutput | undefined
|
|
1846
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1869
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1847
1870
|
}
|
|
1848
1871
|
| {
|
|
1849
1872
|
listKey: string
|
|
@@ -1851,7 +1874,7 @@ export type AfterTransactionHookArgs<
|
|
|
1851
1874
|
status: 'rolled-back'
|
|
1852
1875
|
originalItem: TOutput | undefined
|
|
1853
1876
|
error: unknown
|
|
1854
|
-
context: import('../access/types.js').AccessContext<TPrisma>
|
|
1877
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1855
1878
|
}
|
|
1856
1879
|
|
|
1857
1880
|
export type Hooks<
|
|
@@ -1859,16 +1882,19 @@ export type Hooks<
|
|
|
1859
1882
|
TCreateInput = Record<string, unknown>,
|
|
1860
1883
|
TUpdateInput = Record<string, unknown>,
|
|
1861
1884
|
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1885
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1862
1886
|
> = {
|
|
1863
1887
|
resolveInput?: (
|
|
1864
|
-
args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma>,
|
|
1888
|
+
args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1865
1889
|
) => Promise<TCreateInput | TUpdateInput>
|
|
1866
|
-
validate?: (
|
|
1890
|
+
validate?: (
|
|
1891
|
+
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1892
|
+
) => Promise<void>
|
|
1867
1893
|
beforeOperation?: (
|
|
1868
|
-
args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma>,
|
|
1894
|
+
args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1869
1895
|
) => Promise<void>
|
|
1870
1896
|
afterOperation?: (
|
|
1871
|
-
args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma>,
|
|
1897
|
+
args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1872
1898
|
) => Promise<void>
|
|
1873
1899
|
/**
|
|
1874
1900
|
* Side effect BEFORE the write's transaction opens (#590 / ADR-0010).
|
|
@@ -1877,7 +1903,7 @@ export type Hooks<
|
|
|
1877
1903
|
* with `status: 'rolled-back'`. See {@link BeforeTransactionHookArgs}.
|
|
1878
1904
|
*/
|
|
1879
1905
|
beforeTransaction?: (
|
|
1880
|
-
args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma>,
|
|
1906
|
+
args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1881
1907
|
) => Promise<void> | void
|
|
1882
1908
|
/**
|
|
1883
1909
|
* Side effect AFTER the write's transaction settles (#590 / ADR-0010).
|
|
@@ -1888,13 +1914,13 @@ export type Hooks<
|
|
|
1888
1914
|
* {@link AfterTransactionHookArgs}.
|
|
1889
1915
|
*/
|
|
1890
1916
|
afterTransaction?: (
|
|
1891
|
-
args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma>,
|
|
1917
|
+
args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1892
1918
|
) => Promise<void> | void
|
|
1893
1919
|
/**
|
|
1894
1920
|
* @deprecated Use 'validate' instead. This alias is provided for backwards compatibility.
|
|
1895
1921
|
*/
|
|
1896
1922
|
validateInput?: (
|
|
1897
|
-
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma>,
|
|
1923
|
+
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1898
1924
|
) => Promise<void>
|
|
1899
1925
|
}
|
|
1900
1926
|
|
|
@@ -1963,7 +1989,8 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1963
1989
|
TTypeInfo['item'],
|
|
1964
1990
|
TTypeInfo['inputs']['create'],
|
|
1965
1991
|
TTypeInfo['inputs']['update'],
|
|
1966
|
-
TTypeInfo['prisma']
|
|
1992
|
+
TTypeInfo['prisma'],
|
|
1993
|
+
TTypeInfo['db']
|
|
1967
1994
|
>
|
|
1968
1995
|
/**
|
|
1969
1996
|
* Database configuration for this list (model level)
|
package/src/context/index.ts
CHANGED
|
@@ -313,8 +313,20 @@ interface TransactionCapable<TPrisma> {
|
|
|
313
313
|
* still runs access control), and `transaction()` (interactive, hook-firing
|
|
314
314
|
* transaction). All access-checked operations run their list/field hooks.
|
|
315
315
|
*/
|
|
316
|
-
export interface StackContext<
|
|
317
|
-
|
|
316
|
+
export interface StackContext<
|
|
317
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
318
|
+
// Defaults to the plain Prisma-shaped view (#1232). The generator points a
|
|
319
|
+
// list's `TypeInfo['db']` at its own generated `CustomDB` — the same
|
|
320
|
+
// virtual/transformed-field-augmented description `context.db` already
|
|
321
|
+
// resolves to outside a hook — so a hook's `context: StackContext<TPrisma,
|
|
322
|
+
// TDb>` (keyed via `TTypeInfo['db']`) describes the same rows. Left
|
|
323
|
+
// unconstrained (no `extends AccessControlledDB<TPrisma>`) — `CustomDB`'s
|
|
324
|
+
// per-list payload requires strictly more keys than the raw Prisma payload,
|
|
325
|
+
// so constraining this parameter would reintroduce the assignability gap
|
|
326
|
+
// #1233 already worked around for the fragment overload, one level higher.
|
|
327
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
328
|
+
> {
|
|
329
|
+
db: TDb
|
|
318
330
|
session: Session | null
|
|
319
331
|
prisma: TPrisma
|
|
320
332
|
storage: StorageUtils
|
|
@@ -342,10 +354,10 @@ export interface StackContext<TPrisma extends PrismaClientLike = PrismaClientLik
|
|
|
342
354
|
* plugin service) for writes that must be atomic with the transaction.
|
|
343
355
|
*/
|
|
344
356
|
transaction: <T>(
|
|
345
|
-
fn: (txContext: StackContext<TPrisma>) => Promise<T>,
|
|
357
|
+
fn: (txContext: StackContext<TPrisma, TDb>) => Promise<T>,
|
|
346
358
|
options?: TransactionOptions,
|
|
347
359
|
) => Promise<T>
|
|
348
|
-
sudo: () => StackContext<TPrisma>
|
|
360
|
+
sudo: () => StackContext<TPrisma, TDb>
|
|
349
361
|
/**
|
|
350
362
|
* Derive a context identical to this one except for its session, reusing
|
|
351
363
|
* the already-resolved config and this context's own client (including a
|
|
@@ -362,7 +374,7 @@ export interface StackContext<TPrisma extends PrismaClientLike = PrismaClientLik
|
|
|
362
374
|
* state (elevated stays elevated), so `context.withSession(s).sudo()` and
|
|
363
375
|
* `context.sudo().withSession(s)` are equivalent.
|
|
364
376
|
*/
|
|
365
|
-
withSession: (session: Session | null) => StackContext<TPrisma>
|
|
377
|
+
withSession: (session: Session | null) => StackContext<TPrisma, TDb>
|
|
366
378
|
_isSudo: boolean
|
|
367
379
|
/**
|
|
368
380
|
* @internal Present so a hook-bound `StackContext` (issue #1176) satisfies
|
package/src/internal.ts
CHANGED
|
@@ -19,8 +19,8 @@ export type {
|
|
|
19
19
|
FindManyQueryArgs,
|
|
20
20
|
} from './access/types.js'
|
|
21
21
|
|
|
22
|
-
// Typed-query internals (Fragment/FieldSelection appear in generated types)
|
|
23
|
-
export type { Fragment, FieldSelection } from './query/index.js'
|
|
22
|
+
// Typed-query internals (Fragment/FieldSelection/ResultOf appear in generated types)
|
|
23
|
+
export type { Fragment, FieldSelection, ResultOf } from './query/index.js'
|
|
24
24
|
|
|
25
25
|
// Password hashing internals (the password field emits HashedPassword into generated types)
|
|
26
26
|
export {
|