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.
Files changed (667) hide show
  1. package/AGENTS.md +381 -0
  2. package/CLAUDE.md +381 -0
  3. package/ai-docs/README.md +44 -0
  4. package/ai-docs/package.json +36 -0
  5. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  6. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
  7. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  8. package/ai-docs/src/01_effect/01_basics/index.md +5 -0
  9. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  10. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  11. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  12. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  13. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  14. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  15. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  16. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  17. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  18. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  19. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  20. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  21. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  22. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  23. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  24. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  25. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  26. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  27. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  28. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  29. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  30. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  31. package/ai-docs/src/03_stream/30_encoding.ts +165 -0
  32. package/ai-docs/src/03_stream/index.md +4 -0
  33. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  34. package/ai-docs/src/04_integration/index.md +5 -0
  35. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  36. package/ai-docs/src/05_batching/index.md +3 -0
  37. package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
  38. package/ai-docs/src/06_schedule/index.md +3 -0
  39. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  40. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  41. package/ai-docs/src/07_datetime/index.md +5 -0
  42. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  43. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  44. package/ai-docs/src/08_observability/index.md +7 -0
  45. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  46. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  47. package/ai-docs/src/09_testing/index.md +1 -0
  48. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  49. package/ai-docs/src/10_predicate/index.md +9 -0
  50. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  51. package/ai-docs/src/50_http-client/index.md +3 -0
  52. package/ai-docs/src/51_http-server/10_basics.ts +116 -0
  53. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  54. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  55. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  56. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
  57. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
  58. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  59. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
  60. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
  61. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
  62. package/ai-docs/src/51_http-server/index.md +3 -0
  63. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  64. package/ai-docs/src/60_child-process/index.md +3 -0
  65. package/ai-docs/src/70_cli/10_basics.ts +136 -0
  66. package/ai-docs/src/70_cli/index.md +5 -0
  67. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  68. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  69. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  70. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  71. package/ai-docs/src/71_ai/index.md +5 -0
  72. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  73. package/ai-docs/src/80_cluster/index.md +4 -0
  74. package/ai-docs/src/index.md +10 -0
  75. package/ai-docs/tsconfig.json +24 -0
  76. package/dist/Brand.d.ts +3 -3
  77. package/dist/Brand.d.ts.map +1 -1
  78. package/dist/Brand.js +4 -3
  79. package/dist/Brand.js.map +1 -1
  80. package/dist/Cache.js +1 -1
  81. package/dist/Cache.js.map +1 -1
  82. package/dist/Channel.d.ts +1 -1
  83. package/dist/Channel.d.ts.map +1 -1
  84. package/dist/Channel.js.map +1 -1
  85. package/dist/Config.d.ts.map +1 -1
  86. package/dist/Config.js +30 -8
  87. package/dist/Config.js.map +1 -1
  88. package/dist/ConfigProvider.d.ts.map +1 -1
  89. package/dist/ConfigProvider.js +2 -1
  90. package/dist/ConfigProvider.js.map +1 -1
  91. package/dist/Context.d.ts +2 -3
  92. package/dist/Context.d.ts.map +1 -1
  93. package/dist/Context.js +1 -22
  94. package/dist/Context.js.map +1 -1
  95. package/dist/Cron.d.ts +31 -0
  96. package/dist/Cron.d.ts.map +1 -1
  97. package/dist/Cron.js +58 -2
  98. package/dist/Cron.js.map +1 -1
  99. package/dist/Crypto.d.ts.map +1 -1
  100. package/dist/Crypto.js +13 -5
  101. package/dist/Crypto.js.map +1 -1
  102. package/dist/Duration.d.ts.map +1 -1
  103. package/dist/Duration.js +12 -1
  104. package/dist/Duration.js.map +1 -1
  105. package/dist/Effect.d.ts +132 -14
  106. package/dist/Effect.d.ts.map +1 -1
  107. package/dist/Effect.js +38 -0
  108. package/dist/Effect.js.map +1 -1
  109. package/dist/Equal.d.ts.map +1 -1
  110. package/dist/Equal.js +10 -2
  111. package/dist/Equal.js.map +1 -1
  112. package/dist/ExecutionPlan.d.ts +73 -0
  113. package/dist/ExecutionPlan.d.ts.map +1 -1
  114. package/dist/ExecutionPlan.js +1 -1
  115. package/dist/ExecutionPlan.js.map +1 -1
  116. package/dist/FiberSet.js +1 -1
  117. package/dist/FileSystem.d.ts +2 -2
  118. package/dist/Function.d.ts +4 -3
  119. package/dist/Function.d.ts.map +1 -1
  120. package/dist/Function.js +5 -5
  121. package/dist/Function.js.map +1 -1
  122. package/dist/Iterable.d.ts.map +1 -1
  123. package/dist/Iterable.js +11 -10
  124. package/dist/Iterable.js.map +1 -1
  125. package/dist/Layer.d.ts.map +1 -1
  126. package/dist/Layer.js +7 -5
  127. package/dist/Layer.js.map +1 -1
  128. package/dist/Optic.d.ts +35 -21
  129. package/dist/Optic.d.ts.map +1 -1
  130. package/dist/Optic.js +33 -34
  131. package/dist/Optic.js.map +1 -1
  132. package/dist/Schedule.d.ts +8 -8
  133. package/dist/Schedule.d.ts.map +1 -1
  134. package/dist/Schedule.js +4 -4
  135. package/dist/Schedule.js.map +1 -1
  136. package/dist/Schema.d.ts +105 -57
  137. package/dist/Schema.d.ts.map +1 -1
  138. package/dist/Schema.js +105 -67
  139. package/dist/Schema.js.map +1 -1
  140. package/dist/SchemaAST.d.ts +33 -3
  141. package/dist/SchemaAST.d.ts.map +1 -1
  142. package/dist/SchemaAST.js +87 -63
  143. package/dist/SchemaAST.js.map +1 -1
  144. package/dist/SchemaError.d.ts +8 -8
  145. package/dist/SchemaError.d.ts.map +1 -1
  146. package/dist/SchemaError.js +7 -6
  147. package/dist/SchemaError.js.map +1 -1
  148. package/dist/SchemaGetter.d.ts +8 -5
  149. package/dist/SchemaGetter.d.ts.map +1 -1
  150. package/dist/SchemaGetter.js +41 -37
  151. package/dist/SchemaGetter.js.map +1 -1
  152. package/dist/SchemaIssue.d.ts +195 -38
  153. package/dist/SchemaIssue.d.ts.map +1 -1
  154. package/dist/SchemaIssue.js +243 -68
  155. package/dist/SchemaIssue.js.map +1 -1
  156. package/dist/SchemaParser.d.ts +30 -0
  157. package/dist/SchemaParser.d.ts.map +1 -1
  158. package/dist/SchemaParser.js +74 -62
  159. package/dist/SchemaParser.js.map +1 -1
  160. package/dist/SchemaTransformation.d.ts +2 -2
  161. package/dist/SchemaTransformation.d.ts.map +1 -1
  162. package/dist/SchemaTransformation.js +26 -26
  163. package/dist/SchemaTransformation.js.map +1 -1
  164. package/dist/ScopedCache.js +1 -1
  165. package/dist/ScopedCache.js.map +1 -1
  166. package/dist/Sink.d.ts +1 -1
  167. package/dist/Sink.d.ts.map +1 -1
  168. package/dist/Stdio.d.ts +17 -4
  169. package/dist/Stdio.d.ts.map +1 -1
  170. package/dist/Stdio.js +6 -3
  171. package/dist/Stdio.js.map +1 -1
  172. package/dist/Stream.d.ts +27 -4
  173. package/dist/Stream.d.ts.map +1 -1
  174. package/dist/Stream.js +27 -2
  175. package/dist/Stream.js.map +1 -1
  176. package/dist/SynchronizedRef.js +1 -1
  177. package/dist/SynchronizedRef.js.map +1 -1
  178. package/dist/Terminal.js +1 -1
  179. package/dist/Terminal.js.map +1 -1
  180. package/dist/Tuple.d.ts +6 -4
  181. package/dist/Tuple.d.ts.map +1 -1
  182. package/dist/Tuple.js.map +1 -1
  183. package/dist/TxReentrantLock.d.ts +0 -56
  184. package/dist/TxReentrantLock.d.ts.map +1 -1
  185. package/dist/TxReentrantLock.js +8 -8
  186. package/dist/TxReentrantLock.js.map +1 -1
  187. package/dist/internal/dateTime.js +1 -1
  188. package/dist/internal/dateTime.js.map +1 -1
  189. package/dist/internal/executionPlan.js +51 -3
  190. package/dist/internal/executionPlan.js.map +1 -1
  191. package/dist/internal/hashMap.js +12 -8
  192. package/dist/internal/hashMap.js.map +1 -1
  193. package/dist/internal/matcher.js +1 -1
  194. package/dist/internal/matcher.js.map +1 -1
  195. package/dist/internal/schedule.js.map +1 -1
  196. package/dist/internal/schema/annotations.js +2 -0
  197. package/dist/internal/schema/annotations.js.map +1 -1
  198. package/dist/internal/schema/schema.js +1 -9
  199. package/dist/internal/schema/schema.js.map +1 -1
  200. package/dist/internal/schema/toArbitrary.js +1 -1
  201. package/dist/internal/schema/toArbitrary.js.map +1 -1
  202. package/dist/internal/trie.js +13 -3
  203. package/dist/internal/trie.js.map +1 -1
  204. package/dist/testing/TestClock.d.ts.map +1 -1
  205. package/dist/testing/TestClock.js +11 -1
  206. package/dist/testing/TestClock.js.map +1 -1
  207. package/dist/testing/TestSchema.d.ts +2 -2
  208. package/dist/testing/TestSchema.d.ts.map +1 -1
  209. package/dist/testing/TestSchema.js +8 -7
  210. package/dist/testing/TestSchema.js.map +1 -1
  211. package/dist/unstable/ai/AiError.js +19 -19
  212. package/dist/unstable/ai/AiError.js.map +1 -1
  213. package/dist/unstable/ai/Chat.js +1 -1
  214. package/dist/unstable/ai/Chat.js.map +1 -1
  215. package/dist/unstable/ai/LanguageModel.js +4 -2
  216. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  217. package/dist/unstable/ai/McpSchema.d.ts +132 -132
  218. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  219. package/dist/unstable/ai/McpSchema.js +8 -8
  220. package/dist/unstable/ai/McpSchema.js.map +1 -1
  221. package/dist/unstable/ai/McpServer.js +1 -1
  222. package/dist/unstable/ai/McpServer.js.map +1 -1
  223. package/dist/unstable/ai/Prompt.d.ts +15 -3
  224. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  225. package/dist/unstable/ai/Prompt.js +10 -7
  226. package/dist/unstable/ai/Prompt.js.map +1 -1
  227. package/dist/unstable/cli/CliError.d.ts +3 -3
  228. package/dist/unstable/cli/CliError.js +11 -11
  229. package/dist/unstable/cli/CliError.js.map +1 -1
  230. package/dist/unstable/cli/Command.d.ts +9 -9
  231. package/dist/unstable/cli/Command.d.ts.map +1 -1
  232. package/dist/unstable/cli/Command.js +8 -6
  233. package/dist/unstable/cli/Command.js.map +1 -1
  234. package/dist/unstable/cli/Param.d.ts +7 -5
  235. package/dist/unstable/cli/Param.d.ts.map +1 -1
  236. package/dist/unstable/cli/Param.js +15 -11
  237. package/dist/unstable/cli/Param.js.map +1 -1
  238. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  239. package/dist/unstable/cli/Primitive.js +31 -24
  240. package/dist/unstable/cli/Primitive.js.map +1 -1
  241. package/dist/unstable/cli/Prompt.d.ts.map +1 -1
  242. package/dist/unstable/cli/Prompt.js +31 -17
  243. package/dist/unstable/cli/Prompt.js.map +1 -1
  244. package/dist/unstable/cli/internal/ansi.js +2 -2
  245. package/dist/unstable/cli/internal/ansi.js.map +1 -1
  246. package/dist/unstable/cli/internal/command.d.ts +2 -2
  247. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  248. package/dist/unstable/cli/internal/command.js +10 -9
  249. package/dist/unstable/cli/internal/command.js.map +1 -1
  250. package/dist/unstable/cli/internal/completions/bash.js +69 -9
  251. package/dist/unstable/cli/internal/completions/bash.js.map +1 -1
  252. package/dist/unstable/cli/internal/completions/descriptor.js +24 -18
  253. package/dist/unstable/cli/internal/completions/descriptor.js.map +1 -1
  254. package/dist/unstable/cli/internal/completions/fish.js +5 -5
  255. package/dist/unstable/cli/internal/completions/fish.js.map +1 -1
  256. package/dist/unstable/cli/internal/help.d.ts.map +1 -1
  257. package/dist/unstable/cli/internal/help.js +4 -2
  258. package/dist/unstable/cli/internal/help.js.map +1 -1
  259. package/dist/unstable/cli/internal/parser.js +3 -3
  260. package/dist/unstable/cli/internal/parser.js.map +1 -1
  261. package/dist/unstable/cli/internal/wizard.js +2 -2
  262. package/dist/unstable/cli/internal/wizard.js.map +1 -1
  263. package/dist/unstable/cluster/ClusterError.js +7 -7
  264. package/dist/unstable/cluster/ClusterError.js.map +1 -1
  265. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  266. package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
  267. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  268. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  269. package/dist/unstable/cluster/MessageStorage.js +8 -1
  270. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  271. package/dist/unstable/cluster/Reply.d.ts +8 -0
  272. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  273. package/dist/unstable/cluster/Reply.js +16 -4
  274. package/dist/unstable/cluster/Reply.js.map +1 -1
  275. package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
  276. package/dist/unstable/cluster/RunnerServer.js +4 -2
  277. package/dist/unstable/cluster/RunnerServer.js.map +1 -1
  278. package/dist/unstable/cluster/RunnerStorage.d.ts +1 -2
  279. package/dist/unstable/cluster/RunnerStorage.d.ts.map +1 -1
  280. package/dist/unstable/cluster/RunnerStorage.js +7 -6
  281. package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
  282. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  283. package/dist/unstable/cluster/Sharding.js +22 -4
  284. package/dist/unstable/cluster/Sharding.js.map +1 -1
  285. package/dist/unstable/cluster/internal/entityManager.js +1 -1
  286. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  287. package/dist/unstable/cluster/internal/resourceMap.js +2 -2
  288. package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
  289. package/dist/unstable/cluster/internal/resourceRef.js +17 -0
  290. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  291. package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
  292. package/dist/unstable/devtools/DevToolsClient.js +7 -2
  293. package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
  294. package/dist/unstable/encoding/Ini.d.ts +20 -0
  295. package/dist/unstable/encoding/Ini.d.ts.map +1 -0
  296. package/dist/unstable/encoding/Ini.js +153 -0
  297. package/dist/unstable/encoding/Ini.js.map +1 -0
  298. package/dist/unstable/encoding/Msgpack.d.ts +2 -1
  299. package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
  300. package/dist/unstable/encoding/Msgpack.js +27 -13
  301. package/dist/unstable/encoding/Msgpack.js.map +1 -1
  302. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  303. package/dist/unstable/encoding/Ndjson.js +7 -1
  304. package/dist/unstable/encoding/Ndjson.js.map +1 -1
  305. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  306. package/dist/unstable/encoding/Sse.js +14 -23
  307. package/dist/unstable/encoding/Sse.js.map +1 -1
  308. package/dist/unstable/encoding/Toml.d.ts +19 -0
  309. package/dist/unstable/encoding/Toml.d.ts.map +1 -0
  310. package/dist/unstable/encoding/Toml.js +434 -0
  311. package/dist/unstable/encoding/Toml.js.map +1 -0
  312. package/dist/unstable/encoding/Yaml.d.ts +19 -0
  313. package/dist/unstable/encoding/Yaml.d.ts.map +1 -0
  314. package/dist/unstable/encoding/Yaml.js +461 -0
  315. package/dist/unstable/encoding/Yaml.js.map +1 -0
  316. package/dist/unstable/encoding/index.d.ts +12 -0
  317. package/dist/unstable/encoding/index.d.ts.map +1 -1
  318. package/dist/unstable/encoding/index.js +12 -0
  319. package/dist/unstable/encoding/index.js.map +1 -1
  320. package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
  321. package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
  322. package/dist/unstable/eventlog/EventJournal.js +13 -5
  323. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  324. package/dist/unstable/eventlog/EventLogMessage.js +1 -1
  325. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  326. package/dist/unstable/eventlog/EventLogServerUnencrypted.js +1 -1
  327. package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -1
  328. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
  329. package/dist/unstable/eventlog/SqlEventJournal.js +1 -4
  330. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  331. package/dist/unstable/http/FindMyWay/internal/queryString.d.ts +11 -0
  332. package/dist/unstable/http/FindMyWay/internal/queryString.d.ts.map +1 -0
  333. package/dist/unstable/http/FindMyWay/internal/queryString.js +259 -0
  334. package/dist/unstable/http/FindMyWay/internal/queryString.js.map +1 -0
  335. package/dist/unstable/http/FindMyWay/internal/router.d.ts +2 -0
  336. package/dist/unstable/http/FindMyWay/internal/router.d.ts.map +1 -0
  337. package/dist/unstable/http/FindMyWay/internal/router.js +665 -0
  338. package/dist/unstable/http/FindMyWay/internal/router.js.map +1 -0
  339. package/dist/unstable/http/FindMyWay.d.ts +33 -8
  340. package/dist/unstable/http/FindMyWay.d.ts.map +1 -1
  341. package/dist/unstable/http/FindMyWay.js +4 -7
  342. package/dist/unstable/http/FindMyWay.js.map +1 -1
  343. package/dist/unstable/http/HttpClient.d.ts +59 -3
  344. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  345. package/dist/unstable/http/HttpClient.js +33 -19
  346. package/dist/unstable/http/HttpClient.js.map +1 -1
  347. package/dist/unstable/http/HttpClientError.js +1 -1
  348. package/dist/unstable/http/HttpClientError.js.map +1 -1
  349. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  350. package/dist/unstable/http/HttpClientRequest.js +2 -14
  351. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  352. package/dist/unstable/http/HttpClientResponse.js +1 -16
  353. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  354. package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
  355. package/dist/unstable/http/HttpPlatform.js +21 -3
  356. package/dist/unstable/http/HttpPlatform.js.map +1 -1
  357. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  358. package/dist/unstable/http/HttpServerRequest.js +7 -6
  359. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  360. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  361. package/dist/unstable/http/HttpServerResponse.js +8 -6
  362. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  363. package/dist/unstable/http/Multipart.d.ts +1 -1
  364. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  365. package/dist/unstable/http/Multipart.js +9 -2
  366. package/dist/unstable/http/Multipart.js.map +1 -1
  367. package/dist/unstable/http/MultipartParser/HeadersParser.d.ts +53 -0
  368. package/dist/unstable/http/MultipartParser/HeadersParser.d.ts.map +1 -0
  369. package/dist/unstable/http/MultipartParser/HeadersParser.js +14 -0
  370. package/dist/unstable/http/MultipartParser/HeadersParser.js.map +1 -0
  371. package/dist/unstable/http/MultipartParser/Search.d.ts +11 -0
  372. package/dist/unstable/http/MultipartParser/Search.d.ts.map +1 -0
  373. package/dist/unstable/http/MultipartParser/Search.js +14 -0
  374. package/dist/unstable/http/MultipartParser/Search.js.map +1 -0
  375. package/dist/unstable/http/MultipartParser/internal/contentType.d.ts +5 -0
  376. package/dist/unstable/http/MultipartParser/internal/contentType.d.ts.map +1 -0
  377. package/dist/unstable/http/MultipartParser/internal/contentType.js +82 -0
  378. package/dist/unstable/http/MultipartParser/internal/contentType.js.map +1 -0
  379. package/dist/unstable/http/MultipartParser/internal/headers.d.ts +3 -0
  380. package/dist/unstable/http/MultipartParser/internal/headers.d.ts.map +1 -0
  381. package/dist/unstable/http/MultipartParser/internal/headers.js +194 -0
  382. package/dist/unstable/http/MultipartParser/internal/headers.js.map +1 -0
  383. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts +8 -0
  384. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -0
  385. package/dist/unstable/http/MultipartParser/internal/multipart.js +226 -0
  386. package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -0
  387. package/dist/unstable/http/MultipartParser/internal/search.d.ts +5 -0
  388. package/dist/unstable/http/MultipartParser/internal/search.d.ts.map +1 -0
  389. package/dist/unstable/http/MultipartParser/internal/search.js +120 -0
  390. package/dist/unstable/http/MultipartParser/internal/search.js.map +1 -0
  391. package/dist/unstable/http/MultipartParser.d.ts +98 -0
  392. package/dist/unstable/http/MultipartParser.d.ts.map +1 -0
  393. package/dist/unstable/http/MultipartParser.js +23 -0
  394. package/dist/unstable/http/MultipartParser.js.map +1 -0
  395. package/dist/unstable/http/Template.d.ts.map +1 -1
  396. package/dist/unstable/http/Template.js +2 -2
  397. package/dist/unstable/http/Template.js.map +1 -1
  398. package/dist/unstable/http/index.d.ts +1 -1
  399. package/dist/unstable/http/index.d.ts.map +1 -1
  400. package/dist/unstable/http/index.js +1 -1
  401. package/dist/unstable/http/index.js.map +1 -1
  402. package/dist/unstable/http/internal/httpBody.d.ts +2 -0
  403. package/dist/unstable/http/internal/httpBody.d.ts.map +1 -0
  404. package/dist/unstable/http/internal/httpBody.js +10 -0
  405. package/dist/unstable/http/internal/httpBody.js.map +1 -0
  406. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  407. package/dist/unstable/httpapi/HttpApi.js +5 -5
  408. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  409. package/dist/unstable/httpapi/HttpApiBuilder.js +73 -20
  410. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  411. package/dist/unstable/httpapi/HttpApiClient.d.ts +1 -1
  412. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  413. package/dist/unstable/httpapi/HttpApiClient.js +74 -34
  414. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  415. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +6 -4
  416. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  417. package/dist/unstable/httpapi/HttpApiEndpoint.js +73 -16
  418. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  419. package/dist/unstable/httpapi/HttpApiError.d.ts +5 -5
  420. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  421. package/dist/unstable/httpapi/HttpApiError.js +17 -17
  422. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  423. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
  424. package/dist/unstable/httpapi/HttpApiMiddleware.js +1 -1
  425. package/dist/unstable/httpapi/HttpApiSchema.d.ts +219 -0
  426. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  427. package/dist/unstable/httpapi/HttpApiSchema.js +170 -0
  428. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  429. package/dist/unstable/httpapi/OpenApi.d.ts +8 -0
  430. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  431. package/dist/unstable/httpapi/OpenApi.js +45 -18
  432. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  433. package/dist/unstable/observability/OtlpExporter.d.ts +1 -1
  434. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  435. package/dist/unstable/observability/OtlpExporter.js +2 -1
  436. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  437. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  438. package/dist/unstable/observability/OtlpLogger.js +2 -2
  439. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  440. package/dist/unstable/observability/OtlpMetrics.d.ts +2 -2
  441. package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
  442. package/dist/unstable/observability/OtlpMetrics.js +28 -15
  443. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  444. package/dist/unstable/observability/OtlpTracer.js +1 -1
  445. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  446. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  447. package/dist/unstable/persistence/PersistedQueue.js +9 -9
  448. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  449. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  450. package/dist/unstable/persistence/Persistence.js +17 -7
  451. package/dist/unstable/persistence/Persistence.js.map +1 -1
  452. package/dist/unstable/persistence/RateLimiter.d.ts +22 -12
  453. package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
  454. package/dist/unstable/persistence/RateLimiter.js +15 -42
  455. package/dist/unstable/persistence/RateLimiter.js.map +1 -1
  456. package/dist/unstable/persistence/Redis.js +1 -1
  457. package/dist/unstable/persistence/Redis.js.map +1 -1
  458. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  459. package/dist/unstable/reactivity/AsyncResult.js +4 -4
  460. package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
  461. package/dist/unstable/reactivity/Atom.d.ts +26 -11
  462. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  463. package/dist/unstable/reactivity/Atom.js +9 -22
  464. package/dist/unstable/reactivity/Atom.js.map +1 -1
  465. package/dist/unstable/rpc/RpcClient.d.ts +14 -0
  466. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  467. package/dist/unstable/rpc/RpcClient.js +21 -10
  468. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  469. package/dist/unstable/rpc/RpcClientError.js +2 -2
  470. package/dist/unstable/rpc/RpcClientError.js.map +1 -1
  471. package/dist/unstable/rpc/RpcSerialization.js +3 -1
  472. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  473. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  474. package/dist/unstable/rpc/RpcServer.js +3 -2
  475. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  476. package/dist/unstable/schema/Model.d.ts +1 -1
  477. package/dist/unstable/schema/Model.d.ts.map +1 -1
  478. package/dist/unstable/schema/VariantSchema.d.ts +5 -5
  479. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  480. package/dist/unstable/schema/VariantSchema.js +17 -9
  481. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  482. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  483. package/dist/unstable/socket/Socket.js +28 -12
  484. package/dist/unstable/socket/Socket.js.map +1 -1
  485. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  486. package/dist/unstable/sql/SqlClient.js +7 -3
  487. package/dist/unstable/sql/SqlClient.js.map +1 -1
  488. package/dist/unstable/sql/SqlError.js +13 -13
  489. package/dist/unstable/sql/SqlError.js.map +1 -1
  490. package/dist/unstable/sql/SqlResolver.js +8 -6
  491. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  492. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  493. package/dist/unstable/sql/Statement.js +8 -6
  494. package/dist/unstable/sql/Statement.js.map +1 -1
  495. package/dist/unstable/workers/WorkerError.js +5 -5
  496. package/dist/unstable/workers/WorkerError.js.map +1 -1
  497. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  498. package/dist/unstable/workflow/Workflow.js +2 -2
  499. package/dist/unstable/workflow/Workflow.js.map +1 -1
  500. package/dist/unstable/workflow/WorkflowEngine.d.ts +1 -1
  501. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  502. package/dist/unstable/workflow/WorkflowEngine.js +3 -3
  503. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  504. package/package.json +6 -9
  505. package/src/Brand.ts +4 -4
  506. package/src/Cache.ts +1 -1
  507. package/src/Channel.ts +1 -1
  508. package/src/Config.ts +31 -8
  509. package/src/ConfigProvider.ts +4 -1
  510. package/src/Context.ts +6 -28
  511. package/src/Cron.ts +65 -2
  512. package/src/Crypto.ts +17 -8
  513. package/src/Duration.ts +16 -2
  514. package/src/Effect.ts +141 -17
  515. package/src/Equal.ts +10 -2
  516. package/src/ExecutionPlan.ts +78 -1
  517. package/src/FiberSet.ts +1 -1
  518. package/src/FileSystem.ts +2 -2
  519. package/src/Function.ts +6 -6
  520. package/src/Iterable.ts +11 -10
  521. package/src/Layer.ts +7 -5
  522. package/src/Optic.ts +59 -58
  523. package/src/Schedule.ts +13 -13
  524. package/src/Schema.ts +195 -112
  525. package/src/SchemaAST.ts +154 -85
  526. package/src/SchemaError.ts +9 -9
  527. package/src/SchemaGetter.ts +89 -30
  528. package/src/SchemaIssue.ts +285 -80
  529. package/src/SchemaParser.ts +126 -86
  530. package/src/SchemaTransformation.ts +66 -18
  531. package/src/ScopedCache.ts +1 -1
  532. package/src/Sink.ts +1 -1
  533. package/src/Stdio.ts +23 -4
  534. package/src/Stream.ts +77 -10
  535. package/src/SynchronizedRef.ts +1 -1
  536. package/src/Terminal.ts +1 -1
  537. package/src/Tuple.ts +7 -4
  538. package/src/TxReentrantLock.ts +39 -35
  539. package/src/internal/dateTime.ts +1 -1
  540. package/src/internal/executionPlan.ts +105 -10
  541. package/src/internal/hashMap.ts +20 -14
  542. package/src/internal/matcher.ts +2 -2
  543. package/src/internal/schedule.ts +4 -4
  544. package/src/internal/schema/annotations.ts +3 -0
  545. package/src/internal/schema/schema.ts +1 -17
  546. package/src/internal/schema/toArbitrary.ts +3 -1
  547. package/src/internal/trie.ts +12 -2
  548. package/src/testing/TestClock.ts +13 -1
  549. package/src/testing/TestSchema.ts +9 -9
  550. package/src/unstable/ai/AiError.ts +19 -19
  551. package/src/unstable/ai/Chat.ts +1 -1
  552. package/src/unstable/ai/LanguageModel.ts +4 -2
  553. package/src/unstable/ai/McpSchema.ts +17 -16
  554. package/src/unstable/ai/McpServer.ts +1 -1
  555. package/src/unstable/ai/Prompt.ts +35 -10
  556. package/src/unstable/cli/CliError.ts +12 -12
  557. package/src/unstable/cli/Command.ts +12 -10
  558. package/src/unstable/cli/Param.ts +41 -19
  559. package/src/unstable/cli/Primitive.ts +11 -5
  560. package/src/unstable/cli/Prompt.ts +36 -20
  561. package/src/unstable/cli/internal/ansi.ts +2 -2
  562. package/src/unstable/cli/internal/command.ts +15 -10
  563. package/src/unstable/cli/internal/completions/bash.ts +59 -9
  564. package/src/unstable/cli/internal/completions/descriptor.ts +14 -20
  565. package/src/unstable/cli/internal/completions/fish.ts +5 -7
  566. package/src/unstable/cli/internal/help.ts +4 -2
  567. package/src/unstable/cli/internal/parser.ts +3 -3
  568. package/src/unstable/cli/internal/wizard.ts +2 -2
  569. package/src/unstable/cluster/ClusterError.ts +7 -7
  570. package/src/unstable/cluster/ClusterWorkflowEngine.ts +4 -1
  571. package/src/unstable/cluster/MessageStorage.ts +9 -5
  572. package/src/unstable/cluster/Reply.ts +25 -4
  573. package/src/unstable/cluster/RunnerServer.ts +4 -10
  574. package/src/unstable/cluster/RunnerStorage.ts +9 -7
  575. package/src/unstable/cluster/Sharding.ts +35 -7
  576. package/src/unstable/cluster/internal/entityManager.ts +1 -1
  577. package/src/unstable/cluster/internal/resourceMap.ts +5 -2
  578. package/src/unstable/cluster/internal/resourceRef.ts +27 -5
  579. package/src/unstable/devtools/DevToolsClient.ts +3 -2
  580. package/src/unstable/encoding/Ini.ts +174 -0
  581. package/src/unstable/encoding/Msgpack.ts +59 -36
  582. package/src/unstable/encoding/Ndjson.ts +9 -1
  583. package/src/unstable/encoding/Sse.ts +11 -21
  584. package/src/unstable/encoding/Toml.ts +504 -0
  585. package/src/unstable/encoding/Yaml.ts +541 -0
  586. package/src/unstable/encoding/index.ts +15 -0
  587. package/src/unstable/eventlog/EventJournal.ts +14 -6
  588. package/src/unstable/eventlog/EventLogMessage.ts +1 -1
  589. package/src/unstable/eventlog/EventLogServerUnencrypted.ts +1 -1
  590. package/src/unstable/eventlog/SqlEventJournal.ts +6 -4
  591. package/src/unstable/http/FindMyWay/internal/queryString.ts +420 -0
  592. package/src/unstable/http/FindMyWay/internal/router.ts +950 -0
  593. package/src/unstable/http/FindMyWay.ts +65 -6
  594. package/src/unstable/http/HttpClient.ts +132 -23
  595. package/src/unstable/http/HttpClientError.ts +1 -1
  596. package/src/unstable/http/HttpClientRequest.ts +2 -14
  597. package/src/unstable/http/HttpClientResponse.ts +1 -17
  598. package/src/unstable/http/HttpPlatform.ts +34 -6
  599. package/src/unstable/http/HttpServerRequest.ts +14 -6
  600. package/src/unstable/http/HttpServerResponse.ts +9 -7
  601. package/src/unstable/http/Multipart.ts +9 -2
  602. package/src/unstable/http/MultipartParser/HeadersParser.ts +68 -0
  603. package/src/unstable/http/MultipartParser/Search.ts +17 -0
  604. package/src/unstable/http/MultipartParser/internal/contentType.ts +103 -0
  605. package/src/unstable/http/MultipartParser/internal/headers.ts +615 -0
  606. package/src/unstable/http/MultipartParser/internal/multipart.ts +262 -0
  607. package/src/unstable/http/MultipartParser/internal/search.ts +167 -0
  608. package/src/unstable/http/MultipartParser.ts +115 -0
  609. package/src/unstable/http/Template.ts +6 -5
  610. package/src/unstable/http/index.ts +1 -1
  611. package/src/unstable/http/internal/httpBody.ts +15 -0
  612. package/src/unstable/httpapi/HttpApi.ts +6 -7
  613. package/src/unstable/httpapi/HttpApiBuilder.ts +142 -25
  614. package/src/unstable/httpapi/HttpApiClient.ts +130 -49
  615. package/src/unstable/httpapi/HttpApiEndpoint.ts +117 -29
  616. package/src/unstable/httpapi/HttpApiError.ts +33 -39
  617. package/src/unstable/httpapi/HttpApiMiddleware.ts +1 -1
  618. package/src/unstable/httpapi/HttpApiSchema.ts +353 -0
  619. package/src/unstable/httpapi/OpenApi.ts +70 -20
  620. package/src/unstable/observability/OtlpExporter.ts +4 -2
  621. package/src/unstable/observability/OtlpLogger.ts +3 -1
  622. package/src/unstable/observability/OtlpMetrics.ts +32 -18
  623. package/src/unstable/observability/OtlpTracer.ts +1 -1
  624. package/src/unstable/persistence/PersistedQueue.ts +12 -9
  625. package/src/unstable/persistence/Persistence.ts +27 -7
  626. package/src/unstable/persistence/RateLimiter.ts +54 -31
  627. package/src/unstable/persistence/Redis.ts +1 -1
  628. package/src/unstable/reactivity/AsyncResult.ts +11 -6
  629. package/src/unstable/reactivity/Atom.ts +44 -25
  630. package/src/unstable/rpc/RpcClient.ts +42 -13
  631. package/src/unstable/rpc/RpcClientError.ts +2 -2
  632. package/src/unstable/rpc/RpcSerialization.ts +1 -1
  633. package/src/unstable/rpc/RpcServer.ts +4 -2
  634. package/src/unstable/schema/VariantSchema.ts +36 -18
  635. package/src/unstable/socket/Socket.ts +24 -14
  636. package/src/unstable/sql/SqlClient.ts +65 -56
  637. package/src/unstable/sql/SqlError.ts +13 -13
  638. package/src/unstable/sql/SqlResolver.ts +8 -6
  639. package/src/unstable/sql/Statement.ts +13 -8
  640. package/src/unstable/workers/WorkerError.ts +5 -5
  641. package/src/unstable/workflow/Workflow.ts +2 -5
  642. package/src/unstable/workflow/WorkflowEngine.ts +8 -3
  643. package/dist/unstable/http/Multipasta/HeadersParser.d.ts +0 -14
  644. package/dist/unstable/http/Multipasta/HeadersParser.d.ts.map +0 -1
  645. package/dist/unstable/http/Multipasta/HeadersParser.js +0 -14
  646. package/dist/unstable/http/Multipasta/HeadersParser.js.map +0 -1
  647. package/dist/unstable/http/Multipasta/Node.d.ts +0 -14
  648. package/dist/unstable/http/Multipasta/Node.d.ts.map +0 -1
  649. package/dist/unstable/http/Multipasta/Node.js +0 -14
  650. package/dist/unstable/http/Multipasta/Node.js.map +0 -1
  651. package/dist/unstable/http/Multipasta/Search.d.ts +0 -14
  652. package/dist/unstable/http/Multipasta/Search.d.ts.map +0 -1
  653. package/dist/unstable/http/Multipasta/Search.js +0 -14
  654. package/dist/unstable/http/Multipasta/Search.js.map +0 -1
  655. package/dist/unstable/http/Multipasta/Web.d.ts +0 -14
  656. package/dist/unstable/http/Multipasta/Web.d.ts.map +0 -1
  657. package/dist/unstable/http/Multipasta/Web.js +0 -14
  658. package/dist/unstable/http/Multipasta/Web.js.map +0 -1
  659. package/dist/unstable/http/Multipasta.d.ts +0 -15
  660. package/dist/unstable/http/Multipasta.d.ts.map +0 -1
  661. package/dist/unstable/http/Multipasta.js +0 -15
  662. package/dist/unstable/http/Multipasta.js.map +0 -1
  663. package/src/unstable/http/Multipasta/HeadersParser.ts +0 -14
  664. package/src/unstable/http/Multipasta/Node.ts +0 -14
  665. package/src/unstable/http/Multipasta/Search.ts +0 -14
  666. package/src/unstable/http/Multipasta/Web.ts +0 -14
  667. 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