-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add compile, build and execute functions
- Loading branch information
Showing
6 changed files
with
73 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import compile from './compile' | ||
import Thing from './Thing' | ||
|
||
/** | ||
* Build a `Thing`. | ||
* | ||
* The `build` function, like the `compile` function is used to prepare a thing | ||
* for execution. However, it usually involves the creation of build artifacts | ||
* (which may take some time to build) that are exernal to the thing | ||
* e.g. a binary executable or Docker image. | ||
* Like `compile`, it may add or modify properties of the thing | ||
* such as providing a URL to the built artifacts. | ||
* | ||
* @param thing The thing to build | ||
* @param format The format of the thing as a MIME type (only applicable when `thing` is a string) | ||
*/ | ||
export default function build (thing: string | object | Thing, format: string = 'application/ld+json'): Thing { | ||
thing = compile(thing, format) | ||
return thing as Thing | ||
} |
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,13 @@ | ||
import import_ from './import' | ||
import Thing from './Thing' | ||
|
||
/** | ||
* Compile a thing | ||
* | ||
* @param thing The thing to compile | ||
* @param format The format of the thing as a MIME type (only applicable when `thing` is a string) | ||
*/ | ||
export default function compile (thing: string | object | Thing, format: string = 'application/ld+json'): Thing { | ||
thing = import_(thing, format) | ||
return thing as Thing | ||
} |
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,13 @@ | ||
import build from './build' | ||
import Thing from './Thing' | ||
|
||
/** | ||
* Execute a thing | ||
* | ||
* @param thing The thing to execute | ||
* @param format The format of the thing as a MIME type (only applicable when `thing` is a string) | ||
*/ | ||
export default function execute (thing: string | object | Thing, format: string= 'application/ld+json'): Thing { | ||
thing = build(thing, format) | ||
return thing as Thing | ||
} |
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,9 @@ | ||
import build from '../src/build' | ||
import Thing from '../src/Thing' | ||
|
||
test('build:Thing', () => { | ||
const thing = new Thing() | ||
expect(build('{"type": "Thing"}')).toEqual(thing) | ||
expect(build({type: 'Thing'})).toEqual(thing) | ||
expect(build(thing)).toEqual(thing) | ||
}) |
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,9 @@ | ||
import compile from '../src/compile' | ||
import Thing from '../src/Thing' | ||
|
||
test('compile:Thing', () => { | ||
const thing = new Thing() | ||
expect(compile('{"type": "Thing"}')).toEqual(thing) | ||
expect(compile({type: 'Thing'})).toEqual(thing) | ||
expect(compile(thing)).toEqual(thing) | ||
}) |
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,9 @@ | ||
import execute from '../src/execute' | ||
import Thing from '../src/Thing' | ||
|
||
test('execute:Thing', () => { | ||
const thing = new Thing() | ||
expect(execute('{"type": "Thing"}')).toEqual(thing) | ||
expect(execute({type: 'Thing'})).toEqual(thing) | ||
expect(execute(thing)).toEqual(thing) | ||
}) |