@json-eval-rs/react-native 0.0.28

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.
@@ -0,0 +1,532 @@
1
+ package com.jsonevalrs
2
+
3
+ import com.facebook.react.bridge.*
4
+ import com.facebook.react.module.annotations.ReactModule
5
+
6
+ @ReactModule(name = JsonEvalRsModule.NAME)
7
+ class JsonEvalRsModule(reactContext: ReactApplicationContext) :
8
+ ReactContextBaseJavaModule(reactContext) {
9
+
10
+ override fun getName(): String {
11
+ return NAME
12
+ }
13
+
14
+ companion object {
15
+ const val NAME = "JsonEvalRs"
16
+
17
+ init {
18
+ try {
19
+ System.loadLibrary("json_eval_rs")
20
+ System.loadLibrary("json_eval_rn")
21
+ } catch (e: UnsatisfiedLinkError) {
22
+ e.printStackTrace()
23
+ }
24
+ }
25
+ }
26
+
27
+ @ReactMethod(isBlockingSynchronousMethod = true)
28
+ fun create(
29
+ schema: String,
30
+ context: String?,
31
+ data: String?
32
+ ): String {
33
+ return nativeCreate(schema, context ?: "", data ?: "")
34
+ }
35
+
36
+ @ReactMethod
37
+ fun evaluate(
38
+ handle: String,
39
+ data: String,
40
+ context: String?,
41
+ promise: Promise
42
+ ) {
43
+ nativeEvaluateAsync(handle, data, context ?: "", promise)
44
+ }
45
+
46
+ @ReactMethod
47
+ fun validate(
48
+ handle: String,
49
+ data: String,
50
+ context: String?,
51
+ promise: Promise
52
+ ) {
53
+ nativeValidateAsync(handle, data, context ?: "", promise)
54
+ }
55
+
56
+ @ReactMethod
57
+ fun evaluateDependents(
58
+ handle: String,
59
+ changedPathsJson: String,
60
+ data: String?,
61
+ context: String?,
62
+ reEvaluate: Boolean,
63
+ promise: Promise
64
+ ) {
65
+ nativeEvaluateDependentsAsync(handle, changedPathsJson, data ?: "", context ?: "", reEvaluate, promise)
66
+ }
67
+
68
+ @ReactMethod
69
+ fun getEvaluatedSchema(
70
+ handle: String,
71
+ skipLayout: Boolean,
72
+ promise: Promise
73
+ ) {
74
+ nativeGetEvaluatedSchemaAsync(handle, skipLayout, promise)
75
+ }
76
+
77
+ @ReactMethod
78
+ fun getSchemaValue(
79
+ handle: String,
80
+ promise: Promise
81
+ ) {
82
+ nativeGetSchemaValueAsync(handle, promise)
83
+ }
84
+
85
+ @ReactMethod
86
+ fun getEvaluatedSchemaWithoutParams(
87
+ handle: String,
88
+ skipLayout: Boolean,
89
+ promise: Promise
90
+ ) {
91
+ nativeGetEvaluatedSchemaWithoutParamsAsync(handle, skipLayout, promise)
92
+ }
93
+
94
+ @ReactMethod
95
+ fun getEvaluatedSchemaByPath(
96
+ handle: String,
97
+ path: String,
98
+ skipLayout: Boolean,
99
+ promise: Promise
100
+ ) {
101
+ nativeGetEvaluatedSchemaByPathAsync(handle, path, skipLayout, promise)
102
+ }
103
+
104
+ @ReactMethod
105
+ fun getEvaluatedSchemaByPaths(
106
+ handle: String,
107
+ pathsJson: String,
108
+ skipLayout: Boolean,
109
+ promise: Promise
110
+ ) {
111
+ nativeGetEvaluatedSchemaByPathsAsync(handle, pathsJson, skipLayout, promise)
112
+ }
113
+
114
+ @ReactMethod
115
+ fun getSchemaByPath(
116
+ handle: String,
117
+ path: String,
118
+ promise: Promise
119
+ ) {
120
+ nativeGetSchemaByPathAsync(handle, path, promise)
121
+ }
122
+
123
+ @ReactMethod
124
+ fun getSchemaByPaths(
125
+ handle: String,
126
+ pathsJson: String,
127
+ promise: Promise
128
+ ) {
129
+ nativeGetSchemaByPathsAsync(handle, pathsJson, promise)
130
+ }
131
+
132
+ @ReactMethod
133
+ fun reloadSchema(
134
+ handle: String,
135
+ schema: String,
136
+ context: String?,
137
+ data: String?,
138
+ promise: Promise
139
+ ) {
140
+ nativeReloadSchemaAsync(handle, schema, context ?: "", data ?: "", promise)
141
+ }
142
+
143
+ @ReactMethod
144
+ fun reloadSchemaMsgpack(
145
+ handle: String,
146
+ schemaMsgpack: ReadableArray,
147
+ context: String?,
148
+ data: String?,
149
+ promise: Promise
150
+ ) {
151
+ // Convert ReadableArray to ByteArray
152
+ val byteArray = ByteArray(schemaMsgpack.size())
153
+ for (i in 0 until schemaMsgpack.size()) {
154
+ byteArray[i] = schemaMsgpack.getInt(i).toByte()
155
+ }
156
+ nativeReloadSchemaMsgpackAsync(handle, byteArray, context ?: "", data ?: "", promise)
157
+ }
158
+
159
+ @ReactMethod
160
+ fun reloadSchemaFromCache(
161
+ handle: String,
162
+ cacheKey: String,
163
+ context: String?,
164
+ data: String?,
165
+ promise: Promise
166
+ ) {
167
+ nativeReloadSchemaFromCacheAsync(handle, cacheKey, context ?: "", data ?: "", promise)
168
+ }
169
+
170
+ @ReactMethod
171
+ fun createFromMsgpack(
172
+ schemaMsgpack: ReadableArray,
173
+ context: String?,
174
+ data: String?,
175
+ promise: Promise
176
+ ) {
177
+ try {
178
+ // Convert ReadableArray to ByteArray
179
+ val byteArray = ByteArray(schemaMsgpack.size())
180
+ for (i in 0 until schemaMsgpack.size()) {
181
+ byteArray[i] = schemaMsgpack.getInt(i).toByte()
182
+ }
183
+ val handle = nativeCreateFromMsgpack(byteArray, context ?: "", data ?: "")
184
+ promise.resolve(handle)
185
+ } catch (e: Exception) {
186
+ promise.reject("CREATE_FROM_MSGPACK_ERROR", e.message, e)
187
+ }
188
+ }
189
+
190
+ @ReactMethod
191
+ fun createFromCache(
192
+ cacheKey: String,
193
+ context: String?,
194
+ data: String?,
195
+ promise: Promise
196
+ ) {
197
+ try {
198
+ val handle = nativeCreateFromCache(cacheKey, context ?: "", data ?: "")
199
+ promise.resolve(handle)
200
+ } catch (e: Exception) {
201
+ promise.reject("CREATE_FROM_CACHE_ERROR", e.message, e)
202
+ }
203
+ }
204
+
205
+ @ReactMethod
206
+ fun cacheStats(
207
+ handle: String,
208
+ promise: Promise
209
+ ) {
210
+ nativeCacheStatsAsync(handle, promise)
211
+ }
212
+
213
+ @ReactMethod
214
+ fun clearCache(
215
+ handle: String,
216
+ promise: Promise
217
+ ) {
218
+ nativeClearCacheAsync(handle, promise)
219
+ }
220
+
221
+ @ReactMethod
222
+ fun cacheLen(
223
+ handle: String,
224
+ promise: Promise
225
+ ) {
226
+ nativeCacheLenAsync(handle, promise)
227
+ }
228
+
229
+ @ReactMethod
230
+ fun enableCache(
231
+ handle: String,
232
+ promise: Promise
233
+ ) {
234
+ nativeEnableCacheAsync(handle, promise)
235
+ }
236
+
237
+ @ReactMethod
238
+ fun disableCache(
239
+ handle: String,
240
+ promise: Promise
241
+ ) {
242
+ nativeDisableCacheAsync(handle, promise)
243
+ }
244
+
245
+ @ReactMethod(isBlockingSynchronousMethod = true)
246
+ fun isCacheEnabled(
247
+ handle: String
248
+ ): Boolean {
249
+ return nativeIsCacheEnabled(handle)
250
+ }
251
+
252
+ @ReactMethod
253
+ fun validatePaths(
254
+ handle: String,
255
+ data: String,
256
+ context: String?,
257
+ paths: ReadableArray?,
258
+ promise: Promise
259
+ ) {
260
+ val pathsJson = if (paths != null) arrayToJsonString(paths) else ""
261
+ nativeValidatePathsAsync(handle, data, context ?: "", pathsJson, promise)
262
+ }
263
+
264
+ @ReactMethod
265
+ fun resolveLayout(
266
+ handle: String,
267
+ evaluate: Boolean,
268
+ promise: Promise
269
+ ) {
270
+ nativeResolveLayoutAsync(handle, evaluate, promise)
271
+ }
272
+
273
+ @ReactMethod
274
+ fun compileAndRunLogic(
275
+ handle: String,
276
+ logicStr: String,
277
+ data: String?,
278
+ context: String?,
279
+ promise: Promise
280
+ ) {
281
+ nativeCompileAndRunLogicAsync(handle, logicStr, data ?: "", context ?: "", promise)
282
+ }
283
+
284
+ @ReactMethod
285
+ fun compileLogic(
286
+ handle: String,
287
+ logicStr: String,
288
+ promise: Promise
289
+ ) {
290
+ try {
291
+ val logicId = nativeCompileLogic(handle, logicStr)
292
+ if (logicId == 0.0) {
293
+ promise.reject("COMPILE_LOGIC_ERROR", "Failed to compile logic")
294
+ } else {
295
+ promise.resolve(logicId)
296
+ }
297
+ } catch (e: Exception) {
298
+ promise.reject("COMPILE_LOGIC_ERROR", e.message, e)
299
+ }
300
+ }
301
+
302
+ @ReactMethod
303
+ fun runLogic(
304
+ handle: String,
305
+ logicId: Double,
306
+ data: String?,
307
+ context: String?,
308
+ promise: Promise
309
+ ) {
310
+ nativeRunLogicAsync(handle, logicId, data ?: "", context ?: "", promise)
311
+ }
312
+
313
+ // ========================================================================
314
+ // Subform Methods
315
+ // ========================================================================
316
+
317
+ @ReactMethod
318
+ fun evaluateSubform(
319
+ handle: String,
320
+ subformPath: String,
321
+ data: String,
322
+ context: String?,
323
+ promise: Promise
324
+ ) {
325
+ nativeEvaluateSubformAsync(handle, subformPath, data, context ?: "", promise)
326
+ }
327
+
328
+ @ReactMethod
329
+ fun validateSubform(
330
+ handle: String,
331
+ subformPath: String,
332
+ data: String,
333
+ context: String?,
334
+ promise: Promise
335
+ ) {
336
+ nativeValidateSubformAsync(handle, subformPath, data, context ?: "", promise)
337
+ }
338
+
339
+ @ReactMethod
340
+ fun evaluateDependentsSubform(
341
+ handle: String,
342
+ subformPath: String,
343
+ changedPath: String,
344
+ data: String?,
345
+ context: String?,
346
+ promise: Promise
347
+ ) {
348
+ nativeEvaluateDependentsSubformAsync(handle, subformPath, changedPath, data ?: "", context ?: "", promise)
349
+ }
350
+
351
+ @ReactMethod
352
+ fun resolveLayoutSubform(
353
+ handle: String,
354
+ subformPath: String,
355
+ evaluate: Boolean,
356
+ promise: Promise
357
+ ) {
358
+ nativeResolveLayoutSubformAsync(handle, subformPath, evaluate, promise)
359
+ }
360
+
361
+ @ReactMethod
362
+ fun getEvaluatedSchemaSubform(
363
+ handle: String,
364
+ subformPath: String,
365
+ resolveLayout: Boolean,
366
+ promise: Promise
367
+ ) {
368
+ nativeGetEvaluatedSchemaSubformAsync(handle, subformPath, resolveLayout, promise)
369
+ }
370
+
371
+ @ReactMethod
372
+ fun getSchemaValueSubform(
373
+ handle: String,
374
+ subformPath: String,
375
+ promise: Promise
376
+ ) {
377
+ nativeGetSchemaValueSubformAsync(handle, subformPath, promise)
378
+ }
379
+
380
+ @ReactMethod
381
+ fun getEvaluatedSchemaWithoutParamsSubform(
382
+ handle: String,
383
+ subformPath: String,
384
+ resolveLayout: Boolean,
385
+ promise: Promise
386
+ ) {
387
+ nativeGetEvaluatedSchemaWithoutParamsSubformAsync(handle, subformPath, resolveLayout, promise)
388
+ }
389
+
390
+ @ReactMethod
391
+ fun getEvaluatedSchemaByPathSubform(
392
+ handle: String,
393
+ subformPath: String,
394
+ schemaPath: String,
395
+ skipLayout: Boolean,
396
+ promise: Promise
397
+ ) {
398
+ nativeGetEvaluatedSchemaByPathSubformAsync(handle, subformPath, schemaPath, skipLayout, promise)
399
+ }
400
+
401
+ @ReactMethod
402
+ fun getEvaluatedSchemaByPathsSubform(
403
+ handle: String,
404
+ subformPath: String,
405
+ schemaPathsJson: String,
406
+ skipLayout: Boolean,
407
+ promise: Promise
408
+ ) {
409
+ nativeGetEvaluatedSchemaByPathsSubformAsync(handle, subformPath, schemaPathsJson, skipLayout, promise)
410
+ }
411
+
412
+ @ReactMethod
413
+ fun getSubformPaths(
414
+ handle: String,
415
+ promise: Promise
416
+ ) {
417
+ nativeGetSubformPathsAsync(handle, promise)
418
+ }
419
+
420
+ @ReactMethod
421
+ fun getSchemaByPathSubform(
422
+ handle: String,
423
+ subformPath: String,
424
+ schemaPath: String,
425
+ promise: Promise
426
+ ) {
427
+ nativeGetSchemaByPathSubformAsync(handle, subformPath, schemaPath, promise)
428
+ }
429
+
430
+ @ReactMethod
431
+ fun getSchemaByPathsSubform(
432
+ handle: String,
433
+ subformPath: String,
434
+ schemaPathsJson: String,
435
+ promise: Promise
436
+ ) {
437
+ nativeGetSchemaByPathsSubformAsync(handle, subformPath, schemaPathsJson, promise)
438
+ }
439
+
440
+ @ReactMethod
441
+ fun hasSubform(
442
+ handle: String,
443
+ subformPath: String,
444
+ promise: Promise
445
+ ) {
446
+ nativeHasSubformAsync(handle, subformPath, promise)
447
+ }
448
+
449
+ @ReactMethod(isBlockingSynchronousMethod = true)
450
+ fun dispose(
451
+ handle: String
452
+ ) {
453
+ nativeDispose(handle)
454
+ }
455
+
456
+ @ReactMethod
457
+ fun version(promise: Promise) {
458
+ try {
459
+ val ver = nativeVersion()
460
+ promise.resolve(ver)
461
+ } catch (e: Exception) {
462
+ promise.reject("VERSION_ERROR", e.message, e)
463
+ }
464
+ }
465
+
466
+ @ReactMethod
467
+ fun multiply(a: Double, b: Double, promise: Promise) {
468
+ promise.resolve(a * b)
469
+ }
470
+
471
+ private fun arrayToJsonString(array: ReadableArray): String {
472
+ val items = mutableListOf<String>()
473
+ for (i in 0 until array.size()) {
474
+ items.add("\"${array.getString(i)}\"")
475
+ }
476
+ return "[${items.joinToString(",")}]"
477
+ }
478
+
479
+ // Native methods
480
+ private external fun nativeCreate(schema: String, context: String, data: String): String
481
+ private external fun nativeCreateFromMsgpack(schemaMsgpack: ByteArray, context: String, data: String): String
482
+ private external fun nativeCreateFromCache(cacheKey: String, context: String, data: String): String
483
+ private external fun nativeEvaluateAsync(handle: String, data: String, context: String, promise: Promise)
484
+ private external fun nativeValidateAsync(handle: String, data: String, context: String, promise: Promise)
485
+ private external fun nativeEvaluateDependentsAsync(
486
+ handle: String,
487
+ changedPathsJson: String,
488
+ data: String,
489
+ context: String,
490
+ reEvaluate: Boolean,
491
+ promise: Promise
492
+ )
493
+ private external fun nativeGetEvaluatedSchemaAsync(handle: String, skipLayout: Boolean, promise: Promise)
494
+ private external fun nativeGetSchemaValueAsync(handle: String, promise: Promise)
495
+ private external fun nativeGetEvaluatedSchemaWithoutParamsAsync(handle: String, skipLayout: Boolean, promise: Promise)
496
+ private external fun nativeGetEvaluatedSchemaByPathAsync(handle: String, path: String, skipLayout: Boolean, promise: Promise)
497
+ private external fun nativeGetEvaluatedSchemaByPathsAsync(handle: String, pathsJson: String, skipLayout: Boolean, promise: Promise)
498
+ private external fun nativeGetSchemaByPathAsync(handle: String, path: String, promise: Promise)
499
+ private external fun nativeGetSchemaByPathsAsync(handle: String, pathsJson: String, promise: Promise)
500
+ private external fun nativeReloadSchemaAsync(handle: String, schema: String, context: String, data: String, promise: Promise)
501
+ private external fun nativeReloadSchemaMsgpackAsync(handle: String, schemaMsgpack: ByteArray, context: String, data: String, promise: Promise)
502
+ private external fun nativeReloadSchemaFromCacheAsync(handle: String, cacheKey: String, context: String, data: String, promise: Promise)
503
+ private external fun nativeCacheStatsAsync(handle: String, promise: Promise)
504
+ private external fun nativeClearCacheAsync(handle: String, promise: Promise)
505
+ private external fun nativeCacheLenAsync(handle: String, promise: Promise)
506
+ private external fun nativeEnableCacheAsync(handle: String, promise: Promise)
507
+ private external fun nativeDisableCacheAsync(handle: String, promise: Promise)
508
+ private external fun nativeIsCacheEnabled(handle: String): Boolean
509
+ private external fun nativeValidatePathsAsync(handle: String, data: String, context: String, pathsJson: String, promise: Promise)
510
+ private external fun nativeResolveLayoutAsync(handle: String, evaluate: Boolean, promise: Promise)
511
+ private external fun nativeCompileAndRunLogicAsync(handle: String, logicStr: String, data: String, context: String, promise: Promise)
512
+ private external fun nativeCompileLogic(handle: String, logicStr: String): Double
513
+ private external fun nativeRunLogicAsync(handle: String, logicId: Double, data: String, context: String, promise: Promise)
514
+
515
+ // Subform native methods
516
+ private external fun nativeEvaluateSubformAsync(handle: String, subformPath: String, data: String, context: String, promise: Promise)
517
+ private external fun nativeValidateSubformAsync(handle: String, subformPath: String, data: String, context: String, promise: Promise)
518
+ private external fun nativeEvaluateDependentsSubformAsync(handle: String, subformPath: String, changedPath: String, data: String, context: String, promise: Promise)
519
+ private external fun nativeResolveLayoutSubformAsync(handle: String, subformPath: String, evaluate: Boolean, promise: Promise)
520
+ private external fun nativeGetEvaluatedSchemaSubformAsync(handle: String, subformPath: String, resolveLayout: Boolean, promise: Promise)
521
+ private external fun nativeGetSchemaValueSubformAsync(handle: String, subformPath: String, promise: Promise)
522
+ private external fun nativeGetEvaluatedSchemaWithoutParamsSubformAsync(handle: String, subformPath: String, resolveLayout: Boolean, promise: Promise)
523
+ private external fun nativeGetEvaluatedSchemaByPathSubformAsync(handle: String, subformPath: String, schemaPath: String, skipLayout: Boolean, promise: Promise)
524
+ private external fun nativeGetEvaluatedSchemaByPathsSubformAsync(handle: String, subformPath: String, schemaPathsJson: String, skipLayout: Boolean, promise: Promise)
525
+ private external fun nativeGetSchemaByPathSubformAsync(handle: String, subformPath: String, schemaPath: String, promise: Promise)
526
+ private external fun nativeGetSchemaByPathsSubformAsync(handle: String, subformPath: String, schemaPathsJson: String, promise: Promise)
527
+ private external fun nativeGetSubformPathsAsync(handle: String, promise: Promise)
528
+ private external fun nativeHasSubformAsync(handle: String, subformPath: String, promise: Promise)
529
+
530
+ private external fun nativeDispose(handle: String)
531
+ private external fun nativeVersion(): String
532
+ }
@@ -0,0 +1,16 @@
1
+ package com.jsonevalrs
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class JsonEvalRsPackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
+ return listOf(JsonEvalRsModule(reactContext))
11
+ }
12
+
13
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
+ return emptyList()
15
+ }
16
+ }