prisma-util
Version:
Prisma Util is an easy to use tool that merges multiple Prisma schema files, allows extending of models, resolves naming conflicts both manually and automatically and provides easy access to Prisma commands and timing reports. It's mostly a plug-and-play
220 lines (219 loc) • 8.04 kB
TypeScript
/**
* Project Toolchain asset representing a PrismaClient file and its name inside the Generation Toolchain.
* This type is used to initialize the Generation Toolchain.
*
* The key of this object represents the code name of this asset.
* The value of this object represents the path of the asset relative to the project root.
*/
declare type AssetBundle = {
[key: string]: string | AssetBundle;
};
/**
* Ignore search step.
*/
export declare const IGNORE_SEARCH_STEP = "<IGNORE_SEARCH>";
/**
* Project Toolchain default assets to be used in the Generation Toolchain.
*
* This map includes all runtime declarations of `@prisma/client/runtime`:
*
* PRISMA_CLIENT_RUNTIME: {
* EDGE: "node_modules/@prisma/client/runtime/edge.js",
* EDGE_ESM: "node_modules/@prisma/client/runtime/edge-esm.js",
* INDEX: "node_modules/@prisma/client/runtime/index.js",
* }
*
* This map includes all generated declarations of `.prisma/client`:
*
* PRISMA_CLIENT_GENERATED: {
* EDGE: "node_modules/.prisma/client/edge.js",
* INDEX: "node_modules/.prisma/client/index.js",
* INDEX_TYPES: "node_modules/.prisma/client/index.d.ts",
* }
*/
declare const DEFAULT_ASSETS: {
PRISMA_CLIENT_RUNTIME: {
EDGE: string;
EDGE_ESM: string;
INDEX: string;
};
PRISMA_CLIENT_GENERATED: {
EDGE: string;
INDEX: string;
INDEX_TYPES: string;
};
};
/**
* The strategy that the Generation Toolchain should use for an {@link EditTransaction}.
*/
export declare enum EditStrategy {
REGEX = 0,
JOIN = 1,
REPLACE = 2,
REPLACE_UNSAFE = 3,
REPLACE_FULL = 4,
NONE = 5
}
/**
* Project Toolchain backend implementation.
*
* This class orchestrates code generation and editing and provides an unified API for using the generated code.
* It provides utilities as well as state handling between edits to make sure that the correct code is written.
*
* This API is intended for internal use only. You should not instantiate this class, but rather use the exported
* instance. ({@link GenerationToolchainInstance})
*/
declare class GenerationToolchain {
private _assets;
private queue;
private processPromise?;
private _useExtensions;
constructor();
/**
* Use extensions instead of code edits.
* @param useExtensions Whether extensions should be used or not.
* @returns This instance for chaining.
*/
useExtensions(useExtensions: boolean): GenerationToolchain;
/**
* Returns the current repository of assets.
*/
get ASSETS(): AssetBundle & typeof DEFAULT_ASSETS;
/**
* This function allows you to add assets that you can use later when generating.
* @param assets The assets that should be added to the repository.
*/
addAssets(assets: AssetBundle): void;
/**
* Create a transaction to modify internal assets from PrismaClient.
* @returns An {@link EditTransaction} that you can use to modify internal assets.
*/
createEditTransaction(): EditTransaction;
/**
* Add an edit transaction to the processing queue. Transactions are processed sequentially and can't
* be created while the Generation Toolchain is processing.
* @param transaction The transaction that should be queued.
* @returns True if the transaction has been added to the queue, false otherwise.
*/
queueEditTransaction(transaction: EditTransaction): boolean;
/**
* Start processing the transaction queue.
* @returns A Promise that will resolve when processing finishes.
*/
process(): Promise<void>;
}
/**
* Edit Transaction is an interface that allows you to edit a PrismaClient internal asset without worrying
* about index shifting or file searching.
*
* To create an EditTransaction, use the {@link GenerationToolchain.createEditTransaction} function and chain the
* function calls to this class, then use {@link EditTransaction.end} when you're done.
*/
export declare class EditTransaction {
private generationToolchain;
private requestedAsset;
private transactionBlocks;
constructor(generationToolchain: GenerationToolchain);
/**
* Returns the path to the requested asset of this transaction.
*/
get changedAsset(): string;
/**
* Returns the changes for this transaction.
*/
get blocks(): EditTransactionBlock[];
/**
* Mark this transaction as finished. This function will add the transaction to the queue for edits
* and will be processed sequentially.
* @returns The {@link GenerationToolchain} instance that was used for this transaction.
*/
end(): GenerationToolchain;
/**
* Change the asset being edited in this transaction.
* @param assetName The asset that you want to edit.
* @returns This transaction for chaining.
*/
requestAsset(assetName: string): EditTransaction;
/**
* Add a transaction block to this edit transaction.
*
* This method isn't supposed to be called manually.
*
* Method Flags: @Internal @NoManual
* @param transactionBlock The transaction block to add.
*/
pushTransactionBlock(transactionBlock: EditTransactionBlock): void;
/**
* Create a new change for this transaction.
* @returns A new transaction block.
*/
createBlock(): EditTransactionBlock;
}
/**
* A transaction block handles a change in a transaction.
*/
export declare class EditTransactionBlock {
private editTransaction;
strategy: EditStrategy;
from: (string | RegExp);
to: (string | ((...groups: string[]) => string));
search: string;
ammend: number;
ignoreExtensions: boolean;
constructor(editTransaction: EditTransaction);
/**
* Change the edit strategy for this block.
* @param strategy The new strategy to use.
* @returns This transaction block for chaining.
*/
setStrategy(strategy: EditStrategy): EditTransactionBlock;
/**
* Disable this block based on extension status.
* @param ignoreExtensions Whether this block should be ran even if extensions are enabked.
* @returns This transaction block for chaining.
*/
setIgnoreExtensions(ignoreExtensions: boolean): EditTransactionBlock;
/**
* Change a line from this asset.
* @param from The line to search for.
* @param modifier The value that will be added to the index.
* @returns This transaction block for chaining.
*/
findLine(from: string | RegExp, modifier?: number): EditTransactionBlock;
/**
* Append content to the file.
* @param to The content to add.
* @returns This transaction block for chaining.
*/
appendContent(to: (string | ((...groups: string[]) => string))): EditTransactionBlock;
/**
* Add search query to be used with {@link EditStrategy.REPLACE_UNSAFE}.
* @param search The search query that will be used for security.
* @returns This transaction block for chaining.
*/
setSearch(search: string): EditTransactionBlock;
/**
* Create a new change for this transaction.
* @returns A new transaction block.
*/
createBlock(): EditTransactionBlock;
/**
* Mark this transaction as finished. This function will add the transaction to the queue for edits
* and will be processed sequentially.
* @returns The {@link GenerationToolchain} instance that was used for this transaction.
*/
end(): GenerationToolchain;
/**
* Mark this transaction block as finished.
* @returns The {@link EditTransaction} that this block belongs to.
*/
endBlock(): EditTransaction;
}
/**
* Instance of the Project Toolchain backend implementation.
*
* This is the entry-point to all code generation and PrismaClient edits, as it provides an unified interface
* for making changes and creating comments.
*/
export declare const GenerationToolchainInstance: GenerationToolchain;
export {};