@based/functions 2.1.3 → 2.2.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/dist/context.d.ts +3 -3
- package/dist/context.js +2 -2
- package/dist/context.js.map +1 -1
- package/dist/functions.d.ts +20 -4
- package/dist/functions.js.map +1 -1
- package/dist/uws.js +3 -0
- package/dist/uws.js.map +1 -0
- package/package.json +1 -1
- package/src/context.ts +8 -4
- package/src/functions.ts +35 -2
package/dist/context.d.ts
CHANGED
|
@@ -93,6 +93,6 @@ export type Context<S extends Session = Session> = {
|
|
|
93
93
|
};
|
|
94
94
|
export declare const isHttpContext: (ctx: Context<Session>) => ctx is Context<HttpSession>;
|
|
95
95
|
export declare const isWsContext: (ctx: Context<Session>) => ctx is Context<WebSocketSession>;
|
|
96
|
-
export declare const isClientContext: (ctx: Context<Session>) => ctx is Context<
|
|
97
|
-
export declare const isHttpSession: (session: Session) => session is HttpSession;
|
|
98
|
-
export declare const isWsSession: (session: Session) => session is WebSocketSession;
|
|
96
|
+
export declare const isClientContext: (ctx: Context<Session>) => ctx is Context<HttpSession | WebSocketSession>;
|
|
97
|
+
export declare const isHttpSession: (session: Session | undefined) => session is HttpSession;
|
|
98
|
+
export declare const isWsSession: (session: Session | undefined) => session is WebSocketSession;
|
package/dist/context.js
CHANGED
|
@@ -23,14 +23,14 @@ const isClientContext = (ctx) => {
|
|
|
23
23
|
};
|
|
24
24
|
exports.isClientContext = isClientContext;
|
|
25
25
|
const isHttpSession = (session) => {
|
|
26
|
-
if ('res' in session) {
|
|
26
|
+
if (session && 'res' in session) {
|
|
27
27
|
return true;
|
|
28
28
|
}
|
|
29
29
|
return false;
|
|
30
30
|
};
|
|
31
31
|
exports.isHttpSession = isHttpSession;
|
|
32
32
|
const isWsSession = (session) => {
|
|
33
|
-
if ('send' in session) {
|
|
33
|
+
if (session && 'send' in session) {
|
|
34
34
|
return true;
|
|
35
35
|
}
|
|
36
36
|
return false;
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AA0GO,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,EAC2B,EAAE;IAClD,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,IAAA,mBAAW,EAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAA,qBAAa,EAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE;QAC3E,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,eAAe,mBAO3B;AAEM,MAAM,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AA0GO,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,EAC2B,EAAE;IAClD,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,IAAA,mBAAW,EAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAA,qBAAa,EAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE;QAC3E,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,eAAe,mBAO3B;AAEM,MAAM,aAAa,GAAG,CAC3B,OAA4B,EACJ,EAAE;IAC1B,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE;QAC/B,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,aAAa,iBAOzB;AAEM,MAAM,WAAW,GAAG,CACzB,OAA4B,EACC,EAAE;IAC/B,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,EAAE;QAChC,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,WAAW,eAOvB"}
|
package/dist/functions.d.ts
CHANGED
|
@@ -11,6 +11,17 @@ export type HttpHeaders = {
|
|
|
11
11
|
export type SendHttpResponse = (responseData: any, headers?: HttpHeaders, status?: string | number) => void;
|
|
12
12
|
export type HttpResponse<P = any, K = any> = (based: BasedFunctionClient, payload: P, responseData: K, send: SendHttpResponse, ctx: Context<HttpSession>) => Promise<void>;
|
|
13
13
|
export type BasedFunction<P = any, K = any> = (based: BasedFunctionClient, payload: P, ctx: Context) => Promise<K>;
|
|
14
|
+
export type BasedAppFunction = (based: BasedFunctionClient, assets: {
|
|
15
|
+
css: {
|
|
16
|
+
text: Promise<string>;
|
|
17
|
+
url: string;
|
|
18
|
+
};
|
|
19
|
+
js: {
|
|
20
|
+
text: Promise<string>;
|
|
21
|
+
url: string;
|
|
22
|
+
};
|
|
23
|
+
favicon: string;
|
|
24
|
+
}, ctx: Context) => Promise<string>;
|
|
14
25
|
export type StreamPayload<P = any> = {
|
|
15
26
|
payload?: P;
|
|
16
27
|
mimeType: string;
|
|
@@ -81,7 +92,7 @@ type FunctionConfigShared = {
|
|
|
81
92
|
timeoutCounter?: number;
|
|
82
93
|
};
|
|
83
94
|
type FunctionConfigSharedComplete = Required<FunctionConfigShared, 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'>;
|
|
84
|
-
export type BasedFunctionTypes = 'channel' | 'query' | 'function' | 'stream';
|
|
95
|
+
export type BasedFunctionTypes = 'channel' | 'query' | 'function' | 'stream' | 'app';
|
|
85
96
|
type BasedChannelFunctionConfig = {
|
|
86
97
|
/** Function type `channel, function, query, stream, authorize` */
|
|
87
98
|
type: 'channel';
|
|
@@ -137,12 +148,17 @@ type BasedStreamFunctionConfig = {
|
|
|
137
148
|
type: 'stream';
|
|
138
149
|
fn: BasedStreamFunction;
|
|
139
150
|
};
|
|
140
|
-
|
|
141
|
-
|
|
151
|
+
type BasedAppFunctionConfig = {
|
|
152
|
+
type: 'app';
|
|
153
|
+
main: string;
|
|
154
|
+
path?: string;
|
|
155
|
+
};
|
|
156
|
+
export type BasedFunctionConfig<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig & FunctionConfigShared : T extends 'function' ? BasedCallFunctionConfig & FunctionConfigShared : T extends 'query' ? BasedQueryFunctionConfig & FunctionConfigShared : T extends 'stream' ? BasedStreamFunctionConfig & FunctionConfigShared : T extends 'app' ? BasedAppFunctionConfig & FunctionConfigShared : (BasedChannelFunctionConfig & FunctionConfigShared) | (BasedCallFunctionConfig & FunctionConfigShared) | (BasedQueryFunctionConfig & FunctionConfigShared) | (BasedStreamFunctionConfig & FunctionConfigShared) | (BasedAppFunctionConfig & FunctionConfigShared);
|
|
157
|
+
export type BasedFunctionConfigComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig & FunctionConfigSharedComplete : T extends 'function' ? BasedCallFunctionConfig & FunctionConfigSharedComplete : T extends 'query' ? BasedQueryFunctionConfig & FunctionConfigSharedComplete : T extends 'stream' ? BasedStreamFunctionConfig & FunctionConfigSharedComplete : T extends 'app' ? BasedAppFunctionConfig & FunctionConfigSharedComplete : (BasedChannelFunctionConfig & FunctionConfigSharedComplete) | (BasedCallFunctionConfig & FunctionConfigSharedComplete) | (BasedQueryFunctionConfig & FunctionConfigSharedComplete) | (BasedStreamFunctionConfig & FunctionConfigSharedComplete) | (BasedAppFunctionConfig & FunctionConfigSharedComplete);
|
|
142
158
|
export type BasedAuthorizeFunctionConfig = {
|
|
143
159
|
/** Function type `authorize` */
|
|
144
160
|
type: 'authorize';
|
|
145
|
-
|
|
161
|
+
fn?: Authorize;
|
|
146
162
|
};
|
|
147
163
|
export type BasedRoute<T extends BasedFunctionTypes = BasedFunctionTypes, R extends keyof BasedFunctionConfig = 'type' | 'name'> = Required<Partial<BasedFunctionConfig<T>>, R>;
|
|
148
164
|
export type BasedRouteComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = Required<Partial<BasedFunctionConfig<T>>, 'type' | 'name' | 'maxPayloadSize' | 'rateLimitTokens'>;
|
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":";;;AA4SA,SAAgB,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;AAVD,oCAUC;AAED,SAAgB,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;AAVD,0CAUC;AAED,SAAgB,qBAAqB,CACnC,IAAO,EACP,MAAW;IAEX,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AACnC,CAAC;AALD,sDAKC;AAED,SAAgB,wBAAwB,CACtC,MAAW;IAEX,OAAO,eAAe,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC;AAJD,4DAIC"}
|
package/dist/uws.js
ADDED
package/dist/uws.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uws.js","sourceRoot":"","sources":["../src/uws.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -131,15 +131,19 @@ export const isClientContext = (
|
|
|
131
131
|
return false
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
export const isHttpSession = (
|
|
135
|
-
|
|
134
|
+
export const isHttpSession = (
|
|
135
|
+
session: Session | undefined
|
|
136
|
+
): session is HttpSession => {
|
|
137
|
+
if (session && 'res' in session) {
|
|
136
138
|
return true
|
|
137
139
|
}
|
|
138
140
|
return false
|
|
139
141
|
}
|
|
140
142
|
|
|
141
|
-
export const isWsSession = (
|
|
142
|
-
|
|
143
|
+
export const isWsSession = (
|
|
144
|
+
session: Session | undefined
|
|
145
|
+
): session is WebSocketSession => {
|
|
146
|
+
if (session && 'send' in session) {
|
|
143
147
|
return true
|
|
144
148
|
}
|
|
145
149
|
return false
|
package/src/functions.ts
CHANGED
|
@@ -40,6 +40,22 @@ export type BasedFunction<P = any, K = any> = (
|
|
|
40
40
|
ctx: Context
|
|
41
41
|
) => Promise<K>
|
|
42
42
|
|
|
43
|
+
export type BasedAppFunction = (
|
|
44
|
+
based: BasedFunctionClient,
|
|
45
|
+
assets: {
|
|
46
|
+
css: {
|
|
47
|
+
text: Promise<string>
|
|
48
|
+
url: string
|
|
49
|
+
}
|
|
50
|
+
js: {
|
|
51
|
+
text: Promise<string>
|
|
52
|
+
url: string
|
|
53
|
+
}
|
|
54
|
+
favicon: string
|
|
55
|
+
},
|
|
56
|
+
ctx: Context
|
|
57
|
+
) => Promise<string>
|
|
58
|
+
|
|
43
59
|
export type StreamPayload<P = any> = {
|
|
44
60
|
payload?: P
|
|
45
61
|
mimeType: string
|
|
@@ -154,7 +170,12 @@ type FunctionConfigSharedComplete = Required<
|
|
|
154
170
|
'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'
|
|
155
171
|
>
|
|
156
172
|
|
|
157
|
-
export type BasedFunctionTypes =
|
|
173
|
+
export type BasedFunctionTypes =
|
|
174
|
+
| 'channel'
|
|
175
|
+
| 'query'
|
|
176
|
+
| 'function'
|
|
177
|
+
| 'stream'
|
|
178
|
+
| 'app'
|
|
158
179
|
|
|
159
180
|
type BasedChannelFunctionConfig = {
|
|
160
181
|
/** Function type `channel, function, query, stream, authorize` */
|
|
@@ -215,6 +236,12 @@ type BasedStreamFunctionConfig = {
|
|
|
215
236
|
fn: BasedStreamFunction
|
|
216
237
|
}
|
|
217
238
|
|
|
239
|
+
type BasedAppFunctionConfig = {
|
|
240
|
+
type: 'app'
|
|
241
|
+
main: string
|
|
242
|
+
path?: string
|
|
243
|
+
}
|
|
244
|
+
|
|
218
245
|
export type BasedFunctionConfig<
|
|
219
246
|
T extends BasedFunctionTypes = BasedFunctionTypes
|
|
220
247
|
> = T extends 'channel'
|
|
@@ -225,11 +252,14 @@ export type BasedFunctionConfig<
|
|
|
225
252
|
? BasedQueryFunctionConfig & FunctionConfigShared
|
|
226
253
|
: T extends 'stream'
|
|
227
254
|
? BasedStreamFunctionConfig & FunctionConfigShared
|
|
255
|
+
: T extends 'app'
|
|
256
|
+
? BasedAppFunctionConfig & FunctionConfigShared
|
|
228
257
|
:
|
|
229
258
|
| (BasedChannelFunctionConfig & FunctionConfigShared)
|
|
230
259
|
| (BasedCallFunctionConfig & FunctionConfigShared)
|
|
231
260
|
| (BasedQueryFunctionConfig & FunctionConfigShared)
|
|
232
261
|
| (BasedStreamFunctionConfig & FunctionConfigShared)
|
|
262
|
+
| (BasedAppFunctionConfig & FunctionConfigShared)
|
|
233
263
|
|
|
234
264
|
export type BasedFunctionConfigComplete<
|
|
235
265
|
T extends BasedFunctionTypes = BasedFunctionTypes
|
|
@@ -241,16 +271,19 @@ export type BasedFunctionConfigComplete<
|
|
|
241
271
|
? BasedQueryFunctionConfig & FunctionConfigSharedComplete
|
|
242
272
|
: T extends 'stream'
|
|
243
273
|
? BasedStreamFunctionConfig & FunctionConfigSharedComplete
|
|
274
|
+
: T extends 'app'
|
|
275
|
+
? BasedAppFunctionConfig & FunctionConfigSharedComplete
|
|
244
276
|
:
|
|
245
277
|
| (BasedChannelFunctionConfig & FunctionConfigSharedComplete)
|
|
246
278
|
| (BasedCallFunctionConfig & FunctionConfigSharedComplete)
|
|
247
279
|
| (BasedQueryFunctionConfig & FunctionConfigSharedComplete)
|
|
248
280
|
| (BasedStreamFunctionConfig & FunctionConfigSharedComplete)
|
|
281
|
+
| (BasedAppFunctionConfig & FunctionConfigSharedComplete)
|
|
249
282
|
|
|
250
283
|
export type BasedAuthorizeFunctionConfig = {
|
|
251
284
|
/** Function type `authorize` */
|
|
252
285
|
type: 'authorize'
|
|
253
|
-
|
|
286
|
+
fn?: Authorize
|
|
254
287
|
}
|
|
255
288
|
|
|
256
289
|
export type BasedRoute<
|