Aktueller Stand

This commit is contained in:
2026-01-23 01:33:35 +01:00
parent 082dc5e110
commit 2766dd12c5
10109 changed files with 1578841 additions and 77685 deletions

View File

@@ -0,0 +1,57 @@
import * as schema from './getSchema';
import { PrintOptions } from './printSchema';
import * as finder from './finder';
type ReplaceReturnType<Original extends (...args: any) => any, NewReturn> = (...a: Parameters<Original>) => NewReturn;
type ExtractKeys = 'getSchema' | 'getSubject' | 'getParent' | 'print';
type NeutralKeys = 'break' | 'comment' | 'attribute' | 'enumerator' | 'then' | 'findByType' | 'findAllByType';
type DatasourceOrGeneratorKeys = 'assignment';
type EnumKeys = 'enumerator';
type FieldKeys = 'attribute' | 'removeAttribute';
type BlockKeys = 'blockAttribute' | 'field' | 'removeField';
type PrismaSchemaFinderOptions = finder.ByTypeOptions & {
within?: finder.ByTypeSourceObject[];
};
type PrismaSchemaSubset<Universe extends keyof ConcretePrismaSchemaBuilder, Method> = ReplaceReturnType<ConcretePrismaSchemaBuilder[Universe], PrismaSchemaBuilder<Exclude<keyof ConcretePrismaSchemaBuilder, Method>>>;
type PrismaSchemaBuilder<K extends keyof ConcretePrismaSchemaBuilder> = {
[U in K]: U extends ExtractKeys ? ConcretePrismaSchemaBuilder[U] : U extends NeutralKeys ? ConcretePrismaSchemaBuilder[U] : U extends 'datasource' ? PrismaSchemaSubset<U, 'datasource' | EnumKeys | FieldKeys | BlockKeys> : U extends 'generator' ? PrismaSchemaSubset<U, EnumKeys | FieldKeys | BlockKeys> : U extends 'model' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'view' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'type' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'field' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> : U extends 'removeField' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys> : U extends 'enum' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | BlockKeys | FieldKeys> : U extends 'removeAttribute' ? PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys> : PrismaSchemaSubset<U, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys | BlockKeys | 'comment'>;
};
type Arg = string | {
name: string;
function?: Arg[];
};
type Subject = schema.Block | schema.Field | schema.Enumerator | undefined;
export declare class ConcretePrismaSchemaBuilder {
private schema;
private _subject;
private _parent;
constructor(source?: string);
print(options?: PrintOptions): string;
getSchema(): schema.Schema;
generator(name: string, provider?: string): this;
drop(name: string): this;
datasource(provider: string, url: string | {
env: string;
}): this;
model(name: string): this;
view(name: string): this;
type(name: string): this;
enum(name: string, enumeratorNames?: string[]): this;
enumerator(value: string): this;
private getSubject;
private getParent;
blockAttribute(name: string, args?: string | string[] | Record<string, schema.Value>): this;
attribute<T extends schema.Field>(name: string, args?: Arg[] | Record<string, string[]>): this;
removeAttribute<T extends schema.Field>(name: string): this;
assignment<T extends schema.Generator | schema.Datasource>(key: string, value: string): this;
findByType<const Match extends finder.ByTypeMatch>(typeToMatch: Match, { within, ...options }: PrismaSchemaFinderOptions): finder.FindByBlock<Match> | null;
findAllByType<const Match extends finder.ByTypeMatch>(typeToMatch: Match, { within, ...options }: PrismaSchemaFinderOptions): Array<finder.FindByBlock<Match> | null>;
private blockInsert;
break(): this;
comment(text: string, node?: boolean): this;
schemaComment(text: string, node?: boolean): this;
field(name: string, fieldType?: string | schema.Func): this;
removeField(name: string): this;
then<R extends NonNullable<Subject>>(callback: (subject: R) => unknown): this;
}
export declare function createPrismaSchemaBuilder(source?: string): PrismaSchemaBuilder<Exclude<keyof ConcretePrismaSchemaBuilder, DatasourceOrGeneratorKeys | EnumKeys | FieldKeys | BlockKeys>>;
export {};

View File

