@based/functions 2.1.4 → 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 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<WebSocketSession | HttpSession>;
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;
@@ -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
- 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 : (BasedChannelFunctionConfig & FunctionConfigShared) | (BasedCallFunctionConfig & FunctionConfigShared) | (BasedQueryFunctionConfig & FunctionConfigShared) | (BasedStreamFunctionConfig & FunctionConfigShared);
141
- 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 : (BasedChannelFunctionConfig & FunctionConfigSharedComplete) | (BasedCallFunctionConfig & FunctionConfigSharedComplete) | (BasedQueryFunctionConfig & FunctionConfigSharedComplete) | (BasedStreamFunctionConfig & FunctionConfigSharedComplete);
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
- function: Authorize;
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'>;
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;AA2QA,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,K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B,wBAAwB,CACtC,MAAW;IAEX,OAAO,eAAe,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC;AAJD,4DAIC"}
package/dist/uws.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=uws.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uws.js","sourceRoot":"","sources":["../src/uws.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/functions",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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 = 'channel' | 'query' | 'function' | 'stream'
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
- function: Authorize
286
+ fn?: Authorize
254
287
  }
255
288
 
256
289
  export type BasedRoute<