This commit is contained in:
Benjamin Toby 2025-08-13 11:42:07 +01:00
parent 56198e8ac5
commit e8269a8b5e
7 changed files with 40 additions and 32 deletions

View File

@ -1,16 +1,16 @@
import { GrabUserResourceParams } from "../../../../types"; import { GrabUserResourceParams } from "../../../../types";
export default function (params?: GrabUserResourceParams): import("../../../../types").ServerQueryParam<{ export default function (params?: GrabUserResourceParams): import("../../../../types").ServerQueryParam<{
[k: string]: any; [k: string]: any;
}> & { }, string> & {
query?: import("../../../../types").ServerQueryQueryObject<{ query?: import("../../../../types").ServerQueryQueryObject<{
[k: string]: any; [k: string]: any;
}> | undefined; }, string> | undefined;
} & import("../../../../types").ServerQueryParam<any> & { } & import("../../../../types").ServerQueryParam<any, string> & {
query?: import("../../../../types").ServerQueryQueryObject<any> | undefined; query?: import("../../../../types").ServerQueryQueryObject<any, string> | undefined;
} & import("../../../../types").ServerQueryParam<{ } & import("../../../../types").ServerQueryParam<{
[k: string]: any; [k: string]: any;
}> & { }, string> & {
query?: import("../../../../types").ServerQueryQueryObject<{ query?: import("../../../../types").ServerQueryQueryObject<{
[k: string]: any; [k: string]: any;
}> | undefined; }, string> | undefined;
}; };

View File

