@configu/sdk
Version:
Configu TypeScript SDK
487 lines (470 loc) • 15.7 kB
TypeScript
import { JSONSchema as JSONSchema$1, FromSchema } from 'json-schema-to-ts';
export { FromSchema, JSONSchema as JSONSchemaObject } from 'json-schema-to-ts';
export { default as _ } from 'lodash';
export { default as validator } from 'validator';
export { z } from 'zod';
export { assert, expect, should } from 'chai';
import { Jsonify, Merge } from 'type-fest';
interface Config {
set: string;
key: string;
value: string;
}
declare class ConfigKey {
static readonly pattern = "^[A-Za-z0-9_-]+$";
static readonly reserved: string[];
private static readonly normalizedReserved;
static normalize(key: string): string;
static validate({ key, errorPrefix }: {
key: string;
errorPrefix?: string;
}): void;
}
type ExpressionString = string;
declare class ConfigExpression {
private static globals;
private static suffix;
private static marker;
private static delimiters;
private static escapeRegex;
static pattern: RegExp;
static register(key: string, registeree: unknown): void;
private static parse;
static evaluate(expression: ExpressionString, context?: Record<string, unknown>): any;
static evaluateBoolean(expression: ExpressionString, context: Record<string, unknown>): boolean;
static evaluateTemplateString(expression: ExpressionString, context: Record<string, unknown>): string;
static references(expression: ExpressionString): string[];
static sort(expressionsDict: Record<string, string>): string[];
}
declare class JSONSchema {
private static ajv;
static validate(schema: JSONSchema$1, data: unknown): void;
static AnyPropertySchema: {
readonly type: readonly ["string", "number", "boolean", "object", "array"];
readonly oneOf: readonly [{
readonly type: "string";
}, {
readonly type: "number";
}, {
readonly type: "boolean";
}, {
readonly type: "object";
}, {
readonly type: "array";
}];
};
static AnyArrayPropertySchema: {
readonly type: "array";
readonly uniqueItems: true;
readonly items: {
readonly type: readonly ["string", "number", "boolean", "object", "array"];
readonly oneOf: readonly [{
readonly type: "string";
}, {
readonly type: "number";
}, {
readonly type: "boolean";
}, {
readonly type: "object";
}, {
readonly type: "array";
}];
};
};
static createPropertyExclusiveSchema({ property, exclusive, }: {
property: string;
exclusive: string[];
}): JSONSchema$1;
}
interface ICfgu {
description?: string;
label?: string | string[];
hidden?: boolean;
lazy?: boolean;
const?: ExpressionString;
default?: any;
required?: boolean;
pattern?: string;
enum?: any[];
schema?: JSONSchema$1;
test?: ExpressionString | ExpressionString[];
}
declare const CfguSchema: {
readonly type: "object";
readonly required: readonly [];
readonly additionalProperties: false;
readonly nullable: true;
readonly properties: {
readonly description: {
readonly type: "string";
readonly minLength: 1;
};
readonly label: {
readonly type: readonly ["string", "array"];
readonly oneOf: readonly [{
readonly type: "string";
readonly minLength: 1;
}, {
readonly type: "array";
readonly minItems: 1;
readonly uniqueItems: true;
readonly items: {
readonly type: "string";
readonly minLength: 1;
};
}];
};
readonly hidden: {
readonly type: "boolean";
};
readonly lazy: {
readonly type: "boolean";
};
readonly const: {
readonly type: "string";
readonly minLength: 1;
};
readonly default: {
readonly type: readonly ["string", "number", "boolean", "object", "array"];
readonly oneOf: readonly [{
readonly type: "string";
}, {
readonly type: "number";
}, {
readonly type: "boolean";
}, {
readonly type: "object";
}, {
readonly type: "array";
}];
};
readonly required: {
readonly type: "boolean";
};
readonly pattern: {
readonly type: "string";
readonly minLength: 1;
};
readonly enum: {
readonly type: "array";
readonly uniqueItems: true;
readonly items: {
readonly type: readonly ["string", "number", "boolean", "object", "array"];
readonly oneOf: readonly [{
readonly type: "string";
}, {
readonly type: "number";
}, {
readonly type: "boolean";
}, {
readonly type: "object";
}, {
readonly type: "array";
}];
};
};
readonly schema: {
readonly type: "object";
readonly minProperties: 1;
};
readonly test: {
readonly type: readonly ["string", "array"];
readonly oneOf: readonly [{
readonly type: "string";
readonly minLength: 1;
}, {
readonly type: "array";
readonly minItems: 1;
readonly uniqueItems: true;
readonly items: {
readonly type: "string";
readonly minLength: 1;
};
}];
};
};
readonly allOf: readonly [JSONSchema$1, JSONSchema$1, JSONSchema$1, JSONSchema$1];
};
type Cfgu = FromSchema<typeof CfguSchema>;
declare const ConfigSchemaKeysSchema: {
readonly type: "object";
readonly required: readonly [];
readonly minProperties: 1;
readonly additionalProperties: {
readonly type: "object";
readonly required: readonly [];
readonly additionalProperties: false;
readonly nullable: true;
readonly properties: {
readonly description: {
readonly type: "string";
readonly minLength: 1;
};
readonly label: {
readonly type: readonly ["string", "array"];
readonly oneOf: readonly [{
readonly type: "string";
readonly minLength: 1;
}, {
readonly type: "array";
readonly minItems: 1;
readonly uniqueItems: true;
readonly items: {
readonly type: "string";
readonly minLength: 1;
};
}];
};
readonly hidden: {
readonly type: "boolean";
};
readonly lazy: {
readonly type: "boolean";
};
readonly const: {
readonly type: "string";
readonly minLength: 1;
};
readonly default: {
readonly type: readonly ["string", "number", "boolean", "object", "array"];
readonly oneOf: readonly [{
readonly type: "string";
}, {
readonly type: "number";
}, {
readonly type: "boolean";
}, {
readonly type: "object";
}, {
readonly type: "array";
}];
};
readonly required: {
readonly type: "boolean";
};
readonly pattern: {
readonly type: "string";
readonly minLength: 1;
};
readonly enum: {
readonly type: "array";
readonly uniqueItems: true;
readonly items: {
readonly type: readonly ["string", "number", "boolean", "object", "array"];
readonly oneOf: readonly [{
readonly type: "string";
}, {
readonly type: "number";
}, {
readonly type: "boolean";
}, {
readonly type: "object";
}, {
readonly type: "array";
}];
};
};
readonly schema: {
readonly type: "object";
readonly minProperties: 1;
};
readonly test: {
readonly type: readonly ["string", "array"];
readonly oneOf: readonly [{
readonly type: "string";
readonly minLength: 1;
}, {
readonly type: "array";
readonly minItems: 1;
readonly uniqueItems: true;
readonly items: {
readonly type: "string";
readonly minLength: 1;
};
}];
};
};
readonly allOf: readonly [JSONSchema$1, JSONSchema$1, JSONSchema$1, JSONSchema$1];
};
};
type ConfigSchemaKeys = FromSchema<typeof ConfigSchemaKeysSchema>;
type V0ConfigSchemaKeys = {
[x: string]: any;
};
declare class ConfigSchema {
readonly keys: ConfigSchemaKeys;
constructor(keys?: ConfigSchemaKeys);
static fromLegacyConfigSchema(contents: V0ConfigSchemaKeys): ConfigSchema;
}
declare class ConfigSet {
readonly path: string;
static readonly separator = "/";
static readonly root = "";
static readonly rootLabel = "/";
readonly hierarchy: string[];
constructor(path?: string);
}
type ConfigQuery = Pick<Config, 'set' | 'key'>;
interface ConfigStoreConstructor {
new (configuration: any): ConfigStore;
type: string;
}
declare abstract class ConfigStore {
private static stores;
readonly type: string;
static get type(): string;
static register(store: ConfigStoreConstructor): void;
static has(type: string): boolean;
static construct(type: string, configuration?: {}): ConfigStore;
init(): Promise<void>;
abstract get(queries: ConfigQuery[]): Promise<Config[]>;
abstract set(configs: Config[]): Promise<void>;
}
type ConfigValueAny = FromSchema<typeof JSONSchema.AnyPropertySchema>;
type ConfigValueString = Config['value'];
type ConfigWithCfgu = Config & {
cfgu: Cfgu;
};
type ConfigExpressionContext = {
store?: ConfigStore;
set?: ConfigSet;
schema?: ConfigSchema;
current?: string;
configs: {
[key: string]: ConfigWithCfgu;
};
};
type ConfigContext = Merge<ConfigWithCfgu, {
labels: string[];
value: ConfigValueAny;
storedValue: string;
}>;
type ConfigEvaluationContext = {
$: Partial<ConfigContext> & {
input?: {
store: Jsonify<ConfigStore>;
set: Jsonify<ConfigSet>;
schema: Jsonify<ConfigSchema>;
};
configs: {
[key: string]: ConfigContext;
};
};
};
declare class ConfigValue {
static parse(value: ConfigValueString): ConfigValueAny;
static stringify(value: ConfigValueAny): ConfigValueString;
static createEvaluationContext(context: ConfigExpressionContext): ConfigEvaluationContext;
static test({ test, errorSuffix, context, }: {
test: ExpressionString;
errorSuffix?: string;
context: Required<ConfigExpressionContext>;
}): void;
static validate(context: Required<ConfigExpressionContext>): void;
}
declare class NoopConfigStore extends ConfigStore {
get(queries: ConfigQuery[]): Promise<Config[]>;
set(configs: Config[]): Promise<void>;
}
declare class InMemoryConfigStore extends ConfigStore {
private data;
get(queries: ConfigQuery[]): Promise<Config[]>;
set(configs: Config[]): Promise<void>;
}
type ConfigCommandInput<I extends object> = I;
type ConfigCommandOutput<O> = {
result: O;
metadata: {
version: string;
start: number;
end: number;
duration: number;
};
};
declare abstract class ConfigCommand<I extends object, O> {
input: I;
constructor(input: I);
abstract execute(): Promise<O>;
run(): Promise<ConfigCommandOutput<O>>;
}
declare enum EvaluatedConfigOrigin {
Const = "const",
Override = "override",
Store = "store",
Default = "default",
Empty = "empty"
}
type EvaluatedConfig = ConfigWithCfgu & {
origin: EvaluatedConfigOrigin;
};
type EvalCommandOutput = {
[key: string]: EvaluatedConfig;
};
type EvalCommandInput = {
store: ConfigStore;
set: ConfigSet;
schema: ConfigSchema;
configs?: {
[key: string]: ConfigValueAny;
};
pipe?: EvalCommandOutput;
validate?: boolean;
};
declare class EvalCommand extends ConfigCommand<EvalCommandInput, EvalCommandOutput> {
execute(): Promise<EvalCommandOutput>;
private evalEmpty;
private evalOverride;
private evalStore;
private evalDefault;
private evalPipe;
private evalConst;
private validateResult;
}
declare enum ConfigDiffAction {
Add = "add",
Update = "update",
Delete = "delete"
}
type ConfigDiff = {
prev: string;
next: string;
action: ConfigDiffAction;
};
type UpsertedConfig = ConfigWithCfgu & ConfigDiff;
type UpsertCommandOutput = {
[key: string]: UpsertedConfig;
};
type UpsertCommandInput = {
store: ConfigStore;
set: ConfigSet;
schema: ConfigSchema;
configs?: {
[key: string]: ConfigValueAny;
};
pipe?: EvalCommandOutput;
dry?: boolean;
};
declare class UpsertCommand extends ConfigCommand<UpsertCommandInput, UpsertCommandOutput> {
execute(): Promise<UpsertCommandOutput>;
}
type ExportCommandOutput<T> = T;
type ExportCommandInput = {
pipe: EvalCommandOutput;
coerce?: boolean;
};
declare class ExportCommand extends ConfigCommand<ExportCommandInput, ExportCommandOutput<{
[key: string]: ConfigValueAny;
}>> {
execute(): Promise<{
[x: string]: string | number | boolean | {
[x: string]: unknown;
} | unknown[];
}>;
protected validatePipe(pipe: EvalCommandOutput): void;
protected kv(pipe: EvalCommandOutput): {
[x: string]: string | number | boolean | {
[x: string]: unknown;
} | unknown[];
};
}
export { type Cfgu, CfguSchema, type Config, ConfigCommand, type ConfigCommandInput, type ConfigCommandOutput, type ConfigDiff, ConfigDiffAction, type ConfigEvaluationContext, ConfigExpression, ConfigKey, type ConfigQuery, ConfigSchema, type ConfigSchemaKeys, ConfigSchemaKeysSchema, ConfigSet, ConfigStore, type ConfigStoreConstructor, ConfigValue, type ConfigValueAny, type ConfigValueString, type ConfigWithCfgu, EvalCommand, type EvalCommandInput, type EvalCommandOutput, type EvaluatedConfig, EvaluatedConfigOrigin, ExportCommand, type ExportCommandInput, type ExportCommandOutput, type ExpressionString, type ICfgu, InMemoryConfigStore, JSONSchema, NoopConfigStore, UpsertCommand, type UpsertCommandInput, type UpsertCommandOutput, type UpsertedConfig, type V0ConfigSchemaKeys };