introspeql 0.0.4 → 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.
- package/README.md +313 -83
- package/dist/comments/comment-converter.d.ts +54 -0
- package/dist/comments/comment-converter.js +185 -0
- package/dist/comments/index.d.ts +2 -0
- package/dist/comments/index.js +18 -0
- package/dist/comments/prettify-comment.d.ts +1 -0
- package/dist/comments/prettify-comment.js +18 -0
- package/dist/config/connection-options.d.ts +14 -0
- package/dist/config/connection-options.js +42 -0
- package/dist/config/create-relation-options.d.ts +22 -0
- package/dist/config/create-relation-options.js +60 -0
- package/dist/config/default-type-mappings.d.ts +13 -0
- package/dist/config/default-type-mappings.js +16 -0
- package/dist/config/entity-data.d.ts +6 -0
- package/dist/config/entity-data.js +8 -0
- package/dist/config/function-options.d.ts +23 -0
- package/dist/config/function-options.js +74 -0
- package/dist/config/general-options.d.ts +7 -0
- package/dist/config/general-options.js +75 -0
- package/dist/config/index.d.ts +123 -0
- package/dist/config/index.js +43 -0
- package/dist/config/materialized-view-options.d.ts +24 -0
- package/dist/config/materialized-view-options.js +5 -0
- package/dist/config/output-options.d.ts +8 -0
- package/dist/config/output-options.js +40 -0
- package/dist/config/table-options.d.ts +24 -0
- package/dist/config/table-options.js +5 -0
- package/dist/config/view-options.d.ts +24 -0
- package/dist/config/view-options.js +5 -0
- package/dist/enums/enum-data.d.ts +9 -0
- package/dist/enums/enum-data.js +11 -0
- package/dist/enums/enum-definition.d.ts +7 -0
- package/dist/enums/enum-definition.js +24 -0
- package/dist/enums/index.d.ts +4 -0
- package/dist/enums/index.js +20 -0
- package/dist/enums/is-enum-replaced-with-custom-type.d.ts +3 -0
- package/dist/enums/is-enum-replaced-with-custom-type.js +9 -0
- package/dist/enums/read-enum-data.d.ts +3 -0
- package/dist/enums/read-enum-data.js +57 -0
- package/dist/functions/function-data.d.ts +26 -0
- package/dist/functions/function-data.js +27 -0
- package/dist/functions/function-definition.d.ts +7 -0
- package/dist/functions/function-definition.js +21 -0
- package/dist/functions/index.d.ts +9 -0
- package/dist/functions/index.js +25 -0
- package/dist/functions/overload-type-definition.d.ts +8 -0
- package/dist/functions/overload-type-definition.js +21 -0
- package/dist/functions/parameter-type-definition-builder.d.ts +16 -0
- package/dist/functions/parameter-type-definition-builder.js +41 -0
- package/dist/functions/parameter-type-definition.d.ts +9 -0
- package/dist/functions/parameter-type-definition.js +28 -0
- package/dist/functions/read-function-data.d.ts +4 -0
- package/dist/functions/read-function-data.js +93 -0
- package/dist/functions/return-type-definition.d.ts +7 -0
- package/dist/functions/return-type-definition.js +20 -0
- package/dist/functions/should-include-function.d.ts +2 -0
- package/dist/functions/should-include-function.js +6 -0
- package/dist/functions/should-include-overload.d.ts +2 -0
- package/dist/functions/should-include-overload.js +23 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -1
- package/dist/introspeql.d.ts +7 -0
- package/dist/introspeql.js +161 -0
- package/dist/relations/abstract-relation-definition.d.ts +11 -0
- package/dist/relations/abstract-relation-definition.js +43 -0
- package/dist/relations/column-data.d.ts +14 -0
- package/dist/relations/column-data.js +16 -0
- package/dist/relations/column-definition.d.ts +8 -0
- package/dist/relations/column-definition.js +19 -0
- package/dist/relations/column-type-definition.d.ts +7 -0
- package/dist/relations/column-type-definition.js +19 -0
- package/dist/relations/index.d.ts +11 -0
- package/dist/relations/index.js +27 -0
- package/dist/relations/materialized-view-definition.d.ts +4 -0
- package/dist/relations/materialized-view-definition.js +29 -0
- package/dist/relations/read-column-data.d.ts +3 -0
- package/dist/relations/read-column-data.js +55 -0
- package/dist/relations/read-relation-data.d.ts +4 -0
- package/dist/relations/read-relation-data.js +87 -0
- package/dist/relations/relation-data.d.ts +8 -0
- package/dist/relations/relation-data.js +10 -0
- package/dist/relations/should-include-relation.d.ts +10 -0
- package/dist/relations/should-include-relation.js +24 -0
- 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/index.d.ts +3 -0
- package/dist/schemas/index.js +19 -0
- package/dist/schemas/read-schema-data.d.ts +17 -0
- package/dist/schemas/read-schema-data.js +219 -0
- package/dist/schemas/schema-definition-factory.d.ts +15 -0
- package/dist/schemas/schema-definition-factory.js +177 -0
- package/dist/schemas/schema-definition.d.ts +13 -0
- package/dist/schemas/schema-definition.js +52 -0
- package/dist/shared/capitalize.d.ts +1 -0
- package/dist/shared/capitalize.js +6 -0
- package/dist/shared/convert-pg-identifier-to-ts-identifier.d.ts +19 -0
- package/dist/shared/convert-pg-identifier-to-ts-identifier.js +55 -0
- package/dist/shared/directives.d.ts +12 -0
- package/dist/shared/directives.js +16 -0
- package/dist/shared/get-tokens.d.ts +1 -0
- package/dist/shared/get-tokens.js +7 -0
- package/dist/shared/indent.d.ts +1 -0
- package/dist/shared/indent.js +9 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.js +22 -0
- package/dist/shared/parsing-error.d.ts +3 -0
- package/dist/shared/parsing-error.js +26 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +17 -0
- package/dist/types/lookup-type.d.ts +15 -0
- package/dist/types/lookup-type.js +25 -0
- package/package.json +32 -17
- package/dist/append-schema.d.ts +0 -8
- package/dist/append-schema.js +0 -96
- package/dist/generate-types.d.ts +0 -8
- package/dist/generate-types.js +0 -110
- package/dist/introspect-columns.d.ts +0 -21
- package/dist/introspect-columns.js +0 -53
- package/dist/introspect-enum.d.ts +0 -20
- package/dist/introspect-enum.js +0 -24
- package/dist/introspect-procedures.d.ts +0 -53
- package/dist/introspect-procedures.js +0 -129
- package/dist/introspect-tables.d.ts +0 -19
- package/dist/introspect-tables.js +0 -43
- package/dist/introspeql-config.d.ts +0 -40
- package/dist/introspeql-config.js +0 -104
- package/dist/prepare-data-for-writing.d.ts +0 -38
- package/dist/prepare-data-for-writing.js +0 -145
- package/dist/snake-case-to-pascal-case.d.ts +0 -8
- package/dist/snake-case-to-pascal-case.js +0 -17
- package/dist/write-header.d.ts +0 -2
- package/dist/write-header.js +0 -10
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.relationDataSchema = void 0;
|
|
4
|
+
var zod_1 = require("zod");
|
|
5
|
+
exports.relationDataSchema = zod_1.z.object({
|
|
6
|
+
oid: zod_1.z.number(),
|
|
7
|
+
schema: zod_1.z.string(),
|
|
8
|
+
name: zod_1.z.string(),
|
|
9
|
+
comment: zod_1.z.string().nullable(),
|
|
10
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EntityData } from '../config/entity-data';
|
|
2
|
+
interface ShouldIncludeRelationParams {
|
|
3
|
+
name: string;
|
|
4
|
+
schema: string;
|
|
5
|
+
comment: string | null;
|
|
6
|
+
mode: 'inclusive' | 'exclusive';
|
|
7
|
+
exceptions: EntityData[];
|
|
8
|
+
}
|
|
9
|
+
export declare function shouldIncludeRelation({ name, schema, comment, mode, exceptions, }: ShouldIncludeRelationParams): boolean;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldIncludeRelation = shouldIncludeRelation;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
function shouldIncludeRelation(_a) {
|
|
6
|
+
var name = _a.name, schema = _a.schema, comment = _a.comment, mode = _a.mode, exceptions = _a.exceptions;
|
|
7
|
+
var tokens = (0, shared_1.getTokens)(comment);
|
|
8
|
+
if (mode === 'inclusive') {
|
|
9
|
+
if (exceptions.some(function (e) { return e.schema === schema && e.name === name; })) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (tokens.some(function (t) { return t === shared_1.Directives.Exclude; })) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (exceptions.some(function (e) { return e.schema === schema && e.name === name; })) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (tokens.some(function (t) { return t === shared_1.Directives.Include; })) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./read-schema-data"), exports);
|
|
18
|
+
__exportStar(require("./schema-definition"), exports);
|
|
19
|
+
__exportStar(require("./schema-definition-factory"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Client } from 'pg';
|
|
2
|
+
import { type EnumData } from '../enums';
|
|
3
|
+
import { type FunctionData } from '../functions';
|
|
4
|
+
import { type ColumnData, type RelationData } from '../relations';
|
|
5
|
+
import type { ParsedConfig } from '../config';
|
|
6
|
+
export interface RelationDataWithColumns extends RelationData {
|
|
7
|
+
columns: ColumnData[];
|
|
8
|
+
}
|
|
9
|
+
export interface SchemaData {
|
|
10
|
+
name: string;
|
|
11
|
+
enums: EnumData[];
|
|
12
|
+
functions: FunctionData[];
|
|
13
|
+
tables: RelationDataWithColumns[];
|
|
14
|
+
views: RelationDataWithColumns[];
|
|
15
|
+
materializedViews: RelationDataWithColumns[];
|
|
16
|
+
}
|
|
17
|
+
export declare function readSchemaData(client: Client, parsedConfig: ParsedConfig): Promise<Record<string, SchemaData>>;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.readSchemaData = readSchemaData;
|
|
51
|
+
var zod_1 = require("zod");
|
|
52
|
+
var enums_1 = require("../enums");
|
|
53
|
+
var functions_1 = require("../functions");
|
|
54
|
+
var relations_1 = require("../relations");
|
|
55
|
+
function readSchemaData(client, parsedConfig) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var schemas;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
schemas = {};
|
|
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)];
|
|
81
|
+
case 1:
|
|
82
|
+
functions = _e.sent();
|
|
83
|
+
_i = 0, functions_2 = functions;
|
|
84
|
+
_e.label = 2;
|
|
85
|
+
case 2:
|
|
86
|
+
if (!(_i < functions_2.length)) return [3 /*break*/, 11];
|
|
87
|
+
f = functions_2[_i];
|
|
88
|
+
registerDBObject(f, 'function', schemas);
|
|
89
|
+
_a = 0, _b = f.overloads;
|
|
90
|
+
_e.label = 3;
|
|
91
|
+
case 3:
|
|
92
|
+
if (!(_a < _b.length)) return [3 /*break*/, 10];
|
|
93
|
+
overload = _b[_a];
|
|
94
|
+
_c = 0, _d = overload.paramTypes;
|
|
95
|
+
_e.label = 4;
|
|
96
|
+
case 4:
|
|
97
|
+
if (!(_c < _d.length)) return [3 /*break*/, 7];
|
|
98
|
+
paramType = _d[_c];
|
|
99
|
+
return [4 /*yield*/, readAndRegisterTypeIfEnum(paramType, client, parsedConfig, schemas)];
|
|
100
|
+
case 5:
|
|
101
|
+
_e.sent();
|
|
102
|
+
_e.label = 6;
|
|
103
|
+
case 6:
|
|
104
|
+
_c++;
|
|
105
|
+
return [3 /*break*/, 4];
|
|
106
|
+
case 7: return [4 /*yield*/, readAndRegisterTypeIfEnum(overload.returnType, client, parsedConfig, schemas)];
|
|
107
|
+
case 8:
|
|
108
|
+
_e.sent();
|
|
109
|
+
_e.label = 9;
|
|
110
|
+
case 9:
|
|
111
|
+
_a++;
|
|
112
|
+
return [3 /*break*/, 3];
|
|
113
|
+
case 10:
|
|
114
|
+
_i++;
|
|
115
|
+
return [3 /*break*/, 2];
|
|
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];
|
|
144
|
+
return [4 /*yield*/, readAndRegisterTypeIfEnum(column.type, client, parsedConfig, 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*/];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function registerDBObject(dbObject, dbObjectType, schemas) {
|
|
160
|
+
if (!(dbObject.schema in schemas)) {
|
|
161
|
+
schemas[dbObject.schema] = {
|
|
162
|
+
name: dbObject.schema,
|
|
163
|
+
enums: [],
|
|
164
|
+
functions: [],
|
|
165
|
+
tables: [],
|
|
166
|
+
views: [],
|
|
167
|
+
materializedViews: [],
|
|
168
|
+
};
|
|
169
|
+
}
|
|
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;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function readAndRegisterTypeIfEnum(maybeEnum, client, parsedConfig, schemas) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var enumData;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0:
|
|
202
|
+
if (!(maybeEnum.isEnum &&
|
|
203
|
+
!isEnumDefinedInConfig(maybeEnum.schema, maybeEnum.name, parsedConfig))) return [3 /*break*/, 2];
|
|
204
|
+
return [4 /*yield*/, (0, enums_1.readEnumData)(client, maybeEnum.oid)];
|
|
205
|
+
case 1:
|
|
206
|
+
enumData = _a.sent();
|
|
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
|
+
}
|
|
211
|
+
_a.label = 2;
|
|
212
|
+
case 2: return [2 /*return*/];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function isEnumDefinedInConfig(schema, name, parsedConfig) {
|
|
218
|
+
return "".concat(schema, ".").concat(name) in parsedConfig.types;
|
|
219
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SchemaDefinition } from './schema-definition';
|
|
2
|
+
import type { SchemaData } from './read-schema-data';
|
|
3
|
+
import type { ParsedConfig } from '../config';
|
|
4
|
+
export declare class SchemaDefinitionFactory {
|
|
5
|
+
static createSchemaDefinition(data: SchemaData, config: ParsedConfig): SchemaDefinition;
|
|
6
|
+
private static validateDBObjectNames;
|
|
7
|
+
private static createSortedEnumDefinitions;
|
|
8
|
+
private static sortDBObjectData;
|
|
9
|
+
private static createEnumDefinitions;
|
|
10
|
+
private static shouldCopyDBObjectComment;
|
|
11
|
+
private static createSortedRelationDefinitions;
|
|
12
|
+
private static createRelationDefinitions;
|
|
13
|
+
private static createSortedFunctionDefinitions;
|
|
14
|
+
private static createFunctionDefinitions;
|
|
15
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaDefinitionFactory = void 0;
|
|
4
|
+
var schema_definition_1 = require("./schema-definition");
|
|
5
|
+
var enums_1 = require("../enums");
|
|
6
|
+
var relations_1 = require("../relations");
|
|
7
|
+
var functions_1 = require("../functions");
|
|
8
|
+
var types_1 = require("../types");
|
|
9
|
+
var comments_1 = require("../comments");
|
|
10
|
+
var shared_1 = require("../shared");
|
|
11
|
+
var SchemaDefinitionFactory = /** @class */ (function () {
|
|
12
|
+
function SchemaDefinitionFactory() {
|
|
13
|
+
}
|
|
14
|
+
SchemaDefinitionFactory.createSchemaDefinition = function (data, config) {
|
|
15
|
+
this.validateDBObjectNames(data.enums);
|
|
16
|
+
this.validateDBObjectNames(data.tables);
|
|
17
|
+
this.validateDBObjectNames(data.functions);
|
|
18
|
+
this.validateDBObjectNames(data.views);
|
|
19
|
+
this.validateDBObjectNames(data.materializedViews);
|
|
20
|
+
var enumDefinitions = this.createSortedEnumDefinitions(data, config);
|
|
21
|
+
var tableDefinitions = this.createSortedRelationDefinitions('table', data, config);
|
|
22
|
+
var viewDefinitions = this.createSortedRelationDefinitions('view', data, config);
|
|
23
|
+
var materializedViewDefinitions = this.createSortedRelationDefinitions('materializedView', data, config);
|
|
24
|
+
var functionDefinitions = this.createSortedFunctionDefinitions(data, config);
|
|
25
|
+
return new schema_definition_1.SchemaDefinition(data.name, enumDefinitions, tableDefinitions, viewDefinitions, materializedViewDefinitions, functionDefinitions);
|
|
26
|
+
};
|
|
27
|
+
SchemaDefinitionFactory.validateDBObjectNames = function (dbObjects) {
|
|
28
|
+
var seen = new Set();
|
|
29
|
+
for (var _i = 0, dbObjects_1 = dbObjects; _i < dbObjects_1.length; _i++) {
|
|
30
|
+
var dbObject = dbObjects_1[_i];
|
|
31
|
+
var formattedName = (0, shared_1.convertPGIdentifierToTSIdentifier)(dbObject.name);
|
|
32
|
+
if (seen.has(formattedName)) {
|
|
33
|
+
throw new shared_1.ParsingError('Duplicate identifier: ' + formattedName);
|
|
34
|
+
}
|
|
35
|
+
seen.add(formattedName);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
SchemaDefinitionFactory.createSortedEnumDefinitions = function (data, config) {
|
|
39
|
+
var sortedEnums = this.sortDBObjectData(data.enums);
|
|
40
|
+
return this.createEnumDefinitions(sortedEnums, config);
|
|
41
|
+
};
|
|
42
|
+
SchemaDefinitionFactory.sortDBObjectData = function (objectData) {
|
|
43
|
+
return objectData.toSorted(function (a, b) {
|
|
44
|
+
return (0, shared_1.convertPGIdentifierToTSIdentifier)(a.name).localeCompare((0, shared_1.convertPGIdentifierToTSIdentifier)(b.name));
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
SchemaDefinitionFactory.createEnumDefinitions = function (enums, config) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
var enumDefinitions = enums.map(function (enumData) {
|
|
50
|
+
var comment = '';
|
|
51
|
+
if (_this.shouldCopyDBObjectComment(enumData, config)) {
|
|
52
|
+
try {
|
|
53
|
+
comment = comments_1.CommentConverter.convertComment(enumData.comment);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (e instanceof shared_1.ParsingError) {
|
|
57
|
+
console.warn(e.message);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new enums_1.EnumDefinition(enumData.name, enumData.values, comment);
|
|
65
|
+
});
|
|
66
|
+
return enumDefinitions;
|
|
67
|
+
};
|
|
68
|
+
SchemaDefinitionFactory.shouldCopyDBObjectComment = function (objectData, config) {
|
|
69
|
+
if (!objectData.comment)
|
|
70
|
+
return false;
|
|
71
|
+
var commentTokens = (0, shared_1.getTokens)(objectData.comment);
|
|
72
|
+
return ((config.copyComments &&
|
|
73
|
+
!commentTokens.includes(shared_1.Directives.DisableTSDocComments)) ||
|
|
74
|
+
(!config.copyComments &&
|
|
75
|
+
commentTokens.includes(shared_1.Directives.EnableTSDocComments)));
|
|
76
|
+
};
|
|
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);
|
|
82
|
+
};
|
|
83
|
+
SchemaDefinitionFactory.createRelationDefinitions = function (relationType, relations, config) {
|
|
84
|
+
var _this = this;
|
|
85
|
+
var relationDefinitions = relations.map(function (relationData) {
|
|
86
|
+
var shouldCopyRelationComment = _this.shouldCopyDBObjectComment(relationData, config);
|
|
87
|
+
var comment = '';
|
|
88
|
+
if (shouldCopyRelationComment) {
|
|
89
|
+
try {
|
|
90
|
+
comment = comments_1.CommentConverter.convertComment(relationData.comment);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
if (e instanceof shared_1.ParsingError) {
|
|
94
|
+
console.warn(e.message);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/*
|
|
102
|
+
By default, comments on a column are copied if the parent relation's
|
|
103
|
+
comments should be copied. This can be overridden with directives
|
|
104
|
+
applied to the column-level comment directly.
|
|
105
|
+
*/
|
|
106
|
+
var shouldCopyColumnComment = function (comment) {
|
|
107
|
+
if (!comment)
|
|
108
|
+
return false;
|
|
109
|
+
var tokens = (0, shared_1.getTokens)(comment);
|
|
110
|
+
return ((shouldCopyRelationComment &&
|
|
111
|
+
!tokens.includes(shared_1.Directives.DisableTSDocComments)) ||
|
|
112
|
+
(!shouldCopyRelationComment &&
|
|
113
|
+
tokens.includes(shared_1.Directives.EnableTSDocComments)));
|
|
114
|
+
};
|
|
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);
|
|
118
|
+
var comment = '';
|
|
119
|
+
if (shouldCopyColumnComment(columnData.comment)) {
|
|
120
|
+
try {
|
|
121
|
+
comment = comments_1.CommentConverter.convertComment(columnData.comment);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
if (e instanceof shared_1.ParsingError) {
|
|
125
|
+
console.warn(e.message);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw e;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return new relations_1.ColumnDefinition(columnData.name, typeDefinition, comment);
|
|
133
|
+
});
|
|
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));
|
|
139
|
+
});
|
|
140
|
+
return relationDefinitions;
|
|
141
|
+
};
|
|
142
|
+
SchemaDefinitionFactory.createSortedFunctionDefinitions = function (data, config) {
|
|
143
|
+
var sortedFunctionData = this.sortDBObjectData(data.functions);
|
|
144
|
+
return this.createFunctionDefinitions(sortedFunctionData, config);
|
|
145
|
+
};
|
|
146
|
+
SchemaDefinitionFactory.createFunctionDefinitions = function (functions, config) {
|
|
147
|
+
return functions.map(function (functionData) {
|
|
148
|
+
var overloadDefinitions = functionData.overloads.map(function (overloadData) {
|
|
149
|
+
var overloadCommentTokens = (0, shared_1.getTokens)(overloadData.comment);
|
|
150
|
+
var nullableArgs = (config.functions.nullableArgs &&
|
|
151
|
+
!overloadCommentTokens.includes(shared_1.Directives.DisableNullableArgs)) ||
|
|
152
|
+
(!config.functions.nullableArgs &&
|
|
153
|
+
overloadCommentTokens.includes(shared_1.Directives.EnableNullableArgs));
|
|
154
|
+
var parameterTypeDefs = overloadData.paramTypes.map(function (paramType) {
|
|
155
|
+
var tsType = (0, types_1.lookupType)(paramType, functionData.schema, config);
|
|
156
|
+
return functions_1.ParameterTypeDefinitionBuilder.getBuilder()
|
|
157
|
+
.withTSType(tsType)
|
|
158
|
+
.withIsArray(paramType.isArray)
|
|
159
|
+
.withIsNullable(nullableArgs)
|
|
160
|
+
.withIsVariadic(paramType.isVariadic)
|
|
161
|
+
.withIsOptional(paramType.isOptional)
|
|
162
|
+
.build();
|
|
163
|
+
});
|
|
164
|
+
var returnType = (0, types_1.lookupType)(overloadData.returnType, functionData.schema, config);
|
|
165
|
+
var nullableReturnType = (config.functions.nullableReturnTypes &&
|
|
166
|
+
!overloadCommentTokens.includes(shared_1.Directives.DisableNullableReturnTypes)) ||
|
|
167
|
+
(!config.functions.nullableReturnTypes &&
|
|
168
|
+
overloadCommentTokens.includes(shared_1.Directives.EnableNullableReturnTypes));
|
|
169
|
+
var returnTypeDefinition = new functions_1.ReturnTypeDefinition(returnType, overloadData.returnType.isArray, nullableReturnType);
|
|
170
|
+
return new functions_1.OverloadTypeDefinition(parameterTypeDefs, returnTypeDefinition);
|
|
171
|
+
});
|
|
172
|
+
return new functions_1.FunctionDefinition(functionData.name, overloadDefinitions);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
return SchemaDefinitionFactory;
|
|
176
|
+
}());
|
|
177
|
+
exports.SchemaDefinitionFactory = SchemaDefinitionFactory;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EnumDefinition } from '../enums';
|
|
2
|
+
import { FunctionDefinition } from '../functions';
|
|
3
|
+
import { TableDefinition, ViewDefinition, MaterializedViewDefinition } from '../relations';
|
|
4
|
+
export declare class SchemaDefinition {
|
|
5
|
+
protected pgSchemaName: string;
|
|
6
|
+
protected enumDefinitions: EnumDefinition[];
|
|
7
|
+
protected tableDefinitions: TableDefinition[];
|
|
8
|
+
protected viewDefinitions: ViewDefinition[];
|
|
9
|
+
protected materializedViewDefinitions: MaterializedViewDefinition[];
|
|
10
|
+
protected functionDefinitions: FunctionDefinition[];
|
|
11
|
+
constructor(pgSchemaName: string, enumDefinitions: EnumDefinition[], tableDefinitions: TableDefinition[], viewDefinitions: ViewDefinition[], materializedViewDefinitions: MaterializedViewDefinition[], functionDefinitions: FunctionDefinition[]);
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaDefinition = void 0;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
var SchemaDefinition = /** @class */ (function () {
|
|
6
|
+
function SchemaDefinition(pgSchemaName, enumDefinitions, tableDefinitions, viewDefinitions, materializedViewDefinitions, functionDefinitions) {
|
|
7
|
+
this.pgSchemaName = pgSchemaName;
|
|
8
|
+
this.enumDefinitions = enumDefinitions;
|
|
9
|
+
this.tableDefinitions = tableDefinitions;
|
|
10
|
+
this.viewDefinitions = viewDefinitions;
|
|
11
|
+
this.materializedViewDefinitions = materializedViewDefinitions;
|
|
12
|
+
this.functionDefinitions = functionDefinitions;
|
|
13
|
+
}
|
|
14
|
+
SchemaDefinition.prototype.toString = function () {
|
|
15
|
+
var tsSchemaName = (0, shared_1.convertPGIdentifierToTSIdentifier)(this.pgSchemaName);
|
|
16
|
+
var enums = this.enumDefinitions
|
|
17
|
+
.map(function (enumDef) { return enumDef.toString(); })
|
|
18
|
+
.join('\n\n');
|
|
19
|
+
var tables = this.tableDefinitions
|
|
20
|
+
.map(function (tableDef) { return tableDef.toString(); })
|
|
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');
|
|
28
|
+
var functions = this.functionDefinitions
|
|
29
|
+
.map(function (funcDef) { return funcDef.toString(); })
|
|
30
|
+
.join('\n\n');
|
|
31
|
+
var result = "export namespace ".concat(tsSchemaName, " {\n export const PGSchemaName = '").concat(this.pgSchemaName, "';");
|
|
32
|
+
if (enums.length) {
|
|
33
|
+
result += "\n\n export namespace Enums {\n".concat((0, shared_1.indent)(enums, 4), "\n }");
|
|
34
|
+
}
|
|
35
|
+
if (tables.length) {
|
|
36
|
+
result += "\n\n export namespace Tables {\n".concat((0, shared_1.indent)(tables, 4), "\n }");
|
|
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
|
+
}
|
|
44
|
+
if (functions.length) {
|
|
45
|
+
result += "\n\n export namespace Functions {\n".concat((0, shared_1.indent)(functions, 4), "\n }");
|
|
46
|
+
}
|
|
47
|
+
result += '\n}';
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
return SchemaDefinition;
|
|
51
|
+
}());
|
|
52
|
+
exports.SchemaDefinition = SchemaDefinition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function capitalize<T extends string>(str: T): Capitalize<T>;
|