@form-engine-ts/storage-azure-table 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/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,26 @@
1
+ # @form-engine-ts/storage-azure-table
2
+
3
+ Azure Table Storage implementation of the paged form-engine-ts storage contract using an injected
4
+ `@azure/data-tables`-compatible client.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pnpm add @form-engine-ts/core @form-engine-ts/storage-azure-table @azure/data-tables
10
+ ```
11
+
12
+ ## Quick start
13
+
14
+ ```ts
15
+ import { TableClient } from "@azure/data-tables";
16
+ import { createAzureTableStorage } from "@form-engine-ts/storage-azure-table";
17
+
18
+ const client = TableClient.fromConnectionString(process.env.AZURE_STORAGE_CONNECTION_STRING!, "forms");
19
+ const storage = createAzureTableStorage({ client });
20
+
21
+ const page = await storage.listSubmissionPage("contact", { pageSize: 500, locale: "ja" });
22
+ ```
23
+
24
+ Submission entities use `formId` as `PartitionKey` and `submittedAt_responseId` as `RowKey`. Built-in date, locale,
25
+ version, and cursor constraints are sent as OData filters. Custom predicates and metadata filters are applied before page
26
+ sizing. The caller owns table creation, credentials, retries, and the client lifecycle.
package/dist/index.cjs ADDED
@@ -0,0 +1,216 @@
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
+ createAzureTableStorage: () => createAzureTableStorage
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_core = require("@form-engine-ts/core");
27
+ function cloneJson(value) {
28
+ return JSON.parse(JSON.stringify(value));
29
+ }
30
+ function isRecord(value) {
31
+ return typeof value === "object" && value !== null && !Array.isArray(value);
32
+ }
33
+ function isFormValue(value) {
34
+ return value === void 0 || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || Array.isArray(value) && value.every((item) => typeof item === "string");
35
+ }
36
+ function parseJson(value, location) {
37
+ if (typeof value !== "string") throw new Error(`Azure Table ${location} payload is invalid.`);
38
+ try {
39
+ return JSON.parse(value);
40
+ } catch (cause) {
41
+ throw new Error(`Azure Table ${location} payload is invalid.`, { cause });
42
+ }
43
+ }
44
+ function parseSubmission(value, location) {
45
+ const parsed = parseJson(value, location);
46
+ if (!isRecord(parsed) || typeof parsed.id !== "string" || typeof parsed.formId !== "string" || !Number.isInteger(parsed.formVersion) || typeof parsed.locale !== "string" || typeof parsed.submittedAt !== "string" || !isRecord(parsed.values) || !Object.values(parsed.values).every(isFormValue)) {
47
+ throw new Error(`Azure Table ${location} submission is invalid.`);
48
+ }
49
+ return cloneJson(parsed);
50
+ }
51
+ function parseEntity(value) {
52
+ if (typeof value.partitionKey !== "string" || typeof value.rowKey !== "string" || value.kind !== "schema" && value.kind !== "submission" || !Number.isInteger(value.formVersion) || typeof value.payload !== "string") {
53
+ throw new Error("Azure Table entity is invalid.");
54
+ }
55
+ return value;
56
+ }
57
+ function parseSchemaEntity(value) {
58
+ const entity = parseEntity(value);
59
+ const schema = parseJson(entity.payload, `schema ${entity.partitionKey}/${entity.rowKey}`);
60
+ (0, import_core.assertValidFormSchema)(schema);
61
+ if (entity.kind !== "schema" || schema.id !== entity.partitionKey || schema.version !== entity.formVersion) {
62
+ throw new Error("Azure Table schema entity has inconsistent metadata.");
63
+ }
64
+ return cloneJson(schema);
65
+ }
66
+ function parseSubmissionEntity(value) {
67
+ const entity = parseEntity(value);
68
+ const submission = parseSubmission(entity.payload, `submission ${entity.partitionKey}/${entity.rowKey}`);
69
+ if (entity.kind !== "submission" || entity.partitionKey !== submission.formId || entity.rowKey !== submissionRowKey(submission) || entity.formVersion !== submission.formVersion || entity.locale !== submission.locale || entity.submittedAt !== submission.submittedAt || entity.responseId !== submission.id) {
70
+ throw new Error("Azure Table submission entity has inconsistent metadata.");
71
+ }
72
+ return submission;
73
+ }
74
+ function schemaRowKey(version) {
75
+ return `schema_${version}`;
76
+ }
77
+ function submissionRowKey(submission) {
78
+ return `${submission.submittedAt}_${submission.id}`;
79
+ }
80
+ function escapeOData(value) {
81
+ return value.replaceAll("'", "''");
82
+ }
83
+ function odataFilter(formId, options = {}) {
84
+ const filters = [
85
+ ...formId === void 0 ? [] : [`PartitionKey eq '${escapeOData(formId)}'`],
86
+ "kind eq 'submission'",
87
+ ...options.version === void 0 ? [] : [`formVersion eq ${options.version}`],
88
+ ...options.since === void 0 ? [] : [`submittedAt ge '${escapeOData(options.since)}'`],
89
+ ...options.until === void 0 ? [] : [`submittedAt le '${escapeOData(options.until)}'`],
90
+ ...options.locale === void 0 ? [] : [`locale eq '${escapeOData(options.locale)}'`]
91
+ ];
92
+ if (options.cursor !== void 0) {
93
+ const cursor = (0, import_core.decodeSubmissionCursor)(options.cursor);
94
+ filters.push(`RowKey gt '${escapeOData(`${cursor.submittedAt}_${cursor.responseId}`)}'`);
95
+ }
96
+ return filters.join(" and ");
97
+ }
98
+ function isNotFound(error) {
99
+ return isRecord(error) && (error.statusCode === 404 || error.code === "ResourceNotFound" || error.code === "EntityNotFound");
100
+ }
101
+ function matchesBuiltInFilters(submission, formId, options) {
102
+ const cursor = options.cursor === void 0 ? void 0 : (0, import_core.decodeSubmissionCursor)(options.cursor);
103
+ return 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);
104
+ }
105
+ function createAzureTableStorage(options) {
106
+ if (options?.client === void 0) throw new TypeError("client is required.");
107
+ const { client } = options;
108
+ const listSubmissionCandidates = async (formId, query) => {
109
+ const submissions = [];
110
+ for await (const raw of client.listEntities({ queryOptions: { filter: odataFilter(formId, query) } })) {
111
+ const entity = parseEntity(raw);
112
+ if (entity.kind !== "submission") continue;
113
+ const submission = parseSubmissionEntity(entity);
114
+ if (!matchesBuiltInFilters(submission, formId, query)) continue;
115
+ if (!(0, import_core.matchesSubmissionPageFilters)(submission, query)) continue;
116
+ submissions.push(submission);
117
+ }
118
+ return submissions.sort(
119
+ (left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id)
120
+ );
121
+ };
122
+ return {
123
+ async saveSchema(schema) {
124
+ (0, import_core.assertValidFormSchema)(schema);
125
+ await client.upsertEntity(
126
+ {
127
+ partitionKey: schema.id,
128
+ rowKey: schemaRowKey(schema.version),
129
+ kind: "schema",
130
+ formVersion: schema.version,
131
+ payload: JSON.stringify(schema)
132
+ },
133
+ "Replace"
134
+ );
135
+ },
136
+ async getSchema(formId, formVersion) {
137
+ try {
138
+ return parseSchemaEntity(await client.getEntity(formId, schemaRowKey(formVersion)));
139
+ } catch (error) {
140
+ if (isNotFound(error)) return null;
141
+ throw error;
142
+ }
143
+ },
144
+ async listSchemas() {
145
+ const schemas = [];
146
+ for await (const raw of client.listEntities({ queryOptions: { filter: "kind eq 'schema'" } })) {
147
+ const entity = parseEntity(raw);
148
+ if (entity.kind === "schema") schemas.push(parseSchemaEntity(entity));
149
+ }
150
+ return schemas.sort((left, right) => left.id.localeCompare(right.id) || left.version - right.version);
151
+ },
152
+ async deleteSchema(formId, formVersion) {
153
+ await client.deleteEntity(formId, schemaRowKey(formVersion));
154
+ },
155
+ async saveSubmission(submission) {
156
+ const stored = parseSubmission(JSON.stringify(submission), `input ${String(submission?.id)}`);
157
+ await client.createEntity({
158
+ partitionKey: stored.formId,
159
+ rowKey: submissionRowKey(stored),
160
+ kind: "submission",
161
+ formVersion: stored.formVersion,
162
+ locale: stored.locale,
163
+ submittedAt: stored.submittedAt,
164
+ responseId: stored.id,
165
+ payload: JSON.stringify(stored)
166
+ });
167
+ },
168
+ async listSubmissions(formId, formVersion, queryOptions = {}) {
169
+ return listSubmissionCandidates(formId, {
170
+ ...queryOptions,
171
+ ...formVersion === void 0 ? {} : { version: formVersion }
172
+ });
173
+ },
174
+ async listSubmissionPage(formId, query = {}) {
175
+ const pageSize = (0, import_core.normalizeSubmissionPageSize)(query.pageSize);
176
+ const candidates = await listSubmissionCandidates(formId, query);
177
+ const hasMore = candidates.length > pageSize;
178
+ const items = candidates.slice(0, pageSize);
179
+ const last = items.at(-1);
180
+ return {
181
+ items,
182
+ hasMore,
183
+ ...hasMore && last !== void 0 ? { nextCursor: (0, import_core.encodeSubmissionCursor)({ submittedAt: last.submittedAt, responseId: last.id }) } : {}
184
+ };
185
+ },
186
+ async deleteSubmission(submissionId) {
187
+ for await (const raw of client.listEntities({ queryOptions: { filter: "kind eq 'submission'" } })) {
188
+ const entity = parseEntity(raw);
189
+ if (entity.kind === "submission" && entity.responseId === submissionId) {
190
+ await client.deleteEntity(entity.partitionKey, entity.rowKey);
191
+ return;
192
+ }
193
+ }
194
+ },
195
+ async clearResponses(formId) {
196
+ for await (const raw of client.listEntities({
197
+ queryOptions: { filter: `PartitionKey eq '${escapeOData(formId)}' and kind eq 'submission'` }
198
+ })) {
199
+ const entity = parseEntity(raw);
200
+ if (entity.partitionKey === formId && entity.kind === "submission") {
201
+ await client.deleteEntity(entity.partitionKey, entity.rowKey);
202
+ }
203
+ }
204
+ },
205
+ async clear() {
206
+ for await (const raw of client.listEntities()) {
207
+ const entity = parseEntity(raw);
208
+ await client.deleteEntity(entity.partitionKey, entity.rowKey);
209
+ }
210
+ }
211
+ };
212
+ }
213
+ // Annotate the CommonJS export names for ESM import in node:
214
+ 0 && (module.exports = {
215
+ createAzureTableStorage
216
+ });
@@ -0,0 +1,20 @@
1
+ import { PagedSubmissionStorageAdapter } from '@form-engine-ts/core';
2
+
3
+ interface AzureTableListOptions {
4
+ readonly queryOptions?: {
5
+ readonly filter?: string;
6
+ };
7
+ }
8
+ interface AzureTableClientLike {
9
+ createEntity(entity: Record<string, unknown>): Promise<unknown>;
10
+ upsertEntity(entity: Record<string, unknown>, mode?: "Merge" | "Replace"): Promise<unknown>;
11
+ getEntity(partitionKey: string, rowKey: string): Promise<Record<string, unknown>>;
12
+ listEntities(options?: AzureTableListOptions): AsyncIterable<Record<string, unknown>>;
13
+ deleteEntity(partitionKey: string, rowKey: string): Promise<unknown>;
14
+ }
15
+ interface AzureTableStorageOptions {
16
+ readonly client: AzureTableClientLike;
17
+ }
18
+ declare function createAzureTableStorage(options: AzureTableStorageOptions): PagedSubmissionStorageAdapter;
19
+
20
+ export { type AzureTableClientLike, type AzureTableListOptions, type AzureTableStorageOptions, createAzureTableStorage };
@@ -0,0 +1,20 @@
1
+ import { PagedSubmissionStorageAdapter } from '@form-engine-ts/core';
2
+
3
+ interface AzureTableListOptions {
4
+ readonly queryOptions?: {
5
+ readonly filter?: string;
6
+ };
7
+ }
8
+ interface AzureTableClientLike {
9
+ createEntity(entity: Record<string, unknown>): Promise<unknown>;
10
+ upsertEntity(entity: Record<string, unknown>, mode?: "Merge" | "Replace"): Promise<unknown>;
11
+ getEntity(partitionKey: string, rowKey: string): Promise<Record<string, unknown>>;
12
+ listEntities(options?: AzureTableListOptions): AsyncIterable<Record<string, unknown>>;
13
+ deleteEntity(partitionKey: string, rowKey: string): Promise<unknown>;
14
+ }
15
+ interface AzureTableStorageOptions {
16
+ readonly client: AzureTableClientLike;
17
+ }
18
+ declare function createAzureTableStorage(options: AzureTableStorageOptions): PagedSubmissionStorageAdapter;
19
+
20
+ export { type AzureTableClientLike, type AzureTableListOptions, type AzureTableStorageOptions, createAzureTableStorage };
package/dist/index.js ADDED
@@ -0,0 +1,197 @@
1
+ // src/index.ts
2
+ import {
3
+ assertValidFormSchema,
4
+ decodeSubmissionCursor,
5
+ encodeSubmissionCursor,
6
+ matchesSubmissionPageFilters,
7
+ normalizeSubmissionPageSize
8
+ } from "@form-engine-ts/core";
9
+ function cloneJson(value) {
10
+ return JSON.parse(JSON.stringify(value));
11
+ }
12
+ function isRecord(value) {
13
+ return typeof value === "object" && value !== null && !Array.isArray(value);
14
+ }
15
+ function isFormValue(value) {
16
+ return value === void 0 || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || Array.isArray(value) && value.every((item) => typeof item === "string");
17
+ }
18
+ function parseJson(value, location) {
19
+ if (typeof value !== "string") throw new Error(`Azure Table ${location} payload is invalid.`);
20
+ try {
21
+ return JSON.parse(value);
22
+ } catch (cause) {
23
+ throw new Error(`Azure Table ${location} payload is invalid.`, { cause });
24
+ }
25
+ }
26
+ function parseSubmission(value, location) {
27
+ const parsed = parseJson(value, location);
28
+ if (!isRecord(parsed) || typeof parsed.id !== "string" || typeof parsed.formId !== "string" || !Number.isInteger(parsed.formVersion) || typeof parsed.locale !== "string" || typeof parsed.submittedAt !== "string" || !isRecord(parsed.values) || !Object.values(parsed.values).every(isFormValue)) {
29
+ throw new Error(`Azure Table ${location} submission is invalid.`);
30
+ }
31
+ return cloneJson(parsed);
32
+ }
33
+ function parseEntity(value) {
34
+ if (typeof value.partitionKey !== "string" || typeof value.rowKey !== "string" || value.kind !== "schema" && value.kind !== "submission" || !Number.isInteger(value.formVersion) || typeof value.payload !== "string") {
35
+ throw new Error("Azure Table entity is invalid.");
36
+ }
37
+ return value;
38
+ }
39
+ function parseSchemaEntity(value) {
40
+ const entity = parseEntity(value);
41
+ const schema = parseJson(entity.payload, `schema ${entity.partitionKey}/${entity.rowKey}`);
42
+ assertValidFormSchema(schema);
43
+ if (entity.kind !== "schema" || schema.id !== entity.partitionKey || schema.version !== entity.formVersion) {
44
+ throw new Error("Azure Table schema entity has inconsistent metadata.");
45
+ }
46
+ return cloneJson(schema);
47
+ }
48
+ function parseSubmissionEntity(value) {
49
+ const entity = parseEntity(value);
50
+ const submission = parseSubmission(entity.payload, `submission ${entity.partitionKey}/${entity.rowKey}`);
51
+ if (entity.kind !== "submission" || entity.partitionKey !== submission.formId || entity.rowKey !== submissionRowKey(submission) || entity.formVersion !== submission.formVersion || entity.locale !== submission.locale || entity.submittedAt !== submission.submittedAt || entity.responseId !== submission.id) {
52
+ throw new Error("Azure Table submission entity has inconsistent metadata.");
53
+ }
54
+ return submission;
55
+ }
56
+ function schemaRowKey(version) {
57
+ return `schema_${version}`;
58
+ }
59
+ function submissionRowKey(submission) {
60
+ return `${submission.submittedAt}_${submission.id}`;
61
+ }
62
+ function escapeOData(value) {
63
+ return value.replaceAll("'", "''");
64
+ }
65
+ function odataFilter(formId, options = {}) {
66
+ const filters = [
67
+ ...formId === void 0 ? [] : [`PartitionKey eq '${escapeOData(formId)}'`],
68
+ "kind eq 'submission'",
69
+ ...options.version === void 0 ? [] : [`formVersion eq ${options.version}`],
70
+ ...options.since === void 0 ? [] : [`submittedAt ge '${escapeOData(options.since)}'`],
71
+ ...options.until === void 0 ? [] : [`submittedAt le '${escapeOData(options.until)}'`],
72
+ ...options.locale === void 0 ? [] : [`locale eq '${escapeOData(options.locale)}'`]
73
+ ];
74
+ if (options.cursor !== void 0) {
75
+ const cursor = decodeSubmissionCursor(options.cursor);
76
+ filters.push(`RowKey gt '${escapeOData(`${cursor.submittedAt}_${cursor.responseId}`)}'`);
77
+ }
78
+ return filters.join(" and ");
79
+ }
80
+ function isNotFound(error) {
81
+ return isRecord(error) && (error.statusCode === 404 || error.code === "ResourceNotFound" || error.code === "EntityNotFound");
82
+ }
83
+ function matchesBuiltInFilters(submission, formId, options) {
84
+ const cursor = options.cursor === void 0 ? void 0 : decodeSubmissionCursor(options.cursor);
85
+ return 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);
86
+ }
87
+ function createAzureTableStorage(options) {
88
+ if (options?.client === void 0) throw new TypeError("client is required.");
89
+ const { client } = options;
90
+ const listSubmissionCandidates = async (formId, query) => {
91
+ const submissions = [];
92
+ for await (const raw of client.listEntities({ queryOptions: { filter: odataFilter(formId, query) } })) {
93
+ const entity = parseEntity(raw);
94
+ if (entity.kind !== "submission") continue;
95
+ const submission = parseSubmissionEntity(entity);
96
+ if (!matchesBuiltInFilters(submission, formId, query)) continue;
97
+ if (!matchesSubmissionPageFilters(submission, query)) continue;
98
+ submissions.push(submission);
99
+ }
100
+ return submissions.sort(
101
+ (left, right) => left.submittedAt.localeCompare(right.submittedAt) || left.id.localeCompare(right.id)
102
+ );
103
+ };
104
+ return {
105
+ async saveSchema(schema) {
106
+ assertValidFormSchema(schema);
107
+ await client.upsertEntity(
108
+ {
109
+ partitionKey: schema.id,
110
+ rowKey: schemaRowKey(schema.version),
111
+ kind: "schema",
112
+ formVersion: schema.version,
113
+ payload: JSON.stringify(schema)
114
+ },
115
+ "Replace"
116
+ );
117
+ },
118
+ async getSchema(formId, formVersion) {
119
+ try {
120
+ return parseSchemaEntity(await client.getEntity(formId, schemaRowKey(formVersion)));
121
+ } catch (error) {
122
+ if (isNotFound(error)) return null;
123
+ throw error;
124
+ }
125
+ },
126
+ async listSchemas() {
127
+ const schemas = [];
128
+ for await (const raw of client.listEntities({ queryOptions: { filter: "kind eq 'schema'" } })) {
129
+ const entity = parseEntity(raw);
130
+ if (entity.kind === "schema") schemas.push(parseSchemaEntity(entity));
131
+ }
132
+ return schemas.sort((left, right) => left.id.localeCompare(right.id) || left.version - right.version);
133
+ },
134
+ async deleteSchema(formId, formVersion) {
135
+ await client.deleteEntity(formId, schemaRowKey(formVersion));
136
+ },
137
+ async saveSubmission(submission) {
138
+ const stored = parseSubmission(JSON.stringify(submission), `input ${String(submission?.id)}`);
139
+ await client.createEntity({
140
+ partitionKey: stored.formId,
141
+ rowKey: submissionRowKey(stored),
142
+ kind: "submission",
143
+ formVersion: stored.formVersion,
144
+ locale: stored.locale,
145
+ submittedAt: stored.submittedAt,
146
+ responseId: stored.id,
147
+ payload: JSON.stringify(stored)
148
+ });
149
+ },
150
+ async listSubmissions(formId, formVersion, queryOptions = {}) {
151
+ return listSubmissionCandidates(formId, {
152
+ ...queryOptions,
153
+ ...formVersion === void 0 ? {} : { version: formVersion }
154
+ });
155
+ },
156
+ async listSubmissionPage(formId, query = {}) {
157
+ const pageSize = normalizeSubmissionPageSize(query.pageSize);
158
+ const candidates = await listSubmissionCandidates(formId, query);
159
+ const hasMore = candidates.length > pageSize;
160
+ const items = candidates.slice(0, pageSize);
161
+ const last = items.at(-1);
162
+ return {
163
+ items,
164
+ hasMore,
165
+ ...hasMore && last !== void 0 ? { nextCursor: encodeSubmissionCursor({ submittedAt: last.submittedAt, responseId: last.id }) } : {}
166
+ };
167
+ },
168
+ async deleteSubmission(submissionId) {
169
+ for await (const raw of client.listEntities({ queryOptions: { filter: "kind eq 'submission'" } })) {
170
+ const entity = parseEntity(raw);
171
+ if (entity.kind === "submission" && entity.responseId === submissionId) {
172
+ await client.deleteEntity(entity.partitionKey, entity.rowKey);
173
+ return;
174
+ }
175
+ }
176
+ },
177
+ async clearResponses(formId) {
178
+ for await (const raw of client.listEntities({
179
+ queryOptions: { filter: `PartitionKey eq '${escapeOData(formId)}' and kind eq 'submission'` }
180
+ })) {
181
+ const entity = parseEntity(raw);
182
+ if (entity.partitionKey === formId && entity.kind === "submission") {
183
+ await client.deleteEntity(entity.partitionKey, entity.rowKey);
184
+ }
185
+ }
186
+ },
187
+ async clear() {
188
+ for await (const raw of client.listEntities()) {
189
+ const entity = parseEntity(raw);
190
+ await client.deleteEntity(entity.partitionKey, entity.rowKey);
191
+ }
192
+ }
193
+ };
194
+ }
195
+ export {
196
+ createAzureTableStorage
197
+ };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@form-engine-ts/storage-azure-table",
3
+ "version": "2.5.1",
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-azure-table"
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
+ "storage",
37
+ "azure",
38
+ "azure-table-storage",
39
+ "typescript"
40
+ ],
41
+ "dependencies": {
42
+ "@form-engine-ts/core": "2.5.1"
43
+ },
44
+ "peerDependencies": {
45
+ "@azure/data-tables": "^13.3.2"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@azure/data-tables": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "devDependencies": {
53
+ "@azure/data-tables": "^13.3.2"
54
+ },
55
+ "scripts": {
56
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean --external @form-engine-ts/core",
57
+ "check": "biome check . && tsc --noEmit",
58
+ "test": "vitest run --globals",
59
+ "typecheck": "tsc --noEmit"
60
+ }
61
+ }