@json-eval-rs/react-native 0.0.55 → 0.0.57
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/android/src/main/cpp/json-eval-rn.cpp +76 -16
- package/android/src/main/java/com/jsonevalrs/JsonEvalRsModule.kt +48 -0
- package/android/src/main/jniLibs/arm64-v8a/libjson_eval_rs.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libjson_eval_rs.so +0 -0
- package/android/src/main/jniLibs/x86/libjson_eval_rs.so +0 -0
- package/android/src/main/jniLibs/x86_64/libjson_eval_rs.so +0 -0
- package/cpp/json-eval-bridge.cpp +126 -0
- package/cpp/json-eval-bridge.h +48 -0
- package/ios/JsonEvalRs.mm +78 -0
- package/ios/JsonEvalRs.xcframework/ios-arm64/libjson_eval_rs.a +0 -0
- package/ios/JsonEvalRs.xcframework/ios-arm64_x86_64-simulator/libjson_eval_rs.a +0 -0
- package/lib/commonjs/index.js +70 -17
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +71 -17
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +41 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +400 -131
|
@@ -330,6 +330,82 @@ Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueAsync(
|
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
JNIEXPORT void JNICALL
|
|
334
|
+
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueArrayAsync(
|
|
335
|
+
JNIEnv* env,
|
|
336
|
+
jobject /* this */,
|
|
337
|
+
jstring handle,
|
|
338
|
+
jobject promise
|
|
339
|
+
) {
|
|
340
|
+
std::string handleStr = jstringToString(env, handle);
|
|
341
|
+
|
|
342
|
+
runAsyncWithPromise(env, promise, "GET_SCHEMA_VALUE_ARRAY_ERROR", [handleStr](auto callback) {
|
|
343
|
+
JsonEvalBridge::getSchemaValueArrayAsync(handleStr, callback);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
JNIEXPORT void JNICALL
|
|
348
|
+
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueObjectAsync(
|
|
349
|
+
JNIEnv* env,
|
|
350
|
+
jobject /* this */,
|
|
351
|
+
jstring handle,
|
|
352
|
+
jobject promise
|
|
353
|
+
) {
|
|
354
|
+
std::string handleStr = jstringToString(env, handle);
|
|
355
|
+
|
|
356
|
+
runAsyncWithPromise(env, promise, "GET_SCHEMA_VALUE_OBJECT_ERROR", [handleStr](auto callback) {
|
|
357
|
+
JsonEvalBridge::getSchemaValueObjectAsync(handleStr, callback);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
JNIEXPORT void JNICALL
|
|
362
|
+
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueSubformAsync(
|
|
363
|
+
JNIEnv* env,
|
|
364
|
+
jobject /* this */,
|
|
365
|
+
jstring handle,
|
|
366
|
+
jstring subformPath,
|
|
367
|
+
jobject promise
|
|
368
|
+
) {
|
|
369
|
+
std::string handleStr = jstringToString(env, handle);
|
|
370
|
+
std::string subformPathStr = jstringToString(env, subformPath);
|
|
371
|
+
|
|
372
|
+
runAsyncWithPromise(env, promise, "GET_SCHEMA_VALUE_SUBFORM_ERROR", [handleStr, subformPathStr](auto callback) {
|
|
373
|
+
JsonEvalBridge::getSchemaValueSubformAsync(handleStr, subformPathStr, callback);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
JNIEXPORT void JNICALL
|
|
378
|
+
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueArraySubformAsync(
|
|
379
|
+
JNIEnv* env,
|
|
380
|
+
jobject /* this */,
|
|
381
|
+
jstring handle,
|
|
382
|
+
jstring subformPath,
|
|
383
|
+
jobject promise
|
|
384
|
+
) {
|
|
385
|
+
std::string handleStr = jstringToString(env, handle);
|
|
386
|
+
std::string subformPathStr = jstringToString(env, subformPath);
|
|
387
|
+
|
|
388
|
+
runAsyncWithPromise(env, promise, "GET_SCHEMA_VALUE_ARRAY_SUBFORM_ERROR", [handleStr, subformPathStr](auto callback) {
|
|
389
|
+
JsonEvalBridge::getSchemaValueArraySubformAsync(handleStr, subformPathStr, callback);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
JNIEXPORT void JNICALL
|
|
394
|
+
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueObjectSubformAsync(
|
|
395
|
+
JNIEnv* env,
|
|
396
|
+
jobject /* this */,
|
|
397
|
+
jstring handle,
|
|
398
|
+
jstring subformPath,
|
|
399
|
+
jobject promise
|
|
400
|
+
) {
|
|
401
|
+
std::string handleStr = jstringToString(env, handle);
|
|
402
|
+
std::string subformPathStr = jstringToString(env, subformPath);
|
|
403
|
+
|
|
404
|
+
runAsyncWithPromise(env, promise, "GET_SCHEMA_VALUE_OBJECT_SUBFORM_ERROR", [handleStr, subformPathStr](auto callback) {
|
|
405
|
+
JsonEvalBridge::getSchemaValueObjectSubformAsync(handleStr, subformPathStr, callback);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
333
409
|
JNIEXPORT void JNICALL
|
|
334
410
|
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetEvaluatedSchemaWithoutParamsAsync(
|
|
335
411
|
JNIEnv* env,
|
|
@@ -788,22 +864,6 @@ Java_com_jsonevalrs_JsonEvalRsModule_nativeGetEvaluatedSchemaSubformAsync(
|
|
|
788
864
|
});
|
|
789
865
|
}
|
|
790
866
|
|
|
791
|
-
JNIEXPORT void JNICALL
|
|
792
|
-
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetSchemaValueSubformAsync(
|
|
793
|
-
JNIEnv* env,
|
|
794
|
-
jobject /* this */,
|
|
795
|
-
jstring handle,
|
|
796
|
-
jstring subformPath,
|
|
797
|
-
jobject promise
|
|
798
|
-
) {
|
|
799
|
-
std::string handleStr = jstringToString(env, handle);
|
|
800
|
-
std::string subformPathStr = jstringToString(env, subformPath);
|
|
801
|
-
|
|
802
|
-
runAsyncWithPromise(env, promise, "GET_SCHEMA_VALUE_SUBFORM_ERROR", [handleStr, subformPathStr](auto callback) {
|
|
803
|
-
JsonEvalBridge::getSchemaValueSubformAsync(handleStr, subformPathStr, callback);
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
|
|
807
867
|
JNIEXPORT void JNICALL
|
|
808
868
|
Java_com_jsonevalrs_JsonEvalRsModule_nativeGetEvaluatedSchemaWithoutParamsSubformAsync(
|
|
809
869
|
JNIEnv* env,
|
|
@@ -83,6 +83,22 @@ class JsonEvalRsModule(reactContext: ReactApplicationContext) :
|
|
|
83
83
|
nativeGetSchemaValueAsync(handle, promise)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
@ReactMethod
|
|
87
|
+
fun getSchemaValueArray(
|
|
88
|
+
handle: String,
|
|
89
|
+
promise: Promise
|
|
90
|
+
) {
|
|
91
|
+
nativeGetSchemaValueArrayAsync(handle, promise)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@ReactMethod
|
|
95
|
+
fun getSchemaValueObject(
|
|
96
|
+
handle: String,
|
|
97
|
+
promise: Promise
|
|
98
|
+
) {
|
|
99
|
+
nativeGetSchemaValueObjectAsync(handle, promise)
|
|
100
|
+
}
|
|
101
|
+
|
|
86
102
|
@ReactMethod
|
|
87
103
|
fun getEvaluatedSchemaWithoutParams(
|
|
88
104
|
handle: String,
|
|
@@ -397,6 +413,24 @@ class JsonEvalRsModule(reactContext: ReactApplicationContext) :
|
|
|
397
413
|
nativeGetSchemaValueSubformAsync(handle, subformPath, promise)
|
|
398
414
|
}
|
|
399
415
|
|
|
416
|
+
@ReactMethod
|
|
417
|
+
fun getSchemaValueArraySubform(
|
|
418
|
+
handle: String,
|
|
419
|
+
subformPath: String,
|
|
420
|
+
promise: Promise
|
|
421
|
+
) {
|
|
422
|
+
nativeGetSchemaValueArraySubformAsync(handle, subformPath, promise)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
@ReactMethod
|
|
426
|
+
fun getSchemaValueObjectSubform(
|
|
427
|
+
handle: String,
|
|
428
|
+
subformPath: String,
|
|
429
|
+
promise: Promise
|
|
430
|
+
) {
|
|
431
|
+
nativeGetSchemaValueObjectSubformAsync(handle, subformPath, promise)
|
|
432
|
+
}
|
|
433
|
+
|
|
400
434
|
@ReactMethod
|
|
401
435
|
fun getEvaluatedSchemaWithoutParamsSubform(
|
|
402
436
|
handle: String,
|
|
@@ -495,6 +529,16 @@ class JsonEvalRsModule(reactContext: ReactApplicationContext) :
|
|
|
495
529
|
nativeCancel(handle)
|
|
496
530
|
}
|
|
497
531
|
|
|
532
|
+
@ReactMethod
|
|
533
|
+
fun version(promise: Promise) {
|
|
534
|
+
try {
|
|
535
|
+
val version = nativeVersion()
|
|
536
|
+
promise.resolve(version)
|
|
537
|
+
} catch (e: Exception) {
|
|
538
|
+
promise.reject("VERSION_ERROR", e.message, e)
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
498
542
|
@ReactMethod
|
|
499
543
|
fun multiply(a: Double, b: Double, promise: Promise) {
|
|
500
544
|
promise.resolve(a * b)
|
|
@@ -524,6 +568,8 @@ class JsonEvalRsModule(reactContext: ReactApplicationContext) :
|
|
|
524
568
|
)
|
|
525
569
|
private external fun nativeGetEvaluatedSchemaAsync(handle: String, skipLayout: Boolean, promise: Promise)
|
|
526
570
|
private external fun nativeGetSchemaValueAsync(handle: String, promise: Promise)
|
|
571
|
+
private external fun nativeGetSchemaValueArrayAsync(handle: String, promise: Promise)
|
|
572
|
+
private external fun nativeGetSchemaValueObjectAsync(handle: String, promise: Promise)
|
|
527
573
|
private external fun nativeGetEvaluatedSchemaWithoutParamsAsync(handle: String, skipLayout: Boolean, promise: Promise)
|
|
528
574
|
private external fun nativeGetEvaluatedSchemaByPathAsync(handle: String, path: String, skipLayout: Boolean, promise: Promise)
|
|
529
575
|
private external fun nativeGetEvaluatedSchemaByPathsAsync(handle: String, pathsJson: String, skipLayout: Boolean, format: Int, promise: Promise)
|
|
@@ -594,6 +640,8 @@ class JsonEvalRsModule(reactContext: ReactApplicationContext) :
|
|
|
594
640
|
private external fun nativeResolveLayoutSubformAsync(handle: String, subformPath: String, evaluate: Boolean, promise: Promise)
|
|
595
641
|
private external fun nativeGetEvaluatedSchemaSubformAsync(handle: String, subformPath: String, resolveLayout: Boolean, promise: Promise)
|
|
596
642
|
private external fun nativeGetSchemaValueSubformAsync(handle: String, subformPath: String, promise: Promise)
|
|
643
|
+
private external fun nativeGetSchemaValueArraySubformAsync(handle: String, subformPath: String, promise: Promise)
|
|
644
|
+
private external fun nativeGetSchemaValueObjectSubformAsync(handle: String, subformPath: String, promise: Promise)
|
|
597
645
|
private external fun nativeGetEvaluatedSchemaWithoutParamsSubformAsync(handle: String, subformPath: String, resolveLayout: Boolean, promise: Promise)
|
|
598
646
|
private external fun nativeGetEvaluatedSchemaByPathSubformAsync(handle: String, subformPath: String, schemaPath: String, skipLayout: Boolean, promise: Promise)
|
|
599
647
|
private external fun nativeGetEvaluatedSchemaByPathsSubformAsync(handle: String, subformPath: String, schemaPathsJson: String, skipLayout: Boolean, format: Int, promise: Promise)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cpp/json-eval-bridge.cpp
CHANGED
|
@@ -25,6 +25,8 @@ extern "C" {
|
|
|
25
25
|
FFIResult json_eval_evaluate_dependents(JSONEvalHandle* handle, const char* changed_path, const char* data, const char* context, int re_evaluate);
|
|
26
26
|
FFIResult json_eval_get_evaluated_schema(JSONEvalHandle* handle, bool skip_layout);
|
|
27
27
|
FFIResult json_eval_get_schema_value(JSONEvalHandle* handle);
|
|
28
|
+
FFIResult json_eval_get_schema_value_array(JSONEvalHandle* handle);
|
|
29
|
+
FFIResult json_eval_get_schema_value_object(JSONEvalHandle* handle);
|
|
28
30
|
FFIResult json_eval_get_evaluated_schema_without_params(JSONEvalHandle* handle, bool skip_layout);
|
|
29
31
|
FFIResult json_eval_get_evaluated_schema_by_path(JSONEvalHandle* handle, const char* path, bool skip_layout);
|
|
30
32
|
FFIResult json_eval_get_evaluated_schema_by_paths(JSONEvalHandle* handle, const char* paths_json, bool skip_layout, uint8_t format);
|
|
@@ -54,6 +56,8 @@ extern "C" {
|
|
|
54
56
|
FFIResult json_eval_resolve_layout_subform(JSONEvalHandle* handle, const char* subform_path, bool evaluate);
|
|
55
57
|
FFIResult json_eval_get_evaluated_schema_subform(JSONEvalHandle* handle, const char* subform_path, bool resolve_layout);
|
|
56
58
|
FFIResult json_eval_get_schema_value_subform(JSONEvalHandle* handle, const char* subform_path);
|
|
59
|
+
FFIResult json_eval_get_schema_value_array_subform(JSONEvalHandle* handle, const char* subform_path);
|
|
60
|
+
FFIResult json_eval_get_schema_value_object_subform(JSONEvalHandle* handle, const char* subform_path);
|
|
57
61
|
FFIResult json_eval_get_evaluated_schema_without_params_subform(JSONEvalHandle* handle, const char* subform_path, bool resolve_layout);
|
|
58
62
|
FFIResult json_eval_get_evaluated_schema_by_path_subform(JSONEvalHandle* handle, const char* subform_path, const char* schema_path, bool skip_layout);
|
|
59
63
|
FFIResult json_eval_get_evaluated_schema_by_paths_subform(JSONEvalHandle* handle, const char* subform_path, const char* schema_paths_json, bool skip_layout, uint8_t format);
|
|
@@ -467,6 +471,66 @@ void JsonEvalBridge::getSchemaValueAsync(
|
|
|
467
471
|
}, callback);
|
|
468
472
|
}
|
|
469
473
|
|
|
474
|
+
void JsonEvalBridge::getSchemaValueArrayAsync(
|
|
475
|
+
const std::string& handleId,
|
|
476
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
477
|
+
) {
|
|
478
|
+
runAsync([handleId]() -> std::string {
|
|
479
|
+
std::lock_guard<std::mutex> lock(handlesMutex);
|
|
480
|
+
auto it = handles.find(handleId);
|
|
481
|
+
if (it == handles.end()) {
|
|
482
|
+
throw std::runtime_error("Invalid handle");
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
FFIResult result = json_eval_get_schema_value_array(it->second);
|
|
486
|
+
|
|
487
|
+
if (!result.success) {
|
|
488
|
+
std::string error = result.error ? result.error : "Unknown error";
|
|
489
|
+
json_eval_free_result(result);
|
|
490
|
+
throw std::runtime_error(error);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
std::string resultStr;
|
|
494
|
+
if (result.data_ptr && result.data_len > 0) {
|
|
495
|
+
resultStr.assign(reinterpret_cast<const char*>(result.data_ptr), result.data_len);
|
|
496
|
+
} else {
|
|
497
|
+
resultStr = "[]";
|
|
498
|
+
}
|
|
499
|
+
json_eval_free_result(result);
|
|
500
|
+
return resultStr;
|
|
501
|
+
}, callback);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
void JsonEvalBridge::getSchemaValueObjectAsync(
|
|
505
|
+
const std::string& handleId,
|
|
506
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
507
|
+
) {
|
|
508
|
+
runAsync([handleId]() -> std::string {
|
|
509
|
+
std::lock_guard<std::mutex> lock(handlesMutex);
|
|
510
|
+
auto it = handles.find(handleId);
|
|
511
|
+
if (it == handles.end()) {
|
|
512
|
+
throw std::runtime_error("Invalid handle");
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
FFIResult result = json_eval_get_schema_value_object(it->second);
|
|
516
|
+
|
|
517
|
+
if (!result.success) {
|
|
518
|
+
std::string error = result.error ? result.error : "Unknown error";
|
|
519
|
+
json_eval_free_result(result);
|
|
520
|
+
throw std::runtime_error(error);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
std::string resultStr;
|
|
524
|
+
if (result.data_ptr && result.data_len > 0) {
|
|
525
|
+
resultStr.assign(reinterpret_cast<const char*>(result.data_ptr), result.data_len);
|
|
526
|
+
} else {
|
|
527
|
+
resultStr = "{}";
|
|
528
|
+
}
|
|
529
|
+
json_eval_free_result(result);
|
|
530
|
+
return resultStr;
|
|
531
|
+
}, callback);
|
|
532
|
+
}
|
|
533
|
+
|
|
470
534
|
void JsonEvalBridge::getEvaluatedSchemaWithoutParamsAsync(
|
|
471
535
|
const std::string& handleId,
|
|
472
536
|
bool skipLayout,
|
|
@@ -1171,6 +1235,68 @@ void JsonEvalBridge::getSchemaValueSubformAsync(
|
|
|
1171
1235
|
}, callback);
|
|
1172
1236
|
}
|
|
1173
1237
|
|
|
1238
|
+
void JsonEvalBridge::getSchemaValueArraySubformAsync(
|
|
1239
|
+
const std::string& handleId,
|
|
1240
|
+
const std::string& subformPath,
|
|
1241
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
1242
|
+
) {
|
|
1243
|
+
runAsync([handleId, subformPath]() -> std::string {
|
|
1244
|
+
std::lock_guard<std::mutex> lock(handlesMutex);
|
|
1245
|
+
auto it = handles.find(handleId);
|
|
1246
|
+
if (it == handles.end()) {
|
|
1247
|
+
throw std::runtime_error("Invalid handle");
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
FFIResult result = json_eval_get_schema_value_array_subform(it->second, subformPath.c_str());
|
|
1251
|
+
|
|
1252
|
+
if (!result.success) {
|
|
1253
|
+
std::string error = result.error ? result.error : "Unknown error";
|
|
1254
|
+
json_eval_free_result(result);
|
|
1255
|
+
throw std::runtime_error(error);
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
std::string resultStr;
|
|
1259
|
+
if (result.data_ptr && result.data_len > 0) {
|
|
1260
|
+
resultStr.assign(reinterpret_cast<const char*>(result.data_ptr), result.data_len);
|
|
1261
|
+
} else {
|
|
1262
|
+
resultStr = "[]";
|
|
1263
|
+
}
|
|
1264
|
+
json_eval_free_result(result);
|
|
1265
|
+
return resultStr;
|
|
1266
|
+
}, callback);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
void JsonEvalBridge::getSchemaValueObjectSubformAsync(
|
|
1270
|
+
const std::string& handleId,
|
|
1271
|
+
const std::string& subformPath,
|
|
1272
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
1273
|
+
) {
|
|
1274
|
+
runAsync([handleId, subformPath]() -> std::string {
|
|
1275
|
+
std::lock_guard<std::mutex> lock(handlesMutex);
|
|
1276
|
+
auto it = handles.find(handleId);
|
|
1277
|
+
if (it == handles.end()) {
|
|
1278
|
+
throw std::runtime_error("Invalid handle");
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
FFIResult result = json_eval_get_schema_value_object_subform(it->second, subformPath.c_str());
|
|
1282
|
+
|
|
1283
|
+
if (!result.success) {
|
|
1284
|
+
std::string error = result.error ? result.error : "Unknown error";
|
|
1285
|
+
json_eval_free_result(result);
|
|
1286
|
+
throw std::runtime_error(error);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
std::string resultStr;
|
|
1290
|
+
if (result.data_ptr && result.data_len > 0) {
|
|
1291
|
+
resultStr.assign(reinterpret_cast<const char*>(result.data_ptr), result.data_len);
|
|
1292
|
+
} else {
|
|
1293
|
+
resultStr = "{}";
|
|
1294
|
+
}
|
|
1295
|
+
json_eval_free_result(result);
|
|
1296
|
+
return resultStr;
|
|
1297
|
+
}, callback);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1174
1300
|
void JsonEvalBridge::getEvaluatedSchemaWithoutParamsSubformAsync(
|
|
1175
1301
|
const std::string& handleId,
|
|
1176
1302
|
const std::string& subformPath,
|
package/cpp/json-eval-bridge.h
CHANGED
|
@@ -134,6 +134,28 @@ public:
|
|
|
134
134
|
std::function<void(const std::string&, const std::string&)> callback
|
|
135
135
|
);
|
|
136
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Get all schema values as array of path-value pairs (async)
|
|
139
|
+
* Returns [{path: "", value: ""}, ...]
|
|
140
|
+
* @param handle Instance handle
|
|
141
|
+
* @param callback Result callback
|
|
142
|
+
*/
|
|
143
|
+
static void getSchemaValueArrayAsync(
|
|
144
|
+
const std::string& handle,
|
|
145
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get all schema values as object with dotted path keys (async)
|
|
150
|
+
* Returns {path: value, ...}
|
|
151
|
+
* @param handle Instance handle
|
|
152
|
+
* @param callback Result callback
|
|
153
|
+
*/
|
|
154
|
+
static void getSchemaValueObjectAsync(
|
|
155
|
+
const std::string& handle,
|
|
156
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
157
|
+
);
|
|
158
|
+
|
|
137
159
|
/**
|
|
138
160
|
* Get evaluated schema without $params field (async)
|
|
139
161
|
* @param handle Instance handle
|
|
@@ -488,6 +510,32 @@ public:
|
|
|
488
510
|
std::function<void(const std::string&, const std::string&)> callback
|
|
489
511
|
);
|
|
490
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Get all schema values as array of path-value pairs from subform (async)
|
|
515
|
+
* Returns [{path: "", value: ""}, ...]
|
|
516
|
+
* @param handleId Instance handle
|
|
517
|
+
* @param subformPath Path to the subform
|
|
518
|
+
* @param callback Result callback
|
|
519
|
+
*/
|
|
520
|
+
static void getSchemaValueArraySubformAsync(
|
|
521
|
+
const std::string& handleId,
|
|
522
|
+
const std::string& subformPath,
|
|
523
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Get all schema values as object with dotted path keys from subform (async)
|
|
528
|
+
* Returns {path: value, ...}
|
|
529
|
+
* @param handleId Instance handle
|
|
530
|
+
* @param subformPath Path to the subform
|
|
531
|
+
* @param callback Result callback
|
|
532
|
+
*/
|
|
533
|
+
static void getSchemaValueObjectSubformAsync(
|
|
534
|
+
const std::string& handleId,
|
|
535
|
+
const std::string& subformPath,
|
|
536
|
+
std::function<void(const std::string&, const std::string&)> callback
|
|
537
|
+
);
|
|
538
|
+
|
|
491
539
|
/**
|
|
492
540
|
* Get evaluated schema without $params from subform (async)
|
|
493
541
|
* @param handleId Instance handle
|
package/ios/JsonEvalRs.mm
CHANGED
|
@@ -242,6 +242,40 @@ RCT_EXPORT_METHOD(getSchemaValue:(NSString *)handle
|
|
|
242
242
|
);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
RCT_EXPORT_METHOD(getSchemaValueArray:(NSString *)handle
|
|
246
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
247
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
248
|
+
{
|
|
249
|
+
std::string handleStr = [self stdStringFromNSString:handle];
|
|
250
|
+
|
|
251
|
+
JsonEvalBridge::getSchemaValueArrayAsync(handleStr,
|
|
252
|
+
[resolve, reject](const std::string& result, const std::string& error) {
|
|
253
|
+
if (error.empty()) {
|
|
254
|
+
resolve([NSString stringWithUTF8String:result.c_str()]);
|
|
255
|
+
} else {
|
|
256
|
+
reject(@"GET_SCHEMA_VALUE_ARRAY_ERROR", [NSString stringWithUTF8String:error.c_str()], nil);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
RCT_EXPORT_METHOD(getSchemaValueObject:(NSString *)handle
|
|
263
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
264
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
265
|
+
{
|
|
266
|
+
std::string handleStr = [self stdStringFromNSString:handle];
|
|
267
|
+
|
|
268
|
+
JsonEvalBridge::getSchemaValueObjectAsync(handleStr,
|
|
269
|
+
[resolve, reject](const std::string& result, const std::string& error) {
|
|
270
|
+
if (error.empty()) {
|
|
271
|
+
resolve([NSString stringWithUTF8String:result.c_str()]);
|
|
272
|
+
} else {
|
|
273
|
+
reject(@"GET_SCHEMA_VALUE_OBJECT_ERROR", [NSString stringWithUTF8String:error.c_str()], nil);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
245
279
|
RCT_EXPORT_METHOD(getEvaluatedSchemaWithoutParams:(NSString *)handle
|
|
246
280
|
skipLayout:(BOOL)skipLayout
|
|
247
281
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
@@ -714,6 +748,44 @@ RCT_EXPORT_METHOD(getSchemaValueSubform:(NSString *)handle
|
|
|
714
748
|
);
|
|
715
749
|
}
|
|
716
750
|
|
|
751
|
+
RCT_EXPORT_METHOD(getSchemaValueArraySubform:(NSString *)handle
|
|
752
|
+
subformPath:(NSString *)subformPath
|
|
753
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
754
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
755
|
+
{
|
|
756
|
+
std::string handleStr = [self stdStringFromNSString:handle];
|
|
757
|
+
std::string pathStr = [self stdStringFromNSString:subformPath];
|
|
758
|
+
|
|
759
|
+
JsonEvalBridge::getSchemaValueArraySubformAsync(handleStr, pathStr,
|
|
760
|
+
[resolve, reject](const std::string& result, const std::string& error) {
|
|
761
|
+
if (error.empty()) {
|
|
762
|
+
resolve([NSString stringWithUTF8String:result.c_str()]);
|
|
763
|
+
} else {
|
|
764
|
+
reject(@"GET_SCHEMA_VALUE_ARRAY_SUBFORM_ERROR", [NSString stringWithUTF8String:error.c_str()], nil);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
RCT_EXPORT_METHOD(getSchemaValueObjectSubform:(NSString *)handle
|
|
771
|
+
subformPath:(NSString *)subformPath
|
|
772
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
773
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
774
|
+
{
|
|
775
|
+
std::string handleStr = [self stdStringFromNSString:handle];
|
|
776
|
+
std::string pathStr = [self stdStringFromNSString:subformPath];
|
|
777
|
+
|
|
778
|
+
JsonEvalBridge::getSchemaValueObjectSubformAsync(handleStr, pathStr,
|
|
779
|
+
[resolve, reject](const std::string& result, const std::string& error) {
|
|
780
|
+
if (error.empty()) {
|
|
781
|
+
resolve([NSString stringWithUTF8String:result.c_str()]);
|
|
782
|
+
} else {
|
|
783
|
+
reject(@"GET_SCHEMA_VALUE_OBJECT_SUBFORM_ERROR", [NSString stringWithUTF8String:error.c_str()], nil);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
|
|
717
789
|
RCT_EXPORT_METHOD(getEvaluatedSchemaWithoutParamsSubform:(NSString *)handle
|
|
718
790
|
subformPath:(NSString *)subformPath
|
|
719
791
|
resolveLayout:(BOOL)resolveLayout
|
|
@@ -876,6 +948,12 @@ RCT_EXPORT_METHOD(setTimezoneOffset:(NSString *)handle
|
|
|
876
948
|
}
|
|
877
949
|
}
|
|
878
950
|
|
|
951
|
+
RCT_EXPORT_METHOD(cancel:(NSString *)handle)
|
|
952
|
+
{
|
|
953
|
+
std::string handleStr = [self stdStringFromNSString:handle];
|
|
954
|
+
JsonEvalBridge::cancel(handleStr);
|
|
955
|
+
}
|
|
956
|
+
|
|
879
957
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(dispose:(NSString *)handle)
|
|
880
958
|
{
|
|
881
959
|
std::string handleStr = [self stdStringFromNSString:handle];
|
|
Binary file
|
|
Binary file
|
package/lib/commonjs/index.js
CHANGED
|
@@ -18,6 +18,9 @@ const JsonEvalRs = _reactNative.NativeModules.JsonEvalRs ? _reactNative.NativeMo
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Item for get schema value array results
|
|
23
|
+
*/
|
|
21
24
|
/**
|
|
22
25
|
* Return format for path-based methods
|
|
23
26
|
*/
|
|
@@ -86,22 +89,22 @@ let ReturnFormat = exports.ReturnFormat = /*#__PURE__*/function (ReturnFormat) {
|
|
|
86
89
|
*/
|
|
87
90
|
/**
|
|
88
91
|
* High-performance JSON Logic evaluator with schema validation for React Native
|
|
89
|
-
*
|
|
92
|
+
*
|
|
90
93
|
* ## Zero-Copy Architecture
|
|
91
|
-
*
|
|
94
|
+
*
|
|
92
95
|
* This binding is optimized for minimal memory copies:
|
|
93
96
|
* - **Rust FFI Layer**: Returns raw pointers (zero-copy)
|
|
94
97
|
* - **C++ Bridge**: Uses direct pointer access with single-copy string construction
|
|
95
98
|
* - **Native Platform**: Minimizes intermediate conversions
|
|
96
99
|
* - **JS Bridge**: React Native's architecture requires serialization (unavoidable)
|
|
97
|
-
*
|
|
100
|
+
*
|
|
98
101
|
* While true zero-copy across JS/Native boundary is not possible due to React Native's
|
|
99
102
|
* architecture, we minimize copies within the native layer to maximize performance.
|
|
100
|
-
*
|
|
103
|
+
*
|
|
101
104
|
* @example
|
|
102
105
|
* ```typescript
|
|
103
106
|
* import { JSONEval } from '@json-eval-rs/react-native';
|
|
104
|
-
*
|
|
107
|
+
*
|
|
105
108
|
* const schema = {
|
|
106
109
|
* type: 'object',
|
|
107
110
|
* properties: {
|
|
@@ -118,18 +121,18 @@ let ReturnFormat = exports.ReturnFormat = /*#__PURE__*/function (ReturnFormat) {
|
|
|
118
121
|
* }
|
|
119
122
|
* }
|
|
120
123
|
* };
|
|
121
|
-
*
|
|
124
|
+
*
|
|
122
125
|
* const eval = new JSONEval({ schema });
|
|
123
|
-
*
|
|
126
|
+
*
|
|
124
127
|
* const data = { user: { name: 'John' } };
|
|
125
128
|
* const result = await eval.evaluate({ data });
|
|
126
129
|
* console.log(result);
|
|
127
|
-
*
|
|
130
|
+
*
|
|
128
131
|
* const validation = await eval.validate({ data });
|
|
129
132
|
* if (validation.hasError) {
|
|
130
133
|
* console.error('Validation errors:', validation.errors);
|
|
131
134
|
* }
|
|
132
|
-
*
|
|
135
|
+
*
|
|
133
136
|
* await eval.dispose();
|
|
134
137
|
* ```
|
|
135
138
|
*/
|
|
@@ -212,7 +215,7 @@ class JSONEval {
|
|
|
212
215
|
|
|
213
216
|
/**
|
|
214
217
|
* Cancel any running evaluation
|
|
215
|
-
* The generic auto-cancellation on new evaluation will still work,
|
|
218
|
+
* The generic auto-cancellation on new evaluation will still work,
|
|
216
219
|
* but this allows manual cancellation.
|
|
217
220
|
*/
|
|
218
221
|
async cancel() {
|
|
@@ -308,6 +311,30 @@ class JSONEval {
|
|
|
308
311
|
return JSON.parse(resultStr);
|
|
309
312
|
}
|
|
310
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Get all schema values as array of path-value pairs
|
|
316
|
+
* Returns [{path: "", value: ""}, ...]
|
|
317
|
+
* @returns Promise resolving to array of SchemaValueItem objects
|
|
318
|
+
* @throws {Error} If operation fails
|
|
319
|
+
*/
|
|
320
|
+
async getSchemaValueArray() {
|
|
321
|
+
this.throwIfDisposed();
|
|
322
|
+
const resultStr = await JsonEvalRs.getSchemaValueArray(this.handle);
|
|
323
|
+
return JSON.parse(resultStr);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Get all schema values as object with dotted path keys
|
|
328
|
+
* Returns {path: value, ...}
|
|
329
|
+
* @returns Promise resolving to flat object with dotted paths as keys
|
|
330
|
+
* @throws {Error} If operation fails
|
|
331
|
+
*/
|
|
332
|
+
async getSchemaValueObject() {
|
|
333
|
+
this.throwIfDisposed();
|
|
334
|
+
const resultStr = await JsonEvalRs.getSchemaValueObject(this.handle);
|
|
335
|
+
return JSON.parse(resultStr);
|
|
336
|
+
}
|
|
337
|
+
|
|
311
338
|
/**
|
|
312
339
|
* Get the evaluated schema without $params field
|
|
313
340
|
* @param skipLayout - Whether to skip layout resolution (default: false)
|
|
@@ -520,15 +547,15 @@ class JSONEval {
|
|
|
520
547
|
* Pass null to reset to UTC
|
|
521
548
|
* @returns Promise that resolves when timezone is set
|
|
522
549
|
* @throws {Error} If operation fails
|
|
523
|
-
*
|
|
550
|
+
*
|
|
524
551
|
* @example
|
|
525
552
|
* ```typescript
|
|
526
553
|
* // Set to UTC+7 (Jakarta, Bangkok)
|
|
527
554
|
* await eval.setTimezoneOffset(420);
|
|
528
|
-
*
|
|
555
|
+
*
|
|
529
556
|
* // Set to UTC-5 (New York, EST)
|
|
530
557
|
* await eval.setTimezoneOffset(-300);
|
|
531
|
-
*
|
|
558
|
+
*
|
|
532
559
|
* // Reset to UTC
|
|
533
560
|
* await eval.setTimezoneOffset(null);
|
|
534
561
|
* ```
|
|
@@ -681,6 +708,32 @@ class JSONEval {
|
|
|
681
708
|
return JSON.parse(resultStr);
|
|
682
709
|
}
|
|
683
710
|
|
|
711
|
+
/**
|
|
712
|
+
* Get schema values from subform as a flat array of path-value pairs.
|
|
713
|
+
* Returns an array like `[{path: "field.sub", value: 123}, ...]`.
|
|
714
|
+
* @param options - Options including subform path
|
|
715
|
+
* @returns Promise resolving to array of SchemaValueItem objects
|
|
716
|
+
* @throws {Error} If operation fails
|
|
717
|
+
*/
|
|
718
|
+
async getSchemaValueArraySubform(options) {
|
|
719
|
+
this.throwIfDisposed();
|
|
720
|
+
const resultStr = await JsonEvalRs.getSchemaValueArraySubform(this.handle, options.subformPath);
|
|
721
|
+
return JSON.parse(resultStr);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Get schema values from subform as a flat object with dotted path keys.
|
|
726
|
+
* Returns an object like `{"field.sub": 123, ...}`.
|
|
727
|
+
* @param options - Options including subform path
|
|
728
|
+
* @returns Promise resolving to flat object with dotted paths
|
|
729
|
+
* @throws {Error} If operation fails
|
|
730
|
+
*/
|
|
731
|
+
async getSchemaValueObjectSubform(options) {
|
|
732
|
+
this.throwIfDisposed();
|
|
733
|
+
const resultStr = await JsonEvalRs.getSchemaValueObjectSubform(this.handle, options.subformPath);
|
|
734
|
+
return JSON.parse(resultStr);
|
|
735
|
+
}
|
|
736
|
+
|
|
684
737
|
/**
|
|
685
738
|
* Get evaluated schema without $params from subform
|
|
686
739
|
* @param options - Options including subform path and resolveLayout flag
|
|
@@ -791,20 +844,20 @@ class JSONEval {
|
|
|
791
844
|
* Hook for using JSONEval in React components with automatic cleanup
|
|
792
845
|
* @param options - Configuration options
|
|
793
846
|
* @returns JSONEval instance or null if not yet initialized
|
|
794
|
-
*
|
|
847
|
+
*
|
|
795
848
|
* @example
|
|
796
849
|
* ```typescript
|
|
797
850
|
* import { useJSONEval } from '@json-eval-rs/react-native';
|
|
798
|
-
*
|
|
851
|
+
*
|
|
799
852
|
* function MyComponent() {
|
|
800
853
|
* const eval = useJSONEval({ schema: mySchema });
|
|
801
|
-
*
|
|
854
|
+
*
|
|
802
855
|
* const handleValidate = async () => {
|
|
803
856
|
* if (!eval) return;
|
|
804
857
|
* const result = await eval.validate({ data: myData });
|
|
805
858
|
* console.log(result);
|
|
806
859
|
* };
|
|
807
|
-
*
|
|
860
|
+
*
|
|
808
861
|
* return <Button onPress={handleValidate} title="Validate" />;
|
|
809
862
|
* }
|
|
810
863
|
* ```
|