@atscript/db-mongo 0.1.105 → 0.1.107
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.cjs +15 -6
- package/dist/index.mjs +15 -6
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -2,15 +2,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_mongo_filter = require("./mongo-filter-z_hLPMyv.cjs");
|
|
3
3
|
let _atscript_db = require("@atscript/db");
|
|
4
4
|
let mongodb = require("mongodb");
|
|
5
|
+
//#region src/lib/path-utils.ts
|
|
6
|
+
function hasAncestorIn(path, set) {
|
|
7
|
+
let dot = path.indexOf(".");
|
|
8
|
+
while (dot !== -1) {
|
|
9
|
+
if (set.has(path.slice(0, dot))) return true;
|
|
10
|
+
dot = path.indexOf(".", dot + 1);
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
5
15
|
//#region src/lib/projection-dedupe.ts
|
|
6
16
|
function dedupeProjection(projection) {
|
|
7
17
|
const includeKeys = Object.keys(projection).filter((k) => projection[k] === 1);
|
|
8
18
|
if (includeKeys.length < 2) return projection;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const prefix = parent + ".";
|
|
12
|
-
for (const other of includeKeys) if (other !== parent && other.startsWith(prefix)) toRemove.add(other);
|
|
13
|
-
}
|
|
19
|
+
const includes = new Set(includeKeys);
|
|
20
|
+
const toRemove = new Set(includeKeys.filter((k) => hasAncestorIn(k, includes)));
|
|
14
21
|
if (toRemove.size === 0) return projection;
|
|
15
22
|
const result = {};
|
|
16
23
|
for (const k of Object.keys(projection)) if (!toRemove.has(k)) result[k] = projection[k];
|
|
@@ -1144,8 +1151,10 @@ async function syncColumnsImpl(host, diff) {
|
|
|
1144
1151
|
}
|
|
1145
1152
|
async function dropColumnsImpl(host, columns) {
|
|
1146
1153
|
if (columns.length === 0) return;
|
|
1154
|
+
const dropped = new Set(columns);
|
|
1155
|
+
const minimal = columns.filter((col) => !hasAncestorIn(col, dropped));
|
|
1147
1156
|
const unsetSpec = {};
|
|
1148
|
-
for (const col of
|
|
1157
|
+
for (const col of minimal) unsetSpec[arraySafePath(host, col, col)] = "";
|
|
1149
1158
|
await host.collection.updateMany({}, { $unset: unsetSpec }, host._getSessionOpts());
|
|
1150
1159
|
}
|
|
1151
1160
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { t as buildMongoFilter } from "./mongo-filter-DceAGI-S.mjs";
|
|
2
2
|
import { AtscriptDbView, BaseDbAdapter, DbError, DbSpace, computeInsights, getDbFieldOp, getKeyProps, resolveDesignType } from "@atscript/db";
|
|
3
3
|
import { MongoClient, MongoServerError, ObjectId } from "mongodb";
|
|
4
|
+
//#region src/lib/path-utils.ts
|
|
5
|
+
function hasAncestorIn(path, set) {
|
|
6
|
+
let dot = path.indexOf(".");
|
|
7
|
+
while (dot !== -1) {
|
|
8
|
+
if (set.has(path.slice(0, dot))) return true;
|
|
9
|
+
dot = path.indexOf(".", dot + 1);
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
4
14
|
//#region src/lib/projection-dedupe.ts
|
|
5
15
|
function dedupeProjection(projection) {
|
|
6
16
|
const includeKeys = Object.keys(projection).filter((k) => projection[k] === 1);
|
|
7
17
|
if (includeKeys.length < 2) return projection;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const prefix = parent + ".";
|
|
11
|
-
for (const other of includeKeys) if (other !== parent && other.startsWith(prefix)) toRemove.add(other);
|
|
12
|
-
}
|
|
18
|
+
const includes = new Set(includeKeys);
|
|
19
|
+
const toRemove = new Set(includeKeys.filter((k) => hasAncestorIn(k, includes)));
|
|
13
20
|
if (toRemove.size === 0) return projection;
|
|
14
21
|
const result = {};
|
|
15
22
|
for (const k of Object.keys(projection)) if (!toRemove.has(k)) result[k] = projection[k];
|
|
@@ -1143,8 +1150,10 @@ async function syncColumnsImpl(host, diff) {
|
|
|
1143
1150
|
}
|
|
1144
1151
|
async function dropColumnsImpl(host, columns) {
|
|
1145
1152
|
if (columns.length === 0) return;
|
|
1153
|
+
const dropped = new Set(columns);
|
|
1154
|
+
const minimal = columns.filter((col) => !hasAncestorIn(col, dropped));
|
|
1146
1155
|
const unsetSpec = {};
|
|
1147
|
-
for (const col of
|
|
1156
|
+
for (const col of minimal) unsetSpec[arraySafePath(host, col, col)] = "";
|
|
1148
1157
|
await host.collection.updateMany({}, { $unset: unsetSpec }, host._getSessionOpts());
|
|
1149
1158
|
}
|
|
1150
1159
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.107",
|
|
4
4
|
"description": "Mongodb plugin for atscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -46,17 +46,17 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@atscript/core": "^0.1.
|
|
50
|
-
"@atscript/typescript": "^0.1.
|
|
49
|
+
"@atscript/core": "^0.1.77",
|
|
50
|
+
"@atscript/typescript": "^0.1.77",
|
|
51
51
|
"mongodb": "^6.17.0",
|
|
52
52
|
"mongodb-memory-server-core": "^10.0.0",
|
|
53
|
-
"unplugin-atscript": "^0.1.
|
|
53
|
+
"unplugin-atscript": "^0.1.77"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@atscript/core": "^0.1.
|
|
57
|
-
"@atscript/typescript": "^0.1.
|
|
56
|
+
"@atscript/core": "^0.1.77",
|
|
57
|
+
"@atscript/typescript": "^0.1.77",
|
|
58
58
|
"mongodb": "^6.17.0",
|
|
59
|
-
"@atscript/db": "^0.1.
|
|
59
|
+
"@atscript/db": "^0.1.107"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"postinstall": "asc -f dts",
|