@narrative.io/data-collaboration-sdk-ts 3.7.0 → 3.8.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.
@@ -45,11 +45,17 @@ export interface ParticipantsAll {
45
45
  export interface ParticipantsNone {
46
46
  type: "none";
47
47
  }
48
+ /** Only these companies. `company_ids` must be non-empty. */
48
49
  export interface ParticipantsInclusion {
49
50
  type: "inclusion";
50
51
  company_ids: number[];
51
52
  }
52
- export type Participants = ParticipantsAll | ParticipantsNone | ParticipantsInclusion;
53
+ /** Every company except these. `company_ids` must be non-empty. */
54
+ export interface ParticipantsExclusion {
55
+ type: "exclusion";
56
+ company_ids: number[];
57
+ }
58
+ export type Participants = ParticipantsAll | ParticipantsNone | ParticipantsInclusion | ParticipantsExclusion;
53
59
  export interface ComputePoolCollaborators {
54
60
  use: Participants;
55
61
  }
@@ -189,17 +189,40 @@ function parseFunction(n) {
189
189
  if (n.type !== "function") {
190
190
  return nqlOrFail(n);
191
191
  }
192
+ // CAST is the one special-syntax call the server structures completely:
193
+ // its args arrive as [value, type_spec], and the only non-standard piece
194
+ // is the `AS` argument separator in the text. Parse it into a Func whose
195
+ // second argument is a string literal carrying the type keyword —
196
+ // compileFunction owns the matching `CAST(value AS TYPE)` serialization,
197
+ // so the pair round-trips without falling back to Raw.
198
+ if (n.name.toUpperCase() === "CAST" &&
199
+ n.args.length === 2 &&
200
+ n.args[1].type === "type_spec") {
201
+ return {
202
+ type: "function",
203
+ as: n.as,
204
+ name: n.name,
205
+ args: [
206
+ parseExpression(n.args[0]),
207
+ {
208
+ type: "lit",
209
+ value_type: { type: "string" },
210
+ value: n.args[1].nql,
211
+ },
212
+ ],
213
+ };
214
+ }
192
215
  // Only structure functions whose original text is the standard call
193
216
  // syntax `NAME(arg, arg, ...)`, optionally followed by an alias — the
194
217
  // server serializes `expr AS alias` as the inner node with the alias
195
218
  // wrapper's `as`/`nql` merged on top, so an aliased function's `nql`
196
219
  // span reads `NAME(args) AS alias`. Functions with special syntax —
197
- // EXTRACT(unit FROM x), CAST(x AS type), TRIM(BOTH ' ' FROM x) — cannot
198
- // be regenerated from name + args and must stay Raw passthroughs, or
199
- // compiling would emit comma syntax and corrupt the query. The match
200
- // tolerates whitespace differences (and a missing/implicit AS keyword)
201
- // because compiling name + args back to `NAME(arg, arg, ...) AS "alias"`
202
- // only ever normalizes those, never changes semantics.
220
+ // EXTRACT(unit FROM x), TRIM(BOTH ' ' FROM x) — cannot be regenerated
221
+ // from name + args and must stay Raw passthroughs, or compiling would
222
+ // emit comma syntax and corrupt the query. The match tolerates
223
+ // whitespace differences (and a missing/implicit AS keyword) because
224
+ // compiling name + args back to `NAME(arg, arg, ...) AS "alias"` only
225
+ // ever normalizes those, never changes semantics.
203
226
  const argTexts = n.args.map((a) => "nql" in a ? a.nql : undefined);
204
227
  if (argTexts.some((t) => t === undefined)) {
205
228
  return nqlOrFail(n);
@@ -219,7 +219,10 @@ export function compileOutput(n, dsMap) {
219
219
  case "raw_ref":
220
220
  return compileRawRef(n.nql, n.as);
221
221
  case "nql":
222
- return raw(n);
222
+ // like functions, aliased raw outputs compile bare — the server's
223
+ // parser rejects `(expr AS "alias")` (an alias isn't valid inside
224
+ // a parenthesized expression)
225
+ return aliased(n.nql, n.as, false);
223
226
  case "placeholder":
224
227
  return compilePlaceholder(n);
225
228
  }
@@ -360,6 +363,16 @@ function compileRawRef(nql, as) {
360
363
  return aliased(nql, as);
361
364
  }
362
365
  function compileFunction(n, dsMap, parens) {
366
+ // CAST uses `AS` as its argument separator, never a comma — the second
367
+ // argument is the type keyword AstParser lifted out of the server's
368
+ // type_spec node.
369
+ if (n.name.toUpperCase() === "CAST" &&
370
+ n.args.length === 2 &&
371
+ n.args[1].type === "lit" &&
372
+ typeof n.args[1].value === "string") {
373
+ const value = compileExpression(n.args[0], dsMap);
374
+ return aliased(`${n.name}(${value} AS ${n.args[1].value})`, n.as, parens);
375
+ }
363
376
  const args = n.args.map((arg) => compileExpression(arg, dsMap)).join(", ");
364
377
  return aliased(`${n.name}(${args})`, n.as, parens);
365
378
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",