@@ -0,0 +1,12 @@
import type * as schema from './getSchema';
export type ByTypeSourceObject = schema.Block | schema.Enumerator | schema.Field | schema.Property | schema.Attribute | schema.Assignment;
export type ByTypeMatchObject = Exclude<ByTypeSourceObject, schema.Comment | schema.Break>;
export type ByTypeMatch = ByTypeMatchObject['type'];
export type ByTypeOptions = {
name?: string | RegExp;
};
export type FindByBlock<Match> = Extract<ByTypeMatchObject, {
type: Match;
}>;
export declare const findByType: <const Match extends "model" | "view" | "datasource" | "generator" | "enum" | "type" | "enumerator" | "field" | "attribute" | "assignment">(list: ByTypeSourceObject[], typeToMatch: Match, options?: ByTypeOptions) => FindByBlock<Match> | null;
export declare const findAllByType: <const Match extends "model" | "view" | "datasource" | "generator" | "enum" | "type" | "enumerator" | "field" | "attribute" | "assignment">(list: ByTypeSourceObject[], typeToMatch: Match, options?: ByTypeOptions) => FindByBlock<Match>[];

View File

@@ -0,0 +1,6 @@
import type { IParserConfig } from 'chevrotain';
export type PrismaAstParserConfig = Pick<IParserConfig, 'nodeLocationTracking'>;
export interface PrismaAstConfig {
parser: PrismaAstParserConfig;
}
export default function getConfig(): PrismaAstConfig;

View File

@@ -0,0 +1,119 @@
import { PrismaVisitor } from './visitor';
import type { CstNodeLocation } from 'chevrotain';
import { PrismaParser } from './parser';
export declare function getSchema(source: string, options?: {
parser: PrismaParser;
visitor: PrismaVisitor;
}): Schema;
export interface Schema {
type: 'schema';
list: Block[];
}
export type Block = Model | View | Datasource | Generator | Enum | Comment | Break | Type;
export interface Object {
type: 'model' | 'view' | 'type';
name: string;
properties: Array<Property | Comment | Break>;
}
export interface Model extends Object {
type: 'model';
location?: CstNodeLocation;
}
export interface View extends Object {
type: 'view';
location?: CstNodeLocation;
}
export interface Type extends Object {
type: 'type';
location?: CstNodeLocation;
}
export interface Datasource {
type: 'datasource';
name: string;
assignments: Array<Assignment | Comment | Break>;
location?: CstNodeLocation;
}
export interface Generator {
type: 'generator';
name: string;
assignments: Array<Assignment | Comment | Break>;
location?: CstNodeLocation;
}
export interface Enum {
type: 'enum';
name: string;
enumerators: Array<Enumerator | Comment | Break | BlockAttribute | GroupedAttribute>;
location?: CstNodeLocation;
}
export interface Comment {
type: 'comment';
text: string;
}
export interface Break {
type: 'break';
}
export type Property = GroupedBlockAttribute | BlockAttribute | Field;
export interface Assignment {
type: 'assignment';
key: string;
value: Value;
}
export interface Enumerator {
type: 'enumerator';
name: string;
value?: Value;
attributes?: Attribute[];
comment?: string;
}
export interface BlockAttribute {
type: 'attribute';
kind: 'object' | 'view' | 'type';
group?: string;
name: string;
args: AttributeArgument[];
location?: CstNodeLocation;
}
export type GroupedBlockAttribute = BlockAttribute & {
group: string;
};
export interface Field {
type: 'field';
name: string;
fieldType: string | Func;
array?: boolean;
optional?: boolean;
attributes?: Attribute[];
comment?: string;
location?: CstNodeLocation;
}
export type Attr = Attribute | GroupedAttribute | BlockAttribute | GroupedBlockAttribute;
export interface Attribute {
type: 'attribute';
kind: 'field';
group?: string;
name: string;
args?: AttributeArgument[];
location?: CstNodeLocation;
}
export type GroupedAttribute = Attribute & {
group: string;
};
export interface AttributeArgument {
type: 'attributeArgument';
value: KeyValue | Value | Func;
}
export interface KeyValue {
type: 'keyValue';
key: string;
value: Value;
}
export interface Func {
type: 'function';
name: string;
params?: Value[];
}
export interface RelationArray {
type: 'array';
args: string[];
}
export type Value = string | number | boolean | Func | RelationArray | Array<Value>;

View File

@@ -0,0 +1,8 @@
export * from './produceSchema';
export * from './getSchema';
export * from './printSchema';
export * from './PrismaSchemaBuilder';
export type { PrismaAstConfig } from './getConfig';
export type { CstNodeLocation } from 'chevrotain';
export { VisitorClassFactory } from './visitor';
export { PrismaParser } from './parser';

View File

@@ -0,0 +1,8 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./prisma-ast.cjs.production.min.js')
} else {
module.exports = require('./prisma-ast.cjs.development.js')
}

View File

