inanis 0.0.7-beta.4 → 0.0.7-beta.6
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/api/index.d.ts +6 -5
- package/dist/api/index.js +10 -21
- package/dist/api/router.d.ts +0 -4
- package/dist/api/router.js +0 -11
- package/dist/main.d.ts +3 -1
- package/dist/main.js +2 -2
- package/dist/modules/data-model.d.ts +1 -0
- package/dist/modules/data-model.js +2 -0
- package/dist/utils/validate.d.ts +4 -4
- package/package.json +1 -1
package/dist/api/index.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export declare class APIManager extends Event<Channels> {
|
|
|
32
32
|
routers: Router[];
|
|
33
33
|
constructor(params: Params);
|
|
34
34
|
_injectInanis(inanis: Inanis): void;
|
|
35
|
-
loadAll(routers?: Router<any, any, string, Record<string, any>, Record<string, any>>[]): Promise<void>;
|
|
36
35
|
createRoute<Path extends string, Fails extends FailData, BeforeData, Headers extends string>(params: RouterParams<Path, Fails, Record<any, any>, BeforeData, Headers>): Router<Path, Fails, Headers, Record<any, any>, BeforeData>;
|
|
37
36
|
eachMethods(cb: (_route: Router, _method: keyof Methods) => void): void;
|
|
38
37
|
getRouter(path: string): Router<any, any, string, Record<string, any>, Record<string, any>>;
|
|
@@ -43,13 +42,15 @@ export declare class APIManager extends Event<Channels> {
|
|
|
43
42
|
json: string;
|
|
44
43
|
yaml: string;
|
|
45
44
|
}>>;
|
|
46
|
-
expressHandlers: () =>
|
|
45
|
+
expressHandlers: () => {
|
|
47
46
|
path: string;
|
|
48
47
|
method: string;
|
|
49
48
|
handler: (..._args: any[]) => void;
|
|
50
|
-
}[]
|
|
51
|
-
lambdaHandler: () =>
|
|
52
|
-
serverlessFunctionsConfig: (
|
|
49
|
+
}[];
|
|
50
|
+
lambdaHandler: () => Record<string, APIGatewayProxyHandler>;
|
|
51
|
+
serverlessFunctionsConfig: (params?: {
|
|
52
|
+
handler: (group: any) => any;
|
|
53
|
+
}) => Promise<{
|
|
53
54
|
json: string;
|
|
54
55
|
yaml: string;
|
|
55
56
|
}>;
|
package/dist/api/index.js
CHANGED
|
@@ -54,19 +54,6 @@ class APIManager extends power_helper_1.Event {
|
|
|
54
54
|
inanis
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
async loadAll(routers = this.routers) {
|
|
58
|
-
let loadedFlag = false;
|
|
59
|
-
while (!loadedFlag) {
|
|
60
|
-
loadedFlag = true;
|
|
61
|
-
for (let router of routers) {
|
|
62
|
-
if (!router.loaded) {
|
|
63
|
-
await router.load();
|
|
64
|
-
await this.loadAll(router.children);
|
|
65
|
-
loadedFlag = false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
57
|
createRoute(params) {
|
|
71
58
|
const route = new router_js_1.Router(this, params);
|
|
72
59
|
this.routers.push(route);
|
|
@@ -122,7 +109,6 @@ class APIManager extends power_helper_1.Event {
|
|
|
122
109
|
get outputs() {
|
|
123
110
|
return {
|
|
124
111
|
toTypes: async () => {
|
|
125
|
-
await this.loadAll();
|
|
126
112
|
const outputs = [];
|
|
127
113
|
const openApi = await this.outputs.openApiDocument({ servers: [] });
|
|
128
114
|
for (let doc in openApi) {
|
|
@@ -131,15 +117,13 @@ class APIManager extends power_helper_1.Event {
|
|
|
131
117
|
return outputs.join('\n\n');
|
|
132
118
|
},
|
|
133
119
|
openApiDocument: async (params) => {
|
|
134
|
-
await this.loadAll();
|
|
135
120
|
const outputs = {};
|
|
136
121
|
for (let router of this.routers) {
|
|
137
122
|
outputs[router.name] = await (0, export_open_api_js_1.exportOpenApi)(router, params);
|
|
138
123
|
}
|
|
139
124
|
return outputs;
|
|
140
125
|
},
|
|
141
|
-
expressHandlers:
|
|
142
|
-
await this.loadAll();
|
|
126
|
+
expressHandlers: () => {
|
|
143
127
|
const output = [];
|
|
144
128
|
this.eachMethods((route, method) => {
|
|
145
129
|
let path = route.path.replace('{', ':').replace('}', '');
|
|
@@ -153,8 +137,8 @@ class APIManager extends power_helper_1.Event {
|
|
|
153
137
|
});
|
|
154
138
|
return output;
|
|
155
139
|
},
|
|
156
|
-
|
|
157
|
-
|
|
140
|
+
// 不支援非同步
|
|
141
|
+
lambdaHandler: () => {
|
|
158
142
|
const outputs = {};
|
|
159
143
|
this.eachMethods((router, method) => {
|
|
160
144
|
const group = getLambdaGroup(this, method, router.path);
|
|
@@ -176,8 +160,7 @@ class APIManager extends power_helper_1.Event {
|
|
|
176
160
|
});
|
|
177
161
|
return outputs;
|
|
178
162
|
},
|
|
179
|
-
serverlessFunctionsConfig: async () => {
|
|
180
|
-
await this.loadAll();
|
|
163
|
+
serverlessFunctionsConfig: async (params) => {
|
|
181
164
|
const outputs = {};
|
|
182
165
|
this.eachMethods((router, method) => {
|
|
183
166
|
let group = getLambdaGroup(this, method, router.path);
|
|
@@ -190,6 +173,12 @@ class APIManager extends power_helper_1.Event {
|
|
|
190
173
|
memorySize: group.memorySize,
|
|
191
174
|
events: []
|
|
192
175
|
};
|
|
176
|
+
if (params.handler) {
|
|
177
|
+
let newGroup = params.handler(outputs[group.name]);
|
|
178
|
+
if (newGroup) {
|
|
179
|
+
outputs[group.name] = newGroup;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
193
182
|
}
|
|
194
183
|
const m = router.methods[method];
|
|
195
184
|
const output = outputs[group.name];
|
package/dist/api/router.d.ts
CHANGED
|
@@ -24,8 +24,6 @@ export type RouterParams<Path extends string, Fails extends FailData, ParentData
|
|
|
24
24
|
};
|
|
25
25
|
export declare class Router<Path extends string = any, Fails extends FailData = any, Headers extends string = string, ParentData = Record<string, any>, BeforeData = Record<string, any>> {
|
|
26
26
|
tags: string[];
|
|
27
|
-
loaded: boolean;
|
|
28
|
-
loadCallback: (() => Promise<void>) | null;
|
|
29
27
|
path: Path;
|
|
30
28
|
manager: APIManager;
|
|
31
29
|
before: (_data: any, _context: any) => Promise<BeforeData>;
|
|
@@ -41,8 +39,6 @@ export declare class Router<Path extends string = any, Fails extends FailData =
|
|
|
41
39
|
get schema(): typeof definedValidateSchema;
|
|
42
40
|
get nowAuthorizerExpression(): AuthorizerExpression | null;
|
|
43
41
|
child<ChildPath extends `${Path}/${string}`, ChildBeforeData, ChildFails extends FailData, ChildHeaders extends string>(params: RouterParams<ChildPath, ChildFails, BeforeData, ChildBeforeData, ChildHeaders>): Router<ChildPath, ChildFails, ChildHeaders, BeforeData, ChildBeforeData>;
|
|
44
|
-
onLoad(cb: (() => Promise<void>)): void;
|
|
45
|
-
load(): Promise<void>;
|
|
46
42
|
export(): Record<string, Router<any, any, string, Record<string, any>, Record<string, any>>>;
|
|
47
43
|
deepEachChildren(callback: (_route: Router) => void | '_break'): any;
|
|
48
44
|
getParents(): Router<any, any, string, Record<string, any>, Record<string, any>>[];
|
package/dist/api/router.js
CHANGED
|
@@ -7,8 +7,6 @@ const validate_js_1 = require("../utils/validate.js");
|
|
|
7
7
|
const string_js_1 = require("../utils/string.js");
|
|
8
8
|
class Router {
|
|
9
9
|
tags;
|
|
10
|
-
loaded = false;
|
|
11
|
-
loadCallback = null;
|
|
12
10
|
path;
|
|
13
11
|
manager;
|
|
14
12
|
before;
|
|
@@ -56,15 +54,6 @@ class Router {
|
|
|
56
54
|
router.parent = this;
|
|
57
55
|
return router;
|
|
58
56
|
}
|
|
59
|
-
onLoad(cb) {
|
|
60
|
-
this.loadCallback = cb;
|
|
61
|
-
}
|
|
62
|
-
async load() {
|
|
63
|
-
this.loaded = true;
|
|
64
|
-
if (this.loadCallback) {
|
|
65
|
-
await this.loadCallback();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
57
|
export() {
|
|
69
58
|
const output = {};
|
|
70
59
|
const parse = (route) => {
|
package/dist/main.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export declare class Inanis {
|
|
|
21
21
|
private getProcessManagers;
|
|
22
22
|
eachManagements(cb: (_manager: Manager) => Promise<any>): Promise<void>;
|
|
23
23
|
toLambdaHandlers(): {};
|
|
24
|
-
toServerlessFunctions: (
|
|
24
|
+
toServerlessFunctions: (params?: {
|
|
25
|
+
handler: (group: any) => any;
|
|
26
|
+
}) => Promise<string>;
|
|
25
27
|
}
|
|
26
28
|
export {};
|
package/dist/main.js
CHANGED
|
@@ -55,11 +55,11 @@ class Inanis {
|
|
|
55
55
|
});
|
|
56
56
|
return outputs;
|
|
57
57
|
}
|
|
58
|
-
toServerlessFunctions = async () => {
|
|
58
|
+
toServerlessFunctions = async (params) => {
|
|
59
59
|
const output = [];
|
|
60
60
|
await this.eachManagements(async (manager) => {
|
|
61
61
|
if ('outputs' in manager && 'serverlessFunctionsConfig' in manager.outputs) {
|
|
62
|
-
let { yaml } = await manager.outputs.serverlessFunctionsConfig();
|
|
62
|
+
let { yaml } = await manager.outputs.serverlessFunctionsConfig(params);
|
|
63
63
|
output.push(yaml);
|
|
64
64
|
}
|
|
65
65
|
});
|
|
@@ -3,6 +3,7 @@ export declare class DataModelConfig<T extends TableManager<any, any, any, any,
|
|
|
3
3
|
table: T;
|
|
4
4
|
defData: DefData;
|
|
5
5
|
publicKeys: PublicKey[];
|
|
6
|
+
publicKeyMaps: Record<PublicKey, true>;
|
|
6
7
|
_initData: Omit<T['_putType'], keyof ReturnType<DefData>> & Partial<T['_putType']>;
|
|
7
8
|
constructor(params: {
|
|
8
9
|
table: T;
|
|
@@ -6,11 +6,13 @@ class DataModelConfig {
|
|
|
6
6
|
table;
|
|
7
7
|
defData;
|
|
8
8
|
publicKeys;
|
|
9
|
+
publicKeyMaps = {};
|
|
9
10
|
_initData = null;
|
|
10
11
|
constructor(params) {
|
|
11
12
|
this.table = params.table;
|
|
12
13
|
this.defData = params.defData;
|
|
13
14
|
this.publicKeys = params.publicKeys;
|
|
15
|
+
this.publicKeyMaps = Object.fromEntries(this.publicKeys.map(k => [k, true]));
|
|
14
16
|
}
|
|
15
17
|
newData(data) {
|
|
16
18
|
return {
|
package/dist/utils/validate.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { DeepRequired } from '../types.js';
|
|
3
|
-
import type {
|
|
4
|
-
export type ValidateCallback<T extends Record<string,
|
|
3
|
+
import type { ZodType } from 'zod';
|
|
4
|
+
export type ValidateCallback<T extends Record<string, ZodType>> = (_z: typeof z) => {
|
|
5
5
|
[K in keyof T]: T[K];
|
|
6
6
|
};
|
|
7
7
|
export type ValidateCallbackOutputs<T extends ValidateCallback<any>, R = ReturnType<T>> = {
|
|
8
|
-
[K in keyof R]: R[K] extends
|
|
8
|
+
[K in keyof R]: R[K] extends ZodType ? DeepRequired<z.infer<R[K]>> : unknown;
|
|
9
9
|
};
|
|
10
10
|
export declare function definedValidateSchema<T extends ValidateCallback<any>>(cb: T): T;
|
|
11
|
-
export declare function validate<T extends ValidateCallback<any>, R = ReturnType<T>>(target: any, schemaCallback: T): { [K in keyof R]: R[K] extends
|
|
11
|
+
export declare function validate<T extends ValidateCallback<any>, R = ReturnType<T>>(target: any, schemaCallback: T): { [K in keyof R]: R[K] extends ZodType ? DeepRequired<z.infer<R[K]>> : unknown; };
|