@opensaas/stack-core 0.12.1 → 0.14.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +291 -0
- package/README.md +6 -3
- package/dist/access/engine.d.ts +2 -0
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +8 -6
- package/dist/access/engine.js.map +1 -1
- package/dist/access/engine.test.js +4 -0
- package/dist/access/engine.test.js.map +1 -1
- package/dist/access/types.d.ts +31 -4
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/index.d.ts +12 -10
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +37 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/types.d.ts +341 -82
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +330 -60
- package/dist/context/index.js.map +1 -1
- package/dist/context/nested-operations.d.ts.map +1 -1
- package/dist/context/nested-operations.js +38 -25
- package/dist/context/nested-operations.js.map +1 -1
- package/dist/hooks/index.d.ts +45 -7
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +10 -4
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/access/engine.test.ts +4 -0
- package/src/access/engine.ts +10 -7
- package/src/access/types.ts +45 -4
- package/src/config/index.ts +65 -9
- package/src/config/types.ts +402 -91
- package/src/context/index.ts +421 -82
- package/src/context/nested-operations.ts +40 -25
- package/src/hooks/index.ts +66 -14
- package/src/index.ts +11 -0
- package/tests/access.test.ts +28 -28
- package/tests/config.test.ts +20 -3
- package/tests/nested-access-and-hooks.test.ts +8 -3
- package/tests/singleton.test.ts +329 -0
- package/tests/sudo.test.ts +2 -13
- package/tsconfig.tsbuildinfo +1 -1
package/src/config/index.ts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
OpenSaasConfig,
|
|
3
|
+
ListConfig,
|
|
4
|
+
ListConfigInput,
|
|
5
|
+
OperationAccess,
|
|
6
|
+
ListAccessControl,
|
|
7
|
+
} from './types.js'
|
|
2
8
|
import { executePlugins } from './plugin-engine.js'
|
|
9
|
+
import type { AccessControl } from '../access/types.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Normalize access control shorthand to object form
|
|
13
|
+
* Converts function shorthand to { operation: { query, create, update, delete } } form
|
|
14
|
+
*/
|
|
15
|
+
function normalizeListAccess<T>(
|
|
16
|
+
access: ListAccessControl<T> | undefined,
|
|
17
|
+
): { operation?: OperationAccess<T> } | undefined {
|
|
18
|
+
if (!access) return undefined
|
|
19
|
+
|
|
20
|
+
// If it's a function, convert to object form applying to all operations
|
|
21
|
+
if (typeof access === 'function') {
|
|
22
|
+
const fn = access as AccessControl<T>
|
|
23
|
+
return {
|
|
24
|
+
operation: {
|
|
25
|
+
query: fn,
|
|
26
|
+
create: fn,
|
|
27
|
+
update: fn,
|
|
28
|
+
delete: fn,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Already in object form
|
|
34
|
+
return access
|
|
35
|
+
}
|
|
3
36
|
|
|
4
37
|
/**
|
|
5
38
|
* Helper function to define configuration with type safety
|
|
@@ -61,25 +94,37 @@ export function config(userConfig: OpenSaasConfig): OpenSaasConfig | Promise<Ope
|
|
|
61
94
|
* fields: { title: text() },
|
|
62
95
|
* hooks: { ... }
|
|
63
96
|
* })
|
|
97
|
+
*
|
|
98
|
+
* // Access control shorthand
|
|
99
|
+
* const isAdmin = ({ session }) => session?.role === 'admin'
|
|
100
|
+
*
|
|
101
|
+
* Settings: list({
|
|
102
|
+
* access: isAdmin, // Applies to all operations
|
|
103
|
+
* isSingleton: true,
|
|
104
|
+
* fields: { ... }
|
|
105
|
+
* })
|
|
64
106
|
* ```
|
|
65
107
|
*/
|
|
66
|
-
export function list<TTypeInfo extends import('./types.js').TypeInfo>(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
108
|
+
export function list<TTypeInfo extends import('./types.js').TypeInfo>(
|
|
109
|
+
config: ListConfigInput<TTypeInfo>,
|
|
110
|
+
): ListConfig<TTypeInfo> {
|
|
111
|
+
// Normalize access control shorthand to object form
|
|
112
|
+
const normalizedConfig = {
|
|
113
|
+
...config,
|
|
114
|
+
access: normalizeListAccess(config.access),
|
|
70
115
|
}
|
|
71
|
-
|
|
72
|
-
mcp?: import('./types.js').ListMcpConfig
|
|
73
|
-
}): ListConfig<TTypeInfo> {
|
|
116
|
+
|
|
74
117
|
// At runtime, field configs are unchanged
|
|
75
118
|
// At type level, they're transformed to inject TypeInfo types
|
|
76
|
-
return
|
|
119
|
+
return normalizedConfig as ListConfig<TTypeInfo>
|
|
77
120
|
}
|
|
78
121
|
|
|
79
122
|
// Re-export all types
|
|
80
123
|
export type {
|
|
81
124
|
OpenSaasConfig,
|
|
82
125
|
ListConfig,
|
|
126
|
+
ListConfigInput,
|
|
127
|
+
ListAccessControl,
|
|
83
128
|
FieldConfig,
|
|
84
129
|
BaseFieldConfig,
|
|
85
130
|
TextField,
|
|
@@ -115,4 +160,15 @@ export type {
|
|
|
115
160
|
Plugin,
|
|
116
161
|
PluginContext,
|
|
117
162
|
GeneratedFiles,
|
|
163
|
+
// List-level hook argument types
|
|
164
|
+
ResolveInputHookArgs,
|
|
165
|
+
ValidateHookArgs,
|
|
166
|
+
BeforeOperationHookArgs,
|
|
167
|
+
AfterOperationHookArgs,
|
|
168
|
+
// Field-level hook argument types
|
|
169
|
+
FieldResolveInputHookArgs,
|
|
170
|
+
FieldValidateHookArgs,
|
|
171
|
+
FieldBeforeOperationHookArgs,
|
|
172
|
+
FieldAfterOperationHookArgs,
|
|
173
|
+
FieldResolveOutputHookArgs,
|
|
118
174
|
} from './types.js'
|