@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.
Files changed (727) hide show
  1. package/README.md +1 -1
  2. package/dist/database/initDb.d.ts +7 -0
  3. package/dist/database/initDb.d.ts.map +1 -0
  4. package/dist/database/initDb.js +36 -0
  5. package/dist/database/initDb.js.map +1 -0
  6. package/dist/database/initDbAndSchema.test.d.ts +2 -0
  7. package/dist/database/initDbAndSchema.test.d.ts.map +1 -0
  8. package/dist/database/initDbAndSchema.test.js +110 -0
  9. package/dist/database/initDbAndSchema.test.js.map +1 -0
  10. package/dist/database/jsonbPlugin.d.ts +20 -0
  11. package/dist/database/jsonbPlugin.d.ts.map +1 -0
  12. package/dist/database/jsonbPlugin.js +183 -0
  13. package/dist/database/jsonbPlugin.js.map +1 -0
  14. package/dist/database/jsonbPlugin.test.d.ts +2 -0
  15. package/dist/database/jsonbPlugin.test.d.ts.map +1 -0
  16. package/dist/database/jsonbPlugin.test.js +119 -0
  17. package/dist/database/jsonbPlugin.test.js.map +1 -0
  18. package/dist/database/schema.d.ts +74 -0
  19. package/dist/database/schema.d.ts.map +1 -0
  20. package/dist/database/schema.js +45 -0
  21. package/dist/database/schema.js.map +1 -0
  22. package/dist/helper.d.ts +71 -0
  23. package/dist/helper.d.ts.map +1 -0
  24. package/dist/helper.js +91 -0
  25. package/dist/helper.js.map +1 -0
  26. package/dist/human-id/human-id.d.ts +3 -0
  27. package/dist/human-id/human-id.d.ts.map +1 -0
  28. package/dist/human-id/human-id.js +12 -0
  29. package/dist/human-id/human-id.js.map +1 -0
  30. package/dist/human-id/words.d.ts.map +1 -0
  31. package/dist/{storage/human-id → human-id}/words.js +4 -0
  32. package/dist/human-id/words.js.map +1 -0
  33. package/dist/human-id/words.test.d.ts.map +1 -0
  34. package/dist/{storage/human-id → human-id}/words.test.js +4 -0
  35. package/dist/human-id/words.test.js.map +1 -0
  36. package/dist/import-export/exportFiles.d.ts +11 -0
  37. package/dist/import-export/exportFiles.d.ts.map +1 -0
  38. package/dist/import-export/exportFiles.js +26 -0
  39. package/dist/import-export/exportFiles.js.map +1 -0
  40. package/dist/import-export/importFiles.d.ts +13 -0
  41. package/dist/import-export/importFiles.d.ts.map +1 -0
  42. package/dist/import-export/importFiles.js +124 -0
  43. package/dist/import-export/importFiles.js.map +1 -0
  44. package/dist/import-export/importFiles.test.d.ts +2 -0
  45. package/dist/import-export/importFiles.test.d.ts.map +1 -0
  46. package/dist/import-export/importFiles.test.js +179 -0
  47. package/dist/import-export/importFiles.test.js.map +1 -0
  48. package/dist/import-export/roundtrip.test.d.ts +2 -0
  49. package/dist/import-export/roundtrip.test.d.ts.map +1 -0
  50. package/dist/import-export/roundtrip.test.js +273 -0
  51. package/dist/import-export/roundtrip.test.js.map +1 -0
  52. package/dist/import-export/upsertBundleNestedMatchByProperties.d.ts +4 -0
  53. package/dist/import-export/upsertBundleNestedMatchByProperties.d.ts.map +1 -0
  54. package/dist/import-export/upsertBundleNestedMatchByProperties.js +58 -0
  55. package/dist/import-export/upsertBundleNestedMatchByProperties.js.map +1 -0
  56. package/dist/index.d.ts +21 -18
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +20 -17
  59. package/dist/index.js.map +1 -0
  60. package/dist/json-schema/old-v1-message/fromMessageV1.d.ts +9 -0
  61. package/dist/json-schema/old-v1-message/fromMessageV1.d.ts.map +1 -0
  62. package/dist/json-schema/old-v1-message/fromMessageV1.js +84 -0
  63. package/dist/json-schema/old-v1-message/fromMessageV1.js.map +1 -0
  64. package/dist/json-schema/old-v1-message/fromMessageV1.test.d.ts +2 -0
  65. package/dist/json-schema/old-v1-message/fromMessageV1.test.d.ts.map +1 -0
  66. package/dist/json-schema/old-v1-message/fromMessageV1.test.js +85 -0
  67. package/dist/json-schema/old-v1-message/fromMessageV1.test.js.map +1 -0
  68. package/dist/json-schema/old-v1-message/schemaV1.d.ts +86 -0
  69. package/dist/json-schema/old-v1-message/schemaV1.d.ts.map +1 -0
  70. package/dist/json-schema/old-v1-message/schemaV1.js +35 -0
  71. package/dist/json-schema/old-v1-message/schemaV1.js.map +1 -0
  72. package/dist/json-schema/old-v1-message/toMessageV1.d.ts +9 -0
  73. package/dist/json-schema/old-v1-message/toMessageV1.d.ts.map +1 -0
  74. package/dist/json-schema/old-v1-message/toMessageV1.js +67 -0
  75. package/dist/json-schema/old-v1-message/toMessageV1.js.map +1 -0
  76. package/dist/json-schema/old-v1-message/toMessageV1.test.d.ts +2 -0
  77. package/dist/json-schema/old-v1-message/toMessageV1.test.d.ts.map +1 -0
  78. package/dist/json-schema/old-v1-message/toMessageV1.test.js +85 -0
  79. package/dist/json-schema/old-v1-message/toMessageV1.test.js.map +1 -0
  80. package/dist/json-schema/pattern.d.ts +190 -0
  81. package/dist/json-schema/pattern.d.ts.map +1 -0
  82. package/dist/json-schema/pattern.js +43 -0
  83. package/dist/json-schema/pattern.js.map +1 -0
  84. package/dist/json-schema/settings.d.ts +31 -0
  85. package/dist/json-schema/settings.d.ts.map +1 -0
  86. package/dist/json-schema/settings.js +96 -0
  87. package/dist/json-schema/settings.js.map +1 -0
  88. package/dist/json-schema/settings.test-d.d.ts +2 -0
  89. package/dist/json-schema/settings.test-d.d.ts.map +1 -0
  90. package/dist/json-schema/settings.test-d.js +20 -0
  91. package/dist/json-schema/settings.test-d.js.map +1 -0
  92. package/dist/lix-plugin/applyChanges.d.ts +3 -0
  93. package/dist/lix-plugin/applyChanges.d.ts.map +1 -0
  94. package/dist/lix-plugin/applyChanges.js +127 -0
  95. package/dist/lix-plugin/applyChanges.js.map +1 -0
  96. package/dist/lix-plugin/applyChanges.test.d.ts +2 -0
  97. package/dist/lix-plugin/applyChanges.test.d.ts.map +1 -0
  98. package/dist/lix-plugin/applyChanges.test.js +135 -0
  99. package/dist/lix-plugin/applyChanges.test.js.map +1 -0
  100. package/dist/lix-plugin/detectConflicts.d.ts +3 -0
  101. package/dist/lix-plugin/detectConflicts.d.ts.map +1 -0
  102. package/dist/lix-plugin/detectConflicts.js +47 -0
  103. package/dist/lix-plugin/detectConflicts.js.map +1 -0
  104. package/dist/lix-plugin/detectConflicts.test.d.ts +2 -0
  105. package/dist/lix-plugin/detectConflicts.test.d.ts.map +1 -0
  106. package/dist/lix-plugin/detectConflicts.test.js +251 -0
  107. package/dist/lix-plugin/detectConflicts.test.js.map +1 -0
  108. package/dist/lix-plugin/inlangLixPluginV1.d.ts +8 -0
  109. package/dist/lix-plugin/inlangLixPluginV1.d.ts.map +1 -0
  110. package/dist/lix-plugin/inlangLixPluginV1.js +109 -0
  111. package/dist/lix-plugin/inlangLixPluginV1.js.map +1 -0
  112. package/dist/lix-plugin/inlangLixPluginV1.test.d.ts +2 -0
  113. package/dist/lix-plugin/inlangLixPluginV1.test.d.ts.map +1 -0
  114. package/dist/lix-plugin/inlangLixPluginV1.test.js +418 -0
  115. package/dist/lix-plugin/inlangLixPluginV1.test.js.map +1 -0
  116. package/dist/lix-plugin/merge.test.d.ts +2 -0
  117. package/dist/lix-plugin/merge.test.d.ts.map +1 -0
  118. package/dist/lix-plugin/merge.test.js +120 -0
  119. package/dist/lix-plugin/merge.test.js.map +1 -0
  120. package/dist/lix-plugin/resolveConflictBySelecting.test.d.ts +2 -0
  121. package/dist/lix-plugin/resolveConflictBySelecting.test.d.ts.map +1 -0
  122. package/dist/lix-plugin/resolveConflictBySelecting.test.js +176 -0
  123. package/dist/lix-plugin/resolveConflictBySelecting.test.js.map +1 -0
  124. package/dist/migrations/v2/createMessageV1.d.ts +28 -0
  125. package/dist/migrations/v2/createMessageV1.d.ts.map +1 -0
  126. package/dist/migrations/v2/createMessageV1.js +31 -0
  127. package/dist/migrations/v2/createMessageV1.js.map +1 -0
  128. package/dist/migrations/v2/withLanguageTagToLocaleMigration.d.ts +9 -0
  129. package/dist/migrations/v2/withLanguageTagToLocaleMigration.d.ts.map +1 -0
  130. package/dist/migrations/v2/withLanguageTagToLocaleMigration.js +31 -0
  131. package/dist/migrations/v2/withLanguageTagToLocaleMigration.js.map +1 -0
  132. package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.d.ts +2 -0
  133. package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.d.ts.map +1 -0
  134. package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.js +45 -0
  135. package/dist/migrations/v2/withLanguageTagToLocaleMigration.test.js.map +1 -0
  136. package/dist/plugin/cache.d.ts +6 -0
  137. package/dist/plugin/cache.d.ts.map +1 -0
  138. package/dist/plugin/cache.js +59 -0
  139. package/dist/plugin/cache.js.map +1 -0
  140. package/dist/plugin/cache.test.d.ts +2 -0
  141. package/dist/plugin/cache.test.d.ts.map +1 -0
  142. package/dist/plugin/cache.test.js +61 -0
  143. package/dist/plugin/cache.test.js.map +1 -0
  144. package/dist/plugin/errors.d.ts +41 -0
  145. package/dist/plugin/errors.d.ts.map +1 -0
  146. package/dist/plugin/errors.js +48 -0
  147. package/dist/plugin/errors.js.map +1 -0
  148. package/dist/plugin/importPlugins.d.ts +19 -0
  149. package/dist/plugin/importPlugins.d.ts.map +1 -0
  150. package/dist/plugin/importPlugins.js +43 -0
  151. package/dist/plugin/importPlugins.js.map +1 -0
  152. package/dist/plugin/importPlugins.test.d.ts +2 -0
  153. package/dist/plugin/importPlugins.test.d.ts.map +1 -0
  154. package/dist/plugin/importPlugins.test.js +95 -0
  155. package/dist/plugin/importPlugins.test.js.map +1 -0
  156. package/dist/plugin/meta/ideExtension.d.ts +54 -0
  157. package/dist/plugin/meta/ideExtension.d.ts.map +1 -0
  158. package/dist/plugin/meta/ideExtension.js +5 -0
  159. package/dist/plugin/meta/ideExtension.js.map +1 -0
  160. package/dist/plugin/schema.d.ts +152 -0
  161. package/dist/plugin/schema.d.ts.map +1 -0
  162. package/dist/plugin/schema.js +5 -0
  163. package/dist/plugin/schema.js.map +1 -0
  164. package/dist/project/api.d.ts +74 -0
  165. package/dist/project/api.d.ts.map +1 -0
  166. package/dist/project/api.js +5 -0
  167. package/dist/project/api.js.map +1 -0
  168. package/dist/project/initHandleSaveToLixOnChange.d.ts +14 -0
  169. package/dist/project/initHandleSaveToLixOnChange.d.ts.map +1 -0
  170. package/dist/project/initHandleSaveToLixOnChange.js +87 -0
  171. package/dist/project/initHandleSaveToLixOnChange.js.map +1 -0
  172. package/dist/project/loadProject.d.ts +53 -0
  173. package/dist/project/loadProject.d.ts.map +1 -0
  174. package/dist/project/loadProject.js +167 -0
  175. package/dist/project/loadProject.js.map +1 -0
  176. package/dist/project/loadProject.test.d.ts.map +1 -0
  177. package/dist/project/loadProject.test.js +146 -0
  178. package/dist/project/loadProject.test.js.map +1 -0
  179. package/dist/project/loadProjectFromDirectory.d.ts +77 -0
  180. package/dist/project/loadProjectFromDirectory.d.ts.map +1 -0
  181. package/dist/project/loadProjectFromDirectory.js +584 -0
  182. package/dist/project/loadProjectFromDirectory.js.map +1 -0
  183. package/dist/project/loadProjectFromDirectory.test.d.ts +2 -0
  184. package/dist/project/loadProjectFromDirectory.test.d.ts.map +1 -0
  185. package/dist/project/loadProjectFromDirectory.test.js +663 -0
  186. package/dist/project/loadProjectFromDirectory.test.js.map +1 -0
  187. package/dist/project/loadProjectInMemory.d.ts +8 -0
  188. package/dist/project/loadProjectInMemory.d.ts.map +1 -0
  189. package/dist/project/loadProjectInMemory.js +32 -0
  190. package/dist/project/loadProjectInMemory.js.map +1 -0
  191. package/dist/project/loadProjectInMemory.test.d.ts +2 -0
  192. package/dist/project/loadProjectInMemory.test.d.ts.map +1 -0
  193. package/dist/project/loadProjectInMemory.test.js +27 -0
  194. package/dist/project/loadProjectInMemory.test.js.map +1 -0
  195. package/dist/project/maybeCaptureTelemetry.d.ts +13 -0
  196. package/dist/project/maybeCaptureTelemetry.d.ts.map +1 -0
  197. package/dist/project/maybeCaptureTelemetry.js +53 -0
  198. package/dist/project/maybeCaptureTelemetry.js.map +1 -0
  199. package/dist/project/maybeCaptureTelemetry.test.d.ts +2 -0
  200. package/dist/project/maybeCaptureTelemetry.test.d.ts.map +1 -0
  201. package/dist/project/maybeCaptureTelemetry.test.js +65 -0
  202. package/dist/project/maybeCaptureTelemetry.test.js.map +1 -0
  203. package/dist/project/newProject.d.ts +17 -0
  204. package/dist/project/newProject.d.ts.map +1 -0
  205. package/dist/project/newProject.js +71 -0
  206. package/dist/project/newProject.js.map +1 -0
  207. package/dist/project/newProject.test.d.ts +2 -0
  208. package/dist/project/newProject.test.d.ts.map +1 -0
  209. package/dist/project/newProject.test.js +37 -0
  210. package/dist/project/newProject.test.js.map +1 -0
  211. package/dist/project/saveProjectToDirectory.d.ts +8 -0
  212. package/dist/project/saveProjectToDirectory.d.ts.map +1 -0
  213. package/dist/project/saveProjectToDirectory.js +86 -0
  214. package/dist/project/saveProjectToDirectory.js.map +1 -0
  215. package/dist/project/saveProjectToDirectory.test.d.ts +2 -0
  216. package/dist/project/saveProjectToDirectory.test.d.ts.map +1 -0
  217. package/dist/project/saveProjectToDirectory.test.js +245 -0
  218. package/dist/project/saveProjectToDirectory.test.js.map +1 -0
  219. package/dist/project/state/id$.d.ts +6 -0
  220. package/dist/project/state/id$.d.ts.map +1 -0
  221. package/dist/project/state/id$.js +19 -0
  222. package/dist/project/state/id$.js.map +1 -0
  223. package/dist/project/state/id$.test.d.ts +2 -0
  224. package/dist/project/state/id$.test.d.ts.map +1 -0
  225. package/dist/project/state/id$.test.js +36 -0
  226. package/dist/project/state/id$.test.js.map +1 -0
  227. package/dist/project/state/setSettings.d.ts +7 -0
  228. package/dist/project/state/setSettings.d.ts.map +1 -0
  229. package/dist/project/state/setSettings.js +16 -0
  230. package/dist/project/state/setSettings.js.map +1 -0
  231. package/dist/project/state/setSettings.test.d.ts +2 -0
  232. package/dist/project/state/setSettings.test.d.ts.map +1 -0
  233. package/dist/project/state/setSettings.test.js +58 -0
  234. package/dist/project/state/setSettings.test.js.map +1 -0
  235. package/dist/project/state/settings$.d.ts +7 -0
  236. package/dist/project/state/settings$.d.ts.map +1 -0
  237. package/dist/project/state/settings$.js +21 -0
  238. package/dist/project/state/settings$.js.map +1 -0
  239. package/dist/project/state/settings$.test.d.ts +2 -0
  240. package/dist/project/state/settings$.test.d.ts.map +1 -0
  241. package/dist/project/state/settings$.test.js +51 -0
  242. package/dist/project/state/settings$.test.js.map +1 -0
  243. package/dist/project/state/state.d.ts +58 -0
  244. package/dist/project/state/state.d.ts.map +1 -0
  245. package/dist/project/state/state.js +67 -0
  246. package/dist/project/state/state.js.map +1 -0
  247. package/dist/project/state/state.test.d.ts +2 -0
  248. package/dist/project/state/state.test.d.ts.map +1 -0
  249. package/dist/project/state/state.test.js +103 -0
  250. package/dist/project/state/state.test.js.map +1 -0
  251. package/dist/query-utilities/index.d.ts +5 -0
  252. package/dist/query-utilities/index.d.ts.map +1 -0
  253. package/dist/query-utilities/index.js +8 -0
  254. package/dist/query-utilities/index.js.map +1 -0
  255. package/dist/query-utilities/insertBundleNested.d.ts +4 -0
  256. package/dist/query-utilities/insertBundleNested.d.ts.map +1 -0
  257. package/dist/query-utilities/insertBundleNested.js +39 -0
  258. package/dist/query-utilities/insertBundleNested.js.map +1 -0
  259. package/dist/query-utilities/pollQuery.d.ts +14 -0
  260. package/dist/query-utilities/pollQuery.d.ts.map +1 -0
  261. package/dist/query-utilities/pollQuery.js +22 -0
  262. package/dist/query-utilities/pollQuery.js.map +1 -0
  263. package/dist/query-utilities/pollQuery.test.d.ts +2 -0
  264. package/dist/query-utilities/pollQuery.test.d.ts.map +1 -0
  265. package/dist/query-utilities/pollQuery.test.js +67 -0
  266. package/dist/query-utilities/pollQuery.test.js.map +1 -0
  267. package/dist/query-utilities/selectBundleNested.d.ts +107 -0
  268. package/dist/query-utilities/selectBundleNested.d.ts.map +1 -0
  269. package/dist/query-utilities/selectBundleNested.js +43 -0
  270. package/dist/query-utilities/selectBundleNested.js.map +1 -0
  271. package/dist/query-utilities/updateBundleNested.d.ts +12 -0
  272. package/dist/query-utilities/updateBundleNested.d.ts.map +1 -0
  273. package/dist/query-utilities/updateBundleNested.js +25 -0
  274. package/dist/query-utilities/updateBundleNested.js.map +1 -0
  275. package/dist/query-utilities/upsertBundleNested.d.ts +4 -0
  276. package/dist/query-utilities/upsertBundleNested.d.ts.map +1 -0
  277. package/dist/query-utilities/upsertBundleNested.js +50 -0
  278. package/dist/query-utilities/upsertBundleNested.js.map +1 -0
  279. package/dist/services/env-variables/index.d.ts +6 -0
  280. package/dist/services/env-variables/index.d.ts.map +1 -0
  281. package/dist/services/env-variables/index.js +9 -0
  282. package/dist/services/env-variables/index.js.map +1 -0
  283. package/dist/services/error-reporting/index.d.ts +15 -0
  284. package/dist/services/error-reporting/index.d.ts.map +1 -0
  285. package/dist/services/error-reporting/index.js +30 -0
  286. package/dist/services/error-reporting/index.js.map +1 -0
  287. package/dist/{telemetry → services/telemetry}/capture.d.ts +4 -2
  288. package/dist/services/telemetry/capture.d.ts.map +1 -0
  289. package/dist/services/telemetry/capture.js +77 -0
  290. package/dist/services/telemetry/capture.js.map +1 -0
  291. package/dist/services/telemetry/capture.test.d.ts +2 -0
  292. package/dist/services/telemetry/capture.test.d.ts.map +1 -0
  293. package/dist/services/telemetry/capture.test.js +44 -0
  294. package/dist/services/telemetry/capture.test.js.map +1 -0
  295. package/dist/utilities/detectJsonFormatting.d.ts +11 -0
  296. package/dist/utilities/detectJsonFormatting.d.ts.map +1 -0
  297. package/dist/utilities/detectJsonFormatting.js +83 -0
  298. package/dist/utilities/detectJsonFormatting.js.map +1 -0
  299. package/dist/utilities/detectJsonFormatting.test.d.ts +2 -0
  300. package/dist/utilities/detectJsonFormatting.test.d.ts.map +1 -0
  301. package/dist/utilities/detectJsonFormatting.test.js +33 -0
  302. package/dist/utilities/detectJsonFormatting.test.js.map +1 -0
  303. package/package.json +32 -40
  304. package/src/database/initDb.ts +34 -0
  305. package/src/database/initDbAndSchema.test.ts +125 -0
  306. package/src/database/jsonbPlugin.test.ts +154 -0
  307. package/src/database/jsonbPlugin.ts +215 -0
  308. package/src/database/schema.ts +127 -0
  309. package/src/helper.ts +113 -0
  310. package/src/human-id/human-id.ts +14 -0
  311. package/src/{storage/human-id → human-id}/words.test.ts +14 -14
  312. package/src/{storage/human-id → human-id}/words.ts +4 -4
  313. package/src/import-export/exportFiles.ts +36 -0
  314. package/src/import-export/importFiles.test.ts +211 -0
  315. package/src/import-export/importFiles.ts +142 -0
  316. package/src/import-export/roundtrip.test.ts +313 -0
  317. package/src/import-export/upsertBundleNestedMatchByProperties.ts +74 -0
  318. package/src/index.ts +29 -37
  319. package/src/json-schema/old-v1-message/README.md +1 -0
  320. package/src/json-schema/old-v1-message/fromMessageV1.test.ts +87 -0
  321. package/src/json-schema/old-v1-message/fromMessageV1.ts +99 -0
  322. package/src/json-schema/old-v1-message/schemaV1.ts +66 -0
  323. package/src/json-schema/old-v1-message/toMessageV1.test.ts +87 -0
  324. package/src/json-schema/old-v1-message/toMessageV1.ts +79 -0
  325. package/src/json-schema/pattern.ts +59 -0
  326. package/src/json-schema/settings.test-d.ts +21 -0
  327. package/src/json-schema/settings.ts +138 -0
  328. package/src/lix-plugin/applyChanges.test.ts +150 -0
  329. package/src/lix-plugin/applyChanges.ts +171 -0
  330. package/src/lix-plugin/detectConflicts.test.ts +286 -0
  331. package/src/lix-plugin/detectConflicts.ts +62 -0
  332. package/src/lix-plugin/inlangLixPluginV1.test.ts +439 -0
  333. package/src/lix-plugin/inlangLixPluginV1.ts +132 -0
  334. package/src/lix-plugin/merge.test.ts +133 -0
  335. package/src/lix-plugin/resolveConflictBySelecting.test.ts +188 -0
  336. package/src/migrations/v2/createMessageV1.ts +37 -0
  337. package/src/migrations/v2/withLanguageTagToLocaleMigration.test.ts +51 -0
  338. package/src/migrations/v2/withLanguageTagToLocaleMigration.ts +31 -0
  339. package/src/plugin/cache.test.ts +83 -0
  340. package/src/plugin/cache.ts +79 -0
  341. package/src/plugin/errors.ts +67 -0
  342. package/src/plugin/importPlugins.test.ts +107 -0
  343. package/src/plugin/importPlugins.ts +60 -0
  344. package/src/plugin/meta/ideExtension.ts +56 -0
  345. package/src/plugin/schema.ts +165 -0
  346. package/src/project/api.ts +77 -0
  347. package/src/project/initHandleSaveToLixOnChange.ts +93 -0
  348. package/src/project/loadProject.test.ts +177 -0
  349. package/src/project/loadProject.ts +245 -0
  350. package/src/project/loadProjectFromDirectory.test.ts +854 -0
  351. package/src/project/loadProjectFromDirectory.ts +752 -0
  352. package/src/project/loadProjectInMemory.test.ts +29 -0
  353. package/src/project/loadProjectInMemory.ts +36 -0
  354. package/src/project/maybeCaptureTelemetry.test.ts +72 -0
  355. package/src/project/maybeCaptureTelemetry.ts +61 -0
  356. package/src/project/newProject.test.ts +36 -0
  357. package/src/project/newProject.ts +78 -0
  358. package/src/project/saveProjectToDirectory.test.ts +310 -0
  359. package/src/project/saveProjectToDirectory.ts +100 -0
  360. package/src/query-utilities/index.ts +4 -0
  361. package/src/query-utilities/insertBundleNested.ts +46 -0
  362. package/src/query-utilities/selectBundleNested.ts +46 -0
  363. package/src/query-utilities/updateBundleNested.ts +35 -0
  364. package/src/query-utilities/upsertBundleNested.ts +61 -0
  365. package/src/services/env-variables/createIndexFile.js +40 -0
  366. package/src/{env-variables → services/env-variables}/index.d.ts +8 -5
  367. package/src/services/error-reporting/index.ts +28 -0
  368. package/src/services/telemetry/capture.test.ts +48 -0
  369. package/src/services/telemetry/capture.ts +98 -0
  370. package/src/utilities/detectJsonFormatting.test.ts +38 -0
  371. package/src/utilities/detectJsonFormatting.ts +109 -0
  372. package/dist/adapter/solidAdapter.d.ts +0 -33
  373. package/dist/adapter/solidAdapter.d.ts.map +0 -1
  374. package/dist/adapter/solidAdapter.js +0 -40
  375. package/dist/adapter/solidAdapter.test.d.ts +0 -2
  376. package/dist/adapter/solidAdapter.test.d.ts.map +0 -1
  377. package/dist/adapter/solidAdapter.test.js +0 -356
  378. package/dist/api.d.ts +0 -113
  379. package/dist/api.d.ts.map +0 -1
  380. package/dist/api.js +0 -1
  381. package/dist/api.test-d.d.ts +0 -2
  382. package/dist/api.test-d.d.ts.map +0 -1
  383. package/dist/api.test-d.js +0 -4
  384. package/dist/createMessageLintReportsQuery.d.ts +0 -12
  385. package/dist/createMessageLintReportsQuery.d.ts.map +0 -1
  386. package/dist/createMessageLintReportsQuery.js +0 -176
  387. package/dist/createMessagesQuery.d.ts +0 -19
  388. package/dist/createMessagesQuery.d.ts.map +0 -1
  389. package/dist/createMessagesQuery.js +0 -451
  390. package/dist/createMessagesQuery.test.d.ts +0 -2
  391. package/dist/createMessagesQuery.test.d.ts.map +0 -1
  392. package/dist/createMessagesQuery.test.js +0 -402
  393. package/dist/createNewProject.d.ts +0 -12
  394. package/dist/createNewProject.d.ts.map +0 -1
  395. package/dist/createNewProject.js +0 -38
  396. package/dist/createNewProject.test.d.ts +0 -2
  397. package/dist/createNewProject.test.d.ts.map +0 -1
  398. package/dist/createNewProject.test.js +0 -91
  399. package/dist/createNodeishFsWithAbsolutePaths.d.ts +0 -12
  400. package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +0 -1
  401. package/dist/createNodeishFsWithAbsolutePaths.js +0 -38
  402. package/dist/createNodeishFsWithAbsolutePaths.test.d.ts +0 -2
  403. package/dist/createNodeishFsWithAbsolutePaths.test.d.ts.map +0 -1
  404. package/dist/createNodeishFsWithAbsolutePaths.test.js +0 -44
  405. package/dist/createNodeishFsWithWatcher.d.ts +0 -14
  406. package/dist/createNodeishFsWithWatcher.d.ts.map +0 -1
  407. package/dist/createNodeishFsWithWatcher.js +0 -75
  408. package/dist/createNodeishFsWithWatcher.test.d.ts +0 -2
  409. package/dist/createNodeishFsWithWatcher.test.d.ts.map +0 -1
  410. package/dist/createNodeishFsWithWatcher.test.js +0 -38
  411. package/dist/defaultProjectSettings.d.ts +0 -14
  412. package/dist/defaultProjectSettings.d.ts.map +0 -1
  413. package/dist/defaultProjectSettings.js +0 -22
  414. package/dist/env-variables/index.d.ts +0 -4
  415. package/dist/env-variables/index.d.ts.map +0 -1
  416. package/dist/env-variables/index.js +0 -3
  417. package/dist/errors.d.ts +0 -48
  418. package/dist/errors.d.ts.map +0 -1
  419. package/dist/errors.js +0 -62
  420. package/dist/lint/index.d.ts +0 -3
  421. package/dist/lint/index.d.ts.map +0 -1
  422. package/dist/lint/index.js +0 -2
  423. package/dist/lint/message/errors.d.ts +0 -7
  424. package/dist/lint/message/errors.d.ts.map +0 -1
  425. package/dist/lint/message/errors.js +0 -9
  426. package/dist/lint/message/lintMessages.d.ts +0 -13
  427. package/dist/lint/message/lintMessages.d.ts.map +0 -1
  428. package/dist/lint/message/lintMessages.js +0 -12
  429. package/dist/lint/message/lintMessages.test.d.ts +0 -2
  430. package/dist/lint/message/lintMessages.test.d.ts.map +0 -1
  431. package/dist/lint/message/lintMessages.test.js +0 -107
  432. package/dist/lint/message/lintSingleMessage.d.ts +0 -19
  433. package/dist/lint/message/lintSingleMessage.d.ts.map +0 -1
  434. package/dist/lint/message/lintSingleMessage.js +0 -38
  435. package/dist/lint/message/lintSingleMessage.test.d.ts +0 -2
  436. package/dist/lint/message/lintSingleMessage.test.d.ts.map +0 -1
  437. package/dist/lint/message/lintSingleMessage.test.js +0 -161
  438. package/dist/listProjects.d.ts +0 -5
  439. package/dist/listProjects.d.ts.map +0 -1
  440. package/dist/listProjects.js +0 -38
  441. package/dist/listProjects.test.d.ts +0 -2
  442. package/dist/listProjects.test.d.ts.map +0 -1
  443. package/dist/listProjects.test.js +0 -72
  444. package/dist/loadProject.d.ts +0 -19
  445. package/dist/loadProject.d.ts.map +0 -1
  446. package/dist/loadProject.js +0 -343
  447. package/dist/loadProject.test.d.ts.map +0 -1
  448. package/dist/loadProject.test.js +0 -975
  449. package/dist/messages/errors.d.ts +0 -13
  450. package/dist/messages/errors.d.ts.map +0 -1
  451. package/dist/messages/errors.js +0 -18
  452. package/dist/messages/index.d.ts +0 -3
  453. package/dist/messages/index.d.ts.map +0 -1
  454. package/dist/messages/index.js +0 -2
  455. package/dist/messages/variant.d.ts +0 -46
  456. package/dist/messages/variant.d.ts.map +0 -1
  457. package/dist/messages/variant.js +0 -176
  458. package/dist/messages/variant.test.d.ts +0 -2
  459. package/dist/messages/variant.test.d.ts.map +0 -1
  460. package/dist/messages/variant.test.js +0 -439
  461. package/dist/migrations/maybeAddModuleCache.d.ts +0 -6
  462. package/dist/migrations/maybeAddModuleCache.d.ts.map +0 -1
  463. package/dist/migrations/maybeAddModuleCache.js +0 -62
  464. package/dist/migrations/maybeCreateFirstProjectId.d.ts +0 -16
  465. package/dist/migrations/maybeCreateFirstProjectId.d.ts.map +0 -1
  466. package/dist/migrations/maybeCreateFirstProjectId.js +0 -46
  467. package/dist/migrations/maybeCreateFirstProjectId.test.d.ts +0 -2
  468. package/dist/migrations/maybeCreateFirstProjectId.test.d.ts.map +0 -1
  469. package/dist/migrations/maybeCreateFirstProjectId.test.js +0 -24
  470. package/dist/migrations/migrateToDirectory.d.ts +0 -10
  471. package/dist/migrations/migrateToDirectory.d.ts.map +0 -1
  472. package/dist/migrations/migrateToDirectory.js +0 -48
  473. package/dist/migrations/migrateToDirectory.test.d.ts +0 -2
  474. package/dist/migrations/migrateToDirectory.test.d.ts.map +0 -1
  475. package/dist/migrations/migrateToDirectory.test.js +0 -48
  476. package/dist/parseConfig.d.ts +0 -8
  477. package/dist/parseConfig.d.ts.map +0 -1
  478. package/dist/parseConfig.js +0 -26
  479. package/dist/persistence/batchedIO.d.ts +0 -11
  480. package/dist/persistence/batchedIO.d.ts.map +0 -1
  481. package/dist/persistence/batchedIO.js +0 -49
  482. package/dist/persistence/batchedIO.test.d.ts +0 -2
  483. package/dist/persistence/batchedIO.test.d.ts.map +0 -1
  484. package/dist/persistence/batchedIO.test.js +0 -56
  485. package/dist/persistence/filelock/acquireFileLock.d.ts +0 -3
  486. package/dist/persistence/filelock/acquireFileLock.d.ts.map +0 -1
  487. package/dist/persistence/filelock/acquireFileLock.js +0 -111
  488. package/dist/persistence/filelock/releaseLock.d.ts +0 -3
  489. package/dist/persistence/filelock/releaseLock.d.ts.map +0 -1
  490. package/dist/persistence/filelock/releaseLock.js +0 -24
  491. package/dist/persistence/store.d.ts +0 -107
  492. package/dist/persistence/store.d.ts.map +0 -1
  493. package/dist/persistence/store.js +0 -99
  494. package/dist/persistence/store.test.d.ts +0 -2
  495. package/dist/persistence/store.test.d.ts.map +0 -1
  496. package/dist/persistence/store.test.js +0 -79
  497. package/dist/persistence/storeApi.d.ts +0 -22
  498. package/dist/persistence/storeApi.d.ts.map +0 -1
  499. package/dist/persistence/storeApi.js +0 -1
  500. package/dist/reactivity/map.d.ts +0 -67
  501. package/dist/reactivity/map.d.ts.map +0 -1
  502. package/dist/reactivity/map.js +0 -143
  503. package/dist/reactivity/solid.d.ts +0 -14
  504. package/dist/reactivity/solid.d.ts.map +0 -1
  505. package/dist/reactivity/solid.js +0 -15
  506. package/dist/reactivity/solid.test.d.ts +0 -2
  507. package/dist/reactivity/solid.test.d.ts.map +0 -1
  508. package/dist/reactivity/solid.test.js +0 -189
  509. package/dist/reactivity/trigger.d.ts +0 -11
  510. package/dist/reactivity/trigger.d.ts.map +0 -1
  511. package/dist/reactivity/trigger.js +0 -46
  512. package/dist/resolve-modules/cache.d.ts +0 -6
  513. package/dist/resolve-modules/cache.d.ts.map +0 -1
  514. package/dist/resolve-modules/cache.js +0 -58
  515. package/dist/resolve-modules/errors.d.ts +0 -41
  516. package/dist/resolve-modules/errors.d.ts.map +0 -1
  517. package/dist/resolve-modules/errors.js +0 -45
  518. package/dist/resolve-modules/import.d.ts +0 -19
  519. package/dist/resolve-modules/import.d.ts.map +0 -1
  520. package/dist/resolve-modules/import.js +0 -102
  521. package/dist/resolve-modules/import.test.d.ts +0 -2
  522. package/dist/resolve-modules/import.test.d.ts.map +0 -1
  523. package/dist/resolve-modules/import.test.js +0 -47
  524. package/dist/resolve-modules/index.d.ts +0 -3
  525. package/dist/resolve-modules/index.d.ts.map +0 -1
  526. package/dist/resolve-modules/index.js +0 -2
  527. package/dist/resolve-modules/message-lint-rules/errors.d.ts +0 -9
  528. package/dist/resolve-modules/message-lint-rules/errors.d.ts.map +0 -1
  529. package/dist/resolve-modules/message-lint-rules/errors.js +0 -6
  530. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts +0 -9
  531. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts.map +0 -1
  532. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +0 -24
  533. package/dist/resolve-modules/plugins/errors.d.ts +0 -33
  534. package/dist/resolve-modules/plugins/errors.d.ts.map +0 -1
  535. package/dist/resolve-modules/plugins/errors.js +0 -38
  536. package/dist/resolve-modules/plugins/resolvePlugins.d.ts +0 -3
  537. package/dist/resolve-modules/plugins/resolvePlugins.d.ts.map +0 -1
  538. package/dist/resolve-modules/plugins/resolvePlugins.js +0 -92
  539. package/dist/resolve-modules/plugins/resolvePlugins.test.d.ts +0 -2
  540. package/dist/resolve-modules/plugins/resolvePlugins.test.d.ts.map +0 -1
  541. package/dist/resolve-modules/plugins/resolvePlugins.test.js +0 -252
  542. package/dist/resolve-modules/plugins/types.d.ts +0 -57
  543. package/dist/resolve-modules/plugins/types.d.ts.map +0 -1
  544. package/dist/resolve-modules/plugins/types.js +0 -1
  545. package/dist/resolve-modules/plugins/types.test.d.ts +0 -2
  546. package/dist/resolve-modules/plugins/types.test.d.ts.map +0 -1
  547. package/dist/resolve-modules/plugins/types.test.js +0 -45
  548. package/dist/resolve-modules/resolveModules.d.ts +0 -3
  549. package/dist/resolve-modules/resolveModules.d.ts.map +0 -1
  550. package/dist/resolve-modules/resolveModules.js +0 -80
  551. package/dist/resolve-modules/resolveModules.test.d.ts +0 -2
  552. package/dist/resolve-modules/resolveModules.test.d.ts.map +0 -1
  553. package/dist/resolve-modules/resolveModules.test.js +0 -185
  554. package/dist/resolve-modules/types.d.ts +0 -63
  555. package/dist/resolve-modules/types.d.ts.map +0 -1
  556. package/dist/resolve-modules/types.js +0 -1
  557. package/dist/resolve-modules/validateModuleSettings.test.d.ts +0 -2
  558. package/dist/resolve-modules/validateModuleSettings.test.d.ts.map +0 -1
  559. package/dist/resolve-modules/validateModuleSettings.test.js +0 -71
  560. package/dist/resolve-modules/validatedModuleSettings.d.ts +0 -7
  561. package/dist/resolve-modules/validatedModuleSettings.d.ts.map +0 -1
  562. package/dist/resolve-modules/validatedModuleSettings.js +0 -11
  563. package/dist/storage/helper.d.ts +0 -11
  564. package/dist/storage/helper.d.ts.map +0 -1
  565. package/dist/storage/helper.js +0 -63
  566. package/dist/storage/helpers.test.d.ts +0 -2
  567. package/dist/storage/helpers.test.d.ts.map +0 -1
  568. package/dist/storage/helpers.test.js +0 -84
  569. package/dist/storage/human-id/human-readable-id.d.ts +0 -3
  570. package/dist/storage/human-id/human-readable-id.d.ts.map +0 -1
  571. package/dist/storage/human-id/human-readable-id.js +0 -20
  572. package/dist/storage/human-id/words.d.ts.map +0 -1
  573. package/dist/storage/human-id/words.test.d.ts.map +0 -1
  574. package/dist/telemetry/capture.d.ts.map +0 -1
  575. package/dist/telemetry/capture.js +0 -39
  576. package/dist/telemetry/groupIdentify.d.ts +0 -13
  577. package/dist/telemetry/groupIdentify.d.ts.map +0 -1
  578. package/dist/telemetry/groupIdentify.js +0 -35
  579. package/dist/test-utilities/createMessage.d.ts +0 -18
  580. package/dist/test-utilities/createMessage.d.ts.map +0 -1
  581. package/dist/test-utilities/createMessage.js +0 -17
  582. package/dist/test-utilities/createMessage.test.d.ts +0 -2
  583. package/dist/test-utilities/createMessage.test.d.ts.map +0 -1
  584. package/dist/test-utilities/createMessage.test.js +0 -106
  585. package/dist/test-utilities/index.d.ts +0 -3
  586. package/dist/test-utilities/index.d.ts.map +0 -1
  587. package/dist/test-utilities/index.js +0 -2
  588. package/dist/test-utilities/sleep.d.ts +0 -4
  589. package/dist/test-utilities/sleep.d.ts.map +0 -1
  590. package/dist/test-utilities/sleep.js +0 -9
  591. package/dist/v2/helper.d.ts +0 -43
  592. package/dist/v2/helper.d.ts.map +0 -1
  593. package/dist/v2/helper.js +0 -75
  594. package/dist/v2/helper.test.d.ts +0 -2
  595. package/dist/v2/helper.test.d.ts.map +0 -1
  596. package/dist/v2/helper.test.js +0 -92
  597. package/dist/v2/index.d.ts +0 -4
  598. package/dist/v2/index.d.ts.map +0 -1
  599. package/dist/v2/index.js +0 -2
  600. package/dist/v2/mocks/index.d.ts +0 -3
  601. package/dist/v2/mocks/index.d.ts.map +0 -1
  602. package/dist/v2/mocks/index.js +0 -2
  603. package/dist/v2/mocks/multipleMatcher/bundle.d.ts +0 -3
  604. package/dist/v2/mocks/multipleMatcher/bundle.d.ts.map +0 -1
  605. package/dist/v2/mocks/multipleMatcher/bundle.js +0 -194
  606. package/dist/v2/mocks/multipleMatcher/bundle.test.d.ts +0 -2
  607. package/dist/v2/mocks/multipleMatcher/bundle.test.d.ts.map +0 -1
  608. package/dist/v2/mocks/multipleMatcher/bundle.test.js +0 -10
  609. package/dist/v2/mocks/plural/bundle.d.ts +0 -3
  610. package/dist/v2/mocks/plural/bundle.d.ts.map +0 -1
  611. package/dist/v2/mocks/plural/bundle.js +0 -162
  612. package/dist/v2/mocks/plural/bundle.test.d.ts +0 -2
  613. package/dist/v2/mocks/plural/bundle.test.d.ts.map +0 -1
  614. package/dist/v2/mocks/plural/bundle.test.js +0 -15
  615. package/dist/v2/shim.d.ts +0 -12
  616. package/dist/v2/shim.d.ts.map +0 -1
  617. package/dist/v2/shim.js +0 -151
  618. package/dist/v2/shim.test.d.ts +0 -2
  619. package/dist/v2/shim.test.d.ts.map +0 -1
  620. package/dist/v2/shim.test.js +0 -49
  621. package/dist/v2/stubQueryApi.d.ts +0 -9
  622. package/dist/v2/stubQueryApi.d.ts.map +0 -1
  623. package/dist/v2/stubQueryApi.js +0 -38
  624. package/dist/v2/types.d.ts +0 -521
  625. package/dist/v2/types.d.ts.map +0 -1
  626. package/dist/v2/types.js +0 -78
  627. package/dist/validateProjectPath.d.ts +0 -17
  628. package/dist/validateProjectPath.d.ts.map +0 -1
  629. package/dist/validateProjectPath.js +0 -31
  630. package/dist/validateProjectPath.test.d.ts +0 -2
  631. package/dist/validateProjectPath.test.d.ts.map +0 -1
  632. package/dist/validateProjectPath.test.js +0 -40
  633. package/dist/versionedInterfaces.d.ts +0 -8
  634. package/dist/versionedInterfaces.d.ts.map +0 -1
  635. package/dist/versionedInterfaces.js +0 -8
  636. package/src/adapter/solidAdapter.test.ts +0 -472
  637. package/src/adapter/solidAdapter.ts +0 -79
  638. package/src/api.test-d.ts +0 -8
  639. package/src/api.ts +0 -116
  640. package/src/createMessageLintReportsQuery.ts +0 -225
  641. package/src/createMessagesQuery.test.ts +0 -538
  642. package/src/createMessagesQuery.ts +0 -635
  643. package/src/createNewProject.test.ts +0 -105
  644. package/src/createNewProject.ts +0 -46
  645. package/src/createNodeishFsWithAbsolutePaths.test.ts +0 -55
  646. package/src/createNodeishFsWithAbsolutePaths.ts +0 -52
  647. package/src/createNodeishFsWithWatcher.test.ts +0 -50
  648. package/src/createNodeishFsWithWatcher.ts +0 -85
  649. package/src/defaultProjectSettings.ts +0 -26
  650. package/src/env-variables/.prettierignore +0 -1
  651. package/src/env-variables/createIndexFile.js +0 -28
  652. package/src/errors.ts +0 -84
  653. package/src/lint/index.ts +0 -2
  654. package/src/lint/message/errors.ts +0 -9
  655. package/src/lint/message/lintMessages.test.ts +0 -126
  656. package/src/lint/message/lintMessages.ts +0 -25
  657. package/src/lint/message/lintSingleMessage.test.ts +0 -191
  658. package/src/lint/message/lintSingleMessage.ts +0 -57
  659. package/src/listProjects.test.ts +0 -91
  660. package/src/listProjects.ts +0 -48
  661. package/src/loadProject.test.ts +0 -1173
  662. package/src/loadProject.ts +0 -460
  663. package/src/messages/errors.ts +0 -25
  664. package/src/messages/index.ts +0 -2
  665. package/src/messages/variant.test.ts +0 -511
  666. package/src/messages/variant.ts +0 -247
  667. package/src/migrations/maybeAddModuleCache.ts +0 -68
  668. package/src/migrations/maybeCreateFirstProjectId.test.ts +0 -31
  669. package/src/migrations/maybeCreateFirstProjectId.ts +0 -51
  670. package/src/migrations/migrateToDirectory.test.ts +0 -54
  671. package/src/migrations/migrateToDirectory.ts +0 -62
  672. package/src/parseConfig.ts +0 -35
  673. package/src/persistence/batchedIO.test.ts +0 -63
  674. package/src/persistence/batchedIO.ts +0 -64
  675. package/src/persistence/filelock/acquireFileLock.ts +0 -129
  676. package/src/persistence/filelock/releaseLock.ts +0 -29
  677. package/src/persistence/store.test.ts +0 -102
  678. package/src/persistence/store.ts +0 -119
  679. package/src/persistence/storeApi.ts +0 -19
  680. package/src/reactivity/map.ts +0 -135
  681. package/src/reactivity/solid.test.ts +0 -222
  682. package/src/reactivity/solid.ts +0 -42
  683. package/src/reactivity/trigger.ts +0 -46
  684. package/src/resolve-modules/cache.ts +0 -89
  685. package/src/resolve-modules/errors.ts +0 -69
  686. package/src/resolve-modules/import.test.ts +0 -62
  687. package/src/resolve-modules/import.ts +0 -133
  688. package/src/resolve-modules/index.ts +0 -2
  689. package/src/resolve-modules/message-lint-rules/errors.ts +0 -9
  690. package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +0 -27
  691. package/src/resolve-modules/plugins/errors.ts +0 -56
  692. package/src/resolve-modules/plugins/resolvePlugins.test.ts +0 -301
  693. package/src/resolve-modules/plugins/resolvePlugins.ts +0 -129
  694. package/src/resolve-modules/plugins/types.test.ts +0 -53
  695. package/src/resolve-modules/plugins/types.ts +0 -76
  696. package/src/resolve-modules/resolveModules.test.ts +0 -224
  697. package/src/resolve-modules/resolveModules.ts +0 -113
  698. package/src/resolve-modules/types.ts +0 -72
  699. package/src/resolve-modules/validateModuleSettings.test.ts +0 -85
  700. package/src/resolve-modules/validatedModuleSettings.ts +0 -19
  701. package/src/storage/helper.ts +0 -74
  702. package/src/storage/helpers.test.ts +0 -95
  703. package/src/storage/human-id/human-readable-id.ts +0 -27
  704. package/src/telemetry/capture.ts +0 -49
  705. package/src/telemetry/groupIdentify.ts +0 -41
  706. package/src/test-utilities/createMessage.test.ts +0 -118
  707. package/src/test-utilities/createMessage.ts +0 -21
  708. package/src/test-utilities/index.ts +0 -2
  709. package/src/test-utilities/sleep.ts +0 -11
  710. package/src/v2/helper.test.ts +0 -95
  711. package/src/v2/helper.ts +0 -98
  712. package/src/v2/index.ts +0 -3
  713. package/src/v2/mocks/index.ts +0 -2
  714. package/src/v2/mocks/multipleMatcher/bundle.test.ts +0 -11
  715. package/src/v2/mocks/multipleMatcher/bundle.ts +0 -196
  716. package/src/v2/mocks/plural/bundle.test.ts +0 -18
  717. package/src/v2/mocks/plural/bundle.ts +0 -164
  718. package/src/v2/shim.test.ts +0 -56
  719. package/src/v2/shim.ts +0 -173
  720. package/src/v2/stubQueryApi.ts +0 -43
  721. package/src/v2/types.ts +0 -159
  722. package/src/validateProjectPath.test.ts +0 -50
  723. package/src/validateProjectPath.ts +0 -38
  724. package/src/versionedInterfaces.ts +0 -9
  725. /package/dist/{storage/human-id → human-id}/words.d.ts +0 -0
  726. /package/dist/{storage/human-id → human-id}/words.test.d.ts +0 -0
  727. /package/dist/{loadProject.test.d.ts → project/loadProject.test.d.ts} +0 -0
