-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update ioc,backend package;add rpc protocoll package;add cache …
…& config module;update docs
- Loading branch information
Showing
63 changed files
with
1,021 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"farmfe", | ||
"flexable", | ||
"Inversify", | ||
"jexl", | ||
"linkcode", | ||
"Naily", | ||
"nailyjs", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
{ | ||
"hash": "1cdb2662", | ||
"hash": "e6fe7b68", | ||
"configHash": "6bb8cdf2", | ||
"lockfileHash": "f84ebc7b", | ||
"browserHash": "32d6c109", | ||
"lockfileHash": "4a58e439", | ||
"browserHash": "30c24cb6", | ||
"optimized": { | ||
"vue": { | ||
"src": "../../../../node_modules/.pnpm/[email protected][email protected]/node_modules/vue/dist/vue.runtime.esm-bundler.js", | ||
"file": "vue.js", | ||
"fileHash": "2029d163", | ||
"fileHash": "0114871d", | ||
"needsInterop": false | ||
}, | ||
"vitepress > @vue/devtools-api": { | ||
"src": "../../../../node_modules/.pnpm/@[email protected]/node_modules/@vue/devtools-api/dist/index.js", | ||
"file": "vitepress___@vue_devtools-api.js", | ||
"fileHash": "02f5f3ec", | ||
"fileHash": "cec2fd64", | ||
"needsInterop": false | ||
}, | ||
"vitepress > @vueuse/core": { | ||
"src": "../../../../node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@vueuse/core/index.mjs", | ||
"file": "vitepress___@vueuse_core.js", | ||
"fileHash": "b0f77eba", | ||
"fileHash": "75c9c5c6", | ||
"needsInterop": false | ||
}, | ||
"@shikijs/vitepress-twoslash/client": { | ||
"src": "../../../../node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@shikijs/vitepress-twoslash/dist/client.mjs", | ||
"file": "@shikijs_vitepress-twoslash_client.js", | ||
"fileHash": "bb186c04", | ||
"fileHash": "43aaa425", | ||
"needsInterop": false | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 指南 | ||
|
||
Naily.js的核心是一个以`IOC`(即控制反转)为核心的框架,它的目标是提供一个`轻量级` `易扩展`的毛坯房,让你可以根据自己的需求来进行装修。 | ||
|
||
## 捆绑包大小 | ||
|
||
你可以使用[pkg-size.dev](https://pkg-size.dev/)来查看捆绑包的大小。 | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>捆绑包</th> | ||
<th>安装大小</th> | ||
<th>捆绑包大小</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>核心容器</td> | ||
<td><a href="https://pkg-size.dev/@nailyjs/ioc"><img src="https://pkg-size.dev/badge/install/383266" title="Install size for @nailyjs/ioc"></a></td> | ||
<td><a href="https://pkg-size.dev/@nailyjs/ioc"><img src="https://pkg-size.dev/badge/bundle/20331" title="Bundle size for @nailyjs/ioc"></a></td> | ||
</tr> | ||
<tr> | ||
<td>后端支持</td> | ||
<td><a href="https://pkg-size.dev/@nailyjs/backend"><img src="https://pkg-size.dev/badge/install/383266" title="Install size for @nailyjs/ioc-backend"></a></td> | ||
<td><a href="https://pkg-size.dev/@nailyjs/backend"><img src="https://pkg-size.dev/badge/bundle/20331" title="Bundle size for @nailyjs/backend"></a></td> | ||
</tr> | ||
<tr> | ||
<td>RPC支持</td> | ||
<td><a href="https://pkg-size.dev/@nailyjs/rpc"><img src="https://pkg-size.dev/badge/install/383266" title="Install size for @nailyjs/rpc"></a></td> | ||
<td><a href="https://pkg-size.dev/@nailyjs/rpc"><img src="https://pkg-size.dev/badge/bundle/20331" title="Bundle size for @nailyjs/rpc"></a></td> | ||
</tr> | ||
<tr> | ||
<td>unplugin-rpc插件</td> | ||
<td><a href="https://pkg-size.dev/unplugin-rpc"><img src="https://pkg-size.dev/badge/install/383266" title="Install size for unplugin-rpc"></a></td> | ||
<td><a href="https://pkg-size.dev/unplugin-rpc"><img src="https://pkg-size.dev/badge/bundle/20331" title="Bundle size for unplugin-rpc"></a></td> | ||
</tr> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Restful 指南 | ||
|
||
传统的Restful API同样受Naily.js支持。和`Spring`/`Cell.js`/`Nest.js`/`Midway.js`等一众`IOC框架`一样,Naily.js也提供了一套`Restful`的编程模型。 | ||
|
||
::: tip 注意 | ||
虽然Naily.js支持Restful API,但是我们更主推`Naily RPC`。Restful的理念长久以来一直受到争议,如果是新项目,我们更推荐使用`Naily RPC`,方便快捷创建全栈应用。 | ||
::: | ||
|
||
## 创建 Restful API | ||
|
||
类似其他的`IOC`框架,我们可以通过 `@RestController` `@Get` 等来创建一个Restful API。 | ||
|
||
```typescript twoslash | ||
// welcome.controller.ts | ||
import { Get, RestController } from '@nailyjs/backend' | ||
|
||
@RestController() | ||
export class UserController { | ||
@Get() | ||
getUsers() { | ||
return 'Hello, World!' | ||
} | ||
} | ||
``` | ||
|
||
## 启动应用程序 | ||
|
||
`naily.js`内部参考`nest.js`的架构提供了一个`Adapter`,但是这个`Adapter`架构默认不和`nest.js`一样用来切换`express`/`fastify`等底层框架,而是用来切换`node.js`/`bun`/`deno`等运行时环境的。 | ||
|
||
比如下面一个例子,我们从`@nailyjs/backend`的分包`node-adapter`中导入`NodeBootstrap`,就可以在`node.js`环境下创建一个`HTTP`服务器并启动它了。 | ||
|
||
```typescript twoslash | ||
// main.ts | ||
import { NodeBootstrap } from '@nailyjs/backend/node-adapter' | ||
import './welcome.controller' | ||
|
||
new NodeBootstrap() | ||
.run(3000) | ||
.then(() => console.log(`Backend started on port http://localhost:3000`)) | ||
``` | ||
|
||
创建好了服务器,我们需要导入刚刚我们在`welcome.controller.ts`中创建的`UserController`,这样我们的`UserController`才能被`NodeBootstrap`扫描到。 | ||
|
||
::: tip | ||
目前`naily.js`只支持`node.js`环境,后续会支持更多的运行时环境,如`bun`等。 | ||
|
||
以后我们会提供更多的`Adapter`,比如`node-express-adapter`/`node-fastify-adapter`等,但是大概率不会封装在`@nailyjs/backend`中,而是单独的分包。 | ||
::: | ||
|
||
同样这里也是参考了`cell.js`的机制,但是启动器这块比`cell.js`的`export default autoBind()`更加的透明,不会让初学者抓不着头脑。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
hello: 'world', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "backend", | ||
"type": "module", | ||
"version": "0.0.4", | ||
"private": true, | ||
"description": "The backend fixture", | ||
"author": "Naily Zero <[email protected]> (https://naily.cc)", | ||
"scripts": { | ||
"build": "tsup", | ||
"watch": "tsup -w", | ||
"dev": "tsup && node dist/main.js" | ||
}, | ||
"dependencies": { | ||
"@nailyjs/backend": "workspace:*", | ||
"@nailyjs/config": "workspace:*", | ||
"@nailyjs/ioc": "workspace:*", | ||
"@nailyjs/jexl": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"tsup": "^8.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NodeBootstrap } from '@nailyjs/backend/node-adapter' | ||
import { Configuration } from '@nailyjs/config' | ||
import './test.controller' | ||
import './test.filter' | ||
|
||
new NodeBootstrap() | ||
.use(Configuration()) | ||
.then(bootstrap => bootstrap.run(3000)) | ||
.then(() => console.log(`Backend started on port http://localhost:3000`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable ts/consistent-type-imports */ | ||
|
||
import { Get, RestController } from '@nailyjs/backend' | ||
import { Value } from '@nailyjs/config' | ||
import { Autowired } from '@nailyjs/ioc' | ||
import { JexlExecutor } from '@nailyjs/jexl' | ||
|
||
@RestController() | ||
export class TestController { | ||
@Value('1 + 1') | ||
private readonly hello: string | ||
|
||
@Autowired() | ||
private readonly jexl: JexlExecutor | ||
|
||
@Get() | ||
getString(): string { | ||
return 'Hello World' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Catch, Filter } from '@nailyjs/ioc' | ||
|
||
@Filter() | ||
export class TestFilter { | ||
@Catch() | ||
catch(error: unknown): void { | ||
console.log('catch error', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "ES2022", | ||
"moduleResolution": "Bundler" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from 'tsup' | ||
|
||
export default defineConfig({ | ||
entry: { | ||
main: './src/main.ts', | ||
}, | ||
dts: true, | ||
sourcemap: true, | ||
clean: true, | ||
format: ['cjs', 'esm'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.