cry-db-exec 1.0.18

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/doc.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const doc: string;
package/dist/doc.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doc = void 0;
4
+ const ops_1 = require("./ops");
5
+ exports.doc = Object.values(ops_1.opsArr)
6
+ .map(op => `${op.operation}(${op.params.join(",")})`)
7
+ .sort()
8
+ .join("\n");
9
+ //# sourceMappingURL=doc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doc.js","sourceRoot":"","sources":["../src/doc.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAEjB,QAAA,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,YAAM,CAAC;KACnC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;KACpD,IAAI,EAAE;KACN,IAAI,CAAC,IAAI,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare function execDb(req: {
2
+ operation: string;
3
+ db: string;
4
+ }, mongo: any, verbose?: boolean): Promise<any>;
package/dist/execDb.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.execDb = void 0;
4
+ //@ts-check
5
+ const ops_1 = require("./ops");
6
+ async function execDb(req, mongo, verbose) {
7
+ let operation = req === null || req === void 0 ? void 0 : req.operation;
8
+ if (!mongo)
9
+ throw new Error("execDb: pass mongo instance");
10
+ if (!operation)
11
+ throw new Error("execDb: specify operation");
12
+ if (!req)
13
+ throw new Error("execDb: specify req as Object");
14
+ let cmdParams = ops_1.opsObj[operation];
15
+ if (!cmdParams)
16
+ throw new Error(`execDb: operation ${operation} not supported`);
17
+ if (!mongo[operation])
18
+ throw new Error(`execDb: passed-in mongo instance does not support ${operation}`);
19
+ if (typeof (mongo[operation]) !== "function")
20
+ throw new Error(`execDb: passed-in mongo instance ${operation} is ${typeof mongo[operation]} instead of function`);
21
+ if (!mongo.setDb)
22
+ throw new Error(`execDb: passed-in mongo instance does not provide setDb`);
23
+ if ((typeof mongo.setDb) !== "function")
24
+ throw new Error(`execDb: passed-in mongo instance setDb is not a function`);
25
+ if (cmdParams.needDb && !req.db)
26
+ throw new Error("execDb: specify db in req");
27
+ if (verbose)
28
+ console.log(`execDb: setting db to ${req.db || "local"}`);
29
+ mongo.setDb(req.db || "local");
30
+ // build parameter list
31
+ let params = [mongo];
32
+ for (let param of cmdParams.params)
33
+ params.push(req[param]);
34
+ // call mongo
35
+ let f = mongo[operation];
36
+ if (verbose)
37
+ console.log(`execDb: call ${operation} with `, params);
38
+ let ret = await f.call(...params);
39
+ if (verbose)
40
+ console.log(`execDb: result = `, ret);
41
+ return ret;
42
+ }
43
+ exports.execDb = execDb;
44
+ //# sourceMappingURL=execDb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execDb.js","sourceRoot":"","sources":["../src/execDb.ts"],"names":[],"mappings":";;;AAAA,WAAW;AACX,+BAA8B;AAEvB,KAAK,UAAU,MAAM,CAAC,GAAqC,EAAE,KAAU,EAAE,OAAiB;IAE7F,IAAI,SAAS,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,CAAC;IAC/B,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAC1D,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC5D,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;IAC1D,IAAI,SAAS,GAAG,YAAM,CAAC,SAAS,CAAC,CAAC;IAClC,IAAI,CAAC,SAAS;QAA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CAAC;IAElC,IAAI,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAA;IAElD,OAAO,GAAG,CAAA;AACd,CAAC;AA9BD,wBA8BC"}
@@ -0,0 +1,3 @@
1
+ export { execDb } from "./execDb";
2
+ export { opsArr, opsObj } from "./ops";
3
+ export { doc } from "./doc";
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.doc = exports.opsObj = exports.opsArr = exports.execDb = void 0;
4
+ var execDb_1 = require("./execDb");
5
+ Object.defineProperty(exports, "execDb", { enumerable: true, get: function () { return execDb_1.execDb; } });
6
+ var ops_1 = require("./ops");
7
+ Object.defineProperty(exports, "opsArr", { enumerable: true, get: function () { return ops_1.opsArr; } });
8
+ Object.defineProperty(exports, "opsObj", { enumerable: true, get: function () { return ops_1.opsObj; } });
9
+ var doc_1 = require("./doc");
10
+ Object.defineProperty(exports, "doc", { enumerable: true, get: function () { return doc_1.doc; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,mCAAiC;AAAxB,gGAAA,MAAM,OAAA;AACf,6BAAsC;AAA7B,6FAAA,MAAM,OAAA;AAAE,6FAAA,MAAM,OAAA;AACvB,6BAA2B;AAAlB,0FAAA,GAAG,OAAA"}
package/dist/ops.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const opsArr: {
2
+ operation: string;
3
+ params: string[];
4
+ needDb: boolean;
5
+ }[];
6
+ export declare const opsObj: Record<string, {
7
+ operation: string;
8
+ params: string[];
9
+ needDb: boolean;
10
+ }>;
package/dist/ops.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.opsObj = exports.opsArr = void 0;
4
+ const ops = [
5
+ { operation: "aggregate", params: "collection, pipeline, opts", needDb: true },
6
+ { operation: "blockOne", params: "collection, query", needDb: true },
7
+ { operation: "count", params: "collection, query,opts", needDb: true },
8
+ { operation: "distinct", params: "collection, field", needDb: true },
9
+ { operation: "collectFieldValues", params: "collection, field, inArray, opts", needDb: true },
10
+ { operation: "createCollection", params: "collection", needDb: true },
11
+ { operation: "createCollections", params: "collections", needDb: true },
12
+ { operation: "dbLogGet", params: "collection, id", needDb: true },
13
+ { operation: "dbLogPurge", params: "collection, id", needDb: true },
14
+ { operation: "delete", params: "collection, query", needDb: true },
15
+ { operation: "deleteOne", params: "collection, query", needDb: true },
16
+ { operation: "dropCollection", params: "collection", needDb: true },
17
+ { operation: "dropCollections", params: "collections", needDb: true },
18
+ { operation: "find", params: "collection, query, opts", needDb: true },
19
+ { operation: "findAfter", params: "collection, csq, query, opts", needDb: true },
20
+ { operation: "findAfterMany", params: "spec", needDb: true },
21
+ { operation: "findAll", params: "collection, query, opts", needDb: true },
22
+ { operation: "findById", params: "collection, id, project", needDb: true },
23
+ { operation: "findNewer", params: "collection, timestamp, query, opts", needDb: true },
24
+ { operation: "findNewerMany", params: "spec", needDb: true },
25
+ { operation: "findNewerFromDate", params: "collection, date, query, opts", needDb: true },
26
+ { operation: "findOne", params: "collection, query, project", needDb: true },
27
+ { operation: "getDatabaseInfos", params: "", },
28
+ { operation: "getDatabases", params: "", },
29
+ { operation: "hardDelete", params: "collection, query", needDb: true },
30
+ { operation: "hardDeleteOne", params: "collection, query", needDb: true },
31
+ { operation: "insert", params: "collection, insert", needDb: true },
32
+ { operation: "insertMany", params: "collection, insert", needDb: true },
33
+ { operation: "isOnReplicaSet", params: "", },
34
+ { operation: "isUnique", params: "collection, field, value, id", needDb: true },
35
+ { operation: "newId", params: "", },
36
+ { operation: "ping", params: "", },
37
+ { operation: "resetCollectionSync", params: "collection", needDb: true },
38
+ { operation: "save", params: "collection, update, id", needDb: true },
39
+ { operation: "testHash", params: "collection, query, field, unhashedValue", needDb: true },
40
+ { operation: "unblockOne", params: "collection, query", needDb: true },
41
+ { operation: "update", params: "collection, query, update", needDb: true },
42
+ { operation: "updateOne", params: "collection, query, update, options", needDb: true },
43
+ { operation: "upsert", params: "collection, query, update, options", needDb: true },
44
+ { operation: "upsertBatch", params: "collection, batch", needDb: true },
45
+ ];
46
+ exports.opsArr = ops.reduce((prev, curr) => {
47
+ prev.push({
48
+ operation: curr.operation,
49
+ params: curr.params.split(",").map(p => p.trim()).filter(p => !!p),
50
+ needDb: !!curr.needDb
51
+ });
52
+ return prev;
53
+ }, []);
54
+ exports.opsObj = exports.opsArr.reduce((prev, curr) => {
55
+ prev[curr.operation] = curr;
56
+ return prev;
57
+ }, {});
58
+ //# sourceMappingURL=ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ops.js","sourceRoot":"","sources":["../src/ops.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG,GACL;IACI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,4BAA4B,EAAE,MAAM,EAAE,IAAI,EAAE;IAC9E,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,EAAE;IACpE,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,IAAI,EAAE;IACtE,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,EAAE;IACpE,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,EAAE,kCAAkC,EAAE,MAAM,EAAE,IAAI,EAAE;IAC7F,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE;IACrE,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE;IACvE,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,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oCAAoC,EAAE,MAAM,EAAE,IAAI,EAAE;IACtF,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,oCAAoC,EAAE,MAAM,EAAE,IAAI,EAAE;IACnF,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,EAAE;CAC1E,CAAC;AAGO,QAAA,MAAM,GACf,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IACtB,IAAI,CAAC,IAAI,CAAC;QACN,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAClE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM;KACxB,CAAC,CAAA;IACF,OAAO,IAAI,CAAC;AAChB,CAAC,EAAE,EAAgE,CAClE,CAAC;AAEO,QAAA,MAAM,GAAG,cAAM,CAAC,MAAM,CAC/B,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IACX,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IAC5B,OAAO,IAAI,CAAC;AAChB,CAAC,EACD,EAA2E,CAC9E,CAAA"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "cry-db-exec",
3
+ "version": "1.0.18",
4
+ "description": "execute db command passed-in as json",
5
+ "main": "./dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "directories": {
10
+ "test": "test"
11
+ },
12
+ "scripts": {
13
+ "test": "mocha -b --timeout 4000"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://bitbucket.org/primozk/cry-db-exec/src/master/"
18
+ },
19
+ "author": "Primož Krajnik",
20
+ "license": "ISC",
21
+ "devDependencies": {
22
+ "chai": "^4.3.4",
23
+ "mocha": "^9.1.2",
24
+ "typescript": "^4.4.3"
25
+ },
26
+ "dependencies": {
27
+ "cry-db": "^2.0.9"
28
+ }
29
+ }