inibase 3.1.0 → 3.1.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.
package/README.md CHANGED
@@ -889,8 +889,8 @@ await db.createTable("orders", [
889
889
  { key: "unitPriceCents", type: "number" },
890
890
  ],
891
891
  },
892
- { key: "totalCents", type: "number", computed: "sum(5, 6)" }, // quantity x unitPriceCents
893
- { key: "totalCentsLive", type: "number", computed: "sum(5, 4.2)" }, // quantity x product.price
892
+ { key: "totalCents", type: "number", computed: "sum(5 * 6)" }, // quantity x unitPriceCents
893
+ { key: "totalCentsLive", type: "number", computed: "sum(5 * 4.2)" }, // quantity x product.price
894
894
  ]);
895
895
 
896
896
  const posted = await db.post(
@@ -912,10 +912,10 @@ const posted = await db.post(
912
912
 
913
913
  **Expression language (v1, integer-only).**
914
914
 
915
- - Operators: `+` `-` `,` (multiply) `/` `%`; `( )` for grouping. Multiplication
916
- binds tighter than addition (`1 , 2 + 3` = `(1*2) + 3`).
915
+ - Operators: `+` `-` `*` `/` `%`; `( )` for grouping. Multiplication
916
+ binds tighter than addition (`1 * 2 + 3` = `(1*2) + 3`).
917
917
  - Helpers: `sum` `count` `avg` `min` `max` iterate an array-of-objects found by
918
- the ids inside the parentheses (`sum(5, 6)` = quantity x unit-price per item).
918
+ the ids inside the parentheses (`sum(5 * 6)` = quantity x unit-price per item).
919
919
  - Paths: `id ("." id)*` where `.` hops through a `table` link
920
920
  (`4.2` = price of the linked product row).
921
921
  - Integers only: there are no decimal literals — `.` is the path separator, so
@@ -982,7 +982,7 @@ const posted = await db.post(
982
982
 
983
983
  ### Computed fields
984
984
 
985
- Write-time evaluation cost (helpers `sum(3 , 4)`, `avg(4)`, `min(4)`, `max(4)`, `count(3)` over an `items` array with 3 lines, plus an arithmetic field `itemTotal × (314 / 100)`), compared against the identical table without computed fields:
985
+ Write-time evaluation cost (helpers `sum(3 * 4)`, `avg(4)`, `min(4)`, `max(4)`, `count(3)` over an `items` array with 3 lines, plus an arithmetic field `itemTotal × (314 / 100)`), compared against the identical table without computed fields:
986
986
 
987
987
  | rows | POST bulk (plain / computed) | POST single (plain / computed) | PUT recompute (plain / computed) |
988
988
  |------|------------------------------|--------------------------------|----------------------------------|
@@ -5,7 +5,7 @@
5
5
  * -------
6
6
  * ```
7
7
  * expression := term (("+" | "-") term)*
8
- * term := factor (("," | "/" | "%") factor)* // "," = multiply
8
+ * term := factor (("*" | "/" | "%") factor)* // "*" = multiply
9
9
  * factor := integer-literal | path | function-call | "(" expression ")"
10
10
  * path := id ( "." id )* // "." = link/binding hop
11
11
  * function := "sum" | "count" | "avg" | "min" | "max" "(" expression ")"
@@ -19,7 +19,7 @@
19
19
  *
20
20
  * A bare integer that **matches a field id in the table's schema** is that
21
21
  * field's value (ids are locative); a bare integer that matches no field id
22
- * is an integer literal. This is what makes both `sum(4, 3.4)` (id 4 =
22
+ * is an integer literal. This is what makes both `sum(4 * 3.4)` (id 4 =
23
23
  * quantity) and `314 / 100` (no such ids) usable.
24
24
  *
25
25
  * Compiled expressions are persisted with the schema as
@@ -5,7 +5,7 @@
5
5
  * -------
6
6
  * ```
7
7
  * expression := term (("+" | "-") term)*
8
- * term := factor (("," | "/" | "%") factor)* // "," = multiply
8
+ * term := factor (("*" | "/" | "%") factor)* // "*" = multiply
9
9
  * factor := integer-literal | path | function-call | "(" expression ")"
10
10
  * path := id ( "." id )* // "." = link/binding hop
11
11
  * function := "sum" | "count" | "avg" | "min" | "max" "(" expression ")"
@@ -19,7 +19,7 @@
19
19
  *
20
20
  * A bare integer that **matches a field id in the table's schema** is that
21
21
  * field's value (ids are locative); a bare integer that matches no field id
22
- * is an integer literal. This is what makes both `sum(4, 3.4)` (id 4 =
22
+ * is an integer literal. This is what makes both `sum(4 * 3.4)` (id 4 =
23
23
  * quantity) and `314 / 100` (no such ids) usable.
24
24
  *
25
25
  * Compiled expressions are persisted with the schema as
@@ -79,7 +79,7 @@ function tokenize(source) {
79
79
  continue;
80
80
  case "+":
81
81
  case "-":
82
- case ",":
82
+ case "*":
83
83
  case "/":
84
84
  case "%":
85
85
  tokens.push({ t: "op", v: ch });
@@ -135,9 +135,9 @@ export function parseExpression(source, language = "en", fieldKey = "") {
135
135
  const term = () => {
136
136
  enter();
137
137
  let left = factor();
138
- while (peek().t === "op" && [",", "/", "%"].includes(peek().v)) {
138
+ while (peek().t === "op" && ["*", "/", "%"].includes(peek().v)) {
139
139
  const op = next().v;
140
- const binOp = op === "," ? "mul" : op === "/" ? "div" : "mod";
140
+ const binOp = op === "*" ? "mul" : op === "/" ? "div" : "mod";
141
141
  left = { kind: "bin", op: binOp, left, right: factor() };
142
142
  }
143
143
  leave();
@@ -315,7 +315,7 @@ async function resolveNode(node, ctx, inHelper) {
315
315
  case "num":
316
316
  // A bare integer that matches an existing field id is that field
317
317
  // (ids are locative, inside helpers included — this is what makes
318
- // `sum(5, 4.2)` and `sum(5, 6)` usable); any other bare integer is
318
+ // `sum(5 * 4.2)` and `sum(5 * 6)` usable); any other bare integer is
319
319
  // an integer literal (`314 / 100`).
320
320
  if (ctx.index.has(node.value))
321
321
  return resolvePathNode({ kind: "path", ids: [node.value] }, ctx, inHelper);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",
@@ -88,7 +88,7 @@
88
88
  "benchmark": "./benchmark/run.js",
89
89
  "benchmark:durability": "tsx ./benchmark/durability.ts",
90
90
  "benchmark:computed": "tsx ./benchmark/computed.ts",
91
- "test": "tsx ./tests/inibase.test.ts",
91
+ "test": "tsx ./tests/inibase.test.ts && tsx ./tests/inibase.advanced.test.ts && tsx ./tests/transaction.test.ts && tsx ./tests/durability.test.ts && tsx ./tests/expression.test.ts && tsx ./tests/utils.test.ts",
92
92
  "test:durability": "tsx ./tests/durability.test.ts",
93
93
  "test:transaction": "tsx ./tests/transaction.test.ts",
94
94
  "test:utils": "tsx ./tests/utils.test.ts",