@gorules/zen-engine 0.19.2 → 0.20.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 +16 -0
  2. package/index.js +39 -10
  3. package/package.json +9 -9
package/index.d.ts CHANGED
@@ -47,6 +47,7 @@ export class ZenDecisionContent {
47
47
  export class ZenDecision {
48
48
  constructor()
49
49
  evaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
50
+ safeEvaluate(context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
50
51
  validate(): void
51
52
  }
52
53
  export class ZenEngine {
@@ -54,6 +55,8 @@ export class ZenEngine {
54
55
  evaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<ZenEngineResponse>
55
56
  createDecision(content: ZenDecisionContent | Buffer | object): ZenDecision
56
57
  getDecision(key: string): Promise<ZenDecision>
58
+ safeEvaluate(key: string, context: any, opts?: ZenEvaluateOptions | undefined | null): Promise<SafeResult<ZenEngineResponse>>
59
+ safeGetDecision(key: string): Promise<SafeResult<ZenDecision>>
57
60
  /**
58
61
  * Function used to dispose memory allocated for loaders
59
62
  * In the future, it will likely be removed and made automatic
@@ -67,3 +70,16 @@ export class ZenEngineHandlerRequest {
67
70
  getField(path: string): unknown
68
71
  getFieldRaw(path: string): unknown
69
72
  }
73
+
74
+ // Custom definitions
75
+ type SafeResultSuccess<T> = {
76
+ success: true;
77
+ data: T;
78
+ }
79
+
80
+ type SafeResultError = {
81
+ success: false;
82
+ error: any;
83
+ }
84
+
85
+ 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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorules/zen-engine",
3
- "version": "0.19.2",
3
+ "version": "0.20.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": "d0ec9a1e61fecd6f0241298abaae412f08fd848a",
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.20.0",
85
+ "@gorules/zen-engine-linux-x64-gnu": "0.20.0",
86
+ "@gorules/zen-engine-win32-x64-msvc": "0.20.0",
87
+ "@gorules/zen-engine-linux-arm64-gnu": "0.20.0",
88
+ "@gorules/zen-engine-darwin-arm64": "0.20.0"
89
89
  }
90
90
  }