metamigo-common: build, fmt, lint
This commit is contained in:
parent
2a1ced5383
commit
75fb3f84c4
21 changed files with 95 additions and 156 deletions
|
|
@ -12,7 +12,7 @@ export type PgProtocol<T> = IDatabase<T> & T;
|
|||
* @param aRecordType the record type runtime definition
|
||||
*/
|
||||
// haven't figured out a good return type for this function
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
|
||||
export function unboundRepositoryBase<
|
||||
TRecordInfo extends PgRecordInfo,
|
||||
TDatabaseExtension
|
||||
|
|
@ -48,7 +48,6 @@ export function unboundRepositoryBase<
|
|||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function RepositoryBase<
|
||||
Rec extends PgRecordInfo,
|
||||
TDatabaseExtension = unknown
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { TableName } from "pg-promise";
|
||||
import decamelcaseKeys from "decamelcase-keys";
|
||||
import isObject from "lodash/isObject";
|
||||
|
|
@ -106,7 +106,7 @@ export abstract class CrudRepository<
|
|||
`idsObj(${this.schemaTable}): passed record has multiple primary keys. the ids must be passed as an object or array. ${idValues}`
|
||||
);
|
||||
}
|
||||
// @ts-ignore
|
||||
|
||||
ids[idKeys[0]] = idValues;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
export interface EntityType<TUnsaved = any, TSaved = any, TIds extends object = any> {
|
||||
_saved: TSaved;
|
||||
_unsaved: TUnsaved;
|
||||
_idKeys: TIds;
|
||||
idOf: (rec: TSaved) => TIds;
|
||||
}
|
||||
export declare type UnsavedR<T extends {
|
||||
_unsaved: any;
|
||||
}> = T["_unsaved"];
|
||||
export declare type SavedR<T extends {
|
||||
_saved: any;
|
||||
}> = T["_saved"];
|
||||
export declare type KeyType<R extends EntityType> = R["_idKeys"];
|
||||
export interface PgRecordInfo<Unsaved = any, Saved extends Unsaved & IdType = any, IdType extends object = any> extends EntityType<Unsaved, Saved, IdType> {
|
||||
tableName: string;
|
||||
schemaName: string;
|
||||
idKeys: (keyof Saved)[];
|
||||
}
|
||||
/**
|
||||
* Extract the runtime key name from a recordInfo
|
||||
*/
|
||||
export declare function idKeysOf<RI extends PgRecordInfo>(recordInfoWithIdKey: RI): string[];
|
||||
/**
|
||||
* Turns a record type with possibly more fields than "id" into an array
|
||||
*/
|
||||
export declare function collectIdValues<RecordT extends PgRecordInfo>(idObj: KeyType<RecordT>, knexRecordType: RecordT): string[];
|
||||
/**
|
||||
*
|
||||
* Creates a record descriptor that captures the table name, primary key name,
|
||||
* unsaved type, and saved type of a database record type. Assumes "id" as the
|
||||
* primary key name
|
||||
*
|
||||
*/
|
||||
export declare function recordInfo<Unsaved, Saved extends Unsaved & {
|
||||
id: any;
|
||||
}>(schemaName: string, tableName: string): PgRecordInfo<Unsaved, Saved, Pick<Saved, "id">>;
|
||||
export declare function recordInfo<Type extends {
|
||||
id: string;
|
||||
}>(schemaName: string, tableName: string): PgRecordInfo<Type, Type, Pick<Type, "id">>;
|
||||
/**
|
||||
*
|
||||
* Creates a record descriptor that captures the table name, primary key name,
|
||||
* unsaved type, and saved type of a database record type.
|
||||
*
|
||||
*/
|
||||
export declare function recordInfo<Unsaved, Saved extends Unsaved, Id extends keyof Saved>(schemaName: string, tableName: string, idKey: Id[]): PgRecordInfo<Unsaved, Saved, Pick<Saved, Id>>;
|
||||
/**
|
||||
*
|
||||
* Creates a record descriptor for records with composite primary keys
|
||||
*
|
||||
*/
|
||||
export declare function compositeRecordType<TUnsaved, TSaved extends TUnsaved = TUnsaved>(schemaName: string, tableName: string): {
|
||||
withCompositeKeys<TKeys extends keyof TSaved>(keys: TKeys[]): PgRecordInfo<TUnsaved, TSaved, Pick<TSaved, TKeys>>;
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import at from "lodash/at";
|
||||
import pick from "lodash/pick";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue