@xcitedbs/client 0.3.1 → 0.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcitedbs/client",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "XCiteDB BaaS client SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -85,6 +85,7 @@ A path selects a value from the current context.
85
85
  | `[n]` | Array index (0-based) | `"Dependants[0].FirstName"` |
86
86
  | `[expr]` | Computed index | `"Field1[$index+1]"` |
87
87
  | `[]` | Whole array (projection over all elements) | `"Array1[].Field1"` |
88
+ | `[a:b]` | Array **slice** in a context modifier (half-open; negative counts from end) | `"scores:[0:3]"`, `"scores:[-2:]"` |
88
89
  | `/Field` | Absolute from document root | `"/employees.$(.)"` |
89
90
  | `../Field` | Up one path level (skips array indices) | `"../DBInstanceIdentifier"` |
90
91
  | `<<Field` | Read same field in *previous* document context | `"<<Field1"` after a `->$file(...)` |
@@ -259,18 +260,21 @@ Equivalent to SQL `GROUP BY bin`. Combine with aggregate values for grouped stat
259
260
  { "$(Title)": "$avg(Salary)" }
260
261
  ```
261
262
 
262
- ### 5.4 Copy-all keys — `{}` and `{'regex'}`
263
+ ### 5.4 Copy-all keys — `{}`, `{'regex'}`, and slice `{a:b}`
263
264
 
264
- `{}` evaluates to *every* key in the queried object. `{'regex'}` evaluates to keys matching the regex.
265
+ `{}` evaluates to *every* key in the queried object. `{'regex'}` evaluates to keys matching the regex. `{a:b}` is a positional **slice** of the source-key sequence (half-open, negative values count from the end) — keys are visited in their stored sort order, so this naturally gives "first K", "last K", or a middle range.
265
266
 
266
267
  ```json
267
268
  { "{}": "value" } // every key gets the constant 'value' (rarely useful)
268
269
  { "{}:": "." } // copy every key → its value (very useful)
269
270
  { "{'A.*B'}:": "." } // copy only keys matching the regex
270
271
  { "{}:": ".?$key!='ID'" } // copy all except ID (predicate filter)
272
+ { "{:3}:": "." } // first 3 keys (alphabetical)
273
+ { "{-2:}:": "." } // last 2 keys
274
+ { "{2:5}:": "." } // keys at positions 2..4 inclusive
271
275
  ```
272
276
 
273
- The trailing `:` after `{}` is a context modifier ("for each key, switch context to that key"). Without `:`, `{}` is just the empty-key spec.
277
+ The trailing `:` after `{}` is a context modifier ("for each key, switch context to that key"). Without `:`, `{}` is just the empty-key spec. The slice form `{a:b}` mirrors the array slice `[a:b]` (see §4 path expressions and §6 context modifiers): `{:K}` is the first K, `{-K:}` the last K, `{a:b}` the half-open range.
274
278
 
275
279
  ### 5.5 Key utility functions
276
280
 
@@ -298,7 +302,9 @@ A modifier may be followed by `?cond` (predicate). Modifiers chain freely.
298
302
  | `:` (nothing after) | Repeat the key name as the path: `"Field1:"` ≡ `"Field1:Field1"` |
299
303
  | `:[]` | Iterate over each array element |
300
304
  | `:[n]` | Switch to array index `n` |
305
+ | `:[a:b]` | Iterate over the array **slice** at indices `a..b` (half-open; negative counts from end) |
301
306
  | `:{}` | Iterate over each object field |
307
+ | `:{a:b}` | Iterate over the object-key **slice** at positions `a..b` (half-open; negative counts from end) |
302
308
  | `:{'regex'}` | Iterate over fields matching regex |
303
309
  | `:**` | Recursive descent (every path under current) |
304
310
  | `:.` | Stay at current path (rarely needed) |
@@ -308,8 +314,18 @@ A modifier may be followed by `?cond` (predicate). Modifiers chain freely.
308
314
  { "result:Customers[]?Balance>100000:Accounts[]": ["accountNumber"] }
309
315
  { "result:{}": ["."] }
310
316
  { "#return:**": ["$key@unique_ascending"] }
317
+ { "first:scores[:3]": ["."] } // first 3 elements of `scores`
318
+ { "tail:scores[-2:]": ["."] } // last 2 elements
319
+ { "middle:scores[2:5]": ["."] } // elements at positions 2..4
311
320
  ```
312
321
 
322
+ **Slice semantics** (same shape for arrays and object-key iteration):
323
+ - `[:K]` / `{:K}` — first K (start defaults to 0).
324
+ - `[K:]` / `{K:}` — from index K to end.
325
+ - `[a:b]` / `{a:b}` — half-open range `[a, b)`.
326
+ - `[-K:]` / `{-K:}` — last K (negative values count from the end).
327
+ - Out-of-range bounds are clamped; `b ≤ a` yields an empty result.
328
+
313
329
  ### 6.2 The `:Field` shorthand (very common)
314
330
 
315
331
  `"FirstName:"` is identical to `"FirstName:FirstName"`. Use it whenever the result key matches the source field:
@@ -151,7 +151,7 @@ Roughly in parse order:
151
151
 
152
152
  | Prefix / form | AST | Notes |
153
153
  |-----------------|-----|--------|
154
- | `[` optional `]` | `TExprSubfield(TExprField("."), expr?, is_index)` | `[]` = whole array on current `.`; `[e]` = index. |
154
+ | `[` optional `]` | `TExprSubfield(TExprField("."), expr?, is_index)` | `[]` = whole array on current `.`; `[e]` = index. (Slice `[a:b]` form is currently parsed only on context modifiers, not in path expressions.) |
155
155
  | `$` `(` `expression` `)` | `TExprField(expr)` | Evaluate / path from dynamic name (`$()`). |
156
156
  | `$if` `(` `condition` `,` `expression` `,` `expression` `)` | `TExprITE` | |
157
157
  | `$call` `(` IDENT `)` | `TExprCall(name)` | Zero-arg user function by name. |
@@ -294,9 +294,12 @@ key ::= '$' '(' expression ')' (* dynamic key → TQParamKey *)
294
294
  | '$' IDENT ... | '%' IDENT ... (* whole thing parsed as expression() → TQParamKey *)
295
295
  | '{' '}' (* TQRegexKey empty regex *)
296
296
  | '{' QUOTED '}' (* TQRegexKey *)
297
+ | '{' slice '}' (* TQRegexKey + slice over source-key sequence *)
297
298
  | '#' directive
298
299
  | pathId (* TQSimpleKey, name may include quoted segments from pathId *)
299
300
 
301
+ slice ::= INT? ':' INT? (* INT may be `-` INT for negative-from-end *)
302
+
300
303
  directive ::= 'if'
301
304
  | 'func' IDENT ( '(' IDENT ( ',' IDENT )* ')' )? (* register arity; TQFuncDefinition *)
302
305
  | 'var' IDENT
@@ -336,8 +339,10 @@ Parsed **after** `key()` from the **same** JSON key string. Mode parameter `Cont
336
339
  | `->` … | `Arrow` | See §8.2 (`identifierExpression`, builtins, legacy JSON-field lookup, `->$each`); often `new_frame = true` |
337
340
  | `[` `]` | `Array` | traversal |
338
341
  | `[` INT `]` | *(string context)* | literal index path segment |
342
+ | `[` (INT)? `:` (INT)? `]` | `Array` + slice | half-open slice; sets `array_slice_set` and the start/end fields on the `TQContextMod`. Negative ints count from end. (`-` token + INT recognized.) |
339
343
  | `.` | *(path)* | context string `"."` |
340
344
  | IDENT… `[` `]`? | `Array` if trailing `[]`, else path | Empty path + no `[` → **`Reskey`** mode |
345
+ | IDENT… `[` slice `]` | `Array` + slice | `Field[a:b]` after a path |
341
346
  | Optional `?` `condition` after each atom | — | Wraps inner mod chain in `TQValueWithCond` |
342
347
 
343
348
  Recursion: `context_mod(...)` parses the **rest** of the chain; result wrapped in `TQContextMod` (expr or string form).