@uruhalushia/rule-converter-wasm 0.2.0 → 0.3.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/README.md CHANGED
@@ -145,6 +145,15 @@ const geositeRules = bufToStr(geositeDatBytes, {
145
145
  })
146
146
  ```
147
147
 
148
+ Use `detectBuf` / `detectStr` to inspect uploaded input without converting it:
149
+
150
+ ```js
151
+ import init, { detectBuf } from '@uruhalushia/rule-converter-wasm'
152
+
153
+ await init()
154
+ console.log(detectBuf(new Uint8Array(await file.arrayBuffer())))
155
+ ```
156
+
148
157
 
149
158
  Rule matching uses the same input options as conversion. Mihomo config input is supported when providers use local `path`/`file://` references supplied by the host application; browser HTTP provider downloads should be handled by the caller before matching:
150
159
 
@@ -164,8 +173,8 @@ Options use the same names as the N-API package:
164
173
 
165
174
  ```ts
166
175
  type RuleTarget = 'mihomo' | 'general' | 'egern' | 'sing-box'
167
- type InputFormat = 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat'
168
- type OutputFormat = 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat'
176
+ type InputFormat = 'yaml' | 'mrs' | 'text' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
177
+ type OutputFormat = 'mrs' | 'text' | 'yaml' | 'json' | 'srs' | 'domainset' | 'ruleset' | 'ipset' | 'mmdb' | 'sing-db' | 'metadb' | 'dat' | 'sing-geosite'
169
178
  type InputBehavior = 'auto' | 'domain' | 'ip' | 'classical'
170
179
  type OutputBehavior = 'domain' | 'ip' | 'classical'
171
180
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uruhalushia/rule-converter-wasm",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "files": [
6
6
  "rule_converter_wasm_bg.wasm",
7
7
  "rule_converter_wasm.js",
@@ -5,6 +5,12 @@ export function bufToBuf(payload: Uint8Array, options: any): any;
5
5
 
6
6
  export function bufToStr(payload: Uint8Array, options: any): any;
7
7
 
8
+ export function buildDb(options: any): any;
9
+
10
+ export function detectBuf(input: Uint8Array): any;
11
+
12
+ export function detectStr(input: string): any;
13
+
8
14
  export function listAsnNumbers(payload: Uint8Array): any;
9
15
 
10
16
  export function listGeoipCountries(payload: Uint8Array): any;
@@ -13,6 +19,8 @@ export function listGeoipDatCountries(payload: Uint8Array): any;
13
19
 
14
20
  export function listGeositeCodes(payload: Uint8Array): any;
15
21
 
22
+ export function listIndexes(payload: Uint8Array): any;
23
+
16
24
  export function matchBuf(payload: Uint8Array, query: string, options: any): any;
17
25
 
18
26
  export function matchStr(payload: string, query: string, options: any): any;
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./rule_converter_wasm_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
 
7
7
  export {
8
- bufToBuf, bufToStr, listAsnNumbers, listGeoipCountries, listGeoipDatCountries, listGeositeCodes, matchBuf, matchStr, strToBuf, strToStr
8
+ bufToBuf, bufToStr, buildDb, detectBuf, detectStr, listAsnNumbers, listGeoipCountries, listGeoipDatCountries, listGeositeCodes, listIndexes, matchBuf, matchStr, strToBuf, strToStr
9
9
  } from "./rule_converter_wasm_bg.js";
@@ -44,6 +44,70 @@ export function bufToStr(payload, options) {
44
44
  }
45
45
  }
46
46
 
47
+ /**
48
+ * @param {any} options
49
+ * @returns {any}
50
+ */
51
+ export function buildDb(options) {
52
+ try {
53
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
54
+ wasm.buildDb(retptr, addHeapObject(options));
55
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
56
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
57
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
58
+ if (r2) {
59
+ throw takeObject(r1);
60
+ }
61
+ return takeObject(r0);
62
+ } finally {
63
+ wasm.__wbindgen_add_to_stack_pointer(16);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * @param {Uint8Array} input
69
+ * @returns {any}
70
+ */
71
+ export function detectBuf(input) {
72
+ try {
73
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
74
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
75
+ const len0 = WASM_VECTOR_LEN;
76
+ wasm.detectBuf(retptr, ptr0, len0);
77
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
78
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
79
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
80
+ if (r2) {
81
+ throw takeObject(r1);
82
+ }
83
+ return takeObject(r0);
84
+ } finally {
85
+ wasm.__wbindgen_add_to_stack_pointer(16);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @param {string} input
91
+ * @returns {any}
92
+ */
93
+ export function detectStr(input) {
94
+ try {
95
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
96
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
97
+ const len0 = WASM_VECTOR_LEN;
98
+ wasm.detectStr(retptr, ptr0, len0);
99
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
100
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
101
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
102
+ if (r2) {
103
+ throw takeObject(r1);
104
+ }
105
+ return takeObject(r0);
106
+ } finally {
107
+ wasm.__wbindgen_add_to_stack_pointer(16);
108
+ }
109
+ }
110
+
47
111
  /**
48
112
  * @param {Uint8Array} payload
49
113
  * @returns {any}
@@ -132,6 +196,28 @@ export function listGeositeCodes(payload) {
132
196
  }
133
197
  }
134
198
 
199
+ /**
200
+ * @param {Uint8Array} payload
201
+ * @returns {any}
202
+ */
203
+ export function listIndexes(payload) {
204
+ try {
205
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
206
+ const ptr0 = passArray8ToWasm0(payload, wasm.__wbindgen_export);
207
+ const len0 = WASM_VECTOR_LEN;
208
+ wasm.listIndexes(retptr, ptr0, len0);
209
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
210
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
211
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
212
+ if (r2) {
213
+ throw takeObject(r1);
214
+ }
215
+ return takeObject(r0);
216
+ } finally {
217
+ wasm.__wbindgen_add_to_stack_pointer(16);
218
+ }
219
+ }
220
+
135
221
  /**
136
222
  * @param {Uint8Array} payload
137
223
  * @param {string} query
Binary file