@vaultgradient/pipequery-lang 1.12.2 → 1.13.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.
@@ -1,4 +1,9 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/react/PipeQueryBuilder.tsx
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkLWM2ZXGDcjs = require('../chunk-LWM2ZXGD.cjs');
5
+
6
+ // src/react/PipeQueryBuilder.tsx
2
7
  var _react = require('react');
3
8
  var _material = require('@mui/material');
4
9
 
@@ -314,10 +319,21 @@ function generateQuery(source, steps) {
314
319
  const parts = [source];
315
320
  for (const { step } of steps) {
316
321
  const dsl = stepToDsl(step);
317
- if (dsl) parts.push(dsl);
322
+ if (dsl) parts.push(normalizeFragment(dsl));
318
323
  }
319
324
  return parts.join(" | ");
320
325
  }
326
+ var FRAGMENT_PREFIX = "_data | ";
327
+ function normalizeFragment(fragment) {
328
+ try {
329
+ const ast = _chunkLWM2ZXGDcjs.parseQuery.call(void 0, FRAGMENT_PREFIX + fragment);
330
+ if (ast.operations.length !== 1) return fragment;
331
+ const printed = _chunkLWM2ZXGDcjs.printQuery.call(void 0, ast);
332
+ return printed.startsWith(FRAGMENT_PREFIX) ? printed.slice(FRAGMENT_PREFIX.length) : fragment;
333
+ } catch (e2) {
334
+ return fragment;
335
+ }
336
+ }
321
337
  function stepToDsl(step) {
322
338
  switch (step.type) {
323
339
  case "where":
@@ -1,3 +1,8 @@
1
+ import {
2
+ parseQuery,
3
+ printQuery
4
+ } from "../chunk-KNVFXND5.js";
5
+
1
6
  // src/react/PipeQueryBuilder.tsx
2
7
  import { useState as useState3, useCallback, useMemo, useEffect, useRef } from "react";
3
8
  import { Box as Box6 } from "@mui/material";
@@ -314,10 +319,21 @@ function generateQuery(source, steps) {
314
319
  const parts = [source];
315
320
  for (const { step } of steps) {
316
321
  const dsl = stepToDsl(step);
317
- if (dsl) parts.push(dsl);
322
+ if (dsl) parts.push(normalizeFragment(dsl));
318
323
  }
319
324
  return parts.join(" | ");
320
325
  }
326
+ var FRAGMENT_PREFIX = "_data | ";
327
+ function normalizeFragment(fragment) {
328
+ try {
329
+ const ast = parseQuery(FRAGMENT_PREFIX + fragment);
330
+ if (ast.operations.length !== 1) return fragment;
331
+ const printed = printQuery(ast);
332
+ return printed.startsWith(FRAGMENT_PREFIX) ? printed.slice(FRAGMENT_PREFIX.length) : fragment;
333
+ } catch {
334
+ return fragment;
335
+ }
336
+ }
321
337
  function stepToDsl(step) {
322
338
  switch (step.type) {
323
339
  case "where":
@@ -0,0 +1,141 @@
1
+ interface NumberLiteral {
2
+ kind: 'NumberLiteral';
3
+ value: number;
4
+ }
5
+ interface StringLiteral {
6
+ kind: 'StringLiteral';
7
+ value: string;
8
+ }
9
+ interface BooleanLiteral {
10
+ kind: 'BooleanLiteral';
11
+ value: boolean;
12
+ }
13
+ interface NullLiteral {
14
+ kind: 'NullLiteral';
15
+ }
16
+ interface FieldAccess {
17
+ kind: 'FieldAccess';
18
+ path: string[];
19
+ }
20
+ interface BinaryExpr {
21
+ kind: 'BinaryExpr';
22
+ operator: '>' | '>=' | '<' | '<=' | '==' | '!=' | '&&' | '||' | '+' | '-' | '*' | '/' | '%';
23
+ left: Expression;
24
+ right: Expression;
25
+ }
26
+ interface UnaryExpr {
27
+ kind: 'UnaryExpr';
28
+ operator: '!' | '-';
29
+ operand: Expression;
30
+ }
31
+ interface FunctionCall {
32
+ kind: 'FunctionCall';
33
+ name: string;
34
+ args: Expression[];
35
+ }
36
+ interface AliasExpr {
37
+ kind: 'AliasExpr';
38
+ expression: Expression;
39
+ alias: string;
40
+ }
41
+ type Expression = NumberLiteral | StringLiteral | BooleanLiteral | NullLiteral | FieldAccess | BinaryExpr | UnaryExpr | FunctionCall | AliasExpr;
42
+ interface WhereOp {
43
+ kind: 'WhereOp';
44
+ condition: Expression;
45
+ }
46
+ interface SelectOp {
47
+ kind: 'SelectOp';
48
+ fields: Expression[];
49
+ }
50
+ interface SortOp {
51
+ kind: 'SortOp';
52
+ criteria: Array<{
53
+ expression: Expression;
54
+ direction: 'asc' | 'desc';
55
+ }>;
56
+ }
57
+ interface GroupByOp {
58
+ kind: 'GroupByOp';
59
+ keys: Expression[];
60
+ }
61
+ interface JoinOp {
62
+ kind: 'JoinOp';
63
+ right: string;
64
+ condition: Expression;
65
+ }
66
+ interface FirstOp {
67
+ kind: 'FirstOp';
68
+ count: number;
69
+ }
70
+ interface LastOp {
71
+ kind: 'LastOp';
72
+ count: number;
73
+ }
74
+ interface DistinctOp {
75
+ kind: 'DistinctOp';
76
+ fields?: Expression[];
77
+ }
78
+ interface FlattenOp {
79
+ kind: 'FlattenOp';
80
+ field?: Expression;
81
+ }
82
+ type AggregateFnName = 'sum' | 'avg' | 'min' | 'max' | 'count' | 'median' | 'stddev' | 'var' | 'percentile' | 'skew' | 'kurt' | 'vwap' | 'wavg' | 'drawdown' | 'pct' | 'sharpe' | 'calmar' | 'sortino' | 'info_ratio' | 'distinct_count' | 'sum_abs' | 'abs_sum' | 'first_value' | 'last_value';
83
+ interface AggregateOp {
84
+ kind: 'AggregateOp';
85
+ function: AggregateFnName;
86
+ field?: Expression;
87
+ args?: Expression[];
88
+ }
89
+ interface RollupOp {
90
+ kind: 'RollupOp';
91
+ keys: Expression[];
92
+ aggregates: Expression[];
93
+ }
94
+ interface PivotOp {
95
+ kind: 'PivotOp';
96
+ pivotField: Expression;
97
+ aggregates: Expression[];
98
+ }
99
+ interface TransposeOp {
100
+ kind: 'TransposeOp';
101
+ headerField?: Expression;
102
+ }
103
+ interface MapOp {
104
+ kind: 'MapOp';
105
+ fields: Expression[];
106
+ }
107
+ interface ReduceOp {
108
+ kind: 'ReduceOp';
109
+ initial: Expression;
110
+ accumulator: Expression;
111
+ }
112
+ type Operation = WhereOp | SelectOp | SortOp | GroupByOp | JoinOp | FirstOp | LastOp | DistinctOp | FlattenOp | AggregateOp | RollupOp | PivotOp | TransposeOp | MapOp | ReduceOp;
113
+ interface Pipeline {
114
+ kind: 'Pipeline';
115
+ source: string;
116
+ operations: Operation[];
117
+ }
118
+ declare class DataWeaveError extends Error {
119
+ position: number;
120
+ line: number;
121
+ column: number;
122
+ constructor(message: string, position: number, line: number, column: number);
123
+ }
124
+ declare class LexerError extends DataWeaveError {
125
+ constructor(message: string, position: number, line: number, column: number);
126
+ }
127
+ declare class ParseError extends DataWeaveError {
128
+ constructor(message: string, position: number, line: number, column: number);
129
+ }
130
+ declare class RuntimeError extends Error {
131
+ constructor(message: string);
132
+ }
133
+ type DataContext = Record<string, unknown[]>;
134
+ type RowData = Record<string, unknown>;
135
+ interface CompiledQuery {
136
+ (context: DataContext): unknown;
137
+ source: string;
138
+ ast: Pipeline;
139
+ }
140
+
141
+ export { type CompiledQuery as C, type DataContext as D, type Expression as E, LexerError as L, type Operation as O, type Pipeline as P, type RowData as R, DataWeaveError as a, ParseError as b, RuntimeError as c };
@@ -0,0 +1,141 @@
1
+ interface NumberLiteral {
2
+ kind: 'NumberLiteral';
3
+ value: number;
4
+ }
5
+ interface StringLiteral {
6
+ kind: 'StringLiteral';
7
+ value: string;
8
+ }
9
+ interface BooleanLiteral {
10
+ kind: 'BooleanLiteral';
11
+ value: boolean;
12
+ }
13
+ interface NullLiteral {
14
+ kind: 'NullLiteral';
15
+ }
16
+ interface FieldAccess {
17
+ kind: 'FieldAccess';
18
+ path: string[];
19
+ }
20
+ interface BinaryExpr {
21
+ kind: 'BinaryExpr';
22
+ operator: '>' | '>=' | '<' | '<=' | '==' | '!=' | '&&' | '||' | '+' | '-' | '*' | '/' | '%';
23
+ left: Expression;
24
+ right: Expression;
25
+ }
26
+ interface UnaryExpr {
27
+ kind: 'UnaryExpr';
28
+ operator: '!' | '-';
29
+ operand: Expression;
30
+ }
31
+ interface FunctionCall {
32
+ kind: 'FunctionCall';
33
+ name: string;
34
+ args: Expression[];
35
+ }
36
+ interface AliasExpr {
37
+ kind: 'AliasExpr';
38
+ expression: Expression;
39
+ alias: string;
40
+ }
41
+ type Expression = NumberLiteral | StringLiteral | BooleanLiteral | NullLiteral | FieldAccess | BinaryExpr | UnaryExpr | FunctionCall | AliasExpr;
42
+ interface WhereOp {
43
+ kind: 'WhereOp';
44
+ condition: Expression;
45
+ }
46
+ interface SelectOp {
47
+ kind: 'SelectOp';
48
+ fields: Expression[];
49
+ }
50
+ interface SortOp {
51
+ kind: 'SortOp';
52
+ criteria: Array<{
53
+ expression: Expression;
54
+ direction: 'asc' | 'desc';
55
+ }>;
56
+ }
57
+ interface GroupByOp {
58
+ kind: 'GroupByOp';
59
+ keys: Expression[];
60
+ }
61
+ interface JoinOp {
62
+ kind: 'JoinOp';
63
+ right: string;
64
+ condition: Expression;
65
+ }
66
+ interface FirstOp {
67
+ kind: 'FirstOp';
68
+ count: number;
69
+ }
70
+ interface LastOp {
71
+ kind: 'LastOp';
72
+ count: number;
73
+ }
74
+ interface DistinctOp {
75
+ kind: 'DistinctOp';
76
+ fields?: Expression[];
77
+ }
78
+ interface FlattenOp {
79
+ kind: 'FlattenOp';
80
+ field?: Expression;
81
+ }
82
+ type AggregateFnName = 'sum' | 'avg' | 'min' | 'max' | 'count' | 'median' | 'stddev' | 'var' | 'percentile' | 'skew' | 'kurt' | 'vwap' | 'wavg' | 'drawdown' | 'pct' | 'sharpe' | 'calmar' | 'sortino' | 'info_ratio' | 'distinct_count' | 'sum_abs' | 'abs_sum' | 'first_value' | 'last_value';
83
+ interface AggregateOp {
84
+ kind: 'AggregateOp';
85
+ function: AggregateFnName;
86
+ field?: Expression;
87
+ args?: Expression[];
88
+ }
89
+ interface RollupOp {
90
+ kind: 'RollupOp';
91
+ keys: Expression[];
92
+ aggregates: Expression[];
93
+ }
94
+ interface PivotOp {
95
+ kind: 'PivotOp';
96
+ pivotField: Expression;
97
+ aggregates: Expression[];
98
+ }
99
+ interface TransposeOp {
100
+ kind: 'TransposeOp';
101
+ headerField?: Expression;
102
+ }
103
+ interface MapOp {
104
+ kind: 'MapOp';
105
+ fields: Expression[];
106
+ }
107
+ interface ReduceOp {
108
+ kind: 'ReduceOp';
109
+ initial: Expression;
110
+ accumulator: Expression;
111
+ }
112
+ type Operation = WhereOp | SelectOp | SortOp | GroupByOp | JoinOp | FirstOp | LastOp | DistinctOp | FlattenOp | AggregateOp | RollupOp | PivotOp | TransposeOp | MapOp | ReduceOp;
113
+ interface Pipeline {
114
+ kind: 'Pipeline';
115
+ source: string;
116
+ operations: Operation[];
117
+ }
118
+ declare class DataWeaveError extends Error {
119
+ position: number;
120
+ line: number;
121
+ column: number;
122
+ constructor(message: string, position: number, line: number, column: number);
123
+ }
124
+ declare class LexerError extends DataWeaveError {
125
+ constructor(message: string, position: number, line: number, column: number);
126
+ }
127
+ declare class ParseError extends DataWeaveError {
128
+ constructor(message: string, position: number, line: number, column: number);
129
+ }
130
+ declare class RuntimeError extends Error {
131
+ constructor(message: string);
132
+ }
133
+ type DataContext = Record<string, unknown[]>;
134
+ type RowData = Record<string, unknown>;
135
+ interface CompiledQuery {
136
+ (context: DataContext): unknown;
137
+ source: string;
138
+ ast: Pipeline;
139
+ }
140
+
141
+ export { type CompiledQuery as C, type DataContext as D, type Expression as E, LexerError as L, type Operation as O, type Pipeline as P, type RowData as R, DataWeaveError as a, ParseError as b, RuntimeError as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultgradient/pipequery-lang",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
4
4
  "description": "Pipe-based query language for filtering, transforming, and aggregating data",
5
5
  "type": "module",
6
6
  "main": "./dist/engine/index.cjs",
@@ -17,6 +17,16 @@
17
17
  "default": "./dist/engine/index.cjs"
18
18
  }
19
19
  },
20
+ "./builder": {
21
+ "import": {
22
+ "types": "./dist/builder/index.d.ts",
23
+ "default": "./dist/builder/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/builder/index.d.cts",
27
+ "default": "./dist/builder/index.cjs"
28
+ }
29
+ },
20
30
  "./highlighting": {
21
31
  "import": {
22
32
  "types": "./dist/highlighting/index.d.ts",