itty-router 5.0.0 → 5.0.1

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 (183) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/.eslintrc +0 -28
  4. package/.github/FUNDING.yml +0 -12
  5. package/.github/ISSUE_TEMPLATE/issue_template.md +0 -52
  6. package/.github/ISSUE_TEMPLATE/question.md +0 -16
  7. package/.github/pull_request_template.md +0 -17
  8. package/.github/workflows/coveralls.yml +0 -20
  9. package/.github/workflows/lint.yml +0 -21
  10. package/.github/workflows/verify.yml +0 -22
  11. package/.nyc_output/17f58b46-7631-4765-9ac8-c567ad984881.json +0 -1
  12. package/.nyc_output/37b99878-3734-4671-b7ad-9716c334e6da.json +0 -1
  13. package/.nyc_output/522b1502-594a-4786-90b9-0b52ce677765.json +0 -1
  14. package/.nyc_output/5ad76e3a-7bd8-4131-b761-9eda43350422.json +0 -1
  15. package/.nyc_output/8518a247-c46c-4288-b558-73a9da27d039.json +0 -1
  16. package/.nyc_output/8cdba743-d03a-4ae0-80a9-be1698a6621a.json +0 -1
  17. package/.nyc_output/a5a529a4-8c20-4fc6-8e19-68f85c854251.json +0 -1
  18. package/.nyc_output/a9e151d4-d47a-4440-885b-1ab50a6ac1a0.json +0 -1
  19. package/.nyc_output/bfc97de7-26ae-4d9c-a9a6-2021b608d83b.json +0 -1
  20. package/.nyc_output/c26290ed-5973-4907-a3f1-29678d97224a.json +0 -1
  21. package/.nyc_output/c6b55c94-7cf5-4f08-86e7-ce60b0d7064c.json +0 -1
  22. package/.nyc_output/e2b16e51-822d-4c53-ad21-bb54668ec04d.json +0 -1
  23. package/.nyc_output/e548baf2-1d0a-4dc2-abe4-4a52ae914581.json +0 -1
  24. package/.nyc_output/processinfo/17f58b46-7631-4765-9ac8-c567ad984881.json +0 -16
  25. package/.nyc_output/processinfo/37b99878-3734-4671-b7ad-9716c334e6da.json +0 -19
  26. package/.nyc_output/processinfo/522b1502-594a-4786-90b9-0b52ce677765.json +0 -16
  27. package/.nyc_output/processinfo/5ad76e3a-7bd8-4131-b761-9eda43350422.json +0 -16
  28. package/.nyc_output/processinfo/8518a247-c46c-4288-b558-73a9da27d039.json +0 -17
  29. package/.nyc_output/processinfo/8cdba743-d03a-4ae0-80a9-be1698a6621a.json +0 -16
  30. package/.nyc_output/processinfo/a5a529a4-8c20-4fc6-8e19-68f85c854251.json +0 -17
  31. package/.nyc_output/processinfo/a9e151d4-d47a-4440-885b-1ab50a6ac1a0.json +0 -20
  32. package/.nyc_output/processinfo/bfc97de7-26ae-4d9c-a9a6-2021b608d83b.json +0 -16
  33. package/.nyc_output/processinfo/c26290ed-5973-4907-a3f1-29678d97224a.json +0 -16
  34. package/.nyc_output/processinfo/c6b55c94-7cf5-4f08-86e7-ce60b0d7064c.json +0 -16
  35. package/.nyc_output/processinfo/e2b16e51-822d-4c53-ad21-bb54668ec04d.json +0 -17
  36. package/.nyc_output/processinfo/e548baf2-1d0a-4dc2-abe4-4a52ae914581.json +0 -16
  37. package/.nyc_output/processinfo/index.json +0 -70
  38. package/.prettierignore +0 -1
  39. package/.prettierrc +0 -4
  40. package/CHANGELOG.md +0 -78
  41. package/CODE_OF_CONDUCT.md +0 -128
  42. package/CONTRIBUTING.md +0 -92
  43. package/dist/LICENSE +0 -21
  44. package/example/bun-autorouter-advanced.ts +0 -35
  45. package/example/bun-autorouter.ts +0 -30
  46. package/example/bun-router.ts +0 -26
  47. package/example/bun.ts +0 -15
  48. package/example/cors-types.ts +0 -92
  49. package/example/custom-router-props.ts +0 -11
  50. package/example/index.ts +0 -57
  51. package/example/node-import.js +0 -20
  52. package/example/node-require.js +0 -20
  53. package/example/request-types.ts +0 -101
  54. package/example/runtimes/bun.ts +0 -15
  55. package/example/runtimes/express.js +0 -16
  56. package/example/runtimes/node.js +0 -20
  57. package/example/types/content.ts +0 -22
  58. package/example/types/extra-props.ts +0 -13
  59. package/example/types/global-and-route-level-request.ts +0 -17
  60. package/example/types/global-request.ts +0 -16
  61. package/example/types/middleware.ts +0 -41
  62. package/example/types/requestlike.ts +0 -11
  63. package/example/types/route-level-request.ts +0 -16
  64. package/example/types/router.ts +0 -8
  65. package/lib/index.ts +0 -72
  66. package/rollup.config.mjs +0 -68
  67. package/tsconfig.json +0 -28
  68. package/vitest.config.ts +0 -20
  69. package/yarn-error.log +0 -4335
  70. /package/{dist/AutoRouter.d.ts → AutoRouter.d.ts} +0 -0
  71. /package/{dist/AutoRouter.js → AutoRouter.js} +0 -0
  72. /package/{dist/AutoRouter.js.map → AutoRouter.js.map} +0 -0
  73. /package/{dist/AutoRouter.mjs → AutoRouter.mjs} +0 -0
  74. /package/{dist/AutoRouter.mjs.map → AutoRouter.mjs.map} +0 -0
  75. /package/{dist/IttyRouter.d.ts → IttyRouter.d.ts} +0 -0
  76. /package/{dist/IttyRouter.js → IttyRouter.js} +0 -0
  77. /package/{dist/IttyRouter.js.map → IttyRouter.js.map} +0 -0
  78. /package/{dist/IttyRouter.mjs → IttyRouter.mjs} +0 -0
  79. /package/{dist/IttyRouter.mjs.map → IttyRouter.mjs.map} +0 -0
  80. /package/{dist/Router.d.ts → Router.d.ts} +0 -0
  81. /package/{dist/Router.js → Router.js} +0 -0
  82. /package/{dist/Router.js.map → Router.js.map} +0 -0
  83. /package/{dist/Router.mjs → Router.mjs} +0 -0
  84. /package/{dist/Router.mjs.map → Router.mjs.map} +0 -0
  85. /package/{dist/StatusError.d.ts → StatusError.d.ts} +0 -0
  86. /package/{dist/StatusError.js → StatusError.js} +0 -0
  87. /package/{dist/StatusError.js.map → StatusError.js.map} +0 -0
  88. /package/{dist/StatusError.mjs → StatusError.mjs} +0 -0
  89. /package/{dist/StatusError.mjs.map → StatusError.mjs.map} +0 -0
  90. /package/{dist/cors.d.ts → cors.d.ts} +0 -0
  91. /package/{dist/cors.js → cors.js} +0 -0
  92. /package/{dist/cors.js.map → cors.js.map} +0 -0
  93. /package/{dist/cors.mjs → cors.mjs} +0 -0
  94. /package/{dist/cors.mjs.map → cors.mjs.map} +0 -0
  95. /package/{dist/createResponse.d.ts → createResponse.d.ts} +0 -0
  96. /package/{dist/createResponse.js → createResponse.js} +0 -0
  97. /package/{dist/createResponse.js.map → createResponse.js.map} +0 -0
  98. /package/{dist/createResponse.mjs → createResponse.mjs} +0 -0
  99. /package/{dist/createResponse.mjs.map → createResponse.mjs.map} +0 -0
  100. /package/{dist/error.d.ts → error.d.ts} +0 -0
  101. /package/{dist/error.js → error.js} +0 -0
  102. /package/{dist/error.js.map → error.js.map} +0 -0
  103. /package/{dist/error.mjs → error.mjs} +0 -0
  104. /package/{dist/error.mjs.map → error.mjs.map} +0 -0
  105. /package/{dist/html.d.ts → html.d.ts} +0 -0
  106. /package/{dist/html.js → html.js} +0 -0
  107. /package/{dist/html.js.map → html.js.map} +0 -0
  108. /package/{dist/html.mjs → html.mjs} +0 -0
  109. /package/{dist/html.mjs.map → html.mjs.map} +0 -0
  110. /package/{dist/index.d.ts → index.d.ts} +0 -0
  111. /package/{dist/index.js → index.js} +0 -0
  112. /package/{dist/index.js.map → index.js.map} +0 -0
  113. /package/{dist/index.mjs → index.mjs} +0 -0
  114. /package/{dist/index.mjs.map → index.mjs.map} +0 -0
  115. /package/{dist/jpeg.d.ts → jpeg.d.ts} +0 -0
  116. /package/{dist/jpeg.js → jpeg.js} +0 -0
  117. /package/{dist/jpeg.js.map → jpeg.js.map} +0 -0
  118. /package/{dist/jpeg.mjs → jpeg.mjs} +0 -0
  119. /package/{dist/jpeg.mjs.map → jpeg.mjs.map} +0 -0
  120. /package/{dist/json.d.ts → json.d.ts} +0 -0
  121. /package/{dist/json.js → json.js} +0 -0
  122. /package/{dist/json.js.map → json.js.map} +0 -0
  123. /package/{dist/json.mjs → json.mjs} +0 -0
  124. /package/{dist/json.mjs.map → json.mjs.map} +0 -0
  125. /package/{dist/png.d.ts → png.d.ts} +0 -0
  126. /package/{dist/png.js → png.js} +0 -0
  127. /package/{dist/png.js.map → png.js.map} +0 -0
  128. /package/{dist/png.mjs → png.mjs} +0 -0
  129. /package/{dist/png.mjs.map → png.mjs.map} +0 -0
  130. /package/{dist/status.d.ts → status.d.ts} +0 -0
  131. /package/{dist/status.js → status.js} +0 -0
  132. /package/{dist/status.js.map → status.js.map} +0 -0
  133. /package/{dist/status.mjs → status.mjs} +0 -0
  134. /package/{dist/status.mjs.map → status.mjs.map} +0 -0
  135. /package/{dist/text.d.ts → text.d.ts} +0 -0
  136. /package/{dist/text.js → text.js} +0 -0
  137. /package/{dist/text.js.map → text.js.map} +0 -0
  138. /package/{dist/text.mjs → text.mjs} +0 -0
  139. /package/{dist/text.mjs.map → text.mjs.map} +0 -0
  140. /package/{dist/types → types}/AutoRouterOptions.d.ts +0 -0
  141. /package/{dist/types → types}/CustomRoutes.d.ts +0 -0
  142. /package/{dist/types → types}/ErrorFormatter.d.ts +0 -0
  143. /package/{dist/types → types}/ErrorHandler.d.ts +0 -0
  144. /package/{dist/types → types}/GenericTraps.d.ts +0 -0
  145. /package/{dist/types → types}/HasContent.d.ts +0 -0
  146. /package/{dist/types → types}/IRequest.d.ts +0 -0
  147. /package/{dist/types → types}/IRequestStrict.d.ts +0 -0
  148. /package/{dist/types → types}/IttyRouterOptions.d.ts +0 -0
  149. /package/{dist/types → types}/IttyRouterType.d.ts +0 -0
  150. /package/{dist/types → types}/RequestHandler.d.ts +0 -0
  151. /package/{dist/types → types}/RequestLike.d.ts +0 -0
  152. /package/{dist/types → types}/ResponseFormatter.d.ts +0 -0
  153. /package/{dist/types → types}/ResponseHandler.d.ts +0 -0
  154. /package/{dist/types → types}/Route.d.ts +0 -0
  155. /package/{dist/types → types}/RouteEntry.d.ts +0 -0
  156. /package/{dist/types → types}/RouterOptions.d.ts +0 -0
  157. /package/{dist/types → types}/RouterType.d.ts +0 -0
  158. /package/{dist/types.d.ts → types.d.ts} +0 -0
  159. /package/{dist/webp.d.ts → webp.d.ts} +0 -0
  160. /package/{dist/webp.js → webp.js} +0 -0
  161. /package/{dist/webp.js.map → webp.js.map} +0 -0
  162. /package/{dist/webp.mjs → webp.mjs} +0 -0
  163. /package/{dist/webp.mjs.map → webp.mjs.map} +0 -0
  164. /package/{dist/websocket.d.ts → websocket.d.ts} +0 -0
  165. /package/{dist/websocket.js → websocket.js} +0 -0
  166. /package/{dist/websocket.js.map → websocket.js.map} +0 -0
  167. /package/{dist/websocket.mjs → websocket.mjs} +0 -0
  168. /package/{dist/websocket.mjs.map → websocket.mjs.map} +0 -0
  169. /package/{dist/withContent.d.ts → withContent.d.ts} +0 -0
  170. /package/{dist/withContent.js → withContent.js} +0 -0
  171. /package/{dist/withContent.js.map → withContent.js.map} +0 -0
  172. /package/{dist/withContent.mjs → withContent.mjs} +0 -0
  173. /package/{dist/withContent.mjs.map → withContent.mjs.map} +0 -0
  174. /package/{dist/withCookies.d.ts → withCookies.d.ts} +0 -0
  175. /package/{dist/withCookies.js → withCookies.js} +0 -0
  176. /package/{dist/withCookies.js.map → withCookies.js.map} +0 -0
  177. /package/{dist/withCookies.mjs → withCookies.mjs} +0 -0
  178. /package/{dist/withCookies.mjs.map → withCookies.mjs.map} +0 -0
  179. /package/{dist/withParams.d.ts → withParams.d.ts} +0 -0
  180. /package/{dist/withParams.js → withParams.js} +0 -0
  181. /package/{dist/withParams.js.map → withParams.js.map} +0 -0
  182. /package/{dist/withParams.mjs → withParams.mjs} +0 -0
  183. /package/{dist/withParams.mjs.map → withParams.mjs.map} +0 -0
