@nattyjs/common 0.0.1-beta.37 → 0.0.1-beta.39
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/index.cjs +45 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.mjs +45 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -284,6 +284,9 @@ class AuthorizationFilter {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
class ActionFilter {
|
|
287
|
+
onModelBinding(context) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
287
290
|
onActionExecuting(context) {
|
|
288
291
|
return;
|
|
289
292
|
}
|
|
@@ -682,6 +685,47 @@ class AbstractConsoleLogger {
|
|
|
682
685
|
class ConsoleLogger extends AbstractConsoleLogger {
|
|
683
686
|
}
|
|
684
687
|
|
|
688
|
+
function typed() {
|
|
689
|
+
return function(OriginalClass) {
|
|
690
|
+
return class extends OriginalClass {
|
|
691
|
+
constructor(...args) {
|
|
692
|
+
super(...args);
|
|
693
|
+
const typeInfo = commonContainer.types[OriginalClass.name];
|
|
694
|
+
defineProps(this, typeInfo?.props, OriginalClass.name);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
const types = ["string", "number", "boolean"];
|
|
700
|
+
function defineProps(instance, props, modelName) {
|
|
701
|
+
if (props && Array.isArray(props)) {
|
|
702
|
+
for (const prop of props) {
|
|
703
|
+
if (prop.type && types.indexOf(prop.type) > -1) {
|
|
704
|
+
overrideProp(instance, prop, modelName);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function overrideProp(instance, prop, modelName) {
|
|
710
|
+
let descriptor = Object.getOwnPropertyDescriptor(
|
|
711
|
+
Object.getPrototypeOf(instance),
|
|
712
|
+
prop.name
|
|
713
|
+
);
|
|
714
|
+
let value = instance[prop.name];
|
|
715
|
+
Object.defineProperty(instance, prop.name, {
|
|
716
|
+
get: () => {
|
|
717
|
+
return descriptor ? descriptor.get.call(instance) : value;
|
|
718
|
+
},
|
|
719
|
+
set: (v) => {
|
|
720
|
+
const type = typeof v;
|
|
721
|
+
if (prop.type == type)
|
|
722
|
+
value = v;
|
|
723
|
+
else
|
|
724
|
+
throw new Error(`Incorrect value type of ${modelName} class property '${prop.name}' `);
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
685
729
|
exports.ALLOW_METHODS = ALLOW_METHODS;
|
|
686
730
|
exports.AbstractRunner = AbstractRunner;
|
|
687
731
|
exports.ActionFilter = ActionFilter;
|
|
@@ -724,3 +768,4 @@ exports.readEnv = readEnv;
|
|
|
724
768
|
exports.readEnvKey = readEnvKey;
|
|
725
769
|
exports.registerType = registerType;
|
|
726
770
|
exports.typeContainer = typeContainer;
|
|
771
|
+
exports.typed = typed;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestRouteInfo, IHttpResult, IModelBindingContext, ProblemDetail, IExceptionContext, HttpResponseInit, NattyTestModule, ModelBinding, BuildOptions, TypesInfo, ClassTypeInfo } from '@nattyjs/types';
|
|
1
|
+
import { RequestRouteInfo, IHttpResult, Cookie, IModelBindingContext, ProblemDetail, IExceptionContext, HttpResponseInit, NattyTestModule, ModelBinding, BuildOptions, TypesInfo, ClassTypeInfo } from '@nattyjs/types';
|
|
2
2
|
import { ChildProcess } from 'child_process';
|
|
3
3
|
|
|
4
4
|
interface ClassType<T> extends Function {
|
|
@@ -22,6 +22,11 @@ interface IExecutionContext {
|
|
|
22
22
|
|
|
23
23
|
interface IActionExecutedContext extends IExecutionContext {
|
|
24
24
|
content: any;
|
|
25
|
+
get response(): {
|
|
26
|
+
cookies: Array<Cookie>;
|
|
27
|
+
headers: Headers;
|
|
28
|
+
status: number;
|
|
29
|
+
};
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
interface IActionExecutingContext extends IExecutionContext {
|
|
@@ -29,6 +34,7 @@ interface IActionExecutingContext extends IExecutionContext {
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
declare abstract class ActionFilter {
|
|
37
|
+
onModelBinding(context: IActionExecutingContext): Promise<void>;
|
|
32
38
|
onActionExecuting(context: IActionExecutingContext): Promise<void>;
|
|
33
39
|
onActionExecuted(context: IActionExecutedContext): Promise<void>;
|
|
34
40
|
}
|
|
@@ -291,4 +297,8 @@ declare abstract class AbstractConsoleLogger {
|
|
|
291
297
|
declare class ConsoleLogger extends AbstractConsoleLogger {
|
|
292
298
|
}
|
|
293
299
|
|
|
294
|
-
|
|
300
|
+
declare function typed(): <T extends {
|
|
301
|
+
new (...args: any[]): {};
|
|
302
|
+
}>(OriginalClass: T) => T;
|
|
303
|
+
|
|
304
|
+
export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, Claim, ClassType, ConsoleLogger, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, GlobalConfig, HTTP_METHOD_ROUTES, IActionExecutedContext, IActionExecutingContext, IAuthorizationContext, IExecutionContext, IGNORE_METHODS, List, MetaConfigProps, Middleware, NattyAppConfig, NattyCliConfig, NattyConfig, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer, typed };
|
package/dist/index.mjs
CHANGED
|
@@ -267,6 +267,9 @@ class AuthorizationFilter {
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
class ActionFilter {
|
|
270
|
+
onModelBinding(context) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
270
273
|
onActionExecuting(context) {
|
|
271
274
|
return;
|
|
272
275
|
}
|
|
@@ -665,4 +668,45 @@ class AbstractConsoleLogger {
|
|
|
665
668
|
class ConsoleLogger extends AbstractConsoleLogger {
|
|
666
669
|
}
|
|
667
670
|
|
|
668
|
-
|
|
671
|
+
function typed() {
|
|
672
|
+
return function(OriginalClass) {
|
|
673
|
+
return class extends OriginalClass {
|
|
674
|
+
constructor(...args) {
|
|
675
|
+
super(...args);
|
|
676
|
+
const typeInfo = commonContainer.types[OriginalClass.name];
|
|
677
|
+
defineProps(this, typeInfo?.props, OriginalClass.name);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
const types = ["string", "number", "boolean"];
|
|
683
|
+
function defineProps(instance, props, modelName) {
|
|
684
|
+
if (props && Array.isArray(props)) {
|
|
685
|
+
for (const prop of props) {
|
|
686
|
+
if (prop.type && types.indexOf(prop.type) > -1) {
|
|
687
|
+
overrideProp(instance, prop, modelName);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function overrideProp(instance, prop, modelName) {
|
|
693
|
+
let descriptor = Object.getOwnPropertyDescriptor(
|
|
694
|
+
Object.getPrototypeOf(instance),
|
|
695
|
+
prop.name
|
|
696
|
+
);
|
|
697
|
+
let value = instance[prop.name];
|
|
698
|
+
Object.defineProperty(instance, prop.name, {
|
|
699
|
+
get: () => {
|
|
700
|
+
return descriptor ? descriptor.get.call(instance) : value;
|
|
701
|
+
},
|
|
702
|
+
set: (v) => {
|
|
703
|
+
const type = typeof v;
|
|
704
|
+
if (prop.type == type)
|
|
705
|
+
value = v;
|
|
706
|
+
else
|
|
707
|
+
throw new Error(`Incorrect value type of ${modelName} class property '${prop.name}' `);
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
export { ALLOW_METHODS, AbstractRunner, ActionFilter, AuthenticationFilter, AuthorizationFilter, BACK_SLASH_REGEX, BLANK, CONTROLLER, ConsoleLogger, DEFAULT_ACTIONS, DEFAULT_CHILD_PATH, DELETE, ENVIRONMENTS, ExceptionFilter, FrameworkType, GET, HTTP_METHOD_ROUTES, IGNORE_METHODS, List, MetaConfigProps, Middleware, POST, PUT, RIGHT_SLASH, ROUTE_INSTANCES, ROUTE_METHODS, ROUTE_PATHS, TS_EXTENSION, UserIdentity, commonContainer, createPath, createTestServer, getPath, getPort, isConstructor, isEqual, isFunction, isObject, readEnv, readEnvKey, registerType, typeContainer, typed };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nattyjs/common",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.39",
|
|
4
4
|
"description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "ajayojha <ojhaajay@outlook.com>",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "20.3.1",
|
|
24
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
24
|
+
"@nattyjs/types": "0.0.1-beta.39",
|
|
25
25
|
"unbuild": "1.2.1"
|
|
26
26
|
}
|
|
27
27
|
}
|