@inlang/sdk 0.36.3 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +167 -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 +13 -0
- package/dist/project/maybeCaptureTelemetry.d.ts.map +1 -0
- package/dist/project/maybeCaptureTelemetry.js +53 -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 +65 -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 +4 -2
- package/dist/services/telemetry/capture.d.ts.map +1 -0
- package/dist/services/telemetry/capture.js +77 -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 +44 -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 +177 -0
- package/src/project/loadProject.ts +245 -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 +72 -0
- package/src/project/maybeCaptureTelemetry.ts +61 -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 +48 -0
- package/src/services/telemetry/capture.ts +98 -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,127 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9b9ba9f2-e828-592b-9d34-ef9bdb8f67c0")}catch(e){}}();
|
|
5
|
+
import { getLeafChange, } from "@lix-js/sdk";
|
|
6
|
+
import { contentFromDatabase, loadDatabaseInMemory } from "sqlite-wasm-kysely";
|
|
7
|
+
import { initDb } from "../database/initDb.js";
|
|
8
|
+
export const applyChanges = async ({ lix, file, changes, }) => {
|
|
9
|
+
if (file.path?.endsWith("db.sqlite") === false) {
|
|
10
|
+
throw new Error("Unimplemented. Only the db.sqlite file can be handled for now.");
|
|
11
|
+
}
|
|
12
|
+
// todo make transactional
|
|
13
|
+
const sqlite = await loadDatabaseInMemory(file.data);
|
|
14
|
+
const db = initDb({ sqlite });
|
|
15
|
+
// the award for the most inefficient deduplication goes to...
|
|
16
|
+
const leafChanges = [
|
|
17
|
+
...new Set(await Promise.all(changes.map(async (change) => {
|
|
18
|
+
const leafChange = await getLeafChange({ change, lix });
|
|
19
|
+
// enable string comparison to avoid duplicates
|
|
20
|
+
return JSON.stringify(leafChange);
|
|
21
|
+
}))),
|
|
22
|
+
].map((v) => JSON.parse(v));
|
|
23
|
+
// changes need to be applied in order of foreign keys to avoid constraint violations
|
|
24
|
+
// 1. bundles
|
|
25
|
+
// 2. messages
|
|
26
|
+
// 3. variants
|
|
27
|
+
const applyOrder = {
|
|
28
|
+
bundle: 1,
|
|
29
|
+
message: 2,
|
|
30
|
+
variant: 3,
|
|
31
|
+
};
|
|
32
|
+
// future optimization potential here but sorting in one go
|
|
33
|
+
const orderedLeafChanges = [...leafChanges].sort((a, b) => {
|
|
34
|
+
const orderA = applyOrder[a.type];
|
|
35
|
+
const orderB = applyOrder[b.type];
|
|
36
|
+
if (orderA === undefined || orderB === undefined) {
|
|
37
|
+
throw new Error(`Received an unknown entity type: ${a.type} && ${b.type}. Expected one of: ${Object.keys(applyOrder)}`);
|
|
38
|
+
}
|
|
39
|
+
return orderA - orderB;
|
|
40
|
+
});
|
|
41
|
+
for (const leafChange of orderedLeafChanges) {
|
|
42
|
+
// deletion
|
|
43
|
+
if (leafChange.value === undefined) {
|
|
44
|
+
await db
|
|
45
|
+
.deleteFrom(leafChange.type)
|
|
46
|
+
.where("id", "=", leafChange.meta?.id)
|
|
47
|
+
.execute();
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// upsert the value
|
|
51
|
+
const value = leafChange.value;
|
|
52
|
+
try {
|
|
53
|
+
await db
|
|
54
|
+
.insertInto(leafChange.type)
|
|
55
|
+
.values(value)
|
|
56
|
+
.onConflict((c) => c.column("id").doUpdateSet(value))
|
|
57
|
+
.execute();
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
// 787 = SQLITE_CONSTRAINT_FOREIGNKEY
|
|
61
|
+
if (e instanceof Error && e?.resultCode === 787) {
|
|
62
|
+
await handleForeignKeyViolation({ change: leafChange, lix, db });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { fileData: contentFromDatabase(sqlite) };
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Handles foreign key violations e.g. a change
|
|
73
|
+
* doesn't exist in the target database but is referenced
|
|
74
|
+
* by an entity.
|
|
75
|
+
*/
|
|
76
|
+
async function handleForeignKeyViolation(args) {
|
|
77
|
+
const lastKnown = async (type, id) => await args.lix.db
|
|
78
|
+
.selectFrom("change")
|
|
79
|
+
.selectAll()
|
|
80
|
+
// heuristic that getting the last bundle value is fine
|
|
81
|
+
// and using created_at is fine too. if the change is undesired
|
|
82
|
+
// , a user can revert it with lix change control
|
|
83
|
+
.orderBy("created_at desc")
|
|
84
|
+
.where("type", "=", type)
|
|
85
|
+
.where((eb) => eb.ref("value", "->>").key("id"), "=", id)
|
|
86
|
+
.where("operation", "in", ["create", "update"])
|
|
87
|
+
// TODO shouldn't throw. The API needs to be able to
|
|
88
|
+
// report issues back to the app without throwing and potentially failing
|
|
89
|
+
// to apply 1000 changes because 1 change is invalid
|
|
90
|
+
// same requirement as in inlang, see https://github.com/opral/inlang-sdk/issues/213
|
|
91
|
+
.executeTakeFirstOrThrow();
|
|
92
|
+
if (args.change.type === "message") {
|
|
93
|
+
const lastKnownBundle = await lastKnown("bundle", args.change.value?.bundleId);
|
|
94
|
+
await args.db
|
|
95
|
+
.insertInto("bundle")
|
|
96
|
+
.values(lastKnownBundle.value)
|
|
97
|
+
.execute();
|
|
98
|
+
}
|
|
99
|
+
else if (args.change.type === "variant") {
|
|
100
|
+
const lastKnownMessage = await lastKnown("message", args.change.value?.messageId);
|
|
101
|
+
// getting the bundle too out of precaution
|
|
102
|
+
const lastKnownBundle = await lastKnown("bundle", lastKnownMessage.value?.bundleId);
|
|
103
|
+
await args.db
|
|
104
|
+
.insertInto("bundle")
|
|
105
|
+
.values(lastKnownBundle.value)
|
|
106
|
+
// the bundle exists, so we can ignore the conflict
|
|
107
|
+
.onConflict((c) => c.doNothing())
|
|
108
|
+
.execute();
|
|
109
|
+
await args.db
|
|
110
|
+
.insertInto("message")
|
|
111
|
+
.values(lastKnownMessage.value)
|
|
112
|
+
.execute();
|
|
113
|
+
await args.db
|
|
114
|
+
.insertInto(args.change.type)
|
|
115
|
+
.values(args.change.value)
|
|
116
|
+
.onConflict((c) => c.column("id").doUpdateSet(args.change.value))
|
|
117
|
+
.execute();
|
|
118
|
+
}
|
|
119
|
+
// re-execute applying the change
|
|
120
|
+
await args.db
|
|
121
|
+
.insertInto(args.change.type)
|
|
122
|
+
.values(args.change.value)
|
|
123
|
+
.onConflict((c) => c.column("id").doUpdateSet(args.change.value))
|
|
124
|
+
.execute();
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=applyChanges.js.map
|
|
127
|
+
//# debugId=9b9ba9f2-e828-592b-9d34-ef9bdb8f67c0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyChanges.js","sources":["lix-plugin/applyChanges.ts"],"sourceRoot":"/","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\nimport {\n\tgetLeafChange,\n\ttype Change,\n\ttype LixPlugin,\n\ttype LixReadonly,\n} from \"@lix-js/sdk\";\nimport { contentFromDatabase, loadDatabaseInMemory } from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\nimport type { Kysely } from \"kysely\";\nimport type { InlangDatabaseSchema } from \"../database/schema.js\";\n\nexport const applyChanges: NonNullable<LixPlugin[\"applyChanges\"]> = async ({\n\tlix,\n\tfile,\n\tchanges,\n}) => {\n\tif (file.path?.endsWith(\"db.sqlite\") === false) {\n\t\tthrow new Error(\n\t\t\t\"Unimplemented. Only the db.sqlite file can be handled for now.\"\n\t\t);\n\t}\n\n\t// todo make transactional\n\n\tconst sqlite = await loadDatabaseInMemory(file.data);\n\tconst db = initDb({ sqlite });\n\n\t// the award for the most inefficient deduplication goes to...\n\tconst leafChanges = [\n\t\t...new Set(\n\t\t\tawait Promise.all(\n\t\t\t\tchanges.map(async (change) => {\n\t\t\t\t\tconst leafChange = await getLeafChange({ change, lix });\n\t\t\t\t\t// enable string comparison to avoid duplicates\n\t\t\t\t\treturn JSON.stringify(leafChange);\n\t\t\t\t})\n\t\t\t)\n\t\t),\n\t].map((v) => JSON.parse(v));\n\n\t// changes need to be applied in order of foreign keys to avoid constraint violations\n\t// 1. bundles\n\t// 2. messages\n\t// 3. variants\n\tconst applyOrder: Record<string, number> = {\n\t\tbundle: 1,\n\t\tmessage: 2,\n\t\tvariant: 3,\n\t};\n\n\t// future optimization potential here but sorting in one go\n\tconst orderedLeafChanges = [...leafChanges].sort((a, b) => {\n\t\tconst orderA = applyOrder[a.type];\n\t\tconst orderB = applyOrder[b.type];\n\n\t\tif (orderA === undefined || orderB === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Received an unknown entity type: ${a.type} && ${\n\t\t\t\t\tb.type\n\t\t\t\t}. Expected one of: ${Object.keys(applyOrder)}`\n\t\t\t);\n\t\t}\n\n\t\treturn orderA - orderB;\n\t});\n\tfor (const leafChange of orderedLeafChanges) {\n\t\t// deletion\n\t\tif (leafChange.value === undefined) {\n\t\t\tawait db\n\t\t\t\t.deleteFrom(leafChange.type as \"bundle\" | \"message\" | \"variant\")\n\t\t\t\t.where(\"id\", \"=\", leafChange.meta?.id)\n\t\t\t\t.execute();\n\t\t\tcontinue;\n\t\t}\n\n\t\t// upsert the value\n\t\tconst value = leafChange.value as any;\n\n\t\ttry {\n\t\t\tawait db\n\t\t\t\t.insertInto(leafChange.type as \"bundle\" | \"message\" | \"variant\")\n\t\t\t\t.values(value)\n\t\t\t\t.onConflict((c) => c.column(\"id\").doUpdateSet(value))\n\t\t\t\t.execute();\n\t\t} catch (e) {\n\t\t\t// 787 = SQLITE_CONSTRAINT_FOREIGNKEY\n\t\t\tif (e instanceof Error && (e as any)?.resultCode === 787) {\n\t\t\t\tawait handleForeignKeyViolation({ change: leafChange, lix, db });\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\treturn { fileData: contentFromDatabase(sqlite) };\n};\n\n/**\n * Handles foreign key violations e.g. a change\n * doesn't exist in the target database but is referenced\n * by an entity.\n */\nasync function handleForeignKeyViolation(args: {\n\tchange: Change;\n\tlix: LixReadonly;\n\tdb: Kysely<InlangDatabaseSchema>;\n}) {\n\tconst lastKnown = async (\n\t\ttype: \"bundle\" | \"message\" | \"variant\",\n\t\tid: string\n\t) =>\n\t\tawait args.lix.db\n\t\t\t.selectFrom(\"change\")\n\t\t\t.selectAll()\n\t\t\t// heuristic that getting the last bundle value is fine\n\t\t\t// and using created_at is fine too. if the change is undesired\n\t\t\t// , a user can revert it with lix change control\n\t\t\t.orderBy(\"created_at desc\")\n\t\t\t.where(\"type\", \"=\", type)\n\t\t\t.where((eb) => eb.ref(\"value\", \"->>\").key(\"id\"), \"=\", id)\n\t\t\t.where(\"operation\", \"in\", [\"create\", \"update\"])\n\t\t\t// TODO shouldn't throw. The API needs to be able to\n\t\t\t// report issues back to the app without throwing and potentially failing\n\t\t\t// to apply 1000 changes because 1 change is invalid\n\t\t\t// same requirement as in inlang, see https://github.com/opral/inlang-sdk/issues/213\n\t\t\t.executeTakeFirstOrThrow();\n\n\tif (args.change.type === \"message\") {\n\t\tconst lastKnownBundle = await lastKnown(\n\t\t\t\"bundle\",\n\t\t\targs.change.value?.bundleId\n\t\t);\n\t\tawait args.db\n\t\t\t.insertInto(\"bundle\")\n\t\t\t.values(lastKnownBundle.value as any)\n\t\t\t.execute();\n\t} else if (args.change.type === \"variant\") {\n\t\tconst lastKnownMessage = await lastKnown(\n\t\t\t\"message\",\n\t\t\targs.change.value?.messageId\n\t\t);\n\t\t// getting the bundle too out of precaution\n\t\tconst lastKnownBundle = await lastKnown(\n\t\t\t\"bundle\",\n\t\t\tlastKnownMessage.value?.bundleId\n\t\t);\n\t\tawait args.db\n\t\t\t.insertInto(\"bundle\")\n\t\t\t.values(lastKnownBundle.value as any)\n\t\t\t// the bundle exists, so we can ignore the conflict\n\t\t\t.onConflict((c) => c.doNothing())\n\t\t\t.execute();\n\t\tawait args.db\n\t\t\t.insertInto(\"message\")\n\t\t\t.values(lastKnownMessage.value as any)\n\t\t\t.execute();\n\t\tawait args.db\n\t\t\t.insertInto(args.change.type as \"bundle\" | \"message\" | \"variant\")\n\t\t\t.values(args.change.value as any)\n\t\t\t.onConflict((c) => c.column(\"id\").doUpdateSet(args.change.value as any))\n\t\t\t.execute();\n\t}\n\t// re-execute applying the change\n\tawait args.db\n\t\t.insertInto(args.change.type as \"bundle\" | \"message\" | \"variant\")\n\t\t.values(args.change.value as any)\n\t\t.onConflict((c) => c.column(\"id\").doUpdateSet(args.change.value as any))\n\t\t.execute();\n}\n"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc;;;AAEd,OAAO,EACN,aAAa,GAIb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,MAAM,CAAC,MAAM,YAAY,GAA2C,KAAK,EAAE,EAC1E,GAAG,EACH,IAAI,EACJ,OAAO,GACP,EAAE,EAAE;IACJ,IAAI,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,KAAK,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACd,gEAAgE,CAChE,CAAC;IACH,CAAC;IAED,0BAA0B;IAE1B,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAE9B,8DAA8D;IAC9D,MAAM,WAAW,GAAG;QACnB,GAAG,IAAI,GAAG,CACT,MAAM,OAAO,CAAC,GAAG,CAChB,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC5B,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YACxD,+CAA+C;YAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACnC,CAAC,CAAC,CACF,CACD;KACD,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5B,qFA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CAAC,MAAM,CAAC,IAAwC,CAAC;SAChE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAY,CAAC;SAChC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,KAAY,CAAC,CAAC;SACvE,OAAO,EAAE,CAAC;AACb,CAAC","debug_id":"9b9ba9f2-e828-592b-9d34-ef9bdb8f67c0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyChanges.test.d.ts","sourceRoot":"/","sources":["lix-plugin/applyChanges.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="49e45424-5b74-554e-8523-570380dd1e01")}catch(e){}}();
|
|
5
|
+
import { test, expect } from "vitest";
|
|
6
|
+
import { loadProjectInMemory } from "../project/loadProjectInMemory.js";
|
|
7
|
+
import { newProject } from "../project/newProject.js";
|
|
8
|
+
import { applyChanges } from "./applyChanges.js";
|
|
9
|
+
import { loadDatabaseInMemory } from "sqlite-wasm-kysely";
|
|
10
|
+
import { initDb } from "../database/initDb.js";
|
|
11
|
+
test.skip("it should be able to delete", async () => {
|
|
12
|
+
const project = await loadProjectInMemory({
|
|
13
|
+
blob: await newProject(),
|
|
14
|
+
});
|
|
15
|
+
const changes = [
|
|
16
|
+
{
|
|
17
|
+
id: "1",
|
|
18
|
+
operation: "create",
|
|
19
|
+
file_id: "mock",
|
|
20
|
+
plugin_key: "mock",
|
|
21
|
+
type: "bundle",
|
|
22
|
+
meta: { id: "mock" },
|
|
23
|
+
value: {
|
|
24
|
+
id: "mock",
|
|
25
|
+
declarations: [],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "2",
|
|
30
|
+
parent_id: "1",
|
|
31
|
+
operation: "update",
|
|
32
|
+
file_id: "mock",
|
|
33
|
+
plugin_key: "mock",
|
|
34
|
+
type: "bundle",
|
|
35
|
+
meta: {
|
|
36
|
+
id: "mock",
|
|
37
|
+
},
|
|
38
|
+
value: {
|
|
39
|
+
id: "mock",
|
|
40
|
+
declarations: [],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "3",
|
|
45
|
+
parent_id: "2",
|
|
46
|
+
operation: "delete",
|
|
47
|
+
file_id: "mock",
|
|
48
|
+
plugin_key: "mock",
|
|
49
|
+
meta: {
|
|
50
|
+
id: "mock",
|
|
51
|
+
},
|
|
52
|
+
type: "bundle",
|
|
53
|
+
value: undefined,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
await project.db
|
|
57
|
+
.insertInto("bundle")
|
|
58
|
+
.values({
|
|
59
|
+
id: "mock",
|
|
60
|
+
})
|
|
61
|
+
.execute();
|
|
62
|
+
const dbFile = await project.lix.db
|
|
63
|
+
.selectFrom("file")
|
|
64
|
+
.selectAll()
|
|
65
|
+
.where("path", "=", "/db.sqlite")
|
|
66
|
+
.executeTakeFirstOrThrow();
|
|
67
|
+
const dbFileAfter = await applyChanges({
|
|
68
|
+
lix: project.lix,
|
|
69
|
+
file: dbFile,
|
|
70
|
+
changes: changes,
|
|
71
|
+
});
|
|
72
|
+
const db = initDb({
|
|
73
|
+
sqlite: await loadDatabaseInMemory(dbFileAfter.fileData),
|
|
74
|
+
});
|
|
75
|
+
const bundles = await db.selectFrom("bundle").selectAll().execute();
|
|
76
|
+
expect(bundles).toHaveLength(0);
|
|
77
|
+
});
|
|
78
|
+
test.skip("it should be able to upsert (insert & update)", async () => {
|
|
79
|
+
const project = await loadProjectInMemory({
|
|
80
|
+
blob: await newProject(),
|
|
81
|
+
});
|
|
82
|
+
const changes = [
|
|
83
|
+
{
|
|
84
|
+
id: "1",
|
|
85
|
+
parent_id: undefined,
|
|
86
|
+
operation: "create",
|
|
87
|
+
file_id: "mock",
|
|
88
|
+
plugin_key: "mock",
|
|
89
|
+
type: "bundle",
|
|
90
|
+
meta: { id: "mock" },
|
|
91
|
+
value: {
|
|
92
|
+
id: "mock",
|
|
93
|
+
declarations: [],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "2",
|
|
98
|
+
parent_id: "1",
|
|
99
|
+
operation: "update",
|
|
100
|
+
file_id: "mock",
|
|
101
|
+
plugin_key: "mock",
|
|
102
|
+
type: "bundle",
|
|
103
|
+
meta: {
|
|
104
|
+
id: "mock",
|
|
105
|
+
},
|
|
106
|
+
value: {
|
|
107
|
+
id: "mock",
|
|
108
|
+
declarations: [],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
await project.db
|
|
113
|
+
.insertInto("bundle")
|
|
114
|
+
.values({
|
|
115
|
+
id: "mock",
|
|
116
|
+
})
|
|
117
|
+
.execute();
|
|
118
|
+
const dbFile = await project.lix.db
|
|
119
|
+
.selectFrom("file")
|
|
120
|
+
.selectAll()
|
|
121
|
+
.where("path", "=", "/db.sqlite")
|
|
122
|
+
.executeTakeFirstOrThrow();
|
|
123
|
+
const dbFileAfter = await applyChanges({
|
|
124
|
+
lix: project.lix,
|
|
125
|
+
file: dbFile,
|
|
126
|
+
changes: changes,
|
|
127
|
+
});
|
|
128
|
+
const db = initDb({
|
|
129
|
+
sqlite: await loadDatabaseInMemory(dbFileAfter.fileData),
|
|
130
|
+
});
|
|
131
|
+
const bundles = await db.selectFrom("bundle").selectAll().execute();
|
|
132
|
+
expect(bundles).toHaveLength(1);
|
|
133
|
+
});
|
|
134
|
+
//# sourceMappingURL=applyChanges.test.js.map
|
|
135
|
+
//# debugId=49e45424-5b74-554e-8523-570380dd1e01
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyChanges.test.js","sources":["lix-plugin/applyChanges.test.ts"],"sourceRoot":"/","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\nimport { test, expect } from \"vitest\";\nimport { loadProjectInMemory } from \"../project/loadProjectInMemory.js\";\nimport { newProject } from \"../project/newProject.js\";\nimport type { Change, NewChange } from \"@lix-js/sdk\";\nimport { applyChanges } from \"./applyChanges.js\";\nimport { loadDatabaseInMemory } from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\nimport type { Bundle } from \"../database/schema.js\";\n\ntest.skip(\"it should be able to delete\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\n\tconst changes: NewChange[] = [\n\t\t{\n\t\t\tid: \"1\",\n\t\t\toperation: \"create\",\n\t\t\tfile_id: \"mock\",\n\t\t\tplugin_key: \"mock\",\n\t\t\ttype: \"bundle\",\n\t\t\tmeta: { id: \"mock\" },\n\t\t\tvalue: {\n\t\t\t\tid: \"mock\",\n\t\t\t\tdeclarations: [],\n\t\t\t} satisfies Bundle,\n\t\t},\n\t\t{\n\t\t\tid: \"2\",\n\t\t\tparent_id: \"1\",\n\t\t\toperation: \"update\",\n\t\t\tfile_id: \"mock\",\n\t\t\tplugin_key: \"mock\",\n\t\t\ttype: \"bundle\",\n\t\t\tmeta: {\n\t\t\t\tid: \"mock\",\n\t\t\t},\n\t\t\tvalue: {\n\t\t\t\tid: \"mock\",\n\t\t\t\tdeclarations: [],\n\t\t\t} satisfies Bundle,\n\t\t},\n\t\t{\n\t\t\tid: \"3\",\n\t\t\tparent_id: \"2\",\n\t\t\toperation: \"delete\",\n\t\t\tfile_id: \"mock\",\n\t\t\tplugin_key: \"mock\",\n\t\t\tmeta: {\n\t\t\t\tid: \"mock\",\n\t\t\t},\n\t\t\ttype: \"bundle\",\n\t\t\tvalue: undefined,\n\t\t},\n\t];\n\n\tawait project.db\n\t\t.insertInto(\"bundle\")\n\t\t.values({\n\t\t\tid: \"mock\",\n\t\t})\n\t\t.execute();\n\n\tconst dbFile = await project.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.selectAll()\n\t\t.where(\"path\", \"=\", \"/db.sqlite\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst dbFileAfter = await applyChanges({\n\t\tlix: project.lix,\n\t\tfile: dbFile,\n\t\tchanges: changes as Change[],\n\t});\n\n\tconst db = initDb({\n\t\tsqlite: await loadDatabaseInMemory(dbFileAfter.fileData),\n\t});\n\n\tconst bundles = await db.selectFrom(\"bundle\").selectAll().execute();\n\n\texpect(bundles).toHaveLength(0);\n});\n\ntest.skip(\"it should be able to upsert (insert & update)\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\n\tconst changes: NewChange[] = [\n\t\t{\n\t\t\tid: \"1\",\n\t\t\tparent_id: undefined,\n\t\t\toperation: \"create\",\n\t\t\tfile_id: \"mock\",\n\t\t\tplugin_key: \"mock\",\n\t\t\ttype: \"bundle\",\n\t\t\tmeta: { id: \"mock\" },\n\t\t\tvalue: {\n\t\t\t\tid: \"mock\",\n\t\t\t\tdeclarations: [],\n\t\t\t} satisfies Bundle,\n\t\t},\n\t\t{\n\t\t\tid: \"2\",\n\t\t\tparent_id: \"1\",\n\t\t\toperation: \"update\",\n\t\t\tfile_id: \"mock\",\n\t\t\tplugin_key: \"mock\",\n\t\t\ttype: \"bundle\",\n\t\t\tmeta: {\n\t\t\t\tid: \"mock\",\n\t\t\t},\n\t\t\tvalue: {\n\t\t\t\tid: \"mock\",\n\t\t\t\tdeclarations: [],\n\t\t\t} satisfies Bundle,\n\t\t},\n\t];\n\n\tawait project.db\n\t\t.insertInto(\"bundle\")\n\t\t.values({\n\t\t\tid: \"mock\",\n\t\t})\n\t\t.execute();\n\n\tconst dbFile = await project.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.selectAll()\n\t\t.where(\"path\", \"=\", \"/db.sqlite\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst dbFileAfter = await applyChanges({\n\t\tlix: project.lix,\n\t\tfile: dbFile,\n\t\tchanges: changes as Change[],\n\t});\n\n\tconst db = initDb({\n\t\tsqlite: await loadDatabaseInMemory(dbFileAfter.fileData),\n\t});\n\n\tconst bundles = await db.selectFrom(\"bundle\").selectAll().execute();\n\n\texpect(bundles).toHaveLength(1);\n});\n"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc;;;AAEd,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C,IAAI,CAAC,IAAI,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;IACnD,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC;QACzC,IAAI,EAAE,MAAM,UAAU,EAAE;KACxB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAgB;QAC5B;YACC,EAAE,EAAE,GAAG;YACP,SAAS,EAAE,QAAQ;YACnB,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;YACpB,KAAK,EAAE;gBACN,EAAE,EAAE,MAAM;gBACV,YAAY,EAAE,EAAE;aACC;SAClB;QACD;YACC,EAAE,EAAE,GAAG;YACP,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,QAAQ;YACnB,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,QAAQ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AAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC;IAEpE,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC","debug_id":"49e45424-5b74-554e-8523-570380dd1e01"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectConflicts.d.ts","sourceRoot":"/","sources":["lix-plugin/detectConflicts.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,eAAe,EAAE,SAAS,CAAC,iBAAiB,CAmDxD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0ac92cf1-42cb-51b1-a701-6f18a71b3811")}catch(e){}}();
|
|
5
|
+
import { getLowestCommonAncestor, getLeafChange, } from "@lix-js/sdk";
|
|
6
|
+
export const detectConflicts = async ({ sourceLix, targetLix, leafChangesOnlyInSource, }) => {
|
|
7
|
+
const result = [];
|
|
8
|
+
for (const change of leafChangesOnlyInSource) {
|
|
9
|
+
const lowestCommonAncestor = await getLowestCommonAncestor({
|
|
10
|
+
sourceChange: change,
|
|
11
|
+
sourceLix,
|
|
12
|
+
targetLix,
|
|
13
|
+
});
|
|
14
|
+
if (lowestCommonAncestor === undefined) {
|
|
15
|
+
// no common parent, no conflict. must be an insert
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const leafChangeInTarget = await getLeafChange({
|
|
19
|
+
change: lowestCommonAncestor,
|
|
20
|
+
lix: targetLix,
|
|
21
|
+
});
|
|
22
|
+
if (lowestCommonAncestor.id === leafChangeInTarget.id) {
|
|
23
|
+
// no conflict. the lowest common ancestor is
|
|
24
|
+
// the leaf change in the target. aka, no changes
|
|
25
|
+
// in target have been made that could conflict with the source
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const hasDiff = JSON.stringify(change.value) !== JSON.stringify(leafChangeInTarget.value);
|
|
29
|
+
if (hasDiff === false) {
|
|
30
|
+
// TODO we have two different changes that yielded the same snapshot,
|
|
31
|
+
// lix or the plugin need to change the parents of the target change
|
|
32
|
+
// to both the source and the target change. users likely want to
|
|
33
|
+
// see that two "branches" led to the same snapshot
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// naive raise any snapshot difference as a conflict for now
|
|
37
|
+
// more sophisticated conflict reporting can be incrementally added
|
|
38
|
+
result.push({
|
|
39
|
+
change_id: leafChangeInTarget.id,
|
|
40
|
+
conflicting_change_id: change.id,
|
|
41
|
+
reason: "The snapshots of the change do not match. More sophisticated reasoning will be added later.",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=detectConflicts.js.map
|
|
47
|
+
//# debugId=0ac92cf1-42cb-51b1-a701-6f18a71b3811
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectConflicts.js","sources":["lix-plugin/detectConflicts.ts"],"sourceRoot":"/","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\nimport {\n\tgetLowestCommonAncestor,\n\tgetLeafChange,\n\ttype LixPlugin,\n\ttype NewConflict,\n} from \"@lix-js/sdk\";\n\nexport const detectConflicts: LixPlugin[\"detectConflicts\"] = async ({\n\tsourceLix,\n\ttargetLix,\n\tleafChangesOnlyInSource,\n}) => {\n\tconst result: NewConflict[] = [];\n\tfor (const change of leafChangesOnlyInSource) {\n\t\tconst lowestCommonAncestor = await getLowestCommonAncestor({\n\t\t\tsourceChange: change,\n\t\t\tsourceLix,\n\t\t\ttargetLix,\n\t\t});\n\n\t\tif (lowestCommonAncestor === undefined) {\n\t\t\t// no common parent, no conflict. must be an insert\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst leafChangeInTarget = await getLeafChange({\n\t\t\tchange: lowestCommonAncestor,\n\t\t\tlix: targetLix,\n\t\t});\n\n\t\tif (lowestCommonAncestor.id === leafChangeInTarget.id) {\n\t\t\t// no conflict. the lowest common ancestor is\n\t\t\t// the leaf change in the target. aka, no changes\n\t\t\t// in target have been made that could conflict with the source\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst hasDiff =\n\t\t\tJSON.stringify(change.value) !== JSON.stringify(leafChangeInTarget.value);\n\n\t\tif (hasDiff === false) {\n\t\t\t// TODO we have two different changes that yielded the same snapshot,\n\t\t\t// lix or the plugin need to change the parents of the target change\n\t\t\t// to both the source and the target change. users likely want to\n\t\t\t// see that two \"branches\" led to the same snapshot\n\t\t\tcontinue;\n\t\t}\n\n\t\t// naive raise any snapshot difference as a conflict for now\n\t\t// more sophisticated conflict reporting can be incrementally added\n\t\tresult.push({\n\t\t\tchange_id: leafChangeInTarget.id,\n\t\t\tconflicting_change_id: change.id,\n\t\t\treason:\n\t\t\t\t\"The snapshots of the change do not match. More sophisticated reasoning will be added later.\",\n\t\t});\n\t}\n\treturn result;\n};\n"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc;;;AAEd,OAAO,EACN,uBAAuB,EACvB,aAAa,GAGb,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,eAAe,GAAiC,KAAK,EAAE,EACnE,SAAS,EACT,SAAS,EACT,uBAAuB,GACvB,EAAE,EAAE;IACJ,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,KAAK,MAAM,MAAM,IAAI,uBAAuB,EAAE,CAAC;QAC9C,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CAAC;YAC1D,YAAY,EAAE,MAAM;YACpB,SAAS;YACT,SAAS;SACT,CAAC,CAAC;QAEH,IAAI,oBAAoB,KAAK,SAAS,EAAE,CAAC;YACxC,mDAAmD;YACnD,SAAS;QACV,CAAC;QAED,MAAM,kBAAkB,GAAG,MAAM,aAAa,CAAC;YAC9C,MAAM,EAAE,oBAAoB;YAC5B,GAAG,EAAE,SAAS;SACd,CAAC,CAAC;QAEH,IAAI,oBAAoB,CAAC,EAAE,KAAK,kBAAkB,CAAC,EAAE,EAAE,CAAC;YACvD,6CAA6C;YAC7C,iDAAiD;YACjD,+DAA+D;YAC/D,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GACZ,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE3E,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YACvB,qEAAqE;YACrE,oEAAoE;YACpE,iEAAiE;YACjE,mDAAmD;YACnD,SAAS;QACV,CAAC;QAED,4DAA4D;QAC5D,mEAAmE;QACnE,MAAM,CAAC,IAAI,CAAC;YACX,SAAS,EAAE,kBAAkB,CAAC,EAAE;YAChC,qBAAqB,EAAE,MAAM,CAAC,EAAE;YAChC,MAAM,EACL,6FAA6F;SAC9F,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC,CAAC","debug_id":"0ac92cf1-42cb-51b1-a701-6f18a71b3811"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectConflicts.test.d.ts","sourceRoot":"/","sources":["lix-plugin/detectConflicts.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f9a7650e-ee5a-5709-96eb-9c505f2c06fa")}catch(e){}}();
|
|
5
|
+
import { test, expect } from "vitest";
|
|
6
|
+
import { inlangLixPluginV1 } from "./inlangLixPluginV1.js";
|
|
7
|
+
import { newLixFile, openLixInMemory, } from "@lix-js/sdk";
|
|
8
|
+
test.skip("a create operation should not report a conflict given that the change does not exist in target", async () => {
|
|
9
|
+
const targetLix = await openLixInMemory({ blob: await newLixFile() });
|
|
10
|
+
const sourceLix = await openLixInMemory({ blob: await newLixFile() });
|
|
11
|
+
const changes = await sourceLix.db
|
|
12
|
+
.insertInto("change")
|
|
13
|
+
.values([
|
|
14
|
+
{
|
|
15
|
+
id: "1",
|
|
16
|
+
parent_id: undefined,
|
|
17
|
+
operation: "create",
|
|
18
|
+
file_id: "mock",
|
|
19
|
+
plugin_key: "mock",
|
|
20
|
+
type: "mock",
|
|
21
|
+
value: { id: "change 1" },
|
|
22
|
+
},
|
|
23
|
+
])
|
|
24
|
+
.returningAll()
|
|
25
|
+
.execute();
|
|
26
|
+
const conflicts = await inlangLixPluginV1.detectConflicts({
|
|
27
|
+
sourceLix,
|
|
28
|
+
targetLix,
|
|
29
|
+
leafChangesOnlyInSource: changes,
|
|
30
|
+
});
|
|
31
|
+
expect(conflicts).toHaveLength(0);
|
|
32
|
+
});
|
|
33
|
+
test.todo("it should report deletions as a conflict if the parent of the target and source are not identical", async () => {
|
|
34
|
+
const targetLix = await openLixInMemory({ blob: await newLixFile() });
|
|
35
|
+
await targetLix.db
|
|
36
|
+
.insertInto("change")
|
|
37
|
+
.values([
|
|
38
|
+
{
|
|
39
|
+
id: "1",
|
|
40
|
+
parent_id: undefined,
|
|
41
|
+
operation: "create",
|
|
42
|
+
file_id: "mock",
|
|
43
|
+
plugin_key: "mock",
|
|
44
|
+
type: "mock",
|
|
45
|
+
value: {
|
|
46
|
+
id: "change 1",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
])
|
|
50
|
+
.execute();
|
|
51
|
+
const sourceLix = await openLixInMemory({ blob: await targetLix.toBlob() });
|
|
52
|
+
const changesNotInTarget = [
|
|
53
|
+
{
|
|
54
|
+
id: "2",
|
|
55
|
+
parent_id: "1",
|
|
56
|
+
operation: "delete",
|
|
57
|
+
file_id: "mock",
|
|
58
|
+
plugin_key: "mock",
|
|
59
|
+
type: "mock",
|
|
60
|
+
value: undefined,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
await sourceLix.db
|
|
64
|
+
.insertInto("change")
|
|
65
|
+
.values(changesNotInTarget)
|
|
66
|
+
.execute();
|
|
67
|
+
const conflicts = await inlangLixPluginV1.detectConflicts({
|
|
68
|
+
sourceLix,
|
|
69
|
+
targetLix,
|
|
70
|
+
leafChangesOnlyInSource: changesNotInTarget,
|
|
71
|
+
});
|
|
72
|
+
expect(conflicts).toHaveLength(1);
|
|
73
|
+
expect(conflicts[0]?.change_id).toBe("1");
|
|
74
|
+
expect(conflicts[0]?.conflicting_change_id).toBe("2");
|
|
75
|
+
throw new Error("The parent is identicak, fix this test");
|
|
76
|
+
});
|
|
77
|
+
test.skip("it should report an UPDATE as a conflict if leaf changes are conflicting", async () => {
|
|
78
|
+
const targetLix = await openLixInMemory({ blob: await newLixFile() });
|
|
79
|
+
const sourceLix = await openLixInMemory({ blob: await targetLix.toBlob() });
|
|
80
|
+
const commonChanges = [
|
|
81
|
+
{
|
|
82
|
+
id: "12s",
|
|
83
|
+
parent_id: undefined,
|
|
84
|
+
operation: "create",
|
|
85
|
+
file_id: "mock",
|
|
86
|
+
plugin_key: "mock",
|
|
87
|
+
type: "mock",
|
|
88
|
+
value: {
|
|
89
|
+
id: "change 12s",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
const changesOnlyInTarget = [
|
|
94
|
+
{
|
|
95
|
+
id: "3sd",
|
|
96
|
+
parent_id: "12s",
|
|
97
|
+
operation: "update",
|
|
98
|
+
file_id: "mock",
|
|
99
|
+
plugin_key: "mock",
|
|
100
|
+
type: "mock",
|
|
101
|
+
value: {
|
|
102
|
+
id: "change 3sd",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
const changesOnlyInSource = [
|
|
107
|
+
{
|
|
108
|
+
id: "2qa",
|
|
109
|
+
parent_id: "12s",
|
|
110
|
+
operation: "update",
|
|
111
|
+
file_id: "mock",
|
|
112
|
+
plugin_key: "mock",
|
|
113
|
+
type: "mock",
|
|
114
|
+
value: {
|
|
115
|
+
id: "change 2qa",
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
await sourceLix.db
|
|
120
|
+
.insertInto("change")
|
|
121
|
+
.values([...commonChanges, ...changesOnlyInSource])
|
|
122
|
+
.execute();
|
|
123
|
+
await targetLix.db
|
|
124
|
+
.insertInto("change")
|
|
125
|
+
.values([...commonChanges, ...changesOnlyInTarget])
|
|
126
|
+
.execute();
|
|
127
|
+
const conflicts = await inlangLixPluginV1.detectConflicts({
|
|
128
|
+
leafChangesOnlyInSource: changesOnlyInSource,
|
|
129
|
+
sourceLix: sourceLix,
|
|
130
|
+
targetLix: targetLix,
|
|
131
|
+
});
|
|
132
|
+
expect(conflicts).toHaveLength(1);
|
|
133
|
+
});
|
|
134
|
+
/**
|
|
135
|
+
* If the common ancestor is the leaf change of the target, then the
|
|
136
|
+
* source change are (likely) not a conflict because no update has
|
|
137
|
+
* been made to the target change that could conflict with updates
|
|
138
|
+
* in the source.
|
|
139
|
+
*/
|
|
140
|
+
test.skip("it should NOT report an UPDATE as a conflict if the common ancestor is the leaf change of the target", async () => {
|
|
141
|
+
const targetLix = await openLixInMemory({ blob: await newLixFile() });
|
|
142
|
+
const sourceLix = await openLixInMemory({ blob: await targetLix.toBlob() });
|
|
143
|
+
const commonChanges = [
|
|
144
|
+
{
|
|
145
|
+
id: "12s",
|
|
146
|
+
parent_id: undefined,
|
|
147
|
+
operation: "create",
|
|
148
|
+
file_id: "mock",
|
|
149
|
+
plugin_key: "mock",
|
|
150
|
+
type: "mock",
|
|
151
|
+
value: {
|
|
152
|
+
id: "change 12s",
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
const changesOnlyInTarget = [
|
|
157
|
+
{
|
|
158
|
+
id: "3sd",
|
|
159
|
+
parent_id: "12s",
|
|
160
|
+
operation: "update",
|
|
161
|
+
file_id: "mock",
|
|
162
|
+
plugin_key: "mock",
|
|
163
|
+
type: "mock",
|
|
164
|
+
value: {
|
|
165
|
+
id: "change 3sd",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "23a",
|
|
170
|
+
parent_id: "3sd",
|
|
171
|
+
operation: "update",
|
|
172
|
+
file_id: "mock",
|
|
173
|
+
plugin_key: "mock",
|
|
174
|
+
type: "mock",
|
|
175
|
+
value: {
|
|
176
|
+
id: "change 23a",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
const changesOnlyInSource = [];
|
|
181
|
+
await sourceLix.db
|
|
182
|
+
.insertInto("change")
|
|
183
|
+
.values([...commonChanges, ...changesOnlyInSource])
|
|
184
|
+
.execute();
|
|
185
|
+
await targetLix.db
|
|
186
|
+
.insertInto("change")
|
|
187
|
+
.values([...commonChanges, ...changesOnlyInTarget])
|
|
188
|
+
.execute();
|
|
189
|
+
const conflicts = await inlangLixPluginV1.detectConflicts({
|
|
190
|
+
leafChangesOnlyInSource: changesOnlyInSource,
|
|
191
|
+
sourceLix: sourceLix,
|
|
192
|
+
targetLix: targetLix,
|
|
193
|
+
});
|
|
194
|
+
expect(conflicts).toHaveLength(0);
|
|
195
|
+
});
|
|
196
|
+
test.skip("it should NOT report a DELETE as a conflict if the parent of the target and source are identical", async () => {
|
|
197
|
+
const targetLix = await openLixInMemory({ blob: await newLixFile() });
|
|
198
|
+
await targetLix.db
|
|
199
|
+
.insertInto("change")
|
|
200
|
+
.values([
|
|
201
|
+
{
|
|
202
|
+
id: "12s",
|
|
203
|
+
parent_id: undefined,
|
|
204
|
+
operation: "create",
|
|
205
|
+
file_id: "mock",
|
|
206
|
+
plugin_key: "mock",
|
|
207
|
+
type: "mock",
|
|
208
|
+
value: {
|
|
209
|
+
id: "change 12s",
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
])
|
|
213
|
+
.execute();
|
|
214
|
+
const sourceLix = await openLixInMemory({ blob: await targetLix.toBlob() });
|
|
215
|
+
const changesNotInTarget = [
|
|
216
|
+
{
|
|
217
|
+
id: "3sd",
|
|
218
|
+
parent_id: "12s",
|
|
219
|
+
operation: "delete",
|
|
220
|
+
file_id: "mock",
|
|
221
|
+
plugin_key: "mock",
|
|
222
|
+
type: "mock",
|
|
223
|
+
value: undefined,
|
|
224
|
+
},
|
|
225
|
+
];
|
|
226
|
+
const changesNotInSource = [
|
|
227
|
+
{
|
|
228
|
+
id: "2qa",
|
|
229
|
+
parent_id: "12s",
|
|
230
|
+
operation: "update",
|
|
231
|
+
file_id: "mock",
|
|
232
|
+
plugin_key: "mock",
|
|
233
|
+
type: "mock",
|
|
234
|
+
value: {
|
|
235
|
+
id: "2qa",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
];
|
|
239
|
+
await sourceLix.db.insertInto("change").values(changesNotInTarget).execute();
|
|
240
|
+
await targetLix.db.insertInto("change").values(changesNotInSource).execute();
|
|
241
|
+
const conflicts = await inlangLixPluginV1.detectConflicts({
|
|
242
|
+
sourceLix,
|
|
243
|
+
targetLix,
|
|
244
|
+
leafChangesOnlyInSource: changesNotInTarget,
|
|
245
|
+
});
|
|
246
|
+
expect(conflicts).toHaveLength(1);
|
|
247
|
+
expect(conflicts[0]?.change_id).toBe("2qa");
|
|
248
|
+
expect(conflicts[0]?.conflicting_change_id).toBe("3sd");
|
|
249
|
+
});
|
|
250
|
+
//# sourceMappingURL=detectConflicts.test.js.map
|
|
251
|
+
//# debugId=f9a7650e-ee5a-5709-96eb-9c505f2c06fa
|