@inlang/sdk 0.34.8 → 0.34.9

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/api.d.ts CHANGED
@@ -48,7 +48,7 @@ export type InlangProject = {
48
48
  };
49
49
  /**
50
50
  * WIP template for async V2 crud interfaces
51
- * E.g. `project.messageBundles.get({ id: "..." })`
51
+ * E.g. `await project.messageBundles.get({ id: "..." })`
52
52
  **/
53
53
  interface Query<T> {
54
54
  get: (args: unknown) => Promise<T>;
@@ -2,7 +2,11 @@ import type { InlangProject, InstalledMessageLintRule, MessageQueryApi } from ".
2
2
  import type { ProjectSettings } from "@inlang/project-settings";
3
3
  import type { resolveModules } from "./resolve-modules/index.js";
4
4
  /**
5
- * Creates a ~~reactive~~ query API for lint reports.
5
+ * Creates a non-reactive async query API for lint reports.
6
+ * e.g. used in editor/.../Listheader.tsx
7
+ *
8
+ * TODO MESDK-50: reactivity should be restored in future
9
+ * See https://github.com/opral/monorepo/pull/2378 for why this design.
6
10
  */
7
11
  export declare function createMessageLintReportsQuery(messagesQuery: MessageQueryApi, settings: () => ProjectSettings, installedMessageLintRules: () => Array<InstalledMessageLintRule>, resolvedModules: () => Awaited<ReturnType<typeof resolveModules>> | undefined): InlangProject["query"]["messageLintReports"];
8
12
  //# sourceMappingURL=createMessageLintReportsQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createMessageLintReportsQuery.d.ts","sourceRoot":"","sources":["../src/createMessageLintReportsQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,wBAAwB,EAExB,eAAe,EAEf,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAQhE;;GAEG;AACH,wBAAgB,6BAA6B,CAC5C,aAAa,EAAE,eAAe,EAC9B,QAAQ,EAAE,MAAM,eAAe,EAC/B,yBAAyB,EAAE,MAAM,KAAK,CAAC,wBAAwB,CAAC,EAChE,eAAe,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,GAAG,SAAS,GAC3E,aAAa,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,CA6E9C"}
1
+ {"version":3,"file":"createMessageLintReportsQuery.d.ts","sourceRoot":"","sources":["../src/createMessageLintReportsQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,wBAAwB,EAExB,eAAe,EAEf,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAWhE;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC5C,aAAa,EAAE,eAAe,EAC9B,QAAQ,EAAE,MAAM,eAAe,EAC/B,yBAAyB,EAAE,MAAM,KAAK,CAAC,wBAAwB,CAAC,EAChE,eAAe,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,GAAG,SAAS,GAC3E,aAAa,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,CA8E9C"}
@@ -1,9 +1,15 @@
1
1
  import { lintSingleMessage } from "./lint/index.js";
2
+ import _debug from "debug";
3
+ const debug = _debug("sdk:lintReports");
2
4
  function sleep(ms) {
3
5
  return new Promise((resolve) => setTimeout(resolve, ms));
4
6
  }
5
7
  /**
6
- * Creates a ~~reactive~~ query API for lint reports.
8
+ * Creates a non-reactive async query API for lint reports.
9
+ * e.g. used in editor/.../Listheader.tsx
10
+ *
11
+ * TODO MESDK-50: reactivity should be restored in future
12
+ * See https://github.com/opral/monorepo/pull/2378 for why this design.
7
13
  */
8
14
  export function createMessageLintReportsQuery(messagesQuery, settings, installedMessageLintRules, resolvedModules) {
9
15
  const index = new Map();
@@ -28,7 +34,7 @@ export function createMessageLintReportsQuery(messagesQuery, settings, installed
28
34
  message: message,
29
35
  }).then((report) => {
30
36
  if (report.errors.length === 0 && index.get(message.id) !== report.data) {
31
- // console.log("lintSingleMessage", messageId, report.data.length)
37
+ debug("lintSingleMessage", message.id, report.data.length);
32
38
  index.set(message.id, report.data);
33
39
  }
34
40
  });
@@ -63,10 +69,13 @@ export function createMessageLintReportsQuery(messagesQuery, settings, installed
63
69
  return {
64
70
  getAll: async () => {
65
71
  await sleep(0); // evaluate on next tick to allow for out-of-order effects
66
- return structuredClone([...index.values()].flat().length === 0 ? [] : [...index.values()].flat());
72
+ const flatValues = [...index.values()].flat();
73
+ debug("getAll", flatValues.length);
74
+ return structuredClone(flatValues.length === 0 ? [] : flatValues);
67
75
  },
68
76
  get: async (args) => {
69
77
  await sleep(0); // evaluate on next tick to allow for out-of-order effects
78
+ debug("get", args.where.messageId);
70
79
  return structuredClone(index.get(args.where.messageId) ?? []);
71
80
  },
72
81
  };
@@ -9,7 +9,7 @@ import _debug from "debug";
9
9
  import { releaseLock } from "./persistence/filelock/releaseLock.js";
10
10
  import { PluginLoadMessagesError, PluginSaveMessagesError } from "./errors.js";
11
11
  import { humanIdHash } from "./storage/human-id/human-readable-id.js";
12
- const debug = _debug("sdk:createMessagesQuery");
12
+ const debug = _debug("sdk:messages");
13
13
  function sleep(ms) {
14
14
  return new Promise((resolve) => setTimeout(resolve, ms));
15
15
  }
@@ -3,11 +3,6 @@ import { ProjectSettings } from "@inlang/project-settings";
3
3
  /**
4
4
  * Creates a new project in the given directory.
5
5
  * The directory must be an absolute path, must not exist, and must end with {name}.inlang
6
- * Uses defaultProjectSettings unless projectSettings are provided.
7
- *
8
- * @param projectPath - Absolute path to the [name].inlang directory
9
- * @param repo - An instance of a lix repo as returned by `openRepository`
10
- * @param projectSettings - Optional project settings to use for the new project.
11
6
  */
12
7
  export declare function createNewProject(args: {
13
8
  projectPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"createNewProject.d.ts","sourceRoot":"","sources":["../src/createNewProject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAI1D;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;IAChB,eAAe,EAAE,eAAe,CAAA;CAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhB"}
1
+ {"version":3,"file":"createNewProject.d.ts","sourceRoot":"","sources":["../src/createNewProject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAI1D;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;IAChB,eAAe,EAAE,eAAe,CAAA;CAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhB"}
@@ -4,11 +4,6 @@ import { defaultProjectSettings } from "./defaultProjectSettings.js";
4
4
  /**
5
5
  * Creates a new project in the given directory.
6
6
  * The directory must be an absolute path, must not exist, and must end with {name}.inlang
7
- * Uses defaultProjectSettings unless projectSettings are provided.
8
- *
9
- * @param projectPath - Absolute path to the [name].inlang directory
10
- * @param repo - An instance of a lix repo as returned by `openRepository`
11
- * @param projectSettings - Optional project settings to use for the new project.
12
7
  */
13
8
  export async function createNewProject(args) {
14
9
  assertValidProjectPath(args.projectPath);
@@ -1 +1 @@
1
- {"version":3,"file":"acquireFileLock.d.ts","sourceRoot":"","sources":["../../../src/persistence/filelock/acquireFileLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAQnD,wBAAsB,eAAe,CACpC,EAAE,EAAE,iBAAiB,EACrB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,MAAU,GAClB,OAAO,CAAC,MAAM,CAAC,CA8GjB"}
1
+ {"version":3,"file":"acquireFileLock.d.ts","sourceRoot":"","sources":["../../../src/persistence/filelock/acquireFileLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAQnD,wBAAsB,eAAe,CACpC,EAAE,EAAE,iBAAiB,EACrB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,MAAU,GAClB,OAAO,CAAC,MAAM,CAAC,CAgHjB"}
@@ -1,12 +1,12 @@
1
1
  import {} from "@lix-js/fs";
2
2
  import _debug from "debug";
3
- const debug = _debug("sdk:acquireFileLock");
3
+ const debug = _debug("sdk:fileLock");
4
4
  const maxRetries = 10;
5
5
  const nProbes = 50;
6
6
  const probeInterval = 100;
7
7
  export async function acquireFileLock(fs, lockDirPath, lockOrigin, tryCount = 0) {
8
8
  if (tryCount > maxRetries) {
9
- throw new Error(lockOrigin + " exceeded maximum Retries (5) to acquire lockfile " + tryCount);
9
+ throw new Error(`${lockOrigin} exceeded maximum retries (${maxRetries}) to acquire lockfile ${tryCount}`);
10
10
  }
11
11
  try {
12
12
  debug(lockOrigin + " tries to acquire a lockfile Retry Nr.: " + tryCount);
@@ -1,6 +1,6 @@
1
1
  import {} from "@lix-js/fs";
2
2
  import _debug from "debug";
3
- const debug = _debug("sdk:releaseLock");
3
+ const debug = _debug("sdk:fileLock");
4
4
  export async function releaseLock(fs, lockDirPath, lockOrigin, lockTime) {
5
5
  debug(lockOrigin + " releasing the lock ");
6
6
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inlang/sdk",
3
3
  "type": "module",
4
- "version": "0.34.8",
4
+ "version": "0.34.9",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -42,8 +42,8 @@
42
42
  "@inlang/project-settings": "2.4.2",
43
43
  "@inlang/result": "1.1.0",
44
44
  "@inlang/translatable": "1.3.1",
45
- "@lix-js/fs": "1.0.0",
46
- "@lix-js/client": "1.4.0"
45
+ "@lix-js/client": "1.4.0",
46
+ "@lix-js/fs": "1.0.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/debug": "^4.1.12",
package/src/api.ts CHANGED
@@ -65,7 +65,7 @@ export type InlangProject = {
65
65
 
66
66
  /**
67
67
  * WIP template for async V2 crud interfaces
68
- * E.g. `project.messageBundles.get({ id: "..." })`
68
+ * E.g. `await project.messageBundles.get({ id: "..." })`
69
69
  **/
70
70
  interface Query<T> {
71
71
  get: (args: unknown) => Promise<T>
@@ -10,12 +10,19 @@ import type { resolveModules } from "./resolve-modules/index.js"
10
10
  import type { MessageLintReport, Message } from "./versionedInterfaces.js"
11
11
  import { lintSingleMessage } from "./lint/index.js"
12
12
 
13
+ import _debug from "debug"
14
+ const debug = _debug("sdk:lintReports")
15
+
13
16
  function sleep(ms: number) {
14
17
  return new Promise((resolve) => setTimeout(resolve, ms))
15
18
  }
16
19
 
17
20
  /**
18
- * Creates a ~~reactive~~ query API for lint reports.
21
+ * Creates a non-reactive async query API for lint reports.
22
+ * e.g. used in editor/.../Listheader.tsx
23
+ *
24
+ * TODO MESDK-50: reactivity should be restored in future
25
+ * See https://github.com/opral/monorepo/pull/2378 for why this design.
19
26
  */
20
27
  export function createMessageLintReportsQuery(
21
28
  messagesQuery: MessageQueryApi,
@@ -51,7 +58,7 @@ export function createMessageLintReportsQuery(
51
58
  message: message,
52
59
  }).then((report) => {
53
60
  if (report.errors.length === 0 && index.get(message.id) !== report.data) {
54
- // console.log("lintSingleMessage", messageId, report.data.length)
61
+ debug("lintSingleMessage", message.id, report.data.length)
55
62
  index.set(message.id, report.data)
56
63
  }
57
64
  })
@@ -90,12 +97,13 @@ export function createMessageLintReportsQuery(
90
97
  return {
91
98
  getAll: async () => {
92
99
  await sleep(0) // evaluate on next tick to allow for out-of-order effects
93
- return structuredClone(
94
- [...index.values()].flat().length === 0 ? [] : [...index.values()].flat()
95
- )
100
+ const flatValues = [...index.values()].flat()
101
+ debug("getAll", flatValues.length)
102
+ return structuredClone(flatValues.length === 0 ? [] : flatValues)
96
103
  },
97
104
  get: async (args: Parameters<MessageLintReportsQueryApi["get"]>[0]) => {
98
105
  await sleep(0) // evaluate on next tick to allow for out-of-order effects
106
+ debug("get", args.where.messageId)
99
107
  return structuredClone(index.get(args.where.messageId) ?? [])
100
108
  },
101
109
  }
@@ -15,7 +15,7 @@ import type { ProjectSettings } from "@inlang/project-settings"
15
15
  import { releaseLock } from "./persistence/filelock/releaseLock.js"
16
16
  import { PluginLoadMessagesError, PluginSaveMessagesError } from "./errors.js"
17
17
  import { humanIdHash } from "./storage/human-id/human-readable-id.js"
18
- const debug = _debug("sdk:createMessagesQuery")
18
+ const debug = _debug("sdk:messages")
19
19
 
20
20
  function sleep(ms: number) {
21
21
  return new Promise((resolve) => setTimeout(resolve, ms))
@@ -6,11 +6,6 @@ import { defaultProjectSettings } from "./defaultProjectSettings.js"
6
6
  /**
7
7
  * Creates a new project in the given directory.
8
8
  * The directory must be an absolute path, must not exist, and must end with {name}.inlang
9
- * Uses defaultProjectSettings unless projectSettings are provided.
10
- *
11
- * @param projectPath - Absolute path to the [name].inlang directory
12
- * @param repo - An instance of a lix repo as returned by `openRepository`
13
- * @param projectSettings - Optional project settings to use for the new project.
14
9
  */
15
10
  export async function createNewProject(args: {
16
11
  projectPath: string
@@ -1,7 +1,7 @@
1
1
  import { type NodeishFilesystem } from "@lix-js/fs"
2
2
  import type { NodeishStats } from "@lix-js/fs"
3
3
  import _debug from "debug"
4
- const debug = _debug("sdk:acquireFileLock")
4
+ const debug = _debug("sdk:fileLock")
5
5
 
6
6
  const maxRetries = 10
7
7
  const nProbes = 50
@@ -13,7 +13,9 @@ export async function acquireFileLock(
13
13
  tryCount: number = 0
14
14
  ): Promise<number> {
15
15
  if (tryCount > maxRetries) {
16
- throw new Error(lockOrigin + " exceeded maximum Retries (5) to acquire lockfile " + tryCount)
16
+ throw new Error(
17
+ `${lockOrigin} exceeded maximum retries (${maxRetries}) to acquire lockfile ${tryCount}`
18
+ )
17
19
  }
18
20
 
19
21
  try {
@@ -1,6 +1,6 @@
1
1
  import { type NodeishFilesystem } from "@lix-js/fs"
2
2
  import _debug from "debug"
3
- const debug = _debug("sdk:releaseLock")
3
+ const debug = _debug("sdk:fileLock")
4
4
 
5
5
  export async function releaseLock(
6
6
  fs: NodeishFilesystem,