expr-json-spec Pub Share

Json

$when:: expr.json.create (customer)
   . (dieselScope[="cart"]=(cart || {id:customer,items:[]}))

$when:: expr.json.addItem (sku, quantity)
   . (dieselScope[="cart"]=(cart + {items:{sku:sku,quantity:quantity}}))

$when:: testing.invcheck
   . (payload="ok")

$when:: expr.json.create2 (a, b)
   ctx.json (a=a, b=b)

$when:: expr.json.sum2 (a, b)
   ctx.json (a=a)
   . (aj=payload)
   ctx.json (b=b)
   . (bj=payload)
   . (payload=(aj + bj))

/$when shipping.package /=> cart/items $map item => inv.get (item.sku,item.quantity})

Test numbers

$when:: expr.simplejson.do (x)
   ctx.json (x=x)

Calling with flatenning

$when:: dieseltest.asAttrs (a, b)
   . (dieselScope[="res33"]=(a + b))

Complex objects

no inventory registered listAll | new
class DieselTestStudent (
name,
address:DieselTestAddress,
name,
address:DieselTestAddress
)
no inventory registered listAll | new
class DieselTestAddress (
street,
no,
street,
no
)

$when:: test.diesel.rule40
   . (student[="address"][="no"]="65")

Array ops

$when:: test.diesel.isin (x in ["123","234"], y not in [1,2])
   . (dieselScope[="y46"]=true)

simple scripting - JS by default

You can embed and use simple JS scripts like this:

fcall | jplay | splay
def: test.util.addMonths (mths)
  m = parseInt(mths);
  d = new Date();
  d.setMonth(d.getMonth() + m);
  x=0;
  // you can use for loops and any other JS construct that 
  // doesn't contain a double curly brace...
  for(i=0; i < 5; i++) {
    x = x+i;
  }
  return d.toISOString().replace(/T.*/g, '');
fcall | jplay | splay
def: test.util.today
  return new Date().toISOString().replace(/T.*/g, '');

Access to complex objects from/to JS:

Get values from input and send back as both payload and as a side effect:

fcall | jplay | splay
def: testdiesel.jstx (students)
  x = students[0].age;
  y = students[1].age;
  return x + y;
fcall | jplay | splay
def: testdiesel.jstxo (students)
  x = students[0].age;
  y = students[1].age;
  return {sum:x + y};


Was this useful?    

By: Razie | 2019-06-10 .. 2021-02-02 | Tags: spec , dsl , private


Viewed 890 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2024, all rights reserved.