tranfi 0.0.2 → 0.2.0

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 (151) hide show
  1. package/LICENSE +177 -21
  2. package/NOTICE +8 -0
  3. package/README.md +627 -0
  4. package/app/assets/index-6quYZ5Ap.css +5 -0
  5. package/app/assets/index-BIAIKnrp.js +160 -0
  6. package/app/assets/materialdesignicons-webfont-B7mPwVP_.ttf +0 -0
  7. package/app/assets/materialdesignicons-webfont-CSr8KVlo.eot +0 -0
  8. package/app/assets/materialdesignicons-webfont-Dp5v-WZN.woff2 +0 -0
  9. package/app/assets/materialdesignicons-webfont-PXm3-2wK.woff +0 -0
  10. package/app/index.html +13 -0
  11. package/binding.gyp +121 -0
  12. package/csrc/arena.c +93 -0
  13. package/csrc/batch.c +976 -0
  14. package/csrc/buffer.c +154 -0
  15. package/csrc/cJSON.c +3386 -0
  16. package/csrc/cJSON.h +316 -0
  17. package/csrc/codec_csv.c +1951 -0
  18. package/csrc/codec_jsonl.c +1086 -0
  19. package/csrc/codec_table.c +248 -0
  20. package/csrc/codec_text.c +447 -0
  21. package/csrc/compiler.c +130 -0
  22. package/csrc/config.h +21 -0
  23. package/csrc/date_utils.h +94 -0
  24. package/csrc/dsl.c +5417 -0
  25. package/csrc/dsl.h +22 -0
  26. package/csrc/expr.c +1553 -0
  27. package/csrc/expr.h +58 -0
  28. package/csrc/internal.h +539 -0
  29. package/csrc/ir.c +166 -0
  30. package/csrc/ir.h +208 -0
  31. package/csrc/ir_schema.c +75 -0
  32. package/csrc/ir_serialize.c +166 -0
  33. package/csrc/ir_sql.c +1822 -0
  34. package/csrc/ir_validate.c +576 -0
  35. package/csrc/json_path.c +210 -0
  36. package/csrc/main.c +1241 -0
  37. package/csrc/memory_estimate.c +477 -0
  38. package/csrc/op_acf.c +283 -0
  39. package/csrc/op_across.c +477 -0
  40. package/csrc/op_anomaly.c +255 -0
  41. package/csrc/op_assert.c +761 -0
  42. package/csrc/op_bin.c +248 -0
  43. package/csrc/op_cast.c +523 -0
  44. package/csrc/op_clip.c +99 -0
  45. package/csrc/op_date_trunc.c +355 -0
  46. package/csrc/op_datetime.c +394 -0
  47. package/csrc/op_derive.c +216 -0
  48. package/csrc/op_diff.c +250 -0
  49. package/csrc/op_ewma.c +222 -0
  50. package/csrc/op_explode.c +206 -0
  51. package/csrc/op_fill_down.c +235 -0
  52. package/csrc/op_fill_null.c +268 -0
  53. package/csrc/op_filter.c +181 -0
  54. package/csrc/op_frequency.c +721 -0
  55. package/csrc/op_grep.c +181 -0
  56. package/csrc/op_group_agg.c +1956 -0
  57. package/csrc/op_hash.c +159 -0
  58. package/csrc/op_head.c +84 -0
  59. package/csrc/op_interpolate.c +445 -0
  60. package/csrc/op_join.c +2902 -0
  61. package/csrc/op_json_extract.c +227 -0
  62. package/csrc/op_json_filter.c +384 -0
  63. package/csrc/op_json_flatten.c +293 -0
  64. package/csrc/op_json_schema.c +503 -0
  65. package/csrc/op_label_encode.c +419 -0
  66. package/csrc/op_lag.c +181 -0
  67. package/csrc/op_lead.c +242 -0
  68. package/csrc/op_normalize.c +510 -0
  69. package/csrc/op_onehot.c +457 -0
  70. package/csrc/op_pivot.c +1754 -0
  71. package/csrc/op_quarantine.c +189 -0
  72. package/csrc/op_registry.c +3044 -0
  73. package/csrc/op_rename.c +129 -0
  74. package/csrc/op_replace.c +354 -0
  75. package/csrc/op_rleid.c +297 -0
  76. package/csrc/op_rowid.c +559 -0
  77. package/csrc/op_sample.c +158 -0
  78. package/csrc/op_schema.c +1341 -0
  79. package/csrc/op_schema_infer.c +252 -0
  80. package/csrc/op_select.c +340 -0
  81. package/csrc/op_set.c +3449 -0
  82. package/csrc/op_skip.c +95 -0
  83. package/csrc/op_sort.c +819 -0
  84. package/csrc/op_source_name.c +120 -0
  85. package/csrc/op_split.c +151 -0
  86. package/csrc/op_split_data.c +119 -0
  87. package/csrc/op_stack.c +271 -0
  88. package/csrc/op_stats.c +875 -0
  89. package/csrc/op_step.c +333 -0
  90. package/csrc/op_tail.c +105 -0
  91. package/csrc/op_tee.c +338 -0
  92. package/csrc/op_top.c +357 -0
  93. package/csrc/op_trim.c +138 -0
  94. package/csrc/op_unique.c +1343 -0
  95. package/csrc/op_unpivot.c +193 -0
  96. package/csrc/op_validate.c +648 -0
  97. package/csrc/op_window.c +591 -0
  98. package/csrc/path_policy.c +85 -0
  99. package/csrc/pipeline.c +1088 -0
  100. package/csrc/recipes.c +104 -0
  101. package/csrc/recipes.h +27 -0
  102. package/csrc/report.c +506 -0
  103. package/csrc/report.h +22 -0
  104. package/csrc/selector.c +1097 -0
  105. package/csrc/size_utils.c +348 -0
  106. package/csrc/spill.c +317 -0
  107. package/csrc/spill.h +21 -0
  108. package/csrc/tranfi.h +291 -0
  109. package/csrc/transform.h +209 -0
  110. package/csrc/transform_api.c +2237 -0
  111. package/csrc/transform_categorical.c +923 -0
  112. package/csrc/transform_internal.h +472 -0
  113. package/csrc/transform_json.c +3812 -0
  114. package/csrc/transform_numeric.c +1966 -0
  115. package/csrc/transform_sha256.c +154 -0
  116. package/csrc/transform_wasm.h +162 -0
  117. package/csrc/transform_wasm_api.c +1373 -0
  118. package/csrc/wasm_api.c +218 -0
  119. package/napi_api.c +534 -0
  120. package/napi_transform.c +1648 -0
  121. package/napi_transform.h +8 -0
  122. package/package.json +64 -59
  123. package/scripts/install-native.js +76 -0
  124. package/scripts/prepack.js +64 -0
  125. package/scripts/sync-csrc.js +23 -0
  126. package/src/cli.js +190 -0
  127. package/src/engines/duckdb.js +142 -0
  128. package/src/index.js +925 -0
  129. package/src/memory_policy.js +411 -0
  130. package/src/native.js +18 -0
  131. package/src/pipeline.js +709 -0
  132. package/src/recipe_json.js +80 -0
  133. package/src/server.js +279 -0
  134. package/src/transform.js +403 -0
  135. package/src/transform_error.js +10 -0
  136. package/src/wasm.js +21 -0
  137. package/wasm/index.js +732 -0
  138. package/wasm/package.json +1 -0
  139. package/wasm/tranfi_core.js +0 -0
  140. package/wasm/transform.js +1156 -0
  141. package/wasm/worker.js +786 -0
  142. package/dist/bundle.js +0 -1
  143. package/index.html +0 -18
  144. package/src/app.css +0 -169
  145. package/src/app.js +0 -203
  146. package/src/app.vue +0 -250
  147. package/src/bulma-input.vue +0 -110
  148. package/src/common-inputs.js +0 -28
  149. package/src/main.js +0 -20
  150. package/src/transforms.js +0 -166
  151. package/webpack.config.js +0 -108
