/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { grpc } from "@improbable-eng/grpc-web";
export function requestUnary(caller) {
    return new Promise((resolve, reject) => {
        caller((err, res) => {
            if (err != null) {
                reject(err);
            }
            else if (res != null) {
                resolve(res);
            }
            else {
                reject(new Error('Invalid gRPC response. Error and result are empty.'));
            }
        });
    });
}
export async function* requestPaged(fetch, next) {
    let cursor = undefined;
    do {
        const res = await requestUnary(fetch(cursor));
        yield res;
        cursor = next(res);
    } while (cursor != null);
}
export async function createMetadata(jwtProvider, deviceId) {
    const jwt = await jwtProvider();
    const meta = new grpc.Metadata({
        'jwt-context': JSON.stringify({
            jwt,
            metadata: { 'x-device-id': deviceId || '' },
        }),
    });
    return meta;
}
//# sourceMappingURL=grpc.js.map
