New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pgsql-ast-parser

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgsql-ast-parser - npm Package Compare versions

Comparing version 4.1.8 to 4.1.9

11

ast-mapper.d.ts

@@ -8,2 +8,5 @@ import * as a from './syntax/ast';

delete?: (val: a.DeleteStatement) => a.Statement | nil;
comment?: (val: a.CommentStatement) => a.Statement | nil;
raise?: (val: a.RaiseStatement) => a.Statement | nil;
createSchema?: (val: a.CreateSchemaStatement) => a.Statement | nil;
dropTable?: (val: a.DropTableStatement) => a.Statement | nil;

@@ -97,2 +100,5 @@ createEnum?(val: a.CreateEnumType): a.Statement | nil;

export declare type MapperBuilder = (defaultImplem: IAstMapper) => IAstPartialMapper;
declare type PartialNil<T> = {
[P in keyof T]?: T[P] | nil;
};
/**

@@ -103,3 +109,3 @@ * An helper function that returns a copy of an object with modified properties

*/
export declare function assignChanged<T>(orig: T, assign: Partial<T>): T;
export declare function assignChanged<T>(orig: T, assign: PartialNil<T>): T;
/**

@@ -123,2 +129,3 @@ * An helper function that returns a map of an array, but:

statement(val: a.Statement): a.Statement | nil;
comment(val: a.CommentStatement): a.Statement | nil;
createView(val: a.CreateViewStatement): a.Statement | nil;

@@ -138,3 +145,5 @@ createMaterializedView(val: a.CreateMaterializedViewStatement): a.Statement | nil;

insert(val: a.InsertStatement): a.Statement | nil;
raise(val: a.RaiseStatement): a.Statement | nil;
delete(val: a.DeleteStatement): a.Statement | nil;
createSchema(val: a.CreateSchemaStatement): a.Statement | nil;
createTable(val: a.CreateTableStatement): a.Statement | nil;

@@ -141,0 +150,0 @@ truncateTable(val: a.TruncateTableStatement): a.Statement | nil;

2

package.json
{
"name": "pgsql-ast-parser",
"version": "4.1.8",
"version": "4.1.9",
"description": "Yet another simple Postgres SQL parser/modifier",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,2 +11,5 @@ import * as a from './syntax/ast';

delete?: (val: a.DeleteStatement) => a.Statement | nil
comment?: (val: a.CommentStatement) => a.Statement | nil
raise?: (val: a.RaiseStatement) => a.Statement | nil
createSchema?: (val: a.CreateSchemaStatement) => a.Statement | nil
dropTable?: (val: a.DropTableStatement) => a.Statement | nil

@@ -112,3 +115,5 @@ createEnum?(val: a.CreateEnumType): a.Statement | nil

type PartialNil<T> = {
[P in keyof T]?: T[P] | nil;
};
/**

@@ -119,3 +124,3 @@ * An helper function that returns a copy of an object with modified properties

*/
export function assignChanged<T>(orig: T, assign: Partial<T>): T {
export function assignChanged<T>(orig: T, assign: PartialNil<T>): T {
let changed = false;

@@ -248,2 +253,8 @@ for (const k of Object.keys(assign)) {

return this.createMaterializedView(val);
case 'create schema':
return this.createSchema(val);
case 'raise':
return this.raise(val);
case 'comment':
return this.comment(val);
default:

@@ -254,2 +265,6 @@ throw NotSupported.never(val);

comment(val: a.CommentStatement): a.Statement | nil {
// not really supported :/
return val;
}

@@ -404,2 +419,14 @@ createView(val: a.CreateViewStatement): a.Statement | nil {

raise(val: a.RaiseStatement): a.Statement | nil {
return assignChanged(val, {
formatExprs: val.formatExprs && arrayNilMap(val.formatExprs, x => this.expr(x)),
using: val.using && arrayNilMap(val.using, u => {
return assignChanged(u, {
value: this.expr(u.value),
})
}),
});
}
delete(val: a.DeleteStatement): a.Statement | nil {

@@ -420,2 +447,5 @@ const from = this.tableRef(val.from);

createSchema(val: a.CreateSchemaStatement): a.Statement | nil {
return val;
}

@@ -422,0 +452,0 @@ createTable(val: a.CreateTableStatement): a.Statement | nil {

@@ -31,2 +31,5 @@ // import { IType } from '../../interfaces';

| DropIndexStatement
| CommentStatement
| CreateSchemaStatement
| RaiseStatement
| StartTransactionStatement) & {

@@ -36,2 +39,43 @@ [LOCATION]?: StatementLocation;

export interface CommentStatement {
type: 'comment';
comment: string;
/** This is not exhaustive compared to https://www.postgresql.org/docs/13/sql-comment.html
* But this is what's supported. File an issue if you want more.
*/
on: {
type: 'table' | 'database' | 'index' | 'materialized view' | 'trigger' | 'type' | 'view';
name: QName;
} | {
type: 'column';
column: QColumn;
};
}
export interface RaiseStatement {
type: 'raise';
level?: 'debug' | 'log' | 'info' | 'notice' | 'warning' | 'exception';
format: string;
formatExprs?: Expr[] | nil;
using?: {
type: 'message'
| 'detail'
| 'hint'
| 'errcode'
| 'column'
| 'constraint'
| 'datatype'
| 'table'
| 'schema';
value: Expr;
}[] | nil;
}
export interface CreateSchemaStatement {
type: 'create schema';
name: string;
ifNotExists?: boolean;
}
export interface PrepareStatement {

@@ -308,2 +352,8 @@ type: 'prepare';

export interface QColumn {
table: string;
column: string;
schema?: string;
}
export type DataTypeDef = ArrayDataTypeDef | BasicDataTypeDef;

@@ -702,7 +752,3 @@

cycle?: 'cycle' | 'no cycle';
ownedBy?: 'none' | {
table: string;
column: string;
schema?: string;
};
ownedBy?: 'none' | QColumn;
}

@@ -709,0 +755,0 @@

@@ -106,2 +106,103 @@ import 'mocha';

});
checkStatement(['create schema test'], {
type: 'create schema',
name: 'test',
});
checkStatement(['create schema if not exists test'], {
type: 'create schema',
name: 'test',
ifNotExists: true,
});
checkStatement(`RAISE 'message'`, {
type: 'raise',
format: 'message',
});
checkStatement(`RAISE NOTICE 'message'`, {
type: 'raise',
level: 'notice',
format: 'message',
});
checkStatement(`RAISE NOTICE 'message', 42`, {
type: 'raise',
level: 'notice',
format: 'message',
formatExprs: [{ type: 'integer', value: 42 }],
});
checkStatement(`RAISE NOTICE 'message', 2+2, 42`, {
type: 'raise',
level: 'notice',
format: 'message',
formatExprs: [{
type: 'binary',
op: '+',
left: { type: 'integer', value: 2 },
right: { type: 'integer', value: 2 },
}, { type: 'integer', value: 42 }],
});
checkStatement(`RAISE NOTICE 'message' USING hint='some hint'`, {
type: 'raise',
level: 'notice',
format: 'message',
using: [{
type: 'hint',
value: { type: 'string', value: 'some hint' },
}]
});
checkStatement(`RAISE WARNING 'message', 42 USING hint='some hint', message='some message'`, {
type: 'raise',
level: 'warning',
format: 'message',
formatExprs: [{ type: 'integer', value: 42 }],
using: [
{ type: 'hint', value: { type: 'string', value: 'some hint' }, },
{ type: 'message', value: { type: 'string', value: 'some message' }, },
],
});
checkStatement(`COMMENT ON TABLE groups is 'some text'`, {
type: 'comment',
comment: 'some text',
on: {
type: 'table',
name: { name: 'groups' }
}
})
checkStatement(`COMMENT ON TABLE public.groups is 'some text'`, {
type: 'comment',
comment: 'some text',
on: {
type: 'table',
name: { schema: 'public', name: 'groups', }
}
})
checkStatement(`COMMENT ON COLUMN groups.members is 'some text'`, {
type: 'comment',
comment: 'some text',
on: {
type: 'column',
column: { table: 'groups', column: 'members', }
}
})
checkStatement(`COMMENT ON COLUMN public.groups.members is 'some text'`, {
type: 'comment',
comment: 'some text',
on: {
type: 'column',
column: { schema: 'public', table: 'groups', column: 'members', }
}
})
});
import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper';
import { astVisitor, IAstVisitor, IAstFullVisitor } from './ast-visitor';
import { NotSupported, nil, ReplaceReturnType } from './utils';
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated } from './syntax/ast';
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated, QColumn } from './syntax/ast';
import { literal } from './pg-escape';

