@based/client 3.3.0 → 4.0.2
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/README.md +32 -336
- package/dist/Emitter.d.ts +7 -6
- package/dist/Emitter.js +31 -6
- package/dist/Emitter.js.map +1 -1
- package/dist/authState/parseAuthState.d.ts +3 -0
- package/dist/authState/parseAuthState.js +51 -0
- package/dist/authState/parseAuthState.js.map +1 -0
- package/dist/authState/updateAuthState.d.ts +3 -0
- package/dist/authState/updateAuthState.js +15 -0
- package/dist/authState/updateAuthState.js.map +1 -0
- package/dist/channel/cleanUp.d.ts +2 -0
- package/dist/channel/cleanUp.js +32 -0
- package/dist/channel/cleanUp.js.map +1 -0
- package/dist/channel/index.d.ts +12 -0
- package/dist/channel/index.js +67 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/genObserveId.d.ts +1 -0
- package/dist/genObserveId.js +12 -0
- package/dist/genObserveId.js.map +1 -0
- package/dist/getTargetInfo.d.ts +6 -0
- package/dist/getTargetInfo.js +14 -0
- package/dist/getTargetInfo.js.map +1 -0
- package/dist/getUrlFromOpts.d.ts +3 -0
- package/dist/getUrlFromOpts.js +27 -0
- package/dist/getUrlFromOpts.js.map +1 -0
- package/dist/incoming/debug.d.ts +9 -0
- package/dist/incoming/debug.js +132 -0
- package/dist/incoming/debug.js.map +1 -0
- package/dist/incoming/index.d.ts +2 -0
- package/dist/incoming/index.js +341 -0
- package/dist/incoming/index.js.map +1 -0
- package/dist/incoming/protocol.d.ts +9 -0
- package/dist/incoming/protocol.js +62 -0
- package/dist/incoming/protocol.js.map +1 -0
- package/dist/index.d.ts +70 -127
- package/dist/index.js +225 -15
- package/dist/index.js.map +1 -1
- package/dist/outgoing/debug.d.ts +8 -0
- package/dist/outgoing/debug.js +70 -0
- package/dist/outgoing/debug.js.map +1 -0
- package/dist/outgoing/index.d.ts +14 -0
- package/dist/outgoing/index.js +227 -0
- package/dist/outgoing/index.js.map +1 -0
- package/dist/outgoing/protocol.d.ts +24 -0
- package/dist/outgoing/protocol.js +200 -0
- package/dist/outgoing/protocol.js.map +1 -0
- package/dist/persistentStorage/browser.d.ts +5 -0
- package/dist/persistentStorage/browser.js +150 -0
- package/dist/persistentStorage/browser.js.map +1 -0
- package/dist/persistentStorage/index.d.ts +6 -0
- package/dist/persistentStorage/index.js +56 -0
- package/dist/persistentStorage/index.js.map +1 -0
- package/dist/persistentStorage/node.d.ts +6 -0
- package/dist/persistentStorage/node.js +104 -0
- package/dist/persistentStorage/node.js.map +1 -0
- package/dist/query/index.d.ts +17 -0
- package/dist/query/index.js +112 -0
- package/dist/query/index.js.map +1 -0
- package/dist/stream/fetch.d.ts +4 -0
- package/dist/stream/fetch.js +38 -0
- package/dist/stream/fetch.js.map +1 -0
- package/dist/stream/index.d.ts +4 -0
- package/dist/stream/index.js +65 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/nodeStream.d.ts +6 -0
- package/dist/stream/nodeStream.js +114 -0
- package/dist/stream/nodeStream.js.map +1 -0
- package/dist/stream/types.d.ts +37 -0
- package/dist/stream/types.js +8 -0
- package/dist/stream/types.js.map +1 -0
- package/dist/stream/uploadFileBrowser.d.ts +4 -0
- package/dist/stream/uploadFileBrowser.js +106 -0
- package/dist/stream/uploadFileBrowser.js.map +1 -0
- package/dist/types/auth.d.ts +11 -0
- package/dist/{selvaTypes/get.js → types/auth.js} +1 -1
- package/dist/types/auth.js.map +1 -0
- package/dist/types/cache.d.ts +6 -0
- package/dist/{selvaTypes/set.js → types/cache.js} +1 -1
- package/dist/types/cache.js.map +1 -0
- package/dist/types/channel.d.ts +25 -0
- package/dist/types/channel.js +3 -0
- package/dist/types/channel.js.map +1 -0
- package/dist/types/error.d.ts +37 -0
- package/dist/types/error.js +41 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/events.d.ts +34 -0
- package/dist/{selvaTypes/schema.js → types/events.js} +1 -1
- package/dist/types/events.js.map +1 -0
- package/dist/types/functions.d.ts +8 -0
- package/dist/types/functions.js +3 -0
- package/dist/types/functions.js.map +1 -0
- package/dist/types/generic.d.ts +22 -0
- package/dist/types/generic.js +3 -0
- package/dist/types/generic.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/{subscriptions → types}/index.js +6 -10
- package/dist/types/index.js.map +1 -0
- package/dist/types/observe.d.ts +46 -0
- package/dist/types/observe.js +3 -0
- package/dist/types/observe.js.map +1 -0
- package/dist/websocket/index.d.ts +1 -1
- package/dist/websocket/index.js +19 -5
- package/dist/websocket/index.js.map +1 -1
- package/dist/websocket/types.d.ts +0 -0
- package/dist/websocket/types.js +0 -0
- package/dist/websocket/types.js.map +0 -0
- package/dist/websocket/urlLoader.d.ts +0 -0
- package/dist/websocket/urlLoader.js +0 -0
- package/dist/websocket/urlLoader.js.map +0 -0
- package/package.json +18 -27
- package/dist/Client.d.ts +0 -80
- package/dist/Client.js +0 -271
- package/dist/Client.js.map +0 -1
- package/dist/auth.d.ts +0 -13
- package/dist/auth.js +0 -87
- package/dist/auth.js.map +0 -1
- package/dist/createError.d.ts +0 -3
- package/dist/createError.js +0 -67
- package/dist/createError.js.map +0 -1
- package/dist/debug.d.ts +0 -2
- package/dist/debug.js +0 -21
- package/dist/debug.js.map +0 -1
- package/dist/file/fetch.d.ts +0 -6
- package/dist/file/fetch.js +0 -27
- package/dist/file/fetch.js.map +0 -1
- package/dist/file/getUrl.d.ts +0 -4
- package/dist/file/getUrl.js +0 -42
- package/dist/file/getUrl.js.map +0 -1
- package/dist/file/index.d.ts +0 -6
- package/dist/file/index.js +0 -95
- package/dist/file/index.js.map +0 -1
- package/dist/file/stream/browser.d.ts +0 -7
- package/dist/file/stream/browser.js +0 -17
- package/dist/file/stream/browser.js.map +0 -1
- package/dist/file/stream/index.d.ts +0 -7
- package/dist/file/stream/index.js +0 -86
- package/dist/file/stream/index.js.map +0 -1
- package/dist/file/uploadFileBrowser.d.ts +0 -3
- package/dist/file/uploadFileBrowser.js +0 -72
- package/dist/file/uploadFileBrowser.js.map +0 -1
- package/dist/findPrefix.d.ts +0 -3
- package/dist/findPrefix.js +0 -20
- package/dist/findPrefix.js.map +0 -1
- package/dist/idleTimeout.d.ts +0 -3
- package/dist/idleTimeout.js +0 -17
- package/dist/idleTimeout.js.map +0 -1
- package/dist/observable/index.d.ts +0 -28
- package/dist/observable/index.js +0 -84
- package/dist/observable/index.js.map +0 -1
- package/dist/printBasedObject.d.ts +0 -4
- package/dist/printBasedObject.js +0 -76
- package/dist/printBasedObject.js.map +0 -1
- package/dist/queue.d.ts +0 -5
- package/dist/queue.js +0 -53
- package/dist/queue.js.map +0 -1
- package/dist/request.d.ts +0 -6
- package/dist/request.js +0 -67
- package/dist/request.js.map +0 -1
- package/dist/selvaTypes/get.d.ts +0 -97
- package/dist/selvaTypes/get.js.map +0 -1
- package/dist/selvaTypes/schema.d.ts +0 -89
- package/dist/selvaTypes/schema.js.map +0 -1
- package/dist/selvaTypes/set.d.ts +0 -73
- package/dist/selvaTypes/set.js.map +0 -1
- package/dist/subscriptions/addGetSubscriber.d.ts +0 -3
- package/dist/subscriptions/addGetSubscriber.js +0 -87
- package/dist/subscriptions/addGetSubscriber.js.map +0 -1
- package/dist/subscriptions/addSubscriber.d.ts +0 -2
- package/dist/subscriptions/addSubscriber.js +0 -136
- package/dist/subscriptions/addSubscriber.js.map +0 -1
- package/dist/subscriptions/generateId.d.ts +0 -1
- package/dist/subscriptions/generateId.js +0 -11
- package/dist/subscriptions/generateId.js.map +0 -1
- package/dist/subscriptions/incomingSubscription.d.ts +0 -3
- package/dist/subscriptions/incomingSubscription.js +0 -87
- package/dist/subscriptions/incomingSubscription.js.map +0 -1
- package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -3
- package/dist/subscriptions/incomingSubscriptionDiff.js +0 -85
- package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -1
- package/dist/subscriptions/index.d.ts +0 -10
- package/dist/subscriptions/index.js.map +0 -1
- package/dist/subscriptions/logoutSubscriptions.d.ts +0 -3
- package/dist/subscriptions/logoutSubscriptions.js +0 -36
- package/dist/subscriptions/logoutSubscriptions.js.map +0 -1
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -2
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -14
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -1
- package/dist/subscriptions/removeSubscriber.d.ts +0 -2
- package/dist/subscriptions/removeSubscriber.js +0 -44
- package/dist/subscriptions/removeSubscriber.js.map +0 -1
- package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -2
- package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -14
- package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -1
- package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -2
- package/dist/subscriptions/sendAllSubscriptions.js +0 -114
- package/dist/subscriptions/sendAllSubscriptions.js.map +0 -1
- package/dist/token.d.ts +0 -4
- package/dist/token.js +0 -35
- package/dist/token.js.map +0 -1
- package/dist/track.d.ts +0 -8
- package/dist/track.js +0 -71
- package/dist/track.js.map +0 -1
- package/docs/auth-based-ui-howto.md +0 -74
- package/docs/auth-howto.md +0 -166
- package/docs/auth.md +0 -93
- package/docs/authorize.md +0 -56
- package/docs/files.md +0 -66
- package/docs/get-started.md +0 -60
- package/docs/get.md +0 -759
- package/docs/schema.md +0 -244
- package/docs/set.md +0 -652
|
@@ -0,0 +1,114 @@
|
|
|
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 opts_1 = __importDefault(require("@based/opts"));
|
|
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
|
+
const url = await (0, opts_1.default)(client.opts, true);
|
|
96
|
+
const headers = {
|
|
97
|
+
'Content-Length': String(options.size),
|
|
98
|
+
'Content-Type': options.mimeType || 'text/plain',
|
|
99
|
+
Authorization: (0, __1.encodeAuthState)(client.authState),
|
|
100
|
+
};
|
|
101
|
+
if (options.fileName) {
|
|
102
|
+
headers['Content-Name'] = options.fileName;
|
|
103
|
+
}
|
|
104
|
+
if (!options.mimeType && options.extension) {
|
|
105
|
+
headers['Content-Extension'] = options.extension;
|
|
106
|
+
}
|
|
107
|
+
let q = '';
|
|
108
|
+
if (options.payload) {
|
|
109
|
+
q = '?' + (0, utils_1.serializeQuery)(options.payload);
|
|
110
|
+
}
|
|
111
|
+
return streamRequest(options.contents, name, url, headers, q);
|
|
112
|
+
};
|
|
113
|
+
exports.uploadFileStream = uploadFileStream;
|
|
114
|
+
//# 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;AACjD,uDAAmC;AACnC,0CAAwD;AACxD,wCAA6C;AAE7C,MAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,IAAI,CAAC,CAAA;AAE/B,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAAoC,EAAE;IACzE,IAAI;QACF,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1B,OAAO;YACL,IAAI,EAAE,CAAC,CAAC,IAAI;SACb,CAAA;KACF;IAAC,OAAO,GAAG,EAAE,GAAE;AAClB,CAAC,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,QAAa,EAAwB,EAAE;IAC9D,OAAO,QAAQ,YAAY,iBAAQ,CAAA;AACrC,CAAC,CAAA;AAFY,QAAA,QAAQ,YAEpB;AAED,MAAM,UAAU,GAAG,uDAAuD,CAAA;AAEnE,MAAM,cAAc,GAAG,KAAK,EACjC,MAAmB,EACnB,IAAY,EACZ,OAA2B,EAC3B,EAAE;IACF,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1C,IAAI,IAAI,EAAE;QACR,OAAO,IAAA,wBAAgB,EAAC,MAAM,EAAE,IAAI,EAAE;YACpC,QAAQ,EAAE,YAAE,CAAC,g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AC;QACtC,cAAc,EAAE,OAAO,CAAC,QAAQ,IAAI,YAAY;QAChD,aAAa,EAAE,IAAA,mBAAe,EAAC,MAAM,CAAC,SAAS,CAAC;KACjD,CAAA;IAED,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAA;KAC3C;IAED,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE;QAC1C,OAAO,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,SAAS,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;AApCY,QAAA,gBAAgB,oBAoC5B"}
|
|
@@ -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,106 @@
|
|
|
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 opts_1 = __importDefault(require("@based/opts"));
|
|
8
|
+
const error_1 = require("../types/error");
|
|
9
|
+
const inProgress = {};
|
|
10
|
+
const queue = {};
|
|
11
|
+
const reject = (err, q) => {
|
|
12
|
+
q.forEach((item) => {
|
|
13
|
+
item.reject(err);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const drainQueue = (client, functionName, authorization) => {
|
|
17
|
+
if (!inProgress[functionName]) {
|
|
18
|
+
inProgress[functionName] = true;
|
|
19
|
+
setTimeout(async () => {
|
|
20
|
+
inProgress[functionName] = false;
|
|
21
|
+
const url = await (0, opts_1.default)(client.opts, true);
|
|
22
|
+
const q = queue[functionName];
|
|
23
|
+
queue[functionName] = [];
|
|
24
|
+
const body = new global.FormData();
|
|
25
|
+
for (let i = 0; i < q.length; i++) {
|
|
26
|
+
const options = q[i].options;
|
|
27
|
+
const { contents, payload } = options;
|
|
28
|
+
const p = payload || {};
|
|
29
|
+
body.append(`size=${contents.size},${JSON.stringify(p)}`, contents);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const xhr = new global.XMLHttpRequest();
|
|
33
|
+
xhr.upload.onprogress = (p) => {
|
|
34
|
+
const progress =
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
(p.loaded || p.position) / (p.totalSize || p.total);
|
|
37
|
+
q.forEach((item) => {
|
|
38
|
+
if (item.progressListener) {
|
|
39
|
+
item.progressListener(progress, q.length);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
xhr.onerror = (p) => {
|
|
44
|
+
if (xhr.status === 0 && !xhr.statusText) {
|
|
45
|
+
const err = (0, error_1.convertDataToBasedError)({
|
|
46
|
+
message: `[${functionName}] Function not found`,
|
|
47
|
+
code: error_1.BasedErrorCode.FunctionNotFound,
|
|
48
|
+
});
|
|
49
|
+
reject(err, q);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// go handle this!
|
|
53
|
+
console.error(p);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
xhr.timeout = 1e3 * 60 * 60 * 24;
|
|
57
|
+
xhr.onabort = () => {
|
|
58
|
+
const err = new Error('File upload aborted before it finished');
|
|
59
|
+
reject(err, q);
|
|
60
|
+
};
|
|
61
|
+
xhr.ontimeout = () => {
|
|
62
|
+
console.error('on timeout');
|
|
63
|
+
};
|
|
64
|
+
xhr.onload = () => {
|
|
65
|
+
try {
|
|
66
|
+
const x = JSON.parse(xhr.response);
|
|
67
|
+
for (let i = 0; i < x.length; i++) {
|
|
68
|
+
const result = x[i];
|
|
69
|
+
if (result.error) {
|
|
70
|
+
q[i].reject((0, error_1.convertDataToBasedError)(result.error));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
q[i].resolve(x[i].value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
reject(err, q);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
xhr.open('POST', url + '/' + functionName);
|
|
82
|
+
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
|
|
83
|
+
xhr.setRequestHeader('Authorization', authorization);
|
|
84
|
+
xhr.send(body);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.warn('Something unexpected happened with file upload', err);
|
|
88
|
+
reject(err, q);
|
|
89
|
+
}
|
|
90
|
+
}, 500);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.default = async (client, functionName, options, progressListener) => {
|
|
94
|
+
if (!client.connected) {
|
|
95
|
+
await client.once('connect');
|
|
96
|
+
}
|
|
97
|
+
// TODO: key is something special
|
|
98
|
+
if (!queue[functionName]) {
|
|
99
|
+
queue[functionName] = [];
|
|
100
|
+
}
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
queue[functionName].push({ options, resolve, reject, progressListener });
|
|
103
|
+
drainQueue(client, functionName, (0, __1.encodeAuthState)(client.authState));
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=uploadFileBrowser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadFileBrowser.js","sourceRoot":"","sources":["../../src/stream/uploadFileBrowser.ts"],"names":[],"mappings":";;;;;AAAA,0BAAiD;AAEjD,uDAAmC;AACnC,0CAAwE;AACxE,MAAM,UAAU,GAA+B,EAAE,CAAA;AASjD,MAAM,KAAK,GAEP,EAAE,CAAA;AAEN,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,IAAA,cAAS,EAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAC9C,MAAM,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAA;YAE7B,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;YACxB,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAA;YAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACj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AC,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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":""}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../../src/types/channel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
IncorrectAccessKey = 40031
|
|
23
|
+
}
|
|
24
|
+
export type BasedErrorData = {
|
|
25
|
+
message: string;
|
|
26
|
+
stack?: string;
|
|
27
|
+
requestId?: number;
|
|
28
|
+
observableId?: number;
|
|
29
|
+
channelId?: number;
|
|
30
|
+
code: BasedErrorCode;
|
|
31
|
+
statusCode?: number;
|
|
32
|
+
};
|
|
33
|
+
export declare class BasedError extends Error {
|
|
34
|
+
statusMessage?: string;
|
|
35
|
+
code: BasedErrorCode;
|
|
36
|
+
}
|
|
37
|
+
export declare const convertDataToBasedError: (payload: BasedErrorData, stack?: string) => BasedError;
|
|
@@ -0,0 +1,41 @@
|
|
|
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[BasedErrorCode["IncorrectAccessKey"] = 40031] = "IncorrectAccessKey";
|
|
27
|
+
})(BasedErrorCode = exports.BasedErrorCode || (exports.BasedErrorCode = {}));
|
|
28
|
+
class BasedError extends Error {
|
|
29
|
+
}
|
|
30
|
+
exports.BasedError = BasedError;
|
|
31
|
+
const convertDataToBasedError = (payload, stack) => {
|
|
32
|
+
const { message, code } = payload;
|
|
33
|
+
const msg = message[0] === '[' ? message : `[${BasedErrorCode[code]}] ` + message;
|
|
34
|
+
const error = new BasedError(msg);
|
|
35
|
+
error.stack = stack ? msg + ' ' + stack : msg;
|
|
36
|
+
error.name = BasedErrorCode[code];
|
|
37
|
+
error.code = code;
|
|
38
|
+
return error;
|
|
39
|
+
};
|
|
40
|
+
exports.convertDataToBasedError = convertDataToBasedError;
|
|
41
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/types/error.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAsBX;AAtBD,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;IACtC,mFAA0B,CAAA;AAC5B,CAAC,EAtBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAsBzB;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 {};
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/types/functions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type GenericObject = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type BasedUrlFn = () => Promise<string>;
|
|
5
|
+
export type BasedOpts = {
|
|
6
|
+
env?: string;
|
|
7
|
+
project?: string;
|
|
8
|
+
org?: string;
|
|
9
|
+
cluster?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
key?: string;
|
|
12
|
+
optionalKey?: boolean;
|
|
13
|
+
url?: string | BasedUrlFn;
|
|
14
|
+
discoveryUrls?: string[];
|
|
15
|
+
params?: {
|
|
16
|
+
[key: string]: string | number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type Settings = {
|
|
20
|
+
maxCacheSize?: number;
|
|
21
|
+
persistentStorage?: string;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../src/types/generic.ts"],"names":[],"mappings":""}
|
|
@@ -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("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../../src/types/observe.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Connection } from './types';
|
|
2
|
-
import { BasedClient } from '
|
|
2
|
+
import { BasedClient } from '..';
|
|
3
3
|
declare const connect: (client: BasedClient, url: string | (() => Promise<string>), connection?: Connection, time?: number, reconnect?: boolean) => Connection;
|
|
4
4
|
export default connect;
|