@comapeo/map-server 1.0.0-pre.3 → 1.0.0-pre.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/lib/download-request.js +1 -1
- package/dist/lib/map-share.js +2 -2
- package/package.json +1 -1
- package/src/index.ts +7 -4
- package/src/lib/download-request.ts +1 -1
- package/src/lib/map-share.ts +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { errors } from './lib/errors.js';
|
|
2
|
+
export { CUSTOM_MAP_ID, DEFAULT_MAP_ID } from './lib/constants.js';
|
|
2
3
|
export type { MapInfo, MapShareState, MapShareStateUpdate, DownloadStateUpdate, } from './types.js';
|
|
3
4
|
export type { DownloadState } from './lib/download-request.js';
|
|
4
5
|
export type { MapShareCreateParams, MapShareDeclineParams, } from './routes/map-shares.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAElE,YAAY,EACX,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EACX,oBAAoB,EACpB,qBAAqB,GACrB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,MAAM,MAAM,aAAa,GAAG;IAC3B,qBAAqB,EAAE,MAAM,GAAG,GAAG,CAAA;IACnC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAA;IAC3B,eAAe,EAAE,MAAM,GAAG,GAAG,CAAA;IAC7B,OAAO,CAAC,EAAE;QACT,SAAS,EAAE,UAAU,CAAA;QACrB,SAAS,EAAE,UAAU,CAAA;KACrB,CAAA;CACD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAOD,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa;kBA+C9B,aAAa;;;;;EA+BjC"}
|
package/dist/index.js
CHANGED
|
@@ -8,12 +8,13 @@ import { Context } from './context.js';
|
|
|
8
8
|
import { fetchAPI } from './lib/fetch-api.js';
|
|
9
9
|
import { RootRouter } from './routes/root.js';
|
|
10
10
|
export { errors } from './lib/errors.js';
|
|
11
|
+
export { CUSTOM_MAP_ID, DEFAULT_MAP_ID } from './lib/constants.js';
|
|
11
12
|
export function createServer(options) {
|
|
12
13
|
validateOptions(options);
|
|
13
14
|
if (!options.keyPair) {
|
|
14
15
|
options.keyPair = Agent.keyPair();
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
let deferredListen = pDefer();
|
|
17
18
|
const context = new Context({
|
|
18
19
|
...options,
|
|
19
20
|
keyPair: options.keyPair,
|
|
@@ -78,6 +79,8 @@ export function createServer(options) {
|
|
|
78
79
|
once(localHttpServer, 'close'),
|
|
79
80
|
once(secretStreamServer, 'close'),
|
|
80
81
|
]);
|
|
82
|
+
// Reset deferred listen for potential restart with different ports
|
|
83
|
+
deferredListen = pDefer();
|
|
81
84
|
},
|
|
82
85
|
};
|
|
83
86
|
}
|
|
@@ -51,7 +51,7 @@ export class DownloadRequest extends TypedEventTarget {
|
|
|
51
51
|
}
|
|
52
52
|
else if (getErrorCode(error)) {
|
|
53
53
|
// Specific known error from the server
|
|
54
|
-
this.#updateState({ status: 'error', error });
|
|
54
|
+
this.#updateState({ status: 'error', error: jsonError(error) });
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
// Once the download has started, the sender can only close the
|
package/dist/lib/map-share.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypedEventTarget } from '../lib/event-target.js';
|
|
2
|
-
import { errors } from './errors.js';
|
|
2
|
+
import { errors, jsonError } from './errors.js';
|
|
3
3
|
import { StateUpdateEvent } from './state-update-event.js';
|
|
4
4
|
import { addTrailingSlash, generateId, getErrorCode } from './utils.js';
|
|
5
5
|
/**
|
|
@@ -117,7 +117,7 @@ export class DownloadResponse extends TypedEventTarget {
|
|
|
117
117
|
this.#updateState({ status: 'aborted' });
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
120
|
-
this.#updateState({ status: 'error', error });
|
|
120
|
+
this.#updateState({ status: 'error', error: jsonError(error) });
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
this.#response = new Response(this.#stream.readable, {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert'
|
|
2
2
|
import { once } from 'node:events'
|
|
3
3
|
import http from 'node:http'
|
|
4
|
-
import { type AddressInfo } from 'node:net'
|
|
4
|
+
import { type AddressInfo, type Socket } from 'node:net'
|
|
5
5
|
|
|
6
6
|
import { createServerAdapter } from '@whatwg-node/server'
|
|
7
7
|
import pDefer from 'p-defer'
|
|
@@ -16,6 +16,7 @@ import { RootRouter } from './routes/root.js'
|
|
|
16
16
|
import type { FetchContext } from './types.js'
|
|
17
17
|
|
|
18
18
|
export { errors } from './lib/errors.js'
|
|
19
|
+
export { CUSTOM_MAP_ID, DEFAULT_MAP_ID } from './lib/constants.js'
|
|
19
20
|
|
|
20
21
|
export type {
|
|
21
22
|
MapInfo,
|
|
@@ -56,7 +57,7 @@ export function createServer(options: ServerOptions) {
|
|
|
56
57
|
options.keyPair = Agent.keyPair()
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
let deferredListen = pDefer<ListenResult>()
|
|
60
61
|
const context = new Context({
|
|
61
62
|
...options,
|
|
62
63
|
keyPair: options.keyPair,
|
|
@@ -86,8 +87,8 @@ export function createServer(options: ServerOptions) {
|
|
|
86
87
|
})
|
|
87
88
|
|
|
88
89
|
// Track connections for proper cleanup
|
|
89
|
-
const connections = new Set<
|
|
90
|
-
const onConnection = (socket:
|
|
90
|
+
const connections = new Set<Socket>()
|
|
91
|
+
const onConnection = (socket: Socket) => {
|
|
91
92
|
connections.add(socket)
|
|
92
93
|
socket.once('close', () => {
|
|
93
94
|
connections.delete(socket)
|
|
@@ -124,6 +125,8 @@ export function createServer(options: ServerOptions) {
|
|
|
124
125
|
once(localHttpServer, 'close'),
|
|
125
126
|
once(secretStreamServer, 'close'),
|
|
126
127
|
])
|
|
128
|
+
// Reset deferred listen for potential restart with different ports
|
|
129
|
+
deferredListen = pDefer<ListenResult>()
|
|
127
130
|
},
|
|
128
131
|
}
|
|
129
132
|
}
|
|
@@ -67,7 +67,7 @@ export class DownloadRequest extends TypedEventTarget<
|
|
|
67
67
|
this.#updateState({ status: 'canceled' })
|
|
68
68
|
} else if (getErrorCode(error)) {
|
|
69
69
|
// Specific known error from the server
|
|
70
|
-
this.#updateState({ status: 'error', error })
|
|
70
|
+
this.#updateState({ status: 'error', error: jsonError(error) })
|
|
71
71
|
} else {
|
|
72
72
|
// Once the download has started, the sender can only close the
|
|
73
73
|
// connection to cancel the download, which we only see as an
|
package/src/lib/map-share.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type DownloadStateUpdate,
|
|
6
6
|
type MapInfo,
|
|
7
7
|
} from '../types.js'
|
|
8
|
-
import { errors } from './errors.js'
|
|
8
|
+
import { errors, jsonError } from './errors.js'
|
|
9
9
|
import { StateUpdateEvent } from './state-update-event.js'
|
|
10
10
|
import { addTrailingSlash, generateId, getErrorCode } from './utils.js'
|
|
11
11
|
|
|
@@ -155,7 +155,7 @@ export class DownloadResponse extends TypedEventTarget<
|
|
|
155
155
|
} else if (getErrorCode(error) === 'ECONNRESET') {
|
|
156
156
|
this.#updateState({ status: 'aborted' })
|
|
157
157
|
} else {
|
|
158
|
-
this.#updateState({ status: 'error', error })
|
|
158
|
+
this.#updateState({ status: 'error', error: jsonError(error) })
|
|
159
159
|
}
|
|
160
160
|
})
|
|
161
161
|
|