@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.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +291 -0
  3. package/README.md +6 -3
  4. package/dist/access/engine.d.ts +2 -0
  5. package/dist/access/engine.d.ts.map +1 -1
  6. package/dist/access/engine.js +8 -6
  7. package/dist/access/engine.js.map +1 -1
  8. package/dist/access/engine.test.js +4 -0
  9. package/dist/access/engine.test.js.map +1 -1
  10. package/dist/access/types.d.ts +31 -4
  11. package/dist/access/types.d.ts.map +1 -1
  12. package/dist/config/index.d.ts +12 -10
  13. package/dist/config/index.d.ts.map +1 -1
  14. package/dist/config/index.js +37 -1
  15. package/dist/config/index.js.map +1 -1
  16. package/dist/config/types.d.ts +341 -82
  17. package/dist/config/types.d.ts.map +1 -1
  18. package/dist/context/index.d.ts.map +1 -1
  19. package/dist/context/index.js +330 -60
  20. package/dist/context/index.js.map +1 -1
  21. package/dist/context/nested-operations.d.ts.map +1 -1
  22. package/dist/context/nested-operations.js +38 -25
  23. package/dist/context/nested-operations.js.map +1 -1
  24. package/dist/hooks/index.d.ts +45 -7
  25. package/dist/hooks/index.d.ts.map +1 -1
  26. package/dist/hooks/index.js +10 -4
  27. package/dist/hooks/index.js.map +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/access/engine.test.ts +4 -0
  33. package/src/access/engine.ts +10 -7
  34. package/src/access/types.ts +45 -4
  35. package/src/config/index.ts +65 -9
  36. package/src/config/types.ts +402 -91
  37. package/src/context/index.ts +421 -82
  38. package/src/context/nested-operations.ts +40 -25
  39. package/src/hooks/index.ts +66 -14
  40. package/src/index.ts +11 -0
  41. package/tests/access.test.ts +28 -28
  42. package/tests/config.test.ts +20 -3
  43. package/tests/nested-access-and-hooks.test.ts +8 -3
  44. package/tests/singleton.test.ts +329 -0
  45. package/tests/sudo.test.ts +2 -13
  46. package/tsconfig.tsbuildinfo +1 -1
@@ -1,5 +1,38 @@
1
- import type { OpenSaasConfig, ListConfig, OperationAccess, Hooks } from './types.js'
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>(config: {
67
- fields: import('./types.js').FieldsWithTypeInfo<TTypeInfo>
68
- access?: {
69
- operation?: OperationAccess<TTypeInfo['item']>
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
- hooks?: Hooks<TTypeInfo['item'], TTypeInfo['inputs']['create'], TTypeInfo['inputs']['update']>
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 config as ListConfig<TTypeInfo>
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'