Adding new API CRUD v3 functionality.

This commit is contained in:
Scott Idem
2026-01-02 18:11:07 -05:00
parent 9111e14961
commit 2c7ed476af
4 changed files with 298 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
import type { key_val } from '$lib/stores/ae_stores';
import { get_object } from './api_get_object';
interface GetAeObjLiV3Params {
api_cfg: any;
obj_type: string;
for_obj_type?: string;
for_obj_id?: string;
enabled?: 'all' | 'enabled' | 'not_enabled';
hidden?: 'all' | 'hidden' | 'not_hidden';
limit?: number;
offset?: number;
order_by_li?: Record<string, 'ASC' | 'DESC'> | null;
delay_ms?: number;
log_lvl?: number;
}
export async function get_ae_obj_li_v3({
api_cfg,
obj_type,
for_obj_type,
for_obj_id,
enabled = 'enabled',
hidden = 'not_hidden',
limit = 100,
offset = 0,
order_by_li = null,
delay_ms = 0,
log_lvl = 0
}: GetAeObjLiV3Params) {
// 1. Build V3 Endpoint (Note: No /list suffix)
const endpoint = `/v3/crud/${obj_type}/`;
// 2. Build Query Params
const params: key_val = {
enabled,
hidden,
limit,
offset
};
if (for_obj_type) params['for_obj_type'] = for_obj_type;
if (for_obj_id) params['for_obj_id'] = for_obj_id;
if (order_by_li) params['order_by_li'] = JSON.stringify(order_by_li);
if (delay_ms > 0) params['delay_ms'] = delay_ms;
if (log_lvl) {
console.log('*** get_ae_obj_li_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Params:', params);
}
return await get_object({
api_cfg,
endpoint,
params,
log_lvl
});
}
interface GetNestedObjLiV3Params {
api_cfg: any;
parent_type: string;
parent_id: string;
child_type: string;
limit?: number;
offset?: number;
enabled?: 'all' | 'enabled' | 'not_enabled';
hidden?: 'all' | 'hidden' | 'not_hidden';
order_by_li?: Record<string, 'ASC' | 'DESC'> | null;
delay_ms?: number;
log_lvl?: number;
}
export async function get_nested_obj_li_v3({
api_cfg,
parent_type,
parent_id,
child_type,
limit = 100,
offset = 0,
enabled = 'enabled',
hidden = 'not_hidden',
order_by_li = null,
delay_ms = 0,
log_lvl = 0
}: GetNestedObjLiV3Params) {
const endpoint = `/v3/crud/${parent_type}/${parent_id}/${child_type}/`;
const params: key_val = {
enabled,
hidden,
limit,
offset
};
if (order_by_li) params['order_by_li'] = JSON.stringify(order_by_li);
if (delay_ms > 0) params['delay_ms'] = delay_ms;
if (log_lvl) {
console.log('*** get_nested_obj_li_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Params:', params);
}
return await get_object({
api_cfg,
endpoint,
params,
log_lvl
});
}

View File

@@ -0,0 +1,50 @@
import type { key_val } from '$lib/stores/ae_stores';
import { post_object } from './api_post_object';
interface SearchAeObjV3Params {
api_cfg: any;
obj_type: string;
search_query: any; // Complex SearchQuery object
order_by_li?: Record<string, 'ASC' | 'DESC'> | null;
limit?: number;
offset?: number;
delay_ms?: number;
log_lvl?: number;
}
export async function search_ae_obj_v3({
api_cfg,
obj_type,
search_query,
order_by_li = null,
limit = 100,
offset = 0,
delay_ms = 0,
log_lvl = 0
}: SearchAeObjV3Params) {
const endpoint = `/v3/crud/${obj_type}/search`;
const params: key_val = {
limit,
offset
};
if (order_by_li) params['order_by_li'] = JSON.stringify(order_by_li);
if (delay_ms > 0) params['delay_ms'] = delay_ms;
if (log_lvl) {
console.log('*** search_ae_obj_v3 ***');
console.log('Endpoint:', endpoint);
console.log('Params:', params);
console.log('Search Query:', search_query);
}
// Note: search_query is sent in the BODY via POST
return await post_object({
api_cfg,
endpoint,
params,
data: search_query,
log_lvl
});
}

View File

@@ -12,6 +12,8 @@ import { post_object } from '$lib/ae_api/api_post_object'; // Exported at the en
import { get_ae_obj_id_crud } from '$lib/ae_api/api_get__crud_obj_id';
import { get_ae_obj_li_for_obj_id_crud } from '$lib/ae_api/api_get__crud_obj_li_v1';
import { get_ae_obj_li_for_obj_id_crud_v2 } from '$lib/ae_api/api_get__crud_obj_li_v2';
import { get_ae_obj_li_v3, get_nested_obj_li_v3 } from '$lib/ae_api/api_get__crud_obj_li_v3';
import { search_ae_obj_v3 } from '$lib/ae_api/api_post__crud_search_v3';
// This new function has not been tested yet!!!
// Updated 2024-08-07
@@ -916,6 +918,9 @@ const obj = {
get_ae_obj_id_crud: get_ae_obj_id_crud,
get_ae_obj_li_for_obj_id_crud: get_ae_obj_li_for_obj_id_crud,
get_ae_obj_li_for_obj_id_crud_v2: get_ae_obj_li_for_obj_id_crud_v2,
get_ae_obj_li_v3: get_ae_obj_li_v3,
get_nested_obj_li_v3: get_nested_obj_li_v3,
search_ae_obj_v3: search_ae_obj_v3,
create_ae_obj_crud: create_ae_obj_crud,
update_ae_obj_id_crud: update_ae_obj_id_crud,
delete_ae_obj_id_crud: delete_ae_obj_id_crud,