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.2.0 to 0.3.0

6

dist/errors.d.ts

@@ -16,8 +16,2 @@ export declare class InvalidConfigError extends Error {

}
/**
* Error when no package provides the API to handle messages.
*/
export declare class NoPluginProvidesLoadOrSaveMessagesError extends Error {
constructor();
}
//# sourceMappingURL=errors.d.ts.map

@@ -31,10 +31,1 @@ export class InvalidConfigError extends Error {

}
/**
* Error when no package provides the API to handle messages.
*/
export class NoPluginProvidesLoadOrSaveMessagesError extends Error {
constructor() {
super("It seems you did not install any plugin that handles messages. Please add one to make inlang work. See https://inlang.com/documentation/plugins/registry."); // TODO: check if link is correct
this.name = "NoPluginProvidesLoadOrSaveMessagesError";
}
}

2

dist/index.d.ts

@@ -11,3 +11,3 @@ /**

export { createMessagesQuery } from "./createMessagesQuery.js";
export { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, NoPluginProvidesLoadOrSaveMessagesError, PluginLoadMessagesError, PluginSaveMessagesError, } from "./errors.js";
export { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, PluginLoadMessagesError, PluginSaveMessagesError, } from "./errors.js";
export * from "./messages/variant.js";

@@ -14,0 +14,0 @@ export * from "./versionedInterfaces.js";

@@ -10,5 +10,5 @@ /**

export { createMessagesQuery } from "./createMessagesQuery.js";
export { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, NoPluginProvidesLoadOrSaveMessagesError, PluginLoadMessagesError, PluginSaveMessagesError, } from "./errors.js";
export { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, PluginLoadMessagesError, PluginSaveMessagesError, } from "./errors.js";
export * from "./messages/variant.js";
export * from "./versionedInterfaces.js";
export { InlangModule } from "@inlang/module";
import { resolveModules } from "./resolve-modules/index.js";
import { TypeCompiler } from "@sinclair/typebox/compiler";
import { Value } from "@sinclair/typebox/value";
import { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, NoPluginProvidesLoadOrSaveMessagesError, PluginLoadMessagesError, PluginSaveMessagesError, } from "./errors.js";
import { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, PluginLoadMessagesError, PluginSaveMessagesError, } from "./errors.js";
import { createRoot, createSignal, createEffect } from "./reactivity/solid.js";

@@ -58,7 +58,2 @@ import { createMessagesQuery } from "./createMessagesQuery.js";

.then((resolvedModules) => {
// TODO move to resolveModules
if (!resolvedModules.resolvedPluginApi.loadMessages ||
!resolvedModules.resolvedPluginApi.saveMessages) {
throw new NoPluginProvidesLoadOrSaveMessagesError();
}
setResolvedModules(resolvedModules);

@@ -65,0 +60,0 @@ // TODO: handle `detectedLanguageTags`

/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { describe, it, expect, vi } from "vitest";
import { openInlangProject } from "./openInlangProject.js";
import { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, NoPluginProvidesLoadOrSaveMessagesError, } from "./errors.js";
import { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, } from "./errors.js";
import { createNodeishMemoryFs } from "@lix-js/fs";

@@ -147,28 +147,2 @@ // ------------------------------------------------------------------------------------------------

describe("modules", () => {
it("should return an error if no plugin defines readMessages", async () => {
const $badImport = async () => ({
default: { ...mockPlugin, loadMessages: undefined },
});
const fs = await createNodeishMemoryFs();
await fs.writeFile("./project.inlang.json", JSON.stringify(config));
const inlang = await openInlangProject({
projectFilePath: "./project.inlang.json",
nodeishFs: fs,
_import: $badImport,
});
expect(inlang.errors()[0]).toBeInstanceOf(NoPluginProvidesLoadOrSaveMessagesError);
});
it("should return an error if no plugin defines writeMessages", async () => {
const $badImport = async () => ({
default: { ...mockPlugin, writeMessages: undefined },
});
const fs = createNodeishMemoryFs();
await fs.writeFile("./project.inlang.json", JSON.stringify(config));
const inlang = await openInlangProject({
projectFilePath: "./project.inlang.json",
nodeishFs: fs,
_import: $badImport,
});
expect(inlang.errors()[0]).toBeInstanceOf(NoPluginProvidesLoadOrSaveMessagesError);
});
it("should return an error if an error occurs while resolving a plugin", async () => {

@@ -185,3 +159,3 @@ const $badImport = async () => ({

});
expect(inlang.errors()).toHaveLength(1);
expect(inlang.errors()).not.toHaveLength(0);
});

@@ -188,0 +162,0 @@ // it.todo("should throw if lintRules contain errors ???")

@@ -21,4 +21,2 @@ import type { NodeishFilesystemSubset } from "@inlang/plugin";

readFile: NodeishFilesystemSubset["readFile"];
/** http client implementation */
fetch: typeof fetch;
}): (uri: string) => ReturnType<typeof $import>;

@@ -30,8 +28,4 @@ declare function $import(uri: string, options: {

readFile: NodeishFilesystemSubset["readFile"];
/**
* Required to import via network.
*/
fetch: typeof fetch;
}): Promise<any>;
export {};
//# sourceMappingURL=import.d.ts.map

@@ -20,3 +20,3 @@ import { dedent } from "ts-dedent";

if (uri.startsWith("http")) {
moduleAsText = await (await options.fetch(uri)).text();
moduleAsText = await (await fetch(uri)).text();
}

@@ -23,0 +23,0 @@ else {

@@ -21,3 +21,2 @@ // @vitest-environment jsdom

readFile: fs.readFile,
fetch,
});

@@ -24,0 +23,0 @@ it("should import a module from a local path", async () => {

@@ -27,3 +27,6 @@ import type { Plugin } from "@inlang/plugin";

}
export declare class PluginsDoNotProvideLoadOrSaveMessagesError extends PluginError {
constructor(message: string, options: PluginErrorOptions);
}
export {};
//# sourceMappingURL=errors.d.ts.map

@@ -45,1 +45,8 @@ class PluginError extends Error {

}
export class PluginsDoNotProvideLoadOrSaveMessagesError extends PluginError {
constructor(message, options) {
super(message, options);
this.name = "PluginsDoNotProvideLoadOrSaveMessagesError";
options.plugin = "plugin.inlang.missing";
}
}
import { Plugin } from "@inlang/plugin";
import { PluginReturnedInvalidCustomApiError, PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginHasInvalidSchemaError, PluginUsesReservedNamespaceError, } from "./errors.js";
import { PluginReturnedInvalidCustomApiError, PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginsDoNotProvideLoadOrSaveMessagesError, PluginHasInvalidIdError, PluginHasInvalidSchemaError, PluginUsesReservedNamespaceError, } from "./errors.js";
import { deepmerge } from "deepmerge-ts";

@@ -107,3 +107,8 @@ import { TypeCompiler } from "@sinclair/typebox/compiler";

}
// --- LOADMESSAGE / SAVEMESSAGE NOT DEFINED ---
if (typeof result.data.loadMessages !== "function" ||
typeof result.data.saveMessages !== "function") {
result.errors.push(new PluginsDoNotProvideLoadOrSaveMessagesError("It seems you did not install any plugin that handles messages. Please add one to make inlang work. See https://inlang.com/documentation/plugins/registry.", { plugin: "plugin.inlang.missing" }));
}
return result;
};
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { describe, expect, it } from "vitest";
import { resolvePlugins } from "./resolvePlugins.js";
import { PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginUsesReservedNamespaceError, PluginReturnedInvalidCustomApiError, PluginHasInvalidSchemaError, } from "./errors.js";
import { PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginUsesReservedNamespaceError, PluginReturnedInvalidCustomApiError, PluginHasInvalidSchemaError, PluginsDoNotProvideLoadOrSaveMessagesError, } from "./errors.js";
describe("generally", () => {

@@ -46,3 +46,2 @@ it("should return an error if a plugin uses an invalid id", async () => {

});
expect(resolved.errors.length).toBe(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError);

@@ -64,3 +63,2 @@ });

});
expect(resolved.errors.length).toBe(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginUsesReservedNamespaceError);

@@ -111,5 +109,21 @@ });

});
expect(resolved.errors).toHaveLength(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginLoadMessagesFunctionAlreadyDefinedError);
});
it("should return an error if no plugin defines loadMessages", async () => {
const mockPlugin = {
meta: {
id: "plugin.namepsace.loadMessagesFirst",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
},
saveMessages: async () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
nodeishFs: {},
settings: {},
});
expect(resolved.errors).toHaveLength(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginsDoNotProvideLoadOrSaveMessagesError);
});
});

@@ -124,2 +138,3 @@ describe("saveMessages", () => {

},
loadMessages: async () => undefined,
saveMessages: async () => undefined,

@@ -156,5 +171,21 @@ };

});
expect(resolved.errors).toHaveLength(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginSaveMessagesFunctionAlreadyDefinedError);
});
it("should return an error if no plugin defines saveMessages", async () => {
const mockPlugin = {
meta: {
id: "plugin.namepsace.loadMessagesFirst",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
},
loadMessages: async () => undefined,
};
const resolved = await resolvePlugins({
plugins: [mockPlugin],
nodeishFs: {},
settings: {},
});
expect(resolved.errors).toHaveLength(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginsDoNotProvideLoadOrSaveMessagesError);
});
});

@@ -266,3 +297,2 @@ describe("detectedLanguageTags", () => {

});
expect(resolved.errors).toHaveLength(1);
expect(resolved.errors[0]).toBeInstanceOf(PluginReturnedInvalidCustomApiError);

@@ -269,0 +299,0 @@ });

import type { LanguageTag } from "@inlang/language-tag";
import type { NodeishFilesystem as LisaNodeishFilesystem } from "@lix-js/fs";
import type { PluginReturnedInvalidCustomApiError, PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginHasInvalidSchemaError, PluginUsesReservedNamespaceError } from "./errors.js";
import type { PluginReturnedInvalidCustomApiError, PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFunctionAlreadyDefinedError, PluginHasInvalidIdError, PluginHasInvalidSchemaError, PluginUsesReservedNamespaceError, PluginsDoNotProvideLoadOrSaveMessagesError } from "./errors.js";
import type { Message } from "@inlang/message";

@@ -22,3 +22,3 @@ import type { JSONObject } from "@inlang/json-types";

data: ResolvedPluginApi;
errors: Array<PluginReturnedInvalidCustomApiError | PluginLoadMessagesFunctionAlreadyDefinedError | PluginSaveMessagesFunctionAlreadyDefinedError | PluginHasInvalidIdError | PluginHasInvalidSchemaError | PluginUsesReservedNamespaceError>;
errors: Array<PluginReturnedInvalidCustomApiError | PluginLoadMessagesFunctionAlreadyDefinedError | PluginSaveMessagesFunctionAlreadyDefinedError | PluginHasInvalidIdError | PluginHasInvalidSchemaError | PluginUsesReservedNamespaceError | PluginsDoNotProvideLoadOrSaveMessagesError>;
}>;

@@ -25,0 +25,0 @@ /**

@@ -10,3 +10,3 @@ import { InlangModule } from "@inlang/module";

export const resolveModules = async (args) => {
const _import = args._import ?? createImport({ readFile: args.nodeishFs.readFile, fetch });
const _import = args._import ?? createImport({ readFile: args.nodeishFs.readFile });
const moduleErrors = [];

@@ -13,0 +13,0 @@ const allPlugins = [];

export { createMessage } from "./createMessage.js";
export { createNodeishMemoryFs } from "@lix-js/fs";
//# sourceMappingURL=index.d.ts.map
export { createMessage } from "./createMessage.js";
export { createNodeishMemoryFs } from "@lix-js/fs";
{
"name": "@inlang/sdk",
"type": "module",
"version": "0.2.0",
"version": "0.3.0",
"license": "Apache-2.0",

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

@@ -35,13 +35,1 @@ export class InvalidConfigError extends Error {

}
/**
* Error when no package provides the API to handle messages.
*/
export class NoPluginProvidesLoadOrSaveMessagesError extends Error {
constructor() {
super(
"It seems you did not install any plugin that handles messages. Please add one to make inlang work. See https://inlang.com/documentation/plugins/registry.",
) // TODO: check if link is correct
this.name = "NoPluginProvidesLoadOrSaveMessagesError"
}
}

@@ -22,3 +22,2 @@ /**

InvalidConfigError,
NoPluginProvidesLoadOrSaveMessagesError,
PluginLoadMessagesError,

@@ -25,0 +24,0 @@ PluginSaveMessagesError,

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

InvalidConfigError,
NoPluginProvidesLoadOrSaveMessagesError,
} from "./errors.js"

@@ -182,36 +181,2 @@ import { createNodeishMemoryFs } from "@lix-js/fs"

describe("modules", () => {
it("should return an error if no plugin defines readMessages", async () => {
const $badImport: ImportFunction = async () =>
({
default: { ...mockPlugin, loadMessages: undefined as any } as Plugin,
} satisfies InlangModule)
const fs = await createNodeishMemoryFs()
await fs.writeFile("./project.inlang.json", JSON.stringify(config))
const inlang = await openInlangProject({
projectFilePath: "./project.inlang.json",
nodeishFs: fs,
_import: $badImport,
})
expect(inlang.errors()![0]).toBeInstanceOf(NoPluginProvidesLoadOrSaveMessagesError)
})
it("should return an error if no plugin defines writeMessages", async () => {
const $badImport: ImportFunction = async () =>
({
default: { ...mockPlugin, writeMessages: undefined as any } as Plugin,
} satisfies InlangModule)
const fs = createNodeishMemoryFs()
await fs.writeFile("./project.inlang.json", JSON.stringify(config))
const inlang = await openInlangProject({
projectFilePath: "./project.inlang.json",
nodeishFs: fs,
_import: $badImport,
})
expect(inlang.errors()![0]).toBeInstanceOf(NoPluginProvidesLoadOrSaveMessagesError)
})
it("should return an error if an error occurs while resolving a plugin", async () => {

@@ -232,3 +197,3 @@ const $badImport: ImportFunction = async () =>

expect(inlang.errors()).toHaveLength(1)
expect(inlang.errors()).not.toHaveLength(0)
})

@@ -235,0 +200,0 @@ // it.todo("should throw if lintRules contain errors ???")

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

InvalidConfigError,
NoPluginProvidesLoadOrSaveMessagesError,
PluginLoadMessagesError,

@@ -91,9 +90,2 @@ PluginSaveMessagesError,

.then((resolvedModules) => {
// TODO move to resolveModules
if (
!resolvedModules.resolvedPluginApi.loadMessages ||
!resolvedModules.resolvedPluginApi.saveMessages
) {
throw new NoPluginProvidesLoadOrSaveMessagesError()
}
setResolvedModules(resolvedModules)

@@ -100,0 +92,0 @@

@@ -31,3 +31,2 @@ // @vitest-environment jsdom

readFile: fs.readFile,
fetch,
})

@@ -34,0 +33,0 @@

@@ -26,4 +26,2 @@ import { dedent } from "ts-dedent"

readFile: NodeishFilesystemSubset["readFile"]
/** http client implementation */
fetch: typeof fetch
}): (uri: string) => ReturnType<typeof $import> {

@@ -41,6 +39,2 @@ // resembles a native import api

readFile: NodeishFilesystemSubset["readFile"]
/**
* Required to import via network.
*/
fetch: typeof fetch
},

@@ -51,3 +45,3 @@ ): Promise<any> {

if (uri.startsWith("http")) {
moduleAsText = await (await options.fetch(uri)).text()
moduleAsText = await (await fetch(uri)).text()
} else {

@@ -54,0 +48,0 @@ moduleAsText = await options.readFile(normalizePath(uri), { encoding: "utf-8" })

@@ -58,1 +58,9 @@ import type { Plugin } from "@inlang/plugin"

}
export class PluginsDoNotProvideLoadOrSaveMessagesError extends PluginError {
constructor(message: string, options: PluginErrorOptions) {
super(message, options)
this.name = "PluginsDoNotProvideLoadOrSaveMessagesError"
options.plugin = "plugin.inlang.missing"
}
}

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

PluginHasInvalidSchemaError,
PluginsDoNotProvideLoadOrSaveMessagesError,
} from "./errors.js"

@@ -61,3 +62,2 @@ import type { Plugin } from "@inlang/plugin"

expect(resolved.errors.length).toBe(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginHasInvalidSchemaError)

@@ -82,3 +82,2 @@ })

expect(resolved.errors.length).toBe(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginUsesReservedNamespaceError)

@@ -137,5 +136,24 @@ })

expect(resolved.errors).toHaveLength(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginLoadMessagesFunctionAlreadyDefinedError)
})
it("should return an error if no plugin defines loadMessages", async () => {
const mockPlugin: Plugin = {
meta: {
id: "plugin.namepsace.loadMessagesFirst",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
},
saveMessages: async () => undefined as any,
}
const resolved = await resolvePlugins({
plugins: [mockPlugin],
nodeishFs: {} as any,
settings: {},
})
expect(resolved.errors).toHaveLength(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginsDoNotProvideLoadOrSaveMessagesError)
})
})

@@ -151,2 +169,3 @@

},
loadMessages: async () => undefined as any,
saveMessages: async () => undefined as any,

@@ -189,5 +208,23 @@ }

expect(resolved.errors).toHaveLength(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginSaveMessagesFunctionAlreadyDefinedError)
})
it("should return an error if no plugin defines saveMessages", async () => {
const mockPlugin: Plugin = {
meta: {
id: "plugin.namepsace.loadMessagesFirst",
description: { en: "My plugin description" },
displayName: { en: "My plugin" },
},
loadMessages: async () => undefined as any,
}
const resolved = await resolvePlugins({
plugins: [mockPlugin],
nodeishFs: {} as any,
settings: {},
})
expect(resolved.errors).toHaveLength(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginsDoNotProvideLoadOrSaveMessagesError)
})
})

@@ -313,3 +350,2 @@

expect(resolved.errors).toHaveLength(1)
expect(resolved.errors[0]).toBeInstanceOf(PluginReturnedInvalidCustomApiError)

@@ -316,0 +352,0 @@ })

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

PluginSaveMessagesFunctionAlreadyDefinedError,
PluginsDoNotProvideLoadOrSaveMessagesError,
PluginHasInvalidIdError,

@@ -170,3 +171,16 @@ PluginHasInvalidSchemaError,

// --- LOADMESSAGE / SAVEMESSAGE NOT DEFINED ---
if (
typeof result.data.loadMessages !== "function" ||
typeof result.data.saveMessages !== "function"
) {
result.errors.push(
new PluginsDoNotProvideLoadOrSaveMessagesError(
"It seems you did not install any plugin that handles messages. Please add one to make inlang work. See https://inlang.com/documentation/plugins/registry.",
{ plugin: "plugin.inlang.missing" },
),
)
}
return result
}

@@ -10,2 +10,3 @@ import type { LanguageTag } from "@inlang/language-tag"

PluginUsesReservedNamespaceError,
PluginsDoNotProvideLoadOrSaveMessagesError,
} from "./errors.js"

@@ -42,2 +43,3 @@ import type { Message } from "@inlang/message"

| PluginUsesReservedNamespaceError
| PluginsDoNotProvideLoadOrSaveMessagesError
>

@@ -44,0 +46,0 @@ }>

@@ -20,3 +20,3 @@ import type { ResolveModuleFunction } from "./types.js"

export const resolveModules: ResolveModuleFunction = async (args) => {
const _import = args._import ?? createImport({ readFile: args.nodeishFs.readFile, fetch })
const _import = args._import ?? createImport({ readFile: args.nodeishFs.readFile })
const moduleErrors: Array<ModuleError> = []

@@ -85,3 +85,3 @@

plugins: allPlugins,
settings: args.config.settings as any, // TODO: fix type
settings: args.config.settings,
nodeishFs: args.nodeishFs,

@@ -88,0 +88,0 @@ })

export { createMessage } from "./createMessage.js"
export { createNodeishMemoryFs } from "@lix-js/fs"

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

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

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