@@ -18,3 +18,3 @@

function list<T>(elems: T[], act: (e: T) => any, addParen = true) {
function list<T>(elems: T[], act: (e: T) => any, addParen: boolean) {
if (addParen) {

@@ -167,6 +167,3 @@ ret.push('(');

ret.push('OWNED BY ');
if (cs.ownedBy.schema) {
ret.push(name(cs.ownedBy.schema), '.');
}
ret.push(name(cs.ownedBy.table), '.', name(cs.ownedBy.column), ' ');
visitQColumn(cs.ownedBy);
}

@@ -183,2 +180,9 @@

function visitQColumn(col: QColumn) {
if (col.schema) {
ret.push(name(col.schema), '.');
}
ret.push(name(col.table), '.', name(col.column), ' ');
}
function join(m: IAstVisitor, j: JoinClause | nil, tbl: () => void) {

@@ -259,3 +263,3 @@ if (!j) {

ret.push(' AS ENUM ');
list(t.values, x => ret.push(literal(x)));
list(t.values, x => ret.push(literal(x)), true);
ret.push(' ');

@@ -295,3 +299,3 @@ },

array: v => {
list(v.expressions, e => m.expr(e));
list(v.expressions, e => m.expr(e), true);
},

@@ -333,3 +337,3 @@

}
list(v.args, e => m.expr(e));
list(v.args, e => m.expr(e), true);
},

@@ -394,2 +398,15 @@

comment: c => {
ret.push('COMMENT ON ', c.on.type.toUpperCase(), ' ');
switch (c.on.type) {
case 'column':
visitQColumn(c.on.column);
break;
default:
visitQualifiedName(c.on.name);
break;
}
ret.push(' IS ', literal(c.comment),' ');
},
extract: v => {

@@ -587,3 +604,3 @@ ret.push('EXTRACT (', v.field.toUpperCase(), ' FROM ');

}
});
}, true);
ret.push(' ');

