-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyrepo: test with testDataStoreBasic
- Loading branch information
Showing
11 changed files
with
134 additions
and
60 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
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
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
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
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,42 @@ | ||
import { consume, type ConsumerOptions } from "@ndn/endpoint"; | ||
import { type Data, Interest, type Name } from "@ndn/packet"; | ||
|
||
import type * as S from "./data-store"; | ||
|
||
/** Implement DataStore read-side interfaces by sending Interests to the network. */ | ||
export class ReadFromNetwork implements S.Get, S.Find { | ||
constructor(private readonly cOpts?: ConsumerOptions) {} | ||
|
||
public get(name: Name): Promise<Data | undefined> { | ||
return this.find(new Interest(name)); | ||
} | ||
|
||
public async find(interest: Interest): Promise<Data | undefined> { | ||
try { | ||
return await consume(interest, this.cOpts); | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
|
||
/** | ||
* Extend a write-only DataStore with read methods. | ||
* @param inner - Inner DataStore that does not support reading. | ||
* @returns Readable DataStore. | ||
*/ | ||
public mix<T extends {}>(inner: T): T & S.Get & S.Find { | ||
const self = this; // eslint-disable-line unicorn/no-this-assignment, @typescript-eslint/no-this-alias | ||
return new Proxy<any>(inner, { | ||
get(target, prop) { | ||
void target; | ||
switch (prop) { | ||
case "get": | ||
case "find": { | ||
return (self as any)[prop]; | ||
} | ||
} | ||
return (inner as any)[prop]; | ||
}, | ||
}); | ||
} | ||
} |
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