@procedures/mongo 0.0.0-stage → 0.2.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1322 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/connection.d.ts +93 -0
  6. package/dist/connection.d.ts.map +1 -0
  7. package/dist/connection.js +147 -0
  8. package/dist/connection.js.map +1 -0
  9. package/dist/index.d.ts +34 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +45 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/module.d.ts +26 -0
  14. package/dist/module.d.ts.map +1 -0
  15. package/dist/module.js +66 -0
  16. package/dist/module.js.map +1 -0
  17. package/dist/procedures/collections.create.d.ts +21 -0
  18. package/dist/procedures/collections.create.d.ts.map +1 -0
  19. package/dist/procedures/collections.create.js +46 -0
  20. package/dist/procedures/collections.create.js.map +1 -0
  21. package/dist/procedures/collections.drop.d.ts +20 -0
  22. package/dist/procedures/collections.drop.d.ts.map +1 -0
  23. package/dist/procedures/collections.drop.js +40 -0
  24. package/dist/procedures/collections.drop.js.map +1 -0
  25. package/dist/procedures/collections.list.d.ts +17 -0
  26. package/dist/procedures/collections.list.d.ts.map +1 -0
  27. package/dist/procedures/collections.list.js +34 -0
  28. package/dist/procedures/collections.list.js.map +1 -0
  29. package/dist/procedures/collections.stats.d.ts +16 -0
  30. package/dist/procedures/collections.stats.d.ts.map +1 -0
  31. package/dist/procedures/collections.stats.js +41 -0
  32. package/dist/procedures/collections.stats.js.map +1 -0
  33. package/dist/procedures/database.info.d.ts +16 -0
  34. package/dist/procedures/database.info.d.ts.map +1 -0
  35. package/dist/procedures/database.info.js +41 -0
  36. package/dist/procedures/database.info.js.map +1 -0
  37. package/dist/procedures/database.ping.d.ts +18 -0
  38. package/dist/procedures/database.ping.d.ts.map +1 -0
  39. package/dist/procedures/database.ping.js +34 -0
  40. package/dist/procedures/database.ping.js.map +1 -0
  41. package/dist/procedures/documents.aggregate.d.ts +20 -0
  42. package/dist/procedures/documents.aggregate.d.ts.map +1 -0
  43. package/dist/procedures/documents.aggregate.js +43 -0
  44. package/dist/procedures/documents.aggregate.js.map +1 -0
  45. package/dist/procedures/documents.count.d.ts +19 -0
  46. package/dist/procedures/documents.count.d.ts.map +1 -0
  47. package/dist/procedures/documents.count.js +32 -0
  48. package/dist/procedures/documents.count.js.map +1 -0
  49. package/dist/procedures/documents.delete.d.ts +18 -0
  50. package/dist/procedures/documents.delete.d.ts.map +1 -0
  51. package/dist/procedures/documents.delete.js +34 -0
  52. package/dist/procedures/documents.delete.js.map +1 -0
  53. package/dist/procedures/documents.find.d.ts +24 -0
  54. package/dist/procedures/documents.find.d.ts.map +1 -0
  55. package/dist/procedures/documents.find.js +106 -0
  56. package/dist/procedures/documents.find.js.map +1 -0
  57. package/dist/procedures/documents.get.d.ts +21 -0
  58. package/dist/procedures/documents.get.d.ts.map +1 -0
  59. package/dist/procedures/documents.get.js +57 -0
  60. package/dist/procedures/documents.get.js.map +1 -0
  61. package/dist/procedures/documents.insert.d.ts +22 -0
  62. package/dist/procedures/documents.insert.d.ts.map +1 -0
  63. package/dist/procedures/documents.insert.js +58 -0
  64. package/dist/procedures/documents.insert.js.map +1 -0
  65. package/dist/procedures/documents.update.d.ts +27 -0
  66. package/dist/procedures/documents.update.d.ts.map +1 -0
  67. package/dist/procedures/documents.update.js +64 -0
  68. package/dist/procedures/documents.update.js.map +1 -0
  69. package/dist/procedures/index.d.ts +21 -0
  70. package/dist/procedures/index.d.ts.map +1 -0
  71. package/dist/procedures/index.js +26 -0
  72. package/dist/procedures/index.js.map +1 -0
  73. package/dist/procedures/indexes.create.d.ts +21 -0
  74. package/dist/procedures/indexes.create.d.ts.map +1 -0
  75. package/dist/procedures/indexes.create.js +48 -0
  76. package/dist/procedures/indexes.create.js.map +1 -0
  77. package/dist/procedures/indexes.drop.d.ts +18 -0
  78. package/dist/procedures/indexes.drop.d.ts.map +1 -0
  79. package/dist/procedures/indexes.drop.js +33 -0
  80. package/dist/procedures/indexes.drop.js.map +1 -0
  81. package/dist/procedures/indexes.list.d.ts +18 -0
  82. package/dist/procedures/indexes.list.d.ts.map +1 -0
  83. package/dist/procedures/indexes.list.js +43 -0
  84. package/dist/procedures/indexes.list.js.map +1 -0
  85. package/dist/procedures/input-schemas.d.ts +45 -0
  86. package/dist/procedures/input-schemas.d.ts.map +1 -0
  87. package/dist/procedures/input-schemas.js +52 -0
  88. package/dist/procedures/input-schemas.js.map +1 -0
  89. package/dist/procedures/schema.d.ts +2 -0
  90. package/dist/procedures/schema.d.ts.map +1 -0
  91. package/dist/procedures/schema.js +2 -0
  92. package/dist/procedures/schema.js.map +1 -0
  93. package/dist/procedures/target.d.ts +44 -0
  94. package/dist/procedures/target.d.ts.map +1 -0
  95. package/dist/procedures/target.js +98 -0
  96. package/dist/procedures/target.js.map +1 -0
  97. package/dist/procedures.types.d.ts +129 -0
  98. package/dist/procedures.types.d.ts.map +1 -0
  99. package/dist/procedures.types.js +24 -0
  100. package/dist/procedures.types.js.map +1 -0
  101. package/dist/register.d.ts +7 -0
  102. package/dist/register.d.ts.map +1 -0
  103. package/dist/register.js +9 -0
  104. package/dist/register.js.map +1 -0
  105. package/dist/scope.d.ts +33 -0
  106. package/dist/scope.d.ts.map +1 -0
  107. package/dist/scope.js +52 -0
  108. package/dist/scope.js.map +1 -0
  109. package/dist/storage/index.d.ts +6 -0
  110. package/dist/storage/index.d.ts.map +1 -0
  111. package/dist/storage/index.js +5 -0
  112. package/dist/storage/index.js.map +1 -0
  113. package/dist/storage/mongo-storage.d.ts +50 -0
  114. package/dist/storage/mongo-storage.d.ts.map +1 -0
  115. package/dist/storage/mongo-storage.js +109 -0
  116. package/dist/storage/mongo-storage.js.map +1 -0
  117. package/dist/types.d.ts +239 -0
  118. package/dist/types.d.ts.map +1 -0
  119. package/dist/types.js +58 -0
  120. package/dist/types.js.map +1 -0
  121. package/package.json +84 -3
  122. package/src/connection.ts +198 -0
  123. package/src/index.ts +159 -0
  124. package/src/module.ts +71 -0
  125. package/src/procedures/collections.create.ts +72 -0
  126. package/src/procedures/collections.drop.ts +66 -0
  127. package/src/procedures/collections.list.ts +56 -0
  128. package/src/procedures/collections.stats.ts +60 -0
  129. package/src/procedures/database.info.ts +61 -0
  130. package/src/procedures/database.ping.ts +57 -0
  131. package/src/procedures/documents.aggregate.ts +72 -0
  132. package/src/procedures/documents.count.ts +55 -0
  133. package/src/procedures/documents.delete.ts +57 -0
  134. package/src/procedures/documents.find.ts +151 -0
  135. package/src/procedures/documents.get.ts +102 -0
  136. package/src/procedures/documents.insert.ts +86 -0
  137. package/src/procedures/documents.update.ts +96 -0
  138. package/src/procedures/index.ts +30 -0
  139. package/src/procedures/indexes.create.ts +74 -0
  140. package/src/procedures/indexes.drop.ts +56 -0
  141. package/src/procedures/indexes.list.ts +67 -0
  142. package/src/procedures/input-schemas.ts +63 -0
  143. package/src/procedures/schema.ts +1 -0
  144. package/src/procedures/target.ts +123 -0
  145. package/src/procedures.types.ts +162 -0
  146. package/src/register.ts +11 -0
  147. package/src/scope.ts +69 -0
  148. package/src/storage/index.ts +6 -0
  149. package/src/storage/mongo-storage.ts +151 -0
  150. package/src/types.ts +337 -0
