1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-05 19:23:19 +00:00

feat: working non-async iterator

This commit is contained in:
Andreas Coroiu
2025-08-11 09:39:34 +02:00
parent 01d95f325f
commit b15648fec6

View File

@@ -12,6 +12,7 @@ import {
of,
takeWhile,
throwIfEmpty,
firstValueFrom,
} from "rxjs";
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
@@ -20,6 +21,7 @@ import { KeyService, KdfConfigService, KdfConfig, KdfType } from "@bitwarden/key
import {
BitwardenClient,
ClientSettings,
JsRustIterator,
DeviceType as SdkDeviceType,
TokenProvider,
UnsignedSharedKey,
@@ -82,7 +84,46 @@ export class DefaultSdkService implements SdkService {
private kdfConfigService: KdfConfigService,
private keyService: KeyService,
private userAgent: string | null = null,
) {}
) {
(window as any).sdkService = this; // Expose the service to the global window object for debugging purposes
}
async testIterator() {
const client = await firstValueFrom(this.client$);
class JsAsyncIterator implements AsyncIterator<number> {
constructor(private iterator: JsRustIterator) {}
}
class JsIterator implements Iterator<number> {
constructor(private iterator: JsRustIterator) {}
next(): IteratorResult<number, any> {
const nextValue = this.iterator.next();
if (nextValue === undefined) {
return { value: undefined, done: true };
}
return { value: nextValue };
}
}
class JsIterable implements Iterable<number | undefined> {
constructor(private iterator: JsRustIterator) {}
[Symbol.iterator]() {
return new JsIterator(this.iterator);
}
}
const rustIterator = client.platform().iter().create_js_iterator();
const iterable = new JsIterable(rustIterator);
for (const value of iterable) {
// eslint-disable-next-line no-console
console.log("Iterable value: ", value);
}
}
userClient$(userId: UserId): Observable<Rc<BitwardenClient>> {
return this.sdkClientOverrides.pipe(