From fafcad37fc709409fa60087365a88451b0aa3d73 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 2 Feb 2022 09:12:00 +0100 Subject: [PATCH] fix: add durable object types --- packages/api/package.json | 2 +- packages/gateway/package.json | 1 + packages/gateway/src/env.js | 30 ++++++++++++++++++++++++++---- yarn.lock | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 4e8e60684a..872a9203a0 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -33,7 +33,7 @@ "uint8arrays": "^3.0.0" }, "devDependencies": { - "@cloudflare/workers-types": "^3.1.1", + "@cloudflare/workers-types": "^3.3.1", "@sentry/cli": "^1.71.0", "@sentry/webpack-plugin": "^1.16.0", "@types/debug": "^4.1.5", diff --git a/packages/gateway/package.json b/packages/gateway/package.json index aa2d1d9f9d..a88bd1d72b 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -28,6 +28,7 @@ "toucan-js": "^2.5.0" }, "devDependencies": { + "@cloudflare/workers-types": "^3.3.1", "@sentry/cli": "^1.71.0", "ava": "^3.15.0", "delay": "^5.0.0", diff --git a/packages/gateway/src/env.js b/packages/gateway/src/env.js index dd4005bac7..f86031cd27 100644 --- a/packages/gateway/src/env.js +++ b/packages/gateway/src/env.js @@ -2,7 +2,6 @@ import Toucan from 'toucan-js' import pkg from '../package.json' import { Logging } from './logs.js' -// TODO: Get Durable object typedef /** * @typedef {Object} EnvInput * @property {string} IPFS_GATEWAYS @@ -20,9 +19,9 @@ import { Logging } from './logs.js' * * @typedef {Object} EnvTransformed * @property {Array} ipfsGateways - * @property {Object} gatewayMetricsDurable - * @property {Object} summaryMetricsDurable - * @property {Object} cidsTrackerDurable + * @property {DurableObjectNamespace} gatewayMetricsDurable + * @property {DurableObjectNamespace} summaryMetricsDurable + * @property {DurableObjectNamespace} cidsTrackerDurable * @property {number} REQUEST_TIMEOUT * @property {Toucan} [sentry] * @property {Logging} [log] @@ -72,3 +71,26 @@ function getSentry(request, env) { pkg, }) } + +/** + * From: https://github.com/cloudflare/workers-types + * + * @typedef {{ + * toString(): string + * equals(other: DurableObjectId): boolean + * readonly name?: string + * }} DurableObjectId + * + * @typedef {{ + * newUniqueId(options?: { jurisdiction?: string }): DurableObjectId + * idFromName(name: string): DurableObjectId + * idFromString(id: string): DurableObjectId + * get(id: DurableObjectId): DurableObjectStub + * }} DurableObjectNamespace + * + * @typedef {{ + * readonly id: DurableObjectId + * readonly name?: string + * fetch(requestOrUrl: Request | string, requestInit?: RequestInit | Request): Promise + * }} DurableObjectStub + */ diff --git a/yarn.lock b/yarn.lock index cac93c41e2..513070db54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2028,7 +2028,7 @@ resolved "https://registry.yarnpkg.com/@cfworker/json-schema/-/json-schema-1.12.1.tgz#8b151da771678d37bf77c5eda87b1137b2b009c8" integrity sha512-ZVhk1DKw19sBJgO7OHBsvNAzDfHMzpFI0DCkOLTZHb0dccmS+EM8rwwAYh5eaNmD5t8/nCbZ2ZeGzbDQdOzokQ== -"@cloudflare/workers-types@^3.1.1": +"@cloudflare/workers-types@^3.3.1": version "3.3.1" resolved "https://registry.yarnpkg.com/@cloudflare/workers-types/-/workers-types-3.3.1.tgz#8847543bda320472252708c29aaf7bac3374e814" integrity sha512-GJFDgWd8ZHlr/m+Q2mp4xUl0/FIPpR6kf0Ix2C78E9HeJyUCW0c0w2EKCvgEDFFKB2rkzIX3eBqZCnLsbsw8zQ==