@cwqt/refract
Advanced tools
Comparing version 1.2.3 to 1.3.0
import * as Types from '../../types'; | ||
export declare const Key: <T extends string>(name: T, ...modifiers: Types.Modifier<'EnumKey'>[]) => Types.Fields.EnumKey<T>; | ||
export declare const Key: <T extends string>(...args: [name: T, ...modifiers: Types.Modifier<"EnumKey", "map" | "comment">[]] | [name: T, ...modifiers: Types.Modifier<"EnumKey", "map" | "comment">[], comment: string]) => Types.Fields.EnumKey<T>; | ||
declare type R<E extends Types.Fields.EnumKey[]> = (<M extends Types.Modifiers<'Enum'>>(initial?: E[number]['name'] | null, ...modifiers: Types.Modifier<'Enum', M>[]) => Types.Fields.Field<'Enum', M>) & Types.Blocks.Enum; | ||
@@ -4,0 +4,0 @@ export declare function Enum<E extends Types.Fields.EnumKey[]>(name: string, ...keys: E): R<E>; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Enum = exports.Key = void 0; | ||
const utils_1 = require("../../types/utils"); | ||
const Key = (name, ...modifiers) => ({ name, modifiers }); | ||
const Key = (...args) => { | ||
const [name, ...modifiers] = args; | ||
return (0, utils_1.isString)(args[args.length - 1]) | ||
? { | ||
name, | ||
modifiers: [ | ||
...modifiers.slice(0, modifiers.length - 1), | ||
{ type: 'comment', value: args[args.length - 1] }, | ||
], | ||
} | ||
: { name, modifiers: modifiers }; | ||
}; | ||
exports.Key = Key; | ||
@@ -6,0 +17,0 @@ class $Enum extends Function { |
@@ -5,5 +5,5 @@ import * as Types from '../types'; | ||
Raw: (value: string) => Model; | ||
Relation: <T extends Types.Fields.Relation>(name: string, type: Types.Fields.Field<T>) => Model; | ||
Field: <T extends Types.Fields.Scalar | 'Enum' | 'Unsupported'>(name: string, type: Types.Fields.Field<T>) => Model; | ||
Block: <T extends Types.Fields.Compound>(type: Types.Fields.Field<T>) => Model; | ||
Relation: <T extends Types.Fields.Relation>(name: string, type: Types.Fields.Field<T>, comment?: string) => Model; | ||
Field: <T extends Types.Fields.Scalar | 'Enum' | 'Unsupported'>(name: string, type: Types.Fields.Field<T>, comment?: string) => Model; | ||
Block: <T extends Types.Fields.Compound>(type: Types.Fields.Field<T>, comment?: string) => Model; | ||
} & Types.Blocks.Model; | ||
@@ -18,6 +18,6 @@ export declare const Model: (name: string, comment?: string) => Model; | ||
Raw(value: string): this; | ||
Relation<T extends Types.Fields.Relation>(name: string, type: Types.Fields.Field<T>): this; | ||
Field<T extends Types.Fields.Scalar | 'Enum' | 'Unsupported'>(name: string, type: Types.Fields.Field<T>): this; | ||
Block<T extends Types.Fields.Compound>(type: Types.Fields.Field<T>): this; | ||
Relation<T extends Types.Fields.Relation>(name: string, type: Types.Fields.Field<T>, comment?: string): this; | ||
Field<T extends Types.Fields.Scalar | 'Enum' | 'Unsupported'>(name: string, type: Types.Fields.Field<T>, comment?: string): this; | ||
Block<T extends Types.Fields.Compound>(type: Types.Fields.Field<T>, comment?: string): this; | ||
} | ||
export {}; |
@@ -33,11 +33,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
} | ||
Relation(name, type) { | ||
Relation(name, type, comment) { | ||
if (comment) | ||
type.modifiers.push({ type: 'comment', value: comment }); | ||
this.columns.push({ name, ...type }); | ||
return this; | ||
} | ||
Field(name, type) { | ||
Field(name, type, comment) { | ||
if (comment) | ||
type.modifiers.push({ type: 'comment', value: comment }); | ||
this.columns.push({ name, ...type }); | ||
return this; | ||
} | ||
Block(type) { | ||
Block(type, comment) { | ||
if (comment) | ||
type.modifiers.push({ type: 'comment', value: comment }); | ||
this.columns.push(type); | ||
@@ -44,0 +50,0 @@ return this; |
@@ -32,6 +32,2 @@ import * as Types from '../types'; | ||
}; | ||
export declare const Comment: (value: string) => { | ||
type: "comment"; | ||
value: string; | ||
}; | ||
export declare const Limit: <K extends number>(value: K) => Types.Modifier<'String', 'limit'>; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Limit = exports.Comment = exports.Raw = exports.Array = exports.Ignore = exports.Id = exports.Nullable = exports.UpdatedAt = exports.Unique = exports.Map = exports.Default = void 0; | ||
exports.Limit = exports.Raw = exports.Array = exports.Ignore = exports.Id = exports.Nullable = exports.UpdatedAt = exports.Unique = exports.Map = exports.Default = void 0; | ||
const Default = (value) => ({ type: 'default', value }); | ||
@@ -33,5 +33,3 @@ exports.Default = Default; | ||
exports.Raw = Raw; | ||
const Comment = (value) => ({ type: 'comment', value }); | ||
exports.Comment = Comment; | ||
const Limit = (value) => ({ type: 'limit', value }); | ||
exports.Limit = Limit; |
{ | ||
"name": "@cwqt/refract", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "Generate Prisma from TypeScript", | ||
@@ -5,0 +5,0 @@ "author": "cwqt", |
@@ -78,6 +78,7 @@ # refract | ||
User.Field('id', Int(Id, Default('autoincrement()'))); | ||
User.Field('id', Int(Id, Default('autoincrement()')), 'The primary key'); | ||
// This is an optional comment | ||
// // This is an optional comment | ||
// model User { | ||
// // The primary key | ||
// id Int @id @default(autoincrement()) | ||
@@ -109,4 +110,3 @@ // } | ||
Additionally all scalars can use: Nullable, Map, Ignore, Raw, Array & Comment | ||
modifiers. | ||
Additionally all scalars can use: Nullable, Map, Ignore, Raw & Array modifiers. | ||
@@ -146,8 +146,8 @@ ```typescript | ||
- `OneToMany` (model, name?, ...modifiers) | ||
- Nullable, Comment | ||
- Nullable | ||
- `OneToOne` (model, name?, fields, references, ...modifiers) | ||
- `OneToOne` (model, name?, ...modifiers) | ||
- Nullable, OnUpdate(Action), OnDelete(Action), Comment | ||
- Nullable, OnUpdate(Action), OnDelete(Action) | ||
- `ManyToOne` (model, name?, fields, references, ...modifiers) | ||
- Nullable, OnUpdate(Action), OnDelete(Action), Comment | ||
- Nullable, OnUpdate(Action), OnDelete(Action) | ||
@@ -235,4 +235,4 @@ Where `Action` is one of: `Cascade`, `Restrict`, `NoAction`, `SetNull`, `SetDefault` | ||
- `Enum(name, comment?, ...Key)` | ||
- `Key(value, ...modifiers)` | ||
- Map, Comment | ||
- `Key(value, ...modifiers, comment?)` | ||
- Map | ||
@@ -255,5 +255,4 @@ <!-- prettier-ignore --> | ||
const WithComment = Enum( | ||
"Foo", | ||
"This is with a comment", | ||
Key("Bar", Comment("Another comment")) | ||
"Foo", "This is with a comment", | ||
Key("Bar", "Another comment") | ||
); | ||
@@ -260,0 +259,0 @@ // // This is with a comment |
129154
1825
342