@8ms/helpers 1.3.28 → 1.3.31

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.
@@ -9,7 +9,7 @@ jobs:
9
9
  - uses: actions/checkout@v3
10
10
  - uses: actions/setup-node@v3
11
11
  with:
12
- node-version: 16
12
+ node-version: 18
13
13
  - run: yarn
14
14
  - run: yarn build
15
15
  - uses: JS-DevTools/npm-publish@v1
@@ -0,0 +1,11 @@
1
+ import { ReadFileResponse } from "./readFile";
2
+ type ReadBrotli = {
3
+ bucket: string;
4
+ key: string;
5
+ isJson?: boolean;
6
+ };
7
+ /**
8
+ * Read a file from S3 and return either null, the content or JSON decoded.
9
+ */
10
+ declare const readBrotli: ({ bucket, key, isJson }: ReadBrotli) => Promise<ReadFileResponse>;
11
+ export default readBrotli;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getBrotliDecompressed_1 = __importDefault(require("../../util/getBrotliDecompressed"));
7
+ const readFile_1 = __importDefault(require("./readFile"));
8
+ /**
9
+ * Read a file from S3 and return either null, the content or JSON decoded.
10
+ */
11
+ const readBrotli = async ({ bucket, key, isJson }) => {
12
+ let response = await (0, readFile_1.default)({
13
+ bucket,
14
+ key,
15
+ isJson: false
16
+ });
17
+ // Cache exists and is still within our caching timeframe
18
+ if (undefined !== response.body) {
19
+ response.body = await (0, getBrotliDecompressed_1.default)({
20
+ input: response.body,
21
+ });
22
+ if (false !== isJson) {
23
+ response.body = JSON.parse(response.body);
24
+ }
25
+ }
26
+ return response;
27
+ };
28
+ exports.default = readBrotli;
@@ -0,0 +1,12 @@
1
+ type WriteBrotli = {
2
+ bucket: string;
3
+ data: any;
4
+ key: string;
5
+ isJson?: boolean;
6
+ [options: string]: any;
7
+ };
8
+ /**
9
+ * Write a brotli file to S3.
10
+ */
11
+ declare const writeBrotli: ({ bucket, data, key, isJson, ...options }: WriteBrotli) => Promise<any>;
12
+ export default writeBrotli;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getBrotliCompressed_1 = __importDefault(require("../../util/getBrotliCompressed"));
7
+ const writeFile_1 = __importDefault(require("./writeFile"));
8
+ /**
9
+ * Write a brotli file to S3.
10
+ */
11
+ const writeBrotli = async ({ bucket, data, key, isJson, ...options }) => {
12
+ let finalData = data;
13
+ if (false !== isJson) {
14
+ finalData = JSON.stringify(data);
15
+ }
16
+ // Compress the data
17
+ const brotliData = await (0, getBrotliCompressed_1.default)({
18
+ input: finalData,
19
+ });
20
+ const apiResponse = await (0, writeFile_1.default)({
21
+ bucket,
22
+ data: brotliData,
23
+ key,
24
+ ...options,
25
+ });
26
+ return apiResponse;
27
+ };
28
+ exports.default = writeBrotli;
@@ -3,10 +3,9 @@ import { GetKey } from './getKey';
3
3
  type GetCache = GetKey & {
4
4
  bucket: string;
5
5
  cache: Cache;
6
- isJson?: boolean;
7
6
  };
8
7
  /**
9
8
  * Get the stored cache if it exists.
10
9
  */
11
- declare const getCache: ({ bucket, cache, fileName, folder, isJson }: GetCache) => Promise<any>;
10
+ declare const getCache: ({ bucket, cache, fileName, folder }: GetCache) => Promise<any>;
12
11
  export default getCache;
@@ -4,13 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const durations_1 = __importDefault(require("../../date/durations"));
7
- const readFile_1 = __importDefault(require("../s3/readFile"));
8
7
  const getKey_1 = __importDefault(require("./getKey"));
9
- const getBrotliDecompressed_1 = __importDefault(require("../../util/getBrotliDecompressed"));
8
+ const readBrotli_1 = __importDefault(require("../s3/readBrotli"));
10
9
  /**
11
10
  * Get the stored cache if it exists.
12
11
  */
