@form-engine-ts/storage-mongodb 1.0.0 → 1.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/README.md CHANGED
@@ -17,7 +17,12 @@ import { MongoClient } from "mongodb";
17
17
  const client = await new MongoClient(process.env.MONGODB_URI!).connect();
18
18
  const storage = createMongoDbStorage({ db: client.db("forms") });
19
19
 
20
+ await storage.createIndexes();
20
21
  await storage.saveSchema(schema);
22
+ const submissions = await storage.listSubmissions(schema.id, schema.version, {
23
+ since: "2026-01-01T00:00:00.000Z",
24
+ until: "2026-01-31T23:59:59.999Z"
25
+ });
21
26
  ```
22
27
 
23
- The caller owns the MongoDB connection lifecycle. Collection names can be customized in the factory options.
28
+ The caller owns the MongoDB connection lifecycle. Collection names can be customized in the factory options. `createIndexes()` creates named indexes for form/timestamp range scans and locale queries. Range boundaries are inclusive, and MongoDB sorts by submission time and then ID. `clearResponses(formId)` preserves schemas and other forms; `clear()` removes documents only from the configured collections and does not drop collections or indexes.
package/dist/index.cjs CHANGED
@@ -106,9 +106,17 @@ function createMongoDbStorage(options) {
106
106
  submission: stored
107
107
  });
108
108
  },
109
- async listSubmissions(formId, formVersion) {
110
- const documents = await submissions.find({ formId, ...formVersion === void 0 ? {} : { formVersion } }).toArray();
111
- return documents.map(parseSubmissionDocument).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id));
109
+ async listSubmissions(formId, formVersion, options2) {
110
+ const submittedAt = options2?.since === void 0 && options2?.until === void 0 ? void 0 : {
111
+ ...options2.since === void 0 ? {} : { $gte: options2.since },
112
+ ...options2.until === void 0 ? {} : { $lte: options2.until }
113
+ };
114
+ const documents = await submissions.find({
115
+ formId,
116
+ ...formVersion === void 0 ? {} : { formVersion },
117
+ ...submittedAt === void 0 ? {} : { submittedAt }
118
+ }).sort({ submittedAt: 1, _id: 1 }).toArray();
119
+ return documents.map(parseSubmissionDocument);
112
120
  },
113
121
  async deleteSubmission(submissionId) {
114
122
  await submissions.deleteOne({ _id: submissionId });
@@ -118,6 +126,12 @@ function createMongoDbStorage(options) {
118
126
  },
119
127
  async clear() {
120
128
  await Promise.all([schemas.deleteMany({}), submissions.deleteMany({})]);
129
+ },
130
+ async createIndexes() {
131
+ await submissions.createIndexes([
132
+ { key: { formId: 1, submittedAt: 1 }, name: "form_responses_form_submitted_at" },
133
+ { key: { "submission.locale": 1 }, name: "form_responses_locale" }
134
+ ]);
121
135
  }
122
136
  };
123
137
  }
package/dist/index.d.cts CHANGED
@@ -6,6 +6,9 @@ interface MongoDbStorageOptions {
6
6
  readonly schemasCollectionName?: string;
7
7
  readonly responsesCollectionName?: string;
8
8
  }
9
- declare function createMongoDbStorage(options: MongoDbStorageOptions): FormStorageAdapter;
9
+ interface MongoDbStorageAdapter extends FormStorageAdapter {
10
+ createIndexes(): Promise<void>;
11
+ }
12
+ declare function createMongoDbStorage(options: MongoDbStorageOptions): MongoDbStorageAdapter;
10
13
 
11
- export { type MongoDbStorageOptions, createMongoDbStorage };
14
+ export { type MongoDbStorageAdapter, type MongoDbStorageOptions, createMongoDbStorage };
package/dist/index.d.ts CHANGED
@@ -6,6 +6,9 @@ interface MongoDbStorageOptions {
6
6
  readonly schemasCollectionName?: string;
7
7
  readonly responsesCollectionName?: string;
8
8
  }
9
- declare function createMongoDbStorage(options: MongoDbStorageOptions): FormStorageAdapter;
9
+ interface MongoDbStorageAdapter extends FormStorageAdapter {
10
+ createIndexes(): Promise<void>;
11
+ }
12
+ declare function createMongoDbStorage(options: MongoDbStorageOptions): MongoDbStorageAdapter;
10
13
 
11
- export { type MongoDbStorageOptions, createMongoDbStorage };
14
+ export { type MongoDbStorageAdapter, type MongoDbStorageOptions, createMongoDbStorage };
package/dist/index.js CHANGED
@@ -82,9 +82,17 @@ function createMongoDbStorage(options) {
82
82
  submission: stored
83
83
  });
84
84
  },
85
- async listSubmissions(formId, formVersion) {
86
- const documents = await submissions.find({ formId, ...formVersion === void 0 ? {} : { formVersion } }).toArray();
87
- return documents.map(parseSubmissionDocument).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id));
85
+ async listSubmissions(formId, formVersion, options2) {
86
+ const submittedAt = options2?.since === void 0 && options2?.until === void 0 ? void 0 : {
87
+ ...options2.since === void 0 ? {} : { $gte: options2.since },
88
+ ...options2.until === void 0 ? {} : { $lte: options2.until }
89
+ };
90
+ const documents = await submissions.find({
91
+ formId,
92
+ ...formVersion === void 0 ? {} : { formVersion },
93
+ ...submittedAt === void 0 ? {} : { submittedAt }
94
+ }).sort({ submittedAt: 1, _id: 1 }).toArray();
95
+ return documents.map(parseSubmissionDocument);
88
96
  },
89
97
  async deleteSubmission(submissionId) {
90
98
  await submissions.deleteOne({ _id: submissionId });
@@ -94,6 +102,12 @@ function createMongoDbStorage(options) {
94
102
  },
95
103
  async clear() {
96
104
  await Promise.all([schemas.deleteMany({}), submissions.deleteMany({})]);
105
+ },
106
+ async createIndexes() {
107
+ await submissions.createIndexes([
108
+ { key: { formId: 1, submittedAt: 1 }, name: "form_responses_form_submitted_at" },
109
+ { key: { "submission.locale": 1 }, name: "form_responses_locale" }
110
+ ]);
97
111
  }
98
112
  };
99
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-engine-ts/storage-mongodb",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,7 +39,7 @@
39
39
  "typescript"
40
40
  ],
41
41
  "dependencies": {
42
- "@form-engine-ts/core": "1.0.0"
42
+ "@form-engine-ts/core": "1.1.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "mongodb": "^6.0.0"