@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,583 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+ #include <functional>
5
+ #include <thread>
6
+ #include <future>
7
+
8
+ namespace jsoneval {
9
+
10
+ /**
11
+ * C++ Bridge for JSON Eval RS
12
+ * Thread-safe wrapper around the Rust FFI
13
+ */
14
+ class JsonEvalBridge {
15
+ public:
16
+ /**
17
+ * Create a new JSONEval instance
18
+ * @param schema JSON schema string
19
+ * @param context Optional context data
20
+ * @param data Optional initial data
21
+ * @return Handle string or error
22
+ */
23
+ static std::string create(
24
+ const std::string& schema,
25
+ const std::string& context,
26
+ const std::string& data
27
+ );
28
+
29
+ /**
30
+ * Create instance from MessagePack
31
+ * @param schemaMsgpack MessagePack-encoded schema bytes
32
+ * @param context Optional context data
33
+ * @param data Optional initial data
34
+ * @return Handle string or error
35
+ */
36
+ static std::string createFromMsgpack(
37
+ const std::vector<uint8_t>& schemaMsgpack,
38
+ const std::string& context,
39
+ const std::string& data
40
+ );
41
+
42
+ /**
43
+ * Create instance from ParsedSchemaCache
44
+ * @param cacheKey Cache key to lookup in ParsedSchemaCache
45
+ * @param context Optional context data
46
+ * @param data Optional initial data
47
+ * @return Handle string or error
48
+ */
49
+ static std::string createFromCache(
50
+ const std::string& cacheKey,
51
+ const std::string& context,
52
+ const std::string& data
53
+ );
54
+
55
+ /**
56
+ * Evaluate schema with data (async)
57
+ * @param handle Instance handle
58
+ * @param data JSON data string
59
+ * @param context Optional context data
60
+ * @param callback Result callback
61
+ */
62
+ static void evaluateAsync(
63
+ const std::string& handle,
64
+ const std::string& data,
65
+ const std::string& context,
66
+ std::function<void(const std::string&, const std::string&)> callback
67
+ );
68
+
69
+ /**
70
+ * Validate data (async)
71
+ * @param handle Instance handle
72
+ * @param data JSON data string
73
+ * @param context Optional context data
74
+ * @param callback Result callback
75
+ */
76
+ static void validateAsync(
77
+ const std::string& handle,
78
+ const std::string& data,
79
+ const std::string& context,
80
+ std::function<void(const std::string&, const std::string&)> callback
81
+ );
82
+
83
+ /**
84
+ * Evaluate dependents (async) - processes transitively
85
+ * @param handle Instance handle
86
+ * @param changedPathsJson JSON array of field paths that changed
87
+ * @param data Optional updated JSON data string (empty to use existing)
88
+ * @param context Optional context data
89
+ * @param reEvaluate If true, performs full evaluation after processing dependents
90
+ * @param callback Result callback
91
+ */
92
+ static void evaluateDependentsAsync(
93
+ const std::string& handle,
94
+ const std::string& changedPathsJson,
95
+ const std::string& data,
96
+ const std::string& context,
97
+ bool reEvaluate,
98
+ std::function<void(const std::string&, const std::string&)> callback
99
+ );
100
+
101
+ /**
102
+ * Get evaluated schema (async)
103
+ * @param handle Instance handle
104
+ * @param skipLayout Whether to skip layout resolution
105
+ * @param callback Result callback
106
+ */
107
+ static void getEvaluatedSchemaAsync(
108
+ const std::string& handle,
109
+ bool skipLayout,
110
+ std::function<void(const std::string&, const std::string&)> callback
111
+ );
112
+
113
+ /**
114
+ * Get evaluated schema in MessagePack format (async)
115
+ * @param handle Instance handle
116
+ * @param skipLayout Whether to skip layout resolution
117
+ * @param callback Result callback with MessagePack binary data
118
+ */
119
+ static void getEvaluatedSchemaMsgpackAsync(
120
+ const std::string& handle,
121
+ bool skipLayout,
122
+ std::function<void(const std::string&, const std::string&)> callback
123
+ );
124
+
125
+ /**
126
+ * Get schema value (async)
127
+ * @param handle Instance handle
128
+ * @param callback Result callback
129
+ */
130
+ static void getSchemaValueAsync(
131
+ const std::string& handle,
132
+ std::function<void(const std::string&, const std::string&)> callback
133
+ );
134
+
135
+ /**
136
+ * Get evaluated schema without $params field (async)
137
+ * @param handle Instance handle
138
+ * @param skipLayout Whether to skip layout resolution
139
+ * @param callback Result callback
140
+ */
141
+ static void getEvaluatedSchemaWithoutParamsAsync(
142
+ const std::string& handle,
143
+ bool skipLayout,
144
+ std::function<void(const std::string&, const std::string&)> callback
145
+ );
146
+
147
+ /**
148
+ * Get a value from evaluated schema using dotted path notation (async)
149
+ * @param handle Instance handle
150
+ * @param path Dotted path to the value (e.g., "properties.field.value")
151
+ * @param skipLayout Whether to skip layout resolution
152
+ * @param callback Result callback
153
+ */
154
+ static void getEvaluatedSchemaByPathAsync(
155
+ const std::string& handle,
156
+ const std::string& path,
157
+ bool skipLayout,
158
+ std::function<void(const std::string&, const std::string&)> callback
159
+ );
160
+
161
+ /**
162
+ * Get values from evaluated schema using multiple dotted path notations (async)
163
+ * @param handle Instance handle
164
+ * @param pathsJson JSON array of dotted paths to retrieve
165
+ * @param skipLayout Whether to skip layout resolution
166
+ * @param callback Result callback
167
+ */
168
+ static void getEvaluatedSchemaByPathsAsync(
169
+ const std::string& handle,
170
+ const std::string& pathsJson,
171
+ bool skipLayout,
172
+ std::function<void(const std::string&, const std::string&)> callback
173
+ );
174
+
175
+ /**
176
+ * Get a value from schema using dotted path notation (async)
177
+ * @param handle Instance handle
178
+ * @param path Dotted path to the value (e.g., "properties.field.value")
179
+ * @param callback Result callback
180
+ */
181
+ static void getSchemaByPathAsync(
182
+ const std::string& handle,
183
+ const std::string& path,
184
+ std::function<void(const std::string&, const std::string&)> callback
185
+ );
186
+
187
+ /**
188
+ * Get values from schema using multiple dotted path notations (async)
189
+ * @param handle Instance handle
190
+ * @param pathsJson JSON array of dotted paths to retrieve
191
+ * @param callback Result callback
192
+ */
193
+ static void getSchemaByPathsAsync(
194
+ const std::string& handle,
195
+ const std::string& pathsJson,
196
+ std::function<void(const std::string&, const std::string&)> callback
197
+ );
198
+
199
+ /**
200
+ * Reload schema (async)
201
+ * @param handle Instance handle
202
+ * @param schema New JSON schema string
203
+ * @param context Optional context data
204
+ * @param data Optional initial data
205
+ * @param callback Result callback
206
+ */
207
+ static void reloadSchemaAsync(
208
+ const std::string& handle,
209
+ const std::string& schema,
210
+ const std::string& context,
211
+ const std::string& data,
212
+ std::function<void(const std::string&, const std::string&)> callback
213
+ );
214
+
215
+ /**
216
+ * Reload schema from MessagePack (async)
217
+ * @param handle Instance handle
218
+ * @param schemaMsgpack MessagePack-encoded schema bytes
219
+ * @param context Optional context data
220
+ * @param data Optional initial data
221
+ * @param callback Result callback
222
+ */
223
+ static void reloadSchemaMsgpackAsync(
224
+ const std::string& handle,
225
+ const std::vector<uint8_t>& schemaMsgpack,
226
+ const std::string& context,
227
+ const std::string& data,
228
+ std::function<void(const std::string&, const std::string&)> callback
229
+ );
230
+
231
+ /**
232
+ * Reload schema from ParsedSchemaCache (async)
233
+ * @param handle Instance handle
234
+ * @param cacheKey Cache key to lookup in ParsedSchemaCache
235
+ * @param context Optional context data
236
+ * @param data Optional initial data
237
+ * @param callback Result callback
238
+ */
239
+ static void reloadSchemaFromCacheAsync(
240
+ const std::string& handle,
241
+ const std::string& cacheKey,
242
+ const std::string& context,
243
+ const std::string& data,
244
+ std::function<void(const std::string&, const std::string&)> callback
245
+ );
246
+
247
+ /**
248
+ * Get cache stats (async)
249
+ * @param handle Instance handle
250
+ * @param callback Result callback
251
+ */
252
+ static void cacheStatsAsync(
253
+ const std::string& handle,
254
+ std::function<void(const std::string&, const std::string&)> callback
255
+ );
256
+
257
+ /**
258
+ * Clear cache (async)
259
+ * @param handle Instance handle
260
+ * @param callback Result callback
261
+ */
262
+ static void clearCacheAsync(
263
+ const std::string& handle,
264
+ std::function<void(const std::string&, const std::string&)> callback
265
+ );
266
+
267
+ /**
268
+ * Get cache length (async)
269
+ * @param handle Instance handle
270
+ * @param callback Result callback
271
+ */
272
+ static void cacheLenAsync(
273
+ const std::string& handle,
274
+ std::function<void(const std::string&, const std::string&)> callback
275
+ );
276
+
277
+ /**
278
+ * Enable evaluation caching (async)
279
+ * @param handle Instance handle
280
+ * @param callback Result callback
281
+ */
282
+ static void enableCacheAsync(
283
+ const std::string& handle,
284
+ std::function<void(const std::string&, const std::string&)> callback
285
+ );
286
+
287
+ /**
288
+ * Disable evaluation caching (async)
289
+ * @param handle Instance handle
290
+ * @param callback Result callback
291
+ */
292
+ static void disableCacheAsync(
293
+ const std::string& handle,
294
+ std::function<void(const std::string&, const std::string&)> callback
295
+ );
296
+
297
+ /**
298
+ * Check if caching is enabled (synchronous)
299
+ * @param handle Instance handle
300
+ * @returns true if caching is enabled, false otherwise
301
+ */
302
+ static bool isCacheEnabled(const std::string& handle);
303
+
304
+ /**
305
+ * Resolve layout with optional evaluation (async)
306
+ * @param handle Instance handle
307
+ * @param evaluate If true, runs evaluation before resolving layout
308
+ * @param callback Result callback
309
+ */
310
+ static void resolveLayoutAsync(
311
+ const std::string& handle,
312
+ bool evaluate,
313
+ std::function<void(const std::string&, const std::string&)> callback
314
+ );
315
+
316
+ /**
317
+ * Compile and run JSON logic expression
318
+ * @param handle JSONEval instance handle
319
+ * @param logicStr JSON logic expression
320
+ * @param data Optional JSON data string (empty to use existing data)
321
+ * @param context Optional context data string (empty to use existing context)
322
+ * @param callback Result callback
323
+ */
324
+ static void compileAndRunLogicAsync(
325
+ const std::string& handle,
326
+ const std::string& logicStr,
327
+ const std::string& data,
328
+ const std::string& context,
329
+ std::function<void(const std::string&, const std::string&)> callback
330
+ );
331
+
332
+ /**
333
+ * Compile JSON logic expression and return global logic ID
334
+ * @param handle JSONEval instance handle
335
+ * @param logicStr JSON logic expression
336
+ * @return Compiled logic ID (global cache)
337
+ */
338
+ static uint64_t compileLogic(
339
+ const std::string& handle,
340
+ const std::string& logicStr
341
+ );
342
+
343
+ /**
344
+ * Run pre-compiled JSON logic expression by ID
345
+ * @param handle JSONEval instance handle
346
+ * @param logicId Global compiled logic ID
347
+ * @param data Optional JSON data string (empty to use existing data)
348
+ * @param context Optional context data string (empty to use existing context)
349
+ * @param callback Result callback
350
+ */
351
+ static void runLogicAsync(
352
+ const std::string& handle,
353
+ uint64_t logicId,
354
+ const std::string& data,
355
+ const std::string& context,
356
+ std::function<void(const std::string&, const std::string&)> callback
357
+ );
358
+
359
+ /**
360
+ * Validate with paths (async)
361
+ * @param handle Instance handle
362
+ * @param data JSON data string
363
+ * @param context Optional context data
364
+ * @param pathsJson Optional JSON array of paths
365
+ * @param callback Result callback
366
+ */
367
+ static void validatePathsAsync(
368
+ const std::string& handle,
369
+ const std::string& data,
370
+ const std::string& context,
371
+ const std::string& pathsJson,
372
+ std::function<void(const std::string&, const std::string&)> callback
373
+ );
374
+
375
+ // ========================================================================
376
+ // Subform Methods
377
+ // ========================================================================
378
+
379
+ /**
380
+ * Evaluate a subform with data (async)
381
+ * @param handleId Instance handle
382
+ * @param subformPath Path to the subform (e.g., "#/riders")
383
+ * @param data JSON data string for the subform
384
+ * @param context Optional context data
385
+ * @param callback Result callback
386
+ */
387
+ static void evaluateSubformAsync(
388
+ const std::string& handleId,
389
+ const std::string& subformPath,
390
+ const std::string& data,
391
+ const std::string& context,
392
+ std::function<void(const std::string&, const std::string&)> callback
393
+ );
394
+
395
+ /**
396
+ * Validate subform data against its schema rules (async)
397
+ * @param handleId Instance handle
398
+ * @param subformPath Path to the subform
399
+ * @param data JSON data string for the subform
400
+ * @param context Optional context data
401
+ * @param callback Result callback
402
+ */
403
+ static void validateSubformAsync(
404
+ const std::string& handleId,
405
+ const std::string& subformPath,
406
+ const std::string& data,
407
+ const std::string& context,
408
+ std::function<void(const std::string&, const std::string&)> callback
409
+ );
410
+
411
+ /**
412
+ * Evaluate dependents in subform when a field changes (async)
413
+ * @param handleId Instance handle
414
+ * @param subformPath Path to the subform
415
+ * @param changedPath Path of the field that changed
416
+ * @param data Optional updated JSON data string
417
+ * @param context Optional context data
418
+ * @param callback Result callback
419
+ */
420
+ static void evaluateDependentsSubformAsync(
421
+ const std::string& handleId,
422
+ const std::string& subformPath,
423
+ const std::string& changedPath,
424
+ const std::string& data,
425
+ const std::string& context,
426
+ std::function<void(const std::string&, const std::string&)> callback
427
+ );
428
+
429
+ /**
430
+ * Resolve layout for subform (async)
431
+ * @param handleId Instance handle
432
+ * @param subformPath Path to the subform
433
+ * @param evaluate If true, runs evaluation before resolving layout
434
+ * @param callback Result callback
435
+ */
436
+ static void resolveLayoutSubformAsync(
437
+ const std::string& handleId,
438
+ const std::string& subformPath,
439
+ bool evaluate,
440
+ std::function<void(const std::string&, const std::string&)> callback
441
+ );
442
+
443
+ /**
444
+ * Get evaluated schema from subform (async)
445
+ * @param handleId Instance handle
446
+ * @param subformPath Path to the subform
447
+ * @param resolveLayout Whether to resolve layout
448
+ * @param callback Result callback
449
+ */
450
+ static void getEvaluatedSchemaSubformAsync(
451
+ const std::string& handleId,
452
+ const std::string& subformPath,
453
+ bool resolveLayout,
454
+ std::function<void(const std::string&, const std::string&)> callback
455
+ );
456
+
457
+ /**
458
+ * Get schema value from subform (async)
459
+ * @param handleId Instance handle
460
+ * @param subformPath Path to the subform
461
+ * @param callback Result callback
462
+ */
463
+ static void getSchemaValueSubformAsync(
464
+ const std::string& handleId,
465
+ const std::string& subformPath,
466
+ std::function<void(const std::string&, const std::string&)> callback
467
+ );
468
+
469
+ /**
470
+ * Get evaluated schema without $params from subform (async)
471
+ * @param handleId Instance handle
472
+ * @param subformPath Path to the subform
473
+ * @param resolveLayout Whether to resolve layout
474
+ * @param callback Result callback
475
+ */
476
+ static void getEvaluatedSchemaWithoutParamsSubformAsync(
477
+ const std::string& handleId,
478
+ const std::string& subformPath,
479
+ bool resolveLayout,
480
+ std::function<void(const std::string&, const std::string&)> callback
481
+ );
482
+
483
+ /**
484
+ * Get evaluated schema by path from subform (async)
485
+ * @param handleId Instance handle
486
+ * @param subformPath Path to the subform
487
+ * @param schemaPath Dotted path to the value within the subform
488
+ * @param skipLayout Whether to skip layout resolution
489
+ * @param callback Result callback
490
+ */
491
+ static void getEvaluatedSchemaByPathSubformAsync(
492
+ const std::string& handleId,
493
+ const std::string& subformPath,
494
+ const std::string& schemaPath,
495
+ bool skipLayout,
496
+ std::function<void(const std::string&, const std::string&)> callback
497
+ );
498
+
499
+ /**
500
+ * Get evaluated schema by multiple paths from subform (async)
501
+ * @param handleId Instance handle
502
+ * @param subformPath Path to the subform
503
+ * @param schemaPathsJson JSON array of dotted paths to retrieve within the subform
504
+ * @param skipLayout Whether to skip layout resolution
505
+ * @param callback Result callback
506
+ */
507
+ static void getEvaluatedSchemaByPathsSubformAsync(
508
+ const std::string& handleId,
509
+ const std::string& subformPath,
510
+ const std::string& schemaPathsJson,
511
+ bool skipLayout,
512
+ std::function<void(const std::string&, const std::string&)> callback
513
+ );
514
+
515
+ /**
516
+ * Get list of available subform paths (async)
517
+ * @param handleId Instance handle
518
+ * @param callback Result callback
519
+ */
520
+ static void getSubformPathsAsync(
521
+ const std::string& handleId,
522
+ std::function<void(const std::string&, const std::string&)> callback
523
+ );
524
+
525
+ /**
526
+ * Get schema by specific path from subform (async)
527
+ * @param handleId Instance handle
528
+ * @param subformPath Path to the subform
529
+ * @param schemaPath Dotted path to the value within the subform
530
+ * @param callback Result callback
531
+ */
532
+ static void getSchemaByPathSubformAsync(
533
+ const std::string& handleId,
534
+ const std::string& subformPath,
535
+ const std::string& schemaPath,
536
+ std::function<void(const std::string&, const std::string&)> callback
537
+ );
538
+
539
+ /**
540
+ * Get schema by multiple paths from subform (async)
541
+ * @param handleId Instance handle
542
+ * @param subformPath Path to the subform
543
+ * @param schemaPathsJson JSON array of dotted paths to retrieve within the subform
544
+ * @param callback Result callback
545
+ */
546
+ static void getSchemaByPathsSubformAsync(
547
+ const std::string& handleId,
548
+ const std::string& subformPath,
549
+ const std::string& schemaPathsJson,
550
+ std::function<void(const std::string&, const std::string&)> callback
551
+ );
552
+
553
+ /**
554
+ * Check if a subform exists at the given path (async)
555
+ * @param handleId Instance handle
556
+ * @param subformPath Path to check
557
+ * @param callback Result callback
558
+ */
559
+ static void hasSubformAsync(
560
+ const std::string& handleId,
561
+ const std::string& subformPath,
562
+ std::function<void(const std::string&, const std::string&)> callback
563
+ );
564
+
565
+ /**
566
+ * Dispose instance
567
+ * @param handle Instance handle
568
+ */
569
+ static void dispose(const std::string& handle);
570
+
571
+ /**
572
+ * Get library version
573
+ * @return Version string
574
+ */
575
+ static std::string version();
576
+
577
+ private:
578
+ // Helper to run async operations
579
+ template<typename Func>
580
+ static void runAsync(Func&& func, std::function<void(const std::string&, const std::string&)> callback);
581
+ };
582
+
583
+ } // namespace jsoneval
@@ -0,0 +1,5 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface JsonEvalRs : NSObject <RCTBridgeModule>
4
+
5
+ @end