Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.temp

/target
/Cargo.lock
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
napi = { version = "2.16", features = ["serde-json", "error_anyhow", "tokio_rt"] }
napi-derive = "2.16"
napi = { version = "3", features = ["serde-json", "error_anyhow", "tokio_rt"] }
napi-derive = "3"
tokio-util = { workspace = true, features = ["rt"] }
serde_json = { workspace = true }
zen-engine = { path = "../../core/engine" }
Expand Down
2 changes: 0 additions & 2 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import fs from 'fs/promises';

const decision = engine.createDecision(content);
const result = await decision.evaluate({ input: 15 });
engine.dispose();
})();
```

Expand All @@ -59,7 +58,6 @@ const loader = async (key: string) => fs.readFile(path.join(testDataRoot, key))(
const engine = new ZenEngine({ loader });

const result = await engine.evaluate('jdm_graph1.json', { input: 5 });
engine.dispose();
})();
```

Expand Down
121 changes: 65 additions & 56 deletions bindings/nodejs/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,76 @@
/* tslint:disable */
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare class ZenDecision {
constructor()
evaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
safeEvaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
validate(): void
}

/* auto-generated by NAPI-RS */
export declare class ZenDecisionContent {
constructor(content: Buffer | object)
toBuffer(): Buffer
}

export declare class ZenEngine {
constructor(options?: ZenEngineOptions | undefined | null)
evaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
createDecision(content: ZenDecisionContent | Buffer | object): ZenDecision
getDecision(key: string): Promise<ZenDecision>
safeEvaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
safeGetDecision(key: string): Promise<SafeResult<ZenDecision>>
}

export declare class ZenEngineHandlerRequest {
constructor()
get node(): DecisionNode
get input(): any
getField(path: string): unknown
getFieldRaw(path: string): unknown
}

export interface DecisionNode {
id: string
name: string
kind: string
config: any
}

export declare function evaluateExpression(expression: string, context?: any | undefined | null): Promise<any>

export declare function evaluateExpressionSync(expression: string, context?: any | undefined | null): any

export declare function evaluateUnaryExpression(expression: string, context: any): Promise<boolean>

export declare function evaluateUnaryExpressionSync(expression: string, context: any): boolean

export declare function overrideConfig(config: ZenConfig): void

export declare function renderTemplate(template: string, context: any): Promise<any>

export declare function renderTemplateSync(template: string, context: any): any

export interface ZenConfig {
nodesInContext?: boolean
functionTimeoutMillis?: number
}
export declare function overrideConfig(config: ZenConfig): void
export interface ZenEvaluateOptions {
maxDepth?: number
trace?: boolean | 'string' | 'reference' | 'referenceString'

export interface ZenEngineHandlerResponse {
output: any
traceData?: any
}

export interface ZenEngineOptions {
loader?: (key: string) => Promise<Buffer | ZenDecisionContent>
customHandler?: (request: ZenEngineHandlerRequest) => Promise<ZenEngineHandlerResponse>
}
export declare function evaluateExpressionSync(expression: string, context?: any | undefined | null): any
export declare function evaluateUnaryExpressionSync(expression: string, context: any): boolean
export declare function renderTemplateSync(template: string, context: any): any
export declare function evaluateExpression(expression: string, context?: any | undefined | null): Promise<any>
export declare function evaluateUnaryExpression(expression: string, context: any): Promise<boolean>
export declare function renderTemplate(template: string, context: any): Promise<any>

export interface ZenEngineResponse {
performance: string
result: any
trace?: Record<string, ZenEngineTrace>
}

export interface ZenEngineTrace {
id: string
name: string
Expand All @@ -31,48 +80,8 @@ export interface ZenEngineTrace {
traceData?: any
order: number
}
export interface ZenEngineResponse {
performance: string
result: any
trace?: Record<string, ZenEngineTrace>
}
export interface ZenEngineHandlerResponse {
output: any
traceData?: any
}
export interface DecisionNode {
id: string
name: string
kind: string
config: any
}
export declare class ZenDecisionContent {
constructor(content: Buffer | object)
toBuffer(): Buffer
}
export declare class ZenDecision {
constructor()
evaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
safeEvaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
validate(): void
}
export declare class ZenEngine {
constructor(options?: ZenEngineOptions | undefined | null)
evaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
createDecision(content: ZenDecisionContent | Buffer | object): ZenDecision
getDecision(key: string): Promise<ZenDecision>
safeEvaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
safeGetDecision(key: string): Promise<SafeResult<ZenDecision>>
/**
* Function used to dispose memory allocated for loaders
* In the future, it will likely be removed and made automatic
*/
dispose(): void
}
export declare class ZenEngineHandlerRequest {
input: any
node: DecisionNode
constructor()
getField(path: string): unknown
getFieldRaw(path: string): unknown

export interface ZenEvaluateOptions {
maxDepth?: number
trace?: boolean | 'string' | 'reference' | 'referenceString'
}
Loading
Loading