@inlang/sdk 0.26.5 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/solidAdapter.test.js +52 -4
- package/dist/api.d.ts +3 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/createMessageLintReportsQuery.d.ts +1 -1
- package/dist/createMessageLintReportsQuery.d.ts.map +1 -1
- package/dist/createMessageLintReportsQuery.js +30 -22
- package/dist/createMessagesQuery.d.ts.map +1 -1
- package/dist/createMessagesQuery.js +24 -1
- package/dist/createMessagesQuery.test.js +46 -2
- package/dist/createNodeishFsWithAbsolutePaths.d.ts +3 -3
- package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +1 -1
- package/dist/createNodeishFsWithAbsolutePaths.js +9 -1
- package/dist/createNodeishFsWithAbsolutePaths.test.js +7 -1
- package/dist/createNodeishFsWithWatcher.d.ts +3 -3
- package/dist/createNodeishFsWithWatcher.d.ts.map +1 -1
- package/dist/createNodeishFsWithWatcher.js +3 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +12 -0
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +472 -39
- package/dist/loadProject.test.js +91 -14
- package/dist/messages/variant.test.js +3 -0
- package/dist/resolve-modules/plugins/resolvePlugins.test.js +4 -2
- package/dist/storage/helper.d.ts +5 -0
- package/dist/storage/helper.d.ts.map +1 -0
- package/dist/storage/helper.js +35 -0
- package/dist/storage/human-id/human-readable-id.d.ts +3 -0
- package/dist/storage/human-id/human-readable-id.d.ts.map +1 -0
- package/dist/storage/human-id/human-readable-id.js +20 -0
- package/dist/storage/human-id/words.d.ts +5 -0
- package/dist/storage/human-id/words.d.ts.map +1 -0
- package/dist/storage/human-id/words.js +1032 -0
- package/dist/storage/human-id/words.test.d.ts +2 -0
- package/dist/storage/human-id/words.test.d.ts.map +1 -0
- package/dist/storage/human-id/words.test.js +25 -0
- package/dist/test-utilities/createMessage.d.ts +1 -0
- package/dist/test-utilities/createMessage.d.ts.map +1 -1
- package/dist/test-utilities/createMessage.js +1 -0
- package/dist/test-utilities/createMessage.test.js +70 -55
- package/package.json +12 -8
- package/src/adapter/solidAdapter.test.ts +76 -4
- package/src/api.ts +4 -0
- package/src/createMessageLintReportsQuery.ts +46 -34
- package/src/createMessagesQuery.test.ts +54 -2
- package/src/createMessagesQuery.ts +30 -1
- package/src/createNodeishFsWithAbsolutePaths.test.ts +10 -3
- package/src/createNodeishFsWithAbsolutePaths.ts +14 -5
- package/src/createNodeishFsWithWatcher.ts +6 -3
- package/src/errors.ts +20 -0
- package/src/loadProject.test.ts +106 -14
- package/src/loadProject.ts +655 -60
- package/src/messages/variant.test.ts +3 -0
- package/src/resolve-modules/plugins/resolvePlugins.test.ts +4 -2
- package/src/storage/helper.ts +48 -0
- package/src/storage/human-id/human-readable-id.ts +27 -0
- package/src/storage/human-id/words.test.ts +27 -0
- package/src/storage/human-id/words.ts +1035 -0
- package/src/test-utilities/createMessage.test.ts +72 -54
- package/src/test-utilities/createMessage.ts +1 -0
|
@@ -43,6 +43,7 @@ describe("getVariant", () => {
|
|
|
43
43
|
test("it should not throw error if selector is empty and match", () => {
|
|
44
44
|
const mockMessage: Message = {
|
|
45
45
|
id: "mockMessage",
|
|
46
|
+
alias: {},
|
|
46
47
|
selectors: [],
|
|
47
48
|
variants: [
|
|
48
49
|
{
|
|
@@ -69,6 +70,7 @@ describe("getVariant", () => {
|
|
|
69
70
|
test("it should not throw error if selector is empty, return undefined", () => {
|
|
70
71
|
const mockMessage: Message = {
|
|
71
72
|
id: "mockMessage",
|
|
73
|
+
alias: {},
|
|
72
74
|
selectors: [],
|
|
73
75
|
variants: [
|
|
74
76
|
{
|
|
@@ -397,6 +399,7 @@ describe("updateVariant", () => {
|
|
|
397
399
|
const getMockMessage = (): Message => {
|
|
398
400
|
return {
|
|
399
401
|
id: "first-message",
|
|
402
|
+
alias: {},
|
|
400
403
|
selectors: [
|
|
401
404
|
{ type: "VariableReference", name: "gender" },
|
|
402
405
|
{ type: "VariableReference", name: "guestOther" },
|
|
@@ -70,7 +70,9 @@ describe("loadMessages", () => {
|
|
|
70
70
|
id: "plugin.namespace.placeholder",
|
|
71
71
|
description: { en: "My plugin description" },
|
|
72
72
|
displayName: { en: "My plugin" },
|
|
73
|
-
loadMessages: async () => [
|
|
73
|
+
loadMessages: async () => [
|
|
74
|
+
{ id: "test", alias: {}, expressions: [], selectors: [], variants: [] },
|
|
75
|
+
],
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
const resolved = await resolvePlugins({
|
|
@@ -84,7 +86,7 @@ describe("loadMessages", () => {
|
|
|
84
86
|
settings: {} as any,
|
|
85
87
|
nodeishFs: {} as any,
|
|
86
88
|
})
|
|
87
|
-
).toEqual([{ id: "test", expressions: [], selectors: [], variants: [] }])
|
|
89
|
+
).toEqual([{ id: "test", alias: {}, expressions: [], selectors: [], variants: [] }])
|
|
88
90
|
})
|
|
89
91
|
|
|
90
92
|
it("should collect an error if function is defined twice in multiple plugins", async () => {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Message, Variant } from "../versionedInterfaces.js"
|
|
2
|
+
|
|
3
|
+
const fileExtension = ".json"
|
|
4
|
+
|
|
5
|
+
export function getMessageIdFromPath(path: string) {
|
|
6
|
+
if (!path.endsWith(fileExtension)) {
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const cleanedPath = path.replace(/\/$/, "") // This regex matches a trailing slash and replaces it with an empty string
|
|
11
|
+
const messageFileName = cleanedPath.split("/").join("_") // we split by the first leading namespace or _ separator - make sure slashes don't exit in the id
|
|
12
|
+
// const messageFileName = pathParts.at(-1)!
|
|
13
|
+
|
|
14
|
+
const lastDotIndex = messageFileName.lastIndexOf(".")
|
|
15
|
+
|
|
16
|
+
// Extract until the last dot (excluding the dot)
|
|
17
|
+
return messageFileName.slice(0, Math.max(0, lastDotIndex))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getPathFromMessageId(id: string) {
|
|
21
|
+
const path = id.replace("_", "/") + fileExtension
|
|
22
|
+
return path
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function stringifyMessage(message: Message) {
|
|
26
|
+
// create a new object do specify key output order
|
|
27
|
+
const messageWithSortedKeys: any = {}
|
|
28
|
+
for (const key of Object.keys(message).sort()) {
|
|
29
|
+
messageWithSortedKeys[key] = (message as any)[key]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// lets order variants as well
|
|
33
|
+
messageWithSortedKeys["variants"] = messageWithSortedKeys["variants"].sort(
|
|
34
|
+
(variantA: Variant, variantB: Variant) => {
|
|
35
|
+
// First, compare by language
|
|
36
|
+
const languageComparison = variantA.languageTag.localeCompare(variantB.languageTag)
|
|
37
|
+
|
|
38
|
+
// If languages are the same, compare by match
|
|
39
|
+
if (languageComparison === 0) {
|
|
40
|
+
return variantA.match.join("-").localeCompare(variantB.match.join("-"))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return languageComparison
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return JSON.stringify(messageWithSortedKeys, undefined, 4)
|
|
48
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// we use murmur for best distribution https://medium.com/miro-engineering/choosing-a-hash-function-to-solve-a-data-sharding-problem-c656259e2b54
|
|
2
|
+
import murmurhash3 from "murmurhash3js"
|
|
3
|
+
import { adjectives, animals, adverbs, verbs } from "./words.js"
|
|
4
|
+
|
|
5
|
+
export function randomHumanId() {
|
|
6
|
+
return `${adjectives[Math.floor(Math.random() * 256)]}_${
|
|
7
|
+
adjectives[Math.floor(Math.random() * 256)]
|
|
8
|
+
}_${animals[Math.floor(Math.random() * 256)]}_${verbs[Math.floor(Math.random() * 256)]}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function humanIdHash(value: string, offset: number = 0) {
|
|
12
|
+
// Seed value can be any arbitrary value
|
|
13
|
+
const seed = 42
|
|
14
|
+
|
|
15
|
+
// Use MurmurHash3 to produce a 32-bit hash
|
|
16
|
+
const hash32 = murmurhash3.x86.hash32(value, seed)
|
|
17
|
+
// Add 1 and take modulo 2^32 to fit within 32 bits
|
|
18
|
+
const hash32WithOffset: number = (hash32 + offset) >>> 0
|
|
19
|
+
|
|
20
|
+
// Extract four 8-bit parts
|
|
21
|
+
const part1 = (hash32WithOffset >>> 24) & 0xff
|
|
22
|
+
const part2 = (hash32WithOffset >>> 16) & 0xff
|
|
23
|
+
const part3 = (hash32WithOffset >>> 8) & 0xff
|
|
24
|
+
const part4 = hash32WithOffset & 0xff
|
|
25
|
+
|
|
26
|
+
return `${adjectives[part1]}_${animals[part2]}_${verbs[part3]}_${adverbs[part4]}`
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import { adjectives, animals, adverbs, verbs } from "./words.js"
|
|
3
|
+
|
|
4
|
+
const wordlists = [adjectives, animals, adverbs, verbs]
|
|
5
|
+
const allwords = [...adjectives, ...animals, ...adverbs, ...verbs]
|
|
6
|
+
|
|
7
|
+
describe("wordlists", () => {
|
|
8
|
+
it("should have 256 words", () => {
|
|
9
|
+
for (const wordlist of wordlists) {
|
|
10
|
+
expect(wordlist.length).toBe(256)
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
it("words should be unique across lists", () => {
|
|
14
|
+
const unique = new Set(allwords)
|
|
15
|
+
expect(unique.size).toBe(256 * 4)
|
|
16
|
+
})
|
|
17
|
+
it("words should have < 10 characters", () => {
|
|
18
|
+
for (const word of allwords) {
|
|
19
|
+
expect(word.length).toBeLessThan(10)
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
it("words should match /^[a-z]+$/", () => {
|
|
23
|
+
for (const word of allwords) {
|
|
24
|
+
expect(word.match(/^[a-z]+$/) !== null).toBe(true)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|