elasticio / maester-client

The official object-storage client library for sailor-nodejs.
Apache License 2.0
0 stars 0 forks source link

Refactor duplicate code for metadata header x-meta- #4

Open shulkaolka opened 3 years ago

shulkaolka commented 3 years ago

Looks like it is a duplicate for one functionality: https://github.com/elasticio/maester-client/blob/master/src/object.ts#L170

        if (params?.objectFields) {
            Object.entries(params.objectFields).forEach(e => {
                if (e[1].Query) headers[`X-Query-${e[0]}`] = e[1].Query;
                if (e[1].Meta) headers[`X-Meta-${e[0]}`] = e[1].Meta;
            })
        }

and https://github.com/elasticio/maester-client/blob/master/src/object.ts#L24

export function metaToHeaders(meta: ObjectMetadata): Record<string, string> {
    const headers: Record<string, string> = {};
    for (const [key, value] of Object.entries(meta)) {
        headers[`${USER_META_HEADER_PREFIX}${key}`] = String(value);
    }
    return headers;
}