@jayfong/x-server 2.2.0 → 2.2.2

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,2 +1,2 @@
1
- // @index(['../../src/crons/**/*.ts', '!**/_*'], (f, _) => `import '${f.path}'`)
1
+ // @index(['../../src/crons/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `import '${f.path}'`)
2
2
  // @endindex
@@ -1,3 +1,3 @@
1
- // @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
1
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
2
2
 
3
3
  // @endindex
@@ -1,2 +1,2 @@
1
- // @index(['../../src/hooks/**/*.ts', '!**/_*'], (f, _) => `import '${f.path}'`)
1
+ // @index(['../../src/hooks/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `import '${f.path}'`)
2
2
  // @endindex
@@ -2,7 +2,7 @@ import * as handlers from './handlers'
2
2
  import { Handler, XServer } from '@jayfong/x-server'
3
3
 
4
4
  const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
5
- // @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
5
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
6
6
  // @endindex
7
7
  ]
8
8
 
@@ -13,7 +13,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
13
13
  ? I
14
14
  : never
15
15
  type RouteMap = {
16
- // @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
16
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
17
17
  // @endindex
18
18
  }
19
19
  export type HandlerMap = UnionToIntersection<
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.LogService = void 0;
5
+
6
+ var _date = require("vtils/date");
7
+
8
+ class LogService {
9
+ constructor() {
10
+ this.serviceName = 'log';
11
+ }
12
+
13
+ log(level, message) {
14
+ console[level === 'error' ? 'error' : 'log'](`[${(0, _date.formatDate)(new Date(), 'yyyy-mm-dd hh:ii:ss')}] ${level.toUpperCase()} - ${message}`);
15
+ }
16
+
17
+ error(message) {
18
+ this.log('error', message);
19
+ }
20
+
21
+ info(message) {
22
+ this.log('info', message);
23
+ }
24
+
25
+ }
26
+
27
+ exports.LogService = LogService;
package/lib/_cjs/x.js CHANGED
@@ -5,6 +5,8 @@ exports.x = void 0;
5
5
 
6
6
  var _dispose = require("./services/dispose");
7
7
 
8
+ var _log = require("./services/log");
9
+
8
10
  const env = JSON.parse(process.env.X_SERVER_ENVS || '{}');
9
11
  const x = {
10
12
  appId: env.APP_ID,
@@ -19,4 +21,4 @@ const x = {
19
21
  exports.x = x;
20
22
  x.register(new _dispose.DisposeService({
21
23
  disposeOnExit: true
22
- }));
24
+ }), new _log.LogService());
@@ -1,2 +1,2 @@
1
- // @index(['../../src/crons/**/*.ts', '!**/_*'], (f, _) => `import '${f.path}'`)
1
+ // @index(['../../src/crons/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `import '${f.path}'`)
2
2
  // @endindex
@@ -1,3 +1,3 @@
1
- // @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
1
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
2
2
 
3
3
  // @endindex
@@ -1,2 +1,2 @@
1
- // @index(['../../src/hooks/**/*.ts', '!**/_*'], (f, _) => `import '${f.path}'`)
1
+ // @index(['../../src/hooks/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `import '${f.path}'`)
2
2
  // @endindex
@@ -2,7 +2,7 @@ import * as handlers from './handlers'
2
2
  import { Handler, XServer } from '@jayfong/x-server'
3
3
 
4
4
  const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
5
- // @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
5
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
6
6
  // @endindex
7
7
  ]
8
8
 
@@ -13,7 +13,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
13
13
  ? I
14
14
  : never
15
15
  type RouteMap = {
16
- // @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
16
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
17
17
  // @endindex
18
18
  }
19
19
  export type HandlerMap = UnionToIntersection<
@@ -0,0 +1,13 @@
1
+ import { BaseService } from './base';
2
+ export declare type LogServiceLevel = 'error' | 'info';
3
+ export declare class LogService implements BaseService {
4
+ serviceName: string;
5
+ log(level: LogServiceLevel, message: any): void;
6
+ error(message: any): void;
7
+ info(message: any): void;
8
+ }
9
+ declare module '../x' {
10
+ interface X {
11
+ log: LogService;
12
+ }
13
+ }
@@ -0,0 +1,19 @@
1
+ import { formatDate } from 'vtils/date';
2
+ export class LogService {
3
+ constructor() {
4
+ this.serviceName = 'log';
5
+ }
6
+
7
+ log(level, message) {
8
+ console[level === 'error' ? 'error' : 'log'](`[${formatDate(new Date(), 'yyyy-mm-dd hh:ii:ss')}] ${level.toUpperCase()} - ${message}`);
9
+ }
10
+
11
+ error(message) {
12
+ this.log('error', message);
13
+ }
14
+
15
+ info(message) {
16
+ this.log('info', message);
17
+ }
18
+
19
+ }
package/lib/x.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { BaseService } from './services/base';
3
3
  import './services/dispose';
4
+ import './services/log';
4
5
  export interface X {
5
6
  readonly appId: string;
6
7
  readonly env: NodeJS.ProcessEnv;
package/lib/x.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DisposeService } from "./services/dispose";
2
+ import { LogService } from "./services/log";
2
3
  const env = JSON.parse(process.env.X_SERVER_ENVS || '{}');
3
4
  export const x = {
4
5
  appId: env.APP_ID,
@@ -12,4 +13,4 @@ export const x = {
12
13
  };
13
14
  x.register(new DisposeService({
14
15
  disposeOnExit: true
15
- }));
16
+ }), new LogService());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",