@form-engine-ts/core 4.6.0 → 4.7.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 +3 -1
- package/dist/index.cjs +59 -16
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +59 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,9 @@ and missing, translated, stale, or manual states for authoring tools. `populateS
|
|
|
63
63
|
and missing entries while preserving manual translations and reports skipped reasons.
|
|
64
64
|
|
|
65
65
|
Legacy translation metadata can be recognized with `isManualTranslationMetadata` and migrated with
|
|
66
|
-
`migrateSchemaTranslationMetadata`; pass a custom migrator when legacy fields need
|
|
66
|
+
`migrateSchemaTranslationMetadata`; pass a custom migrator (directly or as `{ migrator }`) when legacy fields need
|
|
67
|
+
application-specific conversion. The migrator receives `TranslationMigrationContext` with the locale, JSON path,
|
|
68
|
+
property, node kind, and node identifiers.
|
|
67
69
|
`PopulateTranslationsOptions` is a compatibility alias for `PopulateTranslationOptions`, which also accepts custom
|
|
68
70
|
manual-translation detection and metadata normalization callbacks. `removeLocaleFromSchema(schema, locale)` removes
|
|
69
71
|
the locale from registrations and all form, page, field, option translation values and metadata; the default locale
|
package/dist/index.cjs
CHANGED
|
@@ -2456,10 +2456,9 @@ function removeLocalizedNodeLocale(node, locale) {
|
|
|
2456
2456
|
...translationMetadata === void 0 ? {} : { translationMetadata }
|
|
2457
2457
|
};
|
|
2458
2458
|
}
|
|
2459
|
-
function
|
|
2460
|
-
if (customMigrator !== void 0) return customMigrator(metadata, sourceText);
|
|
2459
|
+
function defaultTranslationMetadataMigrator(metadata, sourceText, defaultLocale) {
|
|
2461
2460
|
const record = metadata !== null && typeof metadata === "object" ? metadata : void 0;
|
|
2462
|
-
const sourceLocale = typeof record?.sourceLocale === "string" ? record.sourceLocale : defaultLocale
|
|
2461
|
+
const sourceLocale = typeof record?.sourceLocale === "string" ? record.sourceLocale : defaultLocale;
|
|
2463
2462
|
const translationSource = isManualTranslationMetadata(record) ? "manual" : "automatic";
|
|
2464
2463
|
return {
|
|
2465
2464
|
sourceLocale,
|
|
@@ -2469,22 +2468,33 @@ function migrateMetadata(metadata, sourceText, defaultLocale, customMigrator) {
|
|
|
2469
2468
|
...typeof record?.editedAt === "string" ? { editedAt: record.editedAt } : {}
|
|
2470
2469
|
};
|
|
2471
2470
|
}
|
|
2472
|
-
function
|
|
2471
|
+
function migrateMetadata(metadata, sourceText, context, migrator) {
|
|
2472
|
+
return migrator(metadata, sourceText, context);
|
|
2473
|
+
}
|
|
2474
|
+
function isTranslationMetadataProperty(property) {
|
|
2475
|
+
return property === "title" || property === "description" || property === "label" || property === "completionMessage";
|
|
2476
|
+
}
|
|
2477
|
+
function migrateNodeMetadata(node, sourceTexts, contextFor, migrator) {
|
|
2473
2478
|
if (node.translationMetadata === void 0) return node;
|
|
2474
2479
|
const translationMetadata = Object.fromEntries(
|
|
2475
2480
|
Object.entries(node.translationMetadata).map(([locale, properties]) => [
|
|
2476
2481
|
locale,
|
|
2477
2482
|
Object.fromEntries(
|
|
2478
|
-
Object.entries(properties).map(([property, metadata]) =>
|
|
2479
|
-
property,
|
|
2480
|
-
|
|
2481
|
-
|
|
2483
|
+
Object.entries(properties).map(([property, metadata]) => {
|
|
2484
|
+
if (!isTranslationMetadataProperty(property)) return [property, metadata];
|
|
2485
|
+
return [
|
|
2486
|
+
property,
|
|
2487
|
+
migrateMetadata(metadata, sourceTexts[property] ?? "", contextFor(locale, property), migrator)
|
|
2488
|
+
];
|
|
2489
|
+
})
|
|
2482
2490
|
)
|
|
2483
2491
|
])
|
|
2484
2492
|
);
|
|
2485
2493
|
return { ...node, translationMetadata };
|
|
2486
2494
|
}
|
|
2487
|
-
var migrateSchemaTranslationMetadata = (schema,
|
|
2495
|
+
var migrateSchemaTranslationMetadata = (schema, migratorOrOptions) => {
|
|
2496
|
+
const defaultLocale = schema.defaultLocale ?? "";
|
|
2497
|
+
const migrator = typeof migratorOrOptions === "function" ? migratorOrOptions : migratorOrOptions?.migrator ?? ((metadata, sourceText, context) => defaultTranslationMetadataMigrator(metadata, sourceText, context.defaultLocale));
|
|
2488
2498
|
const migratedSchema = migrateNodeMetadata(
|
|
2489
2499
|
schema,
|
|
2490
2500
|
{
|
|
@@ -2492,21 +2502,47 @@ var migrateSchemaTranslationMetadata = (schema, customMigrator) => {
|
|
|
2492
2502
|
...schema.description === void 0 ? {} : { description: schema.description },
|
|
2493
2503
|
...schema.completionMessage === void 0 ? {} : { completionMessage: schema.completionMessage }
|
|
2494
2504
|
},
|
|
2495
|
-
|
|
2496
|
-
|
|
2505
|
+
(locale, property) => ({
|
|
2506
|
+
locale,
|
|
2507
|
+
defaultLocale,
|
|
2508
|
+
path: property,
|
|
2509
|
+
property,
|
|
2510
|
+
nodeKind: "form"
|
|
2511
|
+
}),
|
|
2512
|
+
migrator
|
|
2497
2513
|
);
|
|
2498
2514
|
const fields = schema.fields.map((field) => {
|
|
2499
2515
|
const migratedField = migrateNodeMetadata(
|
|
2500
2516
|
field,
|
|
2501
2517
|
{ title: field.title, ...field.description === void 0 ? {} : { description: field.description } },
|
|
2502
|
-
|
|
2503
|
-
|
|
2518
|
+
(locale, property) => ({
|
|
2519
|
+
locale,
|
|
2520
|
+
defaultLocale,
|
|
2521
|
+
path: `fields.${field.id}.${property}`,
|
|
2522
|
+
property,
|
|
2523
|
+
nodeKind: "field",
|
|
2524
|
+
nodeId: field.id
|
|
2525
|
+
}),
|
|
2526
|
+
migrator
|
|
2504
2527
|
);
|
|
2505
2528
|
if (!("options" in migratedField)) return migratedField;
|
|
2506
2529
|
return {
|
|
2507
2530
|
...migratedField,
|
|
2508
2531
|
options: migratedField.options.map(
|
|
2509
|
-
(option) => migrateNodeMetadata(
|
|
2532
|
+
(option) => migrateNodeMetadata(
|
|
2533
|
+
option,
|
|
2534
|
+
{ label: option.label },
|
|
2535
|
+
(locale, property) => ({
|
|
2536
|
+
locale,
|
|
2537
|
+
defaultLocale,
|
|
2538
|
+
path: `fields.${field.id}.options.${option.id}.${property}`,
|
|
2539
|
+
property,
|
|
2540
|
+
nodeKind: "option",
|
|
2541
|
+
nodeId: option.id,
|
|
2542
|
+
parentId: field.id
|
|
2543
|
+
}),
|
|
2544
|
+
migrator
|
|
2545
|
+
)
|
|
2510
2546
|
)
|
|
2511
2547
|
};
|
|
2512
2548
|
});
|
|
@@ -2517,8 +2553,15 @@ var migrateSchemaTranslationMetadata = (schema, customMigrator) => {
|
|
|
2517
2553
|
...page.title === void 0 ? {} : { title: page.title },
|
|
2518
2554
|
...page.description === void 0 ? {} : { description: page.description }
|
|
2519
2555
|
},
|
|
2520
|
-
|
|
2521
|
-
|
|
2556
|
+
(locale, property) => ({
|
|
2557
|
+
locale,
|
|
2558
|
+
defaultLocale,
|
|
2559
|
+
path: `pages.${page.id}.${property}`,
|
|
2560
|
+
property,
|
|
2561
|
+
nodeKind: "page",
|
|
2562
|
+
nodeId: page.id
|
|
2563
|
+
}),
|
|
2564
|
+
migrator
|
|
2522
2565
|
)
|
|
2523
2566
|
);
|
|
2524
2567
|
return {
|
package/dist/index.d.cts
CHANGED
|
@@ -697,6 +697,27 @@ interface LegacyTranslationMetadata {
|
|
|
697
697
|
readonly isManual?: boolean;
|
|
698
698
|
readonly [key: string]: unknown;
|
|
699
699
|
}
|
|
700
|
+
interface TranslationMigrationContext {
|
|
701
|
+
/** Target locale code, for example "en" or "zh-Hans". */
|
|
702
|
+
readonly locale: string;
|
|
703
|
+
/** The schema's default locale. */
|
|
704
|
+
readonly defaultLocale: string;
|
|
705
|
+
/** JSON path of the translated property. */
|
|
706
|
+
readonly path: string;
|
|
707
|
+
/** Translated property name. */
|
|
708
|
+
readonly property: "title" | "description" | "label" | "completionMessage";
|
|
709
|
+
/** Kind of node that owns the translated property. */
|
|
710
|
+
readonly nodeKind: "form" | "page" | "field" | "option";
|
|
711
|
+
/** Identifier of the owning node. */
|
|
712
|
+
readonly nodeId?: string;
|
|
713
|
+
/** Identifier of the parent node, used for options. */
|
|
714
|
+
readonly parentId?: string;
|
|
715
|
+
}
|
|
716
|
+
type TranslationMetadataMigrator = (oldMeta: unknown, sourceText: string, context: TranslationMigrationContext) => CanonicalTranslationMetadata;
|
|
717
|
+
interface MigrateSchemaTranslationMetadataOptions {
|
|
718
|
+
/** Custom migration function used instead of the built-in legacy normalizer. */
|
|
719
|
+
readonly migrator?: TranslationMetadataMigrator;
|
|
720
|
+
}
|
|
700
721
|
declare const isManualTranslationMetadata: (metadata?: LegacyTranslationMetadata | CanonicalTranslationMetadata) => boolean;
|
|
701
722
|
interface PopulateTranslationOptions {
|
|
702
723
|
readonly overwrite?: "all" | "missing-only" | "stale-and-missing";
|
|
@@ -722,7 +743,7 @@ interface TranslationReport {
|
|
|
722
743
|
}
|
|
723
744
|
declare const computeSourceTextHash: (text: string) => string;
|
|
724
745
|
declare function getTranslationStatus(sourceText: string, translatedText: string | undefined, metadata: CanonicalTranslationMetadata | Readonly<Record<string, JsonValue>> | undefined): TranslationStatus;
|
|
725
|
-
declare const migrateSchemaTranslationMetadata: (schema: FormSchema,
|
|
746
|
+
declare const migrateSchemaTranslationMetadata: (schema: FormSchema, migratorOrOptions?: ((oldMeta: unknown, sourceText: string) => CanonicalTranslationMetadata) | TranslationMetadataMigrator | MigrateSchemaTranslationMetadataOptions) => FormSchema;
|
|
726
747
|
/** Removes a locale registration and every localized value and metadata entry for it. */
|
|
727
748
|
declare const removeLocaleFromSchema: (schema: FormSchema, localeToRemove: string) => FormSchema;
|
|
728
749
|
declare function collectTranslationSlots(schema: FormSchema, locale: string): readonly TranslationSlot[];
|
|
@@ -747,4 +768,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
|
|
|
747
768
|
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
748
769
|
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
749
770
|
|
|
750
|
-
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormSubmissionSettings, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LegacyTranslationMetadata, type LocalizedText, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type TranslationStatus, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
|
771
|
+
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormSubmissionSettings, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LegacyTranslationMetadata, type LocalizedText, type MigrateSchemaTranslationMetadataOptions, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationMetadataMigrator, type TranslationMigrationContext, type TranslationReport, type TranslationSlot, type TranslationStatus, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
package/dist/index.d.ts
CHANGED
|
@@ -697,6 +697,27 @@ interface LegacyTranslationMetadata {
|
|
|
697
697
|
readonly isManual?: boolean;
|
|
698
698
|
readonly [key: string]: unknown;
|
|
699
699
|
}
|
|
700
|
+
interface TranslationMigrationContext {
|
|
701
|
+
/** Target locale code, for example "en" or "zh-Hans". */
|
|
702
|
+
readonly locale: string;
|
|
703
|
+
/** The schema's default locale. */
|
|
704
|
+
readonly defaultLocale: string;
|
|
705
|
+
/** JSON path of the translated property. */
|
|
706
|
+
readonly path: string;
|
|
707
|
+
/** Translated property name. */
|
|
708
|
+
readonly property: "title" | "description" | "label" | "completionMessage";
|
|
709
|
+
/** Kind of node that owns the translated property. */
|
|
710
|
+
readonly nodeKind: "form" | "page" | "field" | "option";
|
|
711
|
+
/** Identifier of the owning node. */
|
|
712
|
+
readonly nodeId?: string;
|
|
713
|
+
/** Identifier of the parent node, used for options. */
|
|
714
|
+
readonly parentId?: string;
|
|
715
|
+
}
|
|
716
|
+
type TranslationMetadataMigrator = (oldMeta: unknown, sourceText: string, context: TranslationMigrationContext) => CanonicalTranslationMetadata;
|
|
717
|
+
interface MigrateSchemaTranslationMetadataOptions {
|
|
718
|
+
/** Custom migration function used instead of the built-in legacy normalizer. */
|
|
719
|
+
readonly migrator?: TranslationMetadataMigrator;
|
|
720
|
+
}
|
|
700
721
|
declare const isManualTranslationMetadata: (metadata?: LegacyTranslationMetadata | CanonicalTranslationMetadata) => boolean;
|
|
701
722
|
interface PopulateTranslationOptions {
|
|
702
723
|
readonly overwrite?: "all" | "missing-only" | "stale-and-missing";
|
|
@@ -722,7 +743,7 @@ interface TranslationReport {
|
|
|
722
743
|
}
|
|
723
744
|
declare const computeSourceTextHash: (text: string) => string;
|
|
724
745
|
declare function getTranslationStatus(sourceText: string, translatedText: string | undefined, metadata: CanonicalTranslationMetadata | Readonly<Record<string, JsonValue>> | undefined): TranslationStatus;
|
|
725
|
-
declare const migrateSchemaTranslationMetadata: (schema: FormSchema,
|
|
746
|
+
declare const migrateSchemaTranslationMetadata: (schema: FormSchema, migratorOrOptions?: ((oldMeta: unknown, sourceText: string) => CanonicalTranslationMetadata) | TranslationMetadataMigrator | MigrateSchemaTranslationMetadataOptions) => FormSchema;
|
|
726
747
|
/** Removes a locale registration and every localized value and metadata entry for it. */
|
|
727
748
|
declare const removeLocaleFromSchema: (schema: FormSchema, localeToRemove: string) => FormSchema;
|
|
728
749
|
declare function collectTranslationSlots(schema: FormSchema, locale: string): readonly TranslationSlot[];
|
|
@@ -747,4 +768,4 @@ declare function calculatePageVisibility(schema: FormSchema, currentAnswers: Rea
|
|
|
747
768
|
declare function calculateFieldVisibility(schema: FormSchema, currentAnswers: Readonly<Record<string, unknown>>): Readonly<Record<string, boolean>>;
|
|
748
769
|
declare function selectVisibleAnswers(schema: FormSchema, currentAnswers: FormValues): FormValues;
|
|
749
770
|
|
|
750
|
-
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormSubmissionSettings, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LegacyTranslationMetadata, type LocalizedText, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationReport, type TranslationSlot, type TranslationStatus, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
|
771
|
+
export { type AccumulatorReport, type AccumulatorResponse, type AccumulatorSkipReason, type AnswerValidationResult, type AsyncTranslationAdapter, type BaseField, type BaseFieldConstraintRule, type BuilderTranslationKey, type CanonicalTranslationMetadata, type CheckboxField, type CheckboxQuestionAggregate, type ChoiceDistributionEntry, type ChoiceFieldConstraintRule, type ChoiceOption, type ChoiceQuestionAggregate, type CloneVersionOptions, type CollectedLocales, type ConditionOperator, type ConditionValue, type CreateSubmissionOptions, type CrossTabulationResult, type CsvColumnContext, type CsvColumnDef, type CsvExportOptions, DEFAULT_FIELD_TYPE_DEFINITIONS, type DeleteDraftOptions, type DisplayCondition, type DisplayConditionGroup, type DisplayRule, type ExtensibleNode, type FieldConstraintRule, type FieldDisplayCondition, type FieldOption, type FieldType, type FieldTypeDefinition, type FormAnalytics, type FormEvent, type FormEventType, type FormField, type FormPage, type FormPolicy, type FormResponse, type FormSchema, type FormStorageAdapter, type FormSubmission, type FormSubmissionSettings, type FormValue, type FormValues, type FormVersionRecord, type FormVersionState, type FormVersionStatus, type JsonValue, type LegacyTranslationMetadata, type LocalizedText, type MigrateSchemaTranslationMetadataOptions, type MultiSelectField, type NodeWritableStream, type NumberField, type NumberQuestionAggregate, type NumericSummary, type OptionAggregate, type PagedSubmissionStorageAdapter, type PaginationIteratorOptions, type PopulateTranslationOptions, type PopulateTranslationsOptions, type PublishDraftOptions, type PublishDraftResult, type Question, type QuestionAggregate, type QuestionType, type RatingField, type RatingFieldConstraintRule, type ResponseAccumulator, type ResponseAccumulatorOptions, type Result, type SanitizeSchemaOptions, type SchemaIssue, type SchemaStructureIssue, type SchemaStructureIssueType, type SchemaTranslations, type SchemaValidationResult, type SelectField, type StorageAdapter, type StorageCommitError, type StreamCsvOptions, type SubmissionCursorValue, type SubmissionFilter, type SubmissionPage, type SubmissionPageQueryOptions, type SubmissionQueryOptions, type TextAnswerCursorValue, type TextAnswerItem, type TextAnswerPage, type TextAnswerPageQueryOptions, type TextField, type TextFieldConstraintRule, type TextQuestionAggregate, type TranslationAdapter, type TranslationMetadataMigrator, type TranslationMigrationContext, type TranslationReport, type TranslationSlot, type TranslationStatus, type ValidateFormSchemaOptions, type ValidationCode, type ValidationError, type ValidationIssue, type VersionTransitionError, type VersionTransitionEvent, type VersionTransitionPlan, type VersionedFormStorageAdapter, type WebhookConfig, type WebhookDispatchResult, aggregateResponses, assertValidFormSchema, assertVersionMutable, calculateChoiceDistribution, calculateCrossTabulation, calculateFieldVisibility, calculateNumericSummary, calculatePageVisibility, cloneVersionToDraft, collectSchemaLocales, collectTranslationSlots, computeSourceTextHash, createCloneTransitionPlan, createDeleteDraftTransitionPlan, createPublishTransitionPlan, createResponseAccumulator, createSubmission, decodeSubmissionCursor, decodeTextAnswerCursor, deleteDraft, dispatchWebhook, encodeSubmissionCursor, encodeTextAnswerCursor, escapeCsvCell, exportResponsesToCsv, exportResponsesToCsvStream, getTranslationStatus, isDisplayConditionGroupSatisfied, isDisplayConditionSatisfied, isManualTranslationMetadata, isQuestionVisible, iterateSubmissionPages, jsonValuesEqual, matchesSubmissionFilter, matchesSubmissionPageFilters, migrateSchemaTranslationMetadata, normalizeSubmissionPageSize, pipeResponsesToCsvStream, populateSchemaTranslations, publishDraft, removeLocaleFromSchema, resolveFormTranslation, resolveLocalizedSchema, sanitizeSchema, selectVisibleAnswers, transformFieldType, validateAnswers, validateFormSchema, validatePageAnswers, validateSchemaStructure };
|
package/dist/index.js
CHANGED
|
@@ -2380,10 +2380,9 @@ function removeLocalizedNodeLocale(node, locale) {
|
|
|
2380
2380
|
...translationMetadata === void 0 ? {} : { translationMetadata }
|
|
2381
2381
|
};
|
|
2382
2382
|
}
|
|
2383
|
-
function
|
|
2384
|
-
if (customMigrator !== void 0) return customMigrator(metadata, sourceText);
|
|
2383
|
+
function defaultTranslationMetadataMigrator(metadata, sourceText, defaultLocale) {
|
|
2385
2384
|
const record = metadata !== null && typeof metadata === "object" ? metadata : void 0;
|
|
2386
|
-
const sourceLocale = typeof record?.sourceLocale === "string" ? record.sourceLocale : defaultLocale
|
|
2385
|
+
const sourceLocale = typeof record?.sourceLocale === "string" ? record.sourceLocale : defaultLocale;
|
|
2387
2386
|
const translationSource = isManualTranslationMetadata(record) ? "manual" : "automatic";
|
|
2388
2387
|
return {
|
|
2389
2388
|
sourceLocale,
|
|
@@ -2393,22 +2392,33 @@ function migrateMetadata(metadata, sourceText, defaultLocale, customMigrator) {
|
|
|
2393
2392
|
...typeof record?.editedAt === "string" ? { editedAt: record.editedAt } : {}
|
|
2394
2393
|
};
|
|
2395
2394
|
}
|
|
2396
|
-
function
|
|
2395
|
+
function migrateMetadata(metadata, sourceText, context, migrator) {
|
|
2396
|
+
return migrator(metadata, sourceText, context);
|
|
2397
|
+
}
|
|
2398
|
+
function isTranslationMetadataProperty(property) {
|
|
2399
|
+
return property === "title" || property === "description" || property === "label" || property === "completionMessage";
|
|
2400
|
+
}
|
|
2401
|
+
function migrateNodeMetadata(node, sourceTexts, contextFor, migrator) {
|
|
2397
2402
|
if (node.translationMetadata === void 0) return node;
|
|
2398
2403
|
const translationMetadata = Object.fromEntries(
|
|
2399
2404
|
Object.entries(node.translationMetadata).map(([locale, properties]) => [
|
|
2400
2405
|
locale,
|
|
2401
2406
|
Object.fromEntries(
|
|
2402
|
-
Object.entries(properties).map(([property, metadata]) =>
|
|
2403
|
-
property,
|
|
2404
|
-
|
|
2405
|
-
|
|
2407
|
+
Object.entries(properties).map(([property, metadata]) => {
|
|
2408
|
+
if (!isTranslationMetadataProperty(property)) return [property, metadata];
|
|
2409
|
+
return [
|
|
2410
|
+
property,
|
|
2411
|
+
migrateMetadata(metadata, sourceTexts[property] ?? "", contextFor(locale, property), migrator)
|
|
2412
|
+
];
|
|
2413
|
+
})
|
|
2406
2414
|
)
|
|
2407
2415
|
])
|
|
2408
2416
|
);
|
|
2409
2417
|
return { ...node, translationMetadata };
|
|
2410
2418
|
}
|
|
2411
|
-
var migrateSchemaTranslationMetadata = (schema,
|
|
2419
|
+
var migrateSchemaTranslationMetadata = (schema, migratorOrOptions) => {
|
|
2420
|
+
const defaultLocale = schema.defaultLocale ?? "";
|
|
2421
|
+
const migrator = typeof migratorOrOptions === "function" ? migratorOrOptions : migratorOrOptions?.migrator ?? ((metadata, sourceText, context) => defaultTranslationMetadataMigrator(metadata, sourceText, context.defaultLocale));
|
|
2412
2422
|
const migratedSchema = migrateNodeMetadata(
|
|
2413
2423
|
schema,
|
|
2414
2424
|
{
|
|
@@ -2416,21 +2426,47 @@ var migrateSchemaTranslationMetadata = (schema, customMigrator) => {
|
|
|
2416
2426
|
...schema.description === void 0 ? {} : { description: schema.description },
|
|
2417
2427
|
...schema.completionMessage === void 0 ? {} : { completionMessage: schema.completionMessage }
|
|
2418
2428
|
},
|
|
2419
|
-
|
|
2420
|
-
|
|
2429
|
+
(locale, property) => ({
|
|
2430
|
+
locale,
|
|
2431
|
+
defaultLocale,
|
|
2432
|
+
path: property,
|
|
2433
|
+
property,
|
|
2434
|
+
nodeKind: "form"
|
|
2435
|
+
}),
|
|
2436
|
+
migrator
|
|
2421
2437
|
);
|
|
2422
2438
|
const fields = schema.fields.map((field) => {
|
|
2423
2439
|
const migratedField = migrateNodeMetadata(
|
|
2424
2440
|
field,
|
|
2425
2441
|
{ title: field.title, ...field.description === void 0 ? {} : { description: field.description } },
|
|
2426
|
-
|
|
2427
|
-
|
|
2442
|
+
(locale, property) => ({
|
|
2443
|
+
locale,
|
|
2444
|
+
defaultLocale,
|
|
2445
|
+
path: `fields.${field.id}.${property}`,
|
|
2446
|
+
property,
|
|
2447
|
+
nodeKind: "field",
|
|
2448
|
+
nodeId: field.id
|
|
2449
|
+
}),
|
|
2450
|
+
migrator
|
|
2428
2451
|
);
|
|
2429
2452
|
if (!("options" in migratedField)) return migratedField;
|
|
2430
2453
|
return {
|
|
2431
2454
|
...migratedField,
|
|
2432
2455
|
options: migratedField.options.map(
|
|
2433
|
-
(option) => migrateNodeMetadata(
|
|
2456
|
+
(option) => migrateNodeMetadata(
|
|
2457
|
+
option,
|
|
2458
|
+
{ label: option.label },
|
|
2459
|
+
(locale, property) => ({
|
|
2460
|
+
locale,
|
|
2461
|
+
defaultLocale,
|
|
2462
|
+
path: `fields.${field.id}.options.${option.id}.${property}`,
|
|
2463
|
+
property,
|
|
2464
|
+
nodeKind: "option",
|
|
2465
|
+
nodeId: option.id,
|
|
2466
|
+
parentId: field.id
|
|
2467
|
+
}),
|
|
2468
|
+
migrator
|
|
2469
|
+
)
|
|
2434
2470
|
)
|
|
2435
2471
|
};
|
|
2436
2472
|
});
|
|
@@ -2441,8 +2477,15 @@ var migrateSchemaTranslationMetadata = (schema, customMigrator) => {
|
|
|
2441
2477
|
...page.title === void 0 ? {} : { title: page.title },
|
|
2442
2478
|
...page.description === void 0 ? {} : { description: page.description }
|
|
2443
2479
|
},
|
|
2444
|
-
|
|
2445
|
-
|
|
2480
|
+
(locale, property) => ({
|
|
2481
|
+
locale,
|
|
2482
|
+
defaultLocale,
|
|
2483
|
+
path: `pages.${page.id}.${property}`,
|
|
2484
|
+
property,
|
|
2485
|
+
nodeKind: "page",
|
|
2486
|
+
nodeId: page.id
|
|
2487
|
+
}),
|
|
2488
|
+
migrator
|
|
2446
2489
|
)
|
|
2447
2490
|
);
|
|
2448
2491
|
return {
|