@procedures/mongo 0.0.0-stage → 0.1.0
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +1322 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/connection.d.ts +93 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +147 -0
- package/dist/connection.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +20 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +58 -0
- package/dist/module.js.map +1 -0
- package/dist/procedures/collections.create.d.ts +20 -0
- package/dist/procedures/collections.create.d.ts.map +1 -0
- package/dist/procedures/collections.create.js +43 -0
- package/dist/procedures/collections.create.js.map +1 -0
- package/dist/procedures/collections.drop.d.ts +19 -0
- package/dist/procedures/collections.drop.d.ts.map +1 -0
- package/dist/procedures/collections.drop.js +36 -0
- package/dist/procedures/collections.drop.js.map +1 -0
- package/dist/procedures/collections.list.d.ts +16 -0
- package/dist/procedures/collections.list.d.ts.map +1 -0
- package/dist/procedures/collections.list.js +31 -0
- package/dist/procedures/collections.list.js.map +1 -0
- package/dist/procedures/collections.stats.d.ts +15 -0
- package/dist/procedures/collections.stats.d.ts.map +1 -0
- package/dist/procedures/collections.stats.js +38 -0
- package/dist/procedures/collections.stats.js.map +1 -0
- package/dist/procedures/database.info.d.ts +15 -0
- package/dist/procedures/database.info.d.ts.map +1 -0
- package/dist/procedures/database.info.js +38 -0
- package/dist/procedures/database.info.js.map +1 -0
- package/dist/procedures/database.ping.d.ts +17 -0
- package/dist/procedures/database.ping.d.ts.map +1 -0
- package/dist/procedures/database.ping.js +31 -0
- package/dist/procedures/database.ping.js.map +1 -0
- package/dist/procedures/documents.aggregate.d.ts +19 -0
- package/dist/procedures/documents.aggregate.d.ts.map +1 -0
- package/dist/procedures/documents.aggregate.js +39 -0
- package/dist/procedures/documents.aggregate.js.map +1 -0
- package/dist/procedures/documents.count.d.ts +18 -0
- package/dist/procedures/documents.count.d.ts.map +1 -0
- package/dist/procedures/documents.count.js +29 -0
- package/dist/procedures/documents.count.js.map +1 -0
- package/dist/procedures/documents.delete.d.ts +17 -0
- package/dist/procedures/documents.delete.d.ts.map +1 -0
- package/dist/procedures/documents.delete.js +31 -0
- package/dist/procedures/documents.delete.js.map +1 -0
- package/dist/procedures/documents.find.d.ts +23 -0
- package/dist/procedures/documents.find.d.ts.map +1 -0
- package/dist/procedures/documents.find.js +103 -0
- package/dist/procedures/documents.find.js.map +1 -0
- package/dist/procedures/documents.get.d.ts +20 -0
- package/dist/procedures/documents.get.d.ts.map +1 -0
- package/dist/procedures/documents.get.js +54 -0
- package/dist/procedures/documents.get.js.map +1 -0
- package/dist/procedures/documents.insert.d.ts +21 -0
- package/dist/procedures/documents.insert.d.ts.map +1 -0
- package/dist/procedures/documents.insert.js +55 -0
- package/dist/procedures/documents.insert.js.map +1 -0
- package/dist/procedures/documents.update.d.ts +26 -0
- package/dist/procedures/documents.update.d.ts.map +1 -0
- package/dist/procedures/documents.update.js +61 -0
- package/dist/procedures/documents.update.js.map +1 -0
- package/dist/procedures/index.d.ts +21 -0
- package/dist/procedures/index.d.ts.map +1 -0
- package/dist/procedures/index.js +26 -0
- package/dist/procedures/index.js.map +1 -0
- package/dist/procedures/indexes.create.d.ts +20 -0
- package/dist/procedures/indexes.create.d.ts.map +1 -0
- package/dist/procedures/indexes.create.js +44 -0
- package/dist/procedures/indexes.create.js.map +1 -0
- package/dist/procedures/indexes.drop.d.ts +17 -0
- package/dist/procedures/indexes.drop.d.ts.map +1 -0
- package/dist/procedures/indexes.drop.js +30 -0
- package/dist/procedures/indexes.drop.js.map +1 -0
- package/dist/procedures/indexes.list.d.ts +17 -0
- package/dist/procedures/indexes.list.d.ts.map +1 -0
- package/dist/procedures/indexes.list.js +40 -0
- package/dist/procedures/indexes.list.js.map +1 -0
- package/dist/procedures/input-schemas.d.ts +45 -0
- package/dist/procedures/input-schemas.d.ts.map +1 -0
- package/dist/procedures/input-schemas.js +52 -0
- package/dist/procedures/input-schemas.js.map +1 -0
- package/dist/procedures/schema.d.ts +2 -0
- package/dist/procedures/schema.d.ts.map +1 -0
- package/dist/procedures/schema.js +2 -0
- package/dist/procedures/schema.js.map +1 -0
- package/dist/procedures/target.d.ts +44 -0
- package/dist/procedures/target.d.ts.map +1 -0
- package/dist/procedures/target.js +98 -0
- package/dist/procedures/target.js.map +1 -0
- package/dist/procedures.types.d.ts +129 -0
- package/dist/procedures.types.d.ts.map +1 -0
- package/dist/procedures.types.js +24 -0
- package/dist/procedures.types.js.map +1 -0
- package/dist/register.d.ts +8 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +14 -0
- package/dist/register.js.map +1 -0
- package/dist/scope.d.ts +33 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +52 -0
- package/dist/scope.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +5 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/mongo-storage.d.ts +50 -0
- package/dist/storage/mongo-storage.d.ts.map +1 -0
- package/dist/storage/mongo-storage.js +109 -0
- package/dist/storage/mongo-storage.js.map +1 -0
- package/dist/types.d.ts +239 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/package.json +85 -3
- package/src/connection.ts +198 -0
- package/src/index.ts +159 -0
- package/src/module.ts +62 -0
- package/src/procedures/collections.create.ts +69 -0
- package/src/procedures/collections.drop.ts +62 -0
- package/src/procedures/collections.list.ts +53 -0
- package/src/procedures/collections.stats.ts +57 -0
- package/src/procedures/database.info.ts +58 -0
- package/src/procedures/database.ping.ts +54 -0
- package/src/procedures/documents.aggregate.ts +68 -0
- package/src/procedures/documents.count.ts +52 -0
- package/src/procedures/documents.delete.ts +54 -0
- package/src/procedures/documents.find.ts +147 -0
- package/src/procedures/documents.get.ts +98 -0
- package/src/procedures/documents.insert.ts +83 -0
- package/src/procedures/documents.update.ts +93 -0
- package/src/procedures/index.ts +30 -0
- package/src/procedures/indexes.create.ts +70 -0
- package/src/procedures/indexes.drop.ts +53 -0
- package/src/procedures/indexes.list.ts +64 -0
- package/src/procedures/input-schemas.ts +63 -0
- package/src/procedures/schema.ts +1 -0
- package/src/procedures/target.ts +123 -0
- package/src/procedures.types.ts +162 -0
- package/src/register.ts +17 -0
- package/src/scope.ts +69 -0
- package/src/storage/index.ts +6 -0
- package/src/storage/mongo-storage.ts +151 -0
- package/src/types.ts +337 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.update.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.update.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmB,KAAK,SAAS,EAAqC,MAAM,oBAAoB,CAAC;AAIxG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAA2C,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAGxF,oFAAoF;AACpF,UAAU,WAAY,SAAQ,WAAW;IACvC,wBAAwB;IACxB,MAAM,EAAE,cAAc,CAAC;IACvB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,YAAY;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AAsCD,eAAO,MAAM,eAAe,EAAE,SAAS,CACrC,WAAW,EACX,YAAY,EACZ;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAsBf,CAAC;AAEX,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.update
|
|
3
|
+
* Update documents matching a filter
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { described, documentObject, scopeFields, targetFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { parseTarget, targetFilter, upsertFilter } from "./target.js";
|
|
10
|
+
function parseUpdateInput(data) {
|
|
11
|
+
const procedure = "mongo.documents.update";
|
|
12
|
+
const { target, raw } = parseTarget(procedure, data, ["update", "upsert"]);
|
|
13
|
+
const update = raw["update"];
|
|
14
|
+
if (typeof update !== "object" || update === null) {
|
|
15
|
+
throw new Error(`${procedure}: update must be an object (or a pipeline array)`);
|
|
16
|
+
}
|
|
17
|
+
const result = { ...target, update: update };
|
|
18
|
+
const upsert = raw["upsert"];
|
|
19
|
+
if (upsert !== undefined) {
|
|
20
|
+
if (typeof upsert !== "boolean")
|
|
21
|
+
throw new Error(`${procedure}: upsert must be a boolean`);
|
|
22
|
+
result.upsert = upsert;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
// Schemas
|
|
27
|
+
const updateInputSchema = described(parseUpdateInput, z.object({
|
|
28
|
+
...scopeFields(),
|
|
29
|
+
...targetFields(),
|
|
30
|
+
update: documentObject().describe("The update operations, for example { $set: { status: \"done\" } }"),
|
|
31
|
+
upsert: z.boolean().optional().describe("Insert a document when none matches"),
|
|
32
|
+
}));
|
|
33
|
+
const updateOutputSchema = zodAdapter(z.looseObject({
|
|
34
|
+
acknowledged: z.boolean().describe("True when the server confirmed the write"),
|
|
35
|
+
matchedCount: z.number().describe("The number of documents that matched"),
|
|
36
|
+
modifiedCount: z.number().describe("The number of documents that changed"),
|
|
37
|
+
upsertedId: z.string().nullable().describe("The id of the new document of an upsert, as text, or null"),
|
|
38
|
+
upsertedCount: z.number().describe("The number of documents that an upsert made"),
|
|
39
|
+
}));
|
|
40
|
+
export const updateProcedure = createProcedure()
|
|
41
|
+
.path(["mongo", "documents", "update"])
|
|
42
|
+
.input(updateInputSchema)
|
|
43
|
+
.output(updateOutputSchema)
|
|
44
|
+
.meta({ description: "Update documents matching a filter" })
|
|
45
|
+
.handler(async (input, ctx) => {
|
|
46
|
+
const { collection } = await collectionFor(input, ctx);
|
|
47
|
+
const upsert = input.upsert ?? false;
|
|
48
|
+
const filter = upsert ? await upsertFilter(collection, input) : targetFilter(input);
|
|
49
|
+
const result = input.multi
|
|
50
|
+
? await collection.updateMany(filter, input.update, { upsert })
|
|
51
|
+
: await collection.updateOne(filter, input.update, { upsert });
|
|
52
|
+
return {
|
|
53
|
+
acknowledged: result.acknowledged,
|
|
54
|
+
matchedCount: result.matchedCount,
|
|
55
|
+
modifiedCount: result.modifiedCount,
|
|
56
|
+
upsertedId: result.upsertedId ? String(result.upsertedId) : null,
|
|
57
|
+
upsertedCount: result.upsertedCount,
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
.build();
|
|
61
|
+
//# sourceMappingURL=documents.update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.update.js","sourceRoot":"","sources":["../../src/procedures/documents.update.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAyC,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAmBxF,SAAS,gBAAgB,CAAC,IAAa;IACrC,MAAM,SAAS,GAAG,wBAAwB,CAA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AAM,CAAC,aAAa;QACnC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;QAChE,aAAa,EAAE,MAAM,CAAC,aAAa;KACpC,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure Barrel Export
|
|
3
|
+
*/
|
|
4
|
+
export { pingProcedure } from "./database.ping.js";
|
|
5
|
+
export { infoProcedure } from "./database.info.js";
|
|
6
|
+
export { listProcedure } from "./collections.list.js";
|
|
7
|
+
export { createCollectionProcedure } from "./collections.create.js";
|
|
8
|
+
export { dropProcedure } from "./collections.drop.js";
|
|
9
|
+
export { statsProcedure } from "./collections.stats.js";
|
|
10
|
+
export { findProcedure } from "./documents.find.js";
|
|
11
|
+
export { getProcedure } from "./documents.get.js";
|
|
12
|
+
export { insertProcedure } from "./documents.insert.js";
|
|
13
|
+
export { updateProcedure } from "./documents.update.js";
|
|
14
|
+
export { deleteProcedure } from "./documents.delete.js";
|
|
15
|
+
export { countProcedure } from "./documents.count.js";
|
|
16
|
+
export { aggregateProcedure } from "./documents.aggregate.js";
|
|
17
|
+
export { listIndexesProcedure } from "./indexes.list.js";
|
|
18
|
+
export { createIndexProcedure } from "./indexes.create.js";
|
|
19
|
+
export { dropIndexProcedure } from "./indexes.drop.js";
|
|
20
|
+
export { schema } from "./schema.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/procedures/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure Barrel Export
|
|
3
|
+
*/
|
|
4
|
+
// Database procedures
|
|
5
|
+
export { pingProcedure } from "./database.ping.js";
|
|
6
|
+
export { infoProcedure } from "./database.info.js";
|
|
7
|
+
// Collection procedures
|
|
8
|
+
export { listProcedure } from "./collections.list.js";
|
|
9
|
+
export { createCollectionProcedure } from "./collections.create.js";
|
|
10
|
+
export { dropProcedure } from "./collections.drop.js";
|
|
11
|
+
export { statsProcedure } from "./collections.stats.js";
|
|
12
|
+
// Document procedures
|
|
13
|
+
export { findProcedure } from "./documents.find.js";
|
|
14
|
+
export { getProcedure } from "./documents.get.js";
|
|
15
|
+
export { insertProcedure } from "./documents.insert.js";
|
|
16
|
+
export { updateProcedure } from "./documents.update.js";
|
|
17
|
+
export { deleteProcedure } from "./documents.delete.js";
|
|
18
|
+
export { countProcedure } from "./documents.count.js";
|
|
19
|
+
export { aggregateProcedure } from "./documents.aggregate.js";
|
|
20
|
+
// Index procedures
|
|
21
|
+
export { listIndexesProcedure } from "./indexes.list.js";
|
|
22
|
+
export { createIndexProcedure } from "./indexes.create.js";
|
|
23
|
+
export { dropIndexProcedure } from "./indexes.drop.js";
|
|
24
|
+
// Schema helper
|
|
25
|
+
export { schema } from "./schema.js";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/procedures/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sBAAsB;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,wBAAwB;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,sBAAsB;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,mBAAmB;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.indexes.create
|
|
3
|
+
* Create an index on a collection
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type IndexSpec, type IndexOptions } from "../types.js";
|
|
8
|
+
interface CreateIndexInput extends ScopeInput {
|
|
9
|
+
keys: IndexSpec;
|
|
10
|
+
options?: IndexOptions | undefined;
|
|
11
|
+
}
|
|
12
|
+
interface CreateIndexOutput {
|
|
13
|
+
acknowledged: boolean;
|
|
14
|
+
indexName: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const createIndexProcedure: Procedure<CreateIndexInput, CreateIndexOutput, {
|
|
17
|
+
description: string;
|
|
18
|
+
}>;
|
|
19
|
+
export type { CreateIndexInput, CreateIndexOutput };
|
|
20
|
+
//# sourceMappingURL=indexes.create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.create.d.ts","sourceRoot":"","sources":["../../src/procedures/indexes.create.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAI7D,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhE,UAAU,gBAAiB,SAAQ,UAAU;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACpC;AAED,UAAU,iBAAiB;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AA0BD,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAC1C,gBAAgB,EAChB,iBAAiB,EACjB;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAiBf,CAAC;AAEX,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.indexes.create
|
|
3
|
+
* Create an index on a collection
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const createIndexInputSchema = zodAdapter(z.object({
|
|
12
|
+
...scopeFields(),
|
|
13
|
+
keys: z
|
|
14
|
+
.record(z.string(), z.union([z.literal(1), z.literal(-1), z.literal("text"), z.literal("2dsphere")]))
|
|
15
|
+
.describe('The fields of the index and their order: 1, -1, "text" or "2dsphere"'),
|
|
16
|
+
options: z
|
|
17
|
+
.looseObject({
|
|
18
|
+
name: z.string().optional().describe("The name of the index"),
|
|
19
|
+
unique: z.boolean().optional().describe("A unique index"),
|
|
20
|
+
sparse: z.boolean().optional().describe("A sparse index"),
|
|
21
|
+
})
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("The options of the index"),
|
|
24
|
+
}));
|
|
25
|
+
const createIndexOutputSchema = zodAdapter(z.looseObject({
|
|
26
|
+
acknowledged: z.boolean().describe("True when the server confirmed the write"),
|
|
27
|
+
indexName: z.string().describe("The name of the new index"),
|
|
28
|
+
}));
|
|
29
|
+
export const createIndexProcedure = createProcedure()
|
|
30
|
+
.path(["mongo", "indexes", "create"])
|
|
31
|
+
.input(createIndexInputSchema)
|
|
32
|
+
.output(createIndexOutputSchema)
|
|
33
|
+
.meta({ description: "Create an index on a collection" })
|
|
34
|
+
.handler(async (input, ctx) => {
|
|
35
|
+
const { collection } = await collectionFor(input, ctx);
|
|
36
|
+
// The schema leaves out an option that the input does not give: no option is undefined at run time
|
|
37
|
+
const indexName = await collection.createIndex(input.keys, input.options);
|
|
38
|
+
return {
|
|
39
|
+
acknowledged: true,
|
|
40
|
+
indexName,
|
|
41
|
+
};
|
|
42
|
+
})
|
|
43
|
+
.build();
|
|
44
|
+
//# sourceMappingURL=indexes.create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.create.js","sourceRoot":"","sources":["../../src/procedures/indexes.create.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAyC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAqC,MAAM,aAAa,CAAC;AAahE,UAAU;AACV,MAAM,sBAAsB,GAAG,UAAU,CACvC,CAAC,CAAC,MAAM,CAAC;IACP,GAAG,WAAW,EAAE;IAChB,IAAI,EAAE,CAAC;SACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;SACpG,QAAQ,CAAC,sEAAsE,CAAC;IACnF,OAAO,EAAE,CAAC;SACP,WAAW,CAAC;QACX,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ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
|
3
|
+
* Drop an index from a collection
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
interface DropIndexInput extends ScopeInput {
|
|
8
|
+
indexName: string;
|
|
9
|
+
}
|
|
10
|
+
interface DropIndexOutput {
|
|
11
|
+
acknowledged: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const dropIndexProcedure: Procedure<DropIndexInput, DropIndexOutput, {
|
|
14
|
+
description: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type { DropIndexInput, DropIndexOutput };
|
|
17
|
+
//# sourceMappingURL=indexes.drop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.drop.d.ts","sourceRoot":"","sources":["../../src/procedures/indexes.drop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAK7D,UAAU,cAAe,SAAQ,UAAU;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,eAAe;IACvB,YAAY,EAAE,OAAO,CAAC;CACvB;AAeD,eAAO,MAAM,kBAAkB,EAAE,SAAS,CACxC,cAAc,EACd,eAAe,EACf;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAef,CAAC;AAEX,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.indexes.drop
|
|
3
|
+
* Drop an index from a collection
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// Schemas
|
|
10
|
+
const dropIndexInputSchema = zodAdapter(z.object({
|
|
11
|
+
...scopeFields(),
|
|
12
|
+
indexName: z.string().min(1).describe("The name of the index to drop"),
|
|
13
|
+
}));
|
|
14
|
+
const dropIndexOutputSchema = zodAdapter(z.looseObject({
|
|
15
|
+
acknowledged: z.boolean().describe("True when the server confirmed the write"),
|
|
16
|
+
}));
|
|
17
|
+
export const dropIndexProcedure = createProcedure()
|
|
18
|
+
.path(["mongo", "indexes", "drop"])
|
|
19
|
+
.input(dropIndexInputSchema)
|
|
20
|
+
.output(dropIndexOutputSchema)
|
|
21
|
+
.meta({ description: "Drop an index from a collection" })
|
|
22
|
+
.handler(async (input, ctx) => {
|
|
23
|
+
const { collection } = await collectionFor(input, ctx);
|
|
24
|
+
await collection.dropIndex(input.indexName);
|
|
25
|
+
return {
|
|
26
|
+
acknowledged: true,
|
|
27
|
+
};
|
|
28
|
+
})
|
|
29
|
+
.build();
|
|
30
|
+
//# sourceMappingURL=indexes.drop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.drop.js","sourceRoot":"","sources":["../../src/procedures/indexes.drop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAyC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,UAAU;AACV,MAAM,oBAAoB,GAAG,UAAU,CACrC,CAAC,CAAC,MAAM,CAAC;IACP,GAAG,WAAW,EAAE;IAChB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,+BAA+B,CAAC;CACvE,CAAC,CACH,CAAC;AACF,MAAM,qBAAqB,GAAG,UAAU,CACtC,CAAC,CAAC,WAAW,CAAC;IACZ,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;CAC/E,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAI3B,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;KAClC,KAAK,CAAC,oBAAoB,CAAC;KAC3B,MAAM,CAAC,qBAAqB,CAAC;KAC7B,IAAI,CAAC,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;KACxD,OAAO,CAAC,KAAK,EAAE,KAAqB,EAAE,GAAqB,EAAE,EAAE;IAC9D,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEvD,MAAM,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE5C,OAAO;QACL,YAAY,EAAE,IAAI;KACnB,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.indexes.list
|
|
3
|
+
* List indexes on a collection
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type IndexInfo } from "../types.js";
|
|
8
|
+
/** The input: only the scope fields. */
|
|
9
|
+
type ListIndexesInput = ScopeInput;
|
|
10
|
+
interface ListIndexesOutput {
|
|
11
|
+
indexes: IndexInfo[];
|
|
12
|
+
}
|
|
13
|
+
export declare const listIndexesProcedure: Procedure<ListIndexesInput, ListIndexesOutput, {
|
|
14
|
+
description: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type { ListIndexesInput, ListIndexesOutput };
|
|
17
|
+
//# sourceMappingURL=indexes.list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.list.d.ts","sourceRoot":"","sources":["../../src/procedures/indexes.list.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,wCAAwC;AACxC,KAAK,gBAAgB,GAAG,UAAU,CAAC;AAEnC,UAAU,iBAAiB;IACzB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAqBD,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAC1C,gBAAgB,EAChB,iBAAiB,EACjB;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAoBf,CAAC;AAEX,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.indexes.list
|
|
3
|
+
* List indexes on a collection
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const listIndexesInputSchema = zodAdapter(z.object({ ...scopeFields() }));
|
|
12
|
+
const listIndexesOutputSchema = zodAdapter(z.looseObject({
|
|
13
|
+
indexes: z
|
|
14
|
+
.array(z.looseObject({
|
|
15
|
+
name: z.string().describe("The index name"),
|
|
16
|
+
key: z.record(z.string(), z.union([z.number(), z.string()])).describe("The fields of the index and their kind (1, -1, \"text\", \"hashed\")"),
|
|
17
|
+
unique: z.boolean().optional().describe("True for a unique index"),
|
|
18
|
+
sparse: z.boolean().optional().describe("True for a sparse index"),
|
|
19
|
+
}))
|
|
20
|
+
.describe("The indexes of the collection"),
|
|
21
|
+
}));
|
|
22
|
+
export const listIndexesProcedure = createProcedure()
|
|
23
|
+
.path(["mongo", "indexes", "list"])
|
|
24
|
+
.input(listIndexesInputSchema)
|
|
25
|
+
.output(listIndexesOutputSchema)
|
|
26
|
+
.meta({ description: "List indexes on a collection" })
|
|
27
|
+
.handler(async (input, ctx) => {
|
|
28
|
+
const { collection } = await collectionFor(input, ctx);
|
|
29
|
+
const indexes = await collection.listIndexes().toArray();
|
|
30
|
+
return {
|
|
31
|
+
indexes: indexes.map((idx) => ({
|
|
32
|
+
name: idx.name,
|
|
33
|
+
key: idx.key,
|
|
34
|
+
unique: idx.unique,
|
|
35
|
+
sparse: idx.sparse,
|
|
36
|
+
})),
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
.build();
|
|
40
|
+
//# sourceMappingURL=indexes.list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.list.js","sourceRoot":"","sources":["../../src/procedures/indexes.list.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAyC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAkB,MAAM,aAAa,CAAC;AAU7C,UAAU;AACV,MAAM,sBAAsB,GAAG,UAAU,CACvC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,EAAE,CAAC,CAC/B,CAAC;AACF,MAAM,uBAAuB,GAAG,UAAU,CACxC,CAAC,CAAC,WAAW,CAAC;IACZ,OAAO,EAAE,CAAC;SACP,KAAK,CACJ,CAAC,CAAC,WAAW,CAAC;QACZ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC3C,GAAG,EAAE,CAAC,CAAC,M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+1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared fields of the mongo input schemas (roadmap 2.1).
|
|
3
|
+
*
|
|
4
|
+
* Each `mongo.*` tool describes its fields, so Claude and `mark --help` know them. Before, most
|
|
5
|
+
* tools had a pass-through schema: the tool list showed no fields, and a field name with a
|
|
6
|
+
* typing error reached the handler.
|
|
7
|
+
*
|
|
8
|
+
* A write (`update`, `delete`) and `find`/`get` keep their own parse functions: they check the
|
|
9
|
+
* target rules of deep dive DATA-4 (exactly one of `id` or `filter`, an unknown field is an
|
|
10
|
+
* error, an empty filter needs `confirm`). `described()` gives such a function the JSON Schema of
|
|
11
|
+
* a zod object that names the same fields.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { type ZodLikeSchema } from "@procedures/client";
|
|
15
|
+
/** The fields that select the database and the collection. */
|
|
16
|
+
export declare function scopeFields(): {
|
|
17
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
18
|
+
database: z.ZodOptional<z.ZodString>;
|
|
19
|
+
};
|
|
20
|
+
/** A MongoDB document or a filter: an object with any fields. */
|
|
21
|
+
export declare function documentObject(): z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
22
|
+
/** The fields that select the documents of a write: one `id`, or a `filter`. */
|
|
23
|
+
export declare function targetFields(): {
|
|
24
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
25
|
+
id: z.ZodOptional<z.ZodString>;
|
|
26
|
+
idType: z.ZodOptional<z.ZodEnum<{
|
|
27
|
+
auto: "auto";
|
|
28
|
+
objectId: "objectId";
|
|
29
|
+
string: "string";
|
|
30
|
+
}>>;
|
|
31
|
+
multi: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
};
|
|
34
|
+
/** How to read a string id. */
|
|
35
|
+
export declare function idTypeField(): z.ZodOptional<z.ZodEnum<{
|
|
36
|
+
auto: "auto";
|
|
37
|
+
objectId: "objectId";
|
|
38
|
+
string: "string";
|
|
39
|
+
}>>;
|
|
40
|
+
/**
|
|
41
|
+
* A schema whose validation is a parse function, and whose JSON Schema is the one of a zod object
|
|
42
|
+
* that names the same fields.
|
|
43
|
+
*/
|
|
44
|
+
export declare function described<T>(parse: (data: unknown) => T, fields: z.ZodObject): ZodLikeSchema<T>;
|
|
45
|
+
//# sourceMappingURL=input-schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-schemas.d.ts","sourceRoot":"","sources":["../../src/procedures/input-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAElF,8DAA8D;AAC9D,wBAAgB,WAAW,IAAI;IAAE,UAAU,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAAC,QAAQ,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;CAAE,CAK9G;AAED,iEAAiE;AACjE,wBAAgB,cAAc,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,CAEvE;AAED,gFAAgF;AAChF,wBAAgB,YAAY,IAAI;IAC9B,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9D,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC/B,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,CAAC;IAC3F,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CACtC,CAUA;AAED,+BAA+B;AAC/B,wBAAgB,WAAW,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,CAKhH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,CAE/F"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared fields of the mongo input schemas (roadmap 2.1).
|
|
3
|
+
*
|
|
4
|
+
* Each `mongo.*` tool describes its fields, so Claude and `mark --help` know them. Before, most
|
|
5
|
+
* tools had a pass-through schema: the tool list showed no fields, and a field name with a
|
|
6
|
+
* typing error reached the handler.
|
|
7
|
+
*
|
|
8
|
+
* A write (`update`, `delete`) and `find`/`get` keep their own parse functions: they check the
|
|
9
|
+
* target rules of deep dive DATA-4 (exactly one of `id` or `filter`, an unknown field is an
|
|
10
|
+
* error, an empty filter needs `confirm`). `described()` gives such a function the JSON Schema of
|
|
11
|
+
* a zod object that names the same fields.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { jsonSchemaOf, zodAdapter } from "@procedures/client";
|
|
15
|
+
/** The fields that select the database and the collection. */
|
|
16
|
+
export function scopeFields() {
|
|
17
|
+
return {
|
|
18
|
+
collection: z.string().min(1).optional().describe("The collection name. It takes the place of metadata.collection."),
|
|
19
|
+
database: z.string().min(1).optional().describe("The database name (default: the database of the connection)"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** A MongoDB document or a filter: an object with any fields. */
|
|
23
|
+
export function documentObject() {
|
|
24
|
+
return z.record(z.string(), z.unknown());
|
|
25
|
+
}
|
|
26
|
+
/** The fields that select the documents of a write: one `id`, or a `filter`. */
|
|
27
|
+
export function targetFields() {
|
|
28
|
+
return {
|
|
29
|
+
filter: documentObject()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("The filter of the documents (give exactly one of id or filter). An empty filter needs confirm: true."),
|
|
32
|
+
id: z.string().min(1).optional().describe("The id of one document (the alternative to filter)"),
|
|
33
|
+
idType: idTypeField(),
|
|
34
|
+
multi: z.boolean().optional().describe("Change every matching document, not only the first one"),
|
|
35
|
+
confirm: z.boolean().optional().describe("Set to true to use an empty filter, which matches every document"),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** How to read a string id. */
|
|
39
|
+
export function idTypeField() {
|
|
40
|
+
return z
|
|
41
|
+
.enum(["auto", "objectId", "string"])
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('How to read the id: "auto" (the default: an ObjectId or a string), "objectId" or "string"');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A schema whose validation is a parse function, and whose JSON Schema is the one of a zod object
|
|
47
|
+
* that names the same fields.
|
|
48
|
+
*/
|
|
49
|
+
export function described(parse, fields) {
|
|
50
|
+
return Object.assign(zodAdapter({ parse }), { "~jsonSchema": jsonSchemaOf(fields) });
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=input-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-schemas.js","sourceRoot":"","sources":["../../src/procedures/input-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAsB,MAAM,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I,KAA2B,EAAE,MAAmB;IAC3E,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAI,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/procedures/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/procedures/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The target of a write: one document by `id`, or the documents that match a `filter`.
|
|
3
|
+
*
|
|
4
|
+
* Before, a call without `id` and `filter` used the filter `{}`, and the field name of
|
|
5
|
+
* `find`/`count` (`query`) was ignored: `delete { query, multi: true }` emptied the
|
|
6
|
+
* collection (deep dive DATA-4). Now a write needs exactly one target, an unknown field is an
|
|
7
|
+
* error, and an empty filter needs `confirm: true`.
|
|
8
|
+
*/
|
|
9
|
+
import { type Collection, type Document } from "mongodb";
|
|
10
|
+
import { type DocumentQuery, type IdType } from "../types.js";
|
|
11
|
+
import { type ScopeInput } from "../scope.js";
|
|
12
|
+
/** The fields of a write target. */
|
|
13
|
+
export interface TargetInput extends ScopeInput {
|
|
14
|
+
/** The filter of the documents to change. An empty filter needs `confirm: true`. */
|
|
15
|
+
filter?: DocumentQuery;
|
|
16
|
+
/** The ID of one document (the alternative to `filter`). */
|
|
17
|
+
id?: string;
|
|
18
|
+
/** How to read the ID (default: "auto", which matches an ObjectId or a string). */
|
|
19
|
+
idType?: IdType;
|
|
20
|
+
/** Change all matching documents, not only the first one. */
|
|
21
|
+
multi?: boolean;
|
|
22
|
+
/** Set to true to use an empty filter (it matches every document). */
|
|
23
|
+
confirm?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This function reads and checks the target fields of a write input.
|
|
27
|
+
* `extraFields` are the other fields that the procedure accepts.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseTarget(procedure: string, data: unknown, extraFields?: readonly string[]): {
|
|
30
|
+
target: TargetInput;
|
|
31
|
+
raw: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
/** The filter of a target. */
|
|
34
|
+
export declare function targetFilter(target: TargetInput): Document;
|
|
35
|
+
/**
|
|
36
|
+
* The filter of an upsert by ID. It names one exact `_id`.
|
|
37
|
+
*
|
|
38
|
+
* In the "auto" mode the ID filter is `$or` of the ObjectId and the string form. MongoDB cannot
|
|
39
|
+
* take an `_id` from `$or`, so each upsert inserted a new document with a new ID (deep dive
|
|
40
|
+
* DATA-15). This function uses the `_id` of the existing document, or the ObjectId form when no
|
|
41
|
+
* document matches.
|
|
42
|
+
*/
|
|
43
|
+
export declare function upsertFilter(collection: Collection<Document>, target: TargetInput): Promise<Document>;
|
|
44
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/procedures/target.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAY,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAiB,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvE,oCAAoC;AACpC,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC7C,oFAAoF;IACpF,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,4DAA4D;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAeD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,OAAO,EACb,WAAW,GAAE,SAAS,MAAM,EAAO,GAClC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAsDvD;AAED,8BAA8B;AAC9B,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,CAE1D;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAK3G"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The target of a write: one document by `id`, or the documents that match a `filter`.
|
|
3
|
+
*
|
|
4
|
+
* Before, a call without `id` and `filter` used the filter `{}`, and the field name of
|
|
5
|
+
* `find`/`count` (`query`) was ignored: `delete { query, multi: true }` emptied the
|
|
6
|
+
* collection (deep dive DATA-4). Now a write needs exactly one target, an unknown field is an
|
|
7
|
+
* error, and an empty filter needs `confirm: true`.
|
|
8
|
+
*/
|
|
9
|
+
import { ObjectId } from "mongodb";
|
|
10
|
+
import { buildIdFilter } from "../types.js";
|
|
11
|
+
import { SCOPE_FIELDS, copyScope } from "../scope.js";
|
|
12
|
+
const TARGET_FIELDS = ["filter", "id", "idType", "multi", "confirm", ...SCOPE_FIELDS];
|
|
13
|
+
function isPlainObject(value) {
|
|
14
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function optionalBoolean(procedure, raw, field) {
|
|
17
|
+
const value = raw[field];
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (typeof value !== "boolean")
|
|
21
|
+
throw new Error(`${procedure}: ${field} must be a boolean`);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* This function reads and checks the target fields of a write input.
|
|
26
|
+
* `extraFields` are the other fields that the procedure accepts.
|
|
27
|
+
*/
|
|
28
|
+
export function parseTarget(procedure, data, extraFields = []) {
|
|
29
|
+
if (!isPlainObject(data)) {
|
|
30
|
+
throw new Error(`${procedure}: input must be an object`);
|
|
31
|
+
}
|
|
32
|
+
const raw = data;
|
|
33
|
+
const allowed = new Set([...TARGET_FIELDS, ...extraFields]);
|
|
34
|
+
for (const key of Object.keys(raw)) {
|
|
35
|
+
if (!allowed.has(key)) {
|
|
36
|
+
const hint = key === "query" ? ' Use "filter".' : "";
|
|
37
|
+
throw new Error(`${procedure}: unknown field "${key}".${hint} The fields are: ${[...allowed].join(", ")}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const hasId = raw["id"] !== undefined;
|
|
41
|
+
const hasFilter = raw["filter"] !== undefined;
|
|
42
|
+
if (hasId === hasFilter) {
|
|
43
|
+
throw new Error(`${procedure}: give exactly one of id or filter`);
|
|
44
|
+
}
|
|
45
|
+
const target = {};
|
|
46
|
+
copyScope(raw, target);
|
|
47
|
+
if (hasId) {
|
|
48
|
+
const id = raw["id"];
|
|
49
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
50
|
+
throw new Error(`${procedure}: id must be a non-empty string`);
|
|
51
|
+
}
|
|
52
|
+
target.id = id;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const filter = raw["filter"];
|
|
56
|
+
if (!isPlainObject(filter)) {
|
|
57
|
+
throw new Error(`${procedure}: filter must be an object`);
|
|
58
|
+
}
|
|
59
|
+
target.filter = filter;
|
|
60
|
+
}
|
|
61
|
+
const idType = raw["idType"];
|
|
62
|
+
if (idType !== undefined) {
|
|
63
|
+
if (idType !== "auto" && idType !== "objectId" && idType !== "string") {
|
|
64
|
+
throw new Error(`${procedure}: idType must be "auto", "objectId" or "string"`);
|
|
65
|
+
}
|
|
66
|
+
target.idType = idType;
|
|
67
|
+
}
|
|
68
|
+
const multi = optionalBoolean(procedure, raw, "multi");
|
|
69
|
+
const confirm = optionalBoolean(procedure, raw, "confirm");
|
|
70
|
+
if (multi !== undefined)
|
|
71
|
+
target.multi = multi;
|
|
72
|
+
if (confirm !== undefined)
|
|
73
|
+
target.confirm = confirm;
|
|
74
|
+
if (target.filter && Object.keys(target.filter).length === 0 && confirm !== true) {
|
|
75
|
+
throw new Error(`${procedure}: an empty filter matches every document. Set confirm: true to use it.`);
|
|
76
|
+
}
|
|
77
|
+
return { target, raw };
|
|
78
|
+
}
|
|
79
|
+
/** The filter of a target. */
|
|
80
|
+
export function targetFilter(target) {
|
|
81
|
+
return target.id !== undefined ? buildIdFilter(target.id, target.idType) : target.filter;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The filter of an upsert by ID. It names one exact `_id`.
|
|
85
|
+
*
|
|
86
|
+
* In the "auto" mode the ID filter is `$or` of the ObjectId and the string form. MongoDB cannot
|
|
87
|
+
* take an `_id` from `$or`, so each upsert inserted a new document with a new ID (deep dive
|
|
88
|
+
* DATA-15). This function uses the `_id` of the existing document, or the ObjectId form when no
|
|
89
|
+
* document matches.
|
|
90
|
+
*/
|
|
91
|
+
export async function upsertFilter(collection, target) {
|
|
92
|
+
const filter = targetFilter(target);
|
|
93
|
+
if (target.id === undefined || !("$or" in filter))
|
|
94
|
+
return filter;
|
|
95
|
+
const existing = await collection.findOne(filter, { projection: { _id: 1 } });
|
|
96
|
+
return { _id: existing ? existing["_id"] : new ObjectId(target.id) };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../../src/proc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