@gorules/zen-engine 0.19.2 → 0.21.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.
Files changed (3) hide show
  1. package/index.d.ts +20 -0
  2. package/index.js +41 -11
  3. package/package.json +9 -9
package/index.d.ts CHANGED
@@ -3,6 +3,10 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
+ export interface ZenConfig {
7
+ nodesInContext?: boolean
8
+ }
9
+ export function overrideConfig(config: ZenConfig): void
6
10
  export interface ZenEvaluateOptions {
7
11
  maxDepth?: number
8
12
  trace?: boolean
@@ -47,6 +51,7 @@ export class ZenDecisionContent {
47
51
  export class ZenDecision {
48
52
  constructor()
49
53
  evaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
54
+ safeEvaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
50
55
  validate(): void
51
56
  }
52
57
  export class ZenEngine {
@@ -54,6 +59,8 @@ export class ZenEngine {
54
59
  evaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
55
60
  createDecision(content: ZenDecisionContent | Buffer | object): ZenDecision
56
61
  getDecision(key: string): Promise<ZenDecision>
62
+ safeEvaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
63
+ safeGetDecision(key: string): Promise<SafeResult<ZenDecision>>
57
64
  /**
58
65
  * Function used to dispose memory allocated for loaders
59
66
  * In the future, it will likely be removed and made automatic
@@ -67,3 +74,16 @@ export class ZenEngineHandlerRequest {
67
74
  getField(path: string): unknown
68
75
  getFieldRaw(path: string): unknown
69
76
  }
77
+
78
+ // Custom definitions
79
+ type SafeResultSuccess<T> = {
80
+ success: true;
81
+ data: T;
82
+ }
83
+
84
+ type SafeResultError = {
85
+ success: false;
86
+ error: any;
87
+ }
88
+
89
+ export type SafeResult<T> = SafeResultSuccess<T> | SafeResultError;
package/index.js CHANGED
@@ -224,17 +224,32 @@ switch (platform) {
224
224
  }
225
225
  break
226
226
  case 'arm':
227
- localFileExisted = existsSync(
228
- join(__dirname, 'zen-engine.linux-arm-gnueabihf.node')
229
- )
230
- try {
231
- if (localFileExisted) {
232
- nativeBinding = require('./zen-engine.linux-arm-gnueabihf.node')
233
- } else {
234
- nativeBinding = require('@gorules/zen-engine-linux-arm-gnueabihf')
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'zen-engine.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./zen-engine.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@gorules/zen-engine-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'zen-engine.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./zen-engine.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@gorules/zen-engine-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
235
252
  }
236
- } catch (e) {
237
- loadError = e
238
253
  }
239
254
  break
240
255
  case 'riscv64':
@@ -266,6 +281,20 @@ switch (platform) {
266
281
  }
267
282
  }
268
283
  break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'zen-engine.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./zen-engine.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('@gorules/zen-engine-linux-s390x-gnu')
293
+ }
294
+ } catch (e) {
295
+ loadError = e
296
+ }
297
+ break
269
298
  default:
270
299
  throw new Error(`Unsupported architecture on Linux: ${arch}`)
271
300
  }
@@ -281,8 +310,9 @@ if (!nativeBinding) {
281
310
  throw new Error(`Failed to load native binding`)
282
311
  }
283
312
 
284
- const { ZenDecisionContent, ZenDecision, ZenEngine, evaluateExpressionSync, evaluateUnaryExpressionSync, renderTemplateSync, evaluateExpression, evaluateUnaryExpression, renderTemplate, ZenEngineHandlerRequest } = nativeBinding
313
+ const { overrideConfig, ZenDecisionContent, ZenDecision, ZenEngine, evaluateExpressionSync, evaluateUnaryExpressionSync, renderTemplateSync, evaluateExpression, evaluateUnaryExpression, renderTemplate, ZenEngineHandlerRequest } = nativeBinding
285
314
 
315
+ module.exports.overrideConfig = overrideConfig
286
316
  module.exports.ZenDecisionContent = ZenDecisionContent
287
317
  module.exports.ZenDecision = ZenDecision
288
318
  module.exports.ZenEngine = ZenEngine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorules/zen-engine",
3
- "version": "0.19.2",
3
+ "version": "0.21.0",
4
4
  "main": "index.js",
5
5
  "types": "./index.d.ts",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@jest/globals": "^29.5.0",
51
- "@napi-rs/cli": "^2.14.8",
51
+ "@napi-rs/cli": "^2.18.1",
52
52
  "@types/express": "^4.17.17",
53
53
  "@types/node": "^18.15.0",
54
54
  "babel-jest": "^29.5.0",
@@ -71,7 +71,7 @@
71
71
  "url": "git+https://github.com/gorules/zen.git"
72
72
  },
73
73
  "scripts": {
74
- "build": "napi build --platform --release --js index.js --dts index.d.ts",
74
+ "build": "napi build --dts false --platform --release",
75
75
  "build:debug": "napi build --platform --js index.js --dts index.d.ts",
76
76
  "watch": "cargo watch --ignore '{index.js,index.d.ts}' -- npm run build:debug",
77
77
  "test": "jest",
@@ -79,12 +79,12 @@
79
79
  "prepublishOnly": "napi prepublish",
80
80
  "version": "napi version"
81
81
  },
82
- "gitHead": "71aebdbd2a2fe4de7f0052d42c18168fe86fba18",
82
+ "gitHead": "e0776ffa3e2d87010bf890947e3f4e3421241721",
83
83
  "optionalDependencies": {
84
- "@gorules/zen-engine-darwin-x64": "0.19.2",
85
- "@gorules/zen-engine-linux-x64-gnu": "0.19.2",
86
- "@gorules/zen-engine-win32-x64-msvc": "0.19.2",
87
- "@gorules/zen-engine-linux-arm64-gnu": "0.19.2",
88
- "@gorules/zen-engine-darwin-arm64": "0.19.2"
84
+ "@gorules/zen-engine-darwin-x64": "0.21.0",
85
+ "@gorules/zen-engine-linux-x64-gnu": "0.21.0",
86
+ "@gorules/zen-engine-win32-x64-msvc": "0.21.0",
87
+ "@gorules/zen-engine-linux-arm64-gnu": "0.21.0",
88
+ "@gorules/zen-engine-darwin-arm64": "0.21.0"
89
89
  }
90
90
  }