13
- const getCache = async ({ bucket, cache, fileName, folder, isJson }) => {
12
+ const getCache = async ({ bucket, cache, fileName, folder }) => {
14
13
  let response = undefined;
15
14
  // Store the cache key
16
15
  const s3CacheKey = (0, getKey_1.default)({ fileName, folder });
@@ -18,12 +17,14 @@ const getCache = async ({ bucket, cache, fileName, folder, isJson }) => {
18
17
  if (cache) {
19
18
  // Try to get the cache
20
19
  try {
21
- const cached = await (0, readFile_1.default)({ bucket, key: s3CacheKey, isJson });
20
+ const cached = await (0, readBrotli_1.default)({
21
+ bucket,
22
+ key: s3CacheKey,
23
+ isJson: true,
24
+ });
22
25
  // Cache exists and is still within our caching timeframe
23
26
  if (undefined !== cached.body && (durations_1.default.FOREVER === cache.timeframe || cached.modified[cache.from][cache.timeframe] < cache.duration)) {
24
- response = await (0, getBrotliDecompressed_1.default)({
25
- input: cached.body,
26
- });
27
+ response = cached.body;
27
28
  }
28
29
  }
29
30
  catch (error) {
@@ -6,5 +6,5 @@ type SaveCache = {
6
6
  /**
7
7
  * Save the cache.
8
8
  */
9
- declare const saveCache: ({ bucket, data, key }: SaveCache) => Promise<void>;
9
+ declare const saveCache: ({ bucket, data, key }: SaveCache) => Promise<any>;
10
10
  export default saveCache;
@@ -3,15 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const writeFile_1 = __importDefault(require("../s3/writeFile"));
7
- const getBrotliCompressed_1 = __importDefault(require("../../util/getBrotliCompressed"));
6
+ const writeBrotli_1 = __importDefault(require("../s3/writeBrotli"));
8
7
  /**
9
8
  * Save the cache.
10
9
  */
11
10
  const saveCache = async ({ bucket, data, key }) => {
12
- const brotliData = await (0, getBrotliCompressed_1.default)({
13
- input: data,
11
+ return await (0, writeBrotli_1.default)({
12
+ bucket,
13
+ data,
14
+ key,
14
15
  });
15
- await (0, writeFile_1.default)({ bucket, data: brotliData, key });
16
16
  };
17
17
  exports.default = saveCache;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.3.28",
4
+ "version": "1.3.31",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -13,36 +13,35 @@
13
13
  "jest": "jest --watch"
14
14
  },
15
15
  "dependencies": {
16
- "axios": "1.3.5",
16
+ "axios": "1.4.0",
17
17
  "crypto-js": "4.1.1",
18
- "date-fns": "2.29.3",
18
+ "date-fns": "2.30.0",
19
19
  "date-fns-tz": "1.3.7",
20
20
  "lodash": "4.17.21",
21
21
  "zod": "3.21.4"
22
22
  },
23
23
  "devDependencies": {
24
- "@aws-sdk/client-s3": "3.306.0",
25
- "@aws-sdk/client-ses": "3.306.0",
26
- "@aws-sdk/client-sqs": "3.306.0",
27
- "@aws-sdk/client-ssm": "3.306.0",
28
- "@aws-sdk/s3-request-presigner": "3.306.0",
29
- "@babel/preset-env": "7.21.4",
24
+ "@aws-sdk/client-s3": "3.345.0",
25
+ "@aws-sdk/client-ses": "3.345.0",
26
+ "@aws-sdk/client-sqs": "3.345.0",
27
+ "@aws-sdk/client-ssm": "3.345.0",
28
+ "@aws-sdk/s3-request-presigner": "3.345.0",
29
+ "@babel/preset-env": "7.22.4",
30
30
  "@babel/preset-flow": "7.21.4",
31
- "@babel/preset-typescript": "7.21.4",
31
+ "@babel/preset-typescript": "7.21.5",
32
32
  "@google-cloud/bigquery": "6.2.0",
33
- "@google-cloud/storage": "6.9.5",
34
- "@prisma/client": "4.12.0",
35
- "@types/jest": "29.5.0",
36
- "@types/lodash": "4.14.192",
37
- "@types/node": "18.15.11",
33
+ "@google-cloud/storage": "6.10.1",
34
+ "@prisma/client": "4.15.0",
35
+ "@types/jest": "29.5.2",
36
+ "@types/lodash": "4.14.195",
37
+ "@types/node": "20.2.5",
38
38
  "babel-jest": "29.5.0",
39
39
  "jest": "29.5.0",
40
40
  "node-fetch": "3.3.1",
41
41
  "numbro": "2.3.6",
42
- "prisma-query-log": "3.2.0",
43
42
  "timezone-mock": "1.3.6",
44
43
  "ts-node": "10.9.1",
45
- "tslib": "2.5.0",
44
+ "tslib": "2.5.3",
46
45
  "typescript": "5.0.3"
47
46
  }
48
47
  }
@@ -20,9 +20,6 @@ const initClient = ({ debug } = { debug: false }) => {
20
20
  },
21
21
  ],
22
22
  });
23
- const { createPrismaQueryEventHandler } = require('prisma-query-log');
24
- const log = createPrismaQueryEventHandler();
25
- global.prisma.$on('query', log);
26
23
  }
27
24
  // Standard prisma
28
25
  else {