@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.
Files changed (60) hide show
  1. package/dist/adapter/solidAdapter.test.js +52 -4
  2. package/dist/api.d.ts +3 -0
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/createMessageLintReportsQuery.d.ts +1 -1
  5. package/dist/createMessageLintReportsQuery.d.ts.map +1 -1
  6. package/dist/createMessageLintReportsQuery.js +30 -22
  7. package/dist/createMessagesQuery.d.ts.map +1 -1
  8. package/dist/createMessagesQuery.js +24 -1
  9. package/dist/createMessagesQuery.test.js +46 -2
  10. package/dist/createNodeishFsWithAbsolutePaths.d.ts +3 -3
  11. package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +1 -1
  12. package/dist/createNodeishFsWithAbsolutePaths.js +9 -1
  13. package/dist/createNodeishFsWithAbsolutePaths.test.js +7 -1
  14. package/dist/createNodeishFsWithWatcher.d.ts +3 -3
  15. package/dist/createNodeishFsWithWatcher.d.ts.map +1 -1
  16. package/dist/createNodeishFsWithWatcher.js +3 -0
  17. package/dist/errors.d.ts +14 -0
  18. package/dist/errors.d.ts.map +1 -1
  19. package/dist/errors.js +12 -0
  20. package/dist/loadProject.d.ts.map +1 -1
  21. package/dist/loadProject.js +472 -39
  22. package/dist/loadProject.test.js +91 -14
  23. package/dist/messages/variant.test.js +3 -0
  24. package/dist/resolve-modules/plugins/resolvePlugins.test.js +4 -2
  25. package/dist/storage/helper.d.ts +5 -0
  26. package/dist/storage/helper.d.ts.map +1 -0
  27. package/dist/storage/helper.js +35 -0
  28. package/dist/storage/human-id/human-readable-id.d.ts +3 -0
  29. package/dist/storage/human-id/human-readable-id.d.ts.map +1 -0
  30. package/dist/storage/human-id/human-readable-id.js +20 -0
  31. package/dist/storage/human-id/words.d.ts +5 -0
  32. package/dist/storage/human-id/words.d.ts.map +1 -0
  33. package/dist/storage/human-id/words.js +1032 -0
  34. package/dist/storage/human-id/words.test.d.ts +2 -0
  35. package/dist/storage/human-id/words.test.d.ts.map +1 -0
  36. package/dist/storage/human-id/words.test.js +25 -0
  37. package/dist/test-utilities/createMessage.d.ts +1 -0
  38. package/dist/test-utilities/createMessage.d.ts.map +1 -1
  39. package/dist/test-utilities/createMessage.js +1 -0
  40. package/dist/test-utilities/createMessage.test.js +70 -55
  41. package/package.json +12 -8
  42. package/src/adapter/solidAdapter.test.ts +76 -4
  43. package/src/api.ts +4 -0
  44. package/src/createMessageLintReportsQuery.ts +46 -34
  45. package/src/createMessagesQuery.test.ts +54 -2
  46. package/src/createMessagesQuery.ts +30 -1
  47. package/src/createNodeishFsWithAbsolutePaths.test.ts +10 -3
  48. package/src/createNodeishFsWithAbsolutePaths.ts +14 -5
  49. package/src/createNodeishFsWithWatcher.ts +6 -3
  50. package/src/errors.ts +20 -0
  51. package/src/loadProject.test.ts +106 -14
  52. package/src/loadProject.ts +655 -60
  53. package/src/messages/variant.test.ts +3 -0
  54. package/src/resolve-modules/plugins/resolvePlugins.test.ts +4 -2
  55. package/src/storage/helper.ts +48 -0
  56. package/src/storage/human-id/human-readable-id.ts +27 -0
  57. package/src/storage/human-id/words.test.ts +27 -0
  58. package/src/storage/human-id/words.ts +1035 -0
  59. package/src/test-utilities/createMessage.test.ts +72 -54
  60. 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 () => [{ id: "test", expressions: [], selectors: [], variants: [] }],
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
+ })