@roko-app/instant-react-native 0.0.0-stage → 1.0.67-roko.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +59 -2
  3. package/__tests__/EventSourceShim.test.ts +104 -0
  4. package/dist/EventSourceImpl.d.ts +10 -0
  5. package/dist/EventSourceImpl.d.ts.map +1 -0
  6. package/dist/EventSourceImpl.js +9 -0
  7. package/dist/EventSourceImpl.js.map +1 -0
  8. package/dist/EventSourceShim.d.ts +32 -0
  9. package/dist/EventSourceShim.d.ts.map +1 -0
  10. package/dist/EventSourceShim.js +249 -0
  11. package/dist/EventSourceShim.js.map +1 -0
  12. package/dist/NetworkListener.d.ts +5 -0
  13. package/dist/NetworkListener.d.ts.map +1 -0
  14. package/dist/NetworkListener.js +19 -0
  15. package/dist/NetworkListener.js.map +1 -0
  16. package/dist/Storage.d.ts +3 -0
  17. package/dist/Storage.d.ts.map +1 -0
  18. package/dist/Storage.js +5 -0
  19. package/dist/Storage.js.map +1 -0
  20. package/dist/Storage.native.d.ts +22 -0
  21. package/dist/Storage.native.d.ts.map +1 -0
  22. package/dist/Storage.native.js +79 -0
  23. package/dist/Storage.native.js.map +1 -0
  24. package/dist/Streams.d.ts +15 -0
  25. package/dist/Streams.d.ts.map +1 -0
  26. package/dist/Streams.js +9 -0
  27. package/dist/Streams.js.map +1 -0
  28. package/dist/Streams.native.d.ts +6 -0
  29. package/dist/Streams.native.d.ts.map +1 -0
  30. package/dist/Streams.native.js +9 -0
  31. package/dist/Streams.native.js.map +1 -0
  32. package/dist/cli.d.ts +2 -0
  33. package/dist/cli.d.ts.map +1 -0
  34. package/dist/cli.js +18 -0
  35. package/dist/cli.js.map +1 -0
  36. package/dist/index.d.ts +56 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +87 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/module/EventSourceImpl.d.ts +10 -0
  41. package/dist/module/EventSourceImpl.d.ts.map +1 -0
  42. package/dist/module/EventSourceImpl.js +4 -0
  43. package/dist/module/EventSourceImpl.js.map +1 -0
  44. package/dist/module/EventSourceShim.d.ts +32 -0
  45. package/dist/module/EventSourceShim.d.ts.map +1 -0
  46. package/dist/module/EventSourceShim.js +247 -0
  47. package/dist/module/EventSourceShim.js.map +1 -0
  48. package/dist/module/NetworkListener.d.ts +5 -0
  49. package/dist/module/NetworkListener.d.ts.map +1 -0
  50. package/dist/module/NetworkListener.js +13 -0
  51. package/dist/module/NetworkListener.js.map +1 -0
  52. package/dist/module/Storage.d.ts +3 -0
  53. package/dist/module/Storage.d.ts.map +1 -0
  54. package/dist/module/Storage.js +3 -0
  55. package/dist/module/Storage.js.map +1 -0
  56. package/dist/module/Storage.native.d.ts +22 -0
  57. package/dist/module/Storage.native.d.ts.map +1 -0
  58. package/dist/module/Storage.native.js +75 -0
  59. package/dist/module/Storage.native.js.map +1 -0
  60. package/dist/module/Streams.d.ts +15 -0
  61. package/dist/module/Streams.d.ts.map +1 -0
  62. package/dist/module/Streams.js +6 -0
  63. package/dist/module/Streams.js.map +1 -0
  64. package/dist/module/Streams.native.d.ts +6 -0
  65. package/dist/module/Streams.native.d.ts.map +1 -0
  66. package/dist/module/Streams.native.js +6 -0
  67. package/dist/module/Streams.native.js.map +1 -0
  68. package/dist/module/cli.d.ts +2 -0
  69. package/dist/module/cli.d.ts.map +1 -0
  70. package/dist/module/cli.js +2 -0
  71. package/dist/module/cli.js.map +1 -0
  72. package/dist/module/index.d.ts +56 -0
  73. package/dist/module/index.d.ts.map +1 -0
  74. package/dist/module/index.js +76 -0
  75. package/dist/module/index.js.map +1 -0
  76. package/dist/module/version.d.ts +3 -0
  77. package/dist/module/version.d.ts.map +1 -0
  78. package/dist/module/version.js +3 -0
  79. package/dist/module/version.js.map +1 -0
  80. package/dist/version.d.ts +3 -0
  81. package/dist/version.d.ts.map +1 -0
  82. package/dist/version.js +5 -0
  83. package/dist/version.js.map +1 -0
  84. package/package.json +30 -3
  85. package/src/EventSourceImpl.ts +6 -0
  86. package/src/EventSourceShim.ts +312 -0
  87. package/src/NetworkListener.js +13 -0
  88. package/src/Storage.js +3 -0
  89. package/src/Storage.native.ts +91 -0
  90. package/src/Streams.native.ts +6 -0
  91. package/src/Streams.ts +5 -0
  92. package/src/__types__/typeUtils.ts +39 -0
  93. package/src/__types__/typesTests.ts +86 -0
  94. package/src/cli.ts +1 -0
  95. package/src/index.ts +290 -0
  96. package/src/version.ts +3 -0
  97. package/tsconfig.json +10 -0
  98. package/tsconfig.module.json +8 -0
  99. package/tsconfig.test.json +5 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Streams.js","sourceRoot":"","sources":["../../src/Streams.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,cAAc,EAAE,cAAc;IAC9B,cAAc,EAAE,cAAc;CAC/B,CAAC","sourcesContent":["// RN may need a polyfill for streams, so we put those in Streams.native.ts\nexport const streamConstructors = {\n ReadableStream: ReadableStream,\n WritableStream: WritableStream,\n};\n"]}
@@ -0,0 +1,6 @@
1
+ import { ReadableStream, WritableStream } from 'web-streams-polyfill';
2
+ export declare const streamConstructors: {
3
+ ReadableStream: typeof ReadableStream;
4
+ WritableStream: typeof WritableStream;
5
+ };
6
+ //# sourceMappingURL=Streams.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Streams.native.d.ts","sourceRoot":"","sources":["../../src/Streams.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtE,eAAO,MAAM,kBAAkB;;;CAG9B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { ReadableStream, WritableStream } from 'web-streams-polyfill';
2
+ export const streamConstructors = {
3
+ ReadableStream: ReadableStream,
4
+ WritableStream: WritableStream,
5
+ };
6
+ //# sourceMappingURL=Streams.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Streams.native.js","sourceRoot":"","sources":["../../src/Streams.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,cAAc,EAAE,cAAc;IAC9B,cAAc,EAAE,cAAc;CAC/B,CAAC","sourcesContent":["import { ReadableStream, WritableStream } from 'web-streams-polyfill';\n\nexport const streamConstructors = {\n ReadableStream: ReadableStream,\n WritableStream: WritableStream,\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export * from '@instantdb/core';
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '@instantdb/core';
2
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from '@instantdb/core';\n"]}
@@ -0,0 +1,56 @@
1
+ import 'react-native-get-random-values';
2
+ import Store from './Storage';
3
+ import NetworkListener from './NetworkListener';
4
+ import { InstantReactAbstractDatabase } from '@instantdb/react-common';
5
+ import { i, id, tx, lookup, InstantAPIError, setInstantWarningsEnabled, SyncTableCallbackEventType, createInstantRouteHandler, type RoomSchemaShape, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type ConnectionStatus, type BackwardsCompatibleSchema, type IInstantDatabase, type Config, type Query, type QueryResponse, type InstantObject, type AuthState, type User, type PresencePeer, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type InstantUnknownSchemaDef, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type InstantEntity, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type RoomsOf, type RoomsDef, type PresenceOf, type TopicsOf, type TopicOf, type RoomHandle, type CreateParams, type InstantConfig, type InstantSchemaDef, type InstantUnknownSchema, type TransactionChunk, type InstantRules, type UpdateParams, type LinkParams, type ValidQuery, type CheckMagicCodeParams, type CheckMagicCodeResponse, type ExchangeCodeForTokenParams, type SendMagicCodeParams, type SendMagicCodeResponse, type SignInWithIdTokenParams, type VerifyMagicCodeParams, type VerifyResponse, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type SyncTableCallback, type SyncTableCallbackEvent, type SyncTableInitialSyncBatch, type SyncTableInitialSyncComplete, type SyncTableSyncTransaction, type SyncTableLoadFromStorage, type SyncTableSetupError, StoreInterface, type StoreInterfaceStoreName, CreateReadStreamOpts, CreateWriteStreamOpts, InstantWritableStream, InstantReadableStream, type Logger } from '@instantdb/core';
6
+ /**
7
+ *
8
+ * The first step: init your application!
9
+ *
10
+ * Visit https://instantdb.com/dash to get your `appId` :)
11
+ *
12
+ * @example
13
+ * import { init } from "@instantdb/react-native"
14
+ *
15
+ * const db = init({ appId: "my-app-id" })
16
+ *
17
+ * // You can also provide a schema for type safety and editor autocomplete!
18
+ *
19
+ * import { init } from "@instantdb/react-native"
20
+ * import schema from ""../instant.schema.ts";
21
+ *
22
+ * const db = init({ appId: "my-app-id", schema })
23
+ *
24
+ * // To learn more: https://instantdb.com/docs/modeling-data
25
+ */
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>>;
29
+ /**
30
+ * @deprecated
31
+ * `init_experimental` is deprecated. You can replace it with `init`.
32
+ *
33
+ * @example
34
+ *
35
+ * // Before
36
+ * import { init_experimental } from "@instantdb/react-native"
37
+ * const db = init_experimental({ ... });
38
+ *
39
+ * // After
40
+ * import { init } from "@instantdb/react-native"
41
+ * const db = init({ ... });
42
+ */
43
+ declare const init_experimental: typeof init;
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> {
45
+ static Store: typeof Store;
46
+ static NetworkListener: typeof NetworkListener;
47
+ static EventSourceImpl: {
48
+ new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource;
49
+ prototype: EventSource;
50
+ readonly CONNECTING: 0;
51
+ readonly OPEN: 1;
52
+ readonly CLOSED: 2;
53
+ } | typeof import("./EventSourceShim").default;
54
+ }
55
+ export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, InstantReactNativeDatabase, InstantAPIError, setInstantWarningsEnabled, SyncTableCallbackEventType, type Config, type Query, type QueryResponse, type InstantObject, type User, type AuthState, type ConnectionStatus, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type IInstantDatabase, type InstantEntity, type RoomSchemaShape, type PresencePeer, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type CreateParams, type LinkAttrDef, type InstantConfig, type LinkDef, type InstantUnknownSchemaDef, type LinksDef, type RoomsOf, type RoomsDef, type RoomHandle, type PresenceOf, type TopicsOf, type TopicOf, type ResolveAttrs, type ValueTypes, type InstaQLEntity, type InstaQLResult, type InstaQLEntitySubquery, type InstantSchemaDef, type InstantUnknownSchema, type BackwardsCompatibleSchema, type InstantRules, type UpdateParams, type LinkParams, type ValidQuery, type CheckMagicCodeParams, type CheckMagicCodeResponse, type ExchangeCodeForTokenParams, type SendMagicCodeParams, type TransactionChunk, type SendMagicCodeResponse, type SignInWithIdTokenParams, type VerifyMagicCodeParams, type VerifyResponse, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type InstantWritableStream, type InstantReadableStream, StoreInterface, type StoreInterfaceStoreName, type SyncTableCallback, type SyncTableCallbackEvent, type SyncTableInitialSyncBatch, type SyncTableInitialSyncComplete, type SyncTableSyncTransaction, type SyncTableLoadFromStorage, type SyncTableSetupError, type Logger, };
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,76 @@
1
+ import 'react-native-get-random-values';
2
+ import Store from './Storage';
3
+ import EventSourceImpl from './EventSourceImpl';
4
+ import NetworkListener from './NetworkListener';
5
+ import version from './version';
6
+ import { streamConstructors } from './Streams';
7
+ import { InstantReactAbstractDatabase } from '@instantdb/react-common';
8
+ import { i, id, tx, lookup,
9
+ // error
10
+ InstantAPIError, setInstantWarningsEnabled,
11
+ // sync table enums
12
+ SyncTableCallbackEventType,
13
+ // types
14
+ createInstantRouteHandler, StoreInterface, } from '@instantdb/core';
15
+ /**
16
+ *
17
+ * The first step: init your application!
18
+ *
19
+ * Visit https://instantdb.com/dash to get your `appId` :)
20
+ *
21
+ * @example
22
+ * import { init } from "@instantdb/react-native"
23
+ *
24
+ * const db = init({ appId: "my-app-id" })
25
+ *
26
+ * // You can also provide a schema for type safety and editor autocomplete!
27
+ *
28
+ * import { init } from "@instantdb/react-native"
29
+ * import schema from ""../instant.schema.ts";
30
+ *
31
+ * const db = init({ appId: "my-app-id", schema })
32
+ *
33
+ * // To learn more: https://instantdb.com/docs/modeling-data
34
+ */
35
+ function init(
36
+ // Allows config with missing `useDateObjects`, but keeps `UseDates`
37
+ // as a non-nullable in the InstantConfig type.
38
+ config) {
39
+ const configStrict = {
40
+ ReadableStream: streamConstructors.ReadableStream,
41
+ WritableStream: streamConstructors.WritableStream,
42
+ ...config,
43
+ useDateObjects: (config.useDateObjects ?? false),
44
+ };
45
+ return new InstantReactNativeDatabase(configStrict, {
46
+ '@instantdb/react': version,
47
+ });
48
+ }
49
+ /**
50
+ * @deprecated
51
+ * `init_experimental` is deprecated. You can replace it with `init`.
52
+ *
53
+ * @example
54
+ *
55
+ * // Before
56
+ * import { init_experimental } from "@instantdb/react-native"
57
+ * const db = init_experimental({ ... });
58
+ *
59
+ * // After
60
+ * import { init } from "@instantdb/react-native"
61
+ * const db = init({ ... });
62
+ */
63
+ const init_experimental = init;
64
+ class InstantReactNativeDatabase extends InstantReactAbstractDatabase {
65
+ static Store = Store;
66
+ static NetworkListener = NetworkListener;
67
+ static EventSourceImpl = EventSourceImpl;
68
+ }
69
+ export { init, init_experimental, id, tx, lookup, i, createInstantRouteHandler, InstantReactNativeDatabase,
70
+ // error
71
+ InstantAPIError, setInstantWarningsEnabled,
72
+ // sync table enums
73
+ SyncTableCallbackEventType,
74
+ // custom store
75
+ StoreInterface, };
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EACL,CAAC,EACD,EAAE,EACF,EAAE,EACF,MAAM;AACN,QAAQ;AACR,eAAe,EACf,yBAAyB;AAEzB,mBAAmB;AACnB,0BAA0B;AAE1B,QAAQ;AACR,yBAAyB,EA2EzB,cAAc,GAOf,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,IAAI;AAIX,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC;IAMD,MAAM,YAAY,GAAG;QACnB,cAAc,EAAE,kBAAkB,CAAC,cAAc;QACjD,cAAc,EAAE,kBAAkB,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,OAAO;KAC5B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,0BAOJ,SAAQ,4BAAsD;IAC9D,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;;AAG3C,OAAO,EACL,IAAI,EACJ,iBAAiB,EACjB,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC,EACD,yBAAyB,EACzB,0BAA0B;AAE1B,QAAQ;AACR,eAAe,EACf,yBAAyB;AAEzB,mBAAmB;AACnB,0BAA0B;AA0E1B,eAAe;AACf,cAAc,GAcf,CAAC","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,3 @@
1
+ import { version } from '@instantdb/version';
2
+ export default version;
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,eAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { version } from '@instantdb/version';
2
+ export default version;
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,eAAe,OAAO,CAAC","sourcesContent":["import { version } from '@instantdb/version';\n\nexport default version;\n"]}
@@ -0,0 +1,3 @@
1
+ import { version } from '@instantdb/version';
2
+ export default version;
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,eAAe,OAAO,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const version_1 = require("@instantdb/version");
4
+ exports.default = version_1.version;
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,gDAA6C;AAE7C,kBAAe,iBAAO,CAAC","sourcesContent":["import { version } from '@instantdb/version';\n\nexport default version;\n"]}
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@roko-app/instant-react-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.67-roko.1",
4
+ "description": "Instant DB for React Native (Roko DB build of @instantdb/react-native)",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://github.com/ErionTp/roko-db",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ErionTp/roko-db.git"
10
+ },
11
+ "main": "dist/index.js",
12
+ "module": "dist/module/index.js",
13
+ "types": "dist/module/index.d.ts",
14
+ "unpkg": "dist/index.js",
15
+ "peerDependencies": {
16
+ "@react-native-async-storage/async-storage": ">=1.15",
17
+ "@react-native-community/netinfo": ">=7.1",
18
+ "react": ">=16",
19
+ "react-native": ">=0.56",
20
+ "react-native-get-random-values": ">=1.5"
21
+ },
22
+ "peerDependenciesMeta": {
23
+ "@react-native-async-storage/async-storage": {
24
+ "optional": true
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@instantdb/core": "npm:@roko-app/instant-core@1.0.67-roko.1",
29
+ "@instantdb/react-common": "npm:@roko-app/instant-react-common@1.0.67-roko.1",
30
+ "@instantdb/version": "npm:@roko-app/instant-version@1.0.67-roko.1",
31
+ "web-streams-polyfill": "^4.2.0"
32
+ }
6
33
  }
@@ -0,0 +1,6 @@
1
+ import EventSourceShim from './EventSourceShim';
2
+
3
+ const EventSourceImpl =
4
+ typeof EventSource === 'undefined' ? EventSourceShim : EventSource;
5
+
6
+ export default EventSourceImpl;
@@ -0,0 +1,312 @@
1
+ import { type EventSourceType } from '@instantdb/core';
2
+
3
+ // Modified version of https://github.com/binaryminds/react-native-sse/blob/master/src/EventSource.js
4
+ // that conforms to our `EventSourceType` subset of the browser-native `EventSource`.
5
+
6
+ const XMLReadyStateMap = [
7
+ 'UNSENT',
8
+ 'OPENED',
9
+ 'HEADERS_RECEIVED',
10
+ 'LOADING',
11
+ 'DONE',
12
+ ];
13
+
14
+ class EventSource implements EventSourceType {
15
+ private ERROR = -1;
16
+ static CONNECTING = 0;
17
+ static OPEN = 1;
18
+ static CLOSED = 2;
19
+
20
+ // [roko-db] RN's XHR accumulates the whole streamed body in one string and
21
+ // this shim never recycled the connection, so a long-lived SSE session (e.g.
22
+ // Mac Catalyst, where the WebSocket fallback pins Instant to SSE) grew it
23
+ // until Hermes threw a fatal "RangeError: String length exceeds limit".
24
+ // Past this many processed characters we abort and surface an SSE error;
25
+ // the consumer reconnects with a fresh instance (same path as a normal
26
+ // DONE), which resets the accumulator.
27
+ static MAX_ACCUMULATED_LENGTH = 8 * 1024 * 1024;
28
+
29
+ private CRLF = '\r\n';
30
+ private LF = '\n';
31
+ private CR = '\r';
32
+
33
+ readonly url: string;
34
+
35
+ onopen;
36
+ onerror;
37
+ onmessage;
38
+
39
+ debug: boolean;
40
+
41
+ private status: number;
42
+
43
+ private headers = {
44
+ Accept: 'text/event-stream',
45
+ 'Cache-Control': 'no-cache',
46
+ 'X-Requested-With': 'XMLHttpRequest',
47
+ };
48
+
49
+ private _xhr: XMLHttpRequest | null;
50
+ private lineEndingCharacter: string | null;
51
+ private _lastIndexProcessed: number;
52
+
53
+ constructor(url) {
54
+ this.status = EventSource.CONNECTING;
55
+
56
+ this.lineEndingCharacter = null;
57
+ this._xhr = null;
58
+ this._lastIndexProcessed = 0;
59
+ this.debug = false;
60
+
61
+ if (!url || typeof url !== 'string') {
62
+ throw new SyntaxError('[EventSource] Invalid URL argument.');
63
+ }
64
+
65
+ this.url = url;
66
+
67
+ this.open();
68
+ }
69
+
70
+ public get readyState() {
71
+ if (this.status === this.ERROR) {
72
+ return EventSource.CLOSED;
73
+ }
74
+ return this.status;
75
+ }
76
+
77
+ open() {
78
+ try {
79
+ this.status = EventSource.CONNECTING;
80
+
81
+ this._lastIndexProcessed = 0;
82
+
83
+ this._xhr = new XMLHttpRequest();
84
+ this._xhr.open('GET', this.url, true);
85
+
86
+ for (const [key, value] of Object.entries(this.headers)) {
87
+ if (value !== undefined && value !== null) {
88
+ this._xhr.setRequestHeader(key, value);
89
+ }
90
+ }
91
+
92
+ this._xhr.onreadystatechange = () => {
93
+ if (this.status === EventSource.CLOSED) {
94
+ return;
95
+ }
96
+
97
+ const xhr = this._xhr!;
98
+
99
+ this._logDebug(
100
+ `[EventSource][onreadystatechange] ReadyState: ${XMLReadyStateMap[xhr.readyState] || 'Unknown'}(${
101
+ xhr.readyState
102
+ }), status: ${xhr.status}`,
103
+ );
104
+
105
+ if (
106
+ xhr.readyState !== XMLHttpRequest.DONE &&
107
+ xhr.readyState !== XMLHttpRequest.LOADING
108
+ ) {
109
+ return;
110
+ }
111
+
112
+ if (xhr.status >= 200 && xhr.status < 400) {
113
+ if (this.status === EventSource.CONNECTING) {
114
+ this.status = EventSource.OPEN;
115
+ this.dispatch('open', { type: 'open' });
116
+ this._logDebug(
117
+ '[EventSource][onreadystatechange][OPEN] Connection opened.',
118
+ );
119
+ }
120
+
121
+ this._handleEvent(xhr.responseText || '');
122
+
123
+ // [roko-db] Recycle before the accumulated responseText can exceed
124
+ // Hermes' string cap (see MAX_ACCUMULATED_LENGTH).
125
+ if (
126
+ xhr.readyState === XMLHttpRequest.LOADING &&
127
+ this._lastIndexProcessed > EventSource.MAX_ACCUMULATED_LENGTH
128
+ ) {
129
+ this._logDebug(
130
+ '[EventSource][onreadystatechange] Accumulated response cap reached — recycling connection.',
131
+ );
132
+ this.status = this.ERROR;
133
+ this.dispatch('error', {
134
+ type: 'error',
135
+ message: 'recycled: accumulated response cap reached',
136
+ });
137
+ xhr.abort();
138
+ return;
139
+ }
140
+
141
+ if (xhr.readyState === XMLHttpRequest.DONE) {
142
+ this._logDebug(
143
+ '[EventSource][onreadystatechange][DONE] Operation done.',
144
+ );
145
+ this.dispatch('error', { type: 'error' });
146
+ }
147
+ } else if (xhr.status !== 0) {
148
+ this.status = this.ERROR;
149
+ this.dispatch('error', {
150
+ type: 'error',
151
+ message: xhr.responseText,
152
+ xhrStatus: xhr.status,
153
+ xhrState: xhr.readyState,
154
+ });
155
+
156
+ if (xhr.readyState === XMLHttpRequest.DONE) {
157
+ this._logDebug(
158
+ '[EventSource][onreadystatechange][ERROR] Response status error.',
159
+ );
160
+ }
161
+ }
162
+ };
163
+
164
+ this._xhr.onerror = () => {
165
+ if (this.status === EventSource.CLOSED) {
166
+ return;
167
+ }
168
+
169
+ this.status = this.ERROR;
170
+ this.dispatch('error', {
171
+ type: 'error',
172
+ message: this._xhr!.responseText,
173
+ xhrStatus: this._xhr!.status,
174
+ xhrState: this._xhr!.readyState,
175
+ });
176
+ };
177
+
178
+ this._xhr.send();
179
+ } catch (e) {
180
+ this.status = this.ERROR;
181
+ this.dispatch('error', {
182
+ type: 'exception',
183
+ message: e.message,
184
+ error: e,
185
+ });
186
+ }
187
+ }
188
+
189
+ _logDebug(...msg) {
190
+ if (this.debug) {
191
+ console.debug(...msg);
192
+ }
193
+ }
194
+
195
+ _handleEvent(response) {
196
+ if (this.lineEndingCharacter === null) {
197
+ const detectedNewlineChar = this._detectNewlineChar(response);
198
+ if (detectedNewlineChar !== null) {
199
+ this._logDebug(
200
+ `[EventSource] Automatically detected lineEndingCharacter: ${JSON.stringify(
201
+ detectedNewlineChar,
202
+ ).slice(1, -1)}`,
203
+ );
204
+ this.lineEndingCharacter = detectedNewlineChar;
205
+ } else {
206
+ console.warn(
207
+ "[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.",
208
+ );
209
+ return;
210
+ }
211
+ }
212
+
213
+ const indexOfDoubleNewline = this._getLastDoubleNewlineIndex(response);
214
+ if (indexOfDoubleNewline <= this._lastIndexProcessed) {
215
+ return;
216
+ }
217
+
218
+ const parts = response
219
+ .substring(this._lastIndexProcessed, indexOfDoubleNewline)
220
+ .split(this.lineEndingCharacter);
221
+
222
+ this._lastIndexProcessed = indexOfDoubleNewline;
223
+
224
+ let type: string | undefined = undefined;
225
+ let data: string[] = [];
226
+ let line = '';
227
+
228
+ for (let i = 0; i < parts.length; i++) {
229
+ line = parts[i].trim();
230
+ if (line.startsWith('event')) {
231
+ type = line.replace(/event:?\s*/, '');
232
+ } else if (line.startsWith('retry')) {
233
+ // Ignore for our use case, we'll reconnect with a new
234
+ // instance on error
235
+ } else if (line.startsWith('data')) {
236
+ data.push(line.replace(/data:?\s*/, ''));
237
+ } else if (line.startsWith('id')) {
238
+ // Ignore this, not used for our use case
239
+ } else if (line === '') {
240
+ if (data.length > 0) {
241
+ const eventType = type || 'message';
242
+ const event = {
243
+ type: eventType,
244
+ data: data.join('\n'),
245
+ url: this.url,
246
+ };
247
+
248
+ this.dispatch(eventType, event);
249
+
250
+ data = [];
251
+ type = undefined;
252
+ }
253
+ }
254
+ }
255
+ }
256
+
257
+ _detectNewlineChar(response) {
258
+ const supportedLineEndings = [this.CRLF, this.LF, this.CR];
259
+ for (const char of supportedLineEndings) {
260
+ if (response.includes(char)) {
261
+ return char;
262
+ }
263
+ }
264
+ return null;
265
+ }
266
+
267
+ _getLastDoubleNewlineIndex(response) {
268
+ const doubleLineEndingCharacter =
269
+ this.lineEndingCharacter! + this.lineEndingCharacter!;
270
+ const lastIndex = response.lastIndexOf(doubleLineEndingCharacter);
271
+ if (lastIndex === -1) {
272
+ return -1;
273
+ }
274
+
275
+ return lastIndex + doubleLineEndingCharacter.length;
276
+ }
277
+
278
+ dispatch(type, data) {
279
+ switch (type) {
280
+ case 'open': {
281
+ if (this.onopen) {
282
+ this.onopen(data);
283
+ }
284
+ break;
285
+ }
286
+ case 'error': {
287
+ if (this.onerror) {
288
+ this.onerror(data);
289
+ }
290
+ break;
291
+ }
292
+ case 'message': {
293
+ if (this.onmessage) {
294
+ this.onmessage(data);
295
+ }
296
+ break;
297
+ }
298
+ }
299
+ }
300
+
301
+ close() {
302
+ if (this.status !== EventSource.CLOSED) {
303
+ this.status = EventSource.CLOSED;
304
+ }
305
+
306
+ if (this._xhr) {
307
+ this._xhr.abort();
308
+ }
309
+ }
310
+ }
311
+
312
+ export default EventSource;
@@ -0,0 +1,13 @@
1
+ import NetInfo from '@react-native-community/netinfo';
2
+
3
+ export default class NetworkListener {
4
+ static async getIsOnline() {
5
+ const network = await NetInfo.fetch();
6
+ return network.isConnected;
7
+ }
8
+ static listen(f) {
9
+ return NetInfo.addEventListener((state) => {
10
+ f(state.isConnected);
11
+ });
12
+ }
13
+ }
package/src/Storage.js ADDED
@@ -0,0 +1,3 @@
1
+ import { IndexedDBStorage } from '@instantdb/core';
2
+
3
+ export default IndexedDBStorage;