@inlang/sdk 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/initDb.d.ts +2 -2
- package/dist/database/initDb.d.ts.map +1 -1
- package/dist/database/initDb.js +2 -2
- package/dist/database/initDb.js.map +1 -1
- package/dist/database/jsonbPlugin.d.ts +2 -2
- package/dist/database/jsonbPlugin.d.ts.map +1 -1
- package/dist/database/jsonbPlugin.js +2 -2
- package/dist/database/jsonbPlugin.js.map +1 -1
- package/dist/database/schema.d.ts +2 -2
- package/dist/database/schema.d.ts.map +1 -1
- package/dist/database/schema.js +2 -2
- package/dist/database/schema.js.map +1 -1
- package/dist/project/api.d.ts +2 -2
- package/dist/project/api.d.ts.map +1 -1
- package/dist/project/api.js +2 -2
- package/dist/project/api.js.map +1 -1
- package/dist/project/initHandleSaveToLixOnChange.d.ts +14 -0
- package/dist/project/initHandleSaveToLixOnChange.d.ts.map +1 -0
- package/dist/project/initHandleSaveToLixOnChange.js +87 -0
- package/dist/project/initHandleSaveToLixOnChange.js.map +1 -0
- package/dist/project/loadProject.d.ts +2 -2
- package/dist/project/loadProject.d.ts.map +1 -1
- package/dist/project/loadProject.js +3 -3
- package/dist/project/loadProject.js.map +1 -1
- package/dist/project/loadProjectFromDirectory.d.ts +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/database/initDb.ts +3 -3
- package/src/database/jsonbPlugin.ts +3 -3
- package/src/database/schema.ts +2 -2
- package/src/project/api.ts +2 -2
- package/src/project/loadProject.ts +6 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
2
|
import { type InlangDatabaseSchema } from "./schema.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
4
4
|
export declare function initDb(args: {
|
|
5
|
-
sqlite:
|
|
5
|
+
sqlite: SqliteWasmDatabase;
|
|
6
6
|
}): Kysely<InlangDatabaseSchema>;
|
|
7
7
|
//# sourceMappingURL=initDb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initDb.d.ts","sourceRoot":"/","sources":["database/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAe,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAiB,KAAK,
|
|
1
|
+
{"version":3,"file":"initDb.d.ts","sourceRoot":"/","sources":["database/initDb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAe,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAK5E,wBAAgB,MAAM,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,kBAAkB,CAAA;CAAE,gCAa1D"}
|
package/dist/database/initDb.js
CHANGED
|
@@ -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]="fc2b29fc-faec-5ff5-91e6-5664b8dc4c09")}catch(e){}}();
|
|
3
3
|
import { CamelCasePlugin, Kysely } from "kysely";
|
|
4
4
|
import { applySchema } from "./schema.js";
|
|
5
5
|
import { createDialect } from "sqlite-wasm-kysely";
|
|
@@ -33,4 +33,4 @@ function initDefaultValueFunctions(args) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
//# sourceMappingURL=initDb.js.map
|
|
36
|
-
//# debugId=
|
|
36
|
+
//# debugId=fc2b29fc-faec-5ff5-91e6-5664b8dc4c09
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initDb.js","sources":["database/initDb.ts"],"sourceRoot":"/","sourcesContent":["import { CamelCasePlugin, Kysely } from \"kysely\";\nimport { applySchema, type InlangDatabaseSchema } from \"./schema.js\";\nimport { createDialect, type
|
|
1
|
+
{"version":3,"file":"initDb.js","sources":["database/initDb.ts"],"sourceRoot":"/","sourcesContent":["import { CamelCasePlugin, Kysely } from \"kysely\";\nimport { applySchema, type InlangDatabaseSchema } from \"./schema.js\";\nimport { createDialect, type SqliteWasmDatabase } from \"sqlite-wasm-kysely\";\nimport { v7 } from \"uuid\";\nimport { humanId } from \"../human-id/human-id.js\";\nimport { JsonbPlugin } from \"./jsonbPlugin.js\";\n\nexport function initDb(args: { sqlite: SqliteWasmDatabase }) {\n\tinitDefaultValueFunctions({ sqlite: args.sqlite });\n\tapplySchema({ sqlite: args.sqlite });\n\tconst db = new Kysely<InlangDatabaseSchema>({\n\t\tdialect: createDialect({\n\t\t\tdatabase: args.sqlite,\n\t\t}),\n\t\tplugins: [\n\t\t\tnew CamelCasePlugin(),\n\t\t\tnew JsonbPlugin({ database: args.sqlite }),\n\t\t],\n\t});\n\treturn db;\n}\n\nfunction initDefaultValueFunctions(args: { sqlite: SqliteWasmDatabase }) {\n\targs.sqlite.createFunction({\n\t\tname: \"uuid_v7\",\n\t\tarity: 0,\n\t\txFunc: () => v7(),\n\t});\n\targs.sqlite.createFunction({\n\t\tname: \"human_id\",\n\t\tarity: 0,\n\t\txFunc: () => humanId(),\n\t});\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,WAAW,EAA6B,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,aAAa,EAA2B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,UAAU,MAAM,CAAC,IAAoC;IAC1D,yBAAyB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACnD,WAAW,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,MAAM,EAAE,GAAG,IAAI,MAAM,CAAuB;QAC3C,OAAO,EAAE,aAAa,CAAC;YACtB,QAAQ,EAAE,IAAI,CAAC,MAAM;SACrB,CAAC;QACF,OAAO,EAAE;YACR,IAAI,eAAe,EAAE;YACrB,IAAI,WAAW,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;SAC1C;KACD,CAAC,CAAC;IACH,OAAO,EAAE,CAAC;AACX,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAoC;IACtE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;QAC1B,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;KACjB,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;QAC1B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE;KACtB,CAAC,CAAC;AACJ,CAAC","debug_id":"fc2b29fc-faec-5ff5-91e6-5664b8dc4c09"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type KyselyPlugin, type PluginTransformQueryArgs, type PluginTransformResultArgs, type QueryResult, type RootOperationNode, type UnknownRow } from "kysely";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
3
3
|
export declare class JsonbPlugin implements KyselyPlugin {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(args: {
|
|
6
|
-
database:
|
|
6
|
+
database: SqliteWasmDatabase;
|
|
7
7
|
});
|
|
8
8
|
/**
|
|
9
9
|
* For an outgoing query like insert or update, the JSON
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonbPlugin.d.ts","sourceRoot":"/","sources":["database/jsonbPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAEf,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"jsonbPlugin.d.ts","sourceRoot":"/","sources":["database/jsonbPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAEf,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,qBAAa,WAAY,YAAW,YAAY;;gBAKnC,IAAI,EAAE;QAAE,QAAQ,EAAE,kBAAkB,CAAA;KAAE;IAIlD;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,wBAAwB,GAAG,iBAAiB;IAWjE;;;OAGG;IACG,eAAe,CACpB,IAAI,EAAE,yBAAyB,GAC7B,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;CAwBnC"}
|
|
@@ -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]="e8e4087c-9464-57fc-b765-367ee0953d9b")}catch(e){}}();
|
|
3
3
|
import { OperationNodeTransformer, sql, ValueListNode, ValueNode, ValuesNode, ParseJSONResultsPlugin, OnConflictNode, } from "kysely";
|
|
4
4
|
export class JsonbPlugin {
|
|
5
5
|
#serializeJsonTransformer = new SerializeJsonbTransformer();
|
|
@@ -180,4 +180,4 @@ function maybeSerializeJson(value) {
|
|
|
180
180
|
// };
|
|
181
181
|
// }
|
|
182
182
|
//# sourceMappingURL=jsonbPlugin.js.map
|
|
183
|
-
//# debugId=
|
|
183
|
+
//# debugId=e8e4087c-9464-57fc-b765-367ee0953d9b
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonbPlugin.js","sources":["database/jsonbPlugin.ts"],"sourceRoot":"/","sourcesContent":["import {\n\tOperationNodeTransformer,\n\tsql,\n\tValueListNode,\n\tValueNode,\n\tValuesNode,\n\tParseJSONResultsPlugin,\n\ttype KyselyPlugin,\n\ttype PluginTransformQueryArgs,\n\ttype PluginTransformResultArgs,\n\ttype QueryResult,\n\ttype RootOperationNode,\n\ttype UnknownRow,\n\tOnConflictNode,\n} from \"kysely\";\nimport type { SqliteDatabase } from \"sqlite-wasm-kysely\";\n\nexport class JsonbPlugin implements KyselyPlugin {\n\t#serializeJsonTransformer = new SerializeJsonbTransformer();\n\t#parseJsonPlugin = new ParseJSONResultsPlugin();\n\t#database: SqliteDatabase;\n\n\tconstructor(args: { database: SqliteDatabase }) {\n\t\tthis.#database = args.database;\n\t}\n\n\t/**\n\t * For an outgoing query like insert or update, the JSON\n\t * values are transformed into `jsonb` function calls when\n\t * executed against the database.\n\t */\n\ttransformQuery(args: PluginTransformQueryArgs): RootOperationNode {\n\t\tif (\n\t\t\targs.node.kind === \"InsertQueryNode\" ||\n\t\t\targs.node.kind === \"UpdateQueryNode\"\n\t\t) {\n\t\t\tconst result = this.#serializeJsonTransformer.transformNode(args.node);\n\t\t\treturn result;\n\t\t}\n\t\treturn args.node;\n\t}\n\n\t/**\n\t * For incoming query results, the JSON binaries are parsed\n\t * into JSON objects.\n\t */\n\tasync transformResult(\n\t\targs: PluginTransformResultArgs\n\t): Promise<QueryResult<UnknownRow>> {\n\t\tfor (const row of args.result.rows) {\n\t\t\tfor (const key in row) {\n\t\t\t\tif (\n\t\t\t\t\trow[key] instanceof ArrayBuffer ||\n\t\t\t\t\t// uint8array, etc\n\t\t\t\t\tArrayBuffer.isView(row[key])\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst res = this.#database.exec(`SELECT json(?)`, {\n\t\t\t\t\t\t\treturnValue: \"resultRows\",\n\t\t\t\t\t\t\tbind: [row[key] as any],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\trow[key] = JSON.parse(res[0] as any);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// it's not a json binary\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// in case it's a regular (text) json, run it through kyseley's json parser\n\t\treturn this.#parseJsonPlugin.transformResult(args);\n\t}\n}\n\nclass SerializeJsonbTransformer extends OperationNodeTransformer {\n\tprotected override transformOnConflict(node: OnConflictNode): OnConflictNode {\n\t\treturn super.transformOnConflict({\n\t\t\t...node,\n\t\t\tupdates: node.updates?.map((updateItem) => {\n\t\t\t\tif (updateItem.kind !== \"ColumnUpdateNode\") {\n\t\t\t\t\treturn updateItem;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"ColumnUpdateNode\",\n\t\t\t\t\tcolumn: updateItem.column,\n\t\t\t\t\t// @ts-expect-error - we know that the value is a ValueNode\n\t\t\t\t\tvalue: this.transformValue(updateItem.value),\n\t\t\t\t};\n\t\t\t}),\n\t\t});\n\t}\n\n\tprotected override transformValue(node: ValueNode): ValueNode {\n\t\tconst { value } = node;\n\t\tconst serializedValue = maybeSerializeJson(value);\n\t\tif (value === serializedValue) {\n\t\t\treturn node;\n\t\t}\n\t\t// @ts-expect-error - we know that the node is a ValueNode\n\t\treturn sql`jsonb(${serializedValue})`.toOperationNode();\n\t}\n\t/**\n\t * Transforms the value list node by replacing all JSON objects with `jsonb` function calls.\n\t */\n\tprotected override transformValueList(node: ValueListNode): ValueListNode {\n\t\treturn super.transformValueList({\n\t\t\t...node,\n\t\t\tvalues: node.values.map((listNodeItem) => {\n\t\t\t\tif (listNodeItem.kind !== \"ValueNode\") {\n\t\t\t\t\treturn listNodeItem;\n\t\t\t\t}\n\t\t\t\t// @ts-expect-error - we know that the node is a ValueNode\n\t\t\t\tconst { value } = listNodeItem;\n\t\t\t\tconst serializedValue = maybeSerializeJson(value);\n\n\t\t\t\tif (value === serializedValue) {\n\t\t\t\t\treturn listNodeItem;\n\t\t\t\t}\n\t\t\t\treturn sql`jsonb(${serializedValue})`.toOperationNode();\n\t\t\t}),\n\t\t});\n\t}\n\n\t/**\n\t * Why this function is needed or why this works remains a mystery.\n\t */\n\toverride transformValues(node: ValuesNode): ValuesNode {\n\t\treturn super.transformValues({\n\t\t\t...node,\n\t\t\tvalues: node.values.map((valueItemNode) => {\n\t\t\t\tif (valueItemNode.kind !== \"PrimitiveValueListNode\") {\n\t\t\t\t\treturn valueItemNode;\n\t\t\t\t}\n\n\t\t\t\t// change valueItem to ValueListNode\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"ValueListNode\",\n\t\t\t\t\tvalues: valueItemNode.values.map(\n\t\t\t\t\t\t(value) =>\n\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\tkind: \"ValueNode\",\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t}) as ValueNode\n\t\t\t\t\t),\n\t\t\t\t} as ValueListNode;\n\t\t\t}),\n\t\t});\n\t}\n}\n\nfunction maybeSerializeJson(value: any): any {\n\tif (\n\t\t// binary data\n\t\tvalue instanceof ArrayBuffer ||\n\t\t// uint8array, etc\n\t\tArrayBuffer.isView(value) ||\n\t\tvalue === null ||\n\t\tvalue === undefined\n\t) {\n\t\treturn value;\n\t} else if (typeof value === \"object\" || Array.isArray(value)) {\n\t\treturn JSON.stringify(value);\n\t}\n\treturn value;\n}\n\n// The code here didn't work https://github.com/opral/inlang-sdk/issues/132#issuecomment-2339321910\n// but would be the \"right\" solution to avoid heuristics which column might or might not be a json column\n// // modifies the query in place for readability and performance\n// function mapQuery(\n// \tnode: InsertQueryNode,\n// \tjsonColumns: TableSchema\n// ): InsertQueryNode {\n// \t// if the query is not an insert query, we don't need to do anything\n// \tif (node.into === undefined) {\n// \t\treturn node;\n// \t}\n// \t// if the table is not in the schema that has json columns, we don't need to do anything\n// \tconst columnsWithJson = jsonColumns[node.into.table.identifier.name];\n// \tif (columnsWithJson === undefined) {\n// \t\treturn node;\n// \t}\n// \t// find the indexes of the values that need to be transformed\n// \t// SQL query: INSERT INTO table (col1, col2) VALUES (val1, val2)\n// \tconst indexesThatNeedToBeTransformed: [number, string][] = [];\n// \tfor (const [i, col] of node.columns?.entries() ?? []) {\n// \t\tconst jsonType = columnsWithJson[col.column.name];\n// \t\tif (jsonType !== undefined) {\n// \t\t\tindexesThatNeedToBeTransformed.push([i, jsonType]);\n// \t\t}\n// \t}\n// \tconst values = structuredClone(node.values);\n// \tfor (const [i, jsonType] of indexesThatNeedToBeTransformed) {\n// \t\tif (\n// \t\t\t// top level values node that should contain a list of values\n// \t\t\tnode.values?.kind !== \"ValuesNode\" &&\n// \t\t\t// the node we are interested in must be a value node\n// \t\t\t// @ts-expect-error - we know that the node is a ValuesNode with values\n// \t\t\t(node.values as ValuesNode).values?.[i].kind !== \"ValueNode\"\n// \t\t) {\n// \t\t\tthrow new Error(\"Unexpected node structure\");\n// \t\t}\n// \t\tconst serializedJson = JSON.stringify(node.values.values[0].values[i]);\n// \t\t// @ts-expect-error - we know that the node is a ValuesNode with values\n// \t\tvalues.values[0].values[i] =\n// \t\t\tjsonType === \"jsonb\"\n// \t\t\t\t? sql`jsonb(${serializedJson})`.toOperationNode()\n// \t\t\t\t: sql`json(${serializedJson})`.toOperationNode();\n// \t}\n\n// \treturn {\n// \t\t...node,\n// \t\tvalues,\n// \t};\n// }\n"],"names":[],"mappings":";;AAAA,OAAO,EACN,wBAAwB,EACxB,GAAG,EACH,aAAa,EACb,SAAS,EACT,UAAU,EACV,sBAAsB,EAOtB,cAAc,GACd,MAAM,QAAQ,CAAC;AAGhB,MAAM,OAAO,WAAW;IACvB,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;IAC5D,gBAAgB,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAChD,SAAS,CAAiB;IAE1B,YAAY,IAAkC;QAC7C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,IAA8B;QAC5C,IACC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB;YACpC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB,EACnC,CAAC;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,yBAAyB,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvE,OAAO,MAAM,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CACpB,IAA+B;QAE/B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACpC,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;gBACvB,IACC,GAAG,CAAC,GAAG,CAAC,YAAY,WAAW;oBAC/B,kBAAkB;oBAClB,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAC3B,CAAC;oBACF,IA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d,KAAK,YAAY,WAAW;QAC5B,kBAAkB;QAClB,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS,EAClB,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,mGAAmG;AACnG,yGAAyG;AACzG,iEAAiE;AACjE,qBAAqB;AACrB,0BAA0B;AAC1B,4BAA4B;AAC5B,uBAAuB;AACvB,wEAAwE;AACxE,kCAAkC;AAClC,iBAAiB;AACjB,KAAK;AACL,4FAA4F;AAC5F,yEAAyE;AACzE,wCAAwC;AACxC,iBAAiB;AACjB,KAAK;AACL,iEAAiE;AACjE,oEAAoE;AACpE,kEAAkE;AAClE,2DAA2D;AAC3D,uDAAuD;AACvD,kCAAkC;AAClC,yDAAyD;AACzD,MAAM;AACN,KAAK;AACL,gDAAgD;AAChD,iEAAiE;AACjE,SAAS;AACT,mEAAmE;AACnE,2CAA2C;AAC3C,2DAA2D;AAC3D,6EAA6E;AAC7E,kEAAkE;AAClE,QAAQ;AACR,mDAAmD;AACnD,MAAM;AACN,4EAA4E;AAC5E,4EAA4E;AAC5E,iCAAiC;AACjC,0BAA0B;AAC1B,wDAAwD;AACxD,wDAAwD;AACxD,KAAK;AAEL,YAAY;AACZ,aAAa;AACb,YAAY;AACZ,MAAM;AACN,IAAI","debug_id":"3327df74-20ec-59b9-aa9d-5070dada72f2"}
|
|
1
|
+
{"version":3,"file":"jsonbPlugin.js","sources":["database/jsonbPlugin.ts"],"sourceRoot":"/","sourcesContent":["import {\n\tOperationNodeTransformer,\n\tsql,\n\tValueListNode,\n\tValueNode,\n\tValuesNode,\n\tParseJSONResultsPlugin,\n\ttype KyselyPlugin,\n\ttype PluginTransformQueryArgs,\n\ttype PluginTransformResultArgs,\n\ttype QueryResult,\n\ttype RootOperationNode,\n\ttype UnknownRow,\n\tOnConflictNode,\n} from \"kysely\";\nimport type { SqliteWasmDatabase } from \"sqlite-wasm-kysely\";\n\nexport class JsonbPlugin implements KyselyPlugin {\n\t#serializeJsonTransformer = new SerializeJsonbTransformer();\n\t#parseJsonPlugin = new ParseJSONResultsPlugin();\n\t#database: SqliteWasmDatabase;\n\n\tconstructor(args: { database: SqliteWasmDatabase }) {\n\t\tthis.#database = args.database;\n\t}\n\n\t/**\n\t * For an outgoing query like insert or update, the JSON\n\t * values are transformed into `jsonb` function calls when\n\t * executed against the database.\n\t */\n\ttransformQuery(args: PluginTransformQueryArgs): RootOperationNode {\n\t\tif (\n\t\t\targs.node.kind === \"InsertQueryNode\" ||\n\t\t\targs.node.kind === \"UpdateQueryNode\"\n\t\t) {\n\t\t\tconst result = this.#serializeJsonTransformer.transformNode(args.node);\n\t\t\treturn result;\n\t\t}\n\t\treturn args.node;\n\t}\n\n\t/**\n\t * For incoming query results, the JSON binaries are parsed\n\t * into JSON objects.\n\t */\n\tasync transformResult(\n\t\targs: PluginTransformResultArgs\n\t): Promise<QueryResult<UnknownRow>> {\n\t\tfor (const row of args.result.rows) {\n\t\t\tfor (const key in row) {\n\t\t\t\tif (\n\t\t\t\t\trow[key] instanceof ArrayBuffer ||\n\t\t\t\t\t// uint8array, etc\n\t\t\t\t\tArrayBuffer.isView(row[key])\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst res = this.#database.exec(`SELECT json(?)`, {\n\t\t\t\t\t\t\treturnValue: \"resultRows\",\n\t\t\t\t\t\t\tbind: [row[key] as any],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\trow[key] = JSON.parse(res[0] as any);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// it's not a json binary\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// in case it's a regular (text) json, run it through kyseley's json parser\n\t\treturn this.#parseJsonPlugin.transformResult(args);\n\t}\n}\n\nclass SerializeJsonbTransformer extends OperationNodeTransformer {\n\tprotected override transformOnConflict(node: OnConflictNode): OnConflictNode {\n\t\treturn super.transformOnConflict({\n\t\t\t...node,\n\t\t\tupdates: node.updates?.map((updateItem) => {\n\t\t\t\tif (updateItem.kind !== \"ColumnUpdateNode\") {\n\t\t\t\t\treturn updateItem;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"ColumnUpdateNode\",\n\t\t\t\t\tcolumn: updateItem.column,\n\t\t\t\t\t// @ts-expect-error - we know that the value is a ValueNode\n\t\t\t\t\tvalue: this.transformValue(updateItem.value),\n\t\t\t\t};\n\t\t\t}),\n\t\t});\n\t}\n\n\tprotected override transformValue(node: ValueNode): ValueNode {\n\t\tconst { value } = node;\n\t\tconst serializedValue = maybeSerializeJson(value);\n\t\tif (value === serializedValue) {\n\t\t\treturn node;\n\t\t}\n\t\t// @ts-expect-error - we know that the node is a ValueNode\n\t\treturn sql`jsonb(${serializedValue})`.toOperationNode();\n\t}\n\t/**\n\t * Transforms the value list node by replacing all JSON objects with `jsonb` function calls.\n\t */\n\tprotected override transformValueList(node: ValueListNode): ValueListNode {\n\t\treturn super.transformValueList({\n\t\t\t...node,\n\t\t\tvalues: node.values.map((listNodeItem) => {\n\t\t\t\tif (listNodeItem.kind !== \"ValueNode\") {\n\t\t\t\t\treturn listNodeItem;\n\t\t\t\t}\n\t\t\t\t// @ts-expect-error - we know that the node is a ValueNode\n\t\t\t\tconst { value } = listNodeItem;\n\t\t\t\tconst serializedValue = maybeSerializeJson(value);\n\n\t\t\t\tif (value === serializedValue) {\n\t\t\t\t\treturn listNodeItem;\n\t\t\t\t}\n\t\t\t\treturn sql`jsonb(${serializedValue})`.toOperationNode();\n\t\t\t}),\n\t\t});\n\t}\n\n\t/**\n\t * Why this function is needed or why this works remains a mystery.\n\t */\n\toverride transformValues(node: ValuesNode): ValuesNode {\n\t\treturn super.transformValues({\n\t\t\t...node,\n\t\t\tvalues: node.values.map((valueItemNode) => {\n\t\t\t\tif (valueItemNode.kind !== \"PrimitiveValueListNode\") {\n\t\t\t\t\treturn valueItemNode;\n\t\t\t\t}\n\n\t\t\t\t// change valueItem to ValueListNode\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"ValueListNode\",\n\t\t\t\t\tvalues: valueItemNode.values.map(\n\t\t\t\t\t\t(value) =>\n\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\tkind: \"ValueNode\",\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t}) as ValueNode\n\t\t\t\t\t),\n\t\t\t\t} as ValueListNode;\n\t\t\t}),\n\t\t});\n\t}\n}\n\nfunction maybeSerializeJson(value: any): any {\n\tif (\n\t\t// binary data\n\t\tvalue instanceof ArrayBuffer ||\n\t\t// uint8array, etc\n\t\tArrayBuffer.isView(value) ||\n\t\tvalue === null ||\n\t\tvalue === undefined\n\t) {\n\t\treturn value;\n\t} else if (typeof value === \"object\" || Array.isArray(value)) {\n\t\treturn JSON.stringify(value);\n\t}\n\treturn value;\n}\n\n// The code here didn't work https://github.com/opral/inlang-sdk/issues/132#issuecomment-2339321910\n// but would be the \"right\" solution to avoid heuristics which column might or might not be a json column\n// // modifies the query in place for readability and performance\n// function mapQuery(\n// \tnode: InsertQueryNode,\n// \tjsonColumns: TableSchema\n// ): InsertQueryNode {\n// \t// if the query is not an insert query, we don't need to do anything\n// \tif (node.into === undefined) {\n// \t\treturn node;\n// \t}\n// \t// if the table is not in the schema that has json columns, we don't need to do anything\n// \tconst columnsWithJson = jsonColumns[node.into.table.identifier.name];\n// \tif (columnsWithJson === undefined) {\n// \t\treturn node;\n// \t}\n// \t// find the indexes of the values that need to be transformed\n// \t// SQL query: INSERT INTO table (col1, col2) VALUES (val1, val2)\n// \tconst indexesThatNeedToBeTransformed: [number, string][] = [];\n// \tfor (const [i, col] of node.columns?.entries() ?? []) {\n// \t\tconst jsonType = columnsWithJson[col.column.name];\n// \t\tif (jsonType !== undefined) {\n// \t\t\tindexesThatNeedToBeTransformed.push([i, jsonType]);\n// \t\t}\n// \t}\n// \tconst values = structuredClone(node.values);\n// \tfor (const [i, jsonType] of indexesThatNeedToBeTransformed) {\n// \t\tif (\n// \t\t\t// top level values node that should contain a list of values\n// \t\t\tnode.values?.kind !== \"ValuesNode\" &&\n// \t\t\t// the node we are interested in must be a value node\n// \t\t\t// @ts-expect-error - we know that the node is a ValuesNode with values\n// \t\t\t(node.values as ValuesNode).values?.[i].kind !== \"ValueNode\"\n// \t\t) {\n// \t\t\tthrow new Error(\"Unexpected node structure\");\n// \t\t}\n// \t\tconst serializedJson = JSON.stringify(node.values.values[0].values[i]);\n// \t\t// @ts-expect-error - we know that the node is a ValuesNode with values\n// \t\tvalues.values[0].values[i] =\n// \t\t\tjsonType === \"jsonb\"\n// \t\t\t\t? sql`jsonb(${serializedJson})`.toOperationNode()\n// \t\t\t\t: sql`json(${serializedJson})`.toOperationNode();\n// \t}\n\n// \treturn {\n// \t\t...node,\n// \t\tvalues,\n// \t};\n// }\n"],"names":[],"mappings":";;AAAA,OAAO,EACN,wBAAwB,EACxB,GAAG,EACH,aAAa,EACb,SAAS,EACT,UAAU,EACV,sBAAsB,EAOtB,cAAc,GACd,MAAM,QAAQ,CAAC;AAGhB,MAAM,OAAO,WAAW;IACvB,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;IAC5D,gBAAgB,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAChD,SAAS,CAAqB;IAE9B,YAAY,IAAsC;QACjD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,IAA8B;QAC5C,IACC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB;YACpC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB,EACnC,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,iEAAiE;AACjE,SAAS;AACT,mEAAmE;AACnE,2CAA2C;AAC3C,2DAA2D;AAC3D,6EAA6E;AAC7E,kEAAkE;AAClE,QAAQ;AACR,mDAAmD;AACnD,MAAM;AACN,4EAA4E;AAC5E,4EAA4E;AAC5E,iCAAiC;AACjC,0BAA0B;AAC1B,wDAAwD;AACxD,wDAAwD;AACxD,KAAK;AAEL,YAAY;AACZ,aAAa;AACb,YAAY;AACZ,MAAM;AACN,IAAI","debug_id":"e8e4087c-9464-57fc-b765-367ee0953d9b"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Generated, Insertable, Selectable, Updateable } from "kysely";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
3
3
|
import { Declaration, Pattern, VariableReference } from "../json-schema/pattern.js";
|
|
4
4
|
export declare function applySchema(args: {
|
|
5
|
-
sqlite:
|
|
5
|
+
sqlite: SqliteWasmDatabase;
|
|
6
6
|
}): void;
|
|
7
7
|
export type InlangDatabaseSchema = {
|
|
8
8
|
bundle: BundleTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"/","sources":["database/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"/","sources":["database/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACN,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,MAAM,2BAA2B,CAAC;AAEnC,wBAAgB,WAAW,CAAC,IAAI,EA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AAC,WAAW,CAAC,CAAC;AAChD,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAEnD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAErD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACrC,QAAQ,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAC3C,QAAQ,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,YAAY,CAAC,GAAG;IAC5D,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IACnC,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC1B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG;IACzC,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG;IAC/C,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CAChC,CAAC"}
|
package/dist/database/schema.js
CHANGED
|
@@ -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]="f2febd26-8b4a-5507-b058-13bb83472533")}catch(e){}}();
|
|
3
3
|
import { Declaration, Pattern, VariableReference, } from "../json-schema/pattern.js";
|
|
4
4
|
export function applySchema(args) {
|
|
5
5
|
const foreignKeyActivated = args.sqlite.exec("PRAGMA foreign_keys", {
|
|
@@ -42,4 +42,4 @@ CREATE INDEX IF NOT EXISTS idx_variant_message_id ON variant (message_id);
|
|
|
42
42
|
`);
|
|
43
43
|
}
|
|
44
44
|
//# sourceMappingURL=schema.js.map
|
|
45
|
-
//# debugId=
|
|
45
|
+
//# debugId=f2febd26-8b4a-5507-b058-13bb83472533
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sources":["database/schema.ts"],"sourceRoot":"/","sourcesContent":["import type { Generated, Insertable, Selectable, Updateable } from \"kysely\";\nimport type {
|
|
1
|
+
{"version":3,"file":"schema.js","sources":["database/schema.ts"],"sourceRoot":"/","sourcesContent":["import type { Generated, Insertable, Selectable, Updateable } from \"kysely\";\nimport type { SqliteWasmDatabase } from \"sqlite-wasm-kysely\";\nimport {\n\tDeclaration,\n\tPattern,\n\tVariableReference,\n} from \"../json-schema/pattern.js\";\n\nexport function applySchema(args: { sqlite: SqliteWasmDatabase }) {\n\tconst foreignKeyActivated: any = args.sqlite.exec(\"PRAGMA foreign_keys\", {\n\t\treturnValue: \"resultRows\",\n\t});\n\tif (\n\t\t// first row that is returned\n\t\t// first column of the first row\n\t\t// is equal to 0, then foreign keys are disabled\n\t\tforeignKeyActivated[0][0] === 0\n\t) {\n\t\targs.sqlite.exec(\"PRAGMA foreign_keys = ON\", {\n\t\t\treturnValue: \"resultRows\",\n\t\t});\n\t}\n\n\targs.sqlite.exec(`\nCREATE TABLE IF NOT EXISTS bundle (\n id TEXT PRIMARY KEY DEFAULT (human_id()),\n\tdeclarations BLOB NOT NULL DEFAULT (jsonb('[]'))\n) strict;\n\nCREATE TABLE IF NOT EXISTS message (\n id TEXT PRIMARY KEY DEFAULT (uuid_v7()), \n bundle_id TEXT NOT NULL,\n locale TEXT NOT NULL,\n selectors BLOB NOT NULL DEFAULT (jsonb('[]')),\n FOREIGN KEY (bundle_id) REFERENCES bundle(id) ON DELETE CASCADE\n) strict;\n\n\nCREATE TABLE IF NOT EXISTS variant (\n id TEXT PRIMARY KEY DEFAULT (uuid_v7()), \n message_id TEXT NOT NULL,\n matches BLOB NOT NULL DEFAULT (jsonb('[]')),\n pattern BLOB NOT NULL DEFAULT (jsonb('[]')),\n FOREIGN KEY (message_id) REFERENCES message(id) ON DELETE CASCADE\n) strict;\n \nCREATE INDEX IF NOT EXISTS idx_message_bundle_id ON message (bundle_id);\nCREATE INDEX IF NOT EXISTS idx_variant_message_id ON variant (message_id);\n\t\t`);\n}\n\nexport type InlangDatabaseSchema = {\n\tbundle: BundleTable;\n\tmessage: MessageTable;\n\tvariant: VariantTable;\n};\n\ntype BundleTable = {\n\tid: Generated<string>;\n\tdeclarations: Generated<Array<Declaration>>;\n};\n\ntype MessageTable = {\n\tid: Generated<string>;\n\tbundleId: string;\n\tlocale: string;\n\tselectors: Generated<Array<VariableReference>>;\n};\n\ntype VariantTable = {\n\tid: Generated<string>;\n\tmessageId: string;\n\tmatches: Generated<Array<Match>>;\n\tpattern: Generated<Pattern>;\n};\n\n/**\n * A match is a variable reference that is either a literal or a catch-all.\n *\n * https://github.com/opral/inlang-sdk/issues/205\n *\n * @example\n * match = { type: \"match\", name: \"gender\", value: { type: \"literal\", value: \"male\" }}\n */\nexport type Match = LiteralMatch | CatchAllMatch;\n\nexport type LiteralMatch = {\n\ttype: \"literal-match\";\n\tkey: VariableReference[\"name\"];\n\tvalue: string;\n};\nexport type CatchAllMatch = {\n\ttype: \"catchall-match\";\n\tkey: VariableReference[\"name\"];\n};\n\nexport type Bundle = Selectable<BundleTable>;\nexport type NewBundle = Insertable<BundleTable>;\nexport type BundleUpdate = Updateable<BundleTable>;\n\nexport type Message = Selectable<MessageTable>;\nexport type NewMessage = Insertable<MessageTable>;\nexport type MessageUpdate = Updateable<MessageTable>;\n\nexport type Variant = Selectable<VariantTable>;\nexport type NewVariant = Insertable<VariantTable>;\nexport type VariantUpdate = Updateable<VariantTable>;\n\nexport type MessageNested = Message & {\n\tvariants: Variant[];\n};\nexport type NewMessageNested = NewMessage & {\n\tvariants: NewVariant[];\n};\nexport type MessageNestedUpdate = Updateable<MessageTable> & {\n\tvariants: VariantUpdate[];\n};\n\nexport type BundleNested = Bundle & {\n\tmessages: MessageNested[];\n};\nexport type NewBundleNested = NewBundle & {\n\tmessages: NewMessageNested[];\n};\nexport type BundleNestedUpdate = BundleUpdate & {\n\tmessages: MessageNestedUpdate[];\n};\n"],"names":[],"mappings":";;AAEA,OAAO,EACN,WAAW,EACX,OAAO,EACP,iBAAiB,GACjB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,UAAU,WAAW,CAAC,IAAoC;IAC/D,MAAM,mBAAmB,GAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE;QACxE,WAAW,EAAE,YAAY;KACzB,CAAC,CAAC;IACH;IACC,6BAA6B;IAC7B,gCAAgC;IAChC,gDAAgD;IAChD,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAC9B,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;YAC5C,WAAW,EAAE,YAAY;SACzB,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBf,CAAC,CAAC;AACL,CAAC","debug_id":"f2febd26-8b4a-5507-b058-13bb83472533"}
|
package/dist/project/api.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { InlangDatabaseSchema } from "../database/schema.js";
|
|
|
3
3
|
import type { InlangPlugin } from "../plugin/schema.js";
|
|
4
4
|
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
5
5
|
import type { Lix } from "@lix-js/sdk";
|
|
6
|
-
import type {
|
|
6
|
+
import type { SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
7
7
|
export type InlangProject = {
|
|
8
8
|
db: Kysely<InlangDatabaseSchema>;
|
|
9
9
|
/**
|
|
@@ -12,7 +12,7 @@ export type InlangProject = {
|
|
|
12
12
|
*
|
|
13
13
|
* TODO remove this
|
|
14
14
|
*/
|
|
15
|
-
_sqlite:
|
|
15
|
+
_sqlite: SqliteWasmDatabase;
|
|
16
16
|
id: {
|
|
17
17
|
get: () => Promise<string>;
|
|
18
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"/","sources":["project/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"/","sources":["project/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC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AAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACxB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,OAAO,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK;IAC/D,WAAW,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC"}
|
package/dist/project/api.js
CHANGED
|
@@ -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]="8b543d2d-4604-5a02-a455-7740240ab059")}catch(e){}}();
|
|
3
3
|
export {};
|
|
4
4
|
//# sourceMappingURL=api.js.map
|
|
5
|
-
//# debugId=
|
|
5
|
+
//# debugId=8b543d2d-4604-5a02-a455-7740240ab059
|
package/dist/project/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":["project/api.ts"],"sourceRoot":"/","sourcesContent":["import type { Kysely } from \"kysely\";\nimport type { InlangDatabaseSchema } from \"../database/schema.js\";\nimport type { InlangPlugin } from \"../plugin/schema.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport type { Lix } from \"@lix-js/sdk\";\nimport type {
|
|
1
|
+
{"version":3,"file":"api.js","sources":["project/api.ts"],"sourceRoot":"/","sourcesContent":["import type { Kysely } from \"kysely\";\nimport type { InlangDatabaseSchema } from \"../database/schema.js\";\nimport type { InlangPlugin } from \"../plugin/schema.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport type { Lix } from \"@lix-js/sdk\";\nimport type { SqliteWasmDatabase } from \"sqlite-wasm-kysely\";\n\nexport type InlangProject = {\n\tdb: Kysely<InlangDatabaseSchema>;\n\t/**\n\t * @deprecated Don't use this. Only an internal hack to unblock\n\t * fink v2.\n\t *\n\t * TODO remove this\n\t */\n\t_sqlite: SqliteWasmDatabase;\n\tid: {\n\t\tget: () => Promise<string>;\n\t};\n\tplugins: {\n\t\tget: () => Promise<readonly InlangPlugin[]>;\n\t};\n\terrors: {\n\t\tget: () => Promise<readonly Error[]>;\n\t};\n\tsettings: {\n\t\tget: () => Promise<ProjectSettings>;\n\t\tset: (settings: ProjectSettings) => Promise<void>;\n\t};\n\tlix: Lix;\n\timportFiles: (args: {\n\t\tpluginKey: InlangPlugin[\"key\"];\n\t\tfiles: ImportFile[];\n\t}) => Promise<void>;\n\texportFiles: (args: {\n\t\tpluginKey: InlangPlugin[\"key\"];\n\t}) => Promise<ExportFile[]>;\n\tclose: () => Promise<void>;\n\ttoBlob: () => Promise<Blob>;\n};\n\nexport type ImportFile = {\n\t/** The locale of the resource file */\n\tlocale: string;\n\t/** The binary content of the resource */\n\tcontent: Uint8Array;\n\t/**\n\t * The metadata of the file to be imported.\n\t *\n\t * Used to store additional information that is accessible in `importFiles` via `toBeImportedFilesMetadata`.\n\t * https://github.com/opral/inlang-sdk/issues/218\n\t */\n\ttoBeImportedFilesMetadata?: Record<string, any>;\n};\n\nexport type ExportFile = {\n\t/** The locale of the resource file */\n\tlocale: string;\n\t/**\n\t * The name of the file.\n\t *\n\t * @example\n\t * \"en.json\"\n\t * \"common-de.json\"\n\t *\n\t */\n\tname: string;\n\t/** The binary content of the resource */\n\tcontent: Uint8Array;\n};\n\n/**\n * Minimal RxJS compatible (generic) subscription type.\n */\nexport type Subscription<T> = (callback: (value: T) => void) => {\n\tunsubscribe: () => void;\n};\n"],"names":[],"mappings":"","debug_id":"8b543d2d-4604-5a02-a455-7740240ab059"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,UAAU,2BAA2B,CAAC,IAKjD;IACA,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;QAC1B,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,CAAC;QACR,sCAAsC;QACtC,KAAK,EAAE,GAAG,EAAE;YACX,wDAAwD;YACxD,oDAAoD;YACpD,uDAAuD;YACvD,IAAI,CAAC,eAAe,CAAC,IAAI,CACxB,CAAC,KAAK,IAAI,EAAE;gBACX,IAAI,CAAC;oBACJ,qOAAqO;oBACrO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;oBACzD,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC9C,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;yBACf,WAAW,CAAC,MAAM,CAAC;yBACnB,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;yBACjB,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,YAAY,CAAC;yBAChC,OAAO,EAAE,CAAC;gBACb,CAAC;gBAAC,MAAM,CAAC;oBACR,mCAAmC;oBACnC,6BAA6B;gBAC9B,CAAC;YACF,CAAC,CAAC,EAAE,CACJ,CAAC;YACF,OAAO;QACR,CAAC;KACD,CAAC,CAAC;IAEH,yCAAyC;IACzC,MAAM,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CR,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpB,CAAC","debug_id":"1a4c93a4-17e3-5a38-bc7d-2850d39d1528"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type Account, type Lix } from "@lix-js/sdk";
|
|
2
2
|
import type { InlangPlugin } from "../plugin/schema.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
4
4
|
import { type PreprocessPluginBeforeImportFunction } from "../plugin/importPlugins.js";
|
|
5
5
|
import type { InlangProject } from "./api.js";
|
|
6
6
|
/**
|
|
7
7
|
* Common load project logic.
|
|
8
8
|
*/
|
|
9
9
|
export declare function loadProject(args: {
|
|
10
|
-
sqlite:
|
|
10
|
+
sqlite: SqliteWasmDatabase;
|
|
11
11
|
lix: Lix;
|
|
12
12
|
/**
|
|
13
13
|
* The account that loaded the project.
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EAEN,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,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,kBAAkB,CAAC;IAC3B,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,7 +1,7 @@
|
|
|
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]="92ebad4d-e869-5c7c-88e4-2a6561f4a358")}catch(e){}}();
|
|
3
3
|
import { toBlob } from "@lix-js/sdk";
|
|
4
|
-
import { contentFromDatabase } from "sqlite-wasm-kysely";
|
|
4
|
+
import { contentFromDatabase, } from "sqlite-wasm-kysely";
|
|
5
5
|
import { initDb } from "../database/initDb.js";
|
|
6
6
|
import { importPlugins, } from "../plugin/importPlugins.js";
|
|
7
7
|
import { withLanguageTagToLocaleMigration } from "../migrations/v2/withLanguageTagToLocaleMigration.js";
|
|
@@ -163,4 +163,4 @@ async function maybeMigrateFirstProjectId(args) {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
//# sourceMappingURL=loadProject.js.map
|
|
166
|
-
//# debugId=
|
|
166
|
+
//# debugId=92ebad4d-e869-5c7c-88e4-2a6561f4a358
|
|
@@ -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 { 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,EAA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SAChC,OAAO,EAAE,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,IAAkB;IAC3D,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;SAC1C,UAAU,CAAC,MAAM,CAAC;SAClB,MAAM,CAAC,MAAM,CAAC;SACd,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC;SACjC,gBAAgB,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"}
|
|
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 {\n\tcontentFromDatabase,\n\ttype SqliteWasmDatabase,\n} 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: SqliteWasmDatabase;\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: SqliteWasmDatabase;\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,EACN,mBAAmB,GAEnB,MAAM,oBAAoB,CAAC;AAC5B,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,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AAM,EAAE,IAAI,CAAC;SACjB,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,YAAY,CAAC;SAChC,OAAO,EAAE,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,IAAkB;IAC3D,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;SAC1C,UAAU,CAAC,MAAM,CAAC;SAClB,MAAM,CAAC,MAAM,CAAC;SACd,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC;SACjC,gBAAgB,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":"92ebad4d-e869-5c7c-88e4-2a6561f4a358"}
|
|
@@ -19,7 +19,7 @@ export declare function loadProjectFromDirectory(args: {
|
|
|
19
19
|
get: () => Promise<Error[]>;
|
|
20
20
|
};
|
|
21
21
|
db: import("kysely").Kysely<import("../index.js").InlangDatabaseSchema>;
|
|
22
|
-
_sqlite: import("sqlite-wasm-kysely").
|
|
22
|
+
_sqlite: import("sqlite-wasm-kysely").SqliteWasmDatabase;
|
|
23
23
|
id: {
|
|
24
24
|
get: () => Promise<string>;
|
|
25
25
|
};
|
|
@@ -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]="bcd47d9c-db1f-583a-b641-6f20646045a3")}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.1",
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
9
|
-
//# debugId=
|
|
9
|
+
//# debugId=bcd47d9c-db1f-583a-b641-6f20646045a3
|
|
@@ -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.1\",\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":"bcd47d9c-db1f-583a-b641-6f20646045a3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
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
|
-
"@lix-js/sdk": "0.3.
|
|
34
|
-
"sqlite-wasm-kysely": "0.
|
|
33
|
+
"@lix-js/sdk": "0.3.4",
|
|
34
|
+
"sqlite-wasm-kysely": "0.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@eslint/js": "^9.12.0",
|
package/src/database/initDb.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CamelCasePlugin, Kysely } from "kysely";
|
|
2
2
|
import { applySchema, type InlangDatabaseSchema } from "./schema.js";
|
|
3
|
-
import { createDialect, type
|
|
3
|
+
import { createDialect, type SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
4
4
|
import { v7 } from "uuid";
|
|
5
5
|
import { humanId } from "../human-id/human-id.js";
|
|
6
6
|
import { JsonbPlugin } from "./jsonbPlugin.js";
|
|
7
7
|
|
|
8
|
-
export function initDb(args: { sqlite:
|
|
8
|
+
export function initDb(args: { sqlite: SqliteWasmDatabase }) {
|
|
9
9
|
initDefaultValueFunctions({ sqlite: args.sqlite });
|
|
10
10
|
applySchema({ sqlite: args.sqlite });
|
|
11
11
|
const db = new Kysely<InlangDatabaseSchema>({
|
|
@@ -20,7 +20,7 @@ export function initDb(args: { sqlite: SqliteDatabase }) {
|
|
|
20
20
|
return db;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function initDefaultValueFunctions(args: { sqlite:
|
|
23
|
+
function initDefaultValueFunctions(args: { sqlite: SqliteWasmDatabase }) {
|
|
24
24
|
args.sqlite.createFunction({
|
|
25
25
|
name: "uuid_v7",
|
|
26
26
|
arity: 0,
|
|
@@ -13,14 +13,14 @@ import {
|
|
|
13
13
|
type UnknownRow,
|
|
14
14
|
OnConflictNode,
|
|
15
15
|
} from "kysely";
|
|
16
|
-
import type {
|
|
16
|
+
import type { SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
17
17
|
|
|
18
18
|
export class JsonbPlugin implements KyselyPlugin {
|
|
19
19
|
#serializeJsonTransformer = new SerializeJsonbTransformer();
|
|
20
20
|
#parseJsonPlugin = new ParseJSONResultsPlugin();
|
|
21
|
-
#database:
|
|
21
|
+
#database: SqliteWasmDatabase;
|
|
22
22
|
|
|
23
|
-
constructor(args: { database:
|
|
23
|
+
constructor(args: { database: SqliteWasmDatabase }) {
|
|
24
24
|
this.#database = args.database;
|
|
25
25
|
}
|
|
26
26
|
|
package/src/database/schema.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Generated, Insertable, Selectable, Updateable } from "kysely";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
3
3
|
import {
|
|
4
4
|
Declaration,
|
|
5
5
|
Pattern,
|
|
6
6
|
VariableReference,
|
|
7
7
|
} from "../json-schema/pattern.js";
|
|
8
8
|
|
|
9
|
-
export function applySchema(args: { sqlite:
|
|
9
|
+
export function applySchema(args: { sqlite: SqliteWasmDatabase }) {
|
|
10
10
|
const foreignKeyActivated: any = args.sqlite.exec("PRAGMA foreign_keys", {
|
|
11
11
|
returnValue: "resultRows",
|
|
12
12
|
});
|
package/src/project/api.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { InlangDatabaseSchema } from "../database/schema.js";
|
|
|
3
3
|
import type { InlangPlugin } from "../plugin/schema.js";
|
|
4
4
|
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
5
5
|
import type { Lix } from "@lix-js/sdk";
|
|
6
|
-
import type {
|
|
6
|
+
import type { SqliteWasmDatabase } from "sqlite-wasm-kysely";
|
|
7
7
|
|
|
8
8
|
export type InlangProject = {
|
|
9
9
|
db: Kysely<InlangDatabaseSchema>;
|
|
@@ -13,7 +13,7 @@ export type InlangProject = {
|
|
|
13
13
|
*
|
|
14
14
|
* TODO remove this
|
|
15
15
|
*/
|
|
16
|
-
_sqlite:
|
|
16
|
+
_sqlite: SqliteWasmDatabase;
|
|
17
17
|
id: {
|
|
18
18
|
get: () => Promise<string>;
|
|
19
19
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { toBlob, type Account, type Lix } from "@lix-js/sdk";
|
|
2
2
|
import type { InlangPlugin } from "../plugin/schema.js";
|
|
3
3
|
import type { ProjectSettings } from "../json-schema/settings.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
contentFromDatabase,
|
|
6
|
+
type SqliteWasmDatabase,
|
|
7
|
+
} from "sqlite-wasm-kysely";
|
|
5
8
|
import { initDb } from "../database/initDb.js";
|
|
6
9
|
import {
|
|
7
10
|
importPlugins,
|
|
@@ -19,7 +22,7 @@ import { exportFiles } from "../import-export/exportFiles.js";
|
|
|
19
22
|
* Common load project logic.
|
|
20
23
|
*/
|
|
21
24
|
export async function loadProject(args: {
|
|
22
|
-
sqlite:
|
|
25
|
+
sqlite: SqliteWasmDatabase;
|
|
23
26
|
lix: Lix;
|
|
24
27
|
/**
|
|
25
28
|
* The account that loaded the project.
|
|
@@ -211,7 +214,7 @@ export async function loadProject(args: {
|
|
|
211
214
|
}
|
|
212
215
|
|
|
213
216
|
async function saveDbToLix(args: {
|
|
214
|
-
sqlite:
|
|
217
|
+
sqlite: SqliteWasmDatabase;
|
|
215
218
|
lix: Lix;
|
|
216
219
|
}): Promise<void> {
|
|
217
220
|
const data = contentFromDatabase(args.sqlite);
|