@@ -0,0 +1,218 @@
1
+ /*
2
+ * wasm_api.c — Emscripten WASM exports for Tranfi.
3
+ *
4
+ * Handle-based API: JS gets integer handles instead of raw pointers.
5
+ * Same pattern as statsim/compiler.
6
+ */
7
+
8
+ #ifdef __EMSCRIPTEN__
9
+ #include <emscripten.h>
10
+ #endif
11
+
12
+ #include "tranfi.h"
13
+ #include "internal.h"
14
+ #include "dsl.h"
15
+ #include "recipes.h"
16
+ #include <stdlib.h>
17
+ #include <string.h>
18
+
19
+ /* Handle map: slot index → tf_pipeline* */
20
+ #define MAX_HANDLES 256
21
+ static tf_pipeline *handles[MAX_HANDLES] = {0};
22
+
23
+ static int alloc_handle(tf_pipeline *p) {
24
+ for (int i = 1; i < MAX_HANDLES; i++) {
25
+ if (!handles[i]) {
26
+ handles[i] = p;
27
+ return i;
28
+ }
29
+ }
30
+ return -1; /* no free slots */
31
+ }
32
+
33
+ static tf_pipeline *get_handle(int h) {
34
+ if (h <= 0 || h >= MAX_HANDLES) return NULL;
35
+ return handles[h];
36
+ }
37
+
38
+ static int wasm_validate_buffer(const void *ptr, int len, const char *what) {
39
+ if (len < 0) {
40
+ tf_set_last_error(what ? what : "invalid WASM buffer length");
41
+ return 0;
42
+ }
43
+ if (len > 0 && !ptr) {
44
+ tf_set_last_error(what ? what : "invalid WASM buffer pointer");
45
+ return 0;
46
+ }
47
+ return 1;
48
+ }
49
+
50
+ #ifdef __EMSCRIPTEN__
51
+ #define EXPORT EMSCRIPTEN_KEEPALIVE
52
+ #else
53
+ #define EXPORT
54
+ #endif
55
+
56
+ static int wasm_pipeline_create_policy(const char *json, int len,
57
+ int allow_fs, int allow_spill,
58
+ int allow_rules_file, const char *workspace_root) {
59
+ if (!wasm_validate_buffer(json, len, "invalid WASM plan buffer")) return -1;
60
+ tf_host_policy policy = {0};
61
+ policy.allow_fs = allow_fs != 0;
62
+ policy.allow_spill = allow_spill != 0;
63
+ policy.allow_rules_file = allow_rules_file != 0;
64
+ policy.allow_blocking = true;
65
+ policy.workspace_root = workspace_root && workspace_root[0] ? workspace_root : NULL;
66
+ tf_pipeline *p = tf_pipeline_create_with_host_policy(json, (size_t)len, &policy);
67
+ if (!p) return -1;
68
+ int h = alloc_handle(p);
69
+ if (h < 0) {
70
+ tf_pipeline_free(p);
71
+ return -1;
72
+ }
73
+ return h;
74
+ }
75
+
76
+ EXPORT
77
+ int wasm_pipeline_create(const char *json, int len) {
78
+ return wasm_pipeline_create_policy(json, len, 0, 0, 0, NULL);
79
+ }
80
+
81
+ EXPORT
82
+ int wasm_pipeline_create_with_policy(const char *json, int len, int allow_fs,
83
+ int allow_spill, int allow_rules_file,
84
+ const char *workspace_root) {
85
+ return wasm_pipeline_create_policy(json, len, allow_fs, allow_spill,
86
+ allow_rules_file, workspace_root);
87
+ }
88
+
89
+ EXPORT
90
+ int wasm_pipeline_push(int handle, const uint8_t *data, int len) {
91
+ tf_pipeline *p = get_handle(handle);
92
+ if (!p) return -1;
93
+ if (!wasm_validate_buffer(data, len, "invalid WASM input buffer")) return -1;
94
+ return tf_pipeline_push(p, data, (size_t)len);
95
+ }
96
+
97
+ EXPORT
98
+ int wasm_pipeline_flush_input(int handle) {
99
+ tf_pipeline *p = get_handle(handle);
100
+ if (!p) return -1;
101
+ return tf_pipeline_flush_input(p);
102
+ }
103
+
104
+ EXPORT
105
+ int wasm_pipeline_set_source_name(int handle, const char *name) {
106
+ tf_pipeline *p = get_handle(handle);
107
+ if (!p) return -1;
108
+ return tf_pipeline_set_source_name(p, name);
109
+ }
110
+
111
+ EXPORT
112
+ int wasm_pipeline_finish(int handle) {
113
+ tf_pipeline *p = get_handle(handle);
114
+ if (!p) return -1;
115
+ return tf_pipeline_finish(p);
116
+ }
117
+
118
+ EXPORT
119
+ int wasm_pipeline_finish_step(int handle) {
120
+ tf_pipeline *p = get_handle(handle);
121
+ if (!p) return -1;
122
+ return tf_pipeline_finish_step(p);
123
+ }
124
+
125
+ EXPORT
126
+ int wasm_pipeline_pull(int handle, int channel, uint8_t *buf, int buf_len) {
127
+ tf_pipeline *p = get_handle(handle);
128
+ if (!p) return 0;
129
+ if (!wasm_validate_buffer(buf, buf_len, "invalid WASM output buffer")) return -1;
130
+ return (int)tf_pipeline_pull(p, channel, buf, (size_t)buf_len);
131
+ }
132
+
133
+ EXPORT
134
+ const char *wasm_pipeline_error(int handle) {
135
+ tf_pipeline *p = get_handle(handle);
136
+ if (!p) return tf_last_error();
137
+ const char *err = tf_pipeline_error(p);
138
+ return err ? err : tf_last_error();
139
+ }
140
+
141
+ EXPORT
142
+ void wasm_pipeline_free(int handle) {
143
+ tf_pipeline *p = get_handle(handle);
144
+ if (p) {
145
+ tf_pipeline_free(p);
146
+ handles[handle] = NULL;
147
+ }
148
+ }
149
+
150
+ /*
151
+ * wasm_compile_dsl — parse DSL string, return plan JSON.
152
+ *
153
+ * Returns heap-allocated JSON string (caller must free), or NULL on error.
154
+ * On error, wasm_pipeline_error(-1) returns the message.
155
+ */
156
+ EXPORT
157
+ char *wasm_compile_dsl(const char *dsl, int len) {
158
+ if (!wasm_validate_buffer(dsl, len, "invalid WASM DSL buffer")) return NULL;
159
+ char *error = NULL;
160
+ char *json = tf_compile_dsl(dsl, (size_t)len, &error);
161
+ if (!json) {
162
+ tf_set_last_error(error ? error : "DSL compile failed");
163
+ free(error);
164
+ return NULL;
165
+ }
166
+ return json;
167
+ }
168
+
169
+ /*
170
+ * wasm_compile_to_sql — compile DSL to SQL query string.
171
+ *
172
+ * Returns heap-allocated SQL string (caller must free), or NULL on error.
173
+ */
174
+ EXPORT
175
+ char *wasm_compile_to_sql(const char *dsl, int len) {
176
+ if (!wasm_validate_buffer(dsl, len, "invalid WASM DSL buffer")) return NULL;
177
+ char *error = NULL;
178
+ char *sql = tf_compile_to_sql(dsl, (size_t)len, &error);
179
+ if (!sql) {
180
+ tf_set_last_error(error ? error : "SQL compile failed");
181
+ free(error);
182
+ return NULL;
183
+ }
184
+ free(error);
185
+ return sql;
186
+ }
187
+
188
+ EXPORT
189
+ const char *wasm_version(void) {
190
+ return tf_version();
191
+ }
192
+
193
+ /* ---- Recipe API ---- */
194
+
195
+ EXPORT
196
+ int wasm_recipe_count(void) {
197
+ return (int)tf_recipe_count();
198
+ }
199
+
200
+ EXPORT
201
+ const char *wasm_recipe_name(int index) {
202
+ return tf_recipe_name((size_t)index);
203
+ }
204
+
205
+ EXPORT
206
+ const char *wasm_recipe_dsl(int index) {
207
+ return tf_recipe_dsl((size_t)index);
208
+ }
209
+
210
+ EXPORT
211
+ const char *wasm_recipe_description(int index) {
212
+ return tf_recipe_description((size_t)index);
213
+ }
214
+
215
+ EXPORT
216
+ const char *wasm_recipe_find_dsl(const char *name) {
217
+ return tf_recipe_find_dsl(name);
218
+ }