Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@inlang/core

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inlang/core - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

dist/config/setupConfig.d.ts

6

dist/config/index.d.ts

@@ -1,5 +0,3 @@

export type { Config, EnvironmentFunctions, DefineConfig } from "./schema.js";
export type { $fs } from "./environment-functions/$fs.js";
export type { $import } from "./environment-functions/$import.js";
export { initialize$import } from "./environment-functions/$import.js";
export type { InlangConfig, InlangConfigModule, DefineConfig } from "./schema.js";
export { setupConfig } from "./setupConfig.js";
//# sourceMappingURL=index.d.ts.map

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

export { initialize$import } from "./environment-functions/$import.js";
export { setupConfig } from "./setupConfig.js";
import type { Language } from "../ast/index.js";
import type * as ast from "../ast/index.js";
import type { LintRule } from "../lint/rule.js";
import type { $fs } from "./environment-functions/$fs.js";
import type { $import } from "./environment-functions/$import.js";
import type { SdkConfig } from './_sdk.js';
import type { SdkConfig } from "./_sdk.js";
import type { Plugin, PluginSetupFunction } from "../plugin/types.js";
import type { InlangEnvironment } from "../environment/types.js";
/**
* The environment functions.
* The entrypoint for inlang.
*
* Read more https://inlang.com/documentation/environment-functions
* Read more https://inlang.com/documentation/config
*/
export type EnvironmentFunctions = {
$fs: $fs;
$import: $import;
};
export type DefineConfig = (env: InlangEnvironment) => Promise<InlangConfig | WithRequired<Partial<InlangConfig>, "plugins">>;
/**
* The inlang config function.
* The inlang config module.
*
* Read more https://inlang.com/documentation/config
* Use this type to cast an import of an "inlang.config.js" file.
*
* @example
* import type { ConfigModule } from "@inlang/core/config"
*
* const module = (await import("./inlang.config.js")) as InlangConfigModule
*/
export type DefineConfig = (args: EnvironmentFunctions) => Promise<Config>;
export type InlangConfigModule = {
defineConfig: DefineConfig;
};
/**

@@ -27,3 +31,3 @@ * Inlang config schema.

*/
export type Config = {
export type InlangConfig = {
/**

@@ -49,8 +53,19 @@ * The reference language that other messages are validated against.

readResources: (args: {
config: Config;
config: InlangConfig;
}) => Promise<ast.Resource[]>;
writeResources: (args: {
config: Config;
config: InlangConfig;
resources: ast.Resource[];
}) => Promise<void>;
/**
* Plugins to extend the functionality of inlang.
*
* @example
* plugins: [
* myPlugin({
* pathPattern: "hello",
* })
* ]
*/
plugins?: Array<Plugin | PluginSetupFunction>;
lint?: {

@@ -110,2 +125,6 @@ rules: (LintRule | LintRule[])[];

};
type WithRequired<T, K extends keyof T> = T & {
[P in K]-?: T[P];
};
export {};
//# sourceMappingURL=schema.d.ts.map

@@ -9,5 +9,12 @@ import { z } from "zod";

*/
export declare const Config: z.ZodObject<{
export declare const zConfig: z.ZodObject<{
referenceLanguage: z.ZodEffects<z.ZodString, string, string>;
languages: z.ZodArray<z.ZodString, "many">;
languages: z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>;
lint: z.ZodOptional<z.ZodObject<{
rules: z.ZodArray<z.ZodAny, "many">;
}, "strip", z.ZodTypeAny, {
rules: any[];
}, {
rules: any[];
}>>;
readResources: z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodPromise<z.ZodArray<z.ZodObject<{

@@ -167,2 +174,12 @@ metadata: z.ZodOptional<z.ZodAny>;

writeResources: z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
plugins: z.ZodUnion<[z.ZodUndefined, z.ZodArray<z.ZodObject<{
id: z.ZodString;
config: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
}, "strip", z.ZodTypeAny, {
id: string;
config: (...args: unknown[]) => unknown;
}, {
id: string;
config: (...args: unknown[]) => unknown;
}>, "many">]>;
}, "strip", z.ZodTypeAny, {

@@ -199,2 +216,9 @@ referenceLanguage: string;

writeResources: (args_0: any, ...args_1: unknown[]) => Promise<void>;
lint?: {
rules: any[];
} | undefined;
plugins?: {
id: string;
config: (...args: unknown[]) => unknown;
}[] | undefined;
}, {

@@ -231,3 +255,10 @@ referenceLanguage: string;

writeResources: (args_0: any, ...args_1: unknown[]) => Promise<void>;
lint?: {
rules: any[];
} | undefined;
plugins?: {
id: string;
config: (...args: unknown[]) => unknown;
}[] | undefined;
}>;
//# sourceMappingURL=zod.d.ts.map

@@ -10,5 +10,12 @@ import { z } from "zod";

*/
export const Config = z.object({
export const zConfig = z.object({
referenceLanguage: z.string().transform((value) => value),
languages: z.array(z.string()),
languages: z.array(z.string()).refine((items) => new Set(items).size === items.length, {
message: "Languages contains duplicates. The provided languages must be unique.",
}),
lint: z
.object({
rules: z.array(z.any()),
})
.optional(),
readResources: z

@@ -19,3 +26,4 @@ .function()

writeResources: z.function().args(z.any()).returns(z.promise(z.void())),
plugins: z.union([z.undefined(), z.array(z.object({ id: z.string(), config: z.function() }))]),
// TODO define lint and experimental
});

@@ -24,3 +24,3 @@ import type { LintRule } from "./rule.js";

setup: (args: {
config: Pick<import("../config/schema.js").Config, "referenceLanguage" | "languages">;
config: Pick<import("../config/schema.js").InlangConfig, "referenceLanguage" | "languages">;
report: (args: {

@@ -27,0 +27,0 @@ node: import("./rule.js").LintableNode;

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

import type { Config } from "@inlang/core/config";
import type { InlangConfig } from "@inlang/core/config";
import type * as ast from "@inlang/core/ast";

@@ -20,3 +20,3 @@ import type { LintedResource } from "./rule.js";

export declare const lint: (args: {
config: Pick<Config, "lint" | "languages" | "referenceLanguage">;
config: Pick<InlangConfig, "lint" | "languages" | "referenceLanguage">;
resources: ast.Resource[];

@@ -23,0 +23,0 @@ }) => Promise<[lintedResources: {

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

import type { Config } from "../config/index.js";
import type { InlangConfig } from "../config/index.js";
import type * as ast from "../ast/index.js";

@@ -11,3 +11,3 @@ import type { createReportFunction } from "./report.js";

setup: (args: {
config: Pick<Config, "referenceLanguage" | "languages">;
config: Pick<InlangConfig, "referenceLanguage" | "languages">;
report: ReturnType<typeof createReportFunction>;

@@ -14,0 +14,0 @@ }) => MaybePromise<{

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

import { EnvironmentFunctions } from "../config/index.js";
import type { InlangEnvironment } from "../environment/types.js";
/**

@@ -14,6 +14,6 @@ * Initializes a mock environment.

copyDirectory?: {
fs: EnvironmentFunctions["$fs"];
fs: InlangEnvironment["$fs"];
paths: string[];
};
}): Promise<EnvironmentFunctions>;
}): Promise<InlangEnvironment>;
//# sourceMappingURL=mockEnvironment.d.ts.map

@@ -1,4 +0,4 @@

import { initialize$import } from "../config/index.js";
import { createMemoryFs, normalizePath } from "@inlang-git/fs";
import { dedent } from "ts-dedent";
import { initialize$import } from "../environment/$import.js";
/**

@@ -5,0 +5,0 @@ * Initializes a mock environment.

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

import type { Config } from "../config/schema.js";
import type { InlangConfig } from "../config/schema.js";
import type { Result } from "../utilities/result.js";

@@ -16,4 +16,4 @@ export declare class ValidateConfigException extends Error {

export declare function validateConfig(args: {
config: Config;
config: InlangConfig;
}): Promise<Result<true, ValidateConfigException>>;
//# sourceMappingURL=validateConfig.d.ts.map
var _ValidateConfigException_id;
import { Config as ZodConfig } from "../config/zod.js";
import { Resource } from "../ast/zod.js";

@@ -23,3 +22,2 @@ export class ValidateConfigException extends Error {

try {
validateConfigSchema(args.config);
referenceLanguageMustBeInLanguages(args.config);

@@ -36,8 +34,2 @@ const resources = await args.config.readResources({ config: args.config });

}
function validateConfigSchema(config) {
const result = ZodConfig.safeParse(config);
if (!result.success) {
throw new ValidateConfigException(result.error.issues.join("\n"));
}
}
function referenceLanguageMustBeInLanguages(config) {

@@ -44,0 +36,0 @@ if (!config.languages.includes(config.referenceLanguage)) {

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

import type { EnvironmentFunctions } from "../config/schema.js";
import type { InlangEnvironment } from "../environment/types.js";
import type { Result } from "../utilities/result.js";

@@ -15,4 +15,4 @@ import { ValidateConfigException } from "./validateConfig.js";

file: string;
env: EnvironmentFunctions;
env: InlangEnvironment;
}): Promise<Result<true, ValidateConfigException>>;
//# sourceMappingURL=validateConfigFile.d.ts.map

@@ -40,4 +40,4 @@ import { validateConfig, ValidateConfigException } from "./validateConfig.js";

if (hasError) {
throw new ValidateConfigException("Regular import statements are not allowed. Use the environment function $import instead.");
throw new ValidateConfigException("Regular import statements are not allowed. Use $import of the inlang environment instead.");
}
}
export { Result } from "./result.js";
export { pluginBuildConfig } from "./pluginBuildConfig.js";
//# sourceMappingURL=index.d.ts.map
export {} from "./result.js";
export { pluginBuildConfig } from "./pluginBuildConfig.js";
{
"name": "@inlang/core",
"type": "module",
"version": "0.6.0",
"version": "0.7.0",
"publishConfig": {

@@ -11,6 +11,8 @@ "access": "public"

"./config": "./dist/config/index.js",
"./environment": "./dist/environment/index.js",
"./lint": "./dist/lint/index.js",
"./query": "./dist/query/index.js",
"./test": "./dist/test/index.js",
"./utilities": "./dist/utilities/index.js"
"./utilities": "./dist/utilities/index.js",
"./plugin": "./dist/plugin/index.js"
},

@@ -41,2 +43,3 @@ "files": [

"@inlang-git/fs": "*",
"deepmerge-ts": "^5.1.0",
"ts-dedent": "^2.2.0",

@@ -43,0 +46,0 @@ "zod": "^3.21.4"

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

export type { Config, EnvironmentFunctions, DefineConfig } from "./schema.js"
export type { $fs } from "./environment-functions/$fs.js"
export type { $import } from "./environment-functions/$import.js"
export { initialize$import } from "./environment-functions/$import.js"
export type { InlangConfig, InlangConfigModule, DefineConfig } from "./schema.js"
export { setupConfig } from "./setupConfig.js"
import type { Language } from "../ast/index.js"
import type * as ast from "../ast/index.js"
import type { LintRule } from "../lint/rule.js"
import type { $fs } from "./environment-functions/$fs.js"
import type { $import } from "./environment-functions/$import.js"
import type { SdkConfig } from './_sdk.js'
import type { SdkConfig } from "./_sdk.js"
import type { Plugin, PluginSetupFunction } from "../plugin/types.js"
import type { InlangEnvironment } from "../environment/types.js"
/**
* The environment functions.
* The entrypoint for inlang.
*
* Read more https://inlang.com/documentation/environment-functions
* Read more https://inlang.com/documentation/config
*/
export type EnvironmentFunctions = {
$fs: $fs
$import: $import
}
export type DefineConfig = (
env: InlangEnvironment,
) => Promise<InlangConfig | WithRequired<Partial<InlangConfig>, "plugins">>
/**
* The inlang config function.
* The inlang config module.
*
* Read more https://inlang.com/documentation/config
* Use this type to cast an import of an "inlang.config.js" file.
*
* @example
* import type { ConfigModule } from "@inlang/core/config"
*
* const module = (await import("./inlang.config.js")) as InlangConfigModule
*/
export type DefineConfig = (args: EnvironmentFunctions) => Promise<Config>
export type InlangConfigModule = {
defineConfig: DefineConfig
}

@@ -30,3 +36,3 @@ /**

*/
export type Config = {
export type InlangConfig = {
/**

@@ -51,4 +57,17 @@ * The reference language that other messages are validated against.

languages: Language[]
readResources: (args: { config: Config }) => Promise<ast.Resource[]>
writeResources: (args: { config: Config; resources: ast.Resource[] }) => Promise<void>
readResources: (args: { config: InlangConfig }) => Promise<ast.Resource[]>
writeResources: (args: { config: InlangConfig; resources: ast.Resource[] }) => Promise<void>
/**
* Plugins to extend the functionality of inlang.
*
* @example
* plugins: [
* myPlugin({
* pathPattern: "hello",
* })
* ]
*/
plugins?: Array<Plugin | PluginSetupFunction>
lint?: {

@@ -116,1 +135,3 @@ rules: (LintRule | LintRule[])[]

}
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }
import { z } from "zod"
import { Resource } from "../ast/zod.js"
import type { Language } from "../ast/schema.js"
import { Resource } from "../ast/zod.js"

@@ -12,5 +12,12 @@ /**

*/
export const Config = z.object({
export const zConfig = z.object({
referenceLanguage: z.string().transform((value) => value as Language),
languages: z.array(z.string()),
languages: z.array(z.string()).refine((items) => new Set(items).size === items.length, {
message: "Languages contains duplicates. The provided languages must be unique.",
}),
lint: z
.object({
rules: z.array(z.any()),
})
.optional(),
readResources: z

@@ -21,3 +28,4 @@ .function()

writeResources: z.function().args(z.any()).returns(z.promise(z.void())),
plugins: z.union([z.undefined(), z.array(z.object({ id: z.string(), config: z.function() }))]),
// TODO define lint and experimental
})

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

import type { Config } from "@inlang/core/config"
import type { InlangConfig } from "@inlang/core/config"
import type * as ast from "@inlang/core/ast"

@@ -26,3 +26,3 @@ import type { LintedResource, LintRule, Visitors } from "./rule.js"

export const lint = async (args: {
config: Pick<Config, "lint" | "languages" | "referenceLanguage">
config: Pick<InlangConfig, "lint" | "languages" | "referenceLanguage">
resources: ast.Resource[]

@@ -29,0 +29,0 @@ }): Promise<[lintedResources: LintedResource[], errors?: Error[]]> => {

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

import type { Config } from "../config/index.js"
import type { InlangConfig } from "../config/index.js"
import type * as ast from "../ast/index.js"

@@ -12,3 +12,3 @@ import type { createReportFunction } from "./report.js"

setup: (args: {
config: Pick<Config, "referenceLanguage" | "languages">
config: Pick<InlangConfig, "referenceLanguage" | "languages">
report: ReturnType<typeof createReportFunction>

@@ -15,0 +15,0 @@ }) => MaybePromise<{

import { expect, it } from "vitest"
import { createMemoryFs, fromJson } from "@inlang-git/fs"
import { mockEnvironment } from "./mockEnvironment.js"
import type { EnvironmentFunctions } from "../config/schema.js"
import type { InlangEnvironment } from "../environment/types.js"

@@ -9,3 +9,3 @@ it("should copy a directory into the environment", async () => {

// import fs from "node:fs/promises" above.
const fs = createMemoryFs() as EnvironmentFunctions["$fs"]
const fs = createMemoryFs() as InlangEnvironment["$fs"]
await fs.mkdir("./test")

@@ -26,6 +26,6 @@ await fs.writeFile("./test/file.txt", "Hello World!")

// import fs from "node:fs/promises" above.
const fs = createMemoryFs() as EnvironmentFunctions["$fs"]
const fs = createMemoryFs() as InlangEnvironment["$fs"]
await fs.mkdir("./one")
await fs.writeFile("./one/file.txt", "Hello from one")
await fs.mkdir("./two/subdir")
await fs.mkdir("./two/subdir", { recursive: true })
await fs.writeFile("./two/file.txt", "Hello from two")

@@ -39,4 +39,4 @@

it("should be able to import JavaScript from the environment", async () => {
// const fs = memfs.promises as EnvironmentFunctions["$fs"]
const fs = createMemoryFs() as EnvironmentFunctions["$fs"]
// const fs = memfs.promises as InlangEnvironment["$fs"]
const fs = createMemoryFs() as InlangEnvironment["$fs"]
await fs.mkdir("./test")

@@ -50,4 +50,4 @@ await fs.writeFile("./test/file.js", "export const x = 'hello'")

it("should give an error if the path does not exist (hinting at a current working directory problem)", async () => {
// const fs = memfs.promises as EnvironmentFunctions["$fs"]
const fs = createMemoryFs() as EnvironmentFunctions["$fs"]
// const fs = memfs.promises as InlangEnvironment["$fs"]
const fs = createMemoryFs() as InlangEnvironment["$fs"]
// relative imports are relative to the current working directory, not the file.

@@ -54,0 +54,0 @@ // thus, if you run the tests from the root of the project, the path will be wrong.

@@ -1,4 +0,5 @@

import { EnvironmentFunctions, initialize$import } from "../config/index.js"
import { createMemoryFs, normalizePath } from "@inlang-git/fs"
import { dedent } from "ts-dedent"
import type { InlangEnvironment } from "../environment/types.js"
import { initialize$import } from "../environment/$import.js"

@@ -17,6 +18,6 @@ /**

copyDirectory?: {
fs: EnvironmentFunctions["$fs"]
fs: InlangEnvironment["$fs"]
paths: string[]
}
}): Promise<EnvironmentFunctions> {
}): Promise<InlangEnvironment> {
const $fs = createMemoryFs()

@@ -45,4 +46,4 @@ const $import = initialize$import({

async function copyDirectory(args: {
copyFrom: EnvironmentFunctions["$fs"]
copyTo: EnvironmentFunctions["$fs"]
copyFrom: InlangEnvironment["$fs"]
copyTo: InlangEnvironment["$fs"]
path: string

@@ -49,0 +50,0 @@ }) {

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

import type { Config, EnvironmentFunctions } from "@inlang/core/config"
import type * as ast from "@inlang/core/ast"

@@ -7,2 +6,4 @@ import { expect, it } from "vitest"

import type { Language } from "@inlang/core/ast"
import type { InlangEnvironment } from "../environment/types.js"
import type { InlangConfig } from "../config/index.js"

@@ -71,3 +72,3 @@ it("should succeed if the config is valid", async () => {

// exported for another test
export async function mockDefineConfig(env: EnvironmentFunctions): Promise<Config> {
export async function mockDefineConfig(env: InlangEnvironment): Promise<InlangConfig> {
const pluginConfig = {

@@ -109,5 +110,5 @@ pathPattern: "./{language}.json",

// with the custom pluginConfig argument
args: Parameters<Config["readResources"]>[0] &
EnvironmentFunctions & { pluginConfig: PluginConfig },
): ReturnType<Config["readResources"]> {
args: Parameters<InlangConfig["readResources"]>[0] &
InlangEnvironment & { pluginConfig: PluginConfig },
): ReturnType<InlangConfig["readResources"]> {
const result: ast.Resource[] = []

@@ -127,8 +128,8 @@ for (const language of args.config.languages) {

* The function merges the args from Config['readResources'] with the pluginConfig
* and EnvironmentFunctions.
* and InlangEnvironment.
*/
async function writeResources(
args: Parameters<Config["writeResources"]>[0] &
EnvironmentFunctions & { pluginConfig: PluginConfig },
): ReturnType<Config["writeResources"]> {
args: Parameters<InlangConfig["writeResources"]>[0] &
InlangEnvironment & { pluginConfig: PluginConfig },
): ReturnType<InlangConfig["writeResources"]> {
for (const resource of args.resources) {

@@ -135,0 +136,0 @@ const resourcePath = args.pluginConfig.pathPattern.replace(

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

import type { Config } from "../config/schema.js"
import { Config as ZodConfig } from "../config/zod.js"
import type { InlangConfig } from "../config/schema.js"
import { Resource } from "../ast/zod.js"

@@ -21,7 +20,6 @@ import type * as ast from "../ast/schema.js"

export async function validateConfig(args: {
config: Config
config: InlangConfig
}): Promise<Result<true, ValidateConfigException>> {
// each function throws an error if the validation fails.
try {
validateConfigSchema(args.config)
referenceLanguageMustBeInLanguages(args.config)

@@ -38,10 +36,3 @@ const resources = await args.config.readResources({ config: args.config })

function validateConfigSchema(config: Config) {
const result = ZodConfig.safeParse(config)
if (!result.success) {
throw new ValidateConfigException(result.error.issues.join("\n"))
}
}
function referenceLanguageMustBeInLanguages(config: Config) {
function referenceLanguageMustBeInLanguages(config: InlangConfig) {
if (!config.languages.includes(config.referenceLanguage)) {

@@ -61,3 +52,3 @@ throw new ValidateConfigException(

async function languagesMatch(config: Config, resources: ast.Resource[]) {
async function languagesMatch(config: InlangConfig, resources: ast.Resource[]) {
const languages = resources.map((resource) => resource.languageTag.name)

@@ -84,3 +75,3 @@ // sort the languages to ensure that the order does not matter

*/
async function roundtripTest(config: Config, resources: ast.Resource[]) {
async function roundtripTest(config: InlangConfig, resources: ast.Resource[]) {
const commonErrorMessage =

@@ -87,0 +78,0 @@ "A roundtrip test of the readResources and writeResources functions failed:\n"

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

import type { EnvironmentFunctions } from "../config/schema.js"
import type { InlangEnvironment } from "../environment/types.js"
import type { Result } from "../utilities/result.js"

@@ -16,3 +16,3 @@ import { validateConfig, ValidateConfigException } from "./validateConfig.js"

file: string
env: EnvironmentFunctions
env: InlangEnvironment
}): Promise<Result<true, ValidateConfigException>> {

@@ -48,5 +48,5 @@ try {

throw new ValidateConfigException(
"Regular import statements are not allowed. Use the environment function $import instead.",
"Regular import statements are not allowed. Use $import of the inlang environment instead.",
)
}
}
export { Result } from "./result.js"
export { pluginBuildConfig } from "./pluginBuildConfig.js"

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

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