Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
713 changes: 20 additions & 693 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test:types": "tsc --noEmit",
"publint": "npm run build && publint",
"format": "prettier --write .",
"prepare": "husky && patch-package",
"prepare": "husky",
"build": "tsc -p tsconfig.npm.json",
"prepack": "run-s test build"
},
Expand All @@ -51,7 +51,6 @@
"lint-staged": "^17.4.1",
"msw": "^2.15.0",
"npm-run-all2": "^9.0.3",
"patch-package": "^8.0.1",
"prettier": "^3.9.6",
"publint": "^0.3.24",
"type-fest": "^5.9.0",
Expand All @@ -78,9 +77,9 @@
"*.{js,css,md}": "prettier --write"
},
"dependencies": {
"@comapeo/node-server": "^1.0.0",
"@mapbox/mapbox-gl-style-spec": "^14.29.1",
"@maplibre/maplibre-gl-style-spec": "^26.4.1",
"@whatwg-node/server": "^0.11.0",
"itty-router": "^5.0.24",
"p-defer": "^4.0.1",
"p-mutex": "^1.0.0",
Expand All @@ -90,9 +89,6 @@
"typebox": "~1.3.25",
"typed-event-target": "^4.3.3"
},
"bundleDependencies": [
"@whatwg-node/server"
],
"files": [
"src/",
"dist/"
Expand Down
123 changes: 0 additions & 123 deletions patches/@whatwg-node+server+0.11.0.patch

This file was deleted.

31 changes: 14 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { once } from 'node:events'
import http from 'node:http'
import { type AddressInfo, type Server, type Socket } from 'node:net'

import { createServerAdapter } from '@whatwg-node/server'
import { createAdapter } from '@comapeo/node-server'
import pDefer from 'p-defer'
import Mutex from 'p-mutex'
import {
Expand All @@ -13,7 +13,6 @@ import {

import { Context } from './context.js'
import { errors } from './lib/errors.js'
import { fetchAPI } from './lib/fetch-api.js'
import { getErrorCode, noop } from './lib/utils.js'
import { RootRouter } from './routes/root.js'
import type { FetchContext } from './types.js'
Expand Down Expand Up @@ -91,24 +90,22 @@ export function createServer(options: ServerOptions) {
{ base: '/', uploadIdleTimeoutMs: options.uploadIdleTimeoutMs },
context,
)
// Use native fetch API to avoid ponyfill bugs with stream error propagation
const serverAdapter = createServerAdapter<FetchContext>(router.fetch, {
fetchAPI,
})
const handler = (request: Request, fetchContext: FetchContext) =>
router.fetch(request, fetchContext)
const localHttpServer = http.createServer(
{ highWaterMark: SOCKET_HIGH_WATER_MARK },
(req, res) => {
serverAdapter(req, res, { isLocalhost: true })
},
createAdapter(handler, { getContext: () => ({ isLocalhost: true }) }),
)

const remoteHttpServer = http.createServer((req, res) => {
serverAdapter(req, res, {
isLocalhost: false,
// @ts-expect-error - the types for this are too hard and making them work would not add any type safety.
remoteDeviceId: Buffer.from(req.socket.remotePublicKey).toString('hex'),
})
})
const remoteHttpServer = http.createServer(
createAdapter(handler, {
getContext: (req) => ({
isLocalhost: false,
// @ts-expect-error - secret-stream-http adds remotePublicKey to the socket
remoteDeviceId: Buffer.from(req.socket.remotePublicKey).toString('hex'),
}),
}),
)
const secretStreamServer = createSecretStreamServer(remoteHttpServer, {
keyPair: options.keyPair,
})
Expand Down Expand Up @@ -336,7 +333,7 @@ function validateOptions(options: unknown): asserts options is ServerOptions {
new TypeError('defaultOnlineStyleUrl must be a string or URL'),
)
assert(
URL.canParse(options.defaultOnlineStyleUrl),
URL.canParse(String(options.defaultOnlineStyleUrl)),
new TypeError('defaultOnlineStyleUrl must be a valid URL'),
)
assert(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/download-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DownloadRequest extends TypedEventTarget<
dispatcher: this.#dispatcher,
signal: AbortSignal.timeout(2000),
})
const json = await response.json()
const json: any = await response.json()
if (json.status) {
this.#updateState({ status: json.status, error: json.error })
return
Expand Down Expand Up @@ -146,7 +146,7 @@ export class DownloadRequest extends TypedEventTarget<
})
}
if (!response.ok) {
throw new StatusError(response.status, await response.json())
throw new StatusError(response.status, (await response.json()) as any)
}
if (this.#abortController.signal.aborted) {
response.body.cancel().catch(noop)
Expand Down
18 changes: 0 additions & 18 deletions src/lib/fetch-api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/routes/map-shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export function MapSharesRouter(
}
if (!response.ok) {
// pass through error from sender
throw new StatusError(response.status, await response.json())
throw new StatusError(response.status, (await response.json()) as any)
}
return new Response(null, { status: 204 })
}
Expand Down
4 changes: 3 additions & 1 deletion src/routes/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export function MapsRouter(

if (response && response.ok) {
if (url.toString().startsWith(BASE_MAPBOX_API_URL)) {
const body = await response.json()
const body = (await response.json()) as Parameters<
typeof transformUrls
>[0]

transformUrls(body, {
accessToken:
Expand Down
2 changes: 1 addition & 1 deletion test/map-shares.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ describe('Map Shares and Downloads', () => {

// Should succeed
expect(response.status).toBe(200)
const shareInfo = await response.json()
const shareInfo: any = await response.json()
expect(shareInfo.shareId).toBe(shareId)
expect(shareInfo.receiverDeviceId).toBe(receiver.deviceId)
})
Expand Down
Loading
Loading