@inlang/sdk 0.36.4 → 2.0.0-beta.2
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 +1 -1
- package/dist/database/initDb.d.ts +7 -0
- package/dist/database/initDb.d.ts.map +1 -0
- package/dist/database/initDb.js +36 -0
- package/dist/database/initDb.js.map +1 -0
- package/dist/database/initDbAndSchema.test.d.ts +2 -0
- package/dist/database/initDbAndSchema.test.d.ts.map +1 -0
- package/dist/database/initDbAndSchema.test.js +110 -0
- package/dist/database/initDbAndSchema.test.js.map +1 -0
- package/dist/database/jsonbPlugin.d.ts +20 -0
- package/dist/database/jsonbPlugin.d.ts.map +1 -0
- package/dist/database/jsonbPlugin.js +183 -0
- package/dist/database/jsonbPlugin.js.map +1 -0
- package/dist/database/jsonbPlugin.test.d.ts +2 -0
- package/dist/database/jsonbPlugin.test.d.ts.map +1 -0
- package/dist/database/jsonbPlugin.test.js +119 -0
- package/dist/database/jsonbPlugin.test.js.map +1 -0
- package/dist/database/schema.d.ts +74 -0
- package/dist/database/schema.d.ts.map +1 -0
- package/dist/database/schema.js +45 -0
- package/dist/database/schema.js.map +1 -0
- package/dist/helper.d.ts +71 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/helper.js +91 -0
- package/dist/helper.js.map +1 -0
- package/dist/human-id/human-id.d.ts +3 -0
- package/dist/human-id/human-id.d.ts.map +1 -0
- package/dist/human-id/human-id.js +12 -0
- package/dist/human-id/human-id.js.map +1 -0
- package/dist/human-id/words.d.ts.map +1 -0
- package/dist/{storage/human-id → human-id}/words.js +4 -0
- package/dist/human-id/words.js.map +1 -0
- package/dist/human-id/words.test.d.ts.map +1 -0
- package/dist/{storage/human-id → human-id}/words.test.js +4 -0
- package/dist/human-id/words.test.js.map +1 -0
- package/dist/import-export/exportFiles.d.ts +11 -0
- package/dist/import-export/exportFiles.d.ts.map +1 -0
- package/dist/import-export/exportFiles.js +26 -0
- package/dist/import-export/exportFiles.js.map +1 -0
- package/dist/import-export/importFiles.d.ts +13 -0
- package/dist/import-export/importFiles.d.ts.map +1 -0
- package/dist/import-export/importFiles.js +124 -0
- package/dist/import-export/importFiles.js.map +1 -0
- package/dist/import-export/importFiles.test.d.ts +2 -0
- package/dist/import-export/importFiles.test.d.ts.map +1 -0
- package/dist/import-export/importFiles.test.js +179 -0
- package/dist/import-export/importFiles.test.js.map +1 -0
- package/dist/import-export/roundtrip.test.d.ts +2 -0
- package/dist/import-export/roundtrip.test.d.ts.map +1 -0
- package/dist/import-export/roundtrip.test.js +273 -0
- package/dist/import-export/roundtrip.test.js.map +1 -0
- package/dist/import-export/upsertBundleNestedMatchByProperties.d.ts +4 -0
- package/dist/import-export/upsertBundleNestedMatchByProperties.d.ts.map +1 -0
- package/dist/import-export/upsertBundleNestedMatchByProperties.js +58 -0
- package/dist/import-export/upsertBundleNestedMatchByProperties.js.map +1 -0
- package/dist/index.d.ts +21 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -17
- package/dist/index.js.map +1 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.d.ts +9 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.d.ts.map +1 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.js +84 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.js.map +1 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.test.d.ts +2 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.test.d.ts.map +1 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.test.js +85 -0
- package/dist/json-schema/old-v1-message/fromMessageV1.test.js.map +1 -0
- package/dist/json-schema/old-v1-message/schemaV1.d.ts +86 -0
- package/dist/json-schema/old-v1-message/schemaV1.d.ts.map +1 -0
- package/dist/json-schema/old-v1-message/schemaV1.js +35 -0
- package/dist/json-schema/old-v1-message/schemaV1.js.map +1 -0
- package/dist/json-schema/old-v1-message/toMessageV1.d.ts +9 -0
- package/dist/json-schema/old-v1-message/toMessageV1.d.ts.map +1 -0
- package/dist/json-schema/old-v1-message/toMessageV1.js +67 -0
- package/dist/json-schema/old-v1-message/toMessageV1.js.map +1 -0
- package/dist/json-schema/old-v1-message/toMessageV1.test.d.ts +2 -0
- package/dist/json-schema/old-v1-message/toMessageV1.test.d.ts.map +1 -0
- package/dist/json-schema/old-v1-message/toMessageV1.test.js +85 -0
- package/dist/json-schema/old-v1-message/toMessageV1.test.js.map +1 -0
- package/dist/json-schema/pattern.d.ts +190 -0
- package/dist/json-schema/pattern.d.ts.map +1 -0
- package/dist/json-schema/pattern.js +43 -0
- package/dist/json-schema/pattern.js.map +1 -0
- package/dist/json-schema/settings.d.ts +31 -0
- package/dist/json-schema/settings.d.ts.map +1 -0
- package/dist/json-schema/settings.js +96 -0
- package/dist/json-schema/settings.js.map +1 -0
- package/dist/json-schema/settings.test-d.d.ts +2 -0
- package/dist/json-schema/settings.test-d.d.ts.map +1 -0
- package/dist/json-schema/settings.test-d.js +20 -0
- package/dist/json-schema/settings.test-d.js.map +1 -0
- package/dist/lix-plugin/applyChanges.d.ts +3 -0
- package/dist/lix-plugin/applyChanges.d.ts.map +1 -0
- package/dist/lix-plugin/applyChanges.js +127 -0
- package/dist/lix-plugin/applyChanges.js.map +1 -0
- package/dist/lix-plugin/applyChanges.test.d.ts +2 -0
- package/dist/lix-plugin/applyChanges.test.d.ts.map +1 -0
- package/dist/lix-plugin/applyChanges.test.js +135 -0
- package/dist/lix-plugin/applyChanges.test.js.map +1 -0
- package/dist/lix-plugin/detectConflicts.d.ts +3 -0
- package/dist/lix-plugin/detectConflicts.d.ts.map +1 -0
- package/dist/lix-plugin/detectConflicts.js +47 -0
- package/dist/lix-plugin/detectConflicts.js.map +1 -0
- package/dist/lix-plugin/detectConflicts.test.d.ts +2 -0
- package/dist/lix-plugin/detectConflicts.test.d.ts.map +1 -0
- package/dist/lix-plugin/detectConflicts.test.js +251 -0
- package/dist/lix-plugin/detectConflicts.test.js.map +1 -0
- package/dist/lix-plugin/inlangLixPluginV1.d.ts +8 -0
- package/dist/lix-plugin/inlangLixPluginV1.d.ts.map +1 -0
- package/dist/lix-plugin/inlangLixPluginV1.js +109 -0
- package/dist/lix-plugin/inlangLixPluginV1.js.map +1 -0
- package/dist/lix-plugin/inlangLixPluginV1.test.d.ts +2 -0
- package/dist/lix-plugin/inlangLixPluginV1.test.d.ts.map +1 -0
- package/dist/lix-plugin/inlangLixPluginV1.test.js +418 -0
- package/dist/lix-plugin/inlangLixPluginV1.test.js.map +1 -0
- package/dist/lix-plugin/merge.test.d.ts +2 -0
- package/dist/lix-plugin/merge.test.d.ts.map +1 -0
- package/dist/lix-plugin/merge.test.js +120 -0
- package/dist/lix-plugin/merge.test.js.map +1 -0
- package/dist/lix-plugin/resolveConflictBySelecting.test.d.ts +2 -0
- package/dist/lix-plugin/resolveConflictBySelecting.test.d.ts.map +1 -0
- package/dist/lix-plugin/resolveConflictBySelecting.test.js +176 -0
- package/dist/lix-plugin/resolveConflictBySelecting.test.js.map +1 -0
- package/dist/migrations/v2/createMessageV1.d.ts +28 -0
- package/dist/migrations/v2/createMessageV1.d.ts.map +1 -0
- package/dist/migrations/v2/createMessageV1.js +31 -0
- package/dist/migrations/v2/createMessageV1.js.map +1 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.d.ts +9 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.d.ts.map +1 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.js +31 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.js.map +1 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.d.ts +2 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.d.ts.map +1 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.js +45 -0
- package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.js.map +1 -0
- package/dist/plugin/cache.d.ts +6 -0
- package/dist/plugin/cache.d.ts.map +1 -0
- package/dist/plugin/cache.js +59 -0
- package/dist/plugin/cache.js.map +1 -0
- package/dist/plugin/cache.test.d.ts +2 -0
- package/dist/plugin/cache.test.d.ts.map +1 -0
- package/dist/plugin/cache.test.js +61 -0
- package/dist/plugin/cache.test.js.map +1 -0
- package/dist/plugin/errors.d.ts +41 -0
- package/dist/plugin/errors.d.ts.map +1 -0
- package/dist/plugin/errors.js +48 -0
- package/dist/plugin/errors.js.map +1 -0
- package/dist/plugin/importPlugins.d.ts +19 -0
- package/dist/plugin/importPlugins.d.ts.map +1 -0
- package/dist/plugin/importPlugins.js +43 -0
- package/dist/plugin/importPlugins.js.map +1 -0
- package/dist/plugin/importPlugins.test.d.ts +2 -0
- package/dist/plugin/importPlugins.test.d.ts.map +1 -0
- package/dist/plugin/importPlugins.test.js +95 -0
- package/dist/plugin/importPlugins.test.js.map +1 -0
- package/dist/plugin/meta/ideExtension.d.ts +54 -0
- package/dist/plugin/meta/ideExtension.d.ts.map +1 -0
- package/dist/plugin/meta/ideExtension.js +5 -0
- package/dist/plugin/meta/ideExtension.js.map +1 -0
- package/dist/plugin/schema.d.ts +152 -0
- package/dist/plugin/schema.d.ts.map +1 -0
- package/dist/plugin/schema.js +5 -0
- package/dist/plugin/schema.js.map +1 -0
- package/dist/project/api.d.ts +74 -0
- package/dist/project/api.d.ts.map +1 -0
- package/dist/project/api.js +5 -0
- package/dist/project/api.js.map +1 -0
- package/dist/project/initHandleSaveToLixOnChange.d.ts +14 -0
- package/dist/project/initHandleSaveToLixOnChange.d.ts.map +1 -0
- package/dist/project/initHandleSaveToLixOnChange.js +87 -0
- package/dist/project/initHandleSaveToLixOnChange.js.map +1 -0
- package/dist/project/loadProject.d.ts +53 -0
- package/dist/project/loadProject.d.ts.map +1 -0
- package/dist/project/loadProject.js +168 -0
- package/dist/project/loadProject.js.map +1 -0
- package/dist/project/loadProject.test.d.ts.map +1 -0
- package/dist/project/loadProject.test.js +146 -0
- package/dist/project/loadProject.test.js.map +1 -0
- package/dist/project/loadProjectFromDirectory.d.ts +77 -0
- package/dist/project/loadProjectFromDirectory.d.ts.map +1 -0
- package/dist/project/loadProjectFromDirectory.js +584 -0
- package/dist/project/loadProjectFromDirectory.js.map +1 -0
- package/dist/project/loadProjectFromDirectory.test.d.ts +2 -0
- package/dist/project/loadProjectFromDirectory.test.d.ts.map +1 -0
- package/dist/project/loadProjectFromDirectory.test.js +663 -0
- package/dist/project/loadProjectFromDirectory.test.js.map +1 -0
- package/dist/project/loadProjectInMemory.d.ts +8 -0
- package/dist/project/loadProjectInMemory.d.ts.map +1 -0
- package/dist/project/loadProjectInMemory.js +32 -0
- package/dist/project/loadProjectInMemory.js.map +1 -0
- package/dist/project/loadProjectInMemory.test.d.ts +2 -0
- package/dist/project/loadProjectInMemory.test.d.ts.map +1 -0
- package/dist/project/loadProjectInMemory.test.js +27 -0
- package/dist/project/loadProjectInMemory.test.js.map +1 -0
- package/dist/project/maybeCaptureTelemetry.d.ts +15 -0
- package/dist/project/maybeCaptureTelemetry.d.ts.map +1 -0
- package/dist/project/maybeCaptureTelemetry.js +58 -0
- package/dist/project/maybeCaptureTelemetry.js.map +1 -0
- package/dist/project/maybeCaptureTelemetry.test.d.ts +2 -0
- package/dist/project/maybeCaptureTelemetry.test.d.ts.map +1 -0
- package/dist/project/maybeCaptureTelemetry.test.js +71 -0
- package/dist/project/maybeCaptureTelemetry.test.js.map +1 -0
- package/dist/project/newProject.d.ts +17 -0
- package/dist/project/newProject.d.ts.map +1 -0
- package/dist/project/newProject.js +71 -0
- package/dist/project/newProject.js.map +1 -0
- package/dist/project/newProject.test.d.ts +2 -0
- package/dist/project/newProject.test.d.ts.map +1 -0
- package/dist/project/newProject.test.js +37 -0
- package/dist/project/newProject.test.js.map +1 -0
- package/dist/project/saveProjectToDirectory.d.ts +8 -0
- package/dist/project/saveProjectToDirectory.d.ts.map +1 -0
- package/dist/project/saveProjectToDirectory.js +86 -0
- package/dist/project/saveProjectToDirectory.js.map +1 -0
- package/dist/project/saveProjectToDirectory.test.d.ts +2 -0
- package/dist/project/saveProjectToDirectory.test.d.ts.map +1 -0
- package/dist/project/saveProjectToDirectory.test.js +245 -0
- package/dist/project/saveProjectToDirectory.test.js.map +1 -0
- package/dist/project/state/id$.d.ts +6 -0
- package/dist/project/state/id$.d.ts.map +1 -0
- package/dist/project/state/id$.js +19 -0
- package/dist/project/state/id$.js.map +1 -0
- package/dist/project/state/id$.test.d.ts +2 -0
- package/dist/project/state/id$.test.d.ts.map +1 -0
- package/dist/project/state/id$.test.js +36 -0
- package/dist/project/state/id$.test.js.map +1 -0
- package/dist/project/state/setSettings.d.ts +7 -0
- package/dist/project/state/setSettings.d.ts.map +1 -0
- package/dist/project/state/setSettings.js +16 -0
- package/dist/project/state/setSettings.js.map +1 -0
- package/dist/project/state/setSettings.test.d.ts +2 -0
- package/dist/project/state/setSettings.test.d.ts.map +1 -0
- package/dist/project/state/setSettings.test.js +58 -0
- package/dist/project/state/setSettings.test.js.map +1 -0
- package/dist/project/state/settings$.d.ts +7 -0
- package/dist/project/state/settings$.d.ts.map +1 -0
- package/dist/project/state/settings$.js +21 -0
- package/dist/project/state/settings$.js.map +1 -0
- package/dist/project/state/settings$.test.d.ts +2 -0
- package/dist/project/state/settings$.test.d.ts.map +1 -0
- package/dist/project/state/settings$.test.js +51 -0
- package/dist/project/state/settings$.test.js.map +1 -0
- package/dist/project/state/state.d.ts +58 -0
- package/dist/project/state/state.d.ts.map +1 -0
- package/dist/project/state/state.js +67 -0
- package/dist/project/state/state.js.map +1 -0
- package/dist/project/state/state.test.d.ts +2 -0
- package/dist/project/state/state.test.d.ts.map +1 -0
- package/dist/project/state/state.test.js +103 -0
- package/dist/project/state/state.test.js.map +1 -0
- package/dist/query-utilities/index.d.ts +5 -0
- package/dist/query-utilities/index.d.ts.map +1 -0
- package/dist/query-utilities/index.js +8 -0
- package/dist/query-utilities/index.js.map +1 -0
- package/dist/query-utilities/insertBundleNested.d.ts +4 -0
- package/dist/query-utilities/insertBundleNested.d.ts.map +1 -0
- package/dist/query-utilities/insertBundleNested.js +39 -0
- package/dist/query-utilities/insertBundleNested.js.map +1 -0
- package/dist/query-utilities/pollQuery.d.ts +14 -0
- package/dist/query-utilities/pollQuery.d.ts.map +1 -0
- package/dist/query-utilities/pollQuery.js +22 -0
- package/dist/query-utilities/pollQuery.js.map +1 -0
- package/dist/query-utilities/pollQuery.test.d.ts +2 -0
- package/dist/query-utilities/pollQuery.test.d.ts.map +1 -0
- package/dist/query-utilities/pollQuery.test.js +67 -0
- package/dist/query-utilities/pollQuery.test.js.map +1 -0
- package/dist/query-utilities/selectBundleNested.d.ts +107 -0
- package/dist/query-utilities/selectBundleNested.d.ts.map +1 -0
- package/dist/query-utilities/selectBundleNested.js +43 -0
- package/dist/query-utilities/selectBundleNested.js.map +1 -0
- package/dist/query-utilities/updateBundleNested.d.ts +12 -0
- package/dist/query-utilities/updateBundleNested.d.ts.map +1 -0
- package/dist/query-utilities/updateBundleNested.js +25 -0
- package/dist/query-utilities/updateBundleNested.js.map +1 -0
- package/dist/query-utilities/upsertBundleNested.d.ts +4 -0
- package/dist/query-utilities/upsertBundleNested.d.ts.map +1 -0
- package/dist/query-utilities/upsertBundleNested.js +50 -0
- package/dist/query-utilities/upsertBundleNested.js.map +1 -0
- package/dist/services/env-variables/index.d.ts +6 -0
- package/dist/services/env-variables/index.d.ts.map +1 -0
- package/dist/services/env-variables/index.js +9 -0
- package/dist/services/env-variables/index.js.map +1 -0
- package/dist/services/error-reporting/index.d.ts +15 -0
- package/dist/services/error-reporting/index.d.ts.map +1 -0
- package/dist/services/error-reporting/index.js +30 -0
- package/dist/services/error-reporting/index.js.map +1 -0
- package/dist/{telemetry → services/telemetry}/capture.d.ts +5 -2
- package/dist/services/telemetry/capture.d.ts.map +1 -0
- package/dist/services/telemetry/capture.js +76 -0
- package/dist/services/telemetry/capture.js.map +1 -0
- package/dist/services/telemetry/capture.test.d.ts +2 -0
- package/dist/services/telemetry/capture.test.d.ts.map +1 -0
- package/dist/services/telemetry/capture.test.js +46 -0
- package/dist/services/telemetry/capture.test.js.map +1 -0
- package/dist/utilities/detectJsonFormatting.d.ts +11 -0
- package/dist/utilities/detectJsonFormatting.d.ts.map +1 -0
- package/dist/utilities/detectJsonFormatting.js +83 -0
- package/dist/utilities/detectJsonFormatting.js.map +1 -0
- package/dist/utilities/detectJsonFormatting.test.d.ts +2 -0
- package/dist/utilities/detectJsonFormatting.test.d.ts.map +1 -0
- package/dist/utilities/detectJsonFormatting.test.js +33 -0
- package/dist/utilities/detectJsonFormatting.test.js.map +1 -0
- package/package.json +32 -40
- package/src/database/initDb.ts +34 -0
- package/src/database/initDbAndSchema.test.ts +125 -0
- package/src/database/jsonbPlugin.test.ts +154 -0
- package/src/database/jsonbPlugin.ts +215 -0
- package/src/database/schema.ts +127 -0
- package/src/helper.ts +113 -0
- package/src/human-id/human-id.ts +14 -0
- package/src/{storage/human-id → human-id}/words.test.ts +14 -14
- package/src/{storage/human-id → human-id}/words.ts +4 -4
- package/src/import-export/exportFiles.ts +36 -0
- package/src/import-export/importFiles.test.ts +211 -0
- package/src/import-export/importFiles.ts +142 -0
- package/src/import-export/roundtrip.test.ts +313 -0
- package/src/import-export/upsertBundleNestedMatchByProperties.ts +74 -0
- package/src/index.ts +29 -37
- package/src/json-schema/old-v1-message/README.md +1 -0
- package/src/json-schema/old-v1-message/fromMessageV1.test.ts +87 -0
- package/src/json-schema/old-v1-message/fromMessageV1.ts +99 -0
- package/src/json-schema/old-v1-message/schemaV1.ts +66 -0
- package/src/json-schema/old-v1-message/toMessageV1.test.ts +87 -0
- package/src/json-schema/old-v1-message/toMessageV1.ts +79 -0
- package/src/json-schema/pattern.ts +59 -0
- package/src/json-schema/settings.test-d.ts +21 -0
- package/src/json-schema/settings.ts +138 -0
- package/src/lix-plugin/applyChanges.test.ts +150 -0
- package/src/lix-plugin/applyChanges.ts +171 -0
- package/src/lix-plugin/detectConflicts.test.ts +286 -0
- package/src/lix-plugin/detectConflicts.ts +62 -0
- package/src/lix-plugin/inlangLixPluginV1.test.ts +439 -0
- package/src/lix-plugin/inlangLixPluginV1.ts +132 -0
- package/src/lix-plugin/merge.test.ts +133 -0
- package/src/lix-plugin/resolveConflictBySelecting.test.ts +188 -0
- package/src/migrations/v2/createMessageV1.ts +37 -0
- package/src/migrations/v2/withLanguageTagToLocaleMigration.test.ts +51 -0
- package/src/migrations/v2/withLanguageTagToLocaleMigration.ts +31 -0
- package/src/plugin/cache.test.ts +83 -0
- package/src/plugin/cache.ts +79 -0
- package/src/plugin/errors.ts +67 -0
- package/src/plugin/importPlugins.test.ts +107 -0
- package/src/plugin/importPlugins.ts +60 -0
- package/src/plugin/meta/ideExtension.ts +56 -0
- package/src/plugin/schema.ts +165 -0
- package/src/project/api.ts +77 -0
- package/src/project/initHandleSaveToLixOnChange.ts +93 -0
- package/src/project/loadProject.test.ts +176 -0
- package/src/project/loadProject.ts +246 -0
- package/src/project/loadProjectFromDirectory.test.ts +854 -0
- package/src/project/loadProjectFromDirectory.ts +752 -0
- package/src/project/loadProjectInMemory.test.ts +29 -0
- package/src/project/loadProjectInMemory.ts +36 -0
- package/src/project/maybeCaptureTelemetry.test.ts +79 -0
- package/src/project/maybeCaptureTelemetry.ts +69 -0
- package/src/project/newProject.test.ts +36 -0
- package/src/project/newProject.ts +78 -0
- package/src/project/saveProjectToDirectory.test.ts +310 -0
- package/src/project/saveProjectToDirectory.ts +100 -0
- package/src/query-utilities/index.ts +4 -0
- package/src/query-utilities/insertBundleNested.ts +46 -0
- package/src/query-utilities/selectBundleNested.ts +46 -0
- package/src/query-utilities/updateBundleNested.ts +35 -0
- package/src/query-utilities/upsertBundleNested.ts +61 -0
- package/src/services/env-variables/createIndexFile.js +40 -0
- package/src/{env-variables → services/env-variables}/index.d.ts +8 -5
- package/src/services/error-reporting/index.ts +28 -0
- package/src/services/telemetry/capture.test.ts +50 -0
- package/src/services/telemetry/capture.ts +99 -0
- package/src/utilities/detectJsonFormatting.test.ts +38 -0
- package/src/utilities/detectJsonFormatting.ts +109 -0
- package/dist/adapter/solidAdapter.d.ts +0 -33
- package/dist/adapter/solidAdapter.d.ts.map +0 -1
- package/dist/adapter/solidAdapter.js +0 -40
- package/dist/adapter/solidAdapter.test.d.ts +0 -2
- package/dist/adapter/solidAdapter.test.d.ts.map +0 -1
- package/dist/adapter/solidAdapter.test.js +0 -356
- package/dist/api.d.ts +0 -113
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -1
- package/dist/api.test-d.d.ts +0 -2
- package/dist/api.test-d.d.ts.map +0 -1
- package/dist/api.test-d.js +0 -4
- package/dist/createMessageLintReportsQuery.d.ts +0 -12
- package/dist/createMessageLintReportsQuery.d.ts.map +0 -1
- package/dist/createMessageLintReportsQuery.js +0 -176
- package/dist/createMessagesQuery.d.ts +0 -19
- package/dist/createMessagesQuery.d.ts.map +0 -1
- package/dist/createMessagesQuery.js +0 -451
- package/dist/createMessagesQuery.test.d.ts +0 -2
- package/dist/createMessagesQuery.test.d.ts.map +0 -1
- package/dist/createMessagesQuery.test.js +0 -402
- package/dist/createNewProject.d.ts +0 -12
- package/dist/createNewProject.d.ts.map +0 -1
- package/dist/createNewProject.js +0 -38
- package/dist/createNewProject.test.d.ts +0 -2
- package/dist/createNewProject.test.d.ts.map +0 -1
- package/dist/createNewProject.test.js +0 -91
- package/dist/createNodeishFsWithAbsolutePaths.d.ts +0 -12
- package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +0 -1
- package/dist/createNodeishFsWithAbsolutePaths.js +0 -38
- package/dist/createNodeishFsWithAbsolutePaths.test.d.ts +0 -2
- package/dist/createNodeishFsWithAbsolutePaths.test.d.ts.map +0 -1
- package/dist/createNodeishFsWithAbsolutePaths.test.js +0 -44
- package/dist/createNodeishFsWithWatcher.d.ts +0 -14
- package/dist/createNodeishFsWithWatcher.d.ts.map +0 -1
- package/dist/createNodeishFsWithWatcher.js +0 -75
- package/dist/createNodeishFsWithWatcher.test.d.ts +0 -2
- package/dist/createNodeishFsWithWatcher.test.d.ts.map +0 -1
- package/dist/createNodeishFsWithWatcher.test.js +0 -38
- package/dist/defaultProjectSettings.d.ts +0 -14
- package/dist/defaultProjectSettings.d.ts.map +0 -1
- package/dist/defaultProjectSettings.js +0 -22
- package/dist/env-variables/index.d.ts +0 -4
- package/dist/env-variables/index.d.ts.map +0 -1
- package/dist/env-variables/index.js +0 -3
- package/dist/errors.d.ts +0 -48
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -62
- package/dist/lint/index.d.ts +0 -3
- package/dist/lint/index.d.ts.map +0 -1
- package/dist/lint/index.js +0 -2
- package/dist/lint/message/errors.d.ts +0 -7
- package/dist/lint/message/errors.d.ts.map +0 -1
- package/dist/lint/message/errors.js +0 -9
- package/dist/lint/message/lintMessages.d.ts +0 -13
- package/dist/lint/message/lintMessages.d.ts.map +0 -1
- package/dist/lint/message/lintMessages.js +0 -12
- package/dist/lint/message/lintMessages.test.d.ts +0 -2
- package/dist/lint/message/lintMessages.test.d.ts.map +0 -1
- package/dist/lint/message/lintMessages.test.js +0 -107
- package/dist/lint/message/lintSingleMessage.d.ts +0 -19
- package/dist/lint/message/lintSingleMessage.d.ts.map +0 -1
- package/dist/lint/message/lintSingleMessage.js +0 -38
- package/dist/lint/message/lintSingleMessage.test.d.ts +0 -2
- package/dist/lint/message/lintSingleMessage.test.d.ts.map +0 -1
- package/dist/lint/message/lintSingleMessage.test.js +0 -161
- package/dist/listProjects.d.ts +0 -5
- package/dist/listProjects.d.ts.map +0 -1
- package/dist/listProjects.js +0 -38
- package/dist/listProjects.test.d.ts +0 -2
- package/dist/listProjects.test.d.ts.map +0 -1
- package/dist/listProjects.test.js +0 -72
- package/dist/loadProject.d.ts +0 -19
- package/dist/loadProject.d.ts.map +0 -1
- package/dist/loadProject.js +0 -343
- package/dist/loadProject.test.d.ts.map +0 -1
- package/dist/loadProject.test.js +0 -975
- package/dist/messages/errors.d.ts +0 -13
- package/dist/messages/errors.d.ts.map +0 -1
- package/dist/messages/errors.js +0 -18
- package/dist/messages/index.d.ts +0 -3
- package/dist/messages/index.d.ts.map +0 -1
- package/dist/messages/index.js +0 -2
- package/dist/messages/variant.d.ts +0 -46
- package/dist/messages/variant.d.ts.map +0 -1
- package/dist/messages/variant.js +0 -176
- package/dist/messages/variant.test.d.ts +0 -2
- package/dist/messages/variant.test.d.ts.map +0 -1
- package/dist/messages/variant.test.js +0 -439
- package/dist/migrations/maybeAddModuleCache.d.ts +0 -6
- package/dist/migrations/maybeAddModuleCache.d.ts.map +0 -1
- package/dist/migrations/maybeAddModuleCache.js +0 -62
- package/dist/migrations/maybeCreateFirstProjectId.d.ts +0 -16
- package/dist/migrations/maybeCreateFirstProjectId.d.ts.map +0 -1
- package/dist/migrations/maybeCreateFirstProjectId.js +0 -46
- package/dist/migrations/maybeCreateFirstProjectId.test.d.ts +0 -2
- package/dist/migrations/maybeCreateFirstProjectId.test.d.ts.map +0 -1
- package/dist/migrations/maybeCreateFirstProjectId.test.js +0 -24
- package/dist/migrations/migrateToDirectory.d.ts +0 -10
- package/dist/migrations/migrateToDirectory.d.ts.map +0 -1
- package/dist/migrations/migrateToDirectory.js +0 -48
- package/dist/migrations/migrateToDirectory.test.d.ts +0 -2
- package/dist/migrations/migrateToDirectory.test.d.ts.map +0 -1
- package/dist/migrations/migrateToDirectory.test.js +0 -48
- package/dist/parseConfig.d.ts +0 -8
- package/dist/parseConfig.d.ts.map +0 -1
- package/dist/parseConfig.js +0 -26
- package/dist/persistence/batchedIO.d.ts +0 -11
- package/dist/persistence/batchedIO.d.ts.map +0 -1
- package/dist/persistence/batchedIO.js +0 -49
- package/dist/persistence/batchedIO.test.d.ts +0 -2
- package/dist/persistence/batchedIO.test.d.ts.map +0 -1
- package/dist/persistence/batchedIO.test.js +0 -56
- package/dist/persistence/filelock/acquireFileLock.d.ts +0 -3
- package/dist/persistence/filelock/acquireFileLock.d.ts.map +0 -1
- package/dist/persistence/filelock/acquireFileLock.js +0 -111
- package/dist/persistence/filelock/releaseLock.d.ts +0 -3
- package/dist/persistence/filelock/releaseLock.d.ts.map +0 -1
- package/dist/persistence/filelock/releaseLock.js +0 -24
- package/dist/persistence/store.d.ts +0 -107
- package/dist/persistence/store.d.ts.map +0 -1
- package/dist/persistence/store.js +0 -99
- package/dist/persistence/store.test.d.ts +0 -2
- package/dist/persistence/store.test.d.ts.map +0 -1
- package/dist/persistence/store.test.js +0 -79
- package/dist/persistence/storeApi.d.ts +0 -22
- package/dist/persistence/storeApi.d.ts.map +0 -1
- package/dist/persistence/storeApi.js +0 -1
- package/dist/reactivity/map.d.ts +0 -67
- package/dist/reactivity/map.d.ts.map +0 -1
- package/dist/reactivity/map.js +0 -143
- package/dist/reactivity/solid.d.ts +0 -14
- package/dist/reactivity/solid.d.ts.map +0 -1
- package/dist/reactivity/solid.js +0 -15
- package/dist/reactivity/solid.test.d.ts +0 -2
- package/dist/reactivity/solid.test.d.ts.map +0 -1
- package/dist/reactivity/solid.test.js +0 -189
- package/dist/reactivity/trigger.d.ts +0 -11
- package/dist/reactivity/trigger.d.ts.map +0 -1
- package/dist/reactivity/trigger.js +0 -46
- package/dist/resolve-modules/cache.d.ts +0 -6
- package/dist/resolve-modules/cache.d.ts.map +0 -1
- package/dist/resolve-modules/cache.js +0 -58
- package/dist/resolve-modules/errors.d.ts +0 -41
- package/dist/resolve-modules/errors.d.ts.map +0 -1
- package/dist/resolve-modules/errors.js +0 -45
- package/dist/resolve-modules/import.d.ts +0 -19
- package/dist/resolve-modules/import.d.ts.map +0 -1
- package/dist/resolve-modules/import.js +0 -102
- package/dist/resolve-modules/import.test.d.ts +0 -2
- package/dist/resolve-modules/import.test.d.ts.map +0 -1
- package/dist/resolve-modules/import.test.js +0 -47
- package/dist/resolve-modules/index.d.ts +0 -3
- package/dist/resolve-modules/index.d.ts.map +0 -1
- package/dist/resolve-modules/index.js +0 -2
- package/dist/resolve-modules/message-lint-rules/errors.d.ts +0 -9
- package/dist/resolve-modules/message-lint-rules/errors.d.ts.map +0 -1
- package/dist/resolve-modules/message-lint-rules/errors.js +0 -6
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts +0 -9
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts.map +0 -1
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +0 -24
- package/dist/resolve-modules/plugins/errors.d.ts +0 -33
- package/dist/resolve-modules/plugins/errors.d.ts.map +0 -1
- package/dist/resolve-modules/plugins/errors.js +0 -38
- package/dist/resolve-modules/plugins/resolvePlugins.d.ts +0 -3
- package/dist/resolve-modules/plugins/resolvePlugins.d.ts.map +0 -1
- package/dist/resolve-modules/plugins/resolvePlugins.js +0 -92
- package/dist/resolve-modules/plugins/resolvePlugins.test.d.ts +0 -2
- package/dist/resolve-modules/plugins/resolvePlugins.test.d.ts.map +0 -1
- package/dist/resolve-modules/plugins/resolvePlugins.test.js +0 -252
- package/dist/resolve-modules/plugins/types.d.ts +0 -57
- package/dist/resolve-modules/plugins/types.d.ts.map +0 -1
- package/dist/resolve-modules/plugins/types.js +0 -1
- package/dist/resolve-modules/plugins/types.test.d.ts +0 -2
- package/dist/resolve-modules/plugins/types.test.d.ts.map +0 -1
- package/dist/resolve-modules/plugins/types.test.js +0 -45
- package/dist/resolve-modules/resolveModules.d.ts +0 -3
- package/dist/resolve-modules/resolveModules.d.ts.map +0 -1
- package/dist/resolve-modules/resolveModules.js +0 -80
- package/dist/resolve-modules/resolveModules.test.d.ts +0 -2
- package/dist/resolve-modules/resolveModules.test.d.ts.map +0 -1
- package/dist/resolve-modules/resolveModules.test.js +0 -185
- package/dist/resolve-modules/types.d.ts +0 -63
- package/dist/resolve-modules/types.d.ts.map +0 -1
- package/dist/resolve-modules/types.js +0 -1
- package/dist/resolve-modules/validateModuleSettings.test.d.ts +0 -2
- package/dist/resolve-modules/validateModuleSettings.test.d.ts.map +0 -1
- package/dist/resolve-modules/validateModuleSettings.test.js +0 -71
- package/dist/resolve-modules/validatedModuleSettings.d.ts +0 -7
- package/dist/resolve-modules/validatedModuleSettings.d.ts.map +0 -1
- package/dist/resolve-modules/validatedModuleSettings.js +0 -11
- package/dist/storage/helper.d.ts +0 -11
- package/dist/storage/helper.d.ts.map +0 -1
- package/dist/storage/helper.js +0 -63
- package/dist/storage/helpers.test.d.ts +0 -2
- package/dist/storage/helpers.test.d.ts.map +0 -1
- package/dist/storage/helpers.test.js +0 -84
- package/dist/storage/human-id/human-readable-id.d.ts +0 -3
- package/dist/storage/human-id/human-readable-id.d.ts.map +0 -1
- package/dist/storage/human-id/human-readable-id.js +0 -20
- package/dist/storage/human-id/words.d.ts.map +0 -1
- package/dist/storage/human-id/words.test.d.ts.map +0 -1
- package/dist/telemetry/capture.d.ts.map +0 -1
- package/dist/telemetry/capture.js +0 -39
- package/dist/telemetry/groupIdentify.d.ts +0 -13
- package/dist/telemetry/groupIdentify.d.ts.map +0 -1
- package/dist/telemetry/groupIdentify.js +0 -35
- package/dist/test-utilities/createMessage.d.ts +0 -18
- package/dist/test-utilities/createMessage.d.ts.map +0 -1
- package/dist/test-utilities/createMessage.js +0 -17
- package/dist/test-utilities/createMessage.test.d.ts +0 -2
- package/dist/test-utilities/createMessage.test.d.ts.map +0 -1
- package/dist/test-utilities/createMessage.test.js +0 -106
- package/dist/test-utilities/index.d.ts +0 -3
- package/dist/test-utilities/index.d.ts.map +0 -1
- package/dist/test-utilities/index.js +0 -2
- package/dist/test-utilities/sleep.d.ts +0 -4
- package/dist/test-utilities/sleep.d.ts.map +0 -1
- package/dist/test-utilities/sleep.js +0 -9
- package/dist/v2/helper.d.ts +0 -43
- package/dist/v2/helper.d.ts.map +0 -1
- package/dist/v2/helper.js +0 -75
- package/dist/v2/helper.test.d.ts +0 -2
- package/dist/v2/helper.test.d.ts.map +0 -1
- package/dist/v2/helper.test.js +0 -92
- package/dist/v2/index.d.ts +0 -4
- package/dist/v2/index.d.ts.map +0 -1
- package/dist/v2/index.js +0 -2
- package/dist/v2/mocks/index.d.ts +0 -3
- package/dist/v2/mocks/index.d.ts.map +0 -1
- package/dist/v2/mocks/index.js +0 -2
- package/dist/v2/mocks/multipleMatcher/bundle.d.ts +0 -3
- package/dist/v2/mocks/multipleMatcher/bundle.d.ts.map +0 -1
- package/dist/v2/mocks/multipleMatcher/bundle.js +0 -194
- package/dist/v2/mocks/multipleMatcher/bundle.test.d.ts +0 -2
- package/dist/v2/mocks/multipleMatcher/bundle.test.d.ts.map +0 -1
- package/dist/v2/mocks/multipleMatcher/bundle.test.js +0 -10
- package/dist/v2/mocks/plural/bundle.d.ts +0 -3
- package/dist/v2/mocks/plural/bundle.d.ts.map +0 -1
- package/dist/v2/mocks/plural/bundle.js +0 -162
- package/dist/v2/mocks/plural/bundle.test.d.ts +0 -2
- package/dist/v2/mocks/plural/bundle.test.d.ts.map +0 -1
- package/dist/v2/mocks/plural/bundle.test.js +0 -15
- package/dist/v2/shim.d.ts +0 -12
- package/dist/v2/shim.d.ts.map +0 -1
- package/dist/v2/shim.js +0 -151
- package/dist/v2/shim.test.d.ts +0 -2
- package/dist/v2/shim.test.d.ts.map +0 -1
- package/dist/v2/shim.test.js +0 -49
- package/dist/v2/stubQueryApi.d.ts +0 -9
- package/dist/v2/stubQueryApi.d.ts.map +0 -1
- package/dist/v2/stubQueryApi.js +0 -38
- package/dist/v2/types.d.ts +0 -521
- package/dist/v2/types.d.ts.map +0 -1
- package/dist/v2/types.js +0 -78
- package/dist/validateProjectPath.d.ts +0 -17
- package/dist/validateProjectPath.d.ts.map +0 -1
- package/dist/validateProjectPath.js +0 -31
- package/dist/validateProjectPath.test.d.ts +0 -2
- package/dist/validateProjectPath.test.d.ts.map +0 -1
- package/dist/validateProjectPath.test.js +0 -40
- package/dist/versionedInterfaces.d.ts +0 -8
- package/dist/versionedInterfaces.d.ts.map +0 -1
- package/dist/versionedInterfaces.js +0 -8
- package/src/adapter/solidAdapter.test.ts +0 -472
- package/src/adapter/solidAdapter.ts +0 -79
- package/src/api.test-d.ts +0 -8
- package/src/api.ts +0 -116
- package/src/createMessageLintReportsQuery.ts +0 -225
- package/src/createMessagesQuery.test.ts +0 -538
- package/src/createMessagesQuery.ts +0 -635
- package/src/createNewProject.test.ts +0 -105
- package/src/createNewProject.ts +0 -46
- package/src/createNodeishFsWithAbsolutePaths.test.ts +0 -55
- package/src/createNodeishFsWithAbsolutePaths.ts +0 -52
- package/src/createNodeishFsWithWatcher.test.ts +0 -50
- package/src/createNodeishFsWithWatcher.ts +0 -85
- package/src/defaultProjectSettings.ts +0 -26
- package/src/env-variables/.prettierignore +0 -1
- package/src/env-variables/createIndexFile.js +0 -28
- package/src/errors.ts +0 -84
- package/src/lint/index.ts +0 -2
- package/src/lint/message/errors.ts +0 -9
- package/src/lint/message/lintMessages.test.ts +0 -126
- package/src/lint/message/lintMessages.ts +0 -25
- package/src/lint/message/lintSingleMessage.test.ts +0 -191
- package/src/lint/message/lintSingleMessage.ts +0 -57
- package/src/listProjects.test.ts +0 -91
- package/src/listProjects.ts +0 -48
- package/src/loadProject.test.ts +0 -1173
- package/src/loadProject.ts +0 -460
- package/src/messages/errors.ts +0 -25
- package/src/messages/index.ts +0 -2
- package/src/messages/variant.test.ts +0 -511
- package/src/messages/variant.ts +0 -247
- package/src/migrations/maybeAddModuleCache.ts +0 -68
- package/src/migrations/maybeCreateFirstProjectId.test.ts +0 -31
- package/src/migrations/maybeCreateFirstProjectId.ts +0 -51
- package/src/migrations/migrateToDirectory.test.ts +0 -54
- package/src/migrations/migrateToDirectory.ts +0 -62
- package/src/parseConfig.ts +0 -35
- package/src/persistence/batchedIO.test.ts +0 -63
- package/src/persistence/batchedIO.ts +0 -64
- package/src/persistence/filelock/acquireFileLock.ts +0 -129
- package/src/persistence/filelock/releaseLock.ts +0 -29
- package/src/persistence/store.test.ts +0 -102
- package/src/persistence/store.ts +0 -119
- package/src/persistence/storeApi.ts +0 -19
- package/src/reactivity/map.ts +0 -135
- package/src/reactivity/solid.test.ts +0 -222
- package/src/reactivity/solid.ts +0 -42
- package/src/reactivity/trigger.ts +0 -46
- package/src/resolve-modules/cache.ts +0 -89
- package/src/resolve-modules/errors.ts +0 -69
- package/src/resolve-modules/import.test.ts +0 -62
- package/src/resolve-modules/import.ts +0 -133
- package/src/resolve-modules/index.ts +0 -2
- package/src/resolve-modules/message-lint-rules/errors.ts +0 -9
- package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +0 -27
- package/src/resolve-modules/plugins/errors.ts +0 -56
- package/src/resolve-modules/plugins/resolvePlugins.test.ts +0 -301
- package/src/resolve-modules/plugins/resolvePlugins.ts +0 -129
- package/src/resolve-modules/plugins/types.test.ts +0 -53
- package/src/resolve-modules/plugins/types.ts +0 -76
- package/src/resolve-modules/resolveModules.test.ts +0 -224
- package/src/resolve-modules/resolveModules.ts +0 -113
- package/src/resolve-modules/types.ts +0 -72
- package/src/resolve-modules/validateModuleSettings.test.ts +0 -85
- package/src/resolve-modules/validatedModuleSettings.ts +0 -19
- package/src/storage/helper.ts +0 -74
- package/src/storage/helpers.test.ts +0 -95
- package/src/storage/human-id/human-readable-id.ts +0 -27
- package/src/telemetry/capture.ts +0 -49
- package/src/telemetry/groupIdentify.ts +0 -41
- package/src/test-utilities/createMessage.test.ts +0 -118
- package/src/test-utilities/createMessage.ts +0 -21
- package/src/test-utilities/index.ts +0 -2
- package/src/test-utilities/sleep.ts +0 -11
- package/src/v2/helper.test.ts +0 -95
- package/src/v2/helper.ts +0 -98
- package/src/v2/index.ts +0 -3
- package/src/v2/mocks/index.ts +0 -2
- package/src/v2/mocks/multipleMatcher/bundle.test.ts +0 -11
- package/src/v2/mocks/multipleMatcher/bundle.ts +0 -196
- package/src/v2/mocks/plural/bundle.test.ts +0 -18
- package/src/v2/mocks/plural/bundle.ts +0 -164
- package/src/v2/shim.test.ts +0 -56
- package/src/v2/shim.ts +0 -173
- package/src/v2/stubQueryApi.ts +0 -43
- package/src/v2/types.ts +0 -159
- package/src/validateProjectPath.test.ts +0 -50
- package/src/validateProjectPath.ts +0 -38
- package/src/versionedInterfaces.ts +0 -9
- /package/dist/{storage/human-id → human-id}/words.d.ts +0 -0
- /package/dist/{storage/human-id → human-id}/words.test.d.ts +0 -0
- /package/dist/{loadProject.test.d.ts → project/loadProject.test.d.ts} +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import { importFiles } from "./importFiles.js";
|
|
3
|
+
import { loadProjectInMemory } from "../project/loadProjectInMemory.js";
|
|
4
|
+
import { newProject } from "../project/newProject.js";
|
|
5
|
+
import type { InlangPlugin } from "../plugin/schema.js";
|
|
6
|
+
|
|
7
|
+
test("it should insert a message as is if the id is provided", async () => {
|
|
8
|
+
const project = await loadProjectInMemory({ blob: await newProject() });
|
|
9
|
+
|
|
10
|
+
const mockPlugin: InlangPlugin = {
|
|
11
|
+
key: "mock",
|
|
12
|
+
importFiles: async () => ({
|
|
13
|
+
bundles: [{ id: "mock-bundle" }],
|
|
14
|
+
messages: [{ id: "alfa23", bundleId: "mock-bundle", locale: "en" }],
|
|
15
|
+
variants: [],
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
await importFiles({
|
|
20
|
+
db: project.db,
|
|
21
|
+
files: [{ content: new Uint8Array(), locale: "mock" }],
|
|
22
|
+
pluginKey: "mock",
|
|
23
|
+
plugins: [mockPlugin],
|
|
24
|
+
settings: {} as any,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const messages = await project.db.selectFrom("message").selectAll().execute();
|
|
28
|
+
|
|
29
|
+
expect(messages.length).toBe(1);
|
|
30
|
+
expect(messages[0]?.id).toBe("alfa23");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("it should match an existing message if the id is not provided", async () => {
|
|
34
|
+
const project = await loadProjectInMemory({ blob: await newProject() });
|
|
35
|
+
|
|
36
|
+
await project.db.insertInto("bundle").values({ id: "mock-bundle" }).execute();
|
|
37
|
+
await project.db
|
|
38
|
+
.insertInto("message")
|
|
39
|
+
.values({
|
|
40
|
+
id: "alfa23",
|
|
41
|
+
bundleId: "mock-bundle",
|
|
42
|
+
locale: "en",
|
|
43
|
+
selectors: [],
|
|
44
|
+
})
|
|
45
|
+
.execute();
|
|
46
|
+
|
|
47
|
+
const mockPlugin: InlangPlugin = {
|
|
48
|
+
key: "mock",
|
|
49
|
+
importFiles: async () => ({
|
|
50
|
+
bundles: [],
|
|
51
|
+
messages: [
|
|
52
|
+
{
|
|
53
|
+
bundleId: "mock-bundle",
|
|
54
|
+
locale: "en",
|
|
55
|
+
selectors: [{ type: "variable-reference", name: "platform" }],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
variants: [],
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
await importFiles({
|
|
63
|
+
db: project.db,
|
|
64
|
+
files: [{ content: new Uint8Array(), locale: "mock" }],
|
|
65
|
+
pluginKey: "mock",
|
|
66
|
+
plugins: [mockPlugin],
|
|
67
|
+
settings: {} as any,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const messages = await project.db.selectFrom("message").selectAll().execute();
|
|
71
|
+
|
|
72
|
+
expect(messages.length).toBe(1);
|
|
73
|
+
expect(messages[0]?.id).toBe("alfa23");
|
|
74
|
+
expect(messages[0]?.selectors).toStrictEqual([
|
|
75
|
+
{ type: "variable-reference", name: "platform" },
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("it should create a bundle for a message if the bundle does not exist to avoid foreign key conflicts and enable partial imports", async () => {
|
|
80
|
+
const project = await loadProjectInMemory({ blob: await newProject() });
|
|
81
|
+
|
|
82
|
+
const mockPlugin: InlangPlugin = {
|
|
83
|
+
key: "mock",
|
|
84
|
+
importFiles: async () => ({
|
|
85
|
+
bundles: [],
|
|
86
|
+
messages: [{ bundleId: "non-existent-bundle", locale: "en" }],
|
|
87
|
+
variants: [],
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
await importFiles({
|
|
92
|
+
db: project.db,
|
|
93
|
+
files: [{ content: new Uint8Array(), locale: "mock" }],
|
|
94
|
+
pluginKey: "mock",
|
|
95
|
+
plugins: [mockPlugin],
|
|
96
|
+
settings: {} as any,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const bundles = await project.db.selectFrom("bundle").selectAll().execute();
|
|
100
|
+
|
|
101
|
+
expect(bundles.length).toBe(1);
|
|
102
|
+
expect(bundles[0]?.id).toBe("non-existent-bundle");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("it should insert a variant as is if the id is provided", async () => {
|
|
106
|
+
const project = await loadProjectInMemory({ blob: await newProject() });
|
|
107
|
+
|
|
108
|
+
await project.db.insertInto("bundle").values({ id: "mock-bundle" }).execute();
|
|
109
|
+
await project.db
|
|
110
|
+
.insertInto("message")
|
|
111
|
+
.values({
|
|
112
|
+
id: "mock-message",
|
|
113
|
+
bundleId: "mock-bundle",
|
|
114
|
+
locale: "en",
|
|
115
|
+
})
|
|
116
|
+
.execute();
|
|
117
|
+
|
|
118
|
+
const mockPlugin: InlangPlugin = {
|
|
119
|
+
key: "mock",
|
|
120
|
+
importFiles: async () => ({
|
|
121
|
+
bundles: [],
|
|
122
|
+
messages: [],
|
|
123
|
+
variants: [{ id: "variant-id-23", messageId: "mock-message" }],
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
await importFiles({
|
|
128
|
+
db: project.db,
|
|
129
|
+
files: [{ content: new Uint8Array(), locale: "mock" }],
|
|
130
|
+
pluginKey: "mock",
|
|
131
|
+
plugins: [mockPlugin],
|
|
132
|
+
settings: {} as any,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const variants = await project.db.selectFrom("variant").selectAll().execute();
|
|
136
|
+
|
|
137
|
+
expect(variants.length).toBe(1);
|
|
138
|
+
expect(variants[0]?.id).toBe("variant-id-23");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("it should match an existing variant if the id is not provided", async () => {
|
|
142
|
+
const project = await loadProjectInMemory({ blob: await newProject() });
|
|
143
|
+
|
|
144
|
+
await project.db.insertInto("bundle").values({ id: "mock-bundle" }).execute();
|
|
145
|
+
await project.db
|
|
146
|
+
.insertInto("message")
|
|
147
|
+
.values({
|
|
148
|
+
id: "mock-message",
|
|
149
|
+
bundleId: "mock-bundle",
|
|
150
|
+
locale: "en",
|
|
151
|
+
})
|
|
152
|
+
.execute();
|
|
153
|
+
|
|
154
|
+
const mockPlugin: InlangPlugin = {
|
|
155
|
+
key: "mock",
|
|
156
|
+
importFiles: async () => ({
|
|
157
|
+
bundles: [],
|
|
158
|
+
messages: [],
|
|
159
|
+
variants: [{ messageBundleId: "mock-bundle", messageLocale: "en" }],
|
|
160
|
+
}),
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
await importFiles({
|
|
164
|
+
db: project.db,
|
|
165
|
+
files: [{ content: new Uint8Array(), locale: "mock" }],
|
|
166
|
+
pluginKey: "mock",
|
|
167
|
+
plugins: [mockPlugin],
|
|
168
|
+
settings: {} as any,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const variants = await project.db.selectFrom("variant").selectAll().execute();
|
|
172
|
+
|
|
173
|
+
expect(variants.length).toBe(1);
|
|
174
|
+
expect(variants[0]?.messageId).toBe("mock-message");
|
|
175
|
+
expect(variants[0]?.id).toBeDefined();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("it should create a message for a variant if the message does not exist to avoid foreign key conflicts and enable partial imports", async () => {
|
|
179
|
+
const project = await loadProjectInMemory({ blob: await newProject() });
|
|
180
|
+
|
|
181
|
+
await project.db.insertInto("bundle").values({ id: "mock-bundle" }).execute();
|
|
182
|
+
|
|
183
|
+
const mockPlugin: InlangPlugin = {
|
|
184
|
+
key: "mock",
|
|
185
|
+
importFiles: async () => ({
|
|
186
|
+
bundles: [],
|
|
187
|
+
messages: [],
|
|
188
|
+
variants: [{ messageBundleId: "mock-bundle", messageLocale: "en" }],
|
|
189
|
+
}),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
await importFiles({
|
|
193
|
+
db: project.db,
|
|
194
|
+
files: [{ content: new Uint8Array(), locale: "mock" }],
|
|
195
|
+
pluginKey: "mock",
|
|
196
|
+
plugins: [mockPlugin],
|
|
197
|
+
settings: {} as any,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const bundles = await project.db.selectFrom("bundle").selectAll().execute();
|
|
201
|
+
const messages = await project.db.selectFrom("message").selectAll().execute();
|
|
202
|
+
const variants = await project.db.selectFrom("variant").selectAll().execute();
|
|
203
|
+
|
|
204
|
+
expect(bundles.length).toBe(1);
|
|
205
|
+
expect(messages.length).toBe(1);
|
|
206
|
+
expect(variants.length).toBe(1);
|
|
207
|
+
|
|
208
|
+
expect(messages[0]?.bundleId).toBe("mock-bundle");
|
|
209
|
+
expect(messages[0]?.locale).toBe("en");
|
|
210
|
+
expect(variants[0]?.messageId).toBe(messages[0]?.id);
|
|
211
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import {
|
|
3
|
+
PluginDoesNotImplementFunctionError,
|
|
4
|
+
PluginMissingError,
|
|
5
|
+
} from "../plugin/errors.js";
|
|
6
|
+
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
7
|
+
import type { InlangDatabaseSchema, NewVariant } from "../database/schema.js";
|
|
8
|
+
import type { InlangPlugin, VariantImport } from "../plugin/schema.js";
|
|
9
|
+
import type { ImportFile } from "../project/api.js";
|
|
10
|
+
|
|
11
|
+
export async function importFiles(args: {
|
|
12
|
+
files: ImportFile[];
|
|
13
|
+
readonly pluginKey: string;
|
|
14
|
+
readonly settings: ProjectSettings;
|
|
15
|
+
readonly plugins: readonly InlangPlugin[];
|
|
16
|
+
readonly db: Kysely<InlangDatabaseSchema>;
|
|
17
|
+
}) {
|
|
18
|
+
const plugin = args.plugins.find((p) => p.key === args.pluginKey);
|
|
19
|
+
|
|
20
|
+
if (!plugin) throw new PluginMissingError({ plugin: args.pluginKey });
|
|
21
|
+
|
|
22
|
+
if (!plugin.importFiles) {
|
|
23
|
+
throw new PluginDoesNotImplementFunctionError({
|
|
24
|
+
plugin: args.pluginKey,
|
|
25
|
+
function: "importFiles",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const imported = await plugin.importFiles({
|
|
30
|
+
files: args.files,
|
|
31
|
+
settings: structuredClone(args.settings),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await args.db.transaction().execute(async (trx) => {
|
|
35
|
+
// upsert every bundle
|
|
36
|
+
for (const bundle of imported.bundles) {
|
|
37
|
+
await trx
|
|
38
|
+
.insertInto("bundle")
|
|
39
|
+
.values(bundle)
|
|
40
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(bundle))
|
|
41
|
+
.execute();
|
|
42
|
+
}
|
|
43
|
+
// upsert every message
|
|
44
|
+
for (const message of imported.messages) {
|
|
45
|
+
// match the message by bundle id and locale if
|
|
46
|
+
// no id is provided by the importer
|
|
47
|
+
if (message.id === undefined) {
|
|
48
|
+
const exisingMessage = await trx
|
|
49
|
+
.selectFrom("message")
|
|
50
|
+
.where("bundleId", "=", message.bundleId)
|
|
51
|
+
.where("locale", "=", message.locale)
|
|
52
|
+
.select("id")
|
|
53
|
+
.executeTakeFirst();
|
|
54
|
+
message.id = exisingMessage?.id;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await trx
|
|
58
|
+
.insertInto("message")
|
|
59
|
+
.values(message)
|
|
60
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(message))
|
|
61
|
+
.execute();
|
|
62
|
+
} catch (e) {
|
|
63
|
+
// 787 = SQLITE_CONSTRAINT_FOREIGNKEY
|
|
64
|
+
// handle foreign key violation
|
|
65
|
+
// e.g. a message references a bundle that doesn't exist
|
|
66
|
+
// by creating the bundle
|
|
67
|
+
if ((e as any)?.resultCode === 787) {
|
|
68
|
+
await trx
|
|
69
|
+
.insertInto("bundle")
|
|
70
|
+
.values({ id: message.bundleId })
|
|
71
|
+
.execute();
|
|
72
|
+
await trx.insertInto("message").values(message).execute();
|
|
73
|
+
} else {
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// upsert every variant
|
|
79
|
+
for (const variant of imported.variants) {
|
|
80
|
+
// match the variant by message id and matches if
|
|
81
|
+
// no id is provided by the importer
|
|
82
|
+
if (variant.id === undefined) {
|
|
83
|
+
let existingMessage = await trx
|
|
84
|
+
.selectFrom("message")
|
|
85
|
+
.where("bundleId", "=", variant.messageBundleId)
|
|
86
|
+
.where("locale", "=", variant.messageLocale)
|
|
87
|
+
.select("id")
|
|
88
|
+
.executeTakeFirst();
|
|
89
|
+
|
|
90
|
+
// if the message does not exist, create it
|
|
91
|
+
if (existingMessage === undefined) {
|
|
92
|
+
const existingBundle = await trx
|
|
93
|
+
.selectFrom("bundle")
|
|
94
|
+
.where("id", "=", variant.messageBundleId)
|
|
95
|
+
.select("id")
|
|
96
|
+
.executeTakeFirst();
|
|
97
|
+
// if the bundle does not exist, create it
|
|
98
|
+
if (existingBundle === undefined) {
|
|
99
|
+
await trx
|
|
100
|
+
.insertInto("bundle")
|
|
101
|
+
.values({ id: variant.messageBundleId })
|
|
102
|
+
.execute();
|
|
103
|
+
}
|
|
104
|
+
// insert the message
|
|
105
|
+
existingMessage = await trx
|
|
106
|
+
.insertInto("message")
|
|
107
|
+
.values({
|
|
108
|
+
bundleId: variant.messageBundleId,
|
|
109
|
+
locale: variant.messageLocale,
|
|
110
|
+
})
|
|
111
|
+
.returningAll()
|
|
112
|
+
.executeTakeFirstOrThrow();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const existingVariants = await trx
|
|
116
|
+
.selectFrom("variant")
|
|
117
|
+
.where("messageId", "=", existingMessage.id)
|
|
118
|
+
.selectAll()
|
|
119
|
+
.execute();
|
|
120
|
+
|
|
121
|
+
const existingVariant = existingVariants.find(
|
|
122
|
+
(v) => JSON.stringify(v.matches) === JSON.stringify(variant.matches)
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// need to reset typescript's type narrowing
|
|
126
|
+
(variant as VariantImport).id = existingVariant?.id;
|
|
127
|
+
(variant as VariantImport).messageId = existingMessage.id;
|
|
128
|
+
}
|
|
129
|
+
const toBeInsertedVariant: NewVariant = {
|
|
130
|
+
...variant,
|
|
131
|
+
// @ts-expect-error - bundle id is provided by VariantImport but not needed when inserting
|
|
132
|
+
messageBundleId: undefined,
|
|
133
|
+
messageLocale: undefined,
|
|
134
|
+
};
|
|
135
|
+
await trx
|
|
136
|
+
.insertInto("variant")
|
|
137
|
+
.values(toBeInsertedVariant)
|
|
138
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(toBeInsertedVariant))
|
|
139
|
+
.execute();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import type {
|
|
3
|
+
BundleImport,
|
|
4
|
+
InlangPlugin,
|
|
5
|
+
MessageImport,
|
|
6
|
+
VariantImport,
|
|
7
|
+
} from "../plugin/schema.js";
|
|
8
|
+
import type { Message } from "../database/schema.js";
|
|
9
|
+
import type { Text } from "../json-schema/pattern.js";
|
|
10
|
+
import { loadProjectInMemory } from "../project/loadProjectInMemory.js";
|
|
11
|
+
import { newProject } from "../project/newProject.js";
|
|
12
|
+
import { importFiles } from "./importFiles.js";
|
|
13
|
+
import { exportFiles } from "./exportFiles.js";
|
|
14
|
+
|
|
15
|
+
test("the file should be identical after a roundtrip if no modifications occured", async () => {
|
|
16
|
+
const project = await loadProjectInMemory({
|
|
17
|
+
blob: await newProject(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const enResource = JSON.stringify({
|
|
21
|
+
hello_world: "value1",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await importFiles({
|
|
25
|
+
files: [{ content: new TextEncoder().encode(enResource), locale: "en" }],
|
|
26
|
+
pluginKey: "mock",
|
|
27
|
+
plugins: [mockPluginSimple],
|
|
28
|
+
settings: await project.settings.get(),
|
|
29
|
+
db: project.db,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const importedBundles = await project.db
|
|
33
|
+
.selectFrom("bundle")
|
|
34
|
+
.selectAll()
|
|
35
|
+
.execute();
|
|
36
|
+
const importedMessages = await project.db
|
|
37
|
+
.selectFrom("message")
|
|
38
|
+
.selectAll()
|
|
39
|
+
.execute();
|
|
40
|
+
const importedVariants = await project.db
|
|
41
|
+
.selectFrom("variant")
|
|
42
|
+
.selectAll()
|
|
43
|
+
.execute();
|
|
44
|
+
|
|
45
|
+
expect(importedBundles.length).toBe(1);
|
|
46
|
+
expect(importedMessages.length).toBe(1);
|
|
47
|
+
expect(importedVariants.length).toBe(1);
|
|
48
|
+
expect(importedBundles[0]?.id).toBe("hello_world");
|
|
49
|
+
expect(importedMessages[0]?.bundleId).toBe("hello_world");
|
|
50
|
+
expect(importedVariants[0]?.messageId).toBe(importedMessages[0]?.id);
|
|
51
|
+
|
|
52
|
+
const exportedFiles = await exportFiles({
|
|
53
|
+
pluginKey: "mock",
|
|
54
|
+
plugins: [mockPluginSimple],
|
|
55
|
+
settings: await project.settings.get(),
|
|
56
|
+
db: project.db,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(exportedFiles.length).toBe(1);
|
|
60
|
+
expect(exportedFiles[0]?.name).toBe("en.json");
|
|
61
|
+
expect(new TextDecoder().decode(exportedFiles[0]?.content)).toBe(enResource);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("a variant with an existing match should update the existing variant and not create a new one to enable roundtrips", async () => {
|
|
65
|
+
const project = await loadProjectInMemory({
|
|
66
|
+
blob: await newProject(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const existing = {
|
|
70
|
+
bundles: [
|
|
71
|
+
{
|
|
72
|
+
id: "mock-bundle-id",
|
|
73
|
+
declarations: [],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
messages: [
|
|
77
|
+
{
|
|
78
|
+
id: "mock-message-id",
|
|
79
|
+
locale: "en",
|
|
80
|
+
selectors: [],
|
|
81
|
+
bundleId: "mock-bundle-id",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
variants: [
|
|
85
|
+
{
|
|
86
|
+
id: "mock-variant-id",
|
|
87
|
+
messageId: "mock-message-id",
|
|
88
|
+
matches: [
|
|
89
|
+
{
|
|
90
|
+
type: "literal-match",
|
|
91
|
+
key: "color",
|
|
92
|
+
value: "blue",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
pattern: [
|
|
96
|
+
{
|
|
97
|
+
type: "text",
|
|
98
|
+
value: "You have blue eyes.",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const updated = structuredClone(existing);
|
|
106
|
+
// @ts-expect-error - we know this is a text pattern
|
|
107
|
+
updated.variants[0].pattern[0].value = "You have beautiful blue eyes.";
|
|
108
|
+
|
|
109
|
+
const enResource = JSON.stringify(updated);
|
|
110
|
+
|
|
111
|
+
await importFiles({
|
|
112
|
+
files: [{ content: new TextEncoder().encode(enResource), locale: "en" }],
|
|
113
|
+
pluginKey: "mock",
|
|
114
|
+
plugins: [mockPluginAst],
|
|
115
|
+
settings: await project.settings.get(),
|
|
116
|
+
db: project.db,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const bundles = await project.db.selectFrom("bundle").selectAll().execute();
|
|
120
|
+
const messages = await project.db.selectFrom("message").selectAll().execute();
|
|
121
|
+
const variants = await project.db.selectFrom("variant").selectAll().execute();
|
|
122
|
+
|
|
123
|
+
expect(bundles.length).toBe(1);
|
|
124
|
+
expect(messages.length).toBe(1);
|
|
125
|
+
expect(variants.length).toBe(1);
|
|
126
|
+
// @ts-expect-error - we know this is a text pattern
|
|
127
|
+
expect(variants[0]?.pattern[0].value).toBe("You have beautiful blue eyes.");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("if a message for the bundle id and locale already exists, update it. don't create a new message", async () => {
|
|
131
|
+
const project = await loadProjectInMemory({
|
|
132
|
+
blob: await newProject(),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const existing: any = {
|
|
136
|
+
bundles: [{ id: "mock-bundle-id", declarations: [] }],
|
|
137
|
+
messages: [
|
|
138
|
+
{
|
|
139
|
+
id: "mock-message-id",
|
|
140
|
+
locale: "en",
|
|
141
|
+
selectors: [],
|
|
142
|
+
bundleId: "mock-bundle-id",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
variants: [],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const updated = structuredClone(existing);
|
|
149
|
+
updated.messages[0]!.selectors = [
|
|
150
|
+
{
|
|
151
|
+
type: "variable-reference",
|
|
152
|
+
name: "variable2",
|
|
153
|
+
},
|
|
154
|
+
] satisfies Message["selectors"];
|
|
155
|
+
|
|
156
|
+
const enResource = new TextEncoder().encode(JSON.stringify(updated));
|
|
157
|
+
|
|
158
|
+
await importFiles({
|
|
159
|
+
files: [{ content: enResource, locale: "en" }],
|
|
160
|
+
pluginKey: "mock",
|
|
161
|
+
plugins: [mockPluginAst],
|
|
162
|
+
settings: await project.settings.get(),
|
|
163
|
+
db: project.db,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const bundles = await project.db.selectFrom("bundle").selectAll().execute();
|
|
167
|
+
const messages = await project.db.selectFrom("message").selectAll().execute();
|
|
168
|
+
|
|
169
|
+
expect(bundles.length).toBe(1);
|
|
170
|
+
expect(messages.length).toBe(1);
|
|
171
|
+
|
|
172
|
+
expect(messages[0]?.selectors).toStrictEqual([
|
|
173
|
+
{
|
|
174
|
+
type: "variable-reference",
|
|
175
|
+
name: "variable2",
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("keys should be ordered alphabetically for .json to minimize git diffs", async () => {
|
|
181
|
+
const project = await loadProjectInMemory({
|
|
182
|
+
blob: await newProject(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const enResource = JSON.stringify({
|
|
186
|
+
a: "value1",
|
|
187
|
+
b: "value2",
|
|
188
|
+
d: "value4",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await importFiles({
|
|
192
|
+
files: [{ content: new TextEncoder().encode(enResource), locale: "en" }],
|
|
193
|
+
pluginKey: "mock",
|
|
194
|
+
plugins: [mockPluginSimple],
|
|
195
|
+
settings: await project.settings.get(),
|
|
196
|
+
db: project.db,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
await project.db.insertInto("bundle").values({ id: "c" }).execute();
|
|
200
|
+
await project.db
|
|
201
|
+
.insertInto("message")
|
|
202
|
+
.values({ id: "c-en", bundleId: "c", locale: "en" })
|
|
203
|
+
.execute();
|
|
204
|
+
await project.db
|
|
205
|
+
.insertInto("variant")
|
|
206
|
+
.values({ messageId: "c-en", pattern: [{ type: "text", value: "value3" }] })
|
|
207
|
+
.execute();
|
|
208
|
+
|
|
209
|
+
const exportedFiles = await exportFiles({
|
|
210
|
+
pluginKey: "mock",
|
|
211
|
+
plugins: [mockPluginSimple],
|
|
212
|
+
settings: await project.settings.get(),
|
|
213
|
+
db: project.db,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
expect(
|
|
217
|
+
JSON.parse(new TextDecoder().decode(exportedFiles[0]?.content))
|
|
218
|
+
).toStrictEqual({
|
|
219
|
+
a: "value1",
|
|
220
|
+
b: "value2",
|
|
221
|
+
c: "value3",
|
|
222
|
+
d: "value4",
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const mockPluginAst: InlangPlugin = {
|
|
227
|
+
key: "mock",
|
|
228
|
+
exportFiles: async ({ bundles, messages, variants }) => {
|
|
229
|
+
return [
|
|
230
|
+
{
|
|
231
|
+
locale: "every",
|
|
232
|
+
name: "x.json",
|
|
233
|
+
content: new TextEncoder().encode(
|
|
234
|
+
JSON.stringify({ bundles, messages, variants })
|
|
235
|
+
),
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
},
|
|
239
|
+
importFiles: async ({ files }) => {
|
|
240
|
+
let bundles: any[] = [];
|
|
241
|
+
let messages: any[] = [];
|
|
242
|
+
let variants: any[] = [];
|
|
243
|
+
for (const file of files) {
|
|
244
|
+
const parsed = JSON.parse(new TextDecoder().decode(file.content));
|
|
245
|
+
bundles = [...bundles, ...parsed.bundles];
|
|
246
|
+
messages = [...messages, ...parsed.messages];
|
|
247
|
+
variants = [...variants, ...parsed.variants];
|
|
248
|
+
}
|
|
249
|
+
return { bundles, messages, variants };
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// a simple mock plugin to test roundtrips
|
|
254
|
+
//
|
|
255
|
+
// purposefully not imported a real plugin
|
|
256
|
+
// to keep the interdepenedencies low and
|
|
257
|
+
// increase maintainability
|
|
258
|
+
const mockPluginSimple: InlangPlugin = {
|
|
259
|
+
key: "mock",
|
|
260
|
+
exportFiles: async ({ messages, variants }) => {
|
|
261
|
+
const jsons: any = {};
|
|
262
|
+
for (const message of messages) {
|
|
263
|
+
const key = message.bundleId;
|
|
264
|
+
const value = (
|
|
265
|
+
variants.find((v) => v.messageId === message.id)?.pattern[0] as Text
|
|
266
|
+
).value;
|
|
267
|
+
if (!jsons[message.locale]) {
|
|
268
|
+
jsons[message.locale] = {};
|
|
269
|
+
}
|
|
270
|
+
jsons[message.locale][key] = value;
|
|
271
|
+
}
|
|
272
|
+
return Object.entries(jsons).map(([locale, json]) => ({
|
|
273
|
+
locale,
|
|
274
|
+
name: locale + ".json",
|
|
275
|
+
content: new TextEncoder().encode(JSON.stringify(json)),
|
|
276
|
+
}));
|
|
277
|
+
},
|
|
278
|
+
importFiles: async ({ files }) => {
|
|
279
|
+
const bundles: BundleImport[] = [];
|
|
280
|
+
const messages: MessageImport[] = [];
|
|
281
|
+
const variants: VariantImport[] = [];
|
|
282
|
+
for (const file of files) {
|
|
283
|
+
const parsed = JSON.parse(new TextDecoder().decode(file.content));
|
|
284
|
+
for (const key in parsed) {
|
|
285
|
+
bundles.push({
|
|
286
|
+
id: key,
|
|
287
|
+
declarations: [],
|
|
288
|
+
});
|
|
289
|
+
messages.push({
|
|
290
|
+
bundleId: key,
|
|
291
|
+
locale: file.locale,
|
|
292
|
+
selectors: [],
|
|
293
|
+
});
|
|
294
|
+
variants.push({
|
|
295
|
+
messageBundleId: key,
|
|
296
|
+
messageLocale: file.locale,
|
|
297
|
+
matches: [],
|
|
298
|
+
pattern: [
|
|
299
|
+
{
|
|
300
|
+
type: "text",
|
|
301
|
+
value: parsed[key],
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
bundles,
|
|
309
|
+
messages,
|
|
310
|
+
variants,
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
};
|