fast-publicodes 0.0.0 → 1.1.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.
@@ -0,0 +1,69 @@
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
+ /** `evaluate`, for `getRule(rule).suggestions[name]`. */
38
+ evaluateSuggestion(rule: string, name: string): object
39
+ /**
40
+ * A handle on the expressions evaluated since the cache was last reset, for
41
+ * `missingVariables`.
42
+ */
43
+ evaluations(): unknown
44
+ /** The missing variables of the evaluation at `index` in `evaluations`. */
45
+ missingVariables(evaluations: unknown, index: number): object
46
+ /** Returns the warnings raised by building the engine. */
47
+ takeWarnings(): object
48
+ inversionFail(): boolean
49
+ resetCache(): void
50
+ shallowCopy(copyCache: boolean): Engine
51
+ /** The names of the public rules, in definition order. */
52
+ ruleNames(): Array<string>
53
+ /**
54
+ * Returns `{ rule }`, the rule node with its inferred type and the names of its suggestions,
55
+ * as JSON, or `{ error }`.
56
+ */
57
+ rule(name: string): object
58
+ /** Returns `{ possibilities }`, as JSON, or `{ error }`. */
59
+ applicablePossibilities(name: string): object
60
+ }
61
+ export type NativeEngine = Engine
62
+
63
+ /** `parseExpression`: returns `{ expression }`, as JSON, or `{ error }`. */
64
+ export declare function parseExpression(expression: string, dottedName: string): object
65
+
66
+ /** A thrown value: an `Error` and its message, or another value, which the caller keeps. */
67
+ export interface Thrown {
68
+ message?: string
69
+ }
package/package.json CHANGED
@@ -1 +1,65 @@
1
- {"name":"fast-publicodes","version":"0.0.0","description":"Placeholder for fast-publicodes","license":"MIT"}
1
+ {
2
+ "name": "fast-publicodes",
3
+ "version": "1.1.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,127 @@
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
+ * `evaluate`, for `getRule(rule).suggestions[name]`.
20
+ */
21
+ evaluateSuggestion(rule: string, name: string): object;
22
+ /**
23
+ * Returns `{ nodeValue, index }`, `index` locating it in `evaluations`, with `unit` the index
24
+ * of its unit in the table the caller keeps, or `newUnit` when it is new and takes the next
25
+ * index, after `unitsReset` asks the caller to empty its table; or `{ error }`. `text` is
26
+ * JSON when `json`.
27
+ */
28
+ evaluate(text: string, json: boolean): object;
29
+ /**
30
+ * A handle on the expressions evaluated since the cache was last reset, for
31
+ * `missingVariables`.
32
+ */
33
+ evaluations(): EvaluationsHandle;
34
+ inversionFail(): boolean;
35
+ /**
36
+ * The missing variables of the evaluation at `index` in `evaluations`.
37
+ */
38
+ missingVariables(evaluations: EvaluationsHandle, index: number): object;
39
+ /**
40
+ * `get_today` gives the date `durée` defaults to, as `dd/mm/yyyy`. Fails with the error as
41
+ * JSON `{ name, message, dottedName, warnings }`.
42
+ */
43
+ constructor(rules: string, options: string, get_today: Function, get_unit_key?: Function | null);
44
+ resetCache(): void;
45
+ /**
46
+ * The names of the public rules, in definition order.
47
+ */
48
+ ruleNames(): string[];
49
+ /**
50
+ * Returns `{ rule }`, the rule node with its inferred type and the names of its suggestions,
51
+ * as JSON, or `{ error }`.
52
+ */
53
+ rule(name: string): object;
54
+ /**
55
+ * Returns `{ accepted }`, the names the situation gains, or `{ error, situationReset,
56
+ * accepted }`.
57
+ */
58
+ setSituation(situation: string, keep_previous: boolean, strict: boolean): object;
59
+ shallowCopy(copy_cache: boolean): Engine;
60
+ /**
61
+ * Returns the warnings raised by building the engine.
62
+ */
63
+ takeWarnings(): object;
64
+ }
65
+
66
+ /**
67
+ * The expressions evaluated since the cache was last reset, for `missingVariables`.
68
+ */
69
+ export class EvaluationsHandle {
70
+ private constructor();
71
+ free(): void;
72
+ [Symbol.dispose](): void;
73
+ }
74
+
75
+ /**
76
+ * `parseExpression`: returns `{ expression }`, as JSON, or `{ error }`.
77
+ */
78
+ export function parseExpression(expression: string, dotted_name: string): object;
79
+
80
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
81
+
82
+ export interface InitOutput {
83
+ readonly memory: WebAssembly.Memory;
84
+ readonly __wbg_engine_free: (a: number, b: number) => void;
85
+ readonly __wbg_evaluationshandle_free: (a: number, b: number) => void;
86
+ readonly engine_applicablePossibilities: (a: number, b: number, c: number) => number;
87
+ readonly engine_evaluate: (a: number, b: number, c: number, d: number, e: number) => void;
88
+ readonly engine_evaluateSuggestion: (a: number, b: number, c: number, d: number, e: number) => number;
89
+ readonly engine_evaluations: (a: number) => number;
90
+ readonly engine_inversionFail: (a: number) => number;
91
+ readonly engine_missingVariables: (a: number, b: number, c: number) => number;
92
+ readonly engine_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
93
+ readonly engine_resetCache: (a: number) => void;
94
+ readonly engine_rule: (a: number, b: number, c: number) => number;
95
+ readonly engine_ruleNames: (a: number, b: number) => void;
96
+ readonly engine_setSituation: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
97
+ readonly engine_shallowCopy: (a: number, b: number) => number;
98
+ readonly engine_takeWarnings: (a: number) => number;
99
+ readonly parseExpression: (a: number, b: number, c: number, d: number) => number;
100
+ readonly __wbindgen_export: (a: number, b: number) => number;
101
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
102
+ readonly __wbindgen_export3: (a: number) => void;
103
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
104
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
105
+ }
106
+
107
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
108
+
109
+ /**
110
+ * Instantiates the given `module`, which can either be bytes or
111
+ * a precompiled `WebAssembly.Module`.
112
+ *
113
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
114
+ *
115
+ * @returns {InitOutput}
116
+ */
117
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
118
+
119
+ /**
120
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
121
+ * for everything else, calls `WebAssembly.instantiate` directly.
122
+ *
123
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
124
+ *
125
+ * @returns {Promise<InitOutput>}
126
+ */
127
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;