@inlang/sdk 0.16.0 → 0.17.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/resolve-modules/errors.d.ts.map +1 -1
- package/dist/resolve-modules/errors.js +3 -3
- package/dist/resolve-modules/plugins/resolvePlugins.test.js +1 -20
- package/dist/resolve-modules/validateModuleSettings.test.js +17 -8
- package/dist/resolve-modules/validatedModuleSettings.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/resolve-modules/errors.ts +11 -3
- package/src/resolve-modules/plugins/resolvePlugins.test.ts +0 -23
- package/src/resolve-modules/validateModuleSettings.test.ts +17 -8
- package/src/resolve-modules/validatedModuleSettings.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAE9C,qBAAa,WAAY,SAAQ,KAAK;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAMvE;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;gBAC3C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAOtD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE;CAIrD;AAED,qBAAa,0BAA2B,SAAQ,WAAW;gBAC9C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAE9C,qBAAa,WAAY,SAAQ,KAAK;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAMvE;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;gBAC3C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAOtD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE;CAIrD;AAED,qBAAa,0BAA2B,SAAQ,WAAW;gBAC9C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;CAY7D;AAED,qBAAa,6BAA8B,SAAQ,WAAW;gBACjD,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;CAc7D"}
|
|
@@ -30,15 +30,15 @@ export class ModuleImportError extends ModuleError {
|
|
|
30
30
|
export class ModuleExportIsInvalidError extends ModuleError {
|
|
31
31
|
constructor(options) {
|
|
32
32
|
super(`The export(s) of "${options.module}" are invalid:\n\n${options.errors
|
|
33
|
-
.map((error) => `"${error.path}" "${error.value}": "${error.message}"`)
|
|
33
|
+
.map((error) => `"${error.path}" "${JSON.stringify(error.value, undefined, 2)}": "${error.message}"`)
|
|
34
34
|
.join("\n")}`, options);
|
|
35
35
|
this.name = "ModuleExportIsInvalidError";
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export class ModuleSettingsAreInvalidError extends ModuleError {
|
|
39
39
|
constructor(options) {
|
|
40
|
-
super(`The settings are invalid of "${module}" are invalid:\n\n${options.errors
|
|
41
|
-
.map((error) => `Path "${error.path}" with value "${error.value}": "${error.message}"`)
|
|
40
|
+
super(`The settings are invalid of "${options.module}" are invalid:\n\n${options.errors
|
|
41
|
+
.map((error) => `Path "${error.path}" with value "${JSON.stringify(error.value, undefined, 2)}": "${error.message}"`)
|
|
42
42
|
.join("\n")}`, options);
|
|
43
43
|
this.name = "ModuleSettingsAreInvalidError";
|
|
44
44
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { resolvePlugins } from "./resolvePlugins.js";
|
|
4
|
-
import { PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginReturnedInvalidCustomApiError,
|
|
4
|
+
import { PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginReturnedInvalidCustomApiError, PluginsDoNotProvideLoadOrSaveMessagesError, } from "./errors.js";
|
|
5
5
|
it("should return an error if a plugin uses an invalid id", async () => {
|
|
6
6
|
const mockPlugin = {
|
|
7
7
|
// @ts-expect-error - invalid id
|
|
@@ -18,25 +18,6 @@ it("should return an error if a plugin uses an invalid id", async () => {
|
|
|
18
18
|
});
|
|
19
19
|
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidIdError);
|
|
20
20
|
});
|
|
21
|
-
it("should return an error if a plugin uses APIs that are not available", async () => {
|
|
22
|
-
const mockPlugin = {
|
|
23
|
-
id: "plugin.namespace.undefinedApi",
|
|
24
|
-
description: { en: "My plugin description" },
|
|
25
|
-
displayName: { en: "My plugin" },
|
|
26
|
-
// @ts-expect-error the key is not available in type
|
|
27
|
-
nonExistentKey: {
|
|
28
|
-
nonexistentOptions: "value",
|
|
29
|
-
},
|
|
30
|
-
loadMessages: () => undefined,
|
|
31
|
-
saveMessages: () => undefined,
|
|
32
|
-
};
|
|
33
|
-
const resolved = await resolvePlugins({
|
|
34
|
-
plugins: [mockPlugin],
|
|
35
|
-
settings: {},
|
|
36
|
-
nodeishFs: {},
|
|
37
|
-
});
|
|
38
|
-
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError);
|
|
39
|
-
});
|
|
40
21
|
it("should expose the project settings including the plugin settings", async () => {
|
|
41
22
|
const settings = {
|
|
42
23
|
sourceLanguageTag: "en",
|
|
@@ -7,12 +7,16 @@ import { validatedModuleSettings } from "./validatedModuleSettings.js";
|
|
|
7
7
|
const mockPluginSchema = Type.Object({
|
|
8
8
|
pathPattern: Type.Union([
|
|
9
9
|
Type.String({
|
|
10
|
-
pattern: "^[^*]*\\{languageTag\\}[^*]*\\.json",
|
|
11
|
-
description: "The
|
|
10
|
+
pattern: "^(\\./|\\../|/)[^*]*\\{languageTag\\}[^*]*\\.json",
|
|
11
|
+
description: "The pathPattern must contain `{languageTag}` and end with `.json`.",
|
|
12
12
|
}),
|
|
13
|
-
Type.Record(Type.String({
|
|
14
|
-
pattern: "^[
|
|
15
|
-
description: "
|
|
13
|
+
Type.Record(Type.String({
|
|
14
|
+
pattern: "^[^.]+$",
|
|
15
|
+
description: "Dots are not allowd ",
|
|
16
|
+
examples: ["website", "app", "homepage"],
|
|
17
|
+
}), Type.String({
|
|
18
|
+
pattern: "^(\\./|\\../|/)[^*]*\\{languageTag\\}[^*]*\\.json",
|
|
19
|
+
description: "The pathPattern must contain `{languageTag}` and end with `.json`.",
|
|
16
20
|
})),
|
|
17
21
|
]),
|
|
18
22
|
variableReferencePattern: Type.Array(Type.String()),
|
|
@@ -33,14 +37,19 @@ test("if PluginSchema does match with the moduleSettings", async () => {
|
|
|
33
37
|
});
|
|
34
38
|
expect(isValid).toBe("isValid");
|
|
35
39
|
});
|
|
36
|
-
test("if
|
|
40
|
+
test("if namespace settings are valide", async () => {
|
|
37
41
|
const isValid = validatedModuleSettings({
|
|
38
42
|
settingsSchema: mockPluginSchema,
|
|
39
43
|
moduleSettings: {
|
|
40
|
-
pathPattern:
|
|
44
|
+
pathPattern: {
|
|
45
|
+
website: "./{languageTag}examplerFolder/ExampleFile.json",
|
|
46
|
+
app: "../{languageTag}examplerFolder/ExampleFile.json",
|
|
47
|
+
footer: "./{languageTag}examplerFolder/ExampleFile.json",
|
|
48
|
+
},
|
|
49
|
+
variableReferencePattern: ["{", "}"],
|
|
41
50
|
},
|
|
42
51
|
});
|
|
43
|
-
expect(isValid).
|
|
52
|
+
expect(isValid).toBe("isValid");
|
|
44
53
|
});
|
|
45
54
|
test(" if MessageLintRuleSchema match with the settings", async () => {
|
|
46
55
|
const isValid = await validatedModuleSettings({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatedModuleSettings.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/validatedModuleSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"validatedModuleSettings.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/validatedModuleSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEhE,eAAO,MAAM,uBAAuB,SAAU;IAC7C,cAAc,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAA;IACzD,cAAc,EAAE,OAAO,CAAA;CACvB,KAAG,SAAS,GAAG,UAAU,EAWzB,CAAA"}
|
package/package.json
CHANGED
|
@@ -40,7 +40,10 @@ export class ModuleExportIsInvalidError extends ModuleError {
|
|
|
40
40
|
constructor(options: { module: string; errors: ValueError[] }) {
|
|
41
41
|
super(
|
|
42
42
|
`The export(s) of "${options.module}" are invalid:\n\n${options.errors
|
|
43
|
-
.map(
|
|
43
|
+
.map(
|
|
44
|
+
(error) =>
|
|
45
|
+
`"${error.path}" "${JSON.stringify(error.value, undefined, 2)}": "${error.message}"`
|
|
46
|
+
)
|
|
44
47
|
.join("\n")}`,
|
|
45
48
|
options
|
|
46
49
|
)
|
|
@@ -51,8 +54,13 @@ export class ModuleExportIsInvalidError extends ModuleError {
|
|
|
51
54
|
export class ModuleSettingsAreInvalidError extends ModuleError {
|
|
52
55
|
constructor(options: { module: string; errors: ValueError[] }) {
|
|
53
56
|
super(
|
|
54
|
-
`The settings are invalid of "${module}" are invalid:\n\n${options.errors
|
|
55
|
-
.map(
|
|
57
|
+
`The settings are invalid of "${options.module}" are invalid:\n\n${options.errors
|
|
58
|
+
.map(
|
|
59
|
+
(error) =>
|
|
60
|
+
`Path "${error.path}" with value "${JSON.stringify(error.value, undefined, 2)}": "${
|
|
61
|
+
error.message
|
|
62
|
+
}"`
|
|
63
|
+
)
|
|
56
64
|
.join("\n")}`,
|
|
57
65
|
options
|
|
58
66
|
)
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
PluginSaveMessagesFunctionAlreadyDefinedError,
|
|
7
7
|
PluginHasInvalidIdError,
|
|
8
8
|
PluginReturnedInvalidCustomApiError,
|
|
9
|
-
PluginHasInvalidSchemaError,
|
|
10
9
|
PluginsDoNotProvideLoadOrSaveMessagesError,
|
|
11
10
|
} from "./errors.js"
|
|
12
11
|
import type { Plugin } from "@inlang/plugin"
|
|
@@ -31,28 +30,6 @@ it("should return an error if a plugin uses an invalid id", async () => {
|
|
|
31
30
|
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidIdError)
|
|
32
31
|
})
|
|
33
32
|
|
|
34
|
-
it("should return an error if a plugin uses APIs that are not available", async () => {
|
|
35
|
-
const mockPlugin: Plugin = {
|
|
36
|
-
id: "plugin.namespace.undefinedApi",
|
|
37
|
-
description: { en: "My plugin description" },
|
|
38
|
-
displayName: { en: "My plugin" },
|
|
39
|
-
// @ts-expect-error the key is not available in type
|
|
40
|
-
nonExistentKey: {
|
|
41
|
-
nonexistentOptions: "value",
|
|
42
|
-
},
|
|
43
|
-
loadMessages: () => undefined as any,
|
|
44
|
-
saveMessages: () => undefined as any,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const resolved = await resolvePlugins({
|
|
48
|
-
plugins: [mockPlugin],
|
|
49
|
-
settings: {} as any,
|
|
50
|
-
nodeishFs: {} as any,
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
33
|
it("should expose the project settings including the plugin settings", async () => {
|
|
57
34
|
const settings: ProjectSettings = {
|
|
58
35
|
sourceLanguageTag: "en",
|
|
@@ -8,14 +8,18 @@ import { validatedModuleSettings } from "./validatedModuleSettings.js"
|
|
|
8
8
|
const mockPluginSchema: Plugin["settingsSchema"] = Type.Object({
|
|
9
9
|
pathPattern: Type.Union([
|
|
10
10
|
Type.String({
|
|
11
|
-
pattern: "^[^*]*\\{languageTag\\}[^*]*\\.json",
|
|
12
|
-
description: "The
|
|
11
|
+
pattern: "^(\\./|\\../|/)[^*]*\\{languageTag\\}[^*]*\\.json",
|
|
12
|
+
description: "The pathPattern must contain `{languageTag}` and end with `.json`.",
|
|
13
13
|
}),
|
|
14
14
|
Type.Record(
|
|
15
|
-
Type.String({}),
|
|
16
15
|
Type.String({
|
|
17
|
-
pattern: "^[
|
|
18
|
-
description: "
|
|
16
|
+
pattern: "^[^.]+$",
|
|
17
|
+
description: "Dots are not allowd ",
|
|
18
|
+
examples: ["website", "app", "homepage"],
|
|
19
|
+
}),
|
|
20
|
+
Type.String({
|
|
21
|
+
pattern: "^(\\./|\\../|/)[^*]*\\{languageTag\\}[^*]*\\.json",
|
|
22
|
+
description: "The pathPattern must contain `{languageTag}` and end with `.json`.",
|
|
19
23
|
})
|
|
20
24
|
),
|
|
21
25
|
]),
|
|
@@ -43,14 +47,19 @@ test("if PluginSchema does match with the moduleSettings", async () => {
|
|
|
43
47
|
expect(isValid).toBe("isValid")
|
|
44
48
|
})
|
|
45
49
|
|
|
46
|
-
test("if
|
|
50
|
+
test("if namespace settings are valide", async () => {
|
|
47
51
|
const isValid = validatedModuleSettings({
|
|
48
52
|
settingsSchema: mockPluginSchema,
|
|
49
53
|
moduleSettings: {
|
|
50
|
-
pathPattern:
|
|
54
|
+
pathPattern: {
|
|
55
|
+
website: "./{languageTag}examplerFolder/ExampleFile.json",
|
|
56
|
+
app: "../{languageTag}examplerFolder/ExampleFile.json",
|
|
57
|
+
footer: "./{languageTag}examplerFolder/ExampleFile.json",
|
|
58
|
+
},
|
|
59
|
+
variableReferencePattern: ["{", "}"],
|
|
51
60
|
},
|
|
52
61
|
})
|
|
53
|
-
expect(isValid).
|
|
62
|
+
expect(isValid).toBe("isValid")
|
|
54
63
|
})
|
|
55
64
|
|
|
56
65
|
test(" if MessageLintRuleSchema match with the settings", async () => {
|