@owlmeans/module 0.1.2 → 0.1.4
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 +13 -514
- package/build/index.d.ts +15 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -4
- package/build/index.js.map +1 -1
- package/build/utils/index.d.ts +5 -2
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +3 -2
- package/build/utils/index.js.map +1 -1
- package/package.json +4 -6
- package/src/index.ts +17 -5
- package/src/utils/index.ts +6 -2
- package/tsconfig.json +5 -10
- package/src/consts.ts +0 -7
- package/src/filter.ts +0 -26
- package/src/helper.ts +0 -37
- package/src/module.ts +0 -105
- package/src/types.ts +0 -94
- package/src/utils/module.ts +0 -3
- package/src/utils/types.ts +0 -6
package/README.md
CHANGED
|
@@ -1,521 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @owlmeans/module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Deprecated reexport shim.** This package re-exports everything from [`@owlmeans/entrypoint`](../entrypoint). Use that package instead.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Migration
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```diff
|
|
8
|
+
- import { module, guard, filter } from '@owlmeans/module'
|
|
9
|
+
+ import { entrypoint, guard, filter } from '@owlmeans/entrypoint'
|
|
8
10
|
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
- Generate final URLs for navigation or API calls on both backend and frontend
|
|
12
|
-
- Provide a centralized place where all possible routes are registered
|
|
13
|
-
- Enable micro-applications or micro-services to flawlessly address different parts of the system
|
|
14
|
-
|
|
15
|
-
For **client-side applications**, the [`@owlmeans/client-module`](../client-module) package extends this base module system with client-specific capabilities such as API calls, URL generation, and request validation.
|
|
16
|
-
|
|
17
|
-
## Core Concepts
|
|
18
|
-
|
|
19
|
-
### Module
|
|
20
|
-
A module represents a URL unit that can be transformed into routes or components depending on the environment (frontend/backend). It consists of:
|
|
21
|
-
- A route with URL path and alias
|
|
22
|
-
- Optional guards for authentication/authorization
|
|
23
|
-
- Optional gates for parameter validation
|
|
24
|
-
- Optional filters for request/response validation
|
|
25
|
-
- Optional handlers for processing requests
|
|
26
|
-
|
|
27
|
-
### Parent-Child Relationships
|
|
28
|
-
Modules can be organized in hierarchical structures where child modules inherit properties from their parents, such as guards and gates.
|
|
29
|
-
|
|
30
|
-
### Fullstack Consistency
|
|
31
|
-
A key architectural benefit of the module system is that all validators are defined at the module level using **AJV (Another JSON Schema Validator)** format. Since the system is designed for fullstack development (existing on both frontend and backend), these validation schemas are consistently accessible across all application services and clients. This ensures:
|
|
32
|
-
|
|
33
|
-
- **Unified validation**: Same validation rules apply on both frontend and backend
|
|
34
|
-
- **Consistent data contracts**: API contracts are shared between client and server
|
|
35
|
-
- **Reduced duplication**: No need to define validation schemas separately for frontend and backend
|
|
36
|
-
- **Type safety**: AJV schemas provide runtime validation that complements TypeScript's compile-time checking
|
|
37
|
-
|
|
38
|
-
## API Reference
|
|
39
|
-
|
|
40
|
-
### Types
|
|
41
|
-
|
|
42
|
-
#### CommonModule
|
|
43
|
-
The main module interface that extends `BasicModule` from `@owlmeans/context`.
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
interface CommonModule extends BasicModule {
|
|
47
|
-
route: CommonRouteModel
|
|
48
|
-
sticky: boolean // If true, router attaches this module unconditionally
|
|
49
|
-
filter?: Filter // Request/response validation schemas
|
|
50
|
-
guards?: string[] // Authentication guards
|
|
51
|
-
gate?: string // Authorization gate
|
|
52
|
-
gateParams?: string | string[] // Gate parameters
|
|
53
|
-
handle?: ModuleHandler // Request handler function
|
|
54
|
-
|
|
55
|
-
// Methods
|
|
56
|
-
getAlias(): string
|
|
57
|
-
getPath(): string
|
|
58
|
-
getParentAlias(): string | null
|
|
59
|
-
hasParent(): boolean
|
|
60
|
-
resolve<M extends CommonModule>(): Promise<M>
|
|
61
|
-
getParent<M extends CommonModule>(): M
|
|
62
|
-
setService(service: string): void
|
|
63
|
-
getGuards(): string[]
|
|
64
|
-
getGates(): [string, string[]][]
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
#### ModuleHandler
|
|
69
|
-
Function signature for handling module requests.
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
interface ModuleHandler {
|
|
73
|
-
<T, R extends AbstractRequest<any> = AbstractRequest<any>,
|
|
74
|
-
P extends AbstractResponse<any> = AbstractResponse<any>>
|
|
75
|
-
(req: R, res: P): T | Promise<T>
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
#### Filter
|
|
80
|
-
Schema definitions for request/response validation using **AJV (Another JSON Schema Validator)** format. All validators are defined at the module level, ensuring consistent validation schemas across both frontend and backend environments in fullstack applications.
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
interface Filter {
|
|
84
|
-
query?: AnySchemaObject // Query parameters validation (AJV schema)
|
|
85
|
-
params?: AnySchemaObject // Path parameters validation (AJV schema)
|
|
86
|
-
body?: AnySchemaObject // Request body validation (AJV schema)
|
|
87
|
-
response?: AnySchemaObject // Response validation (AJV schema)
|
|
88
|
-
headers?: AnySchemaObject // Headers validation (AJV schema)
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Since the module system is designed for fullstack development, these AJV validation schemas are accessible and consistent across all application services and clients, providing unified data validation throughout the entire application stack.
|
|
93
|
-
|
|
94
|
-
#### AbstractRequest
|
|
95
|
-
Generic request interface for both frontend and backend.
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
interface AbstractRequest<T extends {} = {}> {
|
|
99
|
-
alias: string
|
|
100
|
-
auth?: Auth
|
|
101
|
-
params: Record<string, string | number | undefined | null> | Partial<T>
|
|
102
|
-
body?: Record<string, any> | Partial<T>
|
|
103
|
-
headers: Record<string, string[] | string | undefined>
|
|
104
|
-
query: Record<string, string | number | undefined | null> | Partial<T>
|
|
105
|
-
path: string
|
|
106
|
-
original?: any
|
|
107
|
-
canceled?: boolean
|
|
108
|
-
cancel?: () => void
|
|
109
|
-
host?: string
|
|
110
|
-
base?: string | boolean
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### AbstractResponse
|
|
115
|
-
Generic response interface for handling module responses.
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
interface AbstractResponse<T> {
|
|
119
|
-
responseProvider?: any
|
|
120
|
-
value?: T
|
|
121
|
-
outcome?: ModuleOutcome
|
|
122
|
-
error?: Error
|
|
123
|
-
resolve(value: T, outcome?: ModuleOutcome): void
|
|
124
|
-
reject(error: Error): void
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### Core Functions
|
|
129
|
-
|
|
130
|
-
#### module(route, opts?)
|
|
131
|
-
Creates a new module instance.
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
function module(route: CommonRouteModel, opts?: CommonModuleOptions): CommonModule
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Parameters:**
|
|
138
|
-
- `route`: CommonRouteModel - The route configuration
|
|
139
|
-
- `opts`: CommonModuleOptions - Optional module configuration
|
|
140
|
-
|
|
141
|
-
**Returns:** CommonModule instance
|
|
142
|
-
|
|
143
|
-
**Example:**
|
|
144
|
-
```typescript
|
|
145
|
-
import { module } from '@owlmeans/module'
|
|
146
|
-
import { route } from '@owlmeans/route'
|
|
147
|
-
|
|
148
|
-
const userModule = module(route('users', '/users'), {
|
|
149
|
-
sticky: true,
|
|
150
|
-
guards: ['authenticated']
|
|
151
|
-
})
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
#### parent(module, aliasOrParent, _parent?)
|
|
155
|
-
Sets parent-child relationships between modules.
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
function parent<T extends CommonModule | CommonModule[]>(
|
|
159
|
-
module: T,
|
|
160
|
-
aliasOrParent: string,
|
|
161
|
-
_parent?: string
|
|
162
|
-
): T
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
**Parameters:**
|
|
166
|
-
- `module`: CommonModule or CommonModule[] - Module(s) to set parent for
|
|
167
|
-
- `aliasOrParent`: string - Parent alias or module alias (when working with arrays)
|
|
168
|
-
- `_parent`: string - Parent name (required when working with arrays)
|
|
169
|
-
|
|
170
|
-
**Returns:** The module(s) with parent relationship set
|
|
171
|
-
|
|
172
|
-
**Example:**
|
|
173
|
-
```typescript
|
|
174
|
-
const userModule = module(route('users', '/users'))
|
|
175
|
-
const userProfileModule = module(route('user-profile', '/profile'))
|
|
176
|
-
|
|
177
|
-
parent(userProfileModule, 'users') // Sets users as parent of user-profile
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Helper Functions
|
|
181
|
-
|
|
182
|
-
#### filter(filter, opts?)
|
|
183
|
-
Creates module options with filter configuration.
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
function filter(filter: Filter, opts?: CommonModuleOptions): CommonModuleOptions
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
**Example:**
|
|
190
|
-
```typescript
|
|
191
|
-
const userModule = module(route('users', '/users'), filter({
|
|
192
|
-
query: { type: 'object', properties: { limit: { type: 'number' } } }
|
|
193
|
-
}))
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
#### guard(guard, opts?)
|
|
197
|
-
Adds authentication guard to module options.
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
function guard(guard: string, opts?: CommonModuleOptions): CommonModuleOptions
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
**Example:**
|
|
204
|
-
```typescript
|
|
205
|
-
const adminModule = module(route('admin', '/admin'), guard('admin'))
|
|
11
|
+
- const myModule = module(route(...))
|
|
12
|
+
+ const myModule = entrypoint(route(...))
|
|
206
13
|
```
|
|
207
14
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
function gate(gate: string, params: string | string[], opts?: CommonModuleOptions): CommonModuleOptions
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
**Example:**
|
|
216
|
-
```typescript
|
|
217
|
-
const userModule = module(route('user', '/user/:id'), gate('user-access', ['id']))
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
#### provideResponse(originalResponse?)
|
|
221
|
-
Creates an abstract response handler.
|
|
222
|
-
|
|
223
|
-
```typescript
|
|
224
|
-
function provideResponse<T>(originalResponse?: unknown): AbstractResponse<T>
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
**Example:**
|
|
228
|
-
```typescript
|
|
229
|
-
const response = provideResponse<UserData>()
|
|
230
|
-
response.resolve(userData, ModuleOutcome.Ok)
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
#### clone(modules, from, to, service)
|
|
234
|
-
Clones an existing module with new alias and service.
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
function clone<M extends CommonModule>(
|
|
238
|
-
modules: M[],
|
|
239
|
-
from: string,
|
|
240
|
-
to: string,
|
|
241
|
-
service: string
|
|
242
|
-
): void
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
**Parameters:**
|
|
246
|
-
- `modules`: M[] - Array of modules to add cloned module to
|
|
247
|
-
- `from`: string - Source module alias
|
|
248
|
-
- `to`: string - New module alias
|
|
249
|
-
- `service`: string - Service name for the cloned module
|
|
250
|
-
|
|
251
|
-
### Filter Building Functions
|
|
252
|
-
|
|
253
|
-
These functions create validation filters using **AJV (Another JSON Schema Validator)** format. All schemas are defined at the module level and remain consistent across both frontend and backend environments, ensuring unified validation throughout your fullstack application.
|
|
254
|
-
|
|
255
|
-
#### body(schema, filter?)
|
|
256
|
-
Creates or extends a filter with body validation schema using AJV format.
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
function body<T>(schema: JSONSchemaType<T>, filter?: Filter): Filter
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### query(schema, filter?)
|
|
263
|
-
Creates or extends a filter with query parameters validation schema using AJV format.
|
|
264
|
-
|
|
265
|
-
```typescript
|
|
266
|
-
function query<T>(schema: JSONSchemaType<T>, filter?: Filter): Filter
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
#### params(schema, filter?)
|
|
270
|
-
Creates or extends a filter with path parameters validation schema using AJV format.
|
|
271
|
-
|
|
272
|
-
```typescript
|
|
273
|
-
function params<T>(schema: JSONSchemaType<T>, filter?: Filter): Filter
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
#### response(schema, code?, filter?)
|
|
277
|
-
Creates or extends a filter with response validation schema using AJV format.
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
function response<T>(schema: JSONSchemaType<T>, code?: number, filter?: Filter): Filter
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
#### headers(schema, filter?)
|
|
284
|
-
Creates or extends a filter with headers validation schema using AJV format.
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
function headers<T>(schema: JSONSchemaType<T>, filter?: Filter): Filter
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
**Example with AJV Schema Format:**
|
|
291
|
-
```typescript
|
|
292
|
-
import { body, query, params, response } from '@owlmeans/module'
|
|
293
|
-
|
|
294
|
-
// AJV schema for request body validation
|
|
295
|
-
const userFilter = body({
|
|
296
|
-
type: 'object',
|
|
297
|
-
properties: {
|
|
298
|
-
name: { type: 'string' },
|
|
299
|
-
email: { type: 'string' }
|
|
300
|
-
},
|
|
301
|
-
required: ['name', 'email']
|
|
302
|
-
}, query({
|
|
303
|
-
type: 'object',
|
|
304
|
-
properties: {
|
|
305
|
-
include: { type: 'string', enum: ['profile', 'preferences'] }
|
|
306
|
-
}
|
|
307
|
-
}))
|
|
308
|
-
|
|
309
|
-
// These AJV schemas are accessible on both frontend and backend
|
|
310
|
-
// providing consistent validation across your fullstack application
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### Utility Functions
|
|
314
|
-
|
|
315
|
-
#### isModule(object)
|
|
316
|
-
Type guard to check if an object is a CommonModule.
|
|
317
|
-
|
|
318
|
-
```typescript
|
|
319
|
-
function isModule(module: Object): module is CommonModule
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
**Example:**
|
|
323
|
-
```typescript
|
|
324
|
-
if (isModule(someObject)) {
|
|
325
|
-
// someObject is definitely a CommonModule
|
|
326
|
-
console.log(someObject.getAlias())
|
|
327
|
-
}
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
### Constants
|
|
331
|
-
|
|
332
|
-
#### ModuleOutcome
|
|
333
|
-
Enumeration of possible module response outcomes.
|
|
334
|
-
|
|
335
|
-
```typescript
|
|
336
|
-
enum ModuleOutcome {
|
|
337
|
-
Ok = 'ok',
|
|
338
|
-
Accepted = 'accepted',
|
|
339
|
-
Created = 'created',
|
|
340
|
-
Finished = 'finished'
|
|
341
|
-
}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
### Service Interfaces
|
|
345
|
-
|
|
346
|
-
#### GuardService
|
|
347
|
-
Service interface for implementing authentication guards.
|
|
348
|
-
|
|
349
|
-
```typescript
|
|
350
|
-
interface GuardService extends InitializedService {
|
|
351
|
-
token?: string
|
|
352
|
-
authenticated(req?: Partial<AbstractRequest>): Promise<string | null>
|
|
353
|
-
match: ModuleMatch
|
|
354
|
-
handle: ModuleHandler
|
|
355
|
-
}
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
#### GateService
|
|
359
|
-
Service interface for implementing authorization gates.
|
|
360
|
-
|
|
361
|
-
```typescript
|
|
362
|
-
interface GateService extends LazyService {
|
|
363
|
-
assert: ModuleAssert // Throws Error if assertion fails
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
## Usage Examples
|
|
368
|
-
|
|
369
|
-
### Basic Module Creation
|
|
370
|
-
|
|
371
|
-
```typescript
|
|
372
|
-
import { module, guard, filter, body } from '@owlmeans/module'
|
|
373
|
-
import { route } from '@owlmeans/route'
|
|
374
|
-
|
|
375
|
-
// Create a simple module
|
|
376
|
-
const homeModule = module(route('home', '/'))
|
|
377
|
-
|
|
378
|
-
// Create a protected module with authentication
|
|
379
|
-
const dashboardModule = module(
|
|
380
|
-
route('dashboard', '/dashboard'),
|
|
381
|
-
guard('authenticated')
|
|
382
|
-
)
|
|
383
|
-
|
|
384
|
-
// Create a module with request validation
|
|
385
|
-
const createUserModule = module(
|
|
386
|
-
route('create-user', '/users', { method: 'POST' }),
|
|
387
|
-
filter(body({
|
|
388
|
-
type: 'object',
|
|
389
|
-
properties: {
|
|
390
|
-
name: { type: 'string' },
|
|
391
|
-
email: { type: 'string' }
|
|
392
|
-
},
|
|
393
|
-
required: ['name', 'email']
|
|
394
|
-
}))
|
|
395
|
-
)
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
### Module Hierarchies
|
|
399
|
-
|
|
400
|
-
```typescript
|
|
401
|
-
// Create parent module
|
|
402
|
-
const apiModule = module(route('api', '/api'))
|
|
403
|
-
|
|
404
|
-
// Create child modules
|
|
405
|
-
const usersModule = module(route('users', '/users'))
|
|
406
|
-
const postsModule = module(route('posts', '/posts'))
|
|
407
|
-
|
|
408
|
-
// Set parent relationships
|
|
409
|
-
parent(usersModule, 'api')
|
|
410
|
-
parent(postsModule, 'api')
|
|
411
|
-
|
|
412
|
-
// Child modules inherit parent guards and gates
|
|
413
|
-
const userProfileModule = module(
|
|
414
|
-
route('user-profile', '/profile'),
|
|
415
|
-
guard('user-access')
|
|
416
|
-
)
|
|
417
|
-
parent(userProfileModule, 'users')
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
### Module with Handler
|
|
421
|
-
|
|
422
|
-
```typescript
|
|
423
|
-
const userModule = module(route('get-user', '/users/:id'), {
|
|
424
|
-
handle: async (req, res) => {
|
|
425
|
-
const userId = req.params.id
|
|
426
|
-
const user = await getUserById(userId)
|
|
427
|
-
res.resolve(user, ModuleOutcome.Ok)
|
|
428
|
-
}
|
|
429
|
-
})
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
### Complex Filter Example
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
import { filter, body, query, params, response } from '@owlmeans/module'
|
|
436
|
-
|
|
437
|
-
const complexModule = module(
|
|
438
|
-
route('complex-api', '/api/users/:id'),
|
|
439
|
-
filter(
|
|
440
|
-
params({
|
|
441
|
-
type: 'object',
|
|
442
|
-
properties: {
|
|
443
|
-
id: { type: 'string', pattern: '^[0-9]+$' }
|
|
444
|
-
},
|
|
445
|
-
required: ['id']
|
|
446
|
-
},
|
|
447
|
-
query({
|
|
448
|
-
type: 'object',
|
|
449
|
-
properties: {
|
|
450
|
-
include: { type: 'string', enum: ['profile', 'posts'] },
|
|
451
|
-
limit: { type: 'number', minimum: 1, maximum: 100 }
|
|
452
|
-
}
|
|
453
|
-
},
|
|
454
|
-
response({
|
|
455
|
-
type: 'object',
|
|
456
|
-
properties: {
|
|
457
|
-
user: { type: 'object' },
|
|
458
|
-
profile: { type: 'object' }
|
|
459
|
-
},
|
|
460
|
-
required: ['user']
|
|
461
|
-
})))
|
|
462
|
-
)
|
|
463
|
-
)
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
## Integration Patterns
|
|
467
|
-
|
|
468
|
-
### Backend Integration
|
|
469
|
-
On the backend, modules are typically transformed into Express-like routes:
|
|
470
|
-
|
|
471
|
-
```typescript
|
|
472
|
-
// Transform module to route with handler
|
|
473
|
-
app.get(userModule.getPath(), async (req, res) => {
|
|
474
|
-
const moduleReq = adaptRequest(req)
|
|
475
|
-
const moduleRes = provideResponse()
|
|
476
|
-
|
|
477
|
-
await userModule.handle(moduleReq, moduleRes)
|
|
478
|
-
|
|
479
|
-
if (moduleRes.error) {
|
|
480
|
-
res.status(500).json({ error: moduleRes.error.message })
|
|
481
|
-
} else {
|
|
482
|
-
res.json(moduleRes.value)
|
|
483
|
-
}
|
|
484
|
-
})
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
### Frontend Integration
|
|
488
|
-
On the frontend, modules help generate URLs and determine which components to render:
|
|
489
|
-
|
|
490
|
-
```typescript
|
|
491
|
-
// Generate URL for navigation
|
|
492
|
-
const userUrl = userModule.getPath() // '/users/:id'
|
|
493
|
-
const finalUrl = userUrl.replace(':id', userId)
|
|
494
|
-
|
|
495
|
-
// Navigate to the route
|
|
496
|
-
router.push(finalUrl)
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
## Best Practices
|
|
500
|
-
|
|
501
|
-
1. **Organize modules hierarchically** to take advantage of guard and gate inheritance
|
|
502
|
-
2. **Use meaningful aliases** for modules to make them easy to reference
|
|
503
|
-
3. **Apply filters consistently** to ensure proper validation
|
|
504
|
-
4. **Leverage guards and gates** for security at the module level
|
|
505
|
-
5. **Keep modules focused** on a single responsibility
|
|
506
|
-
6. **Use the clone function** to create variations of existing modules for different services
|
|
507
|
-
|
|
508
|
-
## Dependencies
|
|
509
|
-
|
|
510
|
-
This package depends on:
|
|
511
|
-
- `@owlmeans/route` - For route management
|
|
512
|
-
- `@owlmeans/context` - For contextual module support
|
|
513
|
-
- `@owlmeans/auth` - For authentication integration
|
|
514
|
-
- `ajv` - For JSON schema validation using AJV format, providing consistent validation across fullstack applications
|
|
515
|
-
|
|
516
|
-
## Related Packages
|
|
15
|
+
Type renames:
|
|
16
|
+
- `CommonModule` → `CommonEntrypoint`
|
|
17
|
+
- `ModuleHandler` → `EntrypointHandler`
|
|
18
|
+
- `ModuleOutcome` → `EntrypointOutcome`
|
|
517
19
|
|
|
518
|
-
|
|
519
|
-
- [`@owlmeans/server-module`](../server-module) - Server-side module implementation
|
|
520
|
-
- [`@owlmeans/route`](../route) - Core routing functionality
|
|
521
|
-
- [`@owlmeans/context`](../context) - Context management system
|
|
20
|
+
See [`@owlmeans/entrypoint`](../entrypoint) for full documentation.
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
export * from '@owlmeans/entrypoint';
|
|
2
|
+
/** @deprecated use `entrypoint()` from @owlmeans/entrypoint */
|
|
3
|
+
export { entrypoint as module } from '@owlmeans/entrypoint';
|
|
4
|
+
/** @deprecated use CommonEntrypoint */
|
|
5
|
+
export type { CommonEntrypoint as CommonModule } from '@owlmeans/entrypoint';
|
|
6
|
+
/** @deprecated use CommonEntrypointOptions */
|
|
7
|
+
export type { CommonEntrypointOptions as CommonModuleOptions } from '@owlmeans/entrypoint';
|
|
8
|
+
/** @deprecated use EntrypointMatch */
|
|
9
|
+
export type { EntrypointMatch as ModuleMatch } from '@owlmeans/entrypoint';
|
|
10
|
+
/** @deprecated use EntrypointHandler */
|
|
11
|
+
export type { EntrypointHandler as ModuleHandler } from '@owlmeans/entrypoint';
|
|
12
|
+
/** @deprecated use EntrypointAssert */
|
|
13
|
+
export type { EntrypointAssert as ModuleAssert } from '@owlmeans/entrypoint';
|
|
14
|
+
/** @deprecated use EntrypointOutcome */
|
|
15
|
+
export { EntrypointOutcome as ModuleOutcome } from '@owlmeans/entrypoint';
|
|
6
16
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAA;AAEpC,+DAA+D;AAC/D,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE3D,uCAAuC;AACvC,YAAY,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC5E,8CAA8C;AAC9C,YAAY,EAAE,uBAAuB,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1F,sCAAsC;AACtC,YAAY,EAAE,eAAe,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC1E,wCAAwC;AACxC,YAAY,EAAE,iBAAiB,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAC9E,uCAAuC;AACvC,YAAY,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC5E,wCAAwC;AACxC,OAAO,EAAE,iBAAiB,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
export * from '@owlmeans/entrypoint';
|
|
2
|
+
/** @deprecated use `entrypoint()` from @owlmeans/entrypoint */
|
|
3
|
+
export { entrypoint as module } from '@owlmeans/entrypoint';
|
|
4
|
+
/** @deprecated use EntrypointOutcome */
|
|
5
|
+
export { EntrypointOutcome as ModuleOutcome } from '@owlmeans/entrypoint';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAA;AAEpC,+DAA+D;AAC/D,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAY3D,wCAAwC;AACxC,OAAO,EAAE,iBAAiB,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAA"}
|
package/build/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
|
|
1
|
+
export * from '@owlmeans/entrypoint/utils';
|
|
2
|
+
/** @deprecated use isEntrypoint */
|
|
3
|
+
export { isEntrypoint as isModule } from '@owlmeans/entrypoint/utils';
|
|
4
|
+
/** @deprecated use CreateEntrypointSignature */
|
|
5
|
+
export type { CreateEntrypointSignature as CreateModuleSignature } from '@owlmeans/entrypoint/utils';
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAA;AAE1C,mCAAmC;AACnC,OAAO,EAAE,YAAY,IAAI,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrE,gDAAgD;AAChD,YAAY,EAAE,yBAAyB,IAAI,qBAAqB,EAAE,MAAM,4BAA4B,CAAA"}
|
package/build/utils/index.js
CHANGED
package/build/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,4BAA4B,CAAA;AAE1C,mCAAmC;AACnC,OAAO,EAAE,YAAY,IAAI,QAAQ,EAAE,MAAM,4BAA4B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/module",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -28,15 +28,13 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@owlmeans/
|
|
32
|
-
"@owlmeans/context": "^0.1.2",
|
|
33
|
-
"@owlmeans/route": "^0.1.2",
|
|
34
|
-
"ajv": "^8.17.1"
|
|
31
|
+
"@owlmeans/entrypoint": "^0.1.4"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
34
|
+
"@owlmeans/dep-config": "workspace:*",
|
|
37
35
|
"nodemon": "^3.1.11",
|
|
38
36
|
"npm-check": "^6.0.1",
|
|
39
|
-
"typescript": "^
|
|
37
|
+
"typescript": "^6.0.2"
|
|
40
38
|
},
|
|
41
39
|
"publishConfig": {
|
|
42
40
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
2
|
+
export * from '@owlmeans/entrypoint'
|
|
3
|
+
|
|
4
|
+
/** @deprecated use `entrypoint()` from @owlmeans/entrypoint */
|
|
5
|
+
export { entrypoint as module } from '@owlmeans/entrypoint'
|
|
6
|
+
|
|
7
|
+
/** @deprecated use CommonEntrypoint */
|
|
8
|
+
export type { CommonEntrypoint as CommonModule } from '@owlmeans/entrypoint'
|
|
9
|
+
/** @deprecated use CommonEntrypointOptions */
|
|
10
|
+
export type { CommonEntrypointOptions as CommonModuleOptions } from '@owlmeans/entrypoint'
|
|
11
|
+
/** @deprecated use EntrypointMatch */
|
|
12
|
+
export type { EntrypointMatch as ModuleMatch } from '@owlmeans/entrypoint'
|
|
13
|
+
/** @deprecated use EntrypointHandler */
|
|
14
|
+
export type { EntrypointHandler as ModuleHandler } from '@owlmeans/entrypoint'
|
|
15
|
+
/** @deprecated use EntrypointAssert */
|
|
16
|
+
export type { EntrypointAssert as ModuleAssert } from '@owlmeans/entrypoint'
|
|
17
|
+
/** @deprecated use EntrypointOutcome */
|
|
18
|
+
export { EntrypointOutcome as ModuleOutcome } from '@owlmeans/entrypoint'
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
export * from '
|
|
3
|
-
|
|
2
|
+
export * from '@owlmeans/entrypoint/utils'
|
|
3
|
+
|
|
4
|
+
/** @deprecated use isEntrypoint */
|
|
5
|
+
export { isEntrypoint as isModule } from '@owlmeans/entrypoint/utils'
|
|
6
|
+
/** @deprecated use CreateEntrypointSignature */
|
|
7
|
+
export type { CreateEntrypointSignature as CreateModuleSignature } from '@owlmeans/entrypoint/utils'
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": [
|
|
3
|
-
"
|
|
3
|
+
"@owlmeans/dep-config/tsconfig.base.json"
|
|
4
4
|
],
|
|
5
5
|
"compilerOptions": {
|
|
6
|
-
"rootDir": "./src/",
|
|
7
|
-
"outDir": "./build/"
|
|
8
|
-
"moduleResolution": "Bundler"
|
|
6
|
+
"rootDir": "./src/",
|
|
7
|
+
"outDir": "./build/"
|
|
9
8
|
},
|
|
10
|
-
"exclude": [
|
|
11
|
-
|
|
12
|
-
"./build/**/*",
|
|
13
|
-
"./*.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
9
|
+
"exclude": ["./dist/**/*", "./build/**/*", "./*.ts"]
|
|
10
|
+
}
|
package/src/consts.ts
DELETED
package/src/filter.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { JSONSchemaType } from 'ajv'
|
|
2
|
-
import type { Filter } from './types.js'
|
|
3
|
-
|
|
4
|
-
export const body = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
5
|
-
return { ...filter, body: schema as any }
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const query = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
9
|
-
return { ...filter, query: schema as any }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const params = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
13
|
-
return { ...filter, params: schema as any }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const response = <T>(schema: JSONSchemaType<T>, code?: number, filter?: Filter): Filter => {
|
|
17
|
-
let _schema: any = schema
|
|
18
|
-
if (filter?.response != null && code != null) {
|
|
19
|
-
_schema = { ...filter.response, [code]: schema }
|
|
20
|
-
}
|
|
21
|
-
return { ...filter, response: _schema }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const headers = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
25
|
-
return { ...filter, headers: schema as any }
|
|
26
|
-
}
|
package/src/helper.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { route } from '@owlmeans/route'
|
|
2
|
-
import { Filter, CommonModuleOptions, AbstractResponse, CommonModule } from './types.js'
|
|
3
|
-
import { module } from './module.js'
|
|
4
|
-
|
|
5
|
-
export const filter = (filter: Filter, opts?: CommonModuleOptions): CommonModuleOptions => ({ filter, ...opts })
|
|
6
|
-
|
|
7
|
-
export const guard = (guard: string, opts?: CommonModuleOptions): CommonModuleOptions =>
|
|
8
|
-
({ ...opts, guards: [...new Set([guard, ...(opts?.guards ?? [])])] })
|
|
9
|
-
|
|
10
|
-
export const gate = (gate: string, params: string | string[], opts?: CommonModuleOptions): CommonModuleOptions =>
|
|
11
|
-
({ ...opts, gate, gateParams: params })
|
|
12
|
-
|
|
13
|
-
export const provideResponse = <T>(originalResponse?: unknown): AbstractResponse<T> => {
|
|
14
|
-
const hanlder: AbstractResponse<T> = {
|
|
15
|
-
responseProvider: originalResponse,
|
|
16
|
-
|
|
17
|
-
resolve: (value, outcome) => {
|
|
18
|
-
hanlder.value = value
|
|
19
|
-
hanlder.outcome = outcome
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
reject: (error) => {
|
|
23
|
-
hanlder.error = error
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return hanlder
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const clone = <M extends CommonModule>(modules: M[], from: string, to: string, service: string) => {
|
|
31
|
-
const source = modules.find(m => m.alias === from)
|
|
32
|
-
|
|
33
|
-
if (source?.route.route != null) {
|
|
34
|
-
const _route = { ...source.route.route, service, resolved: false, alias: to }
|
|
35
|
-
modules.push(module(route(to, _route.path, _route)) as M)
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/module.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { CommonModule } from './types.js'
|
|
2
|
-
import { appendContextual } from '@owlmeans/context'
|
|
3
|
-
import type { CreateModuleSignature } from './utils/types.js'
|
|
4
|
-
|
|
5
|
-
export const module: CreateModuleSignature<CommonModule> = (route, opts) => {
|
|
6
|
-
let guards: string[] | null = null
|
|
7
|
-
let gates: [string, string[]][] | null = null
|
|
8
|
-
const module: CommonModule = appendContextual<CommonModule>(route.route.alias, {
|
|
9
|
-
_module: true,
|
|
10
|
-
|
|
11
|
-
sticky: false,
|
|
12
|
-
|
|
13
|
-
route,
|
|
14
|
-
|
|
15
|
-
getAlias: () => module.route.route.alias,
|
|
16
|
-
getPath: () => module.route.route.path,
|
|
17
|
-
getParentAlias: () => module.route.route.parent ?? null,
|
|
18
|
-
hasParent: () => module.getParentAlias() != null,
|
|
19
|
-
|
|
20
|
-
resolve: async <M extends CommonModule>() => {
|
|
21
|
-
if (module.ctx == null) {
|
|
22
|
-
throw new SyntaxError(`Module has no context yet - ${module.getAlias()}`)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
await module.route.resolve(module.ctx)
|
|
26
|
-
|
|
27
|
-
return module as M
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
getParent: () => {
|
|
31
|
-
const parent = module.getParentAlias()
|
|
32
|
-
if (parent == null) {
|
|
33
|
-
throw new SyntaxError(`Module has no parent - ${module.getAlias()}`)
|
|
34
|
-
}
|
|
35
|
-
if (module.ctx == null) {
|
|
36
|
-
throw new SyntaxError(`Module has no context yet - ${module.getAlias()}`)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return module.ctx.module(parent)
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
setService: service => {
|
|
43
|
-
if (module.route.route.resolved) {
|
|
44
|
-
throw new SyntaxError(`Cannot update a resolved module - ${module.getAlias()}`)
|
|
45
|
-
}
|
|
46
|
-
module.route.route.service = service
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
getGuards: () => {
|
|
50
|
-
if (guards != null) {
|
|
51
|
-
return guards
|
|
52
|
-
}
|
|
53
|
-
guards = module.guards ?? []
|
|
54
|
-
|
|
55
|
-
if (module.hasParent()) {
|
|
56
|
-
guards.push(
|
|
57
|
-
...module.getParent().getGuards().filter(guard => !guards?.includes(guard))
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return guards
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
getGates: () => {
|
|
65
|
-
if (gates != null) {
|
|
66
|
-
return gates
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
gates = module.gate != null ? [[
|
|
70
|
-
module.gate, module.gateParams == null
|
|
71
|
-
? [] : Array.isArray(module.gateParams)
|
|
72
|
-
? module.gateParams : [module.gateParams]
|
|
73
|
-
]] : []
|
|
74
|
-
|
|
75
|
-
if (module.hasParent()) {
|
|
76
|
-
gates.push(
|
|
77
|
-
...module.getParent().getGates()
|
|
78
|
-
.filter(([gate]) => !gates?.some(([g]) => g === gate))
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return gates
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
...opts
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
return module
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export const parent = <T extends CommonModule | CommonModule[]>(module: T, aliasOrParent: string, _parent?: string): T => {
|
|
92
|
-
if (Array.isArray(module)) {
|
|
93
|
-
if (_parent == null) {
|
|
94
|
-
throw SyntaxError('Elevating parent requires parent name to be specified')
|
|
95
|
-
}
|
|
96
|
-
module = module.find(module => module.route.route.alias === aliasOrParent) as T
|
|
97
|
-
if (module == null) {
|
|
98
|
-
throw SyntaxError(`Module not found ${aliasOrParent}`)
|
|
99
|
-
}
|
|
100
|
-
return parent(module, _parent)
|
|
101
|
-
}
|
|
102
|
-
module.route.route.parent = aliasOrParent
|
|
103
|
-
|
|
104
|
-
return module
|
|
105
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { CommonRouteModel } from '@owlmeans/route'
|
|
2
|
-
import type { InitializedService, LazyService, BasicModule } from '@owlmeans/context'
|
|
3
|
-
import type { AnySchemaObject } from 'ajv'
|
|
4
|
-
import type { ModuleOutcome } from './consts.js'
|
|
5
|
-
import type { Auth } from '@owlmeans/auth'
|
|
6
|
-
|
|
7
|
-
export interface CommonModule extends BasicModule {
|
|
8
|
-
route: CommonRouteModel
|
|
9
|
-
/**
|
|
10
|
-
* @property {boolean} - if true — router attaches this module unconditionaly
|
|
11
|
-
* @default false
|
|
12
|
-
*/
|
|
13
|
-
sticky: boolean
|
|
14
|
-
filter?: Filter
|
|
15
|
-
guards?: string[]
|
|
16
|
-
gate?: string
|
|
17
|
-
gateParams?: string | string[]
|
|
18
|
-
handle?: ModuleHandler
|
|
19
|
-
getAlias: () => string
|
|
20
|
-
getPath: () => string
|
|
21
|
-
getParentAlias: () => string | null
|
|
22
|
-
hasParent: () => boolean
|
|
23
|
-
resolve: <M extends CommonModule>() => Promise<M>
|
|
24
|
-
getParent: <M extends CommonModule>() => M
|
|
25
|
-
setService: (service: string) => void
|
|
26
|
-
getGuards: () => string[]
|
|
27
|
-
getGates: () => [string, string[]][]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface CommonModuleOptions extends Partial<CommonModule> { }
|
|
31
|
-
|
|
32
|
-
export interface ModuleMatch {
|
|
33
|
-
<R extends AbstractRequest, P extends AbstractResponse<any>>(req: R, res: P): Promise<boolean>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ModuleHandler {
|
|
37
|
-
<
|
|
38
|
-
T, R extends AbstractRequest<any> = AbstractRequest<any>,
|
|
39
|
-
P extends AbstractResponse<any> = AbstractResponse<any>,
|
|
40
|
-
>(req: R, res: P): T | Promise<T>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ModuleAssert {
|
|
44
|
-
<R extends AbstractRequest, P extends AbstractResponse<any>>(req: R, res: P, params: string[]): Promise<void>
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface AbstractRequest<T extends {} = {}> {
|
|
48
|
-
alias: string
|
|
49
|
-
auth?: Auth
|
|
50
|
-
params: Record<string, string | number | undefined | null> | Partial<T>
|
|
51
|
-
body?: Record<string, any> | Partial<T>
|
|
52
|
-
headers: Record<string, string[] | string | undefined>
|
|
53
|
-
query: Record<string, string | number | undefined | null> | Partial<T>
|
|
54
|
-
path: string
|
|
55
|
-
original?: any
|
|
56
|
-
canceled?: boolean
|
|
57
|
-
cancel?: () => void
|
|
58
|
-
host?: string
|
|
59
|
-
base?: string | boolean
|
|
60
|
-
unsecure?: boolean
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface AbstractResponse<T> {
|
|
64
|
-
responseProvider?: any
|
|
65
|
-
value?: T,
|
|
66
|
-
outcome?: ModuleOutcome
|
|
67
|
-
error?: Error
|
|
68
|
-
resolve: (value: T, outcome?: ModuleOutcome) => void
|
|
69
|
-
reject: (error: Error) => void
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface GuardService extends InitializedService {
|
|
73
|
-
// Client guard
|
|
74
|
-
token?: string
|
|
75
|
-
authenticated: (req?: Partial<AbstractRequest>) => Promise<string | null>
|
|
76
|
-
// Server guard
|
|
77
|
-
match: ModuleMatch
|
|
78
|
-
handle: ModuleHandler
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface GateService extends LazyService {
|
|
82
|
-
/**
|
|
83
|
-
* @throws {Error}
|
|
84
|
-
*/
|
|
85
|
-
assert: ModuleAssert
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface Filter {
|
|
89
|
-
query?: AnySchemaObject
|
|
90
|
-
params?: AnySchemaObject
|
|
91
|
-
body?: AnySchemaObject
|
|
92
|
-
response?: AnySchemaObject
|
|
93
|
-
headers?: AnySchemaObject
|
|
94
|
-
}
|
package/src/utils/module.ts
DELETED