@based/functions 2.1.4 → 2.2.1
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 +1 -1
- package/dist/functions.d.ts +21 -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/functions.ts +36 -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<
|
|
96
|
+
export declare const isClientContext: (ctx: Context<Session>) => ctx is Context<HttpSession | WebSocketSession>;
|
|
97
97
|
export declare const isHttpSession: (session: Session | undefined) => session is HttpSession;
|
|
98
98
|
export declare const isWsSession: (session: Session | undefined) => session is WebSocketSession;
|
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,18 @@ 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
|
+
favicon?: string;
|
|
156
|
+
};
|
|
157
|
+
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);
|
|
158
|
+
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
159
|
export type BasedAuthorizeFunctionConfig = {
|
|
143
160
|
/** Function type `authorize` */
|
|
144
161
|
type: 'authorize';
|
|
145
|
-
|
|
162
|
+
fn?: Authorize;
|
|
146
163
|
};
|
|
147
164
|
export type BasedRoute<T extends BasedFunctionTypes = BasedFunctionTypes, R extends keyof BasedFunctionConfig = 'type' | 'name'> = Required<Partial<BasedFunctionConfig<T>>, R>;
|
|
148
165
|
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":";;;AA6SA,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/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,13 @@ type BasedStreamFunctionConfig = {
|
|
|
215
236
|
fn: BasedStreamFunction
|
|
216
237
|
}
|
|
217
238
|
|
|
239
|
+
type BasedAppFunctionConfig = {
|
|
240
|
+
type: 'app'
|
|
241
|
+
main: string
|
|
242
|
+
path?: string
|
|
243
|
+
favicon?: string
|
|
244
|
+
}
|
|
245
|
+
|
|
218
246
|
export type BasedFunctionConfig<
|
|
219
247
|
T extends BasedFunctionTypes = BasedFunctionTypes
|
|
220
248
|
> = T extends 'channel'
|
|
@@ -225,11 +253,14 @@ export type BasedFunctionConfig<
|
|
|
225
253
|
? BasedQueryFunctionConfig & FunctionConfigShared
|
|
226
254
|
: T extends 'stream'
|
|
227
255
|
? BasedStreamFunctionConfig & FunctionConfigShared
|
|
256
|
+
: T extends 'app'
|
|
257
|
+
? BasedAppFunctionConfig & FunctionConfigShared
|
|
228
258
|
:
|
|
229
259
|
| (BasedChannelFunctionConfig & FunctionConfigShared)
|
|
230
260
|
| (BasedCallFunctionConfig & FunctionConfigShared)
|
|
231
261
|
| (BasedQueryFunctionConfig & FunctionConfigShared)
|
|
232
262
|
| (BasedStreamFunctionConfig & FunctionConfigShared)
|
|
263
|
+
| (BasedAppFunctionConfig & FunctionConfigShared)
|
|
233
264
|
|
|
234
265
|
export type BasedFunctionConfigComplete<
|
|
235
266
|
T extends BasedFunctionTypes = BasedFunctionTypes
|
|
@@ -241,16 +272,19 @@ export type BasedFunctionConfigComplete<
|
|
|
241
272
|
? BasedQueryFunctionConfig & FunctionConfigSharedComplete
|
|
242
273
|
: T extends 'stream'
|
|
243
274
|
? BasedStreamFunctionConfig & FunctionConfigSharedComplete
|
|
275
|
+
: T extends 'app'
|
|
276
|
+
? BasedAppFunctionConfig & FunctionConfigSharedComplete
|
|
244
277
|
:
|
|
245
278
|
| (BasedChannelFunctionConfig & FunctionConfigSharedComplete)
|
|
246
279
|
| (BasedCallFunctionConfig & FunctionConfigSharedComplete)
|
|
247
280
|
| (BasedQueryFunctionConfig & FunctionConfigSharedComplete)
|
|
248
281
|
| (BasedStreamFunctionConfig & FunctionConfigSharedComplete)
|
|
282
|
+
| (BasedAppFunctionConfig & FunctionConfigSharedComplete)
|
|
249
283
|
|
|
250
284
|
export type BasedAuthorizeFunctionConfig = {
|
|
251
285
|
/** Function type `authorize` */
|
|
252
286
|
type: 'authorize'
|
|
253
|
-
|
|
287
|
+
fn?: Authorize
|
|
254
288
|
}
|
|
255
289
|
|
|
256
290
|
export type BasedRoute<
|