@8ms/helpers 1.12.0 → 1.13.0
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.
- package/date/format.d.ts +1 -1
- package/date/format.js +5 -5
- package/date/getDate.js +10 -4
- package/package.json +41 -38
- package/prisma/initClient.js +12 -8
package/date/format.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ type Format = GetTimeZoned & GetMidnight & {
|
|
|
9
9
|
* Convert a (number | string | Date) into a "yyyy-MM-dd" string or a specified format.
|
|
10
10
|
* As the user would be providing the input we don't want to change the timezone typically.
|
|
11
11
|
*/
|
|
12
|
-
declare const format: (
|
|
12
|
+
declare const format: (props: Format) => string;
|
|
13
13
|
export default format;
|
package/date/format.js
CHANGED
|
@@ -9,12 +9,12 @@ const getDate_1 = __importDefault(require("./getDate"));
|
|
|
9
9
|
* Convert a (number | string | Date) into a "yyyy-MM-dd" string or a specified format.
|
|
10
10
|
* As the user would be providing the input we don't want to change the timezone typically.
|
|
11
11
|
*/
|
|
12
|
-
const format = (
|
|
12
|
+
const format = (props) => {
|
|
13
13
|
const dateInstance = (0, getDate_1.default)({
|
|
14
|
-
input,
|
|
15
|
-
setMidnight,
|
|
16
|
-
setTimeZone,
|
|
14
|
+
input: props.input,
|
|
15
|
+
setMidnight: props?.setMidnight || true,
|
|
16
|
+
setTimeZone: props?.setTimeZone || false,
|
|
17
17
|
});
|
|
18
|
-
return (0, date_fns_1.format)(dateInstance, dateFormat || 'yyyy-MM-dd');
|
|
18
|
+
return (0, date_fns_1.format)(dateInstance, props?.dateFormat || 'yyyy-MM-dd');
|
|
19
19
|
};
|
|
20
20
|
exports.default = format;
|
package/date/getDate.js
CHANGED
|
@@ -17,7 +17,7 @@ const getDate = (props) => {
|
|
|
17
17
|
date = new Date(props.input.valueOf());
|
|
18
18
|
}
|
|
19
19
|
else if ('string' === typeof props.input || 'number' === typeof props.input) {
|
|
20
|
-
// Convert
|
|
20
|
+
// Convert the input into string
|
|
21
21
|
const dateString = props.input.toString();
|
|
22
22
|
const regexes = {
|
|
23
23
|
ymdDash: new RegExp('^[0-9]{4}-[0-9]{2}-[0-9]{2}$'),
|
|
@@ -48,15 +48,21 @@ const getDate = (props) => {
|
|
|
48
48
|
const month = Number(dateString.substring(5, 7)) - 1;
|
|
49
49
|
const day = Number(dateString.substring(8, 10));
|
|
50
50
|
date = new Date();
|
|
51
|
-
//
|
|
52
|
-
date
|
|
53
|
-
date.setHours(1, 0, 0, 0);
|
|
51
|
+
//console.log('default - date', date);
|
|
52
|
+
// Reset the date
|
|
54
53
|
date.setFullYear(year);
|
|
54
|
+
date.setHours(1, 0, 0, 0);
|
|
55
|
+
date.setMonth(0);
|
|
56
|
+
date.setDate(1);
|
|
57
|
+
//console.log('reset - date', date);
|
|
58
|
+
// Finalise date
|
|
55
59
|
date.setMonth(month);
|
|
56
60
|
date.setDate(day);
|
|
57
61
|
date.setHours(0, 0, 0, 0);
|
|
62
|
+
//console.log('finalise - date', date);
|
|
58
63
|
// Resolve timezone offset
|
|
59
64
|
date = (0, date_fns_1.addMinutes)(date, date.getTimezoneOffset() * -1);
|
|
65
|
+
//console.log('timezone - date', date);
|
|
60
66
|
}
|
|
61
67
|
// 2022-04-12 01:01:01
|
|
62
68
|
else if (regexes.ymdHisDash.test(dateString)) {
|
package/package.json
CHANGED
|
@@ -1,49 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name":
|
|
3
|
-
"license":
|
|
4
|
-
"version":
|
|
5
|
-
"repository":
|
|
2
|
+
"name": "@8ms/helpers",
|
|
3
|
+
"license": "UNLICENSED",
|
|
4
|
+
"version": "1.13.0",
|
|
5
|
+
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url":
|
|
7
|
+
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
8
8
|
},
|
|
9
|
-
"main":
|
|
10
|
-
"types":
|
|
11
|
-
"scripts":
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
13
|
-
"jest":
|
|
13
|
+
"jest": "jest --watch"
|
|
14
14
|
},
|
|
15
|
-
"dependencies":
|
|
16
|
-
"axios":
|
|
17
|
-
"crypto-js":
|
|
18
|
-
"date-fns":
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "1.6.8",
|
|
17
|
+
"crypto-js": "4.2.0",
|
|
18
|
+
"date-fns": "3.6.0",
|
|
19
19
|
"date-fns-tz": "3.1.3",
|
|
20
|
-
"lodash":
|
|
21
|
-
"zod":
|
|
20
|
+
"lodash": "4.17.21",
|
|
21
|
+
"zod": "3.23.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@aws-sdk/client-s3":
|
|
25
|
-
"@aws-sdk/client-ses":
|
|
26
|
-
"@aws-sdk/client-sqs":
|
|
27
|
-
"@aws-sdk/client-ssm":
|
|
28
|
-
"@aws-sdk/lib-storage":
|
|
24
|
+
"@aws-sdk/client-s3": "3.567.0",
|
|
25
|
+
"@aws-sdk/client-ses": "3.567.0",
|
|
26
|
+
"@aws-sdk/client-sqs": "3.567.0",
|
|
27
|
+
"@aws-sdk/client-ssm": "3.567.0",
|
|
28
|
+
"@aws-sdk/lib-storage": "3.567.0",
|
|
29
29
|
"@aws-sdk/s3-request-presigner": "3.567.0",
|
|
30
|
-
"@babel/preset-env":
|
|
31
|
-
"@babel/preset-flow":
|
|
32
|
-
"@babel/preset-typescript":
|
|
33
|
-
"@google-cloud/bigquery":
|
|
34
|
-
"@google-cloud/storage":
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@types/
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
30
|
+
"@babel/preset-env": "7.24.5",
|
|
31
|
+
"@babel/preset-flow": "7.24.1",
|
|
32
|
+
"@babel/preset-typescript": "7.24.1",
|
|
33
|
+
"@google-cloud/bigquery": "7.6.1",
|
|
34
|
+
"@google-cloud/storage": "7.10.2",
|
|
35
|
+
"@planetscale/database": "^1.18.0",
|
|
36
|
+
"@prisma/adapter-planetscale": "^5.14.0",
|
|
37
|
+
"@prisma/client": "5.13.0",
|
|
38
|
+
"@types/jest": "29.5.12",
|
|
39
|
+
"@types/lodash": "4.17.0",
|
|
40
|
+
"@types/node": "20.12.8",
|
|
41
|
+
"babel-jest": "29.7.0",
|
|
42
|
+
"jest": "29.7.0",
|
|
43
|
+
"node-fetch": "3.3.2",
|
|
44
|
+
"stream-chain": "2.2.5",
|
|
45
|
+
"stream-json": "1.8.0",
|
|
46
|
+
"timezone-mock": "1.3.6",
|
|
47
|
+
"ts-node": "10.9.2",
|
|
48
|
+
"tslib": "2.6.2",
|
|
49
|
+
"typescript": "5.4.5",
|
|
50
|
+
"undici": "^6.16.1"
|
|
48
51
|
}
|
|
49
52
|
}
|
package/prisma/initClient.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Prevent too many connections
|
|
5
|
-
* https://github.com/prisma/prisma/issues/1983#issuecomment-620621213
|
|
6
|
-
* https://next-auth.js.org/schemas/adapters
|
|
7
|
-
* Library: @prisma/client, prisma-query-log
|
|
8
|
-
*/
|
|
9
3
|
global.prisma = null;
|
|
10
4
|
const initClient = ({ debug } = { debug: false }) => {
|
|
11
5
|
if (!global.prisma) {
|
|
12
|
-
const {
|
|
6
|
+
const { Client } = require("@planetscale/database");
|
|
7
|
+
const { PrismaClient } = require("@prisma/client");
|
|
8
|
+
const { PrismaPlanetScale } = require("@prisma/adapter-planetscale");
|
|
9
|
+
const { fetch: undiciFetch } = require("undici");
|
|
10
|
+
const client = new Client({
|
|
11
|
+
url: process.env.DATABASE_URL, fetch: undiciFetch
|
|
12
|
+
});
|
|
13
|
+
const adapter = new PrismaPlanetScale(client);
|
|
13
14
|
// Show the full query if debugging
|
|
14
15
|
if (debug) {
|
|
15
16
|
global.prisma = new PrismaClient({
|
|
17
|
+
adapter,
|
|
16
18
|
log: [
|
|
17
19
|
{
|
|
18
20
|
emit: "event",
|
|
@@ -23,7 +25,9 @@ const initClient = ({ debug } = { debug: false }) => {
|
|
|
23
25
|
}
|
|
24
26
|
// Standard prisma
|
|
25
27
|
else {
|
|
26
|
-
global.prisma = new PrismaClient(
|
|
28
|
+
global.prisma = new PrismaClient({
|
|
29
|
+
adapter
|
|
30
|
+
});
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
};
|