-
NodeJS ClientSummary
Motivation
Detailed design
What v1 won't do
Setup ExamplesSchemaconst createClientSchema = z.function()
.args(
z.string().url(), // hyper63 URL
z.function().args(z.void()).returns(z.string()), // value for Bearer Token
z.array(
z.object({
name: z.string(),
types: z.array(z.string()),
ports: z.array(z.enum(['data', 'cache', 'search', 'storage'])),
})
)
)
.returns(z.object().passthrough()) Implementation Exampleimport hyper63 from '@hyper63/client'
import * as z from 'zod'
const client = hyper63.createClient(
'https://play.hyper63.com',
() => process.env.TOKEN,
[
{ name: 'movies', types: ['movie', 'actor', 'poster'], ports: ['data', 'cache', 'storage'] },
{ name: 'users', types: ['account', 'user', 'role', 'avatar'], ports: ['data', 'cache', 'storage'] },
{ name: 'titles', ports: ['search'] }
]
)
client.movies.movie.schema(
z.object({
id: z.string(),
title: z.string(),
year: z.string().min(4).max(4)
})
)
client.movies.bulkDocs([
{
id: '1',
type: 'movie',
title: 'Ghostbusters',
year: '1984'
},
{
id: '2',
type: 'movie',
title: 'Groundhog Day',
year: '1993'
}
])
.fork(
e => console.log('error: ', e),
r => console.log('result: ', r)
)
client.movies.movie.post({
id: '3',
title: 'Avengers',
year: '2012'
})
.fork(
e => console.log('error: ', e),
r => console.log('result: ', r)
)
client.movies.movie.get('1')
.fork(
e => console.log('error: ', e),
r => console.log('result: ', r)
)
client.movies.query({
year: {
$gt: '2000'
}
})
.fork(...)
client.titles.search({
query: 'Avengers'
})
.fork(...)
How we teach this
Drawbacks
Alternatives
Unresolved questions
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
@TillaTheHun0 @Benanna2019 @JanitaM @cawilson1 @tripott @rpearce ☝️ Please review this proposal and discuss and question. The goal would to provide a first class client to hyper63 that gives api developers a great user experience connecting with hyper63. The client api would not implement any patterns on v1 it would only abstract the rest api into a DSL api so that users can leverage declarative syntax in their business logic. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
This is real nice 👌. Nearly every question I've written out here so far, upon further inspection, has led me to delete it because what you've got here makes sense. My only remaining questions:
|
Beta Was this translation helpful? Give feedback.
-
Good question let me think through that
I suppose the check on the returned value could resolve either or
…Sent from my iPhone
On Feb 22, 2021, at 3:20 PM, Robert Pearce ***@***.***> wrote:
All that sounds good. Is there a scenario where generateToken needs to do something promisey? If so, would this argument be able to handle async gnerateToken () => {}?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
Took a step back and delivered @hyper.io/connect a easy way to connect to a hyper meta-service using the url and token methods, check it out at https://github.com/hyper63/connect |
Beta Was this translation helpful? Give feedback.
Took a step back and delivered @hyper.io/connect a easy way to connect to a hyper meta-service using the url and token methods, check it out at https://github.com/hyper63/connect