@ts-safeql/generate
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -8,3 +8,2 @@ "use strict"; | ||
require("source-map-support/register"); | ||
const colTypes_1 = require("./utils/colTypes"); | ||
const getLeftJoinTables_1 = require("./utils/getLeftJoinTables"); | ||
@@ -29,2 +28,3 @@ const $cacheMap = new Map(); | ||
async function generate(params) { | ||
var _a; | ||
const { sql, query, cacheMetadata = true } = params; | ||
@@ -57,4 +57,5 @@ const { pgCols, pgColsByTableOidCache, pgTypes } = cacheMetadata | ||
}); | ||
const typesMap = Object.assign(Object.assign({}, shared_1.defaultTypeMapping), (_a = params.overrides) === null || _a === void 0 ? void 0 : _a.types); | ||
return fp_ts_1.either.right({ | ||
result: mapColumnAnalysisResultsToTypeLiteral({ columns, pgTypes, leftTables }), | ||
result: mapColumnAnalysisResultsToTypeLiteral({ columns, pgTypes, leftTables, typesMap }), | ||
stmt: result, | ||
@@ -83,2 +84,3 @@ query: query, | ||
leftTables: params.leftTables, | ||
typesMap: params.typesMap, | ||
}); | ||
@@ -95,3 +97,3 @@ return `${propertySignature};`; | ||
if ("introspected" in params.col) { | ||
const tsType = colTypes_1.defaultTypeMapping[params.col.introspected.colType]; | ||
const tsType = params.typesMap[params.col.introspected.colType]; | ||
const value = params.col.introspected.colNotNull ? tsType : `Nullable<${tsType}>`; | ||
@@ -108,2 +110,3 @@ const isFromLeftJoin = params.leftTables.includes(params.col.introspected.tableOid); | ||
pgTypes: params.pgTypes, | ||
typesMap: params.typesMap, | ||
}); | ||
@@ -121,3 +124,3 @@ return buildInterfacePropertyValue({ | ||
} | ||
return getTsTypeFromPgType({ pgTypeName: pgType.name }); | ||
return getTsTypeFromPgType({ pgTypeName: pgType.name, typesMap: params.typesMap }); | ||
} | ||
@@ -127,3 +130,3 @@ function getTsTypeFromPgType(params) { | ||
const { isArray, pgType } = parsePgType(params.pgTypeName); | ||
const tsType = (_a = colTypes_1.defaultTypeMapping[pgType]) !== null && _a !== void 0 ? _a : "any"; | ||
const tsType = (_a = params.typesMap[pgType]) !== null && _a !== void 0 ? _a : "any"; | ||
return isArray ? `Array<${tsType}>` : tsType; | ||
@@ -130,0 +133,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultTypeMapping = exports.colTypes = void 0; | ||
exports.colTypes = void 0; | ||
exports.colTypes = [ | ||
@@ -45,53 +45,2 @@ "int2", | ||
]; | ||
exports.defaultTypeMapping = { | ||
// Integer types | ||
int2: "number", | ||
int4: "number", | ||
int8: "string", | ||
smallint: "number", | ||
int: "number", | ||
bigint: "string", | ||
// Precision types | ||
real: "number", | ||
float4: "number", | ||
float: "number", | ||
float8: "number", | ||
numeric: "number", | ||
decimal: "number", | ||
// Serial types | ||
smallserial: "number", | ||
serial: "number", | ||
bigserial: "string", | ||
// Common string types | ||
uuid: "string", | ||
text: "string", | ||
varchar: "string", | ||
char: "string", | ||
bpchar: "string", | ||
citext: "string", | ||
// Bool types | ||
bit: "boolean", | ||
bool: "boolean", | ||
boolean: "boolean", | ||
// Dates and times | ||
date: "Date", | ||
timestamp: "Date", | ||
timestamptz: "Date", | ||
time: "Date", | ||
timetz: "Date", | ||
interval: "string", | ||
// Network address types | ||
inet: "string", | ||
cidr: "string", | ||
macaddr: "string", | ||
macaddr8: "string", | ||
// Extra types | ||
money: "number", | ||
void: "void", | ||
// JSON types | ||
json: "any", | ||
jsonb: "any", | ||
// Bytes | ||
bytea: "any", | ||
}; | ||
//# sourceMappingURL=colTypes.js.map |
{ | ||
"name": "@ts-safeql/generate", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -25,4 +25,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@ts-safeql/shared": "0.0.2", | ||
"@ts-safeql/test-utils": "0.0.2", | ||
"@ts-safeql/shared": "0.0.3", | ||
"@ts-safeql/test-utils": "0.0.3", | ||
"fp-ts": "^2.12.3", | ||
@@ -29,0 +29,0 @@ "pg-connection-string": "^2.5.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39315
23
574
+ Added@ts-safeql/shared@0.0.3(transitive)
+ Added@ts-safeql/test-utils@0.0.3(transitive)
- Removed@ts-safeql/shared@0.0.2(transitive)
- Removed@ts-safeql/test-utils@0.0.2(transitive)
Updated@ts-safeql/shared@0.0.3
Updated@ts-safeql/test-utils@0.0.3