@platforma-sdk/workflow-tengo 2.10.0 → 2.10.1

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.
@@ -341,16 +341,32 @@ isValid := func(js, schema) {
341
341
  }
342
342
 
343
343
  /**
344
- * Asserts that a given JSON conforms to a given schema.
344
+ * Alias to ll.assert just for usage convenience
345
+ */
346
+ assert := func(condition, msg, ...args) {
347
+ ll.assert(condition, msg, args...)
348
+ }
349
+
350
+ /**
351
+ * Asserts that a given variable conforms to a given schema.
352
+ *
353
+ * Schema field value examples:
354
+ * - for scalar type checks:
355
+ * "string", "number", "char", "bytes", "bool" to check presence of value of given type
356
+ * "null" - value must be undefined
357
+ * "any" - any value is accepted (even undefined)
358
+ * ["or", "string", "number"] - value must be string or number
359
+ * - for arrays: ["string"], ["number"], ... (any valid scalar type)
360
+ * - for maps: {"name": "string", "age": "number"} - make sure <value> is map with "name" and "age" keys with given value types.
345
361
  *
346
- * @param js: any - the JSON to assert.
347
- * @param schema: any - the schema to assert against.
362
+ * @param value: any - the value to check.
363
+ * @param schema: any - the schema to assert against (see comments above)
348
364
  * @param failMsg: string - optional parameter with custom message to be printed on validation error
349
365
  */
350
- assertJsonSchema := func(js, schema, ...failMsg) {
351
- r := _validateJson(js, schema, "")
366
+ assertType := func(value, schema, ...failMsg) {
367
+ r := _validateJson(value, schema, "")
352
368
 
353
- msg := "JSON validation error"
369
+ msg := "type schema validation error"
354
370
  if len(failMsg) > 0 {
355
371
  msg = failMsg[0]
356
372
  }
@@ -360,6 +376,13 @@ assertJsonSchema := func(js, schema, ...failMsg) {
360
376
  }
361
377
  }
362
378
 
379
+ /**
380
+ * Alias to 'assert' for backward compatibility
381
+ */
382
+ assertJsonSchema := func(js, schema, ...failMsg) {
383
+ assertType(js, schema, failMsg...)
384
+ }
385
+
363
386
  //
364
387
  // Domain-specific schemas and checks:
365
388
  //
@@ -435,15 +458,17 @@ refSchema := {
435
458
  }
436
459
 
437
460
  export ll.toStrict({
438
- success: success,
439
- fail: fail,
440
- isSuccess: isSuccess,
441
- isFail: isFail,
442
- checkJson: checkJson,
443
- isValid: isValid,
444
- assertJsonSchema: assertJsonSchema,
445
- resource: resource,
446
- reference: reference,
447
- resourceType: resourceType,
448
- ref: refSchema
461
+ success: success,
462
+ fail: fail,
463
+ isSuccess: isSuccess,
464
+ isFail: isFail,
465
+ checkJson: checkJson,
466
+ isValid: isValid,
467
+ assert: assert,
468
+ assertType: assertType,
469
+ assertJsonSchema: assertJsonSchema, // deprecated
470
+ resource: resource,
471
+ reference: reference,
472
+ resourceType: resourceType,
473
+ ref: refSchema
449
474
  })
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/workflow-tengo",
3
- "version": "2.10.0",
3
+ "version": "2.10.1",
4
4
  "description": "Tengo SDK library",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",