Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect: Add queue.create and queue.destroy #620

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM gitpod/workspace-full

USER gitpod

RUN echo "force image rebuild: 123"
RUN echo "force image rebuild: 456"

RUN curl -fsSL https://deno.land/x/install/install.sh | sh
RUN /home/gitpod/.deno/bin/deno completions bash > /home/gitpod/.bashrc.d/90-deno && echo 'export DENO_INSTALL="/home/gitpod/.deno"' >> /home/gitpod/.bashrc.d/90-deno && echo 'export PATH="$DENO_INSTALL/bin:$PATH"' >> /home/gitpod/.bashrc.d/90-deno
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tasks": {
"cache": "deno cache --lock=deno.lock --lock-write deno/deps.deno.ts deno/dev_deps.ts",
"test": "deno lint && deno fmt && deno test -A --no-lock --unstable deno/tests",
"test": "deno lint && deno fmt && deno test -A --no-lock deno/tests",
"test:integration": "make test-integration",
"to-node": "make clean to-node"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/connect/deno/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ export function connect(CONNECTION_STRING: string, domain = 'default'): Hyper {
.then(queue.queued())
.then($fetch)
.then(handleResponse),
create: (target, secret) =>
Promise.resolve(h)
.then(queue.create(target, secret))
.then($fetch)
.then(handleResponse),
destroy: (confirm) =>
Promise.resolve(h)
.then(queue.destroy(confirm))
.then($fetch)
.then(handleResponse),
},
info: {
services: () =>
Expand Down
8 changes: 8 additions & 0 deletions packages/connect/deno/services/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ export const errors = () => (h: HyperRequestFunction) =>

export const queued = () => (h: HyperRequestFunction) =>
h({ service, method: Method.GET, params: { status: QueueStatus.READY } })

export const create = (target: string, secret?: string) => (hyper: HyperRequestFunction) =>
hyper({ service, method: Method.PUT, body: { target, secret } })

export const destroy = (confirm?: boolean) => (hyper: HyperRequestFunction) =>
confirm
? hyper({ service, method: Method.DELETE })
: Promise.reject({ ok: false, msg: 'request not confirmed!' })
3 changes: 3 additions & 0 deletions packages/connect/deno/tests/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ test('cache.destroy', async () => {

const noConfirmRequest = (_h: HyperRequest) => {
assert(false, 'unreachable')
return Promise.resolve(
new Request('http://localhost', { method: 'DELETE' }),
)
}

await destroy()(noConfirmRequest).catch(assert)
Expand Down
3 changes: 3 additions & 0 deletions packages/connect/deno/tests/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ test('data.destroy', async () => {

const noConfirmRequest = (_h: HyperRequest) => {
assert(false, 'unreachable')
return Promise.resolve(
new Request('http://localhost', { method: 'DELETE' }),
)
}

await destroy()(noConfirmRequest).catch(assert)
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/deno/tests/hyper-verify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Deno.test('Verify: Compare Secret Signatures Successfully', () => {
assertEquals(result.ok, true)
})

Deno.test('Verify: Compare Signatures that don\'t match ', () => {
Deno.test("Verify: Compare Signatures that don't match ", () => {
const time = new Date()
const s = hmac(
'sha256',
Expand Down
46 changes: 45 additions & 1 deletion packages/connect/deno/tests/queue.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HyperRequest } from '../types.ts'
import { assertEquals } from '../dev_deps.ts'
import { assert, assertEquals } from '../dev_deps.ts'

import { enqueue, errors, queued } from '../services/queue.ts'
import { create } from '../services/queue.ts'
import { destroy } from '../services/queue.ts'

const test = Deno.test

Expand Down Expand Up @@ -57,3 +59,45 @@ test('queue.queued', async () => {
const request = await queued()(mockRequest)
assertEquals(request.url, 'http://localhost/?status=READY')
})

test('queue.create', async () => {
const mockRequest = (h: HyperRequest) => {
assertEquals(h.service, 'queue')
assertEquals(h.method, 'PUT')
return Promise.resolve(
new Request('http://localhost', {
method: 'PUT',
body: JSON.stringify(h.body),
}),
)
}

const result = await create('https://foo.bar', 'shhhh')(mockRequest)
const body = await result.json()
assertEquals(body, { target: 'https://foo.bar', secret: 'shhhh' })

const noSecret = await create('https://foo.bar')(mockRequest)
const noSecertBody = await noSecret.json()
assertEquals(noSecertBody, { target: 'https://foo.bar' })
})

test('queue.destroy', async () => {
const mockRequest = (h: HyperRequest) => {
assertEquals(h.service, 'queue')
assertEquals(h.method, 'DELETE')
return Promise.resolve(
new Request('http://localhost', { method: 'DELETE' }),
)
}

await destroy(true)(mockRequest)

const noConfirmRequest = (_h: HyperRequest) => {
assert(false, 'unreachable')
return Promise.resolve(
new Request('http://localhost', { method: 'DELETE' }),
)
}

await destroy()(noConfirmRequest).catch(assert)
})
3 changes: 3 additions & 0 deletions packages/connect/deno/tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ test('search.destroy', async () => {

const noConfirmRequest = (_h: HyperRequest) => {
assert(false, 'unreachable')
return Promise.resolve(
new Request('http://localhost', { method: 'DELETE' }),
)
}

await destroy()(noConfirmRequest).catch(assert)
Expand Down
3 changes: 3 additions & 0 deletions packages/connect/deno/tests/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ test('storage.destroy', async () => {

const noConfirmRequest = (_h: HyperRequest) => {
assert(false, 'unreachable')
return Promise.resolve(
new Request('http://localhost', { method: 'DELETE' }),
)
}

await destroy()(noConfirmRequest).catch(assert)
Expand Down
5 changes: 5 additions & 0 deletions packages/connect/deno/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ export interface HyperQueue {
enqueue: <Job>(job: Job) => Promise<Result>
errors: <Job>() => Promise<Job[]>
queued: <Job>() => Promise<Job[]>
create: (
target: string,
secret?: string,
) => Promise<Result>
destroy: (confirm: boolean) => Promise<Result>
}

export interface HyperRequest {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/node/tests/hyper-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('Verify: Compare Secret Signatures Successfully', () => {
assert.equal(result.ok, true)
})

test('Verify: Compare Signatures that don\'t match ', () => {
test("Verify: Compare Signatures that don't match ", () => {
const time = new Date()
const s = hmac(
'sha256',
Expand Down
Loading