effect 4.0.0-beta.103 → 4.0.0-beta.105
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/AGENTS.md +381 -0
- package/CLAUDE.md +381 -0
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +5 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +165 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +116 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +136 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +24 -0
- package/dist/Brand.d.ts +3 -3
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +4 -3
- package/dist/Brand.js.map +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cache.js.map +1 -1
- package/dist/Channel.d.ts +1 -1
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +30 -8
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +2 -1
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Context.d.ts +2 -3
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +1 -22
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts +31 -0
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +58 -2
- package/dist/Cron.js.map +1 -1
- package/dist/Crypto.d.ts.map +1 -1
- package/dist/Crypto.js +13 -5
- package/dist/Crypto.js.map +1 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +12 -1
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +132 -14
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +38 -0
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +10 -2
- package/dist/Equal.js.map +1 -1
- package/dist/ExecutionPlan.d.ts +73 -0
- package/dist/ExecutionPlan.d.ts.map +1 -1
- package/dist/ExecutionPlan.js +1 -1
- package/dist/ExecutionPlan.js.map +1 -1
- package/dist/FiberSet.js +1 -1
- package/dist/FileSystem.d.ts +2 -2
- package/dist/Function.d.ts +4 -3
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +5 -5
- package/dist/Function.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +11 -10
- package/dist/Iterable.js.map +1 -1
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +7 -5
- package/dist/Layer.js.map +1 -1
- package/dist/Optic.d.ts +35 -21
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +33 -34
- package/dist/Optic.js.map +1 -1
- package/dist/Schedule.d.ts +8 -8
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +4 -4
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +105 -57
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +105 -67
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +33 -3
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +87 -63
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +8 -8
- package/dist/SchemaError.d.ts.map +1 -1
- package/dist/SchemaError.js +7 -6
- package/dist/SchemaError.js.map +1 -1
- package/dist/SchemaGetter.d.ts +8 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +41 -37
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts +195 -38
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +243 -68
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts +30 -0
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +74 -62
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +26 -26
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Sink.d.ts +1 -1
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Stdio.d.ts +17 -4
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +6 -3
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +27 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +27 -2
- package/dist/Stream.js.map +1 -1
- package/dist/SynchronizedRef.js +1 -1
- package/dist/SynchronizedRef.js.map +1 -1
- package/dist/Terminal.js +1 -1
- package/dist/Terminal.js.map +1 -1
- package/dist/Tuple.d.ts +6 -4
- package/dist/Tuple.d.ts.map +1 -1
- package/dist/Tuple.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +0 -56
- package/dist/TxReentrantLock.d.ts.map +1 -1
- package/dist/TxReentrantLock.js +8 -8
- package/dist/TxReentrantLock.js.map +1 -1
- package/dist/internal/dateTime.js +1 -1
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/executionPlan.js +51 -3
- package/dist/internal/executionPlan.js.map +1 -1
- package/dist/internal/hashMap.js +12 -8
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/matcher.js +1 -1
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schedule.js.map +1 -1
- package/dist/internal/schema/annotations.js +2 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/schema.js +1 -9
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/toArbitrary.js +1 -1
- package/dist/internal/schema/toArbitrary.js.map +1 -1
- package/dist/internal/trie.js +13 -3
- package/dist/internal/trie.js.map +1 -1
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +11 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +2 -2
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +8 -7
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/AiError.js +19 -19
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/Chat.js +1 -1
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +4 -2
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +132 -132
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +8 -8
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.js +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +15 -3
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +10 -7
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +3 -3
- package/dist/unstable/cli/CliError.js +11 -11
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +9 -9
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +8 -6
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +7 -5
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +15 -11
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js +31 -24
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/Prompt.d.ts.map +1 -1
- package/dist/unstable/cli/Prompt.js +31 -17
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +2 -2
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +2 -2
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +10 -9
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/completions/bash.js +69 -9
- package/dist/unstable/cli/internal/completions/bash.js.map +1 -1
- package/dist/unstable/cli/internal/completions/descriptor.js +24 -18
- package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -1
- package/dist/unstable/cli/internal/completions/fish.js +5 -5
- package/dist/unstable/cli/internal/completions/fish.js.map +1 -1
- package/dist/unstable/cli/internal/help.d.ts.map +1 -1
- package/dist/unstable/cli/internal/help.js +4 -2
- package/dist/unstable/cli/internal/help.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +3 -3
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cli/internal/wizard.js +2 -2
- package/dist/unstable/cli/internal/wizard.js.map +1 -1
- package/dist/unstable/cluster/ClusterError.js +7 -7
- package/dist/unstable/cluster/ClusterError.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +8 -1
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +8 -0
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js +16 -4
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerServer.js +4 -2
- package/dist/unstable/cluster/RunnerServer.js.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.d.ts +1 -2
- package/dist/unstable/cluster/RunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.js +7 -6
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +22 -4
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +1 -1
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceMap.js +2 -2
- package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceRef.js +17 -0
- package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsClient.js +7 -2
- package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
- package/dist/unstable/encoding/Ini.d.ts +20 -0
- package/dist/unstable/encoding/Ini.d.ts.map +1 -0
- package/dist/unstable/encoding/Ini.js +153 -0
- package/dist/unstable/encoding/Ini.js.map +1 -0
- package/dist/unstable/encoding/Msgpack.d.ts +2 -1
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js +27 -13
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js +7 -1
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js +14 -23
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/encoding/Toml.d.ts +19 -0
- package/dist/unstable/encoding/Toml.d.ts.map +1 -0
- package/dist/unstable/encoding/Toml.js +434 -0
- package/dist/unstable/encoding/Toml.js.map +1 -0
- package/dist/unstable/encoding/Yaml.d.ts +19 -0
- package/dist/unstable/encoding/Yaml.d.ts.map +1 -0
- package/dist/unstable/encoding/Yaml.js +461 -0
- package/dist/unstable/encoding/Yaml.js.map +1 -0
- package/dist/unstable/encoding/index.d.ts +12 -0
- package/dist/unstable/encoding/index.d.ts.map +1 -1
- package/dist/unstable/encoding/index.js +12 -0
- package/dist/unstable/encoding/index.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventJournal.js +13 -5
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js +1 -1
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.js +1 -4
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/unstable/http/FindMyWay/internal/queryString.d.ts +11 -0
- package/dist/unstable/http/FindMyWay/internal/queryString.d.ts.map +1 -0
- package/dist/unstable/http/FindMyWay/internal/queryString.js +259 -0
- package/dist/unstable/http/FindMyWay/internal/queryString.js.map +1 -0
- package/dist/unstable/http/FindMyWay/internal/router.d.ts +2 -0
- package/dist/unstable/http/FindMyWay/internal/router.d.ts.map +1 -0
- package/dist/unstable/http/FindMyWay/internal/router.js +665 -0
- package/dist/unstable/http/FindMyWay/internal/router.js.map +1 -0
- package/dist/unstable/http/FindMyWay.d.ts +33 -8
- package/dist/unstable/http/FindMyWay.d.ts.map +1 -1
- package/dist/unstable/http/FindMyWay.js +4 -7
- package/dist/unstable/http/FindMyWay.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +59 -3
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +33 -19
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.js +1 -1
- package/dist/unstable/http/HttpClientError.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +2 -14
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js +1 -16
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
- package/dist/unstable/http/HttpPlatform.js +21 -3
- package/dist/unstable/http/HttpPlatform.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +7 -6
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +8 -6
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +9 -2
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/http/MultipartParser/HeadersParser.d.ts +53 -0
- package/dist/unstable/http/MultipartParser/HeadersParser.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/HeadersParser.js +14 -0
- package/dist/unstable/http/MultipartParser/HeadersParser.js.map +1 -0
- package/dist/unstable/http/MultipartParser/Search.d.ts +11 -0
- package/dist/unstable/http/MultipartParser/Search.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/Search.js +14 -0
- package/dist/unstable/http/MultipartParser/Search.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.d.ts +5 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.js +82 -0
- package/dist/unstable/http/MultipartParser/internal/contentType.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/headers.d.ts +3 -0
- package/dist/unstable/http/MultipartParser/internal/headers.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/headers.js +194 -0
- package/dist/unstable/http/MultipartParser/internal/headers.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts +8 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.js +226 -0
- package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/search.d.ts +5 -0
- package/dist/unstable/http/MultipartParser/internal/search.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser/internal/search.js +120 -0
- package/dist/unstable/http/MultipartParser/internal/search.js.map +1 -0
- package/dist/unstable/http/MultipartParser.d.ts +98 -0
- package/dist/unstable/http/MultipartParser.d.ts.map +1 -0
- package/dist/unstable/http/MultipartParser.js +23 -0
- package/dist/unstable/http/MultipartParser.js.map +1 -0
- package/dist/unstable/http/Template.d.ts.map +1 -1
- package/dist/unstable/http/Template.js +2 -2
- package/dist/unstable/http/Template.js.map +1 -1
- package/dist/unstable/http/index.d.ts +1 -1
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +1 -1
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/http/internal/httpBody.d.ts +2 -0
- package/dist/unstable/http/internal/httpBody.d.ts.map +1 -0
- package/dist/unstable/http/internal/httpBody.js +10 -0
- package/dist/unstable/http/internal/httpBody.js.map +1 -0
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +5 -5
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +73 -20
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +74 -34
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +6 -4
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +73 -16
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +5 -5
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +17 -17
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +219 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +170 -0
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +8 -0
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +45 -18
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +2 -1
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +2 -2
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +2 -2
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.js +28 -15
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +1 -1
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +9 -9
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +17 -7
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +22 -12
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +15 -42
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/persistence/Redis.js +1 -1
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +4 -4
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +26 -11
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +9 -22
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +14 -0
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +21 -10
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcClientError.js +2 -2
- package/dist/unstable/rpc/RpcClientError.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +3 -1
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +3 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +1 -1
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +5 -5
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +17 -9
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +28 -12
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js +7 -3
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/sql/SqlError.js +13 -13
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +8 -6
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +8 -6
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workers/WorkerError.js +5 -5
- package/dist/unstable/workers/WorkerError.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +2 -2
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +3 -3
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +6 -9
- package/src/Brand.ts +4 -4
- package/src/Cache.ts +1 -1
- package/src/Channel.ts +1 -1
- package/src/Config.ts +31 -8
- package/src/ConfigProvider.ts +4 -1
- package/src/Context.ts +6 -28
- package/src/Cron.ts +65 -2
- package/src/Crypto.ts +17 -8
- package/src/Duration.ts +16 -2
- package/src/Effect.ts +141 -17
- package/src/Equal.ts +10 -2
- package/src/ExecutionPlan.ts +78 -1
- package/src/FiberSet.ts +1 -1
- package/src/FileSystem.ts +2 -2
- package/src/Function.ts +6 -6
- package/src/Iterable.ts +11 -10
- package/src/Layer.ts +7 -5
- package/src/Optic.ts +59 -58
- package/src/Schedule.ts +13 -13
- package/src/Schema.ts +195 -112
- package/src/SchemaAST.ts +154 -85
- package/src/SchemaError.ts +9 -9
- package/src/SchemaGetter.ts +89 -30
- package/src/SchemaIssue.ts +285 -80
- package/src/SchemaParser.ts +126 -86
- package/src/SchemaTransformation.ts +66 -18
- package/src/ScopedCache.ts +1 -1
- package/src/Sink.ts +1 -1
- package/src/Stdio.ts +23 -4
- package/src/Stream.ts +77 -10
- package/src/SynchronizedRef.ts +1 -1
- package/src/Terminal.ts +1 -1
- package/src/Tuple.ts +7 -4
- package/src/TxReentrantLock.ts +39 -35
- package/src/internal/dateTime.ts +1 -1
- package/src/internal/executionPlan.ts +105 -10
- package/src/internal/hashMap.ts +20 -14
- package/src/internal/matcher.ts +2 -2
- package/src/internal/schedule.ts +4 -4
- package/src/internal/schema/annotations.ts +3 -0
- package/src/internal/schema/schema.ts +1 -17
- package/src/internal/schema/toArbitrary.ts +3 -1
- package/src/internal/trie.ts +12 -2
- package/src/testing/TestClock.ts +13 -1
- package/src/testing/TestSchema.ts +9 -9
- package/src/unstable/ai/AiError.ts +19 -19
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +4 -2
- package/src/unstable/ai/McpSchema.ts +17 -16
- package/src/unstable/ai/McpServer.ts +1 -1
- package/src/unstable/ai/Prompt.ts +35 -10
- package/src/unstable/cli/CliError.ts +12 -12
- package/src/unstable/cli/Command.ts +12 -10
- package/src/unstable/cli/Param.ts +41 -19
- package/src/unstable/cli/Primitive.ts +11 -5
- package/src/unstable/cli/Prompt.ts +36 -20
- package/src/unstable/cli/internal/ansi.ts +2 -2
- package/src/unstable/cli/internal/command.ts +15 -10
- package/src/unstable/cli/internal/completions/bash.ts +59 -9
- package/src/unstable/cli/internal/completions/descriptor.ts +14 -20
- package/src/unstable/cli/internal/completions/fish.ts +5 -7
- package/src/unstable/cli/internal/help.ts +4 -2
- package/src/unstable/cli/internal/parser.ts +3 -3
- package/src/unstable/cli/internal/wizard.ts +2 -2
- package/src/unstable/cluster/ClusterError.ts +7 -7
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +4 -1
- package/src/unstable/cluster/MessageStorage.ts +9 -5
- package/src/unstable/cluster/Reply.ts +25 -4
- package/src/unstable/cluster/RunnerServer.ts +4 -10
- package/src/unstable/cluster/RunnerStorage.ts +9 -7
- package/src/unstable/cluster/Sharding.ts +35 -7
- package/src/unstable/cluster/internal/entityManager.ts +1 -1
- package/src/unstable/cluster/internal/resourceMap.ts +5 -2
- package/src/unstable/cluster/internal/resourceRef.ts +27 -5
- package/src/unstable/devtools/DevToolsClient.ts +3 -2
- package/src/unstable/encoding/Ini.ts +174 -0
- package/src/unstable/encoding/Msgpack.ts +59 -36
- package/src/unstable/encoding/Ndjson.ts +9 -1
- package/src/unstable/encoding/Sse.ts +11 -21
- package/src/unstable/encoding/Toml.ts +504 -0
- package/src/unstable/encoding/Yaml.ts +541 -0
- package/src/unstable/encoding/index.ts +15 -0
- package/src/unstable/eventlog/EventJournal.ts +14 -6
- package/src/unstable/eventlog/EventLogMessage.ts +1 -1
- package/src/unstable/eventlog/EventLogServerUnencrypted.ts +1 -1
- package/src/unstable/eventlog/SqlEventJournal.ts +6 -4
- package/src/unstable/http/FindMyWay/internal/queryString.ts +420 -0
- package/src/unstable/http/FindMyWay/internal/router.ts +950 -0
- package/src/unstable/http/FindMyWay.ts +65 -6
- package/src/unstable/http/HttpClient.ts +132 -23
- package/src/unstable/http/HttpClientError.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +2 -14
- package/src/unstable/http/HttpClientResponse.ts +1 -17
- package/src/unstable/http/HttpPlatform.ts +34 -6
- package/src/unstable/http/HttpServerRequest.ts +14 -6
- package/src/unstable/http/HttpServerResponse.ts +9 -7
- package/src/unstable/http/Multipart.ts +9 -2
- package/src/unstable/http/MultipartParser/HeadersParser.ts +68 -0
- package/src/unstable/http/MultipartParser/Search.ts +17 -0
- package/src/unstable/http/MultipartParser/internal/contentType.ts +103 -0
- package/src/unstable/http/MultipartParser/internal/headers.ts +615 -0
- package/src/unstable/http/MultipartParser/internal/multipart.ts +262 -0
- package/src/unstable/http/MultipartParser/internal/search.ts +167 -0
- package/src/unstable/http/MultipartParser.ts +115 -0
- package/src/unstable/http/Template.ts +6 -5
- package/src/unstable/http/index.ts +1 -1
- package/src/unstable/http/internal/httpBody.ts +15 -0
- package/src/unstable/httpapi/HttpApi.ts +6 -7
- package/src/unstable/httpapi/HttpApiBuilder.ts +142 -25
- package/src/unstable/httpapi/HttpApiClient.ts +130 -49
- package/src/unstable/httpapi/HttpApiEndpoint.ts +117 -29
- package/src/unstable/httpapi/HttpApiError.ts +33 -39
- package/src/unstable/httpapi/HttpApiMiddleware.ts +1 -1
- package/src/unstable/httpapi/HttpApiSchema.ts +353 -0
- package/src/unstable/httpapi/OpenApi.ts +70 -20
- package/src/unstable/observability/OtlpExporter.ts +4 -2
- package/src/unstable/observability/OtlpLogger.ts +3 -1
- package/src/unstable/observability/OtlpMetrics.ts +32 -18
- package/src/unstable/observability/OtlpTracer.ts +1 -1
- package/src/unstable/persistence/PersistedQueue.ts +12 -9
- package/src/unstable/persistence/Persistence.ts +27 -7
- package/src/unstable/persistence/RateLimiter.ts +54 -31
- package/src/unstable/persistence/Redis.ts +1 -1
- package/src/unstable/reactivity/AsyncResult.ts +11 -6
- package/src/unstable/reactivity/Atom.ts +44 -25
- package/src/unstable/rpc/RpcClient.ts +42 -13
- package/src/unstable/rpc/RpcClientError.ts +2 -2
- package/src/unstable/rpc/RpcSerialization.ts +1 -1
- package/src/unstable/rpc/RpcServer.ts +4 -2
- package/src/unstable/schema/VariantSchema.ts +36 -18
- package/src/unstable/socket/Socket.ts +24 -14
- package/src/unstable/sql/SqlClient.ts +65 -56
- package/src/unstable/sql/SqlError.ts +13 -13
- package/src/unstable/sql/SqlResolver.ts +8 -6
- package/src/unstable/sql/Statement.ts +13 -8
- package/src/unstable/workers/WorkerError.ts +5 -5
- package/src/unstable/workflow/Workflow.ts +2 -5
- package/src/unstable/workflow/WorkflowEngine.ts +8 -3
- package/dist/unstable/http/Multipasta/HeadersParser.d.ts +0 -14
- package/dist/unstable/http/Multipasta/HeadersParser.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/HeadersParser.js +0 -14
- package/dist/unstable/http/Multipasta/HeadersParser.js.map +0 -1
- package/dist/unstable/http/Multipasta/Node.d.ts +0 -14
- package/dist/unstable/http/Multipasta/Node.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/Node.js +0 -14
- package/dist/unstable/http/Multipasta/Node.js.map +0 -1
- package/dist/unstable/http/Multipasta/Search.d.ts +0 -14
- package/dist/unstable/http/Multipasta/Search.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/Search.js +0 -14
- package/dist/unstable/http/Multipasta/Search.js.map +0 -1
- package/dist/unstable/http/Multipasta/Web.d.ts +0 -14
- package/dist/unstable/http/Multipasta/Web.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta/Web.js +0 -14
- package/dist/unstable/http/Multipasta/Web.js.map +0 -1
- package/dist/unstable/http/Multipasta.d.ts +0 -15
- package/dist/unstable/http/Multipasta.d.ts.map +0 -1
- package/dist/unstable/http/Multipasta.js +0 -15
- package/dist/unstable/http/Multipasta.js.map +0 -1
- package/src/unstable/http/Multipasta/HeadersParser.ts +0 -14
- package/src/unstable/http/Multipasta/Node.ts +0 -14
- package/src/unstable/http/Multipasta/Search.ts +0 -14
- package/src/unstable/http/Multipasta/Web.ts +0 -14
- package/src/unstable/http/Multipasta.ts +0 -15
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017-2019 Tomas Della Vedova
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type * as Router from "../../FindMyWay.ts"
|
|
26
|
+
import * as QS from "./queryString.ts"
|
|
27
|
+
|
|
28
|
+
const FULL_PATH_REGEXP = /^https?:\/\/.*?\//
|
|
29
|
+
const OPTIONAL_PARAM_REGEXP = /(\/:[^/()]*?)\?(\/?)/
|
|
30
|
+
|
|
31
|
+
interface Route<A = unknown> {
|
|
32
|
+
readonly method: string
|
|
33
|
+
readonly path: Router.PathInput
|
|
34
|
+
readonly pattern: string
|
|
35
|
+
readonly handler: A
|
|
36
|
+
readonly params: ReadonlyArray<string>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
export const make = <A>(
|
|
41
|
+
options: Partial<Router.RouterConfig> = {}
|
|
42
|
+
): Router.Router<A> => new RouterImpl(options)
|
|
43
|
+
|
|
44
|
+
class RouterImpl<A> implements Router.Router<A> {
|
|
45
|
+
constructor(options: Partial<Router.RouterConfig> = {}) {
|
|
46
|
+
this.options = {
|
|
47
|
+
ignoreTrailingSlash: true,
|
|
48
|
+
ignoreDuplicateSlashes: true,
|
|
49
|
+
caseSensitive: false,
|
|
50
|
+
maxParamLength: 100,
|
|
51
|
+
...options
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
readonly options: Router.RouterConfig
|
|
56
|
+
routes: Array<Route> = []
|
|
57
|
+
trees: Record<string, StaticNode> = Object.create(null)
|
|
58
|
+
|
|
59
|
+
on(
|
|
60
|
+
method: string | Iterable<string>,
|
|
61
|
+
path: Router.PathInput,
|
|
62
|
+
handler: A
|
|
63
|
+
): void {
|
|
64
|
+
const optionalParamMatch = path.match(OPTIONAL_PARAM_REGEXP)
|
|
65
|
+
if (optionalParamMatch && optionalParamMatch.index !== undefined) {
|
|
66
|
+
assert(
|
|
67
|
+
path.length === optionalParamMatch.index + optionalParamMatch[0].length,
|
|
68
|
+
"Optional Parameter needs to be the last parameter of the path"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const pathFull = path.replace(
|
|
72
|
+
OPTIONAL_PARAM_REGEXP,
|
|
73
|
+
"$1$2"
|
|
74
|
+
) as Router.PathInput
|
|
75
|
+
const pathOptional = (path.replace(
|
|
76
|
+
OPTIONAL_PARAM_REGEXP,
|
|
77
|
+
"$2"
|
|
78
|
+
) || "/") as Router.PathInput
|
|
79
|
+
|
|
80
|
+
this.on(method, pathFull, handler)
|
|
81
|
+
this.on(method, pathOptional, handler)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.options.ignoreDuplicateSlashes) {
|
|
86
|
+
path = removeDuplicateSlashes(path)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (this.options.ignoreTrailingSlash) {
|
|
90
|
+
path = trimLastSlash(path)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const methods = typeof method === "string" ? [method] : method
|
|
94
|
+
for (const method of methods) {
|
|
95
|
+
this._on(method, path, handler)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
all(path: Router.PathInput, handler: A) {
|
|
100
|
+
this.on(httpMethods, path, handler)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private _on(method: string, path: Router.PathInput, handler: A): void {
|
|
104
|
+
if (this.trees[method] === undefined) {
|
|
105
|
+
this.trees[method] = new StaticNode("/")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let pattern = path
|
|
109
|
+
if (pattern === "*" && this.trees[method].prefix.length !== 0) {
|
|
110
|
+
const currentRoot = this.trees[method]
|
|
111
|
+
this.trees[method] = new StaticNode("")
|
|
112
|
+
this.trees[method].staticChildren["/"] = currentRoot
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let parentNodePathIndex = this.trees[method].prefix.length
|
|
116
|
+
let currentNode: Node = this.trees[method]
|
|
117
|
+
|
|
118
|
+
const params = []
|
|
119
|
+
for (let i = 0; i <= pattern.length; i++) {
|
|
120
|
+
if (pattern.charCodeAt(i) === 58 && pattern.charCodeAt(i + 1) === 58) {
|
|
121
|
+
// It's a double colon
|
|
122
|
+
i++
|
|
123
|
+
continue
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const isParametricNode = pattern.charCodeAt(i) === 58 && pattern.charCodeAt(i + 1) !== 58
|
|
127
|
+
const isWildcardNode = pattern.charCodeAt(i) === 42
|
|
128
|
+
|
|
129
|
+
if (
|
|
130
|
+
isParametricNode ||
|
|
131
|
+
isWildcardNode ||
|
|
132
|
+
(i === pattern.length && i !== parentNodePathIndex)
|
|
133
|
+
) {
|
|
134
|
+
let staticNodePath = pattern.slice(parentNodePathIndex, i)
|
|
135
|
+
if (!this.options.caseSensitive) {
|
|
136
|
+
staticNodePath = staticNodePath.toLowerCase()
|
|
137
|
+
}
|
|
138
|
+
staticNodePath = staticNodePath.split("::").join(":")
|
|
139
|
+
staticNodePath = staticNodePath.split("%").join("%25")
|
|
140
|
+
// add the static part of the route to the tree
|
|
141
|
+
currentNode = (currentNode as StaticNode).createStaticChild(
|
|
142
|
+
staticNodePath
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (isParametricNode) {
|
|
147
|
+
let isRegexNode = false
|
|
148
|
+
let isParamSafe = true
|
|
149
|
+
let backtrack = ""
|
|
150
|
+
const regexps = []
|
|
151
|
+
let nodePatternParts = ""
|
|
152
|
+
|
|
153
|
+
let lastParamStartIndex = i + 1
|
|
154
|
+
for (let j = lastParamStartIndex;; j++) {
|
|
155
|
+
const charCode = pattern.charCodeAt(j)
|
|
156
|
+
|
|
157
|
+
const isRegexParam = charCode === 40
|
|
158
|
+
const isStaticPart = charCode === 45 || charCode === 46
|
|
159
|
+
const isEndOfNode = charCode === 47 || j === pattern.length
|
|
160
|
+
|
|
161
|
+
if (isRegexParam || isStaticPart || isEndOfNode) {
|
|
162
|
+
const paramName = pattern.slice(lastParamStartIndex, j)
|
|
163
|
+
params.push(paramName)
|
|
164
|
+
|
|
165
|
+
isRegexNode = isRegexNode || isRegexParam || isStaticPart
|
|
166
|
+
|
|
167
|
+
if (isRegexParam) {
|
|
168
|
+
const endOfRegexIndex = getClosingParenthensePosition(pattern, j)
|
|
169
|
+
const regexString = pattern.slice(j, endOfRegexIndex + 1)
|
|
170
|
+
|
|
171
|
+
regexps.push(trimRegExpStartAndEnd(regexString))
|
|
172
|
+
|
|
173
|
+
j = endOfRegexIndex + 1
|
|
174
|
+
isParamSafe = true
|
|
175
|
+
} else {
|
|
176
|
+
regexps.push(isParamSafe ? "(.*?)" : `(${backtrack}|(?:(?!${backtrack}).)*)`)
|
|
177
|
+
isParamSafe = false
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const staticPartStartIndex = j
|
|
181
|
+
for (; j < pattern.length; j++) {
|
|
182
|
+
const charCode = pattern.charCodeAt(j)
|
|
183
|
+
if (charCode === 47) break
|
|
184
|
+
if (charCode === 58) {
|
|
185
|
+
const nextCharCode = pattern.charCodeAt(j + 1)
|
|
186
|
+
if (nextCharCode === 58) j++
|
|
187
|
+
else break
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let staticPart = pattern.slice(staticPartStartIndex, j)
|
|
192
|
+
if (staticPart) {
|
|
193
|
+
staticPart = staticPart.split("::").join(":")
|
|
194
|
+
staticPart = staticPart.split("%").join("%25")
|
|
195
|
+
regexps.push(backtrack = escapeRegExp(staticPart))
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
lastParamStartIndex = j + 1
|
|
199
|
+
nodePatternParts += "()" + staticPart
|
|
200
|
+
|
|
201
|
+
if (
|
|
202
|
+
isEndOfNode ||
|
|
203
|
+
pattern.charCodeAt(j) === 47 ||
|
|
204
|
+
j === pattern.length
|
|
205
|
+
) {
|
|
206
|
+
const nodePattern = isRegexNode ? nodePatternParts : staticPart
|
|
207
|
+
const nodePath = pattern.slice(i, j)
|
|
208
|
+
|
|
209
|
+
pattern = pattern.slice(0, i + 1) + nodePattern + pattern.slice(j)
|
|
210
|
+
i += nodePattern.length
|
|
211
|
+
|
|
212
|
+
const regex = isRegexNode
|
|
213
|
+
? new RegExp("^" + regexps.join("") + "$")
|
|
214
|
+
: undefined
|
|
215
|
+
currentNode = (currentNode as StaticNode).createParametricChild(
|
|
216
|
+
regex,
|
|
217
|
+
staticPart,
|
|
218
|
+
nodePath
|
|
219
|
+
)
|
|
220
|
+
parentNodePathIndex = i + 1
|
|
221
|
+
break
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} else if (isWildcardNode) {
|
|
226
|
+
// add the wildcard parameter
|
|
227
|
+
params.push("*")
|
|
228
|
+
currentNode = (currentNode as StaticNode).createWildcardChild()
|
|
229
|
+
parentNodePathIndex = i + 1
|
|
230
|
+
|
|
231
|
+
if (i !== pattern.length - 1) {
|
|
232
|
+
throw new Error("Wildcard must be the last character in the route")
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!this.options.caseSensitive) {
|
|
238
|
+
pattern = pattern.toLowerCase() as Router.PathInput
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (pattern === "*") {
|
|
242
|
+
pattern = "/*"
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
for (const existRoute of this.routes) {
|
|
246
|
+
if (existRoute.method === method && existRoute.pattern === pattern) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`Method '${method}' already declared for route '${pattern}'`
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const route = { method, path, pattern, params, handler }
|
|
254
|
+
this.routes.push(route)
|
|
255
|
+
currentNode.addRoute(route)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
has(method: string, path: string): boolean {
|
|
259
|
+
const node = this.trees[method]
|
|
260
|
+
if (node === undefined) {
|
|
261
|
+
return false
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const staticNode = node.getStaticChild(path)
|
|
265
|
+
if (staticNode === undefined) {
|
|
266
|
+
return false
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return staticNode.isLeafNode
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
find(method: string, path: string): Router.FindResult<A> | undefined {
|
|
273
|
+
let currentNode: Node | undefined = this.trees[method]
|
|
274
|
+
if (currentNode === undefined) return undefined
|
|
275
|
+
|
|
276
|
+
if (path.charCodeAt(0) !== 47) {
|
|
277
|
+
// 47 is '/'
|
|
278
|
+
path = path.replace(FULL_PATH_REGEXP, "/")
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// This must be run before sanitizeUrl as the resulting function
|
|
282
|
+
// .sliceParameter must be constructed with same URL string used
|
|
283
|
+
// throughout the rest of this function.
|
|
284
|
+
if (this.options.ignoreDuplicateSlashes) {
|
|
285
|
+
path = removeDuplicateSlashes(path)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let sanitizedUrl
|
|
289
|
+
let querystring
|
|
290
|
+
let shouldDecodeParam
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
sanitizedUrl = safeDecodeURI(path)
|
|
294
|
+
path = sanitizedUrl.path
|
|
295
|
+
querystring = sanitizedUrl.querystring
|
|
296
|
+
shouldDecodeParam = sanitizedUrl.shouldDecodeParam
|
|
297
|
+
} catch (error) {
|
|
298
|
+
return undefined
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (this.options.ignoreTrailingSlash) {
|
|
302
|
+
path = trimLastSlash(path)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const originPath = path
|
|
306
|
+
|
|
307
|
+
if (this.options.caseSensitive === false) {
|
|
308
|
+
path = path.toLowerCase()
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const maxParamLength = this.options.maxParamLength
|
|
312
|
+
|
|
313
|
+
let pathIndex = (currentNode as StaticNode).prefix.length
|
|
314
|
+
const params = []
|
|
315
|
+
const pathLen = path.length
|
|
316
|
+
|
|
317
|
+
const brothersNodesStack: Array<BrotherNode> = []
|
|
318
|
+
|
|
319
|
+
while (true) {
|
|
320
|
+
if (pathIndex === pathLen && currentNode.isLeafNode) {
|
|
321
|
+
const handle = currentNode.handlerStorage?.find()
|
|
322
|
+
if (handle !== undefined) {
|
|
323
|
+
return {
|
|
324
|
+
handler: handle.handler as A,
|
|
325
|
+
params: handle.createParams(params),
|
|
326
|
+
searchParams: QS.parse(querystring)
|
|
327
|
+
} as const
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
let node: Node | undefined = currentNode.getNextNode(
|
|
332
|
+
path,
|
|
333
|
+
pathIndex,
|
|
334
|
+
brothersNodesStack,
|
|
335
|
+
params.length
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
if (node === undefined) {
|
|
339
|
+
if (brothersNodesStack.length === 0) {
|
|
340
|
+
return undefined
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const brotherNodeState = brothersNodesStack.pop()!
|
|
344
|
+
pathIndex = brotherNodeState.brotherPathIndex
|
|
345
|
+
params.splice(brotherNodeState.paramsCount)
|
|
346
|
+
node = brotherNodeState.brotherNode
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
currentNode = node
|
|
350
|
+
|
|
351
|
+
while (true) {
|
|
352
|
+
if (currentNode._tag === "StaticNode") {
|
|
353
|
+
pathIndex += currentNode.prefix.length
|
|
354
|
+
break
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (currentNode._tag === "WildcardNode") {
|
|
358
|
+
let param = originPath.slice(pathIndex)
|
|
359
|
+
if (shouldDecodeParam) {
|
|
360
|
+
param = safeDecodeURIComponent(param)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
params.push(param)
|
|
364
|
+
pathIndex = pathLen
|
|
365
|
+
break
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
let paramEndIndex = originPath.indexOf("/", pathIndex)
|
|
369
|
+
if (paramEndIndex === -1) {
|
|
370
|
+
paramEndIndex = pathLen
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
let param = originPath.slice(pathIndex, paramEndIndex)
|
|
374
|
+
if (shouldDecodeParam) {
|
|
375
|
+
param = safeDecodeURIComponent(param)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (currentNode.regex !== undefined) {
|
|
379
|
+
const matchedParameters: RegExpExecArray | null = currentNode.regex.exec(param)
|
|
380
|
+
if (matchedParameters === null) {
|
|
381
|
+
if (brothersNodesStack.length === 0) {
|
|
382
|
+
return undefined
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const brotherNodeState = brothersNodesStack.pop()!
|
|
386
|
+
pathIndex = brotherNodeState.brotherPathIndex
|
|
387
|
+
params.splice(brotherNodeState.paramsCount)
|
|
388
|
+
currentNode = brotherNodeState.brotherNode
|
|
389
|
+
continue
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let maxParamLengthExceeded = false
|
|
393
|
+
for (let i = 1; i < matchedParameters.length; i++) {
|
|
394
|
+
const matchedParam = matchedParameters[i] ?? ""
|
|
395
|
+
if (matchedParam.length > maxParamLength) {
|
|
396
|
+
maxParamLengthExceeded = true
|
|
397
|
+
break
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (maxParamLengthExceeded) {
|
|
402
|
+
if (brothersNodesStack.length === 0) {
|
|
403
|
+
return undefined
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const brotherNodeState = brothersNodesStack.pop()!
|
|
407
|
+
pathIndex = brotherNodeState.brotherPathIndex
|
|
408
|
+
params.splice(brotherNodeState.paramsCount)
|
|
409
|
+
currentNode = brotherNodeState.brotherNode
|
|
410
|
+
continue
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
for (let i = 1; i < matchedParameters.length; i++) {
|
|
414
|
+
params.push(matchedParameters[i] ?? "")
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
if (param.length > maxParamLength) {
|
|
418
|
+
if (brothersNodesStack.length === 0) {
|
|
419
|
+
return undefined
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const brotherNodeState = brothersNodesStack.pop()!
|
|
423
|
+
pathIndex = brotherNodeState.brotherPathIndex
|
|
424
|
+
params.splice(brotherNodeState.paramsCount)
|
|
425
|
+
currentNode = brotherNodeState.brotherNode
|
|
426
|
+
continue
|
|
427
|
+
}
|
|
428
|
+
params.push(param)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
pathIndex = paramEndIndex
|
|
432
|
+
break
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// ----------------------------------------------------------------------------
|
|
439
|
+
// Handler storage
|
|
440
|
+
// ----------------------------------------------------------------------------
|
|
441
|
+
|
|
442
|
+
interface Handler {
|
|
443
|
+
readonly params: ReadonlyArray<string>
|
|
444
|
+
readonly handler: unknown
|
|
445
|
+
readonly createParams: (
|
|
446
|
+
paramsArray: ReadonlyArray<string>
|
|
447
|
+
) => Record<string, string>
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
class HandlerStorage {
|
|
451
|
+
readonly handlers: Array<Handler> = []
|
|
452
|
+
unconstrainedHandler: Handler | undefined
|
|
453
|
+
|
|
454
|
+
find() {
|
|
455
|
+
return this.unconstrainedHandler
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
add(route: Route) {
|
|
459
|
+
const handler: Handler = {
|
|
460
|
+
params: route.params,
|
|
461
|
+
handler: route.handler,
|
|
462
|
+
createParams: compileCreateParams(route.params)
|
|
463
|
+
}
|
|
464
|
+
this.handlers.push(handler)
|
|
465
|
+
this.unconstrainedHandler = this.handlers[0]
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ----------------------------------------------------------------------------
|
|
470
|
+
// Nodes
|
|
471
|
+
// ----------------------------------------------------------------------------
|
|
472
|
+
|
|
473
|
+
interface BrotherNode {
|
|
474
|
+
readonly paramsCount: number
|
|
475
|
+
readonly brotherPathIndex: number
|
|
476
|
+
readonly brotherNode: Node
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
type Node = StaticNode | ParametricNode | WildcardNode
|
|
480
|
+
|
|
481
|
+
abstract class NodeBase {
|
|
482
|
+
isLeafNode = false
|
|
483
|
+
routes: Array<Route> | undefined
|
|
484
|
+
handlerStorage: HandlerStorage | undefined
|
|
485
|
+
|
|
486
|
+
addRoute(route: Route) {
|
|
487
|
+
if (this.routes === undefined) {
|
|
488
|
+
this.routes = [route]
|
|
489
|
+
} else {
|
|
490
|
+
this.routes.push(route)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (this.handlerStorage === undefined) {
|
|
494
|
+
this.handlerStorage = new HandlerStorage()
|
|
495
|
+
}
|
|
496
|
+
this.isLeafNode = true
|
|
497
|
+
this.handlerStorage.add(route)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
abstract getNextNode(
|
|
501
|
+
path: string,
|
|
502
|
+
pathIndex: number,
|
|
503
|
+
nodeStack: any,
|
|
504
|
+
paramsCount: number
|
|
505
|
+
): Node | undefined
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
abstract class ParentNode extends NodeBase {
|
|
509
|
+
readonly staticChildren: Record<string, StaticNode> = Object.create(null)
|
|
510
|
+
|
|
511
|
+
findStaticMatchingChild(
|
|
512
|
+
path: string,
|
|
513
|
+
pathIndex: number
|
|
514
|
+
): StaticNode | undefined {
|
|
515
|
+
const staticChild = this.staticChildren[path.charAt(pathIndex)]
|
|
516
|
+
if (
|
|
517
|
+
staticChild === undefined ||
|
|
518
|
+
!staticChild.matchPrefix(path, pathIndex)
|
|
519
|
+
) {
|
|
520
|
+
return undefined
|
|
521
|
+
}
|
|
522
|
+
return staticChild
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
getStaticChild(path: string, pathIndex = 0): StaticNode | undefined {
|
|
526
|
+
if (path.length === pathIndex) {
|
|
527
|
+
return this as any
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const staticChild = this.findStaticMatchingChild(path, pathIndex)
|
|
531
|
+
if (staticChild === undefined) {
|
|
532
|
+
return undefined
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return staticChild.getStaticChild(
|
|
536
|
+
path,
|
|
537
|
+
pathIndex + staticChild.prefix.length
|
|
538
|
+
)
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
createStaticChild(path: string): StaticNode {
|
|
542
|
+
if (path.length === 0) {
|
|
543
|
+
return this as any
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
let staticChild = this.staticChildren[path.charAt(0)]
|
|
547
|
+
if (staticChild) {
|
|
548
|
+
let i = 1
|
|
549
|
+
for (; i < staticChild.prefix.length; i++) {
|
|
550
|
+
if (path.charCodeAt(i) !== staticChild.prefix.charCodeAt(i)) {
|
|
551
|
+
staticChild = staticChild.split(this, i)
|
|
552
|
+
break
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return staticChild.createStaticChild(path.slice(i))
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const label = path.charAt(0)
|
|
559
|
+
this.staticChildren[label] = new StaticNode(path)
|
|
560
|
+
return this.staticChildren[label]
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
class StaticNode extends ParentNode {
|
|
565
|
+
readonly _tag = "StaticNode"
|
|
566
|
+
constructor(prefix: string) {
|
|
567
|
+
super()
|
|
568
|
+
this.setPrefix(prefix)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
prefix!: string
|
|
572
|
+
matchPrefix!: (path: string, pathIndex: number) => boolean
|
|
573
|
+
readonly parametricChildren: Array<ParametricNode> = []
|
|
574
|
+
|
|
575
|
+
wildcardChild: WildcardNode | undefined
|
|
576
|
+
|
|
577
|
+
private setPrefix(prefix: string) {
|
|
578
|
+
this.prefix = prefix
|
|
579
|
+
|
|
580
|
+
if (prefix.length === 1) {
|
|
581
|
+
this.matchPrefix = (_path, _pathIndex) => true
|
|
582
|
+
} else {
|
|
583
|
+
const len = prefix.length
|
|
584
|
+
this.matchPrefix = function(path, pathIndex) {
|
|
585
|
+
for (let i = 1; i < len; i++) {
|
|
586
|
+
if (path.charCodeAt(pathIndex + i) !== this.prefix.charCodeAt(i)) {
|
|
587
|
+
return false
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return true
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
getParametricChild(regex: RegExp | undefined): ParametricNode | undefined {
|
|
596
|
+
if (regex === undefined) {
|
|
597
|
+
return this.parametricChildren.find((child) => child.isRegex === false)
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const source = regex.source
|
|
601
|
+
return this.parametricChildren.find((child) => {
|
|
602
|
+
if (child.regex === undefined) {
|
|
603
|
+
return false
|
|
604
|
+
}
|
|
605
|
+
return child.regex.source === source
|
|
606
|
+
})
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
createParametricChild(
|
|
610
|
+
regex: RegExp | undefined,
|
|
611
|
+
staticSuffix: string | undefined,
|
|
612
|
+
nodePath: string
|
|
613
|
+
) {
|
|
614
|
+
let child = this.getParametricChild(regex)
|
|
615
|
+
if (child !== undefined) {
|
|
616
|
+
child.nodePaths.add(nodePath)
|
|
617
|
+
return child
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
child = new ParametricNode(regex, staticSuffix, nodePath)
|
|
621
|
+
this.parametricChildren.push(child)
|
|
622
|
+
this.parametricChildren.sort((child1, child2) => {
|
|
623
|
+
if (!child1.isRegex) return 1
|
|
624
|
+
if (!child2.isRegex) return -1
|
|
625
|
+
|
|
626
|
+
if (child1.staticSuffix === undefined) return 1
|
|
627
|
+
if (child2.staticSuffix === undefined) return -1
|
|
628
|
+
|
|
629
|
+
if (child2.staticSuffix.endsWith(child1.staticSuffix)) return 1
|
|
630
|
+
if (child1.staticSuffix.endsWith(child2.staticSuffix)) return -1
|
|
631
|
+
|
|
632
|
+
return 0
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
return child
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
createWildcardChild() {
|
|
639
|
+
if (this.wildcardChild === undefined) {
|
|
640
|
+
this.wildcardChild = new WildcardNode()
|
|
641
|
+
}
|
|
642
|
+
return this.wildcardChild
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
split(parentNode: ParentNode, length: number) {
|
|
646
|
+
const parentPrefix = this.prefix.slice(0, length)
|
|
647
|
+
const childPrefix = this.prefix.slice(length)
|
|
648
|
+
|
|
649
|
+
this.setPrefix(childPrefix)
|
|
650
|
+
|
|
651
|
+
const staticNode = new StaticNode(parentPrefix)
|
|
652
|
+
staticNode.staticChildren[childPrefix.charAt(0)] = this
|
|
653
|
+
parentNode.staticChildren[parentPrefix.charAt(0)] = staticNode
|
|
654
|
+
|
|
655
|
+
return staticNode
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
getNextNode(
|
|
659
|
+
path: string,
|
|
660
|
+
pathIndex: number,
|
|
661
|
+
nodeStack: Array<BrotherNode>,
|
|
662
|
+
paramsCount: number
|
|
663
|
+
): Node | undefined {
|
|
664
|
+
let node: Node | undefined = this.findStaticMatchingChild(path, pathIndex)
|
|
665
|
+
let parametricBrotherNodeIndex = 0
|
|
666
|
+
|
|
667
|
+
if (node === undefined) {
|
|
668
|
+
if (this.parametricChildren.length === 0) {
|
|
669
|
+
return this.wildcardChild
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
node = this.parametricChildren[0]
|
|
673
|
+
parametricBrotherNodeIndex = 1
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (this.wildcardChild !== undefined) {
|
|
677
|
+
nodeStack.push({
|
|
678
|
+
paramsCount,
|
|
679
|
+
brotherPathIndex: pathIndex,
|
|
680
|
+
brotherNode: this.wildcardChild
|
|
681
|
+
})
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
for (
|
|
685
|
+
let i = this.parametricChildren.length - 1;
|
|
686
|
+
i >= parametricBrotherNodeIndex;
|
|
687
|
+
i--
|
|
688
|
+
) {
|
|
689
|
+
nodeStack.push({
|
|
690
|
+
paramsCount,
|
|
691
|
+
brotherPathIndex: pathIndex,
|
|
692
|
+
brotherNode: this.parametricChildren[i]
|
|
693
|
+
})
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return node
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
class ParametricNode extends ParentNode {
|
|
701
|
+
readonly _tag = "ParametricNode"
|
|
702
|
+
readonly regex: RegExp | undefined
|
|
703
|
+
readonly staticSuffix: string | undefined
|
|
704
|
+
constructor(
|
|
705
|
+
regex: RegExp | undefined,
|
|
706
|
+
staticSuffix: string | undefined,
|
|
707
|
+
nodePath: string
|
|
708
|
+
) {
|
|
709
|
+
super()
|
|
710
|
+
this.regex = regex
|
|
711
|
+
this.staticSuffix = staticSuffix
|
|
712
|
+
this.isRegex = !!regex
|
|
713
|
+
this.nodePaths = new Set([nodePath])
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
readonly isRegex: boolean
|
|
717
|
+
readonly nodePaths: Set<string>
|
|
718
|
+
|
|
719
|
+
getNextNode(path: string, pathIndex: number) {
|
|
720
|
+
return this.findStaticMatchingChild(path, pathIndex)
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
class WildcardNode extends NodeBase {
|
|
725
|
+
readonly _tag = "WildcardNode"
|
|
726
|
+
getNextNode(
|
|
727
|
+
_path: string,
|
|
728
|
+
_pathIndex: number,
|
|
729
|
+
_nodeStack: any,
|
|
730
|
+
_paramsCount: number
|
|
731
|
+
): Node | undefined {
|
|
732
|
+
return undefined
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// --
|
|
737
|
+
|
|
738
|
+
interface Assert {
|
|
739
|
+
(condition: any, message?: string): asserts condition
|
|
740
|
+
}
|
|
741
|
+
const assert: Assert = (condition, message) => {
|
|
742
|
+
if (!condition) {
|
|
743
|
+
throw new Error(message)
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function removeDuplicateSlashes(path: string): Router.PathInput {
|
|
748
|
+
return path.replace(/\/\/+/g, "/") as Router.PathInput
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function trimLastSlash(path: string): Router.PathInput {
|
|
752
|
+
if (path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
|
|
753
|
+
return path.slice(0, -1) as Router.PathInput
|
|
754
|
+
}
|
|
755
|
+
return path as Router.PathInput
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
function compileCreateParams(
|
|
759
|
+
params: ReadonlyArray<string>
|
|
760
|
+
): (paramsArray: ReadonlyArray<string>) => Record<string, string> {
|
|
761
|
+
const len = params.length
|
|
762
|
+
return function(paramsArray) {
|
|
763
|
+
const paramsObject: Record<string, string> = Object.create(null)
|
|
764
|
+
for (let i = 0; i < len; i++) {
|
|
765
|
+
paramsObject[params[i]] = paramsArray[i]
|
|
766
|
+
}
|
|
767
|
+
return paramsObject
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function getClosingParenthensePosition(path: string, idx: number) {
|
|
772
|
+
// `path.indexOf()` will always return the first position of the closing parenthese,
|
|
773
|
+
// but it's inefficient for grouped or wrong regexp expressions.
|
|
774
|
+
// see issues #62 and #63 for more info
|
|
775
|
+
|
|
776
|
+
let parentheses = 1
|
|
777
|
+
|
|
778
|
+
while (idx < path.length) {
|
|
779
|
+
idx++
|
|
780
|
+
|
|
781
|
+
// ignore skipped chars
|
|
782
|
+
if (path[idx] === "\\") {
|
|
783
|
+
idx++
|
|
784
|
+
continue
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
if (path[idx] === ")") {
|
|
788
|
+
parentheses--
|
|
789
|
+
} else if (path[idx] === "(") {
|
|
790
|
+
parentheses++
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
if (!parentheses) return idx
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
throw new TypeError("Invalid regexp expression in \"" + path + "\"")
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function trimRegExpStartAndEnd(regexString: string) {
|
|
800
|
+
// removes chars that marks start "^" and end "$" of regexp
|
|
801
|
+
if (regexString.charCodeAt(1) === 94) {
|
|
802
|
+
regexString = regexString.slice(0, 1) + regexString.slice(2)
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (regexString.charCodeAt(regexString.length - 2) === 36) {
|
|
806
|
+
regexString = regexString.slice(0, regexString.length - 2) +
|
|
807
|
+
regexString.slice(regexString.length - 1)
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
return regexString
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function escapeRegExp(string: string) {
|
|
814
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// It must spot all the chars where decodeURIComponent(x) !== decodeURI(x)
|
|
818
|
+
// The chars are: # $ & + , / : ; = ? @
|
|
819
|
+
function decodeComponentChar(highCharCode: number, lowCharCode: number) {
|
|
820
|
+
if (highCharCode === 50) {
|
|
821
|
+
if (lowCharCode === 53) return "%"
|
|
822
|
+
|
|
823
|
+
if (lowCharCode === 51) return "#"
|
|
824
|
+
if (lowCharCode === 52) return "$"
|
|
825
|
+
if (lowCharCode === 54) return "&"
|
|
826
|
+
if (lowCharCode === 66) return "+"
|
|
827
|
+
if (lowCharCode === 98) return "+"
|
|
828
|
+
if (lowCharCode === 67) return ","
|
|
829
|
+
if (lowCharCode === 99) return ","
|
|
830
|
+
if (lowCharCode === 70) return "/"
|
|
831
|
+
if (lowCharCode === 102) return "/"
|
|
832
|
+
return undefined
|
|
833
|
+
}
|
|
834
|
+
if (highCharCode === 51) {
|
|
835
|
+
if (lowCharCode === 65) return ":"
|
|
836
|
+
if (lowCharCode === 97) return ":"
|
|
837
|
+
if (lowCharCode === 66) return ";"
|
|
838
|
+
if (lowCharCode === 98) return ";"
|
|
839
|
+
if (lowCharCode === 68) return "="
|
|
840
|
+
if (lowCharCode === 100) return "="
|
|
841
|
+
if (lowCharCode === 70) return "?"
|
|
842
|
+
if (lowCharCode === 102) return "?"
|
|
843
|
+
return undefined
|
|
844
|
+
}
|
|
845
|
+
if (highCharCode === 52 && lowCharCode === 48) {
|
|
846
|
+
return "@"
|
|
847
|
+
}
|
|
848
|
+
return undefined
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function safeDecodeURI(path: string) {
|
|
852
|
+
let shouldDecode = false
|
|
853
|
+
let shouldDecodeParam = false
|
|
854
|
+
|
|
855
|
+
let querystring = ""
|
|
856
|
+
|
|
857
|
+
for (let i = 1; i < path.length; i++) {
|
|
858
|
+
const charCode = path.charCodeAt(i)
|
|
859
|
+
|
|
860
|
+
if (charCode === 37) {
|
|
861
|
+
const highCharCode = path.charCodeAt(i + 1)
|
|
862
|
+
const lowCharCode = path.charCodeAt(i + 2)
|
|
863
|
+
|
|
864
|
+
if (decodeComponentChar(highCharCode, lowCharCode) === undefined) {
|
|
865
|
+
shouldDecode = true
|
|
866
|
+
} else {
|
|
867
|
+
shouldDecodeParam = true
|
|
868
|
+
// %25 - encoded % char. We need to encode one more time to prevent double decoding
|
|
869
|
+
if (highCharCode === 50 && lowCharCode === 53) {
|
|
870
|
+
shouldDecode = true
|
|
871
|
+
path = path.slice(0, i + 1) + "25" + path.slice(i + 1)
|
|
872
|
+
i += 2
|
|
873
|
+
}
|
|
874
|
+
i += 2
|
|
875
|
+
}
|
|
876
|
+
// Some systems do not follow RFC and separate the path and query
|
|
877
|
+
// string with a `;` character (code 59), e.g. `/foo;jsessionid=123456`.
|
|
878
|
+
// Thus, we need to split on `;` as well as `?` and `#`.
|
|
879
|
+
} else if (charCode === 63 || charCode === 59 || charCode === 35) {
|
|
880
|
+
querystring = path.slice(i + 1)
|
|
881
|
+
path = path.slice(0, i)
|
|
882
|
+
break
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
const decodedPath = shouldDecode ? decodeURI(path) : path
|
|
886
|
+
return { path: decodedPath, querystring, shouldDecodeParam } as const
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function safeDecodeURIComponent(uriComponent: string) {
|
|
890
|
+
const startIndex = uriComponent.indexOf("%")
|
|
891
|
+
if (startIndex === -1) return uriComponent
|
|
892
|
+
|
|
893
|
+
let decoded = ""
|
|
894
|
+
let lastIndex = startIndex
|
|
895
|
+
|
|
896
|
+
for (let i = startIndex; i < uriComponent.length; i++) {
|
|
897
|
+
if (uriComponent.charCodeAt(i) === 37) {
|
|
898
|
+
if (i + 2 >= uriComponent.length) break
|
|
899
|
+
|
|
900
|
+
const highCharCode = uriComponent.charCodeAt(i + 1)
|
|
901
|
+
const lowCharCode = uriComponent.charCodeAt(i + 2)
|
|
902
|
+
|
|
903
|
+
const decodedChar = decodeComponentChar(highCharCode, lowCharCode)
|
|
904
|
+
decoded += uriComponent.slice(lastIndex, i) + decodedChar
|
|
905
|
+
|
|
906
|
+
lastIndex = i + 3
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return (
|
|
910
|
+
uriComponent.slice(0, startIndex) + decoded + uriComponent.slice(lastIndex)
|
|
911
|
+
)
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
const httpMethods = [
|
|
915
|
+
"ACL",
|
|
916
|
+
"BIND",
|
|
917
|
+
"CHECKOUT",
|
|
918
|
+
"CONNECT",
|
|
919
|
+
"COPY",
|
|
920
|
+
"DELETE",
|
|
921
|
+
"GET",
|
|
922
|
+
"HEAD",
|
|
923
|
+
"LINK",
|
|
924
|
+
"LOCK",
|
|
925
|
+
"M-SEARCH",
|
|
926
|
+
"MERGE",
|
|
927
|
+
"MKACTIVITY",
|
|
928
|
+
"MKCALENDAR",
|
|
929
|
+
"MKCOL",
|
|
930
|
+
"MOVE",
|
|
931
|
+
"NOTIFY",
|
|
932
|
+
"OPTIONS",
|
|
933
|
+
"PATCH",
|
|
934
|
+
"POST",
|
|
935
|
+
"PROPFIND",
|
|
936
|
+
"PROPPATCH",
|
|
937
|
+
"PURGE",
|
|
938
|
+
"PUT",
|
|
939
|
+
"QUERY",
|
|
940
|
+
"REBIND",
|
|
941
|
+
"REPORT",
|
|
942
|
+
"SEARCH",
|
|
943
|
+
"SOURCE",
|
|
944
|
+
"SUBSCRIBE",
|
|
945
|
+
"TRACE",
|
|
946
|
+
"UNBIND",
|
|
947
|
+
"UNLINK",
|
|
948
|
+
"UNLOCK",
|
|
949
|
+
"UNSUBSCRIBE"
|
|
950
|
+
] as const
|