@latlng/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +343 -0
- package/dist/auth/token.d.ts +2 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/client.d.ts +385 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/errors/index.d.ts +66 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/http/routes.d.ts +41 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/transport.d.ts +26 -0
- package/dist/http/transport.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1455 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/assert.d.ts +6 -0
- package/dist/internal/assert.d.ts.map +1 -0
- package/dist/internal/json.d.ts +3 -0
- package/dist/internal/json.d.ts.map +1 -0
- package/dist/internal/response-parsers.d.ts +26 -0
- package/dist/internal/response-parsers.d.ts.map +1 -0
- package/dist/routing/read-preference.d.ts +7 -0
- package/dist/routing/read-preference.d.ts.map +1 -0
- package/dist/routing/replicas.d.ts +22 -0
- package/dist/routing/replicas.d.ts.map +1 -0
- package/dist/types/events.d.ts +122 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/json.d.ts +7 -0
- package/dist/types/json.d.ts.map +1 -0
- package/dist/types/models.d.ts +408 -0
- package/dist/types/models.d.ts.map +1 -0
- package/dist/types/requests.d.ts +96 -0
- package/dist/types/requests.d.ts.map +1 -0
- package/dist/types/responses.d.ts +108 -0
- package/dist/types/responses.d.ts.map +1 -0
- package/dist/ws/socket.d.ts +66 -0
- package/dist/ws/socket.d.ts.map +1 -0
- package/dist/ws/subscriptions.d.ts +46 -0
- package/dist/ws/subscriptions.d.ts.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LatLngSubscription } from "./subscriptions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for establishing a WebSocket session.
|
|
4
|
+
*/
|
|
5
|
+
export interface LatLngWebSocketConfig {
|
|
6
|
+
/** Full WebSocket endpoint URL, for example `ws://127.0.0.1:7421/ws`. */
|
|
7
|
+
url: string;
|
|
8
|
+
/** Optional bearer token or JWT sent through the initial `auth` command. */
|
|
9
|
+
token?: string;
|
|
10
|
+
/** Custom WebSocket constructor/factory for tests or non-browser runtimes. */
|
|
11
|
+
webSocketFactory?: (url: string) => WebSocket;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* WebSocket client for `latlng` channel subscriptions.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LatLngWebSocketClient {
|
|
17
|
+
private readonly socket;
|
|
18
|
+
private readonly token?;
|
|
19
|
+
private readonly pending;
|
|
20
|
+
private activeSubscription?;
|
|
21
|
+
private constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Opens a WebSocket connection and optionally authenticates it with the provided token.
|
|
24
|
+
*
|
|
25
|
+
* @param config WebSocket connection configuration.
|
|
26
|
+
* @returns Connected WebSocket client.
|
|
27
|
+
*/
|
|
28
|
+
static connect(config: LatLngWebSocketConfig): Promise<LatLngWebSocketClient>;
|
|
29
|
+
/**
|
|
30
|
+
* Sends a protocol-level ping command over the active WebSocket connection.
|
|
31
|
+
*
|
|
32
|
+
* @returns Raw ping acknowledgement payload.
|
|
33
|
+
*/
|
|
34
|
+
ping(): Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribes to one or more explicit channel names.
|
|
37
|
+
*
|
|
38
|
+
* The returned subscription represents the active stream for this socket.
|
|
39
|
+
*
|
|
40
|
+
* @param channels Channel names to subscribe to.
|
|
41
|
+
* @returns Active subscription stream.
|
|
42
|
+
*/
|
|
43
|
+
subscribe(channels: string[]): Promise<LatLngSubscription>;
|
|
44
|
+
/**
|
|
45
|
+
* Subscribes to one or more channel patterns.
|
|
46
|
+
*
|
|
47
|
+
* The returned subscription represents the active stream for this socket.
|
|
48
|
+
*
|
|
49
|
+
* @param patterns Channel patterns to subscribe to.
|
|
50
|
+
* @returns Active subscription stream.
|
|
51
|
+
*/
|
|
52
|
+
psubscribe(patterns: string[]): Promise<LatLngSubscription>;
|
|
53
|
+
/**
|
|
54
|
+
* Requests a graceful server-side close and then closes the underlying socket.
|
|
55
|
+
*/
|
|
56
|
+
quit(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Closes the underlying WebSocket immediately.
|
|
59
|
+
*/
|
|
60
|
+
close(): void;
|
|
61
|
+
private replaceSubscription;
|
|
62
|
+
private command;
|
|
63
|
+
private handleMessage;
|
|
64
|
+
private tryParseEvent;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/ws/socket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yEAAyE;IACzE,GAAG,EAAE,MAAM,CAAC;IACZ,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,CAAC;CAC/C;AAOD;;GAEG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,kBAAkB,CAAC,CAAqB;IAEhD,OAAO;IAoBP;;;;;OAKG;WACiB,OAAO,CACzB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAgCjC;;;;OAIG;IACU,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;OAOG;IACU,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAWvE;;;;;;;OAOG;IACU,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAWxE;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAUlC;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB,OAAO,CAAC,mBAAmB;YASb,OAAO;IAWrB,OAAO,CAAC,aAAa;IAwBrB,OAAO,CAAC,aAAa;CAOtB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { GeofenceEvent } from "../types/events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Event stream wrapper returned by WebSocket subscription commands.
|
|
4
|
+
*
|
|
5
|
+
* It supports callback-style listeners and async iteration.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LatLngSubscription implements AsyncIterable<GeofenceEvent> {
|
|
8
|
+
private readonly events;
|
|
9
|
+
private readonly eventHandlers;
|
|
10
|
+
private readonly closeHandlers;
|
|
11
|
+
private readonly errorHandlers;
|
|
12
|
+
private readonly closeFn;
|
|
13
|
+
private closed;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a subscription wrapper around the underlying socket close callback.
|
|
16
|
+
*
|
|
17
|
+
* @param closeFn Callback used to close the underlying socket transport.
|
|
18
|
+
*/
|
|
19
|
+
constructor(closeFn: () => void);
|
|
20
|
+
/**
|
|
21
|
+
* Registers an event listener.
|
|
22
|
+
*
|
|
23
|
+
* Returns an unsubscribe function that removes the handler again.
|
|
24
|
+
*
|
|
25
|
+
* @param type Event type to subscribe to.
|
|
26
|
+
* @param handler Event handler callback.
|
|
27
|
+
* @returns Function that removes the registered handler.
|
|
28
|
+
*/
|
|
29
|
+
on(type: "event", handler: (event: GeofenceEvent) => void): () => void;
|
|
30
|
+
on(type: "close", handler: () => void): () => void;
|
|
31
|
+
on(type: "error", handler: (error: unknown) => void): () => void;
|
|
32
|
+
push(event: GeofenceEvent): void;
|
|
33
|
+
fail(error: unknown): void;
|
|
34
|
+
/**
|
|
35
|
+
* Closes the subscription and its underlying socket.
|
|
36
|
+
*/
|
|
37
|
+
close(): void;
|
|
38
|
+
finish(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Returns an async iterator that yields geofence events until the subscription closes.
|
|
41
|
+
*
|
|
42
|
+
* @returns Async iterator over geofence events.
|
|
43
|
+
*/
|
|
44
|
+
[Symbol.asyncIterator](): AsyncIterator<GeofenceEvent>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAyCxD;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,aAAa,CAAC,aAAa,CAAC;IACrE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA6C;IAC3E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;IACvD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAuC;IACrE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACgB,OAAO,EAAE,MAAM,IAAI;IAItC;;;;;;;;OAQG;IACI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IACtE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAClD,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI;IA0BhE,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAOhC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAMjC;;OAEG;IACI,KAAK,IAAI,IAAI;IASb,MAAM,IAAI,IAAI;IAUrB;;;;OAIG;IACI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC;CAK9D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@latlng/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for the latlng geospatial object engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"homepage": "https://github.com/tobilg/latlng",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/tobilg/latlng/issues"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/tobilg/latlng"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "vite build && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
35
|
+
"docs:api": "typedoc --options typedoc.json",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
37
|
+
"test:unit": "vitest run test/unit",
|
|
38
|
+
"test:integration": "vitest run test/integration",
|
|
39
|
+
"test": "npm run build && npm run test:unit && npm run test:integration"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@emnapi/core": "^1.10.0",
|
|
43
|
+
"@emnapi/runtime": "^1.10.0",
|
|
44
|
+
"typedoc": "^0.28.19",
|
|
45
|
+
"typescript": "^6.0.3",
|
|
46
|
+
"vite": "^8.0.11",
|
|
47
|
+
"vitest": "^4.1.5"
|
|
48
|
+
}
|
|
49
|
+
}
|