@_tc/template-core 0.0.1-bate.31 → 0.0.1-bate.32

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.
Files changed (46) hide show
  1. package/package.json +10 -5
  2. package/types/app/controller/base.d.ts +12 -0
  3. package/types/app/controller/project.d.ts +10 -0
  4. package/types/app/controller/view.d.ts +7 -0
  5. package/types/app/data/signKey.d.ts +1 -0
  6. package/types/app/extend/db.d.ts +2 -0
  7. package/types/app/extend/generateErrorMessage.d.ts +7 -0
  8. package/types/app/extend/logger.d.ts +11 -0
  9. package/types/app/extend/parsingParamsOnUrl.d.ts +2 -0
  10. package/types/app/extend/render-view.d.ts +3 -0
  11. package/types/app/middleware/api-params-verify.d.ts +4 -0
  12. package/types/app/middleware/api-sign-verify.d.ts +4 -0
  13. package/types/app/middleware/error-handle.d.ts +4 -0
  14. package/types/app/middleware/project-handler.d.ts +4 -0
  15. package/types/app/middleware.d.ts +3 -0
  16. package/types/app/router/project.d.ts +4 -0
  17. package/types/app/router/view.d.ts +4 -0
  18. package/types/app/router-schema/project.d.ts +3 -0
  19. package/types/app/service/bese.d.ts +10 -0
  20. package/types/app/service/project.d.ts +27 -0
  21. package/types/app/type.d.ts +2 -0
  22. package/types/app/typings.d.ts +50 -0
  23. package/types/bundler/dev.d.ts +1 -0
  24. package/types/bundler/index.d.ts +1 -0
  25. package/types/bundler/prod.d.ts +1 -0
  26. package/types/bundler/utils.d.ts +4 -0
  27. package/types/index.d.ts +28 -0
  28. package/types/packages/core/env.d.ts +15 -0
  29. package/types/packages/core/index.d.ts +6 -0
  30. package/types/packages/core/loader/config.d.ts +3 -0
  31. package/types/packages/core/loader/controller.d.ts +3 -0
  32. package/types/packages/core/loader/extend.d.ts +3 -0
  33. package/types/packages/core/loader/middleware.d.ts +3 -0
  34. package/types/packages/core/loader/model.d.ts +14 -0
  35. package/types/packages/core/loader/router-schema.d.ts +3 -0
  36. package/types/packages/core/loader/router.d.ts +3 -0
  37. package/types/packages/core/loader/service.d.ts +3 -0
  38. package/types/packages/core/paths.d.ts +11 -0
  39. package/types/packages/core/types.d.ts +73 -0
  40. package/types/packages/utils/getAllFilesInFolder.d.ts +4 -0
  41. package/types/packages/utils/getAllFnReturnValue.d.ts +0 -0
  42. package/types/packages/utils/index.d.ts +4 -0
  43. package/types/packages/utils/loadFile.d.ts +14 -0
  44. package/types/packages/utils/path.d.ts +6 -0
  45. package/types/packages/utils/runFileFn.d.ts +5 -0
  46. package/types/typings/type.d.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_tc/template-core",
3
- "version": "0.0.1-bate.31",
3
+ "version": "0.0.1-bate.32",
4
4
  "description": "A TypeScript Koa framework template - Monorepo root",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -8,19 +8,24 @@
8
8
  ".": {
9
9
  "import": "./esm/index.js",
10
10
  "require": "./cjs/index.js",
11
- "types": "./esm/index.d.js"
11
+ "types": "./types/index.d.js"
12
12
  },
13
13
  "./bundler": {
14
14
  "import": "./esm/bundler/index.js",
15
15
  "require": "./cjs/bundler/index.js",
16
- "types": "./esm/bundler/index.d.js"
16
+ "types": "./types/bundler/index.d.js"
17
17
  },
