-
Notifications
You must be signed in to change notification settings - Fork 1
/
arangojs.jsy
33 lines (24 loc) · 905 Bytes
/
arangojs.jsy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {bkc_hexkey_api, as_hex_key, as_u8_key} from '../_utils.jsy'
#IF PLAT_NODEJS
import {u8_to_base64, base64_to_u8} from 'u8-utils/esm/node/base64.mjs'
#ELIF PLAT_WEB
import {u8_to_base64, base64_to_u8} from 'u8-utils/esm/web/base64.js'
export {as_hex_key, as_u8_key}
export default bkc_with_arangojs
export async function bkc_with_arangojs(adb_collection) ::
return bkc_hexkey_api @:
async hk_has(hex_key) ::
const exists = await adb_collection
.documentExists(hex_key)
return exists ? 1 : 0
async hk_get(hex_key) ::
const doc = await adb_collection
.document(hex_key, {graceful: true})
if null != doc ::
return base64_to_u8(doc.hc)
async hk_set(hex_key, u8_content) ::
const doc = @{}
_key: hex_key
hc: u8_to_base64(u8_content)
try :: await adb_collection.save(doc)
catch err :: return err