Skip to content

Commit 6828f61

Browse files
committed
refactor(connect): handroll simple Either in lieu of crocks. adjust deno permissions
1 parent 6b224f3 commit 6828f61

File tree

10 files changed

+62
-23
lines changed

10 files changed

+62
-23
lines changed

.github/workflows/connect.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- name: ⚡ Run Tests
3434
run: |
3535
cd packages/connect
36+
deno install
3637
deno task test
3738
env:
3839
CI: true

packages/connect/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ clean:
66
# to copy the types from the output of deno2node into the microbundle output folder in order to get types working
77
# a total hack to get the types working
88
to-node:
9-
@deno run --no-check --allow-read --allow-write \
9+
@deno run --no-check --allow-read --allow-write --allow-env --allow-import \
1010
https://deno.land/x/[email protected]/src/cli.ts ./tsconfig.to-node.jsonc && \
1111
yarn build && \
1212
echo "copying types..." && find ./to-node -mindepth 1 -depth -name '*.d.ts' -exec cp --parents \{\} ./dist \; && \

packages/connect/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tasks": {
3-
"cache": "deno cache --lock=deno.lock --lock-write deno/deps.deno.ts deno/dev_deps.ts",
3+
"cache": "deno cache --lock=deno.lock -A deno/deps.deno.ts deno/dev_deps.ts",
44
"test": "deno lint && deno fmt && deno test -A --no-lock --no-check deno/tests",
55
"test:integration": "make test-integration",
66
"to-node": "make clean to-node"

packages/connect/deno.lock

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/connect/deno/deps.deno.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ export { default as ms } from 'npm:ms@^2'
55

66
// @deno-types="npm:@types/ramda@^0.28.23"
77
export * as R from 'npm:[email protected]'
8-
// deno-lint-ignore ban-ts-comment
9-
// @ts-ignore
10-
export { default as crocks } from 'npm:[email protected]'
118

129
/**
1310
* See deps.node.ts for shims of below

packages/connect/deno/deps.node.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
export * as R from 'ramda'
1111
export { default as ms } from 'ms'
1212

13-
// @ts-nocheck crocks types are not up to date, and we don't use them anyway
14-
export { default as crocks } from 'crocks'
15-
1613
import { SignJWT } from 'jose'
1714
import { BinaryToTextEncoding, createHmac, createSecretKey } from 'crypto'
1815
import { lookup } from 'mime-types'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export class Either {
2+
constructor(value) {
3+
this.value = value
4+
}
5+
6+
static Left(value) {
7+
return new _Left(value)
8+
}
9+
10+
static Right(value) {
11+
return new _Right(value)
12+
}
13+
14+
isLeft() {
15+
return this instanceof _Left
16+
}
17+
18+
isRight() {
19+
return this instanceof _Right
20+
}
21+
22+
map(fn) {
23+
return this.isRight() ? Either.Right(fn(this.value)) : this
24+
}
25+
26+
chain(fn) {
27+
return this.isRight() ? fn(this.value) : this
28+
}
29+
30+
either(leftFn, rightFn) {
31+
return this.isLeft() ? leftFn(this.value) : rightFn(this.value)
32+
}
33+
}
34+
35+
class _Left extends Either {
36+
constructor(value) {
37+
super(value)
38+
}
39+
}
40+
41+
class _Right extends Either {
42+
constructor(value) {
43+
super(value)
44+
}
45+
}
46+
47+
export const Right = Either.Right
48+
export const Left = Either.Left

packages/connect/deno/utils/hyper-verify.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// deno-lint-ignore-file ban-ts-comment
2-
import { crocks, hmac, ms, R } from '../deps.deno.ts'
2+
import { hmac, ms, R } from '../deps.deno.ts'
33
import { Result } from '../types.ts'
4+
import { Left, Right } from './either.js'
45
const {
56
assoc,
67
compose,
@@ -12,7 +13,6 @@ const {
1213
path,
1314
identity,
1415
} = R
15-
const { of, Left, Right } = crocks.Either
1616

1717
interface Parsed {
1818
time: number
@@ -105,7 +105,7 @@ const handleSuccess = () => ({ ok: true })
105105
*/
106106
export function createHyperVerify(secret: string, ttl?: string) {
107107
return function (signature: string, payload: unknown): Result {
108-
return of({ input: { signature, payload }, secret, ttl })
108+
return Right({ input: { signature, payload }, secret, ttl })
109109
.map(splitHyperSignature)
110110
.chain(createHmacSignature)
111111
.chain(compareSignatures)

packages/connect/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"build": "microbundle --tsconfig tsconfig.ci.jsonc"
2727
},
2828
"dependencies": {
29-
"crocks": "^0.12.4",
3029
"jose": "^5.1.3",
3130
"mime-types": "^2.1.35",
3231
"ms": "^2.1.3",

packages/connect/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,11 +1481,6 @@ cosmiconfig@^7.0.0:
14811481
path-type "^4.0.0"
14821482
yaml "^1.10.0"
14831483

1484-
crocks@^0.12.4:
1485-
version "0.12.4"
1486-
resolved "https://registry.npmjs.org/crocks/-/crocks-0.12.4.tgz"
1487-
integrity sha512-paln6xJUrR9e/OWMFsyTi4dLyr+q99C5f7PQbGgSDHtwsfW0sCNZvnpHzvniI2dAE0uoBgeIP1Ukmme8Z0HxxA==
1488-
14891484
css-declaration-sorter@^6.2.2:
14901485
version "6.2.2"
14911486
resolved "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-6.2.2.tgz"

0 commit comments

Comments
 (0)