0.0.32 • Published 1 year ago

@uncloud-sdk/lib v0.0.32

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.8

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.7-beta1

1 year ago

0.0.7-beta4

1 year ago

0.0.7-beta3

1 year ago

0.0.7-beta2

1 year ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

1.0.1

2 years ago