@ronin/syntax
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -1,1 +0,1 @@ | ||
export { c as PromiseTuple, S as SyntaxItem, d as getBatchProxy, e as getProperty, g as getSyntaxProxy, s as setProperty } from './queries-B5GYrcJV.js'; | ||
export { D as DeepCallable, P as PromiseTuple, R as ResultRecord, S as SyntaxItem, a as getBatchProxy, b as getProperty, g as getSyntaxProxy, s as setProperty } from './index-IhF-Kk5m.js'; |
@@ -6,3 +6,3 @@ import { | ||
setProperty | ||
} from "./chunk-KNGCH4OY.js"; | ||
} from "./chunk-NWNBS5JL.js"; | ||
export { | ||
@@ -9,0 +9,0 @@ getBatchProxy, |
@@ -1,291 +0,1 @@ | ||
import { P as PublicModel, M as ModelIndex, a as ModelField, b as ModelTrigger, G as GetInstructions, W as WithInstruction, S as SyntaxItem } from './queries-B5GYrcJV.js'; | ||
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<typeof link> | ReturnType<typeof string> | ReturnType<typeof boolean> | ReturnType<typeof number> | ReturnType<typeof json> | ReturnType<typeof date> | ReturnType<typeof blob> | NestedFieldsPrimitives; | ||
interface NestedFieldsPrimitives { | ||
[key: string]: Primitives; | ||
} | ||
interface Model<Fields> extends Omit<PublicModel, 'fields' | 'indexes' | 'triggers' | 'presets'> { | ||
/** | ||
* The fields that make up this model. | ||
*/ | ||
fields?: Fields; | ||
/** | ||
* Database indexes to optimize query performance. | ||
*/ | ||
indexes?: Array<ModelIndex<Array<ModelField & { | ||
slug: keyof Fields; | ||
}>>>; | ||
/** | ||
* Queries that run automatically in response to other queries. | ||
*/ | ||
triggers?: Array<ModelTrigger<Array<ModelField & { | ||
slug: keyof Fields; | ||
}>>>; | ||
/** | ||
* Predefined query instructions that can be reused across multiple different queries. | ||
*/ | ||
presets?: Record<string, GetInstructions | WithInstruction>; | ||
} | ||
type FieldsToTypes<F> = F extends Record<string, Primitives> ? { | ||
[K in keyof F]: F[K] extends Record<string, Primitives> ? FieldsToTypes<F[K]> : F[K]['type'] extends 'string' ? string : F[K]['type'] extends 'number' ? number : F[K]['type'] extends 'boolean' ? boolean : F[K]['type'] extends 'link' ? string : F[K]['type'] extends 'json' ? object : F[K]['type'] extends 'blob' ? Blob : F[K]['type'] extends 'date' ? Date : never; | ||
} : RoninFields; | ||
type ForbiddenKeys = 'id' | 'ronin' | 'ronin.updatedAt' | 'ronin.createdBy' | 'ronin.updatedBy' | 'ronin.createdAt' | 'ronin.locked'; | ||
type RecordWithoutForbiddenKeys<V> = { | ||
[K in Exclude<string, ForbiddenKeys>]: V; | ||
} & { | ||
[K in ForbiddenKeys]?: never; | ||
}; | ||
type Expand<T> = T 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: <Fields extends RecordWithoutForbiddenKeys<Primitives>>(model: Model<Fields>) => Expand<FieldsToTypes<Fields>> & Expand<RoninFields>; | ||
/** A utility type that maps an attribute's type to a function signature. */ | ||
type AttributeSignature<T> = T extends boolean ? () => any : T extends boolean ? never : (value: string) => any; | ||
/** | ||
* 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<Attrs, Used extends keyof Attrs = never> = { | ||
[K in Exclude<keyof Attrs, Used | 'type'>]: (...args: Parameters<AttributeSignature<Attrs[K]>>) => Chain<Attrs, Used | K>; | ||
} & ('type' extends keyof Attrs ? { | ||
readonly type: Attrs['type']; | ||
} : {}); | ||
type FieldOutput<Type extends ModelField['type']> = Omit<Extract<ModelField, { | ||
type: Type; | ||
}>, 'slug'>; | ||
type SyntaxField<Type extends ModelField['type']> = SyntaxItem<FieldOutput<Type>>; | ||
/** | ||
* Creates a string field definition returning an object that includes the field type | ||
* ("string") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "string" with the specified attributes. | ||
*/ | ||
declare const string: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "string"; | ||
collation?: "BINARY" | "NOCASE" | "RTRIM"; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"string">, never>; | ||
/** | ||
* Creates a number field definition returning an object that includes the field type | ||
* ("number") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "number" with the specified attributes. | ||
*/ | ||
declare const number: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "number"; | ||
increment?: boolean; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"number">, never>; | ||
/** | ||
* Creates a link field definition returning an object that includes the field type | ||
* ("link") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "link" with the specified attributes. | ||
*/ | ||
declare const link: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "link"; | ||
target: string; | ||
kind?: "one" | "many"; | ||
actions?: { | ||
onDelete?: "CASCADE" | "RESTRICT" | "SET NULL" | "SET DEFAULT" | "NO ACTION"; | ||
onUpdate?: "CASCADE" | "RESTRICT" | "SET NULL" | "SET DEFAULT" | "NO ACTION"; | ||
}; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"link">, never>; | ||
/** | ||
* Creates a JSON field definition returning an object that includes the field type | ||
* ("json") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "json" with the specified attributes. | ||
*/ | ||
declare const json: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "json"; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"json">, never>; | ||
/** | ||
* Creates a date field definition returning an object that includes the field type | ||
* ("date") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "date" with the specified attributes. | ||
*/ | ||
declare const date: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "date"; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"date">, never>; | ||
/** | ||
* Creates a boolean field definition returning an object that includes the field type | ||
* ("boolean") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "boolean" with the specified attributes. | ||
*/ | ||
declare const boolean: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "boolean"; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"boolean">, never>; | ||
/** | ||
* Creates a blob field definition returning an object that includes the field type | ||
* ("blob") and attributes. | ||
* | ||
* @param attributes - Optional field attributes. | ||
* | ||
* @returns A field of type "blob" with the specified attributes. | ||
*/ | ||
declare const blob: (initialAttributes?: Partial<Omit<{ | ||
name?: string; | ||
slug: string; | ||
displayAs?: string; | ||
unique?: boolean; | ||
required?: boolean; | ||
defaultValue?: unknown; | ||
computedAs?: { | ||
kind: "VIRTUAL" | "STORED"; | ||
value: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
}; | ||
check?: { | ||
__RONIN_EXPRESSION: string; | ||
}; | ||
} & { | ||
type: "blob"; | ||
}, "type" | "slug">>) => Chain<FieldOutput<"blob">, never>; | ||
export { type SyntaxField, blob, boolean, date, json, link, model, number, string }; | ||
export { M as Model, c as SyntaxField, h as blob, f as boolean, e as date, j as json, l as link, m as model, n as number, d as string } from './index-IhF-Kk5m.js'; |
@@ -10,3 +10,3 @@ import { | ||
string | ||
} from "./chunk-KNGCH4OY.js"; | ||
} from "./chunk-NWNBS5JL.js"; | ||
export { | ||
@@ -13,0 +13,0 @@ blob, |
{ | ||
"name": "@ronin/syntax", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"type": "module", | ||
@@ -44,4 +44,4 @@ "description": "Allows for defining RONIN queries and schemas in code.", | ||
"@biomejs/biome": "1.9.4", | ||
"@ronin/compiler": "0.13.10", | ||
"@types/bun": "1.1.16", | ||
"@ronin/compiler": "0.14.9", | ||
"@types/bun": "1.1.18", | ||
"tsup": "8.3.5", | ||
@@ -48,0 +48,0 @@ "typescript": "5.7.3" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
53957
1214
1