@atscript/db-mongo 0.1.174 → 0.1.175
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/agg.cjs +1 -1
- package/dist/agg.mjs +1 -1
- package/dist/index.cjs +43 -9
- package/dist/index.mjs +44 -10
- package/dist/{mongo-accumulator-BOwAFmrt.cjs → mongo-accumulator-BBRS2_8v.cjs} +3 -2
- package/dist/{mongo-accumulator-D4drEz0-.mjs → mongo-accumulator-CFVRBDiw.mjs} +4 -3
- package/package.json +9 -9
package/dist/agg.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_mongo_accumulator = require("./mongo-accumulator-
|
|
2
|
+
const require_mongo_accumulator = require("./mongo-accumulator-BBRS2_8v.cjs");
|
|
3
3
|
let _atscript_db = require("@atscript/db");
|
|
4
4
|
let _uniqu_core = require("@uniqu/core");
|
|
5
5
|
let _atscript_db_agg = require("@atscript/db/agg");
|
package/dist/agg.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as rowOrderStages, f as sortStages, g as whereToExpr, i as buildMongoFilter, m as orNull, n as distinctCountExpr, p as exprToMongo, s as mongoFilterStages, t as buildAccumulator } from "./mongo-accumulator-
|
|
1
|
+
import { d as rowOrderStages, f as sortStages, g as whereToExpr, i as buildMongoFilter, m as orNull, n as distinctCountExpr, p as exprToMongo, s as mongoFilterStages, t as buildAccumulator } from "./mongo-accumulator-CFVRBDiw.mjs";
|
|
2
2
|
import { DbError, aggregateColumns, evaluateExpr } from "@atscript/db";
|
|
3
3
|
import { BUCKET_MAX_INSTANT, BUCKET_MIN_INSTANT } from "@uniqu/core";
|
|
4
4
|
import { assertAggregateFn, resolveAlias } from "@atscript/db/agg";
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_mongo_accumulator = require("./mongo-accumulator-
|
|
2
|
+
const require_mongo_accumulator = require("./mongo-accumulator-BBRS2_8v.cjs");
|
|
3
3
|
const require_search_messages = require("./search-messages-BqLxxrb8.cjs");
|
|
4
4
|
let _atscript_db = require("@atscript/db");
|
|
5
5
|
let mongodb = require("mongodb");
|
|
@@ -69,6 +69,24 @@ function serverErrorCode(error) {
|
|
|
69
69
|
const code = error.code;
|
|
70
70
|
return typeof code === "number" ? code : void 0;
|
|
71
71
|
}
|
|
72
|
+
/** `WriteConflict`: a write met a concurrent transaction's uncommitted change. */
|
|
73
|
+
const WRITE_CONFLICT = 112;
|
|
74
|
+
/**
|
|
75
|
+
* The retryable `SERIALIZATION_FAILURE` of a driver error that ended a
|
|
76
|
+
* transaction without committing it — one labelled `TransientTransactionError`
|
|
77
|
+
* or `UnknownTransactionCommitResult` (`session.withTransaction` retries
|
|
78
|
+
* those itself for 120 s, then rethrows), or a `WriteConflict` — else `error`
|
|
79
|
+
* as is. The raw driver error is kept as `cause`.
|
|
80
|
+
*/
|
|
81
|
+
function mapTransientTransactionError(error) {
|
|
82
|
+
if (!(error instanceof Error)) return error;
|
|
83
|
+
const labels = error.errorLabels;
|
|
84
|
+
if (!(Array.isArray(labels) && (labels.includes("TransientTransactionError") || labels.includes("UnknownTransactionCommitResult"))) && serverErrorCode(error) !== WRITE_CONFLICT) return error;
|
|
85
|
+
return new _atscript_db.DbError("SERIALIZATION_FAILURE", [{
|
|
86
|
+
path: "",
|
|
87
|
+
message: error.message
|
|
88
|
+
}], void 0, { cause: error });
|
|
89
|
+
}
|
|
72
90
|
/** `DuplicateKey` (E11000) and its legacy update form `DuplicateKeyValue` (E11001). */
|
|
73
91
|
function isDuplicateKeyCode(code) {
|
|
74
92
|
return code === 11e3 || code === 11001;
|
|
@@ -531,7 +549,7 @@ function buildViewPipeline(view, variant) {
|
|
|
531
549
|
out = require_mongo_accumulator.exprToMongo(col.expr, (path) => {
|
|
532
550
|
const c = byPath.get(path);
|
|
533
551
|
return c.expr === void 0 ? { $toDouble: leaf(c) } : computedExpr(c, leaf);
|
|
534
|
-
});
|
|
552
|
+
}, col.viewPath);
|
|
535
553
|
rendered.set(col.viewPath, out);
|
|
536
554
|
}
|
|
537
555
|
return out;
|
|
@@ -767,7 +785,7 @@ async function loadRelationsImpl(host, rows, withRelations, relations, foreignKe
|
|
|
767
785
|
for (const withRel of withRelations) {
|
|
768
786
|
if (withRel.name.includes(".")) continue;
|
|
769
787
|
const relation = relations.get(withRel.name);
|
|
770
|
-
if (!relation) throw
|
|
788
|
+
if (!relation) throw (0, _atscript_db.unknownWithRelation)(withRel.name);
|
|
771
789
|
const lookup = buildRelationLookup(source, withRel, relation, foreignKeys, tableResolver);
|
|
772
790
|
if (lookup) relMeta.push(lookup);
|
|
773
791
|
}
|
|
@@ -1087,6 +1105,8 @@ const RELEVANCE_SORT = { $sort: {
|
|
|
1087
1105
|
_score: -1,
|
|
1088
1106
|
_id: 1
|
|
1089
1107
|
} };
|
|
1108
|
+
/** The order of an unranked search (`$rank: false`, since 0.1.175): the primary key. */
|
|
1109
|
+
const UNRANKED_SORT = { $sort: { _id: 1 } };
|
|
1090
1110
|
function getSearchIndexesImpl(host) {
|
|
1091
1111
|
const result = [];
|
|
1092
1112
|
const indexes = host.getMongoSearchIndexes();
|
|
@@ -1155,12 +1175,24 @@ function buildAggregateSearchStage(host, controls) {
|
|
|
1155
1175
|
/** Text search via $search aggregation stage. */
|
|
1156
1176
|
async function searchImpl(host, text, query, indexName) {
|
|
1157
1177
|
const plan = requireSearchStage(host, text, indexName, query.controls);
|
|
1158
|
-
return runSearchPipeline(host, plan.stage, query, "search",
|
|
1178
|
+
return runSearchPipeline(host, plan.stage, query, "search", textRunOptions(plan, query));
|
|
1159
1179
|
}
|
|
1160
1180
|
/** Text search with faceted count. */
|
|
1161
1181
|
async function searchWithCountImpl(host, text, query, indexName) {
|
|
1162
1182
|
const plan = requireSearchStage(host, text, indexName, query.controls);
|
|
1163
|
-
return runSearchWithCountPipeline(host, plan.stage, query, "searchWithCount",
|
|
1183
|
+
return runSearchWithCountPipeline(host, plan.stage, query, "searchWithCount", textRunOptions(plan, query));
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* The runner options of a text search: relevance from `textScore` for a
|
|
1187
|
+
* classic `$text` match — none under `$rank: false` (since 0.1.175), which
|
|
1188
|
+
* orders by `_id` instead (an Atlas `$search` included).
|
|
1189
|
+
*/
|
|
1190
|
+
function textRunOptions(plan, query) {
|
|
1191
|
+
if (query.controls?.$rank === false) return { defaultSort: UNRANKED_SORT };
|
|
1192
|
+
return plan.classicText ? {
|
|
1193
|
+
classicText: true,
|
|
1194
|
+
defaultSort: RELEVANCE_SORT
|
|
1195
|
+
} : {};
|
|
1164
1196
|
}
|
|
1165
1197
|
/** Vector search via $vectorSearch aggregation stage. */
|
|
1166
1198
|
async function vectorSearchImpl(host, vector, query, indexName) {
|
|
@@ -1569,7 +1601,7 @@ function buildVectorSearchStage(host, vector, indexName, limit, skip) {
|
|
|
1569
1601
|
};
|
|
1570
1602
|
}
|
|
1571
1603
|
/** Runs a search/vector pipeline and returns results. Shared by search + vectorSearch. */
|
|
1572
|
-
async function runSearchPipeline(host, stage, query, label, { threshold, classicText = false, filterStages } = {}) {
|
|
1604
|
+
async function runSearchPipeline(host, stage, query, label, { threshold, classicText = false, defaultSort, filterStages } = {}) {
|
|
1573
1605
|
const controls = query.controls || {};
|
|
1574
1606
|
const pipeline = [stage];
|
|
1575
1607
|
if (threshold !== void 0) {
|
|
@@ -1579,7 +1611,7 @@ async function runSearchPipeline(host, stage, query, label, { threshold, classic
|
|
|
1579
1611
|
pipeline.push(...filterStages ?? require_mongo_accumulator.mongoFilterStages(query.filter, filterOptionsOf(host)));
|
|
1580
1612
|
const { stages: sorted, cleanup } = require_mongo_accumulator.sortStages(controls);
|
|
1581
1613
|
if (sorted.length > 0) pipeline.push(...sorted);
|
|
1582
|
-
else if (
|
|
1614
|
+
else if (defaultSort) pipeline.push(defaultSort);
|
|
1583
1615
|
if (controls.$skip) pipeline.push({ $skip: controls.$skip });
|
|
1584
1616
|
if (controls.$limit) pipeline.push({ $limit: controls.$limit });
|
|
1585
1617
|
else pipeline.push({ $limit: 1e3 });
|
|
@@ -1601,7 +1633,7 @@ async function runSearchPipeline(host, stage, query, label, { threshold, classic
|
|
|
1601
1633
|
* `count: total` — the same counts `$$SEARCH_META` reports), concurrently
|
|
1602
1634
|
* outside a transaction.
|
|
1603
1635
|
*/
|
|
1604
|
-
async function runSearchWithCountPipeline(host, stage, query, label, { threshold, classicText = false, filterStages } = {}) {
|
|
1636
|
+
async function runSearchWithCountPipeline(host, stage, query, label, { threshold, classicText = false, defaultSort, filterStages } = {}) {
|
|
1605
1637
|
const controls = query.controls || {};
|
|
1606
1638
|
const preStages = [];
|
|
1607
1639
|
if (threshold !== void 0) {
|
|
@@ -1609,7 +1641,7 @@ async function runSearchWithCountPipeline(host, stage, query, label, { threshold
|
|
|
1609
1641
|
preStages.push({ $match: { _score: { $gte: threshold } } });
|
|
1610
1642
|
} else if (classicText) preStages.push({ $addFields: { _score: { $meta: "textScore" } } });
|
|
1611
1643
|
const { stages: dataStages, cleanup } = require_mongo_accumulator.sortStages(controls);
|
|
1612
|
-
if (dataStages.length === 0 &&
|
|
1644
|
+
if (dataStages.length === 0 && defaultSort) dataStages.push(defaultSort);
|
|
1613
1645
|
if (controls.$skip) dataStages.push({ $skip: controls.$skip });
|
|
1614
1646
|
if (controls.$limit) dataStages.push({ $limit: controls.$limit });
|
|
1615
1647
|
if (cleanup) dataStages.push(cleanup);
|
|
@@ -2446,6 +2478,8 @@ var MongoAdapter = class MongoAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
2446
2478
|
result = await this._runInTransactionContext(session, fn);
|
|
2447
2479
|
});
|
|
2448
2480
|
return result;
|
|
2481
|
+
} catch (error) {
|
|
2482
|
+
throw mapTransientTransactionError(error);
|
|
2449
2483
|
} finally {
|
|
2450
2484
|
try {
|
|
2451
2485
|
await session.endSession();
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as buildMongoQuery, c as planStages, f as sortStages, h as queryNodeToExpr, i as buildMongoFilter, l as correlate, m as orNull, n as distinctCountExpr, o as collationOfAdapter, p as exprToMongo, r as REL_FILTER_TEMP_PREFIX, s as mongoFilterStages, t as buildAccumulator, u as hasNullsPlacement } from "./mongo-accumulator-
|
|
1
|
+
import { a as buildMongoQuery, c as planStages, f as sortStages, h as queryNodeToExpr, i as buildMongoFilter, l as correlate, m as orNull, n as distinctCountExpr, o as collationOfAdapter, p as exprToMongo, r as REL_FILTER_TEMP_PREFIX, s as mongoFilterStages, t as buildAccumulator, u as hasNullsPlacement } from "./mongo-accumulator-CFVRBDiw.mjs";
|
|
2
2
|
import { t as dynamicSearchEncryptedMessage } from "./search-messages-mQSpJ4GD.mjs";
|
|
3
|
-
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, andFilters, bucketTimeZoneUnavailable, computeInsights, constraintViolation, containsRelationFilter, createChangeRecorder, createFailureCollector, defaultFulltextIndex, geoIndexNotFoundMessage, getDbFieldOp, getKeyProps, getPath, isAtscriptDbView, isFieldRef, isPlainObject, isViewType, parseDefaultLiteral, queryReadColumns, relationStaticFilter, resolveDesignType, searchIndexNotFoundMessage, searchTermInteger, tableNameOf, translateQueryTree, uniqueKeyTuple, vectorIndexNotFoundMessage } from "@atscript/db";
|
|
3
|
+
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, andFilters, bucketTimeZoneUnavailable, computeInsights, constraintViolation, containsRelationFilter, createChangeRecorder, createFailureCollector, defaultFulltextIndex, geoIndexNotFoundMessage, getDbFieldOp, getKeyProps, getPath, isAtscriptDbView, isFieldRef, isPlainObject, isViewType, parseDefaultLiteral, queryReadColumns, relationStaticFilter, resolveDesignType, searchIndexNotFoundMessage, searchTermInteger, tableNameOf, translateQueryTree, uniqueKeyTuple, unknownWithRelation, vectorIndexNotFoundMessage } from "@atscript/db";
|
|
4
4
|
import { MongoClient, ObjectId } from "mongodb";
|
|
5
5
|
import { resolveAggregateSearch } from "@atscript/db/agg";
|
|
6
6
|
//#region src/lib/path-utils.ts
|
|
@@ -68,6 +68,24 @@ function serverErrorCode(error) {
|
|
|
68
68
|
const code = error.code;
|
|
69
69
|
return typeof code === "number" ? code : void 0;
|
|
70
70
|
}
|
|
71
|
+
/** `WriteConflict`: a write met a concurrent transaction's uncommitted change. */
|
|
72
|
+
const WRITE_CONFLICT = 112;
|
|
73
|
+
/**
|
|
74
|
+
* The retryable `SERIALIZATION_FAILURE` of a driver error that ended a
|
|
75
|
+
* transaction without committing it — one labelled `TransientTransactionError`
|
|
76
|
+
* or `UnknownTransactionCommitResult` (`session.withTransaction` retries
|
|
77
|
+
* those itself for 120 s, then rethrows), or a `WriteConflict` — else `error`
|
|
78
|
+
* as is. The raw driver error is kept as `cause`.
|
|
79
|
+
*/
|
|
80
|
+
function mapTransientTransactionError(error) {
|
|
81
|
+
if (!(error instanceof Error)) return error;
|
|
82
|
+
const labels = error.errorLabels;
|
|
83
|
+
if (!(Array.isArray(labels) && (labels.includes("TransientTransactionError") || labels.includes("UnknownTransactionCommitResult"))) && serverErrorCode(error) !== WRITE_CONFLICT) return error;
|
|
84
|
+
return new DbError("SERIALIZATION_FAILURE", [{
|
|
85
|
+
path: "",
|
|
86
|
+
message: error.message
|
|
87
|
+
}], void 0, { cause: error });
|
|
88
|
+
}
|
|
71
89
|
/** `DuplicateKey` (E11000) and its legacy update form `DuplicateKeyValue` (E11001). */
|
|
72
90
|
function isDuplicateKeyCode(code) {
|
|
73
91
|
return code === 11e3 || code === 11001;
|
|
@@ -530,7 +548,7 @@ function buildViewPipeline(view, variant) {
|
|
|
530
548
|
out = exprToMongo(col.expr, (path) => {
|
|
531
549
|
const c = byPath.get(path);
|
|
532
550
|
return c.expr === void 0 ? { $toDouble: leaf(c) } : computedExpr(c, leaf);
|
|
533
|
-
});
|
|
551
|
+
}, col.viewPath);
|
|
534
552
|
rendered.set(col.viewPath, out);
|
|
535
553
|
}
|
|
536
554
|
return out;
|
|
@@ -766,7 +784,7 @@ async function loadRelationsImpl(host, rows, withRelations, relations, foreignKe
|
|
|
766
784
|
for (const withRel of withRelations) {
|
|
767
785
|
if (withRel.name.includes(".")) continue;
|
|
768
786
|
const relation = relations.get(withRel.name);
|
|
769
|
-
if (!relation) throw
|
|
787
|
+
if (!relation) throw unknownWithRelation(withRel.name);
|
|
770
788
|
const lookup = buildRelationLookup(source, withRel, relation, foreignKeys, tableResolver);
|
|
771
789
|
if (lookup) relMeta.push(lookup);
|
|
772
790
|
}
|
|
@@ -1086,6 +1104,8 @@ const RELEVANCE_SORT = { $sort: {
|
|
|
1086
1104
|
_score: -1,
|
|
1087
1105
|
_id: 1
|
|
1088
1106
|
} };
|
|
1107
|
+
/** The order of an unranked search (`$rank: false`, since 0.1.175): the primary key. */
|
|
1108
|
+
const UNRANKED_SORT = { $sort: { _id: 1 } };
|
|
1089
1109
|
function getSearchIndexesImpl(host) {
|
|
1090
1110
|
const result = [];
|
|
1091
1111
|
const indexes = host.getMongoSearchIndexes();
|
|
@@ -1154,12 +1174,24 @@ function buildAggregateSearchStage(host, controls) {
|
|
|
1154
1174
|
/** Text search via $search aggregation stage. */
|
|
1155
1175
|
async function searchImpl(host, text, query, indexName) {
|
|
1156
1176
|
const plan = requireSearchStage(host, text, indexName, query.controls);
|
|
1157
|
-
return runSearchPipeline(host, plan.stage, query, "search",
|
|
1177
|
+
return runSearchPipeline(host, plan.stage, query, "search", textRunOptions(plan, query));
|
|
1158
1178
|
}
|
|
1159
1179
|
/** Text search with faceted count. */
|
|
1160
1180
|
async function searchWithCountImpl(host, text, query, indexName) {
|
|
1161
1181
|
const plan = requireSearchStage(host, text, indexName, query.controls);
|
|
1162
|
-
return runSearchWithCountPipeline(host, plan.stage, query, "searchWithCount",
|
|
1182
|
+
return runSearchWithCountPipeline(host, plan.stage, query, "searchWithCount", textRunOptions(plan, query));
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* The runner options of a text search: relevance from `textScore` for a
|
|
1186
|
+
* classic `$text` match — none under `$rank: false` (since 0.1.175), which
|
|
1187
|
+
* orders by `_id` instead (an Atlas `$search` included).
|
|
1188
|
+
*/
|
|
1189
|
+
function textRunOptions(plan, query) {
|
|
1190
|
+
if (query.controls?.$rank === false) return { defaultSort: UNRANKED_SORT };
|
|
1191
|
+
return plan.classicText ? {
|
|
1192
|
+
classicText: true,
|
|
1193
|
+
defaultSort: RELEVANCE_SORT
|
|
1194
|
+
} : {};
|
|
1163
1195
|
}
|
|
1164
1196
|
/** Vector search via $vectorSearch aggregation stage. */
|
|
1165
1197
|
async function vectorSearchImpl(host, vector, query, indexName) {
|
|
@@ -1568,7 +1600,7 @@ function buildVectorSearchStage(host, vector, indexName, limit, skip) {
|
|
|
1568
1600
|
};
|
|
1569
1601
|
}
|
|
1570
1602
|
/** Runs a search/vector pipeline and returns results. Shared by search + vectorSearch. */
|
|
1571
|
-
async function runSearchPipeline(host, stage, query, label, { threshold, classicText = false, filterStages } = {}) {
|
|
1603
|
+
async function runSearchPipeline(host, stage, query, label, { threshold, classicText = false, defaultSort, filterStages } = {}) {
|
|
1572
1604
|
const controls = query.controls || {};
|
|
1573
1605
|
const pipeline = [stage];
|
|
1574
1606
|
if (threshold !== void 0) {
|
|
@@ -1578,7 +1610,7 @@ async function runSearchPipeline(host, stage, query, label, { threshold, classic
|
|
|
1578
1610
|
pipeline.push(...filterStages ?? mongoFilterStages(query.filter, filterOptionsOf(host)));
|
|
1579
1611
|
const { stages: sorted, cleanup } = sortStages(controls);
|
|
1580
1612
|
if (sorted.length > 0) pipeline.push(...sorted);
|
|
1581
|
-
else if (
|
|
1613
|
+
else if (defaultSort) pipeline.push(defaultSort);
|
|
1582
1614
|
if (controls.$skip) pipeline.push({ $skip: controls.$skip });
|
|
1583
1615
|
if (controls.$limit) pipeline.push({ $limit: controls.$limit });
|
|
1584
1616
|
else pipeline.push({ $limit: 1e3 });
|
|
@@ -1600,7 +1632,7 @@ async function runSearchPipeline(host, stage, query, label, { threshold, classic
|
|
|
1600
1632
|
* `count: total` — the same counts `$$SEARCH_META` reports), concurrently
|
|
1601
1633
|
* outside a transaction.
|
|
1602
1634
|
*/
|
|
1603
|
-
async function runSearchWithCountPipeline(host, stage, query, label, { threshold, classicText = false, filterStages } = {}) {
|
|
1635
|
+
async function runSearchWithCountPipeline(host, stage, query, label, { threshold, classicText = false, defaultSort, filterStages } = {}) {
|
|
1604
1636
|
const controls = query.controls || {};
|
|
1605
1637
|
const preStages = [];
|
|
1606
1638
|
if (threshold !== void 0) {
|
|
@@ -1608,7 +1640,7 @@ async function runSearchWithCountPipeline(host, stage, query, label, { threshold
|
|
|
1608
1640
|
preStages.push({ $match: { _score: { $gte: threshold } } });
|
|
1609
1641
|
} else if (classicText) preStages.push({ $addFields: { _score: { $meta: "textScore" } } });
|
|
1610
1642
|
const { stages: dataStages, cleanup } = sortStages(controls);
|
|
1611
|
-
if (dataStages.length === 0 &&
|
|
1643
|
+
if (dataStages.length === 0 && defaultSort) dataStages.push(defaultSort);
|
|
1612
1644
|
if (controls.$skip) dataStages.push({ $skip: controls.$skip });
|
|
1613
1645
|
if (controls.$limit) dataStages.push({ $limit: controls.$limit });
|
|
1614
1646
|
if (cleanup) dataStages.push(cleanup);
|
|
@@ -2445,6 +2477,8 @@ var MongoAdapter = class MongoAdapter extends BaseDbAdapter {
|
|
|
2445
2477
|
result = await this._runInTransactionContext(session, fn);
|
|
2446
2478
|
});
|
|
2447
2479
|
return result;
|
|
2480
|
+
} catch (error) {
|
|
2481
|
+
throw mapTransientTransactionError(error);
|
|
2448
2482
|
} finally {
|
|
2449
2483
|
try {
|
|
2450
2484
|
await session.endSession();
|
|
@@ -110,10 +110,11 @@ function queryNodeToExpr(node, pathOf) {
|
|
|
110
110
|
* arithmetic would stay exact past 2^53 where SQL rounds.
|
|
111
111
|
* @since 0.1.147
|
|
112
112
|
*/
|
|
113
|
-
function exprToMongo(node, operand) {
|
|
113
|
+
function exprToMongo(node, operand, path = "$select") {
|
|
114
114
|
if (typeof node === "number") return { $toDouble: node };
|
|
115
115
|
if ("field" in node) return operand(node.field);
|
|
116
|
-
|
|
116
|
+
(0, _atscript_db.assertExprArity)(node, path);
|
|
117
|
+
const args = node.args.map((arg) => exprToMongo(arg, operand, path));
|
|
117
118
|
switch (node.op) {
|
|
118
119
|
case "+": return { $add: args };
|
|
119
120
|
case "-": return { $subtract: args };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DbError, INTEGER_REGEX_OP, andFilters, containsRelationFilter, isFieldRef, isResolvedRelationFilter, walkFilter } from "@atscript/db";
|
|
1
|
+
import { DbError, INTEGER_REGEX_OP, andFilters, assertExprArity, containsRelationFilter, isFieldRef, isResolvedRelationFilter, walkFilter } from "@atscript/db";
|
|
2
2
|
import { BSONRegExp } from "mongodb";
|
|
3
3
|
import { isNullsPlacement } from "@uniqu/core";
|
|
4
4
|
import { assertAggregateFn } from "@atscript/db/agg";
|
|
@@ -110,10 +110,11 @@ function queryNodeToExpr(node, pathOf) {
|
|
|
110
110
|
* arithmetic would stay exact past 2^53 where SQL rounds.
|
|
111
111
|
* @since 0.1.147
|
|
112
112
|
*/
|
|
113
|
-
function exprToMongo(node, operand) {
|
|
113
|
+
function exprToMongo(node, operand, path = "$select") {
|
|
114
114
|
if (typeof node === "number") return { $toDouble: node };
|
|
115
115
|
if ("field" in node) return operand(node.field);
|
|
116
|
-
|
|
116
|
+
assertExprArity(node, path);
|
|
117
|
+
const args = node.args.map((arg) => exprToMongo(arg, operand, path));
|
|
117
118
|
switch (node.op) {
|
|
118
119
|
case "+": return { $add: args };
|
|
119
120
|
case "-": return { $subtract: args };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.175",
|
|
4
4
|
"description": "Mongodb plugin for atscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@atscript/core": "^0.2.
|
|
50
|
-
"@atscript/typescript": "^0.2.
|
|
51
|
-
"@uniqu/core": "^0.2.
|
|
49
|
+
"@atscript/core": "^0.2.11",
|
|
50
|
+
"@atscript/typescript": "^0.2.11",
|
|
51
|
+
"@uniqu/core": "^0.2.2",
|
|
52
52
|
"mongodb": "^6.17.0",
|
|
53
53
|
"mongodb-memory-server-core": "^10.0.0",
|
|
54
|
-
"unplugin-atscript": "^0.2.
|
|
54
|
+
"unplugin-atscript": "^0.2.11"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@atscript/core": "^0.2.
|
|
58
|
-
"@atscript/typescript": "^0.2.
|
|
59
|
-
"@uniqu/core": "^0.2.
|
|
57
|
+
"@atscript/core": "^0.2.11",
|
|
58
|
+
"@atscript/typescript": "^0.2.11",
|
|
59
|
+
"@uniqu/core": "^0.2.2",
|
|
60
60
|
"mongodb": "^6.17.0",
|
|
61
|
-
"@atscript/db": "^0.1.
|
|
61
|
+
"@atscript/db": "^0.1.175"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "vp pack",
|