convex-cms 0.0.1 → 0.0.3

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 (267) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +99 -0
  3. package/admin-dist/nitro.json +15 -0
  4. package/admin-dist/public/assets/CmsEmptyState-CRswfTzk.js +5 -0
  5. package/admin-dist/public/assets/CmsPageHeader-CirpXndm.js +1 -0
  6. package/admin-dist/public/assets/CmsStatusBadge-CbEUpQu-.js +1 -0
  7. package/admin-dist/public/assets/CmsToolbar-BI2nZOXp.js +1 -0
  8. package/admin-dist/public/assets/ContentEntryEditor-CBeCyK_m.js +4 -0
  9. package/admin-dist/public/assets/ErrorState-BIVaWmom.js +1 -0
  10. package/admin-dist/public/assets/TaxonomyFilter-ChaY6Y_x.js +1 -0
  11. package/admin-dist/public/assets/_contentTypeId-DQ8k_Rvw.js +1 -0
  12. package/admin-dist/public/assets/_entryId-CKU_glsK.js +1 -0
  13. package/admin-dist/public/assets/alert-BXjTqrwQ.js +1 -0
  14. package/admin-dist/public/assets/badge-hvUOzpVZ.js +1 -0
  15. package/admin-dist/public/assets/circle-check-big-CF_pR17r.js +1 -0
  16. package/admin-dist/public/assets/command-DU82cJlt.js +1 -0
  17. package/admin-dist/public/assets/content-_LXl3pp7.js +1 -0
  18. package/admin-dist/public/assets/content-types-KjxaXGxY.js +2 -0
  19. package/admin-dist/public/assets/globals-CS6BZ0zp.css +1 -0
  20. package/admin-dist/public/assets/index-DNGIZHL-.js +1 -0
  21. package/admin-dist/public/assets/label-KNtpL71g.js +1 -0
  22. package/admin-dist/public/assets/link-2-Bw2aI4V4.js +1 -0
  23. package/admin-dist/public/assets/list-sYepHjt_.js +1 -0
  24. package/admin-dist/public/assets/main-CKj5yfEi.js +97 -0
  25. package/admin-dist/public/assets/media-Bkrkffm7.js +1 -0
  26. package/admin-dist/public/assets/new._contentTypeId-C3LstjNs.js +1 -0
  27. package/admin-dist/public/assets/plus-DUn8v_Xf.js +1 -0
  28. package/admin-dist/public/assets/rotate-ccw-DJEoHcRI.js +1 -0
  29. package/admin-dist/public/assets/scroll-area-DfIlT0in.js +1 -0
  30. package/admin-dist/public/assets/search-MuAUDJKR.js +1 -0
  31. package/admin-dist/public/assets/select-BD29IXCI.js +1 -0
  32. package/admin-dist/public/assets/settings-DmMyn_6A.js +1 -0
  33. package/admin-dist/public/assets/switch-h3Rrnl5i.js +1 -0
  34. package/admin-dist/public/assets/tabs-imc8h-Dp.js +1 -0
  35. package/admin-dist/public/assets/taxonomies-dAsrT65H.js +1 -0
  36. package/admin-dist/public/assets/textarea-BTy7nwzR.js +1 -0
  37. package/admin-dist/public/assets/trash-SAWKZZHv.js +1 -0
  38. package/admin-dist/public/assets/triangle-alert-E52Vfeuh.js +1 -0
  39. package/admin-dist/public/assets/useBreadcrumbLabel-BECBMCzM.js +1 -0
  40. package/admin-dist/public/assets/usePermissions-Basjs9BT.js +1 -0
  41. package/admin-dist/public/favicon.ico +0 -0
  42. package/admin-dist/server/_chunks/_libs/@date-fns/tz.mjs +217 -0
  43. package/admin-dist/server/_chunks/_libs/@floating-ui/core.mjs +719 -0
  44. package/admin-dist/server/_chunks/_libs/@floating-ui/dom.mjs +622 -0
  45. package/admin-dist/server/_chunks/_libs/@floating-ui/react-dom.mjs +292 -0
  46. package/admin-dist/server/_chunks/_libs/@floating-ui/utils.mjs +320 -0
  47. package/admin-dist/server/_chunks/_libs/@radix-ui/number.mjs +6 -0
  48. package/admin-dist/server/_chunks/_libs/@radix-ui/primitive.mjs +11 -0
  49. package/admin-dist/server/_chunks/_libs/@radix-ui/react-arrow.mjs +23 -0
  50. package/admin-dist/server/_chunks/_libs/@radix-ui/react-avatar.mjs +119 -0
  51. package/admin-dist/server/_chunks/_libs/@radix-ui/react-checkbox.mjs +270 -0
  52. package/admin-dist/server/_chunks/_libs/@radix-ui/react-collection.mjs +69 -0
  53. package/admin-dist/server/_chunks/_libs/@radix-ui/react-compose-refs.mjs +39 -0
  54. package/admin-dist/server/_chunks/_libs/@radix-ui/react-context.mjs +137 -0
  55. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dialog.mjs +325 -0
  56. package/admin-dist/server/_chunks/_libs/@radix-ui/react-direction.mjs +9 -0
  57. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dismissable-layer.mjs +210 -0
  58. package/admin-dist/server/_chunks/_libs/@radix-ui/react-dropdown-menu.mjs +253 -0
  59. package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-guards.mjs +29 -0
  60. package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-scope.mjs +206 -0
  61. package/admin-dist/server/_chunks/_libs/@radix-ui/react-id.mjs +14 -0
  62. package/admin-dist/server/_chunks/_libs/@radix-ui/react-label.mjs +23 -0
  63. package/admin-dist/server/_chunks/_libs/@radix-ui/react-menu.mjs +812 -0
  64. package/admin-dist/server/_chunks/_libs/@radix-ui/react-popover.mjs +300 -0
  65. package/admin-dist/server/_chunks/_libs/@radix-ui/react-popper.mjs +286 -0
  66. package/admin-dist/server/_chunks/_libs/@radix-ui/react-portal.mjs +16 -0
  67. package/admin-dist/server/_chunks/_libs/@radix-ui/react-presence.mjs +128 -0
  68. package/admin-dist/server/_chunks/_libs/@radix-ui/react-primitive.mjs +141 -0
  69. package/admin-dist/server/_chunks/_libs/@radix-ui/react-roving-focus.mjs +224 -0
  70. package/admin-dist/server/_chunks/_libs/@radix-ui/react-scroll-area.mjs +721 -0
  71. package/admin-dist/server/_chunks/_libs/@radix-ui/react-select.mjs +1163 -0
  72. package/admin-dist/server/_chunks/_libs/@radix-ui/react-separator.mjs +28 -0
  73. package/admin-dist/server/_chunks/_libs/@radix-ui/react-slot.mjs +601 -0
  74. package/admin-dist/server/_chunks/_libs/@radix-ui/react-switch.mjs +152 -0
  75. package/admin-dist/server/_chunks/_libs/@radix-ui/react-tabs.mjs +189 -0
  76. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-callback-ref.mjs +11 -0
  77. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-controllable-state.mjs +69 -0
  78. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-effect-event.mjs +1 -0
  79. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-escape-keydown.mjs +17 -0
  80. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-is-hydrated.mjs +15 -0
  81. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-layout-effect.mjs +6 -0
  82. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-previous.mjs +14 -0
  83. package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-size.mjs +39 -0
  84. package/admin-dist/server/_chunks/_libs/@radix-ui/react-visually-hidden.mjs +33 -0
  85. package/admin-dist/server/_chunks/_libs/@tanstack/history.mjs +409 -0
  86. package/admin-dist/server/_chunks/_libs/@tanstack/react-router.mjs +1711 -0
  87. package/admin-dist/server/_chunks/_libs/@tanstack/react-store.mjs +56 -0
  88. package/admin-dist/server/_chunks/_libs/@tanstack/router-core.mjs +4829 -0
  89. package/admin-dist/server/_chunks/_libs/@tanstack/store.mjs +134 -0
  90. package/admin-dist/server/_chunks/_libs/react-dom.mjs +10781 -0
  91. package/admin-dist/server/_chunks/_libs/react.mjs +513 -0
  92. package/admin-dist/server/_libs/aria-hidden.mjs +122 -0
  93. package/admin-dist/server/_libs/class-variance-authority.mjs +44 -0
  94. package/admin-dist/server/_libs/clsx.mjs +16 -0
  95. package/admin-dist/server/_libs/cmdk.mjs +315 -0
  96. package/admin-dist/server/_libs/convex.mjs +4841 -0
  97. package/admin-dist/server/_libs/cookie-es.mjs +58 -0
  98. package/admin-dist/server/_libs/croner.mjs +1 -0
  99. package/admin-dist/server/_libs/crossws.mjs +1 -0
  100. package/admin-dist/server/_libs/date-fns.mjs +1716 -0
  101. package/admin-dist/server/_libs/detect-node-es.mjs +1 -0
  102. package/admin-dist/server/_libs/get-nonce.mjs +9 -0
  103. package/admin-dist/server/_libs/h3-v2.mjs +277 -0
  104. package/admin-dist/server/_libs/h3.mjs +401 -0
  105. package/admin-dist/server/_libs/hookable.mjs +1 -0
  106. package/admin-dist/server/_libs/isbot.mjs +20 -0
  107. package/admin-dist/server/_libs/lucide-react.mjs +850 -0
  108. package/admin-dist/server/_libs/ohash.mjs +1 -0
  109. package/admin-dist/server/_libs/react-day-picker.mjs +2201 -0
  110. package/admin-dist/server/_libs/react-remove-scroll-bar.mjs +82 -0
  111. package/admin-dist/server/_libs/react-remove-scroll.mjs +328 -0
  112. package/admin-dist/server/_libs/react-style-singleton.mjs +69 -0
  113. package/admin-dist/server/_libs/rou3.mjs +8 -0
  114. package/admin-dist/server/_libs/seroval-plugins.mjs +58 -0
  115. package/admin-dist/server/_libs/seroval.mjs +1765 -0
  116. package/admin-dist/server/_libs/srvx.mjs +719 -0
  117. package/admin-dist/server/_libs/tailwind-merge.mjs +3010 -0
  118. package/admin-dist/server/_libs/tiny-invariant.mjs +12 -0
  119. package/admin-dist/server/_libs/tiny-warning.mjs +5 -0
  120. package/admin-dist/server/_libs/tslib.mjs +39 -0
  121. package/admin-dist/server/_libs/ufo.mjs +54 -0
  122. package/admin-dist/server/_libs/unctx.mjs +1 -0
  123. package/admin-dist/server/_libs/unstorage.mjs +1 -0
  124. package/admin-dist/server/_libs/use-callback-ref.mjs +66 -0
  125. package/admin-dist/server/_libs/use-sidecar.mjs +106 -0
  126. package/admin-dist/server/_libs/use-sync-external-store.mjs +139 -0
  127. package/admin-dist/server/_libs/zod.mjs +4223 -0
  128. package/admin-dist/server/_ssr/CmsEmptyState-DU7-7-mV.mjs +290 -0
  129. package/admin-dist/server/_ssr/CmsPageHeader-CseW0AHm.mjs +24 -0
  130. package/admin-dist/server/_ssr/CmsStatusBadge-B_pi4KCp.mjs +127 -0
  131. package/admin-dist/server/_ssr/CmsToolbar-X75ex6ek.mjs +49 -0
  132. package/admin-dist/server/_ssr/ContentEntryEditor-CepusRsA.mjs +3720 -0
  133. package/admin-dist/server/_ssr/ErrorState-cI-bKLez.mjs +89 -0
  134. package/admin-dist/server/_ssr/TaxonomyFilter-Bwrq0-cz.mjs +188 -0
  135. package/admin-dist/server/_ssr/_contentTypeId-BqYKEcLr.mjs +379 -0
  136. package/admin-dist/server/_ssr/_entryId-CRfnqeDf.mjs +161 -0
  137. package/admin-dist/server/_ssr/_tanstack-start-manifest_v-BwDlABVk.mjs +4 -0
  138. package/admin-dist/server/_ssr/alert-CVt45UUP.mjs +92 -0
  139. package/admin-dist/server/_ssr/badge-6BsP37vG.mjs +125 -0
  140. package/admin-dist/server/_ssr/command-fy8epIKf.mjs +128 -0
  141. package/admin-dist/server/_ssr/config.server-D7JHDcDv.mjs +117 -0
  142. package/admin-dist/server/_ssr/content-B5RhL7uW.mjs +532 -0
  143. package/admin-dist/server/_ssr/content-types-BIOqCQYN.mjs +1166 -0
  144. package/admin-dist/server/_ssr/index-DHSHDPt1.mjs +193 -0
  145. package/admin-dist/server/_ssr/index.mjs +1275 -0
  146. package/admin-dist/server/_ssr/label-C8Dko1j7.mjs +22 -0
  147. package/admin-dist/server/_ssr/media-CSx3XttC.mjs +1832 -0
  148. package/admin-dist/server/_ssr/new._contentTypeId-DzanEZQM.mjs +144 -0
  149. package/admin-dist/server/_ssr/router-DDWcF-kt.mjs +1556 -0
  150. package/admin-dist/server/_ssr/scroll-area-bjPYwhXN.mjs +59 -0
  151. package/admin-dist/server/_ssr/select-BUhDDf4T.mjs +142 -0
  152. package/admin-dist/server/_ssr/settings-DAsxnw2q.mjs +348 -0
  153. package/admin-dist/server/_ssr/start-HYkvq4Ni.mjs +4 -0
  154. package/admin-dist/server/_ssr/switch-BgyRtQ1Z.mjs +31 -0
  155. package/admin-dist/server/_ssr/tabs-DzMdRB1A.mjs +628 -0
  156. package/admin-dist/server/_ssr/taxonomies-C8j8g5Q5.mjs +915 -0
  157. package/admin-dist/server/_ssr/textarea-9jNeYJSc.mjs +18 -0
  158. package/admin-dist/server/_ssr/trash-DYMxwhZB.mjs +291 -0
  159. package/admin-dist/server/_ssr/useBreadcrumbLabel-FNSAr2Ha.mjs +16 -0
  160. package/admin-dist/server/_ssr/usePermissions-BJGGahrJ.mjs +68 -0
  161. package/admin-dist/server/favicon.ico +0 -0
  162. package/admin-dist/server/index.mjs +627 -0
  163. package/dist/cli/index.js +0 -0
  164. package/dist/client/admin-config.d.ts +0 -1
  165. package/dist/client/admin-config.d.ts.map +1 -1
  166. package/dist/client/admin-config.js +0 -1
  167. package/dist/client/admin-config.js.map +1 -1
  168. package/dist/client/adminApi.d.ts.map +1 -1
  169. package/dist/client/agentTools.d.ts +1237 -135
  170. package/dist/client/agentTools.d.ts.map +1 -1
  171. package/dist/client/agentTools.js +33 -9
  172. package/dist/client/agentTools.js.map +1 -1
  173. package/dist/client/index.d.ts +1 -1
  174. package/dist/client/index.d.ts.map +1 -1
  175. package/dist/client/index.js.map +1 -1
  176. package/dist/component/_generated/component.d.ts +9 -0
  177. package/dist/component/_generated/component.d.ts.map +1 -1
  178. package/dist/component/mediaAssets.d.ts +35 -0
  179. package/dist/component/mediaAssets.d.ts.map +1 -1
  180. package/dist/component/mediaAssets.js +81 -0
  181. package/dist/component/mediaAssets.js.map +1 -1
  182. package/dist/test.d.ts.map +1 -1
  183. package/dist/test.js +2 -1
  184. package/dist/test.js.map +1 -1
  185. package/package.json +24 -9
  186. package/dist/component/auditLog.d.ts +0 -410
  187. package/dist/component/auditLog.d.ts.map +0 -1
  188. package/dist/component/auditLog.js +0 -607
  189. package/dist/component/auditLog.js.map +0 -1
  190. package/dist/component/types.d.ts +0 -4
  191. package/dist/component/types.d.ts.map +0 -1
  192. package/dist/component/types.js +0 -2
  193. package/dist/component/types.js.map +0 -1
  194. package/src/cli/commands/admin.ts +0 -104
  195. package/src/cli/index.ts +0 -21
  196. package/src/cli/utils/detectConvexUrl.ts +0 -54
  197. package/src/cli/utils/openBrowser.ts +0 -16
  198. package/src/client/admin-config.ts +0 -138
  199. package/src/client/adminApi.ts +0 -942
  200. package/src/client/agentTools.ts +0 -1311
  201. package/src/client/argTypes.ts +0 -316
  202. package/src/client/field-types.ts +0 -187
  203. package/src/client/index.ts +0 -1301
  204. package/src/client/queryBuilder.ts +0 -1100
  205. package/src/client/schema/codegen.ts +0 -500
  206. package/src/client/schema/defineContentType.ts +0 -501
  207. package/src/client/schema/index.ts +0 -169
  208. package/src/client/schema/schemaDrift.ts +0 -574
  209. package/src/client/schema/typedClient.ts +0 -688
  210. package/src/client/schema/types.ts +0 -666
  211. package/src/client/types.ts +0 -723
  212. package/src/client/workflows.ts +0 -141
  213. package/src/client/wrapper.ts +0 -4304
  214. package/src/component/_generated/api.ts +0 -140
  215. package/src/component/_generated/component.ts +0 -5029
  216. package/src/component/_generated/dataModel.ts +0 -60
  217. package/src/component/_generated/server.ts +0 -156
  218. package/src/component/authorization.ts +0 -647
  219. package/src/component/authorizationHooks.ts +0 -668
  220. package/src/component/bulkOperations.ts +0 -687
  221. package/src/component/contentEntries.ts +0 -1976
  222. package/src/component/contentEntryMutations.ts +0 -1223
  223. package/src/component/contentEntryValidation.ts +0 -707
  224. package/src/component/contentLock.ts +0 -550
  225. package/src/component/contentTypeMigration.ts +0 -1064
  226. package/src/component/contentTypeMutations.ts +0 -969
  227. package/src/component/contentTypes.ts +0 -346
  228. package/src/component/convex.config.ts +0 -44
  229. package/src/component/documentTypes.ts +0 -240
  230. package/src/component/eventEmitter.ts +0 -485
  231. package/src/component/exportImport.ts +0 -1169
  232. package/src/component/index.ts +0 -491
  233. package/src/component/lib/deepReferenceResolver.ts +0 -999
  234. package/src/component/lib/errors.ts +0 -816
  235. package/src/component/lib/index.ts +0 -145
  236. package/src/component/lib/mediaReferenceResolver.ts +0 -495
  237. package/src/component/lib/metadataExtractor.ts +0 -792
  238. package/src/component/lib/mutationAuth.ts +0 -199
  239. package/src/component/lib/queries.ts +0 -79
  240. package/src/component/lib/ragContentChunker.ts +0 -1371
  241. package/src/component/lib/referenceResolver.ts +0 -430
  242. package/src/component/lib/slugGenerator.ts +0 -262
  243. package/src/component/lib/slugUniqueness.ts +0 -333
  244. package/src/component/lib/softDelete.ts +0 -44
  245. package/src/component/localeFallbackChain.ts +0 -673
  246. package/src/component/localeFields.ts +0 -896
  247. package/src/component/mediaAssetMutations.ts +0 -725
  248. package/src/component/mediaAssets.ts +0 -932
  249. package/src/component/mediaFolderMutations.ts +0 -1046
  250. package/src/component/mediaUploadMutations.ts +0 -224
  251. package/src/component/mediaVariantMutations.ts +0 -900
  252. package/src/component/mediaVariants.ts +0 -793
  253. package/src/component/ragContentIndexer.ts +0 -1067
  254. package/src/component/rateLimitHooks.ts +0 -572
  255. package/src/component/roles.ts +0 -1360
  256. package/src/component/scheduledPublish.ts +0 -358
  257. package/src/component/schema.ts +0 -617
  258. package/src/component/taxonomies.ts +0 -949
  259. package/src/component/taxonomyMutations.ts +0 -1210
  260. package/src/component/trash.ts +0 -724
  261. package/src/component/userContext.ts +0 -898
  262. package/src/component/validation.ts +0 -1388
  263. package/src/component/validators.ts +0 -949
  264. package/src/component/versionMutations.ts +0 -392
  265. package/src/component/webhookTrigger.ts +0 -1922
  266. package/src/react/index.ts +0 -898
  267. package/src/test.ts +0 -1580