@@ -0,0 +1,147 @@
1
+ /**
2
+ * MongoDB connection management for client-mongo
3
+ *
4
+ * Supports:
5
+ * - Environment variable configuration (MONGODB_URI, MONGODB_DATABASE)
6
+ * - Programmatic configuration
7
+ * - Singleton pattern for default connection
8
+ * - Multiple connections for multi-tenant scenarios
9
+ */
10
+ import { MongoClient, Db } from "mongodb";
11
+ // Default connection singleton
12
+ let defaultConnection = null;
13
+ /**
14
+ * Set the default connection used by procedures
15
+ */
16
+ export function setDefaultConnection(conn) {
17
+ defaultConnection = conn;
18
+ }
19
+ /**
20
+ * Get the default connection
21
+ * @throws Error if no connection has been established
22
+ */
23
+ export function getDefaultConnection() {
24
+ if (!defaultConnection) {
25
+ throw new Error("MongoDB connection not initialized. Call connect() first.");
26
+ }
27
+ return defaultConnection;
28
+ }
29
+ /**
30
+ * Check if a default connection exists
31
+ */
32
+ export function hasDefaultConnection() {
33
+ return defaultConnection !== null;
34
+ }
35
+ /**
36
+ * Create and connect to MongoDB
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Using environment variables
41
+ * await connect();
42
+ *
43
+ * // With explicit options
44
+ * await connect({
45
+ * uri: "mongodb://localhost:27017",
46
+ * database: "myapp"
47
+ * });
48
+ * ```
49
+ */
50
+ export async function connect(options = {}) {
51
+ const uri = options.uri ?? process.env["MONGODB_URI"] ?? "mongodb://localhost:27017";
52
+ const database = options.database ?? process.env["MONGODB_DATABASE"] ?? "test";
53
+ const client = new MongoClient(uri, options.clientOptions);
54
+ await client.connect();
55
+ // Close any previous default connection before replacing it. Without this,
56
+ // the prior MongoClient (and its connection pool) is orphaned open and leaks
57
+ // on every call to connect() (e.g. repeated server.mongo.start invocations).
58
+ const previousConnection = defaultConnection;
59
+ let connected = true;
60
+ const connection = {
61
+ getDb: () => {
62
+ if (!connected) {
63
+ throw new Error("Connection has been closed");
64
+ }
65
+ return client.db(database);
66
+ },
67
+ getClient: () => {
68
+ if (!connected) {
69
+ throw new Error("Connection has been closed");
70
+ }
71
+ return client;
72
+ },
73
+ connect: async () => {
74
+ // Already connected
75
+ },
76
+ disconnect: async () => {
77
+ if (connected) {
78
+ await client.close();
79
+ connected = false;
80
+ }
81
+ },
82
+ isConnected: () => connected,
83
+ };
84
+ setDefaultConnection(connection);
85
+ if (previousConnection && previousConnection !== connection) {
86
+ try {
87
+ await previousConnection.disconnect();
88
+ }
89
+ catch {
90
+ // Best effort: ignore errors closing the stale connection so a failure
91
+ // to close the old client never breaks establishing the new one.
92
+ }
93
+ }
94
+ return connection;
95
+ }
96
+ // The options of the connection that ensureConnection() makes, and its attempt in progress
97
+ let lazyOptions = {};
98
+ let pending = null;
99
+ /**
100
+ * Set the options of the connection that the procedures make on their first call.
101
+ * The defaults are the `MONGODB_URI` and `MONGODB_DATABASE` environment variables.
102
+ */
103
+ export function configure(options) {
104
+ lazyOptions = options;
105
+ }
106
+ /**
107
+ * Get the default connection, and connect first when there is no open one.
108
+ *
109
+ * The procedures call this function, so a host does not have to call `connect()`. (Before,
110
+ * nothing called `connect()`, and each `mongo.*` tool of the MCP server failed: deep dive DATA-5.)
111
+ * Concurrent first calls share one connection attempt.
112
+ */
113
+ export function ensureConnection() {
114
+ if (defaultConnection?.isConnected()) {
115
+ return Promise.resolve(defaultConnection);
116
+ }
117
+ if (!pending) {
118
+ pending = connect(lazyOptions).finally(() => {
119
+ pending = null;
120
+ });
121
+ }
122
+ return pending;
123
+ }
124
+ /**
125
+ * Disconnect the default connection
126
+ */
127
+ export async function disconnect() {
128
+ if (defaultConnection) {
129
+ await defaultConnection.disconnect();
130
+ defaultConnection = null;
131
+ }
132
+ }
133
+ /**
134
+ * Get the database from the default connection
135
+ * Convenience function for procedure handlers
136
+ */
137
+ export function getDb() {
138
+ return getDefaultConnection().getDb();
139
+ }
140
+ /**
141
+ * Get the MongoClient from the default connection
142
+ * Convenience function for advanced operations
143
+ */
144
+ export function getClient() {
145
+ return getDefaultConnection().getClient();
146
+ }
147
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,EAAE,EAA2B,MAAM,SAAS,CAAC;AA8BnE,+BAA+B;AAC/B,IAAI,iBAAiB,GAA2B,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAqB;IACxD,iBAAiB,GAAG,IAAI,CAAC;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,2DAA2D,CA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ACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,oBAAoB,EAAE,CAAC,SAAS,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @procedures/mongo
3
+ *
4
+ * MongoDB client wrapper with client procedures for RPC access.
5
+ * Use locally with direct MongoDB connection or remotely via client.call().
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Local usage: the first call connects (MONGODB_URI, or configure())
10
+ * import { configure } from "@procedures/mongo";
11
+ *
12
+ * configure({ uri: "mongodb://localhost:27017", database: "myapp" });
13
+ *
14
+ * // Via RPC client
15
+ * import { Client } from "client";
16
+ *
17
+ * const result = await client.call(
18
+ * ["mongo", "documents", "find"],
19
+ * { collection: "users", query: { status: "active" }, limit: 10 },
20
+ * );
21
+ * ```
22
+ */
23
+ export { connect, configure, ensureConnection, disconnect, getDb, getClient, getDefaultConnection, setDefaultConnection, hasDefaultConnection, } from "./connection.js";
24
+ export type { MongoConnection, MongoConnectionOptions } from "./connection.js";
25
+ export type { ScopeInput } from "./scope.js";
26
+ export { hasCollection, requireCollection, getBaseMeta, } from "./types.js";
27
+ export type { MongoProcedures, ProcedureInput, ProcedureOutput, 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, } from "./procedures.types.js";
28
+ export type { PaginationInput, PaginationOutput, SortOrder, SortSpec, DocumentId, BaseDocument, MongoDocument, DocumentQuery, DocumentUpdate, BaseMeta, CollectionMeta, BulkInsertOne, BulkUpdateOne, BulkDeleteOne, BulkOperation, BulkWriteResult, IndexSpec, IndexOptions, IndexInfo, CollectionOptions, CollectionStats, DatabaseInfo, AggregationStage, AggregationOptions, } from "./types.js";
29
+ export { MongoStorage } from "./storage/index.js";
30
+ export type { MongoStorageOptions } from "./storage/index.js";
31
+ export { registerMongoProcedures, procedures } from "./module.js";
32
+ export * from "./procedures/index.js";
33
+ export type { Db, Collection, Document, ObjectId, Filter, UpdateFilter, FindOptions, AggregateOptions, } from "mongodb";
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,EACL,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7C,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,eAAe,EACf,cAAc,EACd,eAAe,EAEf,SAAS,EACT,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,EACT,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EAEV,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,QAAQ,EAER,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EAEd,QAAQ,EACR,cAAc,EAEd,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EAEf,SAAS,EACT,YAAY,EACZ,SAAS,EAET,iBAAiB,EACjB,eAAe,EAEf,YAAY,EAEZ,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAM9D,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMlE,cAAc,uBAAuB,CAAC;AAMtC,YAAY,EACV,EAAE,EACF,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,WAAW,EACX,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @procedures/mongo
3
+ *
4
+ * MongoDB client wrapper with client procedures for RPC access.
5
+ * Use locally with direct MongoDB connection or remotely via client.call().
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Local usage: the first call connects (MONGODB_URI, or configure())
10
+ * import { configure } from "@procedures/mongo";
11
+ *
12
+ * configure({ uri: "mongodb://localhost:27017", database: "myapp" });
13
+ *
14
+ * // Via RPC client
15
+ * import { Client } from "client";
16
+ *
17
+ * const result = await client.call(
18
+ * ["mongo", "documents", "find"],
19
+ * { collection: "users", query: { status: "active" }, limit: 10 },
20
+ * );
21
+ * ```
22
+ */
23
+ // =============================================================================
24
+ // Connection Management
25
+ // =============================================================================
26
+ export { connect, configure, ensureConnection, disconnect, getDb, getClient, getDefaultConnection, setDefaultConnection, hasDefaultConnection, } from "./connection.js";
27
+ // =============================================================================
28
+ // Types
29
+ // =============================================================================
30
+ export {
31
+ // Type guards
32
+ hasCollection, requireCollection, getBaseMeta, } from "./types.js";
33
+ // =============================================================================
34
+ // Storage (CollectionStorage implementation)
35
+ // =============================================================================
36
+ export { MongoStorage } from "./storage/index.js";
37
+ // =============================================================================
38
+ // Procedure Registration
39
+ // =============================================================================
40
+ export { registerMongoProcedures, procedures } from "./module.js";
41
+ // =============================================================================
42
+ // Individual Procedures (for direct import if needed)
43
+ // =============================================================================
44
+ export * from "./procedures/index.js";
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF,OAAO,EACL,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAKzB,gFAAgF;AAChF,QAAQ;AACR,gFAAgF;AAEhF,OAAO;AACL,cAAc;AACd,aAAa,EACb,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AA2EpB,gFAAgF;AAChF,6CAA6C;AAC7C,gFAAgF;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,gFAAgF;AAChF,yBAAyB;AACzB,gFAAgF;AAEhF,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAElE,gFAAgF;AAChF,sDAAsD;AACtD,gFAAgF;AAEhF,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Module (no side effects): the procedures of this package as data, for `createRegistry()`.
3
+ *
4
+ * Procedure Registration
5
+ *
6
+ * Registers MongoDB procedures with the client system.
7
+ * This file is referenced by package.json's client.procedures field.
8
+ */
9
+ import { type AnyProcedure, type ProcedureModule, type ProcedureRegistry } from "@procedures/client";
10
+ /**
11
+ * All MongoDB procedures
12
+ */
13
+ export declare const procedures: readonly AnyProcedure[];
14
+ /**
15
+ * The module of this package, for `createRegistry()`: its procedures as data. Importing this
16
+ * file registers nothing. (`register.ts` registers the same procedures in the global registry.)
17
+ */
18
+ export declare const mongoModule: ProcedureModule;
19
+ export default mongoModule;
20
+ /**
21
+ * This function registers the procedures of @procedures/mongo, and of the modules that it requires, in
22
+ * a registry. The default is the global registry. Importing this file registers nothing: the
23
+ * `./register` entry starts this function (ARCHITECTURE-PROPOSALS-2026-10, P9).
24
+ */
25
+ export declare function registerMongoProcedures(registry?: ProcedureRegistry): void;
26
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAgB,KAAK,eAAe,EAAuC,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAoBxJ;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,YAAY,EAqB7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,eAAoE,CAAC;eAEhF,WAAW;AAE1B;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,GAAE,iBAAsC,GAAG,IAAI,CAE9F"}
package/dist/module.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Module (no side effects): the procedures of this package as data, for `createRegistry()`.
3
+ *
4
+ * Procedure Registration
5
+ *
6
+ * Registers MongoDB procedures with the client system.
7
+ * This file is referenced by package.json's client.procedures field.
8
+ */
9
+ import { defineModule, PROCEDURE_REGISTRY, registerModules } from "@procedures/client";
10
+ // Import all procedures
11
+ import { pingProcedure } from "./procedures/database.ping.js";
12
+ import { infoProcedure } from "./procedures/database.info.js";
13
+ import { listProcedure } from "./procedures/collections.list.js";
14
+ import { createCollectionProcedure } from "./procedures/collections.create.js";
15
+ import { dropProcedure } from "./procedures/collections.drop.js";
16
+ import { statsProcedure } from "./procedures/collections.stats.js";
17
+ import { findProcedure } from "./procedures/documents.find.js";
18
+ import { getProcedure } from "./procedures/documents.get.js";
19
+ import { insertProcedure } from "./procedures/documents.insert.js";
20
+ import { updateProcedure } from "./procedures/documents.update.js";
21
+ import { deleteProcedure } from "./procedures/documents.delete.js";
22
+ import { countProcedure } from "./procedures/documents.count.js";
23
+ import { aggregateProcedure } from "./procedures/documents.aggregate.js";
24
+ import { listIndexesProcedure } from "./procedures/indexes.list.js";
25
+ import { createIndexProcedure } from "./procedures/indexes.create.js";
26
+ import { dropIndexProcedure } from "./procedures/indexes.drop.js";
27
+ /**
28
+ * All MongoDB procedures
29
+ */
30
+ export const procedures = [
31
+ // Database
32
+ pingProcedure,
33
+ infoProcedure,
34
+ // Collections
35
+ listProcedure,
36
+ createCollectionProcedure,
37
+ dropProcedure,
38
+ statsProcedure,
39
+ // Documents
40
+ findProcedure,
41
+ getProcedure,
42
+ insertProcedure,
43
+ updateProcedure,
44
+ deleteProcedure,
45
+ countProcedure,
46
+ aggregateProcedure,
47
+ // Indexes
48
+ listIndexesProcedure,
49
+ createIndexProcedure,
50
+ dropIndexProcedure,
51
+ ];
52
+ /**
53
+ * The module of this package, for `createRegistry()`: its procedures as data. Importing this
54
+ * file registers nothing. (`register.ts` registers the same procedures in the global registry.)
55
+ */
56
+ export const mongoModule = defineModule("@procedures/mongo", [...procedures]);
57
+ export default mongoModule;
58
+ /**
59
+ * This function registers the procedures of @procedures/mongo, and of the modules that it requires, in
60
+ * a registry. The default is the global registry. Importing this file registers nothing: the
61
+ * `./register` entry starts this function (ARCHITECTURE-PROPOSALS-2026-10, P9).
62
+ */
63
+ export function registerMongoProcedures(registry = PROCEDURE_REGISTRY) {
64
+ registerModules(registry, [mongoModule]);
65
+ }
66
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;;;GA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;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAoB,YAAY,CAAC,mBAAmB,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;AAE/F,eAAe,WAAW,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAQ,GAAsB,kBAAkB;IACtF,eAAe,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Procedure: mongo.collections.create
3
+ * Create a new collection
4
+ */
5
+ import { type Effects, type Procedure } from "@procedures/client";
6
+ import { type ScopeInput } from "../scope.js";
7
+ import { type CollectionOptions } from "../types.js";
8
+ interface CreateInput extends ScopeInput {
9
+ name: string;
10
+ options?: CollectionOptions | undefined;
11
+ }
12
+ interface CreateOutput {
13
+ acknowledged: boolean;
14
+ collectionName: string;
15
+ }
16
+ export declare const createCollectionProcedure: Procedure<CreateInput, CreateOutput, {
17
+ description: string;
18
+ effects?: Effects;
19
+ }>;
20
+ export type { CreateInput, CreateOutput };
21
+ //# sourceMappingURL=collections.create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.create.d.ts","sourceRoot":"","sources":["../../src/procedures/collections.create.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAI3D,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,UAAU,WAAY,SAAQ,UAAU;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CACzC;AAED,UAAU,YAAY;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAyBD,eAAO,MAAM,yBAAyB,EAAE,SAAS,CAC/C,WAAW,EACX,YAAY,EACZ;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAoBlC,CAAC;AAEX,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Procedure: mongo.collections.create
3
+ * Create a new collection
4
+ */
5
+ import { createProcedure, zodAdapter } from "@procedures/client";
6
+ import { databaseFor } 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 createInputSchema = zodAdapter(z.object({
12
+ ...scopeFields(),
13
+ name: z.string().min(1).describe("The name of the new collection"),
14
+ options: z
15
+ .looseObject({
16
+ capped: z.boolean().optional().describe("Make a capped collection"),
17
+ size: z.number().optional().describe("The maximum size in bytes (capped collections)"),
18
+ max: z.number().optional().describe("The maximum number of documents (capped collections)"),
19
+ validator: documentObject().optional().describe("A validator document (for example a $jsonSchema)"),
20
+ })
21
+ .optional()
22
+ .describe("The options of the collection"),
23
+ }));
24
+ const createOutputSchema = zodAdapter(z.looseObject({
25
+ acknowledged: z.boolean().describe("True when the server confirmed the write"),
26
+ collectionName: z.string().describe("The name of the new collection"),
27
+ }));
28
+ export const createCollectionProcedure = createProcedure()
29
+ .path(["mongo", "collections", "create"])
30
+ .input(createInputSchema)
31
+ .output(createOutputSchema)
32
+ .meta({
33
+ description: "Create a new collection",
34
+ effects: { reads: ["mongo", "network"], writes: ["mongo", "network"], destructive: false },
35
+ })
36
+ .handler(async (input, ctx) => {
37
+ const db = await databaseFor(input, ctx);
38
+ // The schema leaves out an option that the input does not give: no option is undefined at run time
39
+ await db.createCollection(input.name, input.options);
40
+ return {
41
+ acknowledged: true,
42
+ collectionName: input.name,
43
+ };
44
+ })
45
+ .build();
46
+ //# sourceMappingURL=collections.create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.create.js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,CAAC;CACtE,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAIlC,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;KACxC,KAAK,CAAC,iBAAiB,CAAC;KACxB,MAAM,CAAC,kBAAkB,CAAC;KAC1B,IAAI,CAAC;IACJ,WAAW,EAAE,yBAAyB;IACtC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE;CAC3F,CAAC;KACD,OAAO,CAAC,KAAK,EAAE,KAAkB,EAAE,GAAqB,EAAE,EAAE;IAC3D,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEzC,mGAAmG;IACnG,MAAM,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAA8C,CAAC,CAAC;IAE5F,OAAO;QACL,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,KAAK,CAAC,IAAI;KAC3B,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Procedure: mongo.collections.drop
3
+ * Drop (delete) a collection
4
+ */
5
+ import { type Effects, type Procedure } from "@procedures/client";
6
+ import { type ScopeInput } from "../scope.js";
7
+ interface DropInput extends ScopeInput {
8
+ /** Confirmation required to prevent accidental drops */
9
+ confirm: boolean;
10
+ }
11
+ interface DropOutput {
12
+ acknowledged: boolean;
13
+ dropped: boolean;
14
+ }
15
+ export declare const dropProcedure: Procedure<DropInput, DropOutput, {
16
+ description: string;
17
+ effects?: Effects;
18
+ }>;
19
+ export type { DropInput, DropOutput };
20
+ //# sourceMappingURL=collections.drop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.drop.d.ts","sourceRoot":"","sources":["../../src/procedures/collections.drop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAK3E,UAAU,SAAU,SAAQ,UAAU;IACpC,wDAAwD;IACxD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,UAAU;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;CAClB;AAgBD,eAAO,MAAM,aAAa,EAAE,SAAS,CACnC,SAAS,EACT,UAAU,EACV;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAyBlC,CAAC;AAEX,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Procedure: mongo.collections.drop
3
+ * Drop (delete) a collection
4
+ */
5
+ import { createProcedure, zodAdapter } from "@procedures/client";
6
+ import { collectionName, databaseFor } from "../scope.js";
7
+ import { scopeFields } from "./input-schemas.js";
8
+ import { z } from "zod";
9
+ // Schemas
10
+ const dropInputSchema = zodAdapter(z.object({
11
+ ...scopeFields(),
12
+ confirm: z.boolean().describe("Set to true to drop the collection and all of its documents"),
13
+ }));
14
+ const dropOutputSchema = zodAdapter(z.looseObject({
15
+ acknowledged: z.boolean().describe("True when the server confirmed the write"),
16
+ dropped: z.boolean().describe("False when the collection did not exist"),
17
+ }));
18
+ export const dropProcedure = createProcedure()
19
+ .path(["mongo", "collections", "drop"])
20
+ .input(dropInputSchema)
21
+ .output(dropOutputSchema)
22
+ .meta({
23
+ description: "Drop (delete) a collection",
24
+ // The drop of a missing collection is not an error: it gives dropped: false
25
+ effects: { reads: ["mongo", "network"], writes: ["mongo", "network"], idempotent: true },
26
+ })
27
+ .handler(async (input, ctx) => {
28
+ const name = collectionName(input, ctx);
29
+ if (!input.confirm) {
30
+ throw new Error("confirm must be true to drop a collection");
31
+ }
32
+ const db = await databaseFor(input, ctx);
33
+ const dropped = await db.dropCollection(name);
34
+ return {
35
+ acknowledged: true,
36
+ dropped,
37
+ };
38
+ })
39
+ .build();
40
+ //# sourceMappingURL=collections.drop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.drop.js","sourceRoot":"","sources":["../../src/procedures/collections.drop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAuD,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,UAAU;AACV,MAAM,eAAe,GAAG,UAAU,CAChC,CAAC,CAAC,MAAM,CAAC;IACP,GAAG,WAAW,EAAE;IAChB,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,6DAA6D,CAAC;CAC7F,CAAC,CACH,CAAC;AACF,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,CAAC,WAAW,CAAC;IACZ,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;IAC9E,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,yCAAyC,CAAC;CACzE,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAItB,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;KACtC,KAAK,CAAC,eAAe,CAAC;KACtB,MAAM,CAAC,gBAAgB,CAAC;KACxB,IAAI,CAAC;IACJ,WAAW,EAAE,4BAA4B;IACzC,4EAA4E;IAC5E,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CACzF,CAAC;KACD,OAAO,CAAC,KAAK,EAAE,KAAgB,EAAE,GAAqB,EAAE,EAAE;IACzD,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAExC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAE9C,OAAO;QACL,YAAY,EAAE,IAAI;QAClB,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Procedure: mongo.collections.list
3
+ * List all collections in the database
4
+ */
5
+ import { type Effects, type Procedure } from "@procedures/client";
6
+ import { type ScopeInput } from "../scope.js";
7
+ /** The input: only the scope fields. */
8
+ type ListInput = ScopeInput;
9
+ interface ListOutput {
10
+ collections: string[];
11
+ }
12
+ export declare const listProcedure: Procedure<ListInput, ListOutput, {
13
+ description: string;
14
+ effects?: Effects;
15
+ }>;
16
+ export type { ListInput, ListOutput };
17
+ //# sourceMappingURL=collections.list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.list.d.ts","sourceRoot":"","sources":["../../src/procedures/collections.list.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAK3D,wCAAwC;AACxC,KAAK,SAAS,GAAG,UAAU,CAAC;AAE5B,UAAU,UAAU;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAYD,eAAO,MAAM,aAAa,EAAE,SAAS,CACnC,SAAS,EACT,UAAU,EACV;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAsBlC,CAAC;AAEX,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Procedure: mongo.collections.list
3
+ * List all collections in the database
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 listInputSchema = zodAdapter(z.object({ ...scopeFields() }));
11
+ const listOutputSchema = zodAdapter(z.looseObject({
12
+ collections: z.array(z.string()).describe("The collection names of the database"),
13
+ }));
14
+ export const listProcedure = createProcedure()
15
+ .path(["mongo", "collections", "list"])
16
+ .input(listInputSchema)
17
+ .output(listOutputSchema)
18
+ .meta({
19
+ description: "List all collections in the database",
20
+ effects: { reads: ["mongo", "network"], writes: [] },
21
+ })
22
+ .handler(async (input, ctx) => {
23
+ const db = await databaseFor(input, ctx);
24
+ const collections = await db.listCollections().toArray();
25
+ const collectionNames = collections
26
+ .filter((c) => c.type === "collection")
27
+ .map((c) => c.name)
28
+ .sort();
29
+ return {
30
+ collections: collectionNames,
31
+ };
32
+ })
33
+ .build();
34
+ //# sourceMappingURL=collections.list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.list.js","sourceRoot":"","sources":["../../src/procedures/collections.list.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAuD,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAA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1,16 @@
1
+ /**
2
+ * Procedure: mongo.collections.stats
3
+ * Get collection statistics
4
+ */
5
+ import { type Effects, type Procedure } from "@procedures/client";
6
+ import { type ScopeInput } from "../scope.js";
7
+ import type { CollectionStats } from "../types.js";
8
+ /** The input: only the scope fields. */
9
+ type StatsInput = ScopeInput;
10
+ export declare const statsProcedure: Procedure<StatsInput, CollectionStats, {
11
+ description: string;
12
+ effects?: Effects;
13
+ }>;
14
+ export type { StatsInput };
15
+ export type StatsOutput = CollectionStats;
16
+ //# sourceMappingURL=collections.stats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.stats.d.ts","sourceRoot":"","sources":["../../src/procedures/collections.stats.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+B,KAAK,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,wCAAwC;AACxC,KAAK,UAAU,GAAG,UAAU,CAAC;AAiB7B,eAAO,MAAM,cAAc,EAAE,SAAS,CACpC,UAAU,EACV,eAAe,EACf;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAuBlC,CAAC;AAEX,YAAY,EAAE,UAAU,EAAE,CAAC;AAC3B,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Procedure: mongo.collections.stats
3
+ * Get collection statistics
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 statsInputSchema = zodAdapter(z.object({ ...scopeFields() }));
11
+ const statsOutputSchema = zodAdapter(z.looseObject({
12
+ count: z.number().describe("The number of documents"),
13
+ size: z.number().describe("The size of the documents, in bytes"),
14
+ avgObjSize: z.number().describe("The average size of a document, in bytes"),
15
+ storageSize: z.number().describe("The storage size, in bytes"),
16
+ nindexes: z.number().describe("The number of indexes"),
17
+ totalIndexSize: z.number().describe("The size of the indexes, in bytes"),
18
+ }));
19
+ export const statsProcedure = createProcedure()
20
+ .path(["mongo", "collections", "stats"])
21
+ .input(statsInputSchema)
22
+ .output(statsOutputSchema)
23
+ .meta({
24
+ description: "Get collection statistics",
25
+ effects: { reads: ["mongo", "network"], writes: [] },
26
+ })
27
+ .handler(async (input, ctx) => {
28
+ const { db, name } = await collectionFor(input, ctx);
29
+ // Use collStats command since stats() is deprecated
30
+ const stats = await db.command({ collStats: name });
31
+ return {
32
+ count: stats["count"] ?? 0,
33
+ size: stats["size"] ?? 0,
34
+ avgObjSize: stats["avgObjSize"] ?? 0,
35
+ storageSize: stats["storageSize"] ?? 0,
36
+ nindexes: stats["nindexes"] ?? 0,
37
+ totalIndexSize: stats["totalIndexSize"] ?? 0,
38
+ };
39
+ })
40
+ .build();
41
+ //# sourceMappingURL=collections.stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.stats.js","sourceRoot":"","sources":["../../src/procedures/collections.stats.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAuD,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,UAAU;AACV,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,EAAE,CAAC,CAC/B,CAAC;AACF,MAAM,iBAAiB,GAAG,UAAU,CAClC,CAAC,CAAC,WAAW,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC,MAAM,E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,EAAG,KAAK,CAAC,aAAa,CAAY,IAAI,CAAC;QAClD,QAAQ,EAAG,KAAK,CAAC,UAAU,CAAY,IAAI,CAAC;QAC5C,cAAc,EAAG,KAAK,CAAC,gBAAgB,CAAY,IAAI,CAAC;KACzD,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Procedure: mongo.database.info
3
+ * Get database information and statistics
4
+ */
5
+ import { type Effects, type Procedure } from "@procedures/client";
6
+ import { type ScopeInput } from "../scope.js";
7
+ import { type DatabaseInfo } from "../types.js";
8
+ /** The input: only the scope fields. */
9
+ type InfoInput = ScopeInput;
10
+ export declare const infoProcedure: Procedure<InfoInput, DatabaseInfo, {
11
+ description: string;
12
+ effects?: Effects;
13
+ }>;
14
+ export type { InfoInput };
15
+ export type InfoOutput = DatabaseInfo;
16
+ //# sourceMappingURL=database.info.d.ts.map