@fidscript/instant-react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EventSourceImpl.d.ts +10 -0
- package/dist/EventSourceImpl.d.ts.map +1 -0
- package/dist/EventSourceImpl.js +9 -0
- package/dist/EventSourceImpl.js.map +1 -0
- package/dist/EventSourceShim.d.ts +31 -0
- package/dist/EventSourceShim.d.ts.map +1 -0
- package/dist/EventSourceShim.js +228 -0
- package/dist/EventSourceShim.js.map +1 -0
- package/dist/NetworkListener.d.ts +5 -0
- package/dist/NetworkListener.d.ts.map +1 -0
- package/dist/NetworkListener.js +19 -0
- package/dist/NetworkListener.js.map +1 -0
- package/dist/Storage.d.ts +3 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/Storage.js +5 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Storage.native.d.ts +22 -0
- package/dist/Storage.native.d.ts.map +1 -0
- package/dist/Storage.native.js +79 -0
- package/dist/Storage.native.js.map +1 -0
- package/dist/Streams.d.ts +15 -0
- package/dist/Streams.d.ts.map +1 -0
- package/dist/Streams.js +9 -0
- package/dist/Streams.js.map +1 -0
- package/dist/Streams.native.d.ts +6 -0
- package/dist/Streams.native.d.ts.map +1 -0
- package/dist/Streams.native.js +9 -0
- package/dist/Streams.native.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +18 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/module/EventSourceImpl.d.ts +10 -0
- package/dist/module/EventSourceImpl.d.ts.map +1 -0
- package/dist/module/EventSourceImpl.js +4 -0
- package/dist/module/EventSourceImpl.js.map +1 -0
- package/dist/module/EventSourceShim.d.ts +31 -0
- package/dist/module/EventSourceShim.d.ts.map +1 -0
- package/dist/module/EventSourceShim.js +226 -0
- package/dist/module/EventSourceShim.js.map +1 -0
- package/dist/module/NetworkListener.d.ts +5 -0
- package/dist/module/NetworkListener.d.ts.map +1 -0
- package/dist/module/NetworkListener.js +13 -0
- package/dist/module/NetworkListener.js.map +1 -0
- package/dist/module/Storage.d.ts +3 -0
- package/dist/module/Storage.d.ts.map +1 -0
- package/dist/module/Storage.js +3 -0
- package/dist/module/Storage.js.map +1 -0
- package/dist/module/Storage.native.d.ts +22 -0
- package/dist/module/Storage.native.d.ts.map +1 -0
- package/dist/module/Storage.native.js +75 -0
- package/dist/module/Storage.native.js.map +1 -0
- package/dist/module/Streams.d.ts +15 -0
- package/dist/module/Streams.d.ts.map +1 -0
- package/dist/module/Streams.js +6 -0
- package/dist/module/Streams.js.map +1 -0
- package/dist/module/Streams.native.d.ts +6 -0
- package/dist/module/Streams.native.d.ts.map +1 -0
- package/dist/module/Streams.native.js +6 -0
- package/dist/module/Streams.native.js.map +1 -0
- package/dist/module/cli.d.ts +2 -0
- package/dist/module/cli.d.ts.map +1 -0
- package/dist/module/cli.js +2 -0
- package/dist/module/cli.js.map +1 -0
- package/dist/module/index.d.ts +56 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +76 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/version.d.ts +3 -0
- package/dist/module/version.d.ts.map +1 -0
- package/dist/module/version.js +3 -0
- package/dist/module/version.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +49 -0
- package/src/EventSourceImpl.ts +6 -0
- package/src/EventSourceShim.ts +285 -0
- package/src/NetworkListener.js +13 -0
- package/src/Storage.js +3 -0
- package/src/Storage.native.ts +91 -0
- package/src/Streams.native.ts +6 -0
- package/src/Streams.ts +5 -0
- package/src/__types__/typeUtils.ts +39 -0
- package/src/__types__/typesTests.ts +86 -0
- package/src/cli.ts +1 -0
- package/src/index.ts +290 -0
- package/src/version.ts +2 -0
- package/tsconfig.json +16 -0
- package/tsconfig.module.json +13 -0
- package/tsconfig.test.json +5 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import EventSourceShim from './EventSourceShim';
|
|
2
|
+
declare const EventSourceImpl: typeof EventSourceShim | {
|
|
3
|
+
new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource;
|
|
4
|
+
prototype: EventSource;
|
|
5
|
+
readonly CONNECTING: 0;
|
|
6
|
+
readonly OPEN: 1;
|
|
7
|
+
readonly CLOSED: 2;
|
|
8
|
+
};
|
|
9
|
+
export default EventSourceImpl;
|
|
10
|
+
//# sourceMappingURL=EventSourceImpl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSourceImpl.d.ts","sourceRoot":"","sources":["../src/EventSourceImpl.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,QAAA,MAAM,eAAe;;;;;;CAC+C,CAAC;AAErE,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 EventSourceShim_1 = __importDefault(require("./EventSourceShim"));
|
|
7
|
+
const EventSourceImpl = typeof EventSource === 'undefined' ? EventSourceShim_1.default : EventSource;
|
|
8
|
+
exports.default = EventSourceImpl;
|
|
9
|
+
//# sourceMappingURL=EventSourceImpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSourceImpl.js","sourceRoot":"","sources":["../src/EventSourceImpl.ts"],"names":[],"mappings":";;;;;AAAA,wEAAgD;AAEhD,MAAM,eAAe,GACnB,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,yBAAe,CAAC,CAAC,CAAC,WAAW,CAAC;AAErE,kBAAe,eAAe,CAAC","sourcesContent":["import EventSourceShim from './EventSourceShim';\n\nconst EventSourceImpl =\n typeof EventSource === 'undefined' ? EventSourceShim : EventSource;\n\nexport default EventSourceImpl;\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type EventSourceType } from '@fidscript/instant-sdk';
|
|
2
|
+
declare class EventSource implements EventSourceType {
|
|
3
|
+
private ERROR;
|
|
4
|
+
static CONNECTING: number;
|
|
5
|
+
static OPEN: number;
|
|
6
|
+
static CLOSED: number;
|
|
7
|
+
private CRLF;
|
|
8
|
+
private LF;
|
|
9
|
+
private CR;
|
|
10
|
+
readonly url: string;
|
|
11
|
+
onopen: any;
|
|
12
|
+
onerror: any;
|
|
13
|
+
onmessage: any;
|
|
14
|
+
debug: boolean;
|
|
15
|
+
private status;
|
|
16
|
+
private headers;
|
|
17
|
+
private _xhr;
|
|
18
|
+
private lineEndingCharacter;
|
|
19
|
+
private _lastIndexProcessed;
|
|
20
|
+
constructor(url: any);
|
|
21
|
+
get readyState(): number;
|
|
22
|
+
open(): void;
|
|
23
|
+
_logDebug(...msg: any[]): void;
|
|
24
|
+
_handleEvent(response: any): void;
|
|
25
|
+
_detectNewlineChar(response: any): string | null;
|
|
26
|
+
_getLastDoubleNewlineIndex(response: any): any;
|
|
27
|
+
dispatch(type: any, data: any): void;
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
30
|
+
export default EventSource;
|
|
31
|
+
//# sourceMappingURL=EventSourceShim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSourceShim.d.ts","sourceRoot":"","sources":["../src/EventSourceShim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAa9D,cAAM,WAAY,YAAW,eAAe;IAC1C,OAAO,CAAC,KAAK,CAAM;IACnB,MAAM,CAAC,UAAU,SAAK;IACtB,MAAM,CAAC,IAAI,SAAK;IAChB,MAAM,CAAC,MAAM,SAAK;IAElB,OAAO,CAAC,IAAI,CAAU;IACtB,OAAO,CAAC,EAAE,CAAQ;IAClB,OAAO,CAAC,EAAE,CAAQ;IAElB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,MAAM,MAAC;IACP,OAAO,MAAC;IACR,SAAS,MAAC;IAEV,KAAK,EAAE,OAAO,CAAC;IAEf,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,OAAO,CAIb;IAEF,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,mBAAmB,CAAS;gBAExB,GAAG,KAAA;IAiBf,IAAW,UAAU,WAKpB;IAED,IAAI;IA8FJ,SAAS,CAAC,GAAG,GAAG,OAAA;IAMhB,YAAY,CAAC,QAAQ,KAAA;IA8DrB,kBAAkB,CAAC,QAAQ,KAAA;IAU3B,0BAA0B,CAAC,QAAQ,KAAA;IAWnC,QAAQ,CAAC,IAAI,KAAA,EAAE,IAAI,KAAA;IAuBnB,KAAK;CASN;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Modified version of https://github.com/binaryminds/react-native-sse/blob/master/src/EventSource.js
|
|
4
|
+
// that conforms to our `EventSourceType` subset of the browser-native `EventSource`.
|
|
5
|
+
const XMLReadyStateMap = [
|
|
6
|
+
'UNSENT',
|
|
7
|
+
'OPENED',
|
|
8
|
+
'HEADERS_RECEIVED',
|
|
9
|
+
'LOADING',
|
|
10
|
+
'DONE',
|
|
11
|
+
];
|
|
12
|
+
class EventSource {
|
|
13
|
+
ERROR = -1;
|
|
14
|
+
static CONNECTING = 0;
|
|
15
|
+
static OPEN = 1;
|
|
16
|
+
static CLOSED = 2;
|
|
17
|
+
CRLF = '\r\n';
|
|
18
|
+
LF = '\n';
|
|
19
|
+
CR = '\r';
|
|
20
|
+
url;
|
|
21
|
+
onopen;
|
|
22
|
+
onerror;
|
|
23
|
+
onmessage;
|
|
24
|
+
debug;
|
|
25
|
+
status;
|
|
26
|
+
headers = {
|
|
27
|
+
Accept: 'text/event-stream',
|
|
28
|
+
'Cache-Control': 'no-cache',
|
|
29
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
30
|
+
};
|
|
31
|
+
_xhr;
|
|
32
|
+
lineEndingCharacter;
|
|
33
|
+
_lastIndexProcessed;
|
|
34
|
+
constructor(url) {
|
|
35
|
+
this.status = EventSource.CONNECTING;
|
|
36
|
+
this.lineEndingCharacter = null;
|
|
37
|
+
this._xhr = null;
|
|
38
|
+
this._lastIndexProcessed = 0;
|
|
39
|
+
this.debug = false;
|
|
40
|
+
if (!url || typeof url !== 'string') {
|
|
41
|
+
throw new SyntaxError('[EventSource] Invalid URL argument.');
|
|
42
|
+
}
|
|
43
|
+
this.url = url;
|
|
44
|
+
this.open();
|
|
45
|
+
}
|
|
46
|
+
get readyState() {
|
|
47
|
+
if (this.status === this.ERROR) {
|
|
48
|
+
return EventSource.CLOSED;
|
|
49
|
+
}
|
|
50
|
+
return this.status;
|
|
51
|
+
}
|
|
52
|
+
open() {
|
|
53
|
+
try {
|
|
54
|
+
this.status = EventSource.CONNECTING;
|
|
55
|
+
this._lastIndexProcessed = 0;
|
|
56
|
+
this._xhr = new XMLHttpRequest();
|
|
57
|
+
this._xhr.open('GET', this.url, true);
|
|
58
|
+
for (const [key, value] of Object.entries(this.headers)) {
|
|
59
|
+
if (value !== undefined && value !== null) {
|
|
60
|
+
this._xhr.setRequestHeader(key, value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
this._xhr.onreadystatechange = () => {
|
|
64
|
+
if (this.status === EventSource.CLOSED) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const xhr = this._xhr;
|
|
68
|
+
this._logDebug(`[EventSource][onreadystatechange] ReadyState: ${XMLReadyStateMap[xhr.readyState] || 'Unknown'}(${xhr.readyState}), status: ${xhr.status}`);
|
|
69
|
+
if (xhr.readyState !== XMLHttpRequest.DONE &&
|
|
70
|
+
xhr.readyState !== XMLHttpRequest.LOADING) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (xhr.status >= 200 && xhr.status < 400) {
|
|
74
|
+
if (this.status === EventSource.CONNECTING) {
|
|
75
|
+
this.status = EventSource.OPEN;
|
|
76
|
+
this.dispatch('open', { type: 'open' });
|
|
77
|
+
this._logDebug('[EventSource][onreadystatechange][OPEN] Connection opened.');
|
|
78
|
+
}
|
|
79
|
+
this._handleEvent(xhr.responseText || '');
|
|
80
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
81
|
+
this._logDebug('[EventSource][onreadystatechange][DONE] Operation done.');
|
|
82
|
+
this.dispatch('error', { type: 'error' });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (xhr.status !== 0) {
|
|
86
|
+
this.status = this.ERROR;
|
|
87
|
+
this.dispatch('error', {
|
|
88
|
+
type: 'error',
|
|
89
|
+
message: xhr.responseText,
|
|
90
|
+
xhrStatus: xhr.status,
|
|
91
|
+
xhrState: xhr.readyState,
|
|
92
|
+
});
|
|
93
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
94
|
+
this._logDebug('[EventSource][onreadystatechange][ERROR] Response status error.');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
this._xhr.onerror = () => {
|
|
99
|
+
if (this.status === EventSource.CLOSED) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.status = this.ERROR;
|
|
103
|
+
this.dispatch('error', {
|
|
104
|
+
type: 'error',
|
|
105
|
+
message: this._xhr.responseText,
|
|
106
|
+
xhrStatus: this._xhr.status,
|
|
107
|
+
xhrState: this._xhr.readyState,
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
this._xhr.send();
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
this.status = this.ERROR;
|
|
114
|
+
this.dispatch('error', {
|
|
115
|
+
type: 'exception',
|
|
116
|
+
message: e.message,
|
|
117
|
+
error: e,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
_logDebug(...msg) {
|
|
122
|
+
if (this.debug) {
|
|
123
|
+
console.debug(...msg);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
_handleEvent(response) {
|
|
127
|
+
if (this.lineEndingCharacter === null) {
|
|
128
|
+
const detectedNewlineChar = this._detectNewlineChar(response);
|
|
129
|
+
if (detectedNewlineChar !== null) {
|
|
130
|
+
this._logDebug(`[EventSource] Automatically detected lineEndingCharacter: ${JSON.stringify(detectedNewlineChar).slice(1, -1)}`);
|
|
131
|
+
this.lineEndingCharacter = detectedNewlineChar;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.warn("[EventSource] Unable to identify the line ending character. Ensure your server delivers a standard line ending character: \\r\\n, \\n, \\r, or specify your custom character using the 'lineEndingCharacter' option.");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const indexOfDoubleNewline = this._getLastDoubleNewlineIndex(response);
|
|
139
|
+
if (indexOfDoubleNewline <= this._lastIndexProcessed) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const parts = response
|
|
143
|
+
.substring(this._lastIndexProcessed, indexOfDoubleNewline)
|
|
144
|
+
.split(this.lineEndingCharacter);
|
|
145
|
+
this._lastIndexProcessed = indexOfDoubleNewline;
|
|
146
|
+
let type = undefined;
|
|
147
|
+
let data = [];
|
|
148
|
+
let line = '';
|
|
149
|
+
for (let i = 0; i < parts.length; i++) {
|
|
150
|
+
line = parts[i].trim();
|
|
151
|
+
if (line.startsWith('event')) {
|
|
152
|
+
type = line.replace(/event:?\s*/, '');
|
|
153
|
+
}
|
|
154
|
+
else if (line.startsWith('retry')) {
|
|
155
|
+
// Ignore for our use case, we'll reconnect with a new
|
|
156
|
+
// instance on error
|
|
157
|
+
}
|
|
158
|
+
else if (line.startsWith('data')) {
|
|
159
|
+
data.push(line.replace(/data:?\s*/, ''));
|
|
160
|
+
}
|
|
161
|
+
else if (line.startsWith('id')) {
|
|
162
|
+
// Ignore this, not used for our use case
|
|
163
|
+
}
|
|
164
|
+
else if (line === '') {
|
|
165
|
+
if (data.length > 0) {
|
|
166
|
+
const eventType = type || 'message';
|
|
167
|
+
const event = {
|
|
168
|
+
type: eventType,
|
|
169
|
+
data: data.join('\n'),
|
|
170
|
+
url: this.url,
|
|
171
|
+
};
|
|
172
|
+
this.dispatch(eventType, event);
|
|
173
|
+
data = [];
|
|
174
|
+
type = undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
_detectNewlineChar(response) {
|
|
180
|
+
const supportedLineEndings = [this.CRLF, this.LF, this.CR];
|
|
181
|
+
for (const char of supportedLineEndings) {
|
|
182
|
+
if (response.includes(char)) {
|
|
183
|
+
return char;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
_getLastDoubleNewlineIndex(response) {
|
|
189
|
+
const doubleLineEndingCharacter = this.lineEndingCharacter + this.lineEndingCharacter;
|
|
190
|
+
const lastIndex = response.lastIndexOf(doubleLineEndingCharacter);
|
|
191
|
+
if (lastIndex === -1) {
|
|
192
|
+
return -1;
|
|
193
|
+
}
|
|
194
|
+
return lastIndex + doubleLineEndingCharacter.length;
|
|
195
|
+
}
|
|
196
|
+
dispatch(type, data) {
|
|
197
|
+
switch (type) {
|
|
198
|
+
case 'open': {
|
|
199
|
+
if (this.onopen) {
|
|
200
|
+
this.onopen(data);
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'error': {
|
|
205
|
+
if (this.onerror) {
|
|
206
|
+
this.onerror(data);
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case 'message': {
|
|
211
|
+
if (this.onmessage) {
|
|
212
|
+
this.onmessage(data);
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
close() {
|
|
219
|
+
if (this.status !== EventSource.CLOSED) {
|
|
220
|
+
this.status = EventSource.CLOSED;
|
|
221
|
+
}
|
|
222
|
+
if (this._xhr) {
|
|
223
|
+
this._xhr.abort();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.default = EventSource;
|
|
228
|
+
//# sourceMappingURL=EventSourceShim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSourceShim.js","sourceRoot":"","sources":["../src/EventSourceShim.ts"],"names":[],"mappings":";;AAEA,qGAAqG;AACrG,qFAAqF;AAErF,MAAM,gBAAgB,GAAG;IACvB,QAAQ;IACR,QAAQ;IACR,kBAAkB;IAClB,SAAS;IACT,MAAM;CACP,CAAC;AAEF,MAAM,WAAW;IACP,KAAK,GAAG,CAAC,CAAC,CAAC;IACnB,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC;IACtB,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;IAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAEV,IAAI,GAAG,MAAM,CAAC;IACd,EAAE,GAAG,IAAI,CAAC;IACV,EAAE,GAAG,IAAI,CAAC;IAET,GAAG,CAAS;IAErB,MAAM,CAAC;IACP,OAAO,CAAC;IACR,SAAS,CAAC;IAEV,KAAK,CAAU;IAEP,MAAM,CAAS;IAEf,OAAO,GAAG;QAChB,MAAM,EAAE,mBAAmB;QAC3B,eAAe,EAAE,UAAU;QAC3B,kBAAkB,EAAE,gBAAgB;KACrC,CAAC;IAEM,IAAI,CAAwB;IAC5B,mBAAmB,CAAgB;IACnC,mBAAmB,CAAS;IAEpC,YAAY,GAAG;QACb,IAAI,CAA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n\n// Modified version of https://github.com/binaryminds/react-native-sse/blob/master/src/EventSource.js\n// that conforms to our `EventSourceType` subset of the browser-native `EventSource`.\n\nconst XMLReadyStateMap = [\n 'UNSENT',\n 'OPENED',\n 'HEADERS_RECEIVED',\n 'LOADING',\n 'DONE',\n];\n\nclass EventSource implements EventSourceType {\n private ERROR = -1;\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSED = 2;\n\n private CRLF = '\\r\\n';\n private LF = '\\n';\n private CR = '\\r';\n\n readonly url: string;\n\n onopen;\n onerror;\n onmessage;\n\n debug: boolean;\n\n private status: number;\n\n private headers = {\n Accept: 'text/event-stream',\n 'Cache-Control': 'no-cache',\n 'X-Requested-With': 'XMLHttpRequest',\n };\n\n private _xhr: XMLHttpRequest | null;\n private lineEndingCharacter: string | null;\n private _lastIndexProcessed: number;\n\n constructor(url) {\n this.status = EventSource.CONNECTING;\n\n this.lineEndingCharacter = null;\n this._xhr = null;\n this._lastIndexProcessed = 0;\n this.debug = false;\n\n if (!url || typeof url !== 'string') {\n throw new SyntaxError('[EventSource] Invalid URL argument.');\n }\n\n this.url = url;\n\n this.open();\n }\n\n public get readyState() {\n if (this.status === this.ERROR) {\n return EventSource.CLOSED;\n }\n return this.status;\n }\n\n open() {\n try {\n this.status = EventSource.CONNECTING;\n\n this._lastIndexProcessed = 0;\n\n this._xhr = new XMLHttpRequest();\n this._xhr.open('GET', this.url, true);\n\n for (const [key, value] of Object.entries(this.headers)) {\n if (value !== undefined && value !== null) {\n this._xhr.setRequestHeader(key, value);\n }\n }\n\n this._xhr.onreadystatechange = () => {\n if (this.status === EventSource.CLOSED) {\n return;\n }\n\n const xhr = this._xhr!;\n\n this._logDebug(\n `[EventSource][onreadystatechange] ReadyState: ${XMLReadyStateMap[xhr.readyState] || 'Unknown'}(${\n xhr.readyState\n }), status: ${xhr.status}`,\n );\n\n if (\n xhr.readyState !== XMLHttpRequest.DONE &&\n xhr.readyState !== XMLHttpRequest.LOADING\n ) {\n return;\n }\n\n if (xhr.status >= 200 && xhr.status < 400) {\n if (this.status === EventSource.CONNECTING) {\n this.status = EventSource.OPEN;\n this.dispatch('open', { type: 'open' });\n this._logDebug(\n '[EventSource][onreadystatechange][OPEN] Connection opened.',\n );\n }\n\n this._handleEvent(xhr.responseText || '');\n\n if (xhr.readyState === XMLHttpRequest.DONE) {\n this._logDebug(\n '[EventSource][onreadystatechange][DONE] Operation done.',\n );\n this.dispatch('error', { type: 'error' });\n }\n } else if (xhr.status !== 0) {\n this.status = this.ERROR;\n this.dispatch('error', {\n type: 'error',\n message: xhr.responseText,\n xhrStatus: xhr.status,\n xhrState: xhr.readyState,\n });\n\n if (xhr.readyState === XMLHttpRequest.DONE) {\n this._logDebug(\n '[EventSource][onreadystatechange][ERROR] Response status error.',\n );\n }\n }\n };\n\n this._xhr.onerror = () => {\n if (this.status === EventSource.CLOSED) {\n return;\n }\n\n this.status = this.ERROR;\n this.dispatch('error', {\n type: 'error',\n message: this._xhr!.responseText,\n xhrStatus: this._xhr!.status,\n xhrState: this._xhr!.readyState,\n });\n };\n\n this._xhr.send();\n } catch (e) {\n this.status = this.ERROR;\n this.dispatch('error', {\n type: 'exception',\n message: e.message,\n error: e,\n });\n }\n }\n\n _logDebug(...msg) {\n if (this.debug) {\n console.debug(...msg);\n }\n }\n\n _handleEvent(response) {\n if (this.lineEndingCharacter === null) {\n const detectedNewlineChar = this._detectNewlineChar(response);\n if (detectedNewlineChar !== null) {\n this._logDebug(\n `[EventSource] Automatically detected lineEndingCharacter: ${JSON.stringify(\n detectedNewlineChar,\n ).slice(1, -1)}`,\n );\n this.lineEndingCharacter = detectedNewlineChar;\n } else {\n console.warn(\n \"[EventSource] Unable to identify the line ending character. Ensure your server delivers a standard line ending character: \\\\r\\\\n, \\\\n, \\\\r, or specify your custom character using the 'lineEndingCharacter' option.\",\n );\n return;\n }\n }\n\n const indexOfDoubleNewline = this._getLastDoubleNewlineIndex(response);\n if (indexOfDoubleNewline <= this._lastIndexProcessed) {\n return;\n }\n\n const parts = response\n .substring(this._lastIndexProcessed, indexOfDoubleNewline)\n .split(this.lineEndingCharacter);\n\n this._lastIndexProcessed = indexOfDoubleNewline;\n\n let type: string | undefined = undefined;\n let data: string[] = [];\n let line = '';\n\n for (let i = 0; i < parts.length; i++) {\n line = parts[i].trim();\n if (line.startsWith('event')) {\n type = line.replace(/event:?\\s*/, '');\n } else if (line.startsWith('retry')) {\n // Ignore for our use case, we'll reconnect with a new\n // instance on error\n } else if (line.startsWith('data')) {\n data.push(line.replace(/data:?\\s*/, ''));\n } else if (line.startsWith('id')) {\n // Ignore this, not used for our use case\n } else if (line === '') {\n if (data.length > 0) {\n const eventType = type || 'message';\n const event = {\n type: eventType,\n data: data.join('\\n'),\n url: this.url,\n };\n\n this.dispatch(eventType, event);\n\n data = [];\n type = undefined;\n }\n }\n }\n }\n\n _detectNewlineChar(response) {\n const supportedLineEndings = [this.CRLF, this.LF, this.CR];\n for (const char of supportedLineEndings) {\n if (response.includes(char)) {\n return char;\n }\n }\n return null;\n }\n\n _getLastDoubleNewlineIndex(response) {\n const doubleLineEndingCharacter =\n this.lineEndingCharacter! + this.lineEndingCharacter!;\n const lastIndex = response.lastIndexOf(doubleLineEndingCharacter);\n if (lastIndex === -1) {\n return -1;\n }\n\n return lastIndex + doubleLineEndingCharacter.length;\n }\n\n dispatch(type, data) {\n switch (type) {\n case 'open': {\n if (this.onopen) {\n this.onopen(data);\n }\n break;\n }\n case 'error': {\n if (this.onerror) {\n this.onerror(data);\n }\n break;\n }\n case 'message': {\n if (this.onmessage) {\n this.onmessage(data);\n }\n break;\n }\n }\n }\n\n close() {\n if (this.status !== EventSource.CLOSED) {\n this.status = EventSource.CLOSED;\n }\n\n if (this._xhr) {\n this._xhr.abort();\n }\n }\n}\n\nexport default EventSource;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkListener.d.ts","sourceRoot":"","sources":["../src/NetworkListener.js"],"names":[],"mappings":"AAEA;IACE,8CAGC;IACD,qFAIC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 netinfo_1 = __importDefault(require("@react-native-community/netinfo"));
|
|
7
|
+
class NetworkListener {
|
|
8
|
+
static async getIsOnline() {
|
|
9
|
+
const network = await netinfo_1.default.fetch();
|
|
10
|
+
return network.isConnected;
|
|
11
|
+
}
|
|
12
|
+
static listen(f) {
|
|
13
|
+
return netinfo_1.default.addEventListener((state) => {
|
|
14
|
+
f(state.isConnected);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = NetworkListener;
|
|
19
|
+
//# sourceMappingURL=NetworkListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkListener.js","sourceRoot":"","sources":["../src/NetworkListener.js"],"names":[],"mappings":";;;;;AAAA,8EAAsD;AAEtD,MAAqB,eAAe;IAClC,MAAM,CAAC,KAAK,CAAC,WAAW;QACtB,MAAM,OAAO,GAAG,MAAM,iBAAO,CAAC,KAAK,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC,WAAW,CAAC;IAC7B,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,CAAC;QACb,OAAO,iBAAO,CAAC,gBAAgB,CAAC,CAAC,KAAK,EAAE,EAAE;YACxC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAVD,kCAUC","sourcesContent":["import NetInfo from '@react-native-community/netinfo';\n\nexport default class NetworkListener {\n static async getIsOnline() {\n const network = await NetInfo.fetch();\n return network.isConnected;\n }\n static listen(f) {\n return NetInfo.addEventListener((state) => {\n f(state.isConnected);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../src/Storage.js"],"names":[],"mappings":";iCAAiC,wBAAwB"}
|
package/dist/Storage.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../src/Storage.js"],"names":[],"mappings":";;AAAA,wDAA0D;AAE1D,kBAAe,8BAAgB,CAAC","sourcesContent":["import { IndexedDBStorage } from '@fidscript/instant-sdk';\n\nexport default IndexedDBStorage;\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StoreInterface, StoreInterfaceStoreName } from '@fidscript/instant-sdk';
|
|
2
|
+
export declare class AsyncStorageStore extends StoreInterface {
|
|
3
|
+
private appId;
|
|
4
|
+
private dbName;
|
|
5
|
+
constructor(appId: string, dbName: StoreInterfaceStoreName);
|
|
6
|
+
private makeKey;
|
|
7
|
+
getItem(k: any): Promise<any>;
|
|
8
|
+
setItem(k: any, v: any): Promise<void>;
|
|
9
|
+
removeItem(k: string): Promise<void>;
|
|
10
|
+
getAllKeys(): Promise<string[]>;
|
|
11
|
+
multiSet(keyValuePairs: Array<[string, any]>): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
declare class MissingStore extends StoreInterface {
|
|
14
|
+
constructor(appId: string, dbName: StoreInterfaceStoreName);
|
|
15
|
+
getItem(_k: string): Promise<any>;
|
|
16
|
+
removeItem(_k: string): Promise<void>;
|
|
17
|
+
multiSet(_keyValuePairs: Array<[string, any]>): Promise<void>;
|
|
18
|
+
getAllKeys(): Promise<string[]>;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: typeof MissingStore;
|
|
21
|
+
export default _default;
|
|
22
|
+
//# sourceMappingURL=Storage.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.native.d.ts","sourceRoot":"","sources":["../src/Storage.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAkBjF,qBAAa,iBAAkB,SAAQ,cAAc;IACnD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA0B;gBAC5B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB;IAM1D,OAAO,CAAC,OAAO;IAIT,OAAO,CAAC,CAAC,KAAA;IAMT,OAAO,CAAC,CAAC,KAAA,EAAE,CAAC,KAAA;IAIZ,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpC,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAY/B,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAKnE;AAED,cAAM,YAAa,SAAQ,cAAc;gBAC3B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB;IAYpD,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIjC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAErC,QAAQ,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7D,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAGtC;;AAED,wBAA+D"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncStorageStore = void 0;
|
|
4
|
+
const instant_sdk_1 = require("@fidscript/instant-sdk");
|
|
5
|
+
const version = 5;
|
|
6
|
+
// AsyncStorage is an optional peer dependency. The `require` must sit
|
|
7
|
+
// directly inside a `try` block: that's what makes Metro treat it as an
|
|
8
|
+
// optional dependency (`transformer.allowOptionalDependencies`, enabled by
|
|
9
|
+
// default in the Expo and React Native metro configs), so bundling doesn't
|
|
10
|
+
// fail when it isn't installed. When it can't be loaded, `init` surfaces a
|
|
11
|
+
// helpful error unless a custom `Store` is passed.
|
|
12
|
+
let AsyncStorage = null;
|
|
13
|
+
let asyncStorageLoadError = null;
|
|
14
|
+
try {
|
|
15
|
+
AsyncStorage = require('@react-native-async-storage/async-storage').default;
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
asyncStorageLoadError = e;
|
|
19
|
+
}
|
|
20
|
+
class AsyncStorageStore extends instant_sdk_1.StoreInterface {
|
|
21
|
+
appId;
|
|
22
|
+
dbName;
|
|
23
|
+
constructor(appId, dbName) {
|
|
24
|
+
super(appId, dbName);
|
|
25
|
+
this.appId = appId;
|
|
26
|
+
this.dbName = dbName;
|
|
27
|
+
}
|
|
28
|
+
makeKey(k) {
|
|
29
|
+
return `instant_${this.appId}_${version}_${this.dbName}_${k}`;
|
|
30
|
+
}
|
|
31
|
+
async getItem(k) {
|
|
32
|
+
const res = await AsyncStorage.getItem(this.makeKey(k));
|
|
33
|
+
if (res === null)
|
|
34
|
+
return res;
|
|
35
|
+
return JSON.parse(res);
|
|
36
|
+
}
|
|
37
|
+
async setItem(k, v) {
|
|
38
|
+
await AsyncStorage.setItem(this.makeKey(k), JSON.stringify(v));
|
|
39
|
+
}
|
|
40
|
+
async removeItem(k) {
|
|
41
|
+
await AsyncStorage.removeItem(this.makeKey(k));
|
|
42
|
+
}
|
|
43
|
+
async getAllKeys() {
|
|
44
|
+
const allKeys = await AsyncStorage.getAllKeys();
|
|
45
|
+
const keys = [];
|
|
46
|
+
const keyPrefix = this.makeKey('');
|
|
47
|
+
for (const key of allKeys) {
|
|
48
|
+
if (key.startsWith(keyPrefix)) {
|
|
49
|
+
keys.push(key.substring(keyPrefix.length));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return keys;
|
|
53
|
+
}
|
|
54
|
+
async multiSet(keyValuePairs) {
|
|
55
|
+
await AsyncStorage.multiSet(keyValuePairs.map(([k, v]) => [this.makeKey(k), JSON.stringify(v)]));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AsyncStorageStore = AsyncStorageStore;
|
|
59
|
+
class MissingStore extends instant_sdk_1.StoreInterface {
|
|
60
|
+
constructor(appId, dbName) {
|
|
61
|
+
super(appId, dbName);
|
|
62
|
+
throw new Error('Instant needs a store to persist data on device. ' +
|
|
63
|
+
'Install `@react-native-async-storage/async-storage`, ' +
|
|
64
|
+
'or pass a `Store` to `init` (e.g. from `@instantdb/react-native-mmkv` or `@instantdb/expo-sqlite`).' +
|
|
65
|
+
(asyncStorageLoadError
|
|
66
|
+
? `\n\nLoading async-storage failed with: ${asyncStorageLoadError}`
|
|
67
|
+
: ''));
|
|
68
|
+
}
|
|
69
|
+
async getItem(_k) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
async removeItem(_k) { }
|
|
73
|
+
async multiSet(_keyValuePairs) { }
|
|
74
|
+
async getAllKeys() {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.default = AsyncStorage ? AsyncStorageStore : MissingStore;
|
|
79
|
+
//# sourceMappingURL=Storage.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.native.js","sourceRoot":"","sources":["../src/Storage.native.ts"],"names":[],"mappings":";;;AAAA,wDAAiF;AAEjF,MAAM,OAAO,GAAG,CAAC,CAAC;AAElB,sEAAsE;AACtE,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,mDAAmD;AACnD,IAAI,YAAY,GAAQ,IAAI,CAAC;AAC7B,IAAI,qBAAqB,GAAY,IAAI,CAAC;AAC1C,IAAI,CAAC;IACH,YAAY,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC;AAAC,OAAO,CAAC,EAAE,C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AC;YAC1B,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,aAAmC;QAChD,MAAM,YAAY,CAAC,QAAQ,CACzB,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CACpE,CAAC;IACJ,CAAC;CACF;AA5CD,8CA4CC;AAED,MAAM,YAAa,SAAQ,4BAAc;IACvC,YAAY,KAAa,EAAE,MAA+B;QACxD,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,mDAAmD;YACjD,uDAAuD;YACvD,qGAAqG;YACrG,CAAC,qBAAqB;gBACpB,CAAC,CAAC,0CAA0C,qBAAqB,EAAE;gBACnE,CAAC,CAAC,EAAE,CAAC,CACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,IAAkB,CAAC;IAE9C,KAAK,CAAC,QAAQ,CAAC,cAAoC,IAAkB,CAAC;IAEtE,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED,kBAAe,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC","sourcesContent":["import { StoreInterface, StoreInterfaceStoreName } from '@fidscript/instant-sdk';\n\nconst version = 5;\n\n// AsyncStorage is an optional peer dependency. The `require` must sit\n// directly inside a `try` block: that's what makes Metro treat it as an\n// optional dependency (`transformer.allowOptionalDependencies`, enabled by\n// default in the Expo and React Native metro configs), so bundling doesn't\n// fail when it isn't installed. When it can't be loaded, `init` surfaces a\n// helpful error unless a custom `Store` is passed.\nlet AsyncStorage: any = null;\nlet asyncStorageLoadError: unknown = null;\ntry {\n AsyncStorage = require('@react-native-async-storage/async-storage').default;\n} catch (e) {\n asyncStorageLoadError = e;\n}\n\nexport class AsyncStorageStore extends StoreInterface {\n private appId: string;\n private dbName: StoreInterfaceStoreName;\n constructor(appId: string, dbName: StoreInterfaceStoreName) {\n super(appId, dbName);\n this.appId = appId;\n this.dbName = dbName;\n }\n\n private makeKey(k: string): string {\n return `instant_${this.appId}_${version}_${this.dbName}_${k}`;\n }\n\n async getItem(k) {\n const res = await AsyncStorage.getItem(this.makeKey(k));\n if (res === null) return res;\n return JSON.parse(res);\n }\n\n async setItem(k, v) {\n await AsyncStorage.setItem(this.makeKey(k), JSON.stringify(v));\n }\n\n async removeItem(k: string): Promise<void> {\n await AsyncStorage.removeItem(this.makeKey(k));\n }\n\n async getAllKeys(): Promise<string[]> {\n const allKeys = await AsyncStorage.getAllKeys();\n const keys: string[] = [];\n const keyPrefix = this.makeKey('');\n for (const key of allKeys) {\n if (key.startsWith(keyPrefix)) {\n keys.push(key.substring(keyPrefix.length));\n }\n }\n return keys;\n }\n\n async multiSet(keyValuePairs: Array<[string, any]>): Promise<void> {\n await AsyncStorage.multiSet(\n keyValuePairs.map(([k, v]) => [this.makeKey(k), JSON.stringify(v)]),\n );\n }\n}\n\nclass MissingStore extends StoreInterface {\n constructor(appId: string, dbName: StoreInterfaceStoreName) {\n super(appId, dbName);\n throw new Error(\n 'Instant needs a store to persist data on device. ' +\n 'Install `@react-native-async-storage/async-storage`, ' +\n 'or pass a `Store` to `init` (e.g. from `@instantdb/react-native-mmkv` or `@instantdb/expo-sqlite`).' +\n (asyncStorageLoadError\n ? `\\n\\nLoading async-storage failed with: ${asyncStorageLoadError}`\n : ''),\n );\n }\n\n async getItem(_k: string): Promise<any> {\n return null;\n }\n\n async removeItem(_k: string): Promise<void> {}\n\n async multiSet(_keyValuePairs: Array<[string, any]>): Promise<void> {}\n\n async getAllKeys(): Promise<string[]> {\n return [];\n }\n}\n\nexport default AsyncStorage ? AsyncStorageStore : MissingStore;\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const streamConstructors: {
|
|
2
|
+
ReadableStream: {
|
|
3
|
+
new (underlyingSource: UnderlyingByteSource, strategy?: {
|
|
4
|
+
highWaterMark?: number;
|
|
5
|
+
}): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
6
|
+
new <R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
|
|
7
|
+
new <R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
|
|
8
|
+
prototype: ReadableStream;
|
|
9
|
+
};
|
|
10
|
+
WritableStream: {
|
|
11
|
+
new <W = any>(underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>): WritableStream<W>;
|
|
12
|
+
prototype: WritableStream;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=Streams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Streams.d.ts","sourceRoot":"","sources":["../src/Streams.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB;;;yBAIgn5oC,CAAC;;;;;;;;;;CAD/o5oC,CAAC"}
|
package/dist/Streams.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamConstructors = void 0;
|
|
4
|
+
// RN may need a polyfill for streams, so we put those in Streams.native.ts
|
|
5
|
+
exports.streamConstructors = {
|
|
6
|
+
ReadableStream: ReadableStream,
|
|
7
|
+
WritableStream: WritableStream,
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=Streams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Streams.js","sourceRoot":"","sources":["../src/Streams.ts"],"names":[],"mappings":";;;AAAA,2EAA2E;AAC9D,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAE,cAAc;IAC9B,cAAc,EAAE,cAAc;CAC/B,CAAC","sourcesContent":["// RN may need a polyfill for streams, so we put those in Streams.native.ts\nexport const streamConstructors = {\n ReadableStream: ReadableStream,\n WritableStream: WritableStream,\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Streams.native.d.ts","sourceRoot":"","sources":["../src/Streams.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtE,eAAO,MAAM,kBAAkB;;;CAG9B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamConstructors = void 0;
|
|
4
|
+
const web_streams_polyfill_1 = require("web-streams-polyfill");
|
|
5
|
+
exports.streamConstructors = {
|
|
6
|
+
ReadableStream: web_streams_polyfill_1.ReadableStream,
|
|
7
|
+
WritableStream: web_streams_polyfill_1.WritableStream,
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=Streams.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Streams.native.js","sourceRoot":"","sources":["../src/Streams.native.ts"],"names":[],"mappings":";;;AAAA,+DAAsE;AAEzD,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAE,qCAAc;IAC9B,cAAc,EAAE,qCAAc;CAC/B,CAAC","sourcesContent":["import { ReadableStream, WritableStream } from 'web-streams-polyfill';\n\nexport const streamConstructors = {\n ReadableStream: ReadableStream,\n WritableStream: WritableStream,\n};\n"]}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@fidscript/instant-sdk"), exports);
|
|
18
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC","sourcesContent":["export * from '@fidscript/instant-sdk';\n"]}
|