-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add TEMPORARY TERRIBLE functionality
- Loading branch information
1 parent
e30a7f8
commit 492be03
Showing
11 changed files
with
104 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
MapDocumentNode, | ||
ProfileDocumentNode, | ||
} from '@superindustries/language'; | ||
|
||
import { Result } from '..'; | ||
import { Variables } from '../internal/interpreter/interfaces'; | ||
import { MapInterpereter } from '../internal/interpreter/map-interpreter'; | ||
import { err, ok } from '../lib'; | ||
import { Config } from './config'; | ||
|
||
// TODO: Create Profile walker for validation of result | ||
export const mapResult = <TResult>( | ||
_profileAST: ProfileDocumentNode, | ||
result?: string | Variables | ||
): TResult => { | ||
return (result as unknown) as TResult; | ||
}; | ||
|
||
export class BoundProvider { | ||
constructor( | ||
private readonly config: Config, | ||
private readonly profileAST: ProfileDocumentNode, | ||
private readonly mapAST: MapDocumentNode | ||
) {} | ||
|
||
async perform<TResult, TError>( | ||
usecase: string, | ||
input?: Variables | ||
): Promise<Result<TResult, TError>> { | ||
try { | ||
const interpreter = new MapInterpereter({ | ||
usecase, | ||
auth: this.config.auth, | ||
input, | ||
}); | ||
|
||
const result = await interpreter.visit(this.mapAST); | ||
const mappedResult = mapResult<TResult>(this.profileAST, result); | ||
|
||
return ok(mappedResult); | ||
} catch (e) { | ||
return err(e); | ||
} | ||
} | ||
} | ||
|
||
export class Provider { | ||
constructor( | ||
private readonly config: Config, | ||
private readonly profileAST: ProfileDocumentNode | ||
) {} | ||
|
||
public async bind(mapAST?: MapDocumentNode): Promise<BoundProvider> { | ||
if (!mapAST) { | ||
throw new Error('Method not implemented'); | ||
} | ||
|
||
return new BoundProvider(this.config, this.profileAST, mapAST); | ||
} | ||
} |
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,18 @@ | ||
import { Config } from './config'; | ||
import { Provider } from './Provider'; | ||
import { Query } from './query'; | ||
|
||
export class SuperfaceClient { | ||
constructor(private readonly config: Config) {} | ||
|
||
public async findProviders( | ||
_profileIds: string | string[], | ||
query: Query | ||
): Promise<Provider[]> { | ||
if (!query.ast) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
return [new Provider(this.config, query.ast.profileAST)]; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export interface Config { | ||
credentials?: { | ||
auth?: { | ||
basic?: { | ||
username: string; | ||
password: string; | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './config'; | ||
export * from './interfaces'; | ||
export * from './query'; | ||
export * from './Provider'; | ||
export * from './SuperfaceClient'; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './client'; | ||
export * from './interfaces'; | ||
// export * from './interfaces'; | ||
export * from './lib'; |
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