@@ -610,2 +627,7 @@ },

createSchema: s => {
ret.push(s.ifNotExists ? 'CREATE SCHEMA IF NOT EXISTS ' : 'CREATE SCHEMA ');
ret.push(name(s.name));
},
truncateTable: t => {

@@ -681,3 +703,3 @@ ret.push('TRUNCATE TABLE ');

m.expr(e);
});
}, true);
}, false);

@@ -727,3 +749,3 @@ ret.push(') AS ', name(s.alias));

}
});
}, true);
}, false);

@@ -741,3 +763,3 @@ ret.push(' ');

if (i.onConflict.on) {
list(i.onConflict.on, e => m.expr(e));
list(i.onConflict.on, e => m.expr(e), true);
}

@@ -759,2 +781,23 @@ if (i.onConflict.do === 'do nothing') {

raise: r => {
ret.push('RAISE ');
if (r.level) {
ret.push(r.level.toUpperCase(), ' ');
}
ret.push(literal(r.format), ' ');
if (r.formatExprs?.length) {
ret.push(', ');
list(r.formatExprs, e => m.expr(e), false);
}
if (r.using?.length) {
ret.push(' USING ');
list(r.using, ({type, value}) => {
ret.push(type.toUpperCase(), '=');
m.expr(value);
}, false);
}
ret.push(' ');
},
member: e => {

@@ -761,0 +804,0 @@ m.expr(e.operand);

import { nil } from '../utils';
export declare const LOCATION: unique symbol;
export declare type Statement = (SelectStatement | CreateTableStatement | CreateSequenceStatement | CreateIndexStatement | CreateExtensionStatement | CommitStatement | InsertStatement | UpdateStatement | ShowStatement | PrepareStatement | DeleteStatement | WithStatement | RollbackStatement | TablespaceStatement | CreateViewStatement | CreateMaterializedViewStatement | AlterTableStatement | AlterSequenceStatement | SetGlobalStatement | SetTimezone | CreateEnumType | TruncateTableStatement | DropTableStatement | DropSequenceStatement | DropIndexStatement | StartTransactionStatement) & {
export declare type Statement = (SelectStatement | CreateTableStatement | CreateSequenceStatement | CreateIndexStatement | CreateExtensionStatement | CommitStatement | InsertStatement | UpdateStatement | ShowStatement | PrepareStatement | DeleteStatement | WithStatement | RollbackStatement | TablespaceStatement | CreateViewStatement | CreateMaterializedViewStatement | AlterTableStatement | AlterSequenceStatement | SetGlobalStatement | SetTimezone | CreateEnumType | TruncateTableStatement | DropTableStatement | DropSequenceStatement | DropIndexStatement | CommentStatement | CreateSchemaStatement | RaiseStatement | StartTransactionStatement) & {
[LOCATION]?: StatementLocation;
};
export interface CommentStatement {
type: 'comment';
comment: string;
/** This is not exhaustive compared to https://www.postgresql.org/docs/13/sql-comment.html
* But this is what's supported. File an issue if you want more.
*/
on: {
type: 'table' | 'database' | 'index' | 'materialized view' | 'trigger' | 'type' | 'view';
name: QName;
} | {
type: 'column';
column: QColumn;
};
}
export interface RaiseStatement {
type: 'raise';
level?: 'debug' | 'log' | 'info' | 'notice' | 'warning' | 'exception';
format: string;
formatExprs?: Expr[] | nil;
using?: {
type: 'message' | 'detail' | 'hint' | 'errcode' | 'column' | 'constraint' | 'datatype' | 'table' | 'schema';
value: Expr;
}[] | nil;
}
export interface CreateSchemaStatement {
type: 'create schema';
name: string;
ifNotExists?: boolean;
}
export interface PrepareStatement {

@@ -224,2 +253,7 @@ type: 'prepare';

}
export interface QColumn {
table: string;
column: string;
schema?: string;
}
export declare type DataTypeDef = ArrayDataTypeDef | BasicDataTypeDef;

@@ -501,7 +535,3 @@ export interface ArrayDataTypeDef {

cycle?: 'cycle' | 'no cycle';
ownedBy?: 'none' | {
table: string;
column: string;
schema?: string;
};
ownedBy?: 'none' | QColumn;
}

@@ -508,0 +538,0 @@ export interface AlterSequenceStatement extends QName {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc