import { n as SyntaxItem } from "./index-DXkdxmdz.js"; import { Model as Model$1, ModelField, ModelIndex, ModelPreset, QUERY_SYMBOLS, StoredObject } from "blade-compiler"; //#region src/schema/model.d.ts interface RoninFields { /** * The unique identifier for this record. */ id: string; /** * Contains metadata about the record like creation date, last update, etc. */ ronin: string; } type Primitives = ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | ReturnType | NestedFieldsPrimitives | Chain, 'name' | 'unique' | 'required' | 'defaultValue' | 'computedAs' | 'check'>; interface NestedFieldsPrimitives { [key: string]: Primitives; } interface Model> extends Omit { /** * The fields that make up this model. */ fields?: Fields$1; /** * Database indexes to optimize query performance. */ indexes?: Record>, 'slug'>>; /** * Predefined query instructions that can be reused across multiple different queries. */ presets?: Record> | ((fields: keyof Fields$1) => Record>); } type FieldToTypeMap = { blob: StoredObject; boolean: boolean; date: Date; json: object; link: string; number: number; string: string; }; type FieldsToTypes = F extends Record ? { [K in keyof F]: F[K] extends Record ? FieldsToTypes : F[K]['type'] extends keyof FieldToTypeMap ? FieldToTypeMap[F[K]['type']] : object } : RoninFields; type ForbiddenKeys = 'id' | 'ronin' | 'ronin.updatedAt' | 'ronin.createdBy' | 'ronin.updatedBy' | 'ronin.createdAt' | 'ronin.locked'; type RecordWithoutForbiddenKeys = { [K in Exclude]: V } & { [K in ForbiddenKeys]?: never }; type Expand = T$1 extends infer O ? { [K in keyof O]: O[K] } : never; /** * Generates a model definition and adds default fields to the provided model. * * @example * ```ts * const Account = model({ * slug: 'account', * pluralSlug: 'accounts', * fields: { * name: string() * }, * }); * ``` * * @template T - A generic type representing the model structure, which contains a slug * and fields. * @param model - An object containing the slug and fields of the model. * * @returns The generated model definition. */ declare const model: = {}>(model: Model | (() => Model)) => Expand>; //#endregion //#region src/schema/primitives.d.ts /** A utility type that maps an attribute's type to a function signature. */ type AttributeSignature = T$1 extends boolean ? () => any : Attribute extends keyof Omit, 'type' | 'slug'> ? ModelFieldExpressions[Attribute] : never; /** * Represents a chain of field attributes in the form of a function chain. * * - `Attrs`: The interface describing your attributes (e.g., { required: boolean; }). * - `Used`: A union of the keys already used in the chain. * * For each attribute key `K` not in `Used`, create a method using the signature derived * from that attribute's type. Calling it returns a new `Chain` marking `K` as used. */ type Chain = { [K in Exclude]: (...args: Array, K>>) => Chain } & ('type' extends keyof Attrs ? { readonly required: boolean; readonly type: Attrs['type']; } : object); type TypeToTSType = Type extends 'string' ? string : Type extends 'number' ? number : Type extends 'boolean' ? boolean : Type extends 'blob' ? Blob : Type extends 'date' ? Date : object; type FieldInput = Partial>> & Extract & ModelFieldExpressions>>; type FieldOutput = Omit>, { type: Type; }>, 'slug' | 'system'>; type ModelFieldExpressions = { check?: (fields: Record) => Type; computedAs?: (fields: Record) => { value: Type; kind: 'VIRTUAL' | 'STORED'; }; defaultValue?: (() => Type) | Type; }; type SyntaxField = SyntaxItem> & any; /** * Creates a string field definition returning an object that includes the field type * ("string") and attributes. * * @example * ```ts * import { model, string } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * name: string(), * email: string({ required: true, unique: true }) * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "string" with the specified attributes. */ declare const string: (initialAttributes?: FieldInput<"string">) => Chain, never>; /** * Creates a number field definition returning an object that includes the field type * ("number") and attributes. * * @example * ```ts * import { model, number } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * points: number(), * numReferrals: number({ defaultValue: 0 }) * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "number" with the specified attributes. */ declare const number: (initialAttributes?: FieldInput<"number">) => Chain, never>; /** * Creates a link field definition returning an object that includes the field type * ("link") and attributes. * * @example * ```ts * import { model, link } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * account: link({ target: 'account' }), * posts: link({ target: 'post', kind: 'many', required: true }) * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "link" with the specified attributes. */ declare const link: (initialAttributes?: FieldInput<"link">) => Chain, never>; /** * Creates a JSON field definition returning an object that includes the field type * ("json") and attributes. * * @example * ```ts * import { model, json } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * settings: json() * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "json" with the specified attributes. */ declare const json: (initialAttributes?: FieldInput<"json">) => Chain, never>; /** * Creates a date field definition returning an object that includes the field type * ("date") and attributes. * * @example * ```ts * import { model, date } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * lastActiveAt: date(), * deactivatedAt: date({ defaultValue: null }) * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "date" with the specified attributes. */ declare const date: (initialAttributes?: FieldInput<"date">) => Chain, never>; /** * Creates a boolean field definition returning an object that includes the field type * ("boolean") and attributes. * * @example * ```ts * import { model, boolean } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * earlyAccess: boolean(), * isVerified: boolean({ defaultValue: false, required: true }) * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "boolean" with the specified attributes. */ declare const boolean: (initialAttributes?: FieldInput<"boolean">) => Chain, never>; /** * Creates a blob field definition returning an object that includes the field type * ("blob") and attributes. * * @example * ```ts * import { model, blob } from 'blade/schema'; * * const User = model({ * slug: 'user', * * fields: { * avatar: blob(), * contents: blob({ required: true }) * }, * }); * ``` * * @param attributes - Optional field attributes. * * @returns A field of type "blob" with the specified attributes. */ declare const blob: (initialAttributes?: FieldInput<"blob">) => Chain, never>; //#endregion //#region src/helpers/expressions.d.ts /** Valid operators for string concatenation */ type StringOperator = '||'; /** Valid arithmetic operators for numbers */ type NumberOperator = '+' | '-' | '*' | '/' | '%'; /** Valid comparison operators for numbers and strings */ type ComparisonOperator = '=' | '!=' | '>' | '<' | '>=' | '<='; /** * Creates a binary operation expression with type safety for operands. * * @param left - The left operand. * @param operator - The operator to use (string concatenation or arithmetic). * @param right - The right operand (must match type of left operand). * * @returns The formatted binary operation expression. */ declare const op: >(left: T, operator: NumberOperator | ComparisonOperator | StringOperator, right: T) => T; //#endregion //#region src/helpers/functions.d.ts /** * Wraps a raw SQL expression as-is. * Use with caution as this bypasses SQL injection protection. * * @param expressions - The raw SQL expression to use. * * @returns The wrapped SQL expression */ declare const sql: (expressions: string) => any; /** * Generates a pseudo-random integer between -9223372036854775808 and +9223372036854775807. * * @returns SQL expression that evaluates to a random number. */ declare const random: () => number; /** * Calculates the absolute value of a number. * * @param value - The number to get absolute value of. * * @returns SQL expression that evaluates to the absolute value. */ declare const abs: (value: number | Record) => number; /** * Formats a timestamp according to the specified format string. * * @param format - The format string (e.g. '%Y-%m-%d'). * @param timestamp - The timestamp to format, or 'now' for current time. * * @returns SQL expression that evaluates to the formatted timestamp. */ declare const strftime: (format: string, timestamp: string | "now") => Date; /** * Extracts a value from a JSON document at the specified path. * * @param json - The JSON document to extract from. * @param path - The path to extract the value from. * * @returns SQL expression that evaluates to the extracted value. */ declare const json_extract: (json: string, path: string) => string; /** * Applies a JSON patch operation to a JSON document. * * @param patch - The JSON patch document defining the modifications. * @param input - The JSON document to patch. * * @returns SQL expression that evaluates to the patched JSON document. */ declare const json_patch: (patch: string, input: string) => string; /** * Sets a value in a JSON document at the specified path. * Creates the path if it doesn't exist and overwrites if it does. * * @param json - The JSON document to modify. * @param path - The path to set the value at. * @param value - The value to set. * * @returns SQL expression that evaluates to the modified JSON document. */ declare const json_set: (json: string, path: string, value: string) => string; /** * Replaces a value in a JSON document at the specified path. * Only modifies existing paths, will not create new ones. * * @param json - The JSON document to modify. * @param path - The path to replace the value at. * @param value - The new value. * * @returns SQL expression that evaluates to the modified JSON document. */ declare const json_replace: (json: string, path: string, value: string) => string; /** * Inserts a value into a JSON document at the specified path. * Only creates new paths, will not modify existing ones. * * @param json - The JSON document to modify. * @param path - The path to insert the value at. * @param value - The value to insert. * * @returns SQL expression that evaluates to the modified JSON document. */ declare const json_insert: (json: string, path: string, value: string) => string; /** * Concatenates a list of strings together. * * @param values - The list of strings to concatenate. * * @returns An expression representing the concatenated string. */ declare const concat: (...values: Array>) => string; /** * Replaces all occurrences of a substring within a string with a replacement value. * * @param input - The string to perform replacements on. * @param search - The substring to search for. * @param replacement - The string to replace matches with. * * @returns SQL expression that evaluates to the modified string. */ declare const replace: (input: string, search: string, replacement: string) => string; //#endregion export { Chain, FieldOutput, type Model, ModelFieldExpressions, SyntaxField, abs, blob, boolean, concat, date, json, json_extract, json_insert, json_patch, json_replace, json_set, link, model, number, op, random, replace, sql, strftime, string };