18
- "./c/r": {
18
+ "./fe/main": {
19
+ "import": "./fe/frontend/main.js",
20
+ "require": "./fe/frontend/main.js",
21
+ "types": "./fe/frontend/main.d.js"
22
+ },
23
+ "./fe/rc": {
19
24
  "import": "./fe/packages/ui/react/index.js",
20
25
  "require": "./fe/packages/ui/react/index.js",
21
26
  "types": "./fe/packages/ui/react/index.d.js"
22
27
  },
23
- "./c/r/*": {
28
+ "./fe/rc/*": {
24
29
  "import": "./fe/packages/ui/react/*",
25
30
  "require": "./fe/packages/ui/react/*",
26
31
  "types": "./fe/packages/ui/react/*"
@@ -0,0 +1,12 @@
1
+ import type { KoaApp, Ctx } from "../type";
2
+ declare const _default: (app: KoaApp) => {
3
+ new (): {
4
+ readonly app: KoaApp;
5
+ readonly config: KoaApp["config"];
6
+ get service(): import("../../packages/core").FrameworkAugment.IServiceAugmented;
7
+ success(ctx: Ctx, data: unknown): void;
8
+ fail(ctx: Ctx, code: number, message: string): void;
9
+ sendData(ctx: Ctx, data?: unknown, code?: number, message?: string | null, status?: number): void;
10
+ };
11
+ };
12
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { KoaApp, Ctx } from "../type";
2
+ export interface IProjectController {
3
+ getModelList(ctx: Ctx): Promise<void>;
4
+ getProjectList(ctx: Ctx): Promise<void>;
5
+ getProject(ctx: Ctx): Promise<void>;
6
+ success(ctx: Ctx, data: unknown): void;
7
+ fail(ctx: Ctx, code: number, message: string): void;
8
+ }
9
+ declare const getProjectController: (app: KoaApp) => new () => IProjectController;
10
+ export default getProjectController;
@@ -0,0 +1,7 @@
1
+ import type { KoaApp, Ctx } from "../type";
2
+ declare const getViewController: (app: KoaApp) => {
3
+ new (): {
4
+ renderPage(ctx: Ctx): Promise<void>;
5
+ };
6
+ };
7
+ export default getViewController;
@@ -0,0 +1 @@
1
+ export declare const signKey = "sakjdfnkjwjfnfkjkjldljksndf";
@@ -0,0 +1,2 @@
1
+ import type { KoaApp } from "../type";
2
+ export default function getDB(app: KoaApp): Promise<{}>;
@@ -0,0 +1,7 @@
1
+ interface ErrorOption {
2
+ status?: number;
3
+ code?: string | number;
4
+ showError?: boolean;
5
+ }
6
+ declare const _default: () => (message: string, option?: ErrorOption) => never;
7
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import type { KoaApp } from "../type";
2
+ interface MConsole {
3
+ log: (...args: any[]) => void;
4
+ info: (...args: any[]) => void;
5
+ warn: (...args: any[]) => void;
6
+ error: (...args: any[]) => void;
7
+ debug: (...args: any[]) => void;
8
+ trace: (...args: any[]) => void;
9
+ }
10
+ declare const _default: (app: KoaApp) => Promise<MConsole>;
11
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => (urlRules: string, url: string) => Record<string, string> | null;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Ctx, KoaApp } from "../type";
2
+ declare const _default: (app: KoaApp) => (view: string, ctx: Ctx, context?: Record<string, unknown>) => void;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type Koa from "koa";
2
+ import type { KoaApp, Ctx } from "../type";
3
+ declare const _default: (app: KoaApp) => (ctx: Ctx, next: Koa.Next) => Promise<any>;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type Koa from "koa";
2
+ import type { Ctx, KoaApp } from "../type";
3
+ declare const _default: (app: KoaApp) => (ctx: Ctx, next: Koa.Next) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { Ctx, KoaApp } from "../type";
2
+ import type Koa from "koa";
3
+ declare const _default: (app: KoaApp) => (ctx: Ctx, next: Koa.Next) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { Ctx } from "../type";
2
+ import type Koa from "koa";
3
+ declare const _default: () => (ctx: Ctx, next: Koa.Next) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { KoaApp } from "./typings";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { KoaApp } from "../type";
2
+ import type Router from "koa-router";
3
+ declare const _default: (app: KoaApp, router: Router) => void;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { KoaApp } from "../type";
2
+ import type Router from "koa-router";
3
+ declare const _default: (app: KoaApp, router: Router) => void;
4
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { RouterSchemaType } from "./types";
2
+ declare const routerSchema: RouterSchemaType;
3
+ export default routerSchema;
@@ -0,0 +1,10 @@
1
+ import type { KoaApp } from "../type";
2
+ import superagent from "superagent";
3
+ declare const _default: (app: KoaApp) => {
4
+ new (): {
5
+ get app(): KoaApp;
6
+ get config(): KoaApp["config"];
7
+ get curl(): superagent.SuperAgentStatic<superagent.Request>;
8
+ };
9
+ };
10
+ export default _default;
@@ -0,0 +1,27 @@
1
+ import type { KoaApp } from "../type";
2
+ export interface ProjectItem {
3
+ key: string;
4
+ name: string;
5
+ desc: string;
6
+ homePage: string;
7
+ modelKey?: string;
8
+ }
9
+ export interface ModelItem {
10
+ model: {
11
+ key: string;
12
+ name: string;
13
+ desc: string;
14
+ };
15
+ project: Record<string, ProjectItem>;
16
+ }
17
+ declare const getProjectService: (app: KoaApp) => {
18
+ new (): {
19
+ getModelList(): Promise<ModelItem[]>;
20
+ getList: (key?: string) => ProjectItem[];
21
+ getProject: (projectKey: string) => ProjectItem | null;
22
+ get app(): KoaApp;
23
+ get config(): KoaApp["config"];
24
+ get curl(): import("superagent/lib/node").SuperAgentStatic<import("superagent/lib/node").Request>;
25
+ };
26
+ };
27
+ export default getProjectService;
@@ -0,0 +1,2 @@
1
+ export type KoaApp = import("./typings").KoaApp;
2
+ export type Ctx = KoaApp["context"];
@@ -0,0 +1,50 @@
1
+ import type { FrameworkAugment, KoaApp, KoaAppExtensions } from "../packages/core";
2
+ import type getProjectService from "./service/project";
3
+ import type getProjectController from "./controller/project";
4
+ import type getViewController from "./controller/view";
5
+ import type getDB from "./extend/db";
6
+ import type getLogger from "./extend/logger";
7
+ import type generateErrorMessage from "./extend/generateErrorMessage";
8
+ import type parsingParamsOnUrl from "./extend/parsingParamsOnUrl";
9
+ import renderView from "./extend/render-view";
10
+ type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
11
+ type GetInstance<T extends (...args: never[]) => unknown> = T extends (...args: never[]) => infer R ? R extends new () => infer C ? C : R extends Promise<infer P> ? P extends new () => infer C2 ? C2 : never : never : never;
12
+ declare module "@tc/core" {
13
+ namespace FrameworkAugment {
14
+ interface IServiceAugmented {
15
+ project: GetInstance<typeof getProjectService>;
16
+ }
17
+ interface IControllerAugmented {
18
+ project: GetInstance<typeof getProjectController>;
19
+ view: GetInstance<typeof getViewController>;
20
+ }
21
+ interface IExtendsAugmented {
22
+ db: UnwrapPromise<ReturnType<typeof getDB>>;
23
+ logger: UnwrapPromise<ReturnType<typeof getLogger>>;
24
+ generateErrorMessage: ReturnType<typeof generateErrorMessage>;
25
+ parsingParamsOnUrl: ReturnType<typeof parsingParamsOnUrl>;
26
+ nunjucksEnv: import("nunjucks").Environment;
27
+ renderView: ReturnType<typeof renderView>;
28
+ }
29
+ interface IMiddlewaresAugmented {
30
+ errorHandle: import("koa").Middleware;
31
+ apiSignVerify: import("koa").Middleware;
32
+ apiParamsVerify: import("koa").Middleware;
33
+ projectHandler: import("koa").Middleware;
34
+ }
35
+ interface AppConfigAugmented {
36
+ frameName: string;
37
+ port?: number;
38
+ host?: string;
39
+ env?: string;
40
+ apiSignVerify?: {
41
+ whiteList?: string[];
42
+ };
43
+ viewsPath?: string;
44
+ nunjucks?: import("nunjucks").ConfigureOptions;
45
+ }
46
+ }
47
+ }
48
+ export type { FrameworkAugment };
49
+ export { KoaAppExtensions };
50
+ export type { KoaApp };
@@ -0,0 +1 @@
1
+ export declare function dev(): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const buildFE: (mode: "dev" | "prod") => void;
@@ -0,0 +1 @@
1
+ export declare function prod(): Promise<void>;
@@ -0,0 +1,4 @@
1
+ export declare function entries(): Record<string, string>;
2
+ export declare function outDir(): string;
3
+ export declare const watchFiles: (callback?: () => Promise<any>) => Promise<void>;
4
+ export declare const VBuildFE: (input: Record<string, string>) => Promise<void>;
@@ -0,0 +1,28 @@
1
+ import { StartOptions } from "./packages/core";
2
+ import "./app/typings";
3
+ import { MOmit } from "./typings/type";
4
+ export type { Ctx } from "./app/type";
5
+ export type { KoaApp, FrameworkAugment } from "./packages/core";
6
+ import type Router from "koa-router";
7
+ export type { Router };
8
+ export declare const serverStart: (options?: MOmit<StartOptions, "frameBaseDir">) => import("./packages/core").KoaApp;
9
+ export declare const baseFn: {
10
+ baseControllerFn: (app: import("./app/type").KoaApp) => {
11
+ new (): {
12
+ readonly app: import("./app/type").KoaApp;
13
+ readonly config: import("./app/type").KoaApp["config"];
14
+ get service(): import("./packages/core").FrameworkAugment.IServiceAugmented;
15
+ success(ctx: import(".").Ctx, data: unknown): void;
16
+ fail(ctx: import(".").Ctx, code: number, message: string): void;
17
+ sendData(ctx: import(".").Ctx, data?: unknown, code?: number, message?: string | null, status?: number): void;
18
+ };
19
+ };
20
+ baseServiceFn: (app: import("./app/type").KoaApp) => {
21
+ new (): {
22
+ get app(): import("./app/type").KoaApp;
23
+ get config(): import("./app/type").KoaApp["config"];
24
+ get curl(): import("superagent/lib/node").SuperAgentStatic<import("superagent/lib/node").Request>;
25
+ };
26
+ };
27
+ };
28
+ export { default as modelLoader } from "./packages/core/loader/model";
@@ -0,0 +1,15 @@
1
+ export type EnvType = {
2
+ local: 'local' | string;
3
+ bate: 'bate' | string;
4
+ prod: 'prod' | string;
5
+ };
6
+ export type EnvKeys = keyof EnvType;
7
+ export interface EnvReturn {
8
+ isLocal(): boolean;
9
+ isBate(): boolean;
10
+ isProd(): boolean;
11
+ get(): EnvType[keyof EnvType];
12
+ getEnvKeys(): EnvType;
13
+ }
14
+ declare const _default: () => EnvReturn;
15
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import "./types";
2
+ import "../../app/typings";
3
+ import type { KoaApp, StartOptions } from "./types";
4
+ export declare const loaderModel: (app: KoaApp) => import("./loader/model").ModelConfig;
5
+ export type { AppConfig, AppOptions, StartOptions, KoaMiddleware, ProcessingFileCallbackFN, IService, IController, IExtends, IMiddlewares, KoaApp, KoaAppExtensions, FrameworkAugment, } from "./types";
6
+ export declare const start: (options?: StartOptions) => KoaApp;
@@ -0,0 +1,3 @@
1
+ import type { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { KoaApp } from "../types";
2
+ export interface ModelItem {
3
+ model: {
4
+ key: string;
5
+ [k: string]: any;
6
+ };
7
+ project: {
8
+ key: string;
9
+ [k: string]: any;
10
+ };
11
+ }
12
+ export type ModelConfig = ModelItem[];
13
+ declare const modelLoader: (app: KoaApp) => ModelConfig;
14
+ export default modelLoader;
@@ -0,0 +1,3 @@
1
+ import { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { KoaApp } from "../types";
2
+ declare const _default: (app: KoaApp) => void;
3
+ export default _default;
@@ -0,0 +1,11 @@
1
+ export type AppPathType = "frame" | "business";
2
+ export interface AppPathInfo {
3
+ type: AppPathType;
4
+ path: string;
5
+ }
6
+ export declare function getAppPath(app: {
7
+ paths?: AppPathInfo[];
8
+ }, type: AppPathType): string | undefined;
9
+ export declare function getAppPaths(app: {
10
+ paths?: AppPathInfo[];
11
+ }): string[];
@@ -0,0 +1,73 @@
1
+ import Koa from "koa";
2
+ import type Router from "koa-router";
3
+ import type { EnvReturn } from "./env";
4
+ import type { AppPathInfo } from "./paths";
5
+ export interface IService {
6
+ [key: string]: unknown;
7
+ }
8
+ export interface IController {
9
+ [key: string]: unknown;
10
+ }
11
+ export interface IExtends {
12
+ [key: string]: unknown;
13
+ }
14
+ export interface IMiddlewares {
15
+ [key: string]: unknown;
16
+ }
17
+ export declare namespace FrameworkAugment {
18
+ interface IServiceAugmented {
19
+ }
20
+ interface IControllerAugmented {
21
+ }
22
+ interface IExtendsAugmented {
23
+ }
24
+ interface IMiddlewaresAugmented {
25
+ }
26
+ interface AppConfigAugmented {
27
+ }
28
+ }
29
+ export type ICTX = Parameters<Router.IMiddleware<any, {}>>[0];
30
+ export interface KoaAppExtensions {
31
+ baseDir: string;
32
+ frameBaseDir: string;
33
+ businessPath: string;
34
+ paths: AppPathInfo[];
35
+ framePath: string;
36
+ envs: EnvReturn;
37
+ config: FrameworkAugment.AppConfigAugmented;
38
+ extends: FrameworkAugment.IExtendsAugmented;
39
+ controller: FrameworkAugment.IControllerAugmented;
40
+ service: FrameworkAugment.IServiceAugmented;
41
+ middlewares: FrameworkAugment.IMiddlewaresAugmented;
42
+ model: unknown[];
43
+ routerSchema: Record<string, unknown>;
44
+ currentUseRouter: Router;
45
+ options: AppOptions;
46
+ logger?: {
47
+ info: (...args: unknown[]) => void;
48
+ error: (...args: unknown[]) => void;
49
+ warn: (...args: unknown[]) => void;
50
+ };
51
+ [key: string]: unknown;
52
+ }
53
+ export interface AppConfigBase {
54
+ port?: number;
55
+ host?: string;
56
+ env?: string;
57
+ }
58
+ export interface AppConfig extends AppConfigBase {
59
+ [key: string]: unknown;
60
+ }
61
+ export interface StartOptions {
62
+ name?: string;
63
+ homePage?: string;
64
+ frameBaseDir?: string;
65
+ }
66
+ export interface AppOptions extends StartOptions {
67
+ overwriteOriginalLogs?: boolean;
68
+ [key: string]: unknown;
69
+ }
70
+ export type KoaApp = Koa & KoaAppExtensions;
71
+ export type KoaMiddleware = Koa.Middleware;
72
+ export type { EnvType, EnvKeys } from "./env";
73
+ export type ProcessingFileCallbackFN = <T extends Record<string, unknown>>(fileName: string, filePath: string, isDir: boolean, tempData: T) => T | undefined;
@@ -0,0 +1,4 @@
1
+ export interface GetAllFilesInFolder {
2
+ getAllFilesInFolder(...paths: string[]): string[];
3
+ }
4
+ export declare const getAllFilesInFolder: (...paths: string[]) => string[];
File without changes
@@ -0,0 +1,4 @@
1
+ export * from "./path";
2
+ export * from "./loadFile";
3
+ export * from "./getAllFilesInFolder";
4
+ export * from "./runFileFn";
@@ -0,0 +1,14 @@
1
+ export type PreProcessingFileCallbackFN = <T extends Record<string, any>>(filePath: string, result: T) => any;
2
+ export type ProcessingFileCallbackFN = <T extends Record<string, any>>(fileName: string, filePath: string, isDir: boolean, tempData: T) => T | undefined;
3
+ export type LoadFileCallbackFN = (filePath: string) => any;
4
+ export interface LoadFileCallbackOptions {
5
+ loadFileCallback?: LoadFileCallbackFN;
6
+ processingFileCallback?: ProcessingFileCallbackFN;
7
+ preProcessingFileCallback?: PreProcessingFileCallbackFN;
8
+ }
9
+ declare function loadFileFn<T extends Record<string, unknown>>(baseDir: string, key: string, callbackOpt?: LoadFileCallbackOptions): T;
10
+ export { loadFileFn };
11
+ declare const _default: {
12
+ loadFileFn: typeof loadFileFn;
13
+ };
14
+ export default _default;
@@ -0,0 +1,6 @@
1
+ export interface SplicingOptions {
2
+ symbol?: string;
3
+ position?: "after" | "before";
4
+ }
5
+ export declare function splicing(str: string, opt?: SplicingOptions): string;
6
+ export declare function resolve(...paths: string[]): string;
@@ -0,0 +1,5 @@
1
+ type AnyFun = (...p: any[]) => any;
2
+ export declare const runFileFn: (fn: {
3
+ default: AnyFun;
4
+ } | AnyFun) => AnyFun;
5
+ export {};
@@ -0,0 +1,4 @@
1
+ export type MOmit<T, K extends keyof T> = Omit<T, K>;
2
+ export type UnionToTuple<T> = [
3
+ T
4
+ ] extends [never] ? [] : ((t: T) => T) extends ((t: infer U) => infer U) ? [...UnionToTuple<Exclude<T, U>>, U] : never;