tranfi 0.1.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.
- package/LICENSE +177 -0
- package/NOTICE +8 -0
- package/README.md +272 -40
- package/app/assets/{index-pDFMluyz.js → index-BIAIKnrp.js} +1 -1
- package/app/index.html +1 -1
- package/binding.gyp +55 -3
- package/csrc/arena.c +7 -5
- package/csrc/batch.c +818 -71
- package/csrc/buffer.c +84 -8
- package/csrc/cJSON.c +262 -19
- package/csrc/cJSON.h +17 -1
- package/csrc/codec_csv.c +1074 -181
- package/csrc/codec_jsonl.c +830 -118
- package/csrc/codec_table.c +108 -78
- package/csrc/codec_text.c +286 -68
- package/csrc/compiler.c +31 -3
- package/csrc/config.h +21 -0
- package/csrc/dsl.c +4722 -485
- package/csrc/expr.c +363 -55
- package/csrc/expr.h +2 -0
- package/csrc/internal.h +316 -27
- package/csrc/ir.c +65 -18
- package/csrc/ir.h +41 -0
- package/csrc/ir_schema.c +20 -5
- package/csrc/ir_serialize.c +68 -6
- package/csrc/ir_sql.c +796 -185
- package/csrc/ir_validate.c +462 -6
- package/csrc/json_path.c +210 -0
- package/csrc/main.c +879 -30
- package/csrc/memory_estimate.c +477 -0
- package/csrc/op_acf.c +171 -21
- package/csrc/op_across.c +477 -0
- package/csrc/op_anomaly.c +167 -32
- package/csrc/op_assert.c +761 -0
- package/csrc/op_bin.c +168 -29
- package/csrc/op_cast.c +383 -55
- package/csrc/op_clip.c +30 -19
- package/csrc/op_date_trunc.c +208 -34
- package/csrc/op_datetime.c +259 -77
- package/csrc/op_derive.c +65 -97
- package/csrc/op_diff.c +146 -30
- package/csrc/op_ewma.c +149 -30
- package/csrc/op_explode.c +124 -26
- package/csrc/op_fill_down.c +125 -53
- package/csrc/op_fill_null.c +176 -31
- package/csrc/op_filter.c +89 -40
- package/csrc/op_frequency.c +571 -43
- package/csrc/op_grep.c +36 -18
- package/csrc/op_group_agg.c +1790 -119
- package/csrc/op_hash.c +48 -15
- package/csrc/op_head.c +21 -86
- package/csrc/op_interpolate.c +268 -62
- package/csrc/op_join.c +2700 -182
- package/csrc/op_json_extract.c +227 -0
- package/csrc/op_json_filter.c +384 -0
- package/csrc/op_json_flatten.c +293 -0
- package/csrc/op_json_schema.c +503 -0
- package/csrc/op_label_encode.c +328 -53
- package/csrc/op_lag.c +181 -0
- package/csrc/op_lead.c +141 -89
- package/csrc/op_normalize.c +363 -79
- package/csrc/op_onehot.c +345 -73
- package/csrc/op_pivot.c +1546 -162
- package/csrc/op_quarantine.c +189 -0
- package/csrc/op_registry.c +2062 -166
- package/csrc/op_rename.c +41 -50
- package/csrc/op_replace.c +270 -118
- package/csrc/op_rleid.c +297 -0
- package/csrc/op_rowid.c +559 -0
- package/csrc/op_sample.c +80 -23
- package/csrc/op_schema.c +1341 -0
- package/csrc/op_schema_infer.c +252 -0
- package/csrc/op_select.c +265 -65
- package/csrc/op_set.c +3449 -0
- package/csrc/op_skip.c +30 -87
- package/csrc/op_sort.c +670 -124
- package/csrc/op_source_name.c +120 -0
- package/csrc/op_split.c +65 -28
- package/csrc/op_split_data.c +41 -9
- package/csrc/op_stack.c +178 -222
- package/csrc/op_stats.c +206 -110
- package/csrc/op_step.c +217 -55
- package/csrc/op_tail.c +21 -12
- package/csrc/op_tee.c +338 -0
- package/csrc/op_top.c +260 -53
- package/csrc/op_trim.c +48 -19
- package/csrc/op_unique.c +1193 -150
- package/csrc/op_unpivot.c +100 -66
- package/csrc/op_validate.c +601 -24
- package/csrc/op_window.c +492 -51
- package/csrc/path_policy.c +85 -0
- package/csrc/pipeline.c +872 -99
- package/csrc/recipes.c +3 -1
- package/csrc/report.c +73 -30
- package/csrc/selector.c +1097 -0
- package/csrc/size_utils.c +348 -0
- package/csrc/spill.c +317 -0
- package/csrc/spill.h +21 -0
- package/csrc/tranfi.h +169 -1
- package/csrc/transform.h +209 -0
- package/csrc/transform_api.c +2237 -0
- package/csrc/transform_categorical.c +923 -0
- package/csrc/transform_internal.h +472 -0
- package/csrc/transform_json.c +3812 -0
- package/csrc/transform_numeric.c +1966 -0
- package/csrc/transform_sha256.c +154 -0
- package/csrc/transform_wasm.h +162 -0
- package/csrc/transform_wasm_api.c +1373 -0
- package/csrc/wasm_api.c +70 -9
- package/napi_api.c +219 -11
- package/napi_transform.c +1648 -0
- package/napi_transform.h +8 -0
- package/package.json +27 -11
- package/scripts/install-native.js +76 -0
- package/scripts/prepack.js +64 -0
- package/scripts/sync-csrc.js +23 -0
- package/src/cli.js +8 -11
- package/src/engines/duckdb.js +45 -12
- package/src/index.js +661 -42
- package/src/memory_policy.js +411 -0
- package/src/native.js +1 -5
- package/src/pipeline.js +454 -31
- package/src/recipe_json.js +80 -0
- package/src/server.js +10 -8
- package/src/transform.js +403 -0
- package/src/transform_error.js +10 -0
- package/src/wasm.js +6 -4
- package/wasm/index.js +498 -10
- package/wasm/tranfi_core.js +0 -0
- package/wasm/transform.js +1156 -0
- package/wasm/worker.js +786 -0
- package/csrc/plan.c +0 -206
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* path_policy.c -- Internal helpers for host-policy-approved file paths.
|
|
3
|
+
*
|
|
4
|
+
* The public policy pass rewrites plan-owned file args to canonical paths.
|
|
5
|
+
* These helpers let operators reject later symlink/path swaps for those
|
|
6
|
+
* rewritten paths while preserving normal fopen() behavior for policy-neutral
|
|
7
|
+
* constructors and custom host resolvers.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "internal.h"
|
|
11
|
+
#include "cJSON.h"
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
|
|
16
|
+
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
|
17
|
+
#include <fcntl.h>
|
|
18
|
+
#include <sys/stat.h>
|
|
19
|
+
#include <unistd.h>
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
const char *tf_policy_validated_path_arg(const cJSON *args, const char *path_arg) {
|
|
23
|
+
if (!args || !path_arg) return NULL;
|
|
24
|
+
const char *hidden = NULL;
|
|
25
|
+
if (strcmp(path_arg, "file") == 0) {
|
|
26
|
+
hidden = TF_POLICY_VALIDATED_FILE_PATH_ARG;
|
|
27
|
+
} else if (strcmp(path_arg, "rules_file") == 0 || strcmp(path_arg, "rulesFile") == 0) {
|
|
28
|
+
hidden = TF_POLICY_VALIDATED_RULES_FILE_PATH_ARG;
|
|
29
|
+
}
|
|
30
|
+
if (!hidden) return NULL;
|
|
31
|
+
const cJSON *item = cJSON_GetObjectItemCaseSensitive((cJSON *)args, hidden);
|
|
32
|
+
return cJSON_IsString(item) && item->valuestring && item->valuestring[0]
|
|
33
|
+
? item->valuestring
|
|
34
|
+
: NULL;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
|
38
|
+
static int policy_fd_matches_validated_path(int fd, const char *path,
|
|
39
|
+
const char *validated_path) {
|
|
40
|
+
struct stat fd_stat;
|
|
41
|
+
struct stat path_stat;
|
|
42
|
+
if (fstat(fd, &fd_stat) != 0 || !S_ISREG(fd_stat.st_mode)) return TF_ERROR;
|
|
43
|
+
|
|
44
|
+
char *resolved = realpath(path, NULL);
|
|
45
|
+
if (!resolved) return TF_ERROR;
|
|
46
|
+
int same_path = strcmp(resolved, validated_path) == 0;
|
|
47
|
+
int stat_ok = stat(resolved, &path_stat) == 0;
|
|
48
|
+
free(resolved);
|
|
49
|
+
if (!same_path || !stat_ok) return TF_ERROR;
|
|
50
|
+
if (fd_stat.st_dev != path_stat.st_dev || fd_stat.st_ino != path_stat.st_ino) {
|
|
51
|
+
return TF_ERROR;
|
|
52
|
+
}
|
|
53
|
+
return TF_OK;
|
|
54
|
+
}
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
FILE *tf_policy_fopen_read(const char *path, const char *validated_path) {
|
|
58
|
+
if (!path || !path[0]) return NULL;
|
|
59
|
+
if (!validated_path || !validated_path[0]) return fopen(path, "rb");
|
|
60
|
+
|
|
61
|
+
#if defined(_WIN32) || defined(__EMSCRIPTEN__)
|
|
62
|
+
return fopen(path, "rb");
|
|
63
|
+
#else
|
|
64
|
+
int flags = O_RDONLY;
|
|
65
|
+
#ifdef O_CLOEXEC
|
|
66
|
+
flags |= O_CLOEXEC;
|
|
67
|
+
#endif
|
|
68
|
+
#ifdef O_NOFOLLOW
|
|
69
|
+
flags |= O_NOFOLLOW;
|
|
70
|
+
#endif
|
|
71
|
+
int fd = open(path, flags);
|
|
72
|
+
if (fd < 0) return NULL;
|
|
73
|
+
if (policy_fd_matches_validated_path(fd, path, validated_path) != TF_OK) {
|
|
74
|
+
close(fd);
|
|
75
|
+
tf_set_last_error("policy path changed before open");
|
|
76
|
+
return NULL;
|
|
77
|
+
}
|
|
78
|
+
FILE *f = fdopen(fd, "rb");
|
|
79
|
+
if (!f) {
|
|
80
|
+
close(fd);
|
|
81
|
+
return NULL;
|
|
82
|
+
}
|
|
83
|
+
return f;
|
|
84
|
+
#endif
|
|
85
|
+
}
|