@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,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.database.info
|
|
3
|
+
* Get database information and statistics
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { databaseFor } from "../scope.js";
|
|
7
|
+
import { scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const infoInputSchema = zodAdapter(z.object({ ...scopeFields() }));
|
|
12
|
+
const infoOutputSchema = zodAdapter(z.looseObject({
|
|
13
|
+
name: z.string().describe("The database name"),
|
|
14
|
+
collections: z.number().describe("The number of collections (views not counted)"),
|
|
15
|
+
views: z.number().describe("The number of views"),
|
|
16
|
+
sizeOnDisk: z.number().describe("The data size, in bytes"),
|
|
17
|
+
empty: z.boolean().describe("True when the database has no collections"),
|
|
18
|
+
}));
|
|
19
|
+
export const infoProcedure = createProcedure()
|
|
20
|
+
.path(["mongo", "database", "info"])
|
|
21
|
+
.input(infoInputSchema)
|
|
22
|
+
.output(infoOutputSchema)
|
|
23
|
+
.meta({ description: "Get database information and statistics" })
|
|
24
|
+
.handler(async (input, ctx) => {
|
|
25
|
+
const db = await databaseFor(input, ctx);
|
|
26
|
+
const stats = await db.stats();
|
|
27
|
+
const collections = await db.listCollections().toArray();
|
|
28
|
+
const views = collections.filter((c) => c.type === "view").length;
|
|
29
|
+
return {
|
|
30
|
+
name: db.databaseName,
|
|
31
|
+
collections: collections.length - views,
|
|
32
|
+
views,
|
|
33
|
+
sizeOnDisk: stats["dataSize"] ?? 0,
|
|
34
|
+
empty: collections.length === 0,
|
|
35
|
+
};
|
|
36
|
+
})
|
|
37
|
+
.build();
|
|
38
|
+
//# sourceMappingURL=database.info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.info.js","sourceRoot":"","sources":["../../src/procedures/database.info.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAyC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqB,MAAM,aAAa,CAAC;AAMhD,UAAU;AACV,MAAM,eAAe,GAAG,UAAU,CAChC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,EAAE,CAAC,CAC/B,CAAC;AACF,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,CAAC,WAAW,CAAC;IACZ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAC9C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;IACjF,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACjD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yBAAyB,CAAC;IAC1D,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,2CAA2C,CAAC;CACzE,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAItB,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;KACnC,KAAK,CAAC,eAAe,CAAC;KACtB,MAAM,CAAC,gBAAgB,CAAC;KACxB,IAAI,CAAC,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAAC;KAChE,OAAO,CAAC,KAAK,EAAE,KAAgB,EAAE,GAAqB,EAAE,EAAE;IACzD,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEzC,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,CAAC;IAEzD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,MAAM,CAAC;IAElE,OAAO;QACL,IAAI,EAAE,EAAE,CAAC,YAAY;QACrB,WAAW,EAAE,WAAW,CAAC,MAAM,GAAG,KAAK;QACvC,KAAK;QACL,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAClC,KAAK,EAAE,WAAW,CAAC,MAAM,KAAK,CAAC;KAChC,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.database.ping
|
|
3
|
+
* Health check and connectivity test
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
/** The input: only the scope fields. */
|
|
8
|
+
type PingInput = ScopeInput;
|
|
9
|
+
interface PingOutput {
|
|
10
|
+
ok: boolean;
|
|
11
|
+
latencyMs: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const pingProcedure: Procedure<PingInput, PingOutput, {
|
|
14
|
+
description: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type { PingInput, PingOutput };
|
|
17
|
+
//# sourceMappingURL=database.ping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.ping.d.ts","sourceRoot":"","sources":["../../src/procedures/database.ping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAK3D,wCAAwC;AACxC,KAAK,SAAS,GAAG,UAAU,CAAC;AAE5B,UAAU,UAAU;IAClB,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAaD,eAAO,MAAM,aAAa,EAAE,SAAS,CACnC,SAAS,EACT,UAAU,EACV;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAkBf,CAAC;AAEX,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.database.ping
|
|
3
|
+
* Health check and connectivity test
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { databaseFor } from "../scope.js";
|
|
7
|
+
import { scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// Schemas
|
|
10
|
+
const pingInputSchema = zodAdapter(z.object({ ...scopeFields() }));
|
|
11
|
+
const pingOutputSchema = zodAdapter(z.looseObject({
|
|
12
|
+
ok: z.boolean().describe("True when the server answered"),
|
|
13
|
+
latencyMs: z.number().describe("The time of the ping, in milliseconds"),
|
|
14
|
+
}));
|
|
15
|
+
export const pingProcedure = createProcedure()
|
|
16
|
+
.path(["mongo", "database", "ping"])
|
|
17
|
+
.input(pingInputSchema)
|
|
18
|
+
.output(pingOutputSchema)
|
|
19
|
+
.meta({ description: "Health check and connectivity test" })
|
|
20
|
+
.handler(async (input, ctx) => {
|
|
21
|
+
const db = await databaseFor(input, ctx);
|
|
22
|
+
const start = Date.now();
|
|
23
|
+
await db.command({ ping: 1 });
|
|
24
|
+
const latencyMs = Date.now() - start;
|
|
25
|
+
return {
|
|
26
|
+
ok: true,
|
|
27
|
+
latencyMs,
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.build();
|
|
31
|
+
//# sourceMappingURL=database.ping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.ping.js","sourceRoot":"","sources":["../../src/procedures/database.ping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAyC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,UAAU;AACV,MAAM,eAAe,GAAG,UAAU,CAChC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,EAAE,CAAC,CAC/B,CAAC;AACF,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,CAAC,WAAW,CAAC;IACZ,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;IACzD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;CACxE,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAItB,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;KACnC,KAAK,CAAC,eAAe,CAAC;KACtB,MAAM,CAAC,gBAAgB,CAAC;KACxB,IAAI,CAAC,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;KAC3D,OAAO,CAAC,KAAK,EAAE,KAAgB,EAAE,GAAqB,EAAE,EAAE;IACzD,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEzC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAErC,OAAO;QACL,EAAE,EAAE,IAAI;QACR,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.aggregate
|
|
3
|
+
* Run an aggregation pipeline
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type AggregationStage, type AggregationOptions, type MongoDocument } from "../types.js";
|
|
8
|
+
interface AggregateInput extends ScopeInput {
|
|
9
|
+
pipeline: AggregationStage[];
|
|
10
|
+
options?: AggregationOptions | undefined;
|
|
11
|
+
}
|
|
12
|
+
interface AggregateOutput {
|
|
13
|
+
results: MongoDocument[];
|
|
14
|
+
}
|
|
15
|
+
export declare const aggregateProcedure: Procedure<AggregateInput, AggregateOutput, {
|
|
16
|
+
description: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type { AggregateInput, AggregateOutput };
|
|
19
|
+
//# sourceMappingURL=documents.aggregate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.aggregate.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.aggregate.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,EACL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAGrB,UAAU,cAAe,SAAQ,UAAU;IACzC,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC1C;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAsBD,eAAO,MAAM,kBAAkB,EAAE,SAAS,CACxC,cAAc,EACd,eAAe,EACf;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAgBf,CAAC;AAEX,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.aggregate
|
|
3
|
+
* Run an aggregation pipeline
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { scopeFields, documentObject } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const aggregateInputSchema = zodAdapter(z.object({
|
|
12
|
+
...scopeFields(),
|
|
13
|
+
pipeline: z.array(documentObject()).describe("The aggregation stages, in order (for example [{ $match: {...} }, { $group: {...} }])"),
|
|
14
|
+
options: z
|
|
15
|
+
.looseObject({
|
|
16
|
+
allowDiskUse: z.boolean().optional().describe("Allow the use of disk for large stages"),
|
|
17
|
+
maxTimeMS: z.number().optional().describe("The longest run time in milliseconds"),
|
|
18
|
+
})
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("The options of the aggregation"),
|
|
21
|
+
}));
|
|
22
|
+
const aggregateOutputSchema = zodAdapter(z.looseObject({
|
|
23
|
+
results: z.array(z.record(z.string(), z.unknown())).describe("The documents that the pipeline gave"),
|
|
24
|
+
}));
|
|
25
|
+
export const aggregateProcedure = createProcedure()
|
|
26
|
+
.path(["mongo", "documents", "aggregate"])
|
|
27
|
+
.input(aggregateInputSchema)
|
|
28
|
+
.output(aggregateOutputSchema)
|
|
29
|
+
.meta({ description: "Run an aggregation pipeline" })
|
|
30
|
+
.handler(async (input, ctx) => {
|
|
31
|
+
const { collection } = await collectionFor(input, ctx);
|
|
32
|
+
const results = await collection
|
|
33
|
+
// The schema leaves out an option that the input does not give
|
|
34
|
+
.aggregate(input.pipeline, input.options)
|
|
35
|
+
.toArray();
|
|
36
|
+
return { results };
|
|
37
|
+
})
|
|
38
|
+
.build();
|
|
39
|
+
//# sourceMappingURL=documents.aggregate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.aggregate.js","sourceRoot":"","sources":["../../src/procedures/documents.aggregate.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,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAIN,MAAM,aAAa,CAAC;AAYrB,UAAU;AACV,MAAM,oBAAoB,GAAG,UAAU,CACrC,CAAC,CAAC,MAAM,CAAC;IACP,GAAG,WAAW,EAAE;IAChB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,uFAAuF,CAAC;IACrI,OAAO,EAAE,CAAC;SACP,WAAW,CAAC;QACX,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAA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ures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type DocumentQuery } from "../types.js";
|
|
8
|
+
interface CountInput extends ScopeInput {
|
|
9
|
+
query?: DocumentQuery | undefined;
|
|
10
|
+
}
|
|
11
|
+
interface CountOutput {
|
|
12
|
+
count: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const countProcedure: Procedure<CountInput, CountOutput, {
|
|
15
|
+
description: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type { CountInput, CountOutput };
|
|
18
|
+
//# sourceMappingURL=documents.count.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.count.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.count.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,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,UAAU,UAAW,SAAQ,UAAU;IACrC,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACnC;AAED,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAeD,eAAO,MAAM,cAAc,EAAE,SAAS,CACpC,UAAU,EACV,WAAW,EACX;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAaf,CAAC;AAEX,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.count
|
|
3
|
+
* Count documents matching a filter
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { scopeFields, documentObject } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const countInputSchema = zodAdapter(z.object({
|
|
12
|
+
...scopeFields(),
|
|
13
|
+
query: documentObject().optional().describe("The filter of the documents to count (default: all documents)"),
|
|
14
|
+
}));
|
|
15
|
+
const countOutputSchema = zodAdapter(z.looseObject({
|
|
16
|
+
count: z.number().describe("The number of documents that match"),
|
|
17
|
+
}));
|
|
18
|
+
export const countProcedure = createProcedure()
|
|
19
|
+
.path(["mongo", "documents", "count"])
|
|
20
|
+
.input(countInputSchema)
|
|
21
|
+
.output(countOutputSchema)
|
|
22
|
+
.meta({ description: "Count documents matching a filter" })
|
|
23
|
+
.handler(async (input, ctx) => {
|
|
24
|
+
const { collection } = await collectionFor(input, ctx);
|
|
25
|
+
const count = await collection.countDocuments(input.query ?? {});
|
|
26
|
+
return { count };
|
|
27
|
+
})
|
|
28
|
+
.build();
|
|
29
|
+
//# sourceMappingURL=documents.count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.count.js","sourceRoot":"","sources":["../../src/procedures/documents.count.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,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAsB,MAAM,aAAa,CAAC;AAWjD,UAAU;AACV,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,CAAC,MAAM,CAAC;IACP,GAAG,WAAW,EAAE;IAChB,KAAK,EAAE,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+DAA+D,CAAC;CAC7G,CAAC,CACH,CAAC;AACF,MAAM,iBAAiB,GAAG,UAAU,CAClC,CAAC,CAAC,WAAW,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;CACjE,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAIvB,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;KACrC,KAAK,CAAC,gBAAgB,CAAC;KACvB,MAAM,CAAC,iBAAiB,CAAC;KACzB,IAAI,CAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE,CAAC;KAC1D,OAAO,CAAC,KAAK,EAAE,KAAiB,EAAE,GAAqB,EAAE,EAAE;IAC1D,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAEjE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.delete
|
|
3
|
+
* Delete documents matching a filter
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type TargetInput } from "./target.js";
|
|
7
|
+
/** The input: exactly one of `id` or `filter`, and the scope fields. */
|
|
8
|
+
type DeleteInput = TargetInput;
|
|
9
|
+
interface DeleteOutput {
|
|
10
|
+
acknowledged: boolean;
|
|
11
|
+
deletedCount: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const deleteProcedure: Procedure<DeleteInput, DeleteOutput, {
|
|
14
|
+
description: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type { DeleteInput, DeleteOutput };
|
|
17
|
+
//# sourceMappingURL=documents.delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.delete.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.delete.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmB,KAAK,SAAS,EAAqC,MAAM,oBAAoB,CAAC;AAIxG,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1E,wEAAwE;AACxE,KAAK,WAAW,GAAG,WAAW,CAAC;AAE/B,UAAU,YAAY;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAcD,eAAO,MAAM,eAAe,EAAE,SAAS,CACrC,WAAW,EACX,YAAY,EACZ;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAgBf,CAAC;AAEX,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.delete
|
|
3
|
+
* Delete documents matching a filter
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { described, scopeFields, targetFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { parseTarget, targetFilter } from "./target.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const deleteInputSchema = described((data) => parseTarget("mongo.documents.delete", data).target, z.object({ ...scopeFields(), ...targetFields() }));
|
|
12
|
+
const deleteOutputSchema = zodAdapter(z.looseObject({
|
|
13
|
+
acknowledged: z.boolean().describe("True when the server confirmed the write"),
|
|
14
|
+
deletedCount: z.number().describe("The number of deleted documents"),
|
|
15
|
+
}));
|
|
16
|
+
export const deleteProcedure = createProcedure()
|
|
17
|
+
.path(["mongo", "documents", "delete"])
|
|
18
|
+
.input(deleteInputSchema)
|
|
19
|
+
.output(deleteOutputSchema)
|
|
20
|
+
.meta({ description: "Delete documents matching a filter" })
|
|
21
|
+
.handler(async (input, ctx) => {
|
|
22
|
+
const { collection } = await collectionFor(input, ctx);
|
|
23
|
+
const filter = targetFilter(input);
|
|
24
|
+
const result = input.multi ? await collection.deleteMany(filter) : await collection.deleteOne(filter);
|
|
25
|
+
return {
|
|
26
|
+
acknowledged: result.acknowledged,
|
|
27
|
+
deletedCount: result.deletedCount,
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.build();
|
|
31
|
+
//# sourceMappingURL=documents.delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.delete.js","sourceRoot":"","sources":["../../src/procedures/documents.delete.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,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAoB,MAAM,aAAa,CAAC;AAW1E,UAAU;AACV,MAAM,iBAAiB,GAAG,SAAS,CACjC,CAAC,IAAa,EAAE,EAAE,CAAC,WAAW,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC,MAAM,EACrE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,EAAE,GAAG,YAAY,EAAE,EAAE,CAAC,CAClD,CAAC;AACF,MAAM,kBAAkB,GAAG,UAAU,CACnC,CAAC,CAAC,WAAW,CAAC;IACZ,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;IAC9E,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;CACrE,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAIxB,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;KACtC,KAAK,CAAC,iBAAiB,CAAC;KACxB,MAAM,CAAC,kBAAkB,CAAC;KAC1B,IAAI,CAAC,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;KAC3D,OAAO,CAAC,KAAK,EAAE,KAAkB,EAAE,GAAqB,EAAE,EAAE;IAC3D,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAEnC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtG,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,YAAY,EAAE,MAAM,CAAC,YAAY;KAClC,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.find
|
|
3
|
+
* Find documents with pagination and filtering
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type PaginationOutput, type DocumentQuery, type SortSpec, type MongoDocument } from "../types.js";
|
|
8
|
+
interface FindInput extends ScopeInput {
|
|
9
|
+
query?: DocumentQuery;
|
|
10
|
+
projection?: Record<string, 0 | 1>;
|
|
11
|
+
sort?: SortSpec;
|
|
12
|
+
page?: number;
|
|
13
|
+
limit?: number;
|
|
14
|
+
}
|
|
15
|
+
interface FindOutput {
|
|
16
|
+
documents: MongoDocument[];
|
|
17
|
+
pagination: PaginationOutput;
|
|
18
|
+
}
|
|
19
|
+
export declare const findProcedure: Procedure<FindInput, FindOutput, {
|
|
20
|
+
description: string;
|
|
21
|
+
}>;
|
|
22
|
+
export type { FindInput, FindOutput };
|
|
23
|
+
//# sourceMappingURL=documents.find.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.find.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.find.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAGxE,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAGrB,UAAU,SAAU,SAAQ,UAAU;IACpC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAClB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,UAAU,EAAE,gBAAgB,CAAC;CAC9B;AAoED,eAAO,MAAM,aAAa,EAAE,SAAS,CACnC,SAAS,EACT,UAAU,EACV;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAwCf,CAAC;AAEX,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.find
|
|
3
|
+
* Find documents with pagination and filtering
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter, } from "@procedures/client";
|
|
6
|
+
import { collectionFor, copyScope } from "../scope.js";
|
|
7
|
+
import { described, documentObject, scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Validate find input. Enforces `page`/`limit` as integers >= 1 so a `page: 0`
|
|
12
|
+
* (which produced a negative `skip`) or a string `limit` (which produced a
|
|
13
|
+
* `NaN` limit) can no longer reach the driver. Other fields pass through.
|
|
14
|
+
*/
|
|
15
|
+
function parseFindInput(data) {
|
|
16
|
+
if (typeof data !== "object" || data === null) {
|
|
17
|
+
throw new Error("mongo.documents.find: input must be an object");
|
|
18
|
+
}
|
|
19
|
+
const raw = data;
|
|
20
|
+
const result = {};
|
|
21
|
+
copyScope(raw, result);
|
|
22
|
+
if (raw["query"] !== undefined) {
|
|
23
|
+
result.query = raw["query"];
|
|
24
|
+
}
|
|
25
|
+
if (raw["projection"] !== undefined) {
|
|
26
|
+
result.projection = raw["projection"];
|
|
27
|
+
}
|
|
28
|
+
if (raw["sort"] !== undefined) {
|
|
29
|
+
result.sort = raw["sort"];
|
|
30
|
+
}
|
|
31
|
+
if (raw["page"] !== undefined) {
|
|
32
|
+
const page = raw["page"];
|
|
33
|
+
if (typeof page !== "number" || !Number.isInteger(page) || page < 1) {
|
|
34
|
+
throw new Error("mongo.documents.find: page must be an integer >= 1");
|
|
35
|
+
}
|
|
36
|
+
result.page = page;
|
|
37
|
+
}
|
|
38
|
+
if (raw["limit"] !== undefined) {
|
|
39
|
+
const limit = raw["limit"];
|
|
40
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1) {
|
|
41
|
+
throw new Error("mongo.documents.find: limit must be an integer >= 1");
|
|
42
|
+
}
|
|
43
|
+
result.limit = limit;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
// Schemas
|
|
48
|
+
const findInputSchema = described(parseFindInput, z.object({
|
|
49
|
+
...scopeFields(),
|
|
50
|
+
query: documentObject().optional().describe("The filter of the documents (default: all documents)"),
|
|
51
|
+
projection: z.record(z.string(), z.union([z.literal(0), z.literal(1)])).optional().describe("The fields to give (1) or to leave out (0)"),
|
|
52
|
+
sort: z.record(z.string(), z.unknown()).optional().describe("The sort order: { field: 1 } ascending, { field: -1 } descending"),
|
|
53
|
+
page: z.number().int().min(1).optional().describe("The page to give, from 1"),
|
|
54
|
+
limit: z.number().int().min(1).optional().describe("The number of documents on a page"),
|
|
55
|
+
}));
|
|
56
|
+
const findOutputSchema = zodAdapter(z.looseObject({
|
|
57
|
+
documents: z.array(z.record(z.string(), z.unknown())).describe("The documents of the page"),
|
|
58
|
+
pagination: z.looseObject({
|
|
59
|
+
page: z.number().describe("The page, from 1"),
|
|
60
|
+
limit: z.number().describe("The number of documents on a page"),
|
|
61
|
+
total: z.number().describe("The number of documents that match"),
|
|
62
|
+
totalPages: z.number().describe("The number of pages"),
|
|
63
|
+
hasNext: z.boolean().describe("True when a next page exists"),
|
|
64
|
+
hasPrev: z.boolean().describe("True when a previous page exists"),
|
|
65
|
+
}).describe("The page of the result"),
|
|
66
|
+
}));
|
|
67
|
+
export const findProcedure = createProcedure()
|
|
68
|
+
.path(["mongo", "documents", "find"])
|
|
69
|
+
.input(findInputSchema)
|
|
70
|
+
.output(findOutputSchema)
|
|
71
|
+
.meta({ description: "Find documents with pagination and filtering" })
|
|
72
|
+
.handler(async (input, ctx) => {
|
|
73
|
+
const { collection } = await collectionFor(input, ctx);
|
|
74
|
+
const query = input.query ?? {};
|
|
75
|
+
const page = input.page ?? 1;
|
|
76
|
+
const limit = Math.min(input.limit ?? 20, 100); // Cap at 100
|
|
77
|
+
const skip = (page - 1) * limit;
|
|
78
|
+
// Execute query and count in parallel
|
|
79
|
+
const [documents, total] = await Promise.all([
|
|
80
|
+
collection
|
|
81
|
+
.find(query)
|
|
82
|
+
.project(input.projection ?? {})
|
|
83
|
+
.sort(input.sort ?? {})
|
|
84
|
+
.skip(skip)
|
|
85
|
+
.limit(limit)
|
|
86
|
+
.toArray(),
|
|
87
|
+
collection.countDocuments(query),
|
|
88
|
+
]);
|
|
89
|
+
const totalPages = Math.ceil(total / limit);
|
|
90
|
+
return {
|
|
91
|
+
documents,
|
|
92
|
+
pagination: {
|
|
93
|
+
page,
|
|
94
|
+
limit,
|
|
95
|
+
total,
|
|
96
|
+
totalPages,
|
|
97
|
+
hasNext: page < totalPages,
|
|
98
|
+
hasPrev: page > 1,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
})
|
|
102
|
+
.build();
|
|
103
|
+
//# sourceMappingURL=documents.find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.find.js","sourceRoot":"","sources":["../../src/procedures/documents.find.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,eAAe,EAGf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKN,MAAM,aAAa,CAAC;AAgBrB;;;;GAIG;AACH,SAAS,cAAc,CAAC,IAAa;IACnC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,GAAG,GAAG,IAA+B,CAAC;IAC5C,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEvB,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,OAAO,CAAkB,CAAC;IAC/C,CAAC;IACD,IAAI,GAAG,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,CAAC,UAAU,GAAG,GAAG,CAAC,YAAY,CAA0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,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IAE5C,OAAO;QACL,SAAS;QACT,UAAU,EAAE;YACV,IAAI;YACJ,KAAK;YACL,KAAK;YACL,UAAU;YACV,OAAO,EAAE,IAAI,GAAG,UAAU;YAC1B,OAAO,EAAE,IAAI,GAAG,CAAC;SAClB;KACF,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.get
|
|
3
|
+
* Get a single document by ID
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type IdType, type MongoDocument } from "../types.js";
|
|
8
|
+
interface GetInput extends ScopeInput {
|
|
9
|
+
id: string;
|
|
10
|
+
/** How to interpret the id (default: "auto" — matches ObjectId or string) */
|
|
11
|
+
idType?: IdType;
|
|
12
|
+
}
|
|
13
|
+
interface GetOutput {
|
|
14
|
+
document: MongoDocument | null;
|
|
15
|
+
}
|
|
16
|
+
export declare const getProcedure: Procedure<GetInput, GetOutput, {
|
|
17
|
+
description: string;
|
|
18
|
+
}>;
|
|
19
|
+
export type { GetInput, GetOutput };
|
|
20
|
+
//# sourceMappingURL=documents.get.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.get.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.get.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAGxE,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAGrB,UAAU,QAAS,SAAQ,UAAU;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,SAAS;IACjB,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;CAChC;AAgDD,eAAO,MAAM,YAAY,EAAE,SAAS,CAClC,QAAQ,EACR,SAAS,EACT;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAef,CAAC;AAEX,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.get
|
|
3
|
+
* Get a single document by ID
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter, } from "@procedures/client";
|
|
6
|
+
import { collectionFor, copyScope } from "../scope.js";
|
|
7
|
+
import { described, idTypeField, scopeFields } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { buildIdFilter, } from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Validate get input: `id` must be a non-empty string, and `idType`, when
|
|
12
|
+
* present, must be one of the supported modes.
|
|
13
|
+
*/
|
|
14
|
+
function parseGetInput(data) {
|
|
15
|
+
if (typeof data !== "object" || data === null) {
|
|
16
|
+
throw new Error("mongo.documents.get: input must be an object");
|
|
17
|
+
}
|
|
18
|
+
const raw = data;
|
|
19
|
+
const id = raw["id"];
|
|
20
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
21
|
+
throw new Error("mongo.documents.get: id must be a non-empty string");
|
|
22
|
+
}
|
|
23
|
+
const result = { id };
|
|
24
|
+
copyScope(raw, result);
|
|
25
|
+
const idType = raw["idType"];
|
|
26
|
+
if (idType !== undefined) {
|
|
27
|
+
if (idType !== "auto" && idType !== "objectId" && idType !== "string") {
|
|
28
|
+
throw new Error('mongo.documents.get: idType must be "auto", "objectId", or "string"');
|
|
29
|
+
}
|
|
30
|
+
result.idType = idType;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
// Schemas
|
|
35
|
+
const getInputSchema = described(parseGetInput, z.object({
|
|
36
|
+
...scopeFields(),
|
|
37
|
+
id: z.string().min(1).describe("The id of the document"),
|
|
38
|
+
idType: idTypeField(),
|
|
39
|
+
}));
|
|
40
|
+
const getOutputSchema = zodAdapter(z.looseObject({
|
|
41
|
+
document: z.record(z.string(), z.unknown()).nullable().describe("The document, or null when no document has the id"),
|
|
42
|
+
}));
|
|
43
|
+
export const getProcedure = createProcedure()
|
|
44
|
+
.path(["mongo", "documents", "get"])
|
|
45
|
+
.input(getInputSchema)
|
|
46
|
+
.output(getOutputSchema)
|
|
47
|
+
.meta({ description: "Get a single document by ID" })
|
|
48
|
+
.handler(async (input, ctx) => {
|
|
49
|
+
const { collection } = await collectionFor(input, ctx);
|
|
50
|
+
const document = await collection.findOne(buildIdFilter(input.id, input.idType));
|
|
51
|
+
return { document };
|
|
52
|
+
})
|
|
53
|
+
.build();
|
|
54
|
+
//# sourceMappingURL=documents.get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.get.js","sourceRoot":"","sources":["../../src/procedures/documents.get.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,eAAe,EAGf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,aAAa,GAGd,MAAM,aAAa,CAAC;AAarB;;;GAGG;AACH,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,GAAG,GAAG,IAA+B,CAAC;IAE5C,MAAM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,CAAC,CAAC;KACnC,KAAK,CAAC,cAAc,CAAC;KACrB,MAAM,CAAC,eAAe,CAAC;KACvB,IAAI,CAAC,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;KACpD,OAAO,CAAC,KAAK,EAAE,KAAe,EAAE,GAAqB,EAAE,EAAE;IACxD,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEvD,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CACvC,aAAa,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CACtC,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.insert
|
|
3
|
+
* Insert one or more documents
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import { type ScopeInput } from "../scope.js";
|
|
7
|
+
import { type MongoDocument } from "../types.js";
|
|
8
|
+
interface InsertInput extends ScopeInput {
|
|
9
|
+
/** Single document or array of documents */
|
|
10
|
+
documents: MongoDocument | MongoDocument[];
|
|
11
|
+
}
|
|
12
|
+
interface InsertOutput {
|
|
13
|
+
acknowledged: boolean;
|
|
14
|
+
insertedIds: string[];
|
|
15
|
+
insertedCount: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const insertProcedure: Procedure<InsertInput, InsertOutput, {
|
|
18
|
+
description: string;
|
|
19
|
+
}>;
|
|
20
|
+
export type { InsertInput, InsertOutput };
|
|
21
|
+
//# sourceMappingURL=documents.insert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.insert.d.ts","sourceRoot":"","sources":["../../src/procedures/documents.insert.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,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,UAAU,WAAY,SAAQ,UAAU;IACtC,4CAA4C;IAC5C,SAAS,EAAE,aAAa,GAAG,aAAa,EAAE,CAAC;CAC5C;AAED,UAAU,YAAY;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB;AAmBD,eAAO,MAAM,eAAe,EAAE,SAAS,CACrC,WAAW,EACX,YAAY,EACZ;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAqCf,CAAC;AAEX,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.insert
|
|
3
|
+
* Insert one or more documents
|
|
4
|
+
*/
|
|
5
|
+
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
6
|
+
import { collectionFor } from "../scope.js";
|
|
7
|
+
import { scopeFields, documentObject } from "./input-schemas.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import {} from "../types.js";
|
|
10
|
+
// Schemas
|
|
11
|
+
const insertInputSchema = zodAdapter(z.object({
|
|
12
|
+
...scopeFields(),
|
|
13
|
+
documents: z
|
|
14
|
+
.union([documentObject(), z.array(documentObject())])
|
|
15
|
+
.describe("One document, or a list of documents"),
|
|
16
|
+
}));
|
|
17
|
+
const insertOutputSchema = zodAdapter(z.looseObject({
|
|
18
|
+
acknowledged: z.boolean().describe("True when the server confirmed the write"),
|
|
19
|
+
insertedIds: z.array(z.string()).describe("The ids of the new documents, as text"),
|
|
20
|
+
insertedCount: z.number().describe("The number of new documents"),
|
|
21
|
+
}));
|
|
22
|
+
export const insertProcedure = createProcedure()
|
|
23
|
+
.path(["mongo", "documents", "insert"])
|
|
24
|
+
.input(insertInputSchema)
|
|
25
|
+
.output(insertOutputSchema)
|
|
26
|
+
.meta({ description: "Insert one or more documents" })
|
|
27
|
+
.handler(async (input, ctx) => {
|
|
28
|
+
const { collection } = await collectionFor(input, ctx);
|
|
29
|
+
const docs = Array.isArray(input.documents)
|
|
30
|
+
? input.documents
|
|
31
|
+
: [input.documents];
|
|
32
|
+
if (docs.length === 0) {
|
|
33
|
+
return {
|
|
34
|
+
acknowledged: true,
|
|
35
|
+
insertedIds: [],
|
|
36
|
+
insertedCount: 0,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (docs.length === 1) {
|
|
40
|
+
const result = await collection.insertOne(docs[0]);
|
|
41
|
+
return {
|
|
42
|
+
acknowledged: result.acknowledged,
|
|
43
|
+
insertedIds: [String(result.insertedId)],
|
|
44
|
+
insertedCount: result.acknowledged ? 1 : 0,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const result = await collection.insertMany(docs);
|
|
48
|
+
return {
|
|
49
|
+
acknowledged: result.acknowledged,
|
|
50
|
+
insertedIds: Object.values(result.insertedIds).map(String),
|
|
51
|
+
insertedCount: result.insertedCount,
|
|
52
|
+
};
|
|
53
|
+
})
|
|
54
|
+
.build();
|
|
55
|
+
//# sourceMappingURL=documents.insert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.insert.js","sourceRoot":"","sources":["../../src/procedures/documents.insert.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,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAsB,MAAM,aAAa,CAAC;AAcjD,UAAU;AACV,MAAM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I;YAClB,WAAW,EAAE,EAAE;YACf,aAAa,EAAE,CAAC;SACjB,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC;QACpD,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACxC,aAAa,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3C,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;QAC1D,aAAa,EAAE,MAAM,CAAC,aAAa;KACpC,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure: mongo.documents.update
|
|
3
|
+
* Update documents matching a filter
|
|
4
|
+
*/
|
|
5
|
+
import { type Procedure } from "@procedures/client";
|
|
6
|
+
import type { DocumentUpdate } from "../types.js";
|
|
7
|
+
import { type TargetInput } from "./target.js";
|
|
8
|
+
/** The input: exactly one of `id` or `filter`, the update, and the scope fields. */
|
|
9
|
+
interface UpdateInput extends TargetInput {
|
|
10
|
+
/** Update operations */
|
|
11
|
+
update: DocumentUpdate;
|
|
12
|
+
/** Insert if not found */
|
|
13
|
+
upsert?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface UpdateOutput {
|
|
16
|
+
acknowledged: boolean;
|
|
17
|
+
matchedCount: number;
|
|
18
|
+
modifiedCount: number;
|
|
19
|
+
upsertedId: string | null;
|
|
20
|
+
upsertedCount: number;
|
|
21
|
+
}
|
|
22
|
+
export declare const updateProcedure: Procedure<UpdateInput, UpdateOutput, {
|
|
23
|
+
description: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type { UpdateInput, UpdateOutput };
|
|
26
|
+
//# sourceMappingURL=documents.update.d.ts.map
|