@form-engine-ts/storage-azure-table 6.0.0 → 6.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.
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createAzureTableStorage: () => createAzureTableStorage,
24
+ createLegacyArrayAzureTableCodec: () => createLegacyArrayAzureTableCodec,
24
25
  createLegacyAzureTableCodec: () => createLegacyAzureTableCodec,
25
26
  defaultAzureTableSubmissionCodec: () => defaultAzureTableSubmissionCodec,
26
27
  metadataFiltersToOData: () => metadataFiltersToOData,
@@ -28,6 +29,57 @@ __export(index_exports, {
28
29
  });
29
30
  module.exports = __toCommonJS(index_exports);
30
31
  var import_core = require("@form-engine-ts/core");
32
+ function createLegacyArrayAzureTableCodec(options = {}) {
33
+ const defaultLocale = options.defaultLocale ?? "ja";
34
+ if (defaultLocale.trim().length === 0) throw new TypeError("defaultLocale must not be empty.");
35
+ return {
36
+ encode: (submission) => ({
37
+ PartitionKey: submission.formId,
38
+ RowKey: submission.id,
39
+ answers: JSON.stringify(Object.entries(submission.values).map(([questionId, value]) => ({ questionId, value }))),
40
+ answeredAt: submission.submittedAt,
41
+ surveyVersion: submission.formVersion,
42
+ locale: submission.locale,
43
+ ...submission.metadata
44
+ }),
45
+ decode: (entity) => {
46
+ const raw = entity;
47
+ if (typeof raw.PartitionKey !== "string" || typeof raw.RowKey !== "string") {
48
+ throw new Error("Azure Table legacy array submission is missing PartitionKey or RowKey.");
49
+ }
50
+ const submittedAt = typeof raw.answeredAt === "string" ? raw.answeredAt : entity.Timestamp;
51
+ if (typeof submittedAt !== "string" || submittedAt.trim().length === 0) {
52
+ throw new Error("Azure Table legacy array submission is missing answeredAt or Timestamp.");
53
+ }
54
+ let values = {};
55
+ if (typeof raw.answers === "string") {
56
+ const parsed = parseJson(raw.answers, "legacy array answers");
57
+ if (Array.isArray(parsed)) {
58
+ values = Object.fromEntries(
59
+ parsed.flatMap((item) => {
60
+ if (!isRecord(item) || typeof item.questionId !== "string") return [];
61
+ return [[item.questionId, item.value]];
62
+ })
63
+ );
64
+ } else if (isRecord(parsed)) {
65
+ values = parsed;
66
+ } else {
67
+ throw new Error("Azure Table legacy array answers payload must be an array or object.");
68
+ }
69
+ }
70
+ const formVersion = Number(raw.surveyVersion);
71
+ return {
72
+ id: raw.RowKey,
73
+ formId: raw.PartitionKey,
74
+ formVersion: Number.isSafeInteger(formVersion) && formVersion > 0 ? formVersion : 1,
75
+ values,
76
+ locale: typeof raw.locale === "string" && raw.locale.trim().length > 0 ? raw.locale : defaultLocale,
77
+ metadata: options.metadataExtractor?.(entity) ?? {},
78
+ submittedAt
79
+ };
80
+ }
81
+ };
82
+ }
31
83
  var createLegacyAzureTableCodec = (options = {}) => {
32
84
  const createPartitionKey = options.partitionKeyGenerator ?? ((formId) => formId);
33
85
  const createRowKey = options.rowKeyGenerator ?? ((submittedAt, submissionId) => `${submittedAt}_${submissionId}`);
@@ -648,6 +700,7 @@ function createAzureTableStorage(options = {}) {
648
700
  // Annotate the CommonJS export names for ESM import in node:
649
701
  0 && (module.exports = {
650
702
  createAzureTableStorage,
703
+ createLegacyArrayAzureTableCodec,
651
704
  createLegacyAzureTableCodec,
652
705
  defaultAzureTableSubmissionCodec,
653
706
  metadataFiltersToOData,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { FormSubmission, SubmissionPageQueryOptions, PagedSubmissionStorageAdapter, SubmissionFilter } from '@form-engine-ts/core';
1
+ import { FormSubmission, SubmissionPageQueryOptions, BaseSubmissionMetadata, StrictFormSubmission, PagedSubmissionStorageAdapter, SubmissionFilter } from '@form-engine-ts/core';
2
2
 
3
3
  interface AzureTableListOptions {
4
4
  readonly queryOptions?: {
@@ -44,6 +44,22 @@ interface AzureTableLegacyCodec {
44
44
  readonly createPartitionKey: (formId: string, submissionId: string) => string;
45
45
  readonly createRowKey: (submittedAt: string, submissionId: string) => string;
46
46
  }
47
+ interface LegacyAnswerArrayEntity extends Record<string, unknown> {
48
+ readonly PartitionKey: string;
49
+ readonly RowKey: string;
50
+ readonly answers: string;
51
+ readonly answeredAt: string;
52
+ readonly surveyVersion: number;
53
+ readonly locale?: string;
54
+ }
55
+ interface LegacyArrayAzureTableCodec<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata> {
56
+ readonly encode: (submission: StrictFormSubmission<TMeta>) => Record<string, unknown>;
57
+ readonly decode: (entity: Record<string, unknown>) => StrictFormSubmission<TMeta>;
58
+ }
59
+ declare function createLegacyArrayAzureTableCodec<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata>(options?: {
60
+ readonly defaultLocale?: string;
61
+ readonly metadataExtractor?: (entity: Record<string, unknown>) => TMeta;
62
+ }): LegacyArrayAzureTableCodec<TMeta>;
47
63
  declare const createLegacyAzureTableCodec: (options?: {
48
64
  readonly partitionKeyGenerator?: (formId: string, submissionId: string) => string;
49
65
  readonly rowKeyGenerator?: (submittedAt: string, submissionId: string) => string;
@@ -104,4 +120,4 @@ declare function metadataFiltersToOData(options: SubmissionPageQueryOptions, map
104
120
  declare function submissionFilterToOData(filter: SubmissionFilter, mapping?: AzureTableFieldMapping): string | undefined;
105
121
  declare function createAzureTableStorage(options?: AzureTableStorageOptions): PagedSubmissionStorageAdapter;
106
122
 
107
- export { type AzureTableClientLike, type AzureTableEntityCodec, type AzureTableEntityIterator, type AzureTableEntityPage, type AzureTableFieldMapping, type AzureTableLegacyCodec, type AzureTableLegacyEntity, type AzureTableListOptions, type AzureTablePageSettings, type AzureTableStorageOptions, type AzureTableSubmissionCodec, type AzureTableValueCodec, type AzureTextAnswerCursorPayload, createAzureTableStorage, createLegacyAzureTableCodec, defaultAzureTableSubmissionCodec, metadataFiltersToOData, submissionFilterToOData };
123
+ export { type AzureTableClientLike, type AzureTableEntityCodec, type AzureTableEntityIterator, type AzureTableEntityPage, type AzureTableFieldMapping, type AzureTableLegacyCodec, type AzureTableLegacyEntity, type AzureTableListOptions, type AzureTablePageSettings, type AzureTableStorageOptions, type AzureTableSubmissionCodec, type AzureTableValueCodec, type AzureTextAnswerCursorPayload, type LegacyAnswerArrayEntity, type LegacyArrayAzureTableCodec, createAzureTableStorage, createLegacyArrayAzureTableCodec, createLegacyAzureTableCodec, defaultAzureTableSubmissionCodec, metadataFiltersToOData, submissionFilterToOData };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FormSubmission, SubmissionPageQueryOptions, PagedSubmissionStorageAdapter, SubmissionFilter } from '@form-engine-ts/core';
1
+ import { FormSubmission, SubmissionPageQueryOptions, BaseSubmissionMetadata, StrictFormSubmission, PagedSubmissionStorageAdapter, SubmissionFilter } from '@form-engine-ts/core';
2
2
 
3
3
  interface AzureTableListOptions {
4
4
  readonly queryOptions?: {
@@ -44,6 +44,22 @@ interface AzureTableLegacyCodec {
44
44
  readonly createPartitionKey: (formId: string, submissionId: string) => string;
45
45
  readonly createRowKey: (submittedAt: string, submissionId: string) => string;
46
46
  }
47
+ interface LegacyAnswerArrayEntity extends Record<string, unknown> {
48
+ readonly PartitionKey: string;
49
+ readonly RowKey: string;
50
+ readonly answers: string;
51
+ readonly answeredAt: string;
52
+ readonly surveyVersion: number;
53
+ readonly locale?: string;
54
+ }
55
+ interface LegacyArrayAzureTableCodec<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata> {
56
+ readonly encode: (submission: StrictFormSubmission<TMeta>) => Record<string, unknown>;
57
+ readonly decode: (entity: Record<string, unknown>) => StrictFormSubmission<TMeta>;
58
+ }
59
+ declare function createLegacyArrayAzureTableCodec<TMeta extends BaseSubmissionMetadata = BaseSubmissionMetadata>(options?: {
60
+ readonly defaultLocale?: string;
61
+ readonly metadataExtractor?: (entity: Record<string, unknown>) => TMeta;
62
+ }): LegacyArrayAzureTableCodec<TMeta>;
47
63
  declare const createLegacyAzureTableCodec: (options?: {
48
64
  readonly partitionKeyGenerator?: (formId: string, submissionId: string) => string;
49
65
  readonly rowKeyGenerator?: (submittedAt: string, submissionId: string) => string;
@@ -104,4 +120,4 @@ declare function metadataFiltersToOData(options: SubmissionPageQueryOptions, map
104
120
  declare function submissionFilterToOData(filter: SubmissionFilter, mapping?: AzureTableFieldMapping): string | undefined;
105
121
  declare function createAzureTableStorage(options?: AzureTableStorageOptions): PagedSubmissionStorageAdapter;
106
122
 
107
- export { type AzureTableClientLike, type AzureTableEntityCodec, type AzureTableEntityIterator, type AzureTableEntityPage, type AzureTableFieldMapping, type AzureTableLegacyCodec, type AzureTableLegacyEntity, type AzureTableListOptions, type AzureTablePageSettings, type AzureTableStorageOptions, type AzureTableSubmissionCodec, type AzureTableValueCodec, type AzureTextAnswerCursorPayload, createAzureTableStorage, createLegacyAzureTableCodec, defaultAzureTableSubmissionCodec, metadataFiltersToOData, submissionFilterToOData };
123
+ export { type AzureTableClientLike, type AzureTableEntityCodec, type AzureTableEntityIterator, type AzureTableEntityPage, type AzureTableFieldMapping, type AzureTableLegacyCodec, type AzureTableLegacyEntity, type AzureTableListOptions, type AzureTablePageSettings, type AzureTableStorageOptions, type AzureTableSubmissionCodec, type AzureTableValueCodec, type AzureTextAnswerCursorPayload, type LegacyAnswerArrayEntity, type LegacyArrayAzureTableCodec, createAzureTableStorage, createLegacyArrayAzureTableCodec, createLegacyAzureTableCodec, defaultAzureTableSubmissionCodec, metadataFiltersToOData, submissionFilterToOData };
package/dist/index.js CHANGED
@@ -1,5 +1,56 @@
1
1
  // src/index.ts
2
2
  import { assertValidFormSchema, matchesSubmissionPageFilters, normalizeSubmissionPageSize } from "@form-engine-ts/core";
3
+ function createLegacyArrayAzureTableCodec(options = {}) {
4
+ const defaultLocale = options.defaultLocale ?? "ja";
5
+ if (defaultLocale.trim().length === 0) throw new TypeError("defaultLocale must not be empty.");
6
+ return {
7
+ encode: (submission) => ({
8
+ PartitionKey: submission.formId,
9
+ RowKey: submission.id,
10
+ answers: JSON.stringify(Object.entries(submission.values).map(([questionId, value]) => ({ questionId, value }))),
11
+ answeredAt: submission.submittedAt,
12
+ surveyVersion: submission.formVersion,
13
+ locale: submission.locale,
14
+ ...submission.metadata
15
+ }),
16
+ decode: (entity) => {
17
+ const raw = entity;
18
+ if (typeof raw.PartitionKey !== "string" || typeof raw.RowKey !== "string") {
19
+ throw new Error("Azure Table legacy array submission is missing PartitionKey or RowKey.");
20
+ }
21
+ const submittedAt = typeof raw.answeredAt === "string" ? raw.answeredAt : entity.Timestamp;
22
+ if (typeof submittedAt !== "string" || submittedAt.trim().length === 0) {
23
+ throw new Error("Azure Table legacy array submission is missing answeredAt or Timestamp.");
24
+ }
25
+ let values = {};
26
+ if (typeof raw.answers === "string") {
27
+ const parsed = parseJson(raw.answers, "legacy array answers");
28
+ if (Array.isArray(parsed)) {
29
+ values = Object.fromEntries(
30
+ parsed.flatMap((item) => {
31
+ if (!isRecord(item) || typeof item.questionId !== "string") return [];
32
+ return [[item.questionId, item.value]];
33
+ })
34
+ );
35
+ } else if (isRecord(parsed)) {
36
+ values = parsed;
37
+ } else {
38
+ throw new Error("Azure Table legacy array answers payload must be an array or object.");
39
+ }
40
+ }
41
+ const formVersion = Number(raw.surveyVersion);
42
+ return {
43
+ id: raw.RowKey,
44
+ formId: raw.PartitionKey,
45
+ formVersion: Number.isSafeInteger(formVersion) && formVersion > 0 ? formVersion : 1,
46
+ values,
47
+ locale: typeof raw.locale === "string" && raw.locale.trim().length > 0 ? raw.locale : defaultLocale,
48
+ metadata: options.metadataExtractor?.(entity) ?? {},
49
+ submittedAt
50
+ };
51
+ }
52
+ };
53
+ }
3
54
  var createLegacyAzureTableCodec = (options = {}) => {
4
55
  const createPartitionKey = options.partitionKeyGenerator ?? ((formId) => formId);
5
56
  const createRowKey = options.rowKeyGenerator ?? ((submittedAt, submissionId) => `${submittedAt}_${submissionId}`);
@@ -619,6 +670,7 @@ function createAzureTableStorage(options = {}) {
619
670
  }
620
671
  export {
621
672
  createAzureTableStorage,
673
+ createLegacyArrayAzureTableCodec,
622
674
  createLegacyAzureTableCodec,
623
675
  defaultAzureTableSubmissionCodec,
624
676
  metadataFiltersToOData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-engine-ts/storage-azure-table",
3
- "version": "6.0.0",
3
+ "version": "6.2.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": "6.0.0"
42
+ "@form-engine-ts/core": "6.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@azure/data-tables": "^13.3.2"