Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
"import": "./lib/index.mjs",
"require": "./lib/index.js",
"default": "./lib/index.js"
},
"./types": {
"types": "./lib/types.d.ts",
"import": "./lib/types.mjs",
"require": "./lib/types.js",
"default": "./lib/types.js"
}
},
"typesVersions": {
"*": {
"types": [
"./lib/types.d.ts"
]
}
},
"files": [
Expand Down
1 change: 1 addition & 0 deletions src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { Builder, type AstNodeParserFields, type AstNodeTemplate } from './build
export { singleItems, resolveItem, lastItem, firstItem } from './visitor/utils';
export { Walker, type WalkerOptions, walk, type WalkerAstNode } from './walker';
export * as mutate from './mutate';
export * from './visitor';
18 changes: 18 additions & 0 deletions src/ast/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,21 @@ export function isAssignment(node: unknown): node is types.ESQLFunction {
}

export const isParametrized = (node: ESQLProperNode): boolean => Walker.params(node).length > 0;

const isESQLAstBaseItem = (node: unknown): node is types.ESQLAstBaseItem =>
Copy link
Contributor Author

@sddonne sddonne Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 were declared in src/types.ts, better if we leave that file only for types.

typeof node === 'object' &&
node !== null &&
Object.hasOwn(node, 'name') &&
Object.hasOwn(node, 'text');

export const isESQLFunction = (node: unknown): node is types.ESQLFunction =>
isESQLAstBaseItem(node) &&
Object.hasOwn(node, 'type') &&
(node as types.ESQLFunction).type === 'function';

export const isESQLNamedParamLiteral = (
node: types.ESQLAstItem
): node is types.ESQLNamedParamLiteral =>
isESQLAstBaseItem(node) &&
(node as types.ESQLNamedParamLiteral).literalType === 'param' &&
(node as types.ESQLNamedParamLiteral).paramType === 'named';
2 changes: 1 addition & 1 deletion src/ast/visitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

export type * from './types';
export type { VisitorMethods } from './types';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only VisitorMethods to not pollute the exports with all the types.

export { Visitor, type VisitorOptions } from './visitor';
export { GlobalVisitorContext, type SharedData } from './global_visitor_context';
export * from './contexts';
3 changes: 3 additions & 0 deletions src/embedded_languages/promql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export type * from './types';
export { PromQLBuilder } from './ast/builder';
export type { PromQLAstNodeTemplate } from './ast/builder/types';

// Walker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Walker was not exposed

export { PromqlWalker, type PromqlWalkerOptions } from './ast/walker';

// Parser
export { PromQLParser, type PromQLParseOptions } from './parser';
export { PromQLErrorListener } from './parser/promql_error_listener';
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export type * from './types';

export * from './parser';
export * from './ast';
export * from './composer';
export * from './pretty_print';
export * from './embedded_languages';
export * from './debug';
2 changes: 1 addition & 1 deletion src/pretty_print/basic_pretty_printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
binaryExpressionGroup,
unaryExpressionGroup,
} from '../ast/grouping';
import type { ESQLAstExpressionNode } from '../ast/visitor';
import type { ESQLAstExpressionNode } from '../ast/visitor/types';
import { Visitor } from '../ast/visitor';
import { resolveItem } from '../ast/visitor/utils';
import {
Expand Down
16 changes: 0 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,6 @@ export interface ESQLFunction<
args: ESQLAstItem[];
}

const isESQLAstBaseItem = (node: unknown): node is ESQLAstBaseItem =>
typeof node === 'object' &&
node !== null &&
Object.hasOwn(node, 'name') &&
Object.hasOwn(node, 'text');

export const isESQLFunction = (node: unknown): node is ESQLFunction =>
isESQLAstBaseItem(node) &&
Object.hasOwn(node, 'type') &&
(node as ESQLFunction).type === 'function';

export interface ESQLFunctionCallExpression extends ESQLFunction<'variadic-call'> {
subtype: 'variadic-call';
args: ESQLAstItem[];
Expand Down Expand Up @@ -684,11 +673,6 @@ export interface ESQLIdentifier extends ESQLAstBaseItem {
type: 'identifier';
}

export const isESQLNamedParamLiteral = (node: ESQLAstItem): node is ESQLNamedParamLiteral =>
isESQLAstBaseItem(node) &&
(node as ESQLNamedParamLiteral).literalType === 'param' &&
(node as ESQLNamedParamLiteral).paramType === 'named';

export interface ESQLMessage {
type: 'error' | 'warning';
text: string;
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
entry: ['src/index.ts', 'src/types.ts'],
format: ['cjs', 'esm'],
outDir: 'lib',
clean: true,
Expand Down