@opensaas/stack-core 0.41.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 +35 -0
- package/dist/access/types.d.ts +2 -2
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/types.d.ts +81 -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 +103 -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
266
|
+
context: import('../access/types.js').AccessContext<TTypeInfo['prisma'], TTypeInfo['db']>
|
|
262
267
|
}
|
|
263
268
|
|
|
264
269
|
/**
|
|
@@ -1499,9 +1504,17 @@ export type GetFieldValueType<
|
|
|
1499
1504
|
*
|
|
1500
1505
|
* @template TKey - The list key/name (e.g., 'Post', 'User')
|
|
1501
1506
|
* @template TFields - The fields configuration for the list
|
|
1507
|
+
* @template TPrisma - The consuming app's own Prisma client type. Defaults to
|
|
1508
|
+
* {@link PrismaClientLike} so a `TypeInfo` written (or defaulted) without it
|
|
1509
|
+
* keeps today's behaviour — a hook's `context` resolves to `StackContext`
|
|
1510
|
+
* over an unnamed client, same as before this member existed.
|
|
1502
1511
|
* @template TItem - The output type (Prisma model type)
|
|
1503
1512
|
* @template TCreateInput - The Prisma create input type
|
|
1504
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.
|
|
1505
1518
|
*
|
|
1506
1519
|
* @example
|
|
1507
1520
|
* ```typescript
|
|
@@ -1513,12 +1526,16 @@ export type GetFieldValueType<
|
|
|
1513
1526
|
* create: Prisma.PostCreateInput
|
|
1514
1527
|
* update: Prisma.PostUpdateInput
|
|
1515
1528
|
* }
|
|
1529
|
+
* prisma: PrismaClient
|
|
1530
|
+
* db: CustomDB
|
|
1516
1531
|
* }
|
|
1517
1532
|
* ```
|
|
1518
1533
|
*/
|
|
1519
1534
|
export interface TypeInfo<
|
|
1520
1535
|
TKey extends string = string,
|
|
1521
1536
|
TFields extends Record<string, any> = Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- TypeInfo must accept any field record
|
|
1537
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1538
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1522
1539
|
> {
|
|
1523
1540
|
key: TKey
|
|
1524
1541
|
fields: TFields
|
|
@@ -1527,6 +1544,18 @@ export interface TypeInfo<
|
|
|
1527
1544
|
create: any // eslint-disable-line @typescript-eslint/no-explicit-any -- Prisma input types are generated and vary per list
|
|
1528
1545
|
update: any // eslint-disable-line @typescript-eslint/no-explicit-any -- Prisma input types are generated and vary per list
|
|
1529
1546
|
}
|
|
1547
|
+
/**
|
|
1548
|
+
* The consuming app's own Prisma client type, so a hook's `context` can be
|
|
1549
|
+
* keyed as `StackContext<TPrisma>`/`AccessContext<TPrisma>` instead of
|
|
1550
|
+
* resolving through the unparameterised {@link PrismaClientLike} default.
|
|
1551
|
+
*/
|
|
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
|
|
1530
1559
|
}
|
|
1531
1560
|
|
|
1532
1561
|
// Generic `any` default allows OperationAccess to work with any list item type
|
|
@@ -1602,6 +1631,8 @@ export type ResolveInputHookArgs<
|
|
|
1602
1631
|
TOutput = Record<string, unknown>,
|
|
1603
1632
|
TCreateInput = Record<string, unknown>,
|
|
1604
1633
|
TUpdateInput = Record<string, unknown>,
|
|
1634
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1635
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1605
1636
|
> =
|
|
1606
1637
|
| {
|
|
1607
1638
|
listKey: string
|
|
@@ -1609,7 +1640,7 @@ export type ResolveInputHookArgs<
|
|
|
1609
1640
|
inputData: TCreateInput
|
|
1610
1641
|
resolvedData: TCreateInput
|
|
1611
1642
|
item: undefined
|
|
1612
|
-
context: import('../context/index.js').StackContext
|
|
1643
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1613
1644
|
}
|
|
1614
1645
|
| {
|
|
1615
1646
|
listKey: string
|
|
@@ -1617,7 +1648,7 @@ export type ResolveInputHookArgs<
|
|
|
1617
1648
|
inputData: TUpdateInput
|
|
1618
1649
|
resolvedData: TUpdateInput
|
|
1619
1650
|
item: TOutput
|
|
1620
|
-
context: import('../context/index.js').StackContext
|
|
1651
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1621
1652
|
}
|
|
1622
1653
|
|
|
1623
1654
|
/**
|
|
@@ -1630,6 +1661,8 @@ export type ValidateHookArgs<
|
|
|
1630
1661
|
TOutput = Record<string, unknown>,
|
|
1631
1662
|
TCreateInput = Record<string, unknown>,
|
|
1632
1663
|
TUpdateInput = Record<string, unknown>,
|
|
1664
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1665
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1633
1666
|
> =
|
|
1634
1667
|
| {
|
|
1635
1668
|
listKey: string
|
|
@@ -1637,7 +1670,7 @@ export type ValidateHookArgs<
|
|
|
1637
1670
|
inputData: TCreateInput
|
|
1638
1671
|
resolvedData: TCreateInput
|
|
1639
1672
|
item: undefined
|
|
1640
|
-
context: import('../context/index.js').StackContext
|
|
1673
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1641
1674
|
addValidationError: (msg: string) => void
|
|
1642
1675
|
}
|
|
1643
1676
|
| {
|
|
@@ -1646,14 +1679,14 @@ export type ValidateHookArgs<
|
|
|
1646
1679
|
inputData: TUpdateInput
|
|
1647
1680
|
resolvedData: TUpdateInput
|
|
1648
1681
|
item: TOutput
|
|
1649
|
-
context: import('../context/index.js').StackContext
|
|
1682
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1650
1683
|
addValidationError: (msg: string) => void
|
|
1651
1684
|
}
|
|
1652
1685
|
| {
|
|
1653
1686
|
listKey: string
|
|
1654
1687
|
operation: 'delete'
|
|
1655
1688
|
item: TOutput
|
|
1656
|
-
context: import('../context/index.js').StackContext
|
|
1689
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1657
1690
|
addValidationError: (msg: string) => void
|
|
1658
1691
|
}
|
|
1659
1692
|
|
|
@@ -1667,13 +1700,15 @@ export type BeforeOperationHookArgs<
|
|
|
1667
1700
|
TOutput = Record<string, unknown>,
|
|
1668
1701
|
TCreateInput = Record<string, unknown>,
|
|
1669
1702
|
TUpdateInput = Record<string, unknown>,
|
|
1703
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1704
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1670
1705
|
> =
|
|
1671
1706
|
| {
|
|
1672
1707
|
listKey: string
|
|
1673
1708
|
operation: 'create'
|
|
1674
1709
|
inputData: TCreateInput
|
|
1675
1710
|
resolvedData: TCreateInput
|
|
1676
|
-
context: import('../context/index.js').StackContext
|
|
1711
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1677
1712
|
}
|
|
1678
1713
|
| {
|
|
1679
1714
|
listKey: string
|
|
@@ -1681,13 +1716,13 @@ export type BeforeOperationHookArgs<
|
|
|
1681
1716
|
inputData: TUpdateInput
|
|
1682
1717
|
item: TOutput
|
|
1683
1718
|
resolvedData: TUpdateInput
|
|
1684
|
-
context: import('../context/index.js').StackContext
|
|
1719
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1685
1720
|
}
|
|
1686
1721
|
| {
|
|
1687
1722
|
listKey: string
|
|
1688
1723
|
operation: 'delete'
|
|
1689
1724
|
item: TOutput
|
|
1690
|
-
context: import('../context/index.js').StackContext
|
|
1725
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1691
1726
|
}
|
|
1692
1727
|
|
|
1693
1728
|
/**
|
|
@@ -1700,6 +1735,8 @@ export type AfterOperationHookArgs<
|
|
|
1700
1735
|
TOutput = Record<string, unknown>,
|
|
1701
1736
|
TCreateInput = Record<string, unknown>,
|
|
1702
1737
|
TUpdateInput = Record<string, unknown>,
|
|
1738
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1739
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1703
1740
|
> =
|
|
1704
1741
|
| {
|
|
1705
1742
|
listKey: string
|
|
@@ -1707,7 +1744,7 @@ export type AfterOperationHookArgs<
|
|
|
1707
1744
|
inputData: TCreateInput
|
|
1708
1745
|
item: TOutput
|
|
1709
1746
|
resolvedData: TCreateInput
|
|
1710
|
-
context: import('../context/index.js').StackContext
|
|
1747
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1711
1748
|
}
|
|
1712
1749
|
| {
|
|
1713
1750
|
listKey: string
|
|
@@ -1716,13 +1753,13 @@ export type AfterOperationHookArgs<
|
|
|
1716
1753
|
originalItem: TOutput
|
|
1717
1754
|
item: TOutput
|
|
1718
1755
|
resolvedData: TUpdateInput
|
|
1719
|
-
context: import('../context/index.js').StackContext
|
|
1756
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1720
1757
|
}
|
|
1721
1758
|
| {
|
|
1722
1759
|
listKey: string
|
|
1723
1760
|
operation: 'delete'
|
|
1724
1761
|
originalItem: TOutput
|
|
1725
|
-
context: import('../context/index.js').StackContext
|
|
1762
|
+
context: import('../context/index.js').StackContext<TPrisma, TDb>
|
|
1726
1763
|
}
|
|
1727
1764
|
|
|
1728
1765
|
/**
|
|
@@ -1738,25 +1775,27 @@ export type BeforeTransactionHookArgs<
|
|
|
1738
1775
|
TOutput = Record<string, unknown>,
|
|
1739
1776
|
TCreateInput = Record<string, unknown>,
|
|
1740
1777
|
TUpdateInput = Record<string, unknown>,
|
|
1778
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1779
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1741
1780
|
> =
|
|
1742
1781
|
| {
|
|
1743
1782
|
listKey: string
|
|
1744
1783
|
operation: 'create'
|
|
1745
1784
|
inputData: TCreateInput
|
|
1746
|
-
context: import('../access/types.js').AccessContext
|
|
1785
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1747
1786
|
}
|
|
1748
1787
|
| {
|
|
1749
1788
|
listKey: string
|
|
1750
1789
|
operation: 'update'
|
|
1751
1790
|
inputData: TUpdateInput
|
|
1752
1791
|
item: TOutput | undefined
|
|
1753
|
-
context: import('../access/types.js').AccessContext
|
|
1792
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1754
1793
|
}
|
|
1755
1794
|
| {
|
|
1756
1795
|
listKey: string
|
|
1757
1796
|
operation: 'delete'
|
|
1758
1797
|
item: TOutput | undefined
|
|
1759
|
-
context: import('../access/types.js').AccessContext
|
|
1798
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1760
1799
|
}
|
|
1761
1800
|
|
|
1762
1801
|
/**
|
|
@@ -1781,6 +1820,8 @@ export type AfterTransactionHookArgs<
|
|
|
1781
1820
|
TOutput = Record<string, unknown>,
|
|
1782
1821
|
TCreateInput = Record<string, unknown>,
|
|
1783
1822
|
TUpdateInput = Record<string, unknown>,
|
|
1823
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1824
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1784
1825
|
> =
|
|
1785
1826
|
| {
|
|
1786
1827
|
listKey: string
|
|
@@ -1789,7 +1830,7 @@ export type AfterTransactionHookArgs<
|
|
|
1789
1830
|
inputData: TCreateInput
|
|
1790
1831
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1791
1832
|
item: TOutput | undefined
|
|
1792
|
-
context: import('../access/types.js').AccessContext
|
|
1833
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1793
1834
|
}
|
|
1794
1835
|
| {
|
|
1795
1836
|
listKey: string
|
|
@@ -1797,7 +1838,7 @@ export type AfterTransactionHookArgs<
|
|
|
1797
1838
|
status: 'rolled-back'
|
|
1798
1839
|
inputData: TCreateInput
|
|
1799
1840
|
error: unknown
|
|
1800
|
-
context: import('../access/types.js').AccessContext
|
|
1841
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1801
1842
|
}
|
|
1802
1843
|
| {
|
|
1803
1844
|
listKey: string
|
|
@@ -1808,7 +1849,7 @@ export type AfterTransactionHookArgs<
|
|
|
1808
1849
|
originalItem: TOutput | undefined
|
|
1809
1850
|
/** Persisted row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1810
1851
|
item: TOutput | undefined
|
|
1811
|
-
context: import('../access/types.js').AccessContext
|
|
1852
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1812
1853
|
}
|
|
1813
1854
|
| {
|
|
1814
1855
|
listKey: string
|
|
@@ -1817,7 +1858,7 @@ export type AfterTransactionHookArgs<
|
|
|
1817
1858
|
inputData: TUpdateInput
|
|
1818
1859
|
originalItem: TOutput | undefined
|
|
1819
1860
|
error: unknown
|
|
1820
|
-
context: import('../access/types.js').AccessContext
|
|
1861
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1821
1862
|
}
|
|
1822
1863
|
| {
|
|
1823
1864
|
listKey: string
|
|
@@ -1825,7 +1866,7 @@ export type AfterTransactionHookArgs<
|
|
|
1825
1866
|
status: 'committed'
|
|
1826
1867
|
/** Pre-write row — populated for the top-level list only; `undefined` for nested lists. */
|
|
1827
1868
|
originalItem: TOutput | undefined
|
|
1828
|
-
context: import('../access/types.js').AccessContext
|
|
1869
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1829
1870
|
}
|
|
1830
1871
|
| {
|
|
1831
1872
|
listKey: string
|
|
@@ -1833,23 +1874,27 @@ export type AfterTransactionHookArgs<
|
|
|
1833
1874
|
status: 'rolled-back'
|
|
1834
1875
|
originalItem: TOutput | undefined
|
|
1835
1876
|
error: unknown
|
|
1836
|
-
context: import('../access/types.js').AccessContext
|
|
1877
|
+
context: import('../access/types.js').AccessContext<TPrisma, TDb>
|
|
1837
1878
|
}
|
|
1838
1879
|
|
|
1839
1880
|
export type Hooks<
|
|
1840
1881
|
TOutput = Record<string, unknown>,
|
|
1841
1882
|
TCreateInput = Record<string, unknown>,
|
|
1842
1883
|
TUpdateInput = Record<string, unknown>,
|
|
1884
|
+
TPrisma extends PrismaClientLike = PrismaClientLike,
|
|
1885
|
+
TDb = AccessControlledDB<TPrisma>,
|
|
1843
1886
|
> = {
|
|
1844
1887
|
resolveInput?: (
|
|
1845
|
-
args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput>,
|
|
1888
|
+
args: ResolveInputHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1846
1889
|
) => Promise<TCreateInput | TUpdateInput>
|
|
1847
|
-
validate?: (
|
|
1890
|
+
validate?: (
|
|
1891
|
+
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1892
|
+
) => Promise<void>
|
|
1848
1893
|
beforeOperation?: (
|
|
1849
|
-
args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput>,
|
|
1894
|
+
args: BeforeOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1850
1895
|
) => Promise<void>
|
|
1851
1896
|
afterOperation?: (
|
|
1852
|
-
args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput>,
|
|
1897
|
+
args: AfterOperationHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1853
1898
|
) => Promise<void>
|
|
1854
1899
|
/**
|
|
1855
1900
|
* Side effect BEFORE the write's transaction opens (#590 / ADR-0010).
|
|
@@ -1858,7 +1903,7 @@ export type Hooks<
|
|
|
1858
1903
|
* with `status: 'rolled-back'`. See {@link BeforeTransactionHookArgs}.
|
|
1859
1904
|
*/
|
|
1860
1905
|
beforeTransaction?: (
|
|
1861
|
-
args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput>,
|
|
1906
|
+
args: BeforeTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1862
1907
|
) => Promise<void> | void
|
|
1863
1908
|
/**
|
|
1864
1909
|
* Side effect AFTER the write's transaction settles (#590 / ADR-0010).
|
|
@@ -1869,12 +1914,14 @@ export type Hooks<
|
|
|
1869
1914
|
* {@link AfterTransactionHookArgs}.
|
|
1870
1915
|
*/
|
|
1871
1916
|
afterTransaction?: (
|
|
1872
|
-
args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput>,
|
|
1917
|
+
args: AfterTransactionHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1873
1918
|
) => Promise<void> | void
|
|
1874
1919
|
/**
|
|
1875
1920
|
* @deprecated Use 'validate' instead. This alias is provided for backwards compatibility.
|
|
1876
1921
|
*/
|
|
1877
|
-
validateInput?: (
|
|
1922
|
+
validateInput?: (
|
|
1923
|
+
args: ValidateHookArgs<TOutput, TCreateInput, TUpdateInput, TPrisma, TDb>,
|
|
1924
|
+
) => Promise<void>
|
|
1878
1925
|
}
|
|
1879
1926
|
|
|
1880
1927
|
/**
|
|
@@ -1938,7 +1985,13 @@ export type ListConfig<TTypeInfo extends TypeInfo> = {
|
|
|
1938
1985
|
access?: {
|
|
1939
1986
|
operation?: OperationAccess<TTypeInfo['item']>
|
|
1940
1987
|
}
|
|
1941
|
-
hooks?: Hooks<
|
|
1988
|
+
hooks?: Hooks<
|
|
1989
|
+
TTypeInfo['item'],
|
|
1990
|
+
TTypeInfo['inputs']['create'],
|
|
1991
|
+
TTypeInfo['inputs']['update'],
|
|
1992
|
+
TTypeInfo['prisma'],
|
|
1993
|
+
TTypeInfo['db']
|
|
1994
|
+
>
|
|
1942
1995
|
/**
|
|
1943
1996
|
* Database configuration for this list (model level)
|
|
1944
1997
|
*/
|
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 {
|