@unchainedshop/mongodb 4.3.2 → 4.3.4
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/package.json +3 -8
- package/lib/check-id.d.ts +0 -5
- package/lib/check-id.d.ts.map +0 -1
- package/lib/check-id.js +0 -6
- package/lib/check-id.js.map +0 -1
- package/lib/email-regex-operator.d.ts +0 -4
- package/lib/email-regex-operator.d.ts.map +0 -1
- package/lib/email-regex-operator.js +0 -12
- package/lib/email-regex-operator.js.map +0 -1
- package/lib/generate-db-mutations.d.ts +0 -11
- package/lib/generate-db-mutations.d.ts.map +0 -1
- package/lib/generate-db-mutations.js +0 -73
- package/lib/generate-db-mutations.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/mongodb",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.4",
|
|
4
4
|
"description": "MongoDB provider for unchained platform",
|
|
5
5
|
"main": "lib/mongodb-index.js",
|
|
6
6
|
"types": "lib/mongodb-index.d.ts",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@unchainedshop/utils": "^4.3.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@mongodb-js/zstd": ">=
|
|
38
|
-
"mongodb": ">=
|
|
37
|
+
"@mongodb-js/zstd": ">= 2 < 8",
|
|
38
|
+
"mongodb": ">= 6 < 8",
|
|
39
39
|
"mongodb-memory-server": ">= 10.1 < 11"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
@@ -52,10 +52,5 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "^24.0.13",
|
|
54
54
|
"typescript": "^5.8.3"
|
|
55
|
-
},
|
|
56
|
-
"overrides": {
|
|
57
|
-
"mongodb-memory-server": {
|
|
58
|
-
"mongodb": "^7.0.0"
|
|
59
|
-
}
|
|
60
55
|
}
|
|
61
56
|
}
|
package/lib/check-id.d.ts
DELETED
package/lib/check-id.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-id.d.ts","sourceRoot":"","sources":["../src/check-id.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UACX,MAAM,UAET;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,GACD,SAAS,KACZ,IAIF,CAAC"}
|
package/lib/check-id.js
DELETED
package/lib/check-id.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-id.js","sourceRoot":"","sources":["../src/check-id.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,KAAa,EACb,KAKa,EACP,EAAE;IACR,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,KAAK,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAC3C,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email-regex-operator.d.ts","sourceRoot":"","sources":["../src/email-regex-operator.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,MAAM,KAAA;;EAUxC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function emailRegexOperator(string) {
|
|
2
|
-
if (typeof string !== 'string') {
|
|
3
|
-
throw new TypeError('Expected a string');
|
|
4
|
-
}
|
|
5
|
-
const escapped = string.trim().replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
6
|
-
if (escapped.length === 0)
|
|
7
|
-
throw new Error('String is empty after trimming');
|
|
8
|
-
if (escapped.length > 255)
|
|
9
|
-
throw new Error('String exceeds maximum allowed length');
|
|
10
|
-
return { $regex: new RegExp(`^${escapped}$`, 'i') };
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=email-regex-operator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email-regex-operator.js","sourceRoot":"","sources":["../src/email-regex-operator.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,MAAM;IACvC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;IAExE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC7E,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAEpF,OAAO,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,QAAQ,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import SimpleSchema from 'simpl-schema';
|
|
2
|
-
import { TimestampFields } from '@unchainedshop/types/common.js';
|
|
3
|
-
import { ModuleCreateMutation, ModuleMutations } from '@unchainedshop/types/core.js';
|
|
4
|
-
import { Collection } from 'mongodb';
|
|
5
|
-
export declare const generateDbMutations: <T extends TimestampFields & {
|
|
6
|
-
_id?: string;
|
|
7
|
-
}>(collection: Collection<T>, schema: SimpleSchema, options?: {
|
|
8
|
-
hasCreateOnly?: boolean;
|
|
9
|
-
permanentlyDeleteByDefault?: boolean;
|
|
10
|
-
}) => ModuleMutations<T> | ModuleCreateMutation<T>;
|
|
11
|
-
//# sourceMappingURL=generate-db-mutations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-mutations.d.ts","sourceRoot":"","sources":["../src/generate-db-mutations.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAC;AAKnD,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,eAAe,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,cAClE,UAAU,CAAC,CAAC,CAAC,UACjB,YAAY,YACV;IACR,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC,KACA,eAAe,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CA6E7C,CAAC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { checkId } from './check-id.js';
|
|
2
|
-
import { generateDbObjectId } from './generate-db-object-id.js';
|
|
3
|
-
import { generateDbFilterById } from './generate-db-filter-by-id.js';
|
|
4
|
-
export const generateDbMutations = (collection, schema, options) => {
|
|
5
|
-
if (!collection)
|
|
6
|
-
throw new Error('Collection is missing');
|
|
7
|
-
if (!schema)
|
|
8
|
-
throw new Error('Schema is missing');
|
|
9
|
-
const { hasCreateOnly, permanentlyDeleteByDefault } = options || {
|
|
10
|
-
hasCreateOnly: false,
|
|
11
|
-
permanentlyDeleteByDefault: false,
|
|
12
|
-
};
|
|
13
|
-
const deletePermanently = async (_id) => {
|
|
14
|
-
checkId(_id);
|
|
15
|
-
const filter = generateDbFilterById(_id);
|
|
16
|
-
const result = await collection.deleteOne(filter);
|
|
17
|
-
return result.deletedCount;
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
create: async (doc) => {
|
|
21
|
-
const values = schema.clean(doc);
|
|
22
|
-
values.created = new Date();
|
|
23
|
-
schema.validate(values);
|
|
24
|
-
values._id = doc._id || generateDbObjectId();
|
|
25
|
-
const result = await collection.insertOne(values);
|
|
26
|
-
return result.insertedId;
|
|
27
|
-
},
|
|
28
|
-
update: hasCreateOnly
|
|
29
|
-
? undefined
|
|
30
|
-
: async (_id, doc) => {
|
|
31
|
-
checkId(_id);
|
|
32
|
-
let modifier;
|
|
33
|
-
if (doc?.$set) {
|
|
34
|
-
const values = schema.clean(doc, { isModifier: true });
|
|
35
|
-
modifier = {
|
|
36
|
-
...values,
|
|
37
|
-
$set: {
|
|
38
|
-
...(values.$set || {}),
|
|
39
|
-
updated: new Date(),
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const values = schema.clean(doc);
|
|
45
|
-
modifier = {
|
|
46
|
-
$set: {
|
|
47
|
-
...values,
|
|
48
|
-
updated: new Date(),
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
schema.validate(modifier, { modifier: true });
|
|
53
|
-
const filter = generateDbFilterById(_id, { deleted: null });
|
|
54
|
-
await collection.updateOne(filter, modifier);
|
|
55
|
-
return _id;
|
|
56
|
-
},
|
|
57
|
-
deletePermanently: hasCreateOnly ? undefined : deletePermanently,
|
|
58
|
-
delete: hasCreateOnly
|
|
59
|
-
? undefined
|
|
60
|
-
: async (_id) => {
|
|
61
|
-
if (permanentlyDeleteByDefault) {
|
|
62
|
-
return deletePermanently(_id);
|
|
63
|
-
}
|
|
64
|
-
checkId(_id);
|
|
65
|
-
const filter = generateDbFilterById(_id, { deleted: null });
|
|
66
|
-
const modifier = { $set: { deleted: new Date() } };
|
|
67
|
-
const values = schema.clean(modifier, { isModifier: true });
|
|
68
|
-
const result = await collection.updateOne(filter, values);
|
|
69
|
-
return result.modifiedCount;
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=generate-db-mutations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-mutations.js","sourceRoot":"","sources":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