-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import memori from '../index'; | ||
|
||
const client = memori('https://backend.memori.ai'); | ||
|
||
describe('engine/functions api', () => { | ||
it('works on functions apis', async () => { | ||
expect( | ||
await client.functions.getFunction( | ||
'768b9654-e781-4c3c-81fa-ae1529d1bfbe', | ||
'768b9654-e781-4c3c-81fa-ae1529d1bfbe' | ||
) | ||
).not.toBeNull(); | ||
}); | ||
|
||
it('works on functions apis with shorthand version', async () => { | ||
expect( | ||
await client.getFunction( | ||
'768b9654-e781-4c3c-81fa-ae1529d1bfbe', | ||
'768b9654-e781-4c3c-81fa-ae1529d1bfbe' | ||
) | ||
).not.toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import type { ResponseSpec, Function } from '../types'; | ||
import { apiFetcher } from '../apiFetcher'; | ||
|
||
/********************* | ||
* * | ||
* Functions * | ||
* * | ||
*********************/ | ||
|
||
export default (apiUrl: string) => ({ | ||
/** | ||
* Lists all Functions objects. | ||
* @param {string} sessionId The session ID | ||
*/ | ||
getAllFunctions: async (sessionId: string) => | ||
apiFetcher(`/Functions/${sessionId}`, { | ||
method: 'GET', | ||
apiUrl, | ||
}) as Promise< | ||
ResponseSpec & { | ||
/** | ||
* Total number of Function objects. | ||
*/ | ||
count: number; | ||
/** | ||
* List of Function objects. May be empty. | ||
*/ | ||
functions: Function[]; | ||
} | ||
>, | ||
|
||
/** | ||
* Lists Function objects with pagination. | ||
* @param {string} sessionId The session ID | ||
* @param {number} from The 0-based index of the first Function object to list | ||
* @param {number} howMany The number of the Function objects to list | ||
*/ | ||
getFunctionsPaginated: async ( | ||
sessionId: string, | ||
from: number, | ||
howMany: number | ||
) => | ||
apiFetcher(`/Functions/${sessionId}/${from}/${howMany}`, { | ||
method: 'GET', | ||
apiUrl, | ||
}) as Promise< | ||
ResponseSpec & { | ||
/** | ||
* Total number of Function objects. | ||
*/ | ||
count: number; | ||
/** | ||
* List of Function objects. May be empty. | ||
*/ | ||
functions: Function[]; | ||
} | ||
>, | ||
|
||
/** | ||
* Gets the details of a Function object. | ||
* @param {string} sessionId The session ID | ||
* @param {string} functionID The Function object ID | ||
*/ | ||
getFunction: async (sessionId: string, functionID: string) => | ||
apiFetcher(`/Function/${sessionId}/${functionID}`, { | ||
method: 'GET', | ||
apiUrl, | ||
}) as Promise< | ||
ResponseSpec & { | ||
function: Function; | ||
} | ||
>, | ||
|
||
/** | ||
* Updates an existing Function object. | ||
* Only non-null (present) fields are considered for update. Null or absent fields are left unaltered. | ||
* @param {string} sessionId The session ID | ||
* @param {Function} func The Function object | ||
*/ | ||
patchFunction: async ( | ||
sessionId: string, | ||
func: Partial<Function> & { functionID: string } | ||
) => | ||
apiFetcher(`/Function/${sessionId}/${func.functionID}`, { | ||
method: 'PATCH', | ||
apiUrl, | ||
body: func, | ||
}) as Promise<ResponseSpec>, | ||
|
||
/** | ||
* Removes an existing Function object. | ||
* @param {string} sessionId The session ID | ||
* @param {string} functionID The Function object ID | ||
*/ | ||
deleteFunction: async (sessionId: string, functionID: string) => | ||
apiFetcher(`/Function/${sessionId}/${functionID}`, { | ||
method: 'DELETE', | ||
apiUrl, | ||
}) as Promise<ResponseSpec>, | ||
|
||
/** | ||
* Creates a new Function object. | ||
* @param {string} sessionId The session ID | ||
* @param {Function} func The Function object | ||
*/ | ||
createFunction: async (sessionId: string, func: Function) => | ||
apiFetcher(`/Function/${sessionId}`, { | ||
method: 'POST', | ||
apiUrl, | ||
body: func, | ||
}) as Promise< | ||
ResponseSpec & { | ||
functionID: string; | ||
} | ||
>, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters