@based/functions 3.0.1 → 3.1.0-alpha
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/auth.d.ts +1 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.js.map +1 -1
- package/dist/functions.d.ts +10 -0
- package/dist/functions.js.map +1 -1
- package/dist/stream.d.ts +3 -6
- package/dist/stream.js +14 -8
- package/dist/stream.js.map +1 -1
- package/package.json +9 -5
- package/src/auth.ts +0 -34
- package/src/channel.ts +0 -10
- package/src/client.ts +0 -35
- package/src/context.ts +0 -151
- package/src/functions.ts +0 -365
- package/src/geo.ts +0 -322
- package/src/index.ts +0 -8
- package/src/query.ts +0 -14
- package/src/stream.ts +0 -95
- package/src/uws.d.ts +0 -469
- package/tsconfig.json +0 -11
package/dist/auth.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type AuthState = {
|
|
|
8
8
|
error?: string;
|
|
9
9
|
persistent?: boolean;
|
|
10
10
|
type?: string;
|
|
11
|
+
t?: 0 | 1;
|
|
11
12
|
};
|
|
12
13
|
export type Authorize = (based: BasedFunctionClient, context: Context<HttpSession | WebSocketSession>, name: string, // name as generic dope
|
|
13
14
|
payload?: any) => Promise<boolean>;
|
package/dist/context.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { parseQuery } from '@saulx/utils';
|
|
|
2
2
|
import { AuthState } from './auth.js';
|
|
3
3
|
import { WebSocket, HttpRequest, HttpResponse } from './uws.js';
|
|
4
4
|
import { BasedFunctionClient } from './client.js';
|
|
5
|
+
import { StreamPayload } from './functions.js';
|
|
5
6
|
export type WebSocketSession = {
|
|
6
7
|
state?: any;
|
|
7
8
|
query: string;
|
|
@@ -10,6 +11,7 @@ export type WebSocketSession = {
|
|
|
10
11
|
id: number;
|
|
11
12
|
method: string;
|
|
12
13
|
authState: AuthState;
|
|
14
|
+
type: '0' | '1';
|
|
13
15
|
origin: string;
|
|
14
16
|
obs: Set<number>;
|
|
15
17
|
unauthorizedObs?: Set<{
|
|
@@ -18,6 +20,9 @@ export type WebSocketSession = {
|
|
|
18
20
|
name: string;
|
|
19
21
|
payload: any;
|
|
20
22
|
}>;
|
|
23
|
+
streams?: {
|
|
24
|
+
[reqId: string]: StreamPayload;
|
|
25
|
+
};
|
|
21
26
|
headers: {
|
|
22
27
|
[key: string]: string;
|
|
23
28
|
};
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AA8GA,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAqB,EACQ,EAAE;IAC/B,IAAI,KAAK,IAAI,GAAG,EAAE,OAAO,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAqB,EACa,EAAE;IACpC,IAAI,GAAG,CAAC,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAAqB,EAC2B,EAAE;IAClD,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAC5E,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAA4B,EACJ,EAAE;IAC1B,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAA4B,EACC,EAAE;IAC/B,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
package/dist/functions.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Context, HttpSession } from './context.js';
|
|
|
3
3
|
import { BasedFunctionClient } from './client.js';
|
|
4
4
|
import { BasedDataStream } from './stream.js';
|
|
5
5
|
import { Authorize } from './auth.js';
|
|
6
|
+
import type { BuildOptions } from 'esbuild';
|
|
6
7
|
export type ObservableUpdateFunction<K = any> = (data: K, checksum?: number, err?: any, cache?: Uint8Array, diff?: any, fromChecksum?: number, isDeflate?: boolean) => void;
|
|
7
8
|
export type ObserveErrorListener = (err: any) => void;
|
|
8
9
|
export type HttpHeaders = {
|
|
@@ -33,6 +34,8 @@ export type StreamPayload<P = any> = {
|
|
|
33
34
|
stream: BasedDataStream;
|
|
34
35
|
fileName?: string;
|
|
35
36
|
extension?: string;
|
|
37
|
+
fn?: string;
|
|
38
|
+
seqId?: number;
|
|
36
39
|
};
|
|
37
40
|
export type BasedStreamFunction<P = any, K = any> = BasedFunction<StreamPayload<P>, K>;
|
|
38
41
|
export type BasedQueryFunction<P = any, K = any> = ((based: BasedFunctionClient, payload: P, update: ObservableUpdateFunction<K>, error: ObserveErrorListener) => Promise<() => void>) | ((based: BasedFunctionClient, payload: P, update: ObservableUpdateFunction<K>, error: ObserveErrorListener) => () => void);
|
|
@@ -158,6 +161,13 @@ type BasedAppFunctionConfig = {
|
|
|
158
161
|
main: string;
|
|
159
162
|
path?: string;
|
|
160
163
|
favicon?: string;
|
|
164
|
+
build?: {
|
|
165
|
+
watch?: {
|
|
166
|
+
include: string[];
|
|
167
|
+
exclude?: string[];
|
|
168
|
+
};
|
|
169
|
+
plugins?: BuildOptions['plugins'];
|
|
170
|
+
};
|
|
161
171
|
};
|
|
162
172
|
type BasedJobFunctionConfig = {
|
|
163
173
|
type: 'job';
|
package/dist/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AA2UA,MAAM,UAAU,YAAY,CAC1B,IAAO,EACP,KAAU;IAEV,OAAO,CACL,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,IAAI,KAAK,IAAI;QACnB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC/B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAU;IACxC,OAAO,CACL,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS;YACvB,KAAK,CAAC,IAAI,KAAK,OAAO;YACtB,KAAK,CAAC,IAAI,KAAK,UAAU;YACzB,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;QAC1B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC/B,CAAA;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAAO,EACP,MAAW;IAEX,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,MAAW;IAEX,OAAO,eAAe,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
5
|
-
import { Duplex, Readable } from 'stream';
|
|
6
|
-
import util from 'util';
|
|
1
|
+
import { Duplex, Readable } from "node:stream";
|
|
2
|
+
import util from "node:util";
|
|
7
3
|
export declare class BasedDataStream extends Duplex {
|
|
8
4
|
size: number;
|
|
5
|
+
paused: boolean;
|
|
9
6
|
receivedBytes: number;
|
|
10
7
|
progessTimer: NodeJS.Timeout;
|
|
11
8
|
constructor(size: number);
|
package/dist/stream.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { Duplex, Readable } from
|
|
2
|
-
import util from
|
|
3
|
-
// prob want to move this to based functions
|
|
1
|
+
import { Duplex, Readable } from "node:stream";
|
|
2
|
+
import util from "node:util";
|
|
4
3
|
export class BasedDataStream extends Duplex {
|
|
5
4
|
size = 0;
|
|
5
|
+
paused = false;
|
|
6
6
|
receivedBytes = 0;
|
|
7
7
|
progessTimer;
|
|
8
8
|
constructor(size) {
|
|
9
9
|
super();
|
|
10
10
|
this.size = size;
|
|
11
|
-
this.
|
|
11
|
+
this.on("pause", () => {
|
|
12
|
+
this.paused = true;
|
|
13
|
+
});
|
|
14
|
+
this.on("resume", () => {
|
|
15
|
+
this.paused = false;
|
|
16
|
+
});
|
|
17
|
+
this.emit("progress", 0);
|
|
12
18
|
}
|
|
13
19
|
_read() { }
|
|
14
20
|
_write(chunk, encoding, callback) {
|
|
@@ -17,7 +23,7 @@ export class BasedDataStream extends Duplex {
|
|
|
17
23
|
if (!this.progessTimer) {
|
|
18
24
|
this.progessTimer = setTimeout(() => {
|
|
19
25
|
const progress = this.receivedBytes / this.size;
|
|
20
|
-
this.emit(
|
|
26
|
+
this.emit("progress", progress);
|
|
21
27
|
this.progessTimer = null;
|
|
22
28
|
}, 200);
|
|
23
29
|
}
|
|
@@ -34,14 +40,14 @@ export class BasedDataStream extends Duplex {
|
|
|
34
40
|
clearTimeout(this.progessTimer);
|
|
35
41
|
this.progessTimer = null;
|
|
36
42
|
}
|
|
37
|
-
this.emit(
|
|
43
|
+
this.emit("progress", 1);
|
|
38
44
|
this.push(null);
|
|
39
45
|
}
|
|
40
46
|
[util.inspect.custom]() {
|
|
41
47
|
if (this.size) {
|
|
42
48
|
const rb = this.receivedBytes < 1000
|
|
43
|
-
? Math.round(this.receivedBytes / 1024) +
|
|
44
|
-
: Math.round(this.receivedBytes / 1024 / 1024) +
|
|
49
|
+
? Math.round(this.receivedBytes / 1024) + "kb"
|
|
50
|
+
: Math.round(this.receivedBytes / 1024 / 1024) + "mb";
|
|
45
51
|
return `[BasedStream ${~~((this.receivedBytes / this.size) *
|
|
46
52
|
100)}% ${rb}]`;
|
|
47
53
|
}
|
package/dist/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/functions",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-alpha",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"files":[
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "npx tsc && cp src/uws.d.ts dist/uws.d.ts && cp ./dist/client.d.ts ./dist/client_original.d.ts",
|
|
9
12
|
"watch": "npx tsc --watch",
|
|
@@ -11,12 +14,13 @@
|
|
|
11
14
|
},
|
|
12
15
|
"sideEffects": false,
|
|
13
16
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
17
|
+
"@saulx/utils": "^5.0.0",
|
|
18
|
+
"esbuild": "^0.24.2",
|
|
19
|
+
"utility-types": "^3.10.0"
|
|
16
20
|
},
|
|
17
21
|
"devDependencies": {
|
|
22
|
+
"rimraf": "^3.0.2",
|
|
18
23
|
"ts-node": "10.9.1",
|
|
19
|
-
"typescript": "^4.3.5"
|
|
20
|
-
"rimraf": "^3.0.2"
|
|
24
|
+
"typescript": "^4.3.5"
|
|
21
25
|
}
|
|
22
26
|
}
|
package/src/auth.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BasedFunctionClient } from './client.js'
|
|
2
|
-
import { HttpRequest } from './uws.js'
|
|
3
|
-
import { Context, WebSocketSession, HttpSession } from './context.js'
|
|
4
|
-
|
|
5
|
-
export type AuthState = {
|
|
6
|
-
token?: string
|
|
7
|
-
userId?: string
|
|
8
|
-
refreshToken?: string
|
|
9
|
-
error?: string
|
|
10
|
-
persistent?: boolean
|
|
11
|
-
type?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type Authorize = (
|
|
15
|
-
based: BasedFunctionClient,
|
|
16
|
-
context: Context<HttpSession | WebSocketSession>,
|
|
17
|
-
name: string, // name as generic dope
|
|
18
|
-
payload?: any
|
|
19
|
-
) => Promise<boolean>
|
|
20
|
-
|
|
21
|
-
// True - its the same all good
|
|
22
|
-
// AuthState - new auth state send it
|
|
23
|
-
// if error send error state (and reject)
|
|
24
|
-
export type VerifyAuthState = (
|
|
25
|
-
based: BasedFunctionClient,
|
|
26
|
-
context: Context<HttpSession | WebSocketSession>,
|
|
27
|
-
authState: AuthState
|
|
28
|
-
) => Promise<true | AuthState>
|
|
29
|
-
|
|
30
|
-
export type AuthorizeConnection = (
|
|
31
|
-
based: BasedFunctionClient,
|
|
32
|
-
req: HttpRequest,
|
|
33
|
-
ip: string
|
|
34
|
-
) => Promise<boolean>
|
package/src/channel.ts
DELETED
package/src/client.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AuthState } from './auth.js'
|
|
2
|
-
import { BasedChannel } from './channel.js'
|
|
3
|
-
import { Context } from './context.js'
|
|
4
|
-
import { BasedQuery } from './query.js'
|
|
5
|
-
import { StreamFunctionOpts } from './stream.js'
|
|
6
|
-
import { Geo } from './geo.js'
|
|
7
|
-
|
|
8
|
-
export abstract class BasedFunctionClient {
|
|
9
|
-
server: any
|
|
10
|
-
|
|
11
|
-
db: any
|
|
12
|
-
|
|
13
|
-
abstract call(name: string, payload?: any, ctx?: Context): Promise<any>
|
|
14
|
-
|
|
15
|
-
abstract query(name: string, payload?: any): BasedQuery
|
|
16
|
-
|
|
17
|
-
abstract channel(name: string, payload?: any): BasedChannel
|
|
18
|
-
|
|
19
|
-
abstract stream(
|
|
20
|
-
name: string,
|
|
21
|
-
payload: StreamFunctionOpts,
|
|
22
|
-
ctx?: Context
|
|
23
|
-
): Promise<any>
|
|
24
|
-
|
|
25
|
-
abstract sendAuthState(ctx: Context, authState: AuthState): void
|
|
26
|
-
|
|
27
|
-
abstract geo(ctx: Context): Promise<Geo>
|
|
28
|
-
|
|
29
|
-
abstract renewAuthState(
|
|
30
|
-
ctx: Context,
|
|
31
|
-
authState?: AuthState
|
|
32
|
-
): Promise<AuthState>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type QueryMap = { [key: string]: { payload: any; result: any } }
|
package/src/context.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { parseQuery } from '@saulx/utils'
|
|
2
|
-
import { AuthState } from './auth.js'
|
|
3
|
-
import { WebSocket, HttpRequest, HttpResponse } from './uws.js'
|
|
4
|
-
import { BasedFunctionClient } from './client.js'
|
|
5
|
-
|
|
6
|
-
export type WebSocketSession = {
|
|
7
|
-
// State can be used for anything - for us the based class instance
|
|
8
|
-
state?: any
|
|
9
|
-
query: string
|
|
10
|
-
ua: string
|
|
11
|
-
ip: string
|
|
12
|
-
id: number // client-id
|
|
13
|
-
method: string
|
|
14
|
-
authState: AuthState
|
|
15
|
-
origin: string
|
|
16
|
-
obs: Set<number>
|
|
17
|
-
unauthorizedObs?: Set<{
|
|
18
|
-
id: number
|
|
19
|
-
checksum: number
|
|
20
|
-
name: string
|
|
21
|
-
payload: any
|
|
22
|
-
}>
|
|
23
|
-
headers: { [key: string]: string }
|
|
24
|
-
unauthorizedChannels?: Set<{
|
|
25
|
-
id: number
|
|
26
|
-
name: string
|
|
27
|
-
payload: any
|
|
28
|
-
}>
|
|
29
|
-
// Optimization so we dont need to keep track of websockets outside of uws
|
|
30
|
-
c?: Context<WebSocketSession>
|
|
31
|
-
ws?: BasedWebSocket
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type BasedWebSocket = WebSocket<WebSocketSession>
|
|
35
|
-
|
|
36
|
-
export type HttpSession = {
|
|
37
|
-
// State can be used for anything - for us the based class instance
|
|
38
|
-
state?: any
|
|
39
|
-
res: HttpResponse
|
|
40
|
-
url: string
|
|
41
|
-
origin: string
|
|
42
|
-
req: HttpRequest
|
|
43
|
-
query?: string
|
|
44
|
-
parsedQuery?: ReturnType<typeof parseQuery>
|
|
45
|
-
ua: string
|
|
46
|
-
ip: string
|
|
47
|
-
id: number // client-id
|
|
48
|
-
authState: AuthState
|
|
49
|
-
method: string
|
|
50
|
-
rawBody?: string
|
|
51
|
-
headers: {
|
|
52
|
-
'content-length'?: number
|
|
53
|
-
'content-type'?: string
|
|
54
|
-
'content-encoding'?: string
|
|
55
|
-
encoding?: string
|
|
56
|
-
} & { [key: string]: string }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type InternalSessionObservable = {
|
|
60
|
-
id: number
|
|
61
|
-
name: string
|
|
62
|
-
headers: { [key: string]: string }
|
|
63
|
-
type: 'query'
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export type InternalSessionChannel = {
|
|
67
|
-
id: number
|
|
68
|
-
name: string
|
|
69
|
-
headers: { [key: string]: string }
|
|
70
|
-
type: 'channel'
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type InternalSessionClient = {
|
|
74
|
-
client: BasedFunctionClient
|
|
75
|
-
headers: { [key: string]: string }
|
|
76
|
-
type: 'client'
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Internal session for internal functions
|
|
80
|
-
export type InternalSession =
|
|
81
|
-
| InternalSessionClient
|
|
82
|
-
| InternalSessionObservable
|
|
83
|
-
| InternalSessionChannel
|
|
84
|
-
|
|
85
|
-
// used for minimal security errors (e.g. rate limit)
|
|
86
|
-
export type MinimalExternalSession = {
|
|
87
|
-
ua: string
|
|
88
|
-
ip: string
|
|
89
|
-
headers: { [key: string]: string }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export type Session = (
|
|
93
|
-
| WebSocketSession
|
|
94
|
-
| HttpSession
|
|
95
|
-
| InternalSession
|
|
96
|
-
| MinimalExternalSession
|
|
97
|
-
) & {
|
|
98
|
-
origin?: string
|
|
99
|
-
|
|
100
|
-
/** Only available in Ws and Http contexts */
|
|
101
|
-
authState?: AuthState
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type Context<S extends Session = Session> = {
|
|
105
|
-
session?: S
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export const isHttpContext = (
|
|
109
|
-
ctx: Context<Session>
|
|
110
|
-
): ctx is Context<HttpSession> => {
|
|
111
|
-
if ('res' in ctx?.session) {
|
|
112
|
-
return true
|
|
113
|
-
}
|
|
114
|
-
return false
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const isWsContext = (
|
|
118
|
-
ctx: Context<Session>
|
|
119
|
-
): ctx is Context<WebSocketSession> => {
|
|
120
|
-
if (ctx.session && isWsSession(ctx.session)) {
|
|
121
|
-
return true
|
|
122
|
-
}
|
|
123
|
-
return false
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export const isClientContext = (
|
|
127
|
-
ctx: Context<Session>
|
|
128
|
-
): ctx is Context<WebSocketSession | HttpSession> => {
|
|
129
|
-
if (ctx.session && (isWsSession(ctx.session) || isHttpSession(ctx.session))) {
|
|
130
|
-
return true
|
|
131
|
-
}
|
|
132
|
-
return false
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const isHttpSession = (
|
|
136
|
-
session: Session | undefined
|
|
137
|
-
): session is HttpSession => {
|
|
138
|
-
if (session && 'res' in session) {
|
|
139
|
-
return true
|
|
140
|
-
}
|
|
141
|
-
return false
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export const isWsSession = (
|
|
145
|
-
session: Session | undefined
|
|
146
|
-
): session is WebSocketSession => {
|
|
147
|
-
if (session && 'send' in session) {
|
|
148
|
-
return true
|
|
149
|
-
}
|
|
150
|
-
return false
|
|
151
|
-
}
|