@ -809,7 +809,7 @@ export type ServerQueryParam<T extends {
[k: string]: any; [k: string]: any;
} = { } = {
[k: string]: any; [k: string]: any;
}> = { }, K extends string = string> = {
selectFields?: (keyof T)[]; selectFields?: (keyof T)[];
omitFields?: (keyof T)[]; omitFields?: (keyof T)[];
query?: ServerQueryQueryObject<T>; query?: ServerQueryQueryObject<T>;
@ -825,27 +825,27 @@ export type ServerQueryParam<T extends {
addUserId?: { addUserId?: {
fieldName: keyof T; fieldName: keyof T;
}; };
join?: ServerQueryParamsJoin[]; join?: ServerQueryParamsJoin<K>[];
group?: (keyof T)[]; group?: (keyof T)[];
[key: string]: any; [key: string]: any;
}; };
export type ServerQueryObject<T extends object = { export type ServerQueryObject<T extends object = {
[key: string]: any; [key: string]: any;
}> = { }, K extends string = string> = {
value?: string | string[]; value?: string | string[];
nullValue?: boolean; nullValue?: boolean;
notNullValue?: boolean; notNullValue?: boolean;
operator?: (typeof ServerQueryOperators)[number]; operator?: (typeof ServerQueryOperators)[number];
equality?: (typeof ServerQueryEqualities)[number]; equality?: (typeof ServerQueryEqualities)[number];
tableName?: string; tableName?: K;
__query?: { __query?: {
[key in keyof T]: Omit<ServerQueryObject<T>, "__query">; [key in keyof T]: Omit<ServerQueryObject<T>, "__query">;
}; };
}; };
export type ServerQueryQueryObject<T extends object = { export type ServerQueryQueryObject<T extends object = {
[key: string]: any; [key: string]: any;
}> = { }, K extends string = string> = {
[key in keyof T]: ServerQueryObject<T>; [key in keyof T]: ServerQueryObject<T, K>;
}; };
export type FetchDataParams = { export type FetchDataParams = {
path: string; path: string;
@ -1218,8 +1218,8 @@ export type DsqlCrudQueryObject<T extends {
[key: string]: any; [key: string]: any;
} = { } = {
[key: string]: any; [key: string]: any;
}> = ServerQueryParam<T> & { }, K extends string = string> = ServerQueryParam<T, K> & {
query?: ServerQueryQueryObject<T>; query?: ServerQueryQueryObject<T, K>;
}; };
export type SQLDeleteGeneratorParams<T extends { export type SQLDeleteGeneratorParams<T extends {
[key: string]: any; [key: string]: any;
@ -1256,7 +1256,7 @@ export type DsqlCrudParam<T extends {
targetId?: string | number; targetId?: string | number;
targetValue?: string | number; targetValue?: string | number;
targetField?: keyof T; targetField?: keyof T;
query?: DsqlCrudQueryObject<T>; query?: DsqlCrudQueryObject<T, K>;
sanitize?: ({ data, batchData }: { sanitize?: ({ data, batchData }: {
data?: T; data?: T;
batchData?: T[]; batchData?: T[];

View File

@ -3,4 +3,4 @@ export default function <T extends {
[key: string]: any; [key: string]: any;
} = { } = {
[key: string]: any; [key: string]: any;
}>({ table, query, count, countOnly, dbFullName, tableSchema, dbConfig, }: Omit<DsqlCrudParam<T>, "action" | "data" | "sanitize">): Promise<APIResponseObject>; }, K extends string = string>({ table, query, count, countOnly, dbFullName, tableSchema, dbConfig, }: Omit<DsqlCrudParam<T, K>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;

View File

@ -986,7 +986,8 @@ export const ServerQueryEqualities = [
] as const; ] as const;
export type ServerQueryParam< export type ServerQueryParam<
T extends { [k: string]: any } = { [k: string]: any } T extends { [k: string]: any } = { [k: string]: any },
K extends string = string
> = { > = {
selectFields?: (keyof T)[]; selectFields?: (keyof T)[];
omitFields?: (keyof T)[]; omitFields?: (keyof T)[];
@ -1003,26 +1004,31 @@ export type ServerQueryParam<
addUserId?: { addUserId?: {
fieldName: keyof T; fieldName: keyof T;
}; };
join?: ServerQueryParamsJoin[]; join?: ServerQueryParamsJoin<K>[];
group?: (keyof T)[]; group?: (keyof T)[];
[key: string]: any; [key: string]: any;
}; };
export type ServerQueryObject<T extends object = { [key: string]: any }> = { export type ServerQueryObject<
T extends object = { [key: string]: any },
K extends string = string
> = {
value?: string | string[]; value?: string | string[];
nullValue?: boolean; nullValue?: boolean;
notNullValue?: boolean; notNullValue?: boolean;
operator?: (typeof ServerQueryOperators)[number]; operator?: (typeof ServerQueryOperators)[number];
equality?: (typeof ServerQueryEqualities)[number]; equality?: (typeof ServerQueryEqualities)[number];
tableName?: string; tableName?: K;
__query?: { __query?: {
[key in keyof T]: Omit<ServerQueryObject<T>, "__query">; [key in keyof T]: Omit<ServerQueryObject<T>, "__query">;
}; };
}; };
export type ServerQueryQueryObject<T extends object = { [key: string]: any }> = export type ServerQueryQueryObject<
{ T extends object = { [key: string]: any },
[key in keyof T]: ServerQueryObject<T>; K extends string = string
> = {
[key in keyof T]: ServerQueryObject<T, K>;
}; };
export type FetchDataParams = { export type FetchDataParams = {
@ -1432,9 +1438,10 @@ export type DsqlCrudTransformQueryFunction<
export const DsqlCrudActions = ["insert", "update", "delete", "get"] as const; export const DsqlCrudActions = ["insert", "update", "delete", "get"] as const;
export type DsqlCrudQueryObject< export type DsqlCrudQueryObject<
T extends { [key: string]: any } = { [key: string]: any } T extends { [key: string]: any } = { [key: string]: any },
> = ServerQueryParam<T> & { K extends string = string
query?: ServerQueryQueryObject<T>; > = ServerQueryParam<T, K> & {
query?: ServerQueryQueryObject<T, K>;
}; };
export type SQLDeleteGeneratorParams< export type SQLDeleteGeneratorParams<
@ -1469,7 +1476,7 @@ export type DsqlCrudParam<
targetId?: string | number; targetId?: string | number;
targetValue?: string | number; targetValue?: string | number;
targetField?: keyof T; targetField?: keyof T;
query?: DsqlCrudQueryObject<T>; query?: DsqlCrudQueryObject<T, K>;
sanitize?: ({ data, batchData }: { data?: T; batchData?: T[] }) => T | T[]; sanitize?: ({ data, batchData }: { data?: T; batchData?: T[] }) => T | T[];
debug?: boolean; debug?: boolean;
count?: boolean; count?: boolean;

View File

@ -5,7 +5,8 @@ import checkArrayDepth from "../check-array-depth";
import parseDbResults from "../../functions/backend/parseDbResults"; import parseDbResults from "../../functions/backend/parseDbResults";
export default async function < export default async function <
T extends { [key: string]: any } = { [key: string]: any } T extends { [key: string]: any } = { [key: string]: any },
K extends string = string
>({ >({
table, table,
query, query,
@ -15,7 +16,7 @@ export default async function <
tableSchema, tableSchema,
dbConfig, dbConfig,
}: Omit< }: Omit<
DsqlCrudParam<T>, DsqlCrudParam<T, K>,
"action" | "data" | "sanitize" "action" | "data" | "sanitize"
>): Promise<APIResponseObject> { >): Promise<APIResponseObject> {
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined; let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;

View File

@ -38,7 +38,7 @@ export default async function dsqlCrud<
switch (action) { switch (action) {
case "get": case "get":
return await dsqlCrudGet(params); return await dsqlCrudGet<T, K>(params);
// case "batch-get": // case "batch-get":
// return await dsqlCrudBatchGet(params); // return await dsqlCrudBatchGet(params);

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "5.2.0", "version": "5.2.1",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {