Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

@ronin/schema

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ronin/schema - npm Package Compare versions

Comparing version 0.1.4-corny-ron-1071-experimental-20 to 0.1.4-leo-ron-1071-experimental-21

@@ -109,2 +109,3 @@ /**

type ModelFieldCollation = 'BINARY' | 'NOCASE' | 'RTRIM';
type ModelFieldLinkAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
type ModelFieldBasics = {

@@ -143,27 +144,45 @@ /** The label that should be used when displaying the field on the RONIN dashboard. */

check?: Expression;
/**
* If the field is of type `string`, setting this attribute defines the collation
* sequence to use for the field value.
*/
};
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';
/**
* If the field is of type `number`, setting this attribute will automatically increment
* the value of the field with every new record that gets inserted.
* Automatically increments the value of the field with every new inserted record.
*/
increment?: boolean;
};
type ModelFieldNormal = ModelFieldBasics & {
type?: 'string' | 'number' | 'boolean' | 'date' | 'json';
};
type ModelFieldReferenceAction = 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
type ModelFieldReference = ModelFieldBasics & {
} | {
/** 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' | 'many';
/**
* If the target record is updated or deleted, the defined actions maybe executed.
*/
actions?: {
onDelete?: ModelFieldReferenceAction;
onUpdate?: ModelFieldReferenceAction;
onDelete?: ModelFieldLinkAction;
onUpdate?: ModelFieldLinkAction;
};
};
type ModelField = ModelFieldNormal | ModelFieldReference;
});
type ModelIndexField<T extends Array<ModelField> = Array<ModelField>> = {

@@ -309,50 +328,5 @@ /** The collating sequence used for text placed inside the field. */

}
interface FieldGeneric {
/**
* The visual display name of the field.
*/
name?: string;
}
interface SerializedField<T> {
/**
* Whether the field is required.
*/
required: boolean;
/**
* The value that the field should provide in the case of a missing value.
*/
defaultValue?: T | null;
/**
* Whether the field's value should be unique across all records of the model.
*/
unique: boolean;
/**
* Whether the field's value should be incremented automatically with each new record.
* Only available for number fields.
*/
increment: T extends number ? boolean : never;
}
interface LinkField {
/**
* Defines referential integrity behavior when linked records are modified.
*/
actions?: {
/**
* Action to take when the referenced record is deleted.
*/
onDelete?: 'cascade' | 'restrict' | 'set null' | 'no action';
/**
* Action to take when the referenced record is updated.
*/
onUpdate?: 'cascade' | 'restrict' | 'set null' | 'no action';
};
/**
* The model that this field links to.
*/
model: RoninFields | {
slug: string;
};
}
interface SerializedLinkField extends Omit<Partial<SerializedField<string>>, 'increment'>, LinkField {
}
type SerializedField<Type> = Partial<Omit<Extract<ModelField, {
type: Type;
}>, 'slug' | 'type'>>;
type FieldsToTypes<F> = F extends Record<string, Primitives> ? {

@@ -400,6 +374,16 @@ [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;

*/
declare const blob: (attributes?: Omit<Partial<SerializedField<string>>, "increment"> & FieldGeneric) => {
declare const blob: (attributes?: SerializedField<"blob">) => {
displayAs?: string | undefined;
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: string | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
name: string | undefined;

@@ -417,6 +401,16 @@ type: "blob";

*/
declare const boolean: (attributes?: Omit<Partial<SerializedField<boolean>>, "increment"> & FieldGeneric) => {
declare const boolean: (attributes?: SerializedField<"boolean">) => {
displayAs?: string | undefined;
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: boolean | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
name: string | undefined;

@@ -434,6 +428,16 @@ type: "boolean";

*/
declare const date: (attributes?: Omit<Partial<SerializedField<string | Date>>, "increment"> & FieldGeneric) => {
declare const date: (attributes?: SerializedField<"date">) => {
displayAs?: string | undefined;
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: string | Date | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
name: string | undefined;

@@ -443,5 +447,2 @@ type: "date";

interface JsonAttributes {
displayAs?: 'rich-text';
}
/**

@@ -455,8 +456,17 @@ * Creates a JSON field definition returning an object that includes the field type

*/
declare const json: (attributes?: Omit<Partial<SerializedField<string | object>>, "increment"> & FieldGeneric & JsonAttributes) => {
declare const json: (attributes?: SerializedField<"json">) => {
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: string | object | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
name: string | undefined;
displayAs: "rich-text" | undefined;
displayAs: string | undefined;
type: "json";

@@ -473,6 +483,16 @@ };

*/
declare const number: (attributes?: Partial<SerializedField<number>> & FieldGeneric) => {
declare const number: (attributes?: SerializedField<"number">) => {
displayAs?: string | undefined;
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: number | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
increment?: boolean | undefined;

@@ -491,13 +511,22 @@ name: string | undefined;

*/
declare const link: (attributes: SerializedLinkField & FieldGeneric) => {
declare const link: (attributes?: SerializedField<"link">) => {
displayAs?: string | undefined;
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: string | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
kind?: ("one" | "many") | undefined;
name: string | undefined;
model: RoninFields | {
slug: string;
};
target: string;
actions: {
onDelete?: "cascade" | "restrict" | "set null" | "no action";
onUpdate?: "cascade" | "restrict" | "set null" | "no action";
onDelete?: "CASCADE" | "RESTRICT" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
onUpdate?: "CASCADE" | "RESTRICT" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
} | undefined;

@@ -507,5 +536,2 @@ type: "link";

interface StringAttributes {
displayAs?: 'single-line' | 'multi-line' | 'secret';
}
/**

@@ -519,8 +545,18 @@ * Creates a string field definition returning an object that includes the field type

*/
declare const string: (attributes?: Omit<Partial<SerializedField<string>>, "increment"> & FieldGeneric & StringAttributes) => {
declare const string: (attributes?: SerializedField<"string">) => {
unique?: boolean | undefined;
required?: boolean | undefined;
defaultValue?: string | null | undefined;
unique?: boolean | undefined;
defaultValue?: unknown;
computedAs?: {
kind: "VIRTUAL" | "STORED";
value: {
__RONIN_EXPRESSION: string;
};
} | undefined;
check?: {
__RONIN_EXPRESSION: string;
} | undefined;
collation?: ("BINARY" | "NOCASE" | "RTRIM") | undefined;
name: string | undefined;
displayAs: "single-line" | "multi-line" | "secret";
displayAs: string;
type: "string";

@@ -527,0 +563,0 @@ };

@@ -919,8 +919,8 @@ var __create = Object.create;

// src/model/primitives/link.ts
var link = (attributes) => {
const { name, model: model2, actions, ...rest } = attributes;
if (!model2) throw new Error("A model is required for a link field");
var link = (attributes = {}) => {
const { name, target, actions, ...rest } = attributes;
if (!target) throw new Error("A model is required for a link field");
return {
name,
model: model2,
target,
actions,

@@ -1089,3 +1089,3 @@ type: "link",

const { type, unique, defaultValue, required, name } = value;
const { actions, model: model2 } = value;
const { actions, target } = value;
return {

@@ -1097,6 +1097,4 @@ slug: key,

defaultValue,
// @ts-expect-error: The `type` property exists in the model.
type,
// @ts-expect-error: The `target` property exists in the model.
target: model2?.slug,
target,
actions

@@ -1103,0 +1101,0 @@ };

{
"name": "@ronin/schema",
"version": "0.1.4-corny-ron-1071-experimental-20",
"version": "0.1.4-leo-ron-1071-experimental-21",
"type": "module",

@@ -32,3 +32,3 @@ "description": "Allows for defining the schema of a RONIN database in code.",

"@biomejs/biome": "1.9.4",
"@ronin/compiler": "0.13.1",
"@ronin/compiler": "0.13.8",
"@types/bun": "1.1.14",

@@ -35,0 +35,0 @@ "ronin": "5.3.5",