forked from WebOfTrust/signify-ts
-
Notifications
You must be signed in to change notification settings - Fork 3
Specify Operation types #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sotatek-Patrick-Vu
wants to merge
6
commits into
feat/common_type_hints
Choose a base branch
from
feat/specify_optypes
base: feat/common_type_hints
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6338ac4
feat: agenting.py type hints and OpenAPI specs
Sotatek-Patrick-Vu 8e3df8e
update TS types after changing End of these files: delegating.py, gro…
Sotatek-Patrick-Vu 1b7511e
fix conflicts + resolve review comments
Sotatek-Patrick-Vu c81a903
fix types for multisig
Sotatek-Patrick-Vu 03c8796
continue fixing Multisig types and update KERIA API schema
Sotatek-Patrick-Vu 37b9c42
Specify Operation types
Sotatek-Patrick-Vu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,8 +3,27 @@ import libsodium from 'libsodium-wrappers-sumo'; | |
| import { Salter } from '../core/salter.ts'; | ||
| import { Matter, MtrDex } from '../core/matter.ts'; | ||
| import { components } from '../../types/keria-api-schema.ts'; | ||
| import { | ||
| OOBIOperation, | ||
| QueryOperation, | ||
| EndRoleOperation, | ||
| WitnessOperation, | ||
| DelegationOperation, | ||
| RegistryOperation, | ||
| LocSchemeOperation, | ||
| ChallengeOperation, | ||
| ExchangeOperation, | ||
| SubmitOperation, | ||
| DoneOperation, | ||
| CredentialOperation, | ||
| GroupOperation, | ||
| DelegatorOperation, | ||
| } from '../core/keyState.ts'; | ||
|
|
||
| type OOBI = components['schemas']['OOBI']; | ||
| type KeyState = components['schemas']['KeyStateRecord']; | ||
| type KeyEventRecord = components['schemas']['KeyEventRecord']; | ||
| type AgentConfig = components['schemas']['AgentConfig']; | ||
|
|
||
| export function randomPasscode(): string { | ||
| const raw = libsodium.randombytes_buf(16); | ||
|
|
@@ -34,7 +53,7 @@ export class Oobis { | |
| * Get the OOBI(s) for a managed indentifier for a given role | ||
| * @param {string} name Name or alias of the identifier | ||
| * @param {string} role Authorized role | ||
| * @returns {Promise<any>} A promise to the OOBI(s) | ||
| * @returns {Promise<OOBI>} A promise to the OOBI(s) | ||
| */ | ||
| async get(name: string, role: string = 'agent'): Promise<OOBI> { | ||
| const path = `/identifiers/${name}/oobis?role=${role}`; | ||
|
|
@@ -48,9 +67,9 @@ export class Oobis { | |
| * @async | ||
| * @param {string} oobi The OOBI to be resolver | ||
| * @param {string} [alias] Optional name or alias to link the OOBI resolution to a contact | ||
| * @returns {Promise<any>} A promise to the long-running operation | ||
| * @returns {Promise<OOBIOperation>} A promise to the long-running operation | ||
| */ | ||
| async resolve(oobi: string, alias?: string): Promise<any> { | ||
| async resolve(oobi: string, alias?: string): Promise<OOBIOperation> { | ||
| const path = `/oobis`; | ||
| const data: any = { | ||
| url: oobi, | ||
|
|
@@ -64,17 +83,21 @@ export class Oobis { | |
| } | ||
| } | ||
|
|
||
| // TODO: the generic will be replaced by specific overrides like IpexOperation | ||
| export type Operation<T = unknown> = Omit< | ||
| components['schemas']['Operation'], | ||
| 'response' | 'metadata' | ||
| > & { | ||
| response?: T; | ||
| metadata?: { | ||
| depends?: Operation; | ||
| [property: string]: any; | ||
| }; | ||
| }; | ||
| export type Operation = | ||
| | OOBIOperation | ||
| | QueryOperation | ||
| | EndRoleOperation | ||
| | WitnessOperation | ||
| | DelegationOperation | ||
| | RegistryOperation | ||
| | LocSchemeOperation | ||
| | ChallengeOperation | ||
| | ExchangeOperation | ||
| | SubmitOperation | ||
| | DoneOperation | ||
| | CredentialOperation | ||
| | GroupOperation | ||
| | DelegatorOperation; | ||
|
|
||
| export interface OperationsDeps { | ||
| fetch( | ||
|
|
@@ -85,10 +108,6 @@ export interface OperationsDeps { | |
| ): Promise<Response>; | ||
| } | ||
|
|
||
| export interface AgentConfig { | ||
| iurls?: string[]; | ||
| } | ||
|
|
||
| /** | ||
| * Operations | ||
| * @remarks | ||
|
|
@@ -110,7 +129,7 @@ export class Operations { | |
| * @param {string} name Name of the operation | ||
| * @returns {Promise<Operation>} A promise to the status of the operation | ||
| */ | ||
| async get<T = unknown>(name: string): Promise<Operation<T>> { | ||
| async get(name: string): Promise<Operation> { | ||
| const path = `/operations/${name}`; | ||
| const data = null; | ||
| const method = 'GET'; | ||
|
|
@@ -123,7 +142,7 @@ export class Operations { | |
| * @param {string} type Select operations by type | ||
| * @returns {Promise<Operation[]>} A list of operations | ||
| */ | ||
| async list(type?: string): Promise<Operation<any>[]> { | ||
| async list(type?: string): Promise<Operation[]> { | ||
| const params = new URLSearchParams(); | ||
| if (type !== undefined) { | ||
| params.append('type', type); | ||
|
|
@@ -149,21 +168,28 @@ export class Operations { | |
| /** | ||
| * Poll for operation to become completed. | ||
| */ | ||
| async wait<T>( | ||
| op: Operation<T>, | ||
| async wait( | ||
| op: Operation, | ||
| options: { | ||
| signal?: AbortSignal; | ||
| minSleep?: number; | ||
| maxSleep?: number; | ||
| increaseFactor?: number; | ||
| } = {} | ||
| ): Promise<Operation<T>> { | ||
| ): Promise<Operation> { | ||
| const minSleep = options.minSleep ?? 10; | ||
| const maxSleep = options.maxSleep ?? 10000; | ||
| const increaseFactor = options.increaseFactor ?? 50; | ||
|
|
||
| if (op.metadata?.depends?.done === false) { | ||
| await this.wait(op.metadata.depends, options); | ||
| if ( | ||
| op.metadata && | ||
| 'depends' in op.metadata && | ||
| op.metadata.depends && | ||
| typeof op.metadata.depends === 'object' && | ||
| 'done' in op.metadata.depends && | ||
| op.metadata.depends.done === false | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see some issues below with depends. |
||
| ) { | ||
| await this.wait(op.metadata.depends as Operation, options); | ||
| } | ||
|
|
||
| if (op.done === true) { | ||
|
|
@@ -208,9 +234,9 @@ export class KeyEvents { | |
| * Retrieve key events for an identifier | ||
| * @async | ||
| * @param {string} pre Identifier prefix | ||
| * @returns {Promise<any>} A promise to the key events | ||
| * @returns {Promise<KeyEventRecord[]>} A promise to the key events | ||
| */ | ||
| async get(pre: string): Promise<any> { | ||
| async get(pre: string): Promise<KeyEventRecord[]> { | ||
| const path = `/events?pre=${pre}`; | ||
| const data = null; | ||
| const method = 'GET'; | ||
|
|
@@ -236,9 +262,9 @@ export class KeyStates { | |
| * Retriene the key state for an identifier | ||
| * @async | ||
| * @param {string} pre Identifier prefix | ||
| * @returns {Promise<any>} A promise to the key states | ||
| * @returns {Promise<KeyState[]>} A promise to the key states | ||
| */ | ||
| async get(pre: string): Promise<any> { | ||
| async get(pre: string): Promise<KeyState[]> { | ||
| const path = `/states?pre=${pre}`; | ||
| const data = null; | ||
| const method = 'GET'; | ||
|
|
@@ -252,7 +278,7 @@ export class KeyStates { | |
| * @param {Array<string>} pres List of identifier prefixes | ||
| * @returns {Promise<any>} A promise to the key states | ||
| */ | ||
| async list(pres: string[]): Promise<any> { | ||
| async list(pres: string[]): Promise<KeyState[]> { | ||
| const path = `/states?${pres.map((pre) => `pre=${pre}`).join('&')}`; | ||
| const data = null; | ||
| const method = 'GET'; | ||
|
|
@@ -266,9 +292,13 @@ export class KeyStates { | |
| * @param {string} pre Identifier prefix | ||
| * @param {number} [sn] Optional sequence number | ||
| * @param {any} [anchor] Optional anchor | ||
| * @returns {Promise<any>} A promise to the long-running operation | ||
| * @returns {Promise<QueryOperation>} A promise to the long-running operation | ||
| */ | ||
| async query(pre: string, sn?: string, anchor?: any): Promise<any> { | ||
| async query( | ||
| pre: string, | ||
| sn?: string, | ||
| anchor?: any | ||
| ): Promise<QueryOperation> { | ||
| const path = `/queries`; | ||
| const data: any = { | ||
| pre: pre, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is very problematic below. Is there any way to determine if we give a particular operation, we get that one back...?
Maybe we need an overload for each operation. Like
wait(op: OOBIOperation, ..): Promise<OOBIOperation>There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to avoid making our lives very very hard in applications that use this library where we need many casts and checks everywhere.