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
package/dist/introspeql.js
CHANGED
|
@@ -107,8 +107,8 @@ function introspeql(config) {
|
|
|
107
107
|
return schemas_1.SchemaDefinitionFactory.createSchemaDefinition(schemaData, parsedConfig);
|
|
108
108
|
});
|
|
109
109
|
typeDefinitionFileContents = createTypeDefinitionFileContents(schemaDefinitions, parsedConfig);
|
|
110
|
-
if (!
|
|
111
|
-
return [4 /*yield*/, writeTypeDefinitionsFile(typeDefinitionFileContents,
|
|
110
|
+
if (!parsedConfig.writeToDisk) return [3 /*break*/, 5];
|
|
111
|
+
return [4 /*yield*/, writeTypeDefinitionsFile(typeDefinitionFileContents, parsedConfig.outFile)];
|
|
112
112
|
case 4:
|
|
113
113
|
_a.sent();
|
|
114
114
|
_a.label = 5;
|
|
@@ -126,12 +126,12 @@ function introspeql(config) {
|
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
function createTypeDefinitionFileContents(schemaDefinitions,
|
|
129
|
+
function createTypeDefinitionFileContents(schemaDefinitions, parsedConfig) {
|
|
130
130
|
var fileContents = schemaDefinitions
|
|
131
131
|
.map(function (schemaDef) { return schemaDef.toString(); })
|
|
132
132
|
.join('\n\n');
|
|
133
|
-
if (
|
|
134
|
-
var header =
|
|
133
|
+
if (parsedConfig.header) {
|
|
134
|
+
var header = parsedConfig.header;
|
|
135
135
|
while (!header.endsWith('\n\n')) {
|
|
136
136
|
header += '\n';
|
|
137
137
|
}
|
|
@@ -147,7 +147,7 @@ function writeTypeDefinitionsFile(fileContents, outFile) {
|
|
|
147
147
|
case 0:
|
|
148
148
|
directoryPath = path.dirname(outFile);
|
|
149
149
|
if (!!(0, fs_1.existsSync)(directoryPath)) return [3 /*break*/, 2];
|
|
150
|
-
return [4 /*yield*/, (0, promises_1.mkdir)(directoryPath)];
|
|
150
|
+
return [4 /*yield*/, (0, promises_1.mkdir)(directoryPath, { recursive: true })];
|
|
151
151
|
case 1:
|
|
152
152
|
_a.sent();
|
|
153
153
|
_a.label = 2;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ColumnDefinition } from './column-definition';
|
|
2
|
+
export declare abstract class AbstractRelationDefinition {
|
|
3
|
+
protected pgRelationName: string;
|
|
4
|
+
protected columns: ColumnDefinition[];
|
|
5
|
+
protected comment?: string;
|
|
6
|
+
protected abstract relationType: string;
|
|
7
|
+
constructor(pgRelationName: string, columns: ColumnDefinition[], comment?: string);
|
|
8
|
+
toString(): string;
|
|
9
|
+
protected createColumnNamesUnion(): string;
|
|
10
|
+
protected createRowTypeDefinition(): string;
|
|
11
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AbstractRelationDefinition = void 0;
|
|
4
4
|
var shared_1 = require("../shared");
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
this.
|
|
5
|
+
var AbstractRelationDefinition = /** @class */ (function () {
|
|
6
|
+
function AbstractRelationDefinition(pgRelationName, columns, comment) {
|
|
7
|
+
this.pgRelationName = pgRelationName;
|
|
8
8
|
this.columns = columns;
|
|
9
9
|
this.comment = comment;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
var tsNamespaceName = (0, shared_1.convertPGIdentifierToTSIdentifier)(this.
|
|
11
|
+
AbstractRelationDefinition.prototype.toString = function () {
|
|
12
|
+
var tsNamespaceName = (0, shared_1.convertPGIdentifierToTSIdentifier)(this.pgRelationName);
|
|
13
13
|
var columnNames = this.createColumnNamesUnion();
|
|
14
14
|
var rowType = this.createRowTypeDefinition();
|
|
15
|
-
var stringified = "export namespace ".concat(tsNamespaceName, " {\n export const
|
|
15
|
+
var stringified = "export namespace ".concat(tsNamespaceName, " {\n export const PG").concat((0, shared_1.capitalize)(this.relationType), "Name = '").concat(this.pgRelationName, "';\n\n").concat((0, shared_1.indent)(columnNames, 2), "\n\n").concat((0, shared_1.indent)(rowType, 2), "\n}");
|
|
16
16
|
if (this.comment) {
|
|
17
17
|
stringified = this.comment + '\n' + stringified;
|
|
18
18
|
}
|
|
19
19
|
return stringified;
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
AbstractRelationDefinition.prototype.createColumnNamesUnion = function () {
|
|
22
22
|
if (this.columns.length === 0) {
|
|
23
23
|
return 'export type ColumnNames = never;';
|
|
24
24
|
}
|
|
@@ -29,7 +29,7 @@ var TableDefinition = /** @class */ (function () {
|
|
|
29
29
|
.join(' |\n');
|
|
30
30
|
return "export type ColumnNames = |\n".concat((0, shared_1.indent)(columnNames, 2), ";");
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
AbstractRelationDefinition.prototype.createRowTypeDefinition = function () {
|
|
33
33
|
if (this.columns.length === 0) {
|
|
34
34
|
return 'export interface RowType {}';
|
|
35
35
|
}
|
|
@@ -38,6 +38,6 @@ var TableDefinition = /** @class */ (function () {
|
|
|
38
38
|
.join('\n');
|
|
39
39
|
return "export interface RowType {\n".concat((0, shared_1.indent)(columnDefinitions, 2), "\n}");
|
|
40
40
|
};
|
|
41
|
-
return
|
|
41
|
+
return AbstractRelationDefinition;
|
|
42
42
|
}());
|
|
43
|
-
exports.
|
|
43
|
+
exports.AbstractRelationDefinition = AbstractRelationDefinition;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './abstract-relation-definition';
|
|
2
|
+
export * from './column-data';
|
|
3
|
+
export * from './column-definition';
|
|
4
|
+
export * from './column-type-definition';
|
|
5
|
+
export * from './materialized-view-definition';
|
|
6
|
+
export * from './read-column-data';
|
|
7
|
+
export * from './read-relation-data';
|
|
8
|
+
export * from './relation-data';
|
|
9
|
+
export * from './should-include-relation';
|
|
10
|
+
export * from './table-definition';
|
|
11
|
+
export * from './view-definition';
|
|
@@ -14,11 +14,14 @@ 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("./abstract-relation-definition"), exports);
|
|
17
18
|
__exportStar(require("./column-data"), exports);
|
|
18
19
|
__exportStar(require("./column-definition"), exports);
|
|
19
20
|
__exportStar(require("./column-type-definition"), exports);
|
|
21
|
+
__exportStar(require("./materialized-view-definition"), exports);
|
|
20
22
|
__exportStar(require("./read-column-data"), exports);
|
|
21
|
-
__exportStar(require("./read-
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
23
|
+
__exportStar(require("./read-relation-data"), exports);
|
|
24
|
+
__exportStar(require("./relation-data"), exports);
|
|
25
|
+
__exportStar(require("./should-include-relation"), exports);
|
|
24
26
|
__exportStar(require("./table-definition"), exports);
|
|
27
|
+
__exportStar(require("./view-definition"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.MaterializedViewDefinition = void 0;
|
|
19
|
+
var abstract_relation_definition_1 = require("./abstract-relation-definition");
|
|
20
|
+
var MaterializedViewDefinition = /** @class */ (function (_super) {
|
|
21
|
+
__extends(MaterializedViewDefinition, _super);
|
|
22
|
+
function MaterializedViewDefinition() {
|
|
23
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
_this.relationType = 'materializedView';
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
return MaterializedViewDefinition;
|
|
28
|
+
}(abstract_relation_definition_1.AbstractRelationDefinition));
|
|
29
|
+
exports.MaterializedViewDefinition = MaterializedViewDefinition;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type RelationData } from './relation-data';
|
|
2
|
+
import type { Client } from 'pg';
|
|
3
|
+
import type { ParsedConfig } from '../config';
|
|
4
|
+
export declare function readRelationData(relationType: 'table' | 'view' | 'materializedView', client: Client, config: ParsedConfig): Promise<RelationData[]>;
|
|
@@ -45,29 +45,32 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
function
|
|
48
|
+
exports.readRelationData = readRelationData;
|
|
49
|
+
var relation_data_1 = require("./relation-data");
|
|
50
|
+
var should_include_relation_1 = require("./should-include-relation");
|
|
51
|
+
function readRelationData(relationType, client, config) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
var schemaPlaceholders, query, parameters, result,
|
|
53
|
+
var relkind, schemaPlaceholders, query, parameters, result, relationData;
|
|
54
54
|
return __generator(this, function (_a) {
|
|
55
55
|
switch (_a.label) {
|
|
56
56
|
case 0:
|
|
57
|
+
relkind = relationType === 'table' ? 'r'
|
|
58
|
+
: relationType === 'view' ? 'v'
|
|
59
|
+
: 'm';
|
|
57
60
|
schemaPlaceholders = config.schemas
|
|
58
61
|
.map(function (_, i) { return "$".concat(i + 1); })
|
|
59
62
|
.join(', ');
|
|
60
|
-
query = "\nSELECT \n c.oid AS oid, \n n.nspname AS schema, \n c.relname AS name,\n obj_description(c.oid, 'pg_class') AS comment\nFROM pg_catalog.pg_class AS c\nINNER JOIN pg_catalog.pg_namespace AS n ON c.relnamespace = n.oid\nWHERE c.relkind = '
|
|
63
|
+
query = "\nSELECT \n c.oid AS oid, \n n.nspname AS schema, \n c.relname AS name,\n obj_description(c.oid, 'pg_class') AS comment\nFROM pg_catalog.pg_class AS c\nINNER JOIN pg_catalog.pg_namespace AS n ON c.relnamespace = n.oid\nWHERE c.relkind = '".concat(relkind, "' AND n.nspname IN (").concat(schemaPlaceholders, ");\n");
|
|
61
64
|
parameters = __spreadArray([], config.schemas, true);
|
|
62
65
|
return [4 /*yield*/, client.query(query, parameters)];
|
|
63
66
|
case 1:
|
|
64
67
|
result = _a.sent();
|
|
65
|
-
|
|
68
|
+
relationData = relation_data_1.relationDataSchema
|
|
66
69
|
.array()
|
|
67
70
|
.parse(result.rows)
|
|
68
71
|
.filter(function (_a) {
|
|
69
72
|
var name = _a.name, schema = _a.schema, comment = _a.comment;
|
|
70
|
-
return (0,
|
|
73
|
+
return (0, should_include_relation_1.shouldIncludeRelation)({
|
|
71
74
|
name: name,
|
|
72
75
|
schema: schema,
|
|
73
76
|
comment: comment,
|
|
@@ -77,7 +80,7 @@ function readTableData(client, config) {
|
|
|
77
80
|
: config.tables.includeTables,
|
|
78
81
|
});
|
|
79
82
|
});
|
|
80
|
-
return [2 /*return*/,
|
|
83
|
+
return [2 /*return*/, relationData];
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
86
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const relationDataSchema: z.ZodObject<{
|
|
3
3
|
oid: z.ZodNumber;
|
|
4
4
|
schema: z.ZodString;
|
|
5
5
|
name: z.ZodString;
|
|
6
6
|
comment: z.ZodNullable<z.ZodString>;
|
|
7
7
|
}, z.core.$strip>;
|
|
8
|
-
export type
|
|
8
|
+
export type RelationData = z.infer<typeof relationDataSchema>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.relationDataSchema = void 0;
|
|
4
4
|
var zod_1 = require("zod");
|
|
5
|
-
exports.
|
|
5
|
+
exports.relationDataSchema = zod_1.z.object({
|
|
6
6
|
oid: zod_1.z.number(),
|
|
7
7
|
schema: zod_1.z.string(),
|
|
8
8
|
name: zod_1.z.string(),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { EntityData } from '../config/entity-data';
|
|
2
|
-
interface
|
|
2
|
+
interface ShouldIncludeRelationParams {
|
|
3
3
|
name: string;
|
|
4
4
|
schema: string;
|
|
5
5
|
comment: string | null;
|
|
6
6
|
mode: 'inclusive' | 'exclusive';
|
|
7
7
|
exceptions: EntityData[];
|
|
8
8
|
}
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function shouldIncludeRelation({ name, schema, comment, mode, exceptions, }: ShouldIncludeRelationParams): boolean;
|
|
10
10
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.shouldIncludeRelation = shouldIncludeRelation;
|
|
4
4
|
var shared_1 = require("../shared");
|
|
5
|
-
function
|
|
5
|
+
function shouldIncludeRelation(_a) {
|
|
6
6
|
var name = _a.name, schema = _a.schema, comment = _a.comment, mode = _a.mode, exceptions = _a.exceptions;
|
|
7
7
|
var tokens = (0, shared_1.getTokens)(comment);
|
|
8
8
|
if (mode === 'inclusive') {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TableDefinition = void 0;
|
|
19
|
+
var abstract_relation_definition_1 = require("./abstract-relation-definition");
|
|
20
|
+
var TableDefinition = /** @class */ (function (_super) {
|
|
21
|
+
__extends(TableDefinition, _super);
|
|
22
|
+
function TableDefinition() {
|
|
23
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
_this.relationType = 'table';
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
return TableDefinition;
|
|
28
|
+
}(abstract_relation_definition_1.AbstractRelationDefinition));
|
|
29
|
+
exports.TableDefinition = TableDefinition;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ViewDefinition = void 0;
|
|
19
|
+
var abstract_relation_definition_1 = require("./abstract-relation-definition");
|
|
20
|
+
var ViewDefinition = /** @class */ (function (_super) {
|
|
21
|
+
__extends(ViewDefinition, _super);
|
|
22
|
+
function ViewDefinition() {
|
|
23
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
_this.relationType = 'view';
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
return ViewDefinition;
|
|
28
|
+
}(abstract_relation_definition_1.AbstractRelationDefinition));
|
|
29
|
+
exports.ViewDefinition = ViewDefinition;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { Client } from 'pg';
|
|
2
2
|
import { type EnumData } from '../enums';
|
|
3
3
|
import { type FunctionData } from '../functions';
|
|
4
|
-
import { type ColumnData, type
|
|
4
|
+
import { type ColumnData, type RelationData } from '../relations';
|
|
5
5
|
import type { ParsedConfig } from '../config';
|
|
6
|
-
export interface
|
|
6
|
+
export interface RelationDataWithColumns extends RelationData {
|
|
7
7
|
columns: ColumnData[];
|
|
8
8
|
}
|
|
9
9
|
export interface SchemaData {
|
|
10
10
|
name: string;
|
|
11
11
|
enums: EnumData[];
|
|
12
12
|
functions: FunctionData[];
|
|
13
|
-
tables:
|
|
13
|
+
tables: RelationDataWithColumns[];
|
|
14
|
+
views: RelationDataWithColumns[];
|
|
15
|
+
materializedViews: RelationDataWithColumns[];
|
|
14
16
|
}
|
|
15
17
|
export declare function readSchemaData(client: Client, parsedConfig: ParsedConfig): Promise<Record<string, SchemaData>>;
|
|
@@ -48,115 +48,151 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.readSchemaData = readSchemaData;
|
|
51
|
+
var zod_1 = require("zod");
|
|
51
52
|
var enums_1 = require("../enums");
|
|
52
53
|
var functions_1 = require("../functions");
|
|
53
|
-
var
|
|
54
|
+
var relations_1 = require("../relations");
|
|
54
55
|
function readSchemaData(client, parsedConfig) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var schemas
|
|
57
|
-
return __generator(this, function (
|
|
58
|
-
switch (
|
|
57
|
+
var schemas;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
59
60
|
case 0:
|
|
60
61
|
schemas = {};
|
|
61
|
-
return [4 /*yield*/,
|
|
62
|
+
return [4 /*yield*/, Promise.all([
|
|
63
|
+
readAndRegisterFunctionData(schemas, client, parsedConfig),
|
|
64
|
+
readAndRegisterRelationData('table', schemas, client, parsedConfig),
|
|
65
|
+
readAndRegisterRelationData('view', schemas, client, parsedConfig),
|
|
66
|
+
readAndRegisterRelationData('materializedView', schemas, client, parsedConfig),
|
|
67
|
+
])];
|
|
68
|
+
case 1:
|
|
69
|
+
_a.sent();
|
|
70
|
+
return [2 /*return*/, schemas];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function readAndRegisterFunctionData(schemas, client, parsedConfig) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var functions, _i, functions_2, f, _a, _b, overload, _c, _d, paramType;
|
|
78
|
+
return __generator(this, function (_e) {
|
|
79
|
+
switch (_e.label) {
|
|
80
|
+
case 0: return [4 /*yield*/, (0, functions_1.readFunctionData)(client, parsedConfig)];
|
|
62
81
|
case 1:
|
|
63
|
-
functions =
|
|
82
|
+
functions = _e.sent();
|
|
64
83
|
_i = 0, functions_2 = functions;
|
|
65
|
-
|
|
84
|
+
_e.label = 2;
|
|
66
85
|
case 2:
|
|
67
86
|
if (!(_i < functions_2.length)) return [3 /*break*/, 11];
|
|
68
87
|
f = functions_2[_i];
|
|
69
|
-
registerDBObject(f, schemas);
|
|
88
|
+
registerDBObject(f, 'function', schemas);
|
|
70
89
|
_a = 0, _b = f.overloads;
|
|
71
|
-
|
|
90
|
+
_e.label = 3;
|
|
72
91
|
case 3:
|
|
73
92
|
if (!(_a < _b.length)) return [3 /*break*/, 10];
|
|
74
93
|
overload = _b[_a];
|
|
75
94
|
_c = 0, _d = overload.paramTypes;
|
|
76
|
-
|
|
95
|
+
_e.label = 4;
|
|
77
96
|
case 4:
|
|
78
97
|
if (!(_c < _d.length)) return [3 /*break*/, 7];
|
|
79
98
|
paramType = _d[_c];
|
|
80
99
|
return [4 /*yield*/, readAndRegisterTypeIfEnum(paramType, client, parsedConfig, schemas)];
|
|
81
100
|
case 5:
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
_e.sent();
|
|
102
|
+
_e.label = 6;
|
|
84
103
|
case 6:
|
|
85
104
|
_c++;
|
|
86
105
|
return [3 /*break*/, 4];
|
|
87
106
|
case 7: return [4 /*yield*/, readAndRegisterTypeIfEnum(overload.returnType, client, parsedConfig, schemas)];
|
|
88
107
|
case 8:
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
_e.sent();
|
|
109
|
+
_e.label = 9;
|
|
91
110
|
case 9:
|
|
92
111
|
_a++;
|
|
93
112
|
return [3 /*break*/, 3];
|
|
94
113
|
case 10:
|
|
95
114
|
_i++;
|
|
96
115
|
return [3 /*break*/, 2];
|
|
97
|
-
case 11: return [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case
|
|
113
|
-
if (!(
|
|
114
|
-
|
|
116
|
+
case 11: return [2 /*return*/];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function readAndRegisterRelationData(relationType, schemas, client, parsedConfig) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var relations, _i, relations_2, r, columns, relationDataWithColumns, _a, columns_1, column;
|
|
124
|
+
return __generator(this, function (_b) {
|
|
125
|
+
switch (_b.label) {
|
|
126
|
+
case 0: return [4 /*yield*/, (0, relations_1.readRelationData)(relationType, client, parsedConfig)];
|
|
127
|
+
case 1:
|
|
128
|
+
relations = _b.sent();
|
|
129
|
+
_i = 0, relations_2 = relations;
|
|
130
|
+
_b.label = 2;
|
|
131
|
+
case 2:
|
|
132
|
+
if (!(_i < relations_2.length)) return [3 /*break*/, 8];
|
|
133
|
+
r = relations_2[_i];
|
|
134
|
+
return [4 /*yield*/, (0, relations_1.readColumnData)(client, r.oid)];
|
|
135
|
+
case 3:
|
|
136
|
+
columns = _b.sent();
|
|
137
|
+
relationDataWithColumns = __assign(__assign({}, r), { columns: columns });
|
|
138
|
+
registerDBObject(relationDataWithColumns, relationType, schemas);
|
|
139
|
+
_a = 0, columns_1 = columns;
|
|
140
|
+
_b.label = 4;
|
|
141
|
+
case 4:
|
|
142
|
+
if (!(_a < columns_1.length)) return [3 /*break*/, 7];
|
|
143
|
+
column = columns_1[_a];
|
|
115
144
|
return [4 /*yield*/, readAndRegisterTypeIfEnum(column.type, client, parsedConfig, schemas)];
|
|
116
|
-
case
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
case
|
|
120
|
-
|
|
121
|
-
return [3 /*break*/,
|
|
122
|
-
case
|
|
123
|
-
|
|
124
|
-
return [3 /*break*/,
|
|
125
|
-
case
|
|
145
|
+
case 5:
|
|
146
|
+
_b.sent();
|
|
147
|
+
_b.label = 6;
|
|
148
|
+
case 6:
|
|
149
|
+
_a++;
|
|
150
|
+
return [3 /*break*/, 4];
|
|
151
|
+
case 7:
|
|
152
|
+
_i++;
|
|
153
|
+
return [3 /*break*/, 2];
|
|
154
|
+
case 8: return [2 /*return*/];
|
|
126
155
|
}
|
|
127
156
|
});
|
|
128
157
|
});
|
|
129
158
|
}
|
|
130
|
-
function registerDBObject(dbObject, schemas) {
|
|
159
|
+
function registerDBObject(dbObject, dbObjectType, schemas) {
|
|
131
160
|
if (!(dbObject.schema in schemas)) {
|
|
132
161
|
schemas[dbObject.schema] = {
|
|
133
162
|
name: dbObject.schema,
|
|
134
163
|
enums: [],
|
|
135
164
|
functions: [],
|
|
136
165
|
tables: [],
|
|
166
|
+
views: [],
|
|
167
|
+
materializedViews: [],
|
|
137
168
|
};
|
|
138
169
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
170
|
+
var relationDataWithColumns = zod_1.z.intersection(relations_1.relationDataSchema, zod_1.z.object({
|
|
171
|
+
columns: relations_1.columnDataSchema.array(),
|
|
172
|
+
}));
|
|
173
|
+
switch (dbObjectType) {
|
|
174
|
+
case 'enum':
|
|
175
|
+
var enumData = enums_1.enumDataSchema.parse(dbObject);
|
|
176
|
+
schemas[dbObject.schema].enums.push(enumData);
|
|
177
|
+
break;
|
|
178
|
+
case 'function':
|
|
179
|
+
var functionData = functions_1.functionDataSchema.parse(dbObject);
|
|
180
|
+
schemas[dbObject.schema].functions.push(functionData);
|
|
181
|
+
break;
|
|
182
|
+
case 'table':
|
|
183
|
+
var tableData = relationDataWithColumns.parse(dbObject);
|
|
184
|
+
schemas[dbObject.schema].tables.push(tableData);
|
|
185
|
+
break;
|
|
186
|
+
case 'view':
|
|
187
|
+
var viewData = relationDataWithColumns.parse(dbObject);
|
|
188
|
+
schemas[dbObject.schema].views.push(viewData);
|
|
189
|
+
break;
|
|
190
|
+
case 'materializedView':
|
|
191
|
+
var materializedViewData = relationDataWithColumns.parse(dbObject);
|
|
192
|
+
schemas[dbObject.schema].materializedViews.push(materializedViewData);
|
|
193
|
+
break;
|
|
147
194
|
}
|
|
148
195
|
}
|
|
149
|
-
function isEnumData(dbObject) {
|
|
150
|
-
return enums_1.enumDataSchema.safeParse(dbObject).success;
|
|
151
|
-
}
|
|
152
|
-
function isFunctionData(dbObject) {
|
|
153
|
-
return functions_1.functionDataSchema.safeParse(dbObject).success;
|
|
154
|
-
}
|
|
155
|
-
function isTableDataWithColumns(dbObject) {
|
|
156
|
-
return (tables_1.tableDataSchema.safeParse(dbObject).success &&
|
|
157
|
-
'columns' in dbObject &&
|
|
158
|
-
tables_1.columnDataSchema.array().safeParse(dbObject.columns).success);
|
|
159
|
-
}
|
|
160
196
|
function readAndRegisterTypeIfEnum(maybeEnum, client, parsedConfig, schemas) {
|
|
161
197
|
return __awaiter(this, void 0, void 0, function () {
|
|
162
198
|
var enumData;
|
|
@@ -164,13 +200,14 @@ function readAndRegisterTypeIfEnum(maybeEnum, client, parsedConfig, schemas) {
|
|
|
164
200
|
switch (_a.label) {
|
|
165
201
|
case 0:
|
|
166
202
|
if (!(maybeEnum.isEnum &&
|
|
167
|
-
!isEnumDefinedInConfig(maybeEnum.schema, maybeEnum.name, parsedConfig)
|
|
168
|
-
!(maybeEnum.schema in schemas &&
|
|
169
|
-
schemas[maybeEnum.schema].enums.some(function (e) { return e.name === maybeEnum.name; })))) return [3 /*break*/, 2];
|
|
203
|
+
!isEnumDefinedInConfig(maybeEnum.schema, maybeEnum.name, parsedConfig))) return [3 /*break*/, 2];
|
|
170
204
|
return [4 /*yield*/, (0, enums_1.readEnumData)(client, maybeEnum.oid)];
|
|
171
205
|
case 1:
|
|
172
206
|
enumData = _a.sent();
|
|
173
|
-
|
|
207
|
+
if (!(maybeEnum.schema in schemas &&
|
|
208
|
+
schemas[maybeEnum.schema].enums.some(function (e) { return e.name === maybeEnum.name; }))) {
|
|
209
|
+
registerDBObject(enumData, 'enum', schemas);
|
|
210
|
+
}
|
|
174
211
|
_a.label = 2;
|
|
175
212
|
case 2: return [2 /*return*/];
|
|
176
213
|
}
|
|
@@ -8,8 +8,8 @@ export declare class SchemaDefinitionFactory {
|
|
|
8
8
|
private static sortDBObjectData;
|
|
9
9
|
private static createEnumDefinitions;
|
|
10
10
|
private static shouldCopyDBObjectComment;
|
|
11
|
-
private static
|
|
12
|
-
private static
|
|
11
|
+
private static createSortedRelationDefinitions;
|
|
12
|
+
private static createRelationDefinitions;
|
|
13
13
|
private static createSortedFunctionDefinitions;
|
|
14
14
|
private static createFunctionDefinitions;
|
|
15
15
|
}
|