@form-engine-ts/storage-memory 2.2.0 → 2.5.1

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
@@ -24,3 +24,7 @@ const responses = await storage.listSubmissions(schema.id, schema.version, {
24
24
  ```
25
25
 
26
26
  Date boundaries are inclusive, and results are ordered by submission time and then ID. Data is cleared when the JavaScript process is restarted.
27
+
28
+ For bounded reads, call `listSubmissionPage(formId, { version, pageSize, cursor, since, until, locale })`. Pass the
29
+ returned `nextCursor` to the next call while `hasMore` is true. The opaque cursor remains stable when submissions share a timestamp.
30
+ Use `metadataFilters` for exact JSON metadata matching or `filter` for a custom predicate; both run before page sizing.
package/dist/index.cjs CHANGED
@@ -74,6 +74,21 @@ function createMemoryStorageAdapter() {
74
74
  (submission) => submission.formId === formId && (formVersion === void 0 || submission.formVersion === formVersion) && (options?.since === void 0 || submission.submittedAt >= options.since) && (options?.until === void 0 || submission.submittedAt <= options.until)
75
75
  ).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id)).map(cloneSubmission);
76
76
  },
77
+ async listSubmissionPage(formId, options = {}) {
78
+ const pageSize = (0, import_core.normalizeSubmissionPageSize)(options.pageSize);
79
+ const cursor = options.cursor === void 0 ? void 0 : (0, import_core.decodeSubmissionCursor)(options.cursor);
80
+ const candidates = [...submissions.values()].filter(
81
+ (submission) => submission.formId === formId && (options.version === void 0 || submission.formVersion === options.version) && (options.since === void 0 || submission.submittedAt >= options.since) && (options.until === void 0 || submission.submittedAt <= options.until) && (options.locale === void 0 || submission.locale === options.locale) && (cursor === void 0 || submission.submittedAt > cursor.submittedAt || submission.submittedAt === cursor.submittedAt && submission.id > cursor.responseId) && (0, import_core.matchesSubmissionPageFilters)(submission, options)
82
+ ).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id));
83
+ const hasMore = candidates.length > pageSize;
84
+ const items = candidates.slice(0, pageSize).map(cloneSubmission);
85
+ const last = items.at(-1);
86
+ return {
87
+ items,
88
+ hasMore,
89
+ ...hasMore && last !== void 0 ? { nextCursor: (0, import_core.encodeSubmissionCursor)({ submittedAt: last.submittedAt, responseId: last.id }) } : {}
90
+ };
91
+ },
77
92
  async deleteSubmission(submissionId) {
78
93
  submissions.delete(submissionId);
79
94
  },
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { FormStorageAdapter } from '@form-engine-ts/core';
1
+ import { PagedSubmissionStorageAdapter } from '@form-engine-ts/core';
2
2
 
3
- declare function createMemoryStorageAdapter(): FormStorageAdapter;
3
+ declare function createMemoryStorageAdapter(): PagedSubmissionStorageAdapter;
4
4
 
5
5
  export { createMemoryStorageAdapter };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { FormStorageAdapter } from '@form-engine-ts/core';
1
+ import { PagedSubmissionStorageAdapter } from '@form-engine-ts/core';
2
2
 
3
- declare function createMemoryStorageAdapter(): FormStorageAdapter;
3
+ declare function createMemoryStorageAdapter(): PagedSubmissionStorageAdapter;
4
4
 
5
5
  export { createMemoryStorageAdapter };
package/dist/index.js CHANGED
@@ -1,5 +1,11 @@
1
1
  // src/index.ts
2
- import { assertValidFormSchema } from "@form-engine-ts/core";
2
+ import {
3
+ assertValidFormSchema,
4
+ decodeSubmissionCursor,
5
+ encodeSubmissionCursor,
6
+ matchesSubmissionPageFilters,
7
+ normalizeSubmissionPageSize
8
+ } from "@form-engine-ts/core";
3
9
  function cloneValue(value) {
4
10
  return Array.isArray(value) ? [...value] : value;
5
11
  }
@@ -50,6 +56,21 @@ function createMemoryStorageAdapter() {
50
56
  (submission) => submission.formId === formId && (formVersion === void 0 || submission.formVersion === formVersion) && (options?.since === void 0 || submission.submittedAt >= options.since) && (options?.until === void 0 || submission.submittedAt <= options.until)
51
57
  ).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id)).map(cloneSubmission);
52
58
  },
59
+ async listSubmissionPage(formId, options = {}) {
60
+ const pageSize = normalizeSubmissionPageSize(options.pageSize);
61
+ const cursor = options.cursor === void 0 ? void 0 : decodeSubmissionCursor(options.cursor);
62
+ const candidates = [...submissions.values()].filter(
63
+ (submission) => submission.formId === formId && (options.version === void 0 || submission.formVersion === options.version) && (options.since === void 0 || submission.submittedAt >= options.since) && (options.until === void 0 || submission.submittedAt <= options.until) && (options.locale === void 0 || submission.locale === options.locale) && (cursor === void 0 || submission.submittedAt > cursor.submittedAt || submission.submittedAt === cursor.submittedAt && submission.id > cursor.responseId) && matchesSubmissionPageFilters(submission, options)
64
+ ).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id));
65
+ const hasMore = candidates.length > pageSize;
66
+ const items = candidates.slice(0, pageSize).map(cloneSubmission);
67
+ const last = items.at(-1);
68
+ return {
69
+ items,
70
+ hasMore,
71
+ ...hasMore && last !== void 0 ? { nextCursor: encodeSubmissionCursor({ submittedAt: last.submittedAt, responseId: last.id }) } : {}
72
+ };
73
+ },
53
74
  async deleteSubmission(submissionId) {
54
75
  submissions.delete(submissionId);
55
76
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-engine-ts/storage-memory",
3
- "version": "2.2.0",
3
+ "version": "2.5.1",
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": "2.2.0"
42
+ "@form-engine-ts/core": "2.5.1"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --external @form-engine-ts/core",