@based/functions 3.0.2 → 3.1.0-alpha

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/src/geo.ts DELETED
@@ -1,322 +0,0 @@
1
- export type CountryCode =
2
- | 'AF'
3
- | 'AL'
4
- | 'DZ'
5
- | 'AS'
6
- | 'AD'
7
- | 'AO'
8
- | 'AI'
9
- | 'AQ'
10
- | 'AG'
11
- | 'AR'
12
- | 'AM'
13
- | 'AW'
14
- | 'AU'
15
- | 'AT'
16
- | 'AZ'
17
- | 'BS'
18
- | 'BH'
19
- | 'BD'
20
- | 'BB'
21
- | 'BY'
22
- | 'BE'
23
- | 'BZ'
24
- | 'BJ'
25
- | 'BM'
26
- | 'BT'
27
- | 'BO'
28
- | 'BQ'
29
- | 'BA'
30
- | 'BW'
31
- | 'BV'
32
- | 'BR'
33
- | 'IO'
34
- | 'BN'
35
- | 'BG'
36
- | 'BF'
37
- | 'BI'
38
- | 'KH'
39
- | 'CM'
40
- | 'CA'
41
- | 'CV'
42
- | 'KY'
43
- | 'CF'
44
- | 'TD'
45
- | 'CL'
46
- | 'CN'
47
- | 'CX'
48
- | 'CC'
49
- | 'CO'
50
- | 'KM'
51
- | 'CG'
52
- | 'CD'
53
- | 'CK'
54
- | 'CR'
55
- | 'HR'
56
- | 'CU'
57
- | 'CW'
58
- | 'CY'
59
- | 'CZ'
60
- | 'CI'
61
- | 'DK'
62
- | 'DJ'
63
- | 'DM'
64
- | 'DO'
65
- | 'EC'
66
- | 'EG'
67
- | 'SV'
68
- | 'GQ'
69
- | 'ER'
70
- | 'EE'
71
- | 'ET'
72
- | 'FK'
73
- | 'FO'
74
- | 'FJ'
75
- | 'FI'
76
- | 'FR'
77
- | 'GF'
78
- | 'PF'
79
- | 'TF'
80
- | 'GA'
81
- | 'GM'
82
- | 'GE'
83
- | 'DE'
84
- | 'GH'
85
- | 'GI'
86
- | 'GR'
87
- | 'GL'
88
- | 'GD'
89
- | 'GP'
90
- | 'GU'
91
- | 'GT'
92
- | 'GG'
93
- | 'GN'
94
- | 'GW'
95
- | 'GY'
96
- | 'HT'
97
- | 'HM'
98
- | 'VA'
99
- | 'HN'
100
- | 'HK'
101
- | 'HU'
102
- | 'IS'
103
- | 'IN'
104
- | 'ID'
105
- | 'IR'
106
- | 'IQ'
107
- | 'IE'
108
- | 'IM'
109
- | 'IL'
110
- | 'IT'
111
- | 'JM'
112
- | 'JP'
113
- | 'JE'
114
- | 'JO'
115
- | 'KZ'
116
- | 'KE'
117
- | 'KI'
118
- | 'KP'
119
- | 'KR'
120
- | 'KW'
121
- | 'KG'
122
- | 'LA'
123
- | 'LV'
124
- | 'LB'
125
- | 'LS'
126
- | 'LR'
127
- | 'LY'
128
- | 'LI'
129
- | 'LT'
130
- | 'LU'
131
- | 'MO'
132
- | 'MK'
133
- | 'MG'
134
- | 'MW'
135
- | 'MY'
136
- | 'MV'
137
- | 'ML'
138
- | 'MT'
139
- | 'MH'
140
- | 'MQ'
141
- | 'MR'
142
- | 'MU'
143
- | 'YT'
144
- | 'MX'
145
- | 'FM'
146
- | 'MD'
147
- | 'MC'
148
- | 'MN'
149
- | 'ME'
150
- | 'MS'
151
- | 'MA'
152
- | 'MZ'
153
- | 'MM'
154
- | 'NA'
155
- | 'NR'
156
- | 'NP'
157
- | 'NL'
158
- | 'NC'
159
- | 'NZ'
160
- | 'NI'
161
- | 'NE'
162
- | 'NG'
163
- | 'NU'
164
- | 'NF'
165
- | 'MP'
166
- | 'NO'
167
- | 'OM'
168
- | 'PK'
169
- | 'PW'
170
- | 'PS'
171
- | 'PA'
172
- | 'PG'
173
- | 'PY'
174
- | 'PE'
175
- | 'PH'
176
- | 'PN'
177
- | 'PL'
178
- | 'PT'
179
- | 'PR'
180
- | 'QA'
181
- | 'RO'
182
- | 'RU'
183
- | 'RW'
184
- | 'RE'
185
- | 'BL'
186
- | 'SH'
187
- | 'KN'
188
- | 'LC'
189
- | 'MF'
190
- | 'PM'
191
- | 'VC'
192
- | 'WS'
193
- | 'SM'
194
- | 'ST'
195
- | 'SA'
196
- | 'SN'
197
- | 'RS'
198
- | 'SC'
199
- | 'SL'
200
- | 'SG'
201
- | 'SX'
202
- | 'SK'
203
- | 'SI'
204
- | 'SB'
205
- | 'SO'
206
- | 'ZA'
207
- | 'GS'
208
- | 'SS'
209
- | 'ES'
210
- | 'LK'
211
- | 'SD'
212
- | 'SR'
213
- | 'SJ'
214
- | 'SZ'
215
- | 'SE'
216
- | 'CH'
217
- | 'SY'
218
- | 'TW'
219
- | 'TJ'
220
- | 'TZ'
221
- | 'TH'
222
- | 'TL'
223
- | 'TG'
224
- | 'TK'
225
- | 'TO'
226
- | 'TT'
227
- | 'TN'
228
- | 'TR'
229
- | 'TM'
230
- | 'TC'
231
- | 'TV'
232
- | 'UG'
233
- | 'UA'
234
- | 'AE'
235
- | 'GB'
236
- | 'US'
237
- | 'UM'
238
- | 'UY'
239
- | 'UZ'
240
- | 'VU'
241
- | 'VE'
242
- | 'VN'
243
- | 'VG'
244
- | 'VI'
245
- | 'WF'
246
- | 'EH'
247
- | 'YE'
248
- | 'ZM'
249
- | 'ZW'
250
- | 'AX'
251
-
252
- type Char =
253
- | 'A'
254
- | 'B'
255
- | 'C'
256
- | 'D'
257
- | 'E'
258
- | 'F'
259
- | 'G'
260
- | 'H'
261
- | 'I'
262
- | 'J'
263
- | 'K'
264
- | 'L'
265
- | 'M'
266
- | 'N'
267
- | 'O'
268
- | 'P'
269
- | 'Q'
270
- | 'R'
271
- | 'S'
272
- | 'T'
273
- | 'U'
274
- | 'V'
275
- | 'W'
276
- | 'X'
277
- | 'Y'
278
- | 'Z'
279
- | '0'
280
- | '1'
281
- | '2'
282
- | '3'
283
- | '4'
284
- | '5'
285
- | '6'
286
- | '7'
287
- | '8'
288
- | '9'
289
-
290
- export type GeoRegionISO = `${Char}${Char}` | `${Char}${Char}${Char}`
291
-
292
- export type Geo = {
293
- country: CountryCode | 'unknown'
294
- /**
295
- Ip formatted as ipv6
296
-
297
- e.g. `2001:0db8:85a3:0000:0000:8a2e:0370:7334`
298
- */
299
- ip: string
300
- /**
301
- Region subdivisions
302
-
303
- e.g. `[{ iso: 'NH', name: 'north-holland' }]`
304
- */
305
- regions: {
306
- iso: GeoRegionISO
307
- name?: string
308
- }[]
309
- lat: number
310
- long: number
311
- /**
312
- Accuracy Radius (km)
313
- */
314
- accuracy: number
315
- /**
316
- City name
317
-
318
- e.g. `Amsterdam`
319
- */
320
- city?: string
321
- postalCode?: string
322
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export * from './context.js'
2
- export * from './auth.js'
3
- export * from './client.js'
4
- export * from './functions.js'
5
- export * from './query.js'
6
- export * from './stream.js'
7
- export * from './channel.js'
8
- export * from './geo.js'
package/src/query.ts DELETED
@@ -1,14 +0,0 @@
1
- import { ObservableUpdateFunction, ObserveErrorListener } from './functions.js'
2
-
3
- export abstract class BasedQuery<K = any> {
4
- abstract subscribe(
5
- onData: ObservableUpdateFunction<K>,
6
- onError?: ObserveErrorListener
7
- ): () => void
8
-
9
- abstract getWhen(
10
- condition: (data: K, checksum: number) => boolean
11
- ): Promise<any>
12
-
13
- abstract get(): Promise<K>
14
- }
package/src/stream.ts DELETED
@@ -1,104 +0,0 @@
1
- import { Duplex, Readable } from "node:stream";
2
- import util from "node:util";
3
-
4
- export class BasedDataStream extends Duplex {
5
- public size: number = 0;
6
- public paused: boolean = false;
7
- public receivedBytes: number = 0;
8
- public progessTimer: NodeJS.Timeout;
9
-
10
- constructor(size: number) {
11
- super();
12
- this.size = size;
13
-
14
- this.on("pause", () => {
15
- this.paused = true;
16
- });
17
-
18
- this.on("resume", () => {
19
- this.paused = false;
20
- });
21
-
22
- this.emit("progress", 0);
23
- }
24
-
25
- override _read() {}
26
-
27
- override _write(chunk, encoding, callback) {
28
- this.receivedBytes += chunk.byteLength;
29
- if (this.size && this.size > 20000) {
30
- if (!this.progessTimer) {
31
- this.progessTimer = setTimeout(() => {
32
- const progress = this.receivedBytes / this.size;
33
- this.emit("progress", progress);
34
- this.progessTimer = null;
35
- }, 200);
36
- }
37
- }
38
- this.push(Buffer.from(chunk, encoding));
39
- callback();
40
- }
41
-
42
- override _final() {
43
- if (!this.size) {
44
- this.size = this.receivedBytes;
45
- }
46
- this.receivedBytes = this.size;
47
- if (this.progessTimer) {
48
- clearTimeout(this.progessTimer);
49
- this.progessTimer = null;
50
- }
51
- this.emit("progress", 1);
52
- this.push(null);
53
- }
54
-
55
- [util.inspect.custom]() {
56
- if (this.size) {
57
- const rb =
58
- this.receivedBytes < 1000
59
- ? Math.round(this.receivedBytes / 1024) + "kb"
60
- : Math.round(this.receivedBytes / 1024 / 1024) + "mb";
61
-
62
- return `[BasedStream ${~~(
63
- (this.receivedBytes / this.size) *
64
- 100
65
- )}% ${rb}]`;
66
- } else {
67
- return `[BasedStream]`;
68
- }
69
- }
70
- }
71
-
72
- // maybe make a type pkg
73
- export type StreamFunctionContents<F = Buffer | ArrayBuffer | string> = {
74
- contents: F;
75
- payload?: any;
76
- mimeType?: string;
77
- fileName?: string;
78
- };
79
-
80
- export type StreamFunctionStream =
81
- | {
82
- contents: Readable | Duplex;
83
- payload?: any;
84
- size: number;
85
- mimeType?: string;
86
- fileName?: string;
87
- extension?: string;
88
- }
89
- | {
90
- contents: BasedDataStream;
91
- payload?: any;
92
- size?: number;
93
- mimeType?: string;
94
- fileName?: string;
95
- extension?: string;
96
- };
97
-
98
- export type StreamFunctionOpts = StreamFunctionContents | StreamFunctionStream;
99
-
100
- export const isStreamFunctionOpts = (
101
- opts: StreamFunctionContents | StreamFunctionStream
102
- ): opts is StreamFunctionStream => {
103
- return opts.contents instanceof Duplex || opts.contents instanceof Readable;
104
- };