ttraenkler
04/27/2021, 8:26 PMmatt
04/27/2021, 8:27 PMttraenkler
04/27/2021, 8:29 PMmatt
04/27/2021, 8:30 PMttraenkler
04/27/2021, 8:31 PMUnsmart | Tech debt
04/27/2021, 8:55 PMUnsmart | Tech debt
04/27/2021, 8:57 PMMallissin
04/28/2021, 1:08 AMvans163
04/28/2021, 1:21 AMvans163
04/28/2021, 3:14 AMvans163
04/28/2021, 3:14 AMpreethi
04/28/2021, 3:36 AMUnsmart | Tech debt
04/28/2021, 5:30 AMjohn.spurlock
04/28/2021, 2:15 PMcf
object is unavailable in module workers, but it sounds like the info will be available at some point in some form in the future. For DO fetches though, you'll probably always want to pass it in from the original client request https://discord.com/channels/595317990191398933/773219443911819284/834489479833059370vans163
04/28/2021, 2:33 PMYoni
04/28/2021, 7:07 PMtoml
# wrangler.toml
[durable_objects]
bindings = [{name = "ROLE_MANAGER", class_name = "RoleManager"}]
typescript
// role-manager-durable-object.ts
export class RoleManager implements DurableObject {
...
// index.ts
import { RoleManager } from './role-manager-durable-object'
export default {
async fetch(request: Request, env: Env) {
try {
env.ROLE_MANAGER.idFromName('someId')
} catch (e) {
return new Response(e.message)
}
return new Response('')
}
}
export { RoleManager }
and ive run wrangler publish --env production --new-class RoleManager
and this code returns Cannot read property 'idFromName' of undefined
matt
04/28/2021, 9:10 PMEnv
type include the ROLE_MANAGER
property? If so, its very likely the problem here is with your typescript setup -- whats your typescript config and build process look like?Yoni
04/28/2021, 9:11 PMts
export interface Env {
DISCORD_APP_ID: string
DISCORD_PUBLIC_KEY: string
DISCORD_TOKEN: string
ROLE_MANAGER: DurableObjectNamespace
}
it shouldnt affect the code right? in the outputted index.mjs
, i see ...async fetch(e,n){try{n.ROLE_MANAGER...
Yoni
04/28/2021, 9:12 PMYoni
04/28/2021, 9:12 PMjson
{
"compilerOptions": {
"outDir": "./tsc-dist",
"module": "ESNext",
"target": "ES2019",
"lib": ["esnext", "webworker"],
"alwaysStrict": true,
"strict": true,
"preserveConstEnums": true,
"moduleResolution": "node",
"sourceMap": true,
"esModuleInterop": true,
"types": ["@cloudflare/workers-types"]
},
"include": [
"./src/*.ts",
"./src/**/*.ts",
"./node_modules/@cloudflare/workers-types/index.d.ts"
],
"exclude": [
"node_modules/",
"./test/*.ts",
"./test/**/*.ts",
"dist/",
"tsc-dist/"
]
}
Yoni
04/28/2021, 9:12 PMjs
import { terser } from 'rollup-plugin-terser'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
export default {
input: 'tsc-dist/index.js',
output: {
exports: 'named',
format: 'es',
file: 'dist/index.mjs',
sourcemap: false,
},
plugins: [commonjs(), nodeResolve({ browser: true }), terser()],
}
matt
04/28/2021, 9:12 PMmatt
04/28/2021, 9:13 PM[durable_objects]
section isn't inheritedYoni
04/28/2021, 9:13 PMtoml
[env.production.durable_objects]
bindings = [{name = "ROLE_MANAGER", class_name = "RoleManager"}]
?matt
04/28/2021, 9:13 PMYoni
04/28/2021, 9:13 PMmatt
04/28/2021, 9:13 PMmatt
04/28/2021, 9:14 PMYoni
04/28/2021, 9:14 PMSome functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
i probably just did something wrongmatt
04/28/2021, 9:15 PM