@@ -0,0 +1,34 @@
import { Lexer, IMultiModeLexerDefinition } from 'chevrotain';
export declare const Identifier: import("chevrotain").TokenType;
export declare const Datasource: import("chevrotain").TokenType;
export declare const Generator: import("chevrotain").TokenType;
export declare const Model: import("chevrotain").TokenType;
export declare const View: import("chevrotain").TokenType;
export declare const Enum: import("chevrotain").TokenType;
export declare const Type: import("chevrotain").TokenType;
export declare const True: import("chevrotain").TokenType;
export declare const False: import("chevrotain").TokenType;
export declare const Null: import("chevrotain").TokenType;
export declare const Comment: import("chevrotain").TokenType;
export declare const DocComment: import("chevrotain").TokenType;
export declare const LineComment: import("chevrotain").TokenType;
export declare const Attribute: import("chevrotain").TokenType;
export declare const BlockAttribute: import("chevrotain").TokenType;
export declare const FieldAttribute: import("chevrotain").TokenType;
export declare const Dot: import("chevrotain").TokenType;
export declare const QuestionMark: import("chevrotain").TokenType;
export declare const LCurly: import("chevrotain").TokenType;
export declare const RCurly: import("chevrotain").TokenType;
export declare const LRound: import("chevrotain").TokenType;
export declare const RRound: import("chevrotain").TokenType;
export declare const LSquare: import("chevrotain").TokenType;
export declare const RSquare: import("chevrotain").TokenType;
export declare const Comma: import("chevrotain").TokenType;
export declare const Colon: import("chevrotain").TokenType;
export declare const Equals: import("chevrotain").TokenType;
export declare const StringLiteral: import("chevrotain").TokenType;
export declare const NumberLiteral: import("chevrotain").TokenType;
export declare const WhiteSpace: import("chevrotain").TokenType;
export declare const LineBreak: import("chevrotain").TokenType;
export declare const multiModeTokens: IMultiModeLexerDefinition;
export declare const PrismaLexer: Lexer;

View File

@@ -0,0 +1,23 @@
import { CstParser } from 'chevrotain';
import { PrismaAstParserConfig } from './getConfig';
export declare class PrismaParser extends CstParser {
readonly config: PrismaAstParserConfig;
constructor(config: PrismaAstParserConfig);
private break;
private keyedArg;
private array;
private func;
private value;
private property;
private assignment;
private field;
private block;
private enum;
private fieldAttribute;
private blockAttribute;
private attributeArg;
private component;
private comment;
schema: import("chevrotain").ParserMethod<[], import("chevrotain").CstNode>;
}
export declare const defaultParser: PrismaParser;

View File

@@ -0,0 +1,9 @@
import * as Types from './getSchema';
type Block = 'generator' | 'datasource' | 'model' | 'view' | 'enum' | 'type';
export interface PrintOptions {
sort?: boolean;
locales?: string | string[];
sortOrder?: Block[];
}
export declare function printSchema(schema: Types.Schema, options?: PrintOptions): string;
export {};

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
import { PrintOptions } from './printSchema';
import { createPrismaSchemaBuilder } from './PrismaSchemaBuilder';
type Options = PrintOptions;
export declare function produceSchema(source: string, producer: (builder: ReturnType<typeof createPrismaSchemaBuilder>) => void, options?: Options): string;
export {};

View File

@@ -0,0 +1,2 @@
import { Block, Schema } from './getSchema';
export declare const schemaSorter: (schema: Schema, locales?: string | string[], sortOrder?: string[]) => (a: Block, b: Block) => number;

View File

@@ -0,0 +1,16 @@
import type { CstNode, IToken } from 'chevrotain';
import * as schema from './getSchema';
declare const schemaObjects: readonly ["model", "view", "type"];
export declare function isOneOfSchemaObjects<T extends string>(obj: schema.Object, schemas: readonly T[]): obj is Extract<schema.Object, {
type: T;
}>;
export declare function isSchemaObject(obj: schema.Object): obj is Extract<schema.Object, {
type: (typeof schemaObjects)[number];
}>;
declare const fieldObjects: readonly ["field", "enumerator"];
export declare function isSchemaField(field: schema.Field | schema.Enumerator): field is Extract<schema.Field, {
type: (typeof fieldObjects)[number];
}>;
export declare function isToken(node: [IToken] | [CstNode]): node is [IToken];
export declare function appendLocationData<T extends Record<string, unknown>>(data: T, ...tokens: IToken[]): T;
export {};

View File

@@ -0,0 +1,8 @@
import { PrismaParser } from './parser';
import { ICstVisitor } from 'chevrotain';
type Class<T> = new (...args: any[]) => T;
export type PrismaVisitor = ICstVisitor<any, any>;
export declare const VisitorClassFactory: (parser: PrismaParser) => Class<PrismaVisitor>;
export declare const DefaultVisitorClass: Class<PrismaVisitor>;
export declare const defaultVisitor: PrismaVisitor;
export {};