@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.
- package/dist/index.mjs +24 -15
- 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.
|
|
460
|
-
* property name, so structural duck-typing is unreliable.
|
|
458
|
+
* Proxy. None of the obvious detection strategies work:
|
|
461
459
|
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
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
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
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 (
|
|
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;
|