Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ website/src/zh/api/dart_node_react/
website/src/zh/api/dart_node_react_native/
website/src/zh/api/dart_node_ws/
website/src/zh/api/dart_node_better_sqlite3/
website/src/zh/api/dart_node_sql_js/
website/src/zh/api/dart_node_mcp/
website/src/zh/api/dart_logging/
website/src/zh/api/reflux/
Expand Down
9 changes: 5 additions & 4 deletions packages/dart_logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pino-style structured logging with child loggers. Provides hierarchical logging

```yaml
dependencies:
dart_logging: ^0.11.0-beta
dart_logging: ^0.13.0-beta
```

## Quick Start
Expand Down Expand Up @@ -81,9 +81,10 @@ This is useful for adding context that applies to a scope (like a request handle
Create custom transports to send logs to different destinations:

```dart
void myTransport(LogEntry entry) {
void myTransport(LogMessage message, LogLevel minimumLogLevel) {
if (message.logLevel.index < minimumLogLevel.index) return;
// Send to external service, file, etc.
print('${entry.level}: ${entry.message}');
print('${message.logLevel}: ${message.message}');
}

final context = createLoggingContext(
Expand Down Expand Up @@ -119,4 +120,4 @@ void main() {

## Source Code

The source code is available on [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_logging).
The source code is available on [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_logging).
8 changes: 4 additions & 4 deletions packages/dart_logging/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pino 风格的结构化日志,支持子日志器。提供具有自动上下文

```yaml
dependencies:
dart_logging: ^0.11.0-beta
dart_logging: ^0.13.0-beta
```

## 快速开始
Expand Down Expand Up @@ -81,9 +81,9 @@ userLogger.info('Action'); // 同时包含 requestId 和 userId
创建自定义传输以将日志发送到不同目的地:

```dart
void myTransport(LogEntry entry) {
void myTransport(LogMessage message, LogLevel minimumLogLevel) {
// 发送到外部服务、文件等
print('${entry.level}: ${entry.message}');
print('${message.logLevel}: ${message.message}');
}

final context = createLoggingContext(
Expand Down Expand Up @@ -119,4 +119,4 @@ void main() {

## 源代码

源代码可在 [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_logging) 上获取。
源代码可在 [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_logging) 上获取。
37 changes: 25 additions & 12 deletions packages/dart_node_better_sqlite3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Typed Dart bindings for [better-sqlite3](https://github.com/WiseLibs/better-sqli

```yaml
dependencies:
dart_node_better_sqlite3: ^0.11.0-beta
nadz: ^0.9.0
dart_node_better_sqlite3: ^0.13.0-beta
nadz: ^0.0.7-beta
```

Also install the npm package:
Expand Down Expand Up @@ -41,7 +41,10 @@ void main() {
Error(:final error) => throw Exception(error),
};

final rows = query.all([]);
final rows = switch (query.all()) {
Success(:final value) => value,
Error(:final error) => throw Exception(error),
};
print(rows);

db.close();
Expand Down Expand Up @@ -93,22 +96,32 @@ final query = switch (db.prepare('SELECT * FROM users WHERE id = ?')) {
};

// Get single row
final row = query.get([1]);
final row = switch (query.get([1])) {
Success(:final value) => value,
Error(:final error) => throw Exception(error),
};

// Get all rows
final allRows = query.all([]);
final allRows = switch (query.all()) {
Success(:final value) => value,
Error(:final error) => throw Exception(error),
};
```

### Transactions

```dart
db.exec('BEGIN');
try {
// Multiple operations...
db.exec('COMMIT');
} catch (e) {
db.exec('ROLLBACK');
rethrow;

// Multiple operations...
final result = db.exec('INSERT INTO users (name) VALUES (?)');

switch (result) {
case Success():
db.exec('COMMIT');
case Error(:final error):
db.exec('ROLLBACK');
throw Exception(error);
}
```

Expand All @@ -124,4 +137,4 @@ node app.js

## Source Code

The source code is available on [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_node_better_sqlite3).
The source code is available on [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_node_better_sqlite3).
6 changes: 3 additions & 3 deletions packages/dart_node_better_sqlite3/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

```yaml
dependencies:
dart_node_better_sqlite3: ^0.11.0-beta
nadz: ^0.9.0
dart_node_better_sqlite3: ^0.13.0-beta
nadz: ^0.0.7-beta
```

通过 npm 安装:
Expand Down Expand Up @@ -124,4 +124,4 @@ node app.js

## 源代码

源代码可在 [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_node_better_sqlite3) 上获取。
源代码可在 [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_node_better_sqlite3) 上获取。
4 changes: 2 additions & 2 deletions packages/dart_node_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

```yaml
dependencies:
dart_node_core: ^0.11.0-beta
dart_node_core: ^0.13.0-beta
```

## Core Utilities
Expand Down Expand Up @@ -90,4 +90,4 @@ void main() {

## Source Code

The source code is available on [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_node_core).
The source code is available on [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_node_core).
4 changes: 2 additions & 2 deletions packages/dart_node_core/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

```yaml
dependencies:
dart_node_core: ^0.11.0-beta
dart_node_core: ^0.13.0-beta
```

## 核心工具
Expand Down Expand Up @@ -90,4 +90,4 @@ void main() {

## 源代码

源代码可在 [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_node_core) 上获取。
源代码可在 [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_node_core) 上获取。
36 changes: 25 additions & 11 deletions packages/dart_node_express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Type-safe Express.js bindings for Dart. Build HTTP servers and REST APIs entirel

```yaml
dependencies:
dart_node_express: ^0.11.0-beta
dart_node_express: ^0.13.0-beta
```

Also install Express via npm:
Expand Down Expand Up @@ -50,7 +50,7 @@ app.post('/users', handler((req, res) {
}));

app.put('/users/:id', handler((req, res) {
final id = req.params['id'];
final id = req.params['id'].toString();
res.jsonMap({'updated': id});
}));

Expand All @@ -64,8 +64,8 @@ app.delete('/users/:id', handler((req, res) {

```dart
app.get('/users/:userId/posts/:postId', handler((req, res) {
final userId = req.params['userId'];
final postId = req.params['postId'];
final userId = req.params['userId'].toString();
final postId = req.params['postId'].toString();

res.jsonMap({
'userId': userId,
Expand All @@ -78,8 +78,8 @@ app.get('/users/:userId/posts/:postId', handler((req, res) {

```dart
app.get('/search', handler((req, res) {
final query = req.query['q'];
final page = int.tryParse(req.query['page'] ?? '1') ?? 1;
final query = req.query['q']?.toString();
final page = int.tryParse(req.query['page']?.toString() ?? '1') ?? 1;

res.jsonMap({
'query': query,
Expand All @@ -98,7 +98,7 @@ app.post('/api/data', handler((req, res) {
final body = req.body;

// Headers
final contentType = req.headers['content-type'];
final contentType = req.headers['content-type']?.toString();

// URL path
final path = req.path;
Expand Down Expand Up @@ -188,6 +188,10 @@ app.get('/profile', handler((req, res) {
Organize routes with the Router:

```dart
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'package:dart_node_express/dart_node_express.dart';

Router createUserRouter() {
final router = Router();

Expand All @@ -201,18 +205,28 @@ Router createUserRouter() {
}));

router.get('/:id', handler((req, res) {
res.jsonMap({'user': req.params['id']});
res.jsonMap({'user': req.params['id'].toString()});
}));

return router;
}

// Mount a Router at a path. Express Routers are callable middleware,
// and `use` accepts a path (as JSAny?) plus a middleware JSFunction.
void mountRouter(ExpressApp app, String path, Router router) {
final routerFn = switch (router as JSAny) {
final JSFunction f => f,
_ => throw StateError('Router is not callable'),
};
app.use(path.toJS, routerFn);
}

void main() {
final app = express();

// Mount the router
final router = createUserRouter();
app.use('/api/users', router);
mountRouter(app, '/api/users', router);

app.listen(3000);
}
Expand Down Expand Up @@ -312,7 +326,7 @@ void main() {
}));

// Mount routers
app.use('/api/users', createUserRouter());
mountRouter(app, '/api/users', createUserRouter());

// Start server
app.listen(3000, () {
Expand All @@ -323,4 +337,4 @@ void main() {

## Source Code

The source code is available on [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_node_express).
The source code is available on [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_node_express).
26 changes: 15 additions & 11 deletions packages/dart_node_express/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

```yaml
dependencies:
dart_node_express: ^0.11.0-beta
dart_node_express: ^0.13.0-beta
```

通过 npm 安装 Express:
Expand Down Expand Up @@ -50,7 +50,7 @@ app.post('/users', handler((req, res) {
}));

app.put('/users/:id', handler((req, res) {
final id = req.params['id'];
final id = req.params['id'].toString();
res.jsonMap({'updated': id});
}));

Expand All @@ -64,8 +64,8 @@ app.delete('/users/:id', handler((req, res) {

```dart
app.get('/users/:userId/posts/:postId', handler((req, res) {
final userId = req.params['userId'];
final postId = req.params['postId'];
final userId = req.params['userId'].toString();
final postId = req.params['postId'].toString();

res.jsonMap({
'userId': userId,
Expand All @@ -78,8 +78,8 @@ app.get('/users/:userId/posts/:postId', handler((req, res) {

```dart
app.get('/search', handler((req, res) {
final query = req.query['q'];
final page = int.tryParse(req.query['page'] ?? '1') ?? 1;
final query = req.query['q'].toString();
final page = int.tryParse(req.query['page']?.toString() ?? '1') ?? 1;

res.jsonMap({
'query': query,
Expand All @@ -98,7 +98,7 @@ app.post('/api/data', handler((req, res) {
final body = req.body;

// 请求头
final contentType = req.headers['content-type'];
final contentType = req.headers['content-type'].toString();

// URL 路径
final path = req.path;
Expand Down Expand Up @@ -201,7 +201,7 @@ Router createUserRouter() {
}));

router.get('/:id', handler((req, res) {
res.jsonMap({'user': req.params['id']});
res.jsonMap({'user': req.params['id'].toString()});
}));

return router;
Expand All @@ -212,7 +212,9 @@ void main() {

// 挂载路由器
final router = createUserRouter();
app.use('/api/users', router);
if (router case final JSFunction fn) {
app.use('/api/users'.toJS, fn);
}

app.listen(3000);
}
Expand Down Expand Up @@ -312,7 +314,9 @@ void main() {
}));

// 挂载路由器
app.use('/api/users', createUserRouter());
if (createUserRouter() case final JSFunction fn) {
app.use('/api/users'.toJS, fn);
}

// 启动服务器
app.listen(3000, () {
Expand All @@ -323,4 +327,4 @@ void main() {

## 源代码

源代码可在 [GitHub](https://github.com/melbournedeveloper/dart_node/tree/main/packages/dart_node_express) 上获取。
源代码可在 [GitHub](https://github.com/MelbourneDeveloper/dart_node/tree/main/packages/dart_node_express) 上获取。
Loading
Loading