{
  "version": 3,
  "sources": ["../../../../src/workers/core/dev-control.worker.ts", "../../../../src/plugins/core/constants.ts", "../../../../src/shared/dev-control.ts"],
  "sourcesContent": ["import { WorkerEntrypoint } from \"cloudflare:workers\";\nimport workerdUnsafe from \"workerd:unsafe\";\nimport { INTROSPECT_SQLITE_METHOD } from \"../../plugins/core/constants\";\nimport { getDevControlDurableObjectBindingName } from \"../../shared/dev-control\";\nimport type { IntrospectSqliteMethod } from \"../../plugins/core/constants\";\nimport type {\n\tDevControl as DevControlInterface,\n\tDurableObjectIdentifier,\n\tDurableObjectEvictionOptions,\n\tDurableObjectStorageOperationOptions,\n} from \"../../shared/dev-control\";\nimport type {\n\tDurableObjectNamespace,\n\tDurableObjectStub,\n\tSqlStorageValue,\n} from \"@cloudflare/workers-types/experimental\";\n\ntype IntrospectableDurableObjectStub = DurableObjectStub & {\n\t[INTROSPECT_SQLITE_METHOD]: IntrospectSqliteMethod;\n};\n\nfunction isDurableObjectNamespace(\n\tbinding: unknown\n): binding is DurableObjectNamespace {\n\treturn (\n\t\ttypeof binding === \"object\" &&\n\t\tbinding !== null &&\n\t\t\"idFromName\" in binding &&\n\t\ttypeof binding.idFromName === \"function\" &&\n\t\t\"idFromString\" in binding &&\n\t\ttypeof binding.idFromString === \"function\" &&\n\t\t\"get\" in binding &&\n\t\ttypeof binding.get === \"function\"\n\t);\n}\n\nfunction getDurableObjectStub(\n\tenv: Record<string, unknown>,\n\tscriptName: string,\n\tclassName: string,\n\tidentifier: DurableObjectIdentifier\n): IntrospectableDurableObjectStub {\n\tconst bindingName = getDevControlDurableObjectBindingName(\n\t\tscriptName,\n\t\tclassName\n\t);\n\tconst namespace = env[bindingName];\n\n\tif (!isDurableObjectNamespace(namespace)) {\n\t\tthrow new TypeError(\n\t\t\t`Expected Durable Object namespace binding for ${scriptName}:${className}`\n\t\t);\n\t}\n\n\tconst id =\n\t\tidentifier.id === undefined\n\t\t\t? namespace.idFromName(identifier.name)\n\t\t\t: namespace.idFromString(identifier.id);\n\n\treturn namespace.get(id) as IntrospectableDurableObjectStub;\n}\n\nexport default class DevControl\n\textends WorkerEntrypoint<Record<string, unknown>>\n\timplements DevControlInterface\n{\n\tasync evictDurableObject(\n\t\tscriptName: string,\n\t\tclassName: string,\n\t\toptions: DurableObjectEvictionOptions\n\t): Promise<void> {\n\t\tconst stub = getDurableObjectStub(this.env, scriptName, className, options);\n\n\t\tawait workerdUnsafe.evict(stub, {\n\t\t\twebSockets: options.webSockets,\n\t\t});\n\t}\n\n\tasync execDurableObjectSql<Row extends Record<string, SqlStorageValue>>(\n\t\tscriptName: string,\n\t\tclassName: string,\n\t\toptions: DurableObjectStorageOperationOptions\n\t): Promise<Row[]> {\n\t\tconst stub = getDurableObjectStub(this.env, scriptName, className, options);\n\n\t\tconst [result] = await stub[INTROSPECT_SQLITE_METHOD]([\n\t\t\t{ sql: options.query, params: options.bindings },\n\t\t]);\n\n\t\tif (result === undefined) {\n\t\t\tthrow new Error(\"Durable Object SQLite query did not return a result.\");\n\t\t}\n\n\t\tconst columns = result.columns ?? [];\n\t\tconst rawRows = result.rows ?? [];\n\t\tconst rows = rawRows.map((rawRow) => {\n\t\t\treturn Object.fromEntries(\n\t\t\t\tcolumns.map((column, index) => [column, rawRow[index]])\n\t\t\t) as Row;\n\t\t});\n\n\t\treturn rows;\n\t}\n}\n", "import type {\n\tDoRawQueryResult,\n\tDoSqlWithParams,\n} from \"../../workers/local-explorer/generated\";\n\nexport const CORE_PLUGIN_NAME = \"core\";\n\n// Service for HTTP socket entrypoint (for checking runtime ready, routing, etc)\nexport const SERVICE_ENTRY = `${CORE_PLUGIN_NAME}:entry`;\n// Service for local explorer (API + UI)\nexport const SERVICE_LOCAL_EXPLORER = `${CORE_PLUGIN_NAME}:local-explorer`;\n// Disk service for local explorer UI assets\nexport const LOCAL_EXPLORER_DISK = `${CORE_PLUGIN_NAME}:local-explorer-disk`;\n// Local observability collector; user workers' `streamingTails` point here.\n// Prefixed via getUserServiceName(), so the name itself must not contain a\n// colon (it collides with the `core:user:` service namespacing).\nexport const OBSERVABILITY_COLLECTOR_SERVICE_NAME =\n\t\"miniflare-observability-collector\";\n// Flags that make a user worker stream its tail (incl. user spans) to the\n// collector; applied to each user worker when observability is enabled\nexport const OBSERVABILITY_COMPAT_FLAGS = [\n\t\"streaming_tail_worker\",\n\t\"tail_worker_user_spans\",\n] as const;\n// Service prefix for all regular user workers\nconst SERVICE_USER_PREFIX = `${CORE_PLUGIN_NAME}:user`;\n// Service prefix for `workerd`'s builtin services (network, external, disk)\nconst SERVICE_BUILTIN_PREFIX = `${CORE_PLUGIN_NAME}:builtin`;\n// Service prefix for custom fetch functions defined in `serviceBindings` option\nconst SERVICE_CUSTOM_FETCH_PREFIX = `${CORE_PLUGIN_NAME}:custom-fetch`;\n// Service prefix for custom Node functions defined in `serviceBindings` option\nconst SERVICE_CUSTOM_NODE_PREFIX = `${CORE_PLUGIN_NAME}:custom-node`;\n\nexport function getUserServiceName(workerName = \"\") {\n\treturn `${SERVICE_USER_PREFIX}:${workerName}`;\n}\n\n// Namespace custom services to avoid conflicts between user-specified names\n// and hardcoded Miniflare names\nexport enum CustomServiceKind {\n\tUNKNOWN = \"#\", // User specified name (i.e. `serviceBindings`)\n\tKNOWN = \"$\", // Miniflare specified name (i.e. `outboundService`)\n}\n\nexport const CUSTOM_SERVICE_KNOWN_OUTBOUND = \"outbound\";\n\nexport function getBuiltinServiceName(\n\tworkerIndex: number,\n\tkind: CustomServiceKind,\n\tbindingName: string\n) {\n\treturn `${SERVICE_BUILTIN_PREFIX}:${workerIndex}:${kind}${bindingName}`;\n}\n\nexport function getCustomFetchServiceName(\n\tworkerIndex: number,\n\tkind: CustomServiceKind,\n\tbindingName: string\n) {\n\treturn `${SERVICE_CUSTOM_FETCH_PREFIX}:${workerIndex}:${kind}${bindingName}`;\n}\n\nexport function getCustomNodeServiceName(\n\tworkerIndex: number,\n\tkind: CustomServiceKind,\n\tbindingName: string\n) {\n\treturn `${SERVICE_CUSTOM_NODE_PREFIX}:${workerIndex}:${kind}${bindingName}`;\n}\n\n/**\n * Used by the local explorer worker.\n * The method name injected into wrapped Durable Objects for SQLite introspection.\n */\nexport const INTROSPECT_SQLITE_METHOD = \"__miniflare_introspectSqlite\";\n\nexport type IntrospectSqliteMethod = (\n\tqueries: DoSqlWithParams[]\n) => Promise<DoRawQueryResult[]>;\n\n/**\n * Used by the local explorer worker.\n * This method is injected into wrapped Durable Objects to allow getting the DO instance name.\n */\nexport const GET_DO_NAME_METHOD = \"__miniflare_getDOName\";\n\nexport type GetDONameMethod = () => string | undefined;\n", "import type { SqlStorage, SqlStorageValue } from \"@cloudflare/workers-types\";\n\nexport type DurableObjectIdentifier =\n\t| { name: string; id?: never }\n\t| { id: string; name?: never };\n\nexport type DurableObjectEvictionOptions = DurableObjectIdentifier & {\n\twebSockets?: \"close\" | \"hibernate\";\n};\n\nexport type DurableObjectStorageOptions = DurableObjectIdentifier;\n\nexport type DurableObjectStorageHandle = {\n\texec<\n\t\tRow extends Record<string, SqlStorageValue> = Record<\n\t\t\tstring,\n\t\t\tSqlStorageValue\n\t\t>,\n\t>(\n\t\t...args: Parameters<SqlStorage[\"exec\"]>\n\t): Promise<Row[]>;\n};\n\nexport type DurableObjectStorageOperationOptions = DurableObjectIdentifier & {\n\tquery: string;\n\tbindings: unknown[];\n};\n\nexport interface DevControl {\n\tevictDurableObject(\n\t\tscriptName: string,\n\t\tclassName: string,\n\t\toptions: DurableObjectEvictionOptions\n\t): Promise<void>;\n\texecDurableObjectSql<Row extends Record<string, SqlStorageValue>>(\n\t\tscriptName: string,\n\t\tclassName: string,\n\t\toptions: DurableObjectStorageOperationOptions\n\t): Promise<Row[]>;\n}\n\nexport function createDurableObjectStorageHandle(\n\tcontrol: DevControl,\n\tscriptName: string,\n\tclassName: string,\n\toptions: DurableObjectStorageOptions\n): DurableObjectStorageHandle {\n\treturn {\n\t\tasync exec(query, ...bindings) {\n\t\t\treturn control.execDurableObjectSql(scriptName, className, {\n\t\t\t\t...options,\n\t\t\t\tquery,\n\t\t\t\tbindings,\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function getDevControlDurableObjectBindingName(\n\tscriptName: string,\n\tclassName: string\n) {\n\treturn [\"MINIFLARE_DEV_CONTROL_DO\", scriptName, className].join(\":\");\n}\n"],
  "mappings": ";AAAA,SAAS,wBAAwB;AACjC,OAAO,mBAAmB;;;ACInB,IAAM,mBAAmB,QAGnB,gBAAgB,GAAG,gBAAgB,UAEnC,yBAAyB,GAAG,gBAAgB,mBAE5C,sBAAsB,GAAG,gBAAgB;AAatD,IAAM,sBAAsB,GAAG,gBAAgB,SAEzC,yBAAyB,GAAG,gBAAgB,YAE5C,8BAA8B,GAAG,gBAAgB,iBAEjD,6BAA6B,GAAG,gBAAgB;AA2C/C,IAAM,2BAA2B;;;AChBjC,SAAS,sCACf,YACA,WACC;AACD,SAAO,CAAC,4BAA4B,YAAY,SAAS,EAAE,KAAK,GAAG;AACpE;;;AF1CA,SAAS,yBACR,SACoC;AACpC,SACC,OAAO,WAAY,YACnB,YAAY,QACZ,gBAAgB,WAChB,OAAO,QAAQ,cAAe,cAC9B,kBAAkB,WAClB,OAAO,QAAQ,gBAAiB,cAChC,SAAS,WACT,OAAO,QAAQ,OAAQ;AAEzB;AAEA,SAAS,qBACR,KACA,YACA,WACA,YACkC;AAClC,MAAM,cAAc;AAAA,IACnB;AAAA,IACA;AAAA,EACD,GACM,YAAY,IAAI,WAAW;AAEjC,MAAI,CAAC,yBAAyB,SAAS;AACtC,UAAM,IAAI;AAAA,MACT,iDAAiD,UAAU,IAAI,SAAS;AAAA,IACzE;AAGD,MAAM,KACL,WAAW,OAAO,SACf,UAAU,WAAW,WAAW,IAAI,IACpC,UAAU,aAAa,WAAW,EAAE;AAExC,SAAO,UAAU,IAAI,EAAE;AACxB;AAEA,IAAqB,aAArB,cACS,iBAET;AAAA,EACC,MAAM,mBACL,YACA,WACA,SACgB;AAChB,QAAM,OAAO,qBAAqB,KAAK,KAAK,YAAY,WAAW,OAAO;AAE1E,UAAM,cAAc,MAAM,MAAM;AAAA,MAC/B,YAAY,QAAQ;AAAA,IACrB,CAAC;AAAA,EACF;AAAA,EAEA,MAAM,qBACL,YACA,WACA,SACiB;AACjB,QAAM,OAAO,qBAAqB,KAAK,KAAK,YAAY,WAAW,OAAO,GAEpE,CAAC,MAAM,IAAI,MAAM,KAAK,wBAAwB,EAAE;AAAA,MACrD,EAAE,KAAK,QAAQ,OAAO,QAAQ,QAAQ,SAAS;AAAA,IAChD,CAAC;AAED,QAAI,WAAW;AACd,YAAM,IAAI,MAAM,sDAAsD;AAGvE,QAAM,UAAU,OAAO,WAAW,CAAC;AAQnC,YAPgB,OAAO,QAAQ,CAAC,GACX,IAAI,CAAC,WAClB,OAAO;AAAA,MACb,QAAQ,IAAI,CAAC,QAAQ,UAAU,CAAC,QAAQ,OAAO,KAAK,CAAC,CAAC;AAAA,IACvD,CACA;AAAA,EAGF;AACD;",
  "names": []
}
