Socket
Socket
Sign inDemoInstall

@ts-safeql/generate

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-safeql/generate - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

lib/src/utils/get-nonnullable-columns.d.ts

4

lib/src/generate.d.ts

@@ -1,2 +0,2 @@

import { DuplicateColumnsError, IdentiferCase, ParsedQuery, PostgresError } from "@ts-safeql/shared";
import { DuplicateColumnsError, IdentiferCase, LibPgQueryAST, PostgresError } from "@ts-safeql/shared";
import { either } from "fp-ts";

@@ -22,3 +22,3 @@ import postgres from "postgres";

query: string;
pgParsed: ParsedQuery.Root;
pgParsed: LibPgQueryAST.ParseResult;
cacheMetadata?: boolean;

@@ -25,0 +25,0 @@ cacheKey: CacheKey;

@@ -8,2 +8,3 @@ "use strict";

const get_relations_with_joins_1 = require("./utils/get-relations-with-joins");
const get_nonnullable_columns_1 = require("./utils/get-nonnullable-columns");
function createGenerator() {

@@ -50,2 +51,3 @@ const cacheMap = new Map();

const relationsWithJoins = (0, get_relations_with_joins_1.flattenRelationsWithJoinsMap)((0, get_relations_with_joins_1.getRelationsWithJoins)(params.pgParsed));
const nonNullableColumnsBasedOnAST = (0, get_nonnullable_columns_1.getNonNullableColumns)(params.pgParsed);
const columns = result.columns.map((col) => {

@@ -55,3 +57,7 @@ var _a;

.get(col.table)) === null || _a === void 0 ? void 0 : _a.find((x) => x.colNum === col.number);
return introspected === undefined ? { described: col } : { described: col, introspected };
return {
described: col,
introspected: introspected,
isNonNullableBasedOnAST: nonNullableColumnsBasedOnAST.has(col.name),
};
});

