@roko-app/instant-react-native 0.0.0-stage → 1.0.67-roko.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +59 -2
- package/__tests__/EventSourceShim.test.ts +104 -0
- 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 +32 -0
- package/dist/EventSourceShim.d.ts.map +1 -0
- package/dist/EventSourceShim.js +249 -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 +32 -0
- package/dist/module/EventSourceShim.d.ts.map +1 -0
- package/dist/module/EventSourceShim.js +247 -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 +30 -3
- package/src/EventSourceImpl.ts +6 -0
- package/src/EventSourceShim.ts +312 -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 +3 -0
- package/tsconfig.json +10 -0
- package/tsconfig.module.json +8 -0
- package/tsconfig.test.json +5 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StoreInterface = exports.SyncTableCallbackEventType = exports.setInstantWarningsEnabled = exports.InstantAPIError = exports.InstantReactNativeDatabase = exports.createInstantRouteHandler = exports.i = exports.lookup = exports.tx = exports.id = exports.init_experimental = void 0;
|
|
7
|
+
exports.init = init;
|
|
8
|
+
require("react-native-get-random-values");
|
|
9
|
+
const Storage_1 = __importDefault(require("./Storage"));
|
|
10
|
+
const EventSourceImpl_1 = __importDefault(require("./EventSourceImpl"));
|
|
11
|
+
const NetworkListener_1 = __importDefault(require("./NetworkListener"));
|
|
12
|
+
const version_1 = __importDefault(require("./version"));
|
|
13
|
+
const Streams_1 = require("./Streams");
|
|
14
|
+
const react_common_1 = require("@instantdb/react-common");
|
|
15
|
+
const core_1 = require("@instantdb/core");
|
|
16
|
+
Object.defineProperty(exports, "i", { enumerable: true, get: function () { return core_1.i; } });
|
|
17
|
+
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return core_1.id; } });
|
|
18
|
+
Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return core_1.tx; } });
|
|
19
|
+
Object.defineProperty(exports, "lookup", { enumerable: true, get: function () { return core_1.lookup; } });
|
|
20
|
+
Object.defineProperty(exports, "InstantAPIError", { enumerable: true, get: function () { return
|
|
21
|
+
// error
|
|
22
|
+
core_1.InstantAPIError; } });
|
|
23
|
+
Object.defineProperty(exports, "setInstantWarningsEnabled", { enumerable: true, get: function () { return core_1.setInstantWarningsEnabled; } });
|
|
24
|
+
Object.defineProperty(exports, "SyncTableCallbackEventType", { enumerable: true, get: function () { return
|
|
25
|
+
// sync table enums
|
|
26
|
+
core_1.SyncTableCallbackEventType; } });
|
|
27
|
+
Object.defineProperty(exports, "createInstantRouteHandler", { enumerable: true, get: function () { return
|
|
28
|
+
// types
|
|
29
|
+
core_1.createInstantRouteHandler; } });
|
|
30
|
+
Object.defineProperty(exports, "StoreInterface", { enumerable: true, get: function () { return core_1.StoreInterface; } });
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* The first step: init your application!
|
|
34
|
+
*
|
|
35
|
+
* Visit https://instantdb.com/dash to get your `appId` :)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* import { init } from "@instantdb/react-native"
|
|
39
|
+
*
|
|
40
|
+
* const db = init({ appId: "my-app-id" })
|
|
41
|
+
*
|
|
42
|
+
* // You can also provide a schema for type safety and editor autocomplete!
|
|
43
|
+
*
|
|
44
|
+
* import { init } from "@instantdb/react-native"
|
|
45
|
+
* import schema from ""../instant.schema.ts";
|
|
46
|
+
*
|
|
47
|
+
* const db = init({ appId: "my-app-id", schema })
|
|
48
|
+
*
|
|
49
|
+
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
50
|
+
*/
|
|
51
|
+
function init(
|
|
52
|
+
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
53
|
+
// as a non-nullable in the InstantConfig type.
|
|
54
|
+
config) {
|
|
55
|
+
const configStrict = {
|
|
56
|
+
ReadableStream: Streams_1.streamConstructors.ReadableStream,
|
|
57
|
+
WritableStream: Streams_1.streamConstructors.WritableStream,
|
|
58
|
+
...config,
|
|
59
|
+
useDateObjects: (config.useDateObjects ?? false),
|
|
60
|
+
};
|
|
61
|
+
return new InstantReactNativeDatabase(configStrict, {
|
|
62
|
+
'@instantdb/react': version_1.default,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated
|
|
67
|
+
* `init_experimental` is deprecated. You can replace it with `init`.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
*
|
|
71
|
+
* // Before
|
|
72
|
+
* import { init_experimental } from "@instantdb/react-native"
|
|
73
|
+
* const db = init_experimental({ ... });
|
|
74
|
+
*
|
|
75
|
+
* // After
|
|
76
|
+
* import { init } from "@instantdb/react-native"
|
|
77
|
+
* const db = init({ ... });
|
|
78
|
+
*/
|
|
79
|
+
const init_experimental = init;
|
|
80
|
+
exports.init_experimental = init_experimental;
|
|
81
|
+
class InstantReactNativeDatabase extends react_common_1.InstantReactAbstractDatabase {
|
|
82
|
+
static Store = Storage_1.default;
|
|
83
|
+
static NetworkListener = NetworkListener_1.default;
|
|
84
|
+
static EventSourceImpl = EventSourceImpl_1.default;
|
|
85
|
+
}
|
|
86
|
+
exports.InstantReactNativeDatabase = InstantReactNativeDatabase;
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AA0LE,oBAAI;AA1LN,0CAAwC;AAExC,wDAA8B;AAC9B,wEAAgD;AAChD,wEAAgD;AAChD,wDAAgC;AAChC,uCAA+C;AAE/C,0DAAuE;AAEvE,0CA+FyB;AAsFvB,kFApLA,QAAC,OAoLA;AAHD,mFAhLA,SAAE,OAgLA;AACF,mFAhLA,SAAE,OAgLA;AACF,uFAhLA,aAAM,OAgLA;AAMN;IArLA,QAAQ;IACR,sBAAe,OAoLA;AACf,0GApLA,gCAAyB,OAoLA;AAGzB;IArLA,mBAAmB;IACnB,iCAA0B,OAoLA;AAR1B;IA1KA,QAAQ;IACR,gCAAyB,OAyKA;AAmFzB,+FAjLA,qBAAc,OAiLA;AAxKhB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,IAAI;AAIX,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC;IAMD,MAAM,YAAY,GAAG;QACnB,cAAc,EAAE,4BAAkB,CAAC,cAAc;QACjD,cAAc,EAAE,4BAAkB,CAAC,cAAc;QACjD,GAAG,MAAM;QACT,cAAc,EAAE,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK,CAAa;KAC7D,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;IAC9D,MAAM,CAAC,KAAK,GAAG,iBAAK,CAAC;IACrB,MAAM,CAAC,eAAe,GAAG,yBAAe,CAAC;IACzC,MAAM,CAAC,eAAe,GAAG,yBAAe,CAAC;;AAWzC,gEAA0B","sourcesContent":["import 'react-native-get-random-values';\n\nimport Store from './Storage';\nimport EventSourceImpl from './EventSourceImpl';\nimport NetworkListener from './NetworkListener';\nimport version from './version';\nimport { streamConstructors } from './Streams';\n\nimport { InstantReactAbstractDatabase } from '@instantdb/react-common';\n\nimport {\n i,\n id,\n tx,\n lookup,\n // error\n InstantAPIError,\n setInstantWarningsEnabled,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n createInstantRouteHandler,\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 CheckMagicCodeParams,\n type CheckMagicCodeResponse,\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 StoreInterface,\n type StoreInterfaceStoreName,\n CreateReadStreamOpts,\n CreateWriteStreamOpts,\n InstantWritableStream,\n InstantReadableStream,\n type Logger,\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 ReadableStream: streamConstructors.ReadableStream,\n WritableStream: streamConstructors.WritableStream,\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 Store = Store;\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 createInstantRouteHandler,\n InstantReactNativeDatabase,\n\n // error\n InstantAPIError,\n setInstantWarningsEnabled,\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 CheckMagicCodeParams,\n type CheckMagicCodeResponse,\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 // stream types\n type CreateReadStreamOpts,\n type CreateWriteStreamOpts,\n type InstantWritableStream,\n type InstantReadableStream,\n\n // custom store\n StoreInterface,\n type StoreInterfaceStoreName,\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 // logger\n type Logger,\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import EventSourceShim from './EventSourceShim';
|
|
2
|
+
declare const EventSourceImpl: {
|
|
3
|
+
new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource;
|
|
4
|
+
prototype: EventSource;
|
|
5
|
+
readonly CONNECTING: 0;
|
|
6
|
+
readonly OPEN: 1;
|
|
7
|
+
readonly CLOSED: 2;
|
|
8
|
+
} | typeof EventSourceShim;
|
|
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;;;;;;0BAC+C,CAAC;AAErE,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSourceImpl.js","sourceRoot":"","sources":["../../src/EventSourceImpl.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,MAAM,eAAe,GACnB,OAAO,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,WAAW,CAAC;AAErE,eAAe,eAAe,CAAC","sourcesContent":["import EventSourceShim from './EventSourceShim';\n\nconst EventSourceImpl =\n typeof EventSource === 'undefined' ? EventSourceShim : EventSource;\n\nexport default EventSourceImpl;\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type EventSourceType } from '@instantdb/core';
|
|
2
|
+
declare class EventSource implements EventSourceType {
|
|
3
|
+
private ERROR;
|
|
4
|
+
static CONNECTING: number;
|
|
5
|
+
static OPEN: number;
|
|
6
|
+
static CLOSED: number;
|
|
7
|
+
static MAX_ACCUMULATED_LENGTH: number;
|
|
8
|
+
private CRLF;
|
|
9
|
+
private LF;
|
|
10
|
+
private CR;
|
|
11
|
+
readonly url: string;
|
|
12
|
+
onopen: any;
|
|
13
|
+
onerror: any;
|
|
14
|
+
onmessage: any;
|
|
15
|
+
debug: boolean;
|
|
16
|
+
private status;
|
|
17
|
+
private headers;
|
|
18
|
+
private _xhr;
|
|
19
|
+
private lineEndingCharacter;
|
|
20
|
+
private _lastIndexProcessed;
|
|
21
|
+
constructor(url: any);
|
|
22
|
+
get readyState(): number;
|
|
23
|
+
open(): void;
|
|
24
|
+
_logDebug(...msg: any[]): void;
|
|
25
|
+
_handleEvent(response: any): void;
|
|
26
|
+
_detectNewlineChar(response: any): string | null;
|
|
27
|
+
_getLastDoubleNewlineIndex(response: any): any;
|
|
28
|
+
dispatch(type: any, data: any): void;
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
export default EventSource;
|
|
32
|
+
//# 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,iBAAiB,CAAC;AAavD,cAAM,WAAY,YAAW,eAAe;IAC1C,OAAO,CAAC,KAAK,CAAM;IACnB,MAAM,CAAC,UAAU,SAAK;IACtB,MAAM,CAAC,IAAI,SAAK;IAChB,MAAM,CAAC,MAAM,SAAK;IASlB,MAAM,CAAC,sBAAsB,SAAmB;IAEhD,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;IAgHJ,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,247 @@
|
|
|
1
|
+
// Modified version of https://github.com/binaryminds/react-native-sse/blob/master/src/EventSource.js
|
|
2
|
+
// that conforms to our `EventSourceType` subset of the browser-native `EventSource`.
|
|
3
|
+
const XMLReadyStateMap = [
|
|
4
|
+
'UNSENT',
|
|
5
|
+
'OPENED',
|
|
6
|
+
'HEADERS_RECEIVED',
|
|
7
|
+
'LOADING',
|
|
8
|
+
'DONE',
|
|
9
|
+
];
|
|
10
|
+
class EventSource {
|
|
11
|
+
ERROR = -1;
|
|
12
|
+
static CONNECTING = 0;
|
|
13
|
+
static OPEN = 1;
|
|
14
|
+
static CLOSED = 2;
|
|
15
|
+
// [roko-db] RN's XHR accumulates the whole streamed body in one string and
|
|
16
|
+
// this shim never recycled the connection, so a long-lived SSE session (e.g.
|
|
17
|
+
// Mac Catalyst, where the WebSocket fallback pins Instant to SSE) grew it
|
|
18
|
+
// until Hermes threw a fatal "RangeError: String length exceeds limit".
|
|
19
|
+
// Past this many processed characters we abort and surface an SSE error;
|
|
20
|
+
// the consumer reconnects with a fresh instance (same path as a normal
|
|
21
|
+
// DONE), which resets the accumulator.
|
|
22
|
+
static MAX_ACCUMULATED_LENGTH = 8 * 1024 * 1024;
|
|
23
|
+
CRLF = '\r\n';
|
|
24
|
+
LF = '\n';
|
|
25
|
+
CR = '\r';
|
|
26
|
+
url;
|
|
27
|
+
onopen;
|
|
28
|
+
onerror;
|
|
29
|
+
onmessage;
|
|
30
|
+
debug;
|
|
31
|
+
status;
|
|
32
|
+
headers = {
|
|
33
|
+
Accept: 'text/event-stream',
|
|
34
|
+
'Cache-Control': 'no-cache',
|
|
35
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
36
|
+
};
|
|
37
|
+
_xhr;
|
|
38
|
+
lineEndingCharacter;
|
|
39
|
+
_lastIndexProcessed;
|
|
40
|
+
constructor(url) {
|
|
41
|
+
this.status = EventSource.CONNECTING;
|
|
42
|
+
this.lineEndingCharacter = null;
|
|
43
|
+
this._xhr = null;
|
|
44
|
+
this._lastIndexProcessed = 0;
|
|
45
|
+
this.debug = false;
|
|
46
|
+
if (!url || typeof url !== 'string') {
|
|
47
|
+
throw new SyntaxError('[EventSource] Invalid URL argument.');
|
|
48
|
+
}
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.open();
|
|
51
|
+
}
|
|
52
|
+
get readyState() {
|
|
53
|
+
if (this.status === this.ERROR) {
|
|
54
|
+
return EventSource.CLOSED;
|
|
55
|
+
}
|
|
56
|
+
return this.status;
|
|
57
|
+
}
|
|
58
|
+
open() {
|
|
59
|
+
try {
|
|
60
|
+
this.status = EventSource.CONNECTING;
|
|
61
|
+
this._lastIndexProcessed = 0;
|
|
62
|
+
this._xhr = new XMLHttpRequest();
|
|
63
|
+
this._xhr.open('GET', this.url, true);
|
|
64
|
+
for (const [key, value] of Object.entries(this.headers)) {
|
|
65
|
+
if (value !== undefined && value !== null) {
|
|
66
|
+
this._xhr.setRequestHeader(key, value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this._xhr.onreadystatechange = () => {
|
|
70
|
+
if (this.status === EventSource.CLOSED) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const xhr = this._xhr;
|
|
74
|
+
this._logDebug(`[EventSource][onreadystatechange] ReadyState: ${XMLReadyStateMap[xhr.readyState] || 'Unknown'}(${xhr.readyState}), status: ${xhr.status}`);
|
|
75
|
+
if (xhr.readyState !== XMLHttpRequest.DONE &&
|
|
76
|
+
xhr.readyState !== XMLHttpRequest.LOADING) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (xhr.status >= 200 && xhr.status < 400) {
|
|
80
|
+
if (this.status === EventSource.CONNECTING) {
|
|
81
|
+
this.status = EventSource.OPEN;
|
|
82
|
+
this.dispatch('open', { type: 'open' });
|
|
83
|
+
this._logDebug('[EventSource][onreadystatechange][OPEN] Connection opened.');
|
|
84
|
+
}
|
|
85
|
+
this._handleEvent(xhr.responseText || '');
|
|
86
|
+
// [roko-db] Recycle before the accumulated responseText can exceed
|
|
87
|
+
// Hermes' string cap (see MAX_ACCUMULATED_LENGTH).
|
|
88
|
+
if (xhr.readyState === XMLHttpRequest.LOADING &&
|
|
89
|
+
this._lastIndexProcessed > EventSource.MAX_ACCUMULATED_LENGTH) {
|
|
90
|
+
this._logDebug('[EventSource][onreadystatechange] Accumulated response cap reached — recycling connection.');
|
|
91
|
+
this.status = this.ERROR;
|
|
92
|
+
this.dispatch('error', {
|
|
93
|
+
type: 'error',
|
|
94
|
+
message: 'recycled: accumulated response cap reached',
|
|
95
|
+
});
|
|
96
|
+
xhr.abort();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
100
|
+
this._logDebug('[EventSource][onreadystatechange][DONE] Operation done.');
|
|
101
|
+
this.dispatch('error', { type: 'error' });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (xhr.status !== 0) {
|
|
105
|
+
this.status = this.ERROR;
|
|
106
|
+
this.dispatch('error', {
|
|
107
|
+
type: 'error',
|
|
108
|
+
message: xhr.responseText,
|
|
109
|
+
xhrStatus: xhr.status,
|
|
110
|
+
xhrState: xhr.readyState,
|
|
111
|
+
});
|
|
112
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
113
|
+
this._logDebug('[EventSource][onreadystatechange][ERROR] Response status error.');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
this._xhr.onerror = () => {
|
|
118
|
+
if (this.status === EventSource.CLOSED) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.status = this.ERROR;
|
|
122
|
+
this.dispatch('error', {
|
|
123
|
+
type: 'error',
|
|
124
|
+
message: this._xhr.responseText,
|
|
125
|
+
xhrStatus: this._xhr.status,
|
|
126
|
+
xhrState: this._xhr.readyState,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
this._xhr.send();
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
this.status = this.ERROR;
|
|
133
|
+
this.dispatch('error', {
|
|
134
|
+
type: 'exception',
|
|
135
|
+
message: e.message,
|
|
136
|
+
error: e,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
_logDebug(...msg) {
|
|
141
|
+
if (this.debug) {
|
|
142
|
+
console.debug(...msg);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
_handleEvent(response) {
|
|
146
|
+
if (this.lineEndingCharacter === null) {
|
|
147
|
+
const detectedNewlineChar = this._detectNewlineChar(response);
|
|
148
|
+
if (detectedNewlineChar !== null) {
|
|
149
|
+
this._logDebug(`[EventSource] Automatically detected lineEndingCharacter: ${JSON.stringify(detectedNewlineChar).slice(1, -1)}`);
|
|
150
|
+
this.lineEndingCharacter = detectedNewlineChar;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
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.");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const indexOfDoubleNewline = this._getLastDoubleNewlineIndex(response);
|
|
158
|
+
if (indexOfDoubleNewline <= this._lastIndexProcessed) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const parts = response
|
|
162
|
+
.substring(this._lastIndexProcessed, indexOfDoubleNewline)
|
|
163
|
+
.split(this.lineEndingCharacter);
|
|
164
|
+
this._lastIndexProcessed = indexOfDoubleNewline;
|
|
165
|
+
let type = undefined;
|
|
166
|
+
let data = [];
|
|
167
|
+
let line = '';
|
|
168
|
+
for (let i = 0; i < parts.length; i++) {
|
|
169
|
+
line = parts[i].trim();
|
|
170
|
+
if (line.startsWith('event')) {
|
|
171
|
+
type = line.replace(/event:?\s*/, '');
|
|
172
|
+
}
|
|
173
|
+
else if (line.startsWith('retry')) {
|
|
174
|
+
// Ignore for our use case, we'll reconnect with a new
|
|
175
|
+
// instance on error
|
|
176
|
+
}
|
|
177
|
+
else if (line.startsWith('data')) {
|
|
178
|
+
data.push(line.replace(/data:?\s*/, ''));
|
|
179
|
+
}
|
|
180
|
+
else if (line.startsWith('id')) {
|
|
181
|
+
// Ignore this, not used for our use case
|
|
182
|
+
}
|
|
183
|
+
else if (line === '') {
|
|
184
|
+
if (data.length > 0) {
|
|
185
|
+
const eventType = type || 'message';
|
|
186
|
+
const event = {
|
|
187
|
+
type: eventType,
|
|
188
|
+
data: data.join('\n'),
|
|
189
|
+
url: this.url,
|
|
190
|
+
};
|
|
191
|
+
this.dispatch(eventType, event);
|
|
192
|
+
data = [];
|
|
193
|
+
type = undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
_detectNewlineChar(response) {
|
|
199
|
+
const supportedLineEndings = [this.CRLF, this.LF, this.CR];
|
|
200
|
+
for (const char of supportedLineEndings) {
|
|
201
|
+
if (response.includes(char)) {
|
|
202
|
+
return char;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
_getLastDoubleNewlineIndex(response) {
|
|
208
|
+
const doubleLineEndingCharacter = this.lineEndingCharacter + this.lineEndingCharacter;
|
|
209
|
+
const lastIndex = response.lastIndexOf(doubleLineEndingCharacter);
|
|
210
|
+
if (lastIndex === -1) {
|
|
211
|
+
return -1;
|
|
212
|
+
}
|
|
213
|
+
return lastIndex + doubleLineEndingCharacter.length;
|
|
214
|
+
}
|
|
215
|
+
dispatch(type, data) {
|
|
216
|
+
switch (type) {
|
|
217
|
+
case 'open': {
|
|
218
|
+
if (this.onopen) {
|
|
219
|
+
this.onopen(data);
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case 'error': {
|
|
224
|
+
if (this.onerror) {
|
|
225
|
+
this.onerror(data);
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case 'message': {
|
|
230
|
+
if (this.onmessage) {
|
|
231
|
+
this.onmessage(data);
|
|
232
|
+
}
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
close() {
|
|
238
|
+
if (this.status !== EventSource.CLOSED) {
|
|
239
|
+
this.status = EventSource.CLOSED;
|
|
240
|
+
}
|
|
241
|
+
if (this._xhr) {
|
|
242
|
+
this._xhr.abort();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export default EventSource;
|
|
247
|
+
//# 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;IAElB,2EAA2E;IAC3E,6EAA6E;IAC7E,0EAA0E;IAC1E,wEAAwE;IACxE,yEAAyE;IACzE,uEAAuE;IACvE,uCAAuC;IACvC,MAAM,CAAC,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAExC,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,CAAC,MAAM,GAAG,WAAW,CAAC,UAAU,CAAC;QAErC,IAAI,CAA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C;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;;AAGH,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 // [roko-db] RN's XHR accumulates the whole streamed body in one string and\n // this shim never recycled the connection, so a long-lived SSE session (e.g.\n // Mac Catalyst, where the WebSocket fallback pins Instant to SSE) grew it\n // until Hermes threw a fatal \"RangeError: String length exceeds limit\".\n // Past this many processed characters we abort and surface an SSE error;\n // the consumer reconnects with a fresh instance (same path as a normal\n // DONE), which resets the accumulator.\n static MAX_ACCUMULATED_LENGTH = 8 * 1024 * 1024;\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 // [roko-db] Recycle before the accumulated responseText can exceed\n // Hermes' string cap (see MAX_ACCUMULATED_LENGTH).\n if (\n xhr.readyState === XMLHttpRequest.LOADING &&\n this._lastIndexProcessed > EventSource.MAX_ACCUMULATED_LENGTH\n ) {\n this._logDebug(\n '[EventSource][onreadystatechange] Accumulated response cap reached — recycling connection.',\n );\n this.status = this.ERROR;\n this.dispatch('error', {\n type: 'error',\n message: 'recycled: accumulated response cap reached',\n });\n xhr.abort();\n return;\n }\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,13 @@
|
|
|
1
|
+
import NetInfo from '@react-native-community/netinfo';
|
|
2
|
+
export default class NetworkListener {
|
|
3
|
+
static async getIsOnline() {
|
|
4
|
+
const network = await NetInfo.fetch();
|
|
5
|
+
return network.isConnected;
|
|
6
|
+
}
|
|
7
|
+
static listen(f) {
|
|
8
|
+
return NetInfo.addEventListener((state) => {
|
|
9
|
+
f(state.isConnected);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=NetworkListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkListener.js","sourceRoot":"","sources":["../../src/NetworkListener.js"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,iCAAiC,CAAC;AAEtD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,MAAM,CAAC,KAAK,CAAC,WAAW;QACtB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC,WAAW,CAAC;IAC7B,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,CAAC;QACb,OAAO,OAAO,CAAC,gBAAgB,CAAC,CAAC,KAAK,EAAE,EAAE;YACxC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF","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,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../../src/Storage.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,eAAe,gBAAgB,CAAC","sourcesContent":["import { IndexedDBStorage } from '@instantdb/core';\n\nexport default IndexedDBStorage;\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StoreInterface, StoreInterfaceStoreName } from '@instantdb/core';
|
|
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,iBAAiB,CAAC;AAkB1E,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,75 @@
|
|
|
1
|
+
import { StoreInterface } from '@instantdb/core';
|
|
2
|
+
const version = 5;
|
|
3
|
+
// AsyncStorage is an optional peer dependency. The `require` must sit
|
|
4
|
+
// directly inside a `try` block: that's what makes Metro treat it as an
|
|
5
|
+
// optional dependency (`transformer.allowOptionalDependencies`, enabled by
|
|
6
|
+
// default in the Expo and React Native metro configs), so bundling doesn't
|
|
7
|
+
// fail when it isn't installed. When it can't be loaded, `init` surfaces a
|
|
8
|
+
// helpful error unless a custom `Store` is passed.
|
|
9
|
+
let AsyncStorage = null;
|
|
10
|
+
let asyncStorageLoadError = null;
|
|
11
|
+
try {
|
|
12
|
+
AsyncStorage = require('@react-native-async-storage/async-storage').default;
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
asyncStorageLoadError = e;
|
|
16
|
+
}
|
|
17
|
+
export class AsyncStorageStore extends StoreInterface {
|
|
18
|
+
appId;
|
|
19
|
+
dbName;
|
|
20
|
+
constructor(appId, dbName) {
|
|
21
|
+
super(appId, dbName);
|
|
22
|
+
this.appId = appId;
|
|
23
|
+
this.dbName = dbName;
|
|
24
|
+
}
|
|
25
|
+
makeKey(k) {
|
|
26
|
+
return `instant_${this.appId}_${version}_${this.dbName}_${k}`;
|
|
27
|
+
}
|
|
28
|
+
async getItem(k) {
|
|
29
|
+
const res = await AsyncStorage.getItem(this.makeKey(k));
|
|
30
|
+
if (res === null)
|
|
31
|
+
return res;
|
|
32
|
+
return JSON.parse(res);
|
|
33
|
+
}
|
|
34
|
+
async setItem(k, v) {
|
|
35
|
+
await AsyncStorage.setItem(this.makeKey(k), JSON.stringify(v));
|
|
36
|
+
}
|
|
37
|
+
async removeItem(k) {
|
|
38
|
+
await AsyncStorage.removeItem(this.makeKey(k));
|
|
39
|
+
}
|
|
40
|
+
async getAllKeys() {
|
|
41
|
+
const allKeys = await AsyncStorage.getAllKeys();
|
|
42
|
+
const keys = [];
|
|
43
|
+
const keyPrefix = this.makeKey('');
|
|
44
|
+
for (const key of allKeys) {
|
|
45
|
+
if (key.startsWith(keyPrefix)) {
|
|
46
|
+
keys.push(key.substring(keyPrefix.length));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return keys;
|
|
50
|
+
}
|
|
51
|
+
async multiSet(keyValuePairs) {
|
|
52
|
+
await AsyncStorage.multiSet(keyValuePairs.map(([k, v]) => [this.makeKey(k), JSON.stringify(v)]));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class MissingStore extends StoreInterface {
|
|
56
|
+
constructor(appId, dbName) {
|
|
57
|
+
super(appId, dbName);
|
|
58
|
+
throw new Error('Instant needs a store to persist data on device. ' +
|
|
59
|
+
'Install `@react-native-async-storage/async-storage`, ' +
|
|
60
|
+
'or pass a `Store` to `init` (e.g. from `@instantdb/react-native-mmkv` or `@instantdb/expo-sqlite`).' +
|
|
61
|
+
(asyncStorageLoadError
|
|
62
|
+
? `\n\nLoading async-storage failed with: ${asyncStorageLoadError}`
|
|
63
|
+
: ''));
|
|
64
|
+
}
|
|
65
|
+
async getItem(_k) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
async removeItem(_k) { }
|
|
69
|
+
async multiSet(_keyValuePairs) { }
|
|
70
|
+
async getAllKeys() {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export default AsyncStorage ? AsyncStorageStore : MissingStore;
|
|
75
|
+
//# sourceMappingURL=Storage.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.native.js","sourceRoot":"","sources":["../../src/Storage.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA2B,MAAM,iBAAiB,CAAC;AAE1E,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,CAAC;IACX,qBAAqB,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IAC3C,KAAK,CAAS;IACd,MAAM,CAA0B;IACxC,YAAY,KAAa,EAAE,MAA+B;QACxD,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;IAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACb,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACxD,IAAI,GAAG,KAA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AAM,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,eAAe,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC","sourcesContent":["import { StoreInterface, StoreInterfaceStoreName } from '@instantdb/core';\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"}
|