@form-engine-ts/storage-memory 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nitta-a
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @form-engine-ts/storage-memory
2
+
3
+ In-process implementation of the form-engine-ts storage contract. It is useful for tests, demos, and ephemeral server workloads.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @form-engine-ts/core @form-engine-ts/storage-memory
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { createMemoryStorageAdapter } from "@form-engine-ts/storage-memory";
15
+
16
+ const storage = createMemoryStorageAdapter();
17
+ await storage.saveSchema(schema);
18
+ await storage.saveSubmission(submission);
19
+
20
+ const responses = await storage.listSubmissions(schema.id, schema.version);
21
+ ```
22
+
23
+ Data is cleared when the JavaScript process is restarted.
package/dist/index.cjs ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createMemoryStorageAdapter: () => createMemoryStorageAdapter
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_core = require("@form-engine-ts/core");
27
+ function cloneValue(value) {
28
+ return Array.isArray(value) ? [...value] : value;
29
+ }
30
+ function cloneValues(values) {
31
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, cloneValue(value)]));
32
+ }
33
+ function cloneSubmission(submission) {
34
+ return { ...submission, values: cloneValues(submission.values) };
35
+ }
36
+ function cloneSchema(schema) {
37
+ return JSON.parse(JSON.stringify(schema));
38
+ }
39
+ function schemaKey(formId, formVersion) {
40
+ return `${formId}@${formVersion}`;
41
+ }
42
+ function createMemoryStorageAdapter() {
43
+ const submissions = /* @__PURE__ */ new Map();
44
+ const schemas = /* @__PURE__ */ new Map();
45
+ return {
46
+ async saveSchema(schema) {
47
+ (0, import_core.assertValidFormSchema)(schema);
48
+ schemas.set(schemaKey(schema.id, schema.version), cloneSchema(schema));
49
+ },
50
+ async getSchema(formId, formVersion) {
51
+ const schema = schemas.get(schemaKey(formId, formVersion));
52
+ return schema === void 0 ? null : cloneSchema(schema);
53
+ },
54
+ async listSchemas() {
55
+ return [...schemas.values()].sort((left, right) => left.id.localeCompare(right.id) || left.version - right.version).map(cloneSchema);
56
+ },
57
+ async deleteSchema(formId, formVersion) {
58
+ schemas.delete(schemaKey(formId, formVersion));
59
+ },
60
+ async saveSubmission(submission) {
61
+ if (submissions.has(submission.id)) throw new Error(`A submission with ID "${submission.id}" already exists.`);
62
+ submissions.set(submission.id, cloneSubmission(submission));
63
+ },
64
+ async listSubmissions(formId, formVersion) {
65
+ return [...submissions.values()].filter(
66
+ (submission) => submission.formId === formId && (formVersion === void 0 || submission.formVersion === formVersion)
67
+ ).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt)).map(cloneSubmission);
68
+ },
69
+ async deleteSubmission(submissionId) {
70
+ submissions.delete(submissionId);
71
+ },
72
+ async clearResponses(formId) {
73
+ for (const [submissionId, submission] of submissions) {
74
+ if (submission.formId === formId) submissions.delete(submissionId);
75
+ }
76
+ },
77
+ async clear() {
78
+ schemas.clear();
79
+ submissions.clear();
80
+ }
81
+ };
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ createMemoryStorageAdapter
86
+ });
@@ -0,0 +1,5 @@
1
+ import { FormStorageAdapter } from '@form-engine-ts/core';
2
+
3
+ declare function createMemoryStorageAdapter(): FormStorageAdapter;
4
+
5
+ export { createMemoryStorageAdapter };
@@ -0,0 +1,5 @@
1
+ import { FormStorageAdapter } from '@form-engine-ts/core';
2
+
3
+ declare function createMemoryStorageAdapter(): FormStorageAdapter;
4
+
5
+ export { createMemoryStorageAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ // src/index.ts
2
+ import { assertValidFormSchema } from "@form-engine-ts/core";
3
+ function cloneValue(value) {
4
+ return Array.isArray(value) ? [...value] : value;
5
+ }
6
+ function cloneValues(values) {
7
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, cloneValue(value)]));
8
+ }
9
+ function cloneSubmission(submission) {
10
+ return { ...submission, values: cloneValues(submission.values) };
11
+ }
12
+ function cloneSchema(schema) {
13
+ return JSON.parse(JSON.stringify(schema));
14
+ }
15
+ function schemaKey(formId, formVersion) {
16
+ return `${formId}@${formVersion}`;
17
+ }
18
+ function createMemoryStorageAdapter() {
19
+ const submissions = /* @__PURE__ */ new Map();
20
+ const schemas = /* @__PURE__ */ new Map();
21
+ return {
22
+ async saveSchema(schema) {
23
+ assertValidFormSchema(schema);
24
+ schemas.set(schemaKey(schema.id, schema.version), cloneSchema(schema));
25
+ },
26
+ async getSchema(formId, formVersion) {
27
+ const schema = schemas.get(schemaKey(formId, formVersion));
28
+ return schema === void 0 ? null : cloneSchema(schema);
29
+ },
30
+ async listSchemas() {
31
+ return [...schemas.values()].sort((left, right) => left.id.localeCompare(right.id) || left.version - right.version).map(cloneSchema);
32
+ },
33
+ async deleteSchema(formId, formVersion) {
34
+ schemas.delete(schemaKey(formId, formVersion));
35
+ },
36
+ async saveSubmission(submission) {
37
+ if (submissions.has(submission.id)) throw new Error(`A submission with ID "${submission.id}" already exists.`);
38
+ submissions.set(submission.id, cloneSubmission(submission));
39
+ },
40
+ async listSubmissions(formId, formVersion) {
41
+ return [...submissions.values()].filter(
42
+ (submission) => submission.formId === formId && (formVersion === void 0 || submission.formVersion === formVersion)
43
+ ).sort((left, right) => left.submittedAt.localeCompare(right.submittedAt)).map(cloneSubmission);
44
+ },
45
+ async deleteSubmission(submissionId) {
46
+ submissions.delete(submissionId);
47
+ },
48
+ async clearResponses(formId) {
49
+ for (const [submissionId, submission] of submissions) {
50
+ if (submission.formId === formId) submissions.delete(submissionId);
51
+ }
52
+ },
53
+ async clear() {
54
+ schemas.clear();
55
+ submissions.clear();
56
+ }
57
+ };
58
+ }
59
+ export {
60
+ createMemoryStorageAdapter
61
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@form-engine-ts/storage-memory",
3
+ "version": "1.0.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/nitta-a/form-engine-ts.git",
28
+ "directory": "packages/storage-memory"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/nitta-a/form-engine-ts/issues"
32
+ },
33
+ "homepage": "https://github.com/nitta-a/form-engine-ts#readme",
34
+ "keywords": [
35
+ "form",
36
+ "survey",
37
+ "storage",
38
+ "memory",
39
+ "typescript"
40
+ ],
41
+ "dependencies": {
42
+ "@form-engine-ts/core": "1.0.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean --external @form-engine-ts/core",
46
+ "check": "biome check . && tsc --noEmit",
47
+ "test": "vitest run --globals",
48
+ "typecheck": "tsc --noEmit"
49
+ }
50
+ }