@based/functions 1.0.0 → 1.0.2
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/.turbo/turbo-build.log +1 -1
- package/dist/context.d.ts +2 -1
- package/dist/context.js +8 -1
- package/dist/context.js.map +1 -1
- package/dist/functions.d.ts +8 -4
- package/package.json +1 -1
- package/src/context.ts +10 -1
- package/src/functions.ts +23 -9
- package/dist/errors.d.ts +0 -0
- package/dist/errors.js +0 -2
- package/dist/errors.js.map +0 -1
- package/dist/network.d.ts +0 -0
- package/dist/network.js +0 -3
- package/dist/network.js.map +0 -1
- package/dist/types.d.ts +0 -0
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare type HttpSession = {
|
|
|
43
43
|
export declare type InternalSessionObservable = {
|
|
44
44
|
id: number;
|
|
45
45
|
name: string;
|
|
46
|
-
type: '
|
|
46
|
+
type: 'query';
|
|
47
47
|
};
|
|
48
48
|
export declare type InternalSessionClient = {
|
|
49
49
|
client: BasedFunctionClient;
|
|
@@ -60,4 +60,5 @@ export declare type Context<S extends Session = Session> = {
|
|
|
60
60
|
};
|
|
61
61
|
export declare const isHttpContext: (ctx: Context<Session>) => ctx is Context<HttpSession>;
|
|
62
62
|
export declare const isWsContext: (ctx: Context<Session>) => ctx is Context<WebSocketSession>;
|
|
63
|
+
export declare const isClientContext: (ctx: Context<Session>) => ctx is Context<WebSocketSession>;
|
|
63
64
|
export declare const isWsSession: (session: Session) => session is WebSocketSession;
|
package/dist/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWsSession = exports.isWsContext = exports.isHttpContext = void 0;
|
|
3
|
+
exports.isWsSession = exports.isClientContext = exports.isWsContext = exports.isHttpContext = void 0;
|
|
4
4
|
const isHttpContext = (ctx) => {
|
|
5
5
|
if ('res' in ctx?.session) {
|
|
6
6
|
return true;
|
|
@@ -15,6 +15,13 @@ const isWsContext = (ctx) => {
|
|
|
15
15
|
return false;
|
|
16
16
|
};
|
|
17
17
|
exports.isWsContext = isWsContext;
|
|
18
|
+
const isClientContext = (ctx) => {
|
|
19
|
+
if (ctx.session && 'authState' in ctx.session) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
exports.isClientContext = isClientContext;
|
|
18
25
|
const isWsSession = (session) => {
|
|
19
26
|
if (!('res' in session) && 'ip' in session && 'id' in session) {
|
|
20
27
|
return true;
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AA4EO,MAAM,aAAa,GAAG,CAC3B,GAAqB,EACQ,EAAE;IAC/B,IAAI,KAAK,IAAI,GAAG,EAAE,OAAO,EAAE;QACzB,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,aAAa,iBAOzB;AAEM,MAAM,WAAW,GAAG,CACzB,GAAqB,EACa,EAAE;IACpC,IAAI,GAAG,CAAC,OAAO,IAAI,IAAA,mBAAW,EAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAC3C,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,WAAW,eAOvB;AAEM,MAAM,WAAW,GAAG,CAAC,OAAgB,EAA+B,EAAE;IAC3E,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,EAAE;QAC7D,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AALY,QAAA,WAAW,eAKvB"}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AA4EO,MAAM,aAAa,GAAG,CAC3B,GAAqB,EACQ,EAAE;IAC/B,IAAI,KAAK,IAAI,GAAG,EAAE,OAAO,EAAE;QACzB,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,aAAa,iBAOzB;AAEM,MAAM,WAAW,GAAG,CACzB,GAAqB,EACa,EAAE;IACpC,IAAI,GAAG,CAAC,OAAO,IAAI,IAAA,mBAAW,EAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAC3C,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,WAAW,eAOvB;AAEM,MAAM,eAAe,GAAG,CAC7B,GAAqB,EACa,EAAE;IACpC,IAAI,GAAG,CAAC,OAAO,IAAI,WAAW,IAAI,GAAG,CAAC,OAAO,EAAE;QAC7C,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,eAAe,mBAO3B;AAEM,MAAM,WAAW,GAAG,CAAC,OAAgB,EAA+B,EAAE;IAC3E,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,EAAE;QAC7D,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AALY,QAAA,WAAW,eAKvB"}
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Context, HttpSession } from './context';
|
|
3
3
|
import { BasedFunctionClient } from './client';
|
|
4
|
-
import {
|
|
4
|
+
import { Duplex } from 'stream';
|
|
5
5
|
export declare type ObservableUpdateFunction<K = any> = {
|
|
6
6
|
(data: K, checksum?: number, diff?: any, fromChecksum?: number, isDeflate?: boolean, rawData?: K, err?: any): void;
|
|
7
7
|
__internalObs__?: true;
|
|
8
8
|
};
|
|
9
9
|
export declare type ObserveErrorListener = (err: any) => void;
|
|
10
|
-
export declare type
|
|
10
|
+
export declare type HttpHeaders = {
|
|
11
|
+
[header: string]: number | string | (string | number)[];
|
|
12
|
+
};
|
|
13
|
+
export declare type SendHttpResponse = (responseData: any, headers?: HttpHeaders, status?: string | number) => void;
|
|
14
|
+
export declare type HttpResponse<P = any, K = any> = (based: BasedFunctionClient, payload: P, responseData: K, send: SendHttpResponse, ctx: Context<HttpSession>) => Promise<void>;
|
|
11
15
|
export declare type BasedFunction<P = any, K = any> = (based: BasedFunctionClient, payload: P, ctx: Context) => Promise<K>;
|
|
12
16
|
export declare type StreamPayload<P = any> = {
|
|
13
17
|
payload?: P;
|
|
14
18
|
mimeType: string;
|
|
15
19
|
size: number;
|
|
16
|
-
stream:
|
|
20
|
+
stream: Duplex & {
|
|
17
21
|
size: number;
|
|
18
22
|
receivedBytes: number;
|
|
19
23
|
};
|
|
@@ -21,4 +25,4 @@ export declare type StreamPayload<P = any> = {
|
|
|
21
25
|
extension?: string;
|
|
22
26
|
};
|
|
23
27
|
export declare type BasedStreamFunction<P = any, K = any> = BasedFunction<StreamPayload<P>, K>;
|
|
24
|
-
export declare type BasedQueryFunction<P = any, K = any> = ((based: BasedFunctionClient, payload: P, update: ObservableUpdateFunction<K
|
|
28
|
+
export declare 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);
|
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -47,7 +47,7 @@ export type HttpSession = {
|
|
|
47
47
|
export type InternalSessionObservable = {
|
|
48
48
|
id: number
|
|
49
49
|
name: string
|
|
50
|
-
type: '
|
|
50
|
+
type: 'query'
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export type InternalSessionClient = {
|
|
@@ -92,6 +92,15 @@ export const isWsContext = (
|
|
|
92
92
|
return false
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
export const isClientContext = (
|
|
96
|
+
ctx: Context<Session>
|
|
97
|
+
): ctx is Context<WebSocketSession> => {
|
|
98
|
+
if (ctx.session && 'authState' in ctx.session) {
|
|
99
|
+
return true
|
|
100
|
+
}
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
export const isWsSession = (session: Session): session is WebSocketSession => {
|
|
96
105
|
if (!('res' in session) && 'ip' in session && 'id' in session) {
|
|
97
106
|
return true
|
package/src/functions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, HttpSession } from './context'
|
|
2
2
|
import { BasedFunctionClient } from './client'
|
|
3
|
-
import {
|
|
3
|
+
import { Duplex } from 'stream'
|
|
4
4
|
|
|
5
5
|
export type ObservableUpdateFunction<K = any> = {
|
|
6
6
|
(
|
|
@@ -19,11 +19,23 @@ export type ObservableUpdateFunction<K = any> = {
|
|
|
19
19
|
// TODO: use error package
|
|
20
20
|
export type ObserveErrorListener = (err: any) => void
|
|
21
21
|
|
|
22
|
-
export type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
export type HttpHeaders = {
|
|
23
|
+
[header: string]: number | string | (string | number)[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SendHttpResponse = (
|
|
27
|
+
responseData: any,
|
|
28
|
+
headers?: HttpHeaders,
|
|
29
|
+
status?: string | number
|
|
30
|
+
) => void
|
|
31
|
+
|
|
32
|
+
export type HttpResponse<P = any, K = any> = (
|
|
33
|
+
based: BasedFunctionClient,
|
|
34
|
+
payload: P,
|
|
35
|
+
responseData: K,
|
|
36
|
+
send: SendHttpResponse,
|
|
37
|
+
ctx: Context<HttpSession>
|
|
38
|
+
) => Promise<void>
|
|
27
39
|
|
|
28
40
|
export type BasedFunction<P = any, K = any> = (
|
|
29
41
|
based: BasedFunctionClient,
|
|
@@ -35,7 +47,7 @@ export type StreamPayload<P = any> = {
|
|
|
35
47
|
payload?: P
|
|
36
48
|
mimeType: string
|
|
37
49
|
size: number
|
|
38
|
-
stream:
|
|
50
|
+
stream: Duplex & {
|
|
39
51
|
size: number
|
|
40
52
|
receivedBytes: number
|
|
41
53
|
}
|
|
@@ -52,10 +64,12 @@ export type BasedQueryFunction<P = any, K = any> =
|
|
|
52
64
|
| ((
|
|
53
65
|
based: BasedFunctionClient,
|
|
54
66
|
payload: P,
|
|
55
|
-
update: ObservableUpdateFunction<K
|
|
67
|
+
update: ObservableUpdateFunction<K>,
|
|
68
|
+
error?: ObserveErrorListener
|
|
56
69
|
) => Promise<() => void>)
|
|
57
70
|
| ((
|
|
58
71
|
based: BasedFunctionClient,
|
|
59
72
|
payload: P,
|
|
60
|
-
update: ObservableUpdateFunction<K
|
|
73
|
+
update: ObservableUpdateFunction<K>,
|
|
74
|
+
error?: ObserveErrorListener
|
|
61
75
|
) => () => void)
|
package/dist/errors.d.ts
DELETED
|
File without changes
|
package/dist/errors.js
DELETED
package/dist/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD"}
|
package/dist/network.d.ts
DELETED
|
File without changes
|
package/dist/network.js
DELETED
package/dist/network.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
DELETED
|
File without changes
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,iBAAiB"}
|