import { ClientError } from './errors.js'; import SimpleSchemaGroup from './SimpleSchemaGroup.js'; import { AutoValueFunctionDetails, CleanOptions, DocValidatorFunction, PartialSchemaDefinitionWithShorthand, ResolvedSchemaDefinition, SchemaDefinition, SchemaDefinitionWithShorthand, SchemaKeyDefinitionWithOneType, SimpleSchemaOptions, StandardSchemaKeyDefinition, StandardSchemaKeyDefinitionWithSimpleTypes, SupportedTypes, ValidationError, ValidationOptions, ValidatorFunction } from './types.js'; import ValidationContext from './ValidationContext.js'; export declare const schemaDefinitionOptions: string[]; declare class SimpleSchema { static debug?: boolean; static defaultLabel?: string; /** * Packages that want to allow and check additional options * should add the option names to this set. */ static supportedConstructorOptions: Set; /** * Packages that want to allow and check additional options * should add the option names to this set. */ static supportedCleanOptions: Set; static validationErrorTransform?: (error: ClientError) => Error; static version: number; version: number; private static _constructorOptionDefaults; private static readonly _docValidators; private static readonly _validators; private _autoValues; private _blackboxKeys; private _cleanOptions; private readonly _constructorOptions; private _docValidators; private _firstLevelSchemaKeys; private readonly _rawDefinition; private _schema; private _schemaKeys; private _validationContexts; private _validators; constructor(schema?: SchemaDefinitionWithShorthand, options?: SimpleSchemaOptions); /** /* @returns The entire raw schema definition passed in the constructor */ get rawDefinition(): SchemaDefinitionWithShorthand | null; forEachAncestorSimpleSchema(key: string, func: (ssInstance: SimpleSchema, ancestor: string, ancestorGenericKey: string) => void): void; /** * Returns whether the obj is a SimpleSchema object. * @param [obj] An object to test * @returns True if the given object appears to be a SimpleSchema instance */ static isSimpleSchema(obj: unknown): boolean; /** * @param key One specific or generic key for which to get the schema. * @returns Returns a 2-tuple. * * First item: The SimpleSchema instance that actually defines the given key. * * For example, if you have several nested objects, each their own SimpleSchema * instance, and you pass in 'outerObj.innerObj.innermostObj.name' as the key, you'll * get back the SimpleSchema instance for `outerObj.innerObj.innermostObj` key. * * But if you pass in 'outerObj.innerObj.innermostObj.name' as the key and that key is * defined in the main schema without use of subschemas, then you'll get back the main schema. * * Second item: The part of the key that is in the found schema. * * Always returns a tuple (array) but the values may be `null`. */ nearestSimpleSchemaInstance(key: string | null): [SimpleSchema | null, string | null]; /** * @param [key] One specific or generic key for which to get the schema. * @returns The entire schema object or just the definition for one key. * * Note that this returns the raw, unevaluated definition object. Use `getDefinition` * if you want the evaluated definition, where any properties that are functions * have been run to produce a result. */ schema(): ResolvedSchemaDefinition; schema(key: string): StandardSchemaKeyDefinition | null; /** * @param key One specific or generic key for which to get all possible schemas. * @returns An potentially empty array of possible definitions for one key * * Note that this returns the raw, unevaluated definition object. Use `getDefinition` * if you want the evaluated definition, where any properties that are functions * have been run to produce a result. */ schemas(key: string): StandardSchemaKeyDefinition[]; /** * @returns {Object} The entire schema object with subschemas merged. This is the * equivalent of what schema() returned in SimpleSchema < 2.0 * * Note that this returns the raw, unevaluated definition object. Use `getDefinition` * if you want the evaluated definition, where any properties that are functions * have been run to produce a result. */ mergedSchema(): SchemaDefinition; /** * Returns the evaluated definition for one key in the schema * * @param key Generic or specific schema key * @param [propList] Array of schema properties you need; performance optimization * @param [functionContext] The context to use when evaluating schema options that are functions * @returns The schema definition for the requested key */ getDefinition(key: string, propList?: string[] | null, functionContext?: Record): StandardSchemaKeyDefinitionWithSimpleTypes | undefined; /** * Returns the evaluated definition for one key in the schema * * @param key Generic or specific schema key * @param [propList] Array of schema properties you need; performance optimization * @param [functionContext] The context to use when evaluating schema options that are functions * @returns The schema definition for the requested key */ getDefinitions(key: string, propList?: string[] | null, functionContext?: Record): StandardSchemaKeyDefinitionWithSimpleTypes[]; /** * Resolves the definition for one key in the schema * * @param key Generic or specific schema key * @param schemaKeyDefinition Unresolved definition as returned from simpleSchema.schema() * @param [propList] Array of schema properties you need; performance optimization * @param [functionContext] The context to use when evaluating schema options that are functions * @returns The schema definition for the requested key */ resolveDefinitionForSchema(key: string, schemaKeyDefinition: StandardSchemaKeyDefinition, propList?: string[] | null, functionContext?: Record): StandardSchemaKeyDefinitionWithSimpleTypes; /** * Returns a string identifying the best guess data type for a key. For keys * that allow multiple types, the first type is used. This can be useful for * building forms. * * @param key Generic or specific schema key * @returns A type string. One of: * string, number, boolean, date, object, stringArray, numberArray, booleanArray, * dateArray, objectArray */ getQuickTypeForKey(key: string): string | undefined; /** * Given a key that is an Object, returns a new SimpleSchema instance scoped to that object. * * @param key Generic or specific schema key */ getObjectSchema(key: string): SimpleSchema; autoValueFunctions(): AutoValueFunctionDetails[]; blackboxKeys(): string[]; /** * Check if the key is a nested dot-syntax key inside of a blackbox object * @param key Key to check * @returns True if key is in a black box object */ keyIsInBlackBox(key: string): boolean; allowsKey(key: string): boolean; /** * Returns all the child keys for the object identified by the generic prefix, * or all the top level keys if no prefix is supplied. * * @param [keyPrefix] The Object-type generic key for which to get child keys. Omit for * top-level Object-type keys * @returns Array of child keys for the given object key */ objectKeys(keyPrefix?: string): string[]; /** * Copies this schema into a new instance with the same validators, messages, * and options, but with different keys as defined in `schema` argument * * @param schema * @returns The new SimpleSchema instance (chainable) */ _copyWithSchema(schema: SchemaDefinition): SimpleSchema; /** * Clones this schema into a new instance with the same schema keys, validators, * and options. * * @returns The new SimpleSchema instance (chainable) */ clone(): SimpleSchema; /** * Extends (mutates) this schema with another schema, key by key. * * @param schema The schema or schema definition to extend onto this one * @returns The SimpleSchema instance (chainable) */ extend(schema?: SimpleSchema | PartialSchemaDefinitionWithShorthand): SimpleSchema; getAllowedValuesForKey(key: string): any[] | null; newContext(): ValidationContext; namedContext(name?: string): ValidationContext; addValidator(func: ValidatorFunction): void; addDocValidator(func: DocValidatorFunction): void; /** * @param obj Object or array of objects to validate. * @param options Same options object that ValidationContext#validate takes * * Throws an Error with name `ClientError` and `details` property containing the errors. */ validate(obj: any, options?: ValidationOptions): void; /** * @param obj Object to validate. * @param options Same options object that ValidationContext#validate takes * * Returns a Promise that resolves with the errors */ validateAndReturnErrorsPromise(obj: any, options: ValidationOptions): Promise; validator(options?: ValidationOptions & { clean?: boolean; returnErrorsPromise?: boolean; }): (obj: Record) => void | Promise; getFormValidator(options?: {}): (obj: Record) => void | Promise; clean(doc: Record, options?: CleanOptions): Record; /** * Change schema labels on the fly. Useful when the user changes the language. * * @param labels A dictionary of all the new label values, by schema key. */ labels(labels: Record string)>): void; /** * Gets a field's label or all field labels * * @param key The schema key, specific or generic. * Omit this argument to get a dictionary of all labels. * @returns The label */ label(): Record; label(key: string): string | null; /** * Gets a field's property * * @param key The schema key, specific or generic. * @param prop Name of the property to get for that schema key * @param functionContext The `this` context to use if prop is a function * @returns The property value */ get(key: string, prop: keyof StandardSchemaKeyDefinitionWithSimpleTypes | keyof StandardSchemaKeyDefinition, functionContext?: Record): any; defaultValue(key: string): unknown; messageForError(errorInfo: ValidationError): string; /** * @method SimpleSchema#pick * @param {[fields]} The list of fields to pick to instantiate the subschema * @returns {SimpleSchema} The subschema */ pick: (this: SimpleSchema, ...args: string[]) => SimpleSchema; /** * @method SimpleSchema#omit * @param {[fields]} The list of fields to omit to instantiate the subschema * @returns {SimpleSchema} The subschema */ omit: (this: SimpleSchema, ...args: string[]) => SimpleSchema; /** * If you need to allow properties other than those listed above, call this from your app or package * @param options Additional allowed options */ static extendOptions(options: string[]): void; static defineValidationErrorTransform(transform: (error: ClientError) => Error): void; static validate(obj: any, schema: SimpleSchema | SchemaDefinitionWithShorthand, options?: ValidationOptions): void; static oneOf(...definitions: Array): SimpleSchemaGroup; static Any: string; static addValidator(func: ValidatorFunction): void; static addDocValidator(func: DocValidatorFunction): void; /** * @summary Get/set default values for SimpleSchema constructor options */ static constructorOptionDefaults(options?: SimpleSchemaOptions): undefined | SimpleSchemaOptions; static ErrorTypes: { REQUIRED: string; MIN_STRING: string; MAX_STRING: string; MIN_NUMBER: string; MAX_NUMBER: string; MIN_NUMBER_EXCLUSIVE: string; MAX_NUMBER_EXCLUSIVE: string; MIN_DATE: string; MAX_DATE: string; BAD_DATE: string; MIN_COUNT: string; MAX_COUNT: string; MUST_BE_INTEGER: string; VALUE_NOT_ALLOWED: string; EXPECTED_TYPE: string; FAILED_REGULAR_EXPRESSION: string; KEY_NOT_IN_SCHEMA: string; }; static Integer: string; static ValidationContext: typeof ValidationContext; } export { SimpleSchema, ValidationContext };