Skip to content

Commit

Permalink
refactoring: use webpack + HMR unit tests + one build bundle per lang…
Browse files Browse the repository at this point in the history
…uage
  • Loading branch information
oguimbal committed Jul 16, 2020
1 parent 2a4618d commit f5c9c90
Show file tree
Hide file tree
Showing 15 changed files with 4,232 additions and 4,170 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lib/
.coveralls.yml
bower_components/
umd/
output/
33 changes: 0 additions & 33 deletions .nycrc

This file was deleted.

21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Attach unit tests",
"request": "attach",
"port": 9240,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"skipFiles": [
"<node_internals>/*.js",
"**/loader.js", // webpack hmr reloader
"node_modules/core-js/**",
"output/**"
]
}
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"mochaExplorer.hmrBundle": "output/dev/tests.js",
// When using HMR, it is recommanded to configure a different debug port here.
// otherwise, you wont be able to use mocha tests in multiple instances of vscode.
"mochaExplorer.debuggerPort": 9240,
"mochaExplorer.require": "source-map-support/register",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"node_modules": true,
"output": true,
"package-lock.json": true
}
}
127 changes: 1 addition & 126 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,126 +1 @@
// Type definitions for node-sql-parser 1.0
// Project: https://github.com/taozhi8833998/node-sql-parser#readme
// Definitions by: taozhi8833998 <https://github.com/taozhi8833998>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4

export interface With {
name: string;
stmt: any[];
columns?: any[];
}
export type WhilteListCheckMode = 'table' | 'column';
export interface Option {
database?: string,
type?: string,
}
export interface TableColumnAst {
tableList: string[];
columnList: string[];
ast: AST[] | AST;
}
export interface From {
db: string | null;
table: string;
as: string | null;
}
export interface Dual {
type: 'dual';
}
export interface Limit {
type: string;
value: number;
}
export interface OrderBy {
type: 'ASC' | 'DESC';
expr: any;
}
export interface ColumnRef {
type: 'column_ref';
table: string | null;
column: string;
}
export interface SetList {
column: string;
value: any;
table: string | null;
}
export interface InsertReplaceValue {
type: 'expr_list';
value: any[];
}
export interface Star {
type: 'star';
value: '*';
}
export interface AggrFunc {
type: 'aggr_func';
name: string;
args: ColumnRef | AggrFunc | Star | null;
}
export interface Column {
expr: ColumnRef | AggrFunc;
as: string;
}
export interface Select {
with: With | null;
type: 'select';
options: any[] | null;
distinct: 'DISTINCT' | null;
columns: any[] | Column[] | '*';
from: Array<From | Dual> | null;
where: any;
groupby: ColumnRef[] | null;
having: any[] | null;
orderby: OrderBy[] | null;
limit: Limit[] | null;
}
export interface Insert_Replace {
type: 'replace' | 'insert';
db: string | null;
table: any;
columns: string[] | null;
values: InsertReplaceValue[];
}
export interface Update {
type: 'update';
db: string | null;
table: Array<From | Dual> | null;
set: SetList[];
where: any;
}
export interface Delete {
type: 'delete';
table: any;
from: Array<From | Dual>;
where: any;
}

export interface Alter {
type: 'alter',
table: From,
expr: any
}

export interface Use {
type: 'use';
db: string;
}

export type AST = Use | Select | Insert_Replace | Update | Delete | Alter;

export class Parser {
constructor();

parse(sql: string, opt?: Option): TableColumnAst;

astify(sql: string, opt?: Option): AST[] | AST;

sqlify(ast: AST[] | AST, opt?: Option): string;

whiteListCheck(sql: string, whiteList: string[], opt?: Option): Error | undefined;

tableList(sql: string, opt?: Option): string[];

columnList(sql: string, opt?: Option): string[];
}
export * from './types';
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const Parser = require('./lib/parser').default
const util = require('./lib/util')
import Parser from './src/parser';
import * as util from './src/util';

module.exports = {
export {
Parser,
util,
}
};

if (global && global.window) {
global.window.NodeSQLParser = {
Parser,
util,
}
};
}
Loading

0 comments on commit f5c9c90

Please sign in to comment.