generated from TypeScriptPlayground/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
202 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
/// <reference lib="deno.ns" /> | ||
import * as esbuild from 'https://deno.land/x/[email protected]/mod.js'; | ||
import { green } from 'https://deno.land/[email protected]/fmt/colors.ts'; | ||
import { parseArgs } from 'https://deno.land/[email protected]/cli/parse_args.ts'; | ||
|
||
const args = parseArgs<{ | ||
watch: boolean | undefined, | ||
develope: boolean | undefined, | ||
logLevel: esbuild.LogLevel | ||
}>(Deno.args); | ||
|
||
const filesConfig : esbuild.BuildOptions = { | ||
allowOverwrite: true, | ||
logLevel: args.logLevel ?? 'info', | ||
legalComments: args.develope ? 'inline' : 'none', | ||
color: true, | ||
minify: !args.develope ?? true, | ||
bundle: true, | ||
format: 'esm', | ||
target: 'es2022', | ||
sourcemap: args.develope ?? false, | ||
sourcesContent: args.develope ?? false, | ||
outfile: 'worker/worker.js', | ||
entryPoints: [ | ||
'./src/index.ts' | ||
], | ||
} | ||
|
||
console.log('Build process started.'); | ||
|
||
const timestampNow = Date.now(); | ||
|
||
if (args.watch) { | ||
esbuild.context(filesConfig).then((context) => context.watch()); | ||
} else { | ||
esbuild.build(filesConfig).then(() => { | ||
esbuild.stop(); | ||
console.log(green(`esbuild ${esbuild.version} finished build in ${(Date.now() - timestampNow).toString()}ms.`)); | ||
}) | ||
} | ||
/// <reference lib="deno.ns" /> | ||
import * as esbuild from 'https://deno.land/x/[email protected]/mod.js'; | ||
import { green } from 'https://deno.land/[email protected]/fmt/colors.ts'; | ||
import { parseArgs } from 'https://deno.land/[email protected]/cli/parse_args.ts'; | ||
|
||
const args = parseArgs<{ | ||
watch: boolean | undefined, | ||
develope: boolean | undefined, | ||
logLevel: esbuild.LogLevel | ||
}>(Deno.args); | ||
|
||
const filesConfig : esbuild.BuildOptions = { | ||
allowOverwrite: true, | ||
logLevel: args.logLevel ?? 'info', | ||
legalComments: args.develope ? 'inline' : 'none', | ||
color: true, | ||
minify: !args.develope ?? true, | ||
bundle: true, | ||
format: 'esm', | ||
target: 'es2022', | ||
sourcemap: args.develope ?? false, | ||
sourcesContent: args.develope ?? false, | ||
outfile: 'worker/worker.js', | ||
entryPoints: [ | ||
'./src/index.ts' | ||
], | ||
} | ||
|
||
console.log('Build process started.'); | ||
|
||
const timestampNow = Date.now(); | ||
|
||
if (args.watch) { | ||
esbuild.context(filesConfig).then((context) => context.watch()); | ||
} else { | ||
esbuild.build(filesConfig).then(() => { | ||
esbuild.stop(); | ||
console.log(green(`esbuild ${esbuild.version} finished build in ${(Date.now() - timestampNow).toString()}ms.`)); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
{ | ||
"tasks": { | ||
"build": "deno run -A ./build.config.ts", | ||
"build:watch": "deno run -A ./build.config.ts --watch", | ||
"build:dev": "deno run -A ./build.config.ts --develope", | ||
"build:dev:watch": "deno run -A ./build.config.ts --develope --watch", | ||
"lint": "deno lint", | ||
"test": "deno test -A --check --reload --doc --allow-none --junit-path=\"./report.xml\"" | ||
}, | ||
"exclude": [ | ||
"./dist/", | ||
"./worker/" | ||
], | ||
"test": { | ||
"include": [ | ||
"**/*.test.ts" | ||
] | ||
}, | ||
"compilerOptions": { | ||
"experimentalDecorators": true, | ||
"lib": [ | ||
"ES6", | ||
"DOM", | ||
"DOM.Iterable" | ||
] | ||
}, | ||
"fmt": { | ||
"singleQuote": true, | ||
"lineWidth": 120 | ||
}, | ||
"lint": { | ||
"rules": { | ||
"tags": [ | ||
"recommended" | ||
], | ||
"include": [ | ||
"camelcase", | ||
"default-param-last", | ||
"eqeqeq", | ||
"explicit-function-return-type", | ||
"explicit-module-boundary-types", | ||
"guard-for-in", | ||
"no-eval", | ||
"no-sparse-arrays", | ||
"prefer-ascii" | ||
], | ||
"exclude": [ | ||
"no-inferrable-types" | ||
] | ||
} | ||
} | ||
} | ||
{ | ||
"tasks": { | ||
"build": "deno run -A ./build.config.ts", | ||
"build:watch": "deno run -A ./build.config.ts --watch", | ||
"build:dev": "deno run -A ./build.config.ts --develope", | ||
"build:dev:watch": "deno run -A ./build.config.ts --develope --watch", | ||
"lint": "deno lint", | ||
"test": "deno test -A --check --reload --doc --allow-none --junit-path=\"./report.xml\"" | ||
}, | ||
"exclude": [ | ||
"./dist/", | ||
"./worker/" | ||
], | ||
"test": { | ||
"include": [ | ||
"**/*.test.ts" | ||
] | ||
}, | ||
"compilerOptions": { | ||
"experimentalDecorators": true, | ||
"lib": [ | ||
"ES6", | ||
"DOM", | ||
"DOM.Iterable" | ||
] | ||
}, | ||
"fmt": { | ||
"singleQuote": true, | ||
"lineWidth": 120 | ||
}, | ||
"lint": { | ||
"rules": { | ||
"tags": [ | ||
"recommended" | ||
], | ||
"include": [ | ||
"camelcase", | ||
"default-param-last", | ||
"eqeqeq", | ||
"explicit-function-return-type", | ||
"explicit-module-boundary-types", | ||
"guard-for-in", | ||
"no-eval", | ||
"no-sparse-arrays", | ||
"prefer-ascii" | ||
], | ||
"exclude": [ | ||
"no-inferrable-types" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { endpoints } from './endpoints.ts'; | ||
|
||
export default function dnsRecordsUrl( | ||
zoneId : string, | ||
filter? : Record<string, string>[] | ||
) : string { | ||
const filterString = filter?.map((key_value) => `${Object.keys(key_value)[0]}=${key_value[0]}`) | ||
return `${endpoints.BASE}zones/${zoneId}/dns_records/?${filterString?.join('&')}` | ||
} | ||
import { endpoints } from './endpoints.ts'; | ||
|
||
export default function dnsRecordsUrl( | ||
zoneId : string, | ||
filter? : Record<string, string>[] | ||
) : string { | ||
const filterString = filter?.map((key_value) => `${Object.keys(key_value)[0]}=${key_value[0]}`) | ||
return `${endpoints.BASE}zones/${zoneId}/dns_records/?${filterString?.join('&')}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const endpoints = { | ||
BASE: "https://api.cloudflare.com/client/v4/" | ||
} | ||
export const endpoints = { | ||
BASE: "https://api.cloudflare.com/client/v4/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import buildUrlWithFilter from './url/build_url_with_filter.ts'; | ||
import { ListDNSRecordsResponse } from './response/list_dns_records_response.ts'; | ||
import { parseUrlParameters } from './url/parse_url_parameters.ts'; | ||
import { endpoints } from './api/endpoints.ts'; | ||
import getAllDnsRecords from './record/get_all_dns_records.ts'; | ||
|
||
|
||
|
||
export default { | ||
/** | ||
* [Reference](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/) | ||
* @param request Incoming http request | ||
*/ | ||
async fetch(request : Request) : Promise<void> { | ||
const urlParameters = parseUrlParameters(new URL(request.url).searchParams); | ||
const { | ||
token, | ||
zoneId, | ||
records | ||
} = urlParameters; | ||
|
||
const authorizationHeader = { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${token}` | ||
} | ||
|
||
getAllDnsRecords( | ||
`${endpoints.BASE}zones/${zoneId}/dns_records/`, | ||
authorizationHeader | ||
).then((response) => { | ||
response | ||
}) | ||
|
||
records.forEach(({type, name}) => { | ||
|
||
}) | ||
} | ||
} | ||
import buildUrlWithFilter from './url/build_url_with_filter.ts'; | ||
import { ListDNSRecordsResponse } from './response/list_dns_records_response.ts'; | ||
import { parseUrlParameters } from './url/parse_url_parameters.ts'; | ||
import { endpoints } from './api/endpoints.ts'; | ||
import getAllDnsRecords from './record/get_all_dns_records.ts'; | ||
|
||
|
||
|
||
export default { | ||
/** | ||
* [Reference](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/) | ||
* @param request Incoming http request | ||
*/ | ||
async fetch(request : Request) : Promise<void> { | ||
const urlParameters = parseUrlParameters(new URL(request.url).searchParams); | ||
const { | ||
token, | ||
zoneId, | ||
records | ||
} = urlParameters; | ||
|
||
const authorizationHeader = { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${token}` | ||
} | ||
|
||
getAllDnsRecords( | ||
`${endpoints.BASE}zones/${zoneId}/dns_records/`, | ||
authorizationHeader | ||
).then((response) => { | ||
response | ||
}) | ||
|
||
records.forEach(({type, name}) => { | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { DNSRecord } from './dns_record.ts'; | ||
|
||
export default function getAllDnsRecords( | ||
url : string, | ||
authorizationHeader : {} | ||
) : Promise<DNSRecord[]> { | ||
return fetch( | ||
url, | ||
{headers: authorizationHeader} | ||
).then(response => response.json()) as Promise<DNSRecord[]> | ||
} | ||
import { DNSRecord } from './dns_record.ts'; | ||
|
||
export default function getAllDnsRecords( | ||
url : string, | ||
authorizationHeader : {} | ||
) : Promise<DNSRecord[]> { | ||
return fetch( | ||
url, | ||
{headers: authorizationHeader} | ||
).then(response => response.json()) as Promise<DNSRecord[]> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { DNSRecord } from '../record/dns_record.ts'; | ||
|
||
export interface ListDNSRecordsResponse { | ||
errors : [], | ||
messages : [], | ||
result : DNSRecord[], | ||
success : boolean, | ||
result_info : { | ||
count : number, | ||
page : number, | ||
per_page : number, | ||
total_count : number | ||
} | ||
} | ||
import { DNSRecord } from '../record/dns_record.ts'; | ||
|
||
export interface ListDNSRecordsResponse { | ||
errors : [], | ||
messages : [], | ||
result : DNSRecord[], | ||
success : boolean, | ||
result_info : { | ||
count : number, | ||
page : number, | ||
per_page : number, | ||
total_count : number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export default function buildUrlWithFilter( | ||
url : string, | ||
filter? : Record<string, string> | ||
) : string { | ||
if (filter) { | ||
return `${url}/?${Object.entries(filter).map(([key, value]) => `${key}=${value}`).join('&')}` | ||
} | ||
|
||
return url; | ||
} | ||
export default function buildUrlWithFilter( | ||
url : string, | ||
filter? : Record<string, string> | ||
) : string { | ||
if (filter) { | ||
return `${url}/?${Object.entries(filter).map(([key, value]) => `${key}=${value}`).join('&')}` | ||
} | ||
|
||
return url; | ||
} |
Oops, something went wrong.