@flue/sdk 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +24 -15
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -399,7 +399,6 @@ var CloudflarePlugin = class {
399
399
  return `
400
400
  // Auto-generated by @flue/sdk build (cloudflare)
401
401
  import { Agent, routeAgentRequest } from 'agents';
402
- import { DurableObject } from 'cloudflare:workers';
403
402
  import { Bash, InMemoryFs } from 'just-bash';
404
403
  import {
405
404
  createFlueContext,
@@ -456,24 +455,34 @@ async function createLocalEnv() {
456
455
  * RPC stub, null otherwise.
457
456
  *
458
457
  * NOTE on detection: The value returned by \`getSandbox()\` is a workerd RPC
459
- * Proxy. \`in\` and \`typeof\` against it return \`true\`/\`'function'\` for any
460
- * property name, so structural duck-typing is unreliable.
458
+ * Proxy. None of the obvious detection strategies work:
461
459
  *
462
- * \`instanceof <UserSandboxClass>\` ALSO does not work: the RPC stub's
463
- * prototype chain is workerd's internal \`DurableObject\` runtime class, not
464
- * the user-defined \`Sandbox\` class (the user's class only exists on the
465
- * in-DO side; the caller side gets a generic stub). Empirically:
466
- * typeof stub === 'object'
467
- * Object.getPrototypeOf(stub).constructor.name === 'DurableObject'
460
+ * - Structural duck-typing (\`'X' in stub\`, \`typeof stub.X === 'function'\`):
461
+ * the proxy lies positively for any property name, so any check returns
462
+ * \`true\` regardless of what's actually on the remote.
463
+ * - \`instanceof <UserSandboxClass>\` (e.g. \`Sandbox\` from
464
+ * \`@cloudflare/sandbox\`): the user's class only exists on the in-DO
465
+ * side; over RPC the caller gets a generic stub.
466
+ * - \`instanceof DurableObject\` (imported from \`cloudflare:workers\`): the
467
+ * stub's prototype chain has a class *named* \`DurableObject\`, but it's a
468
+ * workerd-internal class with a different identity than the importable
469
+ * one. \`instanceof\` checks identity, not name, so it returns \`false\`.
468
470
  *
469
- * \`instanceof DurableObject\` (imported from \`cloudflare:workers\`) is the
470
- * one signal that holds: it walks the prototype chain via the runtime and
471
- * matches any DO RPC stub. We treat any DO stub passed to \`init({ sandbox })\`
472
- * as intended for \`@cloudflare/sandbox\`, since that's the only documented
473
- * use case for that argument shape on the Cloudflare target.
471
+ * The one signal that does work — verified by runtime probe — is the string
472
+ * name of the prototype's constructor. Workerd's internal RPC stub class is
473
+ * named \`DurableObject\`, and \`Object.getPrototypeOf(stub).constructor.name\`
474
+ * returns that string. This is a heuristic (it relies on a workerd-internal
475
+ * naming convention, not a contractual API), but it's empirically correct
476
+ * today and will misroute only if a user passes some other DO stub to
477
+ * \`init({ sandbox })\` — in which case \`cfSandboxToSessionEnv\` will fail
478
+ * loudly on first method call.
474
479
  */
475
480
  function resolveSandbox(sandbox) {
476
- if (sandbox instanceof DurableObject) {
481
+ if (
482
+ sandbox &&
483
+ typeof sandbox === 'object' &&
484
+ Object.getPrototypeOf(sandbox)?.constructor?.name === 'DurableObject'
485
+ ) {
477
486
  return cfSandboxToSessionEnv(sandbox);
478
487
  }
479
488
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flue/sdk",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {