@inlang/sdk 2.0.0 → 2.1.0

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 (44) hide show
  1. package/dist/json-schema/settings.d.ts +8 -10
  2. package/dist/json-schema/settings.d.ts.map +1 -1
  3. package/dist/json-schema/settings.js +4 -27
  4. package/dist/json-schema/settings.js.map +1 -1
  5. package/dist/json-schema/settings.test.d.ts +2 -0
  6. package/dist/json-schema/settings.test.d.ts.map +1 -0
  7. package/dist/json-schema/settings.test.js +26 -0
  8. package/dist/json-schema/settings.test.js.map +1 -0
  9. package/dist/plugin/importPlugins.test.js +2 -3
  10. package/dist/plugin/importPlugins.test.js.map +1 -1
  11. package/dist/project/loadProject.d.ts.map +1 -1
  12. package/dist/project/loadProject.js +13 -15
  13. package/dist/project/loadProject.js.map +1 -1
  14. package/dist/project/loadProjectFromDirectory.d.ts +2 -1
  15. package/dist/project/loadProjectFromDirectory.d.ts.map +1 -1
  16. package/dist/project/loadProjectFromDirectory.js +41 -53
  17. package/dist/project/loadProjectFromDirectory.js.map +1 -1
  18. package/dist/project/loadProjectFromDirectory.test.js +95 -4
  19. package/dist/project/loadProjectFromDirectory.test.js.map +1 -1
  20. package/dist/project/newProject.d.ts.map +1 -1
  21. package/dist/project/newProject.js +3 -3
  22. package/dist/project/newProject.js.map +1 -1
  23. package/dist/project/saveProjectToDirectory.d.ts.map +1 -1
  24. package/dist/project/saveProjectToDirectory.js +9 -2
  25. package/dist/project/saveProjectToDirectory.js.map +1 -1
  26. package/dist/project/saveProjectToDirectory.test.js +15 -2
  27. package/dist/project/saveProjectToDirectory.test.js.map +1 -1
  28. package/dist/services/env-variables/index.js +3 -3
  29. package/dist/services/env-variables/index.js.map +1 -1
  30. package/package.json +4 -5
  31. package/src/json-schema/settings.test.ts +26 -0
  32. package/src/json-schema/settings.ts +3 -36
  33. package/src/plugin/importPlugins.test.ts +0 -1
  34. package/src/project/loadProject.ts +15 -15
  35. package/src/project/loadProjectFromDirectory.test.ts +116 -2
  36. package/src/project/loadProjectFromDirectory.ts +49 -98
  37. package/src/project/newProject.ts +5 -1
  38. package/src/project/saveProjectToDirectory.test.ts +20 -0
  39. package/src/project/saveProjectToDirectory.ts +11 -1
  40. package/dist/project/initHandleSaveToLixOnChange.d.ts +0 -14
  41. package/dist/project/initHandleSaveToLixOnChange.d.ts.map +0 -1
  42. package/dist/project/initHandleSaveToLixOnChange.js +0 -87
  43. package/dist/project/initHandleSaveToLixOnChange.js.map +0 -1
  44. package/src/project/initHandleSaveToLixOnChange.ts +0 -93
@@ -1,4 +1,4 @@
1
- import { type Static, type TLiteral } from "@sinclair/typebox";
1
+ import { type Static } from "@sinclair/typebox";
2
2
  export type ProjectSettings = Omit<Static<typeof ProjectSettings>, "languageTags" | "sourceLanguageTag"> & {
3
3
  /** @deprecated Use `baseLocale` */
4
4
  sourceLanguageTag?: string;
@@ -6,9 +6,9 @@ export type ProjectSettings = Omit<Static<typeof ProjectSettings>, "languageTags
6
6
  languageTags?: string[];
7
7
  /** @deprecated This will soon be replaced by `Lix Validation Rules` */
8
8
  messageLintRuleLevels?: Record<string, "error" | "warning">;
9
- };
10
- export declare const ProjectSettings: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
11
- $schema: import("@sinclair/typebox").TOptional<TLiteral<"https://inlang.com/schema/project-settings">>;
9
+ } & Record<string, any>;
10
+ export declare const ProjectSettings: import("@sinclair/typebox").TObject<{
11
+ $schema: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"https://inlang.com/schema/project-settings">>;
12
12
  baseLocale: import("@sinclair/typebox").TString;
13
13
  locales: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
14
14
  sourceLanguageTag: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -22,10 +22,8 @@ export declare const ProjectSettings: import("@sinclair/typebox").TIntersect<[im
22
22
  * "https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js",
23
23
  * ]
24
24
  */
25
- modules: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>>>;
26
- telemetry: import("@sinclair/typebox").TOptional<TLiteral<"off">>;
27
- experimental: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, TLiteral<true>>>;
28
- }>, import("@sinclair/typebox").TObject<{
29
- [x: `plugin.${string}`]: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>;
30
- }>]>;
25
+ modules: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>>>;
26
+ telemetry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"off">>;
27
+ experimental: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TLiteral<true>>>;
28
+ }>;
31
29
  //# sourceMappingURL=settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,MAAM,EAGX,KAAK,QAAQ,EACb,MAAM,mBAAmB,CAAC;AAyH3B,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,MAAM,CAAC,OAAO,eAAe,CAAC,EAC9B,cAAc,GAAG,mBAAmB,CACpC,GAAG;IACH,mCAAmC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5D,CAAC;AACF,eAAO,MAAM,eAAe;;;;;;IAjG3B;;;;;;;;OAQG;;;;;;IAyF0E,CAAC"}
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AA6FtD,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,MAAM,CAAC,OAAO,eAAe,CAAC,EAC9B,cAAc,GAAG,mBAAmB,CACpC,GAAG;IACH,mCAAmC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5D,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACxB,eAAO,MAAM,eAAe;;;;;;IArE3B;;;;;;;;OAQG;;;;EA6DsC,CAAC"}
@@ -1,6 +1,6 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="50e23702-3eef-5ae9-8af9-b048fa48d2c6")}catch(e){}}();
3
- import { Type, } from "@sinclair/typebox";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0ab441fa-e6ed-5327-b6ba-da781e2b1e94")}catch(e){}}();
3
+ import { Type } from "@sinclair/typebox";
4
4
  const SDKSettings = Type.Object({
5
5
  // TODO SDK-v2 SETTINGS do we need to generate a settings v2 schema?
6
6
  $schema: Type.Optional(Type.Literal("https://inlang.com/schema/project-settings")),
@@ -44,10 +44,6 @@ const SDKSettings = Type.Object({
44
44
  description: "The module must end with `.js`.",
45
45
  pattern: ".*\\.js$",
46
46
  }),
47
- Type.String({
48
- description: "The module can only contain a major version number.",
49
- pattern: "^(?!.*@\\d\\.)[^]*$",
50
- }),
51
47
  ]), {
52
48
  uniqueItems: true,
53
49
  description: "The modules to load. Must be a valid URI but can be relative.",
@@ -72,25 +68,6 @@ const SDKSettings = Type.Object({
72
68
  * The plugin settings are validated when importing plugins
73
69
  */
74
70
  });
75
- /**
76
- * Settings defined via apps, plugins, lint rules, etc.
77
- *
78
- * Using external settings to only allow `plugin.*` keys
79
- * and don't block the SDK from adding new settings.
80
- */
81
- const ExternalSettings = Type.Record(Type.String({
82
- pattern: `^((plugin)\\.([a-z][a-zA-Z0-9]*(?:[A-Z][a-z0-9]*)*)|\\$schema|${
83
- // pattern must include the settings properties
84
- Object.keys(SDKSettings.properties)
85
- .map((key) => key.replaceAll(".", "\\."))
86
- .join("|")})$`,
87
- description: "The key must be conform to `plugin.*`.",
88
- examples: ["plugin.csv-importer", "plugin.i18next"],
89
- }),
90
- // Using JSON (array and object) as a workaround to make the
91
- // intersection between `InternalSettings`, which contains an array,
92
- // and `ExternalSettings` which are objects possible
93
- Type.Record(Type.String(), Type.Any()), { description: "Settings defined by apps, plugins, etc." });
94
- export const ProjectSettings = Type.Intersect([SDKSettings, ExternalSettings]);
71
+ export const ProjectSettings = SDKSettings;
95
72
  //# sourceMappingURL=settings.js.map
96
- //# debugId=50e23702-3eef-5ae9-8af9-b048fa48d2c6
73
+ //# debugId=0ab441fa-e6ed-5327-b6ba-da781e2b1e94
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sources":["json-schema/settings.ts"],"sourceRoot":"/","sourcesContent":["import {\n\ttype Static,\n\tType,\n\ttype TTemplateLiteral,\n\ttype TLiteral,\n} from \"@sinclair/typebox\";\n\nconst SDKSettings = Type.Object({\n\t// TODO SDK-v2 SETTINGS do we need to generate a settings v2 schema?\n\t$schema: Type.Optional(\n\t\tType.Literal(\"https://inlang.com/schema/project-settings\")\n\t),\n\tbaseLocale: Type.String({\n\t\ttitle: \"Base locale\",\n\t\tdescription:\n\t\t\t\"The base locale of the project. We recommend BCP-47 language tags.\",\n\t}),\n\tlocales: Type.Array(Type.String(), {\n\t\tuniqueItems: true,\n\t\ttitle: \"Project Locales\",\n\t\tdescription:\n\t\t\t\"Set the locales that are available in your project. All locales needs to be a valid BCP-47 language tag. Needs to include the base locale tag.\",\n\t}),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tsourceLanguageTag: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Use baseLocale instead.\",\n\t\t\tdeprecated: true,\n\t\t})\n\t),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tlanguageTags: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tuniqueItems: true,\n\t\t\tdeprecated: true,\n\t\t\tdescription: \"Use locales instead.\",\n\t\t})\n\t),\n\t/**\n\t * The modules to load.\n\t *\n\t * @example\n\t * modules: [\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t * ]\n\t */\n\tmodules: Type.Optional(\n\t\tType.Array(\n\t\t\tType.Intersect([\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must be a valid URI according to RFC 3986.\",\n\t\t\t\t\tpattern:\n\t\t\t\t\t\t\"(?:[A-Za-z][A-Za-z0-9+.-]*:/{2})?(?:(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})+(?::([A-Za-z0-9-._~]?|[%][A-Fa-f0-9]{2})+)?@)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\\\.){1,126}[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?::[0-9]+)?(?:/(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})*)*(?:\\\\?(?:[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)(?:&|;[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)*)?\",\n\t\t\t\t}),\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must end with `.js`.\",\n\t\t\t\t\tpattern: \".*\\\\.js$\",\n\t\t\t\t}),\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module can only contain a major version number.\",\n\t\t\t\t\tpattern: \"^(?!.*@\\\\d\\\\.)[^]*$\",\n\t\t\t\t}),\n\t\t\t]),\n\t\t\t{\n\t\t\t\tuniqueItems: true,\n\t\t\t\tdescription:\n\t\t\t\t\t\"The modules to load. Must be a valid URI but can be relative.\",\n\t\t\t\texamples: [\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t\t\t\t\t\"./local-testing-plugin.js\",\n\t\t\t\t],\n\t\t\t}\n\t\t)\n\t),\n\ttelemetry: Type.Optional(\n\t\tType.Union(\n\t\t\t[\n\t\t\t\tType.Literal(\"off\", {\n\t\t\t\t\tdescription: \"No telemetry events \",\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ description: \"If not set, defaults to all\" }\n\t\t)\n\t),\n\texperimental: Type.Optional(\n\t\tType.Record(Type.String(), Type.Literal(true), {\n\t\t\ttitle: \"Experimental settings\",\n\t\t\tdescription:\n\t\t\t\t\"Experimental settings that are used for product development.\",\n\t\t})\n\t),\n\t/**\n\t * plugin.*: JSONObject\n\t *\n\t * The plugin settings are validated when importing plugins\n\t */\n});\n\n/**\n * Settings defined via apps, plugins, lint rules, etc.\n *\n * Using external settings to only allow `plugin.*` keys\n * and don't block the SDK from adding new settings.\n */\nconst ExternalSettings = Type.Record(\n\tType.String({\n\t\tpattern: `^((plugin)\\\\.([a-z][a-zA-Z0-9]*(?:[A-Z][a-z0-9]*)*)|\\\\$schema|${\n\t\t\t// pattern must include the settings properties\n\t\t\tObject.keys(SDKSettings.properties)\n\t\t\t\t.map((key) => key.replaceAll(\".\", \"\\\\.\"))\n\t\t\t\t.join(\"|\")\n\t\t})$`,\n\t\tdescription: \"The key must be conform to `plugin.*`.\",\n\t\texamples: [\"plugin.csv-importer\", \"plugin.i18next\"],\n\t}) as unknown as TTemplateLiteral<[TLiteral<`${\"plugin\"}.${string}`>]>,\n\t// Using JSON (array and object) as a workaround to make the\n\t// intersection between `InternalSettings`, which contains an array,\n\t// and `ExternalSettings` which are objects possible\n\tType.Record(Type.String(), Type.Any()),\n\t{ description: \"Settings defined by apps, plugins, etc.\" }\n);\n\nexport type ProjectSettings = Omit<\n\tStatic<typeof ProjectSettings>,\n\t\"languageTags\" | \"sourceLanguageTag\"\n> & {\n\t/** @deprecated Use `baseLocale` */\n\tsourceLanguageTag?: string;\n\t/** @deprecated Use `locales` */\n\tlanguageTags?: string[];\n\t/** @deprecated This will soon be replaced by `Lix Validation Rules` */\n\tmessageLintRuleLevels?: Record<string, \"error\" | \"warning\">;\n};\nexport const ProjectSettings = Type.Intersect([SDKSettings, ExternalSettings]);\n"],"names":[],"mappings":";;AAAA,OAAO,EAEN,IAAI,GAGJ,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,oEAAoE;IACpE,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAC1D;IACD,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;QACvB,KAAK,EAAE,aAAa;QACpB,WAAW,EACV,oEAAoE;KACrE,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QAClC,WAAW,EAAE,IAAI;QACjB,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACV,gJAAgJ;KACjJ,CAAC;I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AC,IAAI,CAAC,EAAE;QAC9C,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EACV,8DAA8D;KAC/D,CAAC,CACF;IACD;;;;OAIG;CACH,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CACnC,IAAI,CAAC,MAAM,CAAC;IACX,OAAO,EAAE,iEAAiE;IACzE,+CAA+C;IAC/C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC;SACjC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;SACxC,IAAI,CAAC,GAAG,CACX,IAAI;IACJ,WAAW,EAAE,wCAAwC;IACrD,QAAQ,EAAE,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;CACnD,CAAqE;AACtE,4DAA4D;AAC5D,oEAAoE;AACpE,oDAAoD;AACpD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,EACtC,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAC1D,CAAC;AAaF,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC","debug_id":"50e23702-3eef-5ae9-8af9-b048fa48d2c6"}
1
+ {"version":3,"file":"settings.js","sources":["json-schema/settings.ts"],"sourceRoot":"/","sourcesContent":["import { type Static, Type } from \"@sinclair/typebox\";\n\nconst SDKSettings = Type.Object({\n\t// TODO SDK-v2 SETTINGS do we need to generate a settings v2 schema?\n\t$schema: Type.Optional(\n\t\tType.Literal(\"https://inlang.com/schema/project-settings\")\n\t),\n\tbaseLocale: Type.String({\n\t\ttitle: \"Base locale\",\n\t\tdescription:\n\t\t\t\"The base locale of the project. We recommend BCP-47 language tags.\",\n\t}),\n\tlocales: Type.Array(Type.String(), {\n\t\tuniqueItems: true,\n\t\ttitle: \"Project Locales\",\n\t\tdescription:\n\t\t\t\"Set the locales that are available in your project. All locales needs to be a valid BCP-47 language tag. Needs to include the base locale tag.\",\n\t}),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tsourceLanguageTag: Type.Optional(\n\t\tType.String({\n\t\t\tdescription: \"Use baseLocale instead.\",\n\t\t\tdeprecated: true,\n\t\t})\n\t),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tlanguageTags: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tuniqueItems: true,\n\t\t\tdeprecated: true,\n\t\t\tdescription: \"Use locales instead.\",\n\t\t})\n\t),\n\t/**\n\t * The modules to load.\n\t *\n\t * @example\n\t * modules: [\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t * ]\n\t */\n\tmodules: Type.Optional(\n\t\tType.Array(\n\t\t\tType.Intersect([\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must be a valid URI according to RFC 3986.\",\n\t\t\t\t\tpattern:\n\t\t\t\t\t\t\"(?:[A-Za-z][A-Za-z0-9+.-]*:/{2})?(?:(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})+(?::([A-Za-z0-9-._~]?|[%][A-Fa-f0-9]{2})+)?@)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\\\.){1,126}[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?::[0-9]+)?(?:/(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})*)*(?:\\\\?(?:[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)(?:&|;[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)*)?\",\n\t\t\t\t}),\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must end with `.js`.\",\n\t\t\t\t\tpattern: \".*\\\\.js$\",\n\t\t\t\t}),\n\t\t\t]),\n\t\t\t{\n\t\t\t\tuniqueItems: true,\n\t\t\t\tdescription:\n\t\t\t\t\t\"The modules to load. Must be a valid URI but can be relative.\",\n\t\t\t\texamples: [\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t\t\t\t\t\"./local-testing-plugin.js\",\n\t\t\t\t],\n\t\t\t}\n\t\t)\n\t),\n\ttelemetry: Type.Optional(\n\t\tType.Union(\n\t\t\t[\n\t\t\t\tType.Literal(\"off\", {\n\t\t\t\t\tdescription: \"No telemetry events \",\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ description: \"If not set, defaults to all\" }\n\t\t)\n\t),\n\texperimental: Type.Optional(\n\t\tType.Record(Type.String(), Type.Literal(true), {\n\t\t\ttitle: \"Experimental settings\",\n\t\t\tdescription:\n\t\t\t\t\"Experimental settings that are used for product development.\",\n\t\t})\n\t),\n\t/**\n\t * plugin.*: JSONObject\n\t *\n\t * The plugin settings are validated when importing plugins\n\t */\n});\n\nexport type ProjectSettings = Omit<\n\tStatic<typeof ProjectSettings>,\n\t\"languageTags\" | \"sourceLanguageTag\"\n> & {\n\t/** @deprecated Use `baseLocale` */\n\tsourceLanguageTag?: string;\n\t/** @deprecated Use `locales` */\n\tlanguageTags?: string[];\n\t/** @deprecated This will soon be replaced by `Lix Validation Rules` */\n\tmessageLintRuleLevels?: Record<string, \"error\" | \"warning\">;\n} & Record<string, any>;\nexport const ProjectSettings = SDKSettings;\n"],"names":[],"mappings":";;AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,oEAAoE;IACpE,OA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QACC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACnB,WAAW,EAAE,sBAAsB;SACnC,CAAC;KACF,EACD,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAC9C,CACD;IACD,YAAY,EAAE,IAAI,CAAC,QAAQ,CAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9C,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EACV,8DAA8D;KAC/D,CAAC,CACF;IACD;;;;OAIG;CACH,CAAC,CAAC;AAaH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC","debug_id":"0ab441fa-e6ed-5327-b6ba-da781e2b1e94"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=settings.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.test.d.ts","sourceRoot":"/","sources":["json-schema/settings.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9b1af2ee-57bc-53aa-87a7-58e094655f60")}catch(e){}}();
3
+ import { TypeCompiler } from "@sinclair/typebox/compiler";
4
+ import { ProjectSettings } from "./settings.js";
5
+ import { test, expect } from "vitest";
6
+ const C = TypeCompiler.Compile(ProjectSettings);
7
+ test("valid settings file", () => {
8
+ const settings = {
9
+ baseLocale: "en",
10
+ locales: ["en", "de"],
11
+ modules: [
12
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js",
13
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js",
14
+ ],
15
+ "plugin.something": {
16
+ key: "value",
17
+ nested: {
18
+ moreNested: {},
19
+ },
20
+ },
21
+ };
22
+ const errors = [...C.Errors(settings)];
23
+ expect(errors).toEqual([]);
24
+ });
25
+ //# sourceMappingURL=settings.test.js.map
26
+ //# debugId=9b1af2ee-57bc-53aa-87a7-58e094655f60
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.test.js","sources":["json-schema/settings.test.ts"],"sourceRoot":"/","sourcesContent":["import { TypeCompiler } from \"@sinclair/typebox/compiler\";\nimport { ProjectSettings } from \"./settings.js\";\nimport { test, expect } from \"vitest\";\n\nconst C = TypeCompiler.Compile(ProjectSettings);\n\ntest(\"valid settings file\", () => {\n\tconst settings: ProjectSettings = {\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tmodules: [\n\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t\t],\n\t\t\"plugin.something\": {\n\t\t\tkey: \"value\",\n\t\t\tnested: {\n\t\t\t\tmoreNested: {},\n\t\t\t},\n\t\t},\n\t};\n\n\tconst errors = [...C.Errors(settings)];\n\n\texpect(errors).toEqual([]);\n});\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAEhD,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAChC,MAAM,QAAQ,GAAoB;QACjC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;QACrB,OAAO,EAAE;YACR,qEAAqE;YACrE,iEAAiE;SACjE;QACD,kBAAkB,EAAE;YACnB,GAAG,EAAE,OAAO;YACZ,MAAM,EAAE;gBACP,UAAU,EAAE,EAAE;aACd;SACD;KACD,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC","debug_id":"9b1af2ee-57bc-53aa-87a7-58e094655f60"}
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="df00fa76-3eb4-5842-9f9d-4f593257ee7e")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d56eea49-1483-5227-ae80-1f01de298ace")}catch(e){}}();
3
3
  import { test, expect, vi } from "vitest";
