@based/client 3.2.2 → 4.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.
Files changed (205) hide show
  1. package/README.md +28 -330
  2. package/dist/Emitter.d.ts +7 -6
  3. package/dist/Emitter.js +31 -6
  4. package/dist/Emitter.js.map +1 -1
  5. package/dist/authState/parseAuthState.d.ts +3 -0
  6. package/dist/authState/parseAuthState.js +51 -0
  7. package/dist/authState/parseAuthState.js.map +1 -0
  8. package/dist/authState/updateAuthState.d.ts +3 -0
  9. package/dist/authState/updateAuthState.js +15 -0
  10. package/dist/authState/updateAuthState.js.map +1 -0
  11. package/dist/channel/cleanUp.d.ts +2 -0
  12. package/dist/channel/cleanUp.js +32 -0
  13. package/dist/channel/cleanUp.js.map +1 -0
  14. package/dist/channel/index.d.ts +12 -0
  15. package/dist/channel/index.js +67 -0
  16. package/dist/channel/index.js.map +1 -0
  17. package/dist/genObserveId.d.ts +1 -0
  18. package/dist/genObserveId.js +12 -0
  19. package/dist/genObserveId.js.map +1 -0
  20. package/dist/getTargetInfo.d.ts +6 -0
  21. package/dist/getTargetInfo.js +14 -0
  22. package/dist/getTargetInfo.js.map +1 -0
  23. package/dist/getUrlFromOpts.d.ts +3 -0
  24. package/dist/getUrlFromOpts.js +24 -0
  25. package/dist/getUrlFromOpts.js.map +1 -0
  26. package/dist/incoming/debug.d.ts +9 -0
  27. package/dist/incoming/debug.js +132 -0
  28. package/dist/incoming/debug.js.map +1 -0
  29. package/dist/incoming/index.d.ts +2 -0
  30. package/dist/incoming/index.js +341 -0
  31. package/dist/incoming/index.js.map +1 -0
  32. package/dist/incoming/protocol.d.ts +9 -0
  33. package/dist/incoming/protocol.js +62 -0
  34. package/dist/incoming/protocol.js.map +1 -0
  35. package/dist/index.d.ts +69 -127
  36. package/dist/index.js +224 -15
  37. package/dist/index.js.map +1 -1
  38. package/dist/outgoing/debug.d.ts +8 -0
  39. package/dist/outgoing/debug.js +70 -0
  40. package/dist/outgoing/debug.js.map +1 -0
  41. package/dist/outgoing/index.d.ts +14 -0
  42. package/dist/outgoing/index.js +227 -0
  43. package/dist/outgoing/index.js.map +1 -0
  44. package/dist/outgoing/protocol.d.ts +24 -0
  45. package/dist/outgoing/protocol.js +200 -0
  46. package/dist/outgoing/protocol.js.map +1 -0
  47. package/dist/persistentStorage/browser.d.ts +5 -0
  48. package/dist/persistentStorage/browser.js +150 -0
  49. package/dist/persistentStorage/browser.js.map +1 -0
  50. package/dist/persistentStorage/index.d.ts +6 -0
  51. package/dist/persistentStorage/index.js +56 -0
  52. package/dist/persistentStorage/index.js.map +1 -0
  53. package/dist/persistentStorage/node.d.ts +6 -0
  54. package/dist/persistentStorage/node.js +104 -0
  55. package/dist/persistentStorage/node.js.map +1 -0
  56. package/dist/query/index.d.ts +17 -0
  57. package/dist/query/index.js +112 -0
  58. package/dist/query/index.js.map +1 -0
  59. package/dist/stream/fetch.d.ts +4 -0
  60. package/dist/stream/fetch.js +42 -0
  61. package/dist/stream/fetch.js.map +1 -0
  62. package/dist/stream/index.d.ts +4 -0
  63. package/dist/stream/index.js +65 -0
  64. package/dist/stream/index.js.map +1 -0
  65. package/dist/stream/nodeStream.d.ts +7 -0
  66. package/dist/stream/nodeStream.js +117 -0
  67. package/dist/stream/nodeStream.js.map +1 -0
  68. package/dist/stream/types.d.ts +37 -0
  69. package/dist/stream/types.js +8 -0
  70. package/dist/stream/types.js.map +1 -0
  71. package/dist/stream/uploadFileBrowser.d.ts +4 -0
  72. package/dist/stream/uploadFileBrowser.js +113 -0
  73. package/dist/stream/uploadFileBrowser.js.map +1 -0
  74. package/dist/types/auth.d.ts +11 -0
  75. package/dist/{selvaTypes/get.js → types/auth.js} +1 -1
  76. package/dist/types/auth.js.map +1 -0
  77. package/dist/types/cache.d.ts +6 -0
  78. package/dist/{selvaTypes/set.js → types/cache.js} +1 -1
  79. package/dist/types/cache.js.map +1 -0
  80. package/dist/types/channel.d.ts +25 -0
  81. package/dist/types/channel.js +3 -0
  82. package/dist/types/channel.js.map +1 -0
  83. package/dist/types/error.d.ts +36 -0
  84. package/dist/types/error.js +40 -0
  85. package/dist/types/error.js.map +1 -0
  86. package/dist/types/events.d.ts +34 -0
  87. package/dist/{selvaTypes/schema.js → types/events.js} +1 -1
  88. package/dist/types/events.js.map +1 -0
  89. package/dist/types/functions.d.ts +8 -0
  90. package/dist/types/functions.js +3 -0
  91. package/dist/types/functions.js.map +1 -0
  92. package/dist/types/generic.d.ts +20 -0
  93. package/dist/types/generic.js +3 -0
  94. package/dist/types/generic.js.map +1 -0
  95. package/dist/types/index.d.ts +6 -0
  96. package/dist/{subscriptions → types}/index.js +6 -10
  97. package/dist/types/index.js.map +1 -0
  98. package/dist/types/observe.d.ts +46 -0
  99. package/dist/types/observe.js +3 -0
  100. package/dist/types/observe.js.map +1 -0
  101. package/dist/websocket/index.d.ts +1 -1
  102. package/dist/websocket/index.js +14 -5
  103. package/dist/websocket/index.js.map +1 -1
  104. package/package.json +17 -27
  105. package/dist/Client.d.ts +0 -80
  106. package/dist/Client.js +0 -271
  107. package/dist/Client.js.map +0 -1
  108. package/dist/auth.d.ts +0 -13
  109. package/dist/auth.js +0 -87
  110. package/dist/auth.js.map +0 -1
  111. package/dist/createError.d.ts +0 -3
  112. package/dist/createError.js +0 -67
  113. package/dist/createError.js.map +0 -1
  114. package/dist/debug.d.ts +0 -2
  115. package/dist/debug.js +0 -21
  116. package/dist/debug.js.map +0 -1
  117. package/dist/file/fetch.d.ts +0 -6
  118. package/dist/file/fetch.js +0 -27
  119. package/dist/file/fetch.js.map +0 -1
  120. package/dist/file/getUrl.d.ts +0 -4
  121. package/dist/file/getUrl.js +0 -42
  122. package/dist/file/getUrl.js.map +0 -1
  123. package/dist/file/index.d.ts +0 -6
  124. package/dist/file/index.js +0 -95
  125. package/dist/file/index.js.map +0 -1
  126. package/dist/file/stream/browser.d.ts +0 -7
  127. package/dist/file/stream/browser.js +0 -17
  128. package/dist/file/stream/browser.js.map +0 -1
  129. package/dist/file/stream/index.d.ts +0 -7
  130. package/dist/file/stream/index.js +0 -86
  131. package/dist/file/stream/index.js.map +0 -1
  132. package/dist/file/uploadFileBrowser.d.ts +0 -3
  133. package/dist/file/uploadFileBrowser.js +0 -72
  134. package/dist/file/uploadFileBrowser.js.map +0 -1
  135. package/dist/findPrefix.d.ts +0 -3
  136. package/dist/findPrefix.js +0 -20
  137. package/dist/findPrefix.js.map +0 -1
  138. package/dist/idleTimeout.d.ts +0 -3
  139. package/dist/idleTimeout.js +0 -17
  140. package/dist/idleTimeout.js.map +0 -1
  141. package/dist/observable/index.d.ts +0 -28
  142. package/dist/observable/index.js +0 -84
  143. package/dist/observable/index.js.map +0 -1
  144. package/dist/printBasedObject.d.ts +0 -4
  145. package/dist/printBasedObject.js +0 -76
  146. package/dist/printBasedObject.js.map +0 -1
  147. package/dist/queue.d.ts +0 -5
  148. package/dist/queue.js +0 -53
  149. package/dist/queue.js.map +0 -1
  150. package/dist/request.d.ts +0 -6
  151. package/dist/request.js +0 -67
  152. package/dist/request.js.map +0 -1
  153. package/dist/selvaTypes/get.d.ts +0 -97
  154. package/dist/selvaTypes/get.js.map +0 -1
  155. package/dist/selvaTypes/schema.d.ts +0 -89
  156. package/dist/selvaTypes/schema.js.map +0 -1
  157. package/dist/selvaTypes/set.d.ts +0 -73
  158. package/dist/selvaTypes/set.js.map +0 -1
  159. package/dist/subscriptions/addGetSubscriber.d.ts +0 -3
  160. package/dist/subscriptions/addGetSubscriber.js +0 -87
  161. package/dist/subscriptions/addGetSubscriber.js.map +0 -1
  162. package/dist/subscriptions/addSubscriber.d.ts +0 -2
  163. package/dist/subscriptions/addSubscriber.js +0 -136
  164. package/dist/subscriptions/addSubscriber.js.map +0 -1
  165. package/dist/subscriptions/generateId.d.ts +0 -1
  166. package/dist/subscriptions/generateId.js +0 -11
  167. package/dist/subscriptions/generateId.js.map +0 -1
  168. package/dist/subscriptions/incomingSubscription.d.ts +0 -3
  169. package/dist/subscriptions/incomingSubscription.js +0 -87
  170. package/dist/subscriptions/incomingSubscription.js.map +0 -1
  171. package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -3
  172. package/dist/subscriptions/incomingSubscriptionDiff.js +0 -85
  173. package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -1
  174. package/dist/subscriptions/index.d.ts +0 -10
  175. package/dist/subscriptions/index.js.map +0 -1
  176. package/dist/subscriptions/logoutSubscriptions.d.ts +0 -3
  177. package/dist/subscriptions/logoutSubscriptions.js +0 -36
  178. package/dist/subscriptions/logoutSubscriptions.js.map +0 -1
  179. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -2
  180. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -14
  181. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -1
  182. package/dist/subscriptions/removeSubscriber.d.ts +0 -2
  183. package/dist/subscriptions/removeSubscriber.js +0 -44
  184. package/dist/subscriptions/removeSubscriber.js.map +0 -1
  185. package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -2
  186. package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -14
  187. package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -1
  188. package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -2
  189. package/dist/subscriptions/sendAllSubscriptions.js +0 -114
  190. package/dist/subscriptions/sendAllSubscriptions.js.map +0 -1
  191. package/dist/token.d.ts +0 -4
  192. package/dist/token.js +0 -35
  193. package/dist/token.js.map +0 -1
  194. package/dist/track.d.ts +0 -8
  195. package/dist/track.js +0 -71
  196. package/dist/track.js.map +0 -1
  197. package/docs/auth-based-ui-howto.md +0 -74
  198. package/docs/auth-howto.md +0 -166
  199. package/docs/auth.md +0 -93
  200. package/docs/authorize.md +0 -56
  201. package/docs/files.md +0 -66
  202. package/docs/get-started.md +0 -60
  203. package/docs/get.md +0 -759
  204. package/docs/schema.md +0 -244
  205. package/docs/set.md +0 -652
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.uploadFileStream = exports.uploadFilePath = exports.isStream = void 0;
7
+ const stream_1 = require("stream");
8
+ const http_1 = require("http");
9
+ const https_1 = require("https");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const util_1 = require("util");
12
+ const __1 = require("..");
13
+ const getUrlFromOpts_1 = __importDefault(require("../getUrlFromOpts"));
14
+ const error_1 = require("../types/error");
15
+ const utils_1 = require("@saulx/utils");
16
+ const stat = (0, util_1.promisify)(fs_1.default.stat);
17
+ const checkFile = async (path) => {
18
+ try {
19
+ const s = await stat(path);
20
+ return {
21
+ size: s.size,
22
+ };
23
+ }
24
+ catch (err) { }
25
+ };
26
+ const isStream = (contents) => {
27
+ return contents instanceof stream_1.Readable;
28
+ };
29
+ exports.isStream = isStream;
30
+ const parseUrlRe = /^(?:(tcp|wss?|https?):\/\/)?([a-z0-9.-]*)(?::(\d+))?$/;
31
+ const uploadFilePath = async (client, name, options) => {
32
+ const info = await checkFile(options.path);
33
+ if (info) {
34
+ return (0, exports.uploadFileStream)(client, name, {
35
+ contents: fs_1.default.createReadStream(options.path),
36
+ mimeType: options.mimeType,
37
+ extension: options.path.match(/\.(.*?)$/)?.[1],
38
+ size: info.size,
39
+ payload: options.payload,
40
+ serverKey: options.serverKey,
41
+ });
42
+ }
43
+ else {
44
+ throw new Error(`File does not exist ${options.path}`);
45
+ }
46
+ };
47
+ exports.uploadFilePath = uploadFilePath;
48
+ const streamRequest = (stream, name, url, headers, query) => {
49
+ const [, protocol, host, port] = parseUrlRe.exec(url);
50
+ // query
51
+ const httpOptions = {
52
+ port,
53
+ host: host,
54
+ path: '/' + name + query,
55
+ method: 'POST',
56
+ headers,
57
+ };
58
+ return new Promise((resolve, reject) => {
59
+ const incomingReady = (incomingReq) => {
60
+ const s = [];
61
+ incomingReq.on('data', (c) => {
62
+ s.push(c.toString());
63
+ });
64
+ incomingReq.once('end', () => {
65
+ const result = s.join('');
66
+ try {
67
+ const parsed = JSON.parse(result);
68
+ if ('code' in parsed && 'error' in parsed) {
69
+ reject((0, error_1.convertDataToBasedError)({
70
+ code: parsed.code,
71
+ message: parsed.error,
72
+ }));
73
+ return;
74
+ }
75
+ resolve(parsed);
76
+ }
77
+ catch (err) { }
78
+ resolve(result);
79
+ });
80
+ };
81
+ const req = protocol === 'wss' || protocol === 'https'
82
+ ? (0, https_1.request)(httpOptions, incomingReady)
83
+ : (0, http_1.request)(httpOptions, incomingReady);
84
+ stream.pipe(req);
85
+ });
86
+ };
87
+ const uploadFileStream = async (client, name, options) => {
88
+ if (!(options.contents instanceof stream_1.Readable)) {
89
+ throw new Error('File Contents has to be an instance of "Readable"');
90
+ }
91
+ if (!client.connected) {
92
+ await client.once('connect');
93
+ }
94
+ // key is something special
95
+ let url = await (0, getUrlFromOpts_1.default)(client.opts);
96
+ if (typeof url === 'function') {
97
+ url = await url();
98
+ }
99
+ const headers = {
100
+ 'Content-Length': String(options.size),
101
+ 'Content-Type': options.mimeType || 'text/plain',
102
+ Authorization: (0, __1.encodeAuthState)(client.authState),
103
+ };
104
+ if (options.fileName) {
105
+ headers['Content-Name'] = options.fileName;
106
+ }
107
+ if (!options.mimeType && options.extension) {
108
+ headers['Content-Extension'] = options.extension;
109
+ }
110
+ let q = '';
111
+ if (options.payload) {
112
+ q = '?' + (0, utils_1.serializeQuery)(options.payload);
113
+ }
114
+ return streamRequest(options.contents, name, url, headers, q);
115
+ };
116
+ exports.uploadFileStream = uploadFileStream;
117
+ //# sourceMappingURL=nodeStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeStream.js","sourceRoot":"","sources":["../../src/stream/nodeStream.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAiC;AACjC,+BAA+C;AAC/C,iCAA6C;AAC7C,4CAAmB;AACnB,+BAAgC;AAMhC,0BAAiD;A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CAAA;KACjD;IAED,IAAI,CAAC,GAAG,EAAE,CAAA;IACV,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,CAAC,GAAG,GAAG,GAAG,IAAA,sBAAc,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;KAC1C;IAED,OAAO,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;AAC/D,CAAC,CAAA;AAvCY,QAAA,gBAAgB,oBAuC5B"}
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ export type ReadableStream = {
3
+ pipe: (x: any) => ReadableStream;
4
+ };
5
+ export type ProgressListener = (progress: number, files: number) => void;
6
+ export type StreamFunctionContents<F = Buffer | ArrayBuffer | string | File | Blob> = {
7
+ contents: F;
8
+ payload?: any;
9
+ mimeType?: string;
10
+ fileName?: string;
11
+ serverKey?: string;
12
+ };
13
+ export declare const isFileContents: (contents: StreamFunctionContents) => contents is StreamFunctionContents<File>;
14
+ export type StreamFunctionStream = {
15
+ contents: ReadableStream;
16
+ payload?: any;
17
+ size: number;
18
+ mimeType?: string;
19
+ fileName?: string;
20
+ serverKey?: string;
21
+ extension?: string;
22
+ };
23
+ export type StreamFunctionPath = {
24
+ path: string;
25
+ payload?: any;
26
+ mimeType?: string;
27
+ fileName?: string;
28
+ serverKey?: string;
29
+ };
30
+ export type StreamFunctionOpts = StreamFunctionPath | StreamFunctionContents | StreamFunctionStream;
31
+ export type StreamHeaders = {
32
+ 'Content-Extension'?: string;
33
+ 'Content-Length'?: string;
34
+ 'Content-Type': string;
35
+ 'Content-Name'?: string;
36
+ Authorization: string;
37
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFileContents = void 0;
4
+ const isFileContents = (contents) => {
5
+ return contents.contents instanceof File;
6
+ };
7
+ exports.isFileContents = isFileContents;
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stream/types.ts"],"names":[],"mappings":";;;AAkBO,MAAM,cAAc,GAAG,CAC5B,QAAgC,EACU,EAAE;IAC5C,OAAO,QAAQ,CAAC,QAAQ,YAAY,IAAI,CAAA;AAC1C,CAAC,CAAA;AAJY,QAAA,cAAc,kBAI1B"}
@@ -0,0 +1,4 @@
1
+ import { BasedClient } from '..';
2
+ import { StreamFunctionContents, ProgressListener } from './types';
3
+ declare const _default: (client: BasedClient, functionName: string, options: StreamFunctionContents<File>, progressListener?: ProgressListener) => Promise<unknown>;
4
+ export default _default;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const __1 = require("..");
7
+ const getUrlFromOpts_1 = __importDefault(require("../getUrlFromOpts"));
8
+ const error_1 = require("../types/error");
9
+ const inProgress = {};
10
+ const queue = {};
11
+ const getUrl = async (client) => {
12
+ let url = await (0, getUrlFromOpts_1.default)(client.opts);
13
+ if (typeof url === 'function') {
14
+ url = await url();
15
+ }
16
+ return url.replace(/^ws/, 'http');
17
+ };
18
+ const reject = (err, q) => {
19
+ q.forEach((item) => {
20
+ item.reject(err);
21
+ });
22
+ };
23
+ const drainQueue = (client, functionName, authorization) => {
24
+ if (!inProgress[functionName]) {
25
+ inProgress[functionName] = true;
26
+ setTimeout(async () => {
27
+ inProgress[functionName] = false;
28
+ const url = await getUrl(client);
29
+ const q = queue[functionName];
30
+ queue[functionName] = [];
31
+ const body = new global.FormData();
32
+ for (let i = 0; i < q.length; i++) {
33
+ const options = q[i].options;
34
+ const { contents, payload } = options;
35
+ const p = payload || {};
36
+ body.append(`size=${contents.size},${JSON.stringify(p)}`, contents);
37
+ }
38
+ try {
39
+ const xhr = new global.XMLHttpRequest();
40
+ xhr.upload.onprogress = (p) => {
41
+ const progress =
42
+ // @ts-ignore
43
+ (p.loaded || p.position) / (p.totalSize || p.total);
44
+ q.forEach((item) => {
45
+ if (item.progressListener) {
46
+ item.progressListener(progress, q.length);
47
+ }
48
+ });
49
+ };
50
+ xhr.onerror = (p) => {
51
+ if (xhr.status === 0 && !xhr.statusText) {
52
+ const err = (0, error_1.convertDataToBasedError)({
53
+ message: `[${functionName}] Function not found`,
54
+ code: error_1.BasedErrorCode.FunctionNotFound,
55
+ });
56
+ reject(err, q);
57
+ }
58
+ else {
59
+ // go handle this!
60
+ console.error(p);
61
+ }
62
+ };
63
+ xhr.timeout = 1e3 * 60 * 60 * 24;
64
+ xhr.onabort = () => {
65
+ const err = new Error('File upload aborted before it finished');
66
+ reject(err, q);
67
+ };
68
+ xhr.ontimeout = () => {
69
+ console.error('on timeout');
70
+ };
71
+ xhr.onload = () => {
72
+ try {
73
+ const x = JSON.parse(xhr.response);
74
+ for (let i = 0; i < x.length; i++) {
75
+ const result = x[i];
76
+ if (result.error) {
77
+ q[i].reject((0, error_1.convertDataToBasedError)(result.error));
78
+ }
79
+ else {
80
+ q[i].resolve(x[i].value);
81
+ }
82
+ }
83
+ }
84
+ catch (err) {
85
+ reject(err, q);
86
+ }
87
+ };
88
+ xhr.open('POST', url + '/' + functionName);
89
+ xhr.setRequestHeader('Content-Type', 'multipart/form-data');
90
+ xhr.setRequestHeader('Authorization', authorization);
91
+ xhr.send(body);
92
+ }
93
+ catch (err) {
94
+ console.warn('Something unexpected happened with file upload', err);
95
+ reject(err, q);
96
+ }
97
+ }, 500);
98
+ }
99
+ };
100
+ exports.default = async (client, functionName, options, progressListener) => {
101
+ if (!client.connected) {
102
+ await client.once('connect');
103
+ }
104
+ // TODO: key is something special
105
+ if (!queue[functionName]) {
106
+ queue[functionName] = [];
107
+ }
108
+ return new Promise((resolve, reject) => {
109
+ queue[functionName].push({ options, resolve, reject, progressListener });
110
+ drainQueue(client, functionName, (0, __1.encodeAuthState)(client.authState));
111
+ });
112
+ };
113
+ //# sourceMappingURL=uploadFileBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadFileBrowser.js","sourceRoot":"","sources":["../../src/stream/uploadFileBrowser.ts"],"names":[],"mappings":";;;;;AAAA,0BAAiD;AAEjD,uEAA8C;AAC9C,0CAAwE;AACxE,MAAM,UAAU,GAA+B,EAAE,CAAA;AASjD,MAAM,KAAK,GAEP,EAAE,CAAA;AAEN,MAAM,MAAM,GAAG,KAAK,EAAE,MAAmB,EAAmB,EAAE;IAC5D,IAAI,GAAG,GAAG,MAAM,IAAA,wBAAc,EAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;QAC7B,GAAG,GAAG,MAAM,GAAG,EAAE,CAAA;KAClB;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AACnC,CAAC,CAAA;AAED,MAAM,MAAM,GAAG,CAAC,GAAU,EAAE,CAAc,EAAE,EAAE;IAC5C,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CACjB,MAAmB,EACnB,YAAoB,EACpB,aAAqB,EACrB,EAAE;IACF,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;QAC7B,UAAU,CAAC,YAAY,CAAC,GAAG,IAAI,CAAA;QAE/B,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,UAAU,CAAC,YAAY,CAAC,GAAG,KAAK,CAAA;YAChC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAA;YAChC,MAAM,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAA;YAE7B,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;YACxB,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,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GAAG,GAAG,GAAG,YAAY,CAAC,CAAA;gBAC1C,GAAG,CAAC,gBAAgB,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAA;gBAC3D,GAAG,CAAC,gBAAgB,CAAC,eAAe,EAAE,aAAa,CAAC,CAAA;gBACpD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACf;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,CAAC,IAAI,CAAC,gDAAgD,EAAE,GAAG,CAAC,CAAA;gBACnE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;aACf;QACH,CAAC,EAAE,GAAG,CAAC,CAAA;KACR;AACH,CAAC,CAAA;AAED,kBAAe,KAAK,EAClB,MAAmB,EACnB,YAAoB,EACpB,OAAqC,EACrC,gBAAmC,EACnC,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;QACrB,MAAM,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;KAC7B;IAED,iCAAiC;IACjC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QACxB,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;KACzB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAA;QACxE,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,IAAA,mBAAe,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ export type AuthState = {
2
+ token?: string;
3
+ userId?: string;
4
+ refreshToken?: string;
5
+ error?: string;
6
+ persistent?: boolean;
7
+ type?: string;
8
+ };
9
+ export type AuthResponseListeners = {
10
+ [reqId: string]: [(val?: any) => void, (err: Error) => void];
11
+ };
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=get.js.map
3
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export type CacheValue = {
2
+ value: any;
3
+ checksum: number;
4
+ persistent?: boolean;
5
+ };
6
+ export type Cache = Map<number, CacheValue>;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=set.js.map
3
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/types/cache.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { BasedError } from './error';
2
+ export type ChannelMessageFunction<K = any> = (message: K) => void;
3
+ export type ChannelType = 5 | 7;
4
+ export type ChannelQueueItem = [
5
+ 5,
6
+ string,
7
+ any
8
+ ] | [
9
+ 5,
10
+ string
11
+ ] | [6, string, any] | [6, string] | [7];
12
+ export type ChannelQueue = Map<number, // id
13
+ ChannelQueueItem>;
14
+ export type ChannelPublishQueueItem = [number, any];
15
+ export type ChannelPublishQueue = ChannelPublishQueueItem[];
16
+ export type ChannelState = Map<number, {
17
+ inTransit?: boolean;
18
+ payload: any;
19
+ name: string;
20
+ subscribers: Map<number, {
21
+ onMessage: ChannelMessageFunction;
22
+ onError?: (err: BasedError) => void;
23
+ }>;
24
+ removeTimer: number;
25
+ }>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.js","sourceRoot":"","sources":["../../src/types/channel.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ export declare enum BasedErrorCode {
2
+ FunctionError = 50001,
3
+ AuthorizeFunctionError = 50002,
4
+ NoOservableCacheAvailable = 50003,
5
+ ObservableFunctionError = 50004,
6
+ ObserveCallbackError = 50005,
7
+ FunctionNotFound = 40401,
8
+ FunctionIsNotObservable = 40402,
9
+ FunctionIsObservable = 40403,
10
+ FunctionIsStream = 40404,
11
+ CannotStreamToObservableFunction = 40405,
12
+ AuthorizeRejectedError = 40301,
13
+ InvalidPayload = 40001,
14
+ PayloadTooLarge = 40002,
15
+ ChunkTooLarge = 40003,
16
+ UnsupportedContentEncoding = 40004,
17
+ NoBinaryProtocol = 40005,
18
+ LengthRequired = 41101,
19
+ MethodNotAllowed = 40501,
20
+ RateLimit = 40029,
21
+ MissingAuthStateProtocolHeader = 40030
22
+ }
23
+ export type BasedErrorData = {
24
+ message: string;
25
+ stack?: string;
26
+ requestId?: number;
27
+ observableId?: number;
28
+ channelId?: number;
29
+ code: BasedErrorCode;
30
+ statusCode?: number;
31
+ };
32
+ export declare class BasedError extends Error {
33
+ statusMessage?: string;
34
+ code: BasedErrorCode;
35
+ }
36
+ export declare const convertDataToBasedError: (payload: BasedErrorData, stack?: string) => BasedError;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertDataToBasedError = exports.BasedError = exports.BasedErrorCode = void 0;
4
+ var BasedErrorCode;
5
+ (function (BasedErrorCode) {
6
+ BasedErrorCode[BasedErrorCode["FunctionError"] = 50001] = "FunctionError";
7
+ BasedErrorCode[BasedErrorCode["AuthorizeFunctionError"] = 50002] = "AuthorizeFunctionError";
8
+ BasedErrorCode[BasedErrorCode["NoOservableCacheAvailable"] = 50003] = "NoOservableCacheAvailable";
9
+ BasedErrorCode[BasedErrorCode["ObservableFunctionError"] = 50004] = "ObservableFunctionError";
10
+ BasedErrorCode[BasedErrorCode["ObserveCallbackError"] = 50005] = "ObserveCallbackError";
11
+ BasedErrorCode[BasedErrorCode["FunctionNotFound"] = 40401] = "FunctionNotFound";
12
+ BasedErrorCode[BasedErrorCode["FunctionIsNotObservable"] = 40402] = "FunctionIsNotObservable";
13
+ BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
14
+ BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
15
+ BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40405] = "CannotStreamToObservableFunction";
16
+ BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
17
+ BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
18
+ BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
19
+ BasedErrorCode[BasedErrorCode["ChunkTooLarge"] = 40003] = "ChunkTooLarge";
20
+ BasedErrorCode[BasedErrorCode["UnsupportedContentEncoding"] = 40004] = "UnsupportedContentEncoding";
21
+ BasedErrorCode[BasedErrorCode["NoBinaryProtocol"] = 40005] = "NoBinaryProtocol";
22
+ BasedErrorCode[BasedErrorCode["LengthRequired"] = 41101] = "LengthRequired";
23
+ BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
24
+ BasedErrorCode[BasedErrorCode["RateLimit"] = 40029] = "RateLimit";
25
+ BasedErrorCode[BasedErrorCode["MissingAuthStateProtocolHeader"] = 40030] = "MissingAuthStateProtocolHeader";
26
+ })(BasedErrorCode = exports.BasedErrorCode || (exports.BasedErrorCode = {}));
27
+ class BasedError extends Error {
28
+ }
29
+ exports.BasedError = BasedError;
30
+ const convertDataToBasedError = (payload, stack) => {
31
+ const { message, code } = payload;
32
+ const msg = message[0] === '[' ? message : `[${BasedErrorCode[code]}] ` + message;
33
+ const error = new BasedError(msg);
34
+ error.stack = stack ? msg + ' ' + stack : msg;
35
+ error.name = BasedErrorCode[code];
36
+ error.code = code;
37
+ return error;
38
+ };
39
+ exports.convertDataToBasedError = convertDataToBasedError;
40
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/types/error.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAqBX;AArBD,WAAY,cAAc;IACxB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;IAC9B,iGAAiC,CAAA;IACjC,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,+GAAwC,CAAA;IACxC,2FAA8B,CAAA;IAC9B,2EAAsB,CAAA;IACtB,6EAAuB,CAAA;IACvB,yEAAqB,CAAA;IACrB,mGAAkC,CAAA;IAClC,+EAAwB,CAAA;IACxB,2EAAsB,CAAA;IACtB,+EAAwB,CAAA;IACxB,iEAAiB,CAAA;IACjB,2GAAsC,CAAA;AACxC,CAAC,EArBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAqBzB;AAYD,MAAa,UAAW,SAAQ,KAAK;CAGpC;AAHD,gCAGC;AAEM,MAAM,uBAAuB,GAAG,CACrC,OAAuB,EACvB,KAAc,EACF,EAAE;IACd,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IACjC,MAAM,GAAG,GACP,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAA;IACvE,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACjC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAA;IAC7C,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACjC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAZY,QAAA,uBAAuB,2BAYnC"}
@@ -0,0 +1,34 @@
1
+ import { AuthState } from './auth';
2
+ type DebugEvent = {
3
+ type: 'function' | 'subscribe' | 'subscriptionDiff' | 'get' | 'auth' | 'error' | 'channelMessage' | 'registerChannelId';
4
+ direction: 'incoming';
5
+ payload?: any;
6
+ target: {
7
+ name?: string;
8
+ id?: number;
9
+ payload?: any;
10
+ };
11
+ msg?: string;
12
+ checksum?: number;
13
+ } | {
14
+ type: 'function' | 'subscribe' | 'unsubscribe' | 'get' | 'auth' | 'subscribeChannel' | 'publishChannel' | 'unsubscribeChannel' | 'registerChannelId' | 'rePublishChannel';
15
+ direction: 'outgoing';
16
+ payload?: any;
17
+ target: {
18
+ name?: string;
19
+ id?: number;
20
+ payload?: any;
21
+ };
22
+ msg?: string;
23
+ checksum?: number;
24
+ };
25
+ export type EventMap = {
26
+ reconnect: true;
27
+ disconnect: true;
28
+ connect: true;
29
+ debug: DebugEvent;
30
+ 'authstate-change': AuthState;
31
+ };
32
+ export type Event = keyof EventMap;
33
+ export type Listener<T> = (data: T) => void;
34
+ export {};
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=schema.js.map
3
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { GenericObject } from './generic';
2
+ export type FunctionResponseListeners = Map<number, [
3
+ (val?: any) => void,
4
+ (err: Error) => void,
5
+ string?
6
+ ]>;
7
+ export type FunctionQueueItem = [number, string, GenericObject];
8
+ export type FunctionQueue = FunctionQueueItem[];
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/types/functions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ export type GenericObject = {
2
+ [key: string]: any;
3
+ };
4
+ export type BasedOpts = {
5
+ env?: string;
6
+ project?: string;
7
+ org?: string;
8
+ cluster?: string;
9
+ name?: string;
10
+ key?: string;
11
+ url?: string | (() => Promise<string>);
12
+ discoveryUrls?: string[];
13
+ params?: {
14
+ [key: string]: string | number;
15
+ };
16
+ };
17
+ export type Settings = {
18
+ maxCacheSize?: number;
19
+ persistentStorage?: string;
20
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=generic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic.js","sourceRoot":"","sources":["../../src/types/generic.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export * from './generic';
2
+ export * from './observe';
3
+ export * from './events';
4
+ export * from './auth';
5
+ export * from './cache';
6
+ export * from './functions';
@@ -14,14 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./addGetSubscriber"), exports);
18
- __exportStar(require("./addSubscriber"), exports);
19
- __exportStar(require("./generateId"), exports);
20
- __exportStar(require("./removeSubscriber"), exports);
21
- __exportStar(require("./removeUnsubscribesFromQueue"), exports);
22
- __exportStar(require("./removeSendSubscriptionDataFromQueue"), exports);
23
- __exportStar(require("./sendAllSubscriptions"), exports);
24
- __exportStar(require("./incomingSubscription"), exports);
25
- __exportStar(require("./incomingSubscriptionDiff"), exports);
26
- __exportStar(require("./logoutSubscriptions"), exports);
17
+ __exportStar(require("./generic"), exports);
18
+ __exportStar(require("./observe"), exports);
19
+ __exportStar(require("./events"), exports);
20
+ __exportStar(require("./auth"), exports);
21
+ __exportStar(require("./cache"), exports);
22
+ __exportStar(require("./functions"), exports);
27
23
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,4CAAyB;AACzB,2CAAwB;AACxB,yCAAsB;AACtB,0CAAuB;AACvB,8CAA2B"}
@@ -0,0 +1,46 @@
1
+ import { BasedError } from './error';
2
+ export type ObserveOpts = {
3
+ localStorage?: boolean;
4
+ maxCacheTime?: number;
5
+ };
6
+ export type ObserveDataListener<K = any> = (data: K, checksum: number) => void;
7
+ export type ObserveErrorListener = (err: BasedError) => void;
8
+ export type CloseObserve = () => void;
9
+ export type ObserveState = Map<number, {
10
+ persistent?: boolean;
11
+ payload: any;
12
+ name: string;
13
+ subscribers: Map<number, {
14
+ onError?: ObserveErrorListener;
15
+ onData: ObserveDataListener;
16
+ }>;
17
+ }>;
18
+ export type GetState = Map<number, [
19
+ (data: any) => void,
20
+ ObserveErrorListener
21
+ ][]>;
22
+ export type ObserveType = 1 | 2;
23
+ export type ObserveQueueItem = [
24
+ 1,
25
+ string,
26
+ number,
27
+ any
28
+ ] | [
29
+ 1,
30
+ string,
31
+ number
32
+ ] | [2];
33
+ export type ObserveQueue = Map<number, // id
34
+ ObserveQueueItem>;
35
+ export type GetObserveQueueItem = [
36
+ 3,
37
+ string,
38
+ number,
39
+ any
40
+ ] | [
41
+ 3,
42
+ string,
43
+ number
44
+ ];
45
+ export type GetObserveQueue = Map<number, // id
46
+ GetObserveQueueItem>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=observe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe.js","sourceRoot":"","sources":["../../src/types/observe.ts"],"names":[],"mappings":""}