Skip to content

Commit

Permalink
Merge commit 'b0d27032125779906e5a653c4536e234d0ec1fd8' into csv-app2
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-lysk committed Sep 25, 2024
2 parents de41938 + b0d2703 commit a2eaae0
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,10 @@ test("im- and exporting multiple files should succeed", async () => {
{
locale: "en",
content: new TextEncoder().encode(JSON.stringify(en)),
name: "en.json",
},
{
locale: "de",
content: new TextEncoder().encode(JSON.stringify(de)),
name: "de.json",
},
],
})
Expand Down Expand Up @@ -395,15 +393,13 @@ test("it should handle namespaces", async () => {
{
locale: "en",
content: new TextEncoder().encode(JSON.stringify(enCommon)),
name: "en.json",
toBeImportedFilesMetadata: {
namespace: "common",
},
},
{
locale: "en",
content: new TextEncoder().encode(JSON.stringify(enLogin)),
name: "en.json",
toBeImportedFilesMetadata: {
namespace: "login",
},
Expand Down Expand Up @@ -444,12 +440,10 @@ test("it should put new entities into the resource file without a namespace", as
{
locale: "en",
content: new TextEncoder().encode(JSON.stringify(enNoNamespace)),
name: "en.json",
},
{
locale: "en",
content: new TextEncoder().encode(JSON.stringify(enCommon)),
name: "en.json",
toBeImportedFilesMetadata: {
namespace: "common",
},
Expand Down Expand Up @@ -509,7 +503,6 @@ function runImportFiles(json: Record<string, any>) {
{
locale: "en",
content: new TextEncoder().encode(JSON.stringify(json)),
name: "en.json",
},
],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Match, MessageNested, ResourceFile, Variant } from "@inlang/sdk2"
import type { ExportFile, Match, MessageNested, Variant } from "@inlang/sdk2"
import { PLUGIN_KEY, type plugin } from "../plugin.js"
import type { FileSchema } from "../fileSchema.js"

Expand All @@ -18,15 +18,14 @@ export const exportFiles: NonNullable<(typeof plugin)["exportFiles"]> = async ({
files[message.locale] = { ...files[message.locale], ...serializeMessage(message) }
}

const result: ResourceFile[] = []
const result: ExportFile[] = []

for (const locale in files) {
result.push({
locale,
// beautify the json
content: new TextEncoder().encode(JSON.stringify(files[locale], undefined, "\t")),
name: locale + ".json",
pluginKey: PLUGIN_KEY,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test("it handles single variants without expressions", async () => {
{
locale: "en",
content: mockEnFile,
name: "en.json",
},
],
})
Expand Down Expand Up @@ -69,7 +68,6 @@ test("it handles variable expressions in patterns", async () => {
{
locale: "en",
content: mockEnFile,
name: "en.json",
},
],
})
Expand Down Expand Up @@ -133,7 +131,6 @@ test("it ingores the $schema property that is used for typesafety", async () =>
{
locale: "en",
content: mockEnFile,
name: "en.json",
},
],
})
Expand Down Expand Up @@ -167,12 +164,10 @@ test("it assigns the correct locales to messages", async () => {
{
locale: "en",
content: mockEnFile,
name: "en.json",
},
{
locale: "de",
content: mockDeFile,
name: "de.json",
},
],
})
Expand Down Expand Up @@ -243,7 +238,6 @@ test("it handles multi variant messages", async () => {
{
locale: "en",
content: mockEnFile,
name: "en.json",
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ test("roundtrip of import and export", async () => {
{
content: new TextEncoder().encode(JSON.stringify(mockEnFileParsed)),
locale: "en",
name: "en.json",
},
],
})
Expand Down Expand Up @@ -72,7 +71,6 @@ test("roundtrip with new variants that have been created by apps", async () => {
{
content: new TextEncoder().encode(JSON.stringify(mockEnFileParsed)),
locale: "en",
name: "en.json",
},
],
})
Expand Down
14 changes: 8 additions & 6 deletions inlang/source-code/sdk2/src/import-export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { ProjectSettings } from "../json-schema/settings.js";
import type { InlangDatabaseSchema } from "../database/schema.js";
import { selectBundleNested } from "../query-utilities/selectBundleNested.js";
import type { InlangPlugin } from "../plugin/schema.js";
import type { ResourceFile } from "../project/api.js";
import { upsertBundleNestedMatchByProperties } from "../query-utilities/upsertBundleNestedMatchByProperties.js";
import type { ImportFile } from "../project/api.js";
import { upsertBundleNestedMatchByProperties } from "./upsertBundleNestedMatchByProperties.js";

export async function importFiles(opts: {
files: ResourceFile[];
files: ImportFile[];
readonly pluginKey: string;
readonly settings: ProjectSettings;
readonly plugins: readonly InlangPlugin[];
Expand All @@ -36,7 +36,6 @@ export async function importFiles(opts: {
);

await Promise.all(insertPromises);
return bundles;
}

export async function exportFiles(opts: {
Expand All @@ -54,8 +53,11 @@ export async function exportFiles(opts: {
});
}

const bundles = await selectBundleNested(opts.db).selectAll().execute();
const files = plugin.exportFiles({
const bundles = await selectBundleNested(opts.db)
.orderBy("id asc")
.selectAll()
.execute();
const files = await plugin.exportFiles({
bundles: bundles,
settings: structuredClone(opts.settings),
});
Expand Down
Loading

0 comments on commit a2eaae0

Please sign in to comment.