speed 1.2.2 → 1.3.0

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.
package/README.md CHANGED
@@ -1,2 +1,32 @@
1
1
  # speed
2
- Framework for TypeScript
2
+
3
+ 一个 TypeScript **微服务编排框架**(对标 Spring Cloud),构建于 [typespeed](https://github.com/speedphp/typespeed) 之上。
4
+
5
+ > 关系:`typespeed`(单体框架 = SpringBoot)造应用,`speed`(微服务编排 = SpringCloud)管应用群。
6
+
7
+ ## 快速开始(1.3.0)
8
+
9
+ ```bash
10
+ npm install speed -g
11
+ speed new demo
12
+ cd demo
13
+ npm install
14
+ npm run start # 访问 http://127.0.0.1:8080/health
15
+ ```
16
+
17
+ `speed new` 生成的项目使用 **标准装饰器**(TC39,`experimentalDecorators: false`),入口骨架见 `src/main.ts`。
18
+
19
+ ## 模块(单包 `speed` + 子路径导出)
20
+
21
+ | 子路径 | 模块 | 版本 |
22
+ |---|---|---|
23
+ | `speed/registry` | ① 注册中心 | 1.3.x |
24
+ | `speed/gateway` | ③ API 网关 | 1.4.x |
25
+ | `speed/config` | ② 配置中心 | 1.5.x |
26
+ | `speed/loadbalancer` | ⑤ 负载均衡 | 1.6.x |
27
+ | `speed/circuit-breaker` | ④ 熔断限流 | 1.7.x |
28
+ | `speed/rpc` | ⑥ RPC 客户端 | 1.8.x |
29
+ | `speed/messaging` | ⑧ 消息驱动 | 1.9.x |
30
+ | `speed/observability` | ⑦+⑨ 追踪可观测 | 1.10.x |
31
+
32
+ > 骨架阶段,开发中。开发计划见 speedphp 项目内的 `speed-微服务化开发计划.md` 及各模块计划文件。
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const commander_1 = require("commander");
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const program = new commander_1.Command();
41
+ program
42
+ .name("speed")
43
+ .description("A microservices orchestration framework for TypeScript (the Spring Cloud equivalent, built on typespeed).")
44
+ .version("1.3.0");
45
+ program.command('new <projectName>')
46
+ .description('Create a new speed project.')
47
+ .action((projectName) => {
48
+ const currentDir = process.cwd();
49
+ const appPath = path.join(currentDir, projectName);
50
+ if (fs.existsSync(appPath)) {
51
+ console.error('');
52
+ console.error(` Error: directory "${projectName}" already exists.`);
53
+ console.error('');
54
+ process.exit(1);
55
+ }
56
+ fs.mkdirSync(appPath);
57
+ mkFile("package.json", appPath, projectName);
58
+ mkFile("tsconfig.json", appPath, projectName);
59
+ mkFile(".gitignore", appPath, projectName);
60
+ fs.mkdirSync(path.join(appPath, "src"));
61
+ mkFile("main.ts", path.join(appPath, "src"), projectName);
62
+ mkFile("config.json", path.join(appPath, "src"), projectName);
63
+ console.log('');
64
+ console.log(' Create speed project success!');
65
+ console.log('');
66
+ console.log(' Next steps:');
67
+ console.log(` cd ${projectName}`);
68
+ console.log(' npm install');
69
+ console.log(' npm run start');
70
+ console.log('');
71
+ });
72
+ program.on('--help', () => {
73
+ console.log('');
74
+ console.log(' Examples:');
75
+ console.log('');
76
+ console.log(' $ speed new demo');
77
+ });
78
+ program.parse(process.argv);
79
+ function mkFile(fileName, targetPath, projectName) {
80
+ const tplPath = path.join(__dirname, "templates");
81
+ const fileContents = fs.readFileSync(path.join(tplPath, fileName + ".tpl"), "utf-8");
82
+ fs.writeFileSync(path.join(targetPath, fileName), fileContents.replace(/###appName###/g, projectName));
83
+ }
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ dist/
3
+ *.log
4
+ .DS_Store
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "###appName###"
3
+ }
@@ -0,0 +1,26 @@
1
+ // Symbol.metadata polyfill:Node 22/24/26 均无 Symbol.metadata,
2
+ // 标准装饰器的 context.metadata 依赖它,缺失会 TypeError,必须最先执行。
3
+ (Symbol as { metadata?: symbol }).metadata ??= Symbol("Symbol.metadata");
4
+
5
+ // 骨架阶段直接使用 typespeed 的 @app 引导(speed 的微服务装饰器 @Service 等自 1.3.2 起提供)。
6
+ import { app, autoware, ServerFactory } from "typespeed";
7
+
8
+ /**
9
+ * speed 项目入口骨架(标准装饰器模式)。
10
+ *
11
+ * 目录约定:
12
+ * - 服务类放 src/(本文件即入口);
13
+ * - 配置文件 src/config.json(可选,typespeed 启动时自动读取,可用 config()/@value 访问);
14
+ * - tsconfig.json 已固定标准装饰器(experimentalDecorators:false + esnext.decorators lib)。
15
+ */
16
+ @app
17
+ class Main {
18
+
19
+ @autoware(ServerFactory)
20
+ public server!: ServerFactory;
21
+
22
+ public main() {
23
+ this.server.start(8080);
24
+ console.log("speed service started at http://127.0.0.1:8080");
25
+ }
26
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "###appName###",
3
+ "version": "1.0.0",
4
+ "description": "A speed microservice project (built on typespeed).",
5
+ "scripts": {
6
+ "start": "ts-node --transpile-only src/main.ts",
7
+ "build": "tsc -p .",
8
+ "test": "ts-node --transpile-only src/main.ts"
9
+ },
10
+ "dependencies": {
11
+ "speed": "^1.3.0",
12
+ "typespeed": "^2.6.7"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5.9.3",
16
+ "ts-node": "^10.9.2",
17
+ "@types/node": "^22.0.0"
18
+ }
19
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "module": "commonjs",
5
+ "moduleResolution": "node",
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": false,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "useDefineForClassFields": true,
12
+ "experimentalDecorators": false,
13
+ "emitDecoratorMetadata": false,
14
+ "lib": ["es2022", "esnext.decorators"]
15
+ },
16
+ "include": ["src/**/*.ts"]
17
+ }
package/package.json CHANGED
@@ -1,8 +1,40 @@
1
1
  {
2
2
  "name": "speed",
3
- "version": "1.2.2",
4
- "description": "A new Framework for TypeScript.",
5
- "author": "speed",
6
- "license": "MIT License"
7
-
3
+ "version": "1.3.0",
4
+ "description": "A microservices orchestration framework for TypeScript (the Spring Cloud equivalent, built on typespeed).",
5
+ "author": "speedphp",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
11
+ "./registry": { "types": "./dist/registry/index.d.ts", "default": "./dist/registry/index.js" },
12
+ "./gateway": { "types": "./dist/gateway/index.d.ts", "default": "./dist/gateway/index.js" },
13
+ "./config": { "types": "./dist/config/index.d.ts", "default": "./dist/config/index.js" },
14
+ "./loadbalancer": { "types": "./dist/loadbalancer/index.d.ts", "default": "./dist/loadbalancer/index.js" },
15
+ "./circuit-breaker": { "types": "./dist/circuit-breaker/index.d.ts", "default": "./dist/circuit-breaker/index.js" },
16
+ "./rpc": { "types": "./dist/rpc/index.d.ts", "default": "./dist/rpc/index.js" },
17
+ "./messaging": { "types": "./dist/messaging/index.d.ts", "default": "./dist/messaging/index.js" },
18
+ "./observability": { "types": "./dist/observability/index.d.ts", "default": "./dist/observability/index.js" }
19
+ },
20
+ "bin": {
21
+ "speed": "dist/scaffold/command.js"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "dependencies": {
27
+ "typespeed": "^2.6.7",
28
+ "commander": "^9.5.0"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.9.3",
32
+ "@types/node": "^22.0.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p .",
36
+ "prebuild": "rm -rf dist",
37
+ "postbuild": "cp -r src/scaffold/templates dist/scaffold/templates",
38
+ "clean": "rm -rf dist"
39
+ }
8
40
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 speed
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.