@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,29 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { newProject } from "./newProject.js";
|
|
3
|
+
import { loadProjectInMemory } from "./loadProjectInMemory.js";
|
|
4
|
+
|
|
5
|
+
test("roundtrip should succeed", async () => {
|
|
6
|
+
const file1 = await newProject();
|
|
7
|
+
const project1 = await loadProjectInMemory({ blob: file1 });
|
|
8
|
+
const numBundles1 = (
|
|
9
|
+
await project1.db.selectFrom("bundle").select("id").execute()
|
|
10
|
+
).length;
|
|
11
|
+
expect(numBundles1).toBe(0);
|
|
12
|
+
|
|
13
|
+
// modify project
|
|
14
|
+
const insertedBundle = await project1.db
|
|
15
|
+
.insertInto("bundle")
|
|
16
|
+
.values({
|
|
17
|
+
id: "mock245",
|
|
18
|
+
})
|
|
19
|
+
.returning("id")
|
|
20
|
+
.executeTakeFirstOrThrow();
|
|
21
|
+
|
|
22
|
+
const file1AfterUpdates = await project1.toBlob();
|
|
23
|
+
await project1.close();
|
|
24
|
+
|
|
25
|
+
const project2 = await loadProjectInMemory({ blob: file1AfterUpdates });
|
|
26
|
+
const bundles = await project2.db.selectFrom("bundle").select("id").execute();
|
|
27
|
+
expect(bundles.length).toBe(1);
|
|
28
|
+
expect(bundles[0]?.id).toBe(insertedBundle.id);
|
|
29
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { openLixInMemory } from "@lix-js/sdk";
|
|
2
|
+
import { createInMemoryDatabase, importDatabase } from "sqlite-wasm-kysely";
|
|
3
|
+
import { loadProject } from "./loadProject.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load a project from a blob in memory.
|
|
7
|
+
*/
|
|
8
|
+
export async function loadProjectInMemory(
|
|
9
|
+
args: {
|
|
10
|
+
blob: Blob;
|
|
11
|
+
} & Omit<Parameters<typeof loadProject>[0], "sqlite" | "lix">
|
|
12
|
+
) {
|
|
13
|
+
const lix = await openLixInMemory({
|
|
14
|
+
blob: args.blob,
|
|
15
|
+
account: args.account,
|
|
16
|
+
providePlugins: [
|
|
17
|
+
// inlangLixPluginV1
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const dbFile = await lix.db
|
|
22
|
+
.selectFrom("file")
|
|
23
|
+
.select("data")
|
|
24
|
+
.where("path", "=", "/db.sqlite")
|
|
25
|
+
.executeTakeFirstOrThrow();
|
|
26
|
+
|
|
27
|
+
const sqlite = await createInMemoryDatabase({});
|
|
28
|
+
importDatabase({ db: sqlite, content: new Uint8Array(dbFile.data) });
|
|
29
|
+
|
|
30
|
+
return await loadProject({
|
|
31
|
+
// pass common arguments to loadProject
|
|
32
|
+
...args,
|
|
33
|
+
sqlite,
|
|
34
|
+
lix,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { expect, test, vi } from "vitest";
|
|
2
|
+
import { loadProjectInMemory } from "./loadProjectInMemory.js";
|
|
3
|
+
import { newProject } from "./newProject.js";
|
|
4
|
+
import { maybeCaptureLoadedProject } from "./maybeCaptureTelemetry.js";
|
|
5
|
+
import { capture } from "../services/telemetry/capture.js";
|
|
6
|
+
|
|
7
|
+
test("it should capture as expected", async () => {
|
|
8
|
+
vi.mock("../services/telemetry/capture.js", async () => {
|
|
9
|
+
return {
|
|
10
|
+
capture: vi.fn(() => Promise.resolve()),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
vi.mock("../services/env-variables/index", async () => {
|
|
15
|
+
return {
|
|
16
|
+
ENV_VARIABLES: {
|
|
17
|
+
PUBLIC_POSTHOG_TOKEN: "mock-defined",
|
|
18
|
+
SDK_VERSION: "1.0.0-mock",
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const project = await loadProjectInMemory({
|
|
24
|
+
blob: await newProject(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const account = await project.lix.db
|
|
28
|
+
.selectFrom("active_account")
|
|
29
|
+
.select("id")
|
|
30
|
+
.executeTakeFirstOrThrow();
|
|
31
|
+
|
|
32
|
+
const bundle = await project.db
|
|
33
|
+
.insertInto("bundle")
|
|
34
|
+
.defaultValues()
|
|
35
|
+
.returningAll()
|
|
36
|
+
.executeTakeFirstOrThrow();
|
|
37
|
+
|
|
38
|
+
const message = await project.db
|
|
39
|
+
.insertInto("message")
|
|
40
|
+
.values({ bundleId: bundle.id, locale: "en" })
|
|
41
|
+
.returningAll()
|
|
42
|
+
.executeTakeFirstOrThrow();
|
|
43
|
+
|
|
44
|
+
await project.db
|
|
45
|
+
.insertInto("variant")
|
|
46
|
+
.values({ messageId: message.id })
|
|
47
|
+
.returningAll()
|
|
48
|
+
.executeTakeFirst();
|
|
49
|
+
|
|
50
|
+
const settings = await project.settings.get();
|
|
51
|
+
|
|
52
|
+
const id = await project.id.get();
|
|
53
|
+
|
|
54
|
+
const plugins = await project.plugins.get();
|
|
55
|
+
|
|
56
|
+
await maybeCaptureLoadedProject({
|
|
57
|
+
id,
|
|
58
|
+
settings,
|
|
59
|
+
plugins,
|
|
60
|
+
lix: project.lix,
|
|
61
|
+
appId: "test",
|
|
62
|
+
db: project.db,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(capture).toHaveBeenCalledWith("SDK loaded project", {
|
|
66
|
+
projectId: await project.id.get(),
|
|
67
|
+
settings: await project.settings.get(),
|
|
68
|
+
accountId: account.id,
|
|
69
|
+
properties: {
|
|
70
|
+
appId: "test",
|
|
71
|
+
settings: await project.settings.get(),
|
|
72
|
+
pluginKeys: [],
|
|
73
|
+
sdkVersion: "1.0.0-mock",
|
|
74
|
+
numBundles: 1,
|
|
75
|
+
numMessages: 1,
|
|
76
|
+
numVariants: 1,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { capture } from "../services/telemetry/capture.js";
|
|
3
|
+
import type { InlangDatabaseSchema } from "../database/schema.js";
|
|
4
|
+
import { ENV_VARIABLES } from "../services/env-variables/index.js";
|
|
5
|
+
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
6
|
+
import { captureError } from "../services/error-reporting/index.js";
|
|
7
|
+
import type { Lix } from "@lix-js/sdk";
|
|
8
|
+
|
|
9
|
+
export async function maybeCaptureLoadedProject(args: {
|
|
10
|
+
id: string;
|
|
11
|
+
lix: Lix;
|
|
12
|
+
settings: ProjectSettings;
|
|
13
|
+
plugins: Readonly<Array<{ key: string }>>;
|
|
14
|
+
appId?: string;
|
|
15
|
+
db: Kysely<InlangDatabaseSchema>;
|
|
16
|
+
}) {
|
|
17
|
+
if (args.settings.telemetry === "off") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const activeAccount = await args.lix.db
|
|
23
|
+
.selectFrom("active_account")
|
|
24
|
+
.select("id")
|
|
25
|
+
.executeTakeFirstOrThrow();
|
|
26
|
+
|
|
27
|
+
const bundles = await args.db
|
|
28
|
+
.selectFrom("bundle")
|
|
29
|
+
.select((s) => s.fn.count("id").as("count"))
|
|
30
|
+
.executeTakeFirst();
|
|
31
|
+
const messages = await args.db
|
|
32
|
+
.selectFrom("message")
|
|
33
|
+
.select((s) => s.fn.count("id").as("count"))
|
|
34
|
+
.executeTakeFirst();
|
|
35
|
+
const variants = await args.db
|
|
36
|
+
.selectFrom("variant")
|
|
37
|
+
.select((s) => s.fn.count("id").as("count"))
|
|
38
|
+
.executeTakeFirst();
|
|
39
|
+
|
|
40
|
+
await capture("SDK loaded project", {
|
|
41
|
+
projectId: args.id,
|
|
42
|
+
settings: args.settings,
|
|
43
|
+
accountId: activeAccount.id,
|
|
44
|
+
properties: {
|
|
45
|
+
// Insight: Which app is used by the SDK
|
|
46
|
+
appId: args.appId,
|
|
47
|
+
// Insight: How many languages are used, etc.
|
|
48
|
+
settings: args.settings,
|
|
49
|
+
// Insight on the used plugins (which one's to prioritize)
|
|
50
|
+
pluginKeys: args.plugins.map((plugin) => plugin.key),
|
|
51
|
+
// Insight: Which version of the SDK is used (can be used to deprecate old versions)
|
|
52
|
+
sdkVersion: ENV_VARIABLES.SDK_VERSION,
|
|
53
|
+
// Insight: Scale of projects (what project size to optimize for)
|
|
54
|
+
numBundles: bundles?.count,
|
|
55
|
+
numMessages: messages?.count,
|
|
56
|
+
numVariants: variants?.count,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
} catch (e) {
|
|
60
|
+
if (
|
|
61
|
+
e instanceof Error &&
|
|
62
|
+
e.message.includes("driver has already been destroyed")
|
|
63
|
+
) {
|
|
64
|
+
// The project has been closed, nothing to capture
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
captureError(e);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { defaultProjectSettings, newProject } from "./newProject.js";
|
|
3
|
+
import { loadProjectInMemory } from "./loadProjectInMemory.js";
|
|
4
|
+
import { validate } from "uuid";
|
|
5
|
+
|
|
6
|
+
test("it should be possible to provide settings for testing or other purposes", async () => {
|
|
7
|
+
const project = await loadProjectInMemory({
|
|
8
|
+
blob: await newProject({
|
|
9
|
+
settings: { baseLocale: "fr", locales: ["fr"], modules: [] },
|
|
10
|
+
}),
|
|
11
|
+
});
|
|
12
|
+
const settings = await project.settings.get();
|
|
13
|
+
expect(settings.baseLocale).toBe("fr");
|
|
14
|
+
expect(settings.locales).toEqual(["fr"]);
|
|
15
|
+
expect(settings.modules).toEqual([]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("it should be possible to create a project with default settings", async () => {
|
|
19
|
+
const project = await loadProjectInMemory({
|
|
20
|
+
blob: await newProject(),
|
|
21
|
+
});
|
|
22
|
+
const settings = await project.settings.get();
|
|
23
|
+
// pruning old settings that might exist for legacy reasons
|
|
24
|
+
delete settings.languageTags;
|
|
25
|
+
delete settings.sourceLanguageTag;
|
|
26
|
+
expect(settings).toStrictEqual(defaultProjectSettings);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("it should have a uuid as project id", async () => {
|
|
30
|
+
const project = await loadProjectInMemory({
|
|
31
|
+
blob: await newProject(),
|
|
32
|
+
});
|
|
33
|
+
const projectId = await project.id.get();
|
|
34
|
+
expect(projectId).toBeDefined();
|
|
35
|
+
expect(validate(projectId)).toBe(true);
|
|
36
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { newLixFile, openLixInMemory, toBlob } from "@lix-js/sdk";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
4
|
+
import {
|
|
5
|
+
contentFromDatabase,
|
|
6
|
+
createInMemoryDatabase,
|
|
7
|
+
} from "sqlite-wasm-kysely";
|
|
8
|
+
import { initDb } from "../database/initDb.js";
|
|
9
|
+
import { captureError } from "../services/error-reporting/index.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new inlang project.
|
|
13
|
+
*
|
|
14
|
+
* The app is responsible for saving the project "whereever"
|
|
15
|
+
* e.g. the user's computer, cloud storage, or OPFS in the browser.
|
|
16
|
+
*/
|
|
17
|
+
export async function newProject(args?: {
|
|
18
|
+
settings?: ProjectSettings;
|
|
19
|
+
}): Promise<Blob> {
|
|
20
|
+
const sqlite = await createInMemoryDatabase({
|
|
21
|
+
readOnly: false,
|
|
22
|
+
});
|
|
23
|
+
initDb({ sqlite });
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const inlangDbContent = contentFromDatabase(sqlite);
|
|
27
|
+
|
|
28
|
+
const lix = await openLixInMemory({ blob: await newLixFile() });
|
|
29
|
+
|
|
30
|
+
// write files to lix
|
|
31
|
+
await lix.db
|
|
32
|
+
.insertInto("file")
|
|
33
|
+
.values([
|
|
34
|
+
{
|
|
35
|
+
path: "/db.sqlite",
|
|
36
|
+
data: inlangDbContent,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: "/settings.json",
|
|
40
|
+
data: new TextEncoder().encode(
|
|
41
|
+
JSON.stringify(args?.settings ?? defaultProjectSettings)
|
|
42
|
+
),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
path: "/project_id",
|
|
46
|
+
data: new TextEncoder().encode(v4()),
|
|
47
|
+
},
|
|
48
|
+
])
|
|
49
|
+
.execute();
|
|
50
|
+
const blob = toBlob({ lix });
|
|
51
|
+
lix.sqlite.close();
|
|
52
|
+
return blob;
|
|
53
|
+
} catch (e) {
|
|
54
|
+
const error = new Error(`Failed to create new inlang project: ${e}`, {
|
|
55
|
+
cause: e,
|
|
56
|
+
});
|
|
57
|
+
captureError(error);
|
|
58
|
+
throw error;
|
|
59
|
+
} finally {
|
|
60
|
+
sqlite.close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const defaultProjectSettings = {
|
|
65
|
+
$schema: "https://inlang.com/schema/project-settings",
|
|
66
|
+
baseLocale: "en",
|
|
67
|
+
locales: ["en"],
|
|
68
|
+
modules: [
|
|
69
|
+
// for instant gratification, we're adding common rules
|
|
70
|
+
// "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-empty-pattern@latest/dist/index.js",
|
|
71
|
+
// "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-missing-translation@latest/dist/index.js",
|
|
72
|
+
// "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-without-source@latest/dist/index.js",
|
|
73
|
+
// default to the message format plugin because it supports all features
|
|
74
|
+
// "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@latest/dist/index.js",
|
|
75
|
+
// the m function matcher should be installed by default in case Sherlock (VS Code extension) is adopted
|
|
76
|
+
// "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@latest/dist/index.js",
|
|
77
|
+
],
|
|
78
|
+
} satisfies ProjectSettings;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { test, expect, vi } from "vitest";
|
|
2
|
+
import { saveProjectToDirectory } from "./saveProjectToDirectory.js";
|
|
3
|
+
import { Volume } from "memfs";
|
|
4
|
+
import { loadProjectInMemory } from "./loadProjectInMemory.js";
|
|
5
|
+
import { newProject } from "./newProject.js";
|
|
6
|
+
import type { InlangPlugin } from "../plugin/schema.js";
|
|
7
|
+
import type { Bundle, NewMessage, Variant } from "../database/schema.js";
|
|
8
|
+
import { loadProjectFromDirectory } from "./loadProjectFromDirectory.js";
|
|
9
|
+
import { selectBundleNested } from "../query-utilities/selectBundleNested.js";
|
|
10
|
+
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
11
|
+
import type { MessageV1 } from "../json-schema/old-v1-message/schemaV1.js";
|
|
12
|
+
|
|
13
|
+
test("it should throw if the path doesn't end with .inlang", async () => {
|
|
14
|
+
await expect(() =>
|
|
15
|
+
saveProjectToDirectory({
|
|
16
|
+
fs: {} as any,
|
|
17
|
+
project: {} as any,
|
|
18
|
+
path: "/foo/bar",
|
|
19
|
+
})
|
|
20
|
+
).rejects.toThrowError("The path must end with .inlang");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("it should overwrite all files to the directory except the db.sqlite file", async () => {
|
|
24
|
+
const mockFs = Volume.fromJSON({
|
|
25
|
+
"/foo/bar.inlang/settings.json": JSON.stringify({
|
|
26
|
+
baseLocale: "en",
|
|
27
|
+
locales: ["en"],
|
|
28
|
+
}),
|
|
29
|
+
}).promises as any;
|
|
30
|
+
|
|
31
|
+
const project = await loadProjectInMemory({
|
|
32
|
+
blob: await newProject({
|
|
33
|
+
settings: {
|
|
34
|
+
baseLocale: "en",
|
|
35
|
+
locales: ["en", "fr", "mock"],
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
await saveProjectToDirectory({
|
|
41
|
+
fs: mockFs,
|
|
42
|
+
project,
|
|
43
|
+
path: "/foo/bar.inlang",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const files = await mockFs.readdir("/foo/bar.inlang");
|
|
47
|
+
const updatedSettingsFile = await mockFs.readFile(
|
|
48
|
+
"/foo/bar.inlang/settings.json",
|
|
49
|
+
"utf-8"
|
|
50
|
+
);
|
|
51
|
+
const updatedSettings = JSON.parse(updatedSettingsFile);
|
|
52
|
+
|
|
53
|
+
// only testing known files at the time of the test.
|
|
54
|
+
// this test should be updated for files that should NOT
|
|
55
|
+
// be contained in the directory in the future
|
|
56
|
+
expect(files).toContain("settings.json");
|
|
57
|
+
expect(files).not.toContain("db.sqlite");
|
|
58
|
+
expect(updatedSettings.baseLocale).toBe("en");
|
|
59
|
+
expect(updatedSettings.locales).toEqual(["en", "fr", "mock"]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("a roundtrip should work", async () => {
|
|
63
|
+
const bundles: Bundle[] = [{ id: "mock-bundle", declarations: [] }];
|
|
64
|
+
const messages: NewMessage[] = [{ bundleId: "mock-bundle", locale: "en" }];
|
|
65
|
+
const variants: Variant[] = [];
|
|
66
|
+
|
|
67
|
+
const volume = Volume.fromJSON({
|
|
68
|
+
"/mock-file.json": JSON.stringify({ bundles, messages, variants }),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const mockPlugin: InlangPlugin = {
|
|
72
|
+
key: "mock-plugin",
|
|
73
|
+
toBeImportedFiles: async () => {
|
|
74
|
+
return [{ path: "/mock-file.json", locale: "mock" }];
|
|
75
|
+
},
|
|
76
|
+
importFiles: async ({ files }) => {
|
|
77
|
+
const { bundles, messages, variants } = JSON.parse(
|
|
78
|
+
new TextDecoder().decode(files[0]?.content)
|
|
79
|
+
);
|
|
80
|
+
return { bundles, messages, variants };
|
|
81
|
+
},
|
|
82
|
+
exportFiles: async ({ bundles }) => {
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
content: new TextEncoder().encode(JSON.stringify(bundles)),
|
|
86
|
+
name: "mock-file.json",
|
|
87
|
+
locale: "mock",
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const exportFilesSpy = vi.spyOn(mockPlugin, "exportFiles");
|
|
94
|
+
const importFilesSpy = vi.spyOn(mockPlugin, "importFiles");
|
|
95
|
+
|
|
96
|
+
const project = await loadProjectInMemory({
|
|
97
|
+
blob: await newProject(),
|
|
98
|
+
providePlugins: [mockPlugin],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await project.db.insertInto("bundle").values(bundles).execute();
|
|
102
|
+
await project.db.insertInto("message").values(messages).execute();
|
|
103
|
+
|
|
104
|
+
await saveProjectToDirectory({
|
|
105
|
+
fs: volume.promises as any,
|
|
106
|
+
project,
|
|
107
|
+
path: "/foo/bar.inlang",
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// const fileTree = volume.toJSON();
|
|
111
|
+
|
|
112
|
+
expect(exportFilesSpy).toHaveBeenCalled();
|
|
113
|
+
expect(importFilesSpy).not.toHaveBeenCalled();
|
|
114
|
+
|
|
115
|
+
// TODO deactivated since mockBundleNested no longer contains the id of the messages
|
|
116
|
+
// expect(fileTree).toEqual(
|
|
117
|
+
// expect.objectContaining({
|
|
118
|
+
// "/foo/mock-file.json": JSON.stringify([mockBundleNested]),
|
|
119
|
+
// })
|
|
120
|
+
// );
|
|
121
|
+
|
|
122
|
+
// testing roundtrip
|
|
123
|
+
|
|
124
|
+
const project2 = await loadProjectFromDirectory({
|
|
125
|
+
fs: volume as any,
|
|
126
|
+
path: "/foo/bar.inlang",
|
|
127
|
+
providePlugins: [mockPlugin],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect(mockPlugin.importFiles).toHaveBeenCalled();
|
|
131
|
+
|
|
132
|
+
const bundlesAfter = await project2.db
|
|
133
|
+
.selectFrom("bundle")
|
|
134
|
+
.selectAll()
|
|
135
|
+
.execute();
|
|
136
|
+
const messagesAfter = await project2.db
|
|
137
|
+
.selectFrom("message")
|
|
138
|
+
.selectAll()
|
|
139
|
+
.execute();
|
|
140
|
+
const variantsAfter = await project2.db
|
|
141
|
+
.selectFrom("variant")
|
|
142
|
+
.selectAll()
|
|
143
|
+
.execute();
|
|
144
|
+
|
|
145
|
+
expect(bundlesAfter).lengthOf(1);
|
|
146
|
+
expect(messagesAfter).lengthOf(1);
|
|
147
|
+
expect(variantsAfter).lengthOf(0);
|
|
148
|
+
|
|
149
|
+
expect(bundlesAfter[0]).toStrictEqual(expect.objectContaining(bundles[0]));
|
|
150
|
+
expect(messagesAfter[0]).toStrictEqual(
|
|
151
|
+
expect.objectContaining(messagesAfter[0])
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test.todo(
|
|
156
|
+
"a roundtrip with legacy load and save messages should work",
|
|
157
|
+
async () => {
|
|
158
|
+
const mockMessageV1: MessageV1 = {
|
|
159
|
+
id: "mock-legacy-message",
|
|
160
|
+
alias: {},
|
|
161
|
+
selectors: [],
|
|
162
|
+
variants: [
|
|
163
|
+
{
|
|
164
|
+
languageTag: "en",
|
|
165
|
+
match: [],
|
|
166
|
+
pattern: [{ type: "Text", value: "Hello from legacy message" }],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const volume = Volume.fromJSON({
|
|
172
|
+
"/foo/bar.inlang/settings.json": JSON.stringify({
|
|
173
|
+
baseLocale: "en",
|
|
174
|
+
locales: ["en"],
|
|
175
|
+
} satisfies ProjectSettings),
|
|
176
|
+
"/foo/i18n/en.json": JSON.stringify([mockMessageV1]),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const mockPlugin: InlangPlugin = {
|
|
180
|
+
id: "mock-legacy-plugin",
|
|
181
|
+
key: "mock-legacy-plugin",
|
|
182
|
+
loadMessages: async ({ nodeishFs }) => {
|
|
183
|
+
// expecting `loadMessages` to transform the relative path
|
|
184
|
+
// to an absolute path `./i18n/en.json` -> `/foo/i18n/en.json`
|
|
185
|
+
const file = await nodeishFs.readFile("./i18n/en.json", {
|
|
186
|
+
encoding: "utf-8",
|
|
187
|
+
});
|
|
188
|
+
return JSON.parse(file as string);
|
|
189
|
+
},
|
|
190
|
+
saveMessages: async ({ messages, nodeishFs }) => {
|
|
191
|
+
await nodeishFs.writeFile(
|
|
192
|
+
"./i18n/en.json",
|
|
193
|
+
new TextEncoder().encode(JSON.stringify(messages))
|
|
194
|
+
.buffer as ArrayBuffer
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const loadMessagesSpy = vi.spyOn(mockPlugin, "loadMessages");
|
|
200
|
+
const saveMessagesSpy = vi.spyOn(mockPlugin, "saveMessages");
|
|
201
|
+
|
|
202
|
+
const project = await loadProjectFromDirectory({
|
|
203
|
+
fs: volume as any,
|
|
204
|
+
path: "/foo/bar.inlang",
|
|
205
|
+
providePlugins: [mockPlugin],
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(loadMessagesSpy).toHaveBeenCalled();
|
|
209
|
+
expect(saveMessagesSpy).not.toHaveBeenCalled();
|
|
210
|
+
|
|
211
|
+
const bundles1 = await selectBundleNested(project.db).execute();
|
|
212
|
+
|
|
213
|
+
expect(bundles1[0]?.messages).lengthOf(1);
|
|
214
|
+
expect(bundles1[0]?.messages[0]?.variants).toEqual([
|
|
215
|
+
expect.objectContaining({
|
|
216
|
+
pattern: [
|
|
217
|
+
{
|
|
218
|
+
type: "text",
|
|
219
|
+
value: "Hello from legacy message",
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
}),
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
// await project.db
|
|
226
|
+
// .updateTable("variant")
|
|
227
|
+
// .set({
|
|
228
|
+
// pattern: [{ type: "text", value: "Updated message" }],
|
|
229
|
+
// })
|
|
230
|
+
// .where("id", "=", bundles1[0]?.messages[0]?.variants[0]?.id as string)
|
|
231
|
+
// .execute();
|
|
232
|
+
|
|
233
|
+
// testing the saveMessages function by removing the en.json file
|
|
234
|
+
await volume.promises.rm("/foo/i18n/en.json");
|
|
235
|
+
|
|
236
|
+
await saveProjectToDirectory({
|
|
237
|
+
fs: volume.promises as any,
|
|
238
|
+
project,
|
|
239
|
+
path: "/foo/bar.inlang",
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(saveMessagesSpy).toHaveBeenCalled();
|
|
243
|
+
|
|
244
|
+
const fileTree = volume.toJSON();
|
|
245
|
+
const parsed = JSON.parse(fileTree["/foo/i18n/en.json"] as string);
|
|
246
|
+
|
|
247
|
+
expect(parsed).toEqual(expect.objectContaining([mockMessageV1]));
|
|
248
|
+
|
|
249
|
+
// testing roundtrip
|
|
250
|
+
|
|
251
|
+
const project2 = await loadProjectFromDirectory({
|
|
252
|
+
fs: volume as any,
|
|
253
|
+
path: "/foo/bar.inlang",
|
|
254
|
+
providePlugins: [mockPlugin],
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const bundles2 = await selectBundleNested(project2.db).execute();
|
|
258
|
+
|
|
259
|
+
// TODO deactivated since the ids must not be equal for separate imports - matching happens on language and matcher now
|
|
260
|
+
expect(bundles1).toStrictEqual(bundles2);
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
test("it should preserve the formatting of existing json resource files", async () => {
|
|
265
|
+
const mockJson =
|
|
266
|
+
JSON.stringify(
|
|
267
|
+
{ key: "value" },
|
|
268
|
+
undefined,
|
|
269
|
+
// tab spacing
|
|
270
|
+
"\t"
|
|
271
|
+
) +
|
|
272
|
+
// ends with new line
|
|
273
|
+
"\n";
|
|
274
|
+
|
|
275
|
+
const mockPlugin: InlangPlugin = {
|
|
276
|
+
key: "mock",
|
|
277
|
+
exportFiles: async () => {
|
|
278
|
+
return [
|
|
279
|
+
{
|
|
280
|
+
name: "en.json",
|
|
281
|
+
// no beautified json
|
|
282
|
+
content: new TextEncoder().encode(JSON.stringify({ key: "value" })),
|
|
283
|
+
locale: "en",
|
|
284
|
+
},
|
|
285
|
+
];
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const volume = Volume.fromJSON({
|
|
290
|
+
"/foo/project.inlang/settings.json": JSON.stringify({
|
|
291
|
+
baseLocale: "en",
|
|
292
|
+
locales: ["en"],
|
|
293
|
+
} satisfies ProjectSettings),
|
|
294
|
+
"/foo/en.json": mockJson,
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const project = await loadProjectInMemory({
|
|
298
|
+
blob: await newProject(),
|
|
299
|
+
providePlugins: [mockPlugin],
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
await saveProjectToDirectory({
|
|
303
|
+
path: "/foo/project.inlang",
|
|
304
|
+
fs: volume.promises as any,
|
|
305
|
+
project,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const fileAfterSave = await volume.promises.readFile("/foo/en.json", "utf-8");
|
|
309
|
+
expect(fileAfterSave).toBe(mockJson);
|
|
310
|
+
});
|