introspeql 0.0.4 → 1.0.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 +286 -85
- 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/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 +71 -0
- package/dist/config/index.js +29 -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 +21 -0
- package/dist/config/table-options.js +48 -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/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +19 -0
- package/dist/schemas/read-schema-data.d.ts +15 -0
- package/dist/schemas/read-schema-data.js +182 -0
- package/dist/schemas/schema-definition-factory.d.ts +15 -0
- package/dist/schemas/schema-definition-factory.js +167 -0
- package/dist/schemas/schema-definition.d.ts +11 -0
- package/dist/schemas/schema-definition.js +38 -0
- package/dist/shared/convert-pg-identifier-to-ts-identifier.d.ts +19 -0
- package/dist/shared/convert-pg-identifier-to-ts-identifier.js +57 -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 +5 -0
- package/dist/shared/index.js +21 -0
- package/dist/shared/parsing-error.d.ts +3 -0
- package/dist/shared/parsing-error.js +26 -0
- package/dist/tables/column-data.d.ts +14 -0
- package/dist/tables/column-data.js +16 -0
- package/dist/tables/column-definition.d.ts +8 -0
- package/dist/tables/column-definition.js +19 -0
- package/dist/tables/column-type-definition.d.ts +7 -0
- package/dist/tables/column-type-definition.js +19 -0
- package/dist/tables/index.d.ts +8 -0
- package/dist/tables/index.js +24 -0
- package/dist/tables/read-column-data.d.ts +3 -0
- package/dist/tables/read-column-data.js +55 -0
- package/dist/tables/read-table-data.d.ts +4 -0
- package/dist/tables/read-table-data.js +84 -0
- package/dist/tables/should-include-table.d.ts +10 -0
- package/dist/tables/should-include-table.js +24 -0
- package/dist/tables/table-data.d.ts +8 -0
- package/dist/tables/table-data.js +10 -0
- package/dist/tables/table-definition.d.ts +10 -0
- package/dist/tables/table-definition.js +43 -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,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertPGIdentifierToTSIdentifier = convertPGIdentifierToTSIdentifier;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a PostgreSQL identifier to a valid TypeScript identifier.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* In PostgreSQL, if an identifier is enclosed in double quotes, it can include
|
|
9
|
+
* a wider selection of characters than are valid in TypeScript.
|
|
10
|
+
* Additionally, while it is idiomatic to use snake_case in PostgreSQL, it is
|
|
11
|
+
* more commonplace to use PascalCase for TypeScript types. Therefore, the
|
|
12
|
+
* following rules are followed when converting identifiers:
|
|
13
|
+
*
|
|
14
|
+
* - If the PostgreSQL identifier begins with underscore(s), these are
|
|
15
|
+
* preserved.
|
|
16
|
+
* - Otherwise, only alphanumeric and $ characters are copied.
|
|
17
|
+
* - All non-letter characters are treated as separators, except for
|
|
18
|
+
* apostrophes, which are simply discarded.
|
|
19
|
+
* - Each word (i.e. the letters between separators) is capitalized.
|
|
20
|
+
* - If the result begins with a number, it is prefaced with an underscore.
|
|
21
|
+
*/
|
|
22
|
+
function convertPGIdentifierToTSIdentifier(identifier) {
|
|
23
|
+
// preserve leading underscores
|
|
24
|
+
var prefix = '';
|
|
25
|
+
while (identifier.startsWith('_')) {
|
|
26
|
+
prefix += '_';
|
|
27
|
+
identifier = identifier.slice(1);
|
|
28
|
+
}
|
|
29
|
+
var words = [];
|
|
30
|
+
var word = '';
|
|
31
|
+
for (var _i = 0, identifier_1 = identifier; _i < identifier_1.length; _i++) {
|
|
32
|
+
var char = identifier_1[_i];
|
|
33
|
+
if (char === "'")
|
|
34
|
+
continue;
|
|
35
|
+
if (/[^A-Za-z]/.test(char)) {
|
|
36
|
+
if (word.length)
|
|
37
|
+
words.push(word);
|
|
38
|
+
if (/[0-9$]/.test(char)) {
|
|
39
|
+
words.push(char);
|
|
40
|
+
}
|
|
41
|
+
word = '';
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
word += char;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (word.length) {
|
|
48
|
+
words.push(word);
|
|
49
|
+
}
|
|
50
|
+
var result = prefix + words.map(function (word) { return capitalize(word); }).join('');
|
|
51
|
+
if (/^\d/.test(result))
|
|
52
|
+
result = '_' + result;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
function capitalize(str) {
|
|
56
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum Directives {
|
|
2
|
+
Include = "@introspeql-include",
|
|
3
|
+
Exclude = "@introspeql-exclude",
|
|
4
|
+
EnableNullableArgs = "@introspeql-enable-nullable-args",
|
|
5
|
+
DisableNullableArgs = "@introspeql-disable-nullable-args",
|
|
6
|
+
EnableNullableReturnTypes = "@introspeql-enable-nullable-return-types",
|
|
7
|
+
DisableNullableReturnTypes = "@introspeql-disable-nullable-return-types",
|
|
8
|
+
EnableTSDocComments = "@introspeql-enable-tsdoc-comments",
|
|
9
|
+
DisableTSDocComments = "@introspeql-disable-tsdoc-comments",
|
|
10
|
+
BeginTSDocComment = "@introspeql-begin-tsdoc-comment",
|
|
11
|
+
EndTSDocComment = "@introspeql-end-tsdoc-comment"
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Directives = void 0;
|
|
4
|
+
var Directives;
|
|
5
|
+
(function (Directives) {
|
|
6
|
+
Directives["Include"] = "@introspeql-include";
|
|
7
|
+
Directives["Exclude"] = "@introspeql-exclude";
|
|
8
|
+
Directives["EnableNullableArgs"] = "@introspeql-enable-nullable-args";
|
|
9
|
+
Directives["DisableNullableArgs"] = "@introspeql-disable-nullable-args";
|
|
10
|
+
Directives["EnableNullableReturnTypes"] = "@introspeql-enable-nullable-return-types";
|
|
11
|
+
Directives["DisableNullableReturnTypes"] = "@introspeql-disable-nullable-return-types";
|
|
12
|
+
Directives["EnableTSDocComments"] = "@introspeql-enable-tsdoc-comments";
|
|
13
|
+
Directives["DisableTSDocComments"] = "@introspeql-disable-tsdoc-comments";
|
|
14
|
+
Directives["BeginTSDocComment"] = "@introspeql-begin-tsdoc-comment";
|
|
15
|
+
Directives["EndTSDocComment"] = "@introspeql-end-tsdoc-comment";
|
|
16
|
+
})(Directives || (exports.Directives = Directives = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTokens(comment: string | null): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function indent(str: string, spaces: number): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./directives"), exports);
|
|
18
|
+
__exportStar(require("./get-tokens"), exports);
|
|
19
|
+
__exportStar(require("./indent"), exports);
|
|
20
|
+
__exportStar(require("./parsing-error"), exports);
|
|
21
|
+
__exportStar(require("./convert-pg-identifier-to-ts-identifier"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
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.ParsingError = void 0;
|
|
19
|
+
var ParsingError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(ParsingError, _super);
|
|
21
|
+
function ParsingError(message) {
|
|
22
|
+
return _super.call(this, message) || this;
|
|
23
|
+
}
|
|
24
|
+
return ParsingError;
|
|
25
|
+
}(Error));
|
|
26
|
+
exports.ParsingError = ParsingError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const columnDataSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
type: z.ZodObject<{
|
|
5
|
+
oid: z.ZodCoercedNumber<unknown>;
|
|
6
|
+
schema: z.ZodString;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
isEnum: z.ZodBoolean;
|
|
9
|
+
numDimensions: z.ZodNumber;
|
|
10
|
+
isNullable: z.ZodBoolean;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
comment: z.ZodNullable<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export type ColumnData = z.infer<typeof columnDataSchema>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.columnDataSchema = void 0;
|
|
4
|
+
var zod_1 = require("zod");
|
|
5
|
+
exports.columnDataSchema = zod_1.z.object({
|
|
6
|
+
name: zod_1.z.string(),
|
|
7
|
+
type: zod_1.z.object({
|
|
8
|
+
oid: zod_1.z.coerce.number(),
|
|
9
|
+
schema: zod_1.z.string(),
|
|
10
|
+
name: zod_1.z.string(),
|
|
11
|
+
isEnum: zod_1.z.boolean(),
|
|
12
|
+
numDimensions: zod_1.z.number(),
|
|
13
|
+
isNullable: zod_1.z.boolean(),
|
|
14
|
+
}),
|
|
15
|
+
comment: zod_1.z.string().nullable(),
|
|
16
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ColumnTypeDefinition } from './column-type-definition';
|
|
2
|
+
export declare class ColumnDefinition {
|
|
3
|
+
readonly pgColumnName: string;
|
|
4
|
+
private typeDefinition;
|
|
5
|
+
private comment?;
|
|
6
|
+
constructor(pgColumnName: string, typeDefinition: ColumnTypeDefinition, comment?: string);
|
|
7
|
+
toString(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColumnDefinition = void 0;
|
|
4
|
+
var ColumnDefinition = /** @class */ (function () {
|
|
5
|
+
function ColumnDefinition(pgColumnName, typeDefinition, comment) {
|
|
6
|
+
this.pgColumnName = pgColumnName;
|
|
7
|
+
this.typeDefinition = typeDefinition;
|
|
8
|
+
this.comment = comment;
|
|
9
|
+
}
|
|
10
|
+
ColumnDefinition.prototype.toString = function () {
|
|
11
|
+
var stringified = "['".concat(this.pgColumnName, "']: ").concat(this.typeDefinition.toString(), ";");
|
|
12
|
+
if (this.comment) {
|
|
13
|
+
stringified = this.comment + '\n' + stringified;
|
|
14
|
+
}
|
|
15
|
+
return stringified;
|
|
16
|
+
};
|
|
17
|
+
return ColumnDefinition;
|
|
18
|
+
}());
|
|
19
|
+
exports.ColumnDefinition = ColumnDefinition;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColumnTypeDefinition = void 0;
|
|
4
|
+
var ColumnTypeDefinition = /** @class */ (function () {
|
|
5
|
+
function ColumnTypeDefinition(tsType, numDimensions, isNullable) {
|
|
6
|
+
this.tsType = tsType;
|
|
7
|
+
this.numDimensions = numDimensions;
|
|
8
|
+
this.isNullable = isNullable;
|
|
9
|
+
}
|
|
10
|
+
ColumnTypeDefinition.prototype.toString = function () {
|
|
11
|
+
var type = this.tsType;
|
|
12
|
+
type += '[]'.repeat(this.numDimensions);
|
|
13
|
+
if (this.isNullable)
|
|
14
|
+
type = "".concat(type, " | null");
|
|
15
|
+
return type;
|
|
16
|
+
};
|
|
17
|
+
return ColumnTypeDefinition;
|
|
18
|
+
}());
|
|
19
|
+
exports.ColumnTypeDefinition = ColumnTypeDefinition;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './column-data';
|
|
2
|
+
export * from './column-definition';
|
|
3
|
+
export * from './column-type-definition';
|
|
4
|
+
export * from './read-column-data';
|
|
5
|
+
export * from './read-table-data';
|
|
6
|
+
export * from './should-include-table';
|
|
7
|
+
export * from './table-data';
|
|
8
|
+
export * from './table-definition';
|
|
@@ -0,0 +1,24 @@
|
|
|
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("./column-data"), exports);
|
|
18
|
+
__exportStar(require("./column-definition"), exports);
|
|
19
|
+
__exportStar(require("./column-type-definition"), exports);
|
|
20
|
+
__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);
|
|
24
|
+
__exportStar(require("./table-definition"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
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);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.readColumnData = readColumnData;
|
|
40
|
+
var column_data_1 = require("./column-data");
|
|
41
|
+
function readColumnData(client, tableOID) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var result, rows, columnData;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0: return [4 /*yield*/, client.query("\nSELECT jsonb_build_object(\n 'name',\n a.attname,\n 'type',\n jsonb_build_object(\n 'oid',\n\t CASE WHEN a.attndims > 0 THEN (\n SELECT base_type.oid\n\t FROM pg_catalog.pg_type AS array_type, pg_catalog.pg_type as base_type\n\t WHERE array_type.oid = a.atttypid AND base_type.typarray = array_type.oid\n ) ELSE a.atttypid END,\n\t 'schema',\n\t (\n\t SELECT nspname \n\t FROM pg_catalog.pg_namespace\n\t WHERE oid = t.typnamespace\n \t),\n\t 'name',\n\t CASE WHEN a.attndims > 0 THEN (\n SELECT base_type.typname\n\t FROM pg_catalog.pg_type AS array_type, pg_catalog.pg_type as base_type\n\t WHERE array_type.oid = a.atttypid AND base_type.typarray = array_type.oid\n ) ELSE t.typname END,\n 'isEnum',\n\t CASE WHEN a.attndims > 0 THEN (\n SELECT t2.typtype = 'e' AS is_enum\n\t FROM pg_catalog.pg_type AS t1, pg_catalog.pg_type as t2\n\t INNER JOIN pg_catalog.pg_namespace AS n ON t2.typnamespace = n.oid\n\t WHERE t1.oid = a.atttypid AND t2.typarray = t1.oid\n ) ELSE t.typtype = 'e' END,\n\t 'numDimensions',\n\t a.attndims,\n\t 'isNullable',\n\t NOT a.attnotnull\n ),\n 'comment',\n col_description(a.attrelid, a.attnum)\n) FROM pg_catalog.pg_class AS c\nINNER JOIN pg_catalog.pg_namespace AS n ON c.relnamespace = n.oid\nINNER JOIN pg_catalog.pg_attribute AS a ON c.oid = a.attrelid\nINNER JOIN pg_catalog.pg_type AS t ON a.atttypid = t.oid\nWHERE c.oid = $1\nAND a.attnum >= 1;", [tableOID])];
|
|
47
|
+
case 1:
|
|
48
|
+
result = _a.sent();
|
|
49
|
+
rows = result.rows.map(function (r) { return r.jsonb_build_object; });
|
|
50
|
+
columnData = column_data_1.columnDataSchema.array().parse(rows);
|
|
51
|
+
return [2 /*return*/, columnData];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
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);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
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) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var schemaPlaceholders, query, parameters, result, tableData;
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
switch (_a.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
schemaPlaceholders = config.schemas
|
|
58
|
+
.map(function (_, i) { return "$".concat(i + 1); })
|
|
59
|
+
.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");
|
|
61
|
+
parameters = __spreadArray([], config.schemas, true);
|
|
62
|
+
return [4 /*yield*/, client.query(query, parameters)];
|
|
63
|
+
case 1:
|
|
64
|
+
result = _a.sent();
|
|
65
|
+
tableData = table_data_1.tableDataSchema
|
|
66
|
+
.array()
|
|
67
|
+
.parse(result.rows)
|
|
68
|
+
.filter(function (_a) {
|
|
69
|
+
var name = _a.name, schema = _a.schema, comment = _a.comment;
|
|
70
|
+
return (0, should_include_table_1.shouldIncludeTable)({
|
|
71
|
+
name: name,
|
|
72
|
+
schema: schema,
|
|
73
|
+
comment: comment,
|
|
74
|
+
mode: config.tables.mode,
|
|
75
|
+
exceptions: config.tables.mode === 'inclusive' ?
|
|
76
|
+
config.tables.excludeTables
|
|
77
|
+
: config.tables.includeTables,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
return [2 /*return*/, tableData];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EntityData } from '../config/entity-data';
|
|
2
|
+
interface ShouldIncludeTableParams {
|
|
3
|
+
name: string;
|
|
4
|
+
schema: string;
|
|
5
|
+
comment: string | null;
|
|
6
|
+
mode: 'inclusive' | 'exclusive';
|
|
7
|
+
exceptions: EntityData[];
|
|
8
|
+
}
|
|
9
|
+
export declare function shouldIncludeTable({ name, schema, comment, mode, exceptions, }: ShouldIncludeTableParams): boolean;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldIncludeTable = shouldIncludeTable;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
function shouldIncludeTable(_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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableDataSchema = void 0;
|
|
4
|
+
var zod_1 = require("zod");
|
|
5
|
+
exports.tableDataSchema = 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 { ColumnDefinition } from './column-definition';
|
|
2
|
+
export declare class TableDefinition {
|
|
3
|
+
protected pgTableName: string;
|
|
4
|
+
protected columns: ColumnDefinition[];
|
|
5
|
+
private comment?;
|
|
6
|
+
constructor(pgTableName: string, columns: ColumnDefinition[], comment?: string);
|
|
7
|
+
toString(): string;
|
|
8
|
+
protected createColumnNamesUnion(): string;
|
|
9
|
+
protected createRowTypeDefinition(): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableDefinition = void 0;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
var TableDefinition = /** @class */ (function () {
|
|
6
|
+
function TableDefinition(pgTableName, columns, comment) {
|
|
7
|
+
this.pgTableName = pgTableName;
|
|
8
|
+
this.columns = columns;
|
|
9
|
+
this.comment = comment;
|
|
10
|
+
}
|
|
11
|
+
TableDefinition.prototype.toString = function () {
|
|
12
|
+
var tsNamespaceName = (0, shared_1.convertPGIdentifierToTSIdentifier)(this.pgTableName);
|
|
13
|
+
var columnNames = this.createColumnNamesUnion();
|
|
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}");
|
|
16
|
+
if (this.comment) {
|
|
17
|
+
stringified = this.comment + '\n' + stringified;
|
|
18
|
+
}
|
|
19
|
+
return stringified;
|
|
20
|
+
};
|
|
21
|
+
TableDefinition.prototype.createColumnNamesUnion = function () {
|
|
22
|
+
if (this.columns.length === 0) {
|
|
23
|
+
return 'export type ColumnNames = never;';
|
|
24
|
+
}
|
|
25
|
+
var columnNames = this.columns
|
|
26
|
+
.map(function (columnDefinition) {
|
|
27
|
+
return "'".concat(columnDefinition.pgColumnName, "'");
|
|
28
|
+
})
|
|
29
|
+
.join(' |\n');
|
|
30
|
+
return "export type ColumnNames = |\n".concat((0, shared_1.indent)(columnNames, 2), ";");
|
|
31
|
+
};
|
|
32
|
+
TableDefinition.prototype.createRowTypeDefinition = function () {
|
|
33
|
+
if (this.columns.length === 0) {
|
|
34
|
+
return 'export interface RowType {}';
|
|
35
|
+
}
|
|
36
|
+
var columnDefinitions = this.columns
|
|
37
|
+
.map(function (columnDefinition) { return columnDefinition.toString(); })
|
|
38
|
+
.join('\n');
|
|
39
|
+
return "export interface RowType {\n".concat((0, shared_1.indent)(columnDefinitions, 2), "\n}");
|
|
40
|
+
};
|
|
41
|
+
return TableDefinition;
|
|
42
|
+
}());
|
|
43
|
+
exports.TableDefinition = TableDefinition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lookup-type';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./lookup-type"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ParsedConfig } from '../config';
|
|
2
|
+
interface TypeInformation {
|
|
3
|
+
schema: string;
|
|
4
|
+
name: string;
|
|
5
|
+
isEnum: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Looks up the correct TypeScript type for a given PostgreSQL type. First
|
|
9
|
+
* checks the config.types object for the type, then checks whether or not the
|
|
10
|
+
* type is an Enum, and if it is, creates a string that will refer to the
|
|
11
|
+
* enum definition generated by IntrospeQL. If the type is not defined in
|
|
12
|
+
* config.types and is not an enum, 'string' is returned.
|
|
13
|
+
*/
|
|
14
|
+
export declare function lookupType({ schema, name, isEnum }: TypeInformation, parentSchema: string, config: ParsedConfig): string;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lookupType = lookupType;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
/**
|
|
6
|
+
* Looks up the correct TypeScript type for a given PostgreSQL type. First
|
|
7
|
+
* checks the config.types object for the type, then checks whether or not the
|
|
8
|
+
* type is an Enum, and if it is, creates a string that will refer to the
|
|
9
|
+
* enum definition generated by IntrospeQL. If the type is not defined in
|
|
10
|
+
* config.types and is not an enum, 'string' is returned.
|
|
11
|
+
*/
|
|
12
|
+
function lookupType(_a, parentSchema, config) {
|
|
13
|
+
var schema = _a.schema, name = _a.name, isEnum = _a.isEnum;
|
|
14
|
+
var key = "".concat(schema, ".").concat(name);
|
|
15
|
+
if (key in config.types) {
|
|
16
|
+
return config.types[key];
|
|
17
|
+
}
|
|
18
|
+
if (isEnum) {
|
|
19
|
+
var type = "Enums.".concat((0, shared_1.convertPGIdentifierToTSIdentifier)(name));
|
|
20
|
+
if (schema !== parentSchema)
|
|
21
|
+
type = "".concat((0, shared_1.convertPGIdentifierToTSIdentifier)(schema), ".").concat(type);
|
|
22
|
+
return type;
|
|
23
|
+
}
|
|
24
|
+
return 'string';
|
|
25
|
+
}
|