@@ -0,0 +1,719 @@
1
+ import nodeHTTP from "node:http";
2
+ import { Readable } from "node:stream";
3
+ import nodeHTTPS from "node:https";
4
+ import nodeHTTP2 from "node:http2";
5
+ function lazyInherit(target, source, sourceKey) {
6
+ for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
7
+ if (key === "constructor") continue;
8
+ const targetDesc = Object.getOwnPropertyDescriptor(target, key);
9
+ const desc = Object.getOwnPropertyDescriptor(source, key);
10
+ let modified = false;
11
+ if (desc.get) {
12
+ modified = true;
13
+ desc.get = targetDesc?.get || function() {
14
+ return this[sourceKey][key];
15
+ };
16
+ }
17
+ if (desc.set) {
18
+ modified = true;
19
+ desc.set = targetDesc?.set || function(value) {
20
+ this[sourceKey][key] = value;
21
+ };
22
+ }
23
+ if (!targetDesc?.value && typeof desc.value === "function") {
24
+ modified = true;
25
+ desc.value = function(...args) {
26
+ return this[sourceKey][key](...args);
27
+ };
28
+ }
29
+ if (modified) Object.defineProperty(target, key, desc);
30
+ }
31
+ }
32
+ const FastURL = /* @__PURE__ */ (() => {
33
+ const NativeURL = globalThis.URL;
34
+ const FastURL$1 = class URL {
35
+ #url;
36
+ #href;
37
+ #protocol;
38
+ #host;
39
+ #pathname;
40
+ #search;
41
+ #searchParams;
42
+ #pos;
43
+ constructor(url) {
44
+ if (typeof url === "string") this.#href = url;
45
+ else {
46
+ this.#protocol = url.protocol;
47
+ this.#host = url.host;
48
+ this.#pathname = url.pathname;
49
+ this.#search = url.search;
50
+ }
51
+ }
52
+ static [Symbol.hasInstance](val) {
53
+ return val instanceof NativeURL;
54
+ }
55
+ get _url() {
56
+ if (this.#url) return this.#url;
57
+ this.#url = new NativeURL(this.href);
58
+ this.#href = void 0;
59
+ this.#protocol = void 0;
60
+ this.#host = void 0;
61
+ this.#pathname = void 0;
62
+ this.#search = void 0;
63
+ this.#searchParams = void 0;
64
+ this.#pos = void 0;
65
+ return this.#url;
66
+ }
67
+ get href() {
68
+ if (this.#url) return this.#url.href;
69
+ if (!this.#href) this.#href = `${this.#protocol || "http:"}//${this.#host || "localhost"}${this.#pathname || "/"}${this.#search || ""}`;
70
+ return this.#href;
71
+ }
72
+ #getPos() {
73
+ if (!this.#pos) {
74
+ const url = this.href;
75
+ const protoIndex = url.indexOf("://");
76
+ const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
77
+ this.#pos = [
78
+ protoIndex,
79
+ pathnameIndex,
80
+ pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex)
81
+ ];
82
+ }
83
+ return this.#pos;
84
+ }
85
+ get pathname() {
86
+ if (this.#url) return this.#url.pathname;
87
+ if (this.#pathname === void 0) {
88
+ const [, pathnameIndex, queryIndex] = this.#getPos();
89
+ if (pathnameIndex === -1) return this._url.pathname;
90
+ this.#pathname = this.href.slice(pathnameIndex, queryIndex === -1 ? void 0 : queryIndex);
91
+ }
92
+ return this.#pathname;
93
+ }
94
+ get search() {
95
+ if (this.#url) return this.#url.search;
96
+ if (this.#search === void 0) {
97
+ const [, pathnameIndex, queryIndex] = this.#getPos();
98
+ if (pathnameIndex === -1) return this._url.search;
99
+ const url = this.href;
100
+ this.#search = queryIndex === -1 || queryIndex === url.length - 1 ? "" : url.slice(queryIndex);
101
+ }
102
+ return this.#search;
103
+ }
104
+ get searchParams() {
105
+ if (this.#url) return this.#url.searchParams;
106
+ if (!this.#searchParams) this.#searchParams = new URLSearchParams(this.search);
107
+ return this.#searchParams;
108
+ }
109
+ get protocol() {
110
+ if (this.#url) return this.#url.protocol;
111
+ if (this.#protocol === void 0) {
112
+ const [protocolIndex] = this.#getPos();
113
+ if (protocolIndex === -1) return this._url.protocol;
114
+ this.#protocol = this.href.slice(0, protocolIndex + 1);
115
+ }
116
+ return this.#protocol;
117
+ }
118
+ toString() {
119
+ return this.href;
120
+ }
121
+ toJSON() {
122
+ return this.href;
123
+ }
124
+ };
125
+ lazyInherit(FastURL$1.prototype, NativeURL.prototype, "_url");
126
+ Object.setPrototypeOf(FastURL$1.prototype, NativeURL.prototype);
127
+ Object.setPrototypeOf(FastURL$1, NativeURL);
128
+ return FastURL$1;
129
+ })();
130
+ function resolvePortAndHost(opts) {
131
+ const _port = opts.port ?? globalThis.process?.env.PORT ?? 3e3;
132
+ const port = typeof _port === "number" ? _port : Number.parseInt(_port, 10);
133
+ if (port < 0 || port > 65535) throw new RangeError(`Port must be between 0 and 65535 (got "${port}").`);
134
+ return {
135
+ port,
136
+ hostname: opts.hostname ?? globalThis.process?.env.HOST
137
+ };
138
+ }
139
+ function fmtURL(host, port, secure) {
140
+ if (!host || !port) return;
141
+ if (host.includes(":")) host = `[${host}]`;
142
+ return `http${secure ? "s" : ""}://${host}:${port}/`;
143
+ }
144
+ function printListening(opts, url) {
145
+ if (!url || (opts.silent ?? globalThis.process?.env?.TEST)) return;
146
+ let additionalInfo = "";
147
+ try {
148
+ const _url = new URL(url);
149
+ if (_url.hostname === "[::]" || _url.hostname === "0.0.0.0") {
150
+ _url.hostname = "localhost";
151
+ url = _url.href;
152
+ additionalInfo = " (all interfaces)";
153
+ }
154
+ } catch {
155
+ }
156
+ let listeningOn = `➜ Listening on:`;
157
+ if (globalThis.process.stdout?.isTTY) {
158
+ listeningOn = `\x1B[32m${listeningOn}\x1B[0m`;
159
+ url = `\x1B[36m${url}\x1B[0m`;
160
+ additionalInfo = `\x1B[2m${additionalInfo}\x1B[0m`;
161
+ }
162
+ console.log(`${listeningOn} ${url}${additionalInfo}`);
163
+ }
164
+ function resolveTLSOptions(opts) {
165
+ if (!opts.tls || opts.protocol === "http") return;
166
+ const cert = resolveCertOrKey(opts.tls.cert);
167
+ const key = resolveCertOrKey(opts.tls.key);
168
+ if (!cert && !key) {
169
+ if (opts.protocol === "https") throw new TypeError("TLS `cert` and `key` must be provided for `https` protocol.");
170
+ return;
171
+ }
172
+ if (!cert || !key) throw new TypeError("TLS `cert` and `key` must be provided together.");
173
+ return {
174
+ cert,
175
+ key,
176
+ passphrase: opts.tls.passphrase
177
+ };
178
+ }
179
+ function resolveCertOrKey(value) {
180
+ if (!value) return;
181
+ if (typeof value !== "string") throw new TypeError("TLS certificate and key must be strings in PEM format or file paths.");
182
+ if (value.startsWith("-----BEGIN ")) return value;
183
+ const { readFileSync } = process.getBuiltinModule("node:fs");
184
+ return readFileSync(value, "utf8");
185
+ }
186
+ function createWaitUntil() {
187
+ const promises = /* @__PURE__ */ new Set();
188
+ return {
189
+ waitUntil: (promise) => {
190
+ if (typeof promise?.then !== "function") return;
191
+ promises.add(Promise.resolve(promise).catch(console.error).finally(() => {
192
+ promises.delete(promise);
193
+ }));
194
+ },
195
+ wait: () => {
196
+ return Promise.all(promises);
197
+ }
198
+ };
199
+ }
200
+ const noColor = /* @__PURE__ */ (() => {
201
+ const env = globalThis.process?.env ?? {};
202
+ return env.NO_COLOR === "1" || env.TERM === "dumb";
203
+ })();
204
+ const _c = (c, r = 39) => (t) => noColor ? t : `\x1B[${c}m${t}\x1B[${r}m`;
205
+ const red = /* @__PURE__ */ _c(31);
206
+ const gray = /* @__PURE__ */ _c(90);
207
+ function wrapFetch(server) {
208
+ const fetchHandler = server.options.fetch;
209
+ const middleware = server.options.middleware || [];
210
+ return middleware.length === 0 ? fetchHandler : (request) => callMiddleware(request, fetchHandler, middleware, 0);
211
+ }
212
+ function callMiddleware(request, fetchHandler, middleware, index) {
213
+ if (index === middleware.length) return fetchHandler(request);
214
+ return middleware[index](request, () => callMiddleware(request, fetchHandler, middleware, index + 1));
215
+ }
216
+ const errorPlugin = (server) => {
217
+ const errorHandler = server.options.error;
218
+ if (!errorHandler) return;
219
+ server.options.middleware.unshift((_req, next) => {
220
+ try {
221
+ const res = next();
222
+ return res instanceof Promise ? res.catch((error) => errorHandler(error)) : res;
223
+ } catch (error) {
224
+ return errorHandler(error);
225
+ }
226
+ });
227
+ };
228
+ const gracefulShutdownPlugin = (server) => {
229
+ const config = server.options?.gracefulShutdown;
230
+ if (!globalThis.process?.on || config === false || config === void 0 && (process.env.CI || process.env.TEST)) return;
231
+ const gracefulShutdown = config === true || !config?.gracefulTimeout ? Number.parseInt(process.env.SERVER_SHUTDOWN_TIMEOUT || "") || 3 : config.gracefulTimeout;
232
+ const forceShutdown = config === true || !config?.forceTimeout ? Number.parseInt(process.env.SERVER_FORCE_SHUTDOWN_TIMEOUT || "") || 5 : config.forceTimeout;
233
+ let isShuttingDown = false;
234
+ let forceClose;
235
+ const shutdown = async () => {
236
+ if (isShuttingDown) {
237
+ forceClose?.();
238
+ return;
239
+ }
240
+ isShuttingDown = true;
241
+ const w = process.stderr.write.bind(process.stderr);
242
+ w(gray(`
243
+ Shutting down server in ${gracefulShutdown}s... (press Ctrl+C again to force close)`));
244
+ let timeout;
245
+ await Promise.race([server.close().finally(() => {
246
+ clearTimeout(timeout);
247
+ w(gray(" Server closed.\n"));
248
+ }), new Promise((resolve) => {
249
+ forceClose = () => {
250
+ clearTimeout(timeout);
251
+ w(gray("\nForce closing...\n"));
252
+ server.close(true);
253
+ resolve();
254
+ };
255
+ timeout = setTimeout(() => {
256
+ w(gray(`
257
+ Force closing connections in ${forceShutdown}s...`));
258
+ timeout = setTimeout(() => {
259
+ w(red("\nCould not close connections in time, force exiting."));
260
+ resolve();
261
+ }, forceShutdown * 1e3);
262
+ return server.close(true);
263
+ }, gracefulShutdown * 1e3);
264
+ })]);
265
+ globalThis.process.exit(0);
266
+ };
267
+ for (const sig of ["SIGINT", "SIGTERM"]) globalThis.process.on(sig, shutdown);
268
+ };
269
+ const NodeResponse = /* @__PURE__ */ (() => {
270
+ const NativeResponse = globalThis.Response;
271
+ const STATUS_CODES = globalThis.process?.getBuiltinModule?.("node:http")?.STATUS_CODES || {};
272
+ class NodeResponse$1 {
273
+ #body;
274
+ #init;
275
+ #headers;
276
+ #response;
277
+ constructor(body, init) {
278
+ this.#body = body;
279
+ this.#init = init;
280
+ }
281
+ static [Symbol.hasInstance](val) {
282
+ return val instanceof NativeResponse;
283
+ }
284
+ get status() {
285
+ return this.#response?.status || this.#init?.status || 200;
286
+ }
287
+ get statusText() {
288
+ return this.#response?.statusText || this.#init?.statusText || STATUS_CODES[this.status] || "";
289
+ }
290
+ get headers() {
291
+ if (this.#response) return this.#response.headers;
292
+ if (this.#headers) return this.#headers;
293
+ const initHeaders = this.#init?.headers;
294
+ return this.#headers = initHeaders instanceof Headers ? initHeaders : new Headers(initHeaders);
295
+ }
296
+ get ok() {
297
+ if (this.#response) return this.#response.ok;
298
+ const status = this.status;
299
+ return status >= 200 && status < 300;
300
+ }
301
+ get _response() {
302
+ if (this.#response) return this.#response;
303
+ this.#response = new NativeResponse(this.#body, this.#headers ? {
304
+ ...this.#init,
305
+ headers: this.#headers
306
+ } : this.#init);
307
+ this.#init = void 0;
308
+ this.#headers = void 0;
309
+ this.#body = void 0;
310
+ return this.#response;
311
+ }
312
+ _toNodeResponse() {
313
+ const status = this.status;
314
+ const statusText = this.statusText;
315
+ let body;
316
+ let contentType;
317
+ let contentLength;
318
+ if (this.#response) body = this.#response.body;
319
+ else if (this.#body) if (this.#body instanceof ReadableStream) body = this.#body;
320
+ else if (typeof this.#body === "string") {
321
+ body = this.#body;
322
+ contentType = "text/plain; charset=UTF-8";
323
+ contentLength = Buffer.byteLength(this.#body);
324
+ } else if (this.#body instanceof ArrayBuffer) {
325
+ body = Buffer.from(this.#body);
326
+ contentLength = this.#body.byteLength;
327
+ } else if (this.#body instanceof Uint8Array) {
328
+ body = this.#body;
329
+ contentLength = this.#body.byteLength;
330
+ } else if (this.#body instanceof DataView) {
331
+ body = Buffer.from(this.#body.buffer);
332
+ contentLength = this.#body.byteLength;
333
+ } else if (this.#body instanceof Blob) {
334
+ body = this.#body.stream();
335
+ contentType = this.#body.type;
336
+ contentLength = this.#body.size;
337
+ } else if (typeof this.#body.pipe === "function") body = this.#body;
338
+ else body = this._response.body;
339
+ const headers = [];
340
+ const initHeaders = this.#init?.headers;
341
+ const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders).map(([k, v]) => [k.toLowerCase(), v]) : void 0);
342
+ let hasContentTypeHeader;
343
+ let hasContentLength;
344
+ if (headerEntries) for (const [key, value] of headerEntries) {
345
+ if (Array.isArray(value)) for (const v of value) headers.push([key, v]);
346
+ else headers.push([key, value]);
347
+ if (key === "content-type") hasContentTypeHeader = true;
348
+ else if (key === "content-length") hasContentLength = true;
349
+ }
350
+ if (contentType && !hasContentTypeHeader) headers.push(["content-type", contentType]);
351
+ if (contentLength && !hasContentLength) headers.push(["content-length", String(contentLength)]);
352
+ this.#init = void 0;
353
+ this.#headers = void 0;
354
+ this.#response = void 0;
355
+ this.#body = void 0;
356
+ return {
357
+ status,
358
+ statusText,
359
+ headers,
360
+ body
361
+ };
362
+ }
363
+ }
364
+ lazyInherit(NodeResponse$1.prototype, NativeResponse.prototype, "_response");
365
+ Object.setPrototypeOf(NodeResponse$1, NativeResponse);
366
+ Object.setPrototypeOf(NodeResponse$1.prototype, NativeResponse.prototype);
367
+ return NodeResponse$1;
368
+ })();
369
+ async function sendNodeResponse(nodeRes, webRes) {
370
+ if (!webRes) {
371
+ nodeRes.statusCode = 500;
372
+ return endNodeResponse(nodeRes);
373
+ }
374
+ if (webRes._toNodeResponse) {
375
+ const res = webRes._toNodeResponse();
376
+ writeHead(nodeRes, res.status, res.statusText, res.headers);
377
+ if (res.body) {
378
+ if (res.body instanceof ReadableStream) return streamBody(res.body, nodeRes);
379
+ else if (typeof res.body?.pipe === "function") {
380
+ res.body.pipe(nodeRes);
381
+ return new Promise((resolve) => nodeRes.on("close", resolve));
382
+ }
383
+ nodeRes.write(res.body);
384
+ }
385
+ return endNodeResponse(nodeRes);
386
+ }
387
+ const rawHeaders = [...webRes.headers];
388
+ writeHead(nodeRes, webRes.status, webRes.statusText, rawHeaders);
389
+ return webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes);
390
+ }
391
+ function writeHead(nodeRes, status, statusText, rawHeaders) {
392
+ const writeHeaders = globalThis.Deno ? rawHeaders : rawHeaders.flat();
393
+ if (!nodeRes.headersSent) if (nodeRes.req?.httpVersion === "2.0") nodeRes.writeHead(status, writeHeaders);
394
+ else nodeRes.writeHead(status, statusText, writeHeaders);
395
+ }
396
+ function endNodeResponse(nodeRes) {
397
+ return new Promise((resolve) => nodeRes.end(resolve));
398
+ }
399
+ function streamBody(stream, nodeRes) {
400
+ if (nodeRes.destroyed) {
401
+ stream.cancel();
402
+ return;
403
+ }
404
+ const reader = stream.getReader();
405
+ function streamCancel(error) {
406
+ reader.cancel(error).catch(() => {
407
+ });
408
+ if (error) nodeRes.destroy(error);
409
+ }
410
+ function streamHandle({ done, value }) {
411
+ try {
412
+ if (done) nodeRes.end();
413
+ else if (nodeRes.write(value)) reader.read().then(streamHandle, streamCancel);
414
+ else nodeRes.once("drain", () => reader.read().then(streamHandle, streamCancel));
415
+ } catch (error) {
416
+ streamCancel(error instanceof Error ? error : void 0);
417
+ }
418
+ }
419
+ nodeRes.on("close", streamCancel);
420
+ nodeRes.on("error", streamCancel);
421
+ reader.read().then(streamHandle, streamCancel);
422
+ return reader.closed.catch(streamCancel).finally(() => {
423
+ nodeRes.off("close", streamCancel);
424
+ nodeRes.off("error", streamCancel);
425
+ });
426
+ }
427
+ var NodeRequestURL = class extends FastURL {
428
+ #req;
429
+ constructor({ req }) {
430
+ const path = req.url || "/";
431
+ if (path[0] === "/") {
432
+ const qIndex = path.indexOf("?");
433
+ const pathname = qIndex === -1 ? path : path?.slice(0, qIndex) || "/";
434
+ const search = qIndex === -1 ? "" : path?.slice(qIndex) || "";
435
+ const host = req.headers.host || req.headers[":authority"] || `${req.socket.localFamily === "IPv6" ? "[" + req.socket.localAddress + "]" : req.socket.localAddress}:${req.socket?.localPort || "80"}`;
436
+ const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" || req.headers[":scheme"] === "https" ? "https:" : "http:";
437
+ super({
438
+ protocol,
439
+ host,
440
+ pathname,
441
+ search
442
+ });
443
+ } else super(path);
444
+ this.#req = req;
445
+ }
446
+ get pathname() {
447
+ return super.pathname;
448
+ }
449
+ set pathname(value) {
450
+ this._url.pathname = value;
451
+ this.#req.url = this._url.pathname + this._url.search;
452
+ }
453
+ };
454
+ const NodeRequestHeaders = /* @__PURE__ */ (() => {
455
+ const NativeHeaders = globalThis.Headers;
456
+ class Headers2 {
457
+ #req;
458
+ #headers;
459
+ constructor(req) {
460
+ this.#req = req;
461
+ }
462
+ static [Symbol.hasInstance](val) {
463
+ return val instanceof NativeHeaders;
464
+ }
465
+ get _headers() {
466
+ if (!this.#headers) {
467
+ const headers = new NativeHeaders();
468
+ const rawHeaders = this.#req.rawHeaders;
469
+ const len = rawHeaders.length;
470
+ for (let i = 0; i < len; i += 2) {
471
+ const key = rawHeaders[i];
472
+ if (key.charCodeAt(0) === 58) continue;
473
+ const value = rawHeaders[i + 1];
474
+ headers.append(key, value);
475
+ }
476
+ this.#headers = headers;
477
+ }
478
+ return this.#headers;
479
+ }
480
+ get(name) {
481
+ if (this.#headers) return this.#headers.get(name);
482
+ const value = this.#req.headers[name.toLowerCase()];
483
+ return Array.isArray(value) ? value.join(", ") : value || null;
484
+ }
485
+ has(name) {
486
+ if (this.#headers) return this.#headers.has(name);
487
+ return name.toLowerCase() in this.#req.headers;
488
+ }
489
+ getSetCookie() {
490
+ if (this.#headers) return this.#headers.getSetCookie();
491
+ const value = this.#req.headers["set-cookie"];
492
+ return Array.isArray(value) ? value : value ? [value] : [];
493
+ }
494
+ *_entries() {
495
+ const rawHeaders = this.#req.rawHeaders;
496
+ const len = rawHeaders.length;
497
+ for (let i = 0; i < len; i += 2) {
498
+ const key = rawHeaders[i];
499
+ if (key.charCodeAt(0) === 58) continue;
500
+ yield [key.toLowerCase(), rawHeaders[i + 1]];
501
+ }
502
+ }
503
+ entries() {
504
+ return this.#headers ? this.#headers.entries() : this._entries();
505
+ }
506
+ [Symbol.iterator]() {
507
+ return this.entries();
508
+ }
509
+ }
510
+ lazyInherit(Headers2.prototype, NativeHeaders.prototype, "_headers");
511
+ Object.setPrototypeOf(Headers2, NativeHeaders);
512
+ Object.setPrototypeOf(Headers2.prototype, NativeHeaders.prototype);
513
+ return Headers2;
514
+ })();
515
+ const NodeRequest = /* @__PURE__ */ (() => {
516
+ const NativeRequest = globalThis.Request;
517
+ class Request {
518
+ runtime;
519
+ #req;
520
+ #url;
521
+ #bodyStream;
522
+ #request;
523
+ #headers;
524
+ #abortController;
525
+ constructor(ctx) {
526
+ this.#req = ctx.req;
527
+ this.runtime = {
528
+ name: "node",
529
+ node: ctx
530
+ };
531
+ }
532
+ static [Symbol.hasInstance](val) {
533
+ return val instanceof NativeRequest;
534
+ }
535
+ get ip() {
536
+ return this.#req.socket?.remoteAddress;
537
+ }
538
+ get method() {
539
+ if (this.#request) return this.#request.method;
540
+ return this.#req.method || "GET";
541
+ }
542
+ get _url() {
543
+ return this.#url ||= new NodeRequestURL({ req: this.#req });
544
+ }
545
+ set _url(url) {
546
+ this.#url = url;
547
+ }
548
+ get url() {
549
+ if (this.#request) return this.#request.url;
550
+ return this._url.href;
551
+ }
552
+ get headers() {
553
+ if (this.#request) return this.#request.headers;
554
+ return this.#headers ||= new NodeRequestHeaders(this.#req);
555
+ }
556
+ get _abortController() {
557
+ if (!this.#abortController) {
558
+ this.#abortController = new AbortController();
559
+ const { req, res } = this.runtime.node;
560
+ const abortController = this.#abortController;
561
+ const abort = (err) => abortController.abort?.(err);
562
+ if (res) res.once("close", () => {
563
+ const reqError = req.errored;
564
+ if (reqError) abort(reqError);
565
+ else if (!res.writableEnded) abort();
566
+ });
567
+ else req.once("close", () => {
568
+ if (!req.complete) abort();
569
+ });
570
+ }
571
+ return this.#abortController;
572
+ }
573
+ get signal() {
574
+ return this.#request ? this.#request.signal : this._abortController.signal;
575
+ }
576
+ get body() {
577
+ if (this.#request) return this.#request.body;
578
+ if (this.#bodyStream === void 0) {
579
+ const method = this.method;
580
+ this.#bodyStream = !(method === "GET" || method === "HEAD") ? Readable.toWeb(this.#req) : null;
581
+ }
582
+ return this.#bodyStream;
583
+ }
584
+ text() {
585
+ if (this.#request) return this.#request.text();
586
+ if (this.#bodyStream !== void 0) return this.#bodyStream ? new Response(this.#bodyStream).text() : Promise.resolve("");
587
+ return readBody(this.#req).then((buf) => buf.toString());
588
+ }
589
+ json() {
590
+ if (this.#request) return this.#request.json();
591
+ return this.text().then((text) => JSON.parse(text));
592
+ }
593
+ get _request() {
594
+ if (!this.#request) {
595
+ const body = this.body;
596
+ this.#request = new NativeRequest(this.url, {
597
+ method: this.method,
598
+ headers: this.headers,
599
+ signal: this._abortController.signal,
600
+ body,
601
+ duplex: body ? "half" : void 0
602
+ });
603
+ this.#headers = void 0;
604
+ this.#bodyStream = void 0;
605
+ }
606
+ return this.#request;
607
+ }
608
+ }
609
+ lazyInherit(Request.prototype, NativeRequest.prototype, "_request");
610
+ Object.setPrototypeOf(Request.prototype, NativeRequest.prototype);
611
+ return Request;
612
+ })();
613
+ function readBody(req) {
614
+ return new Promise((resolve, reject) => {
615
+ const chunks = [];
616
+ const onData = (chunk) => {
617
+ chunks.push(chunk);
618
+ };
619
+ const onError = (err) => {
620
+ reject(err);
621
+ };
622
+ const onEnd = () => {
623
+ req.off("error", onError);
624
+ req.off("data", onData);
625
+ resolve(Buffer.concat(chunks));
626
+ };
627
+ req.on("data", onData).once("end", onEnd).once("error", onError);
628
+ });
629
+ }
630
+ function serve(options) {
631
+ return new NodeServer(options);
632
+ }
633
+ var NodeServer = class {
634
+ runtime = "node";
635
+ options;
636
+ node;
637
+ serveOptions;
638
+ fetch;
639
+ #isSecure;
640
+ #listeningPromise;
641
+ #wait;
642
+ constructor(options) {
643
+ this.options = {
644
+ ...options,
645
+ middleware: [...options.middleware || []]
646
+ };
647
+ for (const plugin of options.plugins || []) plugin(this);
648
+ errorPlugin(this);
649
+ gracefulShutdownPlugin(this);
650
+ const fetchHandler = this.fetch = wrapFetch(this);
651
+ this.#wait = createWaitUntil();
652
+ const handler = (nodeReq, nodeRes) => {
653
+ const request = new NodeRequest({
654
+ req: nodeReq,
655
+ res: nodeRes
656
+ });
657
+ request.waitUntil = this.#wait.waitUntil;
658
+ const res = fetchHandler(request);
659
+ return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
660
+ };
661
+ const tls = resolveTLSOptions(this.options);
662
+ const { port, hostname: host } = resolvePortAndHost(this.options);
663
+ this.serveOptions = {
664
+ port,
665
+ host,
666
+ exclusive: !this.options.reusePort,
667
+ ...tls ? {
668
+ cert: tls.cert,
669
+ key: tls.key,
670
+ passphrase: tls.passphrase
671
+ } : {},
672
+ ...this.options.node
673
+ };
674
+ let server;
675
+ this.#isSecure = !!this.serveOptions.cert && this.options.protocol !== "http";
676
+ if (this.options.node?.http2 ?? this.#isSecure) if (this.#isSecure) server = nodeHTTP2.createSecureServer({
677
+ allowHTTP1: true,
678
+ ...this.serveOptions
679
+ }, handler);
680
+ else throw new Error("node.http2 option requires tls certificate!");
681
+ else if (this.#isSecure) server = nodeHTTPS.createServer(this.serveOptions, handler);
682
+ else server = nodeHTTP.createServer(this.serveOptions, handler);
683
+ this.node = {
684
+ server,
685
+ handler
686
+ };
687
+ if (!options.manual) this.serve();
688
+ }
689
+ serve() {
690
+ if (this.#listeningPromise) return Promise.resolve(this.#listeningPromise).then(() => this);
691
+ this.#listeningPromise = new Promise((resolve) => {
692
+ this.node.server.listen(this.serveOptions, () => {
693
+ printListening(this.options, this.url);
694
+ resolve();
695
+ });
696
+ });
697
+ }
698
+ get url() {
699
+ const addr = this.node?.server?.address();
700
+ if (!addr) return;
701
+ return typeof addr === "string" ? addr : fmtURL(addr.address, addr.port, this.#isSecure);
702
+ }
703
+ ready() {
704
+ return Promise.resolve(this.#listeningPromise).then(() => this);
705
+ }
706
+ async close(closeAll) {
707
+ await Promise.all([this.#wait.wait(), new Promise((resolve, reject) => {
708
+ const server = this.node?.server;
709
+ if (!server || !server.listening) return resolve();
710
+ if (closeAll && "closeAllConnections" in server) server.closeAllConnections();
711
+ server.close((error) => error ? reject(error) : resolve());
712
+ })]);
713
+ }
714
+ };
715
+ export {
716
+ FastURL as F,
717
+ NodeResponse as N,
718
+ serve as s
719
+ };