@mastra/mongodb 1.26.0-alpha.1 → 1.26.0-alpha.2
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/_types/@internal_core@0.1.4/dist/knowledge-compat/index.d.ts +9 -4
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +240 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +240 -30
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts +7 -1
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/dist/storage/domains/knowledge/pages.d.ts +30 -11
- package/dist/storage/domains/knowledge/pages.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { MessageList } from "@mastra/core/agent";
|
|
|
10
10
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
11
11
|
import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
|
|
12
12
|
// package.json
|
|
13
|
-
var version = "1.26.0-alpha.
|
|
13
|
+
var version = "1.26.0-alpha.2";
|
|
14
14
|
// src/vector/filter.ts
|
|
15
15
|
/**
|
|
16
16
|
* Translator for MongoDB filter queries.
|
|
@@ -4874,7 +4874,8 @@ const KNOWLEDGE_PAGES_CORE_FUNCTIONS = [
|
|
|
4874
4874
|
const KNOWLEDGE_PAGES_CORE_NUMBERS = [
|
|
4875
4875
|
"MAX_KNOWLEDGE_MOVE_PAGES",
|
|
4876
4876
|
"MAX_KNOWLEDGE_PAGE_DEPTH",
|
|
4877
|
-
"MAX_KNOWLEDGE_PAGE_LIST_LIMIT"
|
|
4877
|
+
"MAX_KNOWLEDGE_PAGE_LIST_LIMIT",
|
|
4878
|
+
"MAX_KNOWLEDGE_PAGE_LINKS"
|
|
4878
4879
|
];
|
|
4879
4880
|
function resolveKnowledgePagesCore(storageModule) {
|
|
4880
4881
|
const module = typeof storageModule === "object" && storageModule !== null ? storageModule : {};
|
|
@@ -4895,16 +4896,18 @@ function createKnowledgePagesCoreLoader(features, loadStorageModule) {
|
|
|
4895
4896
|
};
|
|
4896
4897
|
}
|
|
4897
4898
|
/**
|
|
4898
|
-
* Keyword-search words: the query split on whitespace, lowercased, deduplicated
|
|
4899
|
-
* least one of them (as a case-insensitive
|
|
4899
|
+
* Keyword-search words: the query split on whitespace, lowercased, deduplicated, keeping the first
|
|
4900
|
+
* {@link KNOWLEDGE_SEARCH_MAX_WORDS}. A hit needs at least one of them (as a case-insensitive
|
|
4901
|
+
* substring); an empty list means the search returns nothing.
|
|
4900
4902
|
*/
|
|
4901
4903
|
function knowledgeSearchWords(query) {
|
|
4902
|
-
return [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))];
|
|
4904
|
+
return [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))].slice(0, 16);
|
|
4903
4905
|
}
|
|
4904
4906
|
/**
|
|
4905
4907
|
* Points one matched search word earns on a page, by the best field it appears in: name, then
|
|
4906
|
-
* description, then body.
|
|
4907
|
-
*
|
|
4908
|
+
* description, then body. A page whose name contains the whole query ranks first; below that, pages
|
|
4909
|
+
* rank by how many query words they match, and these points only break ties between pages that
|
|
4910
|
+
* match the same number of words.
|
|
4908
4911
|
*/
|
|
4909
4912
|
const KNOWLEDGE_SEARCH_WEIGHTS = {
|
|
4910
4913
|
name: 3,
|
|
@@ -4923,11 +4926,13 @@ function knowledgePageKeyProblem(key) {
|
|
|
4923
4926
|
const loadPagesCore = createKnowledgePagesCoreLoader(coreFeatures, () => import("@mastra/core/storage"));
|
|
4924
4927
|
const DEFAULT_LIST_LIMIT = 50;
|
|
4925
4928
|
const MONGO_DUPLICATE_KEY = 11e3;
|
|
4929
|
+
const DEFAULT_LINK_LIMIT = 1e3;
|
|
4926
4930
|
const MONGO_KNOWLEDGE_PAGES_COLLECTIONS = {
|
|
4927
4931
|
pages: "mastra_knowledge_pages",
|
|
4928
4932
|
notes: "mastra_knowledge_notes",
|
|
4929
4933
|
pins: "mastra_knowledge_pins",
|
|
4930
4934
|
activity: "mastra_knowledge_activity",
|
|
4935
|
+
links: "mastra_knowledge_page_links",
|
|
4931
4936
|
state: "mastra_knowledge_access_state"
|
|
4932
4937
|
};
|
|
4933
4938
|
/** Thrown when existing Knowledge collections can't be used as schema 4 without a reset. */
|
|
@@ -5023,10 +5028,17 @@ function toListedPin(row) {
|
|
|
5023
5028
|
pageName: String(row.pageName)
|
|
5024
5029
|
};
|
|
5025
5030
|
}
|
|
5031
|
+
/** IndexNotFound, or NamespaceNotFound when the collection doesn't exist yet. */
|
|
5032
|
+
function isMissingIndex(error) {
|
|
5033
|
+
const code = error?.code;
|
|
5034
|
+
return code === 27 || code === 26;
|
|
5035
|
+
}
|
|
5026
5036
|
function toPin(row) {
|
|
5027
5037
|
return {
|
|
5028
5038
|
id: String(row.id),
|
|
5029
5039
|
pageId: String(row.pageId),
|
|
5040
|
+
kind: row.kind ?? "page",
|
|
5041
|
+
...row.depth == null ? {} : { depth: Number(row.depth) },
|
|
5030
5042
|
audience: [...row.audience ?? []],
|
|
5031
5043
|
createdBy: String(row.createdBy),
|
|
5032
5044
|
createdAt: new Date(row.createdAt),
|
|
@@ -5089,12 +5101,17 @@ var MongoKnowledgePages = class {
|
|
|
5089
5101
|
} }, { upsert: true });
|
|
5090
5102
|
const inspection = await this.inspectSchema();
|
|
5091
5103
|
if (inspection.status === "incompatible-reset-required") throw new MongoKnowledgeResetRequiredError(inspection);
|
|
5092
|
-
const [pages, notes, pins, activity] = await Promise.all([
|
|
5104
|
+
const [pages, notes, pins, activity, links] = await Promise.all([
|
|
5093
5105
|
this.#c("pages"),
|
|
5094
5106
|
this.#c("notes"),
|
|
5095
5107
|
this.#c("pins"),
|
|
5096
|
-
this.#c("activity")
|
|
5108
|
+
this.#c("activity"),
|
|
5109
|
+
this.#c("links")
|
|
5097
5110
|
]);
|
|
5111
|
+
await pins.updateMany({ kind: { $exists: false } }, { $set: { kind: "page" } });
|
|
5112
|
+
await pins.dropIndex("pageId_1").catch((error) => {
|
|
5113
|
+
if (!isMissingIndex(error)) throw error;
|
|
5114
|
+
});
|
|
5098
5115
|
await Promise.all([
|
|
5099
5116
|
pages.createIndex({ id: 1 }, { unique: true }),
|
|
5100
5117
|
pages.createIndex({ address: 1 }, {
|
|
@@ -5134,7 +5151,10 @@ var MongoKnowledgePages = class {
|
|
|
5134
5151
|
notes.createIndex({ pageScopeId: 1 }),
|
|
5135
5152
|
notes.createIndex({ stampScopeIds: 1 }),
|
|
5136
5153
|
pins.createIndex({ id: 1 }, { unique: true }),
|
|
5137
|
-
pins.createIndex({
|
|
5154
|
+
pins.createIndex({
|
|
5155
|
+
pageId: 1,
|
|
5156
|
+
kind: 1
|
|
5157
|
+
}, { unique: true }),
|
|
5138
5158
|
pins.createIndex({ audience: 1 }),
|
|
5139
5159
|
activity.createIndex({ id: 1 }, { unique: true }),
|
|
5140
5160
|
activity.createIndex({
|
|
@@ -5146,12 +5166,19 @@ var MongoKnowledgePages = class {
|
|
|
5146
5166
|
pageId: 1,
|
|
5147
5167
|
createdAt: -1,
|
|
5148
5168
|
id: -1
|
|
5149
|
-
})
|
|
5169
|
+
}),
|
|
5170
|
+
links.createIndex({
|
|
5171
|
+
fromPageId: 1,
|
|
5172
|
+
ref: 1
|
|
5173
|
+
}, { unique: true }),
|
|
5174
|
+
links.createIndex({ toPageId: 1 }),
|
|
5175
|
+
links.createIndex({ ref: 1 })
|
|
5150
5176
|
]);
|
|
5151
5177
|
}
|
|
5152
5178
|
/** Drops exactly the Knowledge collections (never Memory's) and recreates schema 4. */
|
|
5153
5179
|
async reset() {
|
|
5154
5180
|
for (const name of KNOWLEDGE_RESETTABLE_TABLE_NAMES) await this.#drop(name);
|
|
5181
|
+
await this.#drop(MONGO_KNOWLEDGE_PAGES_COLLECTIONS.links);
|
|
5155
5182
|
await this.init();
|
|
5156
5183
|
}
|
|
5157
5184
|
/** The ids of every scope page the read scope can see; `null` means everything. */
|
|
@@ -5544,10 +5571,12 @@ var MongoKnowledgePages = class {
|
|
|
5544
5571
|
async listChildScopes(input) {
|
|
5545
5572
|
const core = await loadPagesCore();
|
|
5546
5573
|
const limit = clampLimit(input.limit, core.MAX_KNOWLEDGE_PAGE_LIST_LIMIT);
|
|
5574
|
+
const readable = input.read ? await this.#readable(input.read) : null;
|
|
5547
5575
|
const filter = {
|
|
5548
5576
|
isScope: true,
|
|
5549
5577
|
parentId: input.parentId,
|
|
5550
|
-
...live
|
|
5578
|
+
...live,
|
|
5579
|
+
...this.#inScopes("id", readable)
|
|
5551
5580
|
};
|
|
5552
5581
|
if (input.cursor) {
|
|
5553
5582
|
const [position, id] = decodeCursor(input.cursor);
|
|
@@ -5929,12 +5958,20 @@ var MongoKnowledgePages = class {
|
|
|
5929
5958
|
} }] } } }], { session });
|
|
5930
5959
|
await this.#refreshMentionScopes([target.id, ...tree.ids], session);
|
|
5931
5960
|
const pins = await this.#c("pins");
|
|
5932
|
-
const
|
|
5961
|
+
const sourcePins = await pins.find({ pageId: source.id }, {
|
|
5933
5962
|
...noProjection,
|
|
5934
5963
|
session
|
|
5935
|
-
});
|
|
5936
|
-
|
|
5937
|
-
await this.#upsertPinAudience(session,
|
|
5964
|
+
}).sort({ kind: 1 }).toArray();
|
|
5965
|
+
for (const sourcePin of sourcePins) {
|
|
5966
|
+
await this.#upsertPinAudience(session, {
|
|
5967
|
+
pageId: target.id,
|
|
5968
|
+
kind: sourcePin.kind ?? "page",
|
|
5969
|
+
depth: sourcePin.depth == null ? null : Number(sourcePin.depth),
|
|
5970
|
+
audience: sourcePin.audience ?? [],
|
|
5971
|
+
createdBy: String(sourcePin.createdBy),
|
|
5972
|
+
now,
|
|
5973
|
+
keepDepth: true
|
|
5974
|
+
});
|
|
5938
5975
|
await pins.deleteOne({ id: sourcePin.id }, { session });
|
|
5939
5976
|
}
|
|
5940
5977
|
await (await this.#c("activity")).updateMany({ pageId: source.id }, { $set: { pageScopeId: target.scopeId } }, { session });
|
|
@@ -6027,6 +6064,23 @@ var MongoKnowledgePages = class {
|
|
|
6027
6064
|
}).limit(limit + 1).toArray();
|
|
6028
6065
|
return this.#noteOutput(rows, limit);
|
|
6029
6066
|
}
|
|
6067
|
+
async countChildScopes(input) {
|
|
6068
|
+
const ids = [...new Set(input.parentIds)];
|
|
6069
|
+
const counts = Object.fromEntries(ids.map((id) => [id, 0]));
|
|
6070
|
+
if (!ids.length) return counts;
|
|
6071
|
+
const readable = await this.#readable(input.read);
|
|
6072
|
+
const rows = await (await this.#c("pages")).aggregate([{ $match: {
|
|
6073
|
+
parentId: { $in: ids },
|
|
6074
|
+
isScope: true,
|
|
6075
|
+
...live,
|
|
6076
|
+
...this.#inScopes("id", readable)
|
|
6077
|
+
} }, { $group: {
|
|
6078
|
+
_id: "$parentId",
|
|
6079
|
+
count: { $sum: 1 }
|
|
6080
|
+
} }]).toArray();
|
|
6081
|
+
for (const row of rows) counts[row._id] = row.count;
|
|
6082
|
+
return counts;
|
|
6083
|
+
}
|
|
6030
6084
|
async countChildPages(input) {
|
|
6031
6085
|
const ids = [...new Set(input.parentIds)];
|
|
6032
6086
|
const counts = Object.fromEntries(ids.map((id) => [id, 0]));
|
|
@@ -6044,6 +6098,117 @@ var MongoKnowledgePages = class {
|
|
|
6044
6098
|
for (const row of rows) counts[row._id] = row.count;
|
|
6045
6099
|
return counts;
|
|
6046
6100
|
}
|
|
6101
|
+
async replacePageBodyLinks(input) {
|
|
6102
|
+
await this.#tx(async (session) => {
|
|
6103
|
+
const links = await this.#c("links");
|
|
6104
|
+
await links.deleteMany({ fromPageId: input.pageId }, { session });
|
|
6105
|
+
if (!input.links.length) return;
|
|
6106
|
+
await links.insertMany(input.links.map((link) => ({
|
|
6107
|
+
fromPageId: input.pageId,
|
|
6108
|
+
ref: link.ref,
|
|
6109
|
+
toPageId: link.toPageId,
|
|
6110
|
+
count: link.count
|
|
6111
|
+
})), { session });
|
|
6112
|
+
});
|
|
6113
|
+
}
|
|
6114
|
+
async listPageBodyLinkSources(input) {
|
|
6115
|
+
const any = [];
|
|
6116
|
+
if (input.refs?.length) any.push({
|
|
6117
|
+
toPageId: null,
|
|
6118
|
+
ref: { $in: input.refs }
|
|
6119
|
+
});
|
|
6120
|
+
if (input.toPageIds?.length) any.push({ toPageId: { $in: input.toPageIds } });
|
|
6121
|
+
if (!any.length) return [];
|
|
6122
|
+
return (await (await this.#c("links")).distinct("fromPageId", { $or: any })).map(String);
|
|
6123
|
+
}
|
|
6124
|
+
/** Resolved links touching `pageIds`, both ends live and readable, notes only through visible notes. */
|
|
6125
|
+
async #visibleLinks(pageIds, read, direction, kinds) {
|
|
6126
|
+
const ids = [...new Set(pageIds)];
|
|
6127
|
+
if (!ids.length) return [];
|
|
6128
|
+
const wanted = new Set(kinds ?? ["body", "note"]);
|
|
6129
|
+
const touching = (from, to) => direction !== "in" && ids.includes(from) || direction !== "out" && !!to && ids.includes(to);
|
|
6130
|
+
const readable = await this.#readable(read);
|
|
6131
|
+
const raw = /* @__PURE__ */ new Map();
|
|
6132
|
+
const add = (fromPageId, toPageId, kind, count) => {
|
|
6133
|
+
if (fromPageId === toPageId) return;
|
|
6134
|
+
const key = `${fromPageId}\u0000${toPageId}\u0000${kind}`;
|
|
6135
|
+
const edge = raw.get(key);
|
|
6136
|
+
if (edge) edge.count += count;
|
|
6137
|
+
else raw.set(key, {
|
|
6138
|
+
fromPageId,
|
|
6139
|
+
toPageId,
|
|
6140
|
+
kind,
|
|
6141
|
+
count
|
|
6142
|
+
});
|
|
6143
|
+
};
|
|
6144
|
+
const side = [];
|
|
6145
|
+
if (direction !== "in") side.push({ fromPageId: { $in: ids } });
|
|
6146
|
+
if (direction !== "out") side.push({ toPageId: { $in: ids } });
|
|
6147
|
+
if (wanted.has("body")) {
|
|
6148
|
+
const rows = await (await this.#c("links")).find({
|
|
6149
|
+
toPageId: { $ne: null },
|
|
6150
|
+
$or: side
|
|
6151
|
+
}, { projection: {
|
|
6152
|
+
_id: 0,
|
|
6153
|
+
fromPageId: 1,
|
|
6154
|
+
toPageId: 1,
|
|
6155
|
+
count: 1
|
|
6156
|
+
} }).toArray();
|
|
6157
|
+
for (const row of rows) if (touching(String(row.fromPageId), String(row.toPageId))) add(String(row.fromPageId), String(row.toPageId), "body", Number(row.count));
|
|
6158
|
+
}
|
|
6159
|
+
if (wanted.has("note")) {
|
|
6160
|
+
const noteSide = [];
|
|
6161
|
+
if (direction !== "in") noteSide.push({ pageId: { $in: ids } });
|
|
6162
|
+
if (direction !== "out") noteSide.push({ mentions: { $in: ids } });
|
|
6163
|
+
const rows = await (await this.#c("notes")).find({
|
|
6164
|
+
...live,
|
|
6165
|
+
...this.#visibleNotes(readable),
|
|
6166
|
+
mentions: {
|
|
6167
|
+
$exists: true,
|
|
6168
|
+
$ne: []
|
|
6169
|
+
},
|
|
6170
|
+
$or: noteSide
|
|
6171
|
+
}, { projection: {
|
|
6172
|
+
_id: 0,
|
|
6173
|
+
pageId: 1,
|
|
6174
|
+
mentions: 1
|
|
6175
|
+
} }).toArray();
|
|
6176
|
+
for (const row of rows) for (const mentioned of new Set(row.mentions ?? [])) if (touching(String(row.pageId), mentioned)) add(String(row.pageId), mentioned, "note", 1);
|
|
6177
|
+
}
|
|
6178
|
+
if (!raw.size) return [];
|
|
6179
|
+
const ends = [...new Set([...raw.values()].flatMap((edge) => [edge.fromPageId, edge.toPageId]))];
|
|
6180
|
+
const visible = new Set((await (await this.#c("pages")).find({
|
|
6181
|
+
id: { $in: ends },
|
|
6182
|
+
...live,
|
|
6183
|
+
...this.#inScopes("scopeId", readable)
|
|
6184
|
+
}, { projection: {
|
|
6185
|
+
_id: 0,
|
|
6186
|
+
id: 1
|
|
6187
|
+
} }).toArray()).map((row) => String(row.id)));
|
|
6188
|
+
return [...raw.values()].filter((edge) => visible.has(edge.fromPageId) && visible.has(edge.toPageId));
|
|
6189
|
+
}
|
|
6190
|
+
async countPageLinks(input) {
|
|
6191
|
+
const linked = new Map(input.pageIds.map((id) => [id, {
|
|
6192
|
+
in: /* @__PURE__ */ new Set(),
|
|
6193
|
+
out: /* @__PURE__ */ new Set()
|
|
6194
|
+
}]));
|
|
6195
|
+
for (const edge of await this.#visibleLinks(input.pageIds, input.read, "both", input.kinds)) {
|
|
6196
|
+
linked.get(edge.fromPageId)?.out.add(edge.toPageId);
|
|
6197
|
+
linked.get(edge.toPageId)?.in.add(edge.fromPageId);
|
|
6198
|
+
}
|
|
6199
|
+
return Object.fromEntries([...linked].map(([id, sets]) => [id, {
|
|
6200
|
+
in: sets.in.size,
|
|
6201
|
+
out: sets.out.size
|
|
6202
|
+
}]));
|
|
6203
|
+
}
|
|
6204
|
+
async listPageLinks(input) {
|
|
6205
|
+
const limit = input.limit ?? DEFAULT_LINK_LIMIT;
|
|
6206
|
+
if (!Number.isInteger(limit) || limit < 1) throw new RangeError("Knowledge link limit must be a positive integer");
|
|
6207
|
+
const core = await loadPagesCore();
|
|
6208
|
+
const kindOrder = (kind) => kind === "body" ? 0 : 1;
|
|
6209
|
+
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
6210
|
+
return (await this.#visibleLinks(input.pageIds, input.read, input.direction ?? "both", input.kinds)).sort((a, b) => compare(a.fromPageId, b.fromPageId) || compare(a.toPageId, b.toPageId) || kindOrder(a.kind) - kindOrder(b.kind)).slice(0, Math.min(limit, core.MAX_KNOWLEDGE_PAGE_LINKS));
|
|
6211
|
+
}
|
|
6047
6212
|
async countNotes(input) {
|
|
6048
6213
|
const ids = [...new Set(input.pageIds)];
|
|
6049
6214
|
const counts = Object.fromEntries(ids.map((id) => [id, 0]));
|
|
@@ -6224,7 +6389,7 @@ var MongoKnowledgePages = class {
|
|
|
6224
6389
|
async removeNote(input) {
|
|
6225
6390
|
return this.#tx(async (session) => {
|
|
6226
6391
|
const note = await this.#requireNote(input.id, session);
|
|
6227
|
-
if (note.deletedAt)
|
|
6392
|
+
if (note.deletedAt) throw new KnowledgeNotFoundError("note", input.id);
|
|
6228
6393
|
const now = /* @__PURE__ */ new Date();
|
|
6229
6394
|
const updated = await (await this.#c("notes")).findOneAndUpdate({ id: input.id }, {
|
|
6230
6395
|
$set: {
|
|
@@ -6478,15 +6643,24 @@ var MongoKnowledgePages = class {
|
|
|
6478
6643
|
"activity",
|
|
6479
6644
|
"pins",
|
|
6480
6645
|
"notes",
|
|
6646
|
+
"links",
|
|
6481
6647
|
"pages"
|
|
6482
6648
|
]) await (await this.#c(name)).deleteMany({}, { session });
|
|
6483
6649
|
});
|
|
6484
6650
|
}
|
|
6485
6651
|
async addPinAudience(input) {
|
|
6652
|
+
const kind = input.kind ?? "page";
|
|
6486
6653
|
return this.#tx(async (session) => {
|
|
6487
6654
|
const page = await this.#requireLivePage(input.pageId, session);
|
|
6488
6655
|
const now = /* @__PURE__ */ new Date();
|
|
6489
|
-
const { pin, changed } = await this.#upsertPinAudience(session,
|
|
6656
|
+
const { pin, changed } = await this.#upsertPinAudience(session, {
|
|
6657
|
+
pageId: page.id,
|
|
6658
|
+
kind,
|
|
6659
|
+
depth: kind === "list" ? input.depth ?? 1 : null,
|
|
6660
|
+
audience: input.audience,
|
|
6661
|
+
createdBy: input.createdBy,
|
|
6662
|
+
now
|
|
6663
|
+
});
|
|
6490
6664
|
if (changed) await this.#log(session, {
|
|
6491
6665
|
action: "pin-added",
|
|
6492
6666
|
scopeId: page.scopeId,
|
|
@@ -6497,9 +6671,14 @@ var MongoKnowledgePages = class {
|
|
|
6497
6671
|
return pin;
|
|
6498
6672
|
});
|
|
6499
6673
|
}
|
|
6500
|
-
|
|
6674
|
+
/** `keepDepth` (merges) leaves an existing pin's depth as it is instead of setting `depth`. */
|
|
6675
|
+
async #upsertPinAudience(session, input) {
|
|
6676
|
+
const { pageId, kind, audience, now } = input;
|
|
6501
6677
|
const pins = await this.#c("pins");
|
|
6502
|
-
const existing = await pins.findOne({
|
|
6678
|
+
const existing = await pins.findOne({
|
|
6679
|
+
pageId,
|
|
6680
|
+
kind
|
|
6681
|
+
}, {
|
|
6503
6682
|
...noProjection,
|
|
6504
6683
|
session
|
|
6505
6684
|
});
|
|
@@ -6507,8 +6686,10 @@ var MongoKnowledgePages = class {
|
|
|
6507
6686
|
const doc = {
|
|
6508
6687
|
id: createKnowledgeUlid(),
|
|
6509
6688
|
pageId,
|
|
6689
|
+
kind,
|
|
6690
|
+
...input.depth === null ? {} : { depth: input.depth },
|
|
6510
6691
|
audience: [...new Set(audience)],
|
|
6511
|
-
createdBy,
|
|
6692
|
+
createdBy: input.createdBy,
|
|
6512
6693
|
createdAt: now,
|
|
6513
6694
|
updatedAt: now
|
|
6514
6695
|
};
|
|
@@ -6525,13 +6706,22 @@ var MongoKnowledgePages = class {
|
|
|
6525
6706
|
}
|
|
6526
6707
|
const current = existing.audience ?? [];
|
|
6527
6708
|
const merged = [.../* @__PURE__ */ new Set([...current, ...audience])];
|
|
6528
|
-
|
|
6709
|
+
const currentDepth = existing.depth == null ? null : Number(existing.depth);
|
|
6710
|
+
const depth = input.keepDepth ? currentDepth : input.depth;
|
|
6711
|
+
if (merged.length === current.length && depth === currentDepth) return {
|
|
6529
6712
|
pin: toPin(existing),
|
|
6530
6713
|
changed: false
|
|
6531
6714
|
};
|
|
6532
6715
|
return {
|
|
6533
|
-
pin: toPin(await pins.findOneAndUpdate({ id: existing.id },
|
|
6716
|
+
pin: toPin(await pins.findOneAndUpdate({ id: existing.id }, depth === null ? {
|
|
6717
|
+
$set: {
|
|
6718
|
+
audience: merged,
|
|
6719
|
+
updatedAt: now
|
|
6720
|
+
},
|
|
6721
|
+
$unset: { depth: "" }
|
|
6722
|
+
} : { $set: {
|
|
6534
6723
|
audience: merged,
|
|
6724
|
+
depth,
|
|
6535
6725
|
updatedAt: now
|
|
6536
6726
|
} }, {
|
|
6537
6727
|
returnDocument: "after",
|
|
@@ -6544,7 +6734,10 @@ var MongoKnowledgePages = class {
|
|
|
6544
6734
|
async removePinAudience(input) {
|
|
6545
6735
|
return this.#tx(async (session) => {
|
|
6546
6736
|
const pins = await this.#c("pins");
|
|
6547
|
-
const existing = await pins.findOne({
|
|
6737
|
+
const existing = await pins.findOne({
|
|
6738
|
+
pageId: input.pageId,
|
|
6739
|
+
kind: input.kind ?? "page"
|
|
6740
|
+
}, {
|
|
6548
6741
|
...noProjection,
|
|
6549
6742
|
session
|
|
6550
6743
|
});
|
|
@@ -6604,10 +6797,11 @@ var MongoKnowledgePages = class {
|
|
|
6604
6797
|
const ids = await this.#readable(input.read);
|
|
6605
6798
|
const match = {};
|
|
6606
6799
|
if (input.audience !== "all") match.audience = { $in: input.audience };
|
|
6607
|
-
|
|
6608
|
-
if (input.pageIds) pageId
|
|
6609
|
-
|
|
6610
|
-
if (
|
|
6800
|
+
if (input.kind) match.kind = input.kind;
|
|
6801
|
+
if (input.pageIds) match.pageId = { $in: input.pageIds };
|
|
6802
|
+
const pageOnly = [];
|
|
6803
|
+
if (input.excludePageIds?.length) pageOnly.push({ $or: [{ kind: { $ne: "page" } }, { pageId: { $nin: input.excludePageIds } }] });
|
|
6804
|
+
if (input.withBody) pageOnly.push({ $or: [{ kind: { $ne: "page" } }, { "page.body": { $regex: "\\S" } }] });
|
|
6611
6805
|
const pins = await this.#c("pins");
|
|
6612
6806
|
const base = [
|
|
6613
6807
|
{ $match: match },
|
|
@@ -6620,7 +6814,7 @@ var MongoKnowledgePages = class {
|
|
|
6620
6814
|
{ $match: {
|
|
6621
6815
|
"page.deletedAt": { $exists: false },
|
|
6622
6816
|
...ids === null ? {} : { "page.scopeId": { $in: ids } },
|
|
6623
|
-
...
|
|
6817
|
+
...pageOnly.length ? { $and: pageOnly } : {}
|
|
6624
6818
|
} }
|
|
6625
6819
|
];
|
|
6626
6820
|
const pageMatch = [];
|
|
@@ -6686,7 +6880,8 @@ var KnowledgeMongoDB = class extends KnowledgeStorage {
|
|
|
6686
6880
|
...super.getCapabilities(),
|
|
6687
6881
|
schemaVersion: 4,
|
|
6688
6882
|
supportsSchemaInspection: true,
|
|
6689
|
-
supportsExplicitReset: true
|
|
6883
|
+
supportsExplicitReset: true,
|
|
6884
|
+
supportsPinKinds: true
|
|
6690
6885
|
};
|
|
6691
6886
|
}
|
|
6692
6887
|
async init() {
|
|
@@ -6716,6 +6911,9 @@ var KnowledgeMongoDB = class extends KnowledgeStorage {
|
|
|
6716
6911
|
listChildScopes(input) {
|
|
6717
6912
|
return this.#pages.listChildScopes(input);
|
|
6718
6913
|
}
|
|
6914
|
+
countChildScopes(input) {
|
|
6915
|
+
return this.#pages.countChildScopes(input);
|
|
6916
|
+
}
|
|
6719
6917
|
getPages(input) {
|
|
6720
6918
|
return this.#pages.getPages(input);
|
|
6721
6919
|
}
|
|
@@ -6755,6 +6953,18 @@ var KnowledgeMongoDB = class extends KnowledgeStorage {
|
|
|
6755
6953
|
listNotes(input) {
|
|
6756
6954
|
return this.#pages.listNotes(input);
|
|
6757
6955
|
}
|
|
6956
|
+
replacePageBodyLinks(input) {
|
|
6957
|
+
return this.#pages.replacePageBodyLinks(input);
|
|
6958
|
+
}
|
|
6959
|
+
listPageBodyLinkSources(input) {
|
|
6960
|
+
return this.#pages.listPageBodyLinkSources(input);
|
|
6961
|
+
}
|
|
6962
|
+
countPageLinks(input) {
|
|
6963
|
+
return this.#pages.countPageLinks(input);
|
|
6964
|
+
}
|
|
6965
|
+
listPageLinks(input) {
|
|
6966
|
+
return this.#pages.listPageLinks(input);
|
|
6967
|
+
}
|
|
6758
6968
|
countChildPages(input) {
|
|
6759
6969
|
return this.#pages.countChildPages(input);
|
|
6760
6970
|
}
|