0.0.32 • Published 2 years ago

@uncloud-sdk/lib v0.0.32

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@uncloud-sdk/lib

Your new best friend for building with getuncloud.com
✨ uncloud is currently in closed preview. Join waitinglist

Hello World example

// __public__/hello.ts
import { service, res } from '@uncloud-sdk/lib'

export const hello = service('hello', ({ props, deps }) => {
  const { name } = props
  const { log } = deps
  if (!name) {
    return res.failure('"name" is required')
  }
  
  log(`Received request to greet "${name}"`)
  return res.success(`Hello ${name} - nice meeting ya 🥳`)
}, {
  log: console.log,
})
  • Run locally by running $ uncloud dev (@uncloud-sdk/cli needs to be installed)
  • Login to uncloud by running $ uncloud login
  • After you're happy, deploy to uncloud by running $ uncloud deploy --production (or just run $ uncloud deploy to deploy to preview environment)

Testing

import { describe, test, expect } from 'vitest'
import { service, res } from '@uncloud-sdk/testutils'
import { hello } from './hello'

describe('hello', () => {
  test('Expect to return failure if name is missing', async () => {
    const response = await service.run(hello, {}, { log: () => {} })
    expect(response).toStrictEqual(res.failure('"name" is required'))
  })

  test('Expect to return success with greeting when name provided', async () => {
    const response = await service.run(hello, { name: 'test' }, { log: () => {} })
    expect(response).toStrictEqual(res.success('Hello test - what a beautiful name!'))
  })
  
  test('Logs upon receiving request', async () => {
    const log = jest.fn()
    await service.run(hello, { name: 'test' }, { log })
    expect(log).toHaveBeenCalledWith('Received request to greet "test"')
  })
})
0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.8

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.7-beta1

3 years ago

0.0.7-beta4

3 years ago

0.0.7-beta3

3 years ago

0.0.7-beta2

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

1.0.1

3 years ago