@delali/narsil-react-native 0.0.0-stage → 0.3.1-next.146

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 (186) hide show
  1. package/LICENSE +201 -0
  2. package/NarsilReactNative.podspec +57 -0
  3. package/README.md +46 -2
  4. package/android/CMakeLists.txt +48 -0
  5. package/android/build.gradle +151 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/AndroidEnvironment.cpp +44 -0
  9. package/android/src/main/cpp/AndroidEnvironment.hpp +11 -0
  10. package/android/src/main/cpp/cpp-adapter.cpp +11 -0
  11. package/android/src/main/java/com/margelo/nitro/narsil/NarsilAndroidEnvironment.kt +29 -0
  12. package/android/src/main/java/com/margelo/nitro/narsil/NarsilReactNativePackage.kt +22 -0
  13. package/app.plugin.js +25 -0
  14. package/cpp/AttachedField.cpp +234 -0
  15. package/cpp/AttachedField.hpp +61 -0
  16. package/cpp/Compression.cpp +113 -0
  17. package/cpp/Compression.hpp +16 -0
  18. package/cpp/GraphHeldAlone.cpp +29 -0
  19. package/cpp/GraphHeldAlone.hpp +25 -0
  20. package/cpp/HostMemory.cpp +123 -0
  21. package/cpp/HostMemory.hpp +53 -0
  22. package/cpp/HybridNarsilCoreImpl.cpp +390 -0
  23. package/cpp/HybridNarsilCoreImpl.hpp +68 -0
  24. package/cpp/HybridNarsilFilesImpl.cpp +245 -0
  25. package/cpp/HybridNarsilFilesImpl.hpp +34 -0
  26. package/cpp/HybridNarsilHostImpl.cpp +126 -0
  27. package/cpp/HybridNarsilHostImpl.hpp +42 -0
  28. package/cpp/NativeAtomics.cpp +110 -0
  29. package/cpp/NativeAtomics.hpp +11 -0
  30. package/cpp/ProcessInfo.cpp +83 -0
  31. package/cpp/ProcessInfo.hpp +11 -0
  32. package/cpp/ThreadPriority.cpp +77 -0
  33. package/cpp/ThreadPriority.hpp +8 -0
  34. package/cpp/WorkletRuntimeDispatcher.cpp +61 -0
  35. package/cpp/WorkletRuntimeDispatcher.hpp +9 -0
  36. package/cpp/core/include/narsil_core.h +208 -0
  37. package/cpp/core/src/connect.c +213 -0
  38. package/cpp/core/src/distance.c +103 -0
  39. package/cpp/core/src/files.c +99 -0
  40. package/cpp/core/src/heap.c +84 -0
  41. package/cpp/core/src/internal.h +284 -0
  42. package/cpp/core/src/kernels_code.c +209 -0
  43. package/cpp/core/src/kernels_float.c +197 -0
  44. package/cpp/core/src/kernels_pair.c +133 -0
  45. package/cpp/core/src/last_links.c +145 -0
  46. package/cpp/core/src/links.c +195 -0
  47. package/cpp/core/src/locks.c +168 -0
  48. package/cpp/core/src/nearest_links.c +147 -0
  49. package/cpp/core/src/place.c +215 -0
  50. package/cpp/core/src/quantize.c +226 -0
  51. package/cpp/core/src/records.c +97 -0
  52. package/cpp/core/src/remove.c +205 -0
  53. package/cpp/core/src/vectors.c +139 -0
  54. package/cpp/core/src/walk.c +231 -0
  55. package/cpp/core/src/workspace.c +167 -0
  56. package/ios/PrivacyInfo.xcprivacy +23 -0
  57. package/lib/client.d.ts +19 -0
  58. package/lib/client.js +41 -0
  59. package/lib/constants.d.ts +9 -0
  60. package/lib/constants.js +9 -0
  61. package/lib/engine/byte-files.d.ts +5 -0
  62. package/lib/engine/byte-files.js +97 -0
  63. package/lib/engine/core.d.ts +3 -0
  64. package/lib/engine/core.js +113 -0
  65. package/lib/engine/files.d.ts +3 -0
  66. package/lib/engine/files.js +188 -0
  67. package/lib/engine/host.d.ts +13 -0
  68. package/lib/engine/host.js +102 -0
  69. package/lib/engine/install.d.ts +4 -0
  70. package/lib/engine/install.js +29 -0
  71. package/lib/engine/native-error.d.ts +1 -0
  72. package/lib/engine/native-error.js +12 -0
  73. package/lib/engine/stand-ins/atomics.d.ts +5 -0
  74. package/lib/engine/stand-ins/atomics.js +236 -0
  75. package/lib/engine/stand-ins/crypto.d.ts +2 -0
  76. package/lib/engine/stand-ins/crypto.js +65 -0
  77. package/lib/engine/stand-ins/process.d.ts +2 -0
  78. package/lib/engine/stand-ins/process.js +22 -0
  79. package/lib/engine/stand-ins/streams.d.ts +1 -0
  80. package/lib/engine/stand-ins/streams.js +31 -0
  81. package/lib/engine/stand-ins/structured-clone.d.ts +1 -0
  82. package/lib/engine/stand-ins/structured-clone.js +121 -0
  83. package/lib/engine/streamed.d.ts +6 -0
  84. package/lib/engine/streamed.js +29 -0
  85. package/lib/engine/transfer.d.ts +3 -0
  86. package/lib/engine/transfer.js +77 -0
  87. package/lib/errors.d.ts +25 -0
  88. package/lib/errors.js +59 -0
  89. package/lib/index.d.ts +3 -0
  90. package/lib/index.js +2 -0
  91. package/lib/methods.d.ts +5 -0
  92. package/lib/methods.js +47 -0
  93. package/lib/native-objects.d.ts +2 -0
  94. package/lib/native-objects.js +24 -0
  95. package/lib/specs/core.nitro.d.ts +79 -0
  96. package/lib/specs/core.nitro.js +1 -0
  97. package/lib/specs/files.nitro.d.ts +36 -0
  98. package/lib/specs/files.nitro.js +1 -0
  99. package/lib/specs/host.nitro.d.ts +24 -0
  100. package/lib/specs/host.nitro.js +1 -0
  101. package/lib/transferred.d.ts +15 -0
  102. package/lib/transferred.js +6 -0
  103. package/lib/types.d.ts +136 -0
  104. package/lib/types.js +1 -0
  105. package/lib/worklets/app-turns.d.ts +1 -0
  106. package/lib/worklets/app-turns.js +44 -0
  107. package/lib/worklets/client.d.ts +30 -0
  108. package/lib/worklets/client.js +144 -0
  109. package/lib/worklets/index.d.ts +4 -0
  110. package/lib/worklets/index.js +2 -0
  111. package/lib/worklets/instances.d.ts +15 -0
  112. package/lib/worklets/instances.js +194 -0
  113. package/lib/worklets/json-part.d.ts +1 -0
  114. package/lib/worklets/json-part.js +42 -0
  115. package/lib/worklets/runtime.d.ts +25 -0
  116. package/lib/worklets/runtime.js +80 -0
  117. package/lib/worklets/transfer-queue.d.ts +7 -0
  118. package/lib/worklets/transfer-queue.js +79 -0
  119. package/lib/worklets/types.d.ts +26 -0
  120. package/lib/worklets/types.js +1 -0
  121. package/nitro.json +32 -0
  122. package/nitrogen/generated/.gitattributes +1 -0
  123. package/nitrogen/generated/android/NarsilReactNative+autolinking.cmake +85 -0
  124. package/nitrogen/generated/android/NarsilReactNative+autolinking.gradle +27 -0
  125. package/nitrogen/generated/android/NarsilReactNativeOnLoad.cpp +69 -0
  126. package/nitrogen/generated/android/NarsilReactNativeOnLoad.hpp +34 -0
  127. package/nitrogen/generated/android/kotlin/com/margelo/nitro/narsil/NarsilReactNativeOnLoad.kt +35 -0
  128. package/nitrogen/generated/ios/NarsilReactNative+autolinking.rb +62 -0
  129. package/nitrogen/generated/ios/NarsilReactNative-Swift-Cxx-Bridge.cpp +17 -0
  130. package/nitrogen/generated/ios/NarsilReactNative-Swift-Cxx-Bridge.hpp +27 -0
  131. package/nitrogen/generated/ios/NarsilReactNative-Swift-Cxx-Umbrella.hpp +38 -0
  132. package/nitrogen/generated/ios/NarsilReactNativeAutolinking.mm +55 -0
  133. package/nitrogen/generated/ios/NarsilReactNativeAutolinking.swift +16 -0
  134. package/nitrogen/generated/shared/c++/DirectoryEntry.hpp +91 -0
  135. package/nitrogen/generated/shared/c++/FileStatus.hpp +103 -0
  136. package/nitrogen/generated/shared/c++/GraphMemory.hpp +120 -0
  137. package/nitrogen/generated/shared/c++/HybridNarsilAttachedGraphSpec.cpp +21 -0
  138. package/nitrogen/generated/shared/c++/HybridNarsilAttachedGraphSpec.hpp +62 -0
  139. package/nitrogen/generated/shared/c++/HybridNarsilAttachedStoreSpec.cpp +21 -0
  140. package/nitrogen/generated/shared/c++/HybridNarsilAttachedStoreSpec.hpp +62 -0
  141. package/nitrogen/generated/shared/c++/HybridNarsilCoreSpec.cpp +35 -0
  142. package/nitrogen/generated/shared/c++/HybridNarsilCoreSpec.hpp +100 -0
  143. package/nitrogen/generated/shared/c++/HybridNarsilFilesSpec.cpp +37 -0
  144. package/nitrogen/generated/shared/c++/HybridNarsilFilesSpec.hpp +86 -0
  145. package/nitrogen/generated/shared/c++/HybridNarsilHostSpec.cpp +34 -0
  146. package/nitrogen/generated/shared/c++/HybridNarsilHostSpec.hpp +78 -0
  147. package/nitrogen/generated/shared/c++/MemoryView.hpp +91 -0
  148. package/nitrogen/generated/shared/c++/NativeConnectOutcome.hpp +87 -0
  149. package/nitrogen/generated/shared/c++/NativeScores.hpp +87 -0
  150. package/nitrogen/generated/shared/c++/NativeSearchHits.hpp +91 -0
  151. package/nitrogen/generated/shared/c++/ProcessMemory.hpp +87 -0
  152. package/nitrogen/generated/shared/c++/StoreMemory.hpp +142 -0
  153. package/package.json +87 -3
  154. package/react-native.config.js +8 -0
  155. package/src/client.ts +44 -0
  156. package/src/constants.ts +9 -0
  157. package/src/engine/byte-files.ts +99 -0
  158. package/src/engine/core.ts +162 -0
  159. package/src/engine/files.ts +186 -0
  160. package/src/engine/host.ts +111 -0
  161. package/src/engine/install.ts +31 -0
  162. package/src/engine/native-error.ts +10 -0
  163. package/src/engine/stand-ins/atomics.ts +288 -0
  164. package/src/engine/stand-ins/crypto.ts +81 -0
  165. package/src/engine/stand-ins/process.ts +30 -0
  166. package/src/engine/stand-ins/streams.ts +45 -0
  167. package/src/engine/stand-ins/structured-clone.ts +118 -0
  168. package/src/engine/streamed.ts +40 -0
  169. package/src/engine/transfer.ts +72 -0
  170. package/src/errors.ts +73 -0
  171. package/src/index.ts +3 -0
  172. package/src/methods.ts +52 -0
  173. package/src/native-objects.ts +30 -0
  174. package/src/specs/core.nitro.ts +140 -0
  175. package/src/specs/files.nitro.ts +42 -0
  176. package/src/specs/host.nitro.ts +30 -0
  177. package/src/transferred.ts +18 -0
  178. package/src/types.ts +164 -0
  179. package/src/worklets/app-turns.ts +48 -0
  180. package/src/worklets/client.ts +165 -0
  181. package/src/worklets/index.ts +4 -0
  182. package/src/worklets/instances.ts +231 -0
  183. package/src/worklets/json-part.ts +38 -0
  184. package/src/worklets/runtime.ts +190 -0
  185. package/src/worklets/transfer-queue.ts +98 -0
  186. package/src/worklets/types.ts +37 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
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
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Delali (https://sondelali.com)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,57 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ app_links_worklets = lambda do
6
+ autolinking = File.join(Pod::Config.instance.installation_root.to_s, "build", "generated", "autolinking", "autolinking.json")
7
+ return false unless File.exist?(autolinking)
8
+ worklets = JSON.parse(File.read(autolinking)).dig("dependencies", "react-native-worklets")
9
+ !worklets.nil? && !worklets.dig("platforms", "ios").nil?
10
+ rescue NameError, JSON::ParserError, SystemCallError
11
+ false
12
+ end
13
+
14
+ links_worklets = app_links_worklets.call
15
+ core_header = File.join(__dir__, "cpp", "core", "include", "narsil_core.h")
16
+ unless File.exist?(core_header)
17
+ raise "#{package["name"]} has no copy of the search core in cpp/core. Run `node scripts/copy-core.mjs` in #{__dir__} first."
18
+ end
19
+
20
+ Pod::Spec.new do |s|
21
+ s.name = "NarsilReactNative"
22
+ s.version = package["version"]
23
+ s.summary = package["description"]
24
+ s.homepage = package["homepage"]
25
+ s.license = package["license"]
26
+ s.authors = package["author"]
27
+
28
+ s.platforms = { :ios => min_ios_version_supported }
29
+ s.source = { :git => "https://github.com/assetcorp/narsil.git", :tag => "#{s.name}-v#{s.version}" }
30
+
31
+ s.source_files = [
32
+ "cpp/*.{hpp,cpp}",
33
+ "cpp/core/src/*.{c,h}",
34
+ "cpp/core/include/*.h",
35
+ ]
36
+ s.private_header_files = ["cpp/*.hpp", "cpp/core/src/*.h", "cpp/core/include/*.h"]
37
+
38
+ header_search_paths = "$(inherited) \"$(PODS_TARGET_SRCROOT)/cpp/core/include\""
39
+ header_search_paths += " \"$(PODS_ROOT)/Headers/Public/RNWorklets\"" if links_worklets
40
+ pod_target_xcconfig = {
41
+ "GCC_C_LANGUAGE_STANDARD" => "c11",
42
+ "OTHER_CFLAGS" => "$(inherited) -ffp-contract=off",
43
+ "HEADER_SEARCH_PATHS" => header_search_paths,
44
+ }
45
+ pod_target_xcconfig["GCC_PREPROCESSOR_DEFINITIONS"] = "$(inherited) NARSIL_LINKS_WORKLETS=1" if links_worklets
46
+ s.pod_target_xcconfig = pod_target_xcconfig
47
+ s.libraries = "z"
48
+ s.resource_bundles = { "NarsilReactNativePrivacyInfo" => ["ios/PrivacyInfo.xcprivacy"] }
49
+
50
+ load "nitrogen/generated/ios/NarsilReactNative+autolinking.rb"
51
+ add_nitrogen_files(s)
52
+
53
+ s.dependency "React-jsi"
54
+ s.dependency "React-callinvoker"
55
+ s.dependency "RNWorklets" if links_worklets
56
+ install_modules_dependencies(s)
57
+ end
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # @delali/narsil-react-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@delali/narsil-react-native` runs a Narsil search engine inside an iOS or Android app, so that the app can search its own documents by keyword, by vector, or by both while the phone is offline. The engine keeps each index in files in the app's private storage, so that the index survives a restart.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @delali/narsil @delali/narsil-react-native react-native-nitro-modules
9
+ ```
10
+
11
+ The package carries native code, so it needs a development build with React Native's New Architecture. Expo Go has no such build, and the package compiles for 64-bit Android alone, so `createNarsil` rejects with `NATIVE_DEPENDENCY_MISSING` in Expo Go and on a 32-bit Android phone.
12
+
13
+ ## Use it
14
+
15
+ ```ts
16
+ import { createNarsil } from '@delali/narsil-react-native'
17
+
18
+ const narsil = await createNarsil()
19
+ await narsil.createIndex('notes', {
20
+ schema: { title: 'string', embedding: 'vector[384]' },
21
+ language: 'english',
22
+ })
23
+ await narsil.insert('notes', { title: 'Pack the tent poles', embedding: tentVector })
24
+ const { hits } = await narsil.query('notes', { term: 'tent', limit: 10 })
25
+ ```
26
+
27
+ The engine works on the app's own JS runtime and takes the same settings as on Node.js, including an embedding adapter, a plugin, or a tokenizer. Every method resolves through a promise, and otherwise it takes the same arguments and returns the same answer as the method of the same name in `@delali/narsil`. Each file read, file write, and vector search runs on a native thread, so the app can keep drawing the screen while the engine works.
28
+
29
+ ## Set up the app
30
+
31
+ An Expo app adds the config plugin to `app.json`, which limits the Android build to 64-bit architectures, and then makes a development build:
32
+
33
+ ```json
34
+ {
35
+ "expo": {
36
+ "plugins": ["@delali/narsil-react-native"]
37
+ }
38
+ }
39
+ ```
40
+
41
+ An app without Expo sets `reactNativeArchitectures=arm64-v8a,x86_64` in `android/gradle.properties` and runs `pod install` before it rebuilds. Neither kind of app needs a change to its Babel or Metro settings.
42
+
43
+ An app can also run the engine on a separate [Worklets](https://docs.swmansion.com/react-native-worklets/) runtime through `@delali/narsil-react-native/worklets`, which needs `react-native-worklets` and the Bundle Mode settings in Babel and Metro. The [React Native guide](https://github.com/assetcorp/narsil/blob/main/docs/react-native.md) gives those settings, and it covers where the index lives, snapshots, memory, and errors.
44
+
45
+ ## License
46
+
47
+ Apache-2.0
@@ -0,0 +1,48 @@
1
+ cmake_minimum_required(VERSION 3.9.0)
2
+ project(NarsilReactNative C CXX)
3
+
4
+ set(PACKAGE_NAME NarsilReactNative)
5
+ set(CMAKE_CXX_STANDARD 20)
6
+ set(CORE_DIRECTORY ${CMAKE_SOURCE_DIR}/../cpp/core)
7
+
8
+ if(NOT EXISTS ${CORE_DIRECTORY}/include/narsil_core.h)
9
+ message(FATAL_ERROR "The package has no copy of the search core in cpp/core. Run `node scripts/copy-core.mjs` in the package directory first.")
10
+ endif()
11
+
12
+ file(GLOB CORE_SOURCES ${CORE_DIRECTORY}/src/*.c)
13
+ file(GLOB BINDING_SOURCES ${CMAKE_SOURCE_DIR}/../cpp/*.cpp)
14
+
15
+ add_library(${PACKAGE_NAME} SHARED
16
+ src/main/cpp/cpp-adapter.cpp
17
+ src/main/cpp/AndroidEnvironment.cpp
18
+ ${BINDING_SOURCES}
19
+ ${CORE_SOURCES}
20
+ )
21
+
22
+ set_source_files_properties(${CORE_SOURCES} PROPERTIES COMPILE_OPTIONS "-std=c11;-ffp-contract=off;-O2")
23
+
24
+ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NarsilReactNative+autolinking.cmake)
25
+
26
+ include_directories(
27
+ "src/main/cpp"
28
+ "../cpp"
29
+ "../cpp/core/include"
30
+ )
31
+
32
+ find_library(LOG_LIB log)
33
+ find_library(Z_LIB z)
34
+
35
+ target_link_options(${PACKAGE_NAME} PRIVATE "-Wl,-z,max-page-size=16384")
36
+
37
+ target_link_libraries(
38
+ ${PACKAGE_NAME}
39
+ ${LOG_LIB}
40
+ ${Z_LIB}
41
+ android
42
+ )
43
+
44
+ if(NARSIL_LINKS_WORKLETS)
45
+ find_package(react-native-worklets REQUIRED CONFIG)
46
+ target_link_libraries(${PACKAGE_NAME} react-native-worklets::worklets)
47
+ target_compile_definitions(${PACKAGE_NAME} PRIVATE NARSIL_LINKS_WORKLETS=1)
48
+ endif()
@@ -0,0 +1,151 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+
7
+ dependencies {
8
+ classpath "com.android.tools.build:gradle:9.3.1"
9
+ }
10
+ }
11
+
12
+ def reactNativeArchitectures() {
13
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
14
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
15
+ }
16
+
17
+ def supportedArchitectures() {
18
+ def supportedAbis = ["arm64-v8a", "x86_64"]
19
+ return reactNativeArchitectures().collect { it.trim() }.findAll { supportedAbis.contains(it) }
20
+ }
21
+
22
+ def linksWorklets = rootProject.findProject(":react-native-worklets") != null
23
+
24
+ def nativeBuildArguments(boolean withWorklets) {
25
+ def arguments = ["-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"]
26
+ if (withWorklets) arguments.add("-DNARSIL_LINKS_WORKLETS=ON")
27
+ return arguments
28
+ }
29
+
30
+ def isNewArchitectureEnabled() {
31
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
32
+ }
33
+
34
+ apply plugin: "com.android.library"
35
+ apply plugin: "org.jetbrains.kotlin.android"
36
+ apply from: "../nitrogen/generated/android/NarsilReactNative+autolinking.gradle"
37
+
38
+ if (isNewArchitectureEnabled()) {
39
+ apply plugin: "com.facebook.react"
40
+ react {
41
+ jsRootDir = file("../src/specs")
42
+ }
43
+ }
44
+
45
+ def getExtOrDefault(name) {
46
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["NarsilReactNative_" + name]
47
+ }
48
+
49
+ def getExtOrIntegerDefault(name) {
50
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NarsilReactNative_" + name]).toInteger()
51
+ }
52
+
53
+ android {
54
+ namespace "com.margelo.nitro.narsil"
55
+
56
+ ndkVersion getExtOrDefault("ndkVersion")
57
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
58
+
59
+ defaultConfig {
60
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
61
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
62
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
63
+
64
+ externalNativeBuild {
65
+ cmake {
66
+ cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
67
+ arguments(*nativeBuildArguments(linksWorklets))
68
+ abiFilters(*supportedArchitectures())
69
+
70
+ buildTypes {
71
+ debug {
72
+ cppFlags "-O1 -g"
73
+ }
74
+ release {
75
+ cppFlags "-O2"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ externalNativeBuild {
83
+ cmake {
84
+ path "CMakeLists.txt"
85
+ }
86
+ }
87
+
88
+ packagingOptions {
89
+ excludes = [
90
+ "META-INF",
91
+ "META-INF/**",
92
+ "**/libc++_shared.so",
93
+ "**/libNitroModules.so",
94
+ "**/libfbjni.so",
95
+ "**/libjsi.so",
96
+ "**/libfolly_json.so",
97
+ "**/libfolly_runtime.so",
98
+ "**/libglog.so",
99
+ "**/libhermes.so",
100
+ "**/libhermes-executor-debug.so",
101
+ "**/libhermes_executor.so",
102
+ "**/libreactnative.so",
103
+ "**/libreactnativejni.so",
104
+ "**/libturbomodulejsijni.so",
105
+ "**/libreact_nativemodule_core.so",
106
+ "**/libjscexecutor.so",
107
+ "**/libworklets.so"
108
+ ]
109
+ }
110
+
111
+ buildFeatures {
112
+ buildConfig true
113
+ prefab true
114
+ }
115
+
116
+ buildTypes {
117
+ release {
118
+ minifyEnabled false
119
+ }
120
+ }
121
+
122
+ lintOptions {
123
+ disable "GradleCompatible"
124
+ }
125
+
126
+ compileOptions {
127
+ sourceCompatibility JavaVersion.VERSION_1_8
128
+ targetCompatibility JavaVersion.VERSION_1_8
129
+ }
130
+
131
+ sourceSets {
132
+ main {
133
+ if (isNewArchitectureEnabled()) {
134
+ java.srcDirs += ["${project.buildDir}/generated/source/codegen/java"]
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+ repositories {
141
+ mavenCentral()
142
+ google()
143
+ }
144
+
145
+ dependencies {
146
+ implementation "com.facebook.react:react-native:+"
147
+ implementation project(":react-native-nitro-modules")
148
+ if (linksWorklets) {
149
+ implementation project(":react-native-worklets")
150
+ }
151
+ }
@@ -0,0 +1,5 @@
1
+ NarsilReactNative_kotlinVersion=2.1.21
2
+ NarsilReactNative_minSdkVersion=24
3
+ NarsilReactNative_targetSdkVersion=36
4
+ NarsilReactNative_compileSdkVersion=36
5
+ NarsilReactNative_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,44 @@
1
+ #include "AndroidEnvironment.hpp"
2
+
3
+ #include <fbjni/fbjni.h>
4
+
5
+ namespace margelo::nitro::narsil {
6
+
7
+ namespace {
8
+
9
+ constexpr double UNKNOWN_BYTES = -1;
10
+
11
+ struct JNarsilAndroidEnvironment : facebook::jni::JavaClass<JNarsilAndroidEnvironment> {
12
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/narsil/NarsilAndroidEnvironment;";
13
+
14
+ static double availableBytes() {
15
+ static const auto method = javaClassStatic()->getStaticMethod<jdouble()>("availableBytes");
16
+ return method(javaClassStatic());
17
+ }
18
+
19
+ static std::string filesDirectory() {
20
+ static const auto method = javaClassStatic()->getStaticMethod<facebook::jni::JString()>("filesDirectory");
21
+ auto directory = method(javaClassStatic());
22
+ return directory ? directory->toStdString() : std::string();
23
+ }
24
+ };
25
+
26
+ }
27
+
28
+ void primeAndroidEnvironment() {
29
+ JNarsilAndroidEnvironment::javaClassStatic();
30
+ }
31
+
32
+ double androidAvailableBytes() {
33
+ double bytes = UNKNOWN_BYTES;
34
+ facebook::jni::ThreadScope::WithClassLoader([&] { bytes = JNarsilAndroidEnvironment::availableBytes(); });
35
+ return bytes;
36
+ }
37
+
38
+ std::string androidFilesDirectory() {
39
+ std::string directory;
40
+ facebook::jni::ThreadScope::WithClassLoader([&] { directory = JNarsilAndroidEnvironment::filesDirectory(); });
41
+ return directory;
42
+ }
43
+
44
+ }
@@ -0,0 +1,11 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+
5
+ namespace margelo::nitro::narsil {
6
+
7
+ void primeAndroidEnvironment();
8
+ double androidAvailableBytes();
9
+ std::string androidFilesDirectory();
10
+
11
+ }
@@ -0,0 +1,11 @@
1
+ #include "AndroidEnvironment.hpp"
2
+ #include "NarsilReactNativeOnLoad.hpp"
3
+ #include <fbjni/fbjni.h>
4
+ #include <jni.h>
5
+
6
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
7
+ return facebook::jni::initialize(vm, []() {
8
+ margelo::nitro::narsil::registerAllNatives();
9
+ margelo::nitro::narsil::primeAndroidEnvironment();
10
+ });
11
+ }
@@ -0,0 +1,29 @@
1
+ package com.margelo.nitro.narsil
2
+
3
+ import android.app.ActivityManager
4
+ import android.content.Context
5
+ import androidx.annotation.Keep
6
+ import com.facebook.proguard.annotations.DoNotStrip
7
+ import com.margelo.nitro.NitroModules
8
+
9
+ @DoNotStrip
10
+ @Keep
11
+ object NarsilAndroidEnvironment {
12
+ private const val UNKNOWN_BYTES = -1.0
13
+
14
+ @JvmStatic
15
+ @DoNotStrip
16
+ @Keep
17
+ fun availableBytes(): Double {
18
+ val context = NitroModules.applicationContext ?: return UNKNOWN_BYTES
19
+ val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager ?: return UNKNOWN_BYTES
20
+ val info = ActivityManager.MemoryInfo()
21
+ manager.getMemoryInfo(info)
22
+ return maxOf(0L, info.availMem - info.threshold).toDouble()
23
+ }
24
+
25
+ @JvmStatic
26
+ @DoNotStrip
27
+ @Keep
28
+ fun filesDirectory(): String? = NitroModules.applicationContext?.filesDir?.absolutePath
29
+ }
@@ -0,0 +1,22 @@
1
+ package com.margelo.nitro.narsil
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+
8
+ class NarsilReactNativePackage : BaseReactPackage() {
9
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
10
+
11
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
12
+
13
+ companion object {
14
+ init {
15
+ try {
16
+ NarsilReactNativeOnLoad.initializeNative()
17
+ } catch (unsupportedAbi: UnsatisfiedLinkError) {
18
+ android.util.Log.e("NarsilReactNative", "Narsil runs only on 64-bit Android", unsupportedAbi)
19
+ }
20
+ }
21
+ }
22
+ }
package/app.plugin.js ADDED
@@ -0,0 +1,25 @@
1
+ const { createRunOncePlugin, withGradleProperties } = require('expo/config-plugins')
2
+ const packageJson = require('./package.json')
3
+
4
+ const ARCHITECTURES_PROPERTY = 'reactNativeArchitectures'
5
+ const SIXTY_FOUR_BIT_ARCHITECTURES = 'arm64-v8a,x86_64'
6
+
7
+ function withSixtyFourBitAndroid(config) {
8
+ return withGradleProperties(config, modified => {
9
+ const properties = modified.modResults
10
+ const existing = properties.find(item => item.type === 'property' && item.key === ARCHITECTURES_PROPERTY)
11
+ if (existing === undefined) {
12
+ properties.push({ type: 'property', key: ARCHITECTURES_PROPERTY, value: SIXTY_FOUR_BIT_ARCHITECTURES })
13
+ } else {
14
+ existing.value = SIXTY_FOUR_BIT_ARCHITECTURES
15
+ }
16
+ return modified
17
+ })
18
+ }
19
+
20
+ function withNarsil(config, options = {}) {
21
+ if (options.keep32BitAndroid === true) return config
22
+ return withSixtyFourBitAndroid(config)
23
+ }
24
+
25
+ module.exports = createRunOncePlugin(withNarsil, packageJson.name, packageJson.version)