@based/functions 2.0.0 → 2.0.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.
@@ -2,7 +2,7 @@ import { Context, HttpSession } from './context';
2
2
  import { BasedFunctionClient } from './client';
3
3
  import { BasedDataStream } from './stream';
4
4
  import { Authorize } from './auth';
5
- import { Required } from 'utility-types';
5
+ import type { Required } from 'utility-types';
6
6
  export type ObservableUpdateFunction<K = any> = (data: K, checksum?: number, err?: any, cache?: Uint8Array, diff?: any, fromChecksum?: number, isDeflate?: boolean) => void;
7
7
  export type ObserveErrorListener = (err: any) => void;
8
8
  export type HttpHeaders = {
@@ -80,8 +80,9 @@ type FunctionConfigShared = {
80
80
  /** Used inernaly to check if a function is ready to uninstall */
81
81
  timeoutCounter?: number;
82
82
  };
83
+ type FunctionConfigSharedComplete = Required<FunctionConfigShared, 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'>;
83
84
  export type BasedFunctionTypes = 'channel' | 'query' | 'function' | 'stream';
84
- export type BasedChannelFunctionConfig = {
85
+ type BasedChannelFunctionConfig = {
85
86
  /** Function type `channel, function, query, stream, authorize` */
86
87
  type: 'channel';
87
88
  /** Channel subscriber
@@ -112,34 +113,34 @@ export type BasedChannelFunctionConfig = {
112
113
  closeAfterIdleTime?: number;
113
114
  /** Only for Publisher */
114
115
  httpResponse?: HttpResponse;
115
- } & FunctionConfigShared;
116
- export type BasedCallFunctionConfig = {
116
+ };
117
+ type BasedCallFunctionConfig = {
117
118
  /** Function type `channel, function, query, stream` */
118
119
  type: 'function';
119
120
  fn: BasedFunction;
120
121
  httpResponse?: HttpResponse;
121
- } & FunctionConfigShared;
122
- export type BasedQueryFunctionConfig = {
122
+ };
123
+ type BasedQueryFunctionConfig = {
123
124
  /** Function type `channel, function, query, stream` */
124
125
  type: 'query';
125
126
  fn: BasedQueryFunction;
126
127
  httpResponse?: HttpResponse;
127
128
  /** How long should the query function remain active after all subscribers are gone, in ms */
128
129
  closeAfterIdleTime?: number;
129
- } & FunctionConfigShared;
130
- export type BasedStreamFunctionConfig = {
130
+ };
131
+ type BasedStreamFunctionConfig = {
131
132
  /** Function type `channel, function, query, stream` */
132
133
  type: 'stream';
133
134
  fn: BasedStreamFunction;
134
- } & FunctionConfigShared;
135
- export type BasedFunctionConfig<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig : T extends 'function' ? BasedCallFunctionConfig : T extends 'query' ? BasedQueryFunctionConfig : T extends 'stream' ? BasedStreamFunctionConfig : BasedChannelFunctionConfig | BasedCallFunctionConfig | BasedQueryFunctionConfig | BasedStreamFunctionConfig;
135
+ };
136
+ 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);
137
+ 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);
136
138
  export type BasedAuthorizeFunctionConfig = {
137
139
  /** Function type `authorize` */
138
140
  type: 'authorize';
139
141
  function: Authorize;
140
142
  };
141
143
  export type BasedRoute<T extends BasedFunctionTypes = BasedFunctionTypes, R extends keyof BasedFunctionConfig = 'type' | 'name'> = Required<Partial<BasedFunctionConfig<T>>, R>;
142
- export type BasedFunctionConfigComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = Required<BasedFunctionConfig<T>, 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'>;
143
144
  export type BasedRouteComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = Required<Partial<BasedFunctionConfig<T>>, 'type' | 'name' | 'maxPayloadSize' | 'rateLimitTokens'>;
144
145
  export declare function isBasedRoute<T extends BasedFunctionTypes>(type: T, route: any): route is BasedRoute<T>;
145
146
  export declare function isAnyBasedRoute(route: any): route is BasedRoute;
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;AAwPA,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"}
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;AAuQA,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/functions",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/functions.ts CHANGED
@@ -2,7 +2,7 @@ import { Context, HttpSession } from './context'
2
2
  import { BasedFunctionClient } from './client'
3
3
  import { BasedDataStream } from './stream'
4
4
  import { Authorize } from './auth'
5
- import { Required } from 'utility-types'
5
+ import type { Required } from 'utility-types'
6
6
 
