@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,98 @@
1
+ /**
2
+ * The target of a write: one document by `id`, or the documents that match a `filter`.
3
+ *
4
+ * Before, a call without `id` and `filter` used the filter `{}`, and the field name of
5
+ * `find`/`count` (`query`) was ignored: `delete { query, multi: true }` emptied the
6
+ * collection (deep dive DATA-4). Now a write needs exactly one target, an unknown field is an
7
+ * error, and an empty filter needs `confirm: true`.
8
+ */
9
+ import { ObjectId } from "mongodb";
10
+ import { buildIdFilter } from "../types.js";
11
+ import { SCOPE_FIELDS, copyScope } from "../scope.js";
12
+ const TARGET_FIELDS = ["filter", "id", "idType", "multi", "confirm", ...SCOPE_FIELDS];
13
+ function isPlainObject(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ function optionalBoolean(procedure, raw, field) {
17
+ const value = raw[field];
18
+ if (value === undefined)
19
+ return undefined;
20
+ if (typeof value !== "boolean")
21
+ throw new Error(`${procedure}: ${field} must be a boolean`);
22
+ return value;
23
+ }
24
+ /**
25
+ * This function reads and checks the target fields of a write input.
26
+ * `extraFields` are the other fields that the procedure accepts.
27
+ */
28
+ export function parseTarget(procedure, data, extraFields = []) {
29
+ if (!isPlainObject(data)) {
30
+ throw new Error(`${procedure}: input must be an object`);
31
+ }
32
+ const raw = data;
33
+ const allowed = new Set([...TARGET_FIELDS, ...extraFields]);
34
+ for (const key of Object.keys(raw)) {
35
+ if (!allowed.has(key)) {
36
+ const hint = key === "query" ? ' Use "filter".' : "";
37
+ throw new Error(`${procedure}: unknown field "${key}".${hint} The fields are: ${[...allowed].join(", ")}`);
38
+ }
39
+ }
40
+ const hasId = raw["id"] !== undefined;
41
+ const hasFilter = raw["filter"] !== undefined;
42
+ if (hasId === hasFilter) {
43
+ throw new Error(`${procedure}: give exactly one of id or filter`);
44
+ }
45
+ const target = {};
46
+ copyScope(raw, target);
47
+ if (hasId) {
48
+ const id = raw["id"];
49
+ if (typeof id !== "string" || id.length === 0) {
50
+ throw new Error(`${procedure}: id must be a non-empty string`);
51
+ }
52
+ target.id = id;
53
+ }
54
+ else {
55
+ const filter = raw["filter"];
56
+ if (!isPlainObject(filter)) {
57
+ throw new Error(`${procedure}: filter must be an object`);
58
+ }
59
+ target.filter = filter;
60
+ }
61
+ const idType = raw["idType"];
62
+ if (idType !== undefined) {
63
+ if (idType !== "auto" && idType !== "objectId" && idType !== "string") {
64
+ throw new Error(`${procedure}: idType must be "auto", "objectId" or "string"`);
65
+ }
66
+ target.idType = idType;
67
+ }
68
+ const multi = optionalBoolean(procedure, raw, "multi");
69
+ const confirm = optionalBoolean(procedure, raw, "confirm");
70
+ if (multi !== undefined)
71
+ target.multi = multi;
72
+ if (confirm !== undefined)
73
+ target.confirm = confirm;
74
+ if (target.filter && Object.keys(target.filter).length === 0 && confirm !== true) {
75
+ throw new Error(`${procedure}: an empty filter matches every document. Set confirm: true to use it.`);
76
+ }
77
+ return { target, raw };
78
+ }
79
+ /** The filter of a target. */
80
+ export function targetFilter(target) {
81
+ return target.id !== undefined ? buildIdFilter(target.id, target.idType) : target.filter;
82
+ }
83
+ /**
84
+ * The filter of an upsert by ID. It names one exact `_id`.
85
+ *
86
+ * In the "auto" mode the ID filter is `$or` of the ObjectId and the string form. MongoDB cannot
87
+ * take an `_id` from `$or`, so each upsert inserted a new document with a new ID (deep dive
88
+ * DATA-15). This function uses the `_id` of the existing document, or the ObjectId form when no
89
+ * document matches.
90
+ */
91
+ export async function upsertFilter(collection, target) {
92
+ const filter = targetFilter(target);
93
+ if (target.id === undefined || !("$or" in filter))
94
+ return filter;
95
+ const existing = await collection.findOne(filter, { projection: { _id: 1 } });
96
+ return { _id: existing ? existing["_id"] : new ObjectId(target.id) };
97
+ }
98
+ //# sourceMappingURL=target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target.js","sourceRoot":"","sources":["../../src/procedures/target.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAkC,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,aAAa,EAAmC,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AAgBvE,MAAM,aAAa,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,YAAY,CAAU,CAAC;AAE/F,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,eAAe,CAAC,SAAiB,EAAE,GAA4B,EAAE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9C,IAAI,OAAO,KAAK,SAAS;QAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAEpD,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,wEAAwE,CAAC,CAAC;IACxG,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACzB,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,YAAY,CAAC,MAAmB;IAC9C,OAAO,MAAM,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,MAAmB,CAAC;AACzG,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAgC,EAAE,MAAmB;IACtF,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,MAAM,CAAC,EAAE,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACjE,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;AACvE,CAAC"}
@@ -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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AC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,GAAG,qBAAqB,GAClE,CAAC,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,GAAG,sBAAsB,GACrE,CAAC,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,GAAG,oBAAoB,GACjE,CAAC,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,GAAG,eAAe,GAC7D,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,UAAU,GACrD,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,GAAG,SAAS,GACnD,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,GAAG,YAAY,GACzD,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,GAAG,YAAY,GACzD,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,GAAG,YAAY,GACzD,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,GAAG,WAAW,GACvD,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,GAAG,eAAe,GAC/D,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,iBAAiB,GAC1D,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,iBAAiB,GAC5D,CAAC,SAAS,CAAC,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,7 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/mongo, and of the modules that it
3
+ * requires, in the global registry: `import "@procedures/mongo/register"`. The package root and the
4
+ * `./module` entry register nothing (ARCHITECTURE-PROPOSALS-2026-10, P9).
5
+ */
6
+ export * from "./module.js";
7
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/mongo, and of the modules that it
3
+ * requires, in the global registry: `import "@procedures/mongo/register"`. The package root and the
4
+ * `./module` entry register nothing (ARCHITECTURE-PROPOSALS-2026-10, P9).
5
+ */
6
+ import { registerMongoProcedures } from "./module.js";
7
+ export * from "./module.js";
8
+ registerMongoProcedures();
9
+ //# 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,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,cAAc,aAAa,CAAC;AAE5B,uBAAuB,EAAE,CAAC"}
@@ -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,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AC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;AACrE,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAiB,EACjB,GAAuC;IAEvC,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACvD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,SAAS,CAAC,GAA4B,EAAE,MAAkB;IACxE,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;IAC3D,IAAI,UAAU,KAAK,SAAS;QAAE,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC;IAC7D,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * MongoDB Storage Exports
3
+ */
4
+ export { MongoStorage } from "./mongo-storage.js";
5
+ export type { MongoStorageOptions } from "./mongo-storage.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -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,5 @@
1
+ /**
2
+ * MongoDB Storage Exports
3
+ */
4
+ export { MongoStorage } from "./mongo-storage.js";
5
+ //# sourceMappingURL=index.js.map
@@ -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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AAM,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,kBAAkB,CAAC;AAkBpD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,YAAY;IACN,cAAc,CAAS;IAExC,YAAY,OAA4B;QACtC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAC3C,CAAC;IAED;;;OA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