@lsby/net-core 0.0.1

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 (69) hide show
  1. package/dist/cjs/global/global.cjs +122 -0
  2. package/dist/cjs/global/global.d.cts +16 -0
  3. package/dist/cjs/index.cjs +400 -0
  4. package/dist/cjs/index.d.cts +14 -0
  5. package/dist/cjs/interface/interface-type.cjs +53 -0
  6. package/dist/cjs/interface/interface-type.d.cts +22 -0
  7. package/dist/cjs/interface/interface.cjs +41 -0
  8. package/dist/cjs/interface/interface.d.cts +18 -0
  9. package/dist/cjs/interface/plug.cjs +41 -0
  10. package/dist/cjs/interface/plug.d.cts +16 -0
  11. package/dist/cjs/plug/chinese-path.cjs +62 -0
  12. package/dist/cjs/plug/chinese-path.d.cts +12 -0
  13. package/dist/cjs/plug/custom-data.cjs +51 -0
  14. package/dist/cjs/plug/custom-data.d.cts +11 -0
  15. package/dist/cjs/plug/json.cjs +163 -0
  16. package/dist/cjs/plug/json.d.cts +14 -0
  17. package/dist/cjs/plug/urlencoded.cjs +76 -0
  18. package/dist/cjs/plug/urlencoded.d.cts +13 -0
  19. package/dist/cjs/result/result.cjs +178 -0
  20. package/dist/cjs/result/result.d.cts +33 -0
  21. package/dist/cjs/server/server.cjs +191 -0
  22. package/dist/cjs/server/server.d.cts +22 -0
  23. package/dist/cjs/tools/get-pro-name.cjs +48 -0
  24. package/dist/cjs/tools/get-pro-name.d.cts +8 -0
  25. package/dist/cjs/tools/log.cjs +72 -0
  26. package/dist/cjs/tools/log.d.cts +16 -0
  27. package/dist/cjs/types/type-hold.cjs +30 -0
  28. package/dist/cjs/types/type-hold.d.cts +3 -0
  29. package/dist/esm/chunk-2GISBUKY.js +26 -0
  30. package/dist/esm/chunk-4S6GMOG5.js +78 -0
  31. package/dist/esm/chunk-FBQ7H3IE.js +30 -0
  32. package/dist/esm/chunk-GWFW2KCB.js +39 -0
  33. package/dist/esm/chunk-KRIDSMPV.js +17 -0
  34. package/dist/esm/chunk-KSZE2DTR.js +17 -0
  35. package/dist/esm/chunk-MFQZP7FG.js +24 -0
  36. package/dist/esm/chunk-PLYBVQKK.js +38 -0
  37. package/dist/esm/chunk-SF5Z34AP.js +29 -0
  38. package/dist/esm/chunk-SJCC3KPB.js +36 -0
  39. package/dist/esm/chunk-THMF6WFQ.js +60 -0
  40. package/dist/esm/chunk-Z4OJO6ZH.js +15 -0
  41. package/dist/esm/global/global.d.ts +16 -0
  42. package/dist/esm/global/global.js +10 -0
  43. package/dist/esm/index.d.ts +14 -0
  44. package/dist/esm/index.js +51 -0
  45. package/dist/esm/interface/interface-type.d.ts +22 -0
  46. package/dist/esm/interface/interface-type.js +6 -0
  47. package/dist/esm/interface/interface.d.ts +18 -0
  48. package/dist/esm/interface/interface.js +6 -0
  49. package/dist/esm/interface/plug.d.ts +16 -0
  50. package/dist/esm/interface/plug.js +6 -0
  51. package/dist/esm/plug/chinese-path.d.ts +12 -0
  52. package/dist/esm/plug/chinese-path.js +7 -0
  53. package/dist/esm/plug/custom-data.d.ts +11 -0
  54. package/dist/esm/plug/custom-data.js +7 -0
  55. package/dist/esm/plug/json.d.ts +14 -0
  56. package/dist/esm/plug/json.js +10 -0
  57. package/dist/esm/plug/urlencoded.d.ts +13 -0
  58. package/dist/esm/plug/urlencoded.js +7 -0
  59. package/dist/esm/result/result.d.ts +33 -0
  60. package/dist/esm/result/result.js +19 -0
  61. package/dist/esm/server/server.d.ts +22 -0
  62. package/dist/esm/server/server.js +9 -0
  63. package/dist/esm/tools/get-pro-name.d.ts +8 -0
  64. package/dist/esm/tools/get-pro-name.js +6 -0
  65. package/dist/esm/tools/log.d.ts +16 -0
  66. package/dist/esm/tools/log.js +6 -0
  67. package/dist/esm/types/type-hold.d.ts +3 -0
  68. package/dist/esm/types/type-hold.js +5 -0
  69. package/package.json +48 -0
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/server/server.ts
31
+ var server_exports = {};
32
+ __export(server_exports, {
33
+ \u670D\u52A1\u5668: () => \u670D\u52A1\u5668
34
+ });
35
+ module.exports = __toCommonJS(server_exports);
36
+ var import_node_os = require("os");
37
+ var import_express = __toESM(require("express"), 1);
38
+ var import_ts_fp_data3 = require("@lsby/ts-fp-data");
39
+
40
+ // src/tools/get-pro-name.ts
41
+ var import_fs = require("fs");
42
+ var import_path = require("path");
43
+ var import_ts_fp_data = require("@lsby/ts-fp-data");
44
+ var GetProName = class {
45
+ proName = null;
46
+ getProName() {
47
+ if (this.proName != null)
48
+ return import_ts_fp_data.Task.pure(this.proName);
49
+ return new import_ts_fp_data.Task(async () => {
50
+ var jsonStr = (0, import_fs.readFileSync)((0, import_path.resolve)(__dirname, "../../package.json"), "utf-8");
51
+ var json = JSON.parse(jsonStr);
52
+ var name = json.name;
53
+ if (name == null)
54
+ throw new Error("\u65E0\u6CD5\u8BFB\u53D6package.json\u4E2D\u7684name\u5B57\u6BB5");
55
+ this.proName = name;
56
+ return name;
57
+ });
58
+ }
59
+ };
60
+
61
+ // src/tools/log.ts
62
+ var import_debug = __toESM(require("debug"), 1);
63
+ var import_ts_fp_data2 = require("@lsby/ts-fp-data");
64
+ var Log = class _Log {
65
+ constructor(fileName) {
66
+ this.fileName = fileName;
67
+ this.debugObj = (0, import_debug.default)(fileName);
68
+ this._info = this.debugObj.extend("info");
69
+ this._debug = this.debugObj.extend("debug");
70
+ this._err = this.debugObj.extend("err");
71
+ }
72
+ debugObj;
73
+ _info;
74
+ _debug;
75
+ _err;
76
+ extend(name) {
77
+ return new _Log(`${this.fileName}:${name}`);
78
+ }
79
+ info(formatter, ...args) {
80
+ return new import_ts_fp_data2.Task(async () => {
81
+ this._info(formatter, ...args);
82
+ });
83
+ }
84
+ debug(formatter, ...args) {
85
+ return new import_ts_fp_data2.Task(async () => {
86
+ this._debug(formatter, ...args);
87
+ });
88
+ }
89
+ err(formatter, ...args) {
90
+ return new import_ts_fp_data2.Task(async () => {
91
+ this._err(formatter, ...args);
92
+ });
93
+ }
94
+ };
95
+
96
+ // src/global/global.ts
97
+ var GlobalLog = class _GlobalLog {
98
+ static instance;
99
+ static getInstance() {
100
+ return GlobalGetProName.getInstance().getProName().map((\u6807\u8BC6\u7B26) => {
101
+ \u6807\u8BC6\u7B26 = \u6807\u8BC6\u7B26.replaceAll("/", ":");
102
+ if (!_GlobalLog.instance)
103
+ _GlobalLog.instance = new Log(\u6807\u8BC6\u7B26);
104
+ return _GlobalLog.instance;
105
+ });
106
+ }
107
+ constructor() {
108
+ }
109
+ };
110
+ var GlobalGetProName = class _GlobalGetProName {
111
+ static instance;
112
+ static getInstance() {
113
+ if (!_GlobalGetProName.instance)
114
+ _GlobalGetProName.instance = new GetProName();
115
+ return _GlobalGetProName.instance;
116
+ }
117
+ constructor() {
118
+ }
119
+ };
120
+
121
+ // src/server/server.ts
122
+ var \u670D\u52A1\u5668 = class {
123
+ constructor(\u63A5\u53E3\u4EEC, \u7AEF\u53E3) {
124
+ this.\u63A5\u53E3\u4EEC = \u63A5\u53E3\u4EEC;
125
+ this.\u7AEF\u53E3 = \u7AEF\u53E3;
126
+ }
127
+ log = GlobalLog.getInstance();
128
+ run() {
129
+ return new import_ts_fp_data3.Task(async () => {
130
+ var log = (await this.log.run()).extend("\u670D\u52A1\u5668");
131
+ const app = (0, import_express.default)();
132
+ app.use((req, res) => {
133
+ new import_ts_fp_data3.Task(async () => {
134
+ const \u8BF7\u6C42\u8DEF\u5F84 = req.path;
135
+ const \u8BF7\u6C42\u65B9\u6CD5 = req.method.toLowerCase();
136
+ await log.debug("\u6536\u5230\u8BF7\u6C42\uFF0C\u8DEF\u5F84\uFF1A%o\uFF0C\u65B9\u6CD5\uFF1A%o", \u8BF7\u6C42\u8DEF\u5F84, \u8BF7\u6C42\u65B9\u6CD5).run();
137
+ const \u76EE\u6807\u63A5\u53E3 = this.\u63A5\u53E3\u4EEC.find((\u63A5\u53E3) => {
138
+ const \u63A5\u53E3\u7C7B\u578B2 = \u63A5\u53E3.\u83B7\u5F97\u7C7B\u578B();
139
+ return \u8BF7\u6C42\u8DEF\u5F84 === \u63A5\u53E3\u7C7B\u578B2.\u83B7\u5F97\u8DEF\u5F84() && \u8BF7\u6C42\u65B9\u6CD5 === \u63A5\u53E3\u7C7B\u578B2.\u83B7\u5F97\u65B9\u6CD5();
140
+ });
141
+ if (\u76EE\u6807\u63A5\u53E3 === void 0) {
142
+ throw new Error("\u65E0\u6CD5\u627E\u5230\u5BF9\u5E94\u63A5\u53E3");
143
+ }
144
+ const \u63A5\u53E3\u7C7B\u578B = \u76EE\u6807\u63A5\u53E3.\u83B7\u5F97\u7C7B\u578B();
145
+ const \u63A5\u53E3\u63D2\u4EF6 = \u63A5\u53E3\u7C7B\u578B.\u83B7\u5F97\u63D2\u4EF6\u4EEC();
146
+ await log.debug("\u627E\u5230 %o \u4E2A \u63D2\u4EF6\uFF0C\u51C6\u5907\u6267\u884C...", \u63A5\u53E3\u63D2\u4EF6.length).run();
147
+ var \u63D2\u4EF6\u7ED3\u679C = (0, import_ts_fp_data3.seqArrayTask)(
148
+ \u63A5\u53E3\u63D2\u4EF6.map((\u63D2\u4EF6) => {
149
+ const \u5B9E\u73B0 = \u63D2\u4EF6.\u83B7\u5F97\u5B9E\u73B0();
150
+ return \u5B9E\u73B0(req, res);
151
+ })
152
+ ).map((a) => a.reduce((s, a2) => Object.assign(s, a2), {}));
153
+ await log.debug("\u63D2\u4EF6 \u6267\u884C\u5B8C\u6BD5").run();
154
+ const \u63A5\u53E3\u5B9E\u73B0 = \u76EE\u6807\u63A5\u53E3.\u83B7\u5F97\u5B9E\u73B0();
155
+ await log.debug("\u51C6\u5907\u6267\u884C\u63A5\u53E3\u903B\u8F91...").run();
156
+ const \u63A5\u53E3\u7ED3\u679C = \u63D2\u4EF6\u7ED3\u679C.bind(\u63A5\u53E3\u5B9E\u73B0);
157
+ await log.debug("\u63A5\u53E3\u903B\u8F91\u6267\u884C\u5B8C\u6BD5").run();
158
+ await log.debug("\u51C6\u5907\u6267\u884C\u8FD4\u56DE\u903B\u8F91...").run();
159
+ (await \u63A5\u53E3\u7ED3\u679C.run()).run(req, res);
160
+ await log.debug("\u8FD4\u56DE\u903B\u8F91\u6267\u884C\u5B8C\u6BD5").run();
161
+ }).tryRun().then((a) => {
162
+ if (a.isLeft()) {
163
+ new import_ts_fp_data3.Task(async () => {
164
+ await log.err(a.getLeft()).run();
165
+ res.send("\u672A\u77E5\u9519\u8BEF");
166
+ }).run().catch(() => {
167
+ });
168
+ }
169
+ }).catch(() => {
170
+ });
171
+ });
172
+ let server = null;
173
+ if (server === null) {
174
+ throw new Error("\u542F\u52A8\u670D\u52A1\u5668\u5931\u8D25");
175
+ }
176
+ await new Promise((res, _rej) => {
177
+ server = app.listen(this.\u7AEF\u53E3, () => {
178
+ res();
179
+ });
180
+ });
181
+ return {
182
+ ip: Object.values((0, import_node_os.networkInterfaces)()).flat().flatMap((address) => address !== void 0 ? [address] : []).map((wrappedAddress) => wrappedAddress.address).map((address) => `http://${address}:${this.\u7AEF\u53E3}`),
183
+ server
184
+ };
185
+ });
186
+ }
187
+ };
188
+ // Annotate the CommonJS export names for ESM import in node:
189
+ 0 && (module.exports = {
190
+ \u670D\u52A1\u5668
191
+ });
@@ -0,0 +1,22 @@
1
+ import * as http from 'node:http';
2
+ import { Task } from '@lsby/ts-fp-data';
3
+ import { 任意接口 as ____ } from '../interface/interface.cjs';
4
+ import 'zod';
5
+ import '../result/result.cjs';
6
+ import 'express';
7
+ import '../types/type-hold.cjs';
8
+ import '../interface/interface-type.cjs';
9
+ import '../interface/plug.cjs';
10
+
11
+ declare class 服务器 {
12
+ private 接口们;
13
+ private 端口;
14
+ private log;
15
+ constructor(接口们: ____[], 端口: number);
16
+ run(): Task<{
17
+ ip: string[];
18
+ server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
19
+ }>;
20
+ }
21
+
22
+ export { 服务器 };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/tools/get-pro-name.ts
21
+ var get_pro_name_exports = {};
22
+ __export(get_pro_name_exports, {
23
+ GetProName: () => GetProName
24
+ });
25
+ module.exports = __toCommonJS(get_pro_name_exports);
26
+ var import_fs = require("fs");
27
+ var import_path = require("path");
28
+ var import_ts_fp_data = require("@lsby/ts-fp-data");
29
+ var GetProName = class {
30
+ proName = null;
31
+ getProName() {
32
+ if (this.proName != null)
33
+ return import_ts_fp_data.Task.pure(this.proName);
34
+ return new import_ts_fp_data.Task(async () => {
35
+ var jsonStr = (0, import_fs.readFileSync)((0, import_path.resolve)(__dirname, "../../package.json"), "utf-8");
36
+ var json = JSON.parse(jsonStr);
37
+ var name = json.name;
38
+ if (name == null)
39
+ throw new Error("\u65E0\u6CD5\u8BFB\u53D6package.json\u4E2D\u7684name\u5B57\u6BB5");
40
+ this.proName = name;
41
+ return name;
42
+ });
43
+ }
44
+ };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ GetProName
48
+ });
@@ -0,0 +1,8 @@
1
+ import { Task } from '@lsby/ts-fp-data';
2
+
3
+ declare class GetProName {
4
+ private proName;
5
+ getProName(): Task<string>;
6
+ }
7
+
8
+ export { GetProName };
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/tools/log.ts
31
+ var log_exports = {};
32
+ __export(log_exports, {
33
+ Log: () => Log
34
+ });
35
+ module.exports = __toCommonJS(log_exports);
36
+ var import_debug = __toESM(require("debug"), 1);
37
+ var import_ts_fp_data = require("@lsby/ts-fp-data");
38
+ var Log = class _Log {
39
+ constructor(fileName) {
40
+ this.fileName = fileName;
41
+ this.debugObj = (0, import_debug.default)(fileName);
42
+ this._info = this.debugObj.extend("info");
43
+ this._debug = this.debugObj.extend("debug");
44
+ this._err = this.debugObj.extend("err");
45
+ }
46
+ debugObj;
47
+ _info;
48
+ _debug;
49
+ _err;
50
+ extend(name) {
51
+ return new _Log(`${this.fileName}:${name}`);
52
+ }
53
+ info(formatter, ...args) {
54
+ return new import_ts_fp_data.Task(async () => {
55
+ this._info(formatter, ...args);
56
+ });
57
+ }
58
+ debug(formatter, ...args) {
59
+ return new import_ts_fp_data.Task(async () => {
60
+ this._debug(formatter, ...args);
61
+ });
62
+ }
63
+ err(formatter, ...args) {
64
+ return new import_ts_fp_data.Task(async () => {
65
+ this._err(formatter, ...args);
66
+ });
67
+ }
68
+ };
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ Log
72
+ });
@@ -0,0 +1,16 @@
1
+ import { Task } from '@lsby/ts-fp-data';
2
+
3
+ declare class Log {
4
+ private fileName;
5
+ private debugObj;
6
+ private _info;
7
+ private _debug;
8
+ private _err;
9
+ constructor(fileName: string);
10
+ extend(name: string): Log;
11
+ info(formatter: unknown, ...args: unknown[]): Task<void>;
12
+ debug(formatter: unknown, ...args: unknown[]): Task<void>;
13
+ err(formatter: unknown, ...args: unknown[]): Task<void>;
14
+ }
15
+
16
+ export { Log };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/types/type-hold.ts
21
+ var type_hold_exports = {};
22
+ __export(type_hold_exports, {
23
+ \u7C7B\u578B\u4FDD\u6301\u7B26\u53F7: () => \u7C7B\u578B\u4FDD\u6301\u7B26\u53F7
24
+ });
25
+ module.exports = __toCommonJS(type_hold_exports);
26
+ var \u7C7B\u578B\u4FDD\u6301\u7B26\u53F7 = Symbol();
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ \u7C7B\u578B\u4FDD\u6301\u7B26\u53F7
30
+ });
@@ -0,0 +1,3 @@
1
+ declare const 类型保持符号: unique symbol;
2
+
3
+ export { 类型保持符号 };
@@ -0,0 +1,26 @@
1
+ import {
2
+ 插件
3
+ } from "./chunk-KSZE2DTR.js";
4
+
5
+ // src/plug/chinese-path.ts
6
+ import { URL } from "node:url";
7
+ import { z } from "zod";
8
+ import { Task } from "@lsby/ts-fp-data";
9
+ var zod\u7C7B\u578B\u8868\u793A = z.object({});
10
+ var \u4E2D\u6587\u8DEF\u5F84\u652F\u6301\u63D2\u4EF6 = class extends \u63D2\u4EF6 {
11
+ constructor() {
12
+ super(
13
+ zod\u7C7B\u578B\u8868\u793A,
14
+ (request) => new Task(async () => {
15
+ const url = new URL(request.url);
16
+ const pathname = url.pathname;
17
+ request.url = request.originalUrl = pathname.replace(pathname, decodeURIComponent(pathname));
18
+ return {};
19
+ })
20
+ );
21
+ }
22
+ };
23
+
24
+ export {
25
+ 中文路径支持插件
26
+ };
@@ -0,0 +1,78 @@
1
+ import {
2
+ GlobalLog
3
+ } from "./chunk-SJCC3KPB.js";
4
+
5
+ // src/server/server.ts
6
+ import { networkInterfaces } from "node:os";
7
+ import express from "express";
8
+ import { seqArrayTask, Task } from "@lsby/ts-fp-data";
9
+ var \u670D\u52A1\u5668 = class {
10
+ constructor(\u63A5\u53E3\u4EEC, \u7AEF\u53E3) {
11
+ this.\u63A5\u53E3\u4EEC = \u63A5\u53E3\u4EEC;
12
+ this.\u7AEF\u53E3 = \u7AEF\u53E3;
13
+ }
14
+ log = GlobalLog.getInstance();
15
+ run() {
16
+ return new Task(async () => {
17
+ var log = (await this.log.run()).extend("\u670D\u52A1\u5668");
18
+ const app = express();
19
+ app.use((req, res) => {
20
+ new Task(async () => {
21
+ const \u8BF7\u6C42\u8DEF\u5F84 = req.path;
22
+ const \u8BF7\u6C42\u65B9\u6CD5 = req.method.toLowerCase();
23
+ await log.debug("\u6536\u5230\u8BF7\u6C42\uFF0C\u8DEF\u5F84\uFF1A%o\uFF0C\u65B9\u6CD5\uFF1A%o", \u8BF7\u6C42\u8DEF\u5F84, \u8BF7\u6C42\u65B9\u6CD5).run();
24
+ const \u76EE\u6807\u63A5\u53E3 = this.\u63A5\u53E3\u4EEC.find((\u63A5\u53E3) => {
25
+ const \u63A5\u53E3\u7C7B\u578B2 = \u63A5\u53E3.\u83B7\u5F97\u7C7B\u578B();
26
+ return \u8BF7\u6C42\u8DEF\u5F84 === \u63A5\u53E3\u7C7B\u578B2.\u83B7\u5F97\u8DEF\u5F84() && \u8BF7\u6C42\u65B9\u6CD5 === \u63A5\u53E3\u7C7B\u578B2.\u83B7\u5F97\u65B9\u6CD5();
27
+ });
28
+ if (\u76EE\u6807\u63A5\u53E3 === void 0) {
29
+ throw new Error("\u65E0\u6CD5\u627E\u5230\u5BF9\u5E94\u63A5\u53E3");
30
+ }
31
+ const \u63A5\u53E3\u7C7B\u578B = \u76EE\u6807\u63A5\u53E3.\u83B7\u5F97\u7C7B\u578B();
32
+ const \u63A5\u53E3\u63D2\u4EF6 = \u63A5\u53E3\u7C7B\u578B.\u83B7\u5F97\u63D2\u4EF6\u4EEC();
33
+ await log.debug("\u627E\u5230 %o \u4E2A \u63D2\u4EF6\uFF0C\u51C6\u5907\u6267\u884C...", \u63A5\u53E3\u63D2\u4EF6.length).run();
34
+ var \u63D2\u4EF6\u7ED3\u679C = seqArrayTask(
35
+ \u63A5\u53E3\u63D2\u4EF6.map((\u63D2\u4EF6) => {
36
+ const \u5B9E\u73B0 = \u63D2\u4EF6.\u83B7\u5F97\u5B9E\u73B0();
37
+ return \u5B9E\u73B0(req, res);
38
+ })
39
+ ).map((a) => a.reduce((s, a2) => Object.assign(s, a2), {}));
40
+ await log.debug("\u63D2\u4EF6 \u6267\u884C\u5B8C\u6BD5").run();
41
+ const \u63A5\u53E3\u5B9E\u73B0 = \u76EE\u6807\u63A5\u53E3.\u83B7\u5F97\u5B9E\u73B0();
42
+ await log.debug("\u51C6\u5907\u6267\u884C\u63A5\u53E3\u903B\u8F91...").run();
43
+ const \u63A5\u53E3\u7ED3\u679C = \u63D2\u4EF6\u7ED3\u679C.bind(\u63A5\u53E3\u5B9E\u73B0);
44
+ await log.debug("\u63A5\u53E3\u903B\u8F91\u6267\u884C\u5B8C\u6BD5").run();
45
+ await log.debug("\u51C6\u5907\u6267\u884C\u8FD4\u56DE\u903B\u8F91...").run();
46
+ (await \u63A5\u53E3\u7ED3\u679C.run()).run(req, res);
47
+ await log.debug("\u8FD4\u56DE\u903B\u8F91\u6267\u884C\u5B8C\u6BD5").run();
48
+ }).tryRun().then((a) => {
49
+ if (a.isLeft()) {
50
+ new Task(async () => {
51
+ await log.err(a.getLeft()).run();
52
+ res.send("\u672A\u77E5\u9519\u8BEF");
53
+ }).run().catch(() => {
54
+ });
55
+ }
56
+ }).catch(() => {
57
+ });
58
+ });
59
+ let server = null;
60
+ if (server === null) {
61
+ throw new Error("\u542F\u52A8\u670D\u52A1\u5668\u5931\u8D25");
62
+ }
63
+ await new Promise((res, _rej) => {
64
+ server = app.listen(this.\u7AEF\u53E3, () => {
65
+ res();
66
+ });
67
+ });
68
+ return {
69
+ ip: Object.values(networkInterfaces()).flat().flatMap((address) => address !== void 0 ? [address] : []).map((wrappedAddress) => wrappedAddress.address).map((address) => `http://${address}:${this.\u7AEF\u53E3}`),
70
+ server
71
+ };
72
+ });
73
+ }
74
+ };
75
+
76
+ export {
77
+ 服务器
78
+ };
@@ -0,0 +1,30 @@
1
+ import {
2
+ 插件
3
+ } from "./chunk-KSZE2DTR.js";
4
+
5
+ // src/plug/urlencoded.ts
6
+ import { format } from "node:util";
7
+ import express from "express";
8
+ import { Task } from "@lsby/ts-fp-data";
9
+ var \u8868\u5355\u89E3\u6790\u63D2\u4EF6 = class extends \u63D2\u4EF6 {
10
+ constructor(t, opt) {
11
+ super(
12
+ t,
13
+ (req, res) => new Task(async () => {
14
+ await new Promise(
15
+ (pRes, _rej) => express.urlencoded({ extended: true, ...opt })(req, res, () => {
16
+ pRes(null);
17
+ })
18
+ );
19
+ const parseResult = t.safeParse({ body: req.body });
20
+ if (!parseResult.success)
21
+ throw new Error(format("parse url encoded body failed: %O", parseResult.error));
22
+ return { body: parseResult.data.body };
23
+ })
24
+ );
25
+ }
26
+ };
27
+
28
+ export {
29
+ 表单解析插件
30
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ GlobalLog
3
+ } from "./chunk-SJCC3KPB.js";
4
+ import {
5
+ 插件
6
+ } from "./chunk-KSZE2DTR.js";
7
+
8
+ // src/plug/json.ts
9
+ import { format } from "node:util";
10
+ import express from "express";
11
+ import { Task } from "@lsby/ts-fp-data";
12
+ var JSON\u89E3\u6790\u63D2\u4EF6 = class extends \u63D2\u4EF6 {
13
+ log = GlobalLog.getInstance();
14
+ constructor(t, opt) {
15
+ super(
16
+ t,
17
+ (req, res) => new Task(async () => {
18
+ var log = (await this.log.run()).extend("JSON\u89E3\u6790\u63D2\u4EF6");
19
+ await new Promise(
20
+ (pRes, _rej) => express.json(opt)(req, res, () => {
21
+ pRes(null);
22
+ })
23
+ );
24
+ await log.debug("\u51C6\u5907\u89E3\u6790 Json\uFF1A%o", req.body).run();
25
+ const parseResult = t.safeParse({ body: req.body });
26
+ if (!parseResult.success) {
27
+ await log.err("\u89E3\u6790 Json \u5931\u8D25\uFF1A%o", parseResult.error).run();
28
+ throw new Error(format("Parse JSON body failed: %O", parseResult.error));
29
+ }
30
+ await log.debug("\u6210\u529F\u89E3\u6790 Json\uFF1A%o", parseResult.data.body).run();
31
+ return { body: parseResult.data.body };
32
+ })
33
+ );
34
+ }
35
+ };
36
+
37
+ export {
38
+ JSON解析插件
39
+ };
@@ -0,0 +1,17 @@
1
+ // src/interface/interface.ts
2
+ var \u63A5\u53E3 = class {
3
+ constructor(\u63A5\u53E3\u7C7B\u578B, \u5B9E\u73B0) {
4
+ this.\u63A5\u53E3\u7C7B\u578B = \u63A5\u53E3\u7C7B\u578B;
5
+ this.\u5B9E\u73B0 = \u5B9E\u73B0;
6
+ }
7
+ \u83B7\u5F97\u7C7B\u578B() {
8
+ return this.\u63A5\u53E3\u7C7B\u578B;
9
+ }
10
+ \u83B7\u5F97\u5B9E\u73B0() {
11
+ return this.\u5B9E\u73B0;
12
+ }
13
+ };
14
+
15
+ export {
16
+ 接口
17
+ };
@@ -0,0 +1,17 @@
1
+ // src/interface/plug.ts
2
+ var \u63D2\u4EF6 = class {
3
+ constructor(\u7C7B\u578B, \u5B9E\u73B0) {
4
+ this.\u7C7B\u578B = \u7C7B\u578B;
5
+ this.\u5B9E\u73B0 = \u5B9E\u73B0;
6
+ }
7
+ \u83B7\u5F97\u7C7B\u578B() {
8
+ return this.\u7C7B\u578B;
9
+ }
10
+ \u83B7\u5F97\u5B9E\u73B0() {
11
+ return this.\u5B9E\u73B0;
12
+ }
13
+ };
14
+
15
+ export {
16
+ 插件
17
+ };
@@ -0,0 +1,24 @@
1
+ // src/tools/get-pro-name.ts
2
+ import { readFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import { Task } from "@lsby/ts-fp-data";
5
+ var GetProName = class {
6
+ proName = null;
7
+ getProName() {
8
+ if (this.proName != null)
9
+ return Task.pure(this.proName);
10
+ return new Task(async () => {
11
+ var jsonStr = readFileSync(resolve(__dirname, "../../package.json"), "utf-8");
12
+ var json = JSON.parse(jsonStr);
13
+ var name = json.name;
14
+ if (name == null)
15
+ throw new Error("\u65E0\u6CD5\u8BFB\u53D6package.json\u4E2D\u7684name\u5B57\u6BB5");
16
+ this.proName = name;
17
+ return name;
18
+ });
19
+ }
20
+ };
21
+
22
+ export {
23
+ GetProName
24
+ };
@@ -0,0 +1,38 @@
1
+ // src/tools/log.ts
2
+ import debugGen from "debug";
3
+ import { Task } from "@lsby/ts-fp-data";
4
+ var Log = class _Log {
5
+ constructor(fileName) {
6
+ this.fileName = fileName;
7
+ this.debugObj = debugGen(fileName);
8
+ this._info = this.debugObj.extend("info");
9
+ this._debug = this.debugObj.extend("debug");
10
+ this._err = this.debugObj.extend("err");
11
+ }
12
+ debugObj;
13
+ _info;
14
+ _debug;
15
+ _err;
16
+ extend(name) {
17
+ return new _Log(`${this.fileName}:${name}`);
18
+ }
19
+ info(formatter, ...args) {
20
+ return new Task(async () => {
21
+ this._info(formatter, ...args);
22
+ });
23
+ }
24
+ debug(formatter, ...args) {
25
+ return new Task(async () => {
26
+ this._debug(formatter, ...args);
27
+ });
28
+ }
29
+ err(formatter, ...args) {
30
+ return new Task(async () => {
31
+ this._err(formatter, ...args);
32
+ });
33
+ }
34
+ };
35
+
36
+ export {
37
+ Log
38
+ };