New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@inlang/sdk

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inlang/sdk - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

2

dist/adapter/solidAdapter.test.js

@@ -146,3 +146,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

},
loadMessages: ({ languageTags }) => (languageTags.length ? exampleMessages : []),
loadMessages: ({ settings }) => (settings.languageTags.length ? exampleMessages : []),
saveMessages: () => undefined,

@@ -149,0 +149,0 @@ };

@@ -80,4 +80,3 @@ import { resolveModules } from "./resolve-modules/index.js";

makeTrulyAsync(_resolvedModules.resolvedPluginApi.loadMessages({
languageTags: settingsValue.languageTags,
sourceLanguageTag: settingsValue.sourceLanguageTag,
settings: settingsValue,
}))

@@ -121,3 +120,6 @@ .then((messages) => {

try {
await resolvedModules()?.resolvedPluginApi.saveMessages({ messages: newMessages });
await resolvedModules()?.resolvedPluginApi.saveMessages({
settings: settingsValue,
messages: newMessages,
});
}

@@ -124,0 +126,0 @@ catch (err) {

@@ -402,3 +402,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

const fs = createNodeishMemoryFs();
await fs.writeFile("./project.inlang.json", JSON.stringify({
const settings = {
sourceLanguageTag: "en",

@@ -410,3 +410,4 @@ languageTags: ["en", "de"],

},
}));
};
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
await fs.mkdir("./resources");

@@ -491,5 +492,3 @@ const mockSaveFn = vi.fn();

expect(mockSaveFn.mock.calls.length).toBe(1);
expect(mockSaveFn.mock.calls[0][0].settings).toStrictEqual({
pathPattern: "./resources/{languageTag}.json",
});
expect(mockSaveFn.mock.calls[0][0].settings).toStrictEqual(settings);
expect(Object.values(mockSaveFn.mock.calls[0][0].messages)).toStrictEqual([

@@ -496,0 +495,0 @@ {

@@ -30,3 +30,3 @@ import { Plugin } from "@inlang/plugin";

if (hasInvalidId) {
result.errors.push(new PluginHasInvalidIdError(`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be kebap-case and contain a namespace like project.my-plugin.`, { plugin: plugin.id }));
result.errors.push(new PluginHasInvalidIdError(`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be camelCase and contain a namespace like plugin.namespace.myPlugin.`, { plugin: plugin.id }));
}

@@ -57,3 +57,3 @@ // -- USES RESERVED NAMESPACE --

const { data: customApi, error } = tryCatch(() => plugin.addCustomApi({
settings: args.settings?.[plugin.id] ?? {},
settings: args.settings,
}));

@@ -79,3 +79,2 @@ if (error) {

..._args,
settings: args.settings?.[plugin.id] ?? {},
nodeishFs: args.nodeishFs,

@@ -87,3 +86,2 @@ });

..._args,
settings: args.settings?.[plugin.id] ?? {},
nodeishFs: args.nodeishFs,

@@ -94,3 +92,3 @@ });

const { data: customApi } = tryCatch(() => plugin.addCustomApi({
settings: args.settings?.[plugin.id] ?? {},
settings: args.settings,
}));

@@ -97,0 +95,0 @@ if (customApi) {

@@ -5,53 +5,84 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

import { PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginUsesReservedNamespaceError, PluginReturnedInvalidCustomApiError, PluginHasInvalidSchemaError, PluginsDoNotProvideLoadOrSaveMessagesError, } from "./errors.js";
describe("generally", () => {
it("should return an error if a plugin uses an invalid id", async () => {
const mockPlugin = {
// @ts-expect-error - invalid id
id: "no-namespace",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined,
saveMessages: () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {},
});
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidIdError);
it("should return an error if a plugin uses an invalid id", async () => {
const mockPlugin = {
// @ts-expect-error - invalid id
id: "no-namespace",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined,
saveMessages: () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {},
});
it("should return an error if a plugin uses APIs that are not available", async () => {
const mockPlugin = {
id: "plugin.namespace.undefinedApi",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
// @ts-expect-error the key is not available in type
nonExistentKey: {
nonexistentOptions: "value",
},
loadMessages: () => undefined,
saveMessages: () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {},
});
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError);
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidIdError);
});
it("should return an error if a plugin uses APIs that are not available", async () => {
const mockPlugin = {
id: "plugin.namespace.undefinedApi",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
// @ts-expect-error the key is not available in type
nonExistentKey: {
nonexistentOptions: "value",
},
loadMessages: () => undefined,
saveMessages: () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {},
});
it("should not initialize a plugin that uses the 'inlang' namespace except for inlang whitelisted plugins", async () => {
const mockPlugin = {
id: "plugin.inlang.notWhitelisted",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {},
});
expect(resolved.errors[0]).toBeInstanceOf(PluginUsesReservedNamespaceError);
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError);
});
it("should not initialize a plugin that uses the 'inlang' namespace except for inlang whitelisted plugins", async () => {
const mockPlugin = {
id: "plugin.inlang.notWhitelisted",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {},
});
expect(resolved.errors[0]).toBeInstanceOf(PluginUsesReservedNamespaceError);
});
it("should expose the project settings including the plugin settings", async () => {
const settings = {
sourceLanguageTag: "en",
languageTags: ["en", "de"],
modules: [],
"plugin.namespace.placeholder": {
myPluginSetting: "value",
},
};
const mockPlugin = {
id: "plugin.namespace.placeholder",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
saveMessages: async ({ settings }) => {
expect(settings).toStrictEqual(settings);
},
addCustomApi: ({ settings }) => {
expect(settings).toStrictEqual(settings);
return {};
},
loadMessages: async ({ settings }) => {
expect(settings).toStrictEqual(settings);
return [];
},
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: settings,
nodeishFs: {},
});
await resolved.data.loadMessages({ settings });
await resolved.data.saveMessages({ settings, messages: [] });
});
describe("loadMessages", () => {

@@ -71,4 +102,3 @@ it("should load messages from a local source", async () => {

expect(await resolved.data.loadMessages({
languageTags: ["en"],
sourceLanguageTag: "en",
settings: {},
})).toEqual([{ id: "test", expressions: [], selectors: [], variants: [] }]);

@@ -75,0 +105,0 @@ });

@@ -1,7 +0,6 @@

import type { LanguageTag } from "@inlang/language-tag";
import type { NodeishFilesystem as LisaNodeishFilesystem } from "@lix-js/fs";
import type { PluginReturnedInvalidCustomApiError, PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginHasInvalidSchemaError, PluginUsesReservedNamespaceError, PluginsDoNotProvideLoadOrSaveMessagesError } from "./errors.js";
import type { Message } from "@inlang/message";
import type { JSONObject } from "@inlang/json-types";
import type { CustomApiInlangIdeExtension, Plugin } from "@inlang/plugin";
import type { ProjectSettings } from "@inlang/project-settings";
/**

@@ -18,3 +17,3 @@ * The filesystem is a subset of project lisa's nodeish filesystem.

plugins: Array<Plugin>;
settings: Record<Plugin["id"], JSONObject>;
settings: ProjectSettings;
nodeishFs: NodeishFilesystemSubset;

@@ -30,6 +29,6 @@ }) => Promise<{

loadMessages: (args: {
languageTags: LanguageTag[];
sourceLanguageTag: LanguageTag;
settings: ProjectSettings;
}) => Promise<Message[]> | Message[];
saveMessages: (args: {
settings: ProjectSettings;
messages: Message[];

@@ -36,0 +35,0 @@ }) => Promise<void> | void;

{
"name": "@inlang/sdk",
"type": "module",
"version": "0.8.0",
"version": "0.9.0",
"license": "Apache-2.0",

@@ -6,0 +6,0 @@ "publishConfig": {

@@ -178,3 +178,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

},
loadMessages: ({ languageTags }) => (languageTags.length ? exampleMessages : []),
loadMessages: ({ settings }) => (settings.languageTags.length ? exampleMessages : []),
saveMessages: () => undefined,

@@ -181,0 +181,0 @@ }

@@ -485,14 +485,13 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

await fs.writeFile(
"./project.inlang.json",
JSON.stringify({
sourceLanguageTag: "en",
languageTags: ["en", "de"],
modules: ["plugin.js"],
"plugin.project.json": {
pathPattern: "./resources/{languageTag}.json",
},
})
)
const settings: ProjectSettings = {
sourceLanguageTag: "en",
languageTags: ["en", "de"],
modules: ["plugin.js"],
"plugin.project.json": {
pathPattern: "./resources/{languageTag}.json",
},
}
await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
await fs.mkdir("./resources")

@@ -587,5 +586,3 @@

expect(mockSaveFn.mock.calls[0][0].settings).toStrictEqual({
pathPattern: "./resources/{languageTag}.json",
})
expect(mockSaveFn.mock.calls[0][0].settings).toStrictEqual(settings)

@@ -592,0 +589,0 @@ expect(Object.values(mockSaveFn.mock.calls[0][0].messages)).toStrictEqual([

@@ -116,4 +116,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

_resolvedModules.resolvedPluginApi.loadMessages({
languageTags: settingsValue!.languageTags,
sourceLanguageTag: settingsValue!.sourceLanguageTag,
settings: settingsValue,
})

@@ -178,3 +177,6 @@ )

try {
await resolvedModules()?.resolvedPluginApi.saveMessages({ messages: newMessages })
await resolvedModules()?.resolvedPluginApi.saveMessages({
settings: settingsValue,
messages: newMessages,
})
} catch (err) {

@@ -181,0 +183,0 @@ throw new PluginSaveMessagesError("Error in saving messages", {

@@ -14,63 +14,96 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

import type { Plugin } from "@inlang/plugin"
import type { ProjectSettings } from "@inlang/project-settings"
describe("generally", () => {
it("should return an error if a plugin uses an invalid id", async () => {
const mockPlugin: Plugin = {
// @ts-expect-error - invalid id
id: "no-namespace",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined as any,
saveMessages: () => undefined as any,
}
it("should return an error if a plugin uses an invalid id", async () => {
const mockPlugin: Plugin = {
// @ts-expect-error - invalid id
id: "no-namespace",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined as any,
saveMessages: () => undefined as any,
}
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {} as any,
})
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidIdError)
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {} as any as any,
nodeishFs: {} as any,
})
it("should return an error if a plugin uses APIs that are not available", async () => {
const mockPlugin: Plugin = {
id: "plugin.namespace.undefinedApi",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
// @ts-expect-error the key is not available in type
nonExistentKey: {
nonexistentOptions: "value",
},
loadMessages: () => undefined as any,
saveMessages: () => undefined as any,
}
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidIdError)
})
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {} as any,
})
it("should return an error if a plugin uses APIs that are not available", async () => {
const mockPlugin: Plugin = {
id: "plugin.namespace.undefinedApi",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
// @ts-expect-error the key is not available in type
nonExistentKey: {
nonexistentOptions: "value",
},
loadMessages: () => undefined as any,
saveMessages: () => undefined as any,
}
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError)
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {} as any,
nodeishFs: {} as any,
})
it("should not initialize a plugin that uses the 'inlang' namespace except for inlang whitelisted plugins", async () => {
const mockPlugin: Plugin = {
id: "plugin.inlang.notWhitelisted",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined as any,
}
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError)
})
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {},
nodeishFs: {} as any,
})
it("should not initialize a plugin that uses the 'inlang' namespace except for inlang whitelisted plugins", async () => {
const mockPlugin: Plugin = {
id: "plugin.inlang.notWhitelisted",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
loadMessages: () => undefined as any,
}
expect(resolved.errors[0]).toBeInstanceOf(PluginUsesReservedNamespaceError)
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: {} as any,
nodeishFs: {} as any,
})
expect(resolved.errors[0]).toBeInstanceOf(PluginUsesReservedNamespaceError)
})
it("should expose the project settings including the plugin settings", async () => {
const settings: ProjectSettings = {
sourceLanguageTag: "en",
languageTags: ["en", "de"],
modules: [],
"plugin.namespace.placeholder": {
myPluginSetting: "value",
},
}
const mockPlugin: Plugin = {
id: "plugin.namespace.placeholder",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
saveMessages: async ({ settings }) => {
expect(settings).toStrictEqual(settings)
},
addCustomApi: ({ settings }) => {
expect(settings).toStrictEqual(settings)
return {}
},
loadMessages: async ({ settings }) => {
expect(settings).toStrictEqual(settings)
return []
},
}
const resolved = await resolvePlugins({
plugins: [mockPlugin],
settings: settings,
nodeishFs: {} as any,
})
await resolved.data.loadMessages!({ settings })
await resolved.data.saveMessages!({ settings, messages: [] })
})
describe("loadMessages", () => {

@@ -87,3 +120,3 @@ it("should load messages from a local source", async () => {

plugins: [mockPlugin],
settings: {},
settings: {} as any,
nodeishFs: {} as any,

@@ -94,4 +127,3 @@ })

await resolved.data.loadMessages!({
languageTags: ["en"],
sourceLanguageTag: "en",
settings: {} as any,
})

@@ -118,3 +150,3 @@ ).toEqual([{ id: "test", expressions: [], selectors: [], variants: [] }])

nodeishFs: {} as any,
settings: {},
settings: {} as any,
})

@@ -136,3 +168,3 @@

nodeishFs: {} as any,
settings: {},
settings: {} as any,
})

@@ -158,3 +190,3 @@

nodeishFs: {} as any,
settings: {},
settings: {} as any,
})

@@ -182,3 +214,3 @@

plugins: [mockPlugin, mockPlugin2],
settings: {},
settings: {} as any,
nodeishFs: {} as any,

@@ -201,3 +233,3 @@ })

nodeishFs: {} as any,
settings: {},
settings: {} as any,
})

@@ -225,3 +257,3 @@ expect(resolved.errors).toHaveLength(1)

plugins: [mockPlugin],
settings: {},
settings: {} as any,
nodeishFs: {} as any,

@@ -261,3 +293,3 @@ })

plugins: [mockPlugin, mockPlugin2],
settings: {},
settings: {} as any,
nodeishFs: {} as any,

@@ -282,3 +314,3 @@ })

plugins: [mockPlugin],
settings: {},
settings: {} as any,
nodeishFs: {} as any,

@@ -306,3 +338,3 @@ })

plugins: [mockPlugin],
settings: {},
settings: {} as any,
nodeishFs: {} as any,

@@ -309,0 +341,0 @@ })

@@ -47,3 +47,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */

new PluginHasInvalidIdError(
`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be kebap-case and contain a namespace like project.my-plugin.`,
`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be camelCase and contain a namespace like plugin.namespace.myPlugin.`,
{ plugin: plugin.id }

@@ -103,3 +103,3 @@ )

plugin.addCustomApi!({
settings: args.settings?.[plugin.id] ?? {},
settings: args.settings,
})

@@ -135,3 +135,2 @@ )

..._args,
settings: args.settings?.[plugin.id] ?? {},
nodeishFs: args.nodeishFs,

@@ -145,3 +144,2 @@ })

