glasswork 0.2.4 → 0.3.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/dist/http/route-helpers.d.ts +4 -4
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js +4 -1
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/list-query/builder.d.ts +33 -0
- package/dist/list-query/builder.d.ts.map +1 -0
- package/dist/list-query/builder.js +104 -0
- package/dist/list-query/builder.js.map +1 -0
- package/dist/list-query/casl.d.ts +36 -0
- package/dist/list-query/casl.d.ts.map +1 -0
- package/dist/list-query/casl.js +42 -0
- package/dist/list-query/casl.js.map +1 -0
- package/dist/list-query/global-search.d.ts +20 -0
- package/dist/list-query/global-search.d.ts.map +1 -0
- package/dist/list-query/global-search.js +68 -0
- package/dist/list-query/global-search.js.map +1 -0
- package/dist/list-query/index.d.ts +6 -0
- package/dist/list-query/index.d.ts.map +1 -0
- package/dist/list-query/index.js +7 -0
- package/dist/list-query/index.js.map +1 -0
- package/dist/list-query/parser.d.ts +17 -0
- package/dist/list-query/parser.d.ts.map +1 -0
- package/dist/list-query/parser.js +162 -0
- package/dist/list-query/parser.js.map +1 -0
- package/dist/list-query/prisma-builder.d.ts +21 -0
- package/dist/list-query/prisma-builder.d.ts.map +1 -0
- package/dist/list-query/prisma-builder.js +224 -0
- package/dist/list-query/prisma-builder.js.map +1 -0
- package/dist/list-query/query-schema.d.ts +15 -0
- package/dist/list-query/query-schema.d.ts.map +1 -0
- package/dist/list-query/query-schema.js +16 -0
- package/dist/list-query/query-schema.js.map +1 -0
- package/dist/list-query/schema-helpers.d.ts +81 -0
- package/dist/list-query/schema-helpers.d.ts.map +1 -0
- package/dist/list-query/schema-helpers.js +85 -0
- package/dist/list-query/schema-helpers.js.map +1 -0
- package/dist/list-query/types.d.ts +66 -0
- package/dist/list-query/types.d.ts.map +1 -0
- package/dist/{hooks → list-query}/types.js.map +1 -1
- package/dist/list-query/validator.d.ts +35 -0
- package/dist/list-query/validator.d.ts.map +1 -0
- package/dist/list-query/validator.js +44 -0
- package/dist/list-query/validator.js.map +1 -0
- package/dist/openapi/defaults.d.ts.map +1 -1
- package/dist/openapi/defaults.js +12 -3
- package/dist/openapi/defaults.js.map +1 -1
- package/dist/openapi/hooks.d.ts.map +1 -1
- package/dist/openapi/hooks.js +7 -4
- package/dist/openapi/hooks.js.map +1 -1
- package/dist/openapi/openapi.d.ts.map +1 -1
- package/dist/openapi/openapi.js +4 -33
- package/dist/openapi/openapi.js.map +1 -1
- package/package.json +12 -1
- 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/openapi/openapi-transformer.d.ts +0 -13
- package/dist/openapi/openapi-transformer.d.ts.map +0 -1
- package/dist/openapi/openapi-transformer.js +0 -87
- package/dist/openapi/openapi-transformer.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
- /package/dist/{hooks → list-query}/types.js +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field path as an array of strings for nested fields
|
|
3
|
+
* Example: ['organization', 'name'] represents 'organization.name'
|
|
4
|
+
*/
|
|
5
|
+
export type FieldPath = readonly string[];
|
|
6
|
+
/**
|
|
7
|
+
* Search field input - accepts either a simple string for flat fields
|
|
8
|
+
* or an array for nested fields
|
|
9
|
+
* Example: 'name' or ['organization', 'name']
|
|
10
|
+
*/
|
|
11
|
+
export type SearchFieldInput = string | readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* Sieve filter operators
|
|
14
|
+
* Based on https://github.com/Biarity/Sieve
|
|
15
|
+
*/
|
|
16
|
+
export type FilterOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | '@=' | '_=' | '_-=' | '!@=' | '!_=' | '!_-=' | '==*' | '!=*' | '@=*' | '_=*' | '_-=*' | '!@=*' | '!_=*' | '!_-=*';
|
|
17
|
+
/**
|
|
18
|
+
* Sort direction
|
|
19
|
+
*/
|
|
20
|
+
export type SortDirection = 'asc' | 'desc';
|
|
21
|
+
/**
|
|
22
|
+
* Parsed filter condition
|
|
23
|
+
*/
|
|
24
|
+
export interface ParsedFilter {
|
|
25
|
+
readonly fieldPath: FieldPath;
|
|
26
|
+
readonly operator: FilterOperator;
|
|
27
|
+
readonly value: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parsed sort condition
|
|
31
|
+
*/
|
|
32
|
+
export interface ParsedSort {
|
|
33
|
+
readonly fieldPath: FieldPath;
|
|
34
|
+
readonly direction: SortDirection;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Raw query parameters from HTTP request
|
|
38
|
+
*/
|
|
39
|
+
export interface RawQueryParams {
|
|
40
|
+
readonly sorts?: string;
|
|
41
|
+
readonly filters?: string;
|
|
42
|
+
readonly page?: number;
|
|
43
|
+
readonly pageSize?: number;
|
|
44
|
+
readonly search?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parsed query parameters
|
|
48
|
+
*/
|
|
49
|
+
export interface ParsedQueryParams {
|
|
50
|
+
readonly sorts: readonly ParsedSort[];
|
|
51
|
+
readonly filters: readonly ParsedFilter[];
|
|
52
|
+
readonly page: number;
|
|
53
|
+
readonly pageSize: number;
|
|
54
|
+
readonly search?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Prisma-ready query parameters for list operations
|
|
58
|
+
* Generic type parameter should be the Prisma WhereInput and OrderByInput types
|
|
59
|
+
*/
|
|
60
|
+
export interface PrismaListParams<TWhere = Record<string, unknown>, TOrderBy = Record<string, unknown>> {
|
|
61
|
+
readonly where: TWhere;
|
|
62
|
+
readonly orderBy: readonly TOrderBy[];
|
|
63
|
+
readonly skip: number;
|
|
64
|
+
readonly take: number;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/list-query/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,MAAM,EAAE,CAAC;AAE1C;;;;GAIG;AACH,MAAM,MA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B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAC/B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAElC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/list-query/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type BaseIssue, type BaseSchema, type InferOutput } from 'valibot';
|
|
2
|
+
/**
|
|
3
|
+
* Schema-based validation configuration
|
|
4
|
+
* Defines Valibot schemas for validating Prisma where and orderBy clauses
|
|
5
|
+
*/
|
|
6
|
+
export interface SchemaValidationConfig<TWhereSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TOrderBySchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> {
|
|
7
|
+
readonly whereSchema: TWhereSchema;
|
|
8
|
+
readonly orderBySchema: TOrderBySchema;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validated list params with proper typing from Valibot schemas
|
|
12
|
+
* Note: orderBy is not readonly to match Prisma's expected type
|
|
13
|
+
*/
|
|
14
|
+
export interface ValidatedListParams<TWhereSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TOrderBySchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> {
|
|
15
|
+
readonly where: InferOutput<TWhereSchema>;
|
|
16
|
+
readonly orderBy: InferOutput<TOrderBySchema>[];
|
|
17
|
+
readonly skip: number;
|
|
18
|
+
readonly take: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validate and parse Prisma where clause against schema
|
|
22
|
+
* Returns the validated and typed result
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateWhere<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(where: Record<string, unknown>, schema: TSchema): InferOutput<TSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* Validate and parse Prisma orderBy clause against schema
|
|
27
|
+
* Returns the validated and typed results as a mutable array (not readonly) to match Prisma's expectations
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateOrderBy<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(orderBy: readonly Record<string, unknown>[], schema: TSchema): InferOutput<TSchema>[];
|
|
30
|
+
/**
|
|
31
|
+
* Validate Prisma list params against schemas
|
|
32
|
+
* Returns validated and properly typed params
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateListParams<TWhereSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TOrderBySchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(where: Record<string, unknown>, orderBy: readonly Record<string, unknown>[], skip: number, take: number, config: SchemaValidationConfig<TWhereSchema, TOrderBySchema>): ValidatedListParams<TWhereSchema, TOrderBySchema>;
|
|
35
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/list-query/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAS,MAAM,SAAS,CAAC;AAEnF;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CACrC,YAAY,SAAS,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,EACrE,cAAc,SAAS,UAAU,CAAC,OAAO,EAAE,OAA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AAO,CAAC,CAAC,EAEvE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC3C,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,sBAAsB,CAAC,YAAY,EAAE,cAAc,CAAC,GAC3D,mBAAmB,CAAC,YAAY,EAAE,cAAc,CAAC,CAOnD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { parse } from 'valibot';
|
|
2
|
+
/**
|
|
3
|
+
* Validate and parse Prisma where clause against schema
|
|
4
|
+
* Returns the validated and typed result
|
|
5
|
+
*/
|
|
6
|
+
export function validateWhere(where, schema) {
|
|
7
|
+
try {
|
|
8
|
+
return parse(schema, where);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error instanceof Error) {
|
|
12
|
+
throw new Error(`Invalid filter: ${error.message}`);
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validate and parse Prisma orderBy clause against schema
|
|
19
|
+
* Returns the validated and typed results as a mutable array (not readonly) to match Prisma's expectations
|
|
20
|
+
*/
|
|
21
|
+
export function validateOrderBy(orderBy, schema) {
|
|
22
|
+
try {
|
|
23
|
+
return orderBy.map((order) => parse(schema, order));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
throw new Error(`Invalid sort: ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate Prisma list params against schemas
|
|
34
|
+
* Returns validated and properly typed params
|
|
35
|
+
*/
|
|
36
|
+
export function validateListParams(where, orderBy, skip, take, config) {
|
|
37
|
+
return {
|
|
38
|
+
where: validateWhere(where, config.whereSchema),
|
|
39
|
+
orderBy: validateOrderBy(orderBy, config.orderBySchema),
|
|
40
|
+
skip,
|
|
41
|
+
take,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/list-query/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,EAAE,MAAM,SAAS,CAAC;AA4BnF;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,KAA8B,EAC9B,MAAe;IAEf,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,mBAAmB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,OAA2C,EAC3C,MAAe;IAEf,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAIhC,KAA8B,EAC9B,OAA2C,EAC3C,IAAY,EACZ,IAAY,EACZ,MAA4D;IAE5D,OAAO;QACL,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC;QAC/C,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;QACvD,IAAI;QACJ,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,CAAC,gBA8FhD,CAAC"}
|
package/dist/openapi/defaults.js
CHANGED
|
@@ -62,7 +62,7 @@ export const defaultOpenAPIComponents = {
|
|
|
62
62
|
maximum: 3600,
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
|
-
// Pagination headers (from
|
|
65
|
+
// Pagination headers (from list-query)
|
|
66
66
|
'X-Total-Count': {
|
|
67
67
|
description: 'Total number of items available',
|
|
68
68
|
schema: {
|
|
@@ -72,7 +72,16 @@ export const defaultOpenAPIComponents = {
|
|
|
72
72
|
maximum: 2147483647, // Max int32
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
|
-
'X-
|
|
75
|
+
'X-Total-Pages': {
|
|
76
|
+
description: 'Total number of pages',
|
|
77
|
+
schema: {
|
|
78
|
+
type: 'integer',
|
|
79
|
+
format: 'int32',
|
|
80
|
+
minimum: 0,
|
|
81
|
+
maximum: 2147483647, // Max int32
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
'X-Current-Page': {
|
|
76
85
|
description: 'Current page number',
|
|
77
86
|
schema: {
|
|
78
87
|
type: 'integer',
|
|
@@ -81,7 +90,7 @@ export const defaultOpenAPIComponents = {
|
|
|
81
90
|
maximum: 2147483647, // Max int32
|
|
82
91
|
},
|
|
83
92
|
},
|
|
84
|
-
'X-
|
|
93
|
+
'X-Page-Size': {
|
|
85
94
|
description: 'Number of items per page',
|
|
86
95
|
schema: {
|
|
87
96
|
type: 'integer',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA+B;IAClE,OAAO,EAAE;QACP,uDAAuD;QACvD,aAAa,EAAE,YAAY,CAAC,gBAAgB,CAA2B;QACvE,uBAAuB,EAAE,YAAY,CAAC,0BAA0B,CAA2B;QAC3F,eAAe,EAAE,YAAY,CAAC,kBAAkB,CAA2B;KAC5E;IACD,OAAO,EAAE;QACP,eAAe;QACf,6BAA6B,EAAE;YAC7B,WAAW,EAAE,kCAAkC;YAC/C,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,qCAAqC;aAC/C;SACF;QAED,6CAA6C;QAC7C,iBAAiB,EAAE;YACjB,WAAW,EAAE,mDAAmD;YAChE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,qBAAqB,EAAE;YACrB,WAAW,EAAE,0CAA0C;YACvD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,iBAAiB,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,IAAI;aACd;SACF;QACD,aAAa,EAAE;YACb,WAAW,EAAE,4DAA4D;YACzE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,IAAI;aACd;SACF;QAED,
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA+B;IAClE,OAAO,EAAE;QACP,uDAAuD;QACvD,aAAa,EAAE,YAAY,CAAC,gBAAgB,CAA2B;QACvE,uBAAuB,EAAE,YAAY,CAAC,0BAA0B,CAA2B;QAC3F,eAAe,EAAE,YAAY,CAAC,kBAAkB,CAA2B;KAC5E;IACD,OAAO,EAAE;QACP,eAAe;QACf,6BAA6B,EAAE;YAC7B,WAAW,EAAE,kCAAkC;YAC/C,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,qCAAqC;aAC/C;SACF;QAED,6CAA6C;QAC7C,iBAAiB,EAAE;YACjB,WAAW,EAAE,mDAAmD;YAChE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,qBAAqB,EAAE;YACrB,WAAW,EAAE,0CAA0C;YACvD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBAC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openapi/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAc3E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAgChF;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,mBAAmB,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/openapi/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAc3E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAgChF;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,mBAAmB,CA4BjE"}
|
package/dist/openapi/hooks.js
CHANGED
|
@@ -67,11 +67,14 @@ export function createPaginationHeadersHook() {
|
|
|
67
67
|
'X-Total-Count': {
|
|
68
68
|
$ref: '#/components/headers/X-Total-Count',
|
|
69
69
|
},
|
|
70
|
-
'X-
|
|
71
|
-
$ref: '#/components/headers/X-
|
|
70
|
+
'X-Total-Pages': {
|
|
71
|
+
$ref: '#/components/headers/X-Total-Pages',
|
|
72
72
|
},
|
|
73
|
-
'X-
|
|
74
|
-
$ref: '#/components/headers/X-
|
|
73
|
+
'X-Current-Page': {
|
|
74
|
+
$ref: '#/components/headers/X-Current-Page',
|
|
75
|
+
},
|
|
76
|
+
'X-Page-Size': {
|
|
77
|
+
$ref: '#/components/headers/X-Page-Size',
|
|
75
78
|
},
|
|
76
79
|
},
|
|
77
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["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AO,EAAE;gBACP,GAAG,QAAQ,CAAC,OAAO;gBACnB,GAAG,OAAO;aACX;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;QAC3B,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAE5C,kEAAkE;QAClE,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;YAClD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE;gBACP,GAAG,QAAQ,CAAC,OAAO;gBACnB,eAAe,EAAE;oBACf,IAAI,EAAE,oCAAoC;iBAC3C;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,oCAAoC;iBAC3C;gBACD,gBAAgB,EAAE;oBAChB,IAAI,EAAE,qCAAqC;iBAC5C;gBACD,aAAa,EAAE;oBACb,IAAI,EAAE,kCAAkC;iBACzC;aACF;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi/openapi.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/openapi/openapi.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAW1B,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,IAAI,CAAC;IACV,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CA2EvE"}
|
package/dist/openapi/openapi.js
CHANGED
|
@@ -6,7 +6,6 @@ import { deepMerge } from '../utils/deep-merge.js';
|
|
|
6
6
|
import { createLogger } from '../utils/logger.js';
|
|
7
7
|
import { defaultOpenAPIComponents } from './defaults.js';
|
|
8
8
|
import { createCorsHeadersHook, createPaginationHeadersHook, createRateLimitHeadersHook, } from './hooks.js';
|
|
9
|
-
import { transformOpenAPIDocument } from './openapi-transformer.js';
|
|
10
9
|
/**
|
|
11
10
|
* Configure OpenAPI documentation for the application.
|
|
12
11
|
*
|
|
@@ -55,23 +54,7 @@ export function configureOpenAPI(options) {
|
|
|
55
54
|
}
|
|
56
55
|
// Serve OpenAPI spec endpoint (development only by default)
|
|
57
56
|
if (shouldServeSpecs) {
|
|
58
|
-
|
|
59
|
-
app.get('/api/openapi-base.json', openAPISpecs(app, { documentation: mergedDocumentation }));
|
|
60
|
-
// Create a custom handler that transforms the spec to OpenAPI 3.1 format
|
|
61
|
-
app.get('/api/openapi.json', async (c) => {
|
|
62
|
-
try {
|
|
63
|
-
// Get the base spec from the internal endpoint
|
|
64
|
-
const response = await app.request('/api/openapi-base.json');
|
|
65
|
-
const spec = (await response.json());
|
|
66
|
-
// Transform to OpenAPI 3.1 format
|
|
67
|
-
const transformedSpec = transformOpenAPIDocument(spec);
|
|
68
|
-
return c.json(transformedSpec);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
logger.error('Failed to generate OpenAPI spec:', error);
|
|
72
|
-
return c.json({ error: 'Failed to generate OpenAPI spec' }, 500);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
57
|
+
app.get('/api/openapi.json', openAPISpecs(app, { documentation: mergedDocumentation }));
|
|
75
58
|
}
|
|
76
59
|
// Serve Swagger UI (development only by default)
|
|
77
60
|
if (shouldServeUI) {
|
|
@@ -84,21 +67,9 @@ export function configureOpenAPI(options) {
|
|
|
84
67
|
// This happens after routes are registered
|
|
85
68
|
setTimeout(async () => {
|
|
86
69
|
try {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const response = await app.request('/api/openapi.json');
|
|
91
|
-
specContent = await response.text();
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
// If not serving specs, generate and transform manually
|
|
95
|
-
// Mount a temporary internal endpoint
|
|
96
|
-
app.get('/api/openapi-internal.json', openAPISpecs(app, { documentation: mergedDocumentation }));
|
|
97
|
-
const response = await app.request('/api/openapi-internal.json');
|
|
98
|
-
const spec = (await response.json());
|
|
99
|
-
const transformedSpec = transformOpenAPIDocument(spec);
|
|
100
|
-
specContent = JSON.stringify(transformedSpec, null, 2);
|
|
101
|
-
}
|
|
70
|
+
// Use Hono's built-in request method to simulate the request
|
|
71
|
+
const response = await app.request('/api/openapi.json');
|
|
72
|
+
const specContent = await response.text();
|
|
102
73
|
await writeFile(filePath, specContent, 'utf-8');
|
|
103
74
|
logger.info(`OpenAPI spec written to ${filePath}`);
|
|
104
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/openapi/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CA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AC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAC3F,CAAC;IAEF,OAAO;QACL,GAAG,UAAU;QACb,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAC1B,UAAkB,EAClB,EAAE,gBAAgB,EAAE,WAAW,EAAuD;IAEtF,gFAAgF;IAChF,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+CAA+C;IAC/C,IAAI,UAAU,KAAK,6BAA6B,EAAE,CAAC;QACjD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,8DAA8D;IAC9D,IAAI,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;QACxE,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,mCAAmC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glasswork",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -60,7 +60,9 @@
|
|
|
60
60
|
"@aws-sdk/client-dynamodb": "^3.902.0",
|
|
61
61
|
"@aws-sdk/client-ssm": "^3.902.0",
|
|
62
62
|
"@aws-sdk/lib-dynamodb": "^3.902.0",
|
|
63
|
+
"@casl/prisma": "^1.4.0",
|
|
63
64
|
"@hono/swagger-ui": "^0.5.0",
|
|
65
|
+
"@prisma/client": "^6.0.0",
|
|
64
66
|
"awilix": "^12.0.0",
|
|
65
67
|
"dotenv": "^16.0.0",
|
|
66
68
|
"hono": "^4.9.0",
|
|
@@ -77,9 +79,15 @@
|
|
|
77
79
|
"@aws-sdk/lib-dynamodb": {
|
|
78
80
|
"optional": true
|
|
79
81
|
},
|
|
82
|
+
"@casl/prisma": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
80
85
|
"@hono/swagger-ui": {
|
|
81
86
|
"optional": true
|
|
82
87
|
},
|
|
88
|
+
"@prisma/client": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
83
91
|
"dotenv": {
|
|
84
92
|
"optional": true
|
|
85
93
|
}
|
|
@@ -87,6 +95,9 @@
|
|
|
87
95
|
"devDependencies": {
|
|
88
96
|
"@aws-sdk/client-ssm": "^3.901.0",
|
|
89
97
|
"@biomejs/biome": "^2.2.5",
|
|
98
|
+
"@casl/ability": "^6.7.3",
|
|
99
|
+
"@casl/prisma": "^1.5.2",
|
|
100
|
+
"@prisma/client": "^6.18.0",
|
|
90
101
|
"@types/node": "^22.18.8",
|
|
91
102
|
"@vitest/coverage-v8": "^3.2.4",
|
|
92
103
|
"dotenv": "^17.2.3",
|
|
@@ -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"}
|