glasswork 0.8.0 → 0.8.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/dist/openapi/openapi-transformer.d.ts +5 -0
- package/dist/openapi/openapi-transformer.d.ts.map +1 -1
- package/dist/openapi/openapi-transformer.js +5 -0
- package/dist/openapi/openapi-transformer.js.map +1 -1
- package/dist/utils/serialize-prisma-types.d.ts +1 -1
- package/dist/utils/serialize-prisma-types.d.ts.map +1 -1
- package/dist/utils/serialize-prisma-types.js +12 -10
- package/dist/utils/serialize-prisma-types.js.map +1 -1
- package/package.json +2 -2
- package/dist/authorization/ability-middleware.d.ts +0 -61
- package/dist/authorization/ability-middleware.d.ts.map +0 -1
- package/dist/authorization/ability-middleware.js +0 -74
- package/dist/authorization/ability-middleware.js.map +0 -1
- package/dist/authorization/index.d.ts +0 -46
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js +0 -46
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/route-helpers.d.ts +0 -106
- package/dist/authorization/route-helpers.d.ts.map +0 -1
- package/dist/authorization/route-helpers.js +0 -136
- package/dist/authorization/route-helpers.js.map +0 -1
- package/dist/authorization/service-proxy.d.ts +0 -59
- package/dist/authorization/service-proxy.d.ts.map +0 -1
- package/dist/authorization/service-proxy.js +0 -110
- package/dist/authorization/service-proxy.js.map +0 -1
- package/dist/authorization/types.d.ts +0 -58
- package/dist/authorization/types.d.ts.map +0 -1
- package/dist/authorization/types.js +0 -7
- package/dist/authorization/types.js.map +0 -1
- package/dist/hooks/authorization-hook.d.ts +0 -100
- package/dist/hooks/authorization-hook.d.ts.map +0 -1
- package/dist/hooks/authorization-hook.js +0 -93
- package/dist/hooks/authorization-hook.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -54
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -55
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/service-hooks.d.ts +0 -82
- package/dist/hooks/service-hooks.d.ts.map +0 -1
- package/dist/hooks/service-hooks.js +0 -158
- package/dist/hooks/service-hooks.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -151
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -2
- package/dist/hooks/types.js.map +0 -1
- package/dist/utils/pagination.d.ts +0 -48
- package/dist/utils/pagination.d.ts.map +0 -1
- package/dist/utils/pagination.js +0 -42
- package/dist/utils/pagination.js.map +0 -1
|
@@ -6,6 +6,11 @@ import type { OpenAPIV3_1 } from 'openapi-types';
|
|
|
6
6
|
* - Converts OpenAPI 3.0-style nullable syntax to OpenAPI 3.1.0 format
|
|
7
7
|
* - Recursively processes all schemas in components, paths, and responses
|
|
8
8
|
*
|
|
9
|
+
* **Note**: As of hono-openapi 1.x, this transformation is no longer needed for
|
|
10
|
+
* hono-openapi generated specs, as they already produce proper OpenAPI 3.1 format.
|
|
11
|
+
* This function is kept for backwards compatibility and for transforming external
|
|
12
|
+
* OpenAPI 3.0 specs.
|
|
13
|
+
*
|
|
9
14
|
* @param doc - OpenAPI document to transform
|
|
10
15
|
* @returns Transformed OpenAPI document
|
|
11
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-transformer.d.ts","sourceRoot":"","sources":["../../src/openapi/openapi-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAmFjD
|
|
1
|
+
{"version":3,"file":"openapi-transformer.d.ts","sourceRoot":"","sources":["../../src/openapi/openapi-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAmFjD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAExF"}
|
|
@@ -78,6 +78,11 @@ function transformNullable(schema) {
|
|
|
78
78
|
* - Converts OpenAPI 3.0-style nullable syntax to OpenAPI 3.1.0 format
|
|
79
79
|
* - Recursively processes all schemas in components, paths, and responses
|
|
80
80
|
*
|
|
81
|
+
* **Note**: As of hono-openapi 1.x, this transformation is no longer needed for
|
|
82
|
+
* hono-openapi generated specs, as they already produce proper OpenAPI 3.1 format.
|
|
83
|
+
* This function is kept for backwards compatibility and for transforming external
|
|
84
|
+
* OpenAPI 3.0 specs.
|
|
85
|
+
*
|
|
81
86
|
* @param doc - OpenAPI document to transform
|
|
82
87
|
* @returns Transformed OpenAPI document
|
|
83
88
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi-transformer.js","sourceRoot":"","sources":["../../src/openapi/openapi-transformer.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,SAAS,iBAAiB,CAAC,KAAgB;IACzC,OAAO,KAAK,CAAC,IAAI,CACf,CAAC,IAAI,EAAE,EAAE,CACP,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAC5F,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,IAAa;IAC3C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,IAA+B,CAAC;IACpD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACrB,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,KAAgB;IAClD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACpE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC9C,OA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KAAK,IAAI,EAAE,CAAC;YACzC,SAAS;QACX,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAyB;IAChE,OAAO,iBAAiB,CAAC,GAAG,CAAyB,CAAC;AACxD,CAAC"}
|
|
@@ -103,7 +103,7 @@ export declare const defaultConfig: SerializationConfig;
|
|
|
103
103
|
* }
|
|
104
104
|
* ```
|
|
105
105
|
*/
|
|
106
|
-
export declare function serializePrismaTypes<T>(data: T, config?: SerializationConfig, _depth?: number,
|
|
106
|
+
export declare function serializePrismaTypes<T>(data: T, config?: SerializationConfig, _depth?: number, _ancestors?: WeakSet<object>): SerializedTypes<T>;
|
|
107
107
|
/**
|
|
108
108
|
* Type representing Prisma's Decimal type structure.
|
|
109
109
|
* We use a structural type to avoid importing from @prisma/client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-prisma-types.d.ts","sourceRoot":"","sources":["../../src/utils/serialize-prisma-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAC3C,MAAM,GACN,CAAC,SAAS;IAAE,WAAW,EAAE;QAAE,IAAI,EAAE,SAAS,CAAA;KAAE,CAAA;CAAE,GAC5C,MAAM,GACN,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GACzB,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACzC,CAAC,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,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AG,IAAI,GAAG,SAAS,GACpC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACrB,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,sBAAsB,CAAC,GACjD,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,GACpC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACxB,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,sBAAsB,CAAC,GACnD,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,sBAAsB,CAAC;CACpD,GACH,CAAC,CAAC"}
|
|
@@ -127,7 +127,7 @@ export const defaultConfig = {
|
|
|
127
127
|
* }
|
|
128
128
|
* ```
|
|
129
129
|
*/
|
|
130
|
-
export function serializePrismaTypes(data, config = defaultConfig, _depth = 0,
|
|
130
|
+
export function serializePrismaTypes(data, config = defaultConfig, _depth = 0, _ancestors = new WeakSet()) {
|
|
131
131
|
// Guard: Maximum recursion depth (prevents stack overflow)
|
|
132
132
|
if (_depth > MAX_SERIALIZATION_DEPTH) {
|
|
133
133
|
throw new Error(`Maximum serialization depth (${MAX_SERIALIZATION_DEPTH}) exceeded. ` +
|
|
@@ -137,14 +137,10 @@ export function serializePrismaTypes(data, config = defaultConfig, _depth = 0, _
|
|
|
137
137
|
if (data === null || data === undefined) {
|
|
138
138
|
return data;
|
|
139
139
|
}
|
|
140
|
-
//
|
|
141
|
-
if (typeof data === 'object' &&
|
|
140
|
+
// Only check for circular reference if it's in the CURRENT recursion path
|
|
141
|
+
if (typeof data === 'object' && _ancestors.has(data)) {
|
|
142
142
|
throw new Error('Circular reference detected during serialization. ' +
|
|
143
|
-
'The data structure contains a reference to
|
|
144
|
-
}
|
|
145
|
-
// Add object to seen set before processing
|
|
146
|
-
if (typeof data === 'object') {
|
|
147
|
-
_seen.add(data);
|
|
143
|
+
'The data structure contains a reference to an ancestor object.');
|
|
148
144
|
}
|
|
149
145
|
// Try each transformer
|
|
150
146
|
for (const transformer of config.transformers) {
|
|
@@ -155,14 +151,20 @@ export function serializePrismaTypes(data, config = defaultConfig, _depth = 0, _
|
|
|
155
151
|
}
|
|
156
152
|
// Handle arrays
|
|
157
153
|
if (Array.isArray(data)) {
|
|
158
|
-
|
|
154
|
+
// Add to ancestors before recursing into children
|
|
155
|
+
_ancestors.add(data);
|
|
156
|
+
const result = data.map((item) => serializePrismaTypes(item, config, _depth + 1, _ancestors));
|
|
157
|
+
_ancestors.delete(data); // Remove when leaving this branch
|
|
158
|
+
return result;
|
|
159
159
|
}
|
|
160
160
|
// Handle objects
|
|
161
161
|
if (typeof data === 'object') {
|
|
162
|
+
_ancestors.add(data);
|
|
162
163
|
const result = {};
|
|
163
164
|
for (const [key, value] of Object.entries(data)) {
|
|
164
|
-
result[key] = serializePrismaTypes(value, config, _depth + 1,
|
|
165
|
+
result[key] = serializePrismaTypes(value, config, _depth + 1, _ancestors);
|
|
165
166
|
}
|
|
167
|
+
_ancestors.delete(data); // Remove when leaving this branch
|
|
166
168
|
return result;
|
|
167
169
|
}
|
|
168
170
|
// Return primitives as-is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-prisma-types.js","sourceRoot":"","sources":["../../src/utils/serialize-prisma-types.ts"],"names":[],"mappings":"AA+CA;;;GAGG;AACH,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC;;;;;;;;;GASG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4BAA4B;IAC5B,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC,IAAI,OAAQ,KAAgC,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC/F,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oEAAoE;IACpE,MAAM,mBAAmB,GACvB,GAA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AE,MAAM,GAAG,CAAC,EAAE,UAAU,CAAC,CACrC,CAAC;QACxB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,kCAAkC;QAC3D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iBAAiB;IACjB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,MAAM,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;QAC5E,CAAC;QACD,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,kCAAkC;QAC3D,OAAO,MAA4B,CAAC;IACtC,CAAC;IAED,0BAA0B;IAC1B,OAAO,IAA0B,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glasswork",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A transparent, Lambda-optimized web framework for building OpenAPI-compliant REST APIs.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -128,4 +128,4 @@
|
|
|
128
128
|
"deepmerge": "^4.3.1",
|
|
129
129
|
"openapi-types": "^12.1.3"
|
|
130
130
|
}
|
|
131
|
-
}
|
|
131
|
+
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Context, MiddlewareHandler } from 'hono';
|
|
2
|
-
import type { AbilityConfig, BaseAbility } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates Hono middleware that attaches a CASL ability to the request context.
|
|
5
|
-
*
|
|
6
|
-
* This middleware is transparent - it exposes the CASL ability directly in the
|
|
7
|
-
* Hono context, making it accessible to route handlers. All CASL features
|
|
8
|
-
* remain available.
|
|
9
|
-
*
|
|
10
|
-
* @param config - Ability configuration with factory function
|
|
11
|
-
* @returns Hono middleware that creates and attaches the ability
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { createPrismaAbility } from '@casl/prisma';
|
|
16
|
-
* import { AbilityBuilder } from '@casl/ability';
|
|
17
|
-
*
|
|
18
|
-
* const abilityMiddleware = withAbility({
|
|
19
|
-
* factory: (c) => {
|
|
20
|
-
* const user = c.get('user');
|
|
21
|
-
* const { can, build } = new AbilityBuilder(createPrismaAbility);
|
|
22
|
-
*
|
|
23
|
-
* if (user.role === 'admin') {
|
|
24
|
-
* can('manage', 'all');
|
|
25
|
-
* } else {
|
|
26
|
-
* can('read', 'User', { id: user.id });
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* return build();
|
|
30
|
-
* }
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* app.use('*', abilityMiddleware);
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function withAbility<T extends BaseAbility = BaseAbility>(config: AbilityConfig<T>): MiddlewareHandler;
|
|
37
|
-
/**
|
|
38
|
-
* Helper to retrieve the ability from Hono context.
|
|
39
|
-
* This provides type-safe access to the CASL ability stored by `withAbility`.
|
|
40
|
-
*
|
|
41
|
-
* @param context - Hono context
|
|
42
|
-
* @param contextKey - The key used to store the ability (default: 'ability')
|
|
43
|
-
* @returns The CASL ability instance
|
|
44
|
-
* @throws Error if ability is not found in context
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* router.get('/users', async (c) => {
|
|
49
|
-
* const ability = getAbility(c);
|
|
50
|
-
*
|
|
51
|
-
* // Use CASL ability directly
|
|
52
|
-
* if (ability.can('read', 'User')) {
|
|
53
|
-
* return c.json(users);
|
|
54
|
-
* }
|
|
55
|
-
*
|
|
56
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare function getAbility<T extends BaseAbility = BaseAbility>(context: Context, contextKey?: string): T;
|
|
61
|
-
//# sourceMappingURL=ability-middleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ability-middleware.d.ts","sourceRoot":"","sources":["../../src/authorization/ability-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC7D,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,iBAAiB,CAYnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC5D,OAAO,EAAE,OAAO,EAChB,UAAU,SAAY,GACrB,CAAC,CAUH"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates Hono middleware that attaches a CASL ability to the request context.
|
|
3
|
-
*
|
|
4
|
-
* This middleware is transparent - it exposes the CASL ability directly in the
|
|
5
|
-
* Hono context, making it accessible to route handlers. All CASL features
|
|
6
|
-
* remain available.
|
|
7
|
-
*
|
|
8
|
-
* @param config - Ability configuration with factory function
|
|
9
|
-
* @returns Hono middleware that creates and attaches the ability
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { createPrismaAbility } from '@casl/prisma';
|
|
14
|
-
* import { AbilityBuilder } from '@casl/ability';
|
|
15
|
-
*
|
|
16
|
-
* const abilityMiddleware = withAbility({
|
|
17
|
-
* factory: (c) => {
|
|
18
|
-
* const user = c.get('user');
|
|
19
|
-
* const { can, build } = new AbilityBuilder(createPrismaAbility);
|
|
20
|
-
*
|
|
21
|
-
* if (user.role === 'admin') {
|
|
22
|
-
* can('manage', 'all');
|
|
23
|
-
* } else {
|
|
24
|
-
* can('read', 'User', { id: user.id });
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* return build();
|
|
28
|
-
* }
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* app.use('*', abilityMiddleware);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export function withAbility(config) {
|
|
35
|
-
const contextKey = config.contextKey || 'ability';
|
|
36
|
-
return async (c, next) => {
|
|
37
|
-
// Create ability using factory
|
|
38
|
-
const ability = await config.factory(c);
|
|
39
|
-
// Store in Hono context
|
|
40
|
-
c.set(contextKey, ability);
|
|
41
|
-
await next();
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Helper to retrieve the ability from Hono context.
|
|
46
|
-
* This provides type-safe access to the CASL ability stored by `withAbility`.
|
|
47
|
-
*
|
|
48
|
-
* @param context - Hono context
|
|
49
|
-
* @param contextKey - The key used to store the ability (default: 'ability')
|
|
50
|
-
* @returns The CASL ability instance
|
|
51
|
-
* @throws Error if ability is not found in context
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* router.get('/users', async (c) => {
|
|
56
|
-
* const ability = getAbility(c);
|
|
57
|
-
*
|
|
58
|
-
* // Use CASL ability directly
|
|
59
|
-
* if (ability.can('read', 'User')) {
|
|
60
|
-
* return c.json(users);
|
|
61
|
-
* }
|
|
62
|
-
*
|
|
63
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
64
|
-
* });
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export function getAbility(context, contextKey = 'ability') {
|
|
68
|
-
const ability = context.get(contextKey);
|
|
69
|
-
if (!ability) {
|
|
70
|
-
throw new Error(`Ability not found in context. Did you forget to use withAbility() middleware?`);
|
|
71
|
-
}
|
|
72
|
-
return ability;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=ability-middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ability-middleware.js","sourceRoot":"","sources":["../../src/authorization/ability-middleware.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,WAAW,CACzB,MAAwB;IAExB,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,SAAS,CAAC;IAElD,OAAO,KAAK,EAAE,CAAU,EAAE,IAAI,EAAE,EAAE;QAChC,+BAA+B;QAC/B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAExC,wBAAwB;QACxB,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3B,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,UAAU,CACxB,OAAgB,EAChB,UAAU,GAAG,SAAS;IAEtB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IAED,OAAO,OAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization module for integrating CASL with Glasswork.
|
|
3
|
-
*
|
|
4
|
-
* This module provides transparent integration with CASL while maintaining framework principles.
|
|
5
|
-
*
|
|
6
|
-
* ## Recommended Approach: Service Hooks
|
|
7
|
-
*
|
|
8
|
-
* Configure authorization globally using the hooks system:
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { authorizationHook, defineServiceMetadata, defineAuthorize } from 'glasswork';
|
|
12
|
-
*
|
|
13
|
-
* const authServiceMeta = defineServiceMetadata({
|
|
14
|
-
* deleteSession: { authorize: defineAuthorize('delete', 'Session') }
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* bootstrap(AppModule, {
|
|
18
|
-
* serviceHooks: [authorizationHook],
|
|
19
|
-
* serviceMetadata: { authService: authServiceMeta }
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // In routes - authorization happens automatically!
|
|
23
|
-
* await services.authService.deleteSession(token);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ## Alternative: Explicit Authorization
|
|
27
|
-
*
|
|
28
|
-
* For fine-grained control, use explicit authorize() calls:
|
|
29
|
-
*
|
|
30
|
-
* ```typescript
|
|
31
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
32
|
-
* authorize(c, 'delete', 'Session', { id: c.req.param('id') });
|
|
33
|
-
* await sessionService.delete(c.req.param('id'));
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @module authorization
|
|
38
|
-
* @see https://casl.js.org/ for CASL documentation
|
|
39
|
-
* @see HOOKS_SYSTEM.md for hooks documentation
|
|
40
|
-
*/
|
|
41
|
-
export type { PureAbility } from '@casl/ability';
|
|
42
|
-
export { ForbiddenError, subject } from '@casl/ability';
|
|
43
|
-
export { getAbility, withAbility } from './ability-middleware.js';
|
|
44
|
-
export { accessibleWhere, authorize, can, cannot } from './route-helpers.js';
|
|
45
|
-
export type { AbilityConfig, AbilityFactory, BaseAbility } from './types.js';
|
|
46
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE7E,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization module for integrating CASL with Glasswork.
|
|
3
|
-
*
|
|
4
|
-
* This module provides transparent integration with CASL while maintaining framework principles.
|
|
5
|
-
*
|
|
6
|
-
* ## Recommended Approach: Service Hooks
|
|
7
|
-
*
|
|
8
|
-
* Configure authorization globally using the hooks system:
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { authorizationHook, defineServiceMetadata, defineAuthorize } from 'glasswork';
|
|
12
|
-
*
|
|
13
|
-
* const authServiceMeta = defineServiceMetadata({
|
|
14
|
-
* deleteSession: { authorize: defineAuthorize('delete', 'Session') }
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* bootstrap(AppModule, {
|
|
18
|
-
* serviceHooks: [authorizationHook],
|
|
19
|
-
* serviceMetadata: { authService: authServiceMeta }
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // In routes - authorization happens automatically!
|
|
23
|
-
* await services.authService.deleteSession(token);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ## Alternative: Explicit Authorization
|
|
27
|
-
*
|
|
28
|
-
* For fine-grained control, use explicit authorize() calls:
|
|
29
|
-
*
|
|
30
|
-
* ```typescript
|
|
31
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
32
|
-
* authorize(c, 'delete', 'Session', { id: c.req.param('id') });
|
|
33
|
-
* await sessionService.delete(c.req.param('id'));
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @module authorization
|
|
38
|
-
* @see https://casl.js.org/ for CASL documentation
|
|
39
|
-
* @see HOOKS_SYSTEM.md for hooks documentation
|
|
40
|
-
*/
|
|
41
|
-
export { ForbiddenError, subject } from '@casl/ability';
|
|
42
|
-
// Ability middleware (attaches CASL abilities to context)
|
|
43
|
-
export { getAbility, withAbility } from './ability-middleware.js';
|
|
44
|
-
// Route helpers (explicit authorization - recommended for fine-grained control)
|
|
45
|
-
export { accessibleWhere, authorize, can, cannot } from './route-helpers.js';
|
|
46
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAIH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAClE,gFAAgF;AAChF,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
import type { BaseAbility } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Authorizes an action on a subject using the CASL ability from context.
|
|
5
|
-
* Throws ForbiddenError if the action is not permitted.
|
|
6
|
-
*
|
|
7
|
-
* This is a thin wrapper around CASL's authorize functionality, exposing
|
|
8
|
-
* the native CASL API while providing convenient access to the ability
|
|
9
|
-
* stored in Hono context.
|
|
10
|
-
*
|
|
11
|
-
* @param context - Hono context containing the ability
|
|
12
|
-
* @param action - CASL action (e.g., 'create', 'read', 'update', 'delete')
|
|
13
|
-
* @param subjectType - Subject type string (e.g., 'User', 'Post')
|
|
14
|
-
* @param subjectData - Optional subject instance data
|
|
15
|
-
* @throws ForbiddenError from CASL if action is not permitted
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
20
|
-
* const sessionId = c.req.param('id');
|
|
21
|
-
* const user = c.get('user');
|
|
22
|
-
*
|
|
23
|
-
* // Explicit authorization - clear and obvious
|
|
24
|
-
* authorize(c, 'delete', 'Session', { userId: user.id, sessionId });
|
|
25
|
-
*
|
|
26
|
-
* await sessionService.delete(sessionId);
|
|
27
|
-
* return c.json({ success: true });
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare function authorize<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): void;
|
|
32
|
-
/**
|
|
33
|
-
* Checks if an action is permitted without throwing an error.
|
|
34
|
-
* Returns boolean indicating if the action is allowed.
|
|
35
|
-
*
|
|
36
|
-
* @param context - Hono context containing the ability
|
|
37
|
-
* @param action - CASL action
|
|
38
|
-
* @param subjectType - Subject type string
|
|
39
|
-
* @param subjectData - Optional subject instance data
|
|
40
|
-
* @returns True if action is permitted, false otherwise
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* router.get('/users', async (c) => {
|
|
45
|
-
* if (!can(c, 'read', 'User')) {
|
|
46
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* const users = await userService.findAll();
|
|
50
|
-
* return c.json(users);
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export declare function can<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Checks if an action is forbidden (opposite of can).
|
|
57
|
-
*
|
|
58
|
-
* @param context - Hono context containing the ability
|
|
59
|
-
* @param action - CASL action
|
|
60
|
-
* @param subjectType - Subject type string
|
|
61
|
-
* @param subjectData - Optional subject instance data
|
|
62
|
-
* @returns True if action is forbidden, false if permitted
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* router.post('/admin/users', async (c) => {
|
|
67
|
-
* if (cannot(c, 'create', 'User')) {
|
|
68
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
69
|
-
* }
|
|
70
|
-
*
|
|
71
|
-
* // ... create user
|
|
72
|
-
* });
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare function cannot<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a Prisma where clause using CASL's accessibleBy helper.
|
|
78
|
-
* This is a transparent wrapper that exposes @casl/prisma functionality.
|
|
79
|
-
*
|
|
80
|
-
* Requires @casl/prisma to be installed as a peer dependency.
|
|
81
|
-
*
|
|
82
|
-
* @param context - Hono context containing the ability
|
|
83
|
-
* @param subjectType - Prisma model name (e.g., 'User', 'Post')
|
|
84
|
-
* @param additionalWhere - Optional additional where conditions to combine
|
|
85
|
-
* @returns Prisma where clause that filters by ability permissions
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* import { accessibleBy } from '@casl/prisma';
|
|
90
|
-
*
|
|
91
|
-
* router.get('/posts', async (c) => {
|
|
92
|
-
* const ability = getAbility(c);
|
|
93
|
-
*
|
|
94
|
-
* // Use CASL Prisma integration directly
|
|
95
|
-
* const posts = await prisma.post.findMany({
|
|
96
|
-
* where: accessibleBy(ability).Post
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* return c.json(posts);
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* @see https://casl.js.org/v6/en/package/casl-prisma
|
|
104
|
-
*/
|
|
105
|
-
export declare function accessibleWhere<T extends BaseAbility = BaseAbility>(context: Context, subjectType: string, additionalWhere?: object): object;
|
|
106
|
-
//# sourceMappingURL=route-helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/authorization/route-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC3D,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CAUN;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACrD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAKT;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACxD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACjE,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAuBR"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { ForbiddenError, subject } from '@casl/ability';
|
|
2
|
-
import { getAbility } from './ability-middleware.js';
|
|
3
|
-
/**
|
|
4
|
-
* Authorizes an action on a subject using the CASL ability from context.
|
|
5
|
-
* Throws ForbiddenError if the action is not permitted.
|
|
6
|
-
*
|
|
7
|
-
* This is a thin wrapper around CASL's authorize functionality, exposing
|
|
8
|
-
* the native CASL API while providing convenient access to the ability
|
|
9
|
-
* stored in Hono context.
|
|
10
|
-
*
|
|
11
|
-
* @param context - Hono context containing the ability
|
|
12
|
-
* @param action - CASL action (e.g., 'create', 'read', 'update', 'delete')
|
|
13
|
-
* @param subjectType - Subject type string (e.g., 'User', 'Post')
|
|
14
|
-
* @param subjectData - Optional subject instance data
|
|
15
|
-
* @throws ForbiddenError from CASL if action is not permitted
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
20
|
-
* const sessionId = c.req.param('id');
|
|
21
|
-
* const user = c.get('user');
|
|
22
|
-
*
|
|
23
|
-
* // Explicit authorization - clear and obvious
|
|
24
|
-
* authorize(c, 'delete', 'Session', { userId: user.id, sessionId });
|
|
25
|
-
*
|
|
26
|
-
* await sessionService.delete(sessionId);
|
|
27
|
-
* return c.json({ success: true });
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export function authorize(context, action, subjectType, subjectData) {
|
|
32
|
-
const ability = getAbility(context);
|
|
33
|
-
// Use CASL's native ForbiddenError.from() pattern
|
|
34
|
-
// This exposes CASL API directly - no wrapper
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
ForbiddenError.from(ability).throwUnlessCan(action, subject(subjectType, subjectData || {}));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Checks if an action is permitted without throwing an error.
|
|
40
|
-
* Returns boolean indicating if the action is allowed.
|
|
41
|
-
*
|
|
42
|
-
* @param context - Hono context containing the ability
|
|
43
|
-
* @param action - CASL action
|
|
44
|
-
* @param subjectType - Subject type string
|
|
45
|
-
* @param subjectData - Optional subject instance data
|
|
46
|
-
* @returns True if action is permitted, false otherwise
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* router.get('/users', async (c) => {
|
|
51
|
-
* if (!can(c, 'read', 'User')) {
|
|
52
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* const users = await userService.findAll();
|
|
56
|
-
* return c.json(users);
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export function can(context, action, subjectType, subjectData) {
|
|
61
|
-
const ability = getAbility(context);
|
|
62
|
-
// Use CASL's native can() method directly
|
|
63
|
-
return ability.can(action, subject(subjectType, subjectData || {}));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Checks if an action is forbidden (opposite of can).
|
|
67
|
-
*
|
|
68
|
-
* @param context - Hono context containing the ability
|
|
69
|
-
* @param action - CASL action
|
|
70
|
-
* @param subjectType - Subject type string
|
|
71
|
-
* @param subjectData - Optional subject instance data
|
|
72
|
-
* @returns True if action is forbidden, false if permitted
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* router.post('/admin/users', async (c) => {
|
|
77
|
-
* if (cannot(c, 'create', 'User')) {
|
|
78
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
79
|
-
* }
|
|
80
|
-
*
|
|
81
|
-
* // ... create user
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export function cannot(context, action, subjectType, subjectData) {
|
|
86
|
-
return !can(context, action, subjectType, subjectData);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Creates a Prisma where clause using CASL's accessibleBy helper.
|
|
90
|
-
* This is a transparent wrapper that exposes @casl/prisma functionality.
|
|
91
|
-
*
|
|
92
|
-
* Requires @casl/prisma to be installed as a peer dependency.
|
|
93
|
-
*
|
|
94
|
-
* @param context - Hono context containing the ability
|
|
95
|
-
* @param subjectType - Prisma model name (e.g., 'User', 'Post')
|
|
96
|
-
* @param additionalWhere - Optional additional where conditions to combine
|
|
97
|
-
* @returns Prisma where clause that filters by ability permissions
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* import { accessibleBy } from '@casl/prisma';
|
|
102
|
-
*
|
|
103
|
-
* router.get('/posts', async (c) => {
|
|
104
|
-
* const ability = getAbility(c);
|
|
105
|
-
*
|
|
106
|
-
* // Use CASL Prisma integration directly
|
|
107
|
-
* const posts = await prisma.post.findMany({
|
|
108
|
-
* where: accessibleBy(ability).Post
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* return c.json(posts);
|
|
112
|
-
* });
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* @see https://casl.js.org/v6/en/package/casl-prisma
|
|
116
|
-
*/
|
|
117
|
-
export function accessibleWhere(context, subjectType, additionalWhere) {
|
|
118
|
-
const ability = getAbility(context);
|
|
119
|
-
// Use CASL Prisma's accessibleBy directly
|
|
120
|
-
// Import is done dynamically to avoid hard dependency
|
|
121
|
-
try {
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
123
|
-
const { accessibleBy } = require('@casl/prisma');
|
|
124
|
-
const abilityWhere = accessibleBy(ability)[subjectType];
|
|
125
|
-
if (additionalWhere) {
|
|
126
|
-
return {
|
|
127
|
-
AND: [abilityWhere, additionalWhere].filter(Boolean),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
return abilityWhere;
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
throw new Error('@casl/prisma is required for accessibleWhere(). Install it with: npm install @casl/prisma');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=route-helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.js","sourceRoot":"","sources":["../../src/authorization/route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,SAAS,CACvB,OAAgB,EAChB,MAAc,EACd,WAAmB,EACnB,WAAoB;IAEpB,MAAM,OAAO,GAAG,UAAU,CAAI,OAAO,CAAC,CAAC;IAEvC,kDAAkD;IAClD,8CAA8C;IAC9C,8DAA8D;IAC7D,cAAc,CAAC,IAAI,CAAC,OAAO,CAAS,CAAC,cAAc,CAClD,MAAM,EACN,OAAO,CAAC,WAAW,EAAE,WAAW,IAAI,EAAE,CAAC,CACxC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,GAAG,CACjB,OAAgB,EAChB,MAAc,EACd,WAAmB,EACnB,WAAoB;IAEpB,MAAM,OAAO,GAAG,UAAU,CAAI,OAAO,CAAC,CAAC;IAEvC,0CAA0C;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,MAAM,CACpB,OAAgB,EAChB,MAAc,EACd,WAAmB,EACnB,WAAoB;IAEpB,OAAO,CAAC,GAAG,CAAI,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAgB,EAChB,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