Skip to content

Commit

Permalink
Save build
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeik committed Sep 13, 2024
1 parent 2df335e commit 52a2252
Show file tree
Hide file tree
Showing 268 changed files with 11,704 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ node_modules/
versions.json

# Dist
/dist
# /dist
/docs/.vitepress/cache
/docs/.vitepress/dist
/lib
Expand Down
13 changes: 13 additions & 0 deletions dist/db.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ClientBase, ClientConfig, QueryArrayConfig, QueryConfig } from 'pg';
import type { DB, Logger } from './types';
export interface DBConnection extends DB {
createConnection(): Promise<void>;
column(columnName: string, queryConfig: QueryArrayConfig, values?: any[]): Promise<any[]>;

Check failure on line 5 in dist/db.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Unexpected any. Specify a different type

Check failure on line 5 in dist/db.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Unexpected any. Specify a different type
column(columnName: string, queryConfig: QueryConfig): Promise<any[]>;

Check failure on line 6 in dist/db.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Unexpected any. Specify a different type
column(columnName: string, queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[]>;

Check failure on line 7 in dist/db.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Unexpected any. Specify a different type

Check failure on line 7 in dist/db.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Unexpected any. Specify a different type
connected: () => boolean;
addBeforeCloseListener: (listener: any) => number;

Check failure on line 9 in dist/db.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Unexpected any. Specify a different type
close(): Promise<void>;
}
declare function db(connection: ClientBase | string | ClientConfig, logger?: Logger): DBConnection;
export default db;
127 changes: 127 additions & 0 deletions dist/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"use strict";

Check failure on line 1 in dist/db.js

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Strings must use singlequote
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {

Check failure on line 12 in dist/db.js

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Expected blank line before this statement
if (from && typeof from === "object" || typeof from === "function") {

Check failure on line 13 in dist/db.js

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Strings must use singlequote

Check failure on line 13 in dist/db.js

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Strings must use singlequote
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var db_exports = {};
__export(db_exports, {
default: () => db_default
});
module.exports = __toCommonJS(db_exports);
var import_node_util = require("node:util");
var import_pg = __toESM(require("pg"));
var ConnectionStatus = /* @__PURE__ */ ((ConnectionStatus2) => {
ConnectionStatus2["DISCONNECTED"] = "DISCONNECTED";
ConnectionStatus2["CONNECTED"] = "CONNECTED";
ConnectionStatus2["ERROR"] = "ERROR";
ConnectionStatus2["EXTERNAL"] = "EXTERNAL";
return ConnectionStatus2;
})(ConnectionStatus || {});
function db(connection, logger = console) {
const isExternalClient = typeof connection === "object" && "query" in connection && typeof connection.query === "function";
const client = isExternalClient ? connection : new import_pg.default.Client(connection);
let connectionStatus = isExternalClient ? "EXTERNAL" /* EXTERNAL */ : "DISCONNECTED" /* DISCONNECTED */;
const beforeCloseListeners = [];
const connected = () => connectionStatus === "CONNECTED" /* CONNECTED */ || connectionStatus === "EXTERNAL" /* EXTERNAL */;
const createConnection = () => new Promise((resolve, reject) => {
if (connected()) {
resolve();
} else if (connectionStatus === "ERROR" /* ERROR */) {
reject(
new Error("Connection already failed, do not try to connect again")
);
} else {
client.connect((err) => {
if (err) {
connectionStatus = "ERROR" /* ERROR */;
logger.error(`could not connect to postgres: ${(0, import_node_util.inspect)(err)}`);
reject(err);
return;
}
connectionStatus = "CONNECTED" /* CONNECTED */;
resolve();
});
}
});
const query = async (queryTextOrConfig, values) => {
await createConnection();
try {
return await client.query(queryTextOrConfig, values);
} catch (error) {
const { message, position } = error;
const string = typeof queryTextOrConfig === "string" ? queryTextOrConfig : queryTextOrConfig.text;
if (message && position >= 1) {
const endLineWrapIndexOf = string.indexOf("\n", position);
const endLineWrapPos = endLineWrapIndexOf >= 0 ? endLineWrapIndexOf : string.length;
const stringStart = string.slice(0, endLineWrapPos);
const stringEnd = string.slice(endLineWrapPos);
const startLineWrapPos = stringStart.lastIndexOf("\n") + 1;
const padding = " ".repeat(position - startLineWrapPos - 1);
logger.error(`Error executing:
${stringStart}
${padding}^^^^${stringEnd}
${message}
`);
} else {
logger.error(`Error executing:
${string}
${error}
`);
}
throw error;
}
};
const select = async (queryTextOrConfig, values) => {
const { rows } = await query(queryTextOrConfig, values);
return rows;
};
const column = async (columnName, queryTextOrConfig, values) => {
const rows = await select(queryTextOrConfig, values);
return rows.map((r) => r[columnName]);
};
return {
createConnection,
query,
select,
column,
connected,
addBeforeCloseListener: (listener) => beforeCloseListeners.push(listener),
close: async () => {
await beforeCloseListeners.reduce(
(promise, listener) => promise.then(listener).catch((error) => {
logger.error(error.stack || error);
}),
Promise.resolve()
);
if (!isExternalClient) {
connectionStatus = "DISCONNECTED" /* DISCONNECTED */;
client.end();
}
}
};
}
var db_default = db;
Loading

0 comments on commit 52a2252

Please sign in to comment.