-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
121 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
import { Test } from "@dylibso/xtp-test"; | ||
|
||
export function test() { | ||
let res = Test.callString("processText", "hello world") | ||
Test.assertEqual("processText('hello world') = [5,5]", res, "[5,5]") | ||
const EmbeddedObject = { | ||
aBoolArray: [true, false, true], | ||
aStringArray: ["Hello", "🌍", "World!"], | ||
anEnumArray: ['option1', 'option2', 'option3'], | ||
anIntArray: [1, 2, 3], | ||
} | ||
|
||
res = Test.callString("convertTemperature", "celsius") | ||
let parsed = JSON.parse(res) | ||
Test.assertEqual("convertTemperature.value = 123", parsed.value, 123) | ||
Test.assertEqual("convertTemperature.scale = celsius", parsed.scale, 'celsius') | ||
const KitchenSink = { | ||
aString: "🌍Hello 🌍 World!🌍", | ||
anInt: 42, | ||
aFloat: 3.14, | ||
aDouble: 3.141592653589793238462643383279502884197, | ||
aBool: true, | ||
//anUntypedObject: { hello: 'world' }, TODO uncomment after bug fix | ||
anEnum: 'option1', | ||
anEmbeddedObject: EmbeddedObject, | ||
anEmbeddedObjectArray: [EmbeddedObject, EmbeddedObject] | ||
} | ||
|
||
export function test() { | ||
let input = JSON.stringify(KitchenSink) | ||
let output = JSON.parse(Test.callString("reflectObject", input)) | ||
// assuming if we re-stringify them here the formatting should be the same | ||
Test.assertEqual("reflectObject preserved the KitchenSink", JSON.stringify(output), JSON.stringify(KitchenSink)) | ||
return 0; | ||
} |
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,109 +1,110 @@ | ||
version: v1-draft | ||
exports: | ||
- name: greetUser | ||
- name: reflectObject | ||
description: | | ||
This function greets a user without requiring any input or output. | ||
This function takes a KitchenSinkObject and returns a KitchenSinkObject. | ||
It should come out the same way it came in. | ||
codeSamples: | ||
- lang: typescript | ||
source: | | ||
console.log('Hello User!') | ||
- name: processText | ||
description: | | ||
This function demonstrates how you can handle text input and return | ||
a JSON encoded array of word lengths. | ||
codeSamples: | ||
- lang: typescript | ||
source: | | ||
return input.split(' ').map(c => c.length) | ||
input: | ||
type: string | ||
contentType: text/plain; charset=UTF-8 | ||
description: A plain text string input | ||
output: | ||
type: array | ||
items: | ||
type: integer | ||
contentType: application/json | ||
description: An array of word lengths encoded as JSON | ||
- name: convertTemperature | ||
description: | | ||
This function demonstrates the use of complex parameters. It takes a | ||
TemperatureScale enum and returns a TemperatureReading JSON object. | ||
codeSamples: | ||
- lang: typescript | ||
source: | | ||
return { scale: TemperatureScale.celsius, value: 123 } | ||
// pass this through the host function and return it back | ||
return reflectObjectHost(input) | ||
input: | ||
$ref: "#/schemas/TemperatureScale" | ||
$ref: "#/schemas/KitchenSinkObject" | ||
output: | ||
$ref: "#/schemas/TemperatureReading" | ||
$ref: "#/schemas/KitchenSinkObject" | ||
imports: | ||
- name: logMessage | ||
input: | ||
type: string | ||
contentType: text/plain; charset=UTF-8 | ||
description: The message to log | ||
output: | ||
type: boolean | ||
contentType: application/json | ||
description: Result of the logging operation as a boolean | ||
description: > | ||
This is a host function that logs a message to the system. Host functions | ||
can perform system-level tasks. | ||
- name: databaseRead | ||
description: Reads data from the database using the provided key | ||
- name: reflectObjectHost | ||
description: | | ||
This function takes a KitchenSinkObject and returns a KitchenSinkObject. | ||
It should come out the same way it came in. It's the same as the export. | ||
But the export should call this. | ||
input: | ||
type: string | ||
contentType: text/plain; charset=UTF-8 | ||
description: The key to look up in the database | ||
$ref: "#/schemas/KitchenSinkObject" | ||
output: | ||
type: buffer | ||
description: The raw byte values stored at the key | ||
- name: databaseWrite | ||
description: Writes data to the database | ||
input: | ||
$ref: "#/schemas/DatabaseWriteParams" | ||
$ref: "#/schemas/KitchenSinkObject" | ||
schemas: | ||
- name: DatabaseWriteParams | ||
contentType: application/json | ||
description: Parameters for writing data to the database | ||
- name: EmbeddedObject | ||
description: An embedded object, has some arrays too | ||
required: | ||
- aBoolArray | ||
- anEnumArray | ||
- aStringArray | ||
- anIntArray | ||
properties: | ||
- name: key | ||
type: string | ||
description: The key for the database entry | ||
- name: value | ||
#type: buffer | ||
type: string | ||
description: The value to store at the key | ||
- name: TemperatureScale | ||
description: Different scales of temperature measurement | ||
enum: | ||
- celsius | ||
- fahrenheit | ||
- kelvin | ||
- name: OperationStatus | ||
description: The status of an operation | ||
- name: aBoolArray | ||
description: an array of bools | ||
type: array | ||
items: | ||
type: boolean | ||
- name: aStringArray | ||
description: an array of strings | ||
type: array | ||
items: | ||
type: string | ||
- name: anEnumArray | ||
description: an array of enums | ||
type: array | ||
items: | ||
$ref: "#/schemas/AStringEnum" | ||
- name: anIntArray | ||
description: an array of enums | ||
type: array | ||
items: | ||
type: integer | ||
- name: AStringEnum | ||
description: A string enum | ||
type: string | ||
enum: | ||
- success | ||
- failure | ||
- name: TemperatureReading | ||
- option1 | ||
- option2 | ||
- option3 | ||
- name: KitchenSinkObject | ||
contentType: application/json | ||
description: A JSON object representing a temperature reading | ||
description: A json object with every type of property | ||
required: | ||
- scale | ||
- value | ||
- aString | ||
- anInt | ||
- aFloat | ||
- aDouble | ||
- aBool | ||
- anEnum | ||
- anEmbeddedObject | ||
- anEmbeddedObjectArray | ||
#- anUntypedObject | ||
properties: | ||
- $ref: "#/schemas/TemperatureScale" | ||
name: scale | ||
description: The scale of the temperature reading | ||
- name: value | ||
#type: number | ||
#format: float | ||
type: integer | ||
description: The temperature value | ||
- name: timestamp | ||
- name: anOptionalString | ||
type: string | ||
format: date-time | ||
description: The time when the temperature was recorded | ||
|
||
|
||
description: A string but not required | ||
- name: aString | ||
type: string | ||
description: A String | ||
- name: anInt | ||
type: integer | ||
description: An Integer | ||
- name: aFloat | ||
type: number | ||
format: float | ||
description: A Float | ||
- name: aDouble | ||
type: number | ||
format: double | ||
description: A Double | ||
- name: aBool | ||
type: boolean | ||
description: A Boolean | ||
# TODO put back after bug fix | ||
# - name: anUntypedObject | ||
# type: object | ||
# description: An untyped object | ||
- name: anEnum | ||
description: A string enum (prop comment) | ||
$ref: "#/schemas/AStringEnum" | ||
- name: anEmbeddedObject | ||
description: A embedded object array(prop comment) | ||
$ref: "#/schemas/EmbeddedObject" | ||
- name: anEmbeddedObjectArray | ||
description: A embedded object array (prop comment) | ||
type: array | ||
items: | ||
$ref: "#/schemas/EmbeddedObject" |