@inlang/sdk 0.36.4 → 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
package/src/messages/variant.ts
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import type { LanguageTag, Message, Variant } from "../versionedInterfaces.js"
|
|
2
|
-
import type { Result } from "@inlang/result"
|
|
3
|
-
import {
|
|
4
|
-
MessagePatternsForLanguageTagDoNotExistError,
|
|
5
|
-
MessageVariantAlreadyExistsError,
|
|
6
|
-
MessageVariantDoesNotExistError,
|
|
7
|
-
} from "./errors.js"
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Tries to match the most specific variant of a message.
|
|
11
|
-
*
|
|
12
|
-
* The selectors determine the specificity of a variant. If no selectors are provided,
|
|
13
|
-
* or if the selectors do not match any variant, the catch all variant is returned
|
|
14
|
-
* (if it exists).
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const variant = getVariant(message, { where: { languageTag: "en", match: ["male"]}});
|
|
18
|
-
*/
|
|
19
|
-
export function getVariant(
|
|
20
|
-
message: Message,
|
|
21
|
-
args: {
|
|
22
|
-
where: {
|
|
23
|
-
languageTag: LanguageTag
|
|
24
|
-
match?: Variant["match"]
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
): Variant | undefined {
|
|
28
|
-
const variant = matchMostSpecificVariant(message, args.where.languageTag, args.where.match)
|
|
29
|
-
if (variant) {
|
|
30
|
-
//! do not return a reference to the message in a resource
|
|
31
|
-
//! modifications to the returned message will leak into the
|
|
32
|
-
//! resource which is considered to be immutable.
|
|
33
|
-
return structuredClone(variant)
|
|
34
|
-
}
|
|
35
|
-
return undefined
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Create a variant for a message
|
|
40
|
-
*
|
|
41
|
-
* All actions are immutable.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* const message = createVariant(message, { languageTag: "en", data: variant })
|
|
45
|
-
*/
|
|
46
|
-
export function createVariant(
|
|
47
|
-
message: Message,
|
|
48
|
-
args: {
|
|
49
|
-
data: Variant
|
|
50
|
-
}
|
|
51
|
-
): Result<Message, MessageVariantAlreadyExistsError> {
|
|
52
|
-
const copy = structuredClone(message)
|
|
53
|
-
|
|
54
|
-
// check if variant already exists
|
|
55
|
-
if (matchVariant(copy, args.data.languageTag, args.data.match)) {
|
|
56
|
-
return { error: new MessageVariantAlreadyExistsError(message.id, args.data.languageTag) }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
copy.variants.push({
|
|
60
|
-
...args.data,
|
|
61
|
-
match: args.data.match,
|
|
62
|
-
})
|
|
63
|
-
return { data: copy }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Update a variant of a message
|
|
68
|
-
*
|
|
69
|
-
* All actions are immutable.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* const message = updateVariant(message, { languageTag: "en", match: ["male"], pattern: []})
|
|
73
|
-
*/
|
|
74
|
-
export function updateVariantPattern(
|
|
75
|
-
message: Message,
|
|
76
|
-
args: {
|
|
77
|
-
where: {
|
|
78
|
-
languageTag: LanguageTag
|
|
79
|
-
match: Variant["match"]
|
|
80
|
-
}
|
|
81
|
-
data: Variant["pattern"]
|
|
82
|
-
}
|
|
83
|
-
): Result<Message, MessageVariantDoesNotExistError | MessagePatternsForLanguageTagDoNotExistError> {
|
|
84
|
-
const copy = structuredClone(message)
|
|
85
|
-
|
|
86
|
-
const containsLanguageTag = message.variants.some(
|
|
87
|
-
(variant) => variant.languageTag === args.where.languageTag
|
|
88
|
-
)
|
|
89
|
-
if (!containsLanguageTag) {
|
|
90
|
-
return {
|
|
91
|
-
error: new MessagePatternsForLanguageTagDoNotExistError(message.id, args.where.languageTag),
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const variant = matchVariant(copy, args.where.languageTag, args.where.match)
|
|
96
|
-
if (variant === undefined) {
|
|
97
|
-
return { error: new MessageVariantDoesNotExistError(message.id, args.where.languageTag) }
|
|
98
|
-
}
|
|
99
|
-
if (variant) {
|
|
100
|
-
variant.pattern = args.data
|
|
101
|
-
return { data: copy }
|
|
102
|
-
}
|
|
103
|
-
return { error: new MessageVariantDoesNotExistError(message.id, args.where.languageTag) }
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Returns the specific variant defined by selectors or undefined
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* const variant = matchVariant(message, languageTag: "en", match: ["male"])
|
|
111
|
-
*/
|
|
112
|
-
const matchVariant = (
|
|
113
|
-
message: Message,
|
|
114
|
-
languageTag: LanguageTag,
|
|
115
|
-
match: Variant["match"]
|
|
116
|
-
): Variant | undefined => {
|
|
117
|
-
const languageVariants = message.variants.filter((variant) => variant.languageTag === languageTag)
|
|
118
|
-
if (languageVariants.length === 0) return undefined
|
|
119
|
-
|
|
120
|
-
for (const variant of languageVariants) {
|
|
121
|
-
let isMatch = true
|
|
122
|
-
//check if vaiant is a match
|
|
123
|
-
if (variant.match.length > 0) {
|
|
124
|
-
variant.match.map((value, index) => {
|
|
125
|
-
if (match && match[index] !== value) {
|
|
126
|
-
isMatch = false
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!message.selectors || !match || match.length !== message.selectors.length) {
|
|
132
|
-
isMatch = false
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (isMatch) {
|
|
136
|
-
return variant
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return undefined
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Returns the most specific variant of a message.
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* const variant = matchMostSpecificVariant(message, languageTag: "en", selectors: { gender: "male" })
|
|
147
|
-
*/
|
|
148
|
-
const matchMostSpecificVariant = (
|
|
149
|
-
message: Message,
|
|
150
|
-
languageTag: LanguageTag,
|
|
151
|
-
match?: Variant["match"]
|
|
152
|
-
): Variant | undefined => {
|
|
153
|
-
// resolve preferenceSelectors to match length and order of message selectors
|
|
154
|
-
const index: Record<string, any> = {}
|
|
155
|
-
|
|
156
|
-
for (const variant of message.variants) {
|
|
157
|
-
if (variant.languageTag !== languageTag) continue
|
|
158
|
-
|
|
159
|
-
let isMatch = true
|
|
160
|
-
|
|
161
|
-
// if slector and stored match are not the same throw error
|
|
162
|
-
if (variant.match.length !== message.selectors.length) {
|
|
163
|
-
return undefined
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
//check if variant is a match
|
|
167
|
-
if (variant.match.length > 0) {
|
|
168
|
-
variant.match.map((value, index) => {
|
|
169
|
-
if (match && match[index] !== value && value !== "*") {
|
|
170
|
-
isMatch = false
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
if (isMatch && match && match.length > 0) {
|
|
175
|
-
// eslint-disable-next-line no-inner-declarations
|
|
176
|
-
function recursiveAddToIndex(
|
|
177
|
-
currentIndex: Record<string, any>,
|
|
178
|
-
selectorIndex: number,
|
|
179
|
-
selectorLength: number,
|
|
180
|
-
variant: Variant
|
|
181
|
-
) {
|
|
182
|
-
const key = variant.match[selectorIndex]
|
|
183
|
-
if (key) {
|
|
184
|
-
if (selectorIndex === 1) {
|
|
185
|
-
currentIndex[key] = variant
|
|
186
|
-
} else {
|
|
187
|
-
if (!currentIndex[key]) {
|
|
188
|
-
currentIndex[key] = {}
|
|
189
|
-
}
|
|
190
|
-
recursiveAddToIndex(currentIndex[key], selectorIndex + 1, selectorLength, variant)
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
recursiveAddToIndex(index, 0, message.selectors ? message.selectors.length - 1 : 0, variant)
|
|
195
|
-
} else if (isMatch && !match) {
|
|
196
|
-
return variant
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// if number of selectors and numver of required match is not the same match catch all
|
|
201
|
-
if (!message.selectors || !match || match.length !== message.selectors.length) {
|
|
202
|
-
const catchAllMatcher: Array<string> = []
|
|
203
|
-
const selectorCount = message.selectors.length
|
|
204
|
-
catchAllMatcher.push("*")
|
|
205
|
-
for (let i = 0; i < selectorCount - 1; i++) {
|
|
206
|
-
catchAllMatcher.push("*")
|
|
207
|
-
}
|
|
208
|
-
return message.variants.find(
|
|
209
|
-
(v) =>
|
|
210
|
-
v.languageTag === languageTag && JSON.stringify(v.match) === JSON.stringify(catchAllMatcher)
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// if selector is empty match empty variant match
|
|
215
|
-
if (message.selectors && message.selectors.length === 0) {
|
|
216
|
-
return message.variants.find(
|
|
217
|
-
(v) => v.languageTag === languageTag && JSON.stringify(v.match) === "[]"
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
//find the most specific variant
|
|
222
|
-
const findOptimalMatch = (
|
|
223
|
-
index: Record<string, any>,
|
|
224
|
-
selectors: string[]
|
|
225
|
-
): Variant | undefined => {
|
|
226
|
-
const keys = Object.keys(index)
|
|
227
|
-
|
|
228
|
-
for (const key of keys) {
|
|
229
|
-
if (key === selectors[0] || key === "*") {
|
|
230
|
-
const nextOptimal = selectors.slice(1)
|
|
231
|
-
|
|
232
|
-
if (nextOptimal.length === 0) {
|
|
233
|
-
return (index[key] as Variant) || undefined
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const match = findOptimalMatch(index[key] as Record<string, any>, nextOptimal)
|
|
237
|
-
|
|
238
|
-
if (match !== undefined) {
|
|
239
|
-
return match
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return undefined
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return findOptimalMatch(index, match || [])
|
|
247
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { Repository } from "@lix-js/client"
|
|
2
|
-
import type { NodeishFilesystem } from "@lix-js/fs"
|
|
3
|
-
|
|
4
|
-
const EXPECTED_IGNORES = ["cache"]
|
|
5
|
-
|
|
6
|
-
export async function maybeAddModuleCache(args: {
|
|
7
|
-
projectPath: string
|
|
8
|
-
repo?: Repository
|
|
9
|
-
}): Promise<void> {
|
|
10
|
-
if (args.repo === undefined) return
|
|
11
|
-
|
|
12
|
-
const projectExists = await directoryExists(args.projectPath, args.repo.nodeishFs)
|
|
13
|
-
if (!projectExists) return
|
|
14
|
-
|
|
15
|
-
const gitignorePath = args.projectPath + "/.gitignore"
|
|
16
|
-
const moduleCache = args.projectPath + "/cache/modules/"
|
|
17
|
-
|
|
18
|
-
const gitignoreExists = await fileExists(gitignorePath, args.repo.nodeishFs)
|
|
19
|
-
const moduleCacheExists = await directoryExists(moduleCache, args.repo.nodeishFs)
|
|
20
|
-
|
|
21
|
-
if (gitignoreExists) {
|
|
22
|
-
// non-destructively add any missing ignores
|
|
23
|
-
try {
|
|
24
|
-
const gitignore = await args.repo.nodeishFs.readFile(gitignorePath, { encoding: "utf-8" })
|
|
25
|
-
const missingIgnores = EXPECTED_IGNORES.filter((ignore) => !gitignore.includes(ignore))
|
|
26
|
-
if (missingIgnores.length > 0) {
|
|
27
|
-
await args.repo.nodeishFs.appendFile(gitignorePath, "\n" + missingIgnores.join("\n"))
|
|
28
|
-
}
|
|
29
|
-
} catch (error) {
|
|
30
|
-
throw new Error("[migrate:module-cache] Failed to update .gitignore", { cause: error })
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
try {
|
|
34
|
-
await args.repo.nodeishFs.writeFile(gitignorePath, EXPECTED_IGNORES.join("\n"))
|
|
35
|
-
} catch (e) {
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
if (e.code && e.code !== "EISDIR" && e.code !== "EEXIST") {
|
|
38
|
-
throw new Error("[migrate:module-cache] Failed to create .gitignore", { cause: e })
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!moduleCacheExists) {
|
|
44
|
-
try {
|
|
45
|
-
await args.repo.nodeishFs.mkdir(moduleCache, { recursive: true })
|
|
46
|
-
} catch (e) {
|
|
47
|
-
throw new Error("[migrate:module-cache] Failed to create cache directory", { cause: e })
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function fileExists(path: string, nodeishFs: NodeishFilesystem): Promise<boolean> {
|
|
53
|
-
try {
|
|
54
|
-
const stat = await nodeishFs.stat(path)
|
|
55
|
-
return stat.isFile()
|
|
56
|
-
} catch {
|
|
57
|
-
return false
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function directoryExists(path: string, nodeishFs: NodeishFilesystem): Promise<boolean> {
|
|
62
|
-
try {
|
|
63
|
-
const stat = await nodeishFs.stat(path)
|
|
64
|
-
return stat.isDirectory()
|
|
65
|
-
} catch {
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { generateProjectId } from "./maybeCreateFirstProjectId.js"
|
|
2
|
-
import { it, expect } from "vitest"
|
|
3
|
-
import { mockRepo } from "@lix-js/client"
|
|
4
|
-
import { type Snapshot } from "@lix-js/fs"
|
|
5
|
-
// eslint-disable-next-line no-restricted-imports -- test
|
|
6
|
-
import { readFileSync } from "node:fs"
|
|
7
|
-
|
|
8
|
-
const ciTestRepo: Snapshot = JSON.parse(
|
|
9
|
-
readFileSync("./mocks/ci-test-repo-no-shallow.json", { encoding: "utf-8" })
|
|
10
|
-
)
|
|
11
|
-
const repo = await mockRepo({ fromSnapshot: ciTestRepo as Snapshot })
|
|
12
|
-
|
|
13
|
-
it("should return if repo is undefined", async () => {
|
|
14
|
-
const projectId = await generateProjectId({ repo: undefined, projectPath: "mocked_project_path" })
|
|
15
|
-
expect(projectId).toBeUndefined()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it("should generate a project id", async () => {
|
|
19
|
-
const projectId = await generateProjectId({ repo, projectPath: "mocked_project_path" })
|
|
20
|
-
expect(projectId).toBe("432d7ef29c510e99d95e2d14ef57a0797a1603859b5a851b7dff7e77161b8c08")
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it("should return undefined if repoMeta contains error", async () => {
|
|
24
|
-
await repo.nodeishFs.rm("/.git", { recursive: true })
|
|
25
|
-
|
|
26
|
-
const projectId = await generateProjectId({
|
|
27
|
-
repo: repo,
|
|
28
|
-
projectPath: "mocked_project_path",
|
|
29
|
-
})
|
|
30
|
-
expect(projectId).toBeUndefined()
|
|
31
|
-
})
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { Repository } from "@lix-js/client"
|
|
2
|
-
import { hash } from "@lix-js/client"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a project id if it does not exist yet.
|
|
6
|
-
*
|
|
7
|
-
* - this is a migration to ensure that all projects have a project id
|
|
8
|
-
* - new projects are created with a project id (in the future)
|
|
9
|
-
*/
|
|
10
|
-
export async function maybeCreateFirstProjectId(args: {
|
|
11
|
-
projectPath: string
|
|
12
|
-
repo?: Repository
|
|
13
|
-
}): Promise<void> {
|
|
14
|
-
// the migration assumes a repository
|
|
15
|
-
if (args.repo === undefined) {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
await args.repo.nodeishFs.readFile(args.projectPath + "/project_id", {
|
|
20
|
-
encoding: "utf-8",
|
|
21
|
-
})
|
|
22
|
-
} catch (error) {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
if (error.code === "ENOENT" && args.repo) {
|
|
25
|
-
const projectId = await generateProjectId({ repo: args.repo, projectPath: args.projectPath })
|
|
26
|
-
if (projectId) {
|
|
27
|
-
await args.repo.nodeishFs
|
|
28
|
-
.writeFile(args.projectPath + "/project_id", projectId)
|
|
29
|
-
.catch((error) => {
|
|
30
|
-
console.error("Failed to write project_id", error)
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function generateProjectId(args: { repo?: Repository; projectPath: string }) {
|
|
38
|
-
if (!args.repo || !args.projectPath) {
|
|
39
|
-
return undefined
|
|
40
|
-
}
|
|
41
|
-
const firstCommitHash = await args.repo.getFirstCommitHash()
|
|
42
|
-
|
|
43
|
-
if (firstCommitHash) {
|
|
44
|
-
try {
|
|
45
|
-
return await hash(`${firstCommitHash + args.projectPath}`)
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error("Failed to generate project_id", error)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return undefined
|
|
51
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { test, expect, vi } from "vitest"
|
|
2
|
-
import { maybeMigrateToDirectory } from "./migrateToDirectory.js"
|
|
3
|
-
import { createNodeishMemoryFs } from "@lix-js/fs"
|
|
4
|
-
import type { ProjectSettings } from "@inlang/project-settings"
|
|
5
|
-
|
|
6
|
-
test("it should return if the settings file has an error (let loadProject handle it)", async () => {
|
|
7
|
-
const projectPath = "./project.inlang"
|
|
8
|
-
const mockFs = {
|
|
9
|
-
stat: vi.fn(() => {}),
|
|
10
|
-
readFile: vi.fn(() => {
|
|
11
|
-
throw Error()
|
|
12
|
-
}),
|
|
13
|
-
}
|
|
14
|
-
await maybeMigrateToDirectory({ nodeishFs: mockFs as any, projectPath })
|
|
15
|
-
// something goes wrong in readFile
|
|
16
|
-
expect(mockFs.readFile).toHaveBeenCalled()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test("it should create the project directory if it does not exist and a project settings file exists", async () => {
|
|
20
|
-
const projectPath = "./project.inlang"
|
|
21
|
-
const mockFs = {
|
|
22
|
-
readFile: vi.fn(
|
|
23
|
-
() => `{
|
|
24
|
-
"sourceLanguageTag": "en",
|
|
25
|
-
"languageTags": ["en", "de"],
|
|
26
|
-
"modules": []
|
|
27
|
-
}`
|
|
28
|
-
),
|
|
29
|
-
stat: vi.fn(() => {
|
|
30
|
-
throw Error()
|
|
31
|
-
}),
|
|
32
|
-
mkdir: vi.fn(),
|
|
33
|
-
writeFile: vi.fn(),
|
|
34
|
-
}
|
|
35
|
-
await maybeMigrateToDirectory({ nodeishFs: mockFs as any, projectPath })
|
|
36
|
-
expect(mockFs.mkdir).toHaveBeenCalled()
|
|
37
|
-
expect(mockFs.writeFile).toHaveBeenCalled()
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test("it should write the settings file to the new path", async () => {
|
|
41
|
-
const fs = createNodeishMemoryFs()
|
|
42
|
-
const mockSettings: ProjectSettings = {
|
|
43
|
-
sourceLanguageTag: "en",
|
|
44
|
-
languageTags: ["en", "de"],
|
|
45
|
-
modules: [],
|
|
46
|
-
}
|
|
47
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(mockSettings))
|
|
48
|
-
await maybeMigrateToDirectory({ nodeishFs: fs, projectPath: "./project.inlang" })
|
|
49
|
-
const migratedSettingsFile = await fs.readFile("./project.inlang/settings.json", {
|
|
50
|
-
encoding: "utf-8",
|
|
51
|
-
})
|
|
52
|
-
expect(migratedSettingsFile).toEqual(JSON.stringify(mockSettings))
|
|
53
|
-
expect(await fs.stat("./project.inlang.README.md")).toBeDefined()
|
|
54
|
-
})
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { tryCatch } from "@inlang/result"
|
|
2
|
-
import type { NodeishFilesystem } from "@lix-js/fs"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Migrates to the new project directory structure
|
|
6
|
-
* https://github.com/opral/monorepo/issues/1678
|
|
7
|
-
*/
|
|
8
|
-
export const maybeMigrateToDirectory = async (args: {
|
|
9
|
-
nodeishFs: NodeishFilesystem
|
|
10
|
-
projectPath: string
|
|
11
|
-
}) => {
|
|
12
|
-
// the migration assumes that the projectPath ends with project.inlang
|
|
13
|
-
if (args.projectPath.endsWith("project.inlang") === false) {
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// we assume that stat will throw when the directory does not exist
|
|
18
|
-
const projectDirectory = await tryCatch(() => args.nodeishFs.stat(args.projectPath))
|
|
19
|
-
|
|
20
|
-
// the migration has already been conducted.
|
|
21
|
-
if (projectDirectory.data) {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const settingsFile = await tryCatch(() =>
|
|
26
|
-
args.nodeishFs.readFile(args.projectPath + ".json", { encoding: "utf-8" })
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
// the settings file does not exist or something else is wrong, let loadProject handle it
|
|
30
|
-
if (settingsFile.error) {
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
await args.nodeishFs.mkdir(args.projectPath)
|
|
35
|
-
await args.nodeishFs.writeFile(`${args.projectPath}/settings.json`, settingsFile.data)
|
|
36
|
-
await args.nodeishFs.writeFile(args.projectPath + ".README.md", readme)
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
// console.log("🔔 migrated project.inlang to directory")
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const readme = `
|
|
43
|
-
# DELETE THE \`project.inlang.json\` FILE
|
|
44
|
-
|
|
45
|
-
The \`project.inlang.json\` file is now contained in a project directory e.g. \`project.inlang/settings.json\`.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## What you need to do
|
|
49
|
-
|
|
50
|
-
1. Update the inlang CLI (if you use it) to use the new path \`project.inlang\` instead of \`project.inlang.json\`.
|
|
51
|
-
2. Delete the \`project.inlang.json\` file.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
## Why is this happening?
|
|
55
|
-
|
|
56
|
-
See this RFC https://docs.google.com/document/d/1OYyA1wYfQRbIJOIBDliYoWjiUlkFBNxH_U2R4WpVRZ4/edit#heading=h.pecv6xb7ial6
|
|
57
|
-
and the following GitHub issue for more information https://github.com/opral/monorepo/issues/1678.
|
|
58
|
-
|
|
59
|
-
- Monorepo support https://github.com/opral/monorepo/discussions/258.
|
|
60
|
-
- Required for many other future features like caching, first class offline support, and more.
|
|
61
|
-
- Stablize the inlang project format.
|
|
62
|
-
`
|
package/src/parseConfig.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ProjectSettings } from "./versionedInterfaces.js"
|
|
2
|
-
import type { Result } from "@inlang/result"
|
|
3
|
-
import { TypeCompiler } from "@sinclair/typebox/compiler"
|
|
4
|
-
|
|
5
|
-
export class ParseConfigError extends Error {
|
|
6
|
-
readonly #id = "ParseConfigException"
|
|
7
|
-
|
|
8
|
-
constructor(message: string, cause?: string) {
|
|
9
|
-
super(message)
|
|
10
|
-
this.name = this.#id
|
|
11
|
-
this.cause = cause
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// @ts-ignore - fix after refactor
|
|
16
|
-
const ConfigCompiler = TypeCompiler.Compile(ProjectSettings)
|
|
17
|
-
|
|
18
|
-
export const parseSettings = (
|
|
19
|
-
config: ProjectSettings
|
|
20
|
-
): Result<ProjectSettings, ParseConfigError> => {
|
|
21
|
-
if (ConfigCompiler.Check(config)) {
|
|
22
|
-
return {
|
|
23
|
-
data: config,
|
|
24
|
-
error: undefined as never,
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
return {
|
|
28
|
-
error: new ParseConfigError(
|
|
29
|
-
"The inlang config is not valid.",
|
|
30
|
-
[...ConfigCompiler.Errors(config)].toString()
|
|
31
|
-
),
|
|
32
|
-
data: undefined as never,
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest"
|
|
2
|
-
import { sleep } from "../test-utilities/sleep.js"
|
|
3
|
-
import { batchedIO } from "./batchedIO.js"
|
|
4
|
-
|
|
5
|
-
let locked = false
|
|
6
|
-
|
|
7
|
-
const instrumentAquireLockStart = vi.fn()
|
|
8
|
-
|
|
9
|
-
async function mockAquireLock() {
|
|
10
|
-
instrumentAquireLockStart()
|
|
11
|
-
let pollCount = 0
|
|
12
|
-
while (locked && pollCount++ < 100) {
|
|
13
|
-
await sleep(10)
|
|
14
|
-
}
|
|
15
|
-
if (locked) {
|
|
16
|
-
throw new Error("Timeout acquiring lock")
|
|
17
|
-
}
|
|
18
|
-
await sleep(10)
|
|
19
|
-
locked = true
|
|
20
|
-
return 69
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
-
async function mockReleaseLock(_: number) {
|
|
25
|
-
sleep(10)
|
|
26
|
-
locked = false
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const instrumentSaveStart = vi.fn()
|
|
30
|
-
const instrumentSaveEnd = vi.fn()
|
|
31
|
-
|
|
32
|
-
async function mockSave() {
|
|
33
|
-
instrumentSaveStart()
|
|
34
|
-
await sleep(50)
|
|
35
|
-
instrumentSaveEnd()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe("batchedIO", () => {
|
|
39
|
-
it("queues 2 requests while waiting for lock and pushes 2 more to the next batch", async () => {
|
|
40
|
-
const save = batchedIO(mockAquireLock, mockReleaseLock, mockSave)
|
|
41
|
-
const p1 = save("1")
|
|
42
|
-
const p2 = save("2")
|
|
43
|
-
await sleep(5)
|
|
44
|
-
expect(instrumentAquireLockStart).toHaveBeenCalledTimes(1)
|
|
45
|
-
expect(instrumentSaveStart).not.toHaveBeenCalled()
|
|
46
|
-
await sleep(10)
|
|
47
|
-
expect(instrumentSaveStart).toHaveBeenCalled()
|
|
48
|
-
expect(instrumentSaveEnd).not.toHaveBeenCalled()
|
|
49
|
-
const p3 = save("3")
|
|
50
|
-
const p4 = save("4")
|
|
51
|
-
expect(instrumentAquireLockStart).toHaveBeenCalledTimes(2)
|
|
52
|
-
expect(locked).toBe(true)
|
|
53
|
-
await sleep(50)
|
|
54
|
-
expect(instrumentSaveEnd).toHaveBeenCalled()
|
|
55
|
-
expect(await p1).toBe("1")
|
|
56
|
-
expect(await p2).toBe("2")
|
|
57
|
-
expect(instrumentSaveStart).toHaveBeenCalledTimes(1)
|
|
58
|
-
expect(await p3).toBe("3")
|
|
59
|
-
expect(await p4).toBe("4")
|
|
60
|
-
expect(instrumentAquireLockStart).toHaveBeenCalledTimes(2)
|
|
61
|
-
expect(instrumentSaveStart).toHaveBeenCalledTimes(2)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import _debug from "debug"
|
|
2
|
-
const debug = _debug("sdk:batchedIO")
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* State machine to convert async save() into batched async save()
|
|
6
|
-
* states = idle -> acquiring -> saving -> idle
|
|
7
|
-
* idle = nothing queued, ready to acquire lock.
|
|
8
|
-
* aquiring = waiting to acquire a lock: requests go into the queue.
|
|
9
|
-
* saving = lock is acquired, save has begun: new requests go into the next batch.
|
|
10
|
-
* The next batch should not acquire the lock while current save is in progress.
|
|
11
|
-
* Queued requests are only resolved when the save completes.
|
|
12
|
-
*/
|
|
13
|
-
export function batchedIO(
|
|
14
|
-
acquireLock: () => Promise<number>,
|
|
15
|
-
releaseLock: (lock: number) => Promise<void>,
|
|
16
|
-
save: () => Promise<void>
|
|
17
|
-
): (id: string) => Promise<string> {
|
|
18
|
-
// 3-state machine
|
|
19
|
-
let state: "idle" | "acquiring" | "saving" = "idle"
|
|
20
|
-
|
|
21
|
-
// Hold requests while acquiring, resolve after saving
|
|
22
|
-
// TODO: rejectQueued if save throws (maybe?)
|
|
23
|
-
// https://github.com/opral/inlang-message-sdk/issues/79
|
|
24
|
-
type Queued = {
|
|
25
|
-
id: string
|
|
26
|
-
resolve: (value: string) => void
|
|
27
|
-
reject: (reason: any) => void
|
|
28
|
-
}
|
|
29
|
-
const queue: Queued[] = []
|
|
30
|
-
|
|
31
|
-
// initialize nextBatch lazily, reset after saving
|
|
32
|
-
let nextBatch: ((id: string) => Promise<string>) | undefined = undefined
|
|
33
|
-
|
|
34
|
-
// batched save function
|
|
35
|
-
return async (id: string) => {
|
|
36
|
-
if (state === "idle") {
|
|
37
|
-
state = "acquiring"
|
|
38
|
-
const lock = await acquireLock()
|
|
39
|
-
state = "saving"
|
|
40
|
-
await save()
|
|
41
|
-
await releaseLock(lock)
|
|
42
|
-
resolveQueued()
|
|
43
|
-
nextBatch = undefined
|
|
44
|
-
state = "idle"
|
|
45
|
-
return id
|
|
46
|
-
} else if (state === "acquiring") {
|
|
47
|
-
return new Promise<string>((resolve, reject) => {
|
|
48
|
-
queue.push({ id, resolve, reject })
|
|
49
|
-
})
|
|
50
|
-
} else {
|
|
51
|
-
// state === "saving"
|
|
52
|
-
nextBatch = nextBatch ?? batchedIO(acquireLock, releaseLock, save)
|
|
53
|
-
return await nextBatch(id)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function resolveQueued() {
|
|
58
|
-
debug("batched", queue.length + 1)
|
|
59
|
-
for (const { id, resolve } of queue) {
|
|
60
|
-
resolve(id)
|
|
61
|
-
}
|
|
62
|
-
queue.length = 0
|
|
63
|
-
}
|
|
64
|
-
}
|