7
7
  export type ObservableUpdateFunction<K = any> = (
8
8
  data: K,
@@ -93,6 +93,7 @@ export type ChannelMessageFunctionInternal<K = any> = (
93
93
 
94
94
  export type UninstallFunction = () => Promise<void>
95
95
 
96
+ // ------------ Config -------------------
96
97
  type FunctionConfigShared = {
97
98
  /** Function name */
98
99
  name?: string
@@ -148,9 +149,14 @@ type FunctionConfigShared = {
148
149
  timeoutCounter?: number
149
150
  }
150
151
 
152
+ type FunctionConfigSharedComplete = Required<
153
+ FunctionConfigShared,
154
+ 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'
155
+ >
156
+
151
157
  export type BasedFunctionTypes = 'channel' | 'query' | 'function' | 'stream'
152
158
 
153
- export type BasedChannelFunctionConfig = {
159
+ type BasedChannelFunctionConfig = {
154
160
  /** Function type `channel, function, query, stream, authorize` */
155
161
  type: 'channel'
156
162
  /** Channel subscriber
@@ -181,45 +187,61 @@ export type BasedChannelFunctionConfig = {
181
187
  closeAfterIdleTime?: number
182
188
  /** Only for Publisher */
183
189
  httpResponse?: HttpResponse
184
- } & FunctionConfigShared
190
+ }
185
191
 
186
- export type BasedCallFunctionConfig = {
192
+ type BasedCallFunctionConfig = {
187
193
  /** Function type `channel, function, query, stream` */
188
194
  type: 'function'
189
195
  fn: BasedFunction
190
196
  httpResponse?: HttpResponse
191
- } & FunctionConfigShared
197
+ }
192
198
 
193
- export type BasedQueryFunctionConfig = {
199
+ type BasedQueryFunctionConfig = {
194
200
  /** Function type `channel, function, query, stream` */
195
201
  type: 'query'
196
202
  fn: BasedQueryFunction
197
203
  httpResponse?: HttpResponse
198
204
  /** How long should the query function remain active after all subscribers are gone, in ms */
199
205
  closeAfterIdleTime?: number
200
- } & FunctionConfigShared
206
+ }
201
207
 
202
- export type BasedStreamFunctionConfig = {
208
+ type BasedStreamFunctionConfig = {
203
209
  /** Function type `channel, function, query, stream` */
204
210
  type: 'stream'
205
211
  fn: BasedStreamFunction
206
- } & FunctionConfigShared
212
+ }
207
213
 
208
214
  export type BasedFunctionConfig<
209
215
  T extends BasedFunctionTypes = BasedFunctionTypes
210
216
  > = T extends 'channel'
211
- ? BasedChannelFunctionConfig
217
+ ? BasedChannelFunctionConfig & FunctionConfigShared
212
218
  : T extends 'function'
213
- ? BasedCallFunctionConfig
219
+ ? BasedCallFunctionConfig & FunctionConfigShared
214
220
  : T extends 'query'
215
- ? BasedQueryFunctionConfig
221
+ ? BasedQueryFunctionConfig & FunctionConfigShared
216
222
  : T extends 'stream'
217
- ? BasedStreamFunctionConfig
223
+ ? BasedStreamFunctionConfig & FunctionConfigShared
218
224
  :
219
- | BasedChannelFunctionConfig
220
- | BasedCallFunctionConfig
221
- | BasedQueryFunctionConfig
222
- | BasedStreamFunctionConfig
225
+ | (BasedChannelFunctionConfig & FunctionConfigShared)
226
+ | (BasedCallFunctionConfig & FunctionConfigShared)
227
+ | (BasedQueryFunctionConfig & FunctionConfigShared)
228
+ | (BasedStreamFunctionConfig & FunctionConfigShared)
229
+
230
+ export type BasedFunctionConfigComplete<
231
+ T extends BasedFunctionTypes = BasedFunctionTypes
232
+ > = T extends 'channel'
233
+ ? BasedChannelFunctionConfig & FunctionConfigSharedComplete
234
+ : T extends 'function'
235
+ ? BasedCallFunctionConfig & FunctionConfigSharedComplete
236
+ : T extends 'query'
237
+ ? BasedQueryFunctionConfig & FunctionConfigSharedComplete
238
+ : T extends 'stream'
239
+ ? BasedStreamFunctionConfig & FunctionConfigSharedComplete
240
+ :
241
+ | (BasedChannelFunctionConfig & FunctionConfigSharedComplete)
242
+ | (BasedCallFunctionConfig & FunctionConfigSharedComplete)
243
+ | (BasedQueryFunctionConfig & FunctionConfigSharedComplete)
244
+ | (BasedStreamFunctionConfig & FunctionConfigSharedComplete)
223
245
 
224
246
  export type BasedAuthorizeFunctionConfig = {
225
247
  /** Function type `authorize` */
@@ -232,13 +254,6 @@ export type BasedRoute<
232
254
  R extends keyof BasedFunctionConfig = 'type' | 'name'
233
255
  > = Required<Partial<BasedFunctionConfig<T>>, R>
234
256
 
235
- export type BasedFunctionConfigComplete<
236
- T extends BasedFunctionTypes = BasedFunctionTypes
237
- > = Required<
238
- BasedFunctionConfig<T>,
239
- 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'
240
- >
241
-
242
257
  export type BasedRouteComplete<
243
258
  T extends BasedFunctionTypes = BasedFunctionTypes
244
259
  > = Required<