introspeql 1.0.0 → 1.2.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/README.md +88 -59
- package/dist/config/create-relation-options.d.ts +22 -0
- package/dist/config/create-relation-options.js +60 -0
- package/dist/config/index.d.ts +52 -0
- package/dist/config/index.js +14 -0
- package/dist/config/materialized-view-options.d.ts +24 -0
- package/dist/config/materialized-view-options.js +5 -0
- package/dist/config/table-options.d.ts +21 -18
- package/dist/config/table-options.js +2 -45
- package/dist/config/view-options.d.ts +24 -0
- package/dist/config/view-options.js +5 -0
- package/dist/introspeql.js +6 -6
- package/dist/relations/abstract-relation-definition.d.ts +11 -0
- package/dist/{tables/table-definition.js → relations/abstract-relation-definition.js} +11 -11
- package/dist/relations/index.d.ts +11 -0
- package/dist/{tables → relations}/index.js +6 -3
- package/dist/relations/materialized-view-definition.d.ts +4 -0
- package/dist/relations/materialized-view-definition.js +29 -0
- package/dist/relations/read-relation-data.d.ts +4 -0
- package/dist/{tables/read-table-data.js → relations/read-relation-data.js} +12 -9
- package/dist/{tables/table-data.d.ts → relations/relation-data.d.ts} +2 -2
- package/dist/{tables/table-data.js → relations/relation-data.js} +2 -2
- package/dist/{tables/should-include-table.d.ts → relations/should-include-relation.d.ts} +2 -2
- package/dist/{tables/should-include-table.js → relations/should-include-relation.js} +2 -2
- package/dist/relations/table-definition.d.ts +4 -0
- package/dist/relations/table-definition.js +29 -0
- package/dist/relations/view-definition.d.ts +4 -0
- package/dist/relations/view-definition.js +29 -0
- package/dist/schemas/read-schema-data.d.ts +5 -3
- package/dist/schemas/read-schema-data.js +103 -66
- package/dist/schemas/schema-definition-factory.d.ts +2 -2
- package/dist/schemas/schema-definition-factory.js +30 -20
- package/dist/schemas/schema-definition.d.ts +4 -2
- package/dist/schemas/schema-definition.js +15 -1
- package/dist/shared/capitalize.d.ts +1 -0
- package/dist/shared/capitalize.js +6 -0
- package/dist/shared/convert-pg-identifier-to-ts-identifier.js +2 -4
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/package.json +2 -2
- package/dist/tables/index.d.ts +0 -8
- package/dist/tables/read-table-data.d.ts +0 -4
- package/dist/tables/table-definition.d.ts +0 -10
- /package/dist/{tables → relations}/column-data.d.ts +0 -0
- /package/dist/{tables → relations}/column-data.js +0 -0
- /package/dist/{tables → relations}/column-definition.d.ts +0 -0
- /package/dist/{tables → relations}/column-definition.js +0 -0
- /package/dist/{tables → relations}/column-type-definition.d.ts +0 -0
- /package/dist/{tables → relations}/column-type-definition.js +0 -0
- /package/dist/{tables → relations}/read-column-data.d.ts +0 -0
- /package/dist/{tables → relations}/read-column-data.js +0 -0
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SchemaDefinitionFactory = void 0;
|
|
4
4
|
var schema_definition_1 = require("./schema-definition");
|
|
5
5
|
var enums_1 = require("../enums");
|
|
6
|
-
var
|
|
6
|
+
var relations_1 = require("../relations");
|
|
7
7
|
var functions_1 = require("../functions");
|
|
8
8
|
var types_1 = require("../types");
|
|
9
9
|
var comments_1 = require("../comments");
|
|
@@ -15,10 +15,14 @@ var SchemaDefinitionFactory = /** @class */ (function () {
|
|
|
15
15
|
this.validateDBObjectNames(data.enums);
|
|
16
16
|
this.validateDBObjectNames(data.tables);
|
|
17
17
|
this.validateDBObjectNames(data.functions);
|
|
18
|
+
this.validateDBObjectNames(data.views);
|
|
19
|
+
this.validateDBObjectNames(data.materializedViews);
|
|
18
20
|
var enumDefinitions = this.createSortedEnumDefinitions(data, config);
|
|
19
|
-
var tableDefinitions = this.
|
|
21
|
+
var tableDefinitions = this.createSortedRelationDefinitions('table', data, config);
|
|
22
|
+
var viewDefinitions = this.createSortedRelationDefinitions('view', data, config);
|
|
23
|
+
var materializedViewDefinitions = this.createSortedRelationDefinitions('materializedView', data, config);
|
|
20
24
|
var functionDefinitions = this.createSortedFunctionDefinitions(data, config);
|
|
21
|
-
return new schema_definition_1.SchemaDefinition(data.name, enumDefinitions, tableDefinitions, functionDefinitions);
|
|
25
|
+
return new schema_definition_1.SchemaDefinition(data.name, enumDefinitions, tableDefinitions, viewDefinitions, materializedViewDefinitions, functionDefinitions);
|
|
22
26
|
};
|
|
23
27
|
SchemaDefinitionFactory.validateDBObjectNames = function (dbObjects) {
|
|
24
28
|
var seen = new Set();
|
|
@@ -70,18 +74,20 @@ var SchemaDefinitionFactory = /** @class */ (function () {
|
|
|
70
74
|
(!config.copyComments &&
|
|
71
75
|
commentTokens.includes(shared_1.Directives.EnableTSDocComments)));
|
|
72
76
|
};
|
|
73
|
-
SchemaDefinitionFactory.
|
|
74
|
-
var
|
|
75
|
-
|
|
77
|
+
SchemaDefinitionFactory.createSortedRelationDefinitions = function (relationType, data, config) {
|
|
78
|
+
var sortedRelations = this.sortDBObjectData(relationType === 'table' ? data.tables
|
|
79
|
+
: relationType === 'view' ? data.views
|
|
80
|
+
: data.materializedViews);
|
|
81
|
+
return this.createRelationDefinitions(relationType, sortedRelations, config);
|
|
76
82
|
};
|
|
77
|
-
SchemaDefinitionFactory.
|
|
83
|
+
SchemaDefinitionFactory.createRelationDefinitions = function (relationType, relations, config) {
|
|
78
84
|
var _this = this;
|
|
79
|
-
var
|
|
80
|
-
var
|
|
85
|
+
var relationDefinitions = relations.map(function (relationData) {
|
|
86
|
+
var shouldCopyRelationComment = _this.shouldCopyDBObjectComment(relationData, config);
|
|
81
87
|
var comment = '';
|
|
82
|
-
if (
|
|
88
|
+
if (shouldCopyRelationComment) {
|
|
83
89
|
try {
|
|
84
|
-
comment = comments_1.CommentConverter.convertComment(
|
|
90
|
+
comment = comments_1.CommentConverter.convertComment(relationData.comment);
|
|
85
91
|
}
|
|
86
92
|
catch (e) {
|
|
87
93
|
if (e instanceof shared_1.ParsingError) {
|
|
@@ -93,7 +99,7 @@ var SchemaDefinitionFactory = /** @class */ (function () {
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
/*
|
|
96
|
-
By default, comments on a column are copied if the parent
|
|
102
|
+
By default, comments on a column are copied if the parent relation's
|
|
97
103
|
comments should be copied. This can be overridden with directives
|
|
98
104
|
applied to the column-level comment directly.
|
|
99
105
|
*/
|
|
@@ -101,14 +107,14 @@ var SchemaDefinitionFactory = /** @class */ (function () {
|
|
|
101
107
|
if (!comment)
|
|
102
108
|
return false;
|
|
103
109
|
var tokens = (0, shared_1.getTokens)(comment);
|
|
104
|
-
return ((
|
|
110
|
+
return ((shouldCopyRelationComment &&
|
|
105
111
|
!tokens.includes(shared_1.Directives.DisableTSDocComments)) ||
|
|
106
|
-
(!
|
|
112
|
+
(!shouldCopyRelationComment &&
|
|
107
113
|
tokens.includes(shared_1.Directives.EnableTSDocComments)));
|
|
108
114
|
};
|
|
109
|
-
var columnDefinitions =
|
|
110
|
-
var tsType = (0, types_1.lookupType)(columnData.type,
|
|
111
|
-
var typeDefinition = new
|
|
115
|
+
var columnDefinitions = relationData.columns.map(function (columnData) {
|
|
116
|
+
var tsType = (0, types_1.lookupType)(columnData.type, relationData.schema, config);
|
|
117
|
+
var typeDefinition = new relations_1.ColumnTypeDefinition(tsType, columnData.type.numDimensions, columnData.type.isNullable);
|
|
112
118
|
var comment = '';
|
|
113
119
|
if (shouldCopyColumnComment(columnData.comment)) {
|
|
114
120
|
try {
|
|
@@ -123,11 +129,15 @@ var SchemaDefinitionFactory = /** @class */ (function () {
|
|
|
123
129
|
}
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
|
-
return new
|
|
132
|
+
return new relations_1.ColumnDefinition(columnData.name, typeDefinition, comment);
|
|
127
133
|
});
|
|
128
|
-
return
|
|
134
|
+
return (relationType === 'table' ?
|
|
135
|
+
new relations_1.TableDefinition(relationData.name, columnDefinitions, comment)
|
|
136
|
+
: relationType === 'view' ?
|
|
137
|
+
new relations_1.ViewDefinition(relationData.name, columnDefinitions, comment)
|
|
138
|
+
: new relations_1.MaterializedViewDefinition(relationData.name, columnDefinitions, comment));
|
|
129
139
|
});
|
|
130
|
-
return
|
|
140
|
+
return relationDefinitions;
|
|
131
141
|
};
|
|
132
142
|
SchemaDefinitionFactory.createSortedFunctionDefinitions = function (data, config) {
|
|
133
143
|
var sortedFunctionData = this.sortDBObjectData(data.functions);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { EnumDefinition } from '../enums';
|
|
2
2
|
import { FunctionDefinition } from '../functions';
|
|
3
|
-
import { TableDefinition } from '../
|
|
3
|
+
import { TableDefinition, ViewDefinition, MaterializedViewDefinition } from '../relations';
|
|
4
4
|
export declare class SchemaDefinition {
|
|
5
5
|
protected pgSchemaName: string;
|
|
6
6
|
protected enumDefinitions: EnumDefinition[];
|
|
7
7
|
protected tableDefinitions: TableDefinition[];
|
|
8
|
+
protected viewDefinitions: ViewDefinition[];
|
|
9
|
+
protected materializedViewDefinitions: MaterializedViewDefinition[];
|
|
8
10
|
protected functionDefinitions: FunctionDefinition[];
|
|
9
|
-
constructor(pgSchemaName: string, enumDefinitions: EnumDefinition[], tableDefinitions: TableDefinition[], functionDefinitions: FunctionDefinition[]);
|
|
11
|
+
constructor(pgSchemaName: string, enumDefinitions: EnumDefinition[], tableDefinitions: TableDefinition[], viewDefinitions: ViewDefinition[], materializedViewDefinitions: MaterializedViewDefinition[], functionDefinitions: FunctionDefinition[]);
|
|
10
12
|
toString(): string;
|
|
11
13
|
}
|
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SchemaDefinition = void 0;
|
|
4
4
|
var shared_1 = require("../shared");
|
|
5
5
|
var SchemaDefinition = /** @class */ (function () {
|
|
6
|
-
function SchemaDefinition(pgSchemaName, enumDefinitions, tableDefinitions, functionDefinitions) {
|
|
6
|
+
function SchemaDefinition(pgSchemaName, enumDefinitions, tableDefinitions, viewDefinitions, materializedViewDefinitions, functionDefinitions) {
|
|
7
7
|
this.pgSchemaName = pgSchemaName;
|
|
8
8
|
this.enumDefinitions = enumDefinitions;
|
|
9
9
|
this.tableDefinitions = tableDefinitions;
|
|
10
|
+
this.viewDefinitions = viewDefinitions;
|
|
11
|
+
this.materializedViewDefinitions = materializedViewDefinitions;
|
|
10
12
|
this.functionDefinitions = functionDefinitions;
|
|
11
13
|
}
|
|
12
14
|
SchemaDefinition.prototype.toString = function () {
|
|
@@ -17,6 +19,12 @@ var SchemaDefinition = /** @class */ (function () {
|
|
|
17
19
|
var tables = this.tableDefinitions
|
|
18
20
|
.map(function (tableDef) { return tableDef.toString(); })
|
|
19
21
|
.join('\n\n');
|
|
22
|
+
var views = this.viewDefinitions
|
|
23
|
+
.map(function (viewDef) { return viewDef.toString(); })
|
|
24
|
+
.join('\n\n');
|
|
25
|
+
var materializedViews = this.materializedViewDefinitions
|
|
26
|
+
.map(function (matViewDef) { return matViewDef.toString(); })
|
|
27
|
+
.join('\n\n');
|
|
20
28
|
var functions = this.functionDefinitions
|
|
21
29
|
.map(function (funcDef) { return funcDef.toString(); })
|
|
22
30
|
.join('\n\n');
|
|
@@ -27,6 +35,12 @@ var SchemaDefinition = /** @class */ (function () {
|
|
|
27
35
|
if (tables.length) {
|
|
28
36
|
result += "\n\n export namespace Tables {\n".concat((0, shared_1.indent)(tables, 4), "\n }");
|
|
29
37
|
}
|
|
38
|
+
if (views.length) {
|
|
39
|
+
result += "\n\n export namespace Views {\n".concat((0, shared_1.indent)(views, 4), "\n }");
|
|
40
|
+
}
|
|
41
|
+
if (materializedViews.length) {
|
|
42
|
+
result += "\n\n export namespace MaterializedViews {\n".concat((0, shared_1.indent)(materializedViews, 4), "\n }");
|
|
43
|
+
}
|
|
30
44
|
if (functions.length) {
|
|
31
45
|
result += "\n\n export namespace Functions {\n".concat((0, shared_1.indent)(functions, 4), "\n }");
|
|
32
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertPGIdentifierToTSIdentifier = convertPGIdentifierToTSIdentifier;
|
|
4
|
+
var capitalize_1 = require("./capitalize");
|
|
4
5
|
/**
|
|
5
6
|
* Converts a PostgreSQL identifier to a valid TypeScript identifier.
|
|
6
7
|
*
|
|
@@ -47,11 +48,8 @@ function convertPGIdentifierToTSIdentifier(identifier) {
|
|
|
47
48
|
if (word.length) {
|
|
48
49
|
words.push(word);
|
|
49
50
|
}
|
|
50
|
-
var result = prefix + words.map(function (word) { return capitalize(word); }).join('');
|
|
51
|
+
var result = prefix + words.map(function (word) { return (0, capitalize_1.capitalize)(word); }).join('');
|
|
51
52
|
if (/^\d/.test(result))
|
|
52
53
|
result = '_' + result;
|
|
53
54
|
return result;
|
|
54
55
|
}
|
|
55
|
-
function capitalize(str) {
|
|
56
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
57
|
-
}
|
package/dist/shared/index.d.ts
CHANGED
package/dist/shared/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./capitalize"), exports);
|
|
17
18
|
__exportStar(require("./directives"), exports);
|
|
18
19
|
__exportStar(require("./get-tokens"), exports);
|
|
19
20
|
__exportStar(require("./indent"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "introspeql",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "IntrospeQL reads information about the schemas, tables,
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "IntrospeQL reads information about the schemas, tables, views, materialized views, functions and enums in your PostgreSQL database and produces a TypeScript file detailing type information for each object in the database.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
package/dist/tables/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './column-data';
|
|
2
|
-
export * from './column-definition';
|
|
3
|
-
export * from './column-type-definition';
|
|
4
|
-
export * from './read-column-data';
|
|
5
|
-
export * from './read-table-data';
|
|
6
|
-
export * from './should-include-table';
|
|
7
|
-
export * from './table-data';
|
|
8
|
-
export * from './table-definition';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ColumnDefinition } from './column-definition';
|
|
2
|
-
export declare class TableDefinition {
|
|
3
|
-
protected pgTableName: string;
|
|
4
|
-
protected columns: ColumnDefinition[];
|
|
5
|
-
private comment?;
|
|
6
|
-
constructor(pgTableName: string, columns: ColumnDefinition[], comment?: string);
|
|
7
|
-
toString(): string;
|
|
8
|
-
protected createColumnNamesUnion(): string;
|
|
9
|
-
protected createRowTypeDefinition(): string;
|
|
10
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|