4
4
  import { importPlugins } from "./importPlugins.js";
5
5
  import { PluginImportError } from "./errors.js";
@@ -21,7 +21,6 @@ test("it should preprocess a plugin", async () => {
21
21
  return moduleText.replace("mock", "preprocessed");
22
22
  },
23
23
  });
24
- expect(global.fetch).toHaveBeenCalledTimes(1);
25
24
  expect(result.plugins.length).toBe(1);
26
25
  expect(result.errors.length).toBe(0);
27
26
  expect(result.plugins[0]?.key).toBe("preprocessed");
@@ -92,4 +91,4 @@ test("cache should work", async () => {
92
91
  expect(result.plugins[0]?.key).toBe("mock");
93
92
  });
94
93
  //# sourceMappingURL=importPlugins.test.js.map
95
- //# debugId=df00fa76-3eb4-5842-9f9d-4f593257ee7e
94
+ //# debugId=d56eea49-1483-5227-ae80-1f01de298ace
@@ -1 +1 @@
1
- {"version":3,"file":"importPlugins.test.js","sources":["plugin/importPlugins.test.ts"],"sourceRoot":"/","sourcesContent":["import { test, expect, vi } from \"vitest\";\nimport { importPlugins } from \"./importPlugins.js\";\nimport { PluginImportError } from \"./errors.js\";\nimport { newLixFile, openLixInMemory } from \"@lix-js/sdk\";\n\ntest(\"it should preprocess a plugin\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: true,\n\t\ttext: vi.fn().mockResolvedValue(\"export default { key: 'mock' }\"),\n\t});\n\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [\"https://mock.com/module.js\"],\n\t\t},\n\t\tpreprocessPluginBeforeImport: async (moduleText) => {\n\t\t\treturn moduleText.replace(\"mock\", \"preprocessed\");\n\t\t},\n\t});\n\n\texpect(global.fetch).toHaveBeenCalledTimes(1);\n\texpect(result.plugins.length).toBe(1);\n\texpect(result.errors.length).toBe(0);\n\texpect(result.plugins[0]?.key).toBe(\"preprocessed\");\n});\n\ntest(\"if a fetch fails, a plugin import error is expected\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: false,\n\t\tstatusText: \"HTTP 404\",\n\t});\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [\"https://mock.com/module.js\"],\n\t\t},\n\t});\n\n\texpect(global.fetch).toHaveBeenCalledTimes(1);\n\texpect(result.plugins.length).toBe(0);\n\texpect(result.errors.length).toBe(1);\n\texpect(result.errors[0]).toBeInstanceOf(PluginImportError);\n});\n\ntest(\"it should filter message lint rules for legacy reasons\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: true,\n\t\ttext: vi\n\t\t\t.fn()\n\t\t\t.mockResolvedValue(\"export default { id: 'messageLintRule.something' }\"),\n\t});\n\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [\"https://mock.com/module.js\"],\n\t\t},\n\t});\n\n\texpect(result.plugins.length).toBe(0);\n\texpect(result.errors.length).toBe(0);\n});\n\n// more tests are found in cache.test.ts\ntest(\"cache should work\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: false,\n\t});\n\n\tconst mockModulePath = \"https://mock.com/module.js\";\n\tconst mockModuleCachePath = \"/cache/plugins/31i1etp0l413h\";\n\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\tawait lix.db\n\t\t.insertInto(\"file\")\n\t\t.values({\n\t\t\tpath: mockModuleCachePath,\n\t\t\tdata: new TextEncoder().encode(\"export default { key: 'mock' }\"),\n\t\t})\n\t\t.execute();\n\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [mockModulePath],\n\t\t},\n\t});\n\n\texpect(result.errors).lengthOf(0);\n\texpect(result.plugins).lengthOf(1);\n\texpect(result.plugins[0]?.key).toBe(\"mock\");\n});\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,IAAI,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;IAChD,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QACxC,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,gCAAgC,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,mBAAmB,EAAE,KAAK,IAAI,EAAE;IACpC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QACxC,EAAE,EAAE,KAAK;KACT,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,4BAA4B,CAAC;IACpD,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;IAE3D,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,UAAU,EAAE,EAAE,CAAC,CAAC;IAEhE,MAAM,GAAG,CAAC,EAAE;SACV,UAAU,CAAC,MAAM,CAAC;SAClB,MAAM,CAAC;QACP,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gCAAgC,CAAC;KAChE,CAAC;SACD,OAAO,EAAE,CAAC;IAEZ,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;QAClC,GAAG;QACH,QAAQ,EAAE;YACT,UAAU,EAAE,IAAI;YAChB,OAAO,EAAE,CAAC,IAAI,CAAC;YACf,OAAO,EAAE,CAAC,cAAc,CAAC;SACzB;KACD,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC,CAAC,CAAC","debug_id":"df00fa76-3eb4-5842-9f9d-4f593257ee7e"}
1
+ {"version":3,"file":"importPlugins.test.js","sources":["plugin/importPlugins.test.ts"],"sourceRoot":"/","sourcesContent":["import { test, expect, vi } from \"vitest\";\nimport { importPlugins } from \"./importPlugins.js\";\nimport { PluginImportError } from \"./errors.js\";\nimport { newLixFile, openLixInMemory } from \"@lix-js/sdk\";\n\ntest(\"it should preprocess a plugin\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: true,\n\t\ttext: vi.fn().mockResolvedValue(\"export default { key: 'mock' }\"),\n\t});\n\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [\"https://mock.com/module.js\"],\n\t\t},\n\t\tpreprocessPluginBeforeImport: async (moduleText) => {\n\t\t\treturn moduleText.replace(\"mock\", \"preprocessed\");\n\t\t},\n\t});\n\n\texpect(result.plugins.length).toBe(1);\n\texpect(result.errors.length).toBe(0);\n\texpect(result.plugins[0]?.key).toBe(\"preprocessed\");\n});\n\ntest(\"if a fetch fails, a plugin import error is expected\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: false,\n\t\tstatusText: \"HTTP 404\",\n\t});\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [\"https://mock.com/module.js\"],\n\t\t},\n\t});\n\n\texpect(global.fetch).toHaveBeenCalledTimes(1);\n\texpect(result.plugins.length).toBe(0);\n\texpect(result.errors.length).toBe(1);\n\texpect(result.errors[0]).toBeInstanceOf(PluginImportError);\n});\n\ntest(\"it should filter message lint rules for legacy reasons\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: true,\n\t\ttext: vi\n\t\t\t.fn()\n\t\t\t.mockResolvedValue(\"export default { id: 'messageLintRule.something' }\"),\n\t});\n\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [\"https://mock.com/module.js\"],\n\t\t},\n\t});\n\n\texpect(result.plugins.length).toBe(0);\n\texpect(result.errors.length).toBe(0);\n});\n\n// more tests are found in cache.test.ts\ntest(\"cache should work\", async () => {\n\tglobal.fetch = vi.fn().mockResolvedValue({\n\t\tok: false,\n\t});\n\n\tconst mockModulePath = \"https://mock.com/module.js\";\n\tconst mockModuleCachePath = \"/cache/plugins/31i1etp0l413h\";\n\n\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\tawait lix.db\n\t\t.insertInto(\"file\")\n\t\t.values({\n\t\t\tpath: mockModuleCachePath,\n\t\t\tdata: new TextEncoder().encode(\"export default { key: 'mock' }\"),\n\t\t})\n\t\t.execute();\n\n\tconst result = await importPlugins({\n\t\tlix,\n\t\tsettings: {\n\t\t\tbaseLocale: \"en\",\n\t\t\tlocales: [\"en\"],\n\t\t\tmodules: [mockModulePath],\n\t\t},\n\t});\n\n\texpect(result.errors).lengthOf(0);\n\texpect(result.plugins).lengthOf(1);\n\texpect(result.plugins[0]?.key).toBe(\"mock\");\n});\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,IAAI,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;IAChD,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QACxC,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,gCAAgC,CAAC;KACjE,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,UAAU,EAAE,E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AAE,MAAM,UAAU,CAAC;AAQ9C;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,GAAG,CAAC;IACT;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC;;;;;;;;;;;OAWG;IACH,4BAA4B,CAAC,EAAE,oCAAoC,CAAC;IACpE;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,aAAa,CAAC,CA8JzB"}
1
+ {"version":3,"file":"loadProject.d.ts","sourceRoot":"/","sources":["project/loadProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,EAEN,KAAK,oCAAoC,EACzC,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQ9C;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,GAAG,CAAC;IACT;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC;;;;;;;;;;;OAWG;IACH,4BAA4B,CAAC,EAAE,oCAAoC,CAAC;IACpE;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,aAAa,CAAC,CAmJzB"}
@@ -1,9 +1,8 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ed6fb309-3e32-52c8-87d0-1d450e0d29b9")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="04d161fd-6b88-5635-ba17-bbbf2ce627e1")}catch(e){}}();
3
3
  import { toBlob } from "@lix-js/sdk";
4
- import {} from "sqlite-wasm-kysely";
4
+ import { contentFromDatabase } from "sqlite-wasm-kysely";
5
5
  import { initDb } from "../database/initDb.js";
6
- import { initHandleSaveToLixOnChange } from "./initHandleSaveToLixOnChange.js";
7
6
  import { importPlugins, } from "../plugin/importPlugins.js";
8
7
  import { withLanguageTagToLocaleMigration } from "../migrations/v2/withLanguageTagToLocaleMigration.js";
9
8
  import { v4 } from "uuid";
@@ -39,16 +38,6 @@ export async function loadProject(args) {
39
38
  // ...args,
40
39
  // settings,
41
40
  // });
42
- // TODO implement garbage collection/a proper queue.
43
- // for the protoype and tests, it seems good enough
44
- // without garbage collection of old promises.
45
- const pendingSaveToLixPromises = [];
46
- await initHandleSaveToLixOnChange({
47
- sqlite: args.sqlite,
48
- db,
49
- lix: args.lix,
50
- pendingPromises: pendingSaveToLixPromises,
51
- });
52
41
  // not awaiting to not block the load time of a project
53
42
  maybeCaptureLoadedProject({
54
43
  db,
@@ -132,17 +121,26 @@ export async function loadProject(args) {
132
121
  })).map((output) => ({ ...output, pluginKey }));
133
122
  },
134
123
  close: async () => {
124
+ await saveDbToLix({ sqlite: args.sqlite, lix: args.lix });
135
125
  await db.destroy();
136
126
  await args.lix.db.destroy();
137
127
  },
138
128
  _sqlite: args.sqlite,
139
129
  toBlob: async () => {
140
- await Promise.all(pendingSaveToLixPromises);
130
+ await saveDbToLix({ sqlite: args.sqlite, lix: args.lix });
141
131
  return await toBlob({ lix: args.lix });
142
132
  },
143
133
  lix: args.lix,
144
134
  };
145
135
  }
136
+ async function saveDbToLix(args) {
137
+ const data = contentFromDatabase(args.sqlite);
138
+ await args.lix.db
139
+ .updateTable("file")
140
+ .set("data", data)
141
+ .where("path", "=", "/db.sqlite")
142
+ .execute();
143
+ }
146
144
  /**
147
145
  * Old leftover migration from v1. Probably not needed anymore.
148
146
  *
@@ -165,4 +163,4 @@ async function maybeMigrateFirstProjectId(args) {
165
163
  }
166
164
  }
167
165
  //# sourceMappingURL=loadProject.js.map
168
- //# debugId=ed6fb309-3e32-52c8-87d0-1d450e0d29b9
166
+ //# debugId=04d161fd-6b88-5635-ba17-bbbf2ce627e1
@@ -1 +1 @@
1
- {"version":3,"file":"loadProject.js","sources":["project/loadProject.ts"],"sourceRoot":"/","sourcesContent":["import { toBlob, type Account, type Lix } from \"@lix-js/sdk\";\nimport type { InlangPlugin } from \"../plugin/schema.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport { type SqliteDatabase } from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\nimport { initHandleSaveToLixOnChange } from \"./initHandleSaveToLixOnChange.js\";\nimport {\n\timportPlugins,\n\ttype PreprocessPluginBeforeImportFunction,\n} from \"../plugin/importPlugins.js\";\nimport type { InlangProject } from \"./api.js\";\nimport { withLanguageTagToLocaleMigration } from \"../migrations/v2/withLanguageTagToLocaleMigration.js\";\nimport { v4 } from \"uuid\";\nimport { initErrorReporting } from \"../services/error-reporting/index.js\";\nimport { maybeCaptureLoadedProject } from \"./maybeCaptureTelemetry.js\";\nimport { importFiles } from \"../import-export/importFiles.js\";\nimport { exportFiles } from \"../import-export/exportFiles.js\";\n\n/**\n * Common load project logic.\n */\nexport async function loadProject(args: {\n\tsqlite: SqliteDatabase;\n\tlix: Lix;\n\t/**\n\t * The account that loaded the project.\n\t *\n\t * Defaults to an anonymous/new account if undefined.\n\t *\n\t * @example\n\t * const account = localStorage.getItem(\"account\")\n\t * const project = await loadProject({ account })\n\t */\n\taccount?: Account;\n\t/**\n\t * Provide plugins to the project.\n\t *\n\t * This is useful for testing or providing plugins that are\n\t * app specific. Keep in mind that provided plugins\n\t * are not shared with other instances.\n\t */\n\tprovidePlugins?: InlangPlugin[];\n\t/**\n\t * Function that preprocesses the plugin before importing it.\n\t *\n\t * The callback can be used to process plugins as needed in the\n\t * environment of the app. For example, Sherlock uses this to convert\n\t * ESM, which all inlang plugins are written in, to CJS which Sherlock\n\t * runs in.\n\t *\n\t * @example\n\t * const project = await loadProject({ preprocessPluginBeforeImport: (moduleText) => convertEsmToCjs(moduleText) })\n\t *\n\t */\n\tpreprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;\n\t/**\n\t * The id of the app that is using the SDK.\n\t *\n\t * The is used for telemetry purposes. To derive insights like\n\t * which app is using the SDK, how many projects are loaded, etc.\n\t *\n\t * The app id can be removed at any time in the future\n\t */\n\tappId?: string;\n}): Promise<InlangProject> {\n\tconst db = initDb({ sqlite: args.sqlite });\n\n\tawait maybeMigrateFirstProjectId({ lix: args.lix });\n\n\tconst settingsFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst settings = withLanguageTagToLocaleMigration(\n\t\tJSON.parse(new TextDecoder().decode(settingsFile.data)) as ProjectSettings\n\t);\n\n\tconst importedPlugins = await importPlugins({\n\t\tsettings,\n\t\tlix: args.lix,\n\t\tpreprocessPluginBeforeImport: args.preprocessPluginBeforeImport,\n\t});\n\n\tconst plugins = [...(args.providePlugins ?? []), ...importedPlugins.plugins];\n\n\tconst idFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.select(\"data\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst id = new TextDecoder().decode(idFile.data);\n\n\t// const state = createProjectState({\n\t// \t...args,\n\t// \tsettings,\n\t// });\n\n\t// TODO implement garbage collection/a proper queue.\n\t// for the protoype and tests, it seems good enough\n\t// without garbage collection of old promises.\n\tconst pendingSaveToLixPromises: Promise<unknown>[] = [];\n\n\tawait initHandleSaveToLixOnChange({\n\t\tsqlite: args.sqlite,\n\t\tdb,\n\t\tlix: args.lix,\n\t\tpendingPromises: pendingSaveToLixPromises,\n\t});\n\n\t// not awaiting to not block the load time of a project\n\tmaybeCaptureLoadedProject({\n\t\tdb,\n\t\tid,\n\t\tsettings,\n\t\tplugins,\n\t\tlix: args.lix,\n\t\tappId: args.appId,\n\t});\n\n\tinitErrorReporting({ projectId: id });\n\n\treturn {\n\t\tdb,\n\t\tid: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn new TextDecoder().decode(file.data);\n\t\t\t},\n\t\t},\n\t\tsettings: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn withLanguageTagToLocaleMigration(\n\t\t\t\t\tJSON.parse(new TextDecoder().decode(file.data))\n\t\t\t\t);\n\t\t\t},\n\t\t\tset: async (newSettings) => {\n\t\t\t\tconst cloned = JSON.parse(JSON.stringify(newSettings));\n\t\t\t\tcloned.languageTags = cloned.locales;\n\t\t\t\tcloned.sourceLanguageTag = cloned.baseLocale;\n\n\t\t\t\tawait args.lix.db\n\t\t\t\t\t.updateTable(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.set({\n\t\t\t\t\t\tdata: new TextEncoder().encode(\n\t\t\t\t\t\t\tJSON.stringify(cloned, undefined, 2)\n\t\t\t\t\t\t),\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t},\n\t\t},\n\t\tplugins: {\n\t\t\tget: async () => plugins,\n\t\t},\n\t\terrors: {\n\t\t\tget: async () => [...importedPlugins.errors],\n\t\t},\n\t\t// errors: state.errors,\n\t\timportFiles: async ({ files, pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn await importFiles({\n\t\t\t\tfiles,\n\t\t\t\tpluginKey,\n\t\t\t\tsettings,\n\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\tplugins,\n\t\t\t\tdb,\n\t\t\t});\n\t\t},\n\t\texportFiles: async ({ pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn (\n\t\t\t\tawait exportFiles({\n\t\t\t\t\tpluginKey,\n\t\t\t\t\tdb,\n\t\t\t\t\tsettings,\n\t\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\t\tplugins,\n\t\t\t\t})\n\t\t\t).map((output) => ({ ...output, pluginKey }));\n\t\t},\n\t\tclose: async () => {\n\t\t\tawait db.destroy();\n\t\t\tawait args.lix.db.destroy();\n\t\t},\n\t\t_sqlite: args.sqlite,\n\t\ttoBlob: async () => {\n\t\t\tawait Promise.all(pendingSaveToLixPromises);\n\t\t\treturn await toBlob({ lix: args.lix });\n\t\t},\n\t\tlix: args.lix,\n\t};\n}\n\n/**\n * Old leftover migration from v1. Probably not needed anymore.\n *\n * Kept it in just in case.\n */\nasync function maybeMigrateFirstProjectId(args: { lix: Lix }): Promise<void> {\n\tconst firstProjectIdFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.executeTakeFirst();\n\n\tif (!firstProjectIdFile) {\n\t\tawait args.lix.db\n\t\t\t.insertInto(\"file\")\n\t\t\t.values({\n\t\t\t\tpath: \"/project_id\",\n\t\t\t\tdata: new TextEncoder().encode(v4()),\n\t\t\t})\n\t\t\t.execute();\n\t}\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAA0B,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAuB,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EACN,aAAa,GAEb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IA2CjC;IACA,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAE3C,MAAM,0BAA0B,CAAC,EAAE,GAAG,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E,CAAC;QACzB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;aACf,UAAU,CAAC,MAAM,CAAC;aAClB,MAAM,CAAC;YACP,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;SACpC,CAAC;aACD,OAAO,EAAE,CAAC;IACb,CAAC;AACF,CAAC","debug_id":"ed6fb309-3e32-52c8-87d0-1d450e0d29b9"}
1
+ {"version":3,"file":"loadProject.js","sources":["project/loadProject.ts"],"sourceRoot":"/","sourcesContent":["import { toBlob, type Account, type Lix } from \"@lix-js/sdk\";\nimport type { InlangPlugin } from \"../plugin/schema.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport { contentFromDatabase, type SqliteDatabase } from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\nimport {\n\timportPlugins,\n\ttype PreprocessPluginBeforeImportFunction,\n} from \"../plugin/importPlugins.js\";\nimport type { InlangProject } from \"./api.js\";\nimport { withLanguageTagToLocaleMigration } from \"../migrations/v2/withLanguageTagToLocaleMigration.js\";\nimport { v4 } from \"uuid\";\nimport { initErrorReporting } from \"../services/error-reporting/index.js\";\nimport { maybeCaptureLoadedProject } from \"./maybeCaptureTelemetry.js\";\nimport { importFiles } from \"../import-export/importFiles.js\";\nimport { exportFiles } from \"../import-export/exportFiles.js\";\n\n/**\n * Common load project logic.\n */\nexport async function loadProject(args: {\n\tsqlite: SqliteDatabase;\n\tlix: Lix;\n\t/**\n\t * The account that loaded the project.\n\t *\n\t * Defaults to an anonymous/new account if undefined.\n\t *\n\t * @example\n\t * const account = localStorage.getItem(\"account\")\n\t * const project = await loadProject({ account })\n\t */\n\taccount?: Account;\n\t/**\n\t * Provide plugins to the project.\n\t *\n\t * This is useful for testing or providing plugins that are\n\t * app specific. Keep in mind that provided plugins\n\t * are not shared with other instances.\n\t */\n\tprovidePlugins?: InlangPlugin[];\n\t/**\n\t * Function that preprocesses the plugin before importing it.\n\t *\n\t * The callback can be used to process plugins as needed in the\n\t * environment of the app. For example, Sherlock uses this to convert\n\t * ESM, which all inlang plugins are written in, to CJS which Sherlock\n\t * runs in.\n\t *\n\t * @example\n\t * const project = await loadProject({ preprocessPluginBeforeImport: (moduleText) => convertEsmToCjs(moduleText) })\n\t *\n\t */\n\tpreprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;\n\t/**\n\t * The id of the app that is using the SDK.\n\t *\n\t * The is used for telemetry purposes. To derive insights like\n\t * which app is using the SDK, how many projects are loaded, etc.\n\t *\n\t * The app id can be removed at any time in the future\n\t */\n\tappId?: string;\n}): Promise<InlangProject> {\n\tconst db = initDb({ sqlite: args.sqlite });\n\n\tawait maybeMigrateFirstProjectId({ lix: args.lix });\n\n\tconst settingsFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst settings = withLanguageTagToLocaleMigration(\n\t\tJSON.parse(new TextDecoder().decode(settingsFile.data)) as ProjectSettings\n\t);\n\n\tconst importedPlugins = await importPlugins({\n\t\tsettings,\n\t\tlix: args.lix,\n\t\tpreprocessPluginBeforeImport: args.preprocessPluginBeforeImport,\n\t});\n\n\tconst plugins = [...(args.providePlugins ?? []), ...importedPlugins.plugins];\n\n\tconst idFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.select(\"data\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst id = new TextDecoder().decode(idFile.data);\n\n\t// const state = createProjectState({\n\t// \t...args,\n\t// \tsettings,\n\t// });\n\n\t// not awaiting to not block the load time of a project\n\tmaybeCaptureLoadedProject({\n\t\tdb,\n\t\tid,\n\t\tsettings,\n\t\tplugins,\n\t\tlix: args.lix,\n\t\tappId: args.appId,\n\t});\n\n\tinitErrorReporting({ projectId: id });\n\n\treturn {\n\t\tdb,\n\t\tid: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn new TextDecoder().decode(file.data);\n\t\t\t},\n\t\t},\n\t\tsettings: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn withLanguageTagToLocaleMigration(\n\t\t\t\t\tJSON.parse(new TextDecoder().decode(file.data))\n\t\t\t\t);\n\t\t\t},\n\t\t\tset: async (newSettings) => {\n\t\t\t\tconst cloned = JSON.parse(JSON.stringify(newSettings));\n\t\t\t\tcloned.languageTags = cloned.locales;\n\t\t\t\tcloned.sourceLanguageTag = cloned.baseLocale;\n\n\t\t\t\tawait args.lix.db\n\t\t\t\t\t.updateTable(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.set({\n\t\t\t\t\t\tdata: new TextEncoder().encode(\n\t\t\t\t\t\t\tJSON.stringify(cloned, undefined, 2)\n\t\t\t\t\t\t),\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t},\n\t\t},\n\t\tplugins: {\n\t\t\tget: async () => plugins,\n\t\t},\n\t\terrors: {\n\t\t\tget: async () => [...importedPlugins.errors],\n\t\t},\n\t\t// errors: state.errors,\n\t\timportFiles: async ({ files, pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn await importFiles({\n\t\t\t\tfiles,\n\t\t\t\tpluginKey,\n\t\t\t\tsettings,\n\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\tplugins,\n\t\t\t\tdb,\n\t\t\t});\n\t\t},\n\t\texportFiles: async ({ pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn (\n\t\t\t\tawait exportFiles({\n\t\t\t\t\tpluginKey,\n\t\t\t\t\tdb,\n\t\t\t\t\tsettings,\n\t\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\t\tplugins,\n\t\t\t\t})\n\t\t\t).map((output) => ({ ...output, pluginKey }));\n\t\t},\n\t\tclose: async () => {\n\t\t\tawait saveDbToLix({ sqlite: args.sqlite, lix: args.lix });\n\t\t\tawait db.destroy();\n\t\t\tawait args.lix.db.destroy();\n\t\t},\n\t\t_sqlite: args.sqlite,\n\t\ttoBlob: async () => {\n\t\t\tawait saveDbToLix({ sqlite: args.sqlite, lix: args.lix });\n\t\t\treturn await toBlob({ lix: args.lix });\n\t\t},\n\t\tlix: args.lix,\n\t};\n}\n\nasync function saveDbToLix(args: {\n\tsqlite: SqliteDatabase;\n\tlix: Lix;\n}): Promise<void> {\n\tconst data = contentFromDatabase(args.sqlite);\n\tawait args.lix.db\n\t\t.updateTable(\"file\")\n\t\t.set(\"data\", data)\n\t\t.where(\"path\", \"=\", \"/db.sqlite\")\n\t\t.execute();\n}\n\n/**\n * Old leftover migration from v1. Probably not needed anymore.\n *\n * Kept it in just in case.\n */\nasync function maybeMigrateFirstProjectId(args: { lix: Lix }): Promise<void> {\n\tconst firstProjectIdFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.executeTakeFirst();\n\n\tif (!firstProjectIdFile) {\n\t\tawait args.lix.db\n\t\t\t.insertInto(\"file\")\n\t\t\t.values({\n\t\t\t\tpath: \"/project_id\",\n\t\t\t\tdata: new TextEncoder().encode(v4()),\n\t\t\t})\n\t\t\t.execute();\n\t}\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAA0B,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAuB,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EACN,aAAa,GAEb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IA2CjC;IACA,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAE3C,MAAM,0BAA0B,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAEpD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;SACpC,UAAU,CAAC,MAAM,CAAC;SAClB,MAAM,CAAC,MAAM,CAAC;SACd,KAAK,CAAC,MAAM,EAAE,GAAG,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gB,EAAE,CAAC;IAErB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACzB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;aACf,UAAU,CAAC,MAAM,CAAC;aAClB,MAAM,CAAC;YACP,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;SACpC,CAAC;aACD,OAAO,EAAE,CAAC;IACb,CAAC;AACF,CAAC","debug_id":"04d161fd-6b88-5635-ba17-bbbf2ce627e1"}
@@ -3,6 +3,7 @@ import { type Lix } from "@lix-js/sdk";
3
3
  import fs from "node:fs";
4
4
  import type { InlangPlugin, NodeFsPromisesSubsetLegacy } from "../plugin/schema.js";
5
5
  import type { ProjectSettings } from "../json-schema/settings.js";
6
+ import type { ImportFile } from "./api.js";
6
7
  /**
7
8
  * Loads a project from a directory.
8
9
  *
@@ -32,7 +33,7 @@ export declare function loadProjectFromDirectory(args: {
32
33
  lix: Lix;
33
34
  importFiles: (args: {
34
35
  pluginKey: InlangPlugin["key"];
35
- files: import("./api.js").ImportFile[];
36
+ files: ImportFile[];
36
37
  }) => Promise<void>;
37
38
  exportFiles: (args: {
38
39
  pluginKey: InlangPlugin["key"];
@@ -1 +1 @@
1
- {"version":3,"file":"loadProjectFromDirectory.d.ts","sourceRoot":"/","sources":["project/loadProjectFromDirectory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,OAAO,KAAK,EACX,YAAY,EACZ,0BAA0B,EAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAKlE;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC7C,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAA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AAG,IAAI,CAClE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,EACzC,MAAM,CACN;;;;;;;;;;;;;;;;;;;;;;;;;;GA0HD;AAgeD,qBAAa,yBAA0B,SAAQ,KAAK;gBACvC,MAAM,EAAE,MAAM;CAM1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAChC,EAAE,EAAE,0BAA0B,EAC9B,WAAW,EAAE,MAAM,GACjB,0BAA0B,CAgB5B;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAWxE;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CAMhD"}
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a707cbbf-d9cd-5dca-9279-55823fc96f37")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9b967a64-af81-5add-8c9c-b28c569a5321")}catch(e){}}();
3
3
  import { newProject } from "./newProject.js";
4
4
  import { loadProjectInMemory } from "./loadProjectInMemory.js";
5
5
  import {} from "@lix-js/sdk";
@@ -43,55 +43,34 @@ export async function loadProjectFromDirectory(args) {
43
43
  lix: project.lix,
44
44
  syncInterval: args.syncInterval,
45
45
  });
46
- const { loadMessagesPlugins, saveMessagesPlugins, importPlugins, exportPlugins, } = categorizePlugins(await project.plugins.get());
46
+ const allPlugins = await project.plugins.get();
47
+ const { loadSavePlugins, importExportPlugins } = categorizePlugins(allPlugins);
47
48
  // TODO i guess we should move this validation logic into sdk2/src/project/loadProject.ts
48
49
  // Two scenarios could arise:
49
50
  // 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
50
51
  // 2. the settings file loaded from disc here is corrupted -> user has to fix the file on disc
51
- if (loadMessagesPlugins.length > 1 || saveMessagesPlugins.length > 1) {
52
+ if (loadSavePlugins.length > 1) {
52
53
  throw new Error("Max one loadMessages (found: " +
53
- loadMessagesPlugins.length +
54
+ loadSavePlugins.length +
54
55
  ") and one saveMessages plugins (found: " +
55
- saveMessagesPlugins.length +
56
+ loadSavePlugins.length +
56
57
  ") are allowed ");
57
58
  }
58
59
  const importedResourceFileErrors = [];
59
- if ((loadMessagesPlugins.length > 0 || saveMessagesPlugins.length > 0) &&
60
- (exportPlugins.length > 0 || importPlugins.length > 0)) {
61
- throw new Error("Plugins for loadMessages (found: " +
62
- loadMessagesPlugins.length +
63
- ") and saveMessages plugins (found: " +
64
- saveMessagesPlugins.length +
65
- ") must not coexist with import (found: " +
66
- importPlugins.length +
67
- ") or export (found: " +
68
- exportPlugins.length +
69
- ") ");
70
- }
71
- else if (loadMessagesPlugins.length > 1 || saveMessagesPlugins.length > 1) {
72
- throw new Error("Max one loadMessages (found: " +
73
- loadMessagesPlugins.length +
74
- ") and one saveMessages plugins (found: " +
75
- saveMessagesPlugins.length +
76
- ") are allowed ");
77
- }
78
- else if (importPlugins[0]) {
79
- const importer = importPlugins[0];
60
+ // import files from local fs
61
+ for (const plugin of importExportPlugins) {
80
62
  const files = [];
81
- if (importer.toBeImportedFiles) {
82
- const toBeImportedFiles = await importer.toBeImportedFiles({
63
+ if (plugin.toBeImportedFiles) {
64
+ const toBeImportedFiles = await plugin.toBeImportedFiles({
83
65
  settings: await project.settings.get(),
84
66
  });
85
67
  for (const toBeImported of toBeImportedFiles) {
86
68
  const absolute = absolutePathFromProject(args.path, toBeImported.path);
87
69
  try {
88
70
  const data = await args.fs.promises.readFile(absolute);
89
- const name = nodePath.basename(toBeImported.path);
90
71
  files.push({
91
- name,
92
72
  locale: toBeImported.locale,
93
73
  content: data,
94
- pluginKey: importer.key,
95
74
  toBeImportedFilesMetadata: toBeImported.metadata,
96
75
  });
97
76
  }
@@ -108,18 +87,17 @@ export async function loadProjectFromDirectory(args) {
108
87
  }
109
88
  }
110
89
  await project.importFiles({
111
- pluginKey: importer.key,
112
- files: files,
90
+ pluginKey: plugin.key,
91
+ files,
113
92
  });
114
93
  }
115
- else if (loadMessagesPlugins[0] !== undefined) {
116
- // TODO create resource files from loadMessageFn call - to poll?
94
+ for (const plugin of loadSavePlugins) {
117
95
  await loadLegacyMessages({
118
96
  project,
97
+ pluginKey: plugin.key ?? plugin.id,
98
+ loadMessagesFn: plugin.loadMessages,
119
99
  projectPath: args.path,
120
100
  fs: args.fs,
121
- pluginKey: loadMessagesPlugins[0].key ?? loadMessagesPlugins[0].id,
122
- loadMessagesFn: loadMessagesPlugins[0].loadMessages,
123
101
  });
124
102
  }
125
103
  return {
@@ -454,30 +432,40 @@ async function syncLixFsFiles(args) {
454
432
  return;
455
433
  }
456
434
  async function upsertFileInLix(args, path, data) {
457
- // file is in known state with lix - means we have only changes on the fs - easy
458
- // NOTE we use file_internal for now see: https://linear.app/opral/issue/LIXDK-102/re-visit-simplifying-the-change-queue-implementation#comment-65eb3485
459
- // This means we don't see changes for the file we update via this method!
435
+ // force posix path when upserting into lix
436
+ // https://github.com/opral/inlang-sdk/issues/229
437
+ let posixPath = path.split(nodePath.win32.sep).join(nodePath.posix.sep);
438
+ if (posixPath.startsWith("/") === false) {
439
+ posixPath = "/" + posixPath;
440
+ }
460
441
  await args.lix.db
461
442
  .insertInto("file") // change queue
462
443
  .values({
463
- path: path,
444
+ path: posixPath,
464
445
  data: new Uint8Array(data),
465
446
  })
466
447
  .onConflict((oc) => oc.column("path").doUpdateSet({ data: new Uint8Array(data) }))
467
448
  .execute();
468
449
  }
469
- // TODO i guess we should move this validation logic into sdk2/src/project/loadProject.ts
450
+ /**
451
+ * Filters legacy load and save messages plugins.
452
+ *
453
+ * Legacy plugins are plugins that implement loadMessages and saveMessages but not importFiles and exportFiles.
454
+ */
470
455
  function categorizePlugins(plugins) {
471
- const loadMessagesPlugins = plugins.filter((plugin) => plugin.loadMessages !== undefined);
472
- const saveMessagesPlugins = plugins.filter((plugin) => plugin.saveMessages !== undefined);
473
- const importPlugins = plugins.filter((plugin) => plugin.importFiles !== undefined && plugin.toBeImportedFiles !== undefined);
474
- const exportPlugins = plugins.filter((plugin) => plugin.exportFiles !== undefined);
475
- return {
476
- loadMessagesPlugins,
477
- saveMessagesPlugins,
478
- importPlugins,
479
- exportPlugins,
480
- };
456
+ const loadSavePlugins = [];
457
+ const importExportPlugins = [];
458
+ for (const plugin of plugins) {
459
+ if (plugin.loadMessages &&
460
+ plugin.saveMessages &&
461
+ !(plugin.importFiles && plugin.exportFiles)) {
462
+ loadSavePlugins.push(plugin);
463
+ }
464
+ else if (plugin.importFiles || plugin.exportFiles) {
465
+ importExportPlugins.push(plugin);
466
+ }
467
+ }
468
+ return { loadSavePlugins, importExportPlugins };
481
469
  }
482
470
  /**
483
471
  * Imports local plugins for backwards compatibility.
@@ -581,4 +569,4 @@ export class ResourceFileImportError extends Error {
581
569
  }
582
570
  }
583
571
  //# sourceMappingURL=loadProjectFromDirectory.js.map
584
- //# debugId=a707cbbf-d9cd-5dca-9279-55823fc96f37
572
+ //# debugId=9b967a64-af81-5add-8c9c-b28c569a5321