@@ -1,101 +0,0 @@
1
- import { IRequest, IRequestStrict, IttyRouter } from '../src/IttyRouter'
2
-
3
- type FooRequest = {
4
- foo: string
5
- } & IRequest
6
-
7
- // extends IRequestStrict, meaning no undefined attributes off Request
8
- type BarRequest = {
9
- bar: number
10
- } & IRequestStrict
11
-
12
- type Env = {
13
- KV: string
14
- }
15
-
16
- type CF = [env: Env, ctx: ExecutionContext]
17
-
18
- // this router defines a global signature of <BarRequest, CF>
19
- const custom = IttyRouter<BarRequest, CF>()
20
-
21
- custom
22
- .get('/', ({ bar, json }) => {
23
- console.log('bar', bar)
24
- })
25
-
26
- // should not be able to access request.foo
27
- .get('/foo/:bar', (request, env, ctx) => {
28
- request.params
29
- request.bar
30
- request.foo
31
- env.KV
32
- ctx.waitUntil
33
- })
34
-
35
- .get<FooRequest>('/', (request) => {
36
- request.foo // found in FooRequest override
37
- })
38
-
39
- const router = IttyRouter({ base: '/' })
40
-
41
- router
42
- // call custom HTTP method
43
- .puppy('/cat/:id', (request) => {
44
- // supports standard Request by default
45
- request.headers // valid
46
- request.foo // valid (generic traps)
47
- })
48
- .puppy<IRequestStrict>('/cat/:id', (request) => {
49
- // supports standard Request by default
50
- request.headers // valid
51
- request.foo // invalid
52
- })
53
-
54
- // standard request
55
- .get('*', (request, env: Env, ctx: ExecutionContext) => {
56
- request.url
57
- env.KV
58
- ctx.waitUntil
59
- })
60
-
61
- // custom request from handler argument
62
- .get('*', (request: FooRequest) => {
63
- request.foo
64
- })
65
-
66
- // custom request from handler argument
67
- .get('*', (request: BarRequest) => {
68
- request.bar
69
- })
70
-
71
- // custom request from handler argument
72
- .get<BarRequest>('*', (request) => {
73
- request.bar
74
- })
75
-
76
- // custom request from Route
77
- .get<BarRequest, CF>('*', ({ bar, foo }, env, ctx) => {
78
- env.KV
79
- ctx.waitUntil
80
- })
81
-
82
- // how to return another custom router method
83
- .get<FooRequest, CF>('*', (request) => {
84
- request.foo
85
- })
86
-
87
- // call custom HTTP method again (to ensure preserved through chain)
88
- .puppy('/cat', () => {})
89
-
90
- // undeclared HTTP method?
91
- .kitten<FooRequest>('/', (request) => {
92
- request.foo
93
- })
94
-
95
- .handle<CF>({ method: 'GET', url: 'foo.bar' }, {}, 'asd')
96
-
97
- type CFfetch = [request: Request, env: Env, ctx: ExecutionContext]
98
-
99
- export default {
100
- fetch: (...args: CFfetch) => router.handle(...args),
101
- }
@@ -1,15 +0,0 @@
1
- import { Router, error, json, withParams } from 'itty-router'
2
-
3
- const router = Router()
4
-
5
- router
6
- .all('*', withParams)
7
- .get('/test', () => 'Success!')
8
- .get('/foo/:bar/:baz?', ({ bar, baz }) => ({ bar, baz }))
9
- .all('*', () => error(404))
10
-
11
- export default {
12
- port: 3001,
13
- fetch: (request, env, ctx) =>
14
- router.handle(request, env, ctx).then(json).catch(error),
15
- }
@@ -1,16 +0,0 @@
1
- import express from 'express'
2
- import { Router, error, json } from 'itty-router'
3
- import 'isomorphic-fetch'
4
-
5
- const app = express()
6
-
7
- const router = Router()
8
-
9
- router.get('/', () => 'Success!').all('*', () => error(404))
10
-
11
- const handle = (request) => router.handle(request).then(json).catch(error)
12
-
13
- app.use(handle)
14
-
15
- app.listen(3001)
16
- console.log('listening at https://localhost:3001')
@@ -1,20 +0,0 @@
1
- import { createServerAdapter } from '@whatwg-node/server'
2
- import { createServer } from 'http'
3
- import 'isomorphic-fetch'
4
- import { Router, error, json } from '../dist/index.js'
5
-
6
- const router = Router()
7
-
8
- router.get('/', () => 'Success!').all('*', () => error(404))
9
-
10
- const ittyServer = createServerAdapter((...args) =>
11
- router
12
- .handle(...args)
13
- .then(json)
14
- .catch(error)
15
- )
16
-
17
- // Then use it in any environment
18
- const httpServer = createServer(ittyServer)
19
- httpServer.listen(3001)
20
- console.log('listening at https://localhost:3001')
@@ -1,22 +0,0 @@
1
- import { IRequestStrict, IRequest, RequestHandler } from 'types'
2
- import { IttyRouter } from 'IttyRouter'
3
- import { withContent } from 'withContent'
4
- import { HasContent } from 'types'
5
-
6
- type User = {
7
- user: string
8
- }
9
-
10
- const router = IttyRouter()
11
-
12
- router
13
- // upstream request sees the request as IRequest (default), so anything goes
14
- .post<HasContent<User>>('/', withContent, ({ content }) => {
15
- content.user
16
- })
17
-
18
- .get('/pollution', (request) => {
19
- request.content.user
20
- })
21
-
22
- export default router
@@ -1,13 +0,0 @@
1
- import { IRequestStrict, IRequest, RequestHandler } from 'types'
2
- import { IttyRouter } from 'IttyRouter'
3
- import { withContent } from 'withContent'
4
- import { HasContent } from 'types'
5
-
6
- const router = IttyRouter({
7
- port: 3000,
8
- })
9
-
10
- router.port = 4000
11
- router.port.toLowerCase()
12
- router.puppy() // should not be typed... RIP
13
-
@@ -1,17 +0,0 @@
1
- import { IRequestStrict } from 'IttyRouter'
2
- import { Router } from 'Router'
3
-
4
- const router = Router<IRequestStrict>()
5
-
6
- type FooRequest = {
7
- foo: string
8
- } & IRequestStrict
9
-
10
- router
11
- .get('/basic', () => new Response('Success!'))
12
- .get('/text', () => 'Success!')
13
- // .get('/params/:foo', ({ foo }) => foo) // should NOT work
14
- .get<FooRequest>('/params/:foo', ({ foo }) => foo) // should work
15
- .get('/json', () => ({ foo: 'bar' }))
16
-
17
- export default router
@@ -1,16 +0,0 @@
1
- import { IRequestStrict } from 'IttyRouter'
2
- import { Router } from 'Router'
3
-
4
- type FooRequest = {
5
- foo: string
6
- } & IRequestStrict
7
-
8
- const router = Router<FooRequest>()
9
-
10
- router
11
- .get('/', (request) => {
12
- request.foo // should work
13
- // request.bar // should NOT work
14
- })
15
-
16
- export default router
@@ -1,41 +0,0 @@
1
- import { IRequestStrict, IRequest, RequestHandler } from '../../src/types'
2
- import { IttyRouter } from 'IttyRouter'
3
-
4
- type UserRequest = {
5
- user: string
6
- } & IRequestStrict
7
-
8
- const router = IttyRouter<IRequestStrict>()
9
-
10
- const withUser: RequestHandler = (request) => {
11
- request.user = 'Kevin'
12
- }
13
-
14
- router
15
- // upstream request sees the request as IRequest (default), so anything goes
16
- .get('/', (request) => {
17
- request.user = 123 // not OK
18
- })
19
-
20
- // then we add the middleware defined above as <UserRequest>
21
- .all('*', withUser, (request) => {
22
- request.user = 'Kevin'
23
- request.user = 123 // NOT ok
24
- })
25
-
26
- // and if we ever need to restore control, add the generic back in
27
- .get<UserRequest, []>('/', (request) => {
28
- request.user = 'Kevin'
29
- request.user = 123 // NOT ok
30
- })
31
-
32
- .get('/', (request) => {
33
- request.user = 'Kevin' // still ok
34
- request.user = 123 // NOT ok
35
- })
36
-
37
- router.get('/', (request) => {
38
- request.user = 123 // NOT ok
39
- })
40
-
41
- export default router
@@ -1,11 +0,0 @@
1
- import { IttyRouter } from 'IttyRouter'
2
-
3
- const router = IttyRouter()
4
-
5
- const request = new Request('https://foo.bar')
6
-
7
- router.fetch(request) // should be OK
8
- router.fetch({ method: 'GET', url: 'foo' }) // should be OK
9
- router.fetch({ method: 'GET' }) // should NOT be OK
10
-
11
-
@@ -1,16 +0,0 @@
1
- import { IRequestStrict } from 'IttyRouter'
2
- import { Router } from 'Router'
3
-
4
- type FooRequest = {
5
- foo: string
6
- } & IRequestStrict
7
-
8
- const router = Router()
9
-
10
- router
11
- .get<FooRequest>('/', (request) => {
12
- request.foo // should work
13
- // request.bar // should NOT work
14
- })
15
-
16
- export default router
@@ -1,8 +0,0 @@
1
- import { Router } from 'Router'
2
-
3
- const router = Router({
4
- port: 4000,
5
- before: [],
6
- })
7
-
8
- router.finally = () => {} // should NOT work
package/lib/index.ts DELETED
@@ -1,72 +0,0 @@
1
- /* istanbul ignore file */
2
- import { expect, it, vi } from 'vitest'
3
-
4
- // generates a request from a string like:
5
- // GET /whatever
6
- // /foo
7
- export const toReq = (methodAndPath: string, options: RequestInit = {}) => {
8
- let [method, path] = methodAndPath.split(' ')
9
- if (!path) {
10
- path = method
11
- method = 'GET'
12
- }
13
-
14
- return new Request(`https://example.com${path}`, { method, ...options })
15
- }
16
-
17
- export const extract = ({ params, query }) => ({ params, query })
18
-
19
- const testRoute = async (
20
- { route, path, method = 'get', returns = true, log = false },
21
- Router
22
- ) => {
23
- const routes = []
24
- const router = Router({ routes })
25
- const handler = vi.fn((req) => req.params)
26
-
27
- // register route
28
- router[method](route, handler)
29
-
30
- log && console.log({
31
- routes,
32
- route,
33
- path,
34
- })
35
-
36
- await router.fetch(toReq(`${method.toUpperCase()} ${path}`))
37
-
38
- if (!returns) {
39
- expect(handler).not.toHaveBeenCalled()
40
- } else {
41
- expect(handler).toHaveBeenCalled()
42
-
43
- if (typeof returns === 'object') {
44
- expect(handler).toHaveReturnedWith(returns)
45
- }
46
- }
47
- }
48
-
49
- export const runTests = (tests, Router) => {
50
- for (let test of tests) {
51
- let { route, path, returns = true, description } = test
52
- const matchNote = returns
53
- ? typeof returns === 'object'
54
- ? `returns params ${JSON.stringify(returns)
55
- .replace('{', '{ ')
56
- .replace('}', ' }')
57
- .replace(/"(\w+)":/g, '$1: ')
58
- .replace(',', ', ')} from`
59
- : 'matches'
60
- : 'does NOT match'
61
- description = description || `route "${route}" ${matchNote} path "${path}"`
62
-
63
- it(description, async () => {
64
- await testRoute(test, Router)
65
- })
66
- }
67
- }
68
-
69
- export const createTestRunner =
70
- (Router) =>
71
- (...args) =>
72
- runTests(...args, Router)
package/rollup.config.mjs DELETED
@@ -1,68 +0,0 @@
1
- import terser from '@rollup/plugin-terser'
2
- import typescript from '@rollup/plugin-typescript'
3
- import { globby } from 'globby'
4
- import bundleSize from 'rollup-plugin-bundle-size'
5
- import copy from 'rollup-plugin-copy'
6
- import fs from 'fs-extra'
7
-
8
- // scan files to build
9
- const files = (await globby('./src/*.ts', {
10
- ignore: ['**/*.spec.ts', 'example', '**/types.ts'],
11
- })).map(path => ({
12
- path,
13
- shortPath: path.replace(/(\/src)|(\.ts)/g, '').replace('./index', '.'),
14
- esm: path.replace('/src/', '/dist/').replace('.ts', '.mjs'),
15
- cjs: path.replace('/src/', '/dist/').replace('.ts', '.js'),
16
- types: path.replace('/src/', '/dist/').replace('.ts', '.d.ts'),
17
- })).sort((a, b) => a.shortPath.toLowerCase() < b.shortPath.toLowerCase() ? -1 : 1)
18
-
19
-
20
- // read original package.json
21
- const pkg = await fs.readJSON('./package.json')
22
-
23
- // create updated exports list from build files
24
- pkg.exports = files.reduce((acc, file) => {
25
- acc[file.shortPath] = {
26
- import: file.esm.replace('/dist', ''),
27
- require: file.cjs.replace('/dist', ''),
28
- types: file.types.replace('/dist', ''),
29
- }
30
-
31
- return acc
32
- }, {})
33
-
34
- // write updated package.json
35
- await fs.writeJSON('./package.json', pkg, { spaces: 2 })
36
-
37
- export default async () => {
38
- console.log(files.map(f => f.path))
39
-
40
- return files.map(file => ({
41
- input: file.path,
42
- output: [
43
- {
44
- format: 'esm',
45
- file: file.esm,
46
- sourcemap: true,
47
- },
48
- {
49
- format: 'cjs',
50
- file: file.cjs,
51
- sourcemap: true,
52
- },
53
- ],
54
- plugins: [
55
- typescript({ sourceMap: true }),
56
- terser(),
57
- bundleSize(),
58
- copy({
59
- targets: [
60
- {
61
- src: ['LICENSE'],
62
- dest: 'dist',
63
- },
64
- ],
65
- }),
66
- ],
67
- }))
68
- }
package/tsconfig.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "allowSyntheticDefaultImports": true,
5
- "baseUrl": "src",
6
- "declaration": true,
7
- "sourceMap": true,
8
- "esModuleInterop": true,
9
- "inlineSourceMap": false,
10
- "lib": ["esnext", "dom", "dom.iterable"],
11
- "listEmittedFiles": false,
12
- "listFiles": false,
13
- "noFallthroughCasesInSwitch": true,
14
- "pretty": true,
15
- // "moduleResolution": "nodeNext", // disabled to be compatible with module: "esnext"
16
- // "resolveJsonModule": true, // disabled to be compatible with module: "esnext"
17
- "rootDir": "src",
18
- "skipLibCheck": true,
19
- "strict": true,
20
- "traceResolution": false,
21
- "outDir": "",
22
- "target": "esnext",
23
- "module": "esnext",
24
- "types": ["@cloudflare/workers-types", "@types/node"]
25
- },
26
- "exclude": ["node_modules", "dist", "**/*.spec.ts", "**/example.ts"],
27
- "include": ["src", "example"]
28
- }
package/vitest.config.ts DELETED
@@ -1,20 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
6
- exclude: ['**/example/**'],
7
- coverage: {
8
- reporter: ['text', 'lcov'],
9
- exclude: [
10
- '**/example/**',
11
- '**/lib/**',
12
- 'src/index.ts',
13
- 'src/types',
14
- 'src/types.ts',
15
- 'src/websocket.ts',
16
- ],
17
- },
18
- environment: 'jsdom',
19
- },
20
- })