@nattyjs/core 0.0.1-beta.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/README.md +11 -0
- package/dist/index.cjs +1273 -0
- package/dist/index.d.ts +468 -0
- package/dist/index.mjs +1233 -0
- package/package.json +25 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { NattyConfig, UserIdentity } from '@nattyjs/common';
|
|
2
|
+
import { GlobalConfig } from '@nattyjs/common/interfaces/global-config';
|
|
3
|
+
|
|
4
|
+
interface DecoratorInfo$1 {
|
|
5
|
+
method: string;
|
|
6
|
+
route: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface TypeInfo$1 {
|
|
10
|
+
name: string;
|
|
11
|
+
documentation: string;
|
|
12
|
+
type: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ParameterInfo {
|
|
16
|
+
parameters: TypeInfo$1[];
|
|
17
|
+
returnType: string;
|
|
18
|
+
documentation: string;
|
|
19
|
+
}
|
|
20
|
+
interface MethodInfo$1 extends TypeInfo$1 {
|
|
21
|
+
info?: ParameterInfo[];
|
|
22
|
+
route?: DecoratorInfo$1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ClassTypeInfo extends TypeInfo$1 {
|
|
26
|
+
filePath?: string;
|
|
27
|
+
constructors?: TypeInfo$1[];
|
|
28
|
+
methods?: MethodInfo$1[];
|
|
29
|
+
properties?: TypeInfo$1[];
|
|
30
|
+
route?: DecoratorInfo$1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface BuildOptions {
|
|
34
|
+
mode: string;
|
|
35
|
+
rootDir: string;
|
|
36
|
+
port: number;
|
|
37
|
+
commandName: string;
|
|
38
|
+
buildVersion: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare function defineNattyConfig(config: NattyConfig | ((buildOptions?: BuildOptions) => NattyConfig | Promise<NattyConfig>)): NattyConfig | ((buildOptions?: BuildOptions) => NattyConfig | Promise<NattyConfig>);
|
|
42
|
+
|
|
43
|
+
declare enum RunOn {
|
|
44
|
+
AzureFunction = 0,
|
|
45
|
+
ExpressJs = 1,
|
|
46
|
+
Koa = 2,
|
|
47
|
+
FastifyJs = 3,
|
|
48
|
+
GoogleFunction = 4,
|
|
49
|
+
Lambda = 5
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare function route(path: string): (target: any, propertyKey?: string, parameterIndex?: any) => any;
|
|
53
|
+
|
|
54
|
+
declare function get(path: string): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
55
|
+
|
|
56
|
+
declare function post(path: string): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
57
|
+
|
|
58
|
+
declare function put(path: string): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
59
|
+
|
|
60
|
+
declare function Delete(): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
61
|
+
|
|
62
|
+
interface DecoratorInfo {
|
|
63
|
+
httpMethod: string;
|
|
64
|
+
route: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface TypeInfo {
|
|
68
|
+
name: string;
|
|
69
|
+
documentation?: string;
|
|
70
|
+
type?: string;
|
|
71
|
+
}
|
|
72
|
+
interface MethodInfo extends TypeInfo {
|
|
73
|
+
parameters?: TypeInfo[];
|
|
74
|
+
returnType?: string;
|
|
75
|
+
route?: DecoratorInfo;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type HttpRequestBodyInfo = {
|
|
79
|
+
Uint8Array?: Uint8Array | Uint8Array[];
|
|
80
|
+
string?: string | string[];
|
|
81
|
+
number?: number | number[];
|
|
82
|
+
boolean?: boolean | boolean[];
|
|
83
|
+
FormData?: FormData;
|
|
84
|
+
ArrayBuffer?: ArrayBuffer;
|
|
85
|
+
Blob?: Blob;
|
|
86
|
+
json?: {
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
} | Array<{
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
interface Cookie {
|
|
94
|
+
name: string;
|
|
95
|
+
value: string;
|
|
96
|
+
domain?: string;
|
|
97
|
+
path?: string;
|
|
98
|
+
expires?: Date | number;
|
|
99
|
+
secure?: boolean;
|
|
100
|
+
httpOnly?: boolean;
|
|
101
|
+
sameSite?: 'Strict' | 'Lax' | 'None' | undefined;
|
|
102
|
+
maxAge?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface HttpRequestInit {
|
|
106
|
+
method?: string;
|
|
107
|
+
url?: string;
|
|
108
|
+
pathName?: string;
|
|
109
|
+
host?: string;
|
|
110
|
+
body?: HttpRequestBodyInfo;
|
|
111
|
+
cookies?: Cookie[];
|
|
112
|
+
headers?: Headers;
|
|
113
|
+
query?: Record<string, string>;
|
|
114
|
+
params?: Record<string, string>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface HttpResponseInit {
|
|
118
|
+
body?: any;
|
|
119
|
+
status?: number;
|
|
120
|
+
headers?: HeadersInit;
|
|
121
|
+
cookies?: Cookie[];
|
|
122
|
+
enableContentNegotiation?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface ProblemDetail {
|
|
126
|
+
type: string;
|
|
127
|
+
title: string;
|
|
128
|
+
detail?: string | number | boolean | {
|
|
129
|
+
[key: string]: any;
|
|
130
|
+
} | Array<{
|
|
131
|
+
[key: string]: any;
|
|
132
|
+
}>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
type ExceptionTypeInfo = string | number | boolean | {
|
|
136
|
+
[key: string]: any;
|
|
137
|
+
} | Array<{
|
|
138
|
+
[key: string]: any;
|
|
139
|
+
}> | ProblemDetail;
|
|
140
|
+
|
|
141
|
+
type TypesInfo = {
|
|
142
|
+
[key: string]: {
|
|
143
|
+
path?: string | any | Function;
|
|
144
|
+
props?: Array<TypeInfo>;
|
|
145
|
+
values?: Array<any>;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
interface DecoratorParams {
|
|
150
|
+
target: Function;
|
|
151
|
+
propertyKey?: string;
|
|
152
|
+
descriptor?: PropertyDescriptor;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface ModelConfig {
|
|
156
|
+
tableName?: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
interface DbFieldConfig {
|
|
160
|
+
name?: string;
|
|
161
|
+
type?: number;
|
|
162
|
+
defaultValue?: any;
|
|
163
|
+
isPrimaryKey?: boolean;
|
|
164
|
+
foreignKey?: any;
|
|
165
|
+
oneToMany?: FieldRelationConfig;
|
|
166
|
+
oneToOne?: FieldRelationConfig;
|
|
167
|
+
}
|
|
168
|
+
interface FieldRelationConfig {
|
|
169
|
+
model: any;
|
|
170
|
+
foreignKey: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface PropConfig {
|
|
174
|
+
db?: DbFieldConfig;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
interface PropertyDecoratorConfig {
|
|
178
|
+
decoratorParams: DecoratorParams;
|
|
179
|
+
validatorConfig?: any;
|
|
180
|
+
propConfig?: PropConfig;
|
|
181
|
+
modelConfig?: ModelConfig;
|
|
182
|
+
sanitizerConfig?: {
|
|
183
|
+
name: string;
|
|
184
|
+
config: any;
|
|
185
|
+
sanitizer: Function;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface IHttpResult {
|
|
190
|
+
getResponse(): HttpResponseInit;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface RouteConfig {
|
|
194
|
+
controller: Function;
|
|
195
|
+
parameters: Array<{
|
|
196
|
+
name: string;
|
|
197
|
+
type: string;
|
|
198
|
+
}>;
|
|
199
|
+
get: {
|
|
200
|
+
[key: string]: {
|
|
201
|
+
name: string;
|
|
202
|
+
parameters: Array<{
|
|
203
|
+
name: string;
|
|
204
|
+
type: string;
|
|
205
|
+
}>;
|
|
206
|
+
returnType: string;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
post: {
|
|
210
|
+
[key: string]: {
|
|
211
|
+
name: string;
|
|
212
|
+
parameters: Array<{
|
|
213
|
+
name: string;
|
|
214
|
+
type: string;
|
|
215
|
+
}>;
|
|
216
|
+
returnType: string;
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
put: {
|
|
220
|
+
[key: string]: {
|
|
221
|
+
name: string;
|
|
222
|
+
parameters: Array<{
|
|
223
|
+
name: string;
|
|
224
|
+
type: string;
|
|
225
|
+
}>;
|
|
226
|
+
returnType: string;
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
delete: {
|
|
230
|
+
[key: string]: {
|
|
231
|
+
name: string;
|
|
232
|
+
parameters: Array<{
|
|
233
|
+
name: string;
|
|
234
|
+
type: string;
|
|
235
|
+
}>;
|
|
236
|
+
returnType: string;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare function init(config: NattyConfig, appConfig: {
|
|
242
|
+
routes: {
|
|
243
|
+
[key: string]: RouteConfig;
|
|
244
|
+
};
|
|
245
|
+
envTsDefinition: {
|
|
246
|
+
[key: string]: string;
|
|
247
|
+
};
|
|
248
|
+
types?: TypesInfo;
|
|
249
|
+
}): {
|
|
250
|
+
[key: string]: RouteConfig;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
declare class HttpRequest {
|
|
254
|
+
private httpRequest;
|
|
255
|
+
constructor(http: HttpRequestInit);
|
|
256
|
+
get cookies(): Cookie[];
|
|
257
|
+
get url(): string;
|
|
258
|
+
get method(): string;
|
|
259
|
+
get headers(): Headers;
|
|
260
|
+
get user(): any;
|
|
261
|
+
get body(): HttpRequestBodyInfo;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
declare class HttpResponse {
|
|
265
|
+
private _cookies;
|
|
266
|
+
private _headers;
|
|
267
|
+
private _body;
|
|
268
|
+
private _status;
|
|
269
|
+
constructor(response?: HttpResponseInit);
|
|
270
|
+
private setValues;
|
|
271
|
+
addCookie(cookie: Cookie): void;
|
|
272
|
+
get cookies(): Cookie[];
|
|
273
|
+
get status(): number;
|
|
274
|
+
set status(value: number);
|
|
275
|
+
get headers(): Headers;
|
|
276
|
+
get body(): HttpRequestBodyInfo;
|
|
277
|
+
set body(value: any);
|
|
278
|
+
write(responseInit: HttpResponseInit): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
declare class HttpContext {
|
|
282
|
+
constructor(request: HttpRequestInit, context: any);
|
|
283
|
+
request: HttpRequest;
|
|
284
|
+
response: HttpResponse;
|
|
285
|
+
context: any;
|
|
286
|
+
config: NattyConfig;
|
|
287
|
+
routes: {
|
|
288
|
+
[key: string]: RouteConfig;
|
|
289
|
+
};
|
|
290
|
+
user: UserIdentity<any>;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
declare class HttpHandler {
|
|
294
|
+
constructor();
|
|
295
|
+
processRequest(httpContext: HttpContext): Promise<HttpResponse>;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interface HttpModule {
|
|
299
|
+
init: (config: NattyConfig) => void;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
declare function injectable<T = unknown>(): Function;
|
|
303
|
+
declare function injectable<T = unknown>(options: any): Function;
|
|
304
|
+
|
|
305
|
+
declare function $request(request: HttpRequestInit): Promise<HttpResponse>;
|
|
306
|
+
|
|
307
|
+
interface ConfigureAt {
|
|
308
|
+
authentication?: boolean;
|
|
309
|
+
authorization?: boolean;
|
|
310
|
+
onException?: boolean;
|
|
311
|
+
filterExecutionIndex?: number;
|
|
312
|
+
}
|
|
313
|
+
interface FilterConfig {
|
|
314
|
+
configureAtGlobal?: ConfigureAt;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
declare function filter(config?: FilterConfig): ClassDecorator;
|
|
318
|
+
|
|
319
|
+
declare function registerDecorator(config: PropertyDecoratorConfig): void;
|
|
320
|
+
|
|
321
|
+
declare abstract class AbstractModelState {
|
|
322
|
+
private _errors;
|
|
323
|
+
get isValid(): boolean;
|
|
324
|
+
get errors(): {
|
|
325
|
+
[key: string]: any;
|
|
326
|
+
};
|
|
327
|
+
private runValidators;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
declare abstract class BaseResponse {
|
|
331
|
+
protected httpContext: HttpContext;
|
|
332
|
+
badRequest(): void;
|
|
333
|
+
success(body: any): HttpResponse;
|
|
334
|
+
notFound(): void;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
declare abstract class ParameterTypeConverter extends BaseResponse {
|
|
338
|
+
sanitizer: {
|
|
339
|
+
number: (value: any) => any;
|
|
340
|
+
boolean: (value: any) => any;
|
|
341
|
+
string: (value: any) => any;
|
|
342
|
+
date: (value: any) => any;
|
|
343
|
+
};
|
|
344
|
+
get types(): TypesInfo;
|
|
345
|
+
getObjectTypeInfo(typeName: string): {
|
|
346
|
+
path?: any;
|
|
347
|
+
props?: TypeInfo[];
|
|
348
|
+
values?: any[];
|
|
349
|
+
};
|
|
350
|
+
isArrayType(typeName: string): boolean;
|
|
351
|
+
getTypeName(typeName: string): string;
|
|
352
|
+
castObject(requestBody: any, properties: TypeInfo[]): {
|
|
353
|
+
body: any;
|
|
354
|
+
invalidProps: any;
|
|
355
|
+
};
|
|
356
|
+
private setValue;
|
|
357
|
+
convert(methodInfo: MethodInfo, jObject: {
|
|
358
|
+
[key: string]: any;
|
|
359
|
+
} | Array<{
|
|
360
|
+
[key: string]: any;
|
|
361
|
+
}>): {
|
|
362
|
+
[key: string]: any;
|
|
363
|
+
} | {
|
|
364
|
+
[key: string]: any;
|
|
365
|
+
}[];
|
|
366
|
+
convertToInstance(entityName: string, data: any): any;
|
|
367
|
+
private getClassTarget;
|
|
368
|
+
mapToInstanceProperties(requestBody: any, instance: any, properties: TypeInfo[]): void;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
declare class ModelBindingContext extends ParameterTypeConverter {
|
|
372
|
+
private type;
|
|
373
|
+
private typeInfo;
|
|
374
|
+
private data;
|
|
375
|
+
root: any;
|
|
376
|
+
parent: any;
|
|
377
|
+
instance: any;
|
|
378
|
+
constructor(type: string, typeInfo: TypeInfo[], data: any);
|
|
379
|
+
private serialize;
|
|
380
|
+
get isValid(): boolean;
|
|
381
|
+
get errors(): {};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
type ValidatorInfo = {
|
|
385
|
+
[key: string]: any;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
declare const entityContainer: {
|
|
389
|
+
register(config: PropertyDecoratorConfig): any;
|
|
390
|
+
getPropertyValidators(entityName: string, propName: string): ValidatorInfo;
|
|
391
|
+
getTarget(entityName: any): Function;
|
|
392
|
+
getPrimaryKeys(entityName: any): Array<string>;
|
|
393
|
+
getModelConfig(entityName: any): ModelConfig;
|
|
394
|
+
getProperties(entityName: string): TypeInfo[];
|
|
395
|
+
getPropsDbConfig(entityName: any): Map<string, DbFieldConfig>;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
declare abstract class BaseController {
|
|
399
|
+
httpContext: HttpContext;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
declare abstract class BaseResult {
|
|
403
|
+
private response;
|
|
404
|
+
constructor(response: HttpResponseInit, responseHeaders?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
405
|
+
getResponse(): HttpResponseInit;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
declare class OkResult extends BaseResult {
|
|
409
|
+
value: any;
|
|
410
|
+
constructor(value: any, response?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
411
|
+
}
|
|
412
|
+
declare function ok(value?: any, response?: Pick<HttpResponseInit, "headers" | "cookies">): OkResult;
|
|
413
|
+
|
|
414
|
+
declare class NotFoundResult extends BaseResult implements IHttpResult {
|
|
415
|
+
constructor(response?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
416
|
+
}
|
|
417
|
+
declare function notFound(response?: Pick<HttpResponseInit, "headers" | "cookies">): NotFoundResult;
|
|
418
|
+
|
|
419
|
+
declare class NoContentResult extends BaseResult implements IHttpResult {
|
|
420
|
+
constructor(response?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
421
|
+
}
|
|
422
|
+
declare function noContent(response?: Pick<HttpResponseInit, "headers" | "cookies">): NoContentResult;
|
|
423
|
+
|
|
424
|
+
declare class ForbiddenAccessInfoResult extends BaseResult implements IHttpResult {
|
|
425
|
+
constructor(value?: ExceptionTypeInfo, response?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
426
|
+
}
|
|
427
|
+
declare function forbiddenAccessInfo(value?: ExceptionTypeInfo, response?: Pick<HttpResponseInit, "headers" | "cookies">): ForbiddenAccessInfoResult;
|
|
428
|
+
|
|
429
|
+
declare class CreatedResult extends BaseResult implements IHttpResult {
|
|
430
|
+
constructor(response?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
431
|
+
}
|
|
432
|
+
declare function created(response?: Pick<HttpResponseInit, "headers" | "cookies">): CreatedResult;
|
|
433
|
+
|
|
434
|
+
declare class BadRequestResult extends BaseResult implements IHttpResult {
|
|
435
|
+
value: ExceptionTypeInfo;
|
|
436
|
+
constructor(value: ExceptionTypeInfo, response?: Pick<HttpResponseInit, "headers" | "cookies">);
|
|
437
|
+
}
|
|
438
|
+
declare function badRequest(value?: ExceptionTypeInfo, response?: Pick<HttpResponseInit, "headers" | "cookies">): BadRequestResult;
|
|
439
|
+
|
|
440
|
+
declare class HttpException {
|
|
441
|
+
private httpResponse;
|
|
442
|
+
constructor(response: HttpResponseInit);
|
|
443
|
+
getResponse(): HttpResponse;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
declare class ForbiddenAccessException extends HttpException {
|
|
447
|
+
constructor(data?: ExceptionTypeInfo);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
declare class HttpBadRequestException extends HttpException {
|
|
451
|
+
constructor(data?: ExceptionTypeInfo);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
declare class HttpNotFoundException extends HttpException {
|
|
455
|
+
constructor(data?: ExceptionTypeInfo);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
declare class UnauthorizedAccessException extends HttpException {
|
|
459
|
+
constructor(data?: ExceptionTypeInfo);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
declare function useFilter(config: GlobalConfig): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
463
|
+
|
|
464
|
+
declare function anonymous(): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
465
|
+
|
|
466
|
+
declare function authenticationOnly(): (target: any, propertyKey?: string, descriptor?: any) => void;
|
|
467
|
+
|
|
468
|
+
export { $request, AbstractModelState, BadRequestResult, BaseController, BuildOptions, ClassTypeInfo, CreatedResult, Delete, ForbiddenAccessException, ForbiddenAccessInfoResult, HttpBadRequestException, HttpContext, HttpException, HttpHandler, HttpModule, HttpNotFoundException, HttpResponse, MethodInfo$1 as MethodInfo, ModelBindingContext, NoContentResult, NotFoundResult, OkResult, ParameterInfo, RunOn, TypeInfo$1 as TypeInfo, UnauthorizedAccessException, anonymous, authenticationOnly, badRequest, created, defineNattyConfig, entityContainer, filter, forbiddenAccessInfo, get, init, injectable, noContent, notFound, ok, post, put, registerDecorator, route, useFilter };
|