..._args,
settings: args.settings?.[plugin.id] ?? {},
nodeishFs: args.nodeishFs,

@@ -154,3 +152,3 @@ })

plugin.addCustomApi!({
settings: args.settings?.[plugin.id] ?? {},
settings: args.settings,
})

@@ -157,0 +155,0 @@ )

@@ -1,2 +0,1 @@

import type { LanguageTag } from "@inlang/language-tag"
import type { NodeishFilesystem as LisaNodeishFilesystem } from "@lix-js/fs"

@@ -13,4 +12,4 @@ import type {

import type { Message } from "@inlang/message"
import type { JSONObject } from "@inlang/json-types"
import type { CustomApiInlangIdeExtension, Plugin } from "@inlang/plugin"
import type { ProjectSettings } from "@inlang/project-settings"

@@ -32,3 +31,3 @@ /**

plugins: Array<Plugin>
settings: Record<Plugin["id"], JSONObject>
settings: ProjectSettings
nodeishFs: NodeishFilesystemSubset

@@ -52,7 +51,4 @@ }) => Promise<{

export type ResolvedPluginApi = {
loadMessages: (args: {
languageTags: LanguageTag[]
sourceLanguageTag: LanguageTag
}) => Promise<Message[]> | Message[]
saveMessages: (args: { messages: Message[] }) => Promise<void> | void
loadMessages: (args: { settings: ProjectSettings }) => Promise<Message[]> | Message[]
saveMessages: (args: { settings: ProjectSettings; messages: Message[] }) => Promise<void> | void
/**

@@ -59,0 +55,0 @@ * App specific APIs.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc