cantian-mongodb 0.0.25 → 0.0.27
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/trash.d.ts +22 -0
- package/dist/trash.js +28 -0
- package/dist/trash.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
package/dist/trash.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FromSchema } from 'json-schema-to-ts';
|
|
2
|
+
export declare const trashModelSchema: {
|
|
3
|
+
readonly type: "object";
|
|
4
|
+
readonly properties: {
|
|
5
|
+
readonly _id: {
|
|
6
|
+
readonly type: "string";
|
|
7
|
+
};
|
|
8
|
+
readonly source: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
};
|
|
11
|
+
readonly origin: {
|
|
12
|
+
readonly type: "object";
|
|
13
|
+
};
|
|
14
|
+
readonly deletedAt: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly additionalProperties: false;
|
|
19
|
+
readonly required: readonly ["source", "origin", "deletedAt"];
|
|
20
|
+
};
|
|
21
|
+
export type TrashModel = FromSchema<typeof trashModelSchema>;
|
|
22
|
+
export declare const moveToTrash: (source: string, origin: Record<string, any> | Record<string, any>[]) => Promise<void>;
|
package/dist/trash.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { db } from './mongoClient.js';
|
|
2
|
+
export const trashModelSchema = {
|
|
3
|
+
type: 'object',
|
|
4
|
+
properties: {
|
|
5
|
+
_id: { type: 'string' },
|
|
6
|
+
source: { type: 'string' },
|
|
7
|
+
origin: { type: 'object' },
|
|
8
|
+
deletedAt: { type: 'string' },
|
|
9
|
+
},
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
required: ['source', 'origin', 'deletedAt'],
|
|
12
|
+
};
|
|
13
|
+
const trashCollection = db.collection('trash');
|
|
14
|
+
export const moveToTrash = async (source, origin) => {
|
|
15
|
+
if (origin) {
|
|
16
|
+
if (!Array.isArray(origin)) {
|
|
17
|
+
origin = [origin];
|
|
18
|
+
}
|
|
19
|
+
const now = new Date().toISOString();
|
|
20
|
+
const records = origin.map((o) => ({
|
|
21
|
+
source,
|
|
22
|
+
origin: o,
|
|
23
|
+
deletedAt: now,
|
|
24
|
+
}));
|
|
25
|
+
await trashCollection.insertMany(records);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=trash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trash.js","sourceRoot":"","sources":["../src/trash.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1B,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC9B;IACD,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC;CACd,CAAC;AAIhC,MAAM,eAAe,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,MAAc,EAAE,MAAmD,EAAE,EAAE;IACvG,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjC,MAAM;YACN,MAAM,EAAE,CAAC;YACT,SAAS,EAAE,GAAG;SACf,CAAC,CAAC,CAAC;QACJ,MAAM,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC,CAAC"}
|