@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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Procedures Interface
|
|
3
|
+
*
|
|
4
|
+
* Provides compile-time autocomplete for client-mongo procedures.
|
|
5
|
+
* Import this type and use with a typed caller for full type safety.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type { MongoProcedures } from "@procedures/mongo";
|
|
10
|
+
* import { createTypedCaller } from "@procedures/client";
|
|
11
|
+
*
|
|
12
|
+
* const call = createTypedCaller<MongoProcedures>(client.call);
|
|
13
|
+
*
|
|
14
|
+
* // Full autocomplete on path and input!
|
|
15
|
+
* const result = await call(
|
|
16
|
+
* ["mongo", "documents", "find"],
|
|
17
|
+
* { query: { status: "active" } },
|
|
18
|
+
* { metadata: { collection: "users" } }
|
|
19
|
+
* );
|
|
20
|
+
* // result is typed as FindOutput
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import type { CollectionStats, DatabaseInfo } from "./types.js";
|
|
24
|
+
import type { PingInput, PingOutput } from "./procedures/database.ping.js";
|
|
25
|
+
import type { InfoInput } from "./procedures/database.info.js";
|
|
26
|
+
import type { ListInput as ListCollectionsInput, ListOutput as ListCollectionsOutput } from "./procedures/collections.list.js";
|
|
27
|
+
import type { CreateInput as CreateCollectionInput, CreateOutput as CreateCollectionOutput } from "./procedures/collections.create.js";
|
|
28
|
+
import type { DropInput as DropCollectionInput, DropOutput as DropCollectionOutput } from "./procedures/collections.drop.js";
|
|
29
|
+
import type { StatsInput } from "./procedures/collections.stats.js";
|
|
30
|
+
import type { FindInput, FindOutput } from "./procedures/documents.find.js";
|
|
31
|
+
import type { GetInput, GetOutput } from "./procedures/documents.get.js";
|
|
32
|
+
import type { InsertInput, InsertOutput } from "./procedures/documents.insert.js";
|
|
33
|
+
import type { UpdateInput, UpdateOutput } from "./procedures/documents.update.js";
|
|
34
|
+
import type { DeleteInput, DeleteOutput } from "./procedures/documents.delete.js";
|
|
35
|
+
import type { CountInput, CountOutput } from "./procedures/documents.count.js";
|
|
36
|
+
import type { AggregateInput, AggregateOutput } from "./procedures/documents.aggregate.js";
|
|
37
|
+
import type { ListIndexesInput, ListIndexesOutput } from "./procedures/indexes.list.js";
|
|
38
|
+
import type { CreateIndexInput, CreateIndexOutput } from "./procedures/indexes.create.js";
|
|
39
|
+
import type { DropIndexInput, DropIndexOutput } from "./procedures/indexes.drop.js";
|
|
40
|
+
export type { PingInput, PingOutput, InfoInput, ListCollectionsInput, ListCollectionsOutput, CreateCollectionInput, CreateCollectionOutput, DropCollectionInput, DropCollectionOutput, StatsInput, FindInput, FindOutput, GetInput, GetOutput, InsertInput, InsertOutput, UpdateInput, UpdateOutput, DeleteInput, DeleteOutput, CountInput, CountOutput, AggregateInput, AggregateOutput, ListIndexesInput, ListIndexesOutput, CreateIndexInput, CreateIndexOutput, DropIndexInput, DropIndexOutput, };
|
|
41
|
+
/**
|
|
42
|
+
* Typed interface for all MongoDB procedures.
|
|
43
|
+
* Use with createTypedCaller for compile-time autocomplete.
|
|
44
|
+
*/
|
|
45
|
+
export interface MongoProcedures {
|
|
46
|
+
mongo: {
|
|
47
|
+
database: {
|
|
48
|
+
ping: {
|
|
49
|
+
input: PingInput;
|
|
50
|
+
output: PingOutput;
|
|
51
|
+
};
|
|
52
|
+
info: {
|
|
53
|
+
input: InfoInput;
|
|
54
|
+
output: DatabaseInfo;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
collections: {
|
|
58
|
+
list: {
|
|
59
|
+
input: ListCollectionsInput;
|
|
60
|
+
output: ListCollectionsOutput;
|
|
61
|
+
};
|
|
62
|
+
create: {
|
|
63
|
+
input: CreateCollectionInput;
|
|
64
|
+
output: CreateCollectionOutput;
|
|
65
|
+
};
|
|
66
|
+
drop: {
|
|
67
|
+
input: DropCollectionInput;
|
|
68
|
+
output: DropCollectionOutput;
|
|
69
|
+
};
|
|
70
|
+
stats: {
|
|
71
|
+
input: StatsInput;
|
|
72
|
+
output: CollectionStats;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
documents: {
|
|
76
|
+
find: {
|
|
77
|
+
input: FindInput;
|
|
78
|
+
output: FindOutput;
|
|
79
|
+
};
|
|
80
|
+
get: {
|
|
81
|
+
input: GetInput;
|
|
82
|
+
output: GetOutput;
|
|
83
|
+
};
|
|
84
|
+
insert: {
|
|
85
|
+
input: InsertInput;
|
|
86
|
+
output: InsertOutput;
|
|
87
|
+
};
|
|
88
|
+
update: {
|
|
89
|
+
input: UpdateInput;
|
|
90
|
+
output: UpdateOutput;
|
|
91
|
+
};
|
|
92
|
+
delete: {
|
|
93
|
+
input: DeleteInput;
|
|
94
|
+
output: DeleteOutput;
|
|
95
|
+
};
|
|
96
|
+
count: {
|
|
97
|
+
input: CountInput;
|
|
98
|
+
output: CountOutput;
|
|
99
|
+
};
|
|
100
|
+
aggregate: {
|
|
101
|
+
input: AggregateInput;
|
|
102
|
+
output: AggregateOutput;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
indexes: {
|
|
106
|
+
list: {
|
|
107
|
+
input: ListIndexesInput;
|
|
108
|
+
output: ListIndexesOutput;
|
|
109
|
+
};
|
|
110
|
+
create: {
|
|
111
|
+
input: CreateIndexInput;
|
|
112
|
+
output: CreateIndexOutput;
|
|
113
|
+
};
|
|
114
|
+
drop: {
|
|
115
|
+
input: DropIndexInput;
|
|
116
|
+
output: DropIndexOutput;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Helper type to extract input type from a procedure path
|
|
123
|
+
*/
|
|
124
|
+
export type ProcedureInput<P extends readonly string[]> = P extends ["mongo", "database", "ping"] ? PingInput : P extends ["mongo", "database", "info"] ? InfoInput : P extends ["mongo", "collections", "list"] ? ListCollectionsInput : P extends ["mongo", "collections", "create"] ? CreateCollectionInput : P extends ["mongo", "collections", "drop"] ? DropCollectionInput : P extends ["mongo", "collections", "stats"] ? StatsInput : P extends ["mongo", "documents", "find"] ? FindInput : P extends ["mongo", "documents", "get"] ? GetInput : P extends ["mongo", "documents", "insert"] ? InsertInput : P extends ["mongo", "documents", "update"] ? UpdateInput : P extends ["mongo", "documents", "delete"] ? DeleteInput : P extends ["mongo", "documents", "count"] ? CountInput : P extends ["mongo", "documents", "aggregate"] ? AggregateInput : P extends ["mongo", "indexes", "list"] ? ListIndexesInput : P extends ["mongo", "indexes", "create"] ? CreateIndexInput : P extends ["mongo", "indexes", "drop"] ? DropIndexInput : never;
|
|
125
|
+
/**
|
|
126
|
+
* Helper type to extract output type from a procedure path
|
|
127
|
+
*/
|
|
128
|
+
export type ProcedureOutput<P extends readonly string[]> = P extends ["mongo", "database", "ping"] ? PingOutput : P extends ["mongo", "database", "info"] ? DatabaseInfo : P extends ["mongo", "collections", "list"] ? ListCollectionsOutput : P extends ["mongo", "collections", "create"] ? CreateCollectionOutput : P extends ["mongo", "collections", "drop"] ? DropCollectionOutput : P extends ["mongo", "collections", "stats"] ? CollectionStats : P extends ["mongo", "documents", "find"] ? FindOutput : P extends ["mongo", "documents", "get"] ? GetOutput : P extends ["mongo", "documents", "insert"] ? InsertOutput : P extends ["mongo", "documents", "update"] ? UpdateOutput : P extends ["mongo", "documents", "delete"] ? DeleteOutput : P extends ["mongo", "documents", "count"] ? CountOutput : P extends ["mongo", "documents", "aggregate"] ? AggregateOutput : P extends ["mongo", "indexes", "list"] ? ListIndexesOutput : P extends ["mongo", "indexes", "create"] ? CreateIndexOutput : P extends ["mongo", "indexes", "drop"] ? DropIndexOutput : never;
|
|
129
|
+
//# sourceMappingURL=procedures.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedures.types.d.ts","sourceRoot":"","sources":["../src/procedures.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAShE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,IAAI,oBAAoB,EAAE,UAAU,IAAI,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC/H,OAAO,KAAK,EAAE,WAAW,IAAI,qBAAqB,EAAE,YAAY,IAAI,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACvI,OAAO,KAAK,EAAE,SAAS,IAAI,mBAAmB,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7H,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,M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AAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,eAAe,GACxD,KAAK,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Procedures Interface
|
|
3
|
+
*
|
|
4
|
+
* Provides compile-time autocomplete for client-mongo procedures.
|
|
5
|
+
* Import this type and use with a typed caller for full type safety.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type { MongoProcedures } from "@procedures/mongo";
|
|
10
|
+
* import { createTypedCaller } from "@procedures/client";
|
|
11
|
+
*
|
|
12
|
+
* const call = createTypedCaller<MongoProcedures>(client.call);
|
|
13
|
+
*
|
|
14
|
+
* // Full autocomplete on path and input!
|
|
15
|
+
* const result = await call(
|
|
16
|
+
* ["mongo", "documents", "find"],
|
|
17
|
+
* { query: { status: "active" } },
|
|
18
|
+
* { metadata: { collection: "users" } }
|
|
19
|
+
* );
|
|
20
|
+
* // result is typed as FindOutput
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=procedures.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedures.types.js","sourceRoot":"","sources":["../src/procedures.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/mongo in the global registry
|
|
3
|
+
* (DECISIONS-2026-10, "Every package root registers its procedures"). The procedures as data
|
|
4
|
+
* are in `module.ts`, which registers nothing: a host with its own registry uses that one.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./module.js";
|
|
7
|
+
export declare function registerMongoProcedures(): void;
|
|
8
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,cAAc,aAAa,CAAC;AAE5B,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/mongo in the global registry
|
|
3
|
+
* (DECISIONS-2026-10, "Every package root registers its procedures"). The procedures as data
|
|
4
|
+
* are in `module.ts`, which registers nothing: a host with its own registry uses that one.
|
|
5
|
+
*/
|
|
6
|
+
import { registerProcedures } from "@procedures/client";
|
|
7
|
+
import { mongoModule } from "./module.js";
|
|
8
|
+
export * from "./module.js";
|
|
9
|
+
export function registerMongoProcedures() {
|
|
10
|
+
registerProcedures(mongoModule.procedures);
|
|
11
|
+
}
|
|
12
|
+
// Auto-register when this module is loaded
|
|
13
|
+
registerMongoProcedures();
|
|
14
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,cAAc,aAAa,CAAC;AAE5B,MAAM,UAAU,uBAAuB;IACrC,kBAAkB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED,2CAA2C;AAC3C,uBAAuB,EAAE,CAAC"}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The database and the collection of a call.
|
|
3
|
+
*
|
|
4
|
+
* Each procedure reads `collection` and `database` from its input. The call metadata stays a
|
|
5
|
+
* fallback for the clients that set it. (Before, only the metadata gave them, and an MCP tool
|
|
6
|
+
* call cannot set metadata: deep dive DATA-5.)
|
|
7
|
+
*/
|
|
8
|
+
import type { Collection, Db, Document } from "mongodb";
|
|
9
|
+
import type { ProcedureContext } from "@procedures/client";
|
|
10
|
+
/** The input fields that select the database and the collection. */
|
|
11
|
+
export interface ScopeInput {
|
|
12
|
+
/** The collection name. It takes the place of `metadata.collection`. */
|
|
13
|
+
collection?: string | undefined;
|
|
14
|
+
/** The database name. It takes the place of `metadata.database` and the connection default. */
|
|
15
|
+
database?: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The names of the scope fields, for the input parsers. */
|
|
18
|
+
export declare const SCOPE_FIELDS: readonly ["collection", "database"];
|
|
19
|
+
/** The database name of a call: the input, then the metadata. Undefined means the connection default. */
|
|
20
|
+
export declare function databaseName(input: ScopeInput, ctx: Pick<ProcedureContext, "metadata">): string | undefined;
|
|
21
|
+
/** The collection name of a call: the input, then the metadata. */
|
|
22
|
+
export declare function collectionName(input: ScopeInput, ctx: Pick<ProcedureContext, "metadata">): string;
|
|
23
|
+
/** The database of a call. This function connects first when there is no open connection. */
|
|
24
|
+
export declare function databaseFor(input: ScopeInput, ctx: Pick<ProcedureContext, "metadata">): Promise<Db>;
|
|
25
|
+
/** The collection of a call. This function connects first when there is no open connection. */
|
|
26
|
+
export declare function collectionFor(input: ScopeInput, ctx: Pick<ProcedureContext, "metadata">): Promise<{
|
|
27
|
+
collection: Collection<Document>;
|
|
28
|
+
name: string;
|
|
29
|
+
db: Db;
|
|
30
|
+
}>;
|
|
31
|
+
/** This function copies the scope fields of a raw input into a parsed input. */
|
|
32
|
+
export declare function copyScope(raw: Record<string, unknown>, parsed: ScopeInput): void;
|
|
33
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,oEAAoE;AACpE,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED,4DAA4D;AAC5D,eAAO,MAAM,YAAY,YAAI,YAAY,EAAE,UAAU,CAAU,CAAC;AAUhE,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,MAAM,GAAG,SAAS,CAE3G;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,MAAM,CAMjG;AAED,6FAA6F;AAC7F,wBAAsB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,CAIzG;AAED,+FAA+F;AAC/F,wBAAsB,aAAa,CACjC,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GACtC,OAAO,CAAC;IAAE,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,EAAE,CAAA;CAAE,CAAC,CAIrE;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAKhF"}
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The database and the collection of a call.
|
|
3
|
+
*
|
|
4
|
+
* Each procedure reads `collection` and `database` from its input. The call metadata stays a
|
|
5
|
+
* fallback for the clients that set it. (Before, only the metadata gave them, and an MCP tool
|
|
6
|
+
* call cannot set metadata: deep dive DATA-5.)
|
|
7
|
+
*/
|
|
8
|
+
import { ensureConnection } from "./connection.js";
|
|
9
|
+
/** The names of the scope fields, for the input parsers. */
|
|
10
|
+
export const SCOPE_FIELDS = ["collection", "database"];
|
|
11
|
+
function optionalName(value, field) {
|
|
12
|
+
if (value === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
15
|
+
throw new Error(`${field} must be a non-empty string`);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
/** The database name of a call: the input, then the metadata. Undefined means the connection default. */
|
|
20
|
+
export function databaseName(input, ctx) {
|
|
21
|
+
return optionalName(input.database, "database") ?? optionalName(ctx.metadata["database"], "metadata.database");
|
|
22
|
+
}
|
|
23
|
+
/** The collection name of a call: the input, then the metadata. */
|
|
24
|
+
export function collectionName(input, ctx) {
|
|
25
|
+
const name = optionalName(input.collection, "collection") ?? optionalName(ctx.metadata["collection"], "metadata.collection");
|
|
26
|
+
if (name === undefined) {
|
|
27
|
+
throw new Error("collection is required: give it in the input (or in the call metadata)");
|
|
28
|
+
}
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
/** The database of a call. This function connects first when there is no open connection. */
|
|
32
|
+
export async function databaseFor(input, ctx) {
|
|
33
|
+
const name = databaseName(input, ctx);
|
|
34
|
+
const connection = await ensureConnection();
|
|
35
|
+
return name ? connection.getClient().db(name) : connection.getDb();
|
|
36
|
+
}
|
|
37
|
+
/** The collection of a call. This function connects first when there is no open connection. */
|
|
38
|
+
export async function collectionFor(input, ctx) {
|
|
39
|
+
const name = collectionName(input, ctx);
|
|
40
|
+
const db = await databaseFor(input, ctx);
|
|
41
|
+
return { collection: db.collection(name), name, db };
|
|
42
|
+
}
|
|
43
|
+
/** This function copies the scope fields of a raw input into a parsed input. */
|
|
44
|
+
export function copyScope(raw, parsed) {
|
|
45
|
+
const collection = optionalName(raw["collection"], "collection");
|
|
46
|
+
const database = optionalName(raw["database"], "database");
|
|
47
|
+
if (collection !== undefined)
|
|
48
|
+
parsed.collection = collection;
|
|
49
|
+
if (database !== undefined)
|
|
50
|
+
parsed.database = database;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAUnD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,YAAY,EAAE,UAAU,CAAU,CAAC;AAEhE,SAAS,YAAY,CAAC,KAAc,EAAE,KAAa;IACjD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,GAAuC;IACrF,OAAO,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,CAAC,CAAC;AACjH,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,KAAiB,EAAE,GAAuC;IACvF,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,qBAAqB,C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@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MongoDB Storage Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements CollectionStorage<T> from client-collections, providing MongoDB
|
|
5
|
+
* as a storage backend for the collections framework.
|
|
6
|
+
*/
|
|
7
|
+
import type { CollectionStorage, StorageMetadata } from "@procedures/collections";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration options for MongoStorage.
|
|
10
|
+
*/
|
|
11
|
+
export interface MongoStorageOptions {
|
|
12
|
+
/** MongoDB collection name */
|
|
13
|
+
collection: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* MongoDB implementation of CollectionStorage.
|
|
17
|
+
*
|
|
18
|
+
* Stores items as documents with the structure:
|
|
19
|
+
* { _id: string, data: T }
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const storage = new MongoStorage<User>({ collection: "users" });
|
|
24
|
+
* await storage.set("user-1", { name: "Alice", email: "alice@example.com" });
|
|
25
|
+
* const user = await storage.get("user-1");
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class MongoStorage<T> implements CollectionStorage<T> {
|
|
29
|
+
private readonly collectionName;
|
|
30
|
+
constructor(options: MongoStorageOptions);
|
|
31
|
+
/**
|
|
32
|
+
* The collection, from the current default connection. The storage does not keep it: after a
|
|
33
|
+
* reconnect the old collection belongs to a closed client (deep dive DATA-6).
|
|
34
|
+
*/
|
|
35
|
+
private getCollection;
|
|
36
|
+
get(id: string): Promise<T | undefined>;
|
|
37
|
+
getAll(): Promise<T[]>;
|
|
38
|
+
find(predicate: (item: T) => boolean): Promise<T[]>;
|
|
39
|
+
has(id: string): Promise<boolean>;
|
|
40
|
+
size(): Promise<number>;
|
|
41
|
+
set(id: string, value: T): Promise<void>;
|
|
42
|
+
delete(id: string): Promise<boolean>;
|
|
43
|
+
clear(): Promise<void>;
|
|
44
|
+
setBatch(items: Array<[string, T]>): Promise<void>;
|
|
45
|
+
deleteBatch(ids: string[]): Promise<number>;
|
|
46
|
+
getBatch(ids: string[]): Promise<Map<string, T>>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
getMetadata(): Promise<StorageMetadata>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=mongo-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-storage.d.ts","sourceRoot":"","sources":["../../src/storage/mongo-storage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGlF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;CACpB;AAUD;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY,CAAC,CAAC,CAAE,YAAW,iBAAiB,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAExC,YAAY,OAAO,EAAE,mBAAmB,EAEvC;IAED;;;OAGG;YACW,aAAa;IAKrB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAG5C;IAEK,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAG3B;IAEK,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAGxD;IAEK,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGtC;IAEK,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAE5B;IAEK,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7C;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGzC;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAEK,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAYvD;IAEK,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAQhD;IAEK,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAYrD;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAEK,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC,CAU5C;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MongoDB Storage Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements CollectionStorage<T> from client-collections, providing MongoDB
|
|
5
|
+
* as a storage backend for the collections framework.
|
|
6
|
+
*/
|
|
7
|
+
import { ensureConnection } from "../connection.js";
|
|
8
|
+
/**
|
|
9
|
+
* MongoDB implementation of CollectionStorage.
|
|
10
|
+
*
|
|
11
|
+
* Stores items as documents with the structure:
|
|
12
|
+
* { _id: string, data: T }
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const storage = new MongoStorage<User>({ collection: "users" });
|
|
17
|
+
* await storage.set("user-1", { name: "Alice", email: "alice@example.com" });
|
|
18
|
+
* const user = await storage.get("user-1");
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class MongoStorage {
|
|
22
|
+
collectionName;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.collectionName = options.collection;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The collection, from the current default connection. The storage does not keep it: after a
|
|
28
|
+
* reconnect the old collection belongs to a closed client (deep dive DATA-6).
|
|
29
|
+
*/
|
|
30
|
+
async getCollection() {
|
|
31
|
+
const connection = await ensureConnection();
|
|
32
|
+
return connection.getDb().collection(this.collectionName);
|
|
33
|
+
}
|
|
34
|
+
async get(id) {
|
|
35
|
+
const doc = await (await this.getCollection()).findOne({ _id: id });
|
|
36
|
+
return doc?.data;
|
|
37
|
+
}
|
|
38
|
+
async getAll() {
|
|
39
|
+
const docs = await (await this.getCollection()).find({}).toArray();
|
|
40
|
+
return docs.map((doc) => doc.data);
|
|
41
|
+
}
|
|
42
|
+
async find(predicate) {
|
|
43
|
+
const all = await this.getAll();
|
|
44
|
+
return all.filter(predicate);
|
|
45
|
+
}
|
|
46
|
+
async has(id) {
|
|
47
|
+
const count = await (await this.getCollection()).countDocuments({ _id: id }, { limit: 1 });
|
|
48
|
+
return count > 0;
|
|
49
|
+
}
|
|
50
|
+
async size() {
|
|
51
|
+
return (await this.getCollection()).countDocuments({});
|
|
52
|
+
}
|
|
53
|
+
async set(id, value) {
|
|
54
|
+
await (await this.getCollection()).updateOne({ _id: id }, { $set: { _id: id, data: value } }, { upsert: true });
|
|
55
|
+
}
|
|
56
|
+
async delete(id) {
|
|
57
|
+
const result = await (await this.getCollection()).deleteOne({ _id: id });
|
|
58
|
+
return result.deletedCount > 0;
|
|
59
|
+
}
|
|
60
|
+
async clear() {
|
|
61
|
+
await (await this.getCollection()).deleteMany({});
|
|
62
|
+
}
|
|
63
|
+
async setBatch(items) {
|
|
64
|
+
if (items.length === 0)
|
|
65
|
+
return;
|
|
66
|
+
const operations = items.map(([id, value]) => ({
|
|
67
|
+
updateOne: {
|
|
68
|
+
filter: { _id: id },
|
|
69
|
+
update: { $set: { _id: id, data: value } },
|
|
70
|
+
upsert: true,
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
await (await this.getCollection()).bulkWrite(operations);
|
|
74
|
+
}
|
|
75
|
+
async deleteBatch(ids) {
|
|
76
|
+
if (ids.length === 0)
|
|
77
|
+
return 0;
|
|
78
|
+
const result = await (await this.getCollection()).deleteMany({
|
|
79
|
+
_id: { $in: ids },
|
|
80
|
+
});
|
|
81
|
+
return result.deletedCount;
|
|
82
|
+
}
|
|
83
|
+
async getBatch(ids) {
|
|
84
|
+
if (ids.length === 0)
|
|
85
|
+
return new Map();
|
|
86
|
+
const docs = await (await this.getCollection())
|
|
87
|
+
.find({ _id: { $in: ids } })
|
|
88
|
+
.toArray();
|
|
89
|
+
const result = new Map();
|
|
90
|
+
for (const doc of docs) {
|
|
91
|
+
result.set(String(doc._id), doc.data);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
async close() {
|
|
96
|
+
// The storage keeps no connection state: the connection belongs to the package
|
|
97
|
+
}
|
|
98
|
+
async getMetadata() {
|
|
99
|
+
const size = await this.size();
|
|
100
|
+
return {
|
|
101
|
+
type: "custom",
|
|
102
|
+
size,
|
|
103
|
+
stats: {
|
|
104
|
+
collectionName: this.collectionName,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=mongo-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-storage.js","sourceRoot":"","sources":["../../src/storage/mongo-storage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAA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