@hazejs/core 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present hazejs contributors
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.
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
1
+ # @hazejs/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The hazejs runtime: application lifecycle, IoC container, routing, middleware, exception handling, validation, auth & authorization, sessions, cache, queues, scheduler, events, WebSocket, file storage and mail — on top of [h3 v2](https://h3.dev).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @hazejs/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createApplication, defineRoutes } from '@hazejs/core'
15
+
16
+ const app = await createApplication({
17
+ routes: [
18
+ defineRoutes(r => r.get('/hello', () => ({ message: 'Hello, hazejs!' })))
19
+ ],
20
+ })
21
+ app.serve({ port: 3000 })
22
+ ```
23
+
24
+ Most projects use it through the `haze` CLI or the Vite plugin, which discover `app/`, `config/` and `route/` automatically. Optional drivers are peer dependencies — install only what you use (`ioredis`, `bullmq`, `@upstash/redis`, `nodemailer`, `@aws-sdk/client-s3`, …).
25
+
26
+ Part of [hazejs](https://github.com/penna-org/haze) — see the main README for documentation.
27
+
28
+ ## License
29
+
30
+ [MIT](./LICENSE)
@@ -0,0 +1,20 @@
1
+ export interface WebSocketDurableObjectOptions {
2
+ /** 应用的请求处理(在 DO 中解析升级请求的钩子,含中间件) */
3
+ fetch: (request: Request) => Promise<Response>;
4
+ /** 注册 Workers 绑定(DO 构造时调用) */
5
+ bind: (env: unknown) => void;
6
+ /** wrangler.json 中 durable_objects 的绑定名,默认 HAZE_WEBSOCKET */
7
+ bindingName?: string;
8
+ }
9
+ /**
10
+ * Cloudflare Workers 的 WebSocket(crossws + Durable Object):所有连接在同一个 DO 中,
11
+ * 订阅与广播全局生效;Socket.publish 在 Worker 中经 RPC 转发到 DO。
12
+ * cloudflare 预设的入口自动使用,`@hazejs/core/cloudflare` 只能在 Workers 中导入。
13
+ */
14
+ export interface WebSocketDurableObject {
15
+ /** Worker 的 fetch 中:升级请求交给 DO */
16
+ handleUpgrade: (request: Request, env: unknown, ctx: unknown) => Promise<Response>;
17
+ /** 由入口以 wrangler.json 中的 class_name 导出 */
18
+ HazeWebSocket: abstract new (state: DurableObjectState, env: unknown) => unknown;
19
+ }
20
+ export declare function createWebSocketDurableObject(options: WebSocketDurableObjectOptions): WebSocketDurableObject;
@@ -0,0 +1,35 @@
1
+ import { a as resolveHooks, i as registerWebSocketAdapter } from "../server-DrbXmvBq.mjs";
2
+ import { DurableObject } from "cloudflare:workers";
3
+ import cloudflareAdapter from "crossws/adapters/cloudflare";
4
+ // src/adapters/cloudflare.ts
5
+ function createWebSocketDurableObject(options) {
6
+ const ws = cloudflareAdapter({
7
+ bindingName: options.bindingName ?? "HAZE_WEBSOCKET",
8
+ resolve: resolveHooks(options.fetch)
9
+ });
10
+ registerWebSocketAdapter(ws);
11
+ class HazeWebSocket extends DurableObject {
12
+ constructor(state, env) {
13
+ super(state, env);
14
+ options.bind(env);
15
+ ws.handleDurableInit(this, state, env);
16
+ }
17
+ fetch(request) {
18
+ return ws.handleDurableUpgrade(this, request);
19
+ }
20
+ webSocketMessage(client, message) {
21
+ return ws.handleDurableMessage(this, client, message);
22
+ }
23
+ webSocketPublish(topic, data, publishOptions) {
24
+ return ws.handleDurablePublish(this, topic, data, publishOptions);
25
+ }
26
+ webSocketClose(client, code, reason, wasClean) {
27
+ return ws.handleDurableClose(this, client, code, reason, wasClean);
28
+ }
29
+ }
30
+ return {
31
+ handleUpgrade: (request, env, ctx) => ws.handleUpgrade(request, env, ctx),
32
+ HazeWebSocket
33
+ };
34
+ }
35
+ export { createWebSocketDurableObject };