Change build setup of JS clients, reintroduce beta publishing after losing it due to unmerged code (#238)

This commit is contained in:
Janos Dobronszki
2021-10-22 09:49:47 +01:00
committed by GitHub
parent 7cc2a86d0f
commit 293d5ecdde
140 changed files with 13946 additions and 643 deletions

View File

@@ -60,8 +60,10 @@ jobs:
go run cmd/publisher/main.go .
env:
MICRO_ADMIN_TOKEN: ${{ secrets.MICRO_ADMIN_TOKEN }}
- name: Generate package
working-directory: services
if: github.ref == 'refs/heads/master'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
@@ -70,6 +72,19 @@ jobs:
go install;
cd ../..;
clients .
- name: Generate beta package
working-directory: services
if: github.ref == 'refs/heads/beta'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
IS_BETA: yup
run: |
pwd
cd cmd/clients;
go install;
cd ../..;
clients .
- uses: EndBug/add-and-commit@v7
with:
@@ -84,3 +99,13 @@ jobs:
npm install
npm run build
npm publish --access public
- name: npm install beta
working-directory: services
if: github.ref == 'refs/heads/beta'
run: |
git status
cd clients/ts;
npm install
npm run build
npm publish --access public --tag beta

53
clients/ts/.gitignore vendored
View File

@@ -1 +1,54 @@
node_modules
dist
es
lib
types
tmp
index.js
index.d.ts
esmesm
index.js
index.d.ts
address
answer
cache
cmd
crypto
currency
db
email
emoji
evchargers
file
forex
function
geocoding
gifs
helloworld
holidays
id
image
ip
location
notes
otp
pkg
postcode
prayer
qr
quran
routing
rss
sentiment
sms
stock
stream
sunnah
test
thumbnail
time
twitter
url
user
vehicle
weather

91
clients/ts/build.js Normal file
View File

@@ -0,0 +1,91 @@
const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const { ncp } = require('ncp');
function getTmpEsmDirectories() {
return fs
.readdirSync('./tmp/esm')
.filter(file => fs.statSync(`./tmp/esm/${file}`).isDirectory());
}
function log(text) {
console.log(`${chalk.cyan('M3O JS:')} ${text}`);
}
function writeModulePackageJsonFile(location) {
fs.writeFileSync(
`${location}/package.json`,
`{"module": "./esm/index.js"}`,
'utf8'
);
}
function deleteDirectory(directory) {
return new Promise(resolve => {
rimraf(directory, err => {
resolve();
});
});
}
function copyAllTmpFolders() {
return new Promise((resolve, reject) => {
// Now copy to root level
ncp(path.join(__dirname, 'tmp'), __dirname, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
function moveToLocalEsmFolders() {
return new Promise((resolve, reject) => {
const esmDirs = getTmpEsmDirectories();
// Move the files around in tmp...
esmDirs.forEach(dir => {
const currentPath = path.join(__dirname, 'tmp/esm', dir);
fs.readdirSync(currentPath).forEach(async file => {
const currentFilePath = path.join(currentPath, file);
const newFilePath = path.join(__dirname, 'tmp', dir, 'esm', file);
const esmFolderLocation = path.join(__dirname, 'tmp', dir, 'esm');
try {
if (!fs.existsSync(esmFolderLocation)) {
fs.mkdirSync(esmFolderLocation);
}
fs.renameSync(currentFilePath, newFilePath);
writeModulePackageJsonFile(`./tmp/${dir}`);
await deleteDirectory(`./tmp/esm/${dir}`);
} catch (err) {
reject(err);
}
});
});
log('Moved local esm folders');
resolve();
});
}
async function build() {
log('Moving to correct folders');
try {
await moveToLocalEsmFolders();
await copyAllTmpFolders();
writeModulePackageJsonFile('./tmp/esm');
await deleteDirectory('./tmp');
} catch (e) {
console.log(e);
}
}
build();

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +1,78 @@
{
"author": "",
"dependencies": {
"@m3o/m3o-node": "^0.0.24"
"@m3o/m3o-node": "^0.0.24",
"@types/estree": "^0.0.47",
"chalk": "^2.4.2",
"move-file": "^3.0.0",
"ncp": "^2.0.0",
"rimraf": "^3.0.2"
},
"description": "",
"devDependencies": {
"prettier": "^2.4.1",
"typescript": "^3.5.1"
},
"exports": {
"./address": "./dist/address/index.js",
"./answer": "./dist/answer/index.js",
"./cache": "./dist/cache/index.js",
"./cmd": "./dist/cmd/index.js",
"./crypto": "./dist/crypto/index.js",
"./currency": "./dist/currency/index.js",
"./db": "./dist/db/index.js",
"./email": "./dist/email/index.js",
"./emoji": "./dist/emoji/index.js",
"./evchargers": "./dist/evchargers/index.js",
"./file": "./dist/file/index.js",
"./forex": "./dist/forex/index.js",
"./function": "./dist/function/index.js",
"./geocoding": "./dist/geocoding/index.js",
"./gifs": "./dist/gifs/index.js",
"./helloworld": "./dist/helloworld/index.js",
"./holidays": "./dist/holidays/index.js",
"./id": "./dist/id/index.js",
"./image": "./dist/image/index.js",
"./ip": "./dist/ip/index.js",
"./location": "./dist/location/index.js",
"./notes": "./dist/notes/index.js",
"./otp": "./dist/otp/index.js",
"./pkg": "./dist/pkg/index.js",
"./postcode": "./dist/postcode/index.js",
"./prayer": "./dist/prayer/index.js",
"./qr": "./dist/qr/index.js",
"./quran": "./dist/quran/index.js",
"./routing": "./dist/routing/index.js",
"./rss": "./dist/rss/index.js",
"./sentiment": "./dist/sentiment/index.js",
"./sms": "./dist/sms/index.js",
"./stock": "./dist/stock/index.js",
"./stream": "./dist/stream/index.js",
"./sunnah": "./dist/sunnah/index.js",
"./test": "./dist/test/index.js",
"./thumbnail": "./dist/thumbnail/index.js",
"./time": "./dist/time/index.js",
"./twitter": "./dist/twitter/index.js",
"./url": "./dist/url/index.js",
"./user": "./dist/user/index.js",
"./vehicle": "./dist/vehicle/index.js",
"./weather": "./dist/weather/index.js"
},
"files": [
"esm",
"index.js",
"index.d.ts",
"address",
"answer",
"cache",
"cmd",
"crypto",
"currency",
"db",
"email",
"emoji",
"evchargers",
"file",
"forex",
"function",
"geocoding",
"gifs",
"helloworld",
"holidays",
"id",
"image",
"ip",
"location",
"notes",
"otp",
"pkg",
"postcode",
"prayer",
"qr",
"quran",
"routing",
"rss",
"sentiment",
"sms",
"stock",
"stream",
"sunnah",
"test",
"thumbnail",
"time",
"twitter",
"url",
"user",
"vehicle",
"weather"
],
"license": "ISC",
"main": "dist",
"main": "index.js",
"module": "esm/index.js",
"name": "m3o",
"repository": {
"type": "git",
"url": "https://github.com/micro/services"
},
"scripts": {
"build": "tsc",
"prepare": "npm run build",
"test": "echo \"Error: no test specified\" \u0026\u0026 exit 1"
"build": "npm run clean \u0026\u0026 tsc \u0026\u0026 tsc --p tsconfig.es.json \u0026\u0026 node build.js",
"clean": "rimraf ./tmp",
"prepare": "npm run build"
},
"type": "module",
"types": "dist/index.d.ts",
"version": "1.0.555"
"types": "index.d.ts",
"version": "1.0.556-beta3"
}

View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "ES2015",
"target": "ES6",
"declaration": true,
"lib": ["es2015", "dom"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "./tmp/esm",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": ["src/index.ts", "src/**/*"],
"exclude": ["./dist", "./node_modules"]
}

View File

@@ -1,16 +1,16 @@
{
"compilerOptions": {
"module": "es6",
"module": "CommonJS",
"target": "es5",
"declaration": true,
"lib": ["es2015", "dom"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "./dist",
"outDir": "./tmp",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": ["index.ts", "./*"],
"exclude": ["src/**/*.spec.*", "./dist", "./node_modules"]
"include": ["src/index.ts", "src/**/*"],
"exclude": ["./dist", "./node_modules"]
}

View File

@@ -6,9 +6,36 @@ import (
"strings"
"testing"
"github.com/Masterminds/semver/v3"
"github.com/getkin/kin-openapi/openapi3"
)
func TestSemver(t *testing.T) {
v, _ := semver.NewVersion("0.0.0-beta1")
if incBeta(*v).String() != "0.0.0-beta2" {
t.Fatal(v)
}
v1, _ := semver.NewVersion("0.0.1")
if !v1.GreaterThan(v) {
t.Fatal("no good")
}
v2, _ := semver.NewVersion("0.0.0")
if !v2.GreaterThan(v) {
t.Fatal("no good")
}
if v.String() != "0.0.0-beta1" {
t.Fatal("no good")
}
v3, _ := semver.NewVersion("0.0.0-beta2")
if !v3.GreaterThan(v) {
t.Fatal("no good")
}
}
type tspec struct {
openapi string
tsresult string

View File

@@ -13,6 +13,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"text/template"
@@ -110,15 +111,14 @@ func main() {
},
}
services := []service{}
tsExportsMap := map[string]string{}
tsFileList := []string{"esm", "index.js", "index.d.ts"}
for _, f := range files {
if strings.Contains(f.Name(), "clients") || strings.Contains(f.Name(), "examples") {
continue
}
if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
serviceName := f.Name()
// see https://stackoverflow.com/questions/44345257/import-from-subfolder-of-npm-package
tsExportsMap["./"+serviceName] = "./dist/" + serviceName + "/index.js"
tsFileList = append(tsFileList, serviceName)
serviceDir := filepath.Join(workDir, f.Name())
cmd := exec.Command("make", "api")
cmd.Dir = serviceDir
@@ -187,12 +187,12 @@ func main() {
os.Exit(1)
}
err = os.MkdirAll(filepath.Join(tsPath, serviceName), 0777)
err = os.MkdirAll(filepath.Join(tsPath, "src", serviceName), 0777)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
f, err := os.OpenFile(filepath.Join(tsPath, serviceName, "index.ts"), os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
f, err := os.OpenFile(filepath.Join(tsPath, "src", serviceName, "index.ts"), os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0744)
if err != nil {
fmt.Println("Failed to open schema file", err)
os.Exit(1)
@@ -204,7 +204,7 @@ func main() {
os.Exit(1)
}
cmd = exec.Command("prettier", "-w", "index.ts")
cmd.Dir = filepath.Join(tsPath, serviceName)
cmd.Dir = filepath.Join(tsPath, "src", serviceName)
outp, err = cmd.CombinedOutput()
if err != nil {
fmt.Println(fmt.Sprintf("Problem formatting '%v' client: %v %s", serviceName, string(outp), err.Error()))
@@ -449,7 +449,7 @@ func main() {
os.Exit(1)
}
tsFiles := filepath.Join(workDir, "cmd", "clients", "ts")
cmd = exec.Command("cp", filepath.Join(tsFiles, "package.json"), filepath.Join(tsFiles, ".gitignore"), filepath.Join(tsFiles, "package-lock.json"), filepath.Join(tsFiles, "tsconfig.json"), filepath.Join(workDir, "clients", "ts"))
cmd = exec.Command("cp", filepath.Join(tsFiles, "package.json"), filepath.Join(tsFiles, ".gitignore"), filepath.Join(tsFiles, "package-lock.json"), filepath.Join(tsFiles, "package-lock.json"), filepath.Join(tsFiles, "build.js"), filepath.Join(tsFiles, "tsconfig.es.json"), filepath.Join(tsFiles, "package-lock.json"), filepath.Join(tsFiles, "tsconfig.json"), filepath.Join(workDir, "clients", "ts"))
cmd.Dir = filepath.Join(tsPath)
outp, err = cmd.CombinedOutput()
if err != nil {
@@ -526,6 +526,14 @@ func main() {
type npmVers struct {
Versions []string `json:"versions"`
}
beta := os.Getenv("IS_BETA") != ""
if beta {
fmt.Println("creating beta version")
} else {
fmt.Println("creating live version")
}
npmOutput := &npmVers{}
var latest *semver.Version
if len(outp) > 0 {
@@ -535,6 +543,7 @@ func main() {
os.Exit(1)
}
}
fmt.Println("npm output version: ", npmOutput.Versions)
for _, version := range npmOutput.Versions {
v, err := semver.NewVersion(version)
@@ -548,11 +557,37 @@ func main() {
if v.GreaterThan(latest) {
latest = v
}
}
if latest == nil {
latest, _ = semver.NewVersion("0.0.0")
fmt.Println("found no semver version")
os.Exit(1)
}
var newV semver.Version
if beta {
// bump a beta version
if strings.Contains(latest.String(), "beta") {
newV = incBeta(*latest)
} else {
// make beta out of latest non beta version
v, _ := semver.NewVersion(latest.IncPatch().String() + "-beta1")
newV = *v
}
} else {
newV = latest.IncPatch()
}
// add file list to gitignore
f, err = os.OpenFile(filepath.Join(tsPath, ".gitignore"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0744)
for _, sname := range tsFileList {
_, err := f.Write([]byte(sname + "\n"))
if err != nil {
fmt.Println("failed to append service to gitignore", err)
os.Exit(1)
}
}
newV := latest.IncPatch()
// bump package to latest version
fmt.Println("Bumping to ", newV.String())
@@ -576,7 +611,7 @@ func main() {
fmt.Println(err)
os.Exit(1)
}
m["exports"] = tsExportsMap
m["files"] = tsFileList
pakJS, err := json.MarshalIndent(m, "", " ")
if err != nil {
fmt.Println(err)
@@ -594,6 +629,24 @@ func main() {
}
}
func incBeta(ver semver.Version) semver.Version {
s := ver.String()
parts := strings.Split(s, "beta")
if len(parts) < 2 {
panic("not a beta version " + s)
}
i, err := strconv.ParseInt(parts[1], 10, 64)
if err != nil {
panic(err)
}
i++
v, err := semver.NewVersion(parts[0] + "beta" + fmt.Sprintf("%v", i))
if err != nil {
panic(err)
}
return *v
}
func schemaToType(language, serviceName, typeName string, schemas map[string]*openapi3.SchemaRef) string {
var recurse func(props map[string]*openapi3.SchemaRef, level int) string

View File

@@ -1 +1,9 @@
node_modules
dist
es
lib
types
tmp
index.js
index.d.ts
esm

91
cmd/clients/ts/build.js Normal file
View File

@@ -0,0 +1,91 @@
const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const { ncp } = require('ncp');
function getTmpEsmDirectories() {
return fs
.readdirSync('./tmp/esm')
.filter(file => fs.statSync(`./tmp/esm/${file}`).isDirectory());
}
function log(text) {
console.log(`${chalk.cyan('M3O JS:')} ${text}`);
}
function writeModulePackageJsonFile(location) {
fs.writeFileSync(
`${location}/package.json`,
`{"module": "./esm/index.js"}`,
'utf8'
);
}
function deleteDirectory(directory) {
return new Promise(resolve => {
rimraf(directory, err => {
resolve();
});
});
}
function copyAllTmpFolders() {
return new Promise((resolve, reject) => {
// Now copy to root level
ncp(path.join(__dirname, 'tmp'), __dirname, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
function moveToLocalEsmFolders() {
return new Promise((resolve, reject) => {
const esmDirs = getTmpEsmDirectories();
// Move the files around in tmp...
esmDirs.forEach(dir => {
const currentPath = path.join(__dirname, 'tmp/esm', dir);
fs.readdirSync(currentPath).forEach(async file => {
const currentFilePath = path.join(currentPath, file);
const newFilePath = path.join(__dirname, 'tmp', dir, 'esm', file);
const esmFolderLocation = path.join(__dirname, 'tmp', dir, 'esm');
try {
if (!fs.existsSync(esmFolderLocation)) {
fs.mkdirSync(esmFolderLocation);
}
fs.renameSync(currentFilePath, newFilePath);
writeModulePackageJsonFile(`./tmp/${dir}`);
await deleteDirectory(`./tmp/esm/${dir}`);
} catch (err) {
reject(err);
}
});
});
log('Moved local esm folders');
resolve();
});
}
async function build() {
log('Moving to correct folders');
try {
await moveToLocalEsmFolders();
await copyAllTmpFolders();
writeModulePackageJsonFile('./tmp/esm');
await deleteDirectory('./tmp');
} catch (e) {
console.log(e);
}
}
build();

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,31 @@
{
"name": "m3o",
"version": "1.0.1",
"description": "",
"main": "dist",
"types": "dist/index.d.ts",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/micro/services"
},
"author": "",
"license": "ISC",
"scripts": {
"build": "tsc",
"prepare": "npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"typescript": "^3.5.1"
},
"dependencies": {
"@m3o/m3o-node": "^0.0.24"
},
"exports": {}
"name": "m3o",
"version": "1.0.1",
"types": "index.d.ts",
"main": "index.js",
"module": "esm/index.js",
"files": [],
"repository": {
"type": "git",
"url": "https://github.com/micro/services"
},
"author": "",
"license": "ISC",
"scripts": {
"clean": "rimraf ./tmp",
"build": "npm run clean && tsc && tsc --p tsconfig.es.json && node build.js",
"prepare": "npm run build"
},
"dependencies": {
"@m3o/m3o-node": "^0.0.24",
"@types/estree": "^0.0.47",
"chalk": "^2.4.2",
"move-file": "^3.0.0",
"ncp": "^2.0.0",
"rimraf": "^3.0.2"
},
"devDependencies": {
"prettier": "^2.4.1",
"typescript": "^3.5.1"
}
}

View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "ES2015",
"target": "ES6",
"declaration": true,
"lib": ["es2015", "dom"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "./tmp/esm",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": ["src/index.ts", "src/**/*"],
"exclude": ["./dist", "./node_modules"]
}

View File

@@ -1,16 +1,16 @@
{
"compilerOptions": {
"module": "es6",
"module": "CommonJS",
"target": "es5",
"declaration": true,
"lib": ["es2015", "dom"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "./dist",
"outDir": "./tmp",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": ["index.ts", "./*"],
"exclude": ["src/**/*.spec.*", "./dist", "./node_modules"]
"include": ["src/index.ts", "src/**/*"],
"exclude": ["./dist", "./node_modules"]
}

View File

@@ -35,12 +35,12 @@ export interface {{ title $typeName }}{{ "{" }}
{{end}}
`
const tsExampleTemplate = `{{ $service := .service }}import * as {{ $service.ImportName }} from 'm3o/{{ $service.Name }}';
const tsExampleTemplate = `{{ $service := .service }}const { {{ title $service.Name }}Service } = require('m3o/{{ $service.Name }}');
{{ if endpointComment .endpoint $service.Spec.Components.Schemas }}{{ endpointComment .endpoint $service.Spec.Components.Schemas }}{{ end }}async function {{ .funcName }}() {
let {{ $service.Name }}Service = new {{ $service.ImportName }}.{{ title $service.Name }}Service(process.env.MICRO_API_TOKEN)
{{ if endpointComment .endpoint $service.Spec.Components.Schemas }}{{ endpointComment .endpoint $service.Spec.Components.Schemas }}{{ end }}async function {{ untitle .funcName }}() {
let {{ $service.Name }}Service = new {{ title $service.Name }}Service(process.env.MICRO_API_TOKEN)
let rsp = await {{ $service.Name }}Service.{{ .endpoint }}({{ tsExampleRequest $service.Name .endpoint $service.Spec.Components.Schemas .example.Request }})
console.log(rsp)
}
await {{ .funcName }}()`
{{ untitle .funcName }}()`

View File

@@ -1,12 +1,12 @@
import * as address from "m3o/address";
const { AddressService } = require("m3o/address");
// Lookup a list of UK addresses by postcode
async function LookupPostcode() {
let addressService = new address.AddressService(process.env.MICRO_API_TOKEN);
async function lookupPostcode() {
let addressService = new AddressService(process.env.MICRO_API_TOKEN);
let rsp = await addressService.lookupPostcode({
postcode: "SW1A 2AA",
});
console.log(rsp);
}
await LookupPostcode();
lookupPostcode();

View File

@@ -1,12 +1,12 @@
import * as answer from "m3o/answer";
const { AnswerService } = require("m3o/answer");
// Ask a question and receive an instant answer
async function AskAquestion() {
let answerService = new answer.AnswerService(process.env.MICRO_API_TOKEN);
async function askAquestion() {
let answerService = new AnswerService(process.env.MICRO_API_TOKEN);
let rsp = await answerService.question({
query: "microsoft",
});
console.log(rsp);
}
await AskAquestion();
askAquestion();

View File

@@ -1,8 +1,8 @@
import * as cache from "m3o/cache";
const { CacheService } = require("m3o/cache");
// Decrement a value (if it's a number)
async function DecrementAvalue() {
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
async function decrementAvalue() {
let cacheService = new CacheService(process.env.MICRO_API_TOKEN);
let rsp = await cacheService.decrement({
key: "counter",
value: 2,
@@ -10,4 +10,4 @@ async function DecrementAvalue() {
console.log(rsp);
}
await DecrementAvalue();
decrementAvalue();

View File

@@ -1,12 +1,12 @@
import * as cache from "m3o/cache";
const { CacheService } = require("m3o/cache");
// Delete a value from the cache
async function DeleteAvalue() {
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
async function deleteAvalue() {
let cacheService = new CacheService(process.env.MICRO_API_TOKEN);
let rsp = await cacheService.delete({
key: "foo",
});
console.log(rsp);
}
await DeleteAvalue();
deleteAvalue();

View File

@@ -1,12 +1,12 @@
import * as cache from "m3o/cache";
const { CacheService } = require("m3o/cache");
// Get an item from the cache by key
async function GetAvalue() {
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
async function getAvalue() {
let cacheService = new CacheService(process.env.MICRO_API_TOKEN);
let rsp = await cacheService.get({
key: "foo",
});
console.log(rsp);
}
await GetAvalue();
getAvalue();

View File

@@ -1,8 +1,8 @@
import * as cache from "m3o/cache";
const { CacheService } = require("m3o/cache");
// Increment a value (if it's a number)
async function IncrementAvalue() {
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
async function incrementAvalue() {
let cacheService = new CacheService(process.env.MICRO_API_TOKEN);
let rsp = await cacheService.increment({
key: "counter",
value: 2,
@@ -10,4 +10,4 @@ async function IncrementAvalue() {
console.log(rsp);
}
await IncrementAvalue();
incrementAvalue();

View File

@@ -1,8 +1,8 @@
import * as cache from "m3o/cache";
const { CacheService } = require("m3o/cache");
// Set an item in the cache. Overwrites any existing value already set.
async function SetAvalue() {
let cacheService = new cache.CacheService(process.env.MICRO_API_TOKEN);
async function setAvalue() {
let cacheService = new CacheService(process.env.MICRO_API_TOKEN);
let rsp = await cacheService.set({
key: "foo",
value: "bar",
@@ -10,4 +10,4 @@ async function SetAvalue() {
console.log(rsp);
}
await SetAvalue();
setAvalue();

View File

@@ -1,12 +1,12 @@
import * as crypto from "m3o/crypto";
const { CryptoService } = require("m3o/crypto");
// Returns the history for the previous close
async function GetPreviousClose() {
let cryptoService = new crypto.CryptoService(process.env.MICRO_API_TOKEN);
async function getPreviousClose() {
let cryptoService = new CryptoService(process.env.MICRO_API_TOKEN);
let rsp = await cryptoService.history({
symbol: "BTCUSD",
});
console.log(rsp);
}
await GetPreviousClose();
getPreviousClose();

View File

@@ -1,12 +1,12 @@
import * as crypto from "m3o/crypto";
const { CryptoService } = require("m3o/crypto");
// Get news related to a currency
async function GetCryptocurrencyNews() {
let cryptoService = new crypto.CryptoService(process.env.MICRO_API_TOKEN);
async function getCryptocurrencyNews() {
let cryptoService = new CryptoService(process.env.MICRO_API_TOKEN);
let rsp = await cryptoService.news({
symbol: "BTCUSD",
});
console.log(rsp);
}
await GetCryptocurrencyNews();
getCryptocurrencyNews();

View File

@@ -1,12 +1,12 @@
import * as crypto from "m3o/crypto";
const { CryptoService } = require("m3o/crypto");
// Get the last price for a given crypto ticker
async function GetCryptocurrencyPrice() {
let cryptoService = new crypto.CryptoService(process.env.MICRO_API_TOKEN);
async function getCryptocurrencyPrice() {
let cryptoService = new CryptoService(process.env.MICRO_API_TOKEN);
let rsp = await cryptoService.price({
symbol: "BTCUSD",
});
console.log(rsp);
}
await GetCryptocurrencyPrice();
getCryptocurrencyPrice();

View File

@@ -1,12 +1,12 @@
import * as crypto from "m3o/crypto";
const { CryptoService } = require("m3o/crypto");
// Get the last quote for a given crypto ticker
async function GetAcryptocurrencyQuote() {
let cryptoService = new crypto.CryptoService(process.env.MICRO_API_TOKEN);
async function getAcryptocurrencyQuote() {
let cryptoService = new CryptoService(process.env.MICRO_API_TOKEN);
let rsp = await cryptoService.quote({
symbol: "BTCUSD",
});
console.log(rsp);
}
await GetAcryptocurrencyQuote();
getAcryptocurrencyQuote();

View File

@@ -1,12 +1,10 @@
import * as currency from "m3o/currency";
const { CurrencyService } = require("m3o/currency");
// Codes returns the supported currency codes for the API
async function GetSupportedCodes() {
let currencyService = new currency.CurrencyService(
process.env.MICRO_API_TOKEN
);
async function getSupportedCodes() {
let currencyService = new CurrencyService(process.env.MICRO_API_TOKEN);
let rsp = await currencyService.codes({});
console.log(rsp);
}
await GetSupportedCodes();
getSupportedCodes();

View File

@@ -1,10 +1,8 @@
import * as currency from "m3o/currency";
const { CurrencyService } = require("m3o/currency");
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
async function Convert10usdToGbp() {
let currencyService = new currency.CurrencyService(
process.env.MICRO_API_TOKEN
);
async function convert10usdToGbp() {
let currencyService = new CurrencyService(process.env.MICRO_API_TOKEN);
let rsp = await currencyService.convert({
amount: 10,
from: "USD",
@@ -13,4 +11,4 @@ async function Convert10usdToGbp() {
console.log(rsp);
}
await Convert10usdToGbp();
convert10usdToGbp();

View File

@@ -1,10 +1,8 @@
import * as currency from "m3o/currency";
const { CurrencyService } = require("m3o/currency");
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
async function ConvertUsdToGbp() {
let currencyService = new currency.CurrencyService(
process.env.MICRO_API_TOKEN
);
async function convertUsdToGbp() {
let currencyService = new CurrencyService(process.env.MICRO_API_TOKEN);
let rsp = await currencyService.convert({
from: "USD",
to: "GBP",
@@ -12,4 +10,4 @@ async function ConvertUsdToGbp() {
console.log(rsp);
}
await ConvertUsdToGbp();
convertUsdToGbp();

View File

@@ -1,10 +1,8 @@
import * as currency from "m3o/currency";
const { CurrencyService } = require("m3o/currency");
// Returns the historic rates for a currency on a given date
async function HistoricRatesForAcurrency() {
let currencyService = new currency.CurrencyService(
process.env.MICRO_API_TOKEN
);
async function historicRatesForAcurrency() {
let currencyService = new CurrencyService(process.env.MICRO_API_TOKEN);
let rsp = await currencyService.history({
code: "USD",
date: "2021-05-30",
@@ -12,4 +10,4 @@ async function HistoricRatesForAcurrency() {
console.log(rsp);
}
await HistoricRatesForAcurrency();
historicRatesForAcurrency();

View File

@@ -1,14 +1,12 @@
import * as currency from "m3o/currency";
const { CurrencyService } = require("m3o/currency");
// Rates returns the currency rates for a given code e.g USD
async function GetRatesForUsd() {
let currencyService = new currency.CurrencyService(
process.env.MICRO_API_TOKEN
);
async function getRatesForUsd() {
let currencyService = new CurrencyService(process.env.MICRO_API_TOKEN);
let rsp = await currencyService.rates({
code: "USD",
});
console.log(rsp);
}
await GetRatesForUsd();
getRatesForUsd();

View File

@@ -1,12 +1,12 @@
import * as db from "m3o/db";
const { DbService } = require("m3o/db");
// Count records in a table
async function CountEntriesInAtable() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
async function countEntriesInAtable() {
let dbService = new DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.count({
table: "users",
});
console.log(rsp);
}
await CountEntriesInAtable();
countEntriesInAtable();

View File

@@ -1,8 +1,8 @@
import * as db from "m3o/db";
const { DbService } = require("m3o/db");
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
async function CreateArecord() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
async function createArecord() {
let dbService = new DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.create({
record: {
age: 42,
@@ -15,4 +15,4 @@ async function CreateArecord() {
console.log(rsp);
}
await CreateArecord();
createArecord();

View File

@@ -1,8 +1,8 @@
import * as db from "m3o/db";
const { DbService } = require("m3o/db");
// Delete a record in the database by id.
async function DeleteArecord() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
async function deleteArecord() {
let dbService = new DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.delete({
id: "1",
table: "users",
@@ -10,4 +10,4 @@ async function DeleteArecord() {
console.log(rsp);
}
await DeleteArecord();
deleteArecord();

View File

@@ -1,8 +1,8 @@
import * as db from "m3o/db";
const { DbService } = require("m3o/db");
// Read data from a table. Lookup can be by ID or via querying any field in the record.
async function ReadRecords() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
async function readRecords() {
let dbService = new DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.read({
query: "age == 43",
table: "users",
@@ -10,4 +10,4 @@ async function ReadRecords() {
console.log(rsp);
}
await ReadRecords();
readRecords();

View File

@@ -1,12 +1,12 @@
import * as db from "m3o/db";
const { DbService } = require("m3o/db");
// Truncate the records in a table
async function TruncateTable() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
async function truncateTable() {
let dbService = new DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.truncate({
table: "users",
});
console.log(rsp);
}
await TruncateTable();
truncateTable();

View File

@@ -1,8 +1,8 @@
import * as db from "m3o/db";
const { DbService } = require("m3o/db");
// Update a record in the database. Include an "id" in the record to update.
async function UpdateArecord() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
async function updateArecord() {
let dbService = new DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.update({
record: {
age: 43,
@@ -13,4 +13,4 @@ async function UpdateArecord() {
console.log(rsp);
}
await UpdateArecord();
updateArecord();

View File

@@ -1,8 +1,8 @@
import * as email from "m3o/email";
const { EmailService } = require("m3o/email");
// Send an email by passing in from, to, subject, and a text or html body
async function SendEmail() {
let emailService = new email.EmailService(process.env.MICRO_API_TOKEN);
async function sendEmail() {
let emailService = new EmailService(process.env.MICRO_API_TOKEN);
let rsp = await emailService.send({
from: "Awesome Dot Com",
subject: "Email verification",
@@ -12,4 +12,4 @@ async function SendEmail() {
console.log(rsp);
}
await SendEmail();
sendEmail();

View File

@@ -1,12 +1,12 @@
import * as emoji from "m3o/emoji";
const { EmojiService } = require("m3o/emoji");
// Find an emoji by its alias e.g :beer:
async function FindEmoji() {
let emojiService = new emoji.EmojiService(process.env.MICRO_API_TOKEN);
async function findEmoji() {
let emojiService = new EmojiService(process.env.MICRO_API_TOKEN);
let rsp = await emojiService.find({
alias: ":beer:",
});
console.log(rsp);
}
await FindEmoji();
findEmoji();

View File

@@ -1,12 +1,12 @@
import * as emoji from "m3o/emoji";
const { EmojiService } = require("m3o/emoji");
// Get the flag for a country. Requires country code e.g GB for great britain
async function GetFlagByCountryCode() {
let emojiService = new emoji.EmojiService(process.env.MICRO_API_TOKEN);
async function getFlagByCountryCode() {
let emojiService = new EmojiService(process.env.MICRO_API_TOKEN);
let rsp = await emojiService.flag({
alias: "GB",
});
console.log(rsp);
}
await GetFlagByCountryCode();
getFlagByCountryCode();

View File

@@ -1,13 +1,13 @@
import * as emoji from "m3o/emoji";
const { EmojiService } = require("m3o/emoji");
// Print text and renders the emojis with aliases e.g
// let's grab a :beer: becomes let's grab a 🍺
async function PrintTextIncludingEmoji() {
let emojiService = new emoji.EmojiService(process.env.MICRO_API_TOKEN);
async function printTextIncludingEmoji() {
let emojiService = new EmojiService(process.env.MICRO_API_TOKEN);
let rsp = await emojiService.print({
text: "let's grab a :beer:",
});
console.log(rsp);
}
await PrintTextIncludingEmoji();
printTextIncludingEmoji();

View File

@@ -1,8 +1,8 @@
import * as emoji from "m3o/emoji";
const { EmojiService } = require("m3o/emoji");
// Send an emoji to anyone via SMS. Messages are sent in the form '<message> Sent from <from>'
async function SendAtextContainingAnEmojiToAnyoneViaSms() {
let emojiService = new emoji.EmojiService(process.env.MICRO_API_TOKEN);
async function sendAtextContainingAnEmojiToAnyoneViaSms() {
let emojiService = new EmojiService(process.env.MICRO_API_TOKEN);
let rsp = await emojiService.send({
from: "Alice",
message: "let's grab a :beer:",
@@ -11,4 +11,4 @@ async function SendAtextContainingAnEmojiToAnyoneViaSms() {
console.log(rsp);
}
await SendAtextContainingAnEmojiToAnyoneViaSms();
sendAtextContainingAnEmojiToAnyoneViaSms();

View File

@@ -1,12 +1,10 @@
import * as evchargers from "m3o/evchargers";
const { EvchargersService } = require("m3o/evchargers");
// Retrieve reference data as used by this API and in conjunction with the Search endpoint
async function GetReferenceData() {
let evchargersService = new evchargers.EvchargersService(
process.env.MICRO_API_TOKEN
);
async function getReferenceData() {
let evchargersService = new EvchargersService(process.env.MICRO_API_TOKEN);
let rsp = await evchargersService.referenceData({});
console.log(rsp);
}
await GetReferenceData();
getReferenceData();

View File

@@ -1,10 +1,8 @@
import * as evchargers from "m3o/evchargers";
const { EvchargersService } = require("m3o/evchargers");
// Search by giving a coordinate and a max distance, or bounding box and optional filters
async function SearchByBoundingBox() {
let evchargersService = new evchargers.EvchargersService(
process.env.MICRO_API_TOKEN
);
async function searchByBoundingBox() {
let evchargersService = new EvchargersService(process.env.MICRO_API_TOKEN);
let rsp = await evchargersService.search({
box: {
bottom_left: {
@@ -21,4 +19,4 @@ async function SearchByBoundingBox() {
console.log(rsp);
}
await SearchByBoundingBox();
searchByBoundingBox();

View File

@@ -1,10 +1,8 @@
import * as evchargers from "m3o/evchargers";
const { EvchargersService } = require("m3o/evchargers");
// Search by giving a coordinate and a max distance, or bounding box and optional filters
async function SearchByLocation() {
let evchargersService = new evchargers.EvchargersService(
process.env.MICRO_API_TOKEN
);
async function searchByLocation() {
let evchargersService = new EvchargersService(process.env.MICRO_API_TOKEN);
let rsp = await evchargersService.search({
distance: 2000,
location: {
@@ -16,4 +14,4 @@ async function SearchByLocation() {
console.log(rsp);
}
await SearchByLocation();
searchByLocation();

View File

@@ -1,10 +1,8 @@
import * as evchargers from "m3o/evchargers";
const { EvchargersService } = require("m3o/evchargers");
// Search by giving a coordinate and a max distance, or bounding box and optional filters
async function SearchWithFiltersFastChargersOnly() {
let evchargersService = new evchargers.EvchargersService(
process.env.MICRO_API_TOKEN
);
async function searchWithFiltersFastChargersOnly() {
let evchargersService = new EvchargersService(process.env.MICRO_API_TOKEN);
let rsp = await evchargersService.search({
distance: 2000,
levels: ["3"],
@@ -17,4 +15,4 @@ async function SearchWithFiltersFastChargersOnly() {
console.log(rsp);
}
await SearchWithFiltersFastChargersOnly();
searchWithFiltersFastChargersOnly();

View File

@@ -1,8 +1,8 @@
import * as file from "m3o/file";
const { FileService } = require("m3o/file");
// Delete a file by project name/path
async function DeleteFile() {
let fileService = new file.FileService(process.env.MICRO_API_TOKEN);
async function deleteFile() {
let fileService = new FileService(process.env.MICRO_API_TOKEN);
let rsp = await fileService.delete({
path: "/document/text-files/file.txt",
project: "examples",
@@ -10,4 +10,4 @@ async function DeleteFile() {
console.log(rsp);
}
await DeleteFile();
deleteFile();

View File

@@ -1,12 +1,12 @@
import * as file from "m3o/file";
const { FileService } = require("m3o/file");
// List files by their project and optionally a path.
async function ListFiles() {
let fileService = new file.FileService(process.env.MICRO_API_TOKEN);
async function listFiles() {
let fileService = new FileService(process.env.MICRO_API_TOKEN);
let rsp = await fileService.list({
project: "examples",
});
console.log(rsp);
}
await ListFiles();
listFiles();

View File

@@ -1,8 +1,8 @@
import * as file from "m3o/file";
const { FileService } = require("m3o/file");
// Read a file by path
async function ReadFile() {
let fileService = new file.FileService(process.env.MICRO_API_TOKEN);
async function readFile() {
let fileService = new FileService(process.env.MICRO_API_TOKEN);
let rsp = await fileService.read({
path: "/document/text-files/file.txt",
project: "examples",
@@ -10,4 +10,4 @@ async function ReadFile() {
console.log(rsp);
}
await ReadFile();
readFile();

View File

@@ -1,8 +1,8 @@
import * as file from "m3o/file";
const { FileService } = require("m3o/file");
// Save a file
async function SaveFile() {
let fileService = new file.FileService(process.env.MICRO_API_TOKEN);
async function saveFile() {
let fileService = new FileService(process.env.MICRO_API_TOKEN);
let rsp = await fileService.save({
file: {
content: "file content example",
@@ -13,4 +13,4 @@ async function SaveFile() {
console.log(rsp);
}
await SaveFile();
saveFile();

View File

@@ -1,12 +1,12 @@
import * as forex from "m3o/forex";
const { ForexService } = require("m3o/forex");
// Returns the data for the previous close
async function GetPreviousClose() {
let forexService = new forex.ForexService(process.env.MICRO_API_TOKEN);
async function getPreviousClose() {
let forexService = new ForexService(process.env.MICRO_API_TOKEN);
let rsp = await forexService.history({
symbol: "GBPUSD",
});
console.log(rsp);
}
await GetPreviousClose();
getPreviousClose();

View File

@@ -1,12 +1,12 @@
import * as forex from "m3o/forex";
const { ForexService } = require("m3o/forex");
// Get the latest price for a given forex ticker
async function GetAnFxPrice() {
let forexService = new forex.ForexService(process.env.MICRO_API_TOKEN);
async function getAnFxPrice() {
let forexService = new ForexService(process.env.MICRO_API_TOKEN);
let rsp = await forexService.price({
symbol: "GBPUSD",
});
console.log(rsp);
}
await GetAnFxPrice();
getAnFxPrice();

View File

@@ -1,12 +1,12 @@
import * as forex from "m3o/forex";
const { ForexService } = require("m3o/forex");
// Get the latest quote for the forex
async function GetAfxQuote() {
let forexService = new forex.ForexService(process.env.MICRO_API_TOKEN);
async function getAfxQuote() {
let forexService = new ForexService(process.env.MICRO_API_TOKEN);
let rsp = await forexService.quote({
symbol: "GBPUSD",
});
console.log(rsp);
}
await GetAfxQuote();
getAfxQuote();

View File

@@ -1,8 +1,8 @@
import * as fx from "m3o/function";
const { FunctionService } = require("m3o/function");
// Call a function by name
async function CallAfunction() {
let functionService = new fx.FunctionService(process.env.MICRO_API_TOKEN);
async function callAfunction() {
let functionService = new FunctionService(process.env.MICRO_API_TOKEN);
let rsp = await functionService.call({
name: "my-first-func",
request: {},
@@ -10,4 +10,4 @@ async function CallAfunction() {
console.log(rsp);
}
await CallAfunction();
callAfunction();

View File

@@ -1,8 +1,8 @@
import * as fx from "m3o/function";
const { FunctionService } = require("m3o/function");
// Delete a function by name
async function DeleteAfunction() {
let functionService = new fx.FunctionService(process.env.MICRO_API_TOKEN);
async function deleteAfunction() {
let functionService = new FunctionService(process.env.MICRO_API_TOKEN);
let rsp = await functionService.delete({
name: "my-first-func",
project: "tests",
@@ -10,4 +10,4 @@ async function DeleteAfunction() {
console.log(rsp);
}
await DeleteAfunction();
deleteAfunction();

View File

@@ -1,8 +1,8 @@
import * as fx from "m3o/function";
const { FunctionService } = require("m3o/function");
// Deploy a group of functions
async function DeployAfunction() {
let functionService = new fx.FunctionService(process.env.MICRO_API_TOKEN);
async function deployAfunction() {
let functionService = new FunctionService(process.env.MICRO_API_TOKEN);
let rsp = await functionService.deploy({
entrypoint: "helloworld",
name: "my-first-func",
@@ -13,4 +13,4 @@ async function DeployAfunction() {
console.log(rsp);
}
await DeployAfunction();
deployAfunction();

View File

@@ -1,8 +1,8 @@
import * as fx from "m3o/function";
const { FunctionService } = require("m3o/function");
//
async function DescribeFunctionStatus() {
let functionService = new fx.FunctionService(process.env.MICRO_API_TOKEN);
async function describeFunctionStatus() {
let functionService = new FunctionService(process.env.MICRO_API_TOKEN);
let rsp = await functionService.describe({
name: "my-first-func",
project: "tests",
@@ -10,4 +10,4 @@ async function DescribeFunctionStatus() {
console.log(rsp);
}
await DescribeFunctionStatus();
describeFunctionStatus();

View File

@@ -1,10 +1,10 @@
import * as fx from "m3o/function";
const { FunctionService } = require("m3o/function");
// List all the deployed functions
async function ListFunctions() {
let functionService = new fx.FunctionService(process.env.MICRO_API_TOKEN);
async function listFunctions() {
let functionService = new FunctionService(process.env.MICRO_API_TOKEN);
let rsp = await functionService.list({});
console.log(rsp);
}
await ListFunctions();
listFunctions();

View File

@@ -1,10 +1,8 @@
import * as geocoding from "m3o/geocoding";
const { GeocodingService } = require("m3o/geocoding");
// Lookup returns a geocoded address including normalized address and gps coordinates. All fields are optional, provide more to get more accurate results
async function GeocodeAnAddress() {
let geocodingService = new geocoding.GeocodingService(
process.env.MICRO_API_TOKEN
);
async function geocodeAnAddress() {
let geocodingService = new GeocodingService(process.env.MICRO_API_TOKEN);
let rsp = await geocodingService.lookup({
address: "10 russell st",
city: "london",
@@ -14,4 +12,4 @@ async function GeocodeAnAddress() {
console.log(rsp);
}
await GeocodeAnAddress();
geocodeAnAddress();

View File

@@ -1,10 +1,8 @@
import * as geocoding from "m3o/geocoding";
const { GeocodingService } = require("m3o/geocoding");
// Reverse lookup an address from gps coordinates
async function ReverseGeocodeLocation() {
let geocodingService = new geocoding.GeocodingService(
process.env.MICRO_API_TOKEN
);
async function reverseGeocodeLocation() {
let geocodingService = new GeocodingService(process.env.MICRO_API_TOKEN);
let rsp = await geocodingService.reverse({
latitude: 51.5123064,
longitude: -0.1216235,
@@ -12,4 +10,4 @@ async function ReverseGeocodeLocation() {
console.log(rsp);
}
await ReverseGeocodeLocation();
reverseGeocodeLocation();

View File

@@ -1,14 +1,12 @@
import * as helloworld from "m3o/helloworld";
const { HelloworldService } = require("m3o/helloworld");
// Call returns a personalised "Hello $name" response
async function CallTheHelloworldService() {
let helloworldService = new helloworld.HelloworldService(
process.env.MICRO_API_TOKEN
);
async function callTheHelloworldService() {
let helloworldService = new HelloworldService(process.env.MICRO_API_TOKEN);
let rsp = await helloworldService.call({
name: "John",
});
console.log(rsp);
}
await CallTheHelloworldService();
callTheHelloworldService();

View File

@@ -1,14 +1,12 @@
import * as helloworld from "m3o/helloworld";
const { HelloworldService } = require("m3o/helloworld");
// Stream returns a stream of "Hello $name" responses
async function StreamsAreCurrentlyTemporarilyNotSupportedInClients() {
let helloworldService = new helloworld.HelloworldService(
process.env.MICRO_API_TOKEN
);
async function streamsAreCurrentlyTemporarilyNotSupportedInClients() {
let helloworldService = new HelloworldService(process.env.MICRO_API_TOKEN);
let rsp = await helloworldService.stream({
name: "not supported",
});
console.log(rsp);
}
await StreamsAreCurrentlyTemporarilyNotSupportedInClients();
streamsAreCurrentlyTemporarilyNotSupportedInClients();

View File

@@ -1,12 +1,10 @@
import * as holidays from "m3o/holidays";
const { HolidaysService } = require("m3o/holidays");
// Get the list of countries that are supported by this API
async function ListCountries() {
let holidaysService = new holidays.HolidaysService(
process.env.MICRO_API_TOKEN
);
async function listCountries() {
let holidaysService = new HolidaysService(process.env.MICRO_API_TOKEN);
let rsp = await holidaysService.countries({});
console.log(rsp);
}
await ListCountries();
listCountries();

View File

@@ -1,10 +1,8 @@
import * as holidays from "m3o/holidays";
const { HolidaysService } = require("m3o/holidays");
// List the holiday dates for a given country and year
async function GetHolidays() {
let holidaysService = new holidays.HolidaysService(
process.env.MICRO_API_TOKEN
);
async function getHolidays() {
let holidaysService = new HolidaysService(process.env.MICRO_API_TOKEN);
let rsp = await holidaysService.list({
country_code: "GB",
year: 2022,
@@ -12,4 +10,4 @@ async function GetHolidays() {
console.log(rsp);
}
await GetHolidays();
getHolidays();

View File

@@ -1,12 +1,12 @@
import * as id from "m3o/id";
const { IdService } = require("m3o/id");
// Generate a unique ID. Defaults to uuid.
async function GenerateAbigflakeId() {
let idService = new id.IdService(process.env.MICRO_API_TOKEN);
async function generateAbigflakeId() {
let idService = new IdService(process.env.MICRO_API_TOKEN);
let rsp = await idService.generate({
type: "bigflake",
});
console.log(rsp);
}
await GenerateAbigflakeId();
generateAbigflakeId();

View File

@@ -1,12 +1,12 @@
import * as id from "m3o/id";
const { IdService } = require("m3o/id");
// Generate a unique ID. Defaults to uuid.
async function GenerateAshortId() {
let idService = new id.IdService(process.env.MICRO_API_TOKEN);
async function generateAshortId() {
let idService = new IdService(process.env.MICRO_API_TOKEN);
let rsp = await idService.generate({
type: "shortid",
});
console.log(rsp);
}
await GenerateAshortId();
generateAshortId();

View File

@@ -1,12 +1,12 @@
import * as id from "m3o/id";
const { IdService } = require("m3o/id");
// Generate a unique ID. Defaults to uuid.
async function GenerateAsnowflakeId() {
let idService = new id.IdService(process.env.MICRO_API_TOKEN);
async function generateAsnowflakeId() {
let idService = new IdService(process.env.MICRO_API_TOKEN);
let rsp = await idService.generate({
type: "snowflake",
});
console.log(rsp);
}
await GenerateAsnowflakeId();
generateAsnowflakeId();

View File

@@ -1,12 +1,12 @@
import * as id from "m3o/id";
const { IdService } = require("m3o/id");
// Generate a unique ID. Defaults to uuid.
async function GenerateAuniqueId() {
let idService = new id.IdService(process.env.MICRO_API_TOKEN);
async function generateAuniqueId() {
let idService = new IdService(process.env.MICRO_API_TOKEN);
let rsp = await idService.generate({
type: "uuid",
});
console.log(rsp);
}
await GenerateAuniqueId();
generateAuniqueId();

View File

@@ -1,10 +1,10 @@
import * as id from "m3o/id";
const { IdService } = require("m3o/id");
// List the types of IDs available. No query params needed.
async function ListTheTypesOfIdsAvailable() {
let idService = new id.IdService(process.env.MICRO_API_TOKEN);
async function listTheTypesOfIdsAvailable() {
let idService = new IdService(process.env.MICRO_API_TOKEN);
let rsp = await idService.types({});
console.log(rsp);
}
await ListTheTypesOfIdsAvailable();
listTheTypesOfIdsAvailable();

View File

@@ -1,9 +1,9 @@
import * as image from "m3o/image";
const { ImageService } = require("m3o/image");
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
// or by uploading the conversion result.
async function ConvertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn() {
let imageService = new image.ImageService(process.env.MICRO_API_TOKEN);
async function convertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn() {
let imageService = new ImageService(process.env.MICRO_API_TOKEN);
let rsp = await imageService.convert({
name: "cat.jpeg",
outputURL: true,
@@ -12,4 +12,4 @@ async function ConvertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn() {
console.log(rsp);
}
await ConvertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn();
convertApngImageToAjpegTakenFromAurlAndSavedToAurlOnMicrosCdn();

View File

@@ -1,10 +1,10 @@
import * as image from "m3o/image";
const { ImageService } = require("m3o/image");
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
// If one of width or height is 0, the image aspect ratio is preserved.
// Optional cropping.
async function Base64toBase64image() {
let imageService = new image.ImageService(process.env.MICRO_API_TOKEN);
async function base64toBase64image() {
let imageService = new ImageService(process.env.MICRO_API_TOKEN);
let rsp = await imageService.resize({
base64:
"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
@@ -14,4 +14,4 @@ async function Base64toBase64image() {
console.log(rsp);
}
await Base64toBase64image();
base64toBase64image();

View File

@@ -1,10 +1,10 @@
import * as image from "m3o/image";
const { ImageService } = require("m3o/image");
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
// If one of width or height is 0, the image aspect ratio is preserved.
// Optional cropping.
async function Base64toBase64imageWithCropping() {
let imageService = new image.ImageService(process.env.MICRO_API_TOKEN);
async function base64toBase64imageWithCropping() {
let imageService = new ImageService(process.env.MICRO_API_TOKEN);
let rsp = await imageService.resize({
base64:
"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
@@ -18,4 +18,4 @@ async function Base64toBase64imageWithCropping() {
console.log(rsp);
}
await Base64toBase64imageWithCropping();
base64toBase64imageWithCropping();

View File

@@ -1,10 +1,10 @@
import * as image from "m3o/image";
const { ImageService } = require("m3o/image");
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
// If one of width or height is 0, the image aspect ratio is preserved.
// Optional cropping.
async function Base64toHostedImage() {
let imageService = new image.ImageService(process.env.MICRO_API_TOKEN);
async function base64toHostedImage() {
let imageService = new ImageService(process.env.MICRO_API_TOKEN);
let rsp = await imageService.resize({
base64:
"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
@@ -16,4 +16,4 @@ async function Base64toHostedImage() {
console.log(rsp);
}
await Base64toHostedImage();
base64toHostedImage();

View File

@@ -1,9 +1,9 @@
import * as image from "m3o/image";
const { ImageService } = require("m3o/image");
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
// To resize an image before uploading, see the Resize endpoint.
async function UploadAbase64imageToMicrosCdn() {
let imageService = new image.ImageService(process.env.MICRO_API_TOKEN);
async function uploadAbase64imageToMicrosCdn() {
let imageService = new ImageService(process.env.MICRO_API_TOKEN);
let rsp = await imageService.upload({
base64:
"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAx0lEQVR4nOzaMaoDMQyE4ZHj+x82vVdhwQoTkzKQEcwP5r0ihT7sbjUTeAJ4HCegXQJYfOYefOyjDuBiz3yjwJBoCIl6QZOeUjTC1Ix1IxEJXF9+0KWsf2bD4bn37OO/c/wuQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9QyRC1D1DJELUPUMkQtQ9Sa/NG94Tf3j4WBdaxudMEkn4IM2rZBA0wBrvo7aOcpj2emXvLeVt0IGm0GVXUj91mvAAAA//+V2CZl+4AKXwAAAABJRU5ErkJggg==",
@@ -13,4 +13,4 @@ async function UploadAbase64imageToMicrosCdn() {
console.log(rsp);
}
await UploadAbase64imageToMicrosCdn();
uploadAbase64imageToMicrosCdn();

View File

@@ -1,9 +1,9 @@
import * as image from "m3o/image";
const { ImageService } = require("m3o/image");
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
// To resize an image before uploading, see the Resize endpoint.
async function UploadAnImageFromAurlToMicrosCdn() {
let imageService = new image.ImageService(process.env.MICRO_API_TOKEN);
async function uploadAnImageFromAurlToMicrosCdn() {
let imageService = new ImageService(process.env.MICRO_API_TOKEN);
let rsp = await imageService.upload({
name: "cat.jpeg",
url: "somewebsite.com/cat.png",
@@ -11,4 +11,4 @@ async function UploadAnImageFromAurlToMicrosCdn() {
console.log(rsp);
}
await UploadAnImageFromAurlToMicrosCdn();
uploadAnImageFromAurlToMicrosCdn();

View File

@@ -1,12 +1,12 @@
import * as ip from "m3o/ip";
const { IpService } = require("m3o/ip");
// Lookup the geolocation information for an IP address
async function LookupIpInfo() {
let ipService = new ip.IpService(process.env.MICRO_API_TOKEN);
async function lookupIpInfo() {
let ipService = new IpService(process.env.MICRO_API_TOKEN);
let rsp = await ipService.lookup({
ip: "93.148.214.31",
});
console.log(rsp);
}
await LookupIpInfo();
lookupIpInfo();

View File

@@ -1,14 +1,12 @@
import * as location from "m3o/location";
const { LocationService } = require("m3o/location");
// Read an entity by its ID
async function GetLocationById() {
let locationService = new location.LocationService(
process.env.MICRO_API_TOKEN
);
async function getLocationById() {
let locationService = new LocationService(process.env.MICRO_API_TOKEN);
let rsp = await locationService.read({
id: "1",
});
console.log(rsp);
}
await GetLocationById();
getLocationById();

View File

@@ -1,10 +1,8 @@
import * as location from "m3o/location";
const { LocationService } = require("m3o/location");
// Save an entity's current position
async function SaveAnEntity() {
let locationService = new location.LocationService(
process.env.MICRO_API_TOKEN
);
async function saveAnEntity() {
let locationService = new LocationService(process.env.MICRO_API_TOKEN);
let rsp = await locationService.save({
entity: {
id: "1",
@@ -19,4 +17,4 @@ async function SaveAnEntity() {
console.log(rsp);
}
await SaveAnEntity();
saveAnEntity();

View File

@@ -1,10 +1,8 @@
import * as location from "m3o/location";
const { LocationService } = require("m3o/location");
// Search for entities in a given radius
async function SearchForLocations() {
let locationService = new location.LocationService(
process.env.MICRO_API_TOKEN
);
async function searchForLocations() {
let locationService = new LocationService(process.env.MICRO_API_TOKEN);
let rsp = await locationService.search({
center: {
latitude: 51.511061,
@@ -17,4 +15,4 @@ async function SearchForLocations() {
console.log(rsp);
}
await SearchForLocations();
searchForLocations();

View File

@@ -1,8 +1,8 @@
import * as notes from "m3o/notes";
const { NotesService } = require("m3o/notes");
// Create a new note
async function CreateAnote() {
let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN);
async function createAnote() {
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
let rsp = await notesService.create({
text: "This is my note",
title: "New Note",
@@ -10,4 +10,4 @@ async function CreateAnote() {
console.log(rsp);
}
await CreateAnote();
createAnote();

View File

@@ -1,12 +1,12 @@
import * as notes from "m3o/notes";
const { NotesService } = require("m3o/notes");
// Delete a note
async function DeleteAnote() {
let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN);
async function deleteAnote() {
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
let rsp = await notesService.delete({
id: "63c0cdf8-2121-11ec-a881-0242e36f037a",
});
console.log(rsp);
}
await DeleteAnote();
deleteAnote();

View File

@@ -1,10 +1,10 @@
import * as notes from "m3o/notes";
const { NotesService } = require("m3o/notes");
// List all the notes
async function ListAllNotes() {
let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN);
async function listAllNotes() {
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
let rsp = await notesService.list({});
console.log(rsp);
}
await ListAllNotes();
listAllNotes();

View File

@@ -1,12 +1,12 @@
import * as notes from "m3o/notes";
const { NotesService } = require("m3o/notes");
// Read a note
async function ReadAnote() {
let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN);
async function readAnote() {
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
let rsp = await notesService.read({
id: "63c0cdf8-2121-11ec-a881-0242e36f037a",
});
console.log(rsp);
}
await ReadAnote();
readAnote();

View File

@@ -1,8 +1,8 @@
import * as notes from "m3o/notes";
const { NotesService } = require("m3o/notes");
// Update a note
async function UpdateAnote() {
let notesService = new notes.NotesService(process.env.MICRO_API_TOKEN);
async function updateAnote() {
let notesService = new NotesService(process.env.MICRO_API_TOKEN);
let rsp = await notesService.update({
note: {
id: "63c0cdf8-2121-11ec-a881-0242e36f037a",
@@ -13,4 +13,4 @@ async function UpdateAnote() {
console.log(rsp);
}
await UpdateAnote();
updateAnote();

View File

@@ -1,12 +1,12 @@
import * as otp from "m3o/otp";
const { OtpService } = require("m3o/otp");
// Generate an OTP (one time pass) code
async function GenerateOtp() {
let otpService = new otp.OtpService(process.env.MICRO_API_TOKEN);
async function generateOtp() {
let otpService = new OtpService(process.env.MICRO_API_TOKEN);
let rsp = await otpService.generate({
id: "asim@example.com",
});
console.log(rsp);
}
await GenerateOtp();
generateOtp();

View File

@@ -1,8 +1,8 @@
import * as otp from "m3o/otp";
const { OtpService } = require("m3o/otp");
// Validate the OTP code
async function ValidateOtp() {
let otpService = new otp.OtpService(process.env.MICRO_API_TOKEN);
async function validateOtp() {
let otpService = new OtpService(process.env.MICRO_API_TOKEN);
let rsp = await otpService.validate({
code: "656211",
id: "asim@example.com",
@@ -10,4 +10,4 @@ async function ValidateOtp() {
console.log(rsp);
}
await ValidateOtp();
validateOtp();

View File

@@ -1,14 +1,12 @@
import * as postcode from "m3o/postcode";
const { PostcodeService } = require("m3o/postcode");
// Lookup a postcode to retrieve the related region, county, etc
async function LookupPostcode() {
let postcodeService = new postcode.PostcodeService(
process.env.MICRO_API_TOKEN
);
async function lookupPostcode() {
let postcodeService = new PostcodeService(process.env.MICRO_API_TOKEN);
let rsp = await postcodeService.lookup({
postcode: "SW1A 2AA",
});
console.log(rsp);
}
await LookupPostcode();
lookupPostcode();

View File

@@ -1,12 +1,10 @@
import * as postcode from "m3o/postcode";
const { PostcodeService } = require("m3o/postcode");
// Return a random postcode and its related info
async function ReturnArandomPostcodeAndItsInformation() {
let postcodeService = new postcode.PostcodeService(
process.env.MICRO_API_TOKEN
);
async function returnArandomPostcodeAndItsInformation() {
let postcodeService = new PostcodeService(process.env.MICRO_API_TOKEN);
let rsp = await postcodeService.random({});
console.log(rsp);
}
await ReturnArandomPostcodeAndItsInformation();
returnArandomPostcodeAndItsInformation();

View File

@@ -1,14 +1,12 @@
import * as postcode from "m3o/postcode";
const { PostcodeService } = require("m3o/postcode");
// Validate a postcode.
async function ReturnArandomPostcodeAndItsInformation() {
let postcodeService = new postcode.PostcodeService(
process.env.MICRO_API_TOKEN
);
async function returnArandomPostcodeAndItsInformation() {
let postcodeService = new PostcodeService(process.env.MICRO_API_TOKEN);
let rsp = await postcodeService.validate({
postcode: "SW1A 2AA",
});
console.log(rsp);
}
await ReturnArandomPostcodeAndItsInformation();
returnArandomPostcodeAndItsInformation();

View File

@@ -1,12 +1,12 @@
import * as prayer from "m3o/prayer";
const { PrayerService } = require("m3o/prayer");
// Get the prayer (salah) times for a location on a given date
async function PrayerTimes() {
let prayerService = new prayer.PrayerService(process.env.MICRO_API_TOKEN);
async function prayerTimes() {
let prayerService = new PrayerService(process.env.MICRO_API_TOKEN);
let rsp = await prayerService.times({
location: "london",
});
console.log(rsp);
}
await PrayerTimes();
prayerTimes();

View File

@@ -1,8 +1,8 @@
import * as qr from "m3o/qr";
const { QrService } = require("m3o/qr");
// Generate a QR code with a specific text and size
async function GenerateAqrCode() {
let qrService = new qr.QrService(process.env.MICRO_API_TOKEN);
async function generateAqrCode() {
let qrService = new QrService(process.env.MICRO_API_TOKEN);
let rsp = await qrService.generate({
size: 300,
text: "https://m3o.com/qr",
@@ -10,4 +10,4 @@ async function GenerateAqrCode() {
console.log(rsp);
}
await GenerateAqrCode();
generateAqrCode();

View File

@@ -1,12 +1,12 @@
import * as quran from "m3o/quran";
const { QuranService } = require("m3o/quran");
// List the Chapters (surahs) of the Quran
async function ListChapters() {
let quranService = new quran.QuranService(process.env.MICRO_API_TOKEN);
async function listChapters() {
let quranService = new QuranService(process.env.MICRO_API_TOKEN);
let rsp = await quranService.chapters({
language: "en",
});
console.log(rsp);
}
await ListChapters();
listChapters();

View File

@@ -1,12 +1,12 @@
import * as quran from "m3o/quran";
const { QuranService } = require("m3o/quran");
// Search the Quran for any form of query or questions
async function SearchTheQuran() {
let quranService = new quran.QuranService(process.env.MICRO_API_TOKEN);
async function searchTheQuran() {
let quranService = new QuranService(process.env.MICRO_API_TOKEN);
let rsp = await quranService.search({
query: "messenger",
});
console.log(rsp);
}
await SearchTheQuran();
searchTheQuran();

View File

@@ -1,12 +1,12 @@
import * as quran from "m3o/quran";
const { QuranService } = require("m3o/quran");
// Get a summary for a given chapter (surah)
async function GetChapterSummary() {
let quranService = new quran.QuranService(process.env.MICRO_API_TOKEN);
async function getChapterSummary() {
let quranService = new QuranService(process.env.MICRO_API_TOKEN);
let rsp = await quranService.summary({
chapter: 1,
});
console.log(rsp);
}
await GetChapterSummary();
getChapterSummary();

View File

@@ -1,14 +1,14 @@
import * as quran from "m3o/quran";
const { QuranService } = require("m3o/quran");
// Lookup the verses (ayahs) for a chapter including
// translation, interpretation and breakdown by individual
// words.
async function GetVersesOfAchapter() {
let quranService = new quran.QuranService(process.env.MICRO_API_TOKEN);
async function getVersesOfAchapter() {
let quranService = new QuranService(process.env.MICRO_API_TOKEN);
let rsp = await quranService.verses({
chapter: 1,
});
console.log(rsp);
}
await GetVersesOfAchapter();
getVersesOfAchapter();

View File

@@ -1,8 +1,8 @@
import * as routing from "m3o/routing";
const { RoutingService } = require("m3o/routing");
// Turn by turn directions from a start point to an end point including maneuvers and bearings
async function TurnByTurnDirections() {
let routingService = new routing.RoutingService(process.env.MICRO_API_TOKEN);
async function turnByTurnDirections() {
let routingService = new RoutingService(process.env.MICRO_API_TOKEN);
let rsp = await routingService.directions({
destination: {
latitude: 52.529407,
@@ -16,4 +16,4 @@ async function TurnByTurnDirections() {
console.log(rsp);
}
await TurnByTurnDirections();
turnByTurnDirections();

View File

@@ -1,8 +1,8 @@
import * as routing from "m3o/routing";
const { RoutingService } = require("m3o/routing");
// Get the eta for a route from origin to destination. The eta is an estimated time based on car routes
async function EtaFromPointAtoPointB() {
let routingService = new routing.RoutingService(process.env.MICRO_API_TOKEN);
async function etaFromPointAtoPointB() {
let routingService = new RoutingService(process.env.MICRO_API_TOKEN);
let rsp = await routingService.eta({
destination: {
latitude: 52.529407,
@@ -16,4 +16,4 @@ async function EtaFromPointAtoPointB() {
console.log(rsp);
}
await EtaFromPointAtoPointB();
etaFromPointAtoPointB();

View File

@@ -1,8 +1,8 @@
import * as routing from "m3o/routing";
const { RoutingService } = require("m3o/routing");
// Retrieve a route as a simple list of gps points along with total distance and estimated duration
async function GpsPointsForAroute() {
let routingService = new routing.RoutingService(process.env.MICRO_API_TOKEN);
async function gpsPointsForAroute() {
let routingService = new RoutingService(process.env.MICRO_API_TOKEN);
let rsp = await routingService.route({
destination: {
latitude: 52.529407,
@@ -16,4 +16,4 @@ async function GpsPointsForAroute() {
console.log(rsp);
}
await GpsPointsForAroute();
gpsPointsForAroute();

View File

@@ -1,8 +1,8 @@
import * as rss from "m3o/rss";
const { RssService } = require("m3o/rss");
// Add a new RSS feed with a name, url, and category
async function AddAnewFeed() {
let rssService = new rss.RssService(process.env.MICRO_API_TOKEN);
async function addAnewFeed() {
let rssService = new RssService(process.env.MICRO_API_TOKEN);
let rsp = await rssService.add({
category: "news",
name: "bbc",
@@ -11,4 +11,4 @@ async function AddAnewFeed() {
console.log(rsp);
}
await AddAnewFeed();
addAnewFeed();

Some files were not shown because too many files have changed in this diff Show More