Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DurableObject newUniqueId #31

Closed
mikecann opened this issue Aug 16, 2021 · 3 comments
Closed

DurableObject newUniqueId #31

mikecann opened this issue Aug 16, 2021 · 3 comments

Comments

@mikecann
Copy link

This method doesnt seem to be implemented or at least it doesnt seems to be able to generate a string when you call toString()) on it.

@evanderkoogh
Copy link
Contributor

Can you give a code example that doesn't work @mikecann? I just tried it and it seems to work just fine?

const id = ns.newUniqueId()
const stub = ns.get(id)
console.log(stub.id.toString())

@mikecann
Copy link
Author

import { router } from "./routes";

export { UserAggregate } from "./aggregates/user/UserAggregate";

export interface EnvInterface {
  UserAggregate: DurableObjectNamespace;
}

export default {
  async fetch(request: Request, env: EnvInterface): Promise<Response> {
    console.log(`TEST`, env.UserAggregate.newUniqueId());
    return new Response(`done`);
  },
};

Outputs: TEST DurableObjectId { name: undefined }

I am using esbuild to bundle my worker:

import { build } from "esbuild";

const isWatchMode = () => false;
const config = {};

async function bootstrap() {
  console.log(`starting`, config);

  await build({
    entryPoints: ["./src/index.ts"],
    bundle: true,
    format: "esm",
    outdir: `dist`,
    outExtension: { ".js": ".mjs" },
    sourcemap: "external",
    platform: "node",
    target: [`node14`],
    external: [],
    watch: isWatchMode()
      ? {
          onRebuild(err, result) {
            if (err) console.error("watch build failed:", err);
            else console.log("watch build succeeded");
          },
        }
      : undefined,
    // banner: {
    //   js: constructServerBannerEnvInjection(getBTEnvVarsForBannerInjection()),
    // },
  });

  console.log(`build complete`);
}

bootstrap()
  .then(() => {
    if (!isWatchMode()) {
      console.log(`build done, exiting now.`);
      process.exit(0);
    }
  })
  .catch(e => {
    console.error(e);
    process.exit(1);
  });

@mikecann
Copy link
Author

scratch that sorry if I do toString() on the ID I get 000000017b4cc362ba6844a4e72bc0cffedebbdcbc9fbd16762ae91aa9b85edb. Apologies for the confusion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants