Skip to content

Commit

Permalink
WIP types
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Oct 3, 2024
1 parent 72f2f99 commit adb2f57
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
9 changes: 8 additions & 1 deletion fixtures/worker-ts/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#:schema node_modules/wrangler/config-schema.json

name = "worker-ts"
main = "src/index.ts"
compatibility_date = "2023-05-04"

[vars]
HELLO="WORLD"

[[d1_databases]]
binding = "MY_DB"

[[kv_namespaces]]
binding = "SOME"
binding = "MY_KV_NAMESPACE"

[[r2_buckets]]
binding = "MY_BUCKET"
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Other"
],
"repository": "https://github.com/cloudflare/workers-sdk",
"publisher": "cloudflare",
"main": "./dist/extension.js",
"scripts": {
"vscode:prepublish": "pnpm run package",
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/api/startDevWorker/ConfigController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async function resolveBindings(
input: StartDevWorkerInput
): Promise<{ bindings: StartDevWorkerOptions["bindings"]; unsafe?: CfUnsafe }> {
const bindings = getBindings(config, input.env, !input.dev?.remote, {
// @ts-expect-error fixme
kv: extractBindingsOfType("kv_namespace", input.bindings),
vars: Object.fromEntries(
extractBindingsOfType("plain_text", input.bindings).map((b) => [
Expand All @@ -143,6 +144,7 @@ async function resolveBindings(
"durable_object_namespace",
input.bindings
),
// @ts-expect-error fixme
r2: extractBindingsOfType("r2_bucket", input.bindings),
services: extractBindingsOfType("service", input.bindings),
d1Databases: extractBindingsOfType("d1", input.bindings),
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the KV Namespace */
binding: string;
/** The ID of the KV namespace */
id: string;
id?: string;
/** The ID of the KV namespace used during `wrangler dev` */
preview_id?: string;
}[];
Expand Down Expand Up @@ -534,7 +534,7 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the R2 bucket in the Worker. */
binding: string;
/** The name of this R2 bucket at the edge. */
bucket_name: string;
bucket_name?: string;
/** The preview name of this R2 bucket at the edge. */
preview_bucket_name?: string;
/** The jurisdiction that the bucket exists in. Default if not present. */
Expand All @@ -554,9 +554,9 @@ export interface EnvironmentNonInheritable {
/** The binding name used to refer to the D1 database in the Worker. */
binding: string;
/** The name of this D1 database. */
database_name: string;
database_name?: string;
/** The UUID of this D1 database (not required). */
database_id: string;
database_id?: string;
/** The UUID of this D1 database for Wrangler Dev (if specified). */
preview_database_id?: string;
/** The name of the migrations table for this D1 database (defaults to 'd1_migrations'). */
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/d1/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function getDatabaseInfoFromConfig(
uuid: d1Database.database_id,
previewDatabaseUuid: d1Database.preview_database_id,
binding: d1Database.binding,
// @ts-expect-error fixme
name: d1Database.database_name,
migrationsTableName:
d1Database.migrations_table || DEFAULT_MIGRATION_TABLE,
Expand Down
8 changes: 5 additions & 3 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ async function ensureBindingsExist(
name: string,
bindings: CfWorkerInit["bindings"]
): Promise<CfWorkerInit["bindings"]> {
if (dryRun) return bindings;
if (dryRun) {
return bindings;
}

assert(accountId, "Missing accountId");

Expand All @@ -389,8 +391,8 @@ async function ensureBindingsExist(
settings.bindings.map((b) => [b.name, b])
);

let creators = [];
let toCreate: CfWorkerInit["bindings"] = {
const creators = [];
const toCreate: CfWorkerInit["bindings"] = {
vars: undefined,
kv_namespaces: undefined,
send_email: undefined,
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/deployment-bundle/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface CfVars {
*/
export interface CfKvNamespace {
binding: string;
id: string;
id?: string;
}

/**
Expand Down Expand Up @@ -160,15 +160,15 @@ export interface CfQueue {

export interface CfR2Bucket {
binding: string;
bucket_name: string;
bucket_name?: string;
jurisdiction?: string;
}

// TODO: figure out if this is duplicated in packages/wrangler/src/config/environment.ts
export interface CfD1Database {
binding: string;
database_id: string;
database_name: string;
database_id?: string;
database_name?: string;
preview_database_id?: string;
database_internal_env?: string;
migrations_table?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,10 @@ export const Handler = async (args: PagesDevArguments) => {
compatibilityFlags,
nodeCompat: nodejsCompatMode === "legacy",
vars,
// @ts-expect-error fixme
kv: kv_namespaces,
durableObjects: do_bindings,
// @ts-expect-error fixme
r2: r2_buckets,
services,
ai,
Expand Down

0 comments on commit adb2f57

Please sign in to comment.