{"version":3,"file":"internal.cjs","names":[],"sources":["../../src/render/internal.ts"],"sourcesContent":["import type { Optional } from \"utility-types\";\nimport type {\n  AccessorHandle,\n  Branded,\n  PObjectId,\n  StringifiedJson,\n  SUniversalPColumnId,\n} from \"@milaboratories/pl-model-common\";\nexport type { AccessorHandle };\nimport type { CommonFieldTraverseOps, FieldTraversalStep, ResourceType } from \"./traversal_ops\";\nimport type {\n  ArchiveFormat,\n  AnyFunction,\n  PColumn,\n  PColumnValues,\n  PFrameDef,\n  PFrameHandle,\n  PObject,\n  PObjectSpec,\n  PTableDef,\n  PTableDefV2,\n  PTableHandle,\n  ResultCollection,\n  ValueOrError,\n  DataInfo,\n  RangeBytes,\n} from \"@milaboratories/pl-model-common\";\nimport type { TreeNodeAccessor } from \"./accessor\";\nimport type { ServiceDispatch } from \"@milaboratories/pl-model-common\";\n\nexport const MainAccessorName = \"main\";\nexport const StagingAccessorName = \"staging\";\n\nexport type FutureHandle = Branded<string, \"FutureHandle\">;\n\nexport type PColumnDataUniversal<TreeEntry = TreeNodeAccessor> =\n  | TreeEntry\n  | DataInfo<TreeEntry>\n  | PColumnValues;\n\n// Raw upstream-block ctx shape lives in `@milaboratories/pl-model-common`\n// (`UpstreamBlockCtx`). Import directly from there at use sites.\nimport type { UpstreamBlockCtx } from \"@milaboratories/pl-model-common\";\n\nexport interface GlobalCfgRenderCtxMethods<AHandle = AccessorHandle, FHandle = FutureHandle> {\n  //\n  // Root accessor creation\n  //\n\n  getAccessorHandleByName(name: string): AHandle | undefined;\n\n  //\n  // Basic resource accessor actions\n  //\n\n  resolveWithCommon(\n    handle: AHandle,\n    commonOptions: CommonFieldTraverseOps,\n    ...steps: (FieldTraversalStep | string)[]\n  ): AHandle | undefined;\n\n  getResourceType(handle: AHandle): ResourceType;\n\n  getInputsLocked(handle: AHandle): boolean;\n\n  getOutputsLocked(handle: AHandle): boolean;\n\n  getIsReadyOrError(handle: AHandle): boolean;\n\n  getIsFinal(handle: AHandle): boolean;\n\n  getError(handle: AHandle): AHandle | undefined;\n\n  listInputFields(handle: AHandle): string[];\n\n  listOutputFields(handle: AHandle): string[];\n\n  listDynamicFields(handle: AHandle): string[];\n\n  getKeyValueBase64(handle: AHandle, key: string): string | undefined;\n\n  getKeyValueAsString(handle: AHandle, key: string): string | undefined;\n\n  hasData(handle: AHandle): boolean;\n\n  getDataBase64(handle: AHandle): string | undefined;\n\n  getDataAsString(handle: AHandle): string | undefined;\n\n  /** @deprecated */\n  parsePObjectCollection(\n    handle: AHandle,\n    errorOnUnknownField: boolean,\n    prefix: string,\n    ...resolvePath: string[]\n  ): Record<string, PObject<AHandle>> | undefined;\n\n  //\n  // Blob\n  //\n\n  getBlobContentAsBase64(handle: AHandle, range?: RangeBytes): FHandle; // string | undefined\n\n  getBlobContentAsString(handle: AHandle, range?: RangeBytes): FHandle; // string | undefined\n\n  getDownloadedBlobContentHandle(handle: AHandle): FHandle; // LocalBlobHandleAndSize | undefined;\n\n  getOnDemandBlobContentHandle(handle: AHandle): FHandle; // RemoteBlobHandleAndSize | undefined;\n\n  //\n  // Blobs to URLs\n  //\n\n  extractArchiveAndGetURL(handle: AHandle, format: ArchiveFormat): FHandle;\n\n  //\n  // Import progress\n  //\n\n  getImportProgress(handle: AHandle): FHandle; // ImportProgress;\n\n  //\n  // Logs\n  //\n\n  getLastLogs(handle: AHandle, nLines: number): FHandle; // string | undefined;\n\n  getProgressLog(handle: AHandle, patternToSearch: string): FHandle; // string | undefined;\n\n  getProgressLogWithInfo(handle: AHandle, patternToSearch: string): FHandle; // ProgressLogWithInfo | undefined;\n\n  getLogHandle(handle: AHandle): FHandle; // AnyLogHandle | undefined;\n\n  //\n  // Blocks\n  //\n\n  /** @deprecated at some point will stop working and will return dummy values */\n  getBlockLabel(blockId: string): string;\n\n  //\n  // Result Pool\n  //\n\n  getDataFromResultPool(): ResultCollection<PObject<AHandle>>;\n\n  getDataWithErrorsFromResultPool(): ResultCollection<\n    Optional<PObject<ValueOrError<AHandle, Error>>, \"id\">\n  >;\n\n  getSpecsFromResultPool(): ResultCollection<PObjectSpec>;\n\n  getSpecFromResultPoolByRef(blockId: string, exportName: string): PObjectSpec | undefined;\n\n  getDataFromResultPoolByRef(blockId: string, exportName: string): PObject<AHandle> | undefined;\n\n  //\n  // Raw result pool — list of upstream block ctx accessor handles.\n  // SDK-side providers compose enumerate/status/data themselves on top of these.\n  //\n\n  /**\n   * For each upstream block in the staging graph, returns its prod/staging ctx\n   * accessor handles (when present). Sandbox uses these handles with\n   * `getPObjectEntryDataHandle` to build\n   * column snapshots; spec/status/data merge with prod-vs-staging precedence\n   * lives sandbox-side.\n   */\n  getUpstreamBlockCtx(): ReadonlyArray<UpstreamBlockCtx<AHandle>>;\n\n  //\n  // PFrame / PTable\n  //\n\n  createPFrame(\n    def: PFrameDef<\n      PObjectId | SUniversalPColumnId | PColumn<AHandle | PColumnValues | DataInfo<AHandle>>\n    >,\n  ): PFrameHandle;\n\n  createPTable(\n    def: PTableDef<\n      PObjectId | SUniversalPColumnId | PColumn<AHandle | PColumnValues | DataInfo<AHandle>>\n    >,\n  ): PTableHandle;\n\n  createPTableV2(\n    def: PTableDefV2<\n      PObjectId | SUniversalPColumnId | PColumn<AHandle | PColumnValues | DataInfo<AHandle>>\n    >,\n  ): PTableHandle;\n\n  //\n  // Computable\n  //\n\n  getCurrentUnstableMarker(): string | undefined;\n\n  //\n  // Logging\n  //\n\n  logInfo(message: string): void;\n\n  logWarn(message: string): void;\n\n  logError(message: string): void;\n}\n\nexport const GlobalCfgRenderCtxFeatureFlags = {\n  explicitColumnsSupport: true as const,\n  inlineColumnsSupport: true as const,\n  activeArgs: true as const,\n  pTablePartitionFiltersSupport: true as const,\n  pFrameInSetFilterSupport: true as const,\n  lazyColumnStatusSupport: true as const,\n};\n\nexport interface GlobalCfgRenderCtx extends GlobalCfgRenderCtxMethods, ServiceDispatch {\n  //\n  // State: Args, UI State, Active Args\n  //\n  // Old runtime injects these values as strings, new runtime injects them as functions\n  // that return strings, if block declares supportsLazyState flag.\n  // If function not called in lazy state API, then resulting output will not depend on these values,\n  // and thus will not be recalculated on corresponding state change.\n  //\n\n  readonly args: string | (() => string);\n  /** @deprecated Use `data` instead. Optional for backward compatibility - falls back to `data` if not injected. */\n  readonly uiState?: string | (() => string);\n  readonly data: string | (() => string);\n  readonly activeArgs: undefined | string | (() => string | undefined);\n\n  readonly blockStorage: () => StringifiedJson;\n\n  // Note: strings below are used because, anyway, using strings is the only way\n  // to get data inside the QuickJS context, as it is implemented now. With this\n  // approach deserialization can be lazily postponed until it is actually needed.\n  readonly callbackRegistry: Record<string, AnyFunction>;\n  readonly featureFlags?: typeof GlobalCfgRenderCtxFeatureFlags;\n}\n\nexport type FutureAwait = {\n  __awaited_futures__: FutureHandle[];\n};\n\nexport function isFutureAwait(obj: unknown): obj is FutureAwait {\n  return typeof obj === \"object\" && obj !== null && \"__awaited_futures__\" in obj;\n}\n\nfunction addAllFutureAwaits(set: Set<string>, visited: Set<unknown>, node: unknown) {\n  if (visited.has(node)) return;\n  visited.add(node);\n\n  const type = typeof node;\n  if (type === \"object\") {\n    if (isFutureAwait(node)) node.__awaited_futures__.forEach((a) => set.add(a));\n    else if (Array.isArray(node))\n      for (const nested of node) addAllFutureAwaits(set, visited, nested);\n    else\n      for (const [, nested] of Object.entries(node as object))\n        if (nested !== node) addAllFutureAwaits(set, visited, nested);\n  }\n}\n\nexport function getAllFutureAwaits(obj: unknown): Set<string> {\n  const set = new Set<string>();\n  addAllFutureAwaits(set, new Set(), obj);\n  return set;\n}\n"],"mappings":";;;;;;;;AA8BA,MAAa,mBAAmB;AAChC,MAAa,sBAAsB;AAkLnC,MAAa,iCAAiC;CAC5C,wBAAwB;CACxB,sBAAsB;CACtB,YAAY;CACZ,+BAA+B;CAC/B,0BAA0B;CAC1B,yBAAyB;AAC3B;AA+BA,SAAgB,cAAc,KAAkC;CAC9D,OAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,yBAAyB;AAC7E;AAEA,SAAS,mBAAmB,KAAkB,SAAuB,MAAe;CAClF,IAAI,QAAQ,IAAI,IAAI,GAAG;CACvB,QAAQ,IAAI,IAAI;CAGhB,IAAI,OADgB,SACP,UAAU;EACrB,IAAI,cAAc,IAAI,GAAG,KAAK,oBAAoB,SAAS,MAAM,IAAI,IAAI,CAAC,CAAC;OACtE,IAAI,MAAM,QAAQ,IAAI,GACzB,KAAK,MAAM,UAAU,MAAM,mBAAmB,KAAK,SAAS,MAAM;OAElE,KAAK,MAAM,GAAG,WAAW,OAAO,QAAQ,IAAc,GACpD,IAAI,WAAW,MAAM,mBAAmB,KAAK,SAAS,MAAM;CAClE;AACF;AAEA,SAAgB,mBAAmB,KAA2B;CAC5D,MAAM,sBAAM,IAAI,IAAY;CAC5B,mBAAmB,qBAAK,IAAI,IAAI,GAAG,GAAG;CACtC,OAAO;AACT"}