@spytecgps/nova-orm 1.3.11-rc4 → 1.3.12

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/dist/utils.js DELETED
@@ -1,86 +0,0 @@
1
- 'use strict';
2
-
3
- var uuidHelpers = require('./uuidHelpers-DVc4n8Yf.js');
4
- require('dayjs');
5
-
6
- const tryParseFloat = (valueToParse, defaultValue = null) => {
7
- const numberFloat = Number.parseFloat(valueToParse);
8
- return Number.isNaN(numberFloat) ? defaultValue : numberFloat;
9
- };
10
- const tryParseDate = (anyDate, defaultValue = null) => {
11
- try {
12
- return anyDate ? new Date(anyDate.toString()) : defaultValue;
13
- }
14
- catch (_error) {
15
- return defaultValue;
16
- }
17
- };
18
- const tryParseBoolean = (valueToParse, defaultValue = null) => {
19
- if (typeof valueToParse === 'boolean') {
20
- return valueToParse;
21
- }
22
- if (typeof valueToParse === 'string') {
23
- return valueToParse.toLowerCase() === 'true';
24
- }
25
- return defaultValue;
26
- };
27
-
28
- const getRandomBoolean = () => {
29
- return Math.random() < 0.5;
30
- };
31
- const getRandomInteger = (max) => {
32
- return Math.floor(Math.random() * max) + 1;
33
- };
34
- const getRandomString = (length) => {
35
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
36
- let result = '';
37
- const charactersLength = characters.length;
38
- for (let i = 0; i < length; i++) {
39
- const randomIndex = Math.floor(Math.random() * charactersLength);
40
- result += characters.charAt(randomIndex);
41
- }
42
- return result;
43
- };
44
- const getRandomImei = (length = 15) => {
45
- const characters = '0123456789';
46
- let result = '';
47
- const charactersLength = characters.length;
48
- for (let i = 0; i < length; i++) {
49
- const randomIndex = Math.floor(Math.random() * charactersLength);
50
- result += characters.charAt(randomIndex);
51
- }
52
- return result;
53
- };
54
- const getRandomDateInRange = (rangeInDays) => {
55
- // Get the current date
56
- const currentDate = new Date();
57
- // Calculate the minimum and maximum date
58
- const minDate = new Date(currentDate);
59
- minDate.setDate(currentDate.getDate() - rangeInDays);
60
- const maxDate = new Date(currentDate);
61
- maxDate.setDate(currentDate.getDate() + rangeInDays);
62
- // Generate a random date within the specified range
63
- const randomTimestamp = minDate.getTime() + Math.random() * (maxDate.getTime() - minDate.getTime());
64
- const randomDate = new Date(randomTimestamp);
65
- return randomDate;
66
- };
67
-
68
- const Utils = {
69
- uuidStringToBinaryBuffer: uuidHelpers.uuidStringToBinaryBuffer,
70
- binaryBufferToUuidString: uuidHelpers.binaryBufferToUuidString,
71
- getRandomBoolean,
72
- getRandomImei,
73
- getRandomDateInRange,
74
- getRandomInteger,
75
- getRandomString,
76
- tryParseBoolean,
77
- tryParseDate,
78
- tryParseFloat,
79
- allAttributesAreNull: uuidHelpers.allAttributesAreNull,
80
- anyAttributeInArrayIsNull: uuidHelpers.anyAttributeInArrayIsNull,
81
- anyAttributeIsNull: uuidHelpers.anyAttributeIsNull,
82
- now: uuidHelpers.now,
83
- addMonthsToNow: uuidHelpers.addMonthsToNow,
84
- };
85
-
86
- exports.Utils = Utils;
@@ -1,226 +0,0 @@
1
- 'use strict';
2
-
3
- var dayjs = require('dayjs');
4
-
5
- function _interopNamespaceDefault(e) {
6
- var n = Object.create(null);
7
- if (e) {
8
- Object.keys(e).forEach(function (k) {
9
- if (k !== 'default') {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () { return e[k]; }
14
- });
15
- }
16
- });
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
-
22
- var dayjs__namespace = /*#__PURE__*/_interopNamespaceDefault(dayjs);
23
-
24
- const SECONDS_A_MINUTE = 60;
25
- const MILLISECONDS_A_SECOND = 1000;
26
- const MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND;
27
- const MIN = 'minute';
28
- const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g;
29
- const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g;
30
- function offsetFromString(value = '') {
31
- const offset = value.match(REGEX_VALID_OFFSET_FORMAT);
32
- if (!offset) {
33
- return null;
34
- }
35
- const [indicator, hoursOffset, minutesOffset] = `${offset[0]}`.match(REGEX_OFFSET_HOURS_MINUTES_FORMAT) || ['-', 0, 0];
36
- const totalOffsetInMinutes = +hoursOffset * 60 + +minutesOffset;
37
- if (totalOffsetInMinutes === 0) {
38
- return 0;
39
- }
40
- return indicator === '+' ? totalOffsetInMinutes : -totalOffsetInMinutes;
41
- }
42
- const utcPlugin = (_option, Dayjs, dayjs) => {
43
- const proto = Dayjs.prototype;
44
- dayjs.utc = function (date) {
45
- const cfg = { date, utc: true, args: arguments }; // eslint-disable-line prefer-rest-params
46
- return new Dayjs(cfg); // eslint-disable-line no-use-before-define
47
- };
48
- proto.utc = function (keepLocalTime) {
49
- const ins = dayjs(this.toDate(), { locale: this.$L, utc: true });
50
- if (keepLocalTime) {
51
- return ins.add(this.utcOffset(), MIN);
52
- }
53
- return ins;
54
- };
55
- proto.local = function () {
56
- return dayjs(this.toDate(), { locale: this.$L, utc: false });
57
- };
58
- const oldParse = proto.parse;
59
- proto.parse = function (cfg) {
60
- if (cfg.utc) {
61
- this.$u = true;
62
- }
63
- if (!this.$utils().u(cfg.$offset)) {
64
- this.$offset = cfg.$offset;
65
- }
66
- oldParse.call(this, cfg);
67
- };
68
- const oldInit = proto.init;
69
- proto.init = function () {
70
- if (this.$u) {
71
- const { $d } = this;
72
- this.$y = $d.getUTCFullYear();
73
- this.$M = $d.getUTCMonth();
74
- this.$D = $d.getUTCDate();
75
- this.$W = $d.getUTCDay();
76
- this.$H = $d.getUTCHours();
77
- this.$m = $d.getUTCMinutes();
78
- this.$s = $d.getUTCSeconds();
79
- this.$ms = $d.getUTCMilliseconds();
80
- }
81
- else {
82
- oldInit.call(this);
83
- }
84
- };
85
- const oldUtcOffset = proto.utcOffset;
86
- proto.utcOffset = function (input, keepLocalTime) {
87
- const { u } = this.$utils();
88
- if (u(input)) {
89
- if (this.$u) {
90
- return 0;
91
- }
92
- if (!u(this.$offset)) {
93
- return this.$offset;
94
- }
95
- return oldUtcOffset.call(this);
96
- }
97
- if (typeof input === 'string') {
98
- input = offsetFromString(input);
99
- if (input === null) {
100
- return this;
101
- }
102
- }
103
- const offset = Math.abs(input) <= 16 ? input * 60 : input;
104
- // eslint-disable-next-line @typescript-eslint/no-this-alias
105
- let ins = this;
106
- if (keepLocalTime) {
107
- ins.$offset = offset;
108
- ins.$u = input === 0;
109
- return ins;
110
- }
111
- if (input !== 0) {
112
- const localTimezoneOffset = this.$u
113
- ? this.toDate().getTimezoneOffset()
114
- : -1 * this.utcOffset();
115
- ins = this.local().add(offset + localTimezoneOffset, MIN);
116
- ins.$offset = offset;
117
- ins.$x.$localOffset = localTimezoneOffset;
118
- }
119
- else {
120
- ins = this.utc();
121
- }
122
- return ins;
123
- };
124
- const oldFormat = proto.format;
125
- const UTC_FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ss[Z]';
126
- proto.format = function (formatStr) {
127
- const str = formatStr || (this.$u ? UTC_FORMAT_DEFAULT : '');
128
- return oldFormat.call(this, str);
129
- };
130
- proto.valueOf = function () {
131
- const addedOffset = !this.$utils().u(this.$offset)
132
- ? this.$offset + (this.$x.$localOffset || this.$d.getTimezoneOffset())
133
- : 0;
134
- return this.$d.valueOf() - addedOffset * MILLISECONDS_A_MINUTE;
135
- };
136
- proto.isUTC = function () {
137
- return !!this.$u;
138
- };
139
- proto.toISOString = function () {
140
- return this.toDate().toISOString();
141
- };
142
- proto.toString = function () {
143
- return this.toDate().toUTCString();
144
- };
145
- const oldToDate = proto.toDate;
146
- proto.toDate = function (type) {
147
- if (type === 's' && this.$offset) {
148
- return dayjs(this.format('YYYY-MM-DD HH:mm:ss:SSS')).toDate();
149
- }
150
- return oldToDate.call(this);
151
- };
152
- const oldDiff = proto.diff;
153
- proto.diff = function (input, units, float) {
154
- if (input && this.$u === input.$u) {
155
- return oldDiff.call(this, input, units, float);
156
- }
157
- const localThis = this.local();
158
- const localInput = dayjs(input).local();
159
- return oldDiff.call(localThis, localInput, units, float);
160
- };
161
- };
162
-
163
- dayjs__namespace.extend(utcPlugin);
164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
- const extendedDayjs = dayjs__namespace;
166
- const now = () => extendedDayjs.utc().toDate();
167
- const addMonthsToNow = (months) => extendedDayjs
168
- .utc()
169
- .add(months, 'month')
170
- .toDate();
171
-
172
- const findNestedValue = (params, attribute) => {
173
- const keys = attribute.split('.');
174
- let current = params;
175
- for (const key of keys) {
176
- if (current[key] == null) {
177
- return null; // Property not found
178
- }
179
- current = current[key];
180
- }
181
- return current;
182
- };
183
- const anyAttributeIsNull = (params, attributes) => !params || !attributes || attributes.some(attribute => findNestedValue(params, attribute) == null);
184
- const anyAttributeInArrayIsNull = (params, attributes) => !params?.length || !attributes || params.some(param => anyAttributeIsNull(param, attributes));
185
- const allAttributesAreNull = (params, attributes) => !params ||
186
- !attributes ||
187
- attributes.every(attribute => findNestedValue(params, attribute) == null);
188
-
189
- const uuidStringToBinaryBuffer = (uuidString) => {
190
- if (!uuidString) {
191
- return null;
192
- }
193
- const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
194
- const match = guidRegex.test(uuidString);
195
- if (!match) {
196
- return null;
197
- }
198
- try {
199
- return Buffer.from(uuidString.replace(/-/g, ''), 'hex');
200
- }
201
- catch (error) {
202
- return null;
203
- }
204
- };
205
- const binaryBufferToUuidString = (buffer) => {
206
- if (!buffer) {
207
- return null;
208
- }
209
- const guidStringWithoutDashes = buffer.toString('hex');
210
- const guidRegex = /^(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})$/;
211
- const match = guidRegex.exec(guidStringWithoutDashes);
212
- if (match) {
213
- return `${match[1]}-${match[2]}-${match[3]}-${match[4]}-${match[5]}`;
214
- }
215
- else {
216
- return null;
217
- }
218
- };
219
-
220
- exports.addMonthsToNow = addMonthsToNow;
221
- exports.allAttributesAreNull = allAttributesAreNull;
222
- exports.anyAttributeInArrayIsNull = anyAttributeInArrayIsNull;
223
- exports.anyAttributeIsNull = anyAttributeIsNull;
224
- exports.binaryBufferToUuidString = binaryBufferToUuidString;
225
- exports.now = now;
226
- exports.uuidStringToBinaryBuffer = uuidStringToBinaryBuffer;