inanis 0.0.7-beta.4 → 0.0.7-beta.5

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.
@@ -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,12 +42,12 @@ export declare class APIManager extends Event<Channels> {
43
42
  json: string;
44
43
  yaml: string;
45
44
  }>>;
46
- expressHandlers: () => Promise<{
45
+ expressHandlers: () => {
47
46
  path: string;
48
47
  method: string;
49
48
  handler: (..._args: any[]) => void;
50
- }[]>;
51
- lambdaHandler: () => Promise<Record<string, APIGatewayProxyHandler>>;
49
+ }[];
50
+ lambdaHandler: () => Record<string, APIGatewayProxyHandler>;
52
51
  serverlessFunctionsConfig: () => Promise<{
53
52
  json: string;
54
53
  yaml: string;
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: async () => {
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
- lambdaHandler: async () => {
157
- await this.loadAll();
140
+ // 不支援非同步
141
+ lambdaHandler: () => {
158
142
  const outputs = {};
159
143
  this.eachMethods((router, method) => {
160
144
  const group = getLambdaGroup(this, method, router.path);
@@ -177,7 +161,6 @@ class APIManager extends power_helper_1.Event {
177
161
  return outputs;
178
162
  },
179
163
  serverlessFunctionsConfig: async () => {
180
- await this.loadAll();
181
164
  const outputs = {};
182
165
  this.eachMethods((router, method) => {
183
166
  let group = getLambdaGroup(this, method, router.path);
@@ -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>>[];
@@ -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) => {
@@ -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 {
@@ -1,11 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { DeepRequired } from '../types.js';
3
- import type { ZodAny } from 'zod';
4
- export type ValidateCallback<T extends Record<string, ZodAny>> = (_z: typeof z) => {
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 ZodAny ? DeepRequired<z.infer<R[K]>> : unknown;
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 ZodAny ? DeepRequired<z.infer<R[K]>> : unknown; };
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; };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inanis",
3
- "version": "0.0.7-beta.4",
3
+ "version": "0.0.7-beta.5",
4
4
  "description": "Micro Service Best Tools.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {