@pomwik/afterdb-react 0.0.0-stage → 0.20.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/CHANGES-FROM-UPSTREAM.md +59 -0
- package/LICENSE +177 -0
- package/NOTICE +9 -0
- package/README.md +10 -2
- package/dist/RealmContext.d.ts +153 -0
- package/dist/RealmContext.d.ts.map +1 -0
- package/dist/RealmProvider.d.ts +95 -0
- package/dist/RealmProvider.d.ts.map +1 -0
- package/dist/cachedCollection.d.ts +58 -0
- package/dist/cachedCollection.d.ts.map +1 -0
- package/dist/cachedObject.d.ts +48 -0
- package/dist/cachedObject.d.ts.map +1 -0
- package/dist/helpers.d.ts +22 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/index.cjs +2818 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2809 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useObject.d.ts +30 -0
- package/dist/useObject.d.ts.map +1 -0
- package/dist/useQuery.d.ts +31 -0
- package/dist/useQuery.d.ts.map +1 -0
- package/dist/useRealm.d.ts +12 -0
- package/dist/useRealm.d.ts.map +1 -0
- package/package.json +117 -4
- package/src/RealmContext.ts +196 -0
- package/src/RealmProvider.tsx +251 -0
- package/src/__tests__/RealmProvider.test.tsx +583 -0
- package/src/__tests__/createRealmTestContext.ts +68 -0
- package/src/__tests__/helpers.ts +35 -0
- package/src/__tests__/mocks.ts +154 -0
- package/src/__tests__/profileHook.tsx +76 -0
- package/src/__tests__/setup.ts +22 -0
- package/src/__tests__/tsconfig.json +14 -0
- package/src/__tests__/useObjectHook.test.tsx +158 -0
- package/src/__tests__/useObjectRender.test.tsx +630 -0
- package/src/__tests__/useQueryHook.test.tsx +209 -0
- package/src/__tests__/useQueryRender.test.tsx +463 -0
- package/src/cachedCollection.ts +210 -0
- package/src/cachedObject.ts +164 -0
- package/src/helpers.ts +60 -0
- package/src/index.tsx +130 -0
- package/src/runtime.d.ts +31 -0
- package/src/types.ts +92 -0
- package/src/useObject.tsx +227 -0
- package/src/useQuery.tsx +205 -0
- package/src/useRealm.tsx +41 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Changes from upstream
|
|
2
|
+
|
|
3
|
+
`@pomwik/afterdb` and `@pomwik/afterdb-react` repackage the official npm tarballs `realm@20.2.0` and
|
|
4
|
+
`@realm/react@0.20.0` of the Realm® JavaScript SDK (Apache-2.0). The compiled libraries of the prebuilt realm-core
|
|
5
|
+
engine are not recompiled or changed; one of its headers and its Android CMake files are (listed below).
|
|
6
|
+
|
|
7
|
+
Realm® is a trademark of MongoDB, Inc. This project is independent and not affiliated with or endorsed by MongoDB.
|
|
8
|
+
|
|
9
|
+
Every file listed here was modified, removed or added. Modified text files carry a « Modified by Pomwik (Firas
|
|
10
|
+
Hmedi), 2026 » note, except `package.json`: JSON has no comments, so it carries an `afterdb` field instead (upstream
|
|
11
|
+
name, version and npm integrity).
|
|
12
|
+
|
|
13
|
+
## @pomwik/afterdb 20.3.1 (from realm@20.2.0)
|
|
14
|
+
|
|
15
|
+
| File | Change | Why |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `package.json` | `name` and `version` | New package |
|
|
18
|
+
| `package.json` | `description`, `homepage`, `repository`, `bugs` and `author` replaced (Pomwik, github.com/FirasHmedi/afterdb); `mongodb` removed from `keywords` | The package is not MongoDB's and must not look like it |
|
|
19
|
+
| `package.json` | `license`: `Apache-2.0` instead of upstream's `apache-2.0` (the podspec's `s.license` reads it too) | `Apache-2.0` is the SPDX identifier that npm expects; the licence itself is unchanged |
|
|
20
|
+
| `package.json` | `install` and `postinstall` scripts removed; `prebuild-install` and `node-machine-id` dependencies removed; `binary` field removed; `exports["./scripts/submit-analytics"]` removed | No download and no analytics at install time (realm/realm-js#7119, #7068, #7126) |
|
|
21
|
+
| `package.json` | `imports["#realm.node"]` removed | Its only user was `dist/platform/node/binding.js` (patched below); the build checks that nothing else in the package refers to it |
|
|
22
|
+
| `package.json` | `gypfile: false`; `files`: `binding.gyp` removed, `prebuilds/node`, `LICENSE`, `NOTICE`, `THIRD-PARTY-NOTICES.md`, `CHANGES-FROM-UPSTREAM.md` and `checksums.txt` added | See `binding.gyp` below; the added files ship in the package |
|
|
23
|
+
| `package.json` | `afterdb` field added | Marks the file as modified, and records where it comes from |
|
|
24
|
+
| `package.json` | From 20.3.1 (not in 20.3.0): `sqlite`, `rocksdb`, `leveldb`, `async storage` and `asyncstorage` removed from `keywords`; `config.anonymizedBundleId` removed | The package is none of those storage engines; only the removed analytics script read `anonymizedBundleId` |
|
|
25
|
+
| `dist/scripts/submit-analytics.*`, `scripts/submit-analytics.js` | Removed | Install-time analytics |
|
|
26
|
+
| `prebuilds/node/<platform>-<arch>/realm.node` | Added: the upstream N-API binaries for darwin-arm64, darwin-x64, linux-x64, linux-arm64, win32-x64, unchanged. Upstream also serves binaries for linux-arm and win32-ia32 (static.realm.io, 20.2.0); they are not shipped, so on those platforms Node gets the error described in the next row. The Linux binaries contain OpenSSL built from the 3.3.1 sources, end-of-life since 2026-04-09: we cannot rebuild them yet | Installs work offline and in CI |
|
|
27
|
+
| `dist/platform/node/binding.js` | Loads the binary of the current platform; if none is shipped for it, throws an error that names the platform and the 5 shipped ones (instead of the upstream `#realm.node` lookup) | Same, and a clear message instead of a module-not-found error |
|
|
28
|
+
| `RealmJS.podspec` | `install_modules_dependencies(s)` instead of `s.dependency 'React'` | iOS linking on React Native >= 0.86 with frameworks (realm/realm-js#7157, fix by TPXP, reused with credit) |
|
|
29
|
+
| `RealmJS.podspec` | `HEADER_SEARCH_PATHS` is a string instead of an array | React Native's `install_modules_dependencies` appends to it as a string, so the array became `["..."] …` and broke header lookups (found by the independent review) |
|
|
30
|
+
| `RealmJS.podspec` | `REALM_ENABLE_SYNC=1` removed from the preprocessor flags, and the upstream comment above it (« compiled with Sync enabled ») replaced | v20 has no sync; no shipped header or binding source reads it |
|
|
31
|
+
| `RealmJS.podspec` | From 20.3.1 (not in 20.3.0): `s.source` names github.com/FirasHmedi/afterdb (tag `v<version>`) instead of a realm/realm-js page | React Native installs the pod from its folder and does not read `s.source`; the podspec names this project |
|
|
32
|
+
| `RealmJS.podspec` | `s.platform`: React Native's minimum iOS version (`min_ios_version_supported`) when React Native defines it, otherwise 15.1, instead of iOS 9.0 | 9.0 is far below what React Native >= 0.71 supports |
|
|
33
|
+
| `binding/android/build.gradle` | `ndkVersion rootProject.ext.ndkVersion` when the app defines it, as React Native libraries do; otherwise AGP's default, as before | `librealm.so` was built with AGP's default NDK (27.0 with AGP 8.12, 28.2 with AGP 9.2) instead of the app's |
|
|
34
|
+
| `binding/android/build.gradle`, new `binding/android/consumer-rules.pro` | `consumerProguardFiles 'consumer-rules.pro'` with `-keep class io.realm.react.** { *; }` | With R8 in the app's release build (on by default in Expo SDK 58), `io.realm.react.util.SSLHelper`, looked up only from native code (`FindClass` in `JNI_OnLoad`), was removed and the app crashed at start with `ClassNotFoundException`. Found with the Expo 58 example on 2026-11-06 |
|
|
35
|
+
| `prebuilds/apple/realm-core.xcframework/*/Headers/external/s2/base/macros.h` | `DECLARE_POD` and `PROPAGATE_POD_FROM_TEMPLATE_ARGUMENT` no longer specialize `std::is_pod` | Build error on Xcode 26.4 (realm/realm-js#7115) |
|
|
36
|
+
| `prebuilds/android/<abi>/deps/openssl-3.5.9-*.tar.gz` | Added: OpenSSL 3.5.9 LTS built from the checksummed OpenSSL source release by `bridge/openssl/build-openssl.sh` (static, no apps, no engines), entries owned by 0:0. Each archive also holds OpenSSL's `LICENSE.txt` and an `include.cmake` that is upstream's file, byte-identical to the one in realm's `openssl-3.3.1` archives (SHA-256 `00510e01b73e57960852921903df79ca5c9e54086483a349d3d05dff7d1cf28a`) | The Android build no longer downloads anything, and OpenSSL 3.3 is end-of-life since 2026-04-09 |
|
|
37
|
+
| `prebuilds/android/<abi>/share/cmake/Realm/RealmConfig.cmake` | Acquires OpenSSL 3.5.9 instead of 3.3.1 | Same |
|
|
38
|
+
| `prebuilds/android/<abi>/share/cmake/Realm/AcquireRealmDependency.cmake` | Uses the bundled archive, downloads only as a fallback; the SHA-256 of the bundled archive is written into the file at build time, and CMake checks it with `file(SHA256)` before using the archive (a mismatch stops the build with `FATAL_ERROR`); the extraction folder includes the version (`openssl-3.5.9`) | Same, a damaged archive is never used, and a build folder left by upstream (OpenSSL 3.3.1) is never reused |
|
|
39
|
+
| `binding.gyp` | Removed | It only rebuilds the Node binary from source; npm would otherwise run node-gyp at install |
|
|
40
|
+
| `README.md` | Replaced, with a « Modified by Pomwik (Firas Hmedi), 2026 » note | Describes this package |
|
|
41
|
+
| `LICENSE`, `NOTICE`, `THIRD-PARTY-NOTICES.md`, `CHANGES-FROM-UPSTREAM.md`, `checksums.txt` | Added (the upstream tarball has no LICENSE file). `THIRD-PARTY-NOTICES.md` lists the third-party code inside the prebuilt realm-core engine and the Node binaries, with its licence texts | Licence and traceability |
|
|
42
|
+
| `RealmJS.podspec`, `binding/android` | Not renamed, on purpose: the iOS pod `RealmJS`, the Android namespace `io.realm.react` and the native library `librealm.so` keep their upstream names. The pod version follows the package version (20.3.1, not an upstream release) | Drop-in compatibility: React Native autolinking, existing Podfiles and lockfiles, and the native code that looks up `io.realm.react` classes by name keep working unchanged |
|
|
43
|
+
|
|
44
|
+
## @pomwik/afterdb-react 0.20.2 (from @realm/react@0.20.0)
|
|
45
|
+
|
|
46
|
+
| File | Change | Why |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `package.json` | `name` and `version` | New package |
|
|
49
|
+
| `package.json` | `description`, `homepage`, `repository`, `bugs` (upstream: the realm/realm-js issues) and `author` replaced, as in `@pomwik/afterdb` | Same |
|
|
50
|
+
| `package.json` | `react-native` moved from `optionalDependencies` to an optional peer dependency; the `realm` peer range (`>=20.0.0`) is unchanged, and `@pomwik/afterdb` satisfies it through the `realm` npm alias | A nested copy of react-native broke Android builds (realm/realm-js#7066) |
|
|
51
|
+
| `package.json` | `files`: `NOTICE` and `CHANGES-FROM-UPSTREAM.md` added (`LICENSE` was already listed upstream, once) | The added files ship in the package |
|
|
52
|
+
| `package.json` | `afterdb` field added | Marks the file as modified, and records where it comes from |
|
|
53
|
+
| `README.md` | Replaced, with a « Modified by Pomwik (Firas Hmedi), 2026 » note | Describes this package |
|
|
54
|
+
| `LICENSE`, `NOTICE`, `CHANGES-FROM-UPSTREAM.md` | Added (the upstream tarball has no LICENSE file). This `NOTICE` has no OpenSSL paragraph: the package ships no OpenSSL | Licence and traceability |
|
|
55
|
+
|
|
56
|
+
## Credits
|
|
57
|
+
|
|
58
|
+
- TPXP: the podspec fix for React Native >= 0.86 (realm/realm-js#7157).
|
|
59
|
+
- MongoDB, Inc. and the Realm JS contributors: everything else (Apache-2.0).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
afterdb-react
|
|
2
|
+
Copyright 2026 Pomwik (Firas Hmedi)
|
|
3
|
+
|
|
4
|
+
This product includes software developed by MongoDB, Inc. and the Realm JS
|
|
5
|
+
contributors (https://github.com/realm/realm-js), licensed under the Apache
|
|
6
|
+
License, Version 2.0. The upstream copyright notices are kept in the source files.
|
|
7
|
+
|
|
8
|
+
Realm(R) is a trademark of MongoDB, Inc. afterdb is an independent project.
|
|
9
|
+
It is not affiliated with, sponsored by or endorsed by MongoDB, Inc.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pomwik/afterdb-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `@realm/react` 0.20.0 hooks for Realm® (RealmProvider, useQuery, useObject, useRealm), repackaged for
|
|
4
|
+
@pomwik/afterdb, with `react-native` as an optional peer dependency instead of a nested copy (realm/realm-js#7066).
|
|
5
|
+
Use it through an npm alias: `"@realm/react": "npm:@pomwik/afterdb-react@0.20.2"`, next to
|
|
6
|
+
`"realm": "npm:@pomwik/afterdb@20.3.1"`. Changes: see CHANGES-FROM-UPSTREAM.md.
|
|
7
|
+
|
|
8
|
+
Realm® is a trademark of MongoDB, Inc. This project is independent and not affiliated with or endorsed by MongoDB.
|
|
9
|
+
Licence: Apache-2.0 (see LICENSE and NOTICE).
|
|
10
|
+
|
|
11
|
+
Modified by Pomwik (Firas Hmedi), 2026: this file replaces the upstream README (see CHANGES-FROM-UPSTREAM.md).
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createUseObject } from "./useObject";
|
|
2
|
+
import { createUseQuery } from "./useQuery";
|
|
3
|
+
import { createUseRealm } from "./useRealm";
|
|
4
|
+
import { DynamicRealmProvider, RealmProviderFromConfiguration, RealmProviderFromRealm } from "./RealmProvider";
|
|
5
|
+
import Realm from "realm";
|
|
6
|
+
export type RealmContext<RealmProvider = DynamicRealmProvider> = {
|
|
7
|
+
/**
|
|
8
|
+
* The Provider component that is required to wrap any component using
|
|
9
|
+
* the Realm hooks.
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* const AppRoot = () => {
|
|
13
|
+
* const syncConfig = {
|
|
14
|
+
* flexible: true,
|
|
15
|
+
* user: currentUser
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <RealmProvider schema={[Task, User]} path={"data.realm"} sync={syncConfig}>
|
|
20
|
+
* <App/>
|
|
21
|
+
* </RealmProvider>
|
|
22
|
+
* )
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
* @param props - The {@link Realm.Configuration} or {@link Realm} of the provider
|
|
26
|
+
* are set based on the options passed to `createRealmProvider`. When using a
|
|
27
|
+
* {@link Realm.Configuration}, individual config keys can be overridden when
|
|
28
|
+
* creating a `<RealmProvider>` by passing them as props. For example, to override
|
|
29
|
+
* the `path` config value, use a prop named `path` e.g., `path="newPath.realm"` an
|
|
30
|
+
* attribute of the same key.
|
|
31
|
+
*/
|
|
32
|
+
RealmProvider: RealmProvider;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the instance of the {@link Realm} opened by the `RealmProvider`.
|
|
35
|
+
* @example
|
|
36
|
+
* ```
|
|
37
|
+
* const realm = useRealm();
|
|
38
|
+
* ```
|
|
39
|
+
* @returns a realm instance
|
|
40
|
+
*/
|
|
41
|
+
useRealm: ReturnType<typeof createUseRealm>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a {@link Realm.Collection} of {@link Realm.Object}s from a given type.
|
|
44
|
+
* The hook will update on any changes to any object in the collection.
|
|
45
|
+
*
|
|
46
|
+
* The result of this can be consumed directly by the `data` argument of any React Native
|
|
47
|
+
* VirtualizedList or FlatList. If the component used for the list's `renderItem` prop is {@link React.Memo}ized,
|
|
48
|
+
* then only the modified object will re-render.
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* // Return all collection items
|
|
52
|
+
* const collection = useQuery({ type: Object });
|
|
53
|
+
*
|
|
54
|
+
* // Return all collection items sorted by name and filtered by category
|
|
55
|
+
* const filteredAndSorted = useQuery({
|
|
56
|
+
* type: Object,
|
|
57
|
+
* query: (collection) => collection.filtered('category == $0',category).sorted('name'),
|
|
58
|
+
* }, [category]);
|
|
59
|
+
*
|
|
60
|
+
* // Return all collection items sorted by name and filtered by category, triggering re-renders only if "name" changes
|
|
61
|
+
* const filteredAndSorted = useQuery({
|
|
62
|
+
* type: Object,
|
|
63
|
+
* query: (collection) => collection.filtered('category == $0',category).sorted('name'),
|
|
64
|
+
* keyPaths: ["name"]
|
|
65
|
+
* }, [category]);
|
|
66
|
+
* ```
|
|
67
|
+
* @param options
|
|
68
|
+
* @param options.type - The object type, depicted by a string or a class extending Realm.Object
|
|
69
|
+
* @param options.query - A function that takes a {@link Realm.Collection} and returns a {@link Realm.Collection} of the same type. This allows for filtering and sorting of the collection, before it is returned.
|
|
70
|
+
* @param options.keyPaths - Indicates a lower bound on the changes relevant for the hook. This is a lower bound, since if multiple hooks add listeners (each with their own `keyPaths`) the union of these key-paths will determine the changes that are considered relevant for all listeners registered on the collection. In other words: A listener might fire and cause a re-render more than the key-paths specify, if other listeners with different key-paths are present.
|
|
71
|
+
* @param deps - An array of dependencies that will be passed to {@link React.useMemo}
|
|
72
|
+
* @returns a collection of realm objects or an empty array
|
|
73
|
+
*/
|
|
74
|
+
useQuery: ReturnType<typeof createUseQuery>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns a {@link Realm.Object} from a given type and value of primary key.
|
|
77
|
+
* The hook will update on any changes to the properties on the returned object
|
|
78
|
+
* and return null if it either doesn't exists or has been deleted.
|
|
79
|
+
* @example
|
|
80
|
+
* ```
|
|
81
|
+
* const object = useObject(ObjectClass, objectId);
|
|
82
|
+
* ```
|
|
83
|
+
* @param type - The object type, depicted by a string or a class extending {@link Realm.Object}
|
|
84
|
+
* @param primaryKey - The primary key of the desired object which will be retrieved using {@link Realm.objectForPrimaryKey}
|
|
85
|
+
* @param keyPaths - Indicates a lower bound on the changes relevant for the hook. This is a lower bound, since if multiple hooks add listeners (each with their own `keyPaths`) the union of these key-paths will determine the changes that are considered relevant for all listeners registered on the object. In other words: A listener might fire and cause a re-render more than the key-paths specify, if other listeners with different key-paths are present.
|
|
86
|
+
* @returns either the desired {@link Realm.Object} or `null` in the case of it being deleted or not existing.
|
|
87
|
+
*/
|
|
88
|
+
useObject: ReturnType<typeof createUseObject>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Creates Realm React hooks and Provider component for a given Realm configuration
|
|
92
|
+
* @example
|
|
93
|
+
* ```
|
|
94
|
+
*class Task extends Realm.Object {
|
|
95
|
+
* ...
|
|
96
|
+
*
|
|
97
|
+
* static schema: ObjectSchema = {
|
|
98
|
+
* name: 'Task',
|
|
99
|
+
* primaryKey: '_id',
|
|
100
|
+
* properties: {
|
|
101
|
+
* ...
|
|
102
|
+
* },
|
|
103
|
+
* };
|
|
104
|
+
*}
|
|
105
|
+
*
|
|
106
|
+
*const {useRealm, useQuery, useObject, RealmProvider} = createRealmContext({schema: [Task]});
|
|
107
|
+
* ```
|
|
108
|
+
* @param realmConfig - {@link Realm.Configuration} used to open the Realm
|
|
109
|
+
* @returns An object containing a `RealmProvider` component, and `useRealm`, `useQuery` and `useObject` hooks
|
|
110
|
+
*/
|
|
111
|
+
export declare function createRealmContext(realmConfig: Realm.Configuration): RealmContext<RealmProviderFromConfiguration>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates Realm React hooks and Provider component for a given Realm instance.
|
|
114
|
+
*
|
|
115
|
+
* **Note:** the hooks returned from `createRealmContext` using an existing Realm can be used outside of the scope of the provider.
|
|
116
|
+
* @example
|
|
117
|
+
* ```
|
|
118
|
+
* const realm = new Realm({ schema: [...] });
|
|
119
|
+
* const {useRealm, useQuery, useObject, RealmProvider} = createRealmContext(realm);
|
|
120
|
+
* ```
|
|
121
|
+
* @param realm - {@link Realm} instance
|
|
122
|
+
* @returns An object containing a `RealmProvider` component, and `useRealm`, `useQuery` and `useObject` hooks
|
|
123
|
+
*/
|
|
124
|
+
export declare function createRealmContext(realm: Realm): RealmContext<RealmProviderFromRealm>;
|
|
125
|
+
/**
|
|
126
|
+
* Creates Realm React hooks and Provider component.
|
|
127
|
+
* @example
|
|
128
|
+
* ```
|
|
129
|
+
* class Task extends Realm.Object {
|
|
130
|
+
* ...
|
|
131
|
+
* static schema: ObjectSchema = {
|
|
132
|
+
* name: 'Task',
|
|
133
|
+
* primaryKey: '_id',
|
|
134
|
+
* properties: {
|
|
135
|
+
* ...
|
|
136
|
+
* },
|
|
137
|
+
* };
|
|
138
|
+
* }
|
|
139
|
+
* const {useRealm, useQuery, useObject, RealmProvider} = createRealmContext();
|
|
140
|
+
* ...
|
|
141
|
+
* <RealmProvider schema={[Task]}></RealmProvider>
|
|
142
|
+
* ```
|
|
143
|
+
* @example
|
|
144
|
+
* ```
|
|
145
|
+
* const realm = await Realm.open({ path: "example.realm", schema: [Task] });
|
|
146
|
+
* const {RealmProvider} = createRealmContext();
|
|
147
|
+
* ...
|
|
148
|
+
* <RealmProvider realm={realm}></RealmProvider>
|
|
149
|
+
* ```
|
|
150
|
+
* @returns An object containing a `RealmProvider` component, and `useRealm`, `useQuery` and `useObject` hooks
|
|
151
|
+
*/
|
|
152
|
+
export declare function createRealmContext(): RealmContext<DynamicRealmProvider>;
|
|
153
|
+
//# sourceMappingURL=RealmContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealmContext.d.ts","sourceRoot":"","sources":["../src/RealmContext.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EACL,oBAAoB,EACpB,8BAA8B,EAC9B,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,YAAY,CAAC,aAAa,GAAG,oBAAoB,IAAI;IAC/D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,aAAa,EAAE,aAAa,CAAC;IAC7B;;;;;;;OAOG;IACH,QAAQ,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;IAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,QAAQ,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;IAC5C;;;;;;;;;;;;OAYG;IACH,SAAS,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;CAC/C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC,8BAA8B,CAAC,CAAC;AACnH;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY,CAAC,sBAAsB,CAAC,CAAC;AACvF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Realm from "realm";
|
|
3
|
+
import { RestrictivePick } from "./helpers";
|
|
4
|
+
type PartialRealmConfiguration = Partial<Realm.Configuration>;
|
|
5
|
+
export type RealmProviderFallback = React.ComponentType;
|
|
6
|
+
/** Props used for a configuration-based Realm provider */
|
|
7
|
+
type RealmProviderConfigurationProps = {
|
|
8
|
+
/**
|
|
9
|
+
* If false, Realm will not be closed when the component unmounts.
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
closeOnUnmount?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* A ref to the Realm instance. This is useful if you need to access the Realm
|
|
15
|
+
* instance outside of a component that uses the Realm hooks.
|
|
16
|
+
*/
|
|
17
|
+
realmRef?: React.MutableRefObject<Realm | null>;
|
|
18
|
+
/**
|
|
19
|
+
* The fallback component to render if the Realm is not open.
|
|
20
|
+
*/
|
|
21
|
+
fallback?: RealmProviderFallback | React.ComponentType | React.ReactElement | null | undefined;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
} & PartialRealmConfiguration;
|
|
24
|
+
/** Props used for a Realm instance-based Realm provider */
|
|
25
|
+
type RealmProviderRealmProps = {
|
|
26
|
+
/**
|
|
27
|
+
* The Realm instance to be used by the provider.
|
|
28
|
+
*/
|
|
29
|
+
realm: Realm;
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
};
|
|
32
|
+
type RealmProviderProps = RealmProviderConfigurationProps & RealmProviderRealmProps;
|
|
33
|
+
/**
|
|
34
|
+
* Represents the provider returned from `createRealmContext` with a Realm instance i.e. `createRealmContext(new Realm(...))`.
|
|
35
|
+
* Omits "realm" as it gets set at creation and cannot be changed.
|
|
36
|
+
|
|
37
|
+
* **Note:** the hooks returned from `createRealmContext` using an existing Realm can be used outside of the scope of the provider.
|
|
38
|
+
*/
|
|
39
|
+
export type RealmProviderFromRealm = React.FC<Omit<RealmProviderRealmProps, "realm">>;
|
|
40
|
+
/**
|
|
41
|
+
* Represents the provider returned from `createRealmContext` with a configuration, i.e. `createRealmContext({schema: [...]})`.
|
|
42
|
+
*/
|
|
43
|
+
export type RealmProviderFromConfiguration = React.FC<RealmProviderConfigurationProps>;
|
|
44
|
+
/**
|
|
45
|
+
* Represents properties of a {@link DynamicRealmProvider} where Realm instance props are set and Configuration props are disallowed.
|
|
46
|
+
*/
|
|
47
|
+
export type DynamicRealmProviderWithRealmProps = RestrictivePick<RealmProviderProps, keyof RealmProviderRealmProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Represents properties of a {@link DynamicRealmProvider} where Realm configuration props are set and Realm instance props are disallowed.
|
|
50
|
+
*/
|
|
51
|
+
export type DynamicRealmProviderWithConfigurationProps = RestrictivePick<RealmProviderProps, keyof RealmProviderConfigurationProps>;
|
|
52
|
+
/**
|
|
53
|
+
* Represents the provider returned from creating context with no arguments (including the default context).
|
|
54
|
+
* Supports either {@link RealmProviderRealmProps} or {@link RealmProviderConfigurationProps}.
|
|
55
|
+
*/
|
|
56
|
+
export type DynamicRealmProvider = React.FC<DynamicRealmProviderWithRealmProps | DynamicRealmProviderWithConfigurationProps>;
|
|
57
|
+
export declare function createRealmProviderFromRealm(realm: Realm, RealmContext: React.Context<Realm | null>): RealmProviderFromRealm;
|
|
58
|
+
/**
|
|
59
|
+
* Generates a `RealmProvider` given a {@link Realm.Configuration} and {@link React.Context}.
|
|
60
|
+
* @param realmConfig - The configuration of the Realm to be instantiated
|
|
61
|
+
* @param RealmContext - The context that will contain the Realm instance
|
|
62
|
+
* @returns a RealmProvider component that provides context to all context hooks
|
|
63
|
+
*/
|
|
64
|
+
export declare function createRealmProviderFromConfig(realmConfig: Realm.Configuration, RealmContext: React.Context<Realm | null>): RealmProviderFromConfiguration;
|
|
65
|
+
/**
|
|
66
|
+
* Generates a `RealmProvider` which is either based on a configuration
|
|
67
|
+
* or based on a realm, depending on its props.
|
|
68
|
+
* @param RealmContext - The context that will contain the Realm instance
|
|
69
|
+
* @returns a RealmProvider component that provides context to all context hooks
|
|
70
|
+
*/
|
|
71
|
+
export declare function createDynamicRealmProvider(RealmContext: React.Context<Realm | null>): DynamicRealmProvider;
|
|
72
|
+
/**
|
|
73
|
+
* Generates the appropriate `RealmProvider` based on whether there is a config, realm, or neither given.
|
|
74
|
+
* @param realmOrConfig - A Realm instance, a configuration, or undefined (including default provider).
|
|
75
|
+
* @param RealmContext - The context that will contain the Realm instance
|
|
76
|
+
* @returns a RealmProvider component that provides context to all context hooks
|
|
77
|
+
*/
|
|
78
|
+
export declare function createRealmProvider(realmOrConfig: Realm.Configuration | Realm | undefined, RealmContext: React.Context<Realm | null>): RealmProviderFromConfiguration | RealmProviderFromRealm | DynamicRealmProvider;
|
|
79
|
+
/**
|
|
80
|
+
* Merge two configurations, creating a configuration using `configA` as the default,
|
|
81
|
+
* merged with `configB`, with properties in `configB` overriding `configA`.
|
|
82
|
+
* @param configA - The default config object
|
|
83
|
+
* @param configB - Config overrides object
|
|
84
|
+
* @returns Merged config object
|
|
85
|
+
*/
|
|
86
|
+
export declare function mergeRealmConfiguration(configA: PartialRealmConfiguration, configB: PartialRealmConfiguration): Realm.Configuration;
|
|
87
|
+
/**
|
|
88
|
+
* Utility function that does a deep comparison (key: value) of object a with object b
|
|
89
|
+
* @param a - Object to compare
|
|
90
|
+
* @param b - Object to compare
|
|
91
|
+
* @returns True if the objects are identical
|
|
92
|
+
*/
|
|
93
|
+
export declare function areConfigurationsIdentical(a: Realm.Configuration, b: Realm.Configuration): boolean;
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=RealmProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealmProvider.d.ts","sourceRoot":"","sources":["../src/RealmProvider.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,KAAK,yBAAyB,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAE9D,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAAC;AAExD,0DAA0D;AAC1D,KAAK,+BAA+B,GAAG;IACrC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAChD;;OAEG;IACH,QAAQ,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/F,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,GAAG,yBAAyB,CAAC;AAE9B,2DAA2D;AAC3D,KAAK,uBAAuB,GAAG;IAC7B;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,KAAK,kBAAkB,GAAG,+BAA+B,GAAG,uBAAuB,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC,CAAC;AAEtF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,KAAK,CAAC,EAAE,CAAC,+BAA+B,CAAC,CAAC;AAEvF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,eAAe,CAAC,kBAAkB,EAAE,MAAM,uBAAuB,CAAC,CAAC;AAEpH;;GAEG;AACH,MAAM,MAAM,0CAA0C,GAAG,eAAe,CACtE,kBAAkB,EAClB,MAAM,+BAA+B,CACtC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,EAAE,CACzC,kCAAkC,GAAG,0CAA0C,CAChF,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GACxC,sBAAsB,CAIxB;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,KAAK,CAAC,aAAa,EAChC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GACxC,8BAA8B,CA0EhC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,oBAAoB,CAY1G;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,KAAK,CAAC,aAAa,GAAG,KAAK,GAAG,SAAS,EACtD,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GACxC,8BAA8B,GAAG,sBAAsB,GAAG,oBAAoB,CAQhF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,GACjC,KAAK,CAAC,aAAa,CAKrB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,OAAO,CAElG"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import Realm from "realm";
|
|
3
|
+
/**
|
|
4
|
+
* Arguments object for {@link createCachedCollection}.
|
|
5
|
+
*/
|
|
6
|
+
type CachedCollectionArgs<T> = {
|
|
7
|
+
/**
|
|
8
|
+
* The {@link Realm.Collection} to proxy
|
|
9
|
+
*/
|
|
10
|
+
collection: Realm.List<T> | Realm.Results<T>;
|
|
11
|
+
/**
|
|
12
|
+
* The {@link Realm} instance
|
|
13
|
+
*/
|
|
14
|
+
realm: Realm;
|
|
15
|
+
/**
|
|
16
|
+
* Callback which is called whenever an object in the collection changes
|
|
17
|
+
*/
|
|
18
|
+
updateCallback: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Reference boolean which is set to true whenever an object in the collection changes
|
|
21
|
+
* It is used to determine if the collection's object reference should be updated
|
|
22
|
+
* The implementing component should reset this to false when updating its object reference
|
|
23
|
+
*/
|
|
24
|
+
updatedRef: React.MutableRefObject<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Optional Map to be used as the cache. This is used to allow a `sorted` or `filtered`
|
|
27
|
+
* (derived) version of the collection to reuse the same cache, preventing excess new object
|
|
28
|
+
* references being created.
|
|
29
|
+
*/
|
|
30
|
+
objectCache?: Map<string, T>;
|
|
31
|
+
/**
|
|
32
|
+
* Optional flag specifying that this is a derived (`sorted` or `filtered`) version of
|
|
33
|
+
* an existing collection, so we should not create or remove listeners or clear the cache
|
|
34
|
+
* when this is torn down.
|
|
35
|
+
*/
|
|
36
|
+
isDerived?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Optional list of key-paths to limit notifications.
|
|
39
|
+
*/
|
|
40
|
+
keyPaths?: string[];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Creates a proxy around a {@link Realm.Collection} that will create new {@link Realm.Object}
|
|
44
|
+
* references on any relevant change (update, insert, deletion) and return the same
|
|
45
|
+
* object reference if no changes have occurred since the last access.
|
|
46
|
+
*
|
|
47
|
+
* This makes the {@link Realm.Collection} behaves in an immutable way, as React expects, so
|
|
48
|
+
* that a {@link Realm.Object} can be wrapped in {@link React.memo} to prevent unnecessary
|
|
49
|
+
* rendering (see {@link useQuery} hook).
|
|
50
|
+
* @param args {@link CachedCollectionArgs} object arguments
|
|
51
|
+
* @returns Proxy object wrapping the collection
|
|
52
|
+
*/
|
|
53
|
+
export declare function createCachedCollection<T extends Realm.Object<any>>({ collection, realm, updateCallback, updatedRef, objectCache, isDerived, keyPaths, }: CachedCollectionArgs<T>): {
|
|
54
|
+
collection: Realm.Results<T> | Realm.List<T>;
|
|
55
|
+
tearDown: () => void;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=cachedCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cachedCollection.d.ts","sourceRoot":"","sources":["../src/cachedCollection.ts"],"names":[],"mappings":";AAkBA,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B;;GAEG;AACH,KAAK,oBAAoB,CAAC,CAAC,IAAI;IAC7B;;OAEG;IACH,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7C;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;IAE3B;;;;OAIG;IACH,UAAU,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE5C;;;;OAIG;IACH,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAClE,UAAU,EACV,KAAK,EACL,cAAc,EACd,UAAU,EACV,WAAuB,EACvB,SAAiB,EACjB,QAAQ,GACT,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG;IAAE,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,IAAI,CAAA;CAAE,CAoHlG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import Realm from "realm";
|
|
3
|
+
/**
|
|
4
|
+
* Arguments object for `cachedObject`.
|
|
5
|
+
*/
|
|
6
|
+
type CachedObjectArgs = {
|
|
7
|
+
/**
|
|
8
|
+
* The {@link Realm.Object} to proxy
|
|
9
|
+
*/
|
|
10
|
+
object: Realm.Object | null;
|
|
11
|
+
/**
|
|
12
|
+
* The {@link Realm} instance
|
|
13
|
+
*/
|
|
14
|
+
realm: Realm;
|
|
15
|
+
/**
|
|
16
|
+
* Callback function called whenver the object changes. Used to force a component
|
|
17
|
+
* using the {@link useObject} hook to re-render.
|
|
18
|
+
*/
|
|
19
|
+
updateCallback: () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Reference boolean which is set to true whenever the object changes
|
|
22
|
+
* It is used to determine if the object's reference should be updated
|
|
23
|
+
* The implementing component should reset this to false when updating its object reference
|
|
24
|
+
*/
|
|
25
|
+
updatedRef: React.MutableRefObject<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Optional list of key-paths to limit notifications.
|
|
28
|
+
*/
|
|
29
|
+
keyPaths?: string[];
|
|
30
|
+
};
|
|
31
|
+
export type CachedObject = {
|
|
32
|
+
object: Realm.Object | null;
|
|
33
|
+
tearDown: () => void;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Creates a proxy around a {@link Realm.Object} that will return a new reference
|
|
37
|
+
* on any relevant update to the object itself. It also wraps accesses to {@link Realm.List}
|
|
38
|
+
* attributes into a {@link cachedCollection}, so that any update, insert or deletion to the
|
|
39
|
+
* list will also return a new object reference.
|
|
40
|
+
*
|
|
41
|
+
* See {@link cachedCollection} and the `useObject` hook for description of how this
|
|
42
|
+
* helps prevent unnecessary rendering.
|
|
43
|
+
* @param args - {@link CachedObjectArgs} object arguments
|
|
44
|
+
* @returns Proxy object wrapping the {@link Realm.Object}
|
|
45
|
+
*/
|
|
46
|
+
export declare function createCachedObject({ object, realm, updateCallback, updatedRef, keyPaths, }: CachedObjectArgs): CachedObject;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=cachedObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cachedObject.d.ts","sourceRoot":"","sources":["../src/cachedObject.ts"],"names":[],"mappings":";AAkBA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B;;GAEG;AACH,KAAK,gBAAgB,GAAG;IACtB;;OAEG;IACH,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IAC5B;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb;;;OAGG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;IAE3B;;;;OAIG;IACH,UAAU,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE5C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,KAAK,EACL,cAAc,EACd,UAAU,EACV,QAAQ,GACT,EAAE,gBAAgB,GAAG,YAAY,CAwFjC"}
|