introspeql 0.0.3 → 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 +33 -18
- 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 -111
- 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
|
+
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.readEnumData = readEnumData;
|
|
40
|
+
var enum_data_1 = require("./enum-data");
|
|
41
|
+
function readEnumData(client, typeOID) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var query, parameters, results, enumData;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
query = "\nSELECT \n t.oid AS oid,\n n.nspname AS schema,\n t.typname AS name,\n ARRAY(SELECT enumlabel FROM pg_enum WHERE enumtypid = t.oid)::text[] AS values,\n obj_description(t.oid, 'pg_type') AS comment\nFROM pg_catalog.pg_type AS t\nINNER JOIN pg_catalog.pg_namespace AS n ON t.typnamespace = n.oid\nWHERE t.oid = $1;\n";
|
|
48
|
+
parameters = [typeOID];
|
|
49
|
+
return [4 /*yield*/, client.query(query, parameters)];
|
|
50
|
+
case 1:
|
|
51
|
+
results = _a.sent();
|
|
52
|
+
enumData = enum_data_1.enumDataSchema.parse(results.rows[0]);
|
|
53
|
+
return [2 /*return*/, enumData];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const functionDataSchema: z.ZodObject<{
|
|
3
|
+
schema: z.ZodString;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
overloads: z.ZodArray<z.ZodObject<{
|
|
6
|
+
paramTypes: z.ZodArray<z.ZodIntersection<z.ZodObject<{
|
|
7
|
+
oid: z.ZodCoercedNumber<unknown>;
|
|
8
|
+
schema: z.ZodString;
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
isEnum: z.ZodBoolean;
|
|
11
|
+
isArray: z.ZodBoolean;
|
|
12
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
13
|
+
isOptional: z.ZodBoolean;
|
|
14
|
+
isVariadic: z.ZodBoolean;
|
|
15
|
+
}, z.core.$strip>>>;
|
|
16
|
+
returnType: z.ZodObject<{
|
|
17
|
+
oid: z.ZodCoercedNumber<unknown>;
|
|
18
|
+
schema: z.ZodString;
|
|
19
|
+
name: z.ZodString;
|
|
20
|
+
isEnum: z.ZodBoolean;
|
|
21
|
+
isArray: z.ZodBoolean;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
comment: z.ZodNullable<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export type FunctionData = z.infer<typeof functionDataSchema>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionDataSchema = void 0;
|
|
4
|
+
var zod_1 = require("zod");
|
|
5
|
+
var typeSchema = zod_1.z.object({
|
|
6
|
+
oid: zod_1.z.coerce.number(),
|
|
7
|
+
schema: zod_1.z.string(),
|
|
8
|
+
name: zod_1.z.string(),
|
|
9
|
+
isEnum: zod_1.z.boolean(),
|
|
10
|
+
isArray: zod_1.z.boolean(),
|
|
11
|
+
});
|
|
12
|
+
exports.functionDataSchema = zod_1.z.object({
|
|
13
|
+
schema: zod_1.z.string(),
|
|
14
|
+
name: zod_1.z.string(),
|
|
15
|
+
overloads: zod_1.z
|
|
16
|
+
.object({
|
|
17
|
+
paramTypes: typeSchema
|
|
18
|
+
.and(zod_1.z.object({
|
|
19
|
+
isOptional: zod_1.z.boolean(),
|
|
20
|
+
isVariadic: zod_1.z.boolean(),
|
|
21
|
+
}))
|
|
22
|
+
.array(),
|
|
23
|
+
returnType: typeSchema,
|
|
24
|
+
comment: zod_1.z.string().nullable(),
|
|
25
|
+
})
|
|
26
|
+
.array(),
|
|
27
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OverloadTypeDefinition } from './overload-type-definition';
|
|
2
|
+
export declare class FunctionDefinition {
|
|
3
|
+
protected pgFunctionName: string;
|
|
4
|
+
protected overloadTypeDefinitions: OverloadTypeDefinition[];
|
|
5
|
+
constructor(pgFunctionName: string, overloadTypeDefinitions: OverloadTypeDefinition[]);
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionDefinition = void 0;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
var FunctionDefinition = /** @class */ (function () {
|
|
6
|
+
function FunctionDefinition(pgFunctionName, overloadTypeDefinitions) {
|
|
7
|
+
this.pgFunctionName = pgFunctionName;
|
|
8
|
+
this.overloadTypeDefinitions = overloadTypeDefinitions;
|
|
9
|
+
}
|
|
10
|
+
FunctionDefinition.prototype.toString = function () {
|
|
11
|
+
var tsNamespaceName = (0, shared_1.convertPGIdentifierToTSIdentifier)(this.pgFunctionName);
|
|
12
|
+
var overloads = this.overloadTypeDefinitions
|
|
13
|
+
.map(function (overloadTypeDef) {
|
|
14
|
+
return overloadTypeDef.toString();
|
|
15
|
+
})
|
|
16
|
+
.join(',\n');
|
|
17
|
+
return "export namespace ".concat(tsNamespaceName, " {\n export const PGFunctionName = '").concat(this.pgFunctionName, "';\n\n export type Overloads = [\n").concat((0, shared_1.indent)(overloads, 4), "\n ];\n}");
|
|
18
|
+
};
|
|
19
|
+
return FunctionDefinition;
|
|
20
|
+
}());
|
|
21
|
+
exports.FunctionDefinition = FunctionDefinition;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './function-data';
|
|
2
|
+
export * from './function-definition';
|
|
3
|
+
export * from './overload-type-definition';
|
|
4
|
+
export * from './parameter-type-definition-builder';
|
|
5
|
+
export * from './parameter-type-definition';
|
|
6
|
+
export * from './read-function-data';
|
|
7
|
+
export * from './return-type-definition';
|
|
8
|
+
export * from './should-include-function';
|
|
9
|
+
export * from './should-include-overload';
|
|
@@ -0,0 +1,25 @@
|
|
|
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("./function-data"), exports);
|
|
18
|
+
__exportStar(require("./function-definition"), exports);
|
|
19
|
+
__exportStar(require("./overload-type-definition"), exports);
|
|
20
|
+
__exportStar(require("./parameter-type-definition-builder"), exports);
|
|
21
|
+
__exportStar(require("./parameter-type-definition"), exports);
|
|
22
|
+
__exportStar(require("./read-function-data"), exports);
|
|
23
|
+
__exportStar(require("./return-type-definition"), exports);
|
|
24
|
+
__exportStar(require("./should-include-function"), exports);
|
|
25
|
+
__exportStar(require("./should-include-overload"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParameterTypeDefinition } from './parameter-type-definition';
|
|
2
|
+
import { ReturnTypeDefinition } from './return-type-definition';
|
|
3
|
+
export declare class OverloadTypeDefinition {
|
|
4
|
+
protected parameterTypeDefinitions: ParameterTypeDefinition[];
|
|
5
|
+
protected returnTypeTypeDefinition: ReturnTypeDefinition;
|
|
6
|
+
constructor(parameterTypeDefinitions: ParameterTypeDefinition[], returnTypeTypeDefinition: ReturnTypeDefinition);
|
|
7
|
+
toString(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OverloadTypeDefinition = void 0;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
var OverloadTypeDefinition = /** @class */ (function () {
|
|
6
|
+
function OverloadTypeDefinition(parameterTypeDefinitions, returnTypeTypeDefinition) {
|
|
7
|
+
this.parameterTypeDefinitions = parameterTypeDefinitions;
|
|
8
|
+
this.returnTypeTypeDefinition = returnTypeTypeDefinition;
|
|
9
|
+
}
|
|
10
|
+
OverloadTypeDefinition.prototype.toString = function () {
|
|
11
|
+
var parameterTypes = 'ParameterTypes: [\n' +
|
|
12
|
+
this.parameterTypeDefinitions
|
|
13
|
+
.map(function (paramTypeDef) { return ' ' + paramTypeDef.toString(); })
|
|
14
|
+
.join(',\n') +
|
|
15
|
+
'\n]';
|
|
16
|
+
var returnType = 'ReturnType: ' + this.returnTypeTypeDefinition.toString();
|
|
17
|
+
return ('{\n' + (0, shared_1.indent)(parameterTypes, 2) + ',\n' + (0, shared_1.indent)(returnType, 2) + '\n}');
|
|
18
|
+
};
|
|
19
|
+
return OverloadTypeDefinition;
|
|
20
|
+
}());
|
|
21
|
+
exports.OverloadTypeDefinition = OverloadTypeDefinition;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ParameterTypeDefinition } from './parameter-type-definition';
|
|
2
|
+
export declare class ParameterTypeDefinitionBuilder {
|
|
3
|
+
protected tsType: string;
|
|
4
|
+
protected isArray: boolean;
|
|
5
|
+
protected isNullable: boolean;
|
|
6
|
+
protected isVariadic: boolean;
|
|
7
|
+
protected isOptional: boolean;
|
|
8
|
+
static getBuilder(): ParameterTypeDefinitionBuilder;
|
|
9
|
+
withTSType(tsType: string): ParameterTypeDefinitionBuilder;
|
|
10
|
+
withIsArray(isArray: boolean): ParameterTypeDefinitionBuilder;
|
|
11
|
+
withIsNullable(isNullable: boolean): ParameterTypeDefinitionBuilder;
|
|
12
|
+
withIsVariadic(isVariadic: boolean): ParameterTypeDefinitionBuilder;
|
|
13
|
+
withIsOptional(isOptional: boolean): ParameterTypeDefinitionBuilder;
|
|
14
|
+
build(): ParameterTypeDefinition;
|
|
15
|
+
private constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParameterTypeDefinitionBuilder = void 0;
|
|
4
|
+
var parameter_type_definition_1 = require("./parameter-type-definition");
|
|
5
|
+
var ParameterTypeDefinitionBuilder = /** @class */ (function () {
|
|
6
|
+
function ParameterTypeDefinitionBuilder(tsType, isArray, isNullable, isVariadic, isOptional) {
|
|
7
|
+
if (tsType === void 0) { tsType = 'unknown'; }
|
|
8
|
+
if (isArray === void 0) { isArray = false; }
|
|
9
|
+
if (isNullable === void 0) { isNullable = false; }
|
|
10
|
+
if (isVariadic === void 0) { isVariadic = false; }
|
|
11
|
+
if (isOptional === void 0) { isOptional = false; }
|
|
12
|
+
this.tsType = tsType;
|
|
13
|
+
this.isArray = isArray;
|
|
14
|
+
this.isNullable = isNullable;
|
|
15
|
+
this.isVariadic = isVariadic;
|
|
16
|
+
this.isOptional = isOptional;
|
|
17
|
+
}
|
|
18
|
+
ParameterTypeDefinitionBuilder.getBuilder = function () {
|
|
19
|
+
return new ParameterTypeDefinitionBuilder();
|
|
20
|
+
};
|
|
21
|
+
ParameterTypeDefinitionBuilder.prototype.withTSType = function (tsType) {
|
|
22
|
+
return new ParameterTypeDefinitionBuilder(tsType, this.isArray, this.isNullable, this.isVariadic, this.isOptional);
|
|
23
|
+
};
|
|
24
|
+
ParameterTypeDefinitionBuilder.prototype.withIsArray = function (isArray) {
|
|
25
|
+
return new ParameterTypeDefinitionBuilder(this.tsType, isArray, this.isNullable, this.isVariadic, this.isOptional);
|
|
26
|
+
};
|
|
27
|
+
ParameterTypeDefinitionBuilder.prototype.withIsNullable = function (isNullable) {
|
|
28
|
+
return new ParameterTypeDefinitionBuilder(this.tsType, this.isArray, isNullable, this.isVariadic, this.isOptional);
|
|
29
|
+
};
|
|
30
|
+
ParameterTypeDefinitionBuilder.prototype.withIsVariadic = function (isVariadic) {
|
|
31
|
+
return new ParameterTypeDefinitionBuilder(this.tsType, this.isArray, this.isNullable, isVariadic, this.isOptional);
|
|
32
|
+
};
|
|
33
|
+
ParameterTypeDefinitionBuilder.prototype.withIsOptional = function (isOptional) {
|
|
34
|
+
return new ParameterTypeDefinitionBuilder(this.tsType, this.isArray, this.isNullable, this.isVariadic, isOptional);
|
|
35
|
+
};
|
|
36
|
+
ParameterTypeDefinitionBuilder.prototype.build = function () {
|
|
37
|
+
return new parameter_type_definition_1.ParameterTypeDefinition(this.tsType, this.isArray, this.isNullable, this.isVariadic, this.isOptional);
|
|
38
|
+
};
|
|
39
|
+
return ParameterTypeDefinitionBuilder;
|
|
40
|
+
}());
|
|
41
|
+
exports.ParameterTypeDefinitionBuilder = ParameterTypeDefinitionBuilder;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class ParameterTypeDefinition {
|
|
2
|
+
protected tsType: string;
|
|
3
|
+
protected isArray: boolean;
|
|
4
|
+
protected isNullable: boolean;
|
|
5
|
+
protected isVariadic: boolean;
|
|
6
|
+
protected isOptional: boolean;
|
|
7
|
+
constructor(tsType: string, isArray: boolean, isNullable: boolean, isVariadic: boolean, isOptional: boolean);
|
|
8
|
+
toString(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParameterTypeDefinition = void 0;
|
|
4
|
+
var ParameterTypeDefinition = /** @class */ (function () {
|
|
5
|
+
function ParameterTypeDefinition(tsType, isArray, isNullable, isVariadic, isOptional) {
|
|
6
|
+
this.tsType = tsType;
|
|
7
|
+
this.isArray = isArray;
|
|
8
|
+
this.isNullable = isNullable;
|
|
9
|
+
this.isVariadic = isVariadic;
|
|
10
|
+
this.isOptional = isOptional;
|
|
11
|
+
}
|
|
12
|
+
ParameterTypeDefinition.prototype.toString = function () {
|
|
13
|
+
var type = this.tsType;
|
|
14
|
+
if (this.isVariadic) {
|
|
15
|
+
type = "...".concat(type, "[]");
|
|
16
|
+
return type;
|
|
17
|
+
}
|
|
18
|
+
if (this.isArray)
|
|
19
|
+
type = "".concat(type, "[]");
|
|
20
|
+
if (this.isNullable)
|
|
21
|
+
type = "".concat(type, " | null");
|
|
22
|
+
if (this.isOptional)
|
|
23
|
+
type = "".concat(type, " | undefined");
|
|
24
|
+
return type;
|
|
25
|
+
};
|
|
26
|
+
return ParameterTypeDefinition;
|
|
27
|
+
}());
|
|
28
|
+
exports.ParameterTypeDefinition = ParameterTypeDefinition;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.readFunctionData = readFunctionData;
|
|
60
|
+
var function_data_1 = require("./function-data");
|
|
61
|
+
var should_include_overload_1 = require("./should-include-overload");
|
|
62
|
+
var should_include_function_1 = require("./should-include-function");
|
|
63
|
+
function readFunctionData(client, config) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var schemaPlaceholders, query, parameters, result, functionData;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
schemaPlaceholders = config.schemas
|
|
70
|
+
.map(function (_, i) { return "$".concat(i + 1); })
|
|
71
|
+
.join(', ');
|
|
72
|
+
query = "\nSELECT \n p1.proname AS name, \n n1.nspname AS schema,\n ARRAY(\n SELECT jsonb_build_object(\n 'paramTypes',\n\t ARRAY(\n SELECT jsonb_build_object(\n\t 'oid',\n\t t.oid,\n\t 'schema',\n\t n2.nspname,\n\t 'name',\n\t t.typname,\n\t\t 'isEnum',\n\t t.typtype = 'e',\n\t 'isArray',\n\t EXISTS(SELECT 1 FROM pg_catalog.pg_type AS t WHERE t.typarray = args.argType),\n\t\t 'isOptional',\n\t\t CASE \n\t\t WHEN args.argOrd > p2.pronargs - p2.pronargdefaults THEN TRUE\n\t\t\t ELSE FALSE\n\t\t END,\n\t\t 'isVariadic',\n\t\t CASE \n\t\t WHEN p2.provariadic > 0 AND p2.pronargs = args.argOrd THEN TRUE\n\t\t\t ELSE FALSE\n\t END\n\t ) FROM UNNEST(p2.proargtypes) WITH ORDINALITY AS args(argType, argOrd)\n\t INNER JOIN pg_catalog.pg_type as t ON \n\t CASE \n\t WHEN EXISTS(SELECT 1 FROM pg_catalog.pg_type AS t WHERE t.typarray = args.argType) \n\t\t THEN args.argType = t.typarray\n\t\t ELSE args.argType = t.oid\n\t END\n\t INNER JOIN pg_catalog.pg_namespace AS n2 ON t.typnamespace = n2.oid\n ),\n\t 'returnType',\n\t (\n\t SELECT jsonb_build_object(\n\t \t 'oid',\n\t t.oid,\n\t 'schema',\n\t n.nspname,\n\t 'name',\n\t t.typname,\n\t\t 'isEnum',\n\t t.typtype = 'e',\n\t 'isArray',\n\t EXISTS(SELECT 1 FROM pg_catalog.pg_type AS t WHERE t.typarray = p2.prorettype)\n ) FROM pg_catalog.pg_type AS t\n\t INNER JOIN pg_catalog.pg_namespace as n\n\t ON t.typnamespace = n.oid\n\t WHERE CASE \n\t WHEN EXISTS(SELECT 1 FROM pg_catalog.pg_type AS t WHERE t.typarray = p2.prorettype) \n\t\t THEN t.typarray = p2.prorettype\n\t\t ELSE t.oid = p2.prorettype\n\t END\n\t ),\n\t 'comment',\n\t obj_description(p2.oid, 'pg_proc')\n\t) FROM pg_catalog.pg_proc AS p2 WHERE p2.proname = p1.proname ORDER BY p2.oid\n) AS overloads\nFROM pg_catalog.pg_proc AS p1\nINNER JOIN pg_catalog.pg_namespace AS n1 ON p1.pronamespace = n1.oid\nWHERE p1.prokind = 'f' AND n1.nspname IN (".concat(schemaPlaceholders, ")\nGROUP BY (p1.proname, n1.nspname);\n");
|
|
73
|
+
parameters = __spreadArray([], config.schemas, true);
|
|
74
|
+
return [4 /*yield*/, client.query(query, parameters)];
|
|
75
|
+
case 1:
|
|
76
|
+
result = _a.sent();
|
|
77
|
+
functionData = function_data_1.functionDataSchema
|
|
78
|
+
.array()
|
|
79
|
+
.parse(result.rows)
|
|
80
|
+
.map(function (fd) {
|
|
81
|
+
return __assign(__assign({}, fd), { overloads: fd.overloads.filter(function (_a) {
|
|
82
|
+
var comment = _a.comment;
|
|
83
|
+
return (0, should_include_overload_1.shouldIncludeOverload)(fd.schema, fd.name, comment, config);
|
|
84
|
+
}) });
|
|
85
|
+
})
|
|
86
|
+
.filter(function (fd) {
|
|
87
|
+
return (0, should_include_function_1.shouldIncludeFunction)(fd);
|
|
88
|
+
});
|
|
89
|
+
return [2 /*return*/, functionData];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReturnTypeDefinition = void 0;
|
|
4
|
+
var ReturnTypeDefinition = /** @class */ (function () {
|
|
5
|
+
function ReturnTypeDefinition(tsType, isArray, isNullable) {
|
|
6
|
+
this.tsType = tsType;
|
|
7
|
+
this.isArray = isArray;
|
|
8
|
+
this.isNullable = isNullable;
|
|
9
|
+
}
|
|
10
|
+
ReturnTypeDefinition.prototype.toString = function () {
|
|
11
|
+
var type = this.tsType;
|
|
12
|
+
if (this.isArray)
|
|
13
|
+
type = "".concat(type, "[]");
|
|
14
|
+
if (this.isNullable)
|
|
15
|
+
type = "".concat(type, " | null");
|
|
16
|
+
return type;
|
|
17
|
+
};
|
|
18
|
+
return ReturnTypeDefinition;
|
|
19
|
+
}());
|
|
20
|
+
exports.ReturnTypeDefinition = ReturnTypeDefinition;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldIncludeOverload = shouldIncludeOverload;
|
|
4
|
+
var shared_1 = require("../shared");
|
|
5
|
+
function shouldIncludeOverload(schema, name, comment, config) {
|
|
6
|
+
var tokens = (0, shared_1.getTokens)(comment);
|
|
7
|
+
/*
|
|
8
|
+
If mode is inclusive, include the overload only if it AND the function
|
|
9
|
+
itself are not marked for exclusion.
|
|
10
|
+
*/
|
|
11
|
+
if (config.functions.mode === 'inclusive') {
|
|
12
|
+
var shouldExcludeFunction = config.functions.excludeFunctions.some(function (f) { return f.schema === schema && f.name === name; });
|
|
13
|
+
var shouldExcludeOverload = tokens.some(function (t) { return t === shared_1.Directives.Exclude; });
|
|
14
|
+
return !shouldExcludeFunction && !shouldExcludeOverload;
|
|
15
|
+
}
|
|
16
|
+
/*
|
|
17
|
+
If mode is exclusive, include the overload if either it OR the function
|
|
18
|
+
itself are marked for inclusion.
|
|
19
|
+
*/
|
|
20
|
+
var shouldIncludeFunction = config.functions.includeFunctions.some(function (f) { return f.schema === schema && f.name === name; });
|
|
21
|
+
var shouldIncludeOverload = tokens.some(function (t) { return t === shared_1.Directives.Include; });
|
|
22
|
+
return shouldIncludeFunction || shouldIncludeOverload;
|
|
23
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { introspeql } from './introspeql';
|
|
2
|
+
export { Directives } from './shared';
|
|
3
|
+
export type { IntrospeQLConfig } from './config';
|
package/dist/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Directives = exports.introspeql = void 0;
|
|
4
|
+
var introspeql_1 = require("./introspeql");
|
|
5
|
+
Object.defineProperty(exports, "introspeql", { enumerable: true, get: function () { return introspeql_1.introspeql; } });
|
|
6
|
+
var shared_1 = require("./shared");
|
|
7
|
+
Object.defineProperty(exports, "Directives", { enumerable: true, get: function () { return shared_1.Directives; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type IntrospeQLConfig } from './config';
|
|
2
|
+
/**
|
|
3
|
+
* Reads information about schemas, tables, columns, functions, and enums from
|
|
4
|
+
* a PostgreSQL database and generates a TypeScript file containing type
|
|
5
|
+
* definitions for those objects.
|
|
6
|
+
*/
|
|
7
|
+
export declare function introspeql(config: IntrospeQLConfig): Promise<string>;
|