@inlang/sdk 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/json-schema/settings.d.ts.map +1 -1
- package/dist/json-schema/settings.js +4 -4
- package/dist/json-schema/settings.js.map +1 -1
- package/dist/services/env-variables/index.js +3 -3
- package/dist/services/env-variables/index.js.map +1 -1
- package/package.json +3 -3
- package/src/json-schema/settings.ts +4 -2
- package/dist/project/initHandleSaveToLixOnChange.d.ts +0 -14
- package/dist/project/initHandleSaveToLixOnChange.d.ts.map +0 -1
- package/dist/project/initHandleSaveToLixOnChange.js +0 -87
- package/dist/project/initHandleSaveToLixOnChange.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,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;AA+FtD,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,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]="
|
|
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]="8d3ca569-3c10-501d-8ae0-6d6ba486ecf5")}catch(e){}}();
|
|
3
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?
|
|
@@ -16,7 +16,7 @@ const SDKSettings = Type.Object({
|
|
|
16
16
|
// exits for backwards compatibility
|
|
17
17
|
// remove in SDK-v3
|
|
18
18
|
sourceLanguageTag: Type.Optional(Type.String({
|
|
19
|
-
description: "Use baseLocale instead.",
|
|
19
|
+
description: "Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.",
|
|
20
20
|
deprecated: true,
|
|
21
21
|
})),
|
|
22
22
|
// exits for backwards compatibility
|
|
@@ -24,7 +24,7 @@ const SDKSettings = Type.Object({
|
|
|
24
24
|
languageTags: Type.Optional(Type.Array(Type.String(), {
|
|
25
25
|
uniqueItems: true,
|
|
26
26
|
deprecated: true,
|
|
27
|
-
description: "Use
|
|
27
|
+
description: "Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.",
|
|
28
28
|
})),
|
|
29
29
|
/**
|
|
30
30
|
* The modules to load.
|
|
@@ -70,4 +70,4 @@ const SDKSettings = Type.Object({
|
|
|
70
70
|
});
|
|
71
71
|
export const ProjectSettings = SDKSettings;
|
|
72
72
|
//# sourceMappingURL=settings.js.map
|
|
73
|
-
//# debugId=
|
|
73
|
+
//# debugId=8d3ca569-3c10-501d-8ae0-6d6ba486ecf5
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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:\n\t\t\t\t\"Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.\",\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:\n\t\t\t\t\"Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.\",\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,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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AAC,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":"8d3ca569-3c10-501d-8ae0-6d6ba486ecf5"}
|
|
@@ -1,9 +1,9 @@
|
|
|
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]="
|
|
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]="653f0f90-c3af-5107-9290-8ba2d71d10af")}catch(e){}}();
|
|
3
3
|
export const ENV_VARIABLES = {
|
|
4
4
|
PUBLIC_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz",
|
|
5
5
|
PUBLIC_INLANG_SDK_SENTRY_DSN: "https://c3d92d5d011122e525e9f9b368e0905d@o4504345873285120.ingest.us.sentry.io/4507903389335553",
|
|
6
|
-
SDK_VERSION: "2.1.
|
|
6
|
+
SDK_VERSION: "2.1.2",
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
9
|
-
//# debugId=
|
|
9
|
+
//# debugId=653f0f90-c3af-5107-9290-8ba2d71d10af
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["services/env-variables/index.ts"],"sourceRoot":"/","sourcesContent":["\nexport const ENV_VARIABLES = {\n PUBLIC_POSTHOG_TOKEN: \"phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz\",\n\tPUBLIC_INLANG_SDK_SENTRY_DSN: \"https://c3d92d5d011122e525e9f9b368e0905d@o4504345873285120.ingest.us.sentry.io/4507903389335553\",\n\tSDK_VERSION: \"2.1.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["services/env-variables/index.ts"],"sourceRoot":"/","sourcesContent":["\nexport const ENV_VARIABLES = {\n PUBLIC_POSTHOG_TOKEN: \"phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz\",\n\tPUBLIC_INLANG_SDK_SENTRY_DSN: \"https://c3d92d5d011122e525e9f9b368e0905d@o4504345873285120.ingest.us.sentry.io/4507903389335553\",\n\tSDK_VERSION: \"2.1.2\",\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,oBAAoB,EAAE,iDAAiD;IACxE,4BAA4B,EAAE,iGAAiG;IAC/H,WAAW,EAAE,OAAO;CACpB,CAAA","debug_id":"653f0f90-c3af-5107-9290-8ba2d71d10af"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@sinclair/typebox": "^0.31.17",
|
|
31
31
|
"kysely": "^0.27.4",
|
|
32
32
|
"uuid": "^10.0.0",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"sqlite-wasm-kysely": "0.3.0",
|
|
34
|
+
"@lix-js/sdk": "0.3.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@eslint/js": "^9.12.0",
|
|
@@ -20,7 +20,8 @@ const SDKSettings = Type.Object({
|
|
|
20
20
|
// remove in SDK-v3
|
|
21
21
|
sourceLanguageTag: Type.Optional(
|
|
22
22
|
Type.String({
|
|
23
|
-
description:
|
|
23
|
+
description:
|
|
24
|
+
"Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.",
|
|
24
25
|
deprecated: true,
|
|
25
26
|
})
|
|
26
27
|
),
|
|
@@ -30,7 +31,8 @@ const SDKSettings = Type.Object({
|
|
|
30
31
|
Type.Array(Type.String(), {
|
|
31
32
|
uniqueItems: true,
|
|
32
33
|
deprecated: true,
|
|
33
|
-
description:
|
|
34
|
+
description:
|
|
35
|
+
"Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.",
|
|
34
36
|
})
|
|
35
37
|
),
|
|
36
38
|
/**
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Kysely } from "kysely";
|
|
2
|
-
import { type SqliteDatabase } from "sqlite-wasm-kysely";
|
|
3
|
-
import type { Lix } from "@lix-js/sdk";
|
|
4
|
-
import type { InlangDatabaseSchema } from "../database/schema.js";
|
|
5
|
-
/**
|
|
6
|
-
* Saves updates of the database (file) to lix.
|
|
7
|
-
*/
|
|
8
|
-
export declare function initHandleSaveToLixOnChange(args: {
|
|
9
|
-
sqlite: SqliteDatabase;
|
|
10
|
-
db: Kysely<InlangDatabaseSchema>;
|
|
11
|
-
lix: Lix;
|
|
12
|
-
pendingPromises: Promise<unknown>[];
|
|
13
|
-
}): Promise<void>;
|
|
14
|
-
//# sourceMappingURL=initHandleSaveToLixOnChange.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initHandleSaveToLixOnChange.d.ts","sourceRoot":"/","sources":["project/initHandleSaveToLixOnChange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAO,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE;;GAEG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,EAAE;IACvD,MAAM,EAAE,cAAc,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACjC,GAAG,EAAE,GAAG,CAAC;IACT,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;CACpC,iBA+EA"}
|
|
@@ -1,87 +0,0 @@
|
|
|
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]="1a4c93a4-17e3-5a38-bc7d-2850d39d1528")}catch(e){}}();
|
|
3
|
-
import { Kysely, sql } from "kysely";
|
|
4
|
-
import { contentFromDatabase } from "sqlite-wasm-kysely";
|
|
5
|
-
/**
|
|
6
|
-
* Saves updates of the database (file) to lix.
|
|
7
|
-
*/
|
|
8
|
-
export async function initHandleSaveToLixOnChange(args) {
|
|
9
|
-
args.sqlite.createFunction({
|
|
10
|
-
name: "save_db_file_to_lix",
|
|
11
|
-
arity: 0,
|
|
12
|
-
// @ts-expect-error - dynamic function
|
|
13
|
-
xFunc: () => {
|
|
14
|
-
// TODO handle in cancellable queue. only the last entry
|
|
15
|
-
// in the queue needs to be pushed to the file table
|
|
16
|
-
// because all previous entries are overwritten anyways
|
|
17
|
-
args.pendingPromises.push((async () => {
|
|
18
|
-
try {
|
|
19
|
-
// We have to await the database operations to be finished and the database to eb in a consistent state, otherwise contentFromDatabase will crash! 100 ms is too short for current test cases, but we need a proper solution for this
|
|
20
|
-
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
21
|
-
const data = contentFromDatabase(args.sqlite);
|
|
22
|
-
await args.lix.db
|
|
23
|
-
.updateTable("file")
|
|
24
|
-
.set("data", data)
|
|
25
|
-
.where("path", "=", "/db.sqlite")
|
|
26
|
-
.execute();
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
// database has likely been closed.
|
|
30
|
-
// TODO needs better handling
|
|
31
|
-
}
|
|
32
|
-
})());
|
|
33
|
-
return;
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
// better way to write to lix on updates?
|
|
37
|
-
await sql `
|
|
38
|
-
CREATE TEMP TRIGGER bundle_insert AFTER INSERT ON bundle
|
|
39
|
-
BEGIN
|
|
40
|
-
SELECT save_db_file_to_lix();
|
|
41
|
-
END;
|
|
42
|
-
|
|
43
|
-
CREATE TEMP TRIGGER bundle_update AFTER UPDATE ON bundle
|
|
44
|
-
BEGIN
|
|
45
|
-
SELECT save_db_file_to_lix();
|
|
46
|
-
END;
|
|
47
|
-
|
|
48
|
-
CREATE TEMP TRIGGER bundle_delete AFTER DELETE ON bundle
|
|
49
|
-
BEGIN
|
|
50
|
-
SELECT save_db_file_to_lix();
|
|
51
|
-
END;
|
|
52
|
-
|
|
53
|
-
CREATE TEMP TRIGGER message_insert AFTER INSERT ON message
|
|
54
|
-
BEGIN
|
|
55
|
-
SELECT save_db_file_to_lix();
|
|
56
|
-
END;
|
|
57
|
-
|
|
58
|
-
CREATE TEMP TRIGGER message_update AFTER UPDATE ON message
|
|
59
|
-
BEGIN
|
|
60
|
-
SELECT save_db_file_to_lix();
|
|
61
|
-
END;
|
|
62
|
-
|
|
63
|
-
CREATE TEMP TRIGGER message_delete AFTER DELETE ON message
|
|
64
|
-
BEGIN
|
|
65
|
-
SELECT save_db_file_to_lix();
|
|
66
|
-
END;
|
|
67
|
-
|
|
68
|
-
CREATE TEMP TRIGGER variant_insert AFTER INSERT ON variant
|
|
69
|
-
BEGIN
|
|
70
|
-
SELECT save_db_file_to_lix();
|
|
71
|
-
END;
|
|
72
|
-
|
|
73
|
-
CREATE TEMP TRIGGER variant_update AFTER UPDATE ON variant
|
|
74
|
-
BEGIN
|
|
75
|
-
SELECT save_db_file_to_lix();
|
|
76
|
-
END;
|
|
77
|
-
|
|
78
|
-
CREATE TEMP TRIGGER variant_delete AFTER DELETE ON variant
|
|
79
|
-
BEGIN
|
|
80
|
-
SELECT save_db_file_to_lix();
|
|
81
|
-
END;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
`.execute(args.db);
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=initHandleSaveToLixOnChange.js.map
|
|
87
|
-
//# debugId=1a4c93a4-17e3-5a38-bc7d-2850d39d1528
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initHandleSaveToLixOnChange.js","sources":["project/initHandleSaveToLixOnChange.ts"],"sourceRoot":"/","sourcesContent":["import { Kysely, sql } from \"kysely\";\nimport { contentFromDatabase, type SqliteDatabase } from \"sqlite-wasm-kysely\";\nimport type { Lix } from \"@lix-js/sdk\";\nimport type { InlangDatabaseSchema } from \"../database/schema.js\";\n\n/**\n * Saves updates of the database (file) to lix.\n */\nexport async function initHandleSaveToLixOnChange(args: {\n\tsqlite: SqliteDatabase;\n\tdb: Kysely<InlangDatabaseSchema>;\n\tlix: Lix;\n\tpendingPromises: Promise<unknown>[];\n}) {\n\targs.sqlite.createFunction({\n\t\tname: \"save_db_file_to_lix\",\n\t\tarity: 0,\n\t\t// @ts-expect-error - dynamic function\n\t\txFunc: () => {\n\t\t\t// TODO handle in cancellable queue. only the last entry\n\t\t\t// in the queue needs to be pushed to the file table\n\t\t\t// because all previous entries are overwritten anyways\n\t\t\targs.pendingPromises.push(\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// We have to await the database operations to be finished and the database to eb in a consistent state, otherwise contentFromDatabase will crash! 100 ms is too short for current test cases, but we need a proper solution for this\n\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 400));\n\t\t\t\t\t\tconst data = contentFromDatabase(args.sqlite);\n\t\t\t\t\t\tawait args.lix.db\n\t\t\t\t\t\t\t.updateTable(\"file\")\n\t\t\t\t\t\t\t.set(\"data\", data)\n\t\t\t\t\t\t\t.where(\"path\", \"=\", \"/db.sqlite\")\n\t\t\t\t\t\t\t.execute();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// database has likely been closed.\n\t\t\t\t\t\t// TODO needs better handling\n\t\t\t\t\t}\n\t\t\t\t})()\n\t\t\t);\n\t\t\treturn;\n\t\t},\n\t});\n\n\t// better way to write to lix on updates?\n\tawait sql`\n\tCREATE TEMP TRIGGER bundle_insert AFTER INSERT ON bundle\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER bundle_update AFTER UPDATE ON bundle\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER bundle_delete AFTER DELETE ON bundle\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\t\tCREATE TEMP TRIGGER message_insert AFTER INSERT ON message\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER message_update AFTER UPDATE ON message\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER message_delete AFTER DELETE ON message\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER variant_insert AFTER INSERT ON variant\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER variant_update AFTER UPDATE ON variant\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\tCREATE TEMP TRIGGER variant_delete AFTER DELETE ON variant\n\tBEGIN\n\t SELECT save_db_file_to_lix();\n\tEND;\n\n\n\t`.execute(args.db);\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAuB,MAAM,oBAAoB,CAAC;AAI9E;;GAEG;AACH,MAAM,CAAC,KAAK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