introspeql 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +88 -59
  2. package/dist/config/create-relation-options.d.ts +22 -0
  3. package/dist/config/create-relation-options.js +60 -0
  4. package/dist/config/index.d.ts +52 -0
  5. package/dist/config/index.js +14 -0
  6. package/dist/config/materialized-view-options.d.ts +24 -0
  7. package/dist/config/materialized-view-options.js +5 -0
  8. package/dist/config/table-options.d.ts +21 -18
  9. package/dist/config/table-options.js +2 -45
  10. package/dist/config/view-options.d.ts +24 -0
  11. package/dist/config/view-options.js +5 -0
  12. package/dist/relations/abstract-relation-definition.d.ts +11 -0
  13. package/dist/{tables/table-definition.js → relations/abstract-relation-definition.js} +11 -11
  14. package/dist/relations/index.d.ts +11 -0
  15. package/dist/{tables → relations}/index.js +6 -3
  16. package/dist/relations/materialized-view-definition.d.ts +4 -0
  17. package/dist/relations/materialized-view-definition.js +29 -0
  18. package/dist/relations/read-relation-data.d.ts +4 -0
  19. package/dist/{tables/read-table-data.js → relations/read-relation-data.js} +12 -9
  20. package/dist/{tables/table-data.d.ts → relations/relation-data.d.ts} +2 -2
  21. package/dist/{tables/table-data.js → relations/relation-data.js} +2 -2
  22. package/dist/{tables/should-include-table.d.ts → relations/should-include-relation.d.ts} +2 -2
  23. package/dist/{tables/should-include-table.js → relations/should-include-relation.js} +2 -2
  24. package/dist/relations/table-definition.d.ts +4 -0
  25. package/dist/relations/table-definition.js +29 -0
  26. package/dist/relations/view-definition.d.ts +4 -0
  27. package/dist/relations/view-definition.js +29 -0
  28. package/dist/schemas/read-schema-data.d.ts +5 -3
  29. package/dist/schemas/read-schema-data.js +103 -66
  30. package/dist/schemas/schema-definition-factory.d.ts +2 -2
  31. package/dist/schemas/schema-definition-factory.js +30 -20
  32. package/dist/schemas/schema-definition.d.ts +4 -2
  33. package/dist/schemas/schema-definition.js +15 -1
  34. package/dist/shared/capitalize.d.ts +1 -0
  35. package/dist/shared/capitalize.js +6 -0
  36. package/dist/shared/convert-pg-identifier-to-ts-identifier.js +2 -4
  37. package/dist/shared/index.d.ts +1 -0
  38. package/dist/shared/index.js +1 -0
  39. package/package.json +2 -2
  40. package/dist/tables/index.d.ts +0 -8
  41. package/dist/tables/read-table-data.d.ts +0 -4
  42. package/dist/tables/table-definition.d.ts +0 -10
  43. /package/dist/{tables → relations}/column-data.d.ts +0 -0
  44. /package/dist/{tables → relations}/column-data.js +0 -0
  45. /package/dist/{tables → relations}/column-definition.d.ts +0 -0
  46. /package/dist/{tables → relations}/column-definition.js +0 -0
  47. /package/dist/{tables → relations}/column-type-definition.d.ts +0 -0
  48. /package/dist/{tables → relations}/column-type-definition.js +0 -0
  49. /package/dist/{tables → relations}/read-column-data.d.ts +0 -0
  50. /package/dist/{tables → relations}/read-column-data.js +0 -0
@@ -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.TableDefinition = void 0;
3
+ exports.AbstractRelationDefinition = void 0;
4
4
  var shared_1 = require("../shared");