@@ -113,9 +119,13 @@ return fp_ts_1.either.right({

switch (findByJoin.joinType) {
case "JOIN_FULL":
case "JOIN_LEFT":
case shared_1.LibPgQueryAST.JoinType.JOIN_LEFT:
case shared_1.LibPgQueryAST.JoinType.JOIN_FULL:
return true;
case "JOIN_ANTI":
case "JOIN_INNER":
case "JOIN_RIGHT":
case "JOIN_SEMI":
case shared_1.LibPgQueryAST.JoinType.JOIN_TYPE_UNDEFINED:
case shared_1.LibPgQueryAST.JoinType.JOIN_INNER:
case shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT:
case shared_1.LibPgQueryAST.JoinType.JOIN_SEMI:
case shared_1.LibPgQueryAST.JoinType.JOIN_ANTI:
case shared_1.LibPgQueryAST.JoinType.JOIN_UNIQUE_OUTER:
case shared_1.LibPgQueryAST.JoinType.JOIN_UNIQUE_INNER:
case shared_1.LibPgQueryAST.JoinType.UNRECOGNIZED:
return false;

@@ -129,10 +139,14 @@ default:

switch (rel.joinType) {
case "JOIN_RIGHT":
case "JOIN_FULL":
case shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT:
case shared_1.LibPgQueryAST.JoinType.JOIN_FULL:
return true;
case "JOIN_LEFT":
case "JOIN_ANTI":
case "JOIN_INNER":
case "JOIN_SEMI":
continue;
case shared_1.LibPgQueryAST.JoinType.JOIN_TYPE_UNDEFINED:
case shared_1.LibPgQueryAST.JoinType.JOIN_INNER:
case shared_1.LibPgQueryAST.JoinType.JOIN_LEFT:
case shared_1.LibPgQueryAST.JoinType.JOIN_SEMI:
case shared_1.LibPgQueryAST.JoinType.JOIN_ANTI:
case shared_1.LibPgQueryAST.JoinType.JOIN_UNIQUE_OUTER:
case shared_1.LibPgQueryAST.JoinType.JOIN_UNIQUE_INNER:
case shared_1.LibPgQueryAST.JoinType.UNRECOGNIZED:
return false;
default:

@@ -164,10 +178,11 @@ (0, shared_1.assertNever)(rel.joinType);

const key = (_e = params.col.described.name) !== null && _e !== void 0 ? _e : (_f = params.col.introspected) === null || _f === void 0 ? void 0 : _f.colName;
let isNullable = false;
if (params.col.introspected !== undefined) {
isNullable =
!params.col.introspected.colNotNull ||
checkIsNullableDueToRelation({
col: params.col.introspected,
relationsWithJoins: params.relationsWithJoins,
});
let isNonNullable = params.col.isNonNullableBasedOnAST;
if (!isNonNullable && params.col.introspected !== undefined) {
isNonNullable = params.col.introspected.colNotNull;
if (checkIsNullableDueToRelation({
col: params.col.introspected,
relationsWithJoins: params.relationsWithJoins,
})) {
isNonNullable = false;
}
}

@@ -177,3 +192,3 @@ return buildInterfacePropertyValue({

value: value,
isNullable: isNullable,
isNullable: !isNonNullable,
});

@@ -180,0 +195,0 @@ }

@@ -1,11 +0,11 @@

import { ParsedQuery } from "@ts-safeql/shared";
import { LibPgQueryAST } from "@ts-safeql/shared";
interface Join {
type: ParsedQuery.JoinExpr["jointype"];
type: LibPgQueryAST.JoinType;
name: string;
}
export type RelationsWithJoinsMap = Map<string, Join[]>;
export declare function getRelationsWithJoins(parsed: ParsedQuery.Root): RelationsWithJoinsMap;
export declare function getRelationsWithJoins(parsed: LibPgQueryAST.ParseResult): RelationsWithJoinsMap;
export interface FlattenedRelationWithJoins {
relName: string;
joinType: ParsedQuery.JoinExpr["jointype"];
joinType: LibPgQueryAST.JoinType;
joinRelName: string;

@@ -12,0 +12,0 @@ }

@@ -5,6 +5,6 @@ "use strict";

function getRelationsWithJoins(parsed) {
var _a;
var _a, _b;
const results = new Map();
const stmt = parsed.stmts[0];
if (stmt === undefined || ((_a = stmt.stmt.SelectStmt) === null || _a === void 0 ? void 0 : _a.fromClause) === undefined) {
if (stmt === undefined || ((_b = (_a = stmt === null || stmt === void 0 ? void 0 : stmt.stmt) === null || _a === void 0 ? void 0 : _a.SelectStmt) === null || _b === void 0 ? void 0 : _b.fromClause) === undefined) {
return results;

@@ -11,0 +11,0 @@ }

@@ -29,3 +29,3 @@ "use strict";

`,
expected: [["caregiver", [{ name: "agency", type: "JOIN_LEFT" }]]],
expected: [["caregiver", [{ name: "agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT }]]],
},

@@ -45,4 +45,4 @@ {

[
{ name: "caregiver_agency", type: "JOIN_LEFT" },
{ name: "agency", type: "JOIN_LEFT" },
{ name: "caregiver_agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT },
{ name: "agency", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT },
],

@@ -73,6 +73,6 @@ ],

[
{ name: "w", type: "JOIN_FULL" },
{ name: "x", type: "JOIN_INNER" },
{ name: "y", type: "JOIN_LEFT" },
{ name: "z", type: "JOIN_RIGHT" },
{ name: "w", type: shared_1.LibPgQueryAST.JoinType.JOIN_FULL },
{ name: "x", type: shared_1.LibPgQueryAST.JoinType.JOIN_INNER },
{ name: "y", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT },
{ name: "z", type: shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT },
],

@@ -83,6 +83,6 @@ ],

[
{ name: "w", type: "JOIN_FULL" },
{ name: "x", type: "JOIN_INNER" },
{ name: "y", type: "JOIN_LEFT" },
{ name: "z", type: "JOIN_RIGHT" },
{ name: "w", type: shared_1.LibPgQueryAST.JoinType.JOIN_FULL },
{ name: "x", type: shared_1.LibPgQueryAST.JoinType.JOIN_INNER },
{ name: "y", type: shared_1.LibPgQueryAST.JoinType.JOIN_LEFT },
{ name: "z", type: shared_1.LibPgQueryAST.JoinType.JOIN_RIGHT },
],

@@ -89,0 +89,0 @@ ],

{
"name": "@ts-safeql/generate",
"version": "0.1.1",
"version": "1.0.0",
"description": "",

@@ -25,4 +25,4 @@ "main": "lib/index.js",

"dependencies": {
"@ts-safeql/shared": "0.1.1",
"@ts-safeql/test-utils": "0.0.11",
"@ts-safeql/shared": "0.2.0",
"@ts-safeql/test-utils": "0.0.12",
"fp-ts": "^2.13.1",

@@ -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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc