sql-parser-cst
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -1,2 +0,2 @@ | ||
import { Node } from "./sql"; | ||
import { Node } from "./cst/Node"; | ||
/** | ||
@@ -3,0 +3,0 @@ * A map with a transform function for each Node type, like: |
@@ -1,2 +0,2 @@ | ||
import { Node } from "./sql"; | ||
import { Node } from "./cst/Node"; | ||
/** | ||
@@ -3,0 +3,0 @@ * A map with a visitor function for each Node type, like: |
@@ -1,2 +0,2 @@ | ||
import { Program } from "../sql"; | ||
import { Program } from "../cst/Node"; | ||
export declare function format(node: Program): string; |
@@ -1,2 +0,2 @@ | ||
import { Node } from "../sql"; | ||
import { Node } from "../cst/Node"; | ||
export declare type Layout = Line | string | Layout[]; | ||
@@ -3,0 +3,0 @@ export declare type Line = { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unroll = void 0; | ||
const util_1 = require("../util"); | ||
const generic_1 = require("../utils/generic"); | ||
const layout_1 = require("./layout"); | ||
@@ -19,3 +19,3 @@ function unroll(item) { | ||
// No need to split when dealing with homogenous array | ||
if (flatArray.every(layout_1.isLine) || flatArray.every(util_1.isString)) { | ||
if (flatArray.every(layout_1.isLine) || flatArray.every(generic_1.isString)) { | ||
return flatArray; | ||
@@ -32,3 +32,3 @@ } | ||
} | ||
if ((0, util_1.isString)(flatArray[i + 1])) { | ||
if ((0, generic_1.isString)(flatArray[i + 1])) { | ||
lines.push({ layout: "line", items: [] }); | ||
@@ -35,0 +35,0 @@ } |
@@ -1,27 +0,55 @@ | ||
import { Node, Program } from "./sql"; | ||
export { format } from "./format/format"; | ||
export * from "./cstVisitor"; | ||
export * from "./cstTransformer"; | ||
export declare type DialectName = "sqlite" | "mysql"; | ||
declare type ParamType = "?" | "?nr" | ":name" | "$name" | "@name"; | ||
export declare type ParserOptions = { | ||
dialect: DialectName; | ||
preserveComments?: boolean; | ||
preserveNewlines?: boolean; | ||
preserveSpaces?: boolean; | ||
includeRange?: boolean; | ||
paramTypes?: ParamType[]; | ||
}; | ||
export declare function parse(sql: string, options: ParserOptions): Program; | ||
/** | ||
* Converts any syntax tree node back to SQL string. | ||
* | ||
* It's a very primitive serializer that won't insert any whitespace on its own. | ||
* It will only restore the whitespace from leading/trailing fields. | ||
* Not having this information available can lead to invalid SQL being generated. | ||
* | ||
* Therefore only feed it syntax trees parsed with options: | ||
* | ||
* { preserveSpaces: true, preserveComments: true, preserveNewlines: true } | ||
*/ | ||
export declare function show(node: Node): string; | ||
export interface IFilePosition { | ||
offset: number; | ||
line: number; | ||
column: number; | ||
} | ||
export interface IFileRange { | ||
start: IFilePosition; | ||
end: IFilePosition; | ||
source: string; | ||
} | ||
export interface ILiteralExpectation { | ||
type: "literal"; | ||
text: string; | ||
ignoreCase: boolean; | ||
} | ||
export interface IClassParts extends Array<string | IClassParts> { | ||
} | ||
export interface IClassExpectation { | ||
type: "class"; | ||
parts: IClassParts; | ||
inverted: boolean; | ||
ignoreCase: boolean; | ||
} | ||
export interface IAnyExpectation { | ||
type: "any"; | ||
} | ||
export interface IEndExpectation { | ||
type: "end"; | ||
} | ||
export interface IOtherExpectation { | ||
type: "other"; | ||
description: string; | ||
} | ||
export declare type Expectation = ILiteralExpectation | IClassExpectation | IAnyExpectation | IEndExpectation | IOtherExpectation; | ||
export declare class SyntaxError extends Error { | ||
static buildMessage(expected: Expectation[], found: string | null): string; | ||
message: string; | ||
expected: Expectation[]; | ||
found: string | null; | ||
location: IFileRange; | ||
name: string; | ||
constructor(message: string, expected: Expectation[], found: string | null, location: IFileRange); | ||
format(sources: { | ||
source: string; | ||
text: string; | ||
}[]): string; | ||
} | ||
export interface IParseOptions { | ||
filename?: string; | ||
startRule?: string; | ||
tracer?: any; | ||
[key: string]: any; | ||
} | ||
export declare type ParseFunction = (input: string, options?: IParseOptions) => any; | ||
export declare const parse: ParseFunction; |
@@ -1,4 +0,4 @@ | ||
import { Node } from "./sql"; | ||
import { Node } from "./cst/Node"; | ||
declare type NodeArray = (Node | NodeArray | string | undefined)[]; | ||
export declare function show(node: Node | NodeArray | string, joinString?: string): string; | ||
export {}; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const cstTransformer_1 = require("./cstTransformer"); | ||
const util_1 = require("./util"); | ||
const generic_1 = require("./utils/generic"); | ||
function show(node, joinString = "") { | ||
@@ -13,3 +13,3 @@ if (typeof node === "string") { | ||
return node | ||
.filter(util_1.isDefined) | ||
.filter(generic_1.isDefined) | ||
.map((n) => show(n)) | ||
@@ -23,3 +23,3 @@ .join(joinString); | ||
] | ||
.filter(util_1.isDefined) | ||
.filter(generic_1.isDefined) | ||
.join(""); | ||
@@ -255,3 +255,3 @@ } | ||
// Expressions | ||
expr_list: (node) => show(node.items, ","), | ||
list_expr: (node) => show(node.items, ","), | ||
paren_expr: (node) => "(" + show(node.expr) + ")", | ||
@@ -258,0 +258,0 @@ binary_expr: (node) => show([node.left, node.operator, node.right]), |
@@ -5,5 +5,5 @@ { | ||
"license": "GPL-2.0-or-later", | ||
"version": "0.4.0", | ||
"main": "lib/parser.js", | ||
"types": "lib/parser.d.ts", | ||
"version": "0.5.0", | ||
"main": "lib/main.js", | ||
"types": "lib/main.d.ts", | ||
"repository": { | ||
@@ -25,3 +25,3 @@ "type": "git", | ||
"watch:generate": "npm-watch", | ||
"clean": "rm -rf lib; rm -rf src/dialects/*.ts", | ||
"clean": "rm -rf lib; rm -rf src/generated_parser.ts", | ||
"build": "yarn clean && yarn generate && tsc", | ||
@@ -48,4 +48,4 @@ "test:mysql": "jest --config test/config/mysql.json", | ||
"watch": { | ||
"generate": "src/sql.pegjs" | ||
"generate": "src/parser.pegjs" | ||
} | ||
} |
@@ -98,6 +98,6 @@ # SQL Parser CST [![npm version](https://img.shields.io/npm/v/sql-parser-cst)](https://www.npmjs.com/package/sql-parser-cst) ![example workflow](https://github.com/nene/sql-parser-cst/actions/workflows/build.yml/badge.svg) | ||
"type": "select_clause", | ||
"selectKw": { "type": "keyword", "text": "SELECT" }, | ||
"selectKw": { "type": "keyword", "text": "SELECT", "name": "SELECT" }, | ||
"options": [], | ||
"columns": { | ||
"type": "expr_list", | ||
"type": "list_expr", | ||
"items": [ | ||
@@ -118,3 +118,3 @@ { | ||
}, | ||
"asKw": { "type": "keyword", "text": "as" }, | ||
"asKw": { "type": "keyword", "text": "as", "name": "AS" }, | ||
"alias": { "type": "identifier", "text": "fname" } | ||
@@ -127,3 +127,3 @@ } | ||
"type": "from_clause", | ||
"fromKw": { "type": "keyword", "text": "FROM" }, | ||
"fromKw": { "type": "keyword", "text": "FROM", "name": "FROM" }, | ||
"expr": { | ||
@@ -155,3 +155,3 @@ "type": "table_ref", | ||
- Parenthesis is represented by separate `type: paren_expr` node. | ||
- Comma-separated lists are represented by separate `type: expr_list` node. | ||
- Comma-separated lists are represented by separate `type: list_expr` node. | ||
- Trailing semicolon is represented by `type: empty_stmt` node in the end. | ||
@@ -158,0 +158,0 @@ - The original source code representation of strings, identifiers, keywords, etc |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1339924
90
40394