rawsql-ts 0.10.8-beta → 0.11.0-beta
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/README.md +174 -44
- package/dist/esm/index.js +30 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.min.js +16 -14
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.js +4 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/transformers/DynamicQueryBuilder.js +155 -0
- package/dist/esm/src/transformers/DynamicQueryBuilder.js.map +1 -0
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js +16 -12
- package/dist/esm/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/SqlFormatter.js +1 -2
- package/dist/esm/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/src/transformers/TypeTransformationPostProcessor.js +342 -0
- package/dist/esm/src/transformers/TypeTransformationPostProcessor.js.map +1 -0
- package/dist/esm/src/transformers/UnifiedJsonMapping.js +59 -0
- package/dist/esm/src/transformers/UnifiedJsonMapping.js.map +1 -0
- package/dist/esm/src/utils/JsonSchemaValidator.js +211 -0
- package/dist/esm/src/utils/JsonSchemaValidator.js.map +1 -0
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/esm/types/src/index.d.ts +4 -0
- package/dist/esm/types/src/transformers/DynamicQueryBuilder.d.ts +108 -0
- package/dist/esm/types/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -1
- package/dist/esm/types/src/transformers/SqlFormatter.d.ts +2 -3
- package/dist/esm/types/src/transformers/TypeTransformationPostProcessor.d.ts +108 -0
- package/dist/esm/types/src/transformers/UnifiedJsonMapping.d.ts +54 -0
- package/dist/esm/types/src/utils/JsonSchemaValidator.d.ts +81 -0
- package/dist/index.min.js +16 -14
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/transformers/DynamicQueryBuilder.d.ts +108 -0
- package/dist/src/transformers/DynamicQueryBuilder.js +159 -0
- package/dist/src/transformers/DynamicQueryBuilder.js.map +1 -0
- package/dist/src/transformers/PostgresJsonQueryBuilder.d.ts +3 -1
- package/dist/src/transformers/PostgresJsonQueryBuilder.js +16 -12
- package/dist/src/transformers/PostgresJsonQueryBuilder.js.map +1 -1
- package/dist/src/transformers/SqlFormatter.d.ts +2 -3
- package/dist/src/transformers/SqlFormatter.js +1 -2
- package/dist/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/src/transformers/TypeTransformationPostProcessor.d.ts +108 -0
- package/dist/src/transformers/TypeTransformationPostProcessor.js +351 -0
- package/dist/src/transformers/TypeTransformationPostProcessor.js.map +1 -0
- package/dist/src/transformers/UnifiedJsonMapping.d.ts +54 -0
- package/dist/src/transformers/UnifiedJsonMapping.js +62 -0
- package/dist/src/transformers/UnifiedJsonMapping.js.map +1 -0
- package/dist/src/utils/JsonSchemaValidator.d.ts +81 -0
- package/dist/src/utils/JsonSchemaValidator.js +215 -0
- package/dist/src/utils/JsonSchemaValidator.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -4
package/dist/src/index.d.ts
CHANGED
|
@@ -14,10 +14,14 @@ export * from './transformers/SelectValueCollector';
|
|
|
14
14
|
export * from './transformers/SelectableColumnCollector';
|
|
15
15
|
export * from './transformers/TableColumnResolver';
|
|
16
16
|
export * from './transformers/TableSourceCollector';
|
|
17
|
+
export * from './transformers/UnifiedJsonMapping';
|
|
17
18
|
export * from './transformers/UpstreamSelectQueryFinder';
|
|
19
|
+
export * from './transformers/TypeTransformationPostProcessor';
|
|
18
20
|
export * from './transformers/SchemaCollector';
|
|
19
21
|
export * from './transformers/SqlParamInjector';
|
|
20
22
|
export * from './transformers/SqlSortInjector';
|
|
21
23
|
export * from './transformers/SqlPaginationInjector';
|
|
24
|
+
export * from './transformers/DynamicQueryBuilder';
|
|
22
25
|
export * from './utils/SqlSchemaValidator';
|
|
26
|
+
export * from './utils/JsonSchemaValidator';
|
|
23
27
|
export * from './utils/SchemaManager';
|
package/dist/src/index.js
CHANGED
|
@@ -31,12 +31,16 @@ __exportStar(require("./transformers/SelectValueCollector"), exports);
|
|
|
31
31
|
__exportStar(require("./transformers/SelectableColumnCollector"), exports);
|
|
32
32
|
__exportStar(require("./transformers/TableColumnResolver"), exports);
|
|
33
33
|
__exportStar(require("./transformers/TableSourceCollector"), exports);
|
|
34
|
+
__exportStar(require("./transformers/UnifiedJsonMapping"), exports);
|
|
34
35
|
__exportStar(require("./transformers/UpstreamSelectQueryFinder"), exports);
|
|
36
|
+
__exportStar(require("./transformers/TypeTransformationPostProcessor"), exports);
|
|
35
37
|
__exportStar(require("./transformers/SchemaCollector"), exports);
|
|
36
38
|
__exportStar(require("./transformers/SqlParamInjector"), exports);
|
|
37
39
|
__exportStar(require("./transformers/SqlSortInjector"), exports);
|
|
38
40
|
__exportStar(require("./transformers/SqlPaginationInjector"), exports);
|
|
41
|
+
__exportStar(require("./transformers/DynamicQueryBuilder"), exports);
|
|
39
42
|
__exportStar(require("./utils/SqlSchemaValidator"), exports);
|
|
43
|
+
__exportStar(require("./utils/JsonSchemaValidator"), exports);
|
|
40
44
|
__exportStar(require("./utils/SchemaManager"), exports);
|
|
41
45
|
// Add more exports here if you want to expose additional public API
|
|
42
46
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAC5C,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,8DAA4C;AAC5C,0EAAwD;AACxD,8DAA4C,CAAC,0BAA0B;AACvE,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,2EAAyD;AACzD,iEAA+C;AAC/C,kEAAgD;AAChD,iEAA+C;AAC/C,uEAAqD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAC5C,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,8DAA4C;AAC5C,0EAAwD;AACxD,8DAA4C,CAAC,0BAA0B;AACvE,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,oEAAkD;AAClD,2EAAyD;AACzD,iFAA+D;AAE/D,iEAA+C;AAC/C,kEAAgD;AAChD,iEAA+C;AAC/C,uEAAqD;AACrD,qEAAmD;AAEnD,6DAA2C;AAC3C,8DAA4C;AAC5C,wDAAsC;AACtC,oEAAoE"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { SelectQuery } from "../models/SelectQuery";
|
|
2
|
+
import { SortConditions } from "./SqlSortInjector";
|
|
3
|
+
import { PaginationOptions } from "./SqlPaginationInjector";
|
|
4
|
+
import { JsonMapping } from "./PostgresJsonQueryBuilder";
|
|
5
|
+
/**
|
|
6
|
+
* Options for dynamic query building
|
|
7
|
+
*/
|
|
8
|
+
export interface QueryBuildOptions {
|
|
9
|
+
/** Filter conditions to inject into WHERE clause */
|
|
10
|
+
filter?: Record<string, any>;
|
|
11
|
+
/** Sort conditions to inject into ORDER BY clause */
|
|
12
|
+
sort?: SortConditions;
|
|
13
|
+
/** Pagination options to inject LIMIT/OFFSET clauses */
|
|
14
|
+
paging?: PaginationOptions;
|
|
15
|
+
/** JSON serialization mapping to transform results into hierarchical JSON
|
|
16
|
+
* - JsonMapping object: explicit mapping configuration
|
|
17
|
+
* - true: auto-load mapping from corresponding .json file
|
|
18
|
+
* - false/undefined: no serialization
|
|
19
|
+
*/
|
|
20
|
+
serialize?: JsonMapping | boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* DynamicQueryBuilder provides pure JavaScript SQL query building capabilities.
|
|
24
|
+
* It combines SQL parsing with dynamic condition injection (filtering, sorting, pagination, serialization).
|
|
25
|
+
*
|
|
26
|
+
* This class is framework-agnostic and does not perform any file I/O operations.
|
|
27
|
+
* It only works with SQL content provided as strings.
|
|
28
|
+
*
|
|
29
|
+
* Key features:
|
|
30
|
+
* - Pure JavaScript/TypeScript - no file system dependencies
|
|
31
|
+
* - Framework-agnostic - can be used with any database framework
|
|
32
|
+
* - Composable - combines multiple injectors in the correct order
|
|
33
|
+
* - Type-safe - provides TypeScript types for all options
|
|
34
|
+
* - Testable - easy to unit test without mocking file system
|
|
35
|
+
*/
|
|
36
|
+
export declare class DynamicQueryBuilder {
|
|
37
|
+
private tableColumnResolver?;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new DynamicQueryBuilder instance
|
|
40
|
+
* @param tableColumnResolver Optional function to resolve table columns for wildcard queries
|
|
41
|
+
*/
|
|
42
|
+
constructor(tableColumnResolver?: (tableName: string) => string[]);
|
|
43
|
+
/**
|
|
44
|
+
* Builds a SelectQuery from SQL content with dynamic conditions.
|
|
45
|
+
* This is a pure function that does not perform any I/O operations.
|
|
46
|
+
* * @param sqlContent Raw SQL string to parse and modify
|
|
47
|
+
* @param options Dynamic conditions to apply (filter, sort, paging, serialize)
|
|
48
|
+
* @returns Modified SelectQuery with all dynamic conditions applied
|
|
49
|
+
* * @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const builder = new DynamicQueryBuilder();
|
|
52
|
+
* const query = builder.buildQuery(
|
|
53
|
+
* 'SELECT id, name FROM users WHERE active = true',
|
|
54
|
+
* {
|
|
55
|
+
* filter: { status: 'premium' },
|
|
56
|
+
* sort: { created_at: { desc: true } },
|
|
57
|
+
* paging: { page: 2, pageSize: 10 },
|
|
58
|
+
* serialize: { rootName: 'user', rootEntity: { id: 'user', name: 'User', columns: { id: 'id', name: 'name' } }, nestedEntities: [] }
|
|
59
|
+
* }
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
buildQuery(sqlContent: string, options?: QueryBuildOptions): SelectQuery;
|
|
64
|
+
/**
|
|
65
|
+
* Builds a SelectQuery with only filtering applied.
|
|
66
|
+
* Convenience method for when you only need dynamic WHERE conditions.
|
|
67
|
+
*
|
|
68
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
69
|
+
* @param filter Filter conditions to apply
|
|
70
|
+
* @returns Modified SelectQuery with filter conditions applied
|
|
71
|
+
*/
|
|
72
|
+
buildFilteredQuery(sqlContent: string, filter: Record<string, any>): SelectQuery;
|
|
73
|
+
/**
|
|
74
|
+
* Builds a SelectQuery with only sorting applied.
|
|
75
|
+
* Convenience method for when you only need dynamic ORDER BY clauses.
|
|
76
|
+
*
|
|
77
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
78
|
+
* @param sort Sort conditions to apply
|
|
79
|
+
* @returns Modified SelectQuery with sort conditions applied
|
|
80
|
+
*/
|
|
81
|
+
buildSortedQuery(sqlContent: string, sort: SortConditions): SelectQuery; /**
|
|
82
|
+
* Builds a SelectQuery with only pagination applied.
|
|
83
|
+
* Convenience method for when you only need LIMIT/OFFSET clauses.
|
|
84
|
+
*
|
|
85
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
86
|
+
* @param paging Pagination options to apply
|
|
87
|
+
* @returns Modified SelectQuery with pagination applied
|
|
88
|
+
*/
|
|
89
|
+
buildPaginatedQuery(sqlContent: string, paging: PaginationOptions): SelectQuery;
|
|
90
|
+
/**
|
|
91
|
+
* Builds a SelectQuery with only JSON serialization applied.
|
|
92
|
+
* Convenience method for when you only need hierarchical JSON transformation.
|
|
93
|
+
*
|
|
94
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
95
|
+
* @param serialize JSON mapping configuration to apply
|
|
96
|
+
* @returns Modified SelectQuery with JSON serialization applied
|
|
97
|
+
*/
|
|
98
|
+
buildSerializedQuery(sqlContent: string, serialize: JsonMapping): SelectQuery;
|
|
99
|
+
/**
|
|
100
|
+
* Validates SQL content by attempting to parse it.
|
|
101
|
+
* Useful for testing SQL validity without applying any modifications.
|
|
102
|
+
*
|
|
103
|
+
* @param sqlContent Raw SQL string to validate
|
|
104
|
+
* @returns true if SQL is valid, throws error if invalid
|
|
105
|
+
* @throws Error if SQL cannot be parsed
|
|
106
|
+
*/
|
|
107
|
+
validateSql(sqlContent: string): boolean;
|
|
108
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicQueryBuilder = void 0;
|
|
4
|
+
const SelectQueryParser_1 = require("../parsers/SelectQueryParser");
|
|
5
|
+
const SqlParamInjector_1 = require("./SqlParamInjector");
|
|
6
|
+
const SqlSortInjector_1 = require("./SqlSortInjector");
|
|
7
|
+
const SqlPaginationInjector_1 = require("./SqlPaginationInjector");
|
|
8
|
+
const PostgresJsonQueryBuilder_1 = require("./PostgresJsonQueryBuilder");
|
|
9
|
+
const QueryBuilder_1 = require("./QueryBuilder");
|
|
10
|
+
/**
|
|
11
|
+
* DynamicQueryBuilder provides pure JavaScript SQL query building capabilities.
|
|
12
|
+
* It combines SQL parsing with dynamic condition injection (filtering, sorting, pagination, serialization).
|
|
13
|
+
*
|
|
14
|
+
* This class is framework-agnostic and does not perform any file I/O operations.
|
|
15
|
+
* It only works with SQL content provided as strings.
|
|
16
|
+
*
|
|
17
|
+
* Key features:
|
|
18
|
+
* - Pure JavaScript/TypeScript - no file system dependencies
|
|
19
|
+
* - Framework-agnostic - can be used with any database framework
|
|
20
|
+
* - Composable - combines multiple injectors in the correct order
|
|
21
|
+
* - Type-safe - provides TypeScript types for all options
|
|
22
|
+
* - Testable - easy to unit test without mocking file system
|
|
23
|
+
*/
|
|
24
|
+
class DynamicQueryBuilder {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new DynamicQueryBuilder instance
|
|
27
|
+
* @param tableColumnResolver Optional function to resolve table columns for wildcard queries
|
|
28
|
+
*/
|
|
29
|
+
constructor(tableColumnResolver) {
|
|
30
|
+
this.tableColumnResolver = tableColumnResolver;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds a SelectQuery from SQL content with dynamic conditions.
|
|
34
|
+
* This is a pure function that does not perform any I/O operations.
|
|
35
|
+
* * @param sqlContent Raw SQL string to parse and modify
|
|
36
|
+
* @param options Dynamic conditions to apply (filter, sort, paging, serialize)
|
|
37
|
+
* @returns Modified SelectQuery with all dynamic conditions applied
|
|
38
|
+
* * @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const builder = new DynamicQueryBuilder();
|
|
41
|
+
* const query = builder.buildQuery(
|
|
42
|
+
* 'SELECT id, name FROM users WHERE active = true',
|
|
43
|
+
* {
|
|
44
|
+
* filter: { status: 'premium' },
|
|
45
|
+
* sort: { created_at: { desc: true } },
|
|
46
|
+
* paging: { page: 2, pageSize: 10 },
|
|
47
|
+
* serialize: { rootName: 'user', rootEntity: { id: 'user', name: 'User', columns: { id: 'id', name: 'name' } }, nestedEntities: [] }
|
|
48
|
+
* }
|
|
49
|
+
* );
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
buildQuery(sqlContent, options = {}) {
|
|
53
|
+
// Parse the base SQL
|
|
54
|
+
let parsedQuery;
|
|
55
|
+
try {
|
|
56
|
+
parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sqlContent);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw new Error(`Failed to parse SQL: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
60
|
+
}
|
|
61
|
+
// Apply dynamic modifications in the correct order
|
|
62
|
+
let modifiedQuery = parsedQuery;
|
|
63
|
+
// 1. Apply filtering first (most selective, should reduce data early)
|
|
64
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
65
|
+
const paramInjector = new SqlParamInjector_1.SqlParamInjector(this.tableColumnResolver);
|
|
66
|
+
// Ensure we have a SimpleSelectQuery for the injector
|
|
67
|
+
const simpleQuery = QueryBuilder_1.QueryBuilder.buildSimpleQuery(modifiedQuery);
|
|
68
|
+
modifiedQuery = paramInjector.inject(simpleQuery, options.filter);
|
|
69
|
+
}
|
|
70
|
+
// 2. Apply sorting second (after filtering to sort smaller dataset)
|
|
71
|
+
if (options.sort && Object.keys(options.sort).length > 0) {
|
|
72
|
+
const sortInjector = new SqlSortInjector_1.SqlSortInjector(this.tableColumnResolver);
|
|
73
|
+
// Ensure we have a SimpleSelectQuery for the injector
|
|
74
|
+
const simpleQuery = QueryBuilder_1.QueryBuilder.buildSimpleQuery(modifiedQuery);
|
|
75
|
+
modifiedQuery = sortInjector.inject(simpleQuery, options.sort);
|
|
76
|
+
} // 3. Apply pagination third (after filtering and sorting)
|
|
77
|
+
if (options.paging) {
|
|
78
|
+
const { page = 1, pageSize } = options.paging;
|
|
79
|
+
if (pageSize !== undefined) {
|
|
80
|
+
const paginationInjector = new SqlPaginationInjector_1.SqlPaginationInjector();
|
|
81
|
+
const paginationOptions = { page, pageSize };
|
|
82
|
+
// Ensure we have a SimpleSelectQuery for the injector
|
|
83
|
+
const simpleQuery = QueryBuilder_1.QueryBuilder.buildSimpleQuery(modifiedQuery);
|
|
84
|
+
modifiedQuery = paginationInjector.inject(simpleQuery, paginationOptions);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// 4. Apply serialization last (transform the final query structure to JSON)
|
|
88
|
+
// Note: boolean values are handled at RawSqlClient level for auto-loading
|
|
89
|
+
if (options.serialize && typeof options.serialize === 'object') {
|
|
90
|
+
const jsonBuilder = new PostgresJsonQueryBuilder_1.PostgresJsonQueryBuilder();
|
|
91
|
+
// Ensure we have a SimpleSelectQuery for the JSON builder
|
|
92
|
+
const simpleQuery = QueryBuilder_1.QueryBuilder.buildSimpleQuery(modifiedQuery);
|
|
93
|
+
modifiedQuery = jsonBuilder.buildJsonQuery(simpleQuery, options.serialize);
|
|
94
|
+
}
|
|
95
|
+
return modifiedQuery;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Builds a SelectQuery with only filtering applied.
|
|
99
|
+
* Convenience method for when you only need dynamic WHERE conditions.
|
|
100
|
+
*
|
|
101
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
102
|
+
* @param filter Filter conditions to apply
|
|
103
|
+
* @returns Modified SelectQuery with filter conditions applied
|
|
104
|
+
*/
|
|
105
|
+
buildFilteredQuery(sqlContent, filter) {
|
|
106
|
+
return this.buildQuery(sqlContent, { filter });
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Builds a SelectQuery with only sorting applied.
|
|
110
|
+
* Convenience method for when you only need dynamic ORDER BY clauses.
|
|
111
|
+
*
|
|
112
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
113
|
+
* @param sort Sort conditions to apply
|
|
114
|
+
* @returns Modified SelectQuery with sort conditions applied
|
|
115
|
+
*/
|
|
116
|
+
buildSortedQuery(sqlContent, sort) {
|
|
117
|
+
return this.buildQuery(sqlContent, { sort });
|
|
118
|
+
} /**
|
|
119
|
+
* Builds a SelectQuery with only pagination applied.
|
|
120
|
+
* Convenience method for when you only need LIMIT/OFFSET clauses.
|
|
121
|
+
*
|
|
122
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
123
|
+
* @param paging Pagination options to apply
|
|
124
|
+
* @returns Modified SelectQuery with pagination applied
|
|
125
|
+
*/
|
|
126
|
+
buildPaginatedQuery(sqlContent, paging) {
|
|
127
|
+
return this.buildQuery(sqlContent, { paging });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Builds a SelectQuery with only JSON serialization applied.
|
|
131
|
+
* Convenience method for when you only need hierarchical JSON transformation.
|
|
132
|
+
*
|
|
133
|
+
* @param sqlContent Raw SQL string to parse and modify
|
|
134
|
+
* @param serialize JSON mapping configuration to apply
|
|
135
|
+
* @returns Modified SelectQuery with JSON serialization applied
|
|
136
|
+
*/
|
|
137
|
+
buildSerializedQuery(sqlContent, serialize) {
|
|
138
|
+
return this.buildQuery(sqlContent, { serialize });
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Validates SQL content by attempting to parse it.
|
|
142
|
+
* Useful for testing SQL validity without applying any modifications.
|
|
143
|
+
*
|
|
144
|
+
* @param sqlContent Raw SQL string to validate
|
|
145
|
+
* @returns true if SQL is valid, throws error if invalid
|
|
146
|
+
* @throws Error if SQL cannot be parsed
|
|
147
|
+
*/
|
|
148
|
+
validateSql(sqlContent) {
|
|
149
|
+
try {
|
|
150
|
+
SelectQueryParser_1.SelectQueryParser.parse(sqlContent);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throw new Error(`Invalid SQL: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.DynamicQueryBuilder = DynamicQueryBuilder;
|
|
159
|
+
//# sourceMappingURL=DynamicQueryBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicQueryBuilder.js","sourceRoot":"","sources":["../../../src/transformers/DynamicQueryBuilder.ts"],"names":[],"mappings":";;;AACA,oEAAiE;AACjE,yDAAsD;AACtD,uDAAoE;AACpE,mEAAmF;AACnF,yEAAmF;AACnF,iDAA8C;AAoB9C;;;;;;;;;;;;;GAaG;AACH,MAAa,mBAAmB;IAE5B;;;OAGG;IACH,YAAY,mBAAqD;QAC7D,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACnD,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,UAAU,CAAC,UAAkB,EAAE,UAA6B,EAAE;QAC1D,qBAAqB;QACrB,IAA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OG;IACH,oBAAoB,CAAC,UAAkB,EAAE,SAAsB;QAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;OAOG;IACH,WAAW,CAAC,UAAkB;QAC1B,IAAI,CAAC;YACD,qCAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACpC,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QAChG,CAAC;IACL,CAAC;CACJ;AA7ID,kDA6IC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SimpleSelectQuery } from '../models/SimpleSelectQuery';
|
|
2
|
+
import { SelectQuery } from '../models/SelectQuery';
|
|
2
3
|
/**
|
|
3
4
|
* Universal JSON mapping definition for creating any level of JSON structures.
|
|
4
5
|
* Supports flat arrays, nested objects, and unlimited hierarchical structures.
|
|
@@ -43,10 +44,11 @@ export declare class PostgresJsonQueryBuilder {
|
|
|
43
44
|
private validateMapping;
|
|
44
45
|
/**
|
|
45
46
|
* Build JSON query from original query and mapping configuration.
|
|
46
|
-
* @param originalQuery Original query to transform
|
|
47
|
+
* @param originalQuery Original query to transform (can be any SelectQuery type)
|
|
47
48
|
* @param mapping JSON mapping configuration
|
|
48
49
|
* @returns Transformed query with JSON aggregation
|
|
49
50
|
*/
|
|
51
|
+
buildJsonQuery(originalQuery: SelectQuery, mapping: JsonMapping): SimpleSelectQuery;
|
|
50
52
|
buildJsonQuery(originalQuery: SimpleSelectQuery, mapping: JsonMapping): SimpleSelectQuery;
|
|
51
53
|
/**
|
|
52
54
|
* Build JSON query from original query and mapping configuration.
|
|
@@ -7,6 +7,7 @@ const ValueComponent_1 = require("../models/ValueComponent");
|
|
|
7
7
|
const SelectValueCollector_1 = require("./SelectValueCollector");
|
|
8
8
|
const PostgresObjectEntityCteBuilder_1 = require("./PostgresObjectEntityCteBuilder");
|
|
9
9
|
const PostgresArrayEntityCteBuilder_1 = require("./PostgresArrayEntityCteBuilder");
|
|
10
|
+
const QueryBuilder_1 = require("./QueryBuilder");
|
|
10
11
|
/**
|
|
11
12
|
* PostgreSQL JSON query builder that transforms SimpleSelectQuery into queries
|
|
12
13
|
* that return JSON arrays or single JSON objects using PostgreSQL JSON functions.
|
|
@@ -27,10 +28,11 @@ class PostgresJsonQueryBuilder {
|
|
|
27
28
|
const collector = new SelectValueCollector_1.SelectValueCollector();
|
|
28
29
|
const selectedValues = collector.collect(query);
|
|
29
30
|
// sv.name is the alias or derived name
|
|
30
|
-
const availableColumns = new Set(selectedValues.map(sv => sv.name));
|
|
31
|
-
// Check root entity columns
|
|
31
|
+
const availableColumns = new Set(selectedValues.map(sv => sv.name)); // Check root entity columns
|
|
32
32
|
for (const jsonKey in mapping.rootEntity.columns) {
|
|
33
|
-
const
|
|
33
|
+
const columnDef = mapping.rootEntity.columns[jsonKey];
|
|
34
|
+
// Handle both string and object formats
|
|
35
|
+
const sourceColumn = typeof columnDef === 'string' ? columnDef : columnDef.column;
|
|
34
36
|
if (!availableColumns.has(sourceColumn)) {
|
|
35
37
|
throw new Error(`Validation Error: Column "${sourceColumn}" for JSON key "${jsonKey}" in root entity "${mapping.rootEntity.name}" not found in the query's select list.`);
|
|
36
38
|
}
|
|
@@ -50,7 +52,9 @@ class PostgresJsonQueryBuilder {
|
|
|
50
52
|
throw new Error(`Validation Error: Parent entity with ID "${entity.parentId}" for nested entity "${entity.name}" (ID: ${entity.id}) not found.`);
|
|
51
53
|
}
|
|
52
54
|
for (const jsonKey in entity.columns) {
|
|
53
|
-
const
|
|
55
|
+
const columnDef = entity.columns[jsonKey];
|
|
56
|
+
// Handle both string and object formats
|
|
57
|
+
const sourceColumn = typeof columnDef === 'string' ? columnDef : columnDef.column;
|
|
54
58
|
if (!availableColumns.has(sourceColumn)) {
|
|
55
59
|
throw new Error(`Validation Error: Column "${sourceColumn}" for JSON key "${jsonKey}" in nested entity "${entity.name}" (ID: ${entity.id}) not found in the query's select list.`);
|
|
56
60
|
}
|
|
@@ -76,14 +80,12 @@ class PostgresJsonQueryBuilder {
|
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Build JSON query from original query and mapping configuration.
|
|
81
|
-
* @param originalQuery Original query to transform
|
|
82
|
-
* @param mapping JSON mapping configuration
|
|
83
|
-
* @returns Transformed query with JSON aggregation
|
|
84
|
-
*/
|
|
85
83
|
buildJsonQuery(originalQuery, mapping) {
|
|
86
|
-
|
|
84
|
+
// Convert any SelectQuery to SimpleSelectQuery using QueryBuilder
|
|
85
|
+
const simpleQuery = originalQuery instanceof SimpleSelectQuery_1.SimpleSelectQuery
|
|
86
|
+
? originalQuery
|
|
87
|
+
: QueryBuilder_1.QueryBuilder.buildSimpleQuery(originalQuery);
|
|
88
|
+
return this.buildJsonWithCteStrategy(simpleQuery, mapping);
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
91
|
* Build JSON query from original query and mapping configuration.
|
|
@@ -202,7 +204,9 @@ class PostgresJsonQueryBuilder {
|
|
|
202
204
|
buildEntityJsonObject(entity, sourceAlias, nestedEntities, allEntities, useJsonb = false) {
|
|
203
205
|
const jsonBuildFunction = useJsonb ? "jsonb_build_object" : "json_build_object";
|
|
204
206
|
const args = []; // Add the entity's own columns
|
|
205
|
-
Object.entries(entity.columns).forEach(([jsonKey,
|
|
207
|
+
Object.entries(entity.columns).forEach(([jsonKey, columnDef]) => {
|
|
208
|
+
// Handle both string and object formats
|
|
209
|
+
const sqlColumn = typeof columnDef === 'string' ? columnDef : columnDef.column;
|
|
206
210
|
args.push(new ValueComponent_1.LiteralValue(jsonKey));
|
|
207
211
|
args.push(new ValueComponent_1.ColumnReference(null, new ValueComponent_1.IdentifierString(sqlColumn)));
|
|
208
212
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresJsonQueryBuilder.js","sourceRoot":"","sources":["../../../src/transformers/PostgresJsonQueryBuilder.ts"],"names":[],"mappings":";;;AAAA,6CAAmM;AACnM,mEAAgE;
|
|
1
|
+
{"version":3,"file":"PostgresJsonQueryBuilder.js","sourceRoot":"","sources":["../../../src/transformers/PostgresJsonQueryBuilder.ts"],"names":[],"mappings":";;;AAAA,6CAAmM;AACnM,mEAAgE;AAEhE,6DAAwO;AACxO,iEAA8D;AAC9D,qFAAqG;AACrG,mFAAgF;AAChF,iDAA8C;AA0B9C;;;GAGG;AACH,MAAa,wBAAwB;IAKjC;QACI,IAAI,CAAC,oBAAoB,GAAG,IAAI,2CAAoB,CAAC,IAAI,CAAC,CAAC;QAC3D,IAAI,CAAC,sBAAsB,GAAG,IAAI,+DAA8B,EAAE,CAAC;QACnE,IAAI,CAAC,qBAAqB,GAAG,IAAI,6DAA6B,EAAE,CAAC;IACrE,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,KAAwB,EAAE,OAAoB;;QAClE,MAAM,SAAS,GAAG,IAAI,2CAAoB,EAAE,CAAC;QAC7C,MAAM,cAAc,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEhD,uCAAuC;QACvC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAQ,4BAA4B;QACxG,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtD,wCAAwC;YACxC,MAAM,YAAY,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAE,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AE,CAAC;gBACnG,yDAAyD;gBACzD,MAAM,cAAc,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC;gBAC1D,IAAI,CAAC,IAAI,CAAC,IAAI,gCAAe,CAAC,IAAI,EAAE,IAAI,iCAAgB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YAC/E,CAAC;iBAAM,IAAI,WAAW,CAAC,gBAAgB,KAAK,OAAO,EAAE,CAAC;gBAClD,mDAAmD;gBACnD,IAAI,CAAC,IAAI,CAAC,IAAI,gCAAe,CAAC,IAAI,EAAE,IAAI,iCAAgB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,6BAAY,CAAC,IAAI,EAAE,IAAI,0BAAS,CAAC,iBAAiB,CAAC,EAAE,IAAI,0BAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/F,CAAC;CACJ;AAtUD,4DAsUC"}
|
|
@@ -26,8 +26,7 @@ export declare class SqlFormatter {
|
|
|
26
26
|
keywordCase?: 'none' | 'upper' | 'lower';
|
|
27
27
|
commaBreak?: CommaBreakStyle;
|
|
28
28
|
andBreak?: AndBreakStyle;
|
|
29
|
-
});
|
|
30
|
-
/**
|
|
29
|
+
}); /**
|
|
31
30
|
* Formats a SQL query string with the given parameters.
|
|
32
31
|
* @param sqlText The SQL query string to format.
|
|
33
32
|
* @param parameters A dictionary of parameters to replace in the query.
|
|
@@ -35,6 +34,6 @@ export declare class SqlFormatter {
|
|
|
35
34
|
*/
|
|
36
35
|
format(sql: SqlComponent): {
|
|
37
36
|
formattedSql: string;
|
|
38
|
-
params: Record<string, any>;
|
|
37
|
+
params: any[] | Record<string, any>;
|
|
39
38
|
};
|
|
40
39
|
}
|
|
@@ -23,8 +23,7 @@ class SqlFormatter {
|
|
|
23
23
|
};
|
|
24
24
|
this.parser = new SqlPrintTokenParser_1.SqlPrintTokenParser(parserOptions);
|
|
25
25
|
this.printer = new SqlPrinter_1.SqlPrinter(options);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
26
|
+
} /**
|
|
28
27
|
* Formats a SQL query string with the given parameters.
|
|
29
28
|
* @param sqlText The SQL query string to format.
|
|
30
29
|
* @param parameters A dictionary of parameters to replace in the query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlFormatter.js","sourceRoot":"","sources":["../../../src/transformers/SqlFormatter.ts"],"names":[],"mappings":";;;AAAA,wEAA+F;AAC/F,6CAA0E;AAK1E,4CAA4C;AAC/B,QAAA,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;AAGnF;;GAEG;AACH,MAAa,YAAY;IAIrB,YAAY,UAWR,EAAE;;QAEF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,6BAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE1E,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,iCAAiC;QAC3F,CAAC;QAED,MAAM,aAAa,GAAG;YAClB,GAAG,YAAY,EAAE,6BAA6B;YAC9C,gBAAgB,EAAE,MAAA,OAAO,CAAC,gBAAgB,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,gBAAgB;YAC5E,eAAe,EAAE,MAAA,OAAO,CAAC,eAAe,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,eAAe;YACzE,cAAc,EAAE,MAAA,OAAO,CAAC,cAAc,mCAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,cAAc;SACzE,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,IAAI,yCAAmB,CAAC,aAAa,CAA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,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;CACJ;AA5CD,oCA4CC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-processor for transforming database values to appropriate TypeScript types
|
|
3
|
+
* after JSON serialization from PostgreSQL
|
|
4
|
+
*/
|
|
5
|
+
export interface TypeTransformationConfig {
|
|
6
|
+
/** Column transformations mapping - takes precedence over value-based detection */
|
|
7
|
+
columnTransformations?: {
|
|
8
|
+
[columnName: string]: TypeTransformation;
|
|
9
|
+
};
|
|
10
|
+
/** Global transformation rules by SQL data type */
|
|
11
|
+
globalTransformations?: {
|
|
12
|
+
[sqlType: string]: TypeTransformation;
|
|
13
|
+
};
|
|
14
|
+
/** Custom transformation functions */
|
|
15
|
+
customTransformers?: {
|
|
16
|
+
[transformerName: string]: (value: any) => any;
|
|
17
|
+
};
|
|
18
|
+
/** Enable value-based type detection when column mapping is not provided (default: true) */
|
|
19
|
+
enableValueBasedDetection?: boolean;
|
|
20
|
+
/** Strict date detection - only convert ISO 8601 with 'T' separator (default: false) */
|
|
21
|
+
strictDateDetection?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface TypeTransformation {
|
|
24
|
+
/** Source SQL data type */
|
|
25
|
+
sourceType: 'DATE' | 'TIMESTAMP' | 'BIGINT' | 'NUMERIC' | 'JSONB' | 'custom';
|
|
26
|
+
/** Target TypeScript type representation */
|
|
27
|
+
targetType: 'Date' | 'bigint' | 'string' | 'number' | 'object' | 'custom';
|
|
28
|
+
/** Custom transformer function name (for custom type) */
|
|
29
|
+
customTransformer?: string;
|
|
30
|
+
/** Whether to handle null values (default: true) */
|
|
31
|
+
handleNull?: boolean;
|
|
32
|
+
/** Validation function for the value */
|
|
33
|
+
validator?: (value: any) => boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Applies type transformations to JSON results from PostgreSQL
|
|
37
|
+
*/
|
|
38
|
+
export declare class TypeTransformationPostProcessor {
|
|
39
|
+
private config;
|
|
40
|
+
constructor(config?: TypeTransformationConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Transform a single result object
|
|
43
|
+
* @param result The result object from PostgreSQL JSON query
|
|
44
|
+
* @returns Transformed result with proper TypeScript types
|
|
45
|
+
*/
|
|
46
|
+
transformResult<T = any>(result: any): T;
|
|
47
|
+
/**
|
|
48
|
+
* Transform a single object recursively
|
|
49
|
+
*/
|
|
50
|
+
private transformSingleObject;
|
|
51
|
+
/**
|
|
52
|
+
* Detect value type and create appropriate transformation based on value characteristics
|
|
53
|
+
* This is the core value-based detection logic
|
|
54
|
+
*/
|
|
55
|
+
private detectValueBasedTransformation;
|
|
56
|
+
/**
|
|
57
|
+
* Get global transformation for a specific value (if any match)
|
|
58
|
+
* This is separate from value-based detection and relies on configured global rules
|
|
59
|
+
*/
|
|
60
|
+
private getGlobalTransformationForValue;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use detectValueBasedTransformation instead
|
|
63
|
+
* Detect value type and get appropriate global transformation
|
|
64
|
+
*/
|
|
65
|
+
private detectAndGetGlobalTransformation;
|
|
66
|
+
/**
|
|
67
|
+
* Check if string is a valid date string
|
|
68
|
+
* Supports both strict (ISO 8601 with T separator) and loose detection
|
|
69
|
+
*/
|
|
70
|
+
private isDateString;
|
|
71
|
+
/**
|
|
72
|
+
* Apply a specific transformation to a value
|
|
73
|
+
*/
|
|
74
|
+
private applyTransformation;
|
|
75
|
+
/**
|
|
76
|
+
* Create a default configuration for common PostgreSQL types
|
|
77
|
+
* Enables value-based detection with loose date detection by default
|
|
78
|
+
*/
|
|
79
|
+
static createDefaultConfig(): TypeTransformationConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Create a safe configuration for handling user input
|
|
82
|
+
* Disables value-based detection and uses strict date detection
|
|
83
|
+
*/
|
|
84
|
+
static createSafeConfig(columnMappings?: {
|
|
85
|
+
[columnName: string]: TypeTransformation;
|
|
86
|
+
}): TypeTransformationConfig;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Convenience function to create and apply transformations
|
|
90
|
+
*/
|
|
91
|
+
export declare function transformDatabaseResult<T = any>(result: any, config?: TypeTransformationConfig): T;
|
|
92
|
+
/**
|
|
93
|
+
* Type-safe transformation helpers
|
|
94
|
+
*/
|
|
95
|
+
export declare const TypeTransformers: {
|
|
96
|
+
/**
|
|
97
|
+
* Transform date string to Date object
|
|
98
|
+
*/
|
|
99
|
+
toDate: (value: string | null) => Date | null;
|
|
100
|
+
/**
|
|
101
|
+
* Transform numeric string to BigInt
|
|
102
|
+
*/
|
|
103
|
+
toBigInt: (value: string | number | null) => bigint | null;
|
|
104
|
+
/**
|
|
105
|
+
* Transform JSON string to object
|
|
106
|
+
*/
|
|
107
|
+
toObject: <T = any>(value: string | null) => T | null;
|
|
108
|
+
};
|