Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
willswire committed Jul 13, 2024
1 parent 007a3e0 commit c83e49f
Show file tree
Hide file tree
Showing 9 changed files with 3,036 additions and 1,624 deletions.
4,465 changes: 2,936 additions & 1,529 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 25 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
{
"name": "cloudflare-workers-openapi",
"version": "0.0.1",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types"
},
"dependencies": {
"@cloudflare/itty-router-openapi": "^1.0.1"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"@types/node": "20.8.3",
"@types/service-worker-mock": "^2.0.1",
"wrangler": "^3.60.3"
}
"name": "cloudflare-workers-openapi",
"version": "0.0.1",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types"
},
"dependencies": {
"@cloudflare/itty-router-openapi": "^1.0.1",
"@microsoft/eslint-formatter-sarif": "^2.1.7"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"@eslint/js": "^9.7.0",
"eslint": "^9.7.0",
"globals": "^15.8.0",
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.0",
"wrangler": "^3.60.3"
},
"overrides": {
"eslint": "^9.7.0"
}
}
58 changes: 32 additions & 26 deletions src/durableState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,39 @@ import type { LockInfo } from "./types/terraform";
import { DurableObject } from "cloudflare:workers";

export class DurableState extends DurableObject {
async lock(info: LockInfo): Promise<Boolean> {
const currentLock: LockInfo = await this.ctx.storage.get("lock") || null;
if (currentLock === null) {
await this.ctx.storage.put("lock", info);
console.log("State locked successfully by", info.ID);
return true;
} else {
console.log("Lock attempt failed: state is already locked by", currentLock.ID);
return false;
}
async lock(info: LockInfo): Promise<boolean> {
const currentLock: LockInfo = (await this.ctx.storage.get("lock")) || null;
if (currentLock === null) {
await this.ctx.storage.put("lock", info);
console.log("State locked successfully by", info.ID);
return true;
} else {
console.log(
"Lock attempt failed: state is already locked by",
currentLock.ID,
);
return false;
}
}

async unlock(info: LockInfo): Promise<Boolean> {
const currentLock: LockInfo = await this.ctx.storage.get("lock") || null;
if (currentLock && currentLock.ID === info.ID) {
await this.ctx.storage.delete("lock");
console.log("State unlocked successfully by", info.ID);
return true;
} else {
console.log("Unlock attempt failed: state is locked by", currentLock ? currentLock.ID : "none");
return false;
}
async unlock(info: LockInfo): Promise<boolean> {
const currentLock: LockInfo = (await this.ctx.storage.get("lock")) || null;
if (currentLock && currentLock.ID === info.ID) {
await this.ctx.storage.delete("lock");
console.log("State unlocked successfully by", info.ID);
return true;
} else {
console.log(
"Unlock attempt failed: state is locked by",
currentLock ? currentLock.ID : "none",
);
return false;
}
}

async getLockInfo(): Promise<LockInfo> {
const currentLock: LockInfo = await this.ctx.storage.get("lock") || null;
console.log("Current lock info:", currentLock);
return currentLock;
}
}
async getLockInfo(): Promise<LockInfo> {
const currentLock: LockInfo = (await this.ctx.storage.get("lock")) || null;
console.log("Current lock info:", currentLock);
return currentLock;
}
}
7 changes: 4 additions & 3 deletions src/endpoints/stateCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Path,
Query,
} from "@cloudflare/itty-router-openapi";
import type { Env } from "../types/worker-configuration";

export class StateCreate extends OpenAPIRoute {
static schema: OpenAPIRouteSchema = {
Expand Down Expand Up @@ -42,9 +43,9 @@ export class StateCreate extends OpenAPIRoute {

async handle(
request: Request,
env: any,
context: any,
data: Record<string, any>,
env: Env,
context: ExecutionContext,
data: { params: { projectName: string; ID?: string } },
) {
const { projectName } = data.params;

Expand Down
7 changes: 4 additions & 3 deletions src/endpoints/stateDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
OpenAPIRouteSchema,
Path,
} from "@cloudflare/itty-router-openapi";
import type { Env } from "../types/worker-configuration";

export class StateDelete extends OpenAPIRoute {
static schema: OpenAPIRouteSchema = {
Expand Down Expand Up @@ -37,9 +38,9 @@ export class StateDelete extends OpenAPIRoute {

async handle(
request: Request,
env: any,
context: any,
data: Record<string, any>,
env: Env,
context: ExecutionContext,
data: { params: { projectName: string } },
) {
const { projectName } = data.params;

Expand Down
10 changes: 5 additions & 5 deletions src/endpoints/stateFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
OpenAPIRouteSchema,
Path,
} from "@cloudflare/itty-router-openapi";
import type { Env } from "../types/worker-configuration";

export class StateFetch extends OpenAPIRoute {
static schema: OpenAPIRouteSchema = {
Expand Down Expand Up @@ -32,9 +33,9 @@ export class StateFetch extends OpenAPIRoute {

async handle(
request: Request,
env: any,
context: any,
data: Record<string, any>,
env: Env,
context: ExecutionContext,
data: { params: { projectName: string } },
) {
const { projectName } = data.params;

Expand All @@ -43,10 +44,9 @@ export class StateFetch extends OpenAPIRoute {
}

// Implement your own object fetch here
const key: String = `${projectName}.tfstate`;
const key: string = `${projectName}.tfstate`;
const state: R2ObjectBody = await env.TF_STATE_BUCKET.get(key);

// @ts-ignore: check if the object exists
if (state === null) {
return new Response(null, { status: 204 });
}
Expand Down
7 changes: 4 additions & 3 deletions src/endpoints/stateLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Path,
} from "@cloudflare/itty-router-openapi";
import type { LockInfo } from "../types/terraform";
import type { Env } from "../types/worker-configuration";

export class StateLock extends OpenAPIRoute {
static schema: OpenAPIRouteSchema = {
Expand Down Expand Up @@ -50,9 +51,9 @@ export class StateLock extends OpenAPIRoute {

async handle(
request: Request,
env: any,
context: any,
data: Record<string, any>,
env: Env,
context: ExecutionContext,
data: { params: { projectName: string } },
) {
const { projectName } = data.params;

Expand Down
56 changes: 26 additions & 30 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"sourceMap": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["esnext"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"strict": false,
"traceResolution": false,
"outDir": "",
"target": "esnext",
"module": "esnext",
"types": [
"@types/node",
"@types/service-worker-mock",
"@cloudflare/workers-types/2023-07-01"
]
},
"exclude": ["node_modules", "dist", "tests"],
"include": ["src", "scripts"]
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"sourceMap": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["esnext"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"strict": false,
"traceResolution": false,
"outDir": "",
"target": "esnext",
"module": "esnext",
"types": ["@types/node", "@cloudflare/workers-types/2023-07-01"]
},
"exclude": ["node_modules", "dist", "tests"],
"include": ["src", "scripts"]
}
7 changes: 0 additions & 7 deletions worker-configuration.d.ts

This file was deleted.

0 comments on commit c83e49f

Please # to comment.