@query-doctor/core 0.0.3
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/.eslintrc.cjs +4 -0
- package/dist/index.cjs +1833 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1787 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +24297 -0
- package/dist/index.mjs.map +1 -0
- package/dist/optimizer/genalgo.d.ts +82 -0
- package/dist/optimizer/genalgo.d.ts.map +1 -0
- package/dist/optimizer/statistics.d.ts +373 -0
- package/dist/optimizer/statistics.d.ts.map +1 -0
- package/dist/sql/analyzer.d.ts +97 -0
- package/dist/sql/analyzer.d.ts.map +1 -0
- package/dist/sql/analyzer_test.d.ts +2 -0
- package/dist/sql/analyzer_test.d.ts.map +1 -0
- package/dist/sql/builder.d.ts +24 -0
- package/dist/sql/builder.d.ts.map +1 -0
- package/dist/sql/database.d.ts +31 -0
- package/dist/sql/database.d.ts.map +1 -0
- package/dist/sql/nudges.d.ts +15 -0
- package/dist/sql/nudges.d.ts.map +1 -0
- package/dist/sql/permutations_test.d.ts +2 -0
- package/dist/sql/permutations_test.d.ts.map +1 -0
- package/dist/sql/schema_dump.d.ts +132 -0
- package/dist/sql/schema_dump.d.ts.map +1 -0
- package/dist/sql/trace.d.ts +1 -0
- package/dist/sql/trace.d.ts.map +1 -0
- package/dist/sql/walker.d.ts +44 -0
- package/dist/sql/walker.d.ts.map +1 -0
- package/package.json +37 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ExportedPgMetadataSchema: z.ZodObject<{
|
|
3
|
+
indexes: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
4
|
+
oid: z.ZodNumber;
|
|
5
|
+
schema_name: z.ZodString;
|
|
6
|
+
table_name: z.ZodString;
|
|
7
|
+
index_name: z.ZodString;
|
|
8
|
+
index_type: z.ZodString;
|
|
9
|
+
is_unique: z.ZodBoolean;
|
|
10
|
+
is_primary: z.ZodBoolean;
|
|
11
|
+
is_clustered: z.ZodBoolean;
|
|
12
|
+
where_predicate: z.ZodNullable<z.ZodString>;
|
|
13
|
+
tablespace: z.ZodNullable<z.ZodString>;
|
|
14
|
+
key_columns: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
order: z.ZodNullable<z.ZodEnum<{
|
|
17
|
+
ASC: "ASC";
|
|
18
|
+
DESC: "DESC";
|
|
19
|
+
}>>;
|
|
20
|
+
nulls: z.ZodNullable<z.ZodEnum<{
|
|
21
|
+
FIRST: "FIRST";
|
|
22
|
+
LAST: "LAST";
|
|
23
|
+
}>>;
|
|
24
|
+
opclass: z.ZodNullable<z.ZodString>;
|
|
25
|
+
collation: z.ZodNullable<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>>>;
|
|
27
|
+
included_columns: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
28
|
+
name: z.ZodString;
|
|
29
|
+
}, z.core.$strip>>>;
|
|
30
|
+
}, z.core.$strip>>>;
|
|
31
|
+
tables: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
32
|
+
oid: z.ZodNumber;
|
|
33
|
+
schema_name: z.ZodString;
|
|
34
|
+
table_name: z.ZodString;
|
|
35
|
+
tablespace: z.ZodNullable<z.ZodString>;
|
|
36
|
+
partition_key_def: z.ZodNullable<z.ZodString>;
|
|
37
|
+
columns: z.ZodArray<z.ZodObject<{
|
|
38
|
+
name: z.ZodString;
|
|
39
|
+
order: z.ZodNumber;
|
|
40
|
+
type: z.ZodString;
|
|
41
|
+
is_nullable: z.ZodBoolean;
|
|
42
|
+
default_value: z.ZodNullable<z.ZodString>;
|
|
43
|
+
dropped: z.ZodBoolean;
|
|
44
|
+
collation: z.ZodNullable<z.ZodString>;
|
|
45
|
+
storage: z.ZodNullable<z.ZodEnum<{
|
|
46
|
+
plain: "plain";
|
|
47
|
+
main: "main";
|
|
48
|
+
external: "external";
|
|
49
|
+
extended: "extended";
|
|
50
|
+
}>>;
|
|
51
|
+
is_identity: z.ZodNullable<z.ZodEnum<{
|
|
52
|
+
always: "always";
|
|
53
|
+
"by default": "by default";
|
|
54
|
+
}>>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
}, z.core.$strip>>>;
|
|
57
|
+
constraints: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
58
|
+
oid: z.ZodNumber;
|
|
59
|
+
schema_name: z.ZodString;
|
|
60
|
+
table_name: z.ZodString;
|
|
61
|
+
constraint_name: z.ZodString;
|
|
62
|
+
constraint_type: z.ZodEnum<{
|
|
63
|
+
CHECK: "CHECK";
|
|
64
|
+
"FOREIGN KEY": "FOREIGN KEY";
|
|
65
|
+
"PRIMARY KEY": "PRIMARY KEY";
|
|
66
|
+
UNIQUE: "UNIQUE";
|
|
67
|
+
EXCLUSION: "EXCLUSION";
|
|
68
|
+
}>;
|
|
69
|
+
definition: z.ZodString;
|
|
70
|
+
is_deferrable: z.ZodNullable<z.ZodBoolean>;
|
|
71
|
+
is_initially_deferred: z.ZodNullable<z.ZodBoolean>;
|
|
72
|
+
is_validated: z.ZodNullable<z.ZodBoolean>;
|
|
73
|
+
backing_index_oid: z.ZodNullable<z.ZodNumber>;
|
|
74
|
+
}, z.core.$strip>>>;
|
|
75
|
+
functions: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
76
|
+
schema_name: z.ZodString;
|
|
77
|
+
object_name: z.ZodString;
|
|
78
|
+
object_type: z.ZodEnum<{
|
|
79
|
+
FUNCTION: "FUNCTION";
|
|
80
|
+
PROCEDURE: "PROCEDURE";
|
|
81
|
+
AGGREGATE: "AGGREGATE";
|
|
82
|
+
"WINDOW FUNCTION": "WINDOW FUNCTION";
|
|
83
|
+
}>;
|
|
84
|
+
identity_arguments: z.ZodNullable<z.ZodString>;
|
|
85
|
+
definition: z.ZodString;
|
|
86
|
+
}, z.core.$strip>>>;
|
|
87
|
+
extensions: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
88
|
+
extension_name: z.ZodString;
|
|
89
|
+
version: z.ZodString;
|
|
90
|
+
schema_name: z.ZodString;
|
|
91
|
+
}, z.core.$strip>>>;
|
|
92
|
+
views: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
93
|
+
schema_name: z.ZodString;
|
|
94
|
+
view_name: z.ZodString;
|
|
95
|
+
object_type: z.ZodEnum<{
|
|
96
|
+
view: "view";
|
|
97
|
+
materialized_view: "materialized_view";
|
|
98
|
+
}>;
|
|
99
|
+
definition: z.ZodString;
|
|
100
|
+
tablespace: z.ZodNullable<z.ZodString>;
|
|
101
|
+
}, z.core.$strip>>>;
|
|
102
|
+
types: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
103
|
+
schema_name: z.ZodString;
|
|
104
|
+
type_name: z.ZodString;
|
|
105
|
+
type_category: z.ZodEnum<{
|
|
106
|
+
enum: "enum";
|
|
107
|
+
domain: "domain";
|
|
108
|
+
composite: "composite";
|
|
109
|
+
}>;
|
|
110
|
+
enum_labels: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
111
|
+
domain_base_type: z.ZodNullable<z.ZodString>;
|
|
112
|
+
domain_is_not_null: z.ZodNullable<z.ZodBoolean>;
|
|
113
|
+
domain_default: z.ZodNullable<z.ZodString>;
|
|
114
|
+
domain_constraints: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
115
|
+
name: z.ZodString;
|
|
116
|
+
definition: z.ZodString;
|
|
117
|
+
}, z.core.$strip>>>;
|
|
118
|
+
composite_attributes: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
119
|
+
name: z.ZodString;
|
|
120
|
+
type: z.ZodString;
|
|
121
|
+
collation: z.ZodNullable<z.ZodString>;
|
|
122
|
+
}, z.core.$strip>>>;
|
|
123
|
+
}, z.core.$strip>>>;
|
|
124
|
+
triggers: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
125
|
+
schema_name: z.ZodString;
|
|
126
|
+
table_name: z.ZodString;
|
|
127
|
+
trigger_name: z.ZodString;
|
|
128
|
+
definition: z.ZodString;
|
|
129
|
+
enabled_mode: z.ZodString;
|
|
130
|
+
}, z.core.$strip>>>;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
//# sourceMappingURL=schema_dump.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema_dump.d.ts","sourceRoot":"","sources":["../../src/sql/schema_dump.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+HxB,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBASnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/sql/trace.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Node } from "@pgsql/types";
|
|
2
|
+
import type { DiscoveredColumnReference } from "./analyzer.ts";
|
|
3
|
+
import type { Nudge } from "./nudges.ts";
|
|
4
|
+
/** Information about tables that appear in the query */
|
|
5
|
+
export type TableMappings = Map<string, ColumnReferencePart>;
|
|
6
|
+
/**
|
|
7
|
+
* Walks the AST of a sql query and extracts query metadata.
|
|
8
|
+
* This pattern is used to segregate the mutable state that's more common for the
|
|
9
|
+
* AST walking process from the rest of the analyzer.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Walker {
|
|
12
|
+
private readonly query;
|
|
13
|
+
private tableMappings;
|
|
14
|
+
private tempTables;
|
|
15
|
+
private highlights;
|
|
16
|
+
private indexRepresentations;
|
|
17
|
+
private indexesToCheck;
|
|
18
|
+
private highlightPositions;
|
|
19
|
+
private seenReferences;
|
|
20
|
+
private shadowedAliases;
|
|
21
|
+
private nudges;
|
|
22
|
+
constructor(query: string);
|
|
23
|
+
walk(root: Node): {
|
|
24
|
+
highlights: DiscoveredColumnReference[];
|
|
25
|
+
indexRepresentations: Set<string>;
|
|
26
|
+
indexesToCheck: DiscoveredColumnReference[];
|
|
27
|
+
shadowedAliases: ColumnReferencePart[];
|
|
28
|
+
tempTables: Set<string>;
|
|
29
|
+
tableMappings: TableMappings;
|
|
30
|
+
nudges: Nudge[];
|
|
31
|
+
};
|
|
32
|
+
private add;
|
|
33
|
+
static traverse(node: unknown, stack: (KeysOfUnion<Node> | string)[], callback: (node: Node, stack: (KeysOfUnion<Node> | string)[]) => void): void;
|
|
34
|
+
}
|
|
35
|
+
export type ColumnReferencePart = {
|
|
36
|
+
/** the text of the column reference (excluding any potential quotes) */
|
|
37
|
+
text: string;
|
|
38
|
+
start?: number;
|
|
39
|
+
quoted: boolean;
|
|
40
|
+
alias?: string;
|
|
41
|
+
};
|
|
42
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=walker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walker.d.ts","sourceRoot":"","sources":["../../src/sql/walker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAgB,MAAM,cAAc,CAAC;AAEvD,OAAO,KAAK,EAAE,yBAAyB,EAAe,MAAM,eAAe,CAAC;AAE5E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAG7D;;;;GAIG;AACH,qBAAa,MAAM;IAaL,OAAO,CAAC,QAAQ,CAAC,KAAK;IAZlC,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,oBAAoB,CAAqB;IACjD,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,kBAAkB,CAAqB;IAG/C,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,MAAM,CAAe;gBAEA,KAAK,EAAE,MAAM;IAE1C,IAAI,CAAC,IAAI,EAAE,IAAI;;;;;;;;;IAoLf,OAAO,CAAC,GAAG;IA6EX,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,EAAE,EACrC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,EAAE,KAAK,IAAI;CAwBxE;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@query-doctor/core",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.3",
|
|
5
|
+
"description": "Core logic for Query Doctor",
|
|
6
|
+
"license": "",
|
|
7
|
+
"author": "Query Doctor",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "tsup src/index.ts --target es2020 --format esm,cjs --watch --external react --onSuccess 'tsc --emitDeclarationOnly --declaration'",
|
|
20
|
+
"build": "tsup src/index.ts --target es2020 --format esm,cjs --external react",
|
|
21
|
+
"test": "node --import tsx --test src/**/*_test.ts"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@pgsql/types": "^17.6.1",
|
|
25
|
+
"colorette": "^2.0.20",
|
|
26
|
+
"dedent": "^1.7.0",
|
|
27
|
+
"pgsql-deparser": "^17.11.1",
|
|
28
|
+
"zod": "^4.1.12"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@pgsql/parser": "^17.5.0",
|
|
32
|
+
"@query-doctor/eslint-config-custom": "*",
|
|
33
|
+
"@query-doctor/typescript-config": "*",
|
|
34
|
+
"tsup": "^8.5.0",
|
|
35
|
+
"typescript": "^5.9.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strictPropertyInitialization": false,
|
|
4
|
+
"target": "es2022",
|
|
5
|
+
"lib": ["es2022"],
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"baseUrl": "."
|
|
8
|
+
},
|
|
9
|
+
"extends": "@query-doctor/typescript-config/react-library.json",
|
|
10
|
+
"include": ["src"],
|
|
11
|
+
"exclude": ["dist", "build", "node_modules"]
|
|
12
|
+
}
|