@instantdb/react-native 0.22.75 → 0.22.76
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/EventSourceShim.d.ts +1 -1
- package/dist/EventSourceShim.js.map +1 -1
- package/dist/NetworkListener.d.ts +1 -1
- package/dist/NetworkListener.d.ts.map +1 -1
- package/dist/Storage.native.d.ts.map +1 -1
- package/dist/Storage.native.js +2 -0
- package/dist/Storage.native.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/module/EventSourceShim.d.ts +1 -1
- package/dist/module/EventSourceShim.js.map +1 -1
- package/dist/module/NetworkListener.d.ts +1 -1
- package/dist/module/NetworkListener.d.ts.map +1 -1
- package/dist/module/Storage.native.d.ts.map +1 -1
- package/dist/module/Storage.native.js +2 -0
- package/dist/module/Storage.native.js.map +1 -1
- package/dist/module/index.d.ts +4 -2
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +7 -2
- package/dist/module/index.js.map +1 -1
- package/package.json +6 -4
- package/src/EventSourceShim.ts +7 -7
- package/src/Storage.native.ts +2 -1
- package/src/__types__/typeUtils.ts +39 -0
- package/src/__types__/typesTests.ts +86 -0
- package/src/index.ts +22 -5
- package/tsconfig.json +3 -2
- package/tsconfig.test.json +5 -0
|
@@ -22,7 +22,7 @@ declare class EventSource implements EventSourceType {
|
|
|
22
22
|
open(): void;
|
|
23
23
|
_logDebug(...msg: any[]): void;
|
|
24
24
|
_handleEvent(response: any): void;
|
|
25
|
-
_detectNewlineChar(response: any): string;
|
|
25
|
+
_detectNewlineChar(response: any): string | null;
|
|
26
26
|
_getLastDoubleNewlineIndex(response: any): any;
|
|
27
27
|
dispatch(type: any, data: any): void;
|
|
28
28
|
close(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventSourceShim.js","sourceRoot":"","sources":["../src/EventSourceSh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,EAAE,CAAC;oBACnB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACvB,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;YACvC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;QACnC,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;;AA1QM,sBAAU,GAAG,CAAC,AAAJ,CAAK;AACf,gBAAI,GAAG,CAAC,AAAJ,CAAK;AACT,kBAAM,GAAG,CAAC,AAAJ,CAAK;AA2QpB,kBAAe,WAAW,CAAC","sourcesContent":["import { type EventSourceType } from '@instantdb/core';\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 = undefined;\n let data = [];\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"]}
|
|
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;IA8Bf,YAAY,GAAG;QA7BP,UAAK,GAAG,CAAC,CAAC,CAAC;QAKX,SAAI,GAAG,MAAM,CAAC;QACd,OAAE,GAAG,IAAI,CAAC;QACV,OAAE,GAAG,IAAI,CAAC;QAYV,YAAO,GAAG;YAChB,MAAM,EAAE,mBAAmB;YAC3B,eAAe,EAAE,UAAU;YAC3B,kBAAkB,EAAE,gBAAgB;SACrC,CAAC;QAOA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC;QAErC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,WAAW,CAAC,qCAAq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AAC;IACtD,CAAC;IAED,QAAQ,CAAC,IAAI,EAAE,IAAI;QACjB,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACjB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACrB,CAAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,SAAS,CAAC,CAAC,CAAC;gBACf,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;oBACnB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACvB,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;YACvC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;QACnC,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;;AA1QM,sBAAU,GAAG,CAAC,AAAJ,CAAK;AACf,gBAAI,GAAG,CAAC,AAAJ,CAAK;AACT,kBAAM,GAAG,CAAC,AAAJ,CAAK;AA2QpB,kBAAe,WAAW,CAAC","sourcesContent":["import { type EventSourceType } from '@instantdb/core';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkListener.d.ts","sourceRoot":"","sources":["../src/NetworkListener.js"],"names":[],"mappings":"AAEA;IACE,
|
|
1
|
+
{"version":3,"file":"NetworkListener.d.ts","sourceRoot":"","sources":["../src/NetworkListener.js"],"names":[],"mappings":"AAEA;IACE,8CAGC;IACD,qFAIC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.native.d.ts","sourceRoot":"","sources":["../src/Storage.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA4B;gBAC9B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,yBAAyB;IAM5D,OAAO,CAAC,OAAO;IAIT,OAAO,CAAC,CAAC,KAAA;
|
|
1
|
+
{"version":3,"file":"Storage.native.d.ts","sourceRoot":"","sources":["../src/Storage.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA4B;gBAC9B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,yBAAyB;IAM5D,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"}
|
package/dist/Storage.native.js
CHANGED
|
@@ -27,6 +27,8 @@ class Storage extends core_1.StorageInterface {
|
|
|
27
27
|
getItem(k) {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
const res = yield async_storage_1.default.getItem(this.makeKey(k));
|
|
30
|
+
if (res === null)
|
|
31
|
+
return res;
|
|
30
32
|
return JSON.parse(res);
|
|
31
33
|
});
|
|
32
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.native.js","sourceRoot":"","sources":["../src/Storage.native.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,8FAAqE;AACrE,0CAA8E;AAE9E,MAAM,OAAO,GAAG,CAAC,CAAC;AAElB,MAAqB,OAAQ,SAAQ,uBAAgB;IAGnD,YAAY,KAAa,EAAE,MAAiC;QAC1D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEO,OAAO,CAAC,CAAS;QACvB,OAAO,WAAW,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAChE,CAAC;IAEK,OAAO,CAAC,CAAC;;YACb,MAAM,GAAG,GAAG,MAAM,uBAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;KAAA;IAEK,OAAO,CAAC,CAAC,EAAE,CAAC;;YAChB,MAAM,uBAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACjE,CAAC;KAAA;IAEK,UAAU,CAAC,CAAS;;YACxB,MAAM,uBAAY,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,CAAC;KAAA;IAEK,UAAU;;YACd,MAAM,OAAO,GAAG,MAAM,uBAAY,CAAC,UAAU,EAAE,CAAC;YAChD,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"Storage.native.js","sourceRoot":"","sources":["../src/Storage.native.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,8F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AC,SAAS,CAAC,EAAE,CAAC;oBAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAEK,QAAQ,CAAC,aAAmC;;YAChD,MAAM,uBAAY,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;QACJ,CAAC;KAAA;CACF;AA5CD,0BA4CC","sourcesContent":["import AsyncStorage from '@react-native-async-storage/async-storage';\nimport { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';\n\nconst version = 5;\n\nexport default class Storage extends StorageInterface {\n private appId: string;\n private dbName: StorageInterfaceStoreName;\n constructor(appId: string, dbName: StorageInterfaceStoreName) {\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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,9 @@ import { i, id, tx, lookup, InstantAPIError, SyncTableCallbackEventType, type Ro
|
|
|
23
23
|
*
|
|
24
24
|
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
25
25
|
*/
|
|
26
|
-
declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: InstantConfig<Schema, UseDates>
|
|
26
|
+
declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
|
|
27
|
+
useDateObjects?: UseDates;
|
|
28
|
+
}): InstantReactNativeDatabase<Schema, UseDates, InstantConfig<Schema, UseDates>>;
|
|
27
29
|
/**
|
|
28
30
|
* @deprecated
|
|
29
31
|
* `init_experimental` is deprecated. You can replace it with `init`.
|
|
@@ -39,7 +41,7 @@ declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUn
|
|
|
39
41
|
* const db = init({ ... });
|
|
40
42
|
*/
|
|
41
43
|
declare const init_experimental: typeof init;
|
|
42
|
-
declare class InstantReactNativeDatabase<Schema extends InstantSchemaDef<any, any, any>, Config extends InstantConfig<Schema,
|
|
44
|
+
declare class InstantReactNativeDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean, Config extends InstantConfig<Schema, UseDates> = InstantConfig<Schema, UseDates>> extends InstantReactAbstractDatabase<Schema, UseDates, Config> {
|
|
43
45
|
static Storage: typeof Storage;
|
|
44
46
|
static NetworkListener: typeof NetworkListener;
|
|
45
47
|
static EventSourceImpl: {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AAExC,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,O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,EACf,KAAK,UAAU,EACf,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EAGnB,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAGvB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,GACzB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -42,8 +42,13 @@ Object.defineProperty(exports, "SyncTableCallbackEventType", { enumerable: true,
|
|
|
42
42
|
*
|
|
43
43
|
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
44
44
|
*/
|
|
45
|
-
function init(
|
|
46
|
-
|
|
45
|
+
function init(
|
|
46
|
+
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
47
|
+
// as a non-nullable in the InstantConfig type.
|
|
48
|
+
config) {
|
|
49
|
+
var _a;
|
|
50
|
+
const configStrict = Object.assign(Object.assign({}, config), { useDateObjects: ((_a = config.useDateObjects) !== null && _a !== void 0 ? _a : false) });
|
|
51
|
+
return new InstantReactNativeDatabase(configStrict, {
|
|
47
52
|
'@instantdb/react': version_1.default,
|
|
48
53
|
});
|
|
49
54
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AA6KE,oBAAI;AA7KN,0CAAwC;AAExC,wDAAgC;AAChC,wEAAgD;AAChD,wEAAgD;AAChD,wDAAgC;AAEhC,0DAAuE;AAEvE,0CAqFyB;AAoFvB,kFAxKA,QAAC,OAwKA;AAHD,mFApKA,SAAE,OAoKA;AACF,mFApKA,SAAE,OAoKA;AACF,uFApKA,aAAM,OAoKA;AAKN;IAvKA,QAAQ;IACR,sBAAe,OAsKA;AAGf;IAvKA,mBAAmB;IACnB,iCAA0B,OAsKA;AAzF5B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,IAAI;AAIX,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC;;IAMD,MAAM,YAAY,mCACb,MAAM,KACT,cAAc,EAAE,CAAC,MAAA,MAAM,CAAC,cAAc,mCAAI,KAAK,CAAa,GAC7D,CAAC;IACF,OAAO,IAAI,0BAA0B,CAInC,YAAY,EAAE;QACd,kBAAkB,EAAE,iBAAO;KAC5B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAiB7B,8CAAiB;AAfnB,MAAM,0BAOJ,SAAQ,2CAAsD;;AAa9D,gEAA0B;AAZnB,kCAAO,GAAG,iBAAO,CAAC;AAClB,0CAAe,GAAG,yBAAe,CAAC;AAClC,0CAAe,GAAG,yBAAe,CAAC","sourcesContent":["import 'react-native-get-random-values';\n\nimport Storage from './Storage';\nimport EventSourceImpl from './EventSourceImpl';\nimport NetworkListener from './NetworkListener';\nimport version from './version';\n\nimport { InstantReactAbstractDatabase } from '@instantdb/react-common';\n\nimport {\n i,\n id,\n tx,\n lookup,\n\n // error\n InstantAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n type RoomSchemaShape,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantSchemaDatabase,\n type ConnectionStatus,\n type BackwardsCompatibleSchema,\n type IInstantDatabase,\n type Config,\n type Query,\n type QueryResponse,\n type InstantObject,\n type AuthState,\n type User,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type InstantGraph,\n type InstantUnknownSchemaDef,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type InstantEntity,\n type ConfigWithSchema,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type CreateParams,\n type InstantConfig,\n type InstantSchemaDef,\n type InstantUnknownSchema,\n type TransactionChunk,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type ValidQuery,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n} from '@instantdb/core';\n\n/**\n *\n * The first step: init your application!\n *\n * Visit https://instantdb.com/dash to get your `appId` :)\n *\n * @example\n * import { init } from \"@instantdb/react-native\"\n *\n * const db = init({ appId: \"my-app-id\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@instantdb/react-native\"\n * import schema from \"\"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", schema })\n *\n * // To learn more: https://instantdb.com/docs/modeling-data\n */\nfunction init<\n Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,\n UseDates extends boolean = false,\n>(\n // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the InstantConfig type.\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n): InstantReactNativeDatabase<\n Schema,\n UseDates,\n InstantConfig<Schema, UseDates>\n> {\n const configStrict = {\n ...config,\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n return new InstantReactNativeDatabase<\n Schema,\n UseDates,\n InstantConfig<Schema, UseDates>\n >(configStrict, {\n '@instantdb/react': version,\n });\n}\n\n/**\n * @deprecated\n * `init_experimental` is deprecated. You can replace it with `init`.\n *\n * @example\n *\n * // Before\n * import { init_experimental } from \"@instantdb/react-native\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@instantdb/react-native\"\n * const db = init({ ... });\n */\nconst init_experimental = init;\n\nclass InstantReactNativeDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean,\n Config extends InstantConfig<Schema, UseDates> = InstantConfig<\n Schema,\n UseDates\n >,\n> extends InstantReactAbstractDatabase<Schema, UseDates, Config> {\n static Storage = Storage;\n static NetworkListener = NetworkListener;\n static EventSourceImpl = EventSourceImpl;\n}\n\nexport {\n init,\n init_experimental,\n id,\n tx,\n lookup,\n i,\n InstantReactNativeDatabase,\n\n // error\n InstantAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n type Config,\n type Query,\n type QueryResponse,\n type InstantObject,\n type User,\n type AuthState,\n type ConnectionStatus,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantSchemaDatabase,\n type IInstantDatabase,\n type InstantEntity,\n type RoomSchemaShape,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type InstantGraph,\n type CreateParams,\n type LinkAttrDef,\n type InstantConfig,\n type LinkDef,\n type InstantUnknownSchemaDef,\n type LinksDef,\n type RoomsOf,\n type RoomsDef,\n type RoomHandle,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type ResolveAttrs,\n type ValueTypes,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type InstantSchemaDef,\n type InstantUnknownSchema,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type ValidQuery,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type TransactionChunk,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n};\n"]}
|
|
@@ -22,7 +22,7 @@ declare class EventSource implements EventSourceType {
|
|
|
22
22
|
open(): void;
|
|
23
23
|
_logDebug(...msg: any[]): void;
|
|
24
24
|
_handleEvent(response: any): void;
|
|
25
|
-
_detectNewlineChar(response: any): string;
|
|
25
|
+
_detectNewlineChar(response: any): string | null;
|
|
26
26
|
_getLastDoubleNewlineIndex(response: any): any;
|
|
27
27
|
dispatch(type: any, data: any): void;
|
|
28
28
|
close(): void;
|
|
@@ -1 +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;IA8Bf,YAAY,GAAG;QA7BP,UAAK,GAAG,CAAC,CAAC,CAAC;QAKX,SAAI,GAAG,MAAM,CAAC;QACd,OAAE,GAAG,IAAI,CAAC;QACV,OAAE,GAAG,IAAI,CAAC;QAYV,YAAO,GAAG;YAChB,MAAM,EAAE,mBAAmB;YAC3B,eAAe,EAAE,UAAU;YAC3B,kBAAkB,EAAE,gBAAgB;SACrC,CAAC;QAOA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC;QAErC,IAAI,CAAC,mBAAmB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AAW,CAAC","sourcesContent":["import { type EventSourceType } from '@instantdb/core';\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 = undefined;\n let data = [];\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"]}
|
|
1
|
+
{"version":3,"file":"EventSourceShim.js","sourceRoot":"","sources":["../../src/EventSourceShim.ts"],"names":[],"mappings":"AAEA,qGA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,SAAS,CAAC,IAAI,CAAC,CAAC;gBACvB,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;YACvC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;QACnC,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;;AA1QM,sBAAU,GAAG,CAAC,AAAJ,CAAK;AACf,gBAAI,GAAG,CAAC,AAAJ,CAAK;AACT,kBAAM,GAAG,CAAC,AAAJ,CAAK;AA2QpB,eAAe,WAAW,CAAC","sourcesContent":["import { type EventSourceType } from '@instantdb/core';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkListener.d.ts","sourceRoot":"","sources":["../../src/NetworkListener.js"],"names":[],"mappings":"AAEA;IACE,
|
|
1
|
+
{"version":3,"file":"NetworkListener.d.ts","sourceRoot":"","sources":["../../src/NetworkListener.js"],"names":[],"mappings":"AAEA;IACE,8CAGC;IACD,qFAIC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.native.d.ts","sourceRoot":"","sources":["../../src/Storage.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA4B;gBAC9B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,yBAAyB;IAM5D,OAAO,CAAC,OAAO;IAIT,OAAO,CAAC,CAAC,KAAA;
|
|
1
|
+
{"version":3,"file":"Storage.native.d.ts","sourceRoot":"","sources":["../../src/Storage.native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IACnD,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA4B;gBAC9B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,yBAAyB;IAM5D,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"}
|
|
@@ -22,6 +22,8 @@ export default class Storage extends StorageInterface {
|
|
|
22
22
|
getItem(k) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
const res = yield AsyncStorage.getItem(this.makeKey(k));
|
|
25
|
+
if (res === null)
|
|
26
|
+
return res;
|
|
25
27
|
return JSON.parse(res);
|
|
26
28
|
});
|
|
27
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.native.js","sourceRoot":"","sources":["../../src/Storage.native.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,YAAY,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAA6B,MAAM,iBAAiB,CAAC;AAE9E,MAAM,OAAO,GAAG,CAAC,CAAC;AAElB,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,gBAAgB;IAGnD,YAAY,KAAa,EAAE,MAAiC;QAC1D,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEO,OAAO,CAAC,CAAS;QACvB,OAAO,WAAW,IAAI,CAAC,KAAK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C,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CACpE,CAAC;QACJ,CAAC;KAAA;CACF","sourcesContent":["import AsyncStorage from '@react-native-async-storage/async-storage';\nimport { StorageInterface, StorageInterfaceStoreName } from '@instantdb/core';\n\nconst version = 5;\n\nexport default class Storage extends StorageInterface {\n private appId: string;\n private dbName: StorageInterfaceStoreName;\n constructor(appId: string, dbName: StorageInterfaceStoreName) {\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"]}
|
package/dist/module/index.d.ts
CHANGED
|
@@ -23,7 +23,9 @@ import { i, id, tx, lookup, InstantAPIError, SyncTableCallbackEventType, type Ro
|
|
|
23
23
|
*
|
|
24
24
|
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
25
25
|
*/
|
|
26
|
-
declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: InstantConfig<Schema, UseDates>
|
|
26
|
+
declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
|
|
27
|
+
useDateObjects?: UseDates;
|
|
28
|
+
}): InstantReactNativeDatabase<Schema, UseDates, InstantConfig<Schema, UseDates>>;
|
|
27
29
|
/**
|
|
28
30
|
* @deprecated
|
|
29
31
|
* `init_experimental` is deprecated. You can replace it with `init`.
|
|
@@ -39,7 +41,7 @@ declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUn
|
|
|
39
41
|
* const db = init({ ... });
|
|
40
42
|
*/
|
|
41
43
|
declare const init_experimental: typeof init;
|
|
42
|
-
declare class InstantReactNativeDatabase<Schema extends InstantSchemaDef<any, any, any>, Config extends InstantConfig<Schema,
|
|
44
|
+
declare class InstantReactNativeDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean, Config extends InstantConfig<Schema, UseDates> = InstantConfig<Schema, UseDates>> extends InstantReactAbstractDatabase<Schema, UseDates, Config> {
|
|
43
45
|
static Storage: typeof Storage;
|
|
44
46
|
static NetworkListener: typeof NetworkListener;
|
|
45
47
|
static EventSourceImpl: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AAExC,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EACL,CAAC,EACD,EAAE,EACF,EAAE,EACF,MAAM,EAGN,eAAe,EAGf,0BAA0B,EAG1B,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KA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29,13 @@ SyncTableCallbackEventType, } from '@instantdb/core';
|
|
|
29
29
|
*
|
|
30
30
|
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
31
31
|
*/
|
|
32
|
-
function init(
|
|
33
|
-
|
|
32
|
+
function init(
|
|
33
|
+
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
34
|
+
// as a non-nullable in the InstantConfig type.
|
|
35
|
+
config) {
|
|
36
|
+
var _a;
|
|
37
|
+
const configStrict = Object.assign(Object.assign({}, config), { useDateObjects: ((_a = config.useDateObjects) !== null && _a !== void 0 ? _a : false) });
|
|
38
|
+
return new InstantReactNativeDatabase(configStrict, {
|
|
34
39
|
'@instantdb/react': version,
|
|
35
40
|
});
|
|
36
41
|
}
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AAExC,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EACL,CAAC,EACD,EAAE,EACF,EAAE,EACF,MAAM;AAEN,QAAQ;AACR,eAAe;AAEf,mBAAmB;AACnB,0BAA0B,GA2E3B,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AAExC,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EACL,CAAC,EACD,EAAE,EACF,EAAE,EACF,MAAM;AAEN,QAAQ;AACR,eAAe;AAEf,mBAAmB;AACnB,0BAA0B,GA2E3B,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,IAAI;AAIX,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC;;IAMD,MAAM,YAAY,mCACb,MAAM,KACT,cAAc,EAAE,CAAC,MAAA,MAAM,CAAC,cAAc,mCAAI,KAAK,CAAa,GAC7D,CAAC;IACF,OAAO,IAAI,0BAA0B,CAInC,YAAY,EAAE;QACd,kBAAkB,EAAE,OAAO;KAC5B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,0BAOJ,SAAQ,4BAAsD;;AACvD,kCAAO,GAAG,OAAO,CAAC;AAClB,0CAAe,GAAG,eAAe,CAAC;AAClC,0CAAe,GAAG,eAAe,CAAC;AAG3C,OAAO,EACL,IAAI,EACJ,iBAAiB,EACjB,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC,EACD,0BAA0B;AAE1B,QAAQ;AACR,eAAe;AAEf,mBAAmB;AACnB,0BAA0B,GA0E3B,CAAC","sourcesContent":["import 'react-native-get-random-values';\n\nimport Storage from './Storage';\nimport EventSourceImpl from './EventSourceImpl';\nimport NetworkListener from './NetworkListener';\nimport version from './version';\n\nimport { InstantReactAbstractDatabase } from '@instantdb/react-common';\n\nimport {\n i,\n id,\n tx,\n lookup,\n\n // error\n InstantAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n type RoomSchemaShape,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantSchemaDatabase,\n type ConnectionStatus,\n type BackwardsCompatibleSchema,\n type IInstantDatabase,\n type Config,\n type Query,\n type QueryResponse,\n type InstantObject,\n type AuthState,\n type User,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type InstantGraph,\n type InstantUnknownSchemaDef,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type InstantEntity,\n type ConfigWithSchema,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type CreateParams,\n type InstantConfig,\n type InstantSchemaDef,\n type InstantUnknownSchema,\n type TransactionChunk,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type ValidQuery,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n} from '@instantdb/core';\n\n/**\n *\n * The first step: init your application!\n *\n * Visit https://instantdb.com/dash to get your `appId` :)\n *\n * @example\n * import { init } from \"@instantdb/react-native\"\n *\n * const db = init({ appId: \"my-app-id\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@instantdb/react-native\"\n * import schema from \"\"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", schema })\n *\n * // To learn more: https://instantdb.com/docs/modeling-data\n */\nfunction init<\n Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,\n UseDates extends boolean = false,\n>(\n // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the InstantConfig type.\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n): InstantReactNativeDatabase<\n Schema,\n UseDates,\n InstantConfig<Schema, UseDates>\n> {\n const configStrict = {\n ...config,\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n return new InstantReactNativeDatabase<\n Schema,\n UseDates,\n InstantConfig<Schema, UseDates>\n >(configStrict, {\n '@instantdb/react': version,\n });\n}\n\n/**\n * @deprecated\n * `init_experimental` is deprecated. You can replace it with `init`.\n *\n * @example\n *\n * // Before\n * import { init_experimental } from \"@instantdb/react-native\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@instantdb/react-native\"\n * const db = init({ ... });\n */\nconst init_experimental = init;\n\nclass InstantReactNativeDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean,\n Config extends InstantConfig<Schema, UseDates> = InstantConfig<\n Schema,\n UseDates\n >,\n> extends InstantReactAbstractDatabase<Schema, UseDates, Config> {\n static Storage = Storage;\n static NetworkListener = NetworkListener;\n static EventSourceImpl = EventSourceImpl;\n}\n\nexport {\n init,\n init_experimental,\n id,\n tx,\n lookup,\n i,\n InstantReactNativeDatabase,\n\n // error\n InstantAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n type Config,\n type Query,\n type QueryResponse,\n type InstantObject,\n type User,\n type AuthState,\n type ConnectionStatus,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantSchemaDatabase,\n type IInstantDatabase,\n type InstantEntity,\n type RoomSchemaShape,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type InstantGraph,\n type CreateParams,\n type LinkAttrDef,\n type InstantConfig,\n type LinkDef,\n type InstantUnknownSchemaDef,\n type LinksDef,\n type RoomsOf,\n type RoomsDef,\n type RoomHandle,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type ResolveAttrs,\n type ValueTypes,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type InstantSchemaDef,\n type InstantUnknownSchema,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type ValidQuery,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type TransactionChunk,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/react-native",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.76",
|
|
4
4
|
"description": "Instant DB for React Native",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/react-native",
|
|
6
6
|
"repository": {
|
|
@@ -29,12 +29,14 @@
|
|
|
29
29
|
"react-native-get-random-values": ">=1.5"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@instantdb/
|
|
33
|
-
"@instantdb/
|
|
34
|
-
"@instantdb/
|
|
32
|
+
"@instantdb/react-common": "0.22.76",
|
|
33
|
+
"@instantdb/version": "0.22.76",
|
|
34
|
+
"@instantdb/core": "0.22.76"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "vitest",
|
|
38
|
+
"test:types": "tsc -p tsconfig.test.json --noEmit",
|
|
39
|
+
"test:ci": "pnpm run test:types",
|
|
38
40
|
"build": "rm -rf dist; npm run build:main && npm run build:module",
|
|
39
41
|
"dev:main": "tsc -p tsconfig.json -w --skipLibCheck --preserveWatchOutput | grep -v '^$'",
|
|
40
42
|
"dev:module": "tsc -p tsconfig.module.json -w --skipLibCheck --preserveWatchOutput | grep -v '^$'",
|
package/src/EventSourceShim.ts
CHANGED
|
@@ -85,7 +85,7 @@ class EventSource implements EventSourceType {
|
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const xhr = this._xhr
|
|
88
|
+
const xhr = this._xhr!;
|
|
89
89
|
|
|
90
90
|
this._logDebug(
|
|
91
91
|
`[EventSource][onreadystatechange] ReadyState: ${XMLReadyStateMap[xhr.readyState] || 'Unknown'}(${
|
|
@@ -142,9 +142,9 @@ class EventSource implements EventSourceType {
|
|
|
142
142
|
this.status = this.ERROR;
|
|
143
143
|
this.dispatch('error', {
|
|
144
144
|
type: 'error',
|
|
145
|
-
message: this._xhr
|
|
146
|
-
xhrStatus: this._xhr
|
|
147
|
-
xhrState: this._xhr
|
|
145
|
+
message: this._xhr!.responseText,
|
|
146
|
+
xhrStatus: this._xhr!.status,
|
|
147
|
+
xhrState: this._xhr!.readyState,
|
|
148
148
|
});
|
|
149
149
|
};
|
|
150
150
|
|
|
@@ -194,8 +194,8 @@ class EventSource implements EventSourceType {
|
|
|
194
194
|
|
|
195
195
|
this._lastIndexProcessed = indexOfDoubleNewline;
|
|
196
196
|
|
|
197
|
-
let type = undefined;
|
|
198
|
-
let data = [];
|
|
197
|
+
let type: string | undefined = undefined;
|
|
198
|
+
let data: string[] = [];
|
|
199
199
|
let line = '';
|
|
200
200
|
|
|
201
201
|
for (let i = 0; i < parts.length; i++) {
|
|
@@ -239,7 +239,7 @@ class EventSource implements EventSourceType {
|
|
|
239
239
|
|
|
240
240
|
_getLastDoubleNewlineIndex(response) {
|
|
241
241
|
const doubleLineEndingCharacter =
|
|
242
|
-
this.lineEndingCharacter + this.lineEndingCharacter
|
|
242
|
+
this.lineEndingCharacter! + this.lineEndingCharacter!;
|
|
243
243
|
const lastIndex = response.lastIndexOf(doubleLineEndingCharacter);
|
|
244
244
|
if (lastIndex === -1) {
|
|
245
245
|
return -1;
|
package/src/Storage.native.ts
CHANGED
|
@@ -18,6 +18,7 @@ export default class Storage extends StorageInterface {
|
|
|
18
18
|
|
|
19
19
|
async getItem(k) {
|
|
20
20
|
const res = await AsyncStorage.getItem(this.makeKey(k));
|
|
21
|
+
if (res === null) return res;
|
|
21
22
|
return JSON.parse(res);
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -31,7 +32,7 @@ export default class Storage extends StorageInterface {
|
|
|
31
32
|
|
|
32
33
|
async getAllKeys(): Promise<string[]> {
|
|
33
34
|
const allKeys = await AsyncStorage.getAllKeys();
|
|
34
|
-
const keys = [];
|
|
35
|
+
const keys: string[] = [];
|
|
35
36
|
const keyPrefix = this.makeKey('');
|
|
36
37
|
for (const key of allKeys) {
|
|
37
38
|
if (key.startsWith(keyPrefix)) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Type testing utils from
|
|
2
|
+
// https://github.com/type-challenges/type-challenges/blob/main/utils/index.d.ts
|
|
3
|
+
|
|
4
|
+
export type Expect<T extends true> = T;
|
|
5
|
+
export type ExpectTrue<T extends true> = T;
|
|
6
|
+
export type ExpectFalse<T extends false> = T;
|
|
7
|
+
export type IsTrue<T extends true> = T;
|
|
8
|
+
export type IsFalse<T extends false> = T;
|
|
9
|
+
|
|
10
|
+
export type Equal<X, Y> =
|
|
11
|
+
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
12
|
+
? true
|
|
13
|
+
: false;
|
|
14
|
+
export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
|
|
15
|
+
|
|
16
|
+
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
|
17
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
18
|
+
export type NotAny<T> = true extends IsAny<T> ? false : true;
|
|
19
|
+
|
|
20
|
+
export type Debug<T> = { [K in keyof T]: T[K] };
|
|
21
|
+
export type MergeInsertions<T> = T extends object
|
|
22
|
+
? { [K in keyof T]: MergeInsertions<T[K]> }
|
|
23
|
+
: T;
|
|
24
|
+
|
|
25
|
+
export type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;
|
|
26
|
+
|
|
27
|
+
export type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE
|
|
28
|
+
? true
|
|
29
|
+
: false;
|
|
30
|
+
export type ExpectValidArgs<
|
|
31
|
+
FUNC extends (...args: any[]) => any,
|
|
32
|
+
ARGS extends any[],
|
|
33
|
+
> = ARGS extends Parameters<FUNC> ? true : false;
|
|
34
|
+
|
|
35
|
+
export type UnionToIntersection<U> = (
|
|
36
|
+
U extends any ? (k: U) => void : never
|
|
37
|
+
) extends (k: infer I) => void
|
|
38
|
+
? I
|
|
39
|
+
: never;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Equal, Expect, IsAny, NotAny } from './typeUtils';
|
|
2
|
+
import { i, init } from '../index';
|
|
3
|
+
|
|
4
|
+
const schema = i.schema({
|
|
5
|
+
entities: {
|
|
6
|
+
tbl: i.entity({
|
|
7
|
+
d: i.date().indexed(),
|
|
8
|
+
dOptional: i.date().optional(),
|
|
9
|
+
}),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function _testUseDatesTest() {
|
|
14
|
+
const db = init({
|
|
15
|
+
schema,
|
|
16
|
+
appId: '123',
|
|
17
|
+
useDateObjects: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
21
|
+
const item = data?.tbl[0];
|
|
22
|
+
if (item) {
|
|
23
|
+
type t = typeof item.d;
|
|
24
|
+
type _cases = [Expect<NotAny<t>>, Expect<Equal<t, Date>>];
|
|
25
|
+
|
|
26
|
+
type tOpt = typeof item.dOptional;
|
|
27
|
+
type _cases_2 = [
|
|
28
|
+
Expect<NotAny<tOpt>>,
|
|
29
|
+
Expect<Equal<tOpt, Date | undefined>>,
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _testUseDatesFalseTest() {
|
|
35
|
+
const db = init({
|
|
36
|
+
schema,
|
|
37
|
+
appId: '123',
|
|
38
|
+
useDateObjects: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
42
|
+
const item = data?.tbl[0];
|
|
43
|
+
if (item) {
|
|
44
|
+
type t = typeof item.d;
|
|
45
|
+
type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];
|
|
46
|
+
|
|
47
|
+
type tOpt = typeof item.dOptional;
|
|
48
|
+
type _cases_2 = [
|
|
49
|
+
Expect<NotAny<tOpt>>,
|
|
50
|
+
Expect<Equal<tOpt, string | number | undefined>>,
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _testUseDatesUndefinedTest() {
|
|
56
|
+
const db = init({
|
|
57
|
+
schema,
|
|
58
|
+
appId: '123',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
62
|
+
const item = data?.tbl[0];
|
|
63
|
+
if (item) {
|
|
64
|
+
type t = typeof item.d;
|
|
65
|
+
type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];
|
|
66
|
+
|
|
67
|
+
type tOpt = typeof item.dOptional;
|
|
68
|
+
type _cases_2 = [
|
|
69
|
+
Expect<NotAny<tOpt>>,
|
|
70
|
+
Expect<Equal<tOpt, string | number | undefined>>,
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _testDataNoSchema() {
|
|
76
|
+
const db = init({
|
|
77
|
+
appId: '123',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
81
|
+
const item = data?.tbl[0];
|
|
82
|
+
if (item) {
|
|
83
|
+
type t = typeof item.d;
|
|
84
|
+
type _cases = [Expect<IsAny<t>>, Expect<Equal<typeof item.id, string>>];
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -118,12 +118,25 @@ function init<
|
|
|
118
118
|
Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,
|
|
119
119
|
UseDates extends boolean = false,
|
|
120
120
|
>(
|
|
121
|
-
config
|
|
122
|
-
|
|
121
|
+
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
122
|
+
// as a non-nullable in the InstantConfig type.
|
|
123
|
+
config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
|
|
124
|
+
useDateObjects?: UseDates;
|
|
125
|
+
},
|
|
126
|
+
): InstantReactNativeDatabase<
|
|
127
|
+
Schema,
|
|
128
|
+
UseDates,
|
|
129
|
+
InstantConfig<Schema, UseDates>
|
|
130
|
+
> {
|
|
131
|
+
const configStrict = {
|
|
132
|
+
...config,
|
|
133
|
+
useDateObjects: (config.useDateObjects ?? false) as UseDates,
|
|
134
|
+
};
|
|
123
135
|
return new InstantReactNativeDatabase<
|
|
124
136
|
Schema,
|
|
137
|
+
UseDates,
|
|
125
138
|
InstantConfig<Schema, UseDates>
|
|
126
|
-
>(
|
|
139
|
+
>(configStrict, {
|
|
127
140
|
'@instantdb/react': version,
|
|
128
141
|
});
|
|
129
142
|
}
|
|
@@ -146,8 +159,12 @@ const init_experimental = init;
|
|
|
146
159
|
|
|
147
160
|
class InstantReactNativeDatabase<
|
|
148
161
|
Schema extends InstantSchemaDef<any, any, any>,
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
UseDates extends boolean,
|
|
163
|
+
Config extends InstantConfig<Schema, UseDates> = InstantConfig<
|
|
164
|
+
Schema,
|
|
165
|
+
UseDates
|
|
166
|
+
>,
|
|
167
|
+
> extends InstantReactAbstractDatabase<Schema, UseDates, Config> {
|
|
151
168
|
static Storage = Storage;
|
|
152
169
|
static NetworkListener = NetworkListener;
|
|
153
170
|
static EventSourceImpl = EventSourceImpl;
|
package/tsconfig.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
3
|
"include": ["src"],
|
|
4
|
-
"exclude": ["node_modules", "dist"],
|
|
4
|
+
"exclude": ["node_modules", "dist", "src/__types__"],
|
|
5
5
|
"compilerOptions": {
|
|
6
6
|
"outDir": "dist",
|
|
7
|
-
"rootDir": "src"
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strictNullChecks": true
|
|
8
9
|
}
|
|
9
10
|
}
|