@@ -0,0 +1,752 @@
1
+ import { newProject } from "./newProject.js";
2
+ import { loadProjectInMemory } from "./loadProjectInMemory.js";
3
+ import { type Lix } from "@lix-js/sdk";
4
+
5
+ import fs from "node:fs";
6
+
7
+ import nodePath from "node:path";
8
+ import type {
9
+ InlangPlugin,
10
+ NodeFsPromisesSubsetLegacy,
11
+ } from "../plugin/schema.js";
12
+ import { fromMessageV1 } from "../json-schema/old-v1-message/fromMessageV1.js";
13
+ import type { ProjectSettings } from "../json-schema/settings.js";
14
+ import type { PreprocessPluginBeforeImportFunction } from "../plugin/importPlugins.js";
15
+ import { PluginImportError } from "../plugin/errors.js";
16
+ import { upsertBundleNestedMatchByProperties } from "../import-export/upsertBundleNestedMatchByProperties.js";
17
+
18
+ /**
19
+ * Loads a project from a directory.
20
+ *
21
+ * Main use case are dev tools that want to load a project from a directory
22
+ * that is stored in git.
23
+ */
24
+ export async function loadProjectFromDirectory(
25
+ args: { path: string; fs: typeof fs; syncInterval?: number } & Omit<
26
+ Parameters<typeof loadProjectInMemory>[0],
27
+ "blob"
28
+ >
29
+ ) {
30
+ const settingsPath = nodePath.join(args.path, "settings.json");
31
+ const settings = JSON.parse(
32
+ await args.fs.promises.readFile(settingsPath, "utf8")
33
+ ) as ProjectSettings;
34
+
35
+ const localImport = await importLocalPlugins({
36
+ fs: args.fs,
37
+ settings,
38
+ path: args.path,
39
+ });
40
+
41
+ const providePluginsWithLocalPlugins = [
42
+ ...(args.providePlugins ?? []),
43
+ ...localImport.locallyImportedPlugins,
44
+ ];
45
+
46
+ // TODO call tempProject.lix.settled() to wait for the new settings file, and remove reload of the proejct as soon as reactive settings has landed
47
+ // NOTE: we need to ensure two things:
48
+ // 1. settled needs to include the changes from the copyFiles call
49
+ // 2. the changes created from the copyFiles call need to be realized and lead to a signal on the settings
50
+ const project = await loadProjectInMemory({
51
+ ...args,
52
+ providePlugins: providePluginsWithLocalPlugins,
53
+ blob: await newProject({
54
+ settings,
55
+ }),
56
+ });
57
+
58
+ await syncLixFsFiles({
59
+ fs: args.fs,
60
+ path: args.path,
61
+ lix: project.lix,
62
+ syncInterval: args.syncInterval,
63
+ });
64
+
65
+ const {
66
+ loadMessagesPlugins,
67
+ saveMessagesPlugins,
68
+ importPlugins,
69
+ exportPlugins,
70
+ } = categorizePlugins(await project.plugins.get());
71
+
72
+ // TODO i guess we should move this validation logic into sdk2/src/project/loadProject.ts
73
+ // Two scenarios could arise:
74
+ // 1. set settings is called from an app - it should detect and reject the setting of settings -> app need to be able to validate before calling set
75
+ // 2. the settings file loaded from disc here is corrupted -> user has to fix the file on disc
76
+ if (loadMessagesPlugins.length > 1 || saveMessagesPlugins.length > 1) {
77
+ throw new Error(
78
+ "Max one loadMessages (found: " +
79
+ loadMessagesPlugins.length +
80
+ ") and one saveMessages plugins (found: " +
81
+ saveMessagesPlugins.length +
82
+ ") are allowed "
83
+ );
84
+ }
85
+ const importedResourceFileErrors: Error[] = [];
86
+
87
+ if (
88
+ (loadMessagesPlugins.length > 0 || saveMessagesPlugins.length > 0) &&
89
+ (exportPlugins.length > 0 || importPlugins.length > 0)
90
+ ) {
91
+ throw new Error(
92
+ "Plugins for loadMessages (found: " +
93
+ loadMessagesPlugins.length +
94
+ ") and saveMessages plugins (found: " +
95
+ saveMessagesPlugins.length +
96
+ ") must not coexist with import (found: " +
97
+ importPlugins.length +
98
+ ") or export (found: " +
99
+ exportPlugins.length +
100
+ ") "
101
+ );
102
+ } else if (loadMessagesPlugins.length > 1 || saveMessagesPlugins.length > 1) {
103
+ throw new Error(
104
+ "Max one loadMessages (found: " +
105
+ loadMessagesPlugins.length +
106
+ ") and one saveMessages plugins (found: " +
107
+ saveMessagesPlugins.length +
108
+ ") are allowed "
109
+ );
110
+ } else if (importPlugins[0]) {
111
+ const importer = importPlugins[0];
112
+ const files = [];
113
+
114
+ if (importer.toBeImportedFiles) {
115
+ const toBeImportedFiles = await importer.toBeImportedFiles({
116
+ settings: await project.settings.get(),
117
+ });
118
+ for (const toBeImported of toBeImportedFiles) {
119
+ const absolute = absolutePathFromProject(args.path, toBeImported.path);
120
+ try {
121
+ const data = await args.fs.promises.readFile(absolute);
122
+ const name = nodePath.basename(toBeImported.path);
123
+ files.push({
124
+ name,
125
+ locale: toBeImported.locale,
126
+ content: data,
127
+ pluginKey: importer.key,
128
+ toBeImportedFilesMetadata: toBeImported.metadata,
129
+ });
130
+ } catch (e) {
131
+ // https://github.com/opral/inlang-sdk/issues/202
132
+ if ((e as any)?.code === "ENOENT") {
133
+ continue;
134
+ }
135
+ importedResourceFileErrors.push(
136
+ new ResourceFileImportError({
137
+ cause: e as Error,
138
+ path: toBeImported.path,
139
+ })
140
+ );
141
+ }
142
+ }
143
+ }
144
+
145
+ await project.importFiles({
146
+ pluginKey: importer.key,
147
+ files: files as any,
148
+ });
149
+ } else if (loadMessagesPlugins[0] !== undefined) {
150
+ // TODO create resource files from loadMessageFn call - to poll?
151
+ await loadLegacyMessages({
152
+ project,
153
+ projectPath: args.path,
154
+ fs: args.fs,
155
+ pluginKey: loadMessagesPlugins[0].key ?? loadMessagesPlugins[0].id,
156
+ loadMessagesFn: loadMessagesPlugins[0].loadMessages,
157
+ });
158
+ }
159
+
160
+ return {
161
+ ...project,
162
+ errors: {
163
+ get: async () => {
164
+ return [...localImport.errors, ...importedResourceFileErrors];
165
+ },
166
+ // subscribe: (
167
+ // callback: Parameters<InlangProject["errors"]["subscribe"]>[0]
168
+ // ) => {
169
+ // return project.errors.subscribe((value) => {
170
+ // callback([
171
+ // ...withLocallyImportedPluginWarning(value),
172
+ // ...localImport.errors,
173
+ // ...importedResourceFileErrors,
174
+ // ]);
175
+ // });
176
+ // },
177
+ },
178
+ };
179
+ }
180
+
181
+ async function loadLegacyMessages(args: {
182
+ project: Awaited<ReturnType<typeof loadProjectInMemory>>;
183
+ pluginKey: NonNullable<InlangPlugin["key"] | InlangPlugin["id"]>;
184
+ loadMessagesFn: Required<InlangPlugin>["loadMessages"];
185
+ projectPath: string;
186
+ fs: typeof fs;
187
+ }) {
188
+ const loadedLegacyMessages = await args.loadMessagesFn({
189
+ settings: await args.project.settings.get(),
190
+ // @ts-expect-error - type mismatch
191
+ nodeishFs: withAbsolutePaths(args.fs.promises, args.projectPath),
192
+ });
193
+ const upsertQueries = [];
194
+
195
+ for (const legacyMessage of loadedLegacyMessages) {
196
+ const messageBundle = fromMessageV1(legacyMessage);
197
+
198
+ upsertQueries.push(
199
+ upsertBundleNestedMatchByProperties(args.project.db, messageBundle)
200
+ );
201
+ }
202
+
203
+ return await Promise.all(upsertQueries);
204
+ }
205
+
206
+ type FsFileState = Record<
207
+ string,
208
+ {
209
+ /*mtime: number, hash: string, */ content: ArrayBuffer;
210
+ state: "known" | "unknown" | "updated" | "gone";
211
+ }
212
+ >;
213
+
214
+ function arrayBuffersEqual(a: ArrayBuffer, b: ArrayBuffer) {
215
+ if (a.byteLength !== b.byteLength) return false;
216
+
217
+ // Create views for byte-by-byte comparison
218
+ const view1 = new Uint8Array(a);
219
+ const view2 = new Uint8Array(b);
220
+
221
+ // Compare each byte
222
+ for (const [i, element] of view1.entries()) {
223
+ if (element !== view2[i]) {
224
+ return false;
225
+ }
226
+ }
227
+
228
+ return true;
229
+ }
230
+
231
+ /**
232
+ * Watches a directory and copies files into lix, keeping them in sync.
233
+ */
234
+ async function syncLixFsFiles(args: {
235
+ fs: typeof fs;
236
+ path: string;
237
+ lix: Lix;
238
+ syncInterval?: number;
239
+ }) {
240
+ // NOTE this function is async - while it runs 100% sync in the naiv implementation - we may want to change to an async version to optimize
241
+ async function checkFsStateRecursive(
242
+ dirPath: string,
243
+ currentState: FsFileState
244
+ ) {
245
+ const entries = args.fs.readdirSync(dirPath, { withFileTypes: true });
246
+
247
+ for (const entry of entries) {
248
+ const fullPath = nodePath.join(dirPath, entry.name);
249
+ if (entry.isDirectory()) {
250
+ checkFsStateRecursive(fullPath, currentState);
251
+ } else {
252
+ // NOTE we could start with comparing the mdate and skip file read completely...
253
+ const data = args.fs.readFileSync(fullPath) as unknown as ArrayBuffer;
254
+
255
+ const relativePath = "/" + nodePath.relative(args.path, fullPath);
256
+
257
+ if (!currentState[relativePath]) {
258
+ currentState[relativePath] = {
259
+ content: data,
260
+ state: "unknown",
261
+ };
262
+ } else {
263
+ if (arrayBuffersEqual(currentState[relativePath].content, data)) {
264
+ currentState[relativePath].state = "known";
265
+ } else {
266
+ currentState[relativePath].state = "updated";
267
+ currentState[relativePath].content = data;
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+
274
+ async function checkLixState(currentLixState: FsFileState) {
275
+ // go through all files in lix and check there state
276
+ const filesInLix = await args.lix.db
277
+ .selectFrom("file")
278
+ .where("path", "not like", "%db.sqlite")
279
+ .selectAll()
280
+ .execute();
281
+
282
+ for (const fileInLix of filesInLix) {
283
+ const currentStateOfFileInLix = currentLixState[fileInLix.path];
284
+ // NOTE we could start with comparing the mdate and skip file read completely...
285
+ if (!currentStateOfFileInLix) {
286
+ currentLixState[fileInLix.path] = {
287
+ content: new Uint8Array(fileInLix.data).buffer,
288
+ state: "unknown",
289
+ };
290
+ } else {
291
+ if (
292
+ arrayBuffersEqual(
293
+ currentStateOfFileInLix.content,
294
+ fileInLix.data.buffer as ArrayBuffer
295
+ )
296
+ ) {
297
+ currentStateOfFileInLix.state = "known";
298
+ } else {
299
+ currentStateOfFileInLix.state = "updated";
300
+ currentStateOfFileInLix.content = fileInLix.data
301
+ .buffer as ArrayBuffer;
302
+ }
303
+ }
304
+ }
305
+ }
306
+
307
+ async function syncUpFsAndLixFiles(statesToSync: {
308
+ fsFileStates: FsFileState;
309
+ lixFileStates: FsFileState;
310
+ }) {
311
+ // for (const file of Object.keys(statesToSync.fsFileStates)) {
312
+ // if (file.includes("gitignore"))
313
+ // console.log(
314
+ // "fsFileStates : " +
315
+ // file +
316
+ // " fs " +
317
+ // statesToSync.fsFileStates[file]?.state +
318
+ // " lix " +
319
+ // statesToSync.lixFileStates[file]?.state
320
+ // );
321
+ // }
322
+
323
+ // Sync cases:
324
+ // fs - no state for file | fs - unkonwn | fs - known | fs - updated | fs - gone
325
+ // lix - no state for file NOTHING (1) | ADD TO LIX(2) | ERROR (3) | ERROR (4) | ERROR (5)
326
+ // lix - unknown ADD TO FS (6) | USE FS VER.(7) | ERROR (8) | CASE (9) | CASE (10)
327
+ // lix - known ERROR (11) | ERROR (12) | NOTHING(13) | ERROR (14) | ERROR (15)
328
+ // lix - updated ERROR (16) | ERROR (17) | USE LIX (18) | CASE (19) | CASE (20)
329
+ // lix - gone ERROR (21) | ERROR (22) | DELETE FS (23)| CASE (24) | CASE (25)
330
+
331
+ // TODO check export import from saveFileToDirectory
332
+
333
+ for (const [path, fsState] of Object.entries(statesToSync.fsFileStates)) {
334
+ // no state for file in LIX
335
+ if (!statesToSync.lixFileStates[path]) {
336
+ if (fsState.state === "unknown") {
337
+ // ADD TO LIX(2)
338
+ await upsertFileInLix(args, path, fsState.content);
339
+ statesToSync.lixFileStates[path] = {
340
+ state: "known",
341
+ content: fsState.content,
342
+ };
343
+ fsState.state = "known";
344
+ } else {
345
+ // ERROR (3), ERROR (4), ERROR (5)
346
+ // The file does not exist in lix but its state differs from unknown?
347
+ throw new Error(
348
+ "Illeagal lix<->fs sync state. The file [" +
349
+ path +
350
+ "] that was " +
351
+ fsState.state +
352
+ " on disc did not exit in lix"
353
+ );
354
+ }
355
+ } else {
356
+ const lixState = statesToSync.lixFileStates[path];
357
+ if (fsState.state === "unknown") {
358
+ if (lixState.state === "unknown") {
359
+ if (arrayBuffersEqual(lixState.content, fsState.content)) {
360
+ lixState.state = "known";
361
+ fsState.state = "known";
362
+ } else {
363
+ await upsertFileInLix(args, path, fsState.content);
364
+ lixState.content = fsState.content;
365
+ lixState.state = "known";
366
+ fsState.state = "known";
367
+ }
368
+ } else {
369
+ // ERROR 12, 17, 22
370
+ throw new Error(
371
+ "Illeagal lix<->fs sync state. The file [" +
372
+ path +
373
+ "] that was " +
374
+ fsState.state +
375
+ " but did exist in lix already"
376
+ );
377
+ }
378
+ } else if (fsState.state === "known") {
379
+ if (lixState.state === "known") {
380
+ // NO OP - NOTHING(13)
381
+ } else if (lixState.state === "updated") {
382
+ // USE LIX (18)
383
+ args.fs.writeFileSync(
384
+ // TODO check platform dependent folder separator
385
+ args.path + path,
386
+ Buffer.from(lixState.content)
387
+ );
388
+ fsState.content = lixState.content;
389
+ fsState.state = "known";
390
+ lixState.state = "known";
391
+ } else if (lixState.state === "gone") {
392
+ // DELETE FS (23)
393
+ args.fs.unlinkSync(args.path + path);
394
+ fsState.state = "gone";
395
+ lixState.state = "gone";
396
+ }
397
+ } else if (fsState.state === "updated") {
398
+ if (lixState.state === "unknown") {
399
+ // TODO A file was added to lix while a known file from fs was updated?
400
+ throw new Error(
401
+ "Illeagal lix<->fs sync state. The file [" +
402
+ path +
403
+ "] that was " +
404
+ fsState.state +
405
+ " but it was not known by lix yet?"
406
+ );
407
+ } else if (lixState.state === "known") {
408
+ await upsertFileInLix(args, path, fsState.content);
409
+ lixState.content = fsState.content;
410
+
411
+ fsState.state = "known";
412
+ } else if (lixState.state === "updated") {
413
+ // seems like we saw an update on the file in fs while some changes on lix have not been reached fs? FS -> Winns?
414
+ console.warn(
415
+ "seems like we saw an update on the file " +
416
+ path +
417
+ " in fs while some changes on lix have not been reached fs? FS -> Winns?"
418
+ );
419
+ await upsertFileInLix(args, path, fsState.content);
420
+ lixState.content = fsState.content;
421
+ lixState.state = "known";
422
+ fsState.state = "known";
423
+ } else if (lixState.state === "gone") {
424
+ console.warn(
425
+ "seems like we saw an delete in lix while some changes on fs have not been reached fs? FS -> Winns?"
426
+ );
427
+ // TODO update the lix state
428
+ lixState.content = fsState.content;
429
+ lixState.state = "known";
430
+ fsState.state = "known";
431
+ }
432
+ } else if (fsState.state === "gone") {
433
+ if (lixState.state === "unknown") {
434
+ // TODO A file was added to lix while a known file from fs was removed?
435
+ throw new Error(
436
+ "Illeagal lix<->fs sync state. The file [" +
437
+ path +
438
+ "] that was " +
439
+ fsState.state +
440
+ " but it was not known by lix yet?"
441
+ );
442
+ } else if (lixState.state === "known") {
443
+ // file is in known state with lix - means we have only changes on the fs - easy
444
+ await args.lix.db
445
+ .deleteFrom("file")
446
+ .where("path", "=", path)
447
+ .execute();
448
+ // NOTE: states where both are gone will get removed in the lix state loop
449
+ lixState.state = "gone";
450
+ } else if (lixState.state === "updated") {
451
+ // seems like we saw an update on the file in fs while some changes on lix have not been reached fs? FS -> Winns?
452
+ console.warn(
453
+ "seems like we saw an update on the file in fs while some changes on lix have not been reached fs? FS -> Winns?"
454
+ );
455
+ await args.lix.db
456
+ .deleteFrom("file")
457
+ .where("path", "=", path)
458
+ .execute();
459
+ // NOTE: states where both are gone will get removed in the lix state loop
460
+ lixState.state = "gone";
461
+ fsState.state = "gone";
462
+ } else if (lixState.state === "gone") {
463
+ console.warn(
464
+ "seems like we saw an delete in lix while we have a delete in lix simultaniously?"
465
+ );
466
+ lixState.state = "gone";
467
+ fsState.state = "gone";
468
+ }
469
+ }
470
+ }
471
+ }
472
+
473
+ for (const [path, lixState] of Object.entries(statesToSync.lixFileStates)) {
474
+ // no state for file in fs
475
+ if (!statesToSync.fsFileStates[path]) {
476
+ if (lixState.state == "unknown") {
477
+ // ADD TO FS (6)
478
+ // create directory if not exists
479
+ args.fs.mkdirSync(nodePath.dirname(nodePath.join(args.path, path)), {
480
+ recursive: true,
481
+ });
482
+ // write file
483
+ args.fs.writeFileSync(
484
+ nodePath.join(args.path, path),
485
+ Buffer.from(lixState.content)
486
+ );
487
+ statesToSync.fsFileStates[path] = {
488
+ state: "known",
489
+ content: lixState.content,
490
+ };
491
+ } else {
492
+ // ERROR (11) 16 21
493
+ // The file does not exist on fs but its state differs from unknown?
494
+ throw new Error(
495
+ "Illeagal lix<->fs sync state. The file [" +
496
+ path +
497
+ "] that was in the state" +
498
+ lixState.state +
499
+ " for lix did not exist on disk"
500
+ );
501
+ }
502
+ } else {
503
+ if (
504
+ lixState.state === "gone" &&
505
+ statesToSync.fsFileStates[path].state === "gone"
506
+ ) {
507
+ delete statesToSync.lixFileStates[path];
508
+ delete statesToSync.fsFileStates[path];
509
+ } else if (lixState.state !== statesToSync.fsFileStates[path].state) {
510
+ throw new Error(
511
+ "At this stage both states should be in sync lix state " +
512
+ lixState.state +
513
+ " fs state " +
514
+ statesToSync.fsFileStates[path].state
515
+ );
516
+ }
517
+ }
518
+ }
519
+ }
520
+
521
+ async function syncFiles(
522
+ dirPath: string,
523
+ fileStates: {
524
+ lixFileStates: FsFileState;
525
+ fsFileStates: FsFileState;
526
+ },
527
+ interval?: number
528
+ ) {
529
+ // mark all states as removed - checkFsStateRecursive will update those that exist on the disc correspondingly
530
+ for (const fsState of Object.values(fileStates.fsFileStates)) {
531
+ fsState.state = "gone";
532
+ }
533
+
534
+ // mark all states as removed - checkFsStateRecursive will update those that exist on the disc correspondingly
535
+ for (const lixState of Object.values(fileStates.lixFileStates)) {
536
+ lixState.state = "gone";
537
+ }
538
+
539
+ // read states from disc - detect changes
540
+ await checkFsStateRecursive(dirPath, fileStates.fsFileStates);
541
+
542
+ // read states form lix - detect changes
543
+ await checkLixState(fileStates.lixFileStates);
544
+
545
+ // sync fs<->lix
546
+ await syncUpFsAndLixFiles(fileStates);
547
+
548
+ if (interval) {
549
+ setTimeout(() => {
550
+ syncFiles(dirPath, fileStates, interval);
551
+ }, interval);
552
+ }
553
+
554
+ return;
555
+ }
556
+
557
+ // Initial copy of all files
558
+ await syncFiles(
559
+ args.path,
560
+ { fsFileStates: {}, lixFileStates: {} },
561
+ args.syncInterval
562
+ );
563
+
564
+ return;
565
+ }
566
+
567
+ async function upsertFileInLix(
568
+ args: { fs: typeof fs; path: string; lix: Lix },
569
+ path: string,
570
+ data: ArrayBuffer
571
+ ) {
572
+ // file is in known state with lix - means we have only changes on the fs - easy
573
+ // NOTE we use file_internal for now see: https://linear.app/opral/issue/LIXDK-102/re-visit-simplifying-the-change-queue-implementation#comment-65eb3485
574
+ // This means we don't see changes for the file we update via this method!
575
+ await args.lix.db
576
+ .insertInto("file") // change queue
577
+ .values({
578
+ path: path,
579
+ data: new Uint8Array(data),
580
+ })
581
+ .onConflict((oc) =>
582
+ oc.column("path").doUpdateSet({ data: new Uint8Array(data) })
583
+ )
584
+ .execute();
585
+ }
586
+
587
+ // TODO i guess we should move this validation logic into sdk2/src/project/loadProject.ts
588
+ function categorizePlugins(plugins: readonly InlangPlugin[]): {
589
+ loadMessagesPlugins: (InlangPlugin &
590
+ Required<Pick<InlangPlugin, "loadMessages">>)[];
591
+ saveMessagesPlugins: (InlangPlugin &
592
+ Required<Pick<InlangPlugin, "saveMessages">>)[];
593
+ importPlugins: (InlangPlugin &
594
+ Required<Pick<InlangPlugin, "importFiles" | "toBeImportedFiles">>)[];
595
+ exportPlugins: (InlangPlugin & Required<Pick<InlangPlugin, "exportFiles">>)[];
596
+ } {
597
+ const loadMessagesPlugins = plugins.filter(
598
+ (
599
+ plugin
600
+ ): plugin is InlangPlugin & Required<Pick<InlangPlugin, "loadMessages">> =>
601
+ plugin.loadMessages !== undefined
602
+ );
603
+
604
+ const saveMessagesPlugins = plugins.filter(
605
+ (
606
+ plugin
607
+ ): plugin is InlangPlugin & Required<Pick<InlangPlugin, "saveMessages">> =>
608
+ plugin.saveMessages !== undefined
609
+ );
610
+
611
+ const importPlugins = plugins.filter(
612
+ (
613
+ plugin
614
+ ): plugin is InlangPlugin &
615
+ Required<Pick<InlangPlugin, "importFiles" | "toBeImportedFiles">> =>
616
+ plugin.importFiles !== undefined && plugin.toBeImportedFiles !== undefined
617
+ );
618
+
619
+ const exportPlugins = plugins.filter(
620
+ (
621
+ plugin
622
+ ): plugin is InlangPlugin & Required<Pick<InlangPlugin, "exportFiles">> =>
623
+ plugin.exportFiles !== undefined
624
+ );
625
+
626
+ return {
627
+ loadMessagesPlugins,
628
+ saveMessagesPlugins,
629
+ importPlugins,
630
+ exportPlugins,
631
+ };
632
+ }
633
+
634
+ /**
635
+ * Imports local plugins for backwards compatibility.
636
+ *
637
+ * https://github.com/opral/inlang-sdk/issues/171
638
+ */
639
+ async function importLocalPlugins(args: {
640
+ fs: typeof fs;
641
+ settings: ProjectSettings;
642
+ path: string;
643
+ preprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;
644
+ }) {
645
+ const errors: Error[] = [];
646
+ const locallyImportedPlugins = [];
647
+ for (const module of args.settings.modules ?? []) {
648
+ if (module.startsWith("http")) {
649
+ continue;
650
+ }
651
+ const modulePath = absolutePathFromProject(args.path, module);
652
+ try {
653
+ let moduleAsText = await args.fs.promises.readFile(modulePath, "utf8");
654
+ if (moduleAsText.includes("messageLintRule")) {
655
+ errors.push(new WarningDeprecatedLintRule(module));
656
+ continue;
657
+ }
658
+ if (args.preprocessPluginBeforeImport) {
659
+ moduleAsText = await args.preprocessPluginBeforeImport(moduleAsText);
660
+ }
661
+ const moduleWithMimeType =
662
+ "data:application/javascript," + encodeURIComponent(moduleAsText);
663
+ const { default: plugin } = await import(
664
+ /* @vite-ignore */ moduleWithMimeType
665
+ );
666
+ locallyImportedPlugins.push(plugin);
667
+ } catch (e) {
668
+ errors.push(new PluginImportError({ plugin: module, cause: e as Error }));
669
+ continue;
670
+ }
671
+ }
672
+ return {
673
+ errors,
674
+ locallyImportedPlugins,
675
+ };
676
+ }
677
+
678
+ export class WarningDeprecatedLintRule extends Error {
679
+ constructor(module: string) {
680
+ super(
681
+ `The lint rule ${module} is deprecated. Please remove the lint rule from the settings. Lint rules are interim built into apps and will be succeeded by more generilizable lix validation rules.`
682
+ );
683
+ this.name = "WarningDeprecatedLintRule";
684
+ }
685
+ }
686
+
687
+ /**
688
+ * Resolving absolute paths for fs functions.
689
+ *
690
+ * This mapping is required for backwards compatibility.
691
+ * Relative paths in the project.inlang/settings.json
692
+ * file are resolved to absolute paths with `*.inlang`
693
+ * being pruned.
694
+ *
695
+ * @example
696
+ * "/website/project.inlang"
697
+ * "./local-plugins/mock-plugin.js"
698
+ * -> "/website/local-plugins/mock-plugin.js"
699
+ *
700
+ */
701
+ export function withAbsolutePaths(
702
+ fs: NodeFsPromisesSubsetLegacy,
703
+ projectPath: string
704
+ ): NodeFsPromisesSubsetLegacy {
705
+ return {
706
+ // @ts-expect-error - node type mismatch
707
+ readFile: (path, options) => {
708
+ return fs.readFile(absolutePathFromProject(projectPath, path), options);
709
+ },
710
+ writeFile: (path, data) => {
711
+ return fs.writeFile(absolutePathFromProject(projectPath, path), data);
712
+ },
713
+ mkdir: (path) => {
714
+ return fs.mkdir(absolutePathFromProject(projectPath, path));
715
+ },
716
+ readdir: (path) => {
717
+ return fs.readdir(absolutePathFromProject(projectPath, path));
718
+ },
719
+ };
720
+ }
721
+
722
+ /**
723
+ * Joins a path from a project path.
724
+ *
725
+ * @example
726
+ * joinPathFromProject("/project.inlang", "./local-plugins/mock-plugin.js") -> "/local-plugins/mock-plugin.js"
727
+ *
728
+ * joinPathFromProject("/website/project.inlang", "./mock-plugin.js") -> "/website/mock-plugin.js"
729
+ */
730
+ export function absolutePathFromProject(projectPath: string, path: string) {
731
+ // need to remove the project path from the module path for legacy reasons
732
+ // "/project.inlang/local-plugins/mock-plugin.js" -> "/local-plugins/mock-plugin.js"
733
+ const pathWithoutProject = projectPath
734
+ .split(nodePath.sep)
735
+ .slice(0, -1)
736
+ .join(nodePath.sep);
737
+
738
+ const resolvedPath = nodePath.resolve(pathWithoutProject, path);
739
+
740
+ return resolvedPath;
741
+ }
742
+
743
+ export class ResourceFileImportError extends Error {
744
+ path: string;
745
+
746
+ constructor(args: { cause: Error; path: string }) {
747
+ super("Could not import a resource file");
748
+ this.name = "ResourceFileImportError";
749
+ this.cause = args.cause;
750
+ this.path = args.path;
751
+ }
752
+ }