@ttoss/lambda-postgres-query 0.2.5 → 0.2.7

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.
@@ -1,7 +1,7 @@
1
1
  import { CloudFormationTemplate } from '@ttoss/cloudformation';
2
2
  export { CloudFormationTemplate } from '@ttoss/cloudformation';
3
3
  import { Handler } from 'aws-lambda';
4
- import { QueryParams } from '../index.cjs';
4
+ import { QueryParams } from '../index.mjs';
5
5
  import 'pg';
6
6
 
7
7
  declare const HANDLER_DEFAULT = "handler.handler";
package/dist/esm/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // src/query.ts
4
4
  import { InvokeCommand, LambdaClient } from "@aws-sdk/client-lambda";
5
+ import camelcaseKeys from "camelcase-keys";
5
6
  var lambdaClient = new LambdaClient();
6
7
  var asciiDecoder = new TextDecoder("ascii");
7
8
  var query = async params => {
@@ -35,7 +36,18 @@ var query = async params => {
35
36
  if ("errorType" in result) {
36
37
  throw result;
37
38
  }
38
- return result;
39
+ return {
40
+ ...result,
41
+ rows: result.rows.map(row => {
42
+ return {
43
+ ...row,
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ ...camelcaseKeys(row, {
46
+ deep: true
47
+ })
48
+ };
49
+ })
50
+ };
39
51
  } catch (error) {
40
52
  console.error("Error invoking Lambda: ", error);
41
53
  throw error;
@@ -1,4 +1,5 @@
1
- import { QueryConfig, QueryResultRow, QueryResult } from 'pg';
1
+ import * as pg from 'pg';
2
+ import { QueryConfig, QueryResultRow } from 'pg';
2
3
 
3
4
  type QueryParams = {
4
5
  readOnly?: boolean;
@@ -9,6 +10,12 @@ type LambdaError = {
9
10
  errorMessage: string;
10
11
  trace: string[];
11
12
  };
12
- declare const query: <Rows extends QueryResultRow = any>(params: QueryParams | string) => Promise<QueryResult<Rows>>;
13
+ declare const query: <Rows extends QueryResultRow = any>(params: QueryParams | string) => Promise<{
14
+ rows: any[];
15
+ command: string;
16
+ rowCount: number | null;
17
+ oid: number;
18
+ fields: pg.FieldDef[];
19
+ }>;
13
20
 
14
21
  export { type LambdaError, type QueryParams, query };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { QueryConfig, QueryResultRow, QueryResult } from 'pg';
1
+ import * as pg from 'pg';
2
+ import { QueryConfig, QueryResultRow } from 'pg';
2
3
 
3
4
  type QueryParams = {
4
5
  readOnly?: boolean;
@@ -9,6 +10,12 @@ type LambdaError = {
9
10
  errorMessage: string;
10
11
  trace: string[];
11
12
  };
12
- declare const query: <Rows extends QueryResultRow = any>(params: QueryParams | string) => Promise<QueryResult<Rows>>;
13
+ declare const query: <Rows extends QueryResultRow = any>(params: QueryParams | string) => Promise<{
14
+ rows: any[];
15
+ command: string;
16
+ rowCount: number | null;
17
+ oid: number;
18
+ fields: pg.FieldDef[];
19
+ }>;
13
20
 
14
21
  export { type LambdaError, type QueryParams, query };
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  "use strict";
3
3
 
4
+ var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
10
  var __export = (target, all) => {
9
11
  for (var name in all) __defProp(target, name, {
@@ -20,6 +22,15 @@ var __copyProps = (to, from, except, desc) => {
20
22
  }
21
23
  return to;
22
24
  };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
31
+ value: mod,
32
+ enumerable: true
33
+ }) : target, mod));
23
34
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
24
35
  value: true
25
36
  }), mod);
@@ -33,6 +44,7 @@ module.exports = __toCommonJS(src_exports);
33
44
 
34
45
  // src/query.ts
35
46
  var import_client_lambda = require("@aws-sdk/client-lambda");
47
+ var import_camelcase_keys = __toESM(require("camelcase-keys"));
36
48
  var lambdaClient = new import_client_lambda.LambdaClient();
37
49
  var asciiDecoder = new TextDecoder("ascii");
38
50
  var query = async params => {
@@ -66,7 +78,18 @@ var query = async params => {
66
78
  if ("errorType" in result) {
67
79
  throw result;
68
80
  }
69
- return result;
81
+ return {
82
+ ...result,
83
+ rows: result.rows.map(row => {
84
+ return {
85
+ ...row,
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ ...(0, import_camelcase_keys.default)(row, {
88
+ deep: true
89
+ })
90
+ };
91
+ })
92
+ };
70
93
  } catch (error) {
71
94
  console.error("Error invoking Lambda: ", error);
72
95
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/lambda-postgres-query",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Create a Lambda function that queries a PostgreSQL database.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -11,7 +11,7 @@
11
11
  "url": "https://github.com/ttoss/ttoss.git",
12
12
  "directory": "packages/lambda-postgres-query"
13
13
  },
14
- "type": "module",
14
+ "type": "commonjs",
15
15
  "exports": {
16
16
  ".": {
17
17
  "import": "./dist/esm/index.js",
@@ -30,12 +30,14 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@aws-sdk/client-lambda": "^3.624.0",
33
+ "camelcase-keys": "^7.0.2",
33
34
  "pg": "^8.12.0",
34
35
  "@ttoss/cloudformation": "^0.10.3"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/jest": "^29.5.12",
38
39
  "@types/pg": "^8.11.6",
40
+ "aws-sdk-client-mock": "^4.0.1",
39
41
  "jest": "^29.7.0",
40
42
  "tsup": "^8.1.0",
41
43
  "@ttoss/config": "^1.32.6",
package/src/query.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  type InvokeCommandInput,
4
4
  LambdaClient,
5
5
  } from '@aws-sdk/client-lambda';
6
+ import camelcaseKeys from 'camelcase-keys';
6
7
  import type { QueryConfig, QueryResult, QueryResultRow } from 'pg';
7
8
 
8
9
  const lambdaClient = new LambdaClient();
@@ -57,7 +58,16 @@ export const query = async <Rows extends QueryResultRow = any>(
57
58
  throw result;
58
59
  }
59
60
 
60
- return result;
61
+ return {
62
+ ...result,
63
+ rows: result.rows.map((row) => {
64
+ return {
65
+ ...row,
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ ...(camelcaseKeys(row, { deep: true }) as any),
68
+ };
69
+ }),
70
+ };
61
71
  } catch (error) {
62
72
  // eslint-disable-next-line no-console
63
73
  console.error('Error invoking Lambda: ', error);