@eggjs/core 7.0.0-beta.34 → 7.0.0-beta.36

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.
@@ -1,101 +1,105 @@
1
- import { type Fun } from '../utils/index.ts';
2
- export declare const FULLPATH: unique symbol;
3
- export declare const EXPORTS: unique symbol;
4
- export declare const CaseStyle: {
5
- readonly camel: "camel";
6
- readonly lower: "lower";
7
- readonly upper: "upper";
1
+ import { Fun } from "../utils/index.js";
2
+
3
+ //#region src/loader/file_loader.d.ts
4
+ declare const FULLPATH: unique symbol;
5
+ declare const EXPORTS: unique symbol;
6
+ declare const CaseStyle: {
7
+ readonly camel: "camel";
8
+ readonly lower: "lower";
9
+ readonly upper: "upper";
8
10
  };
9
- export type CaseStyle = (typeof CaseStyle)[keyof typeof CaseStyle];
10
- export type CaseStyleFunction = (filepath: string) => string[];
11
- export type FileLoaderInitializer = (exports: unknown, options: {
12
- path: string;
13
- pathName: string;
11
+ type CaseStyle = (typeof CaseStyle)[keyof typeof CaseStyle];
12
+ type CaseStyleFunction = (filepath: string) => string[];
13
+ type FileLoaderInitializer = (exports: unknown, options: {
14
+ path: string;
15
+ pathName: string;
14
16
  }) => unknown;
15
- export type FileLoaderFilter = (exports: unknown) => boolean;
16
- export interface FileLoaderOptions {
17
- /** directories to be loaded */
18
- directory: string | string[];
19
- /** attach the target object from loaded files */
20
- target: Record<string, any>;
21
- /** match the files when load, support glob, default to all js files */
22
- match?: string | string[];
23
- /** ignore the files when load, support glob */
24
- ignore?: string | string[];
25
- /** custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` */
26
- initializer?: FileLoaderInitializer;
27
- /** determine whether invoke when exports is function */
28
- call?: boolean;
29
- /** determine whether override the property when get the same name */
30
- override?: boolean;
31
- /** an object that be the argument when invoke the function */
32
- inject?: Record<string, any>;
33
- /** a function that filter the exports which can be loaded */
34
- filter?: FileLoaderFilter;
35
- /** set property's case when converting a filepath to property list. */
36
- caseStyle?: CaseStyle | CaseStyleFunction;
37
- lowercaseFirst?: boolean;
17
+ type FileLoaderFilter = (exports: unknown) => boolean;
18
+ interface FileLoaderOptions {
19
+ /** directories to be loaded */
20
+ directory: string | string[];
21
+ /** attach the target object from loaded files */
22
+ target: Record<string, any>;
23
+ /** match the files when load, support glob, default to all js files */
24
+ match?: string | string[];
25
+ /** ignore the files when load, support glob */
26
+ ignore?: string | string[];
27
+ /** custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` */
28
+ initializer?: FileLoaderInitializer;
29
+ /** determine whether invoke when exports is function */
30
+ call?: boolean;
31
+ /** determine whether override the property when get the same name */
32
+ override?: boolean;
33
+ /** an object that be the argument when invoke the function */
34
+ inject?: Record<string, any>;
35
+ /** a function that filter the exports which can be loaded */
36
+ filter?: FileLoaderFilter;
37
+ /** set property's case when converting a filepath to property list. */
38
+ caseStyle?: CaseStyle | CaseStyleFunction;
39
+ lowercaseFirst?: boolean;
38
40
  }
39
- export interface FileLoaderParseItem {
40
- fullpath: string;
41
- properties: string[];
42
- exports: object | Fun;
41
+ interface FileLoaderParseItem {
42
+ fullpath: string;
43
+ properties: string[];
44
+ exports: object | Fun;
43
45
  }
44
46
  /**
45
- * Load files from directory to target object.
46
- * @since 1.0.0
47
- */
48
- export declare class FileLoader {
49
- static get FULLPATH(): typeof FULLPATH;
50
- static get EXPORTS(): typeof EXPORTS;
51
- readonly options: FileLoaderOptions & Required<Pick<FileLoaderOptions, 'caseStyle'>>;
52
- /**
53
- * @class
54
- * @param {Object} options - options
55
- * @param {String|Array} options.directory - directories to be loaded
56
- * @param {Object} options.target - attach the target object from loaded files
57
- * @param {String} options.match - match the files when load, support glob, default to all js files
58
- * @param {String} options.ignore - ignore the files when load, support glob
59
- * @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
60
- * @param {Boolean} options.call - determine whether invoke when exports is function
61
- * @param {Boolean} options.override - determine whether override the property when get the same name
62
- * @param {Object} options.inject - an object that be the argument when invoke the function
63
- * @param {Function} options.filter - a function that filter the exports which can be loaded
64
- * @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list.
65
- */
66
- constructor(options: FileLoaderOptions);
67
- /**
68
- * attach items to target object. Mapping the directory to properties.
69
- * `app/controller/group/repository.js` => `target.group.repository`
70
- * @returns {Object} target
71
- * @since 1.0.0
72
- */
73
- load(): Promise<object>;
74
- /**
75
- * Parse files from given directories, then return an items list, each item contains properties and exports.
76
- *
77
- * For example, parse `app/controller/group/repository.js`
78
- *
79
- * ```
80
- * module.exports = app => {
81
- * return class RepositoryController extends app.Controller {};
82
- * }
83
- * ```
84
- *
85
- * It returns a item
86
- *
87
- * ```
88
- * {
89
- * properties: [ 'group', 'repository' ],
90
- * exports: app => { ... },
91
- * }
92
- * ```
93
- *
94
- * `Properties` is an array that contains the directory of a filepath.
95
- *
96
- * `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.
97
- * @returns {Array} items
98
- * @since 1.0.0
99
- */
100
- protected parse(): Promise<FileLoaderParseItem[]>;
47
+ * Load files from directory to target object.
48
+ * @since 1.0.0
49
+ */
50
+ declare class FileLoader {
51
+ static get FULLPATH(): typeof FULLPATH;
52
+ static get EXPORTS(): typeof EXPORTS;
53
+ readonly options: FileLoaderOptions & Required<Pick<FileLoaderOptions, "caseStyle">>;
54
+ /**
55
+ * @class
56
+ * @param {Object} options - options
57
+ * @param {String|Array} options.directory - directories to be loaded
58
+ * @param {Object} options.target - attach the target object from loaded files
59
+ * @param {String} options.match - match the files when load, support glob, default to all js files
60
+ * @param {String} options.ignore - ignore the files when load, support glob
61
+ * @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
62
+ * @param {Boolean} options.call - determine whether invoke when exports is function
63
+ * @param {Boolean} options.override - determine whether override the property when get the same name
64
+ * @param {Object} options.inject - an object that be the argument when invoke the function
65
+ * @param {Function} options.filter - a function that filter the exports which can be loaded
66
+ * @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list.
67
+ */
68
+ constructor(options: FileLoaderOptions);
69
+ /**
70
+ * attach items to target object. Mapping the directory to properties.
71
+ * `app/controller/group/repository.js` => `target.group.repository`
72
+ * @returns {Object} target
73
+ * @since 1.0.0
74
+ */
75
+ load(): Promise<object>;
76
+ /**
77
+ * Parse files from given directories, then return an items list, each item contains properties and exports.
78
+ *
79
+ * For example, parse `app/controller/group/repository.js`
80
+ *
81
+ * ```
82
+ * module.exports = app => {
83
+ * return class RepositoryController extends app.Controller {};
84
+ * }
85
+ * ```
86
+ *
87
+ * It returns a item
88
+ *
89
+ * ```
90
+ * {
91
+ * properties: [ 'group', 'repository' ],
92
+ * exports: app => { ... },
93
+ * }
94
+ * ```
95
+ *
96
+ * `Properties` is an array that contains the directory of a filepath.
97
+ *
98
+ * `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.
99
+ * @returns {Array} items
100
+ * @since 1.0.0
101
+ */
102
+ protected parse(): Promise<FileLoaderParseItem[]>;
101
103
  }
104
+ //#endregion
105
+ export { CaseStyle, CaseStyleFunction, EXPORTS, FULLPATH, FileLoader, FileLoaderFilter, FileLoaderInitializer, FileLoaderOptions, FileLoaderParseItem };