//#region src/utils/constants.d.ts /** Query types used for reading data. */ declare const DML_QUERY_TYPES_READ: readonly ["get", "count"]; /** Query types used for writing data. */ declare const DML_QUERY_TYPES_WRITE: readonly ["set", "add", "remove"]; /** Query types used for interacting with data. */ declare const DML_QUERY_TYPES: readonly ["get", "count", "set", "add", "remove"]; /** Query types used for reading the database schema. */ declare const DDL_QUERY_TYPES_READ: readonly ["list"]; /** Query types used for writing the database schema. */ declare const DDL_QUERY_TYPES_WRITE: readonly ["create", "alter", "drop"]; /** Query types used for interacting with the database schema. */ declare const DDL_QUERY_TYPES: readonly ["list", "create", "alter", "drop"]; /** All read query types. */ declare const QUERY_TYPES_READ: readonly ["get", "count", "list"]; /** All write query types. */ declare const QUERY_TYPES_WRITE: readonly ["set", "add", "remove", "create", "alter", "drop"]; /** All query types. */ declare const QUERY_TYPES: readonly ["get", "count", "set", "add", "remove", "list", "create", "alter", "drop"]; /** * A list of placeholders that can be located inside queries after those queries were * serialized into JSON objects. * * These placeholders are used to represent special keys and values. For example, if a * query is nested into a query, the nested query will be marked with `__RONIN_QUERY`, * which allows for distinguishing that nested query from an object of instructions. */ declare const QUERY_SYMBOLS: { readonly QUERY: "__RONIN_QUERY"; readonly EXPRESSION: "__RONIN_EXPRESSION"; readonly FIELD: "__RONIN_FIELD_"; readonly FIELD_PARENT: "__RONIN_FIELD_PARENT_"; readonly VALUE: "__RONIN_VALUE"; }; //#endregion //#region src/types/query.d.ts type QueryTypeEnum = (typeof DML_QUERY_TYPES)[number]; type ModelQueryTypeEnum = (typeof DDL_QUERY_TYPES)[number]; type ModelEntityEnum = 'field' | 'index' | 'preset'; type FieldValue = string | number | boolean | null | unknown; type FieldSelector = Record; type StoredObject = { key: string; src: string; name: string | null; placeholder: { base64: string | null; } | null; meta: { size: number; type: string; width?: number; height?: number; }; }; type Expression = { [QUERY_SYMBOLS.EXPRESSION]: string; }; type WithInstructionRefinement = FieldValue | { being?: FieldValue | Array; notBeing?: FieldValue | Array; startingWith?: FieldValue | Array; notStartingWith?: FieldValue | Array; endingWith?: FieldValue | Array; notEndingWith?: FieldValue | Array; containing?: FieldValue | Array; notContaining?: FieldValue | Array; greaterThan?: FieldValue | Array; greaterOrEqual?: FieldValue | Array; lessThan?: FieldValue | Array; lessOrEqual?: FieldValue | Array; }; type WithInstruction = Record | Record> | Record> | Record>>; type IncludingInstruction = Record; type OrderedByInstruction = { ascending?: Array; descending?: Array; }; type UsingInstruction = Array | Record; type CombinedInstructions = { with?: WithInstruction | Array; to?: FieldSelector; including?: IncludingInstruction; selecting?: Array; orderedBy?: OrderedByInstruction; before?: string | null; after?: string | null; limitedTo?: number; using?: UsingInstruction; }; type InstructionSchema = 'with' | 'to' | 'including' | 'selecting' | 'orderedBy' | 'orderedBy.ascending' | 'orderedBy.descending' | 'before' | 'after' | 'limitedTo' | 'using'; type GetQuery = Record | null>; type SetQuery = Record & { to: FieldSelector; }>; type AddQuery = Record & { with: FieldSelector; }>; type RemoveQuery = Record>; type CountQuery = Record | null>; type AllQueryInstructions = { /** * Limit the list of models for which queries should be generated to only the models * that the provided model links to. */ for?: PublicModel['slug']; /** * Provide query instructions for specific models. */ on?: Record | null>; }; type AllQuery = { all: AllQueryInstructions | null; }; type GetAllQuery = AllQuery; type CountAllQuery = AllQuery; type GetInstructions = Omit; type SetInstructions = Omit & { to: FieldSelector; }; type AddInstructions = Omit & { to: FieldSelector; }; type RemoveInstructions = Omit; type CountInstructions = Omit; type ListQuery = { models?: null; } | { model: string; }; type CreateQuery = { model: string | PublicModel; to?: PublicModel; }; type AlterQuery = { model: string; to?: Partial>; create?: { field?: Omit; index?: Omit; preset?: Omit; }; alter?: { field?: string; to?: Partial>; } | { index?: string; to?: Partial>; } | { preset?: string; to?: Omit; }; drop?: Partial>; }; type DropQuery = { model: string; }; type Query = { get?: GetQuery | GetAllQuery; set?: SetQuery; add?: AddQuery; remove?: RemoveQuery; count?: CountQuery | CountAllQuery; list?: ListQuery; create?: CreateQuery; alter?: AlterQuery; drop?: DropQuery; }; type QueryType = QueryTypeEnum | ModelQueryTypeEnum; type QueryInstructionType = InstructionSchema; type QuerySchemaType = Partial>>; interface Statement { sql: string; params: Array; returning?: boolean; } //#endregion //#region src/types/model.d.ts type ModelFieldCollation = 'BINARY' | 'NOCASE' | 'RTRIM'; type ModelFieldLinkAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION'; type ModelFieldBasics = { /** The label that should be used when displaying the field on the RONIN dashboard. */ name?: string; /** Allows for addressing the field programmatically. */ slug: string; /** * If set, only one record of the same model will be allowed to exist with a given * value for the field. */ unique?: boolean; /** * Whether a value must be provided for the field. If this attribute is set and no * value is provided, an error will be thrown. */ required?: boolean; /** * The value that should be inserted into the field in the case that no value was * explicitly provided for it when a record is created. */ defaultValue?: Expression | unknown; /** * An expression that should be evaluated to form the value of the field. The * expression can either be VIRTUAL (evaluated whenever a record is read) or STORED * (evaluated whenever a record is created or updated). */ computedAs?: { kind: 'VIRTUAL' | 'STORED'; value: Expression; }; /** An expression that gets evaluated every time a value is provided for the field. */ check?: Expression; /** Whether the field was automatically added by RONIN. */ system?: boolean; }; type ModelField = ModelFieldBasics & ({ /** The kind of value that should be stored inside the field. */ type?: never; } | { /** The kind of value that should be stored inside the field. */ type: 'boolean'; } | { /** The kind of value that should be stored inside the field. */ type: 'date'; } | { /** The kind of value that should be stored inside the field. */ type: 'json'; } | { /** The kind of value that should be stored inside the field. */ type: 'blob'; } | { /** The kind of value that should be stored inside the field. */ type: 'string'; /** The collation sequence to use for the field value. */ collation?: ModelFieldCollation; } | { /** The kind of value that should be stored inside the field. */ type: 'number'; /** * Automatically increments the value of the field with every new inserted record. */ increment?: boolean; } | { /** The kind of value that should be stored inside the field. */ type: 'link'; /** The target model of the relationship that is being established. */ target: string; /** Whether the field should be related to one record, or many records. */ kind?: 'one'; /** * If the target record is updated or deleted, the defined actions maybe executed. */ actions?: { onDelete?: ModelFieldLinkAction; onUpdate?: ModelFieldLinkAction; }; } | { /** The kind of value that should be stored inside the field. */ type: 'link'; /** The target model of the relationship that is being established. */ target: string; /** Whether the field should be related to one record, or many records. */ kind: 'many'; }); /** An extended version of `ModelField`, for internal use within the compiler. */ type InternalModelField = ModelField & { /** The path on the final record where the value of the field should be mounted. */ mountingPath: string; /** A custom value that was provided in the query, which is not stored in the DB. */ mountedValue?: unknown; /** If this is set, the field is used during formatting, but not exposed afterward. */ excluded?: boolean; }; type ModelIndexField = ModelEntityList> = { /** The collating sequence used for text placed inside the field. */ collation?: ModelFieldCollation; /** How the records in the index should be ordered. */ order?: 'ASC' | 'DESC'; } & ({ /** The field slug for which the index should be created. */ slug: keyof T$1; } | { /** The field expression for which the index should be created. */ expression: string; }); type ModelIndex = ModelEntityList> = { /** * The list of fields in the model for which the index should be created. */ fields: [ModelIndexField, ...Array>]; /** * The identifier of the index. */ slug: string; /** * Whether only one record with a unique value for the provided fields will be allowed. */ unique?: boolean; /** * An object containing query instructions that will be used to match the records that * should be included in the index. */ filter?: WithInstruction; }; type ModelPreset = { /** The visual display name of the preset. */ name?: string; /** The identifier that can be used for adding the preset to a query. */ slug: string; /** The query instructions that should be applied when the preset is used. */ instructions: GetInstructions; /** Whether the preset was automatically added by RONIN. */ system?: boolean; }; type ModelEntityList = Record, T$1 extends infer U ? Omit : never>; interface Model = ModelEntityList> { id: string; name: string; pluralName: string; slug: string; pluralSlug: string; identifiers: { name: keyof T$1; slug: keyof T$1; }; idPrefix: string; /** The name of the table in SQLite. */ table: string; /** * The table name to which the model was aliased. This will be set in the case that * multiple tables are being joined into one SQL statement. */ tableAlias?: string; /** * Details that identify the model as a model that was automatically created by RONIN, * instead of being manually created by a developer. */ system?: { /** The model that caused the system model to get created. */ model: string | 'root'; /** * If the model is used to associate two models with each other (in the case of * many-cardinality link fields), this property should contain the field slug to * which the associative model should be mounted on the source model. */ associationSlug?: string; }; fields: T$1; indexes?: ModelEntityList>; presets?: ModelEntityList; } type PublicModel = ModelEntityList> = Omit>, 'slug' | 'identifiers' | 'system' | 'tableAlias'> & { slug: Required; identifiers?: Partial; }; //#endregion //#region src/model/defaults.d.ts /** * Generates a unique identifier for a newly created record. * * @returns A string containing the ID. */ declare const getRecordIdentifier: (prefix: string) => string; //#endregion //#region src/types/result.d.ts type RawRow = Array; type ObjectRow = Record; type ResultRecordBase = { /** * The unique identifier of the record. */ id: string; ronin: { /** * The timestamp of when the record was created. */ createdAt: T$1; /** * The ID of the user who created the record. */ createdBy: string | null; /** * The timestamp of the last time the record was updated. */ updatedAt: T$1; /** * The ID of the user who last updated the record. */ updatedBy: string | null; }; }; type ResultRecord = Record & ResultRecordBase; type SingleRecordResult = { record: T$1 | null; modelFields: Record; }; type MultipleRecordResult = { records: Array; moreAfter?: string; moreBefore?: string; modelFields: Record; }; type AmountResult = { amount: number; }; type RegularResult = SingleRecordResult | MultipleRecordResult | AmountResult; type ExpandedResult = { models: Record>; }; type Result = RegularResult | ExpandedResult; type DatabaseResult = { results: Array>; raw: true; } | { results: Array>; raw: false; } | { results: Array>; }; //#endregion //#region src/utils/helpers.d.ts type CompilerErrorCode = 'MODEL_NOT_FOUND' | 'FIELD_NOT_FOUND' | 'INDEX_NOT_FOUND' | 'TRIGGER_NOT_FOUND' | 'PRESET_NOT_FOUND' | 'INVALID_WITH_VALUE' | 'INVALID_TO_VALUE' | 'INVALID_INCLUDING_VALUE' | 'INVALID_FOR_VALUE' | 'INVALID_BEFORE_OR_AFTER_INSTRUCTION' | 'INVALID_MODEL_VALUE' | 'INVALID_FIELD_VALUE' | 'EXISTING_MODEL_ENTITY' | 'REQUIRED_MODEL_ENTITY' | 'MUTUALLY_EXCLUSIVE_INSTRUCTIONS' | 'MISSING_INSTRUCTION' | 'MISSING_FIELD' | 'QUERY_EXECUTION_FAILED'; interface Issue { message: string; path: Array; } interface Details { message: string; code: CompilerErrorCode; field?: string; fields?: Array; issues?: Array; queries?: Array | null; } declare class CompilerError extends Error { code: Details['code']; field?: Details['field']; fields?: Details['fields']; issues?: Details['issues']; queries?: Details['queries']; constructor(details: Details); } /** * Checks if the provided value contains a RONIN model symbol (a represenation of a * particular entity inside a query, such as an expression or a sub query) and returns * its type and value. * * @param value - The value that should be checked. * * @returns The type and value of the symbol, if the provided value contains one. */ declare const getQuerySymbol: (value: unknown) => { type: "query"; value: Query; } | { type: "expression"; value: string; } | null; //#endregion //#region src/index.d.ts interface TransactionOptions { /** A list of models that already exist in the database. */ models?: Array; /** * Place statement parameters directly inside the statement strings instead of * separating them out into a dedicated `params` array. */ inlineParams?: boolean; /** * Whether to compute default field values as part of the generated statement. */ inlineDefaults?: boolean; /** * Applies a default `limitedTo` instruction to queries obtaining multiple records. * Useful for environments in which memory is tightly constrained. */ defaultRecordLimit?: number; } declare class Transaction { #private; statements: Array; models: Array; constructor(queries: Array, options?: TransactionOptions); /** * Formats an individual result of a query (each query has one individual result). * * @param queryType - The type of query that is being executed. * @param queryInstructions - The instructions of the query that is being executed. * @param model - The model for which the query is being executed. * @param rows - The rows that were returned from the database for the query (in the * form of an array containing arrays that contain strings). * @param selectedFields - The model fields that were selected by the query. * @param single - Whether a single or multiple records are being affected by the query. * * @returns A formatted RONIN result for a particular query. */ formatIndividualResult(queryType: QueryType, queryInstructions: CombinedInstructions, model: Model, rows: Array>, selectedFields: Array, single: boolean): RegularResult; /** * Format the results returned from the database into Blade records. * * @param results - A list of results from the database, where each result is an array * of rows. * @param caller - A function that invokes a database and executes a provided list of * SQL statements on it. The return signature contains a `results` property holding an * array of results, where each result is an array of rows. Additionally, the `raw` * property determines whether rows are objects (`false`) or arrays of values (`true`). * The latter is preferred, since that is how SQL databases return rows by default. * * @returns A list of formatted Blade results, where each result is either a single * Blade record, an array of Blade records, or a Blade count result. */ formatResults(caller: (statements: Array) => Promise | DatabaseResult): Promise>>; } declare const CLEAN_ROOT_MODEL: PublicModel; //#endregion export { type AddInstructions, type AddInstructions as AddQueryInstructions, type AddQuery, type AlterQuery, type CombinedInstructions, CompilerError, type CountInstructions, type CountInstructions as CountQueryInstructions, type CountQuery, type CreateQuery, DDL_QUERY_TYPES, DDL_QUERY_TYPES_READ, DDL_QUERY_TYPES_WRITE, DML_QUERY_TYPES, DML_QUERY_TYPES_READ, DML_QUERY_TYPES_WRITE, type DatabaseResult, type DropQuery, type ExpandedResult, type Expression, type GetInstructions, type GetInstructions as GetQueryInstructions, type GetQuery, type ListQuery, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ObjectRow, type Model as PopulatedModel, QUERY_SYMBOLS, QUERY_TYPES, QUERY_TYPES_READ, QUERY_TYPES_WRITE, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RawRow, type RegularResult, type RemoveInstructions, type RemoveInstructions as RemoveQueryInstructions, type RemoveQuery, type Result, type ResultRecord, type ResultRecordBase, type SetInstructions, type SetInstructions as SetQueryInstructions, type SetQuery, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol, getRecordIdentifier };