fast-publicodes 0.0.0 → 1.0.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 +26 -0
- package/README.md +83 -0
- package/dist/api.d.ts +11 -0
- package/dist/api.js +17 -0
- package/dist/binding.d.ts +28 -0
- package/dist/binding.js +27 -0
- package/dist/engine.d.ts +37 -0
- package/dist/engine.js +222 -0
- package/dist/error.d.ts +39 -0
- package/dist/error.js +45 -0
- package/dist/evaluation.d.ts +5 -0
- package/dist/evaluation.js +28 -0
- package/dist/format.d.ts +14 -0
- package/dist/format.js +65 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -0
- package/dist/options.d.ts +22 -0
- package/dist/options.js +58 -0
- package/dist/ruleUtils.d.ts +19 -0
- package/dist/ruleUtils.js +78 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.js +1 -0
- package/dist/units.d.ts +10 -0
- package/dist/units.js +165 -0
- package/dist/web.d.ts +2 -0
- package/dist/web.js +6 -0
- package/native/fast-publicodes.darwin-arm64.node +0 -0
- package/native/fast-publicodes.darwin-x64.node +0 -0
- package/native/fast-publicodes.linux-arm64-gnu.node +0 -0
- package/native/fast-publicodes.linux-arm64-musl.node +0 -0
- package/native/fast-publicodes.linux-x64-gnu.node +0 -0
- package/native/fast-publicodes.linux-x64-musl.node +0 -0
- package/native/fast-publicodes.win32-x64-msvc.node +0 -0
- package/native/index.cjs +783 -0
- package/native/index.d.cts +64 -0
- package/package.json +65 -1
- package/wasm/fast_publicodes.d.ts +121 -0
- package/wasm/fast_publicodes.js +618 -0
- package/wasm/fast_publicodes_bg.wasm +0 -0
- package/wasm/fast_publicodes_bg.wasm.d.ts +23 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Which binding artifact the generated loader actually loaded: `'native'` for
|
|
6
|
+
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
|
|
7
|
+
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
|
|
8
|
+
* can point the loader at a WASI artifact this package does not build itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The engine, taking rules, options and situations as JSON.
|
|
14
|
+
*
|
|
15
|
+
* Calls report the warnings they raised as `warnings`: the text of a warning not sent before,
|
|
16
|
+
* which takes the next index in the table the caller keeps, or the index of one already sent.
|
|
17
|
+
* `warningsReset` asks the caller to empty its table first.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Engine {
|
|
20
|
+
/**
|
|
21
|
+
* `get_today` gives the date `durée` defaults to, as `dd/mm/yyyy`. Fails with the error as
|
|
22
|
+
* JSON `{ name, message, dottedName, warnings }`.
|
|
23
|
+
*/
|
|
24
|
+
constructor(rules: string, options: string, getToday: () => string, getUnitKey?: ((arg: string) => UnitKeyReturn) | undefined | null)
|
|
25
|
+
/**
|
|
26
|
+
* Returns `{ accepted }`, the names the situation gains, or `{ error, situationReset,
|
|
27
|
+
* accepted }`.
|
|
28
|
+
*/
|
|
29
|
+
setSituation(situation: string, keepPrevious: boolean, strict: boolean): object
|
|
30
|
+
/**
|
|
31
|
+
* Returns `{ nodeValue, index }`, `index` locating it in `evaluations`, with `unit` the index
|
|
32
|
+
* of its unit in the table the caller keeps, or `newUnit` when it is new and takes the next
|
|
33
|
+
* index, after `unitsReset` asks the caller to empty its table; or `{ error }`. `text` is
|
|
34
|
+
* JSON when `json`.
|
|
35
|
+
*/
|
|
36
|
+
evaluate(text: string, json: boolean): object
|
|
37
|
+
/**
|
|
38
|
+
* A handle on the expressions evaluated since the cache was last reset, for
|
|
39
|
+
* `missingVariables`.
|
|
40
|
+
*/
|
|
41
|
+
evaluations(): unknown
|
|
42
|
+
/** The missing variables of the evaluation at `index` in `evaluations`. */
|
|
43
|
+
missingVariables(evaluations: unknown, index: number): object
|
|
44
|
+
/** Returns the warnings raised by building the engine. */
|
|
45
|
+
takeWarnings(): object
|
|
46
|
+
inversionFail(): boolean
|
|
47
|
+
resetCache(): void
|
|
48
|
+
shallowCopy(copyCache: boolean): Engine
|
|
49
|
+
/** The names of the public rules, in definition order. */
|
|
50
|
+
ruleNames(): Array<string>
|
|
51
|
+
/** Returns `{ rule }`, the rule node as JSON, or `{ error }`. */
|
|
52
|
+
rule(name: string): object
|
|
53
|
+
/** Returns `{ possibilities }`, as JSON, or `{ error }`. */
|
|
54
|
+
applicablePossibilities(name: string): object
|
|
55
|
+
}
|
|
56
|
+
export type NativeEngine = Engine
|
|
57
|
+
|
|
58
|
+
/** `parseExpression`: returns `{ expression }`, as JSON, or `{ error }`. */
|
|
59
|
+
export declare function parseExpression(expression: string, dottedName: string): object
|
|
60
|
+
|
|
61
|
+
/** A thrown value: an `Error` and its message, or another value, which the caller keeps. */
|
|
62
|
+
export interface Thrown {
|
|
63
|
+
message?: string
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1,65 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "fast-publicodes",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A drop-in replacement for publicodes, with the engine written in Rust.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/troopay/fast-publicodes.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/troopay/fast-publicodes#readme",
|
|
11
|
+
"bugs": "https://github.com/troopay/fast-publicodes/issues",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"publicodes",
|
|
14
|
+
"rules",
|
|
15
|
+
"engine",
|
|
16
|
+
"rust",
|
|
17
|
+
"webassembly"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"node": "./dist/index.js",
|
|
26
|
+
"default": "./dist/web.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"native",
|
|
32
|
+
"wasm"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22"
|
|
36
|
+
},
|
|
37
|
+
"packageManager": "pnpm@10.33.0",
|
|
38
|
+
"napi": {
|
|
39
|
+
"binaryName": "fast-publicodes"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm build:native --release && pnpm build:wasm && pnpm build:ts",
|
|
43
|
+
"build:native": "napi build --platform --manifest-path crates/node/Cargo.toml --output-dir native --js index.cjs --dts index.d.cts",
|
|
44
|
+
"build:wasm": "cargo build -p fast-publicodes-wasm --target wasm32-unknown-unknown --profile wasm && wasm-bindgen --target web --out-dir wasm --out-name fast_publicodes target/wasm32-unknown-unknown/wasm/fast_publicodes_wasm.wasm",
|
|
45
|
+
"build:ts": "tsc -p tsconfig.build.json",
|
|
46
|
+
"lint": "cargo clippy --workspace --all-targets -- -D warnings && cargo fmt --check && biome check && tsc --noEmit",
|
|
47
|
+
"format": "cargo fmt && biome check --write",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:wasm": "FAST_PUBLICODES_TARGET=wasm vitest run",
|
|
50
|
+
"bench": "pnpm build:native --release && vitest bench --run --reporter=default"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@betagouv/aides-velo": "4.0.0",
|
|
54
|
+
"@biomejs/biome": "2.5.15",
|
|
55
|
+
"@incubateur-ademe/nosgestesclimat": "4.17.2",
|
|
56
|
+
"@napi-rs/cli": "3.10.8",
|
|
57
|
+
"@napi-rs/cross-toolchain": "1.0.3",
|
|
58
|
+
"@types/node": "22.20.5",
|
|
59
|
+
"modele-social": "11.1.0",
|
|
60
|
+
"publicodes": "1.10.4",
|
|
61
|
+
"typescript": "7.0.2",
|
|
62
|
+
"vitest": "5.0.3",
|
|
63
|
+
"yaml": "2.9.1"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The engine, taking rules, options and situations as JSON.
|
|
6
|
+
*
|
|
7
|
+
* Calls report the warnings they raised as `warnings`: the text of a warning not sent before,
|
|
8
|
+
* which takes the next index in the table the caller keeps, or the index of one already sent.
|
|
9
|
+
* `warningsReset` asks the caller to empty its table first.
|
|
10
|
+
*/
|
|
11
|
+
export class Engine {
|
|
12
|
+
free(): void;
|
|
13
|
+
[Symbol.dispose](): void;
|
|
14
|
+
/**
|
|
15
|
+
* Returns `{ possibilities }`, as JSON, or `{ error }`.
|
|
16
|
+
*/
|
|
17
|
+
applicablePossibilities(name: string): object;
|
|
18
|
+
/**
|
|
19
|
+
* Returns `{ nodeValue, index }`, `index` locating it in `evaluations`, with `unit` the index
|
|
20
|
+
* of its unit in the table the caller keeps, or `newUnit` when it is new and takes the next
|
|
21
|
+
* index, after `unitsReset` asks the caller to empty its table; or `{ error }`. `text` is
|
|
22
|
+
* JSON when `json`.
|
|
23
|
+
*/
|
|
24
|
+
evaluate(text: string, json: boolean): object;
|
|
25
|
+
/**
|
|
26
|
+
* A handle on the expressions evaluated since the cache was last reset, for
|
|
27
|
+
* `missingVariables`.
|
|
28
|
+
*/
|
|
29
|
+
evaluations(): EvaluationsHandle;
|
|
30
|
+
inversionFail(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The missing variables of the evaluation at `index` in `evaluations`.
|
|
33
|
+
*/
|
|
34
|
+
missingVariables(evaluations: EvaluationsHandle, index: number): object;
|
|
35
|
+
/**
|
|
36
|
+
* `get_today` gives the date `durée` defaults to, as `dd/mm/yyyy`. Fails with the error as
|
|
37
|
+
* JSON `{ name, message, dottedName, warnings }`.
|
|
38
|
+
*/
|
|
39
|
+
constructor(rules: string, options: string, get_today: Function, get_unit_key?: Function | null);
|
|
40
|
+
resetCache(): void;
|
|
41
|
+
/**
|
|
42
|
+
* The names of the public rules, in definition order.
|
|
43
|
+
*/
|
|
44
|
+
ruleNames(): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Returns `{ rule }`, the rule node as JSON, or `{ error }`.
|
|
47
|
+
*/
|
|
48
|
+
rule(name: string): object;
|
|
49
|
+
/**
|
|
50
|
+
* Returns `{ accepted }`, the names the situation gains, or `{ error, situationReset,
|
|
51
|
+
* accepted }`.
|
|
52
|
+
*/
|
|
53
|
+
setSituation(situation: string, keep_previous: boolean, strict: boolean): object;
|
|
54
|
+
shallowCopy(copy_cache: boolean): Engine;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the warnings raised by building the engine.
|
|
57
|
+
*/
|
|
58
|
+
takeWarnings(): object;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The expressions evaluated since the cache was last reset, for `missingVariables`.
|
|
63
|
+
*/
|
|
64
|
+
export class EvaluationsHandle {
|
|
65
|
+
private constructor();
|
|
66
|
+
free(): void;
|
|
67
|
+
[Symbol.dispose](): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `parseExpression`: returns `{ expression }`, as JSON, or `{ error }`.
|
|
72
|
+
*/
|
|
73
|
+
export function parseExpression(expression: string, dotted_name: string): object;
|
|
74
|
+
|
|
75
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
76
|
+
|
|
77
|
+
export interface InitOutput {
|
|
78
|
+
readonly memory: WebAssembly.Memory;
|
|
79
|
+
readonly __wbg_engine_free: (a: number, b: number) => void;
|
|
80
|
+
readonly __wbg_evaluationshandle_free: (a: number, b: number) => void;
|
|
81
|
+
readonly engine_applicablePossibilities: (a: number, b: number, c: number) => number;
|
|
82
|
+
readonly engine_evaluate: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
83
|
+
readonly engine_evaluations: (a: number) => number;
|
|
84
|
+
readonly engine_inversionFail: (a: number) => number;
|
|
85
|
+
readonly engine_missingVariables: (a: number, b: number, c: number) => number;
|
|
86
|
+
readonly engine_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
87
|
+
readonly engine_resetCache: (a: number) => void;
|
|
88
|
+
readonly engine_rule: (a: number, b: number, c: number) => number;
|
|
89
|
+
readonly engine_ruleNames: (a: number, b: number) => void;
|
|
90
|
+
readonly engine_setSituation: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
91
|
+
readonly engine_shallowCopy: (a: number, b: number) => number;
|
|
92
|
+
readonly engine_takeWarnings: (a: number) => number;
|
|
93
|
+
readonly parseExpression: (a: number, b: number, c: number, d: number) => number;
|
|
94
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
95
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
96
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
97
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
98
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
105
|
+
* a precompiled `WebAssembly.Module`.
|
|
106
|
+
*
|
|
107
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
108
|
+
*
|
|
109
|
+
* @returns {InitOutput}
|
|
110
|
+
*/
|
|
111
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
115
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
116
|
+
*
|
|
117
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
118
|
+
*
|
|
119
|
+
* @returns {Promise<InitOutput>}
|
|
120
|
+
*/
|
|
121
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|