5
- var TableDefinition = /** @class */ (function () {
6
- function TableDefinition(pgTableName, columns, comment) {
7
- this.pgTableName = pgTableName;
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
- TableDefinition.prototype.toString = function () {
12
- var tsNamespaceName = (0, shared_1.convertPGIdentifierToTSIdentifier)(this.pgTableName);
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 PGTableName = '").concat(this.pgTableName, "';\n\n").concat((0, shared_1.indent)(columnNames, 2), "\n\n").concat((0, shared_1.indent)(rowType, 2), "\n}");
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
- TableDefinition.prototype.createColumnNamesUnion = function () {
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
- TableDefinition.prototype.createRowTypeDefinition = function () {
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 TableDefinition;
41
+ return AbstractRelationDefinition;
42
42
  }());
43
- exports.TableDefinition = TableDefinition;
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-table-data"), exports);
22
- __exportStar(require("./should-include-table"), exports);
23
- __exportStar(require("./table-data"), exports);
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,4 @@
1
+ import { AbstractRelationDefinition } from './abstract-relation-definition';
2
+ export declare class MaterializedViewDefinition extends AbstractRelationDefinition {
3
+ protected relationType: string;
4
+ }
@@ -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.readTableData = readTableData;
49
- var table_data_1 = require("./table-data");
50
- var should_include_table_1 = require("./should-include-table");
51
- function readTableData(client, config) {
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, tableData;
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 = 'r' AND n.nspname IN (".concat(schemaPlaceholders, ");\n");
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
- tableData = table_data_1.tableDataSchema
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, should_include_table_1.shouldIncludeTable)({
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*/, tableData];
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 tableDataSchema: z.ZodObject<{
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 TableData = z.infer<typeof tableDataSchema>;
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.tableDataSchema = void 0;
3
+ exports.relationDataSchema = void 0;
4
4
  var zod_1 = require("zod");
5
- exports.tableDataSchema = zod_1.z.object({
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 ShouldIncludeTableParams {
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 shouldIncludeTable({ name, schema, comment, mode, exceptions, }: ShouldIncludeTableParams): boolean;
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.shouldIncludeTable = shouldIncludeTable;
3
+ exports.shouldIncludeRelation = shouldIncludeRelation;
4
4
  var shared_1 = require("../shared");
5
- function shouldIncludeTable(_a) {
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,4 @@
1
+ import { AbstractRelationDefinition } from './abstract-relation-definition';
2
+ export declare class TableDefinition extends AbstractRelationDefinition {
3
+ protected relationType: string;
4
+ }
@@ -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,4 @@
1
+ import { AbstractRelationDefinition } from './abstract-relation-definition';
2
+ export declare class ViewDefinition extends AbstractRelationDefinition {
3
+ protected relationType: string;
4
+ }
@@ -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 TableData } from '../tables';
4
+ import { type ColumnData, type RelationData } from '../relations';
5
5
  import type { ParsedConfig } from '../config';
6
- export interface TableDataWithColumns extends TableData {
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: TableDataWithColumns[];
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 tables_1 = require("../tables");
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, functions, _i, functions_2, f, _a, _b, overload, _c, _d, paramType, tables, _e, tables_2, t, columns, tableDataWithColumns, _f, columns_1, column;
57
- return __generator(this, function (_g) {
58
- switch (_g.label) {
57
+ var schemas;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
59
60
  case 0:
60
61
  schemas = {};
61
- return [4 /*yield*/, (0, functions_1.readFunctionData)(client, parsedConfig)];
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 = _g.sent();
82
+ functions = _e.sent();
64
83
  _i = 0, functions_2 = functions;
65
- _g.label = 2;
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
- _g.label = 3;
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
- _g.label = 4;
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
- _g.sent();
83
- _g.label = 6;
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
- _g.sent();
90
- _g.label = 9;
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 [4 /*yield*/, (0, tables_1.readTableData)(client, parsedConfig)];
98
- case 12:
99
- tables = _g.sent();
100
- _e = 0, tables_2 = tables;
101
- _g.label = 13;
102
- case 13:
103
- if (!(_e < tables_2.length)) return [3 /*break*/, 19];
104
- t = tables_2[_e];
105
- return [4 /*yield*/, (0, tables_1.readColumnData)(client, t.oid)];
106
- case 14:
107
- columns = _g.sent();
108
- tableDataWithColumns = __assign(__assign({}, t), { columns: columns });
109
- registerDBObject(tableDataWithColumns, schemas);
110
- _f = 0, columns_1 = columns;
111
- _g.label = 15;
112
- case 15:
113
- if (!(_f < columns_1.length)) return [3 /*break*/, 18];
114
- column = columns_1[_f];
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 16:
117
- _g.sent();
118
- _g.label = 17;
119
- case 17:
120
- _f++;
121
- return [3 /*break*/, 15];
122
- case 18:
123
- _e++;
124
- return [3 /*break*/, 13];
125
- case 19: return [2 /*return*/, schemas];
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
- if (isEnumData(dbObject)) {
140
- schemas[dbObject.schema].enums.push(dbObject);
141
- }
142
- else if (isFunctionData(dbObject)) {
143
- schemas[dbObject.schema].functions.push(dbObject);
144
- }
145
- else if (isTableDataWithColumns(dbObject)) {
146
- schemas[dbObject.schema].tables.push(dbObject);
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
- registerDBObject(enumData, schemas);
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 createSortedTableDefinitions;
12
- private static createTableDefinitions;
11
+ private static createSortedRelationDefinitions;
12
+ private static createRelationDefinitions;
13
13
  private static createSortedFunctionDefinitions;
14
14
  private static createFunctionDefinitions;
15
15
  }