@pol-studios/db 1.0.0 → 1.0.2
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/README.md +434 -0
- package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
- package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
- package/dist/UserMetadataContext-BYYqA6LI.d.ts +89 -0
- package/dist/auth/context.d.ts +47 -0
- package/dist/auth/context.js +12791 -0
- package/dist/auth/context.js.map +1 -0
- package/dist/auth/guards.d.ts +180 -0
- package/dist/auth/guards.js +7651 -0
- package/dist/auth/guards.js.map +1 -0
- package/dist/auth/hooks.d.ts +312 -0
- package/dist/auth/hooks.js +10600 -0
- package/dist/auth/hooks.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.js +13035 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/client/index.d.ts +16 -0
- package/dist/core/index.d.ts +508 -0
- package/dist/executor-CB4KHyYG.d.ts +507 -0
- package/dist/gen/index.d.ts +1099 -0
- package/dist/hooks/index.d.ts +83 -0
- package/dist/index-DNrSptau.d.ts +8780 -0
- package/dist/index.d.ts +338 -0
- package/dist/index.js +10320 -7124
- package/dist/index.js.map +1 -1
- package/dist/index.web.d.ts +318 -0
- package/dist/index.web.js +56795 -0
- package/dist/index.web.js.map +1 -0
- package/dist/mutation/index.d.ts +58 -0
- package/dist/mutation/index.js +4581 -76
- package/dist/mutation/index.js.map +1 -1
- package/dist/parser/index.d.ts +366 -0
- package/dist/parser/index.js +26 -26
- package/dist/parser/index.js.map +1 -1
- package/dist/query/index.d.ts +723 -0
- package/dist/query/index.js +13124 -10324
- package/dist/query/index.js.map +1 -1
- package/dist/realtime/index.d.ts +44 -0
- package/dist/realtime/index.js +13217 -9297
- package/dist/realtime/index.js.map +1 -1
- package/dist/select-query-parser-CLkOKHzc.d.ts +352 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types-CKsWM8T3.d.ts +62 -0
- package/dist/useBatchUpsert-ooLlpJMg.d.ts +24 -0
- package/dist/useDbCount-B5-Va9sg.d.ts +1740 -0
- package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
- package/dist/useResolveFeedback-DuGP4Tgb.d.ts +1165 -0
- package/dist/useSupabase-pPhUZHcl.d.ts +27 -0
- package/package.json +31 -7
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { b as EntityPermissionCheck, a as EntityAction } from '../EntityPermissions-DwFt4tUd.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if a user has access to a specific permission key.
|
|
5
|
+
* Owners bypass all permission checks.
|
|
6
|
+
*
|
|
7
|
+
* @param accessKeys - Array of access keys the user has
|
|
8
|
+
* @param key - The access key to check for
|
|
9
|
+
* @param options - Additional options for the check
|
|
10
|
+
* @param options.isArchived - Whether the user is archived
|
|
11
|
+
* @param options.isSuspended - Whether the user is suspended
|
|
12
|
+
* @returns boolean - true if user has the specified access
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Basic usage
|
|
17
|
+
* const canAccess = hasAccess(['admin', 'viewer'], 'admin'); // true
|
|
18
|
+
* const cannotAccess = hasAccess(['viewer'], 'admin'); // false
|
|
19
|
+
*
|
|
20
|
+
* // Owner bypasses all checks
|
|
21
|
+
* const ownerAccess = hasAccess(['owner'], 'any-key'); // true
|
|
22
|
+
*
|
|
23
|
+
* // Empty key always returns true (no permission required)
|
|
24
|
+
* const noKeyRequired = hasAccess(['viewer'], ''); // true
|
|
25
|
+
*
|
|
26
|
+
* // Archived/suspended users have no access
|
|
27
|
+
* const archivedUser = hasAccess(['admin'], 'admin', { isArchived: true }); // false
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function hasAccess(accessKeys: string[] | undefined | null, key: string, options?: {
|
|
31
|
+
isArchived?: boolean;
|
|
32
|
+
isSuspended?: boolean;
|
|
33
|
+
}): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a user has any of the specified access keys.
|
|
36
|
+
*
|
|
37
|
+
* @param accessKeys - Array of access keys the user has
|
|
38
|
+
* @param keys - Array of access keys to check for (OR logic)
|
|
39
|
+
* @param options - Additional options for the check
|
|
40
|
+
* @returns boolean - true if user has any of the specified keys
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const hasAny = hasAnyAccess(['viewer'], ['admin', 'editor', 'viewer']); // true
|
|
45
|
+
* const hasNone = hasAnyAccess(['viewer'], ['admin', 'editor']); // false
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function hasAnyAccess(accessKeys: string[] | undefined | null, keys: string[], options?: {
|
|
49
|
+
isArchived?: boolean;
|
|
50
|
+
isSuspended?: boolean;
|
|
51
|
+
}): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a user has all of the specified access keys.
|
|
54
|
+
*
|
|
55
|
+
* @param accessKeys - Array of access keys the user has
|
|
56
|
+
* @param keys - Array of access keys to check for (AND logic)
|
|
57
|
+
* @param options - Additional options for the check
|
|
58
|
+
* @returns boolean - true if user has all of the specified keys
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const hasAll = hasAllAccess(['admin', 'editor'], ['admin', 'editor']); // true
|
|
63
|
+
* const hasPartial = hasAllAccess(['admin'], ['admin', 'editor']); // false
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function hasAllAccess(accessKeys: string[] | undefined | null, keys: string[], options?: {
|
|
67
|
+
isArchived?: boolean;
|
|
68
|
+
isSuspended?: boolean;
|
|
69
|
+
}): boolean;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check if a user has entity-level access based on permission check result.
|
|
73
|
+
* Owners (users with 'owner' access key) bypass entity permissions entirely.
|
|
74
|
+
*
|
|
75
|
+
* @param permission - The permission check result from getPermission/usePermission
|
|
76
|
+
* @param action - The action to check for
|
|
77
|
+
* @param options - Additional options for the check
|
|
78
|
+
* @param options.accessKeys - User's access keys (for owner check)
|
|
79
|
+
* @param options.isArchived - Whether the user is archived
|
|
80
|
+
* @param options.isSuspended - Whether the user is suspended
|
|
81
|
+
* @returns boolean - true if user has permission for the action
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Basic usage
|
|
86
|
+
* const permission = await getPermission('Project', 123);
|
|
87
|
+
* const canEdit = hasEntityAccess(permission, 'edit');
|
|
88
|
+
*
|
|
89
|
+
* // With owner bypass
|
|
90
|
+
* const canEditAsOwner = hasEntityAccess(permission, 'edit', {
|
|
91
|
+
* accessKeys: ['owner'],
|
|
92
|
+
* }); // true, owners bypass all checks
|
|
93
|
+
*
|
|
94
|
+
* // Check loading state
|
|
95
|
+
* if (permission.isLoading) {
|
|
96
|
+
* return false; // Wait for permission to load
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function hasEntityAccess(permission: EntityPermissionCheck | null | undefined, action: EntityAction, options?: {
|
|
101
|
+
accessKeys?: string[] | null;
|
|
102
|
+
isArchived?: boolean;
|
|
103
|
+
isSuspended?: boolean;
|
|
104
|
+
}): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Check if a user has any of the specified entity actions.
|
|
107
|
+
*
|
|
108
|
+
* @param permission - The permission check result
|
|
109
|
+
* @param actions - Array of actions to check for (OR logic)
|
|
110
|
+
* @param options - Additional options for the check
|
|
111
|
+
* @returns boolean - true if user has permission for any of the actions
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const canEditOrDelete = hasAnyEntityAccess(permission, ['edit', 'delete']);
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function hasAnyEntityAccess(permission: EntityPermissionCheck | null | undefined, actions: EntityAction[], options?: {
|
|
119
|
+
accessKeys?: string[] | null;
|
|
120
|
+
isArchived?: boolean;
|
|
121
|
+
isSuspended?: boolean;
|
|
122
|
+
}): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Check if a user has all of the specified entity actions.
|
|
125
|
+
*
|
|
126
|
+
* @param permission - The permission check result
|
|
127
|
+
* @param actions - Array of actions to check for (AND logic)
|
|
128
|
+
* @param options - Additional options for the check
|
|
129
|
+
* @returns boolean - true if user has permission for all of the actions
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* // Check if user can edit AND delete (admin-like permissions)
|
|
134
|
+
* const isAdmin = hasAllEntityAccess(permission, ['edit', 'delete', 'share']);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function hasAllEntityAccess(permission: EntityPermissionCheck | null | undefined, actions: EntityAction[], options?: {
|
|
138
|
+
accessKeys?: string[] | null;
|
|
139
|
+
isArchived?: boolean;
|
|
140
|
+
isSuspended?: boolean;
|
|
141
|
+
}): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if entity access was explicitly denied.
|
|
144
|
+
* Useful for distinguishing between "no permission" and "explicitly blocked".
|
|
145
|
+
*
|
|
146
|
+
* @param permission - The permission check result
|
|
147
|
+
* @returns boolean - true if access was explicitly denied
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const permission = await getPermission('Project', 123);
|
|
152
|
+
* if (isEntityAccessDenied(permission)) {
|
|
153
|
+
* showBlockedMessage('You have been explicitly denied access to this project');
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function isEntityAccessDenied(permission: EntityPermissionCheck | null | undefined): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Type guard to check if permission data is loaded and available.
|
|
160
|
+
*
|
|
161
|
+
* @param permission - The permission check result
|
|
162
|
+
* @returns boolean - true if permission data is loaded
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const permission = usePermission('Project', projectId);
|
|
167
|
+
*
|
|
168
|
+
* if (!isPermissionLoaded(permission)) {
|
|
169
|
+
* return <Spinner />;
|
|
170
|
+
* }
|
|
171
|
+
*
|
|
172
|
+
* // TypeScript knows permission is fully loaded here
|
|
173
|
+
* return permission.canEdit ? <Editor /> : <Viewer />;
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function isPermissionLoaded(permission: EntityPermissionCheck | null | undefined): permission is EntityPermissionCheck & {
|
|
177
|
+
isLoading: false;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export { hasAccess, hasAllAccess, hasAllEntityAccess, hasAnyAccess, hasAnyEntityAccess, hasEntityAccess, isEntityAccessDenied, isPermissionLoaded };
|