sql-guard 0.1.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.
- package/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/analysis/functions.d.ts +3 -0
- package/dist/analysis/functions.d.ts.map +1 -0
- package/dist/analysis/relations.d.ts +3 -0
- package/dist/analysis/relations.d.ts.map +1 -0
- package/dist/cjs/index.cjs +1033 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/index.js +1001 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/normalize/identifier.d.ts +55 -0
- package/dist/normalize/identifier.d.ts.map +1 -0
- package/dist/normalize/qualified-name.d.ts +9 -0
- package/dist/normalize/qualified-name.d.ts.map +1 -0
- package/dist/parser/adapter.d.ts +30 -0
- package/dist/parser/adapter.d.ts.map +1 -0
- package/dist/parser/types.d.ts +73 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/policy/compile-policy.d.ts +20 -0
- package/dist/policy/compile-policy.d.ts.map +1 -0
- package/dist/policy/engine.d.ts +30 -0
- package/dist/policy/engine.d.ts.map +1 -0
- package/dist/policy/fail-closed.d.ts +8 -0
- package/dist/policy/fail-closed.d.ts.map +1 -0
- package/dist/policy/function.d.ts +44 -0
- package/dist/policy/function.d.ts.map +1 -0
- package/dist/policy/statement.d.ts +42 -0
- package/dist/policy/statement.d.ts.map +1 -0
- package/dist/types/public.d.ts +175 -0
- package/dist/types/public.d.ts.map +1 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sql-guard
|
|
3
|
+
*
|
|
4
|
+
* Validate AI-generated PostgreSQL queries against explicit table allowlists.
|
|
5
|
+
* This package parses SQL into an AST and denies anything outside your policy.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { validate, assertSafeSql, ErrorCode } from 'sql-guard';
|
|
10
|
+
*
|
|
11
|
+
* const policy = {
|
|
12
|
+
* allowedTables: ['public.users', 'public.orders'],
|
|
13
|
+
* allowedFunctions: ['count', 'lower'],
|
|
14
|
+
* };
|
|
15
|
+
*
|
|
16
|
+
* // Non-throwing validation
|
|
17
|
+
* const result = validate('SELECT * FROM public.users', policy);
|
|
18
|
+
* if (!result.ok) {
|
|
19
|
+
* console.log('Denied:', result.errorCode);
|
|
20
|
+
* console.log('Violations:', result.violations);
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Throwing validation
|
|
24
|
+
* assertSafeSql('SELECT lower(u.email) FROM public.users u', policy);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
import { ErrorCode, SqlValidationError } from './types/public';
|
|
30
|
+
import type { Policy, ValidationResult } from './types/public';
|
|
31
|
+
/**
|
|
32
|
+
* Validates SQL against a policy.
|
|
33
|
+
*
|
|
34
|
+
* Parses the SQL and checks it against the policy rules. Returns a result object
|
|
35
|
+
* indicating whether the SQL is allowed and any violations found.
|
|
36
|
+
*
|
|
37
|
+
* This function never throws. All errors are captured in the returned ValidationResult.
|
|
38
|
+
*
|
|
39
|
+
* @param sql - The SQL query to validate
|
|
40
|
+
* @param policy - The policy defining allowed tables, statements, etc.
|
|
41
|
+
* @returns ValidationResult with ok status and any violations
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const result = validate('SELECT * FROM public.users', {
|
|
46
|
+
* allowedTables: ['public.users'],
|
|
47
|
+
* allowedFunctions: ['count']
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* if (result.ok) {
|
|
51
|
+
* console.log('Query is safe');
|
|
52
|
+
* } else {
|
|
53
|
+
* console.log('Blocked:', result.errorCode);
|
|
54
|
+
* console.log('Reason:', result.violations[0]?.message);
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function validate(sql: string, policy: Policy): ValidationResult;
|
|
59
|
+
/**
|
|
60
|
+
* Validates SQL and throws SqlValidationError if invalid.
|
|
61
|
+
*
|
|
62
|
+
* Same as {@link validate} but throws an exception on validation failure
|
|
63
|
+
* instead of returning a result object. Useful for fail-fast scenarios.
|
|
64
|
+
*
|
|
65
|
+
* @param sql - The SQL query to validate
|
|
66
|
+
* @param policy - The policy defining allowed tables, statements, etc.
|
|
67
|
+
* @throws SqlValidationError if validation fails
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* try {
|
|
72
|
+
* assertSafeSql('SELECT * FROM public.users', policy);
|
|
73
|
+
* // Query is safe, proceed with execution
|
|
74
|
+
* } catch (err) {
|
|
75
|
+
* if (err instanceof SqlValidationError) {
|
|
76
|
+
* console.error('Query blocked:', err.code);
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function assertSafeSql(sql: string, policy: Policy): void;
|
|
82
|
+
export { ErrorCode, SqlValidationError };
|
|
83
|
+
export type { Policy, ValidationResult, TableIdentifierMatching } from './types/public';
|
|
84
|
+
export type { Violation } from './types/public';
|
|
85
|
+
export { parseSql } from './parser/adapter';
|
|
86
|
+
export type { ParseResult, ParsedStatement, TableReference, FunctionCall } from './parser/types';
|
|
87
|
+
export { normalizeTableReference, isTableAllowed } from './normalize/identifier';
|
|
88
|
+
export type { NormalizedTable, NormalizationResult } from './normalize/identifier';
|
|
89
|
+
export { isStatementAllowed, checkMultiStatementPolicy } from './policy/statement';
|
|
90
|
+
export type { StatementCheckResult, StatementType } from './policy/statement';
|
|
91
|
+
export { extractAllTables } from './analysis/relations';
|
|
92
|
+
export { extractAllFunctions } from './analysis/functions';
|
|
93
|
+
export { checkFunctionsAllowed } from './policy/function';
|
|
94
|
+
export type { FunctionCheckResult } from './policy/function';
|
|
95
|
+
export { validateAgainstPolicy } from './policy/engine';
|
|
96
|
+
export type { EngineResult } from './policy/engine';
|
|
97
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAEtE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAS/D;AAGD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;AACzC,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACxF,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACjF,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACnF,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier Normalization
|
|
3
|
+
*
|
|
4
|
+
* Utilities for normalizing table references and checking them against allowlists.
|
|
5
|
+
* Handles schema qualification, quoted identifiers, and resolver callbacks.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { Policy, TableIdentifierMatching } from '../types/public';
|
|
10
|
+
import type { TableReference } from '../parser/types';
|
|
11
|
+
/**
|
|
12
|
+
* A normalized, schema-qualified table reference.
|
|
13
|
+
*/
|
|
14
|
+
export interface NormalizedTable {
|
|
15
|
+
/** Schema name (e.g., 'public') */
|
|
16
|
+
schema: string;
|
|
17
|
+
/** Table name */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Fully qualified name in format 'schema.name' */
|
|
20
|
+
fullyQualified: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result of normalizing a table reference.
|
|
24
|
+
*/
|
|
25
|
+
export interface NormalizationResult {
|
|
26
|
+
/** Whether normalization succeeded */
|
|
27
|
+
success: boolean;
|
|
28
|
+
/** The normalized table (only present if success is true) */
|
|
29
|
+
table?: NormalizedTable;
|
|
30
|
+
/** Error message (only present if success is false) */
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Normalize a table reference using the policy's resolver if needed.
|
|
35
|
+
*
|
|
36
|
+
* For schema-qualified references (e.g., `public.users`), extracts the schema
|
|
37
|
+
* and name directly. For unqualified references (e.g., `users`), uses the
|
|
38
|
+
* policy's resolver function to map to a fully qualified name.
|
|
39
|
+
*
|
|
40
|
+
* @param ref - The table reference from the parser
|
|
41
|
+
* @param policy - The policy containing the resolver
|
|
42
|
+
* @returns NormalizationResult with the normalized table or an error
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeTableReference(ref: TableReference, policy: Policy, mode?: TableIdentifierMatching): NormalizationResult;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a normalized table is in the allowlist.
|
|
47
|
+
*
|
|
48
|
+
* Performs case-insensitive comparison against the allowed tables.
|
|
49
|
+
*
|
|
50
|
+
* @param normalized - The normalized table to check
|
|
51
|
+
* @param allowedTables - Iterable of allowed table names (schema-qualified)
|
|
52
|
+
* @returns True if the table is allowed
|
|
53
|
+
*/
|
|
54
|
+
export declare function isTableAllowed(normalized: NormalizedTable, allowedTables: Iterable<string>, mode?: TableIdentifierMatching): boolean;
|
|
55
|
+
//# sourceMappingURL=identifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier.d.ts","sourceRoot":"","sources":["../../src/normalize/identifier.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,uBAAoE,GACzE,mBAAmB,CAmDrB;AAcD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,eAAe,EAC3B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC/B,IAAI,GAAE,uBAAkC,GACvC,OAAO,CAcT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableIdentifierMatching } from "../types/public";
|
|
2
|
+
export interface QualifiedNameParts {
|
|
3
|
+
schema: string;
|
|
4
|
+
name: string;
|
|
5
|
+
fullyQualified: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseQualifiedName(value: unknown, mode?: TableIdentifierMatching): QualifiedNameParts | null;
|
|
8
|
+
export declare function canonicalizeIdentifier(value: string, mode: TableIdentifierMatching): string;
|
|
9
|
+
//# sourceMappingURL=qualified-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qualified-name.d.ts","sourceRoot":"","sources":["../../src/normalize/qualified-name.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,uBAAkC,GACvC,kBAAkB,GAAG,IAAI,CA2B3B;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,uBAAuB,GAC5B,MAAM,CAGR"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Parser Adapter
|
|
3
|
+
*
|
|
4
|
+
* Wraps node-sql-parser to parse PostgreSQL SQL into an AST.
|
|
5
|
+
* Extracts tables and functions for policy validation.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { ParseResult } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Parse a SQL string into an AST.
|
|
12
|
+
*
|
|
13
|
+
* Parses the SQL and extracts tables, functions, and statement types.
|
|
14
|
+
* Returns a structured result that can be used for policy validation.
|
|
15
|
+
*
|
|
16
|
+
* @param sql - The SQL query to parse
|
|
17
|
+
* @param dialect - SQL dialect to use (defaults to 'postgresql')
|
|
18
|
+
* @returns ParseResult with success status and parsed statements or error info
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = parseSql('SELECT * FROM public.users');
|
|
23
|
+
* if (result.success) {
|
|
24
|
+
* console.log('Tables:', result.statements[0].tables);
|
|
25
|
+
* console.log('Functions:', result.statements[0].functions);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseSql(sql: string, dialect?: 'postgresql'): ParseResult;
|
|
30
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/parser/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAC;AAMvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,YAA2B,GAAG,WAAW,CAmBvF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for parsed SQL statements, tables, and function calls.
|
|
3
|
+
* These types represent the AST (Abstract Syntax Tree) produced by the SQL parser.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A parsed SQL statement with extracted metadata.
|
|
9
|
+
* Contains the statement type, referenced tables, and function calls.
|
|
10
|
+
*/
|
|
11
|
+
export interface ParsedStatement {
|
|
12
|
+
/** The type of SQL statement (select, insert, update, delete, or unknown) */
|
|
13
|
+
type: 'select' | 'insert' | 'update' | 'delete' | 'unknown';
|
|
14
|
+
/** Tables referenced in this statement */
|
|
15
|
+
tables: TableReference[];
|
|
16
|
+
/** Function calls in this statement */
|
|
17
|
+
functions: FunctionCall[];
|
|
18
|
+
/** Raw AST from the parser (internal use) */
|
|
19
|
+
raw: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reference to a table in a SQL query.
|
|
23
|
+
* May be schema-qualified or unqualified.
|
|
24
|
+
*/
|
|
25
|
+
export interface TableReference {
|
|
26
|
+
/** Schema name (e.g., 'public'). Undefined for unqualified tables. */
|
|
27
|
+
schema?: string;
|
|
28
|
+
/** Table name */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Table alias, if specified (e.g., 'u' in `FROM users u`) */
|
|
31
|
+
alias?: string;
|
|
32
|
+
/** Source location in the SQL string */
|
|
33
|
+
location?: {
|
|
34
|
+
line: number;
|
|
35
|
+
column: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reference to a function call in a SQL query.
|
|
40
|
+
*/
|
|
41
|
+
export interface FunctionCall {
|
|
42
|
+
/** Function name */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Schema name (e.g., 'pg_catalog'). Undefined for unqualified functions. */
|
|
45
|
+
schema?: string;
|
|
46
|
+
/** Source location in the SQL string */
|
|
47
|
+
location?: {
|
|
48
|
+
line: number;
|
|
49
|
+
column: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Result of parsing a SQL string.
|
|
54
|
+
* On success, contains the parsed statements.
|
|
55
|
+
* On failure, contains error information.
|
|
56
|
+
*/
|
|
57
|
+
export interface ParseResult {
|
|
58
|
+
/** Whether parsing succeeded */
|
|
59
|
+
success: boolean;
|
|
60
|
+
/** Parsed statements (empty if success is false) */
|
|
61
|
+
statements: ParsedStatement[];
|
|
62
|
+
/** Error information (only present if success is false) */
|
|
63
|
+
error?: {
|
|
64
|
+
/** Error message from the parser */
|
|
65
|
+
message: string;
|
|
66
|
+
/** Location where the error occurred, if available */
|
|
67
|
+
location?: {
|
|
68
|
+
line: number;
|
|
69
|
+
column: number;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/parser/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC5D,0CAA0C;IAC1C,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,uCAAuC;IACvC,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,6CAA6C;IAC7C,GAAG,EAAE,OAAO,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,2DAA2D;IAC3D,KAAK,CAAC,EAAE;QACN,oCAAoC;QACpC,OAAO,EAAE,MAAM,CAAC;QAChB,sDAAsD;QACtD,QAAQ,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;KAC7C,CAAC;CACH"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ErrorCode } from '../types/public';
|
|
2
|
+
import type { Policy, TableIdentifierMatching, Violation } from '../types/public';
|
|
3
|
+
export interface CompiledPolicy {
|
|
4
|
+
allowedTables: Set<string>;
|
|
5
|
+
allowedFunctionsUnqualified: Set<string>;
|
|
6
|
+
allowedFunctionsQualified: Set<string>;
|
|
7
|
+
tableIdentifierMatching: TableIdentifierMatching;
|
|
8
|
+
}
|
|
9
|
+
type CompilePolicyResult = {
|
|
10
|
+
success: true;
|
|
11
|
+
compiled: CompiledPolicy;
|
|
12
|
+
} | {
|
|
13
|
+
success: false;
|
|
14
|
+
errorCode: ErrorCode.INVALID_POLICY;
|
|
15
|
+
violation: Violation;
|
|
16
|
+
};
|
|
17
|
+
export declare function compilePolicy(policy: Policy): CompilePolicyResult;
|
|
18
|
+
export declare function canonicalizeQualifiedName(value: unknown, mode?: TableIdentifierMatching): string | null;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=compile-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-policy.d.ts","sourceRoot":"","sources":["../../src/policy/compile-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,2BAA2B,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzC,yBAAyB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,uBAAuB,EAAE,uBAAuB,CAAC;CAClD;AAED,KAAK,mBAAmB,GACpB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,GAC3C;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC,cAAc,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAElF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB,CAwDjE;AA2BD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,uBAAkC,GACvC,MAAM,GAAG,IAAI,CAGf"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy Validation Engine
|
|
3
|
+
*
|
|
4
|
+
* Core validation logic that orchestrates parsing, policy compilation,
|
|
5
|
+
* and violation detection.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { ErrorCode } from '../types/public';
|
|
10
|
+
import type { Policy, ValidationResult, Violation } from '../types/public';
|
|
11
|
+
/**
|
|
12
|
+
* Internal result type used during validation.
|
|
13
|
+
*/
|
|
14
|
+
export interface EngineResult {
|
|
15
|
+
ok: boolean;
|
|
16
|
+
violations: Violation[];
|
|
17
|
+
errorCode?: ErrorCode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate a SQL query against a policy.
|
|
21
|
+
*
|
|
22
|
+
* This is the main validation function used by {@link validate}.
|
|
23
|
+
* It compiles the policy, parses the SQL, and checks all constraints.
|
|
24
|
+
*
|
|
25
|
+
* @param sql - The SQL query to validate
|
|
26
|
+
* @param policy - The policy to validate against
|
|
27
|
+
* @returns ValidationResult indicating success or failure with violations
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateAgainstPolicy(sql: string, policy: Policy): ValidationResult;
|
|
30
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/policy/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAID;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,CA0JnF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ErrorCode } from '../types/public';
|
|
2
|
+
export interface UnsupportedCheckResult {
|
|
3
|
+
supported: boolean;
|
|
4
|
+
errorCode?: ErrorCode.UNSUPPORTED_SQL_FEATURE;
|
|
5
|
+
errorMessage?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function checkUnsupportedFeatures(ast: unknown): UnsupportedCheckResult;
|
|
8
|
+
//# sourceMappingURL=fail-closed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fail-closed.d.ts","sourceRoot":"","sources":["../../src/policy/fail-closed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,SAAS,CAAC,uBAAuB,CAAC;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAoCD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,sBAAsB,CAsD7E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function Policy Validation
|
|
3
|
+
*
|
|
4
|
+
* Validates function calls against policy allowlists.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { FunctionCall } from '../parser/types';
|
|
9
|
+
import { ErrorCode } from '../types/public';
|
|
10
|
+
import type { CompiledPolicy } from './compile-policy';
|
|
11
|
+
import type { Policy } from '../types/public';
|
|
12
|
+
/**
|
|
13
|
+
* Result of checking if functions are allowed.
|
|
14
|
+
*/
|
|
15
|
+
export interface FunctionCheckResult {
|
|
16
|
+
/** Whether all functions are allowed */
|
|
17
|
+
allowed: boolean;
|
|
18
|
+
/** Error code if any function is not allowed */
|
|
19
|
+
errorCode?: ErrorCode;
|
|
20
|
+
/** Human-readable error message */
|
|
21
|
+
errorMessage?: string;
|
|
22
|
+
/** List of disallowed functions */
|
|
23
|
+
violations: Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
schema?: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if functions in a parsed statement are allowed by the policy.
|
|
30
|
+
*
|
|
31
|
+
* @param functions - Array of function calls from the parser
|
|
32
|
+
* @param policy - The policy containing allowed functions
|
|
33
|
+
* @returns FunctionCheckResult indicating if all functions are allowed
|
|
34
|
+
*/
|
|
35
|
+
export declare function checkFunctionsAllowed(functions: FunctionCall[], policy: Policy): FunctionCheckResult;
|
|
36
|
+
/**
|
|
37
|
+
* Check if functions are allowed using a compiled policy.
|
|
38
|
+
*
|
|
39
|
+
* @param functions - Array of function calls from the parser
|
|
40
|
+
* @param policy - The compiled policy containing function allowlists
|
|
41
|
+
* @returns FunctionCheckResult indicating if all functions are allowed
|
|
42
|
+
*/
|
|
43
|
+
export declare function checkFunctionsAllowedCompiled(functions: FunctionCall[], policy: CompiledPolicy): FunctionCheckResult;
|
|
44
|
+
//# sourceMappingURL=function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/policy/function.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mCAAmC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,YAAY,EAAE,EACzB,MAAM,EAAE,MAAM,GACb,mBAAmB,CAGrB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,YAAY,EAAE,EACzB,MAAM,EAAE,cAAc,GACrB,mBAAmB,CAKrB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Statement Policy Validation
|
|
3
|
+
*
|
|
4
|
+
* Validates SQL statement types against policy restrictions.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { ParsedStatement } from '../parser/types';
|
|
9
|
+
import { ErrorCode } from '../types/public';
|
|
10
|
+
import type { Policy } from '../types/public';
|
|
11
|
+
/**
|
|
12
|
+
* Result of checking if a statement type is allowed.
|
|
13
|
+
*/
|
|
14
|
+
export interface StatementCheckResult {
|
|
15
|
+
/** Whether the statement type is allowed */
|
|
16
|
+
allowed: boolean;
|
|
17
|
+
/** Error code if not allowed */
|
|
18
|
+
errorCode?: ErrorCode;
|
|
19
|
+
/** Human-readable error message */
|
|
20
|
+
errorMessage?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Supported SQL statement types.
|
|
24
|
+
*/
|
|
25
|
+
export type StatementType = 'select' | 'insert' | 'update' | 'delete';
|
|
26
|
+
/**
|
|
27
|
+
* Check if a statement type is allowed by the policy.
|
|
28
|
+
*
|
|
29
|
+
* @param statement - The parsed statement to check
|
|
30
|
+
* @param policy - The policy defining allowed statement types
|
|
31
|
+
* @returns StatementCheckResult indicating if the statement is allowed
|
|
32
|
+
*/
|
|
33
|
+
export declare function isStatementAllowed(statement: ParsedStatement, policy: Policy): StatementCheckResult;
|
|
34
|
+
/**
|
|
35
|
+
* Check if multiple statements are allowed by the policy.
|
|
36
|
+
*
|
|
37
|
+
* @param statements - Array of parsed statements
|
|
38
|
+
* @param policy - The policy defining whether multiple statements are allowed
|
|
39
|
+
* @returns StatementCheckResult indicating if multiple statements are allowed
|
|
40
|
+
*/
|
|
41
|
+
export declare function checkMultiStatementPolicy(statements: ParsedStatement[], policy: Policy): StatementCheckResult;
|
|
42
|
+
//# sourceMappingURL=statement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statement.d.ts","sourceRoot":"","sources":["../../src/policy/statement.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,gCAAgC;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mCAAmC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,MAAM,GACb,oBAAoB,CAsBtB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,eAAe,EAAE,EAC7B,MAAM,EAAE,MAAM,GACb,oBAAoB,CAYtB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes returned by the validator when SQL queries fail validation.
|
|
3
|
+
* Used to identify the specific reason a query was rejected.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { validate, ErrorCode } from 'sql-guard';
|
|
8
|
+
*
|
|
9
|
+
* const result = validate('SELECT * FROM secret_table', { allowedTables: ['public.users'] });
|
|
10
|
+
* if (result.errorCode === ErrorCode.TABLE_NOT_ALLOWED) {
|
|
11
|
+
* console.log('Query tried to access unauthorized table');
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare enum ErrorCode {
|
|
16
|
+
/** SQL could not be parsed into an AST */
|
|
17
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
18
|
+
/** Parsed SQL contains features outside the supported subset (fail closed) */
|
|
19
|
+
UNSUPPORTED_SQL_FEATURE = "UNSUPPORTED_SQL_FEATURE",
|
|
20
|
+
/** A referenced table is not in the policy allowlist */
|
|
21
|
+
TABLE_NOT_ALLOWED = "TABLE_NOT_ALLOWED",
|
|
22
|
+
/** Statement type (e.g., INSERT, UPDATE) is not allowed by the policy */
|
|
23
|
+
STATEMENT_NOT_ALLOWED = "STATEMENT_NOT_ALLOWED",
|
|
24
|
+
/** A function call is not in the policy allowlist */
|
|
25
|
+
FUNCTION_NOT_ALLOWED = "FUNCTION_NOT_ALLOWED",
|
|
26
|
+
/** Query contains multiple statements while allowMultiStatement is disabled */
|
|
27
|
+
MULTI_STATEMENT_DISABLED = "MULTI_STATEMENT_DISABLED",
|
|
28
|
+
/** Policy configuration is invalid */
|
|
29
|
+
INVALID_POLICY = "INVALID_POLICY"
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Controls how table identifiers are matched against policy allowlists.
|
|
33
|
+
*
|
|
34
|
+
* - `strict`: exact case-sensitive matching (security-first default).
|
|
35
|
+
* - `caseInsensitive`: case-insensitive matching.
|
|
36
|
+
*/
|
|
37
|
+
export type TableIdentifierMatching = "strict" | "caseInsensitive";
|
|
38
|
+
/**
|
|
39
|
+
* Policy configuration that defines what SQL is allowed.
|
|
40
|
+
* Used with {@link validate} and {@link assertSafeSql} to enforce query restrictions.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const policy: Policy = {
|
|
45
|
+
* allowedTables: ['public.users', 'public.orders'],
|
|
46
|
+
* allowedStatements: ['select'],
|
|
47
|
+
* allowedFunctions: ['count', 'lower'],
|
|
48
|
+
* allowMultiStatement: false,
|
|
49
|
+
* resolver: (name) => name === 'users' ? 'public.users' : null
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export interface Policy {
|
|
54
|
+
/**
|
|
55
|
+
* List of allowed tables in schema-qualified format (e.g., 'public.users').
|
|
56
|
+
* All tables referenced in SQL must be in this list.
|
|
57
|
+
* @remarks Required field
|
|
58
|
+
*/
|
|
59
|
+
allowedTables: string[];
|
|
60
|
+
/**
|
|
61
|
+
* List of allowed SQL statement types.
|
|
62
|
+
* Defaults to `['select']` if not specified.
|
|
63
|
+
* @default ['select']
|
|
64
|
+
*/
|
|
65
|
+
allowedStatements?: ("select" | "insert" | "update" | "delete")[];
|
|
66
|
+
/**
|
|
67
|
+
* Whether to allow multiple statements in a single query (e.g., `SELECT 1; SELECT 2`).
|
|
68
|
+
* Defaults to `false` for security.
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
allowMultiStatement?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* List of allowed functions. Functions not in this list will be rejected.
|
|
74
|
+
* Use unqualified names (e.g., 'lower') to match unqualified calls.
|
|
75
|
+
* Use qualified names (e.g., 'pg_catalog.current_database') to match qualified calls.
|
|
76
|
+
* @default []
|
|
77
|
+
*/
|
|
78
|
+
allowedFunctions?: string[];
|
|
79
|
+
/**
|
|
80
|
+
* Table identifier matching mode used for allowlist checks.
|
|
81
|
+
* `strict` is the secure default and preserves case distinctions.
|
|
82
|
+
* `caseInsensitive` enables case-insensitive behavior.
|
|
83
|
+
* @default 'strict'
|
|
84
|
+
*/
|
|
85
|
+
tableIdentifierMatching?: TableIdentifierMatching;
|
|
86
|
+
/**
|
|
87
|
+
* Optional resolver function to map unqualified table names to schema-qualified names.
|
|
88
|
+
* Return the fully qualified table name (e.g., 'public.users') or null to deny.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* resolver: (name) => {
|
|
93
|
+
* if (name === 'users') return 'public.users';
|
|
94
|
+
* if (name === 'orders') return 'public.orders';
|
|
95
|
+
* return null; // Deny unknown tables
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
resolver?: (unqualified: string) => string | null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Result of validating a SQL query against a policy.
|
|
103
|
+
* Returned by {@link validate}.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const result = validate('SELECT * FROM public.users', policy);
|
|
108
|
+
* if (result.ok) {
|
|
109
|
+
* console.log('Query is safe');
|
|
110
|
+
* } else {
|
|
111
|
+
* console.log('Violations:', result.violations);
|
|
112
|
+
* console.log('Error code:', result.errorCode);
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export interface ValidationResult {
|
|
117
|
+
/** Whether the SQL passed all policy checks */
|
|
118
|
+
ok: boolean;
|
|
119
|
+
/** List of violations found during validation (empty if ok is true) */
|
|
120
|
+
violations: Violation[];
|
|
121
|
+
/** Error code categorizing why validation failed (undefined if ok is true) */
|
|
122
|
+
errorCode?: ErrorCode;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A single violation found during SQL validation.
|
|
126
|
+
* Part of the {@link ValidationResult.violations} array.
|
|
127
|
+
*/
|
|
128
|
+
export interface Violation {
|
|
129
|
+
/** Type of violation */
|
|
130
|
+
type: "table" | "statement" | "function" | "parse" | "unsupported" | "policy";
|
|
131
|
+
/** Human-readable description of the violation */
|
|
132
|
+
message: string;
|
|
133
|
+
/**
|
|
134
|
+
* Source location where the violation occurred, if available.
|
|
135
|
+
* Line and column numbers are 1-indexed.
|
|
136
|
+
*/
|
|
137
|
+
location?: {
|
|
138
|
+
line?: number;
|
|
139
|
+
column?: number;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Error thrown by {@link assertSafeSql} when validation fails.
|
|
144
|
+
* Extends the standard Error class with additional context.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* try {
|
|
149
|
+
* assertSafeSql('SELECT * FROM secret_table', policy);
|
|
150
|
+
* } catch (err) {
|
|
151
|
+
* if (err instanceof SqlValidationError) {
|
|
152
|
+
* console.log('Error code:', err.code);
|
|
153
|
+
* console.log('Violations:', err.violations);
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare class SqlValidationError extends Error {
|
|
159
|
+
/** Error code indicating the type of validation failure */
|
|
160
|
+
readonly code: ErrorCode;
|
|
161
|
+
/** Detailed violations that caused the failure */
|
|
162
|
+
readonly violations: Violation[];
|
|
163
|
+
/**
|
|
164
|
+
* Creates a new SqlValidationError.
|
|
165
|
+
* @param message - Error message
|
|
166
|
+
* @param code - Error code categorizing the failure
|
|
167
|
+
* @param violations - Array of specific violations found
|
|
168
|
+
*/
|
|
169
|
+
constructor(message: string,
|
|
170
|
+
/** Error code indicating the type of validation failure */
|
|
171
|
+
code: ErrorCode,
|
|
172
|
+
/** Detailed violations that caused the failure */
|
|
173
|
+
violations: Violation[]);
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/types/public.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,oBAAY,SAAS;IACnB,0CAA0C;IAC1C,WAAW,gBAAgB;IAC3B,8EAA8E;IAC9E,uBAAuB,4BAA4B;IACnD,wDAAwD;IACxD,iBAAiB,sBAAsB;IACvC,yEAAyE;IACzE,qBAAqB,0BAA0B;IAC/C,qDAAqD;IACrD,oBAAoB,yBAAyB;IAC7C,+EAA+E;IAC/E,wBAAwB,6BAA6B;IACrD,sCAAsC;IACtC,cAAc,mBAAmB;CAClC;AAED;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,iBAAiB,CAAC;AAEnE;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,aAAa,EAAE,MAAM,EAAE,CAAC;IAExB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC,EAAE,CAAC;IAElE;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE5B;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAElD;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACnD;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,EAAE,EAAE,OAAO,CAAC;IACZ,uEAAuE;IACvE,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,wBAAwB;IACxB,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,aAAa,GAAG,QAAQ,CAAC;IAC9E,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IASzC,2DAA2D;aAC3C,IAAI,EAAE,SAAS;IAC/B,kDAAkD;aAClC,UAAU,EAAE,SAAS,EAAE;IAXzC;;;;;OAKG;gBAED,OAAO,EAAE,MAAM;IACf,2DAA2D;IAC3C,IAAI,EAAE,SAAS;IAC/B,kDAAkD;IAClC,UAAU,EAAE,SAAS,EAAE;CAK1C"}
|