Skip to content

Commit

Permalink
Merge pull request #703 from OpenFn/release/next
Browse files Browse the repository at this point in the history
release apollo
  • Loading branch information
josephjclark authored May 28, 2024
2 parents 4dafcb2 + cc0effc commit dc117fb
Show file tree
Hide file tree
Showing 17 changed files with 952 additions and 124 deletions.
5 changes: 4 additions & 1 deletion integration-tests/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"files": [
"dist",
"README.md"
]
],
"devDependencies": {
"@types/koa": "^2.15.0"
}
}
10 changes: 10 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @openfn/cli

## 1.3.0

### Minor Changes

- 015055c: Add first pass of apollo command. Call an apollo service with `openfn apollo <service-name>`. For basic help run `openfn apollo --help`. For available services see the server index page. This first release is a super basic integration with log streaming through websockets and reasonably intelligent handling of `{ files }` result data.

### Patch Changes

- deploy: Improved error messages from local validation

## 1.2.5

### Patch Changes
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.2.5",
"version": "1.3.0",
"description": "CLI devtools for the openfn toolchain.",
"engines": {
"node": ">=18",
Expand Down Expand Up @@ -39,6 +39,7 @@
"@types/node": "^18.15.13",
"@types/rimraf": "^3.0.2",
"@types/treeify": "^1.0.0",
"@types/ws": "^8.5.10",
"@types/yargs": "^17.0.24",
"ava": "5.3.1",
"mock-fs": "^5.1.4",
Expand All @@ -58,6 +59,7 @@
"figures": "^5.0.0",
"rimraf": "^3.0.2",
"treeify": "^1.1.0",
"ws": "^8.14.1",
"yargs": "^17.7.2"
},
"files": [
Expand Down
189 changes: 189 additions & 0 deletions packages/cli/src/apollo/cat-facts.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"api_key": "YOUR_OPENAI_KEY_HERE",
"endpoint": "/facts",
"model": "gpt3_turbo",
"open_api_spec": {
"openapi": "3.0.0",
"info": {
"title": "Cat Facts API",
"version": "1.0"
},
"paths": {
"/breeds": {
"get": {
"tags": ["Breeds"],
"summary": "Get a list of breeds",
"description": "Returns a a list of breeds",
"operationId": "getBreeds",
"parameters": [
{
"name": "limit",
"in": "query",
"description": "limit the amount of results returned",
"required": false,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Breed"
}
}
}
}
}
}
}
},
"/fact": {
"get": {
"tags": ["Facts"],
"summary": "Get Random Fact",
"description": "Returns a random fact",
"operationId": "getRandomFact",
"parameters": [
{
"name": "max_length",
"in": "query",
"description": "maximum length of returned fact",
"required": false,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CatFact"
}
}
}
},
"404": {
"description": "Fact not found"
}
}
}
},
"/facts": {
"get": {
"tags": ["Facts"],
"summary": "Get a list of facts",
"description": "Returns a a list of facts",
"operationId": "getFacts",
"parameters": [
{
"name": "max_length",
"in": "query",
"description": "maximum length of returned fact",
"required": false,
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "limit",
"in": "query",
"description": "limit the amount of results returned",
"required": false,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CatFact"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Breed": {
"title": "Breed model",
"description": "Breed",
"properties": {
"breed": {
"title": "Breed",
"description": "Breed",
"type": "string",
"format": "string"
},
"country": {
"title": "Country",
"description": "Country",
"type": "string",
"format": "string"
},
"origin": {
"title": "Origin",
"description": "Origin",
"type": "string",
"format": "string"
},
"coat": {
"title": "Coat",
"description": "Coat",
"type": "string",
"format": "string"
},
"pattern": {
"title": "Pattern",
"description": "Pattern",
"type": "string",
"format": "string"
}
},
"type": "object"
},
"CatFact": {
"title": "CatFact model",
"description": "CatFact",
"properties": {
"fact": {
"title": "Fact",
"description": "Fact",
"type": "string",
"format": "string"
},
"length": {
"title": "Length",
"description": "Length",
"type": "integer",
"format": "int32"
}
},
"type": "object"
}
}
}
}
}
42 changes: 42 additions & 0 deletions packages/cli/src/apollo/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import yargs from 'yargs';
import * as o from '../options';
import type { Opts } from '../options';
import { build, ensure, override } from '../util/command-builders';
import { STAGING_URL } from './util';

export type ApolloOptions = Pick<
Opts,
'stateStdin' | 'log' | 'logJson' | 'apolloUrl' | 'outputPath' | 'outputStdout'
> & {
service: string;
payload?: string;
};

const options = [
o.apolloUrl,
o.stateStdin,
o.log,
o.logJson,
o.outputPath,
override(o.outputStdout, {
default: true,
}),
];

const desc = `Call services on the openfn apollo server. Set the local server location with OPENFN_APOLLO_SERVER. The staging server is set to ${STAGING_URL}`;

export default {
command: 'apollo <service> [payload]',
desc,
handler: ensure('apollo', options),
builder: (yargs) =>
build(options, yargs)
.example(
'apollo echo path/to/json',
'Call the echo service, which returns json back'
)
.example(
'apollo adaptor_gen cat-facts.example.json --local',
'Generate an adaptor template against a local server'
),
} as yargs.CommandModule<{}>;
Loading

0 comments on commit dc117fb

Please sign in to comment.