@planet-matrix/mobius-model 0.5.0 → 0.9.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/CHANGELOG.md +61 -0
- package/README.md +123 -36
- package/dist/index.js +715 -4
- package/dist/index.js.map +981 -13
- package/oxlint.config.ts +6 -0
- package/package.json +36 -18
- package/src/abort/README.md +92 -0
- package/src/abort/abort-manager.ts +278 -0
- package/src/abort/abort-signal-listener-manager.ts +81 -0
- package/src/abort/index.ts +2 -0
- package/src/ai/README.md +1 -0
- package/src/ai/ai.ts +107 -0
- package/src/ai/chat-completion-ai/aihubmix-chat-completion.ts +78 -0
- package/src/ai/chat-completion-ai/chat-completion-ai.ts +270 -0
- package/src/ai/chat-completion-ai/chat-completion.ts +189 -0
- package/src/ai/chat-completion-ai/index.ts +7 -0
- package/src/ai/chat-completion-ai/lingyiwanwu-chat-completion.ts +78 -0
- package/src/ai/chat-completion-ai/ohmygpt-chat-completion.ts +78 -0
- package/src/ai/chat-completion-ai/openai-next-chat-completion.ts +78 -0
- package/src/ai/embedding-ai/embedding-ai.ts +63 -0
- package/src/ai/embedding-ai/embedding.ts +50 -0
- package/src/ai/embedding-ai/index.ts +4 -0
- package/src/ai/embedding-ai/openai-next-embedding.ts +23 -0
- package/src/ai/index.ts +4 -0
- package/src/aio/README.md +100 -0
- package/src/aio/content.ts +141 -0
- package/src/aio/index.ts +3 -0
- package/src/aio/json.ts +127 -0
- package/src/aio/prompt.ts +246 -0
- package/src/basic/README.md +72 -116
- package/src/basic/error.ts +19 -5
- package/src/basic/function.ts +83 -64
- package/src/basic/index.ts +1 -0
- package/src/basic/is.ts +152 -71
- package/src/basic/promise.ts +29 -8
- package/src/basic/schedule.ts +111 -0
- package/src/basic/stream.ts +135 -25
- package/src/basic/string.ts +2 -33
- package/src/color/README.md +105 -0
- package/src/color/index.ts +3 -0
- package/src/color/internal.ts +42 -0
- package/src/color/rgb/analyze.ts +236 -0
- package/src/color/rgb/construct.ts +130 -0
- package/src/color/rgb/convert.ts +227 -0
- package/src/color/rgb/derive.ts +303 -0
- package/src/color/rgb/index.ts +6 -0
- package/src/color/rgb/internal.ts +208 -0
- package/src/color/rgb/parse.ts +302 -0
- package/src/color/rgb/serialize.ts +144 -0
- package/src/color/types.ts +57 -0
- package/src/color/xyz/analyze.ts +80 -0
- package/src/color/xyz/construct.ts +19 -0
- package/src/color/xyz/convert.ts +71 -0
- package/src/color/xyz/index.ts +3 -0
- package/src/color/xyz/internal.ts +23 -0
- package/src/credential/README.md +107 -0
- package/src/credential/api-key.ts +158 -0
- package/src/credential/bearer.ts +73 -0
- package/src/credential/index.ts +4 -0
- package/src/credential/json-web-token.ts +96 -0
- package/src/credential/password.ts +170 -0
- package/src/cron/README.md +86 -0
- package/src/cron/cron.ts +87 -0
- package/src/cron/index.ts +1 -0
- package/src/css/README.md +93 -0
- package/src/css/class.ts +559 -0
- package/src/css/index.ts +1 -0
- package/src/drizzle/README.md +1 -0
- package/src/drizzle/drizzle.ts +1 -0
- package/src/drizzle/helper.ts +47 -0
- package/src/drizzle/index.ts +5 -0
- package/src/drizzle/infer.ts +52 -0
- package/src/drizzle/kysely.ts +8 -0
- package/src/drizzle/pagination.ts +200 -0
- package/src/email/README.md +1 -0
- package/src/email/index.ts +1 -0
- package/src/email/resend.ts +25 -0
- package/src/encoding/README.md +66 -79
- package/src/encoding/base64.ts +13 -4
- package/src/environment/README.md +97 -0
- package/src/environment/basic.ts +26 -0
- package/src/environment/device.ts +311 -0
- package/src/environment/feature.ts +285 -0
- package/src/environment/geo.ts +337 -0
- package/src/environment/index.ts +7 -0
- package/src/environment/runtime.ts +400 -0
- package/src/environment/snapshot.ts +60 -0
- package/src/environment/variable.ts +239 -0
- package/src/event/README.md +90 -0
- package/src/event/class-event-proxy.ts +229 -0
- package/src/event/common.ts +29 -0
- package/src/event/event-manager.ts +203 -0
- package/src/event/index.ts +4 -0
- package/src/event/instance-event-proxy.ts +187 -0
- package/src/event/internal.ts +24 -0
- package/src/exception/README.md +96 -0
- package/src/exception/browser.ts +219 -0
- package/src/exception/index.ts +4 -0
- package/src/exception/nodejs.ts +169 -0
- package/src/exception/normalize.ts +106 -0
- package/src/exception/types.ts +99 -0
- package/src/form/README.md +25 -0
- package/src/form/index.ts +1 -0
- package/src/form/inputor-controller/base.ts +874 -0
- package/src/form/inputor-controller/boolean.ts +39 -0
- package/src/form/inputor-controller/file.ts +39 -0
- package/src/form/inputor-controller/form.ts +181 -0
- package/src/form/inputor-controller/helper.ts +117 -0
- package/src/form/inputor-controller/index.ts +17 -0
- package/src/form/inputor-controller/multi-select.ts +99 -0
- package/src/form/inputor-controller/number.ts +116 -0
- package/src/form/inputor-controller/select.ts +109 -0
- package/src/form/inputor-controller/text.ts +82 -0
- package/src/http/READMD.md +1 -0
- package/src/http/api/api-core.ts +84 -0
- package/src/http/api/api-handler.ts +79 -0
- package/src/http/api/api-host.ts +47 -0
- package/src/http/api/api-result.ts +56 -0
- package/src/http/api/api-schema.ts +154 -0
- package/src/http/api/api-server.ts +130 -0
- package/src/http/api/api-test.ts +142 -0
- package/src/http/api/api-type.ts +37 -0
- package/src/http/api/api.ts +81 -0
- package/src/http/api/index.ts +11 -0
- package/src/http/api-adapter/api-core-node-http.ts +260 -0
- package/src/http/api-adapter/api-host-node-http.ts +156 -0
- package/src/http/api-adapter/api-result-arktype.ts +297 -0
- package/src/http/api-adapter/api-result-zod.ts +286 -0
- package/src/http/api-adapter/index.ts +5 -0
- package/src/http/bin/gen-api-list/gen-api-list.ts +126 -0
- package/src/http/bin/gen-api-list/index.ts +1 -0
- package/src/http/bin/gen-api-test/gen-api-test.ts +136 -0
- package/src/http/bin/gen-api-test/index.ts +1 -0
- package/src/http/bin/gen-api-type/calc-code.ts +25 -0
- package/src/http/bin/gen-api-type/gen-api-type.ts +127 -0
- package/src/http/bin/gen-api-type/index.ts +2 -0
- package/src/http/bin/index.ts +2 -0
- package/src/http/index.ts +3 -0
- package/src/huawei/README.md +1 -0
- package/src/huawei/index.ts +2 -0
- package/src/huawei/moderation/index.ts +1 -0
- package/src/huawei/moderation/moderation.ts +355 -0
- package/src/huawei/obs/esdk-obs-nodejs.d.ts +87 -0
- package/src/huawei/obs/index.ts +1 -0
- package/src/huawei/obs/obs.ts +42 -0
- package/src/identifier/README.md +92 -0
- package/src/identifier/id.ts +119 -0
- package/src/identifier/index.ts +2 -0
- package/src/identifier/uuid.ts +187 -0
- package/src/index.ts +33 -1
- package/src/json/README.md +92 -0
- package/src/json/index.ts +1 -0
- package/src/json/repair.ts +18 -0
- package/src/log/README.md +79 -0
- package/src/log/index.ts +5 -0
- package/src/log/log-emitter.ts +72 -0
- package/src/log/log-record.ts +10 -0
- package/src/log/log-scheduler.ts +74 -0
- package/src/log/log-type.ts +8 -0
- package/src/log/logger.ts +554 -0
- package/src/openai/README.md +1 -0
- package/src/openai/index.ts +1 -0
- package/src/openai/openai.ts +510 -0
- package/src/orchestration/README.md +91 -0
- package/src/orchestration/coordination/barrier.ts +214 -0
- package/src/orchestration/coordination/count-down-latch.ts +215 -0
- package/src/orchestration/coordination/errors.ts +98 -0
- package/src/orchestration/coordination/index.ts +16 -0
- package/src/orchestration/coordination/internal/wait-constraints.ts +95 -0
- package/src/orchestration/coordination/internal/wait-queue.ts +109 -0
- package/src/orchestration/coordination/keyed-lock.ts +168 -0
- package/src/orchestration/coordination/mutex.ts +257 -0
- package/src/orchestration/coordination/permit.ts +127 -0
- package/src/orchestration/coordination/read-write-lock.ts +444 -0
- package/src/orchestration/coordination/semaphore.ts +280 -0
- package/src/orchestration/dispatching/dispatcher.ts +83 -0
- package/src/orchestration/dispatching/index.ts +2 -0
- package/src/orchestration/dispatching/selector/base-selector.ts +39 -0
- package/src/orchestration/dispatching/selector/down-count-selector.ts +119 -0
- package/src/orchestration/dispatching/selector/index.ts +2 -0
- package/src/orchestration/index.ts +3 -0
- package/src/orchestration/scheduling/index.ts +2 -0
- package/src/orchestration/scheduling/scheduler.ts +103 -0
- package/src/orchestration/scheduling/task.ts +32 -0
- package/src/random/README.md +56 -86
- package/src/random/base.ts +66 -0
- package/src/random/index.ts +5 -1
- package/src/random/random-boolean.ts +40 -0
- package/src/random/random-integer.ts +60 -0
- package/src/random/random-number.ts +72 -0
- package/src/random/random-string.ts +66 -0
- package/src/reactor/README.md +4 -0
- package/src/reactor/reactor-core/primitive.ts +9 -9
- package/src/reactor/reactor-core/reactive-system.ts +5 -5
- package/src/request/README.md +108 -0
- package/src/request/fetch/base.ts +108 -0
- package/src/request/fetch/browser.ts +285 -0
- package/src/request/fetch/general.ts +20 -0
- package/src/request/fetch/index.ts +4 -0
- package/src/request/fetch/nodejs.ts +285 -0
- package/src/request/index.ts +2 -0
- package/src/request/request/base.ts +250 -0
- package/src/request/request/general.ts +64 -0
- package/src/request/request/index.ts +3 -0
- package/src/request/request/resource.ts +68 -0
- package/src/result/README.md +4 -0
- package/src/result/controller.ts +54 -0
- package/src/result/either.ts +193 -0
- package/src/result/index.ts +2 -0
- package/src/route/README.md +105 -0
- package/src/route/adapter/browser.ts +122 -0
- package/src/route/adapter/driver.ts +56 -0
- package/src/route/adapter/index.ts +2 -0
- package/src/route/index.ts +3 -0
- package/src/route/router/index.ts +2 -0
- package/src/route/router/route.ts +630 -0
- package/src/route/router/router.ts +1642 -0
- package/src/route/uri/hash.ts +308 -0
- package/src/route/uri/index.ts +7 -0
- package/src/route/uri/pathname.ts +376 -0
- package/src/route/uri/search.ts +413 -0
- package/src/singleton/README.md +79 -0
- package/src/singleton/factory.ts +55 -0
- package/src/singleton/index.ts +2 -0
- package/src/singleton/manager.ts +204 -0
- package/src/socket/README.md +105 -0
- package/src/socket/client/index.ts +2 -0
- package/src/socket/client/socket-unit.ts +660 -0
- package/src/socket/client/socket.ts +203 -0
- package/src/socket/common/index.ts +2 -0
- package/src/socket/common/socket-unit-common.ts +23 -0
- package/src/socket/common/socket-unit-heartbeat.ts +427 -0
- package/src/socket/index.ts +3 -0
- package/src/socket/server/index.ts +3 -0
- package/src/socket/server/server.ts +183 -0
- package/src/socket/server/socket-unit.ts +449 -0
- package/src/socket/server/socket.ts +264 -0
- package/src/storage/README.md +107 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/table.ts +449 -0
- package/src/timer/README.md +86 -0
- package/src/timer/expiration/expiration-manager.ts +594 -0
- package/src/timer/expiration/index.ts +3 -0
- package/src/timer/expiration/min-heap.ts +208 -0
- package/src/timer/expiration/remaining-manager.ts +241 -0
- package/src/timer/index.ts +1 -0
- package/src/tube/README.md +99 -0
- package/src/tube/helper.ts +138 -0
- package/src/tube/index.ts +2 -0
- package/src/tube/tube.ts +880 -0
- package/src/type/README.md +54 -307
- package/src/type/class.ts +2 -2
- package/src/type/index.ts +14 -14
- package/src/type/is.ts +265 -2
- package/src/type/object.ts +37 -0
- package/src/type/string.ts +7 -2
- package/src/type/tuple.ts +6 -6
- package/src/type/union.ts +16 -0
- package/src/web/README.md +77 -0
- package/src/web/capture.ts +35 -0
- package/src/web/clipboard.ts +97 -0
- package/src/web/dom.ts +117 -0
- package/src/web/download.ts +16 -0
- package/src/web/event.ts +46 -0
- package/src/web/index.ts +10 -0
- package/src/web/local-storage.ts +113 -0
- package/src/web/location.ts +28 -0
- package/src/web/permission.ts +172 -0
- package/src/web/script-loader.ts +432 -0
- package/src/weixin/README.md +1 -0
- package/src/weixin/index.ts +2 -0
- package/src/weixin/official-account/authorization.ts +159 -0
- package/src/weixin/official-account/index.ts +2 -0
- package/src/weixin/official-account/js-api.ts +134 -0
- package/src/weixin/open/index.ts +1 -0
- package/src/weixin/open/oauth2.ts +133 -0
- package/tests/unit/abort/abort-manager.spec.ts +225 -0
- package/tests/unit/abort/abort-signal-listener-manager.spec.ts +62 -0
- package/tests/unit/ai/ai.spec.ts +85 -0
- package/tests/unit/aio/content.spec.ts +105 -0
- package/tests/unit/aio/json.spec.ts +147 -0
- package/tests/unit/aio/prompt.spec.ts +111 -0
- package/tests/unit/basic/array.spec.ts +1 -1
- package/tests/unit/basic/error.spec.ts +16 -4
- package/tests/unit/basic/schedule.spec.ts +74 -0
- package/tests/unit/basic/stream.spec.ts +91 -38
- package/tests/unit/basic/string.spec.ts +0 -9
- package/tests/unit/color/rgb/analyze.spec.ts +110 -0
- package/tests/unit/color/rgb/construct.spec.ts +56 -0
- package/tests/unit/color/rgb/convert.spec.ts +60 -0
- package/tests/unit/color/rgb/derive.spec.ts +103 -0
- package/tests/unit/color/rgb/parse.spec.ts +66 -0
- package/tests/unit/color/rgb/serialize.spec.ts +46 -0
- package/tests/unit/color/xyz/analyze.spec.ts +33 -0
- package/tests/unit/color/xyz/construct.spec.ts +10 -0
- package/tests/unit/color/xyz/convert.spec.ts +18 -0
- package/tests/unit/credential/api-key.spec.ts +37 -0
- package/tests/unit/credential/bearer.spec.ts +23 -0
- package/tests/unit/credential/json-web-token.spec.ts +23 -0
- package/tests/unit/credential/password.spec.ts +41 -0
- package/tests/unit/cron/cron.spec.ts +84 -0
- package/tests/unit/css/class.spec.ts +157 -0
- package/tests/unit/environment/basic.spec.ts +20 -0
- package/tests/unit/environment/device.spec.ts +146 -0
- package/tests/unit/environment/feature.spec.ts +388 -0
- package/tests/unit/environment/geo.spec.ts +111 -0
- package/tests/unit/environment/runtime.spec.ts +364 -0
- package/tests/unit/environment/snapshot.spec.ts +4 -0
- package/tests/unit/environment/variable.spec.ts +190 -0
- package/tests/unit/event/class-event-proxy.spec.ts +225 -0
- package/tests/unit/event/event-manager.spec.ts +246 -0
- package/tests/unit/event/instance-event-proxy.spec.ts +187 -0
- package/tests/unit/exception/browser.spec.ts +213 -0
- package/tests/unit/exception/nodejs.spec.ts +144 -0
- package/tests/unit/exception/normalize.spec.ts +57 -0
- package/tests/unit/form/inputor-controller/base.spec.ts +458 -0
- package/tests/unit/form/inputor-controller/boolean.spec.ts +30 -0
- package/tests/unit/form/inputor-controller/file.spec.ts +27 -0
- package/tests/unit/form/inputor-controller/form.spec.ts +120 -0
- package/tests/unit/form/inputor-controller/helper.spec.ts +67 -0
- package/tests/unit/form/inputor-controller/multi-select.spec.ts +34 -0
- package/tests/unit/form/inputor-controller/number.spec.ts +36 -0
- package/tests/unit/form/inputor-controller/select.spec.ts +49 -0
- package/tests/unit/form/inputor-controller/text.spec.ts +34 -0
- package/tests/unit/http/api/api-core-host.spec.ts +207 -0
- package/tests/unit/http/api/api-schema.spec.ts +120 -0
- package/tests/unit/http/api/api-server.spec.ts +363 -0
- package/tests/unit/http/api/api-test.spec.ts +117 -0
- package/tests/unit/http/api/api.spec.ts +121 -0
- package/tests/unit/http/api-adapter/node-http.spec.ts +191 -0
- package/tests/unit/identifier/id.spec.ts +71 -0
- package/tests/unit/identifier/uuid.spec.ts +85 -0
- package/tests/unit/json/repair.spec.ts +11 -0
- package/tests/unit/log/log-emitter.spec.ts +33 -0
- package/tests/unit/log/log-scheduler.spec.ts +40 -0
- package/tests/unit/log/log-type.spec.ts +7 -0
- package/tests/unit/log/logger.spec.ts +237 -0
- package/tests/unit/openai/openai.spec.ts +64 -0
- package/tests/unit/orchestration/coordination/barrier.spec.ts +96 -0
- package/tests/unit/orchestration/coordination/count-down-latch.spec.ts +63 -0
- package/tests/unit/orchestration/coordination/errors.spec.ts +29 -0
- package/tests/unit/orchestration/coordination/keyed-lock.spec.ts +109 -0
- package/tests/unit/orchestration/coordination/mutex.spec.ts +132 -0
- package/tests/unit/orchestration/coordination/permit.spec.ts +43 -0
- package/tests/unit/orchestration/coordination/read-write-lock.spec.ts +154 -0
- package/tests/unit/orchestration/coordination/semaphore.spec.ts +135 -0
- package/tests/unit/orchestration/dispatching/dispatcher.spec.ts +41 -0
- package/tests/unit/orchestration/dispatching/selector/down-count-selector.spec.ts +81 -0
- package/tests/unit/orchestration/scheduling/scheduler.spec.ts +103 -0
- package/tests/unit/random/base.spec.ts +58 -0
- package/tests/unit/random/random-boolean.spec.ts +25 -0
- package/tests/unit/random/random-integer.spec.ts +32 -0
- package/tests/unit/random/random-number.spec.ts +33 -0
- package/tests/unit/random/random-string.spec.ts +22 -0
- package/tests/unit/reactor/alien-signals-effect.spec.ts +11 -10
- package/tests/unit/reactor/preact-signal.spec.ts +1 -2
- package/tests/unit/request/fetch/browser.spec.ts +222 -0
- package/tests/unit/request/fetch/general.spec.ts +43 -0
- package/tests/unit/request/fetch/nodejs.spec.ts +225 -0
- package/tests/unit/request/request/base.spec.ts +385 -0
- package/tests/unit/request/request/general.spec.ts +161 -0
- package/tests/unit/route/router/route.spec.ts +431 -0
- package/tests/unit/route/router/router.spec.ts +407 -0
- package/tests/unit/route/uri/hash.spec.ts +72 -0
- package/tests/unit/route/uri/pathname.spec.ts +147 -0
- package/tests/unit/route/uri/search.spec.ts +107 -0
- package/tests/unit/singleton/singleton.spec.ts +49 -0
- package/tests/unit/socket/client.spec.ts +208 -0
- package/tests/unit/socket/server.spec.ts +135 -0
- package/tests/unit/socket/socket-unit-heartbeat.spec.ts +214 -0
- package/tests/unit/storage/table.spec.ts +620 -0
- package/tests/unit/timer/expiration/expiration-manager.spec.ts +464 -0
- package/tests/unit/timer/expiration/min-heap.spec.ts +71 -0
- package/tests/unit/timer/expiration/remaining-manager.spec.ts +234 -0
- package/tests/unit/tube/helper.spec.ts +139 -0
- package/tests/unit/tube/tube.spec.ts +501 -0
- package/.oxlintrc.json +0 -5
- package/src/random/uuid.ts +0 -103
- package/tests/unit/random/uuid.spec.ts +0 -37
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { useNodejs } from "#Source/environment/index.ts"
|
|
2
|
+
|
|
3
|
+
import { normalizeNodejsExceptionRecord } from "./normalize.ts"
|
|
4
|
+
import type {
|
|
5
|
+
ExceptionListenerCleanup,
|
|
6
|
+
NodejsExceptionRecord,
|
|
7
|
+
ObserveExceptionsOptions,
|
|
8
|
+
} from "./types.ts"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 表示 Nodejs 侧异常监听回调。
|
|
12
|
+
*/
|
|
13
|
+
export type NodejsExceptionListener = (record: NodejsExceptionRecord) => void
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 监听 Node.js 的 `uncaughtExceptionMonitor` 事件。
|
|
17
|
+
*/
|
|
18
|
+
export const onNodejsUncaughtExceptionMonitor = (
|
|
19
|
+
listener: NodejsExceptionListener,
|
|
20
|
+
options?: ObserveExceptionsOptions | undefined,
|
|
21
|
+
): ExceptionListenerCleanup => {
|
|
22
|
+
return useNodejs((context) => {
|
|
23
|
+
const currentProcess = context.globalThis.process
|
|
24
|
+
const internalListener = (exception: unknown, origin: unknown): void => {
|
|
25
|
+
listener(normalizeNodejsExceptionRecord({
|
|
26
|
+
source: "nodejs.uncaught-exception-monitor",
|
|
27
|
+
exception,
|
|
28
|
+
timestamp: options?.captureTimestamp?.() ?? Date.now(),
|
|
29
|
+
originalEvent: { exception, origin },
|
|
30
|
+
origin: typeof origin === "string" ? origin : undefined,
|
|
31
|
+
}))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
currentProcess.on("uncaughtExceptionMonitor", internalListener)
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
if (typeof currentProcess.off === "function") {
|
|
38
|
+
currentProcess.off("uncaughtExceptionMonitor", internalListener)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
currentProcess.removeListener?.("uncaughtExceptionMonitor", internalListener)
|
|
43
|
+
}
|
|
44
|
+
}, () => {
|
|
45
|
+
return (): void => {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 监听 Node.js 的 `uncaughtException` 事件。
|
|
53
|
+
*/
|
|
54
|
+
export const onNodejsUncaughtException = (
|
|
55
|
+
listener: NodejsExceptionListener,
|
|
56
|
+
options?: ObserveExceptionsOptions | undefined,
|
|
57
|
+
): ExceptionListenerCleanup => {
|
|
58
|
+
return useNodejs((context) => {
|
|
59
|
+
const currentProcess = context.globalThis.process
|
|
60
|
+
const internalListener = (exception: unknown, origin: unknown): void => {
|
|
61
|
+
listener(normalizeNodejsExceptionRecord({
|
|
62
|
+
source: "nodejs.uncaught-exception",
|
|
63
|
+
exception,
|
|
64
|
+
timestamp: options?.captureTimestamp?.() ?? Date.now(),
|
|
65
|
+
originalEvent: { exception, origin },
|
|
66
|
+
origin: typeof origin === "string" ? origin : undefined,
|
|
67
|
+
}))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
currentProcess.on("uncaughtException", internalListener)
|
|
71
|
+
|
|
72
|
+
return () => {
|
|
73
|
+
if (typeof currentProcess.off === "function") {
|
|
74
|
+
currentProcess.off("uncaughtException", internalListener)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
currentProcess.removeListener?.("uncaughtException", internalListener)
|
|
79
|
+
}
|
|
80
|
+
}, () => {
|
|
81
|
+
return (): void => {
|
|
82
|
+
return undefined
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 监听 Node.js 的 `unhandledRejection` 事件。
|
|
89
|
+
*/
|
|
90
|
+
export const onNodejsUnhandledRejection = (
|
|
91
|
+
listener: NodejsExceptionListener,
|
|
92
|
+
options?: ObserveExceptionsOptions | undefined,
|
|
93
|
+
): ExceptionListenerCleanup => {
|
|
94
|
+
return useNodejs((context) => {
|
|
95
|
+
const currentProcess = context.globalThis.process
|
|
96
|
+
const internalListener = (reason: unknown, promise: unknown): void => {
|
|
97
|
+
listener(normalizeNodejsExceptionRecord({
|
|
98
|
+
source: "nodejs.unhandled-rejection",
|
|
99
|
+
exception: reason,
|
|
100
|
+
timestamp: options?.captureTimestamp?.() ?? Date.now(),
|
|
101
|
+
originalEvent: { reason, promise },
|
|
102
|
+
promise: promise instanceof Promise ? promise : undefined,
|
|
103
|
+
}))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
currentProcess.on("unhandledRejection", internalListener)
|
|
107
|
+
|
|
108
|
+
return () => {
|
|
109
|
+
if (typeof currentProcess.off === "function") {
|
|
110
|
+
currentProcess.off("unhandledRejection", internalListener)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
currentProcess.removeListener?.("unhandledRejection", internalListener)
|
|
115
|
+
}
|
|
116
|
+
}, () => {
|
|
117
|
+
return (): void => {
|
|
118
|
+
return undefined
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 表示批量监听 Nodejs 异常时可选的配置。
|
|
125
|
+
*
|
|
126
|
+
* 未显式传入时,三个 Node.js 入口默认都会启用;仅当对应选项为 `false` 时才跳过该入口。
|
|
127
|
+
*/
|
|
128
|
+
export interface ObserveNodejsExceptionsOptions extends ObserveExceptionsOptions {
|
|
129
|
+
includeUncaughtExceptionMonitor?: boolean | undefined
|
|
130
|
+
includeUncaughtException?: boolean | undefined
|
|
131
|
+
includeUnhandledRejection?: boolean | undefined
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 批量监听 Nodejs 侧全局异常入口。
|
|
136
|
+
*
|
|
137
|
+
* 默认会同时监听 `uncaughtExceptionMonitor`、`uncaughtException` 和 `unhandledRejection`。
|
|
138
|
+
* 如需关闭某个入口,请将对应的 `include*` 选项显式设为 `false`。
|
|
139
|
+
*/
|
|
140
|
+
export const observeNodejsExceptions = (
|
|
141
|
+
listener: NodejsExceptionListener,
|
|
142
|
+
options?: ObserveNodejsExceptionsOptions | undefined,
|
|
143
|
+
): ExceptionListenerCleanup => {
|
|
144
|
+
const {
|
|
145
|
+
includeUncaughtExceptionMonitor,
|
|
146
|
+
includeUncaughtException,
|
|
147
|
+
includeUnhandledRejection
|
|
148
|
+
} = options ?? {}
|
|
149
|
+
|
|
150
|
+
const cleanups: ExceptionListenerCleanup[] = []
|
|
151
|
+
|
|
152
|
+
if (includeUncaughtExceptionMonitor !== false) {
|
|
153
|
+
cleanups.push(onNodejsUncaughtExceptionMonitor(listener, options))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (includeUncaughtException !== false) {
|
|
157
|
+
cleanups.push(onNodejsUncaughtException(listener, options))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (includeUnhandledRejection !== false) {
|
|
161
|
+
cleanups.push(onNodejsUnhandledRejection(listener, options))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return () => {
|
|
165
|
+
for (const cleanup of cleanups) {
|
|
166
|
+
cleanup()
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BrowserExceptionRecord,
|
|
3
|
+
BrowserExceptionRecordInput,
|
|
4
|
+
ExceptionRecord,
|
|
5
|
+
ExceptionRecordInput,
|
|
6
|
+
NodejsExceptionRecord,
|
|
7
|
+
NodejsExceptionRecordInput,
|
|
8
|
+
} from "./types.ts"
|
|
9
|
+
|
|
10
|
+
const internalIsErrorLike = (exception: unknown): exception is { message: string } => {
|
|
11
|
+
if (exception instanceof Error) {
|
|
12
|
+
return true
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (typeof exception !== "object" || exception === null) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (("message" in exception) === false) {
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { message } = exception as { message?: unknown }
|
|
24
|
+
return typeof message === "string"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const internalGetExceptionMessage = (exception: unknown): string | undefined => {
|
|
28
|
+
if (internalIsErrorLike(exception)) {
|
|
29
|
+
return exception.message
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof exception === "string") {
|
|
33
|
+
return exception
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 将异常输入标准化为共享异常记录。
|
|
41
|
+
*/
|
|
42
|
+
export const normalizeExceptionRecord = (input: ExceptionRecordInput): ExceptionRecord => {
|
|
43
|
+
const {
|
|
44
|
+
runtime,
|
|
45
|
+
source,
|
|
46
|
+
exception,
|
|
47
|
+
message,
|
|
48
|
+
timestamp,
|
|
49
|
+
originalEvent,
|
|
50
|
+
}: ExceptionRecordInput = input
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
runtime,
|
|
54
|
+
source,
|
|
55
|
+
exception,
|
|
56
|
+
message: message ?? internalGetExceptionMessage(exception),
|
|
57
|
+
timestamp: timestamp ?? Date.now(),
|
|
58
|
+
originalEvent,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 将浏览器异常输入标准化为浏览器异常记录。
|
|
64
|
+
*/
|
|
65
|
+
export const normalizeBrowserExceptionRecord = (input: BrowserExceptionRecordInput): BrowserExceptionRecord => {
|
|
66
|
+
const {
|
|
67
|
+
source,
|
|
68
|
+
filename,
|
|
69
|
+
lineno,
|
|
70
|
+
colno,
|
|
71
|
+
} = input
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...normalizeExceptionRecord({
|
|
75
|
+
...input,
|
|
76
|
+
runtime: "browser",
|
|
77
|
+
}),
|
|
78
|
+
runtime: "browser",
|
|
79
|
+
source,
|
|
80
|
+
filename,
|
|
81
|
+
lineno,
|
|
82
|
+
colno,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 将 Nodejs 异常输入标准化为 Nodejs 异常记录。
|
|
88
|
+
*/
|
|
89
|
+
export const normalizeNodejsExceptionRecord = (input: NodejsExceptionRecordInput): NodejsExceptionRecord => {
|
|
90
|
+
const {
|
|
91
|
+
source,
|
|
92
|
+
origin,
|
|
93
|
+
promise,
|
|
94
|
+
} = input
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
...normalizeExceptionRecord({
|
|
98
|
+
...input,
|
|
99
|
+
runtime: "nodejs",
|
|
100
|
+
}),
|
|
101
|
+
runtime: "nodejs",
|
|
102
|
+
source,
|
|
103
|
+
origin,
|
|
104
|
+
promise,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表示异常来源所属的运行时类型。
|
|
3
|
+
*/
|
|
4
|
+
export type ExceptionRuntime =
|
|
5
|
+
| "browser"
|
|
6
|
+
| "nodejs"
|
|
7
|
+
| "unknown"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 表示取消异常监听的清理函数。
|
|
11
|
+
*/
|
|
12
|
+
export type ExceptionListenerCleanup = () => void
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 表示一条标准化异常记录中的共享字段。
|
|
16
|
+
*/
|
|
17
|
+
export interface ExceptionRecord {
|
|
18
|
+
runtime: ExceptionRuntime
|
|
19
|
+
source: string
|
|
20
|
+
exception: unknown
|
|
21
|
+
message?: string | undefined
|
|
22
|
+
timestamp: number
|
|
23
|
+
originalEvent?: unknown | undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 表示标准化异常记录时所需的共享输入。
|
|
28
|
+
*/
|
|
29
|
+
export interface ExceptionRecordInput {
|
|
30
|
+
runtime: ExceptionRuntime
|
|
31
|
+
source: string
|
|
32
|
+
exception: unknown
|
|
33
|
+
message?: string | undefined
|
|
34
|
+
timestamp?: number | undefined
|
|
35
|
+
originalEvent?: unknown | undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 表示浏览器侧全局异常来源。
|
|
40
|
+
*/
|
|
41
|
+
export type BrowserExceptionSource =
|
|
42
|
+
| "browser.global-error"
|
|
43
|
+
| "browser.window-onerror"
|
|
44
|
+
| "browser.unhandled-rejection"
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 表示浏览器侧标准化异常记录。
|
|
48
|
+
*/
|
|
49
|
+
export interface BrowserExceptionRecord extends ExceptionRecord {
|
|
50
|
+
runtime: "browser"
|
|
51
|
+
source: BrowserExceptionSource
|
|
52
|
+
filename?: string | undefined
|
|
53
|
+
lineno?: number | undefined
|
|
54
|
+
colno?: number | undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 表示标准化浏览器异常记录时所需的输入。
|
|
59
|
+
*/
|
|
60
|
+
export interface BrowserExceptionRecordInput extends Omit<ExceptionRecordInput, "runtime" | "source"> {
|
|
61
|
+
source: BrowserExceptionSource
|
|
62
|
+
filename?: string | undefined
|
|
63
|
+
lineno?: number | undefined
|
|
64
|
+
colno?: number | undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 表示 Nodejs 侧全局异常来源。
|
|
69
|
+
*/
|
|
70
|
+
export type NodejsExceptionSource =
|
|
71
|
+
| "nodejs.uncaught-exception-monitor"
|
|
72
|
+
| "nodejs.uncaught-exception"
|
|
73
|
+
| "nodejs.unhandled-rejection"
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 表示 Nodejs 侧标准化异常记录。
|
|
77
|
+
*/
|
|
78
|
+
export interface NodejsExceptionRecord extends ExceptionRecord {
|
|
79
|
+
runtime: "nodejs"
|
|
80
|
+
source: NodejsExceptionSource
|
|
81
|
+
origin?: string | undefined
|
|
82
|
+
promise?: Promise<unknown> | undefined
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 表示标准化 Nodejs 异常记录时所需的输入。
|
|
87
|
+
*/
|
|
88
|
+
export interface NodejsExceptionRecordInput extends Omit<ExceptionRecordInput, "runtime" | "source"> {
|
|
89
|
+
source: NodejsExceptionSource
|
|
90
|
+
origin?: string | undefined
|
|
91
|
+
promise?: Promise<unknown> | undefined
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 表示批量安装异常监听器时可选的通用配置。
|
|
96
|
+
*/
|
|
97
|
+
export interface ObserveExceptionsOptions {
|
|
98
|
+
captureTimestamp?: (() => number) | undefined
|
|
99
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Form
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Form 模块提供围绕类表单输入项(form-like input)及其组合关系的通用建模能力,用于表达输入状态、值转换与聚合边界。
|
|
6
|
+
|
|
7
|
+
它关注的不是某个组件库的渲染细节,也不是某个框架各自的表单接入方式,而是“一个输入项应如何被视为可独立管理的输入原子、多个输入项如何组合成更高层的类表单数据管理器、以及输入值与聚合值如何保持清楚且可维护的对应关系”这一类基础问题。它之所以被命名为 Form,不是因为它只服务于页面表单,而是因为表单场景最自然、最直观地体现了这类模型的价值。
|
|
8
|
+
|
|
9
|
+
## For Understanding
|
|
10
|
+
|
|
11
|
+
理解 Form 模块时,首先应把它看成“类表单数据管理模型”,而不是“页面表单组件集合”或“校验规则工具箱”。它要解决的问题,不是把某个现成表单 API 重新包装一遍,而是为输入项本身建立稳定语义:一个输入项有哪些核心状态,输入过程与最终值如何区分,多个输入项如何组合,以及组合之后的整体值应如何被表达。
|
|
12
|
+
|
|
13
|
+
这个模块更适合放在以下边界中:
|
|
14
|
+
|
|
15
|
+
- 你希望把输入逻辑从具体接入层中抽离出来,让输入状态、值更新和聚合关系可以在不同 UI、服务端流程或其它非界面场景之间复用。
|
|
16
|
+
- 你需要先把输入项视为一组可独立管理的输入原子,再把它们组合成更高层的类表单数据管理器,而不是一开始就把所有逻辑揉成单个大对象。
|
|
17
|
+
- 你需要明确区分“输入过程中的值”和“对外稳定表达的值”,并希望这种区分能够成为长期可维护的公共语义。
|
|
18
|
+
|
|
19
|
+
理解这个模块时,还应守住几条边界原则:
|
|
20
|
+
|
|
21
|
+
- Form 模块表达的是输入项状态、输入项组合与值映射语义,不负责页面布局、样式、校验文案或具体提交流程。
|
|
22
|
+
- 它可以服务于具体输入组件,但不应因为适配某个框架或某种表单交互习惯,而把这些宿主细节直接上升为模块公共语义。
|
|
23
|
+
- 它关注的是“输入项如何被建模、如何更新、如何聚合”,而不是所有表单相关问题的总容器;像复杂校验编排、错误展示策略、网络提交流程或业务字段规范,通常应由更上层模块承担。
|
|
24
|
+
|
|
25
|
+
因此,更合适的理解方式是:Form 模块提供的是一套围绕输入原子与类表单聚合的数据管理基础模型能力。表单只是它最典型的落点之一,而不是它的唯一归宿。只有当某个能力确实在澄清这条边界时,它才适合作为该模块的组成部分;如果某个能力只是某类页面表单的临时便利封装,那么它通常不应直接进入这个模块。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./inputor-controller/index.ts"
|