Skip to content

Commit

Permalink
Initial Hono + D1 rewrite
Browse files Browse the repository at this point in the history
Worker has been rewritten to use Hono router and Cloudflare D1 storage with Drizzle ORM
  • Loading branch information
jake-walker committed Jan 27, 2024
1 parent 871c68e commit cbd0ed9
Show file tree
Hide file tree
Showing 27 changed files with 4,660 additions and 4,007 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ jobs:
cypress-run:
runs-on: ubuntu-latest
services:
dynamodb:
image: amazon/dynamodb-local:latest
ports:
- 8000:8000
minio:
image: bitnami/minio:latest
env:
Expand All @@ -22,7 +18,7 @@ jobs:
- name: Setup Node
uses: actions/[email protected]
with:
node-version: 16
node-version: 20
- name: Get cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -34,13 +30,6 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Create DynamoDB Table
uses: giboow/action-aws-cli@v1
with:
args: dynamodb --endpoint-url http://dynamodb:8000 create-table --region eu-west-1 --table-name vh7 --key-schema AttributeName=id,KeyType=HASH --attribute-definitions AttributeName=id,AttributeType=S --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
env:
AWS_ACCESS_KEY_ID: testid
AWS_SECRET_ACCESS_KEY: testkey
- name: Create S3 Bucket
uses: giboow/action-aws-cli@v1
with:
Expand All @@ -62,10 +51,6 @@ jobs:
S3_DEFAULT_REGION: eu-west-1
S3_ENDPOINT_URL: http://localhost:9000
S3_BUCKET: vh7-uploads
DYNAMODB_ACCESS_KEY_ID: testid
DYNAMODB_SECRET_ACCESS_KEY: testkey
DYNAMODB_TABLE: vh7
DYNAMODB_ENDPOINT_URL: http://localhost:8000
VH7_ENV: testing
SENTRY_DSN: ${{ secrets.WORKER_SENTRY_DSN }}
SENTRY_CLIENT_ID: ${{ secrets.WORKER_SENTRY_CLIENT_ID }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup Node
uses: actions/[email protected]
with:
node-version: 16
node-version: 20
- name: Get cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -27,16 +27,16 @@ jobs:
working-directory: ./worker
run: |
yarn install --dev
yarn global add @cloudflare/wrangler
yarn global add wrangler
- name: Migrate database
working-directory: ./worker
run: wrangler d1 migrations apply DB --local
- name: Lint
working-directory: ./worker
run: yarn run lint
# - name: Test
# working-directory: ./worker
# run: yarn run test
- name: Build
- name: Test
working-directory: ./worker
run: wrangler build
run: yarn run test
deploy:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,4 @@ accessgrant.txt
cleanup/backup-*
app/cypress/downloads
cleanup/prod.env
.wrangler
25 changes: 0 additions & 25 deletions cleanup/config.js

This file was deleted.

89 changes: 0 additions & 89 deletions cleanup/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions cleanup/package.json

This file was deleted.

13 changes: 0 additions & 13 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
version: '3.8'
services:
dynamodb:
image: amazon/dynamodb-local:latest
ports:
- "8100:8000"
init-dynamodb:
image: amazon/aws-cli:latest
command: "dynamodb --endpoint-url http://dynamodb:8000 create-table --region eu-west-1 --table-name vh7 --key-schema AttributeName=id,KeyType=HASH --attribute-definitions AttributeName=id,AttributeType=S --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 > /dev/null"
environment:
- "AWS_ACCESS_KEY_ID=DUMMYIDEXAMPLE"
- "AWS_SECRET_ACCESS_KEY=DUMMYEXAMPLEKEY"
depends_on:
dynamodb:
condition: service_started
minio:
image: minio/minio:latest
command: "server /data -console-address ':9001'"
Expand Down
28 changes: 28 additions & 0 deletions worker/migrations/0000_fair_donald_blake.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE short_link_paste (
`short_link_id` text PRIMARY KEY NOT NULL,
`code` text NOT NULL,
`language` text,
FOREIGN KEY (`short_link_id`) REFERENCES short_link(`id`)
);

CREATE TABLE short_link_upload (
`short_link_id` text PRIMARY KEY NOT NULL,
`filename` text NOT NULL,
`size` integer NOT NULL,
`hash` text NOT NULL,
FOREIGN KEY (`short_link_id`) REFERENCES short_link(`id`)
);

CREATE TABLE short_link_url (
`short_link_id` text PRIMARY KEY NOT NULL,
`url` text NOT NULL,
FOREIGN KEY (`short_link_id`) REFERENCES short_link(`id`)
);

CREATE TABLE short_link (
`id` text PRIMARY KEY NOT NULL,
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
`expires_at` integer,
`type` text NOT NULL
);
42 changes: 13 additions & 29 deletions worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,36 @@
"name": "worker",
"version": "1.0.0",
"private": true,
"main": "dist/worker.js",
"type": "module",
"devDependencies": {
"@cloudflare/workers-types": "^3.3.0",
"@types/itty-router-extras": "^0.4.0",
"@types/service-worker-mock": "^2.0.1",
"@cloudflare/workers-types": "^4.20230321.0",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"ava": "^4.0.1",
"better-sqlite3": "^8.0.0",
"drizzle-kit": "^0.20.13",
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^16.1.0",
"eslint-plugin-import": "^2.22.1",
"form-data": "^4.0.0",
"miniflare": "",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"tsx": "^4.7.0",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
"vitest": "^1.2.1",
"wrangler": "^3.24.0"
},
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.150.0",
"@aws-sdk/lib-dynamodb": "^3.150.0",
"aws4fetch": "^1.0.13",
"itty-router": "^2.4.10",
"itty-router-extras": "^0.4.2",
"korma-kv": "^1.0.2",
"drizzle-orm": "^0.29.3",
"hono": "^3.12.7",
"nanoid": "^3.1.30",
"toucan-js": "^2.6.1",
"zod": "^3.11.6"
"zod": "^3.22.4"
},
"scripts": {
"lint": "eslint ./src",
"dev": "miniflare --debug --watch",
"preview": "miniflare",
"dev": "wranger dev",
"build": "webpack",
"publish": "wranger publish",
"test": "yarn run build && ava --verbose test/*.spec.ts"
},
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
]
"test": "vitest --run",
"migrate:generate": "drizzle-kit generate:sqlite --schema ./src/models.ts --out=./migrations",
"migrate:up": "drizzle-kit up:sqlite"
}
}
19 changes: 0 additions & 19 deletions worker/src/bindings.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions worker/src/config.ts

This file was deleted.

Loading

0 comments on commit cbd0ed9

Please sign in to comment.