@inlang/sdk 0.35.5 → 0.35.7
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 +2 -13
- package/dist/api.d.ts.map +1 -1
- package/dist/createNewProject.test.js +1 -3
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +67 -32
- package/dist/loadProject.test.js +6 -2
- package/dist/persistence/batchedIO.d.ts +11 -0
- package/dist/persistence/batchedIO.d.ts.map +1 -0
- package/dist/persistence/batchedIO.js +49 -0
- package/dist/persistence/batchedIO.test.d.ts +2 -0
- package/dist/persistence/batchedIO.test.d.ts.map +1 -0
- package/dist/persistence/batchedIO.test.js +56 -0
- package/dist/persistence/filelock/acquireFileLock.d.ts.map +1 -1
- package/dist/persistence/filelock/acquireFileLock.js +3 -1
- package/dist/persistence/filelock/releaseLock.d.ts.map +1 -1
- package/dist/persistence/filelock/releaseLock.js +2 -1
- package/dist/persistence/store.d.ts +107 -0
- package/dist/persistence/store.d.ts.map +1 -0
- package/dist/persistence/store.js +99 -0
- package/dist/persistence/store.test.d.ts +2 -0
- package/dist/persistence/store.test.d.ts.map +1 -0
- package/dist/persistence/store.test.js +79 -0
- package/dist/persistence/storeApi.d.ts +22 -0
- package/dist/persistence/storeApi.d.ts.map +1 -0
- package/dist/persistence/storeApi.js +1 -0
- package/dist/reactivity/solid.test.js +1 -6
- package/dist/resolve-modules/plugins/resolvePlugins.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/resolvePlugins.js +3 -10
- package/dist/test-utilities/sleep.d.ts +4 -0
- package/dist/test-utilities/sleep.d.ts.map +1 -0
- package/dist/test-utilities/sleep.js +9 -0
- package/dist/v2/helper.d.ts +131 -0
- package/dist/v2/helper.d.ts.map +1 -0
- package/dist/v2/helper.js +75 -0
- package/dist/v2/helper.test.d.ts +2 -0
- package/dist/v2/helper.test.d.ts.map +1 -0
- package/dist/v2/{createMessageBundle.test.js → helper.test.js} +1 -1
- package/dist/v2/index.d.ts +2 -0
- package/dist/v2/index.d.ts.map +1 -1
- package/dist/v2/index.js +2 -1
- package/dist/v2/mocks/index.d.ts +3 -0
- package/dist/v2/mocks/index.d.ts.map +1 -0
- package/dist/v2/mocks/index.js +2 -0
- package/dist/v2/mocks/multipleMatcher/bundle.d.ts +3 -0
- package/dist/v2/mocks/multipleMatcher/bundle.d.ts.map +1 -0
- package/dist/v2/mocks/multipleMatcher/bundle.js +194 -0
- package/dist/v2/mocks/multipleMatcher/bundle.test.d.ts +2 -0
- package/dist/v2/mocks/multipleMatcher/bundle.test.d.ts.map +1 -0
- package/dist/v2/mocks/multipleMatcher/bundle.test.js +10 -0
- package/dist/v2/mocks/plural/bundle.d.ts +1 -1
- package/dist/v2/mocks/plural/bundle.d.ts.map +1 -1
- package/dist/v2/mocks/plural/bundle.js +1 -1
- package/dist/v2/mocks/plural/bundle.test.js +6 -6
- package/dist/v2/shim.d.ts +12 -0
- package/dist/v2/shim.d.ts.map +1 -0
- package/dist/v2/shim.js +151 -0
- package/dist/v2/shim.test.d.ts +2 -0
- package/dist/v2/shim.test.d.ts.map +1 -0
- package/dist/v2/shim.test.js +49 -0
- package/dist/v2/stubQueryApi.d.ts +9 -0
- package/dist/v2/stubQueryApi.d.ts.map +1 -0
- package/dist/v2/stubQueryApi.js +38 -0
- package/dist/v2/types.d.ts +110 -0
- package/dist/v2/types.d.ts.map +1 -1
- package/dist/v2/types.js +9 -0
- package/package.json +6 -5
- package/src/api.ts +2 -13
- package/src/createNewProject.test.ts +1 -4
- package/src/loadProject.test.ts +6 -2
- package/src/loadProject.ts +86 -45
- package/src/persistence/batchedIO.test.ts +63 -0
- package/src/persistence/batchedIO.ts +64 -0
- package/src/persistence/filelock/acquireFileLock.ts +5 -2
- package/src/persistence/filelock/releaseLock.ts +2 -1
- package/src/persistence/store.test.ts +102 -0
- package/src/persistence/store.ts +119 -0
- package/src/persistence/storeApi.ts +19 -0
- package/src/reactivity/solid.test.ts +1 -8
- package/src/resolve-modules/plugins/resolvePlugins.ts +4 -13
- package/src/test-utilities/sleep.ts +11 -0
- package/src/v2/{createMessageBundle.test.ts → helper.test.ts} +1 -1
- package/src/v2/helper.ts +98 -0
- package/src/v2/index.ts +2 -0
- package/src/v2/mocks/index.ts +2 -0
- package/src/v2/mocks/multipleMatcher/bundle.test.ts +11 -0
- package/src/v2/mocks/multipleMatcher/bundle.ts +196 -0
- package/src/v2/mocks/plural/bundle.test.ts +6 -6
- package/src/v2/mocks/plural/bundle.ts +1 -1
- package/src/v2/shim.test.ts +56 -0
- package/src/v2/shim.ts +173 -0
- package/src/v2/stubQueryApi.ts +43 -0
- package/src/v2/types.ts +17 -0
- package/dist/persistence/plugin.d.ts +0 -31
- package/dist/persistence/plugin.d.ts.map +0 -1
- package/dist/persistence/plugin.js +0 -42
- package/dist/persistence/plugin.test.d.ts +0 -2
- package/dist/persistence/plugin.test.d.ts.map +0 -1
- package/dist/persistence/plugin.test.js +0 -49
- package/dist/v2/createMessageBundle.d.ts +0 -25
- package/dist/v2/createMessageBundle.d.ts.map +0 -1
- package/dist/v2/createMessageBundle.js +0 -36
- package/dist/v2/createMessageBundle.test.d.ts +0 -2
- package/dist/v2/createMessageBundle.test.d.ts.map +0 -1
- package/src/persistence/plugin.test.ts +0 -60
- package/src/persistence/plugin.ts +0 -56
- package/src/v2/createMessageBundle.ts +0 -43
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { describe, it, expect } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import { pluralBundle } from "./bundle.js";
|
|
4
4
|
import { MessageBundle } from "../../types.js";
|
|
5
5
|
import { Value } from "@sinclair/typebox/value";
|
|
6
6
|
describe("mock plural messageBundle", () => {
|
|
7
7
|
it("is valid", () => {
|
|
8
|
-
const messageBundle =
|
|
8
|
+
const messageBundle = pluralBundle;
|
|
9
9
|
expect(Value.Check(MessageBundle, messageBundle)).toBe(true);
|
|
10
|
-
expect(
|
|
11
|
-
expect(
|
|
12
|
-
expect(
|
|
13
|
-
expect(
|
|
10
|
+
expect(pluralBundle.messages.length).toBe(2);
|
|
11
|
+
expect(pluralBundle.messages[0].declarations.length).toBe(1);
|
|
12
|
+
expect(pluralBundle.messages[0].selectors.length).toBe(1);
|
|
13
|
+
expect(pluralBundle.messages[0].variants.length).toBe(3);
|
|
14
14
|
});
|
|
15
15
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert between v1 Message and v2 MessageBundle formats.
|
|
3
|
+
* Code adapted from https://github.com/opral/monorepo/pull/2655 legacy.ts
|
|
4
|
+
*/
|
|
5
|
+
import * as V2 from "./types.js";
|
|
6
|
+
import * as V1 from "@inlang/message";
|
|
7
|
+
/**
|
|
8
|
+
* @throws If the message cannot be represented in the v1 format
|
|
9
|
+
*/
|
|
10
|
+
export declare function toV1Message(bundle: V2.MessageBundle): V1.Message;
|
|
11
|
+
export declare function fromV1Message(v1Message: V1.Message): V2.MessageBundle;
|
|
12
|
+
//# sourceMappingURL=shim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shim.d.ts","sourceRoot":"","sources":["../../src/v2/shim.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAErC;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,OAAO,CA+BhE;AAwCD,wBAAgB,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,aAAa,CAgErE"}
|
package/dist/v2/shim.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert between v1 Message and v2 MessageBundle formats.
|
|
3
|
+
* Code adapted from https://github.com/opral/monorepo/pull/2655 legacy.ts
|
|
4
|
+
*/
|
|
5
|
+
import * as V2 from "./types.js";
|
|
6
|
+
import * as V1 from "@inlang/message";
|
|
7
|
+
/**
|
|
8
|
+
* @throws If the message cannot be represented in the v1 format
|
|
9
|
+
*/
|
|
10
|
+
export function toV1Message(bundle) {
|
|
11
|
+
const variants = [];
|
|
12
|
+
const selectorNames = new Set();
|
|
13
|
+
for (const message of bundle.messages) {
|
|
14
|
+
// collect all selector names
|
|
15
|
+
for (const selector of message.selectors.map(toV1Expression)) {
|
|
16
|
+
selectorNames.add(selector.name);
|
|
17
|
+
}
|
|
18
|
+
// collect all variants
|
|
19
|
+
for (const variant of message.variants) {
|
|
20
|
+
variants.push({
|
|
21
|
+
languageTag: message.locale,
|
|
22
|
+
match: variant.match,
|
|
23
|
+
pattern: toV1Pattern(variant.pattern),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const selectors = [...selectorNames].map((name) => ({
|
|
28
|
+
type: "VariableReference",
|
|
29
|
+
name,
|
|
30
|
+
}));
|
|
31
|
+
return {
|
|
32
|
+
id: bundle.id,
|
|
33
|
+
alias: bundle.alias,
|
|
34
|
+
variants,
|
|
35
|
+
selectors,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @throws If the pattern cannot be represented in the v1 format
|
|
40
|
+
*/
|
|
41
|
+
function toV1Pattern(pattern) {
|
|
42
|
+
return pattern.map((element) => {
|
|
43
|
+
switch (element.type) {
|
|
44
|
+
case "text": {
|
|
45
|
+
return {
|
|
46
|
+
type: "Text",
|
|
47
|
+
value: element.value,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case "expression": {
|
|
51
|
+
return toV1Expression(element);
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
throw new Error(`Unsupported pattern element type`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function toV1Expression(expression) {
|
|
60
|
+
if (expression.annotation !== undefined)
|
|
61
|
+
throw new Error("Cannot convert an expression with an annotation to the v1 format");
|
|
62
|
+
if (expression.arg.type !== "variable") {
|
|
63
|
+
throw new Error("Can only convert variable references to the v1 format");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
type: "VariableReference",
|
|
67
|
+
name: expression.arg.name,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function fromV1Message(v1Message) {
|
|
71
|
+
const languages = dedup(v1Message.variants.map((variant) => variant.languageTag));
|
|
72
|
+
const messages = languages.map((language) => {
|
|
73
|
+
//All variants that will be part of this message
|
|
74
|
+
const v1Variants = v1Message.variants.filter((variant) => variant.languageTag === language);
|
|
75
|
+
//find all selector names
|
|
76
|
+
const selectorNames = new Set();
|
|
77
|
+
for (const v1Selector of v1Message.selectors) {
|
|
78
|
+
selectorNames.add(v1Selector.name);
|
|
79
|
+
}
|
|
80
|
+
const selectors = [...selectorNames].map((name) => ({
|
|
81
|
+
type: "expression",
|
|
82
|
+
annotation: undefined,
|
|
83
|
+
arg: {
|
|
84
|
+
type: "variable",
|
|
85
|
+
name: name,
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
//The set of variables that need to be defined - Certainly includes the selectors
|
|
89
|
+
const variableNames = new Set(selectorNames);
|
|
90
|
+
const variants = [];
|
|
91
|
+
for (const v1Variant of v1Variants) {
|
|
92
|
+
for (const element of v1Variant.pattern) {
|
|
93
|
+
if (element.type === "VariableReference") {
|
|
94
|
+
variableNames.add(element.name);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
variants.push({
|
|
98
|
+
match: v1Variant.match,
|
|
99
|
+
pattern: fromV1Pattern(v1Variant.pattern),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//Create an input declaration for each variable and selector we need
|
|
103
|
+
const declarations = [...variableNames].map((name) => ({
|
|
104
|
+
type: "input",
|
|
105
|
+
name,
|
|
106
|
+
value: {
|
|
107
|
+
type: "expression",
|
|
108
|
+
annotation: undefined,
|
|
109
|
+
arg: {
|
|
110
|
+
type: "variable",
|
|
111
|
+
name,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
}));
|
|
115
|
+
return {
|
|
116
|
+
locale: language,
|
|
117
|
+
declarations,
|
|
118
|
+
selectors,
|
|
119
|
+
variants,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
id: v1Message.id,
|
|
124
|
+
alias: v1Message.alias,
|
|
125
|
+
messages,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function fromV1Pattern(pattern) {
|
|
129
|
+
return pattern.map((element) => {
|
|
130
|
+
switch (element.type) {
|
|
131
|
+
case "Text": {
|
|
132
|
+
return {
|
|
133
|
+
type: "text",
|
|
134
|
+
value: element.value,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
case "VariableReference":
|
|
138
|
+
return {
|
|
139
|
+
type: "expression",
|
|
140
|
+
arg: {
|
|
141
|
+
type: "variable",
|
|
142
|
+
name: element.name,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Dedups an array by converting it to a set and back
|
|
150
|
+
*/
|
|
151
|
+
const dedup = (arr) => [...new Set(arr)];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shim.test.d.ts","sourceRoot":"","sources":["../../src/v2/shim.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import * as V2 from "./types.js";
|
|
3
|
+
import * as V1 from "@inlang/message";
|
|
4
|
+
import { createMessageBundle, createMessage } from "./helper.js";
|
|
5
|
+
import { toV1Message, fromV1Message } from "./shim.js";
|
|
6
|
+
import { Value } from "@sinclair/typebox/value";
|
|
7
|
+
const bundle = createMessageBundle({
|
|
8
|
+
id: "hello_world",
|
|
9
|
+
messages: [
|
|
10
|
+
createMessage({ locale: "en", text: "Hello World!" }),
|
|
11
|
+
createMessage({ locale: "de", text: "Hallo Welt!" }),
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
test("toV1Message and fromV1Message", () => {
|
|
15
|
+
expect(Value.Check(V2.MessageBundle, bundle)).toBe(true);
|
|
16
|
+
const v1Message = toV1Message(bundle);
|
|
17
|
+
expect(Value.Check(V1.Message, v1Message)).toBe(true);
|
|
18
|
+
expect(v1Message).toEqual({
|
|
19
|
+
id: "hello_world",
|
|
20
|
+
alias: {},
|
|
21
|
+
variants: [
|
|
22
|
+
{
|
|
23
|
+
languageTag: "en",
|
|
24
|
+
match: [],
|
|
25
|
+
pattern: [
|
|
26
|
+
{
|
|
27
|
+
type: "Text",
|
|
28
|
+
value: "Hello World!",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
languageTag: "de",
|
|
34
|
+
match: [],
|
|
35
|
+
pattern: [
|
|
36
|
+
{
|
|
37
|
+
type: "Text",
|
|
38
|
+
value: "Hallo Welt!",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
selectors: [],
|
|
44
|
+
});
|
|
45
|
+
const v2MessageBundle = fromV1Message(v1Message);
|
|
46
|
+
expect(Value.Check(V2.MessageBundle, v2MessageBundle)).toBe(true);
|
|
47
|
+
expect(v2MessageBundle).toEqual(bundle);
|
|
48
|
+
});
|
|
49
|
+
test.todo("with variable references", () => { });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MessageQueryApi, MessageLintReportsQueryApi } from "../api.js";
|
|
2
|
+
/**
|
|
3
|
+
* noop implementation of the message query api for use with experimental.persistence = true.
|
|
4
|
+
* NOTE: If we implemented v2 shims for the old api we could use existing tests and make apps
|
|
5
|
+
* backwards compatible.
|
|
6
|
+
*/
|
|
7
|
+
export declare const stubMessagesQuery: MessageQueryApi;
|
|
8
|
+
export declare const stubMessageLintReportsQuery: MessageLintReportsQueryApi;
|
|
9
|
+
//# sourceMappingURL=stubQueryApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stubQueryApi.d.ts","sourceRoot":"","sources":["../../src/v2/stubQueryApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAA;AAE5E;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAc/B,CAAA;AAED,eAAO,MAAM,2BAA2B,EAAE,0BAKzC,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* noop implementation of the message query api for use with experimental.persistence = true.
|
|
3
|
+
* NOTE: If we implemented v2 shims for the old api we could use existing tests and make apps
|
|
4
|
+
* backwards compatible.
|
|
5
|
+
*/
|
|
6
|
+
export const stubMessagesQuery = {
|
|
7
|
+
create: () => false,
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
get: subscribable(() => undefined),
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
getByDefaultAlias: subscribable(() => undefined),
|
|
12
|
+
// @ts-expect-error
|
|
13
|
+
includedMessageIds: subscribable(() => []),
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
getAll: subscribable(() => []),
|
|
16
|
+
update: () => false,
|
|
17
|
+
upsert: () => { },
|
|
18
|
+
delete: () => false,
|
|
19
|
+
setDelegate: () => { },
|
|
20
|
+
};
|
|
21
|
+
export const stubMessageLintReportsQuery = {
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
get: subscribable(() => []),
|
|
24
|
+
// @ts-expect-error
|
|
25
|
+
getAll: settleable(subscribable(() => [])),
|
|
26
|
+
};
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
28
|
+
function subscribable(fn) {
|
|
29
|
+
return Object.assign(fn, {
|
|
30
|
+
subscribe: () => { },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
34
|
+
function settleable(fn) {
|
|
35
|
+
return Object.assign(fn, {
|
|
36
|
+
settled: async () => [],
|
|
37
|
+
});
|
|
38
|
+
}
|
package/dist/v2/types.d.ts
CHANGED
|
@@ -408,4 +408,114 @@ export declare const MessageBundle: import("@sinclair/typebox").TObject<{
|
|
|
408
408
|
}>>;
|
|
409
409
|
}>>;
|
|
410
410
|
}>;
|
|
411
|
+
/**
|
|
412
|
+
* A MessageSlot is a placeholder for a message with a locale.
|
|
413
|
+
* This is useful to avoid merge conflicts when translations are added.
|
|
414
|
+
*/
|
|
415
|
+
export type MessageSlot = Static<typeof MessageSlot>;
|
|
416
|
+
export declare const MessageSlot: import("@sinclair/typebox").TObject<{
|
|
417
|
+
locale: import("@sinclair/typebox").TString;
|
|
418
|
+
slot: import("@sinclair/typebox").TLiteral<true>;
|
|
419
|
+
}>;
|
|
420
|
+
export type MessageBundleWithSlots = Static<typeof MessageBundleWithSlots>;
|
|
421
|
+
export declare const MessageBundleWithSlots: import("@sinclair/typebox").TObject<{
|
|
422
|
+
id: import("@sinclair/typebox").TString;
|
|
423
|
+
alias: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>;
|
|
424
|
+
messages: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
425
|
+
locale: import("@sinclair/typebox").TString;
|
|
426
|
+
declarations: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
427
|
+
type: import("@sinclair/typebox").TLiteral<"input">;
|
|
428
|
+
name: import("@sinclair/typebox").TString;
|
|
429
|
+
value: import("@sinclair/typebox").TObject<{
|
|
430
|
+
type: import("@sinclair/typebox").TLiteral<"expression">;
|
|
431
|
+
arg: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
432
|
+
type: import("@sinclair/typebox").TLiteral<"literal">;
|
|
433
|
+
value: import("@sinclair/typebox").TString;
|
|
434
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
435
|
+
type: import("@sinclair/typebox").TLiteral<"variable">;
|
|
436
|
+
name: import("@sinclair/typebox").TString;
|
|
437
|
+
}>]>;
|
|
438
|
+
annotation: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
439
|
+
type: import("@sinclair/typebox").TLiteral<"function">;
|
|
440
|
+
name: import("@sinclair/typebox").TString;
|
|
441
|
+
options: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
442
|
+
name: import("@sinclair/typebox").TString;
|
|
443
|
+
value: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
444
|
+
type: import("@sinclair/typebox").TLiteral<"literal">;
|
|
445
|
+
value: import("@sinclair/typebox").TString;
|
|
446
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
447
|
+
type: import("@sinclair/typebox").TLiteral<"variable">;
|
|
448
|
+
name: import("@sinclair/typebox").TString;
|
|
449
|
+
}>]>;
|
|
450
|
+
}>>;
|
|
451
|
+
}>>;
|
|
452
|
+
}>;
|
|
453
|
+
}>>;
|
|
454
|
+
/**
|
|
455
|
+
* The order in which the selectors are placed determines the precedence of patterns.
|
|
456
|
+
*/
|
|
457
|
+
selectors: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
458
|
+
type: import("@sinclair/typebox").TLiteral<"expression">;
|
|
459
|
+
arg: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
460
|
+
type: import("@sinclair/typebox").TLiteral<"literal">;
|
|
461
|
+
value: import("@sinclair/typebox").TString;
|
|
462
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
463
|
+
type: import("@sinclair/typebox").TLiteral<"variable">;
|
|
464
|
+
name: import("@sinclair/typebox").TString;
|
|
465
|
+
}>]>;
|
|
466
|
+
annotation: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
467
|
+
type: import("@sinclair/typebox").TLiteral<"function">;
|
|
468
|
+
name: import("@sinclair/typebox").TString;
|
|
469
|
+
options: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
470
|
+
name: import("@sinclair/typebox").TString;
|
|
471
|
+
value: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
472
|
+
type: import("@sinclair/typebox").TLiteral<"literal">;
|
|
473
|
+
value: import("@sinclair/typebox").TString;
|
|
474
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
475
|
+
type: import("@sinclair/typebox").TLiteral<"variable">;
|
|
476
|
+
name: import("@sinclair/typebox").TString;
|
|
477
|
+
}>]>;
|
|
478
|
+
}>>;
|
|
479
|
+
}>>;
|
|
480
|
+
}>>;
|
|
481
|
+
variants: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
482
|
+
/**
|
|
483
|
+
* The number of keys in each variant match MUST equal the number of expressions in the selectors.
|
|
484
|
+
*
|
|
485
|
+
* Inspired by: https://github.com/unicode-org/message-format-wg/blob/main/spec/formatting.md#pattern-selection
|
|
486
|
+
*/
|
|
487
|
+
match: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
488
|
+
pattern: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
489
|
+
type: import("@sinclair/typebox").TLiteral<"text">;
|
|
490
|
+
value: import("@sinclair/typebox").TString;
|
|
491
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
492
|
+
type: import("@sinclair/typebox").TLiteral<"expression">;
|
|
493
|
+
arg: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
494
|
+
type: import("@sinclair/typebox").TLiteral<"literal">;
|
|
495
|
+
value: import("@sinclair/typebox").TString;
|
|
496
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
497
|
+
type: import("@sinclair/typebox").TLiteral<"variable">;
|
|
498
|
+
name: import("@sinclair/typebox").TString;
|
|
499
|
+
}>]>;
|
|
500
|
+
annotation: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
501
|
+
type: import("@sinclair/typebox").TLiteral<"function">;
|
|
502
|
+
name: import("@sinclair/typebox").TString;
|
|
503
|
+
options: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
504
|
+
name: import("@sinclair/typebox").TString;
|
|
505
|
+
value: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
506
|
+
type: import("@sinclair/typebox").TLiteral<"literal">;
|
|
507
|
+
value: import("@sinclair/typebox").TString;
|
|
508
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
509
|
+
type: import("@sinclair/typebox").TLiteral<"variable">;
|
|
510
|
+
name: import("@sinclair/typebox").TString;
|
|
511
|
+
}>]>;
|
|
512
|
+
}>>;
|
|
513
|
+
}>>;
|
|
514
|
+
}>]>>;
|
|
515
|
+
}>>;
|
|
516
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
517
|
+
locale: import("@sinclair/typebox").TString;
|
|
518
|
+
slot: import("@sinclair/typebox").TLiteral<true>;
|
|
519
|
+
}>]>>;
|
|
520
|
+
}>;
|
|
411
521
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/v2/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/v2/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAErD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA;AACpD;;;GAGG;AAEH,eAAO,MAAM,OAAO,sbACga,CAAA;AAEpb,eAAO,MAAM,WAAW,qCAItB,CAAA;AAEF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,OAAO,CAAC,CAAA;AAC5C,eAAO,MAAM,OAAO;;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;;;;;;;;;;;;;;;;;;;;;;;;;;YA1CH;;;;eAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgDF,CAAA;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA;AACpD,eAAO,MAAM,WAAW;;;EAGtB,CAAA;AAEF,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAC1E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAzBlC;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;YA1CH;;;;eAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiEF,CAAA"}
|
package/dist/v2/types.js
CHANGED
|
@@ -67,3 +67,12 @@ export const MessageBundle = Type.Object({
|
|
|
67
67
|
alias: Type.Record(Type.String(), Type.String()),
|
|
68
68
|
messages: Type.Array(Message),
|
|
69
69
|
});
|
|
70
|
+
export const MessageSlot = Type.Object({
|
|
71
|
+
locale: LanguageTag,
|
|
72
|
+
slot: Type.Literal(true),
|
|
73
|
+
});
|
|
74
|
+
export const MessageBundleWithSlots = Type.Object({
|
|
75
|
+
id: Type.String(),
|
|
76
|
+
alias: Type.Record(Type.String(), Type.String()),
|
|
77
|
+
messages: Type.Array(Type.Union([Message, MessageSlot])),
|
|
78
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.35.
|
|
4
|
+
"version": "0.35.7",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"./test-utilities": "./dist/test-utilities/index.js",
|
|
17
17
|
"./lint": "./dist/lint/index.js",
|
|
18
18
|
"./messages": "./dist/messages/index.js",
|
|
19
|
-
"./v2": "./dist/v2/index.js"
|
|
19
|
+
"./v2": "./dist/v2/index.js",
|
|
20
|
+
"./v2-mocks": "./dist/v2/mocks/index.js"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
23
|
"./dist",
|
|
@@ -33,15 +34,15 @@
|
|
|
33
34
|
"murmurhash3js": "^3.0.1",
|
|
34
35
|
"solid-js": "1.6.12",
|
|
35
36
|
"throttle-debounce": "^5.0.0",
|
|
37
|
+
"@inlang/language-tag": "1.5.1",
|
|
36
38
|
"@inlang/json-types": "1.1.0",
|
|
37
39
|
"@inlang/message": "2.1.0",
|
|
38
|
-
"@inlang/language-tag": "1.5.1",
|
|
39
|
-
"@inlang/message-lint-rule": "1.4.7",
|
|
40
40
|
"@inlang/module": "1.2.13",
|
|
41
41
|
"@inlang/plugin": "2.4.13",
|
|
42
42
|
"@inlang/project-settings": "2.4.2",
|
|
43
|
-
"@inlang/translatable": "1.3.1",
|
|
44
43
|
"@inlang/result": "1.1.0",
|
|
44
|
+
"@inlang/translatable": "1.3.1",
|
|
45
|
+
"@inlang/message-lint-rule": "1.4.7",
|
|
45
46
|
"@lix-js/client": "2.2.0",
|
|
46
47
|
"@lix-js/fs": "2.1.0"
|
|
47
48
|
},
|
package/src/api.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
MessageLintReport,
|
|
11
11
|
} from "./versionedInterfaces.js"
|
|
12
12
|
import type { ResolvedPluginApi } from "./resolve-modules/plugins/types.js"
|
|
13
|
-
import type
|
|
13
|
+
import type { StoreApi } from "./persistence/storeApi.js"
|
|
14
14
|
|
|
15
15
|
export type InstalledPlugin = {
|
|
16
16
|
id: Plugin["id"]
|
|
@@ -58,18 +58,7 @@ export type InlangProject = {
|
|
|
58
58
|
}
|
|
59
59
|
// WIP V2 message apis
|
|
60
60
|
// use with project settings: experimental.persistence = true
|
|
61
|
-
|
|
62
|
-
messages?: Query<V2.Message>
|
|
63
|
-
variants?: Query<V2.Variant>
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* WIP template for async V2 crud interfaces
|
|
68
|
-
* E.g. `await project.messageBundles.get({ id: "..." })`
|
|
69
|
-
**/
|
|
70
|
-
interface Query<T> {
|
|
71
|
-
get: (args: unknown) => Promise<T>
|
|
72
|
-
getAll: () => Promise<T[]>
|
|
61
|
+
store?: StoreApi
|
|
73
62
|
}
|
|
74
63
|
|
|
75
64
|
// const x = {} as InlangProject
|
|
@@ -4,10 +4,7 @@ import { mockRepo } from "@lix-js/client"
|
|
|
4
4
|
import { defaultProjectSettings } from "./defaultProjectSettings.js"
|
|
5
5
|
import { loadProject } from "./loadProject.js"
|
|
6
6
|
import { createMessage } from "./test-utilities/createMessage.js"
|
|
7
|
-
|
|
8
|
-
function sleep(ms: number) {
|
|
9
|
-
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
10
|
-
}
|
|
7
|
+
import { sleep } from "./test-utilities/sleep.js"
|
|
11
8
|
|
|
12
9
|
describe("createNewProject", () => {
|
|
13
10
|
it("should throw if a path does not end with .inlang", async () => {
|
package/src/loadProject.test.ts
CHANGED
|
@@ -278,11 +278,15 @@ describe("initialization", () => {
|
|
|
278
278
|
expect(result.data).toBeDefined()
|
|
279
279
|
})
|
|
280
280
|
|
|
281
|
+
// TODO: fix this test
|
|
282
|
+
// https://github.com/opral/inlang-message-sdk/issues/76
|
|
283
|
+
// it doesn't work because failure to open the settings file doesn't throw
|
|
284
|
+
// errors are returned in project.errors()
|
|
281
285
|
it("should resolve from a windows path", async () => {
|
|
282
286
|
const repo = await mockRepo()
|
|
283
287
|
const fs = repo.nodeishFs
|
|
284
|
-
fs.mkdir("C:\\Users\\user\\project.inlang", { recursive: true })
|
|
285
|
-
fs.writeFile("C:\\Users\\user\\project.inlang\\settings.json", JSON.stringify(settings))
|
|
288
|
+
await fs.mkdir("C:\\Users\\user\\project.inlang", { recursive: true })
|
|
289
|
+
await fs.writeFile("C:\\Users\\user\\project.inlang\\settings.json", JSON.stringify(settings))
|
|
286
290
|
|
|
287
291
|
const result = await tryCatch(() =>
|
|
288
292
|
loadProject({
|