@aeriajs/common 0.0.98 → 0.0.100
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/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/index.mjs +0 -3
- package/dist/isObjectId.d.ts +1 -1
- package/dist/isObjectId.js +4 -1
- package/dist/isObjectId.mjs +1 -1
- package/package.json +2 -2
- package/dist/convertConditionToQuery.d.ts +0 -2
- package/dist/convertConditionToQuery.js +0 -64
- package/dist/convertConditionToQuery.mjs +0 -62
- package/dist/date.d.ts +0 -7
- package/dist/date.js +0 -42
- package/dist/date.mjs +0 -36
- package/dist/formatValue.d.ts +0 -2
- package/dist/formatValue.js +0 -55
- package/dist/formatValue.mjs +0 -50
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
export * from './arraysIntersect.js';
|
|
2
2
|
export * from './checkForUndefined.js';
|
|
3
|
-
export * from './convertConditionToQuery.js';
|
|
4
|
-
export * from './date.js';
|
|
5
3
|
export * from './deepClone.js';
|
|
6
4
|
export * from './deepMerge.js';
|
|
7
5
|
export * from './dynamicImport.js';
|
|
8
6
|
export * from './result.js';
|
|
9
7
|
export * from './endpointError.js';
|
|
10
8
|
export * from './evaluateCondition.js';
|
|
11
|
-
export * from './formatValue.js';
|
|
12
9
|
export * from './freshItem.js';
|
|
13
10
|
export * from './getMissingProperties.js';
|
|
14
11
|
export * from './getReferenceProperty.js';
|
package/dist/index.js
CHANGED
|
@@ -16,15 +16,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./arraysIntersect.js"), exports);
|
|
18
18
|
__exportStar(require("./checkForUndefined.js"), exports);
|
|
19
|
-
__exportStar(require("./convertConditionToQuery.js"), exports);
|
|
20
|
-
__exportStar(require("./date.js"), exports);
|
|
21
19
|
__exportStar(require("./deepClone.js"), exports);
|
|
22
20
|
__exportStar(require("./deepMerge.js"), exports);
|
|
23
21
|
__exportStar(require("./dynamicImport.js"), exports);
|
|
24
22
|
__exportStar(require("./result.js"), exports);
|
|
25
23
|
__exportStar(require("./endpointError.js"), exports);
|
|
26
24
|
__exportStar(require("./evaluateCondition.js"), exports);
|
|
27
|
-
__exportStar(require("./formatValue.js"), exports);
|
|
28
25
|
__exportStar(require("./freshItem.js"), exports);
|
|
29
26
|
__exportStar(require("./getMissingProperties.js"), exports);
|
|
30
27
|
__exportStar(require("./getReferenceProperty.js"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export * from "./arraysIntersect.mjs";
|
|
3
3
|
export * from "./checkForUndefined.mjs";
|
|
4
|
-
export * from "./convertConditionToQuery.mjs";
|
|
5
|
-
export * from "./date.mjs";
|
|
6
4
|
export * from "./deepClone.mjs";
|
|
7
5
|
export * from "./deepMerge.mjs";
|
|
8
6
|
export * from "./dynamicImport.mjs";
|
|
9
7
|
export * from "./result.mjs";
|
|
10
8
|
export * from "./endpointError.mjs";
|
|
11
9
|
export * from "./evaluateCondition.mjs";
|
|
12
|
-
export * from "./formatValue.mjs";
|
|
13
10
|
export * from "./freshItem.mjs";
|
|
14
11
|
export * from "./getMissingProperties.mjs";
|
|
15
12
|
export * from "./getReferenceProperty.mjs";
|
package/dist/isObjectId.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ObjectId } from 'mongodb';
|
|
2
|
-
export declare const isObjectId: (value:
|
|
2
|
+
export declare const isObjectId: (value: unknown) => value is ObjectId;
|
package/dist/isObjectId.js
CHANGED
|
@@ -6,6 +6,9 @@ const isObjectId = (value) => {
|
|
|
6
6
|
// the latter is prone to errors when `mongodb` dependency is duplicated
|
|
7
7
|
// -- when ./node_modules/mongodb and ../node_modules/mongodb are both
|
|
8
8
|
// present and the bundler doesn't handle this correctly
|
|
9
|
-
return value
|
|
9
|
+
return !!(value
|
|
10
|
+
&& typeof value === 'object'
|
|
11
|
+
&& '_bsontype' in value
|
|
12
|
+
&& value._bsontype === 'ObjectId');
|
|
10
13
|
};
|
|
11
14
|
exports.isObjectId = isObjectId;
|
package/dist/isObjectId.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.100",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"bson": "^6.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
+
"@aeriajs/types": "^0.0.86",
|
|
35
35
|
"bson": "^6.5.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertConditionToQuery = void 0;
|
|
4
|
-
const getValueFromPath_js_1 = require("./getValueFromPath.js");
|
|
5
|
-
const convertExpression = (condition, subject) => {
|
|
6
|
-
const term2 = 'term2' in condition
|
|
7
|
-
? condition.fromState
|
|
8
|
-
? (0, getValueFromPath_js_1.getValueFromPath)(subject, condition.term2)
|
|
9
|
-
: condition.term2
|
|
10
|
-
: null;
|
|
11
|
-
switch (condition.operator) {
|
|
12
|
-
case 'truthy': return {
|
|
13
|
-
$ne: [
|
|
14
|
-
null,
|
|
15
|
-
undefined,
|
|
16
|
-
],
|
|
17
|
-
};
|
|
18
|
-
case 'equal': return term2;
|
|
19
|
-
case 'gt': return {
|
|
20
|
-
$gt: term2,
|
|
21
|
-
};
|
|
22
|
-
case 'lt': return {
|
|
23
|
-
$lt: term2,
|
|
24
|
-
};
|
|
25
|
-
case 'gte': return {
|
|
26
|
-
$gte: term2,
|
|
27
|
-
};
|
|
28
|
-
case 'lte': return {
|
|
29
|
-
$lte: term2,
|
|
30
|
-
};
|
|
31
|
-
case 'regex': return {
|
|
32
|
-
$regex: term2,
|
|
33
|
-
$options: condition.regexOptions,
|
|
34
|
-
};
|
|
35
|
-
case 'in': {
|
|
36
|
-
return Array.isArray(term2)
|
|
37
|
-
? {
|
|
38
|
-
$in: term2,
|
|
39
|
-
}
|
|
40
|
-
: term2;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const convertConditionToQuery = (condition, subject) => {
|
|
45
|
-
if ('or' in condition) {
|
|
46
|
-
return {
|
|
47
|
-
$or: condition.or.map((sub) => (0, exports.convertConditionToQuery)(sub, subject)),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if ('and' in condition) {
|
|
51
|
-
return {
|
|
52
|
-
$and: condition.and.map((sub) => (0, exports.convertConditionToQuery)(sub, subject)),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if ('not' in condition) {
|
|
56
|
-
return {
|
|
57
|
-
$not: (0, exports.convertConditionToQuery)(condition.not, subject),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
[condition.term1]: convertExpression(condition, subject),
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
exports.convertConditionToQuery = convertConditionToQuery;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { getValueFromPath } from "./getValueFromPath.mjs";
|
|
3
|
-
const convertExpression = (condition, subject) => {
|
|
4
|
-
const term2 = "term2" in condition ? condition.fromState ? getValueFromPath(subject, condition.term2) : condition.term2 : null;
|
|
5
|
-
switch (condition.operator) {
|
|
6
|
-
case "truthy":
|
|
7
|
-
return {
|
|
8
|
-
$ne: [
|
|
9
|
-
null,
|
|
10
|
-
void 0
|
|
11
|
-
]
|
|
12
|
-
};
|
|
13
|
-
case "equal":
|
|
14
|
-
return term2;
|
|
15
|
-
case "gt":
|
|
16
|
-
return {
|
|
17
|
-
$gt: term2
|
|
18
|
-
};
|
|
19
|
-
case "lt":
|
|
20
|
-
return {
|
|
21
|
-
$lt: term2
|
|
22
|
-
};
|
|
23
|
-
case "gte":
|
|
24
|
-
return {
|
|
25
|
-
$gte: term2
|
|
26
|
-
};
|
|
27
|
-
case "lte":
|
|
28
|
-
return {
|
|
29
|
-
$lte: term2
|
|
30
|
-
};
|
|
31
|
-
case "regex":
|
|
32
|
-
return {
|
|
33
|
-
$regex: term2,
|
|
34
|
-
$options: condition.regexOptions
|
|
35
|
-
};
|
|
36
|
-
case "in": {
|
|
37
|
-
return Array.isArray(term2) ? {
|
|
38
|
-
$in: term2
|
|
39
|
-
} : term2;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
export const convertConditionToQuery = (condition, subject) => {
|
|
44
|
-
if ("or" in condition) {
|
|
45
|
-
return {
|
|
46
|
-
$or: condition.or.map((sub) => convertConditionToQuery(sub, subject))
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if ("and" in condition) {
|
|
50
|
-
return {
|
|
51
|
-
$and: condition.and.map((sub) => convertConditionToQuery(sub, subject))
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
if ("not" in condition) {
|
|
55
|
-
return {
|
|
56
|
-
$not: convertConditionToQuery(condition.not, subject)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
[condition.term1]: convertExpression(condition, subject)
|
|
61
|
-
};
|
|
62
|
-
};
|
package/dist/date.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type DateFormatOptions = {
|
|
2
|
-
hours?: boolean;
|
|
3
|
-
hoursOnly?: boolean;
|
|
4
|
-
locale?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const formatDateTime: (date: Date | string, options?: DateFormatOptions) => string;
|
|
7
|
-
export declare const getRelativeTimeFromNow: (target: any) => string | undefined;
|
package/dist/date.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRelativeTimeFromNow = exports.formatDateTime = void 0;
|
|
4
|
-
const rtf = new Intl.RelativeTimeFormat(undefined, {
|
|
5
|
-
numeric: 'auto',
|
|
6
|
-
});
|
|
7
|
-
const units = {
|
|
8
|
-
year: 31536000000,
|
|
9
|
-
month: 2628000000,
|
|
10
|
-
day: 86400000,
|
|
11
|
-
hour: 3600000,
|
|
12
|
-
minute: 6000,
|
|
13
|
-
second: 1000,
|
|
14
|
-
};
|
|
15
|
-
const formatDateTime = function (date, options) {
|
|
16
|
-
const target = date instanceof Date
|
|
17
|
-
? date
|
|
18
|
-
: new Date(date);
|
|
19
|
-
if (isNaN(target.getDate())) {
|
|
20
|
-
return '-';
|
|
21
|
-
}
|
|
22
|
-
const { hours, hoursOnly, locale = 'navigator' in globalThis
|
|
23
|
-
? navigator.language
|
|
24
|
-
: 'en-US', } = options || {};
|
|
25
|
-
if (hoursOnly) {
|
|
26
|
-
return target.toLocaleTimeString();
|
|
27
|
-
}
|
|
28
|
-
return hours
|
|
29
|
-
? target.toLocaleString(locale)
|
|
30
|
-
: target.toLocaleDateString(locale);
|
|
31
|
-
};
|
|
32
|
-
exports.formatDateTime = formatDateTime;
|
|
33
|
-
const getRelativeTimeFromNow = function (target) {
|
|
34
|
-
const now = new Date();
|
|
35
|
-
const elapsed = now - target;
|
|
36
|
-
for (const [u, value] of Object.entries(units)) {
|
|
37
|
-
if (Math.abs(elapsed) > value || u === 'second') {
|
|
38
|
-
return rtf.format(-1 * Math.round(elapsed / value), u);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
exports.getRelativeTimeFromNow = getRelativeTimeFromNow;
|
package/dist/date.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const rtf = new Intl.RelativeTimeFormat(void 0, {
|
|
3
|
-
numeric: "auto"
|
|
4
|
-
});
|
|
5
|
-
const units = {
|
|
6
|
-
year: 31536e6,
|
|
7
|
-
month: 2628e6,
|
|
8
|
-
day: 864e5,
|
|
9
|
-
hour: 36e5,
|
|
10
|
-
minute: 6e3,
|
|
11
|
-
second: 1e3
|
|
12
|
-
};
|
|
13
|
-
export const formatDateTime = function(date, options) {
|
|
14
|
-
const target = date instanceof Date ? date : new Date(date);
|
|
15
|
-
if (isNaN(target.getDate())) {
|
|
16
|
-
return "-";
|
|
17
|
-
}
|
|
18
|
-
const {
|
|
19
|
-
hours,
|
|
20
|
-
hoursOnly,
|
|
21
|
-
locale = "navigator" in globalThis ? navigator.language : "en-US"
|
|
22
|
-
} = options || {};
|
|
23
|
-
if (hoursOnly) {
|
|
24
|
-
return target.toLocaleTimeString();
|
|
25
|
-
}
|
|
26
|
-
return hours ? target.toLocaleString(locale) : target.toLocaleDateString(locale);
|
|
27
|
-
};
|
|
28
|
-
export const getRelativeTimeFromNow = function(target) {
|
|
29
|
-
const now = /* @__PURE__ */ new Date();
|
|
30
|
-
const elapsed = now - target;
|
|
31
|
-
for (const [u, value] of Object.entries(units)) {
|
|
32
|
-
if (Math.abs(elapsed) > value || u === "second") {
|
|
33
|
-
return rtf.format(-1 * Math.round(elapsed / value), u);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
package/dist/formatValue.d.ts
DELETED
package/dist/formatValue.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatValue = void 0;
|
|
4
|
-
const date_js_1 = require("./date.js");
|
|
5
|
-
const getReferenceProperty_js_1 = require("./getReferenceProperty.js");
|
|
6
|
-
const formatValue = (value, key, property, index) => {
|
|
7
|
-
if (Array.isArray(value)) {
|
|
8
|
-
return value.map((v) => (0, exports.formatValue)(v, key, property, index)).join(', ');
|
|
9
|
-
}
|
|
10
|
-
const firstValue = (() => {
|
|
11
|
-
if (!property) {
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
const refProperty = (0, getReferenceProperty_js_1.getReferenceProperty)(property);
|
|
15
|
-
if (refProperty) {
|
|
16
|
-
const firstIndex = index || refProperty.indexes?.[0];
|
|
17
|
-
return firstIndex && value?.[firstIndex];
|
|
18
|
-
}
|
|
19
|
-
if (value instanceof Object) {
|
|
20
|
-
return Object.values(value)[0];
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
})();
|
|
24
|
-
const formatted = (() => {
|
|
25
|
-
if (!property) {
|
|
26
|
-
return firstValue;
|
|
27
|
-
}
|
|
28
|
-
if ('type' in property) {
|
|
29
|
-
if (property.type === 'boolean') {
|
|
30
|
-
return firstValue
|
|
31
|
-
? 'true'
|
|
32
|
-
: false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if ('format' in property && property.format) {
|
|
36
|
-
if ([
|
|
37
|
-
'date',
|
|
38
|
-
'date-time',
|
|
39
|
-
].includes(property.format)) {
|
|
40
|
-
return (0, date_js_1.formatDateTime)(String(value), {
|
|
41
|
-
hours: property.format === 'date-time',
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if ([
|
|
46
|
-
undefined,
|
|
47
|
-
null,
|
|
48
|
-
].includes(firstValue)) {
|
|
49
|
-
return '-';
|
|
50
|
-
}
|
|
51
|
-
return firstValue;
|
|
52
|
-
})();
|
|
53
|
-
return String(formatted);
|
|
54
|
-
};
|
|
55
|
-
exports.formatValue = formatValue;
|
package/dist/formatValue.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { formatDateTime } from "./date.mjs";
|
|
3
|
-
import { getReferenceProperty } from "./getReferenceProperty.mjs";
|
|
4
|
-
export const formatValue = (value, key, property, index) => {
|
|
5
|
-
if (Array.isArray(value)) {
|
|
6
|
-
return value.map((v) => formatValue(v, key, property, index)).join(", ");
|
|
7
|
-
}
|
|
8
|
-
const firstValue = (() => {
|
|
9
|
-
if (!property) {
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
const refProperty = getReferenceProperty(property);
|
|
13
|
-
if (refProperty) {
|
|
14
|
-
const firstIndex = index || refProperty.indexes?.[0];
|
|
15
|
-
return firstIndex && value?.[firstIndex];
|
|
16
|
-
}
|
|
17
|
-
if (value instanceof Object) {
|
|
18
|
-
return Object.values(value)[0];
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
})();
|
|
22
|
-
const formatted = (() => {
|
|
23
|
-
if (!property) {
|
|
24
|
-
return firstValue;
|
|
25
|
-
}
|
|
26
|
-
if ("type" in property) {
|
|
27
|
-
if (property.type === "boolean") {
|
|
28
|
-
return firstValue ? "true" : false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if ("format" in property && property.format) {
|
|
32
|
-
if ([
|
|
33
|
-
"date",
|
|
34
|
-
"date-time"
|
|
35
|
-
].includes(property.format)) {
|
|
36
|
-
return formatDateTime(String(value), {
|
|
37
|
-
hours: property.format === "date-time"
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if ([
|
|
42
|
-
void 0,
|
|
43
|
-
null
|
|
44
|
-
].includes(firstValue)) {
|
|
45
|
-
return "-";
|
|
46
|
-
}
|
|
47
|
-
return firstValue;
|
|
48
|
-
})();
|
|
49
|
-
return String(formatted